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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
231c0b0aa33747333e0b4c3386547f35f72e9e5c | 717 | agda | Agda | zerepoch-metatheory/test/StringLiteral.agda | Quantum-One-DLT/zerepoch | c8cf4619e6e496930c9092cf6d64493eff300177 | [
"Apache-2.0"
] | null | null | null | zerepoch-metatheory/test/StringLiteral.agda | Quantum-One-DLT/zerepoch | c8cf4619e6e496930c9092cf6d64493eff300177 | [
"Apache-2.0"
] | null | null | null | zerepoch-metatheory/test/StringLiteral.agda | Quantum-One-DLT/zerepoch | c8cf4619e6e496930c9092cf6d64493eff300177 | [
"Apache-2.0"
] | 2 | 2021-11-13T21:25:19.000Z | 2022-02-21T16:38:59.000Z | module test.StringLiteral where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
-- zerepoch/zerepoch-core/test/data/stringLiteral.plc
postulate str1 : ByteString
{-# FOREIGN GHC import qualified Data.ByteString.Char8 as BS #-}
{-# COMPILE GHC str1 = BS.pack "4321758fabce1aa4780193f" #-}
open import Relation.Binary.PropositionalEquality
open import Agda.Builtin.TrustMe
lemma1 : length str1 ≡ 23
lemma1 = primTrustMe
open import Data.Nat
lemma1' : BoundedB 100 str1
lemma1' rewrite lemma1 = gen _ _ _
stringLit : ∀{Γ} → Γ ⊢ con bytestring (size⋆ 100)
stringLit = con (bytestring 100 str1 lemma1')
| 25.607143 | 64 | 0.76569 |
18c12b19a0849193da4e59da89bc6f9568d7811c | 1,573 | agda | Agda | RefactorAgdaEngine/Test/Tests/input/Test.agda | omega12345/RefactorAgda | 52d1034aed14c578c9e077fb60c3db1d0791416b | [
"BSD-3-Clause"
] | 5 | 2019-01-31T14:10:18.000Z | 2019-05-03T10:03:36.000Z | RefactorAgdaEngine/Test/Tests/input/Test.agda | omega12345/RefactorAgda | 52d1034aed14c578c9e077fb60c3db1d0791416b | [
"BSD-3-Clause"
] | 3 | 2019-01-31T08:03:07.000Z | 2019-02-05T12:53:36.000Z | RefactorAgdaEngine/Test/Tests/input/Test.agda | omega12345/RefactorAgda | 52d1034aed14c578c9e077fb60c3db1d0791416b | [
"BSD-3-Clause"
] | 1 | 2019-01-31T08:40:41.000Z | 2019-01-31T08:40:41.000Z | -- a few random examples
module Test where
import Agda.Builtin.Bool
data Nat : Set where zero : Nat -- Comment which gets eaten
suc : Nat -> Nat --Comment which is preserved
plus {- preserved comment {- which may be nested -} -} :
{- comment after Colon, also preserved-}
{-comments are essentially whitespace, even through they get parsed-} Nat -> {-comment, preserved-} Nat -> Nat
{-# BUILTIN NATURAL
Nat #-}
plus zero m = m
plus (suc n) m = suc (plus n m)
{-# BUILTIN NATPLUS plus #-}
--excess brackets are not preserved
minus : ((Nat)) -> Nat
-- We can nest holes correctly
minus a = {! ? {! Hole inside hole !} !}
-- Seriously long and complicated function type
func : {A : Set} ->
{B : A -> Set} ->
{C : (x : A) -> B x -> Set} ->
(f : {x : A} -> (y : B x) -> C x y) ->
(g : (x : A) -> B x) ->
(x : A) ->
C x (g x)
func f g x = f (g x)
-- Holes can go here as well
id : {a : Set} -> a -> {! !}
id x = x
-- and the code from the planning report, rewritten in Baby-Agda
data List (A : Set) : Set where
empty : List A
cons : A -> List A -> List A
append : {A : Set} -> List A -> List A -> List A
append empty ys = ys
append (cons x xs) ys = cons x (append xs ys)
-- proposed code after refactoring
data List2 (A : Set) : Nat -> Set where
empty2 : List2 A 0
cons2 : {n : Nat} -> A -> List2 A n -> List2 A (plus 1 n)
append2 : {n : Nat} -> {m : Nat} -> {A : Set} ->
List2 A m -> List2 A n -> List2 A (plus m n)
append2 empty2 ys = ys
append2 (cons2 x xs) ys = cons2 x (append2 xs ys)
| 27.12069 | 114 | 0.570884 |
dcb5acf35308f7bcd79e254be15f06f9773adde2 | 2,669 | agda | Agda | src/SystemF/BigStep/Types.agda | ajrouvoet/implicits.agda | ef2e347a4470e55083c83b743efbc2902ef1ad22 | [
"MIT"
] | 4 | 2019-04-05T17:57:11.000Z | 2021-05-07T04:08:41.000Z | src/SystemF/BigStep/Types.agda | ElessarWebb/implicits.agda | ef2e347a4470e55083c83b743efbc2902ef1ad22 | [
"MIT"
] | null | null | null | src/SystemF/BigStep/Types.agda | ElessarWebb/implicits.agda | ef2e347a4470e55083c83b743efbc2902ef1ad22 | [
"MIT"
] | null | null | null | module SystemF.BigStep.Types where
open import Prelude
-- types are indexed by the number of open tvars
infixl 10 _⇒_
data Type (n : ℕ) : Set where
Unit : Type n
ν : (i : Fin n) → Type n
_⇒_ : Type n → Type n → Type n
∀' : Type (suc n) → Type n
open import Data.Fin.Substitution
open import Data.Vec
module App {T} (l : Lift T Type )where
open Lift l hiding (var)
_/_ : ∀ {m n} → Type m → Sub T m n → Type n
Unit / s = Unit
ν i / s = lift (lookup i s)
(a ⇒ b) / s = (a / s) ⇒ (b / s)
∀' x / s = ∀' (x / (s ↑))
open Application (record { _/_ = _/_ }) using (_/✶_)
open import Data.Star
Unit-/✶-↑✶ : ∀ k {m n} (ρs : Subs T m n) → Unit /✶ ρs ↑✶ k ≡ Unit
Unit-/✶-↑✶ k ε = refl
Unit-/✶-↑✶ k (x ◅ ρs) = cong₂ _/_ (Unit-/✶-↑✶ k ρs) refl
∀-/✶-↑✶ : ∀ k {m n t} (ρs : Subs T m n) →
∀' t /✶ ρs ↑✶ k ≡ ∀' (t /✶ ρs ↑✶ suc k)
∀-/✶-↑✶ k ε = refl
∀-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (∀-/✶-↑✶ k ρs) refl
⇒-/✶-↑✶ : ∀ k {m n t₁ t₂} (ρs : Subs T m n) →
t₁ ⇒ t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) ⇒ (t₂ /✶ ρs ↑✶ k)
⇒-/✶-↑✶ k ε = refl
⇒-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (⇒-/✶-↑✶ k ρs) refl
tmSubst : TermSubst Type
tmSubst = record { var = ν; app = App._/_ }
open TermSubst tmSubst hiding (var; subst) public
module Lemmas where
open import Data.Fin.Substitution.Lemmas
tyLemmas : TermLemmas Type
tyLemmas = record
{ termSubst = tmSubst
; app-var = refl
; /✶-↑✶ = Lemma./✶-↑✶
}
where
module Lemma {T₁ T₂} {lift₁ : Lift T₁ Type} {lift₂ : Lift T₂ Type} where
open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)
open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)
/✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) →
(∀ k x → ν x /✶₁ ρs₁ ↑✶₁ k ≡ ν x /✶₂ ρs₂ ↑✶₂ k) →
∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k
/✶-↑✶ ρs₁ ρs₂ hyp k Unit =
begin _ ≡⟨ App.Unit-/✶-↑✶ _ k ρs₁ ⟩ Unit ≡⟨ sym $ App.Unit-/✶-↑✶ _ k ρs₂ ⟩ _ ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (ν i) = hyp k i
/✶-↑✶ ρs₁ ρs₂ hyp k (a ⇒ b) = begin
_ ≡⟨ App.⇒-/✶-↑✶ _ 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 $ App.⇒-/✶-↑✶ _ k ρs₂ ⟩
_ ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (∀' x) = begin
_ ≡⟨ App.∀-/✶-↑✶ _ k ρs₁ ⟩
∀' (x /✶₁ ρs₁ ↑✶₁ (suc k)) ≡⟨ cong ∀' (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) x) ⟩
∀' (x /✶₂ ρs₂ ↑✶₂ (suc k)) ≡⟨ sym $ App.∀-/✶-↑✶ _ k ρs₂ ⟩
_ ∎
open TermLemmas tyLemmas public hiding (var)
| 32.54878 | 86 | 0.449981 |
4a77449488fbd7dcde1b9f52534f28351388fc07 | 432 | agda | Agda | examples/outdated-and-incorrect/syntax/ModuleA.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | examples/outdated-and-incorrect/syntax/ModuleA.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | examples/outdated-and-incorrect/syntax/ModuleA.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | 1 | 2022-03-12T11:35:18.000Z | 2022-03-12T11:35:18.000Z |
-- This module is used to illustrate how to import a non-parameterised module.
module examples.syntax.ModuleA where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
plus : Nat -> Nat -> Nat
eval : Nat -> Nat
eval zero = zero
eval (suc x) = suc (eval x)
eval (plus zero y) = eval y
eval (plus (suc x) y) = suc (eval (plus x y))
eval (plus (plus x y) z) = eval (plus x (plus y z))
| 25.411765 | 78 | 0.578704 |
4ad3c06cc886e1fccd72b9d044ff3379d6110948 | 1,086 | agda | Agda | agda/BBSTree/Properties.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | 6 | 2015-05-21T12:50:35.000Z | 2021-08-24T22:11:15.000Z | agda/BBSTree/Properties.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | agda/BBSTree/Properties.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | open import Relation.Binary.Core
module BBSTree.Properties {A : Set}
(_≤_ : A → A → Set)
(trans≤ : Transitive _≤_) where
open import BBSTree _≤_
open import Bound.Total A
open import Bound.Total.Order.Properties _≤_ trans≤
open import List.Order.Simple _≤_
open import List.Order.Simple.Properties _≤_ trans≤
open import List.Sorted _≤_
lemma-bbst-*≤ : {b : Bound}(x : A) → (t : BBSTree b (val x)) → flatten t *≤ x
lemma-bbst-*≤ x (bslf _) = lenx
lemma-bbst-*≤ x (bsnd {x = y} b≤y y≤x l r) = lemma-++-*≤ (lemma-LeB≤ y≤x) (lemma-bbst-*≤ y l) (lemma-bbst-*≤ x r)
lemma-bbst-≤* : {b : Bound}(x : A) → (t : BBSTree (val x) b) → x ≤* flatten t
lemma-bbst-≤* x (bslf _) = genx
lemma-bbst-≤* x (bsnd {x = y} x≤y y≤t l r) = lemma-≤*-++ (lemma-LeB≤ x≤y) (lemma-bbst-≤* x l) (lemma-bbst-≤* y r)
lemma-bbst-sorted : {b t : Bound}(t : BBSTree b t) → Sorted (flatten t)
lemma-bbst-sorted (bslf _) = nils
lemma-bbst-sorted (bsnd {x = x} b≤x x≤t l r) = lemma-sorted++ (lemma-bbst-*≤ x l) (lemma-bbst-≤* x r) (lemma-bbst-sorted l) (lemma-bbst-sorted r)
| 43.44 | 145 | 0.601289 |
d0812e6d80d1d1dd7edd607673845ac239779985 | 2,329 | agda | Agda | Cubical/Data/Unit/Properties.agda | hyleIndex/cubical | ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4 | [
"MIT"
] | 301 | 2018-10-17T18:00:24.000Z | 2022-03-24T02:10:47.000Z | Cubical/Data/Unit/Properties.agda | hyleIndex/cubical | ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4 | [
"MIT"
] | 584 | 2018-10-15T09:49:02.000Z | 2022-03-30T12:09:17.000Z | Cubical/Data/Unit/Properties.agda | hyleIndex/cubical | ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4 | [
"MIT"
] | 134 | 2018-11-16T06:11:03.000Z | 2022-03-23T16:22:13.000Z | {-# OPTIONS --safe #-}
module Cubical.Data.Unit.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Unit.Base
open import Cubical.Data.Prod.Base
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Reflection.StrictEquiv
isContrUnit : isContr Unit
isContrUnit = tt , λ {tt → refl}
isPropUnit : isProp Unit
isPropUnit _ _ i = tt -- definitionally equal to: isContr→isProp isContrUnit
isSetUnit : isSet Unit
isSetUnit = isProp→isSet isPropUnit
isOfHLevelUnit : (n : HLevel) → isOfHLevel n Unit
isOfHLevelUnit n = isContr→isOfHLevel n isContrUnit
module _ {ℓ} (A : Type ℓ) where
UnitToType≃ : (Unit → A) ≃ A
unquoteDef UnitToType≃ = defStrictEquiv UnitToType≃ (λ f → f _) const
UnitToTypePath : ∀ {ℓ} (A : Type ℓ) → (Unit → A) ≡ A
UnitToTypePath A = ua (UnitToType≃ A)
isContr→Iso2 : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → isContr A → Iso (A → B) B
Iso.fun (isContr→Iso2 iscontr) f = f (fst iscontr)
Iso.inv (isContr→Iso2 iscontr) b _ = b
Iso.rightInv (isContr→Iso2 iscontr) _ = refl
Iso.leftInv (isContr→Iso2 iscontr) f = funExt λ x → cong f (snd iscontr x)
diagonal-unit : Unit ≡ Unit × Unit
diagonal-unit = isoToPath (iso (λ x → tt , tt) (λ x → tt) (λ {(tt , tt) i → tt , tt}) λ {tt i → tt})
fibId : ∀ {ℓ} (A : Type ℓ) → (fiber (λ (x : A) → tt) tt) ≡ A
fibId A = ua e
where
unquoteDecl e = declStrictEquiv e fst (λ a → a , refl)
isContr→≃Unit : ∀ {ℓ} {A : Type ℓ} → isContr A → A ≃ Unit
isContr→≃Unit contr = isoToEquiv (iso (λ _ → tt) (λ _ → fst contr) (λ _ → refl) λ _ → snd contr _)
isContr→≡Unit : {A : Type₀} → isContr A → A ≡ Unit
isContr→≡Unit contr = ua (isContr→≃Unit contr)
isContrUnit* : ∀ {ℓ} → isContr (Unit* {ℓ})
isContrUnit* = tt* , λ _ → refl
isPropUnit* : ∀ {ℓ} → isProp (Unit* {ℓ})
isPropUnit* _ _ = refl
isOfHLevelUnit* : ∀ {ℓ} (n : HLevel) → isOfHLevel n (Unit* {ℓ})
isOfHLevelUnit* zero = tt* , λ _ → refl
isOfHLevelUnit* (suc zero) _ _ = refl
isOfHLevelUnit* (suc (suc zero)) _ _ _ _ _ _ = tt*
isOfHLevelUnit* (suc (suc (suc n))) = isOfHLevelPlus 3 (isOfHLevelUnit* n)
| 32.802817 | 100 | 0.686561 |
d0dbb310fe68f91c4388c5ab0880f9f78eac2aea | 460 | agda | Agda | error.agda | rfindler/ial | f3f0261904577e930bd7646934f756679a6cbba6 | [
"MIT"
] | 29 | 2019-02-06T13:09:31.000Z | 2022-03-04T15:05:12.000Z | error.agda | rfindler/ial | f3f0261904577e930bd7646934f756679a6cbba6 | [
"MIT"
] | 8 | 2018-07-09T22:53:38.000Z | 2022-03-22T03:43:34.000Z | error.agda | rfindler/ial | f3f0261904577e930bd7646934f756679a6cbba6 | [
"MIT"
] | 17 | 2018-12-03T22:38:15.000Z | 2021-11-28T20:13:21.000Z | -- a simple error monad
module error where
open import level
open import string
infixr 0 _≫=err_ _≫err_
data error-t{ℓ}(A : Set ℓ) : Set ℓ where
no-error : A → error-t A
yes-error : string → error-t A
_≫=err_ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → error-t A → (A → error-t B) → error-t B
(no-error a) ≫=err f = f a
(yes-error e) ≫=err _ = yes-error e
_≫err_ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → error-t A → error-t B → error-t B
a ≫err b = a ≫=err λ _ → b
| 23 | 82 | 0.580435 |
d03138a23da3654205fedca1732295b242544a7d | 467 | agda | Agda | core/lib/types/Choice.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | null | null | null | core/lib/types/Choice.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | null | null | null | core/lib/types/Choice.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 lib.Basics
open import lib.types.Truncation
open import lib.types.Pi
module lib.types.Choice where
unchoose : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : A → Type j}
→ Trunc n (Π A B) → Π A (Trunc n ∘ B)
unchoose = Trunc-rec (Π-level λ _ → Trunc-level) (λ f → [_] ∘ f)
has-choice : ∀ {i} (n : ℕ₋₂) (A : Type i) j → Type (lmax i (lsucc j))
has-choice {i} n A j = (B : A → Type j) → is-equiv (unchoose {n = n} {A} {B})
| 31.133333 | 77 | 0.582441 |
cbaa18ca5e472af05ae84c6e8db67fa9276c38bd | 181 | agda | Agda | test/Fail/Issue3338.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/Issue3338.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/Issue3338.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | postulate
R : Set → Set1
r : {X : Set} {{ _ : R X }} → X → Set
A : Set
a : A
instance
RI : R A
-- RI = {!!} -- uncommenting lets instance resolution succeed
foo : r a
| 15.083333 | 63 | 0.524862 |
20acf3535af8c94d9aa0185d4b06bb44f290fcb1 | 6,400 | agda | Agda | BasicIS4/Equipment/KripkeDyadicCanonical.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 29 | 2016-07-03T18:51:56.000Z | 2022-01-01T10:29:18.000Z | BasicIS4/Equipment/KripkeDyadicCanonical.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 1 | 2018-06-10T09:11:22.000Z | 2018-06-10T09:11:22.000Z | BasicIS4/Equipment/KripkeDyadicCanonical.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | null | null | null | -- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Canonical model equipment for Kripke-style semantics.
module BasicIS4.Equipment.KripkeDyadicCanonical where
open import BasicIS4.Syntax.Common public
module Syntax
(_⊢_ : Cx² Ty Ty → Ty → Set)
(mono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A)
(up : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ (□ □ A))
(down : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ A)
(lift : ∀ {A Γ Δ} → (Γ ⁏ Δ) ⊢ A → (□⋆ Γ ⁏ Δ) ⊢ (□ A))
where
-- Worlds.
Worldᶜ : Set
Worldᶜ = Cx² Ty Ty
-- Intuitionistic accessibility.
infix 3 _≤ᶜ_
_≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_≤ᶜ_ = _⊆²_
refl≤ᶜ : ∀ {w} → w ≤ᶜ w
refl≤ᶜ = refl⊆²
trans≤ᶜ : ∀ {w w′ w″} → w ≤ᶜ w′ → w′ ≤ᶜ w″ → w ≤ᶜ w″
trans≤ᶜ = trans⊆²
bot≤ᶜ : ∀ {w} → ∅² ≤ᶜ w
bot≤ᶜ = bot⊆²
-- The canonical modal accessibility, based on the T axiom.
infix 3 _Rᶜ_
_Rᶜ_ : Worldᶜ → Worldᶜ → Set
w Rᶜ w′ = ∀ {A} → w ⊢ (□ A) → w′ ⊢ A
reflRᶜ : ∀ {w} → w Rᶜ w
reflRᶜ = down
transRᶜ : ∀ {w w′ w″} → w Rᶜ w′ → w′ Rᶜ w″ → w Rᶜ w″
transRᶜ ζ ζ′ = ζ′ ∘ ζ ∘ up
botRᶜ : ∀ {w} → ∅² Rᶜ w
botRᶜ = mono²⊢ bot≤ᶜ ∘ down
liftRᶜ : ∀ {Γ Δ} → Γ ⁏ Δ Rᶜ □⋆ Γ ⁏ Δ
liftRᶜ = down ∘ lift ∘ down
-- Composition of accessibility.
infix 3 _≤⨾Rᶜ_
_≤⨾Rᶜ_ : Worldᶜ → Worldᶜ → Set
_≤⨾Rᶜ_ = _≤ᶜ_ ⨾ _Rᶜ_
infix 3 _R⨾≤ᶜ_
_R⨾≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_R⨾≤ᶜ_ = _Rᶜ_ ⨾ _≤ᶜ_
refl≤⨾Rᶜ : ∀ {w} → w ≤⨾Rᶜ w
refl≤⨾Rᶜ {w} = w , (refl≤ᶜ , reflRᶜ)
reflR⨾≤ᶜ : ∀ {w} → w R⨾≤ᶜ w
reflR⨾≤ᶜ {w} = w , (reflRᶜ , refl≤ᶜ)
-- Persistence condition, after Iemhoff; included by Ono.
--
-- w′ v′ → v′
-- ◌───R───● → ●
-- │ → ╱
-- ≤ ξ,ζ → R
-- │ → ╱
-- ● → ●
-- w → w
≤⨾R→Rᶜ : ∀ {v′ w} → w ≤⨾Rᶜ v′ → w Rᶜ v′
≤⨾R→Rᶜ (w′ , (ξ , ζ)) = ζ ∘ mono²⊢ ξ
-- Brilliance condition, after Iemhoff.
--
-- v′ → v′
-- ● → ●
-- │ → ╱
-- ζ,ξ ≤ → R
-- │ → ╱
-- ●───R───◌ → ●
-- w v → w
R⨾≤→Rᶜ : ∀ {w v′} → w R⨾≤ᶜ v′ → w Rᶜ v′
R⨾≤→Rᶜ (v , (ζ , ξ)) = mono²⊢ ξ ∘ ζ
-- Minor persistence condition, included by Božić and Došen.
--
-- w′ v′ → v′
-- ◌───R───● → ●
-- │ → │
-- ≤ ξ,ζ → ≤
-- │ → │
-- ● → ●───R───◌
-- w → w v
--
-- w″ → w″
-- ● → ●
-- │ → │
-- ξ′,ζ′ ≤ → │
-- │ → │
-- ●───R───◌ → ≤
-- │ v′ → │
-- ξ,ζ ≤ → │
-- │ → │
-- ●───R───◌ → ●───────R───────◌
-- w v → w v″
≤⨾R→R⨾≤ᶜ : ∀ {v′ w} → w ≤⨾Rᶜ v′ → w R⨾≤ᶜ v′
≤⨾R→R⨾≤ᶜ {v′} ξ,ζ = v′ , (≤⨾R→Rᶜ ξ,ζ , refl≤ᶜ)
transR⨾≤ᶜ : ∀ {w′ w w″} → w R⨾≤ᶜ w′ → w′ R⨾≤ᶜ w″ → w R⨾≤ᶜ w″
transR⨾≤ᶜ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾R→R⨾≤ᶜ (w′ , (ξ , ζ′))
in v″ , (transRᶜ ζ ζ″ , trans≤ᶜ ξ″ ξ′)
≤→Rᶜ : ∀ {v′ w} → w ≤ᶜ v′ → w Rᶜ v′
≤→Rᶜ {v′} ξ = ≤⨾R→Rᶜ (v′ , (ξ , reflRᶜ))
-- Minor brilliance condition, included by Ewald and Alechina et al.
--
-- v′ → w′ v′
-- ● → ◌───R───●
-- │ → │
-- ζ,ξ ≤ → ≤
-- │ → │
-- ●───R───◌ → ●
-- w v → w
--
-- v′ w″ → v″ w″
-- ◌───R───● → ◌───────R───────●
-- │ → │
-- ≤ ξ′,ζ′ → │
-- v │ → │
-- ◌───R───● → ≤
-- │ w′ → │
-- ≤ ξ,ζ → │
-- │ → │
-- ● → ●
-- w → w
R⨾≤→≤⨾Rᶜ : ∀ {w v′} → w R⨾≤ᶜ v′ → w ≤⨾Rᶜ v′
R⨾≤→≤⨾Rᶜ {w} ζ,ξ = w , (refl≤ᶜ , R⨾≤→Rᶜ ζ,ξ)
trans≤⨾Rᶜ : ∀ {w′ w w″} → w ≤⨾Rᶜ w′ → w′ ≤⨾Rᶜ w″ → w ≤⨾Rᶜ w″
trans≤⨾Rᶜ {w′} (v , (ξ , ζ)) (v′ , (ξ′ , ζ′)) = let v″ , (ξ″ , ζ″) = R⨾≤→≤⨾Rᶜ (w′ , (ζ , ξ′))
in v″ , (trans≤ᶜ ξ ξ″ , transRᶜ ζ″ ζ′)
≤→Rᶜ′ : ∀ {w v′} → w ≤ᶜ v′ → w Rᶜ v′
≤→Rᶜ′ {w} ξ = R⨾≤→Rᶜ (w , (reflRᶜ , ξ))
-- Infimum (greatest lower bound) of accessibility.
--
-- w′
-- ●
-- │
-- ≤ ξ,ζ
-- │
-- ◌───R───●
-- w v
infix 3 _≤⊓Rᶜ_
_≤⊓Rᶜ_ : Worldᶜ → Worldᶜ → Set
_≤⊓Rᶜ_ = _≤ᶜ_ ⊓ _Rᶜ_
infix 3 _R⊓≤ᶜ_
_R⊓≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_R⊓≤ᶜ_ = _Rᶜ_ ⊓ _≤ᶜ_
≤⊓R→R⊓≤ᶜ : ∀ {w′ v} → w′ ≤⊓Rᶜ v → v R⊓≤ᶜ w′
≤⊓R→R⊓≤ᶜ (w , (ξ , ζ)) = w , (ζ , ξ)
R⊓≤→≤⊓Rᶜ : ∀ {w′ v} → v R⊓≤ᶜ w′ → w′ ≤⊓Rᶜ v
R⊓≤→≤⊓Rᶜ (w , (ζ , ξ)) = w , (ξ , ζ)
-- Supremum (least upper bound) of accessibility.
--
-- w′ v′
-- ●───R───◌
-- │
-- ξ,ζ ≤
-- │
-- ●
-- v
infix 3 _≤⊔Rᶜ_
_≤⊔Rᶜ_ : Worldᶜ → Worldᶜ → Set
_≤⊔Rᶜ_ = _≤ᶜ_ ⊔ _Rᶜ_
infix 3 _R⊔≤ᶜ_
_R⊔≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_R⊔≤ᶜ_ = _Rᶜ_ ⊔ _≤ᶜ_
≤⊔R→R⊔≤ᶜ : ∀ {w′ v} → w′ ≤⊔Rᶜ v → v R⊔≤ᶜ w′
≤⊔R→R⊔≤ᶜ (v′ , (ξ , ζ)) = v′ , (ζ , ξ)
R⊔≤→≤⊔Rᶜ : ∀ {w′ v} → v R⊔≤ᶜ w′ → w′ ≤⊔Rᶜ v
R⊔≤→≤⊔Rᶜ (v′ , (ζ , ξ)) = v′ , (ξ , ζ)
-- Infimum-to-supremum condition, included by Ewald.
--
-- w′ → w′ v′
-- ● → ●───R───◌
-- │ → │
-- ≤ ξ,ζ → ≤
-- │ → │
-- ◌───R───● → ●
-- w v → v
-- NOTE: This could be more precise.
≤⊓R→≤⊔Rᶜ : ∀ {v w′} → w′ ≤⊓Rᶜ v → v ≤⊔Rᶜ w′
≤⊓R→≤⊔Rᶜ {v} {w′} (w , (ξ , ζ)) =
(w′ ⧺² v) , (weak⊆²⧺₂ , mono²⊢ (weak⊆²⧺₁ v) ∘ down)
-- Supremum-to-infimum condition.
--
-- w′ v′ → w′
-- ●───R───◌ → ●
-- │ → │
-- ξ,ζ ≤ → ≤
-- │ → │
-- ● → ◌───R───●
-- v → w v
-- NOTE: This could be more precise.
≤⊔R→≤⊓Rᶜ : ∀ {w′ v} → v ≤⊔Rᶜ w′ → w′ ≤⊓Rᶜ v
≤⊔R→≤⊓Rᶜ (v′ , (ξ , ζ)) = ∅² , (bot≤ᶜ , botRᶜ)
| 25.498008 | 95 | 0.29125 |
18edd7f3f8de07c4efdcd52c84f3356c105cfafa | 3,091 | agda | Agda | OlderBasicILP/Direct/Translation.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 29 | 2016-07-03T18:51:56.000Z | 2022-01-01T10:29:18.000Z | OlderBasicILP/Direct/Translation.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 1 | 2018-06-10T09:11:22.000Z | 2018-06-10T09:11:22.000Z | OlderBasicILP/Direct/Translation.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | null | null | null | module OlderBasicILP.Direct.Translation where
open import Common.Context public
-- import OlderBasicILP.Direct.Hilbert.Sequential as HS
import OlderBasicILP.Direct.Hilbert.Nested as HN
import OlderBasicILP.Direct.Gentzen as G
-- open HS using () renaming (_⊢×_ to HS⟨_⊢×_⟩ ; _⊢_ to HS⟨_⊢_⟩) public
open HN using () renaming (_⊢_ to HN⟨_⊢_⟩ ; _⊢⋆_ to HN⟨_⊢⋆_⟩) public
open G using () renaming (_⊢_ to G⟨_⊢_⟩ ; _⊢⋆_ to G⟨_⊢⋆_⟩) public
-- Translation from sequential Hilbert-style to nested.
-- hs→hn : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → HN⟨ Γ ⊢ A ⟩
-- hs→hn = ?
-- Translation from nested Hilbert-style to sequential.
-- hn→hs : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩
-- hn→hs = ?
-- Deduction theorem for sequential Hilbert-style.
-- hs-lam : ∀ {A B Γ} → HS⟨ Γ , A ⊢ B ⟩ → HS⟨ Γ ⊢ A ▻ B ⟩
-- hs-lam = hn→hs ∘ HN.lam ∘ hs→hn
-- Translation from Hilbert-style to Gentzen-style.
mutual
hn→gᵇᵒˣ : HN.Box → G.Box
hn→gᵇᵒˣ HN.[ t ] = {!G.[ hn→g t ]!}
hn→gᵀ : HN.Ty → G.Ty
hn→gᵀ (HN.α P) = G.α P
hn→gᵀ (A HN.▻ B) = hn→gᵀ A G.▻ hn→gᵀ B
hn→gᵀ (T HN.⦂ A) = hn→gᵇᵒˣ T G.⦂ hn→gᵀ A
hn→gᵀ (A HN.∧ B) = hn→gᵀ A G.∧ hn→gᵀ B
hn→gᵀ HN.⊤ = G.⊤
hn→gᵀ⋆ : Cx HN.Ty → Cx G.Ty
hn→gᵀ⋆ ∅ = ∅
hn→gᵀ⋆ (Γ , A) = hn→gᵀ⋆ Γ , hn→gᵀ A
hn→gⁱ : ∀ {A Γ} → A ∈ Γ → hn→gᵀ A ∈ hn→gᵀ⋆ Γ
hn→gⁱ top = top
hn→gⁱ (pop i) = pop (hn→gⁱ i)
hn→g : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → G⟨ hn→gᵀ⋆ Γ ⊢ hn→gᵀ A ⟩
hn→g (HN.var i) = G.var (hn→gⁱ i)
hn→g (HN.app t u) = G.app (hn→g t) (hn→g u)
hn→g HN.ci = G.ci
hn→g HN.ck = G.ck
hn→g HN.cs = G.cs
hn→g (HN.box t) = {!G.box (hn→g t)!}
hn→g HN.cdist = {!G.cdist!}
hn→g HN.cup = {!G.cup!}
hn→g HN.cdown = G.cdown
hn→g HN.cpair = G.cpair
hn→g HN.cfst = G.cfst
hn→g HN.csnd = G.csnd
hn→g HN.unit = G.unit
-- hs→g : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → G⟨ Γ ⊢ A ⟩
-- hs→g = hn→g ∘ hs→hn
-- Translation from Gentzen-style to Hilbert-style.
mutual
g→hnᵇᵒˣ : G.Box → HN.Box
g→hnᵇᵒˣ G.[ t ] = {!HN.[ g→hn t ]!}
g→hnᵀ : G.Ty → HN.Ty
g→hnᵀ (G.α P) = HN.α P
g→hnᵀ (A G.▻ B) = g→hnᵀ A HN.▻ g→hnᵀ B
g→hnᵀ (T G.⦂ A) = g→hnᵇᵒˣ T HN.⦂ g→hnᵀ A
g→hnᵀ (A G.∧ B) = g→hnᵀ A HN.∧ g→hnᵀ B
g→hnᵀ G.⊤ = HN.⊤
g→hnᵀ⋆ : Cx G.Ty → Cx HN.Ty
g→hnᵀ⋆ ∅ = ∅
g→hnᵀ⋆ (Γ , A) = g→hnᵀ⋆ Γ , g→hnᵀ A
g→hnⁱ : ∀ {A Γ} → A ∈ Γ → g→hnᵀ A ∈ g→hnᵀ⋆ Γ
g→hnⁱ top = top
g→hnⁱ (pop i) = pop (g→hnⁱ i)
g→hn : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HN⟨ g→hnᵀ⋆ Γ ⊢ g→hnᵀ A ⟩
g→hn (G.var i) = HN.var (g→hnⁱ i)
g→hn (G.lam t) = HN.lam (g→hn t)
g→hn (G.app t u) = HN.app (g→hn t) (g→hn u)
-- g→hn (G.multibox ts u) = {!HN.multibox (g→hn⋆ ts) (g→hn u)!}
g→hn (G.down t) = HN.down (g→hn t)
g→hn (G.pair t u) = HN.pair (g→hn t) (g→hn u)
g→hn (G.fst t) = HN.fst (g→hn t)
g→hn (G.snd t) = HN.snd (g→hn t)
g→hn G.unit = HN.unit
g→hn⋆ : ∀ {Ξ Γ} → G⟨ Γ ⊢⋆ Ξ ⟩ → HN⟨ g→hnᵀ⋆ Γ ⊢⋆ g→hnᵀ⋆ Ξ ⟩
g→hn⋆ {∅} ∙ = ∙
g→hn⋆ {Ξ , A} (ts , t) = g→hn⋆ ts , g→hn t
-- g→hs : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩
-- g→hs = hn→hs ∘ g→hn
| 28.1 | 71 | 0.484309 |
23cd1fa90ad8819501191f3f8e0afa103fefa2c5 | 8,585 | agda | Agda | agda/PLRTree/Drop/Complete.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | 6 | 2015-05-21T12:50:35.000Z | 2021-08-24T22:11:15.000Z | agda/PLRTree/Drop/Complete.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | agda/PLRTree/Drop/Complete.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | open import Relation.Binary.Core
module PLRTree.Drop.Complete {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.Sum
open import PLRTree {A}
open import PLRTree.Complete {A}
open import PLRTree.Compound {A}
open import PLRTree.Drop _≤_ tot≤
open import PLRTree.DropLast.Complete _≤_ tot≤
open import PLRTree.Equality {A}
open import PLRTree.Order.Properties {A}
open import PLRTree.Push.Complete _≤_ tot≤
lemma-setRoot-complete : {t : PLRTree}(x : A) → Complete t → Complete (setRoot x t)
lemma-setRoot-complete x leaf = leaf
lemma-setRoot-complete x (perfect _ cl cr l≃r) = perfect x cl cr l≃r
lemma-setRoot-complete x (left _ cl cr l⋘r) = left x cl cr l⋘r
lemma-setRoot-complete x (right _ cl cr l⋙r) = right x cl cr l⋙r
lemma-drop-complete : {t : PLRTree} → Complete t → Complete (drop t)
lemma-drop-complete leaf = leaf
lemma-drop-complete (perfect _ _ _ ≃lf) = leaf
lemma-drop-complete (perfect {node perfect x' l' r'} {node perfect x'' l'' r''} x (perfect .x' cl' cr' _) (perfect .x'' cl'' cr'' _) (≃nd .x' .x'' l'≃r' l''≃r'' l'≃l'')) =
let z = last (node perfect x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;
t' = dropLast (node perfect x (node perfect x' l' r') (node perfect x'' l'' r'')) ;
ct' = right x (perfect x' cl' cr' l'≃r') (lemma-dropLast-complete (perfect x'' cl'' cr'' l''≃r'')) (lemma-dropLast-≃ (≃nd x' x'' l'≃r' l''≃r'' l'≃l'') compound)
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left {l} {r} x cl cr l⋘r)
with l | r | l⋘r | lemma-dropLast-⋘ l⋘r
... | leaf | _ | () | _
... | node perfect x' l' r' | _ | () | _
... | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₁ ld⋘r
with dropLast (node left x' l' r') | ld⋘r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect _ _ _ | () | _
... | node left x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node right x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left x cl cr l⋘r) | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₂ ld≃r
with dropLast (node left x' l' r') | ld≃r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect x''' l''' r''' | ld≃r' | cld =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = perfect x cld cr ld≃r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node left _ _ _ | () | _
... | node right _ _ _ | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | leaf | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₁ ()
lemma-drop-complete (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₂ x'≃x''' =
let z = last (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) compound ;
t' = dropLast (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) ;
ct' = perfect x (perfect x' leaf leaf ≃lf) cr x'≃x'''
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₁ ld⋘r
with dropLast (node right x' l' r') | ld⋘r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect _ _ _ | () | _
... | node left x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node right x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₂ ld≃r
with dropLast (node right x' l' r') | ld≃r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect x''' l''' r''' | ld≃r' | cld =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = perfect x cld cr ld≃r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node left _ _ _ | () | _
... | node right _ _ _ | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node left x'' l'' r'' | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node right x'' l'' r'' | () | _
lemma-drop-complete (right {l} {r} x cl cr l⋙r)
with l | r | l⋙r | lemma-dropLast-⋙ l⋙r
... | leaf | leaf | ⋙p () | _
... | node perfect x' leaf leaf | leaf | ⋙p (⋗lf .x') | _ = cl
... | node perfect _ _ (node _ _ _ _) | leaf | ⋙p () | _
... | node perfect _ (node _ _ _ _) _ | leaf | ⋙p () | _
... | node left _ _ _ | leaf | ⋙p () | _
... | node right _ _ _ | leaf | ⋙p () | _
... | leaf | node perfect _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node perfect x'' l'' r'' | ⋙p (⋗nd .x' .x'' l'≃r' l''≃r'' l'⋗l'') | _ =
let z = last (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) ;
ct' = left x (lemma-dropLast-complete cl) cr (lemma-dropLast-⋗ (⋗nd x' x'' l'≃r' l''≃r'' l'⋗l'') compound)
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node left _ _ _ | node perfect _ _ _ | ⋙p () | _
... | node right _ _ _ | node perfect _ _ _ | ⋙p () | _
... | leaf | node left _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node left x'' l'' r'' | _ | inj₁ l⋙rd =
let z = last (node right x (node perfect x' l' r') (node left x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node left x'' l'' r'')) ;
ct' = right x cl (lemma-dropLast-complete cr) l⋙rd
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node perfect _ _ _ | node left _ _ _ | _ | inj₂ ()
... | node left _ _ _ | node left _ _ _ | ⋙p () | _
... | node right _ _ _ | node left _ _ _ | ⋙p () | _
... | leaf | node right _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node right x'' l'' r'' | _ | inj₁ l⋙rd =
let z = last (node right x (node perfect x' l' r') (node right x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node right x'' l'' r'')) ;
ct' = right x cl (lemma-dropLast-complete cr) l⋙rd
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node perfect _ _ _ | node right _ _ _ | _ | inj₂ ()
... | node left _ _ _ | node right _ _ _ | ⋙p () | _
... | node right _ _ _ | node right _ _ _ | ⋙p () | _
| 68.134921 | 183 | 0.509726 |
dc9dc9dfdba90fecaee0970cb9b796d6b42d7e7d | 6,441 | agda | Agda | Cubical/Relation/Binary/Definitions.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/Relation/Binary/Definitions.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/Relation/Binary/Definitions.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Definitions where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Logic hiding (_⇒_; _⇔_; ¬_)
open import Cubical.Foundations.HLevels
open import Cubical.Data.Maybe.Base using (Maybe)
open import Cubical.Data.Sum.Base using (_⊎_)
open import Cubical.Data.Sigma.Base
open import Cubical.HITs.PropositionalTruncation.Base
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.Nullary.Decidable
private
variable
a b c ℓ ℓ′ ℓ′′ ℓ′′′ : Level
A : Type a
B : Type b
C : Type c
------------------------------------------------------------------------
-- Basic defintions
------------------------------------------------------------------------
infix 7 _⇒_ _⇔_ _=[_]⇒_
infix 8 _⟶_Respects_ _Respects_ _Respectsˡ_ _Respectsʳ_ _Respects₂_
idRel : (A : Type ℓ) → Rel A ℓ
idRel A a b .fst = ∥ a ≡ b ∥
idRel A _ _ .snd = squash
invRel : REL A B ℓ′ → REL B A ℓ′
invRel R b a = R a b
compRel : REL A B ℓ′ → REL B C ℓ′′ → REL A C _
compRel R S a c .fst = ∃[ b ∈ _ ] ⟨ R a b ⟩ × ⟨ S b c ⟩
compRel R S _ _ .snd = squash
graphRel : {B : Type b} → (A → B) → isSet B → REL A B b
graphRel f isSetB a b .fst = f a ≡ b
graphRel f isSetB a b .snd = isSetB (f a) b
-- Implication/containment - could also be written _⊆_.
-- and corresponding notion of equivalence
_⇒_ : REL A B ℓ → REL A B ℓ′ → Type _
P ⇒ Q = ∀ {x y} → ⟨ P x y ⟩ → ⟨ Q x y ⟩
_⇔_ : REL A B ℓ → REL A B ℓ′ → Type _
P ⇔ Q = P ⇒ Q × Q ⇒ P
-- Generalised implication - if P ≡ Q it can be read as "f preserves P".
_=[_]⇒_ : Rel A ℓ → (A → B) → Rel B ℓ′ → Type _
P =[ f ]⇒ Q = P ⇒ (Q on f)
-- A synonym for _=[_]⇒_.
_Preserves_⟶_ : (A → B) → Rel A ℓ → Rel B ℓ′ → Type _
f Preserves P ⟶ Q = P =[ f ]⇒ Q
-- An endomorphic variant of _Preserves_⟶_.
_Preserves_ : (A → A) → Rel A ℓ → Type _
f Preserves P = f Preserves P ⟶ P
-- A binary variant of _Preserves_⟶_.
_Preserves₂_⟶_⟶_ : (A → B → C) → Rel A ℓ → Rel B ℓ′ → Rel C ℓ′′ → Type _
_∙_ Preserves₂ P ⟶ Q ⟶ R = ∀ {x y u v} → ⟨ P x y ⟩ → ⟨ Q u v ⟩ → ⟨ R (x ∙ u) (y ∙ v) ⟩
------------------------------------------------------------------------
-- Property predicates
------------------------------------------------------------------------
-- Reflexivity.
Reflexive : Rel A ℓ → Type _
Reflexive _∼_ = ∀ {x} → ⟨ x ∼ x ⟩
-- Equality can be converted to proof of relation.
FromEq : Rel A ℓ → Type _
FromEq _∼_ = _≡ₚ_ ⇒ _∼_
-- Irreflexivity.
Irreflexive : Rel A ℓ → Type _
Irreflexive _<_ = ∀ {x} → ¬ ⟨ x < x ⟩
-- Relation implies inequality.
ToNotEq : Rel A ℓ → Type _
ToNotEq _<_ = _<_ ⇒ _≢ₚ_
-- Generalised symmetry.
Sym : REL A B ℓ → REL B A ℓ′ → Type _
Sym P Q = P ⇒ flip Q
-- Symmetry.
Symmetric : Rel A ℓ → Type _
Symmetric _∼_ = Sym _∼_ _∼_
-- Generalised transitivity.
Trans : REL A B ℓ → REL B C ℓ′ → REL A C ℓ′′ → Type _
Trans P Q R = ∀ {i j k} → ⟨ P i j ⟩ → ⟨ Q j k ⟩ → ⟨ R i k ⟩
-- A flipped variant of generalised transitivity.
TransFlip : REL A B ℓ → REL B C ℓ′ → REL A C ℓ′′ → Type _
TransFlip P Q R = ∀ {i j k} → ⟨ Q j k ⟩ → ⟨ P i j ⟩ → ⟨ R i k ⟩
-- Transitivity.
Transitive : Rel A ℓ → Type _
Transitive _∼_ = Trans _∼_ _∼_ _∼_
-- Generalised antisymmetry.
Antisym : REL A B ℓ → REL B A ℓ′ → REL A B ℓ′′ → Type _
Antisym R S E = ∀ {i j} → ⟨ R i j ⟩ → ⟨ S j i ⟩ → ⟨ E i j ⟩
-- Antisymmetry.
Antisymmetric : Rel A ℓ → Type _
Antisymmetric _≤_ = Antisym _≤_ _≤_ _≡ₚ_
-- Asymmetry.
Asymmetric : Rel A ℓ → Type _
Asymmetric _<_ = ∀ {x y} → ⟨ x < y ⟩ → ¬ ⟨ y < x ⟩
-- Generalised connex - exactly one of the two relations holds.
RawConnex : REL A B ℓ → REL B A ℓ′ → Type _
RawConnex P Q = ∀ x y → ⟨ P x y ⟩ ⊎ ⟨ Q y x ⟩
-- Totality.
RawTotal : Rel A ℓ → Type _
RawTotal _∼_ = RawConnex _∼_ _∼_
-- Truncated connex - Preserves propositions.
Connex : REL A B ℓ → REL B A ℓ′ → Type _
Connex P Q = ∀ x y → ⟨ P x y ⊔ Q y x ⟩
-- Truncated totality.
Total : Rel A ℓ → Type _
Total _∼_ = Connex _∼_ _∼_
-- Generalised trichotomy - exactly one of three types has a witness.
data Tri (A : Type a) (B : Type b) (C : Type c) : Type (ℓ-max a (ℓ-max b c)) where
tri< : ( a : A) (¬b : ¬ B) (¬c : ¬ C) → Tri A B C
tri≡ : (¬a : ¬ A) ( b : B) (¬c : ¬ C) → Tri A B C
tri> : (¬a : ¬ A) (¬b : ¬ B) ( c : C) → Tri A B C
-- Trichotomy.
Trichotomous : Rel A ℓ → Type _
Trichotomous _<_ = ∀ x y → Tri ⟨ x < y ⟩ (x ≡ y) ⟨ x > y ⟩
where _>_ = flip _<_
-- Maximum element.
Maximum : REL A B ℓ → B → Type _
Maximum _≤_ g = ∀ x → ⟨ x ≤ g ⟩
-- Minimum element
Minimum : REL A B ℓ → A → Type _
Minimum _≤_ l = ∀ x → ⟨ l ≤ x ⟩
-- Unary relations respecting a binary relation.
_⟶_Respects_ : (A → hProp ℓ) → (B → hProp ℓ′) → REL A B ℓ′′ → Type _
P ⟶ Q Respects _∼_ = ∀ {x y} → ⟨ x ∼ y ⟩ → ⟨ P x ⟩ → ⟨ Q y ⟩
-- Unary relation respects a binary relation.
_Respects_ : (A → hProp ℓ) → Rel A ℓ′ → Type _
P Respects _∼_ = P ⟶ P Respects _∼_
-- Right respecting - relatedness is preserved on the right by some equivalence.
_Respectsʳ_ : REL A B ℓ → Rel B ℓ′ → Type _
_∼_ Respectsʳ _≈_ = ∀ {x} → (x ∼_) Respects _≈_
-- Left respecting - relatedness is preserved on the left by some equivalence.
_Respectsˡ_ : REL A B ℓ → Rel A ℓ′ → Type _
_∼_ Respectsˡ _≈_ = ∀ {y} → (_∼ y) Respects _≈_
-- Respecting - relatedness is preserved on both sides by some equivalence.
_Respects₂_ : Rel A ℓ → Rel A ℓ′ → Type _
_∼_ Respects₂ _≈_ = (_∼_ Respectsʳ _≈_) × (_∼_ Respectsˡ _≈_)
-- Substitutivity - any two related elements satisfy exactly the same
-- set of unary relations. Note that only the various derivatives
-- of propositional equality can satisfy this property.
Substitutive : Rel A ℓ → (ℓ′ : Level) → Type _
Substitutive {A = A} _∼_ p = (P : A → hProp p) → P Respects _∼_
-- Decidability - it is possible to determine whether a given pair of
-- elements are related.
Decidable : REL A B ℓ → Type _
Decidable _∼_ = ∀ x y → Dec ⟨ x ∼ y ⟩
-- Weak decidability - it is sometimes possible to determine if a given
-- pair of elements are related.
WeaklyDecidable : REL A B ℓ → Type _
WeaklyDecidable _∼_ = ∀ x y → Maybe ⟨ x ∼ y ⟩
-- Universal - all pairs of elements are related
Universal : REL A B ℓ → Type _
Universal _∼_ = ∀ x y → ⟨ x ∼ y ⟩
-- Non-emptiness - at least one pair of elements are related.
NonEmpty : REL A B ℓ → Type _
NonEmpty _∼_ = ∃[ x ∈ _ ] ∃[ y ∈ _ ] ⟨ x ∼ y ⟩
| 26.615702 | 86 | 0.581121 |
18749005038c4224dd0b5dabb5fc0301239f4ae8 | 398 | agda | Agda | Dave/Logic/Bool.agda | DavidStahl97/formal-proofs | 05213fb6ab1f51f770f9858b61526ba950e06232 | [
"MIT"
] | null | null | null | Dave/Logic/Bool.agda | DavidStahl97/formal-proofs | 05213fb6ab1f51f770f9858b61526ba950e06232 | [
"MIT"
] | null | null | null | Dave/Logic/Bool.agda | DavidStahl97/formal-proofs | 05213fb6ab1f51f770f9858b61526ba950e06232 | [
"MIT"
] | null | null | null | module Dave.Logic.Bool where
data Bool : Set where
false : Bool
true : Bool
¬_ : Bool → Bool
¬ true = false
¬ false = true
_∧_ : Bool → Bool → Bool
a ∧ true = a
a ∧ false = false
if_then_else_ : {A : Set} → Bool → A → A → A
if false then a else b = b
if true then a else b = a
identity : {A : Set} → A → A
identity a = a
| 18.952381 | 48 | 0.497487 |
df6c57d9c4a5497b18535f6543357d0c01433d32 | 2,269 | agda | Agda | src/regular-star.agda | shinji-kono/automaton-in-agda | eba0538f088f3d0c0fedb19c47c081954fbc69cb | [
"MIT"
] | null | null | null | src/regular-star.agda | shinji-kono/automaton-in-agda | eba0538f088f3d0c0fedb19c47c081954fbc69cb | [
"MIT"
] | null | null | null | src/regular-star.agda | shinji-kono/automaton-in-agda | eba0538f088f3d0c0fedb19c47c081954fbc69cb | [
"MIT"
] | null | null | null | module regular-star where
open import Level renaming ( suc to Suc ; zero to Zero )
open import Data.List
open import Data.Nat hiding ( _≟_ )
open import Data.Fin hiding ( _+_ )
open import Data.Empty
open import Data.Unit
open import Data.Product
-- open import Data.Maybe
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import logic
open import nat
open import automaton
open import regular-language
open import nfa
open import sbconst2
open import finiteSet
open import finiteSetUtil
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import regular-concat
open Automaton
open FiniteSet
open RegularLanguage
Star-NFA : {Σ : Set} → (A : RegularLanguage Σ ) → NAutomaton (states A ) Σ
Star-NFA {Σ} A = record { Nδ = δnfa ; Nend = nend }
module Star-NFA where
δnfa : states A → Σ → states A → Bool
δnfa q i q₁ with aend (automaton A) q
... | true = equal? (afin A) ( astart A) q₁
... | false = equal? (afin A) (δ (automaton A) q i) q₁
nend : states A → Bool
nend q = aend (automaton A) q
Star-NFA-start : {Σ : Set} → (A : RegularLanguage Σ ) → states A → Bool
Star-NFA-start A q = equal? (afin A) (astart A) q \/ aend (automaton A) q
SNFA-exist : {Σ : Set} → (A : RegularLanguage Σ ) → (states A → Bool) → Bool
SNFA-exist A qs = exists (afin A) qs
M-Star : {Σ : Set} → (A : RegularLanguage Σ ) → RegularLanguage Σ
M-Star {Σ} A = record {
states = states A → Bool
; astart = Star-NFA-start A
; afin = fin→ (afin A)
; automaton = subset-construction (SNFA-exist A ) (Star-NFA A )
}
open Split
open _∧_
open NAutomaton
open import Data.List.Properties
closed-in-star : {Σ : Set} → (A B : RegularLanguage Σ ) → ( x : List Σ ) → isRegular (Star (contain A) ) x ( M-Star A )
closed-in-star {Σ} A B x = ≡-Bool-func closed-in-star→ closed-in-star← where
NFA = (Star-NFA A )
closed-in-star→ : Star (contain A) x ≡ true → contain (M-Star A ) x ≡ true
closed-in-star→ star = {!!}
open Found
closed-in-star← : contain (M-Star A ) x ≡ true → Star (contain A) x ≡ true
closed-in-star← C with subset-construction-lemma← (SNFA-exist A ) NFA {!!} x C
... | CC = {!!}
| 29.467532 | 121 | 0.641252 |
0ec54904ef9ae3e6f8039e3004035d13472975ae | 9,825 | agda | Agda | fracGC/Singleton.agda | JacquesCarette/pi-dual | 003835484facfde0b770bc2b3d781b42b76184c1 | [
"BSD-2-Clause"
] | 14 | 2015-08-18T21:40:15.000Z | 2021-05-05T01:07:57.000Z | fracGC/Singleton.agda | JacquesCarette/pi-dual | 003835484facfde0b770bc2b3d781b42b76184c1 | [
"BSD-2-Clause"
] | 4 | 2018-06-07T16:27:41.000Z | 2021-10-29T20:41:23.000Z | fracGC/Singleton.agda | JacquesCarette/pi-dual | 003835484facfde0b770bc2b3d781b42b76184c1 | [
"BSD-2-Clause"
] | 3 | 2016-05-29T01:56:33.000Z | 2019-09-10T09:47:13.000Z | {-# OPTIONS --without-K --safe #-}
-- Singleton type and its 'inverse'
module Singleton where
open import Data.Unit using (⊤; tt)
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; subst; cong ; cong₂ ; inspect ; [_])
-- open import Level
-- using (zero)
-- open import Axiom.Extensionality.Propositional
-- using (Extensionality)
is-contr : Set → Set
is-contr A = Σ A (λ a → (x : A) → a ≡ x)
is-prop : Set → Set
is-prop A = (x y : A) → x ≡ y
is-set : Set → Set
is-set A = (x y : A) → is-prop (x ≡ y)
contr-prop : {A : Set} → is-contr A → is-prop A
contr-prop (a , ϕ) x y = trans (sym (ϕ x)) (ϕ y)
apd : ∀ {a b} {A : Set a} {B : A → Set b} (f : (x : A) → B x) {x y} → (p : x ≡ y) → subst B p (f x) ≡ f y
apd f refl = refl
prop-set : {A : Set} → is-prop A → is-set A
prop-set {A} ϕ x y p q = trans (l p) (sym (l q))
where g : (z : A) → x ≡ z
g z = ϕ x z
unitr : {y z : A} (p : y ≡ z) → refl ≡ trans (sym p) p
unitr refl = refl
l : {y z : A} (p : y ≡ z) → p ≡ trans (sym (g y)) (g z)
l refl = unitr (g _)
prop-contr : {A : Set} → is-prop A → A → is-contr A
prop-contr ϕ a = a , ϕ a
------------------------------------------------------------------------------
-- Singleton type: A type with a distinguished point
-- The 'interesting' part is that the point is both a parameter
-- and a field.
{--
record Singleton (A : Set) (v : A) : Set where
constructor ⇑
field
● : A
v≡● : v ≡ ●
open Singleton public
--}
Singleton : (A : Set) → (v : A) → Set
Singleton A v = ∃ (λ ● → v ≡ ●)
-- Singleton types are contractible:
pointed-contr : {A : Set} {v : A} → is-contr (Singleton A v)
--pointed-contr {A} {v} = ⇑ v refl , λ { (⇑ ● refl) → refl }
pointed-contr {A} {v} = (v , refl) , λ { ( ● , refl) → refl }
-- and thus have all paths between them:
pointed-all-paths : {A : Set} {v : A} {p q : Singleton A v} → p ≡ q
pointed-all-paths = contr-prop pointed-contr _ _
-- What does Singleton of Singleton do?
-- Values of type Singleton A v are of the form (w , p) where p : v ≡ w
-- Values of type Singleton (Singleton A v) x
ssv : (A : Set) (v : A) (x : Singleton A v) → Singleton (Singleton A v) x
ssv A v (.v , refl) = (v , refl) , refl
{--
ss=s : (A : Set) (v : A) (x : Singleton A v) → Singleton (Singleton A v) x ≡ Singleton A v
ss=s A v (.v , refl) with pointed-contr {A} {v}
... | (.v , refl) , f = let p = f (v , refl) in {!!} -- ??
--}
------------------------------------------------------------------------------
-- The 'reciprocal' of a Singleton type is a function that accepts exactly
-- that point, and returns no information. It acts as a 'witness' that
-- the right point has been fed to it.
{--
Recip : (A : Set) → (v : A) → Set
Recip A v = (w : A) → (v ≡ w) → ⊤
--}
Recip : (A : Set) → (v : A) → Set
Recip A v = Singleton A v → ⊤
-- Recip A v = Singleton A v → ⊤
-- Recip is also contractible, if we're thinking of homotopy types.
-- We need funext to prove it which is not --safe
-- posulate
-- funext : Extensionality zero zero
-- recip-contr : {A : Set} {v : A} → is-contr (Recip A v)
-- recip-contr = (λ _ _ → tt) , λ r → funext λ _ → funext λ _ → refl
------------------------------------------------------------------------------
-- Recip' : {A : Set} {v : A} → Singleton A v → Set
-- Recip' {A} {v} (⇑ w v≡w) = v ≡ w
-- Recip'-ptd : {A : Set} {v : A} → (p : Singleton A v) → Singleton (Recip' p) (v≡● p)
-- Recip'-ptd (⇑ w v≡w) = ⇑ v≡w refl
-- family of path types from arbitrary w to a fixed v
Recip' : (A : Set) → (v : A) → Set
Recip' A v = (w : A) → v ≡ w
-- If A is a n-type, Recip' is a (n-1)-type
-- recip'-contr : {A : Set} {v : A} → is-prop A → is-contr (Recip' A v)
-- recip'-contr {A} {v} ϕ = (λ w → ϕ v w) , λ r → funext λ x → prop-set ϕ v x (ϕ v x) (r x)
-- recip'-prop : {A : Set} {v : A} → is-set A → is-prop (Recip' A v)
-- recip'-prop ϕ r s = funext (λ x → ϕ _ x (r x) (s x))
------------------------------------------------------------------------------
-- Singleton is an idempotent bimonad on pointed sets
-- (need to check some coherences)
∙Set = Σ Set (λ X → X)
∙Set[_,_] : ∙Set → ∙Set → Set
∙Set[ (A , a) , (B , b) ] = Σ (A → B) λ f → f a ≡ b
_∙×_ : ∙Set → ∙Set → ∙Set
(A , a) ∙× (B , b) = (A × B) , (a , b)
-- left version, there's also a right version
-- note that this isn't a coproduct
-- wedge sum is the coproduct
_∙+_ : ∙Set → ∙Set → ∙Set
(A , a) ∙+ (B , b) = (A ⊎ B) , inj₁ a
∙id : ∀{∙A} → ∙Set[ ∙A , ∙A ]
∙id = (λ a → a) , refl
_∘_ : ∀ {∙A ∙B ∙C} → ∙Set[ ∙A , ∙B ] → ∙Set[ ∙B , ∙C ] → ∙Set[ ∙A , ∙C ]
(f , p) ∘ (g , q) = (λ x → g (f x)) , trans (cong g p) q
-- terminal and initial
∙1 : ∙Set
∙1 = ⊤ , tt
∙![_] : ∀ ∙A → ∙Set[ ∙A , ∙1 ]
∙![ (A , a) ] = (λ _ → tt) , refl
∙!-uniq : ∀ {∙A} {x : ∙A .proj₁} → (∙f : ∙Set[ ∙A , ∙1 ]) → (∙f .proj₁) x ≡ (∙![ ∙A ] .proj₁) x
∙!-uniq {A , a} {x} (f , p) = refl
∙¡[_] : ∀ ∙A → ∙Set[ ∙1 , ∙A ]
∙¡[ A , a ] = (λ _ → a) , refl
∙¡-uniq : ∀ {∙A} → (∙f : ∙Set[ ∙1 , ∙A ]) → (∙f .proj₁) tt ≡ (∙¡[ ∙A ] .proj₁) tt
∙¡-uniq (f , p) = p
record ∙Iso[_,_] (∙A ∙B : ∙Set) : Set where
constructor iso
field
∙f : ∙Set[ ∙A , ∙B ]
∙g : ∙Set[ ∙B , ∙A ]
f = ∙f .proj₁
g = ∙g .proj₁
field
f-g : ∀ b → f (g b) ≡ b
g-f : ∀ a → g (f a) ≡ a
open ∙Iso[_,_]
∙Iso⁻¹ : ∀ {∙A ∙B} → ∙Iso[ ∙A , ∙B ] → ∙Iso[ ∙B , ∙A ]
∙Iso⁻¹ (iso ∙f ∙g f-g g-f) = iso ∙g ∙f g-f f-g
Sing : ∙Set → ∙Set
Sing (A , a) = Singleton A a , a , refl
Sing[_,_] : ∀ ∙A ∙B → ∙Set[ ∙A , ∙B ] → ∙Set[ Sing ∙A , Sing ∙B ]
Sing[ (A , a) , (B , .(f a)) ] (f , refl) = (λ { (x , refl) → f x , refl }) , refl
-- monad
η[_] : ∀ ∙A → ∙Set[ ∙A , Sing ∙A ]
η[ (A , a) ] = (λ x → a , refl) , refl
-- Sing(A) is terminal
η-uniq : ∀ {∙A} {x : ∙A .proj₁} → (∙f : ∙Set[ ∙A , Sing ∙A ]) → (∙f .proj₁) x ≡ (η[ ∙A ] .proj₁) x
η-uniq {A , a} (f , p) = pointed-all-paths
Sing≃1 : ∀ {∙A} → ∙Iso[ Sing ∙A , ∙1 ]
Sing≃1 {∙A@(A , a)} = iso ∙![ Sing ∙A ] ( ((λ _ → a) , refl) ∘ η[ ∙A ]) (λ _ → refl) (λ _ → pointed-all-paths)
μ[_] : ∀ ∙A → ∙Iso[ Sing (Sing ∙A) , Sing ∙A ]
μ[ (A , a) ] = iso ((λ { (.(a , refl) , refl) → a , refl }) , refl)
((λ { (a , refl) → (a , refl) , refl }) , refl)
(λ { (a , refl) → refl})
(λ { ((a , refl) , refl) → refl })
-- check
Sη-μ : ∀ {∙A} → ((Sing[ ∙A , Sing ∙A ] η[ ∙A ] ∘ (μ[ ∙A ] .∙f)) .proj₁) (∙A .proj₂ , refl) ≡ (∙A .proj₂ , refl)
Sη-μ = refl
ηS-μ : ∀ {∙A} → ((Sing[ Sing ∙A , Sing (Sing ∙A) ] η[ Sing ∙A ] ∘ (μ[ Sing ∙A ] .∙f)) .proj₁) ((∙A .proj₂ , refl) , refl) ≡ ((∙A .proj₂ , refl) , refl)
ηS-μ = refl
-- strength
σ×[_,_] : ∀ ∙A ∙B → ∙Set[ Sing ∙A ∙× ∙B , Sing (∙A ∙× ∙B) ]
σ×[ (A , a) , (B , b) ] = (λ { ((a , refl) , _) → (a , b) , refl }) , refl
τ×[_,_] : ∀ ∙A ∙B → ∙Set[ ∙A ∙× Sing ∙B , Sing (∙A ∙× ∙B) ]
τ×[ (A , a) , (B , b) ] = (λ { (_ , (b , refl)) → (a , b) , refl }) , refl
σ+[_,_] : ∀ ∙A ∙B → ∙Set[ Sing ∙A ∙+ ∙B , Sing (∙A ∙+ ∙B) ]
σ+[ (A , a) , (B , b) ] = (λ _ → inj₁ a , refl) , refl
τ+[_,_] : ∀ ∙A ∙B → ∙Set[ ∙A ∙+ Sing ∙B , Sing (∙A ∙+ ∙B) ]
τ+[ (A , a) , (B , b) ] = (λ _ → inj₁ a , refl) , refl
-- comonad
ε[_] : ∀ ∙A → ∙Set[ Sing ∙A , ∙A ]
ε[ (A , a) ] = (λ { (x , refl) → x }) , refl
δ[_] : ∀ ∙A → ∙Iso[ Sing ∙A , Sing (Sing ∙A) ]
δ[ ∙A ] = ∙Iso⁻¹ μ[ ∙A ]
-- check
δ-Sε : ∀ {∙A} → ((δ[ ∙A ] .∙f ∘ Sing[ Sing ∙A , ∙A ] ε[ ∙A ]) .proj₁) (∙A .proj₂ , refl) ≡ (∙A .proj₂ , refl)
δ-Sε = refl
δ-εS : ∀ {∙A} → ((δ[ Sing ∙A ] .∙f ∘ Sing[ Sing (Sing ∙A) , Sing ∙A ] ε[ Sing ∙A ]) .proj₁) ((∙A .proj₂ , refl) , refl) ≡ ((∙A .proj₂ , refl) , refl)
δ-εS = refl
-- costrength
σ'×[_,_] : ∀ ∙A ∙B → ∙Set[ Sing (∙A ∙× ∙B) , Sing ∙A ∙× ∙B ]
σ'×[ (A , a) , (B , b) ] = (λ { (.(a , b) , refl) → (a , refl) , b }) , refl
τ'×[_,_] : ∀ ∙A ∙B → ∙Set[ Sing (∙A ∙× ∙B) , ∙A ∙× Sing ∙B ]
τ'×[ (A , a) , (B , b) ] = (λ { (.(a , b) , refl) → a , (b , refl) }) , refl
σ'+[_,_] : ∀ ∙A ∙B → ∙Set[ Sing (∙A ∙+ ∙B) , Sing ∙A ∙+ ∙B ]
σ'+[ (A , a) , (B , b) ] = (λ _ → inj₁ (a , refl)) , refl
τ'+[_,_] : ∀ ∙A ∙B → ∙Set[ Sing (∙A ∙+ ∙B) , ∙A ∙+ Sing ∙B ]
τ'+[ (A , a) , (B , b) ] = (λ _ → inj₁ a) , refl
-- even better, strong monoidal functor
ν×[_,_] : ∀ ∙A ∙B → ∙Iso[ Sing ∙A ∙× Sing ∙B , Sing (∙A ∙× ∙B) ]
ν×[ (A , a) , (B , b) ] = iso ((λ _ → (a , b) , refl) , refl)
((λ _ → (a , refl) , b , refl) , refl)
(λ { (.(a , b) , refl) → refl })
(λ { ((a , refl) , (b , refl)) → refl })
-- this one is only lax
ν+[_,_] : ∀ ∙A ∙B → ∙Set[ Sing ∙A ∙+ Sing ∙B , Sing (∙A ∙+ ∙B) ]
ν+[ (A , a) , (B , b) ] = (λ _ → inj₁ a , refl) , refl
-- free pointed set
U : ∙Set → Set
U = proj₁
U[_,_] : ∀ ∙A ∙B → ∙Set[ ∙A , ∙B ] → (U ∙A → U ∙B)
U[ _ , _ ] = proj₁
F : Set → ∙Set
F A = (A ⊎ ⊤) , inj₂ tt
F[_,_] : ∀ A B → (A → B) → ∙Set[ F A , F B ]
F[ A , B ] f = (λ { (inj₁ a) → inj₁ (f a) ; (inj₂ tt) → inj₂ tt }) , refl
->adj : ∀ {A ∙B} → (A → U ∙B) → ∙Set[ F A , ∙B ]
->adj f = (λ { (inj₁ a) → f a ; (inj₂ tt) → _ }) , refl
<-adj : ∀ {A ∙B} → ∙Set[ F A , ∙B ] → (A → U ∙B)
<-adj (f , refl) a = f (inj₁ a)
η-adj : ∀ {A} → (A → U (F A))
η-adj = <-adj ∙id
ε-adj : ∀ {∙A} → ∙Set[ F (U ∙A), ∙A ]
ε-adj = ->adj λ x → x
-- maybe monad
T : Set → Set
T A = U (F A)
T-η[_] : ∀ A → (A → T A)
T-η[ A ] = η-adj
T-μ[_] : ∀ A → (T (T A) → T A)
T-μ[ A ] = U[ F (T A) , F A ] ε-adj
-- comaybe comonad
D : ∙Set → ∙Set
D ∙A = F (U ∙A)
D-ε[_] : ∀ ∙A → ∙Set[ D ∙A , ∙A ]
D-ε[ ∙A ] = ε-adj
D-δ[_] : ∀ ∙A → ∙Set[ D ∙A , D (D ∙A) ]
D-δ[ ∙A ] = F[ U ∙A , U (D ∙A) ] η-adj
-- but also
D-η[_] : ∀ ∙A → ∙Set[ ∙A , D ∙A ]
D-η[ ∙A ] = (λ _ → inj₂ tt) , refl
-- D ∙A is not contractible
-- distributive laws?
-- same as ∙Set[ ∙1 , D ∙1 ] so follows D-η
Λ : ∀ {∙A} → ∙Set[ Sing (D ∙A) , D (Sing ∙A) ]
Λ = (λ { (.(inj₂ tt) , refl) → inj₂ tt }) , refl
| 30.799373 | 151 | 0.437557 |
18acd0243d181e49f889437b84f5cab28585fb6d | 152 | agda | Agda | Cubical/HITs/Torus.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 301 | 2018-10-17T18:00:24.000Z | 2022-03-24T02:10:47.000Z | Cubical/HITs/Torus.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 584 | 2018-10-15T09:49:02.000Z | 2022-03-30T12:09:17.000Z | Cubical/HITs/Torus.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 134 | 2018-11-16T06:11:03.000Z | 2022-03-23T16:22:13.000Z | {-# OPTIONS --safe #-}
module Cubical.HITs.Torus where
open import Cubical.HITs.Torus.Base public
-- open import Cubical.HITs.Torus.Properties public
| 21.714286 | 51 | 0.763158 |
dce20c39a2ab73f91a5444012e8b71b23de87047 | 3,215 | agda | Agda | theorems/homotopy/SuspAdjointLoop.agda | timjb/HoTT-Agda | 66f800adef943afdf08c17b8ecfba67340fead5e | [
"MIT"
] | null | null | null | theorems/homotopy/SuspAdjointLoop.agda | timjb/HoTT-Agda | 66f800adef943afdf08c17b8ecfba67340fead5e | [
"MIT"
] | null | null | null | theorems/homotopy/SuspAdjointLoop.agda | timjb/HoTT-Agda | 66f800adef943afdf08c17b8ecfba67340fead5e | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.PtdAdjoint
module homotopy.SuspAdjointLoop {i} where
private
SuspFunctor : PtdFunctor i i
SuspFunctor = record {
obj = ⊙Susp;
arr = ⊙Susp-fmap;
id = ⊙Susp-fmap-idf;
comp = ⊙Susp-fmap-∘}
LoopFunctor : PtdFunctor i i
LoopFunctor = record {
obj = ⊙Ω;
arr = ⊙Ω-fmap;
id = λ _ → ⊙Ω-fmap-idf;
comp = ⊙Ω-fmap-∘}
module _ (X : Ptd i) where
η : de⊙ X → Ω (⊙Susp X)
η x = σloop X x
module E = SuspRec (pt X) (pt X) (idf _)
ε : de⊙ (⊙Susp (⊙Ω X)) → de⊙ X
ε = E.f
⊙η : X ⊙→ ⊙Ω (⊙Susp X)
⊙η = (η , σloop-pt)
⊙ε : ⊙Susp (⊙Ω X) ⊙→ X
⊙ε = (ε , idp)
η-natural : {X Y : Ptd i} (f : X ⊙→ Y)
→ ⊙η Y ⊙∘ f == ⊙Ω-fmap (⊙Susp-fmap f) ⊙∘ ⊙η X
η-natural {X = X} (f , idp) = ⊙λ='
(λ x → ! $
ap-∙ (Susp-fmap f) (merid x) (! (merid (pt X)))
∙ SuspFmap.merid-β f x
∙2 (ap-! (Susp-fmap f) (merid (pt X))
∙ ap ! (SuspFmap.merid-β f (pt X))))
(pt-lemma (Susp-fmap f) (merid (pt X)) (SuspFmap.merid-β f (pt X)))
where
pt-lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y : A} (p : x == y) {q : f x == f y} (α : ap f p == q)
→ !-inv-r q == ap (ap f) (!-inv-r p) ∙ idp
[ _== idp ↓ ! (ap-∙ f p (! p) ∙ α ∙2 (ap-! f p ∙ ap ! α)) ]
pt-lemma f idp idp = idp
ε-natural : {X Y : Ptd i} (f : X ⊙→ Y)
→ ⊙ε Y ⊙∘ ⊙Susp-fmap (⊙Ω-fmap f) == f ⊙∘ ⊙ε X
ε-natural (f , idp) = ⊙λ='
(SuspElim.f idp idp
(λ p → ↓-='-from-square $ vert-degen-square $
ap-∘ (ε _) (Susp-fmap (ap f)) (merid p)
∙ ap (ap (ε _)) (SuspFmap.merid-β (ap f) p)
∙ E.merid-β _ (ap f p)
∙ ap (ap f) (! (E.merid-β _ p))
∙ ∘-ap f (ε _) (merid p)))
idp
εΣ-Ση : (X : Ptd i) → ⊙ε (⊙Susp X) ⊙∘ ⊙Susp-fmap (⊙η X) == ⊙idf _
εΣ-Ση X = ⊙λ='
(SuspElim.f
idp
(merid (pt X))
(λ x → ↓-='-from-square $
(ap-∘ (ε (⊙Susp X)) (Susp-fmap (η X)) (merid x)
∙ ap (ap (ε (⊙Susp X))) (SuspFmap.merid-β (η X) x)
∙ E.merid-β _ (merid x ∙ ! (merid (pt X))))
∙v⊡ square-lemma (merid x) (merid (pt X))
⊡v∙ ! (ap-idf (merid x))))
idp
where
square-lemma : ∀ {i} {A : Type i} {x y z : A}
(p : x == y) (q : z == y)
→ Square idp (p ∙ ! q) p q
square-lemma idp idp = ids
Ωε-ηΩ : (X : Ptd i) → ⊙Ω-fmap (⊙ε X) ⊙∘ ⊙η (⊙Ω X) == ⊙idf _
Ωε-ηΩ X = ⊙λ='
(λ p → ap-∙ (ε X) (merid p) (! (merid idp))
∙ (E.merid-β X p ∙2 (ap-! (ε X) (merid idp) ∙ ap ! (E.merid-β X idp)))
∙ ∙-unit-r _)
(pt-lemma (ε X) (merid idp) (E.merid-β X idp))
where
pt-lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y : A} (p : x == y) {q : f x == f y} (α : ap f p == q)
→ ap (ap f) (!-inv-r p) ∙ idp == idp
[ _== idp ↓ ap-∙ f p (! p) ∙ (α ∙2 (ap-! f p ∙ ap ! α)) ∙ !-inv-r q ]
pt-lemma f idp idp = idp
module Eta = E
adj : CounitUnitAdjoint SuspFunctor LoopFunctor
adj = record {
η = ⊙η;
ε = ⊙ε;
η-natural = η-natural;
ε-natural = ε-natural;
εF-Fη = εΣ-Ση;
Gε-ηG = Ωε-ηΩ}
hadj = counit-unit-to-hom adj
open CounitUnitAdjoint adj public
open HomAdjoint hadj public
| 27.956522 | 79 | 0.459098 |
180929a2edc3c6af1d200720aff6ad5b8ff80b54 | 16,601 | agda | Agda | core/lib/types/Sigma.agda | timjb/HoTT-Agda | 66f800adef943afdf08c17b8ecfba67340fead5e | [
"MIT"
] | null | null | null | core/lib/types/Sigma.agda | timjb/HoTT-Agda | 66f800adef943afdf08c17b8ecfba67340fead5e | [
"MIT"
] | null | null | null | core/lib/types/Sigma.agda | timjb/HoTT-Agda | 66f800adef943afdf08c17b8ecfba67340fead5e | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
module lib.types.Sigma where
-- pointed [Σ]
⊙Σ : ∀ {i j} (X : Ptd i) → (de⊙ X → Ptd j) → Ptd (lmax i j)
⊙Σ ⊙[ A , a₀ ] Y = ⊙[ Σ A (de⊙ ∘ Y) , (a₀ , pt (Y a₀)) ]
-- Cartesian product
_×_ : ∀ {i j} (A : Type i) (B : Type j) → Type (lmax i j)
A × B = Σ A (λ _ → B)
_⊙×_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊙× Y = ⊙Σ X (λ _ → Y)
infixr 80 _×_ _⊙×_
-- XXX Do we really need two versions of [⊙fst]?
⊙fstᵈ : ∀ {i j} {X : Ptd i} (Y : de⊙ X → Ptd j) → ⊙Σ X Y ⊙→ X
⊙fstᵈ Y = fst , idp
⊙fst : ∀ {i j} {X : Ptd i} {Y : Ptd j} → X ⊙× Y ⊙→ X
⊙fst = ⊙fstᵈ _
⊙snd : ∀ {i j} {X : Ptd i} {Y : Ptd j} → X ⊙× Y ⊙→ Y
⊙snd = (snd , idp)
fanout : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
→ (A → B) → (A → C) → (A → B × C)
fanout f g x = f x , g x
⊙fanout-pt : ∀ {i j} {A : Type i} {B : Type j}
{a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁)
→ (a₀ , b₀) == (a₁ , b₁) :> A × B
⊙fanout-pt = pair×=
⊙fanout : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ X ⊙→ Y → X ⊙→ Z → X ⊙→ Y ⊙× Z
⊙fanout (f , fpt) (g , gpt) = fanout f g , ⊙fanout-pt fpt gpt
diag : ∀ {i} {A : Type i} → (A → A × A)
diag a = a , a
⊙diag : ∀ {i} {X : Ptd i} → X ⊙→ X ⊙× X
⊙diag = ((λ x → (x , x)) , idp)
⊙×-inl : ∀ {i j} (X : Ptd i) (Y : Ptd j) → X ⊙→ X ⊙× Y
⊙×-inl X Y = (λ x → x , pt Y) , idp
⊙×-inr : ∀ {i j} (X : Ptd i) (Y : Ptd j) → Y ⊙→ X ⊙× Y
⊙×-inr X Y = (λ y → pt X , y) , idp
⊙fst-fanout : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : X ⊙→ Y) (g : X ⊙→ Z)
→ ⊙fst ⊙∘ ⊙fanout f g == f
⊙fst-fanout (f , idp) (g , idp) = idp
⊙snd-fanout : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : X ⊙→ Y) (g : X ⊙→ Z)
→ ⊙snd ⊙∘ ⊙fanout f g == g
⊙snd-fanout (f , idp) (g , idp) = idp
⊙fanout-pre∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(f : Y ⊙→ Z) (g : Y ⊙→ W) (h : X ⊙→ Y)
→ ⊙fanout f g ⊙∘ h == ⊙fanout (f ⊙∘ h) (g ⊙∘ h)
⊙fanout-pre∘ (f , idp) (g , idp) (h , idp) = idp
module _ {i j} {A : Type i} {B : A → Type j} where
pair : (a : A) (b : B a) → Σ A B
pair a b = (a , b)
-- pair= has already been defined
fst= : {ab a'b' : Σ A B} (p : ab == a'b') → (fst ab == fst a'b')
fst= = ap fst
snd= : {ab a'b' : Σ A B} (p : ab == a'b')
→ (snd ab == snd a'b' [ B ↓ fst= p ])
snd= {._} {_} idp = idp
fst=-β : {a a' : A} (p : a == a')
{b : B a} {b' : B a'} (q : b == b' [ B ↓ p ])
→ fst= (pair= p q) == p
fst=-β idp idp = idp
snd=-β : {a a' : A} (p : a == a')
{b : B a} {b' : B a'} (q : b == b' [ B ↓ p ])
→ snd= (pair= p q) == q [ (λ v → b == b' [ B ↓ v ]) ↓ fst=-β p q ]
snd=-β idp idp = idp
pair=-η : {ab a'b' : Σ A B} (p : ab == a'b')
→ p == pair= (fst= p) (snd= p)
pair=-η {._} {_} idp = idp
pair== : {a a' : A} {p p' : a == a'} (α : p == p')
{b : B a} {b' : B a'} {q : b == b' [ B ↓ p ]} {q' : b == b' [ B ↓ p' ]}
(β : q == q' [ (λ u → b == b' [ B ↓ u ]) ↓ α ])
→ pair= p q == pair= p' q'
pair== idp idp = idp
module _ {i j} {A : Type i} {B : Type j} where
fst×= : {ab a'b' : A × B} (p : ab == a'b') → (fst ab == fst a'b')
fst×= = ap fst
snd×= : {ab a'b' : A × B} (p : ab == a'b')
→ (snd ab == snd a'b')
snd×= = ap snd
fst×=-β : {a a' : A} (p : a == a')
{b b' : B} (q : b == b')
→ fst×= (pair×= p q) == p
fst×=-β idp idp = idp
snd×=-β : {a a' : A} (p : a == a')
{b b' : B} (q : b == b')
→ snd×= (pair×= p q) == q
snd×=-β idp idp = idp
pair×=-η : {ab a'b' : A × B} (p : ab == a'b')
→ p == pair×= (fst×= p) (snd×= p)
pair×=-η {._} {_} idp = idp
module _ {i j} {A : Type i} {B : A → Type j} where
=Σ : (x y : Σ A B) → Type (lmax i j)
=Σ (a , b) (a' , b') = Σ (a == a') (λ p → b == b' [ B ↓ p ])
=Σ-econv : (x y : Σ A B) → (=Σ x y) ≃ (x == y)
=Σ-econv x y =
equiv (λ pq → pair= (fst pq) (snd pq)) (λ p → fst= p , snd= p)
(λ p → ! (pair=-η p))
(λ pq → pair= (fst=-β (fst pq) (snd pq)) (snd=-β (fst pq) (snd pq)))
=Σ-conv : (x y : Σ A B) → (=Σ x y) == (x == y)
=Σ-conv x y = ua (=Σ-econv x y)
Σ= : ∀ {i j} {A A' : Type i} (p : A == A') {B : A → Type j} {B' : A' → Type j}
(q : B == B' [ (λ X → (X → Type j)) ↓ p ]) → Σ A B == Σ A' B'
Σ= idp idp = idp
instance
Σ-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {P : A → Type j}
→ has-level n A → ((x : A) → has-level n (P x))
→ has-level n (Σ A P)
Σ-level {n = ⟨-2⟩} p q = has-level-in ((contr-center p , (contr-center (q (contr-center p)))) , lemma)
where abstract lemma = λ y → pair= (contr-path p _) (from-transp! _ _ (contr-path (q _) _))
Σ-level {n = S n} p q = has-level-in lemma where
abstract
lemma = λ x y → equiv-preserves-level (=Σ-econv x y)
{{Σ-level (has-level-apply p _ _) (λ _ →
equiv-preserves-level ((to-transp-equiv _ _)⁻¹) {{has-level-apply (q _) _ _}})}}
×-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j}
→ (has-level n A → has-level n B → has-level n (A × B))
×-level pA pB = Σ-level pA (λ x → pB)
-- Equivalences in a Σ-type
Σ-fmap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k)
→ (f : A → B) → (Σ A (P ∘ f) → Σ B P)
Σ-fmap-l P f (a , r) = (f a , r)
×-fmap-l : ∀ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁} (B : Type j)
→ (f : A₀ → A₁) → (A₀ × B → A₁ × B)
×-fmap-l B = Σ-fmap-l (λ _ → B)
Σ-isemap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) {h : A → B}
→ is-equiv h → is-equiv (Σ-fmap-l P h)
Σ-isemap-l {A = A} {B = B} P {h} e = is-eq _ g f-g g-f
where f = Σ-fmap-l P h
g : Σ B P → Σ A (P ∘ h)
g (b , s) = (is-equiv.g e b , transport P (! (is-equiv.f-g e b)) s)
f-g : ∀ y → f (g y) == y
f-g (b , s) = pair= (is-equiv.f-g e b) (transp-↓ P (is-equiv.f-g e b) s)
g-f : ∀ x → g (f x) == x
g-f (a , r) =
pair= (is-equiv.g-f e a)
(transport (λ q → transport P (! q) r == r [ P ∘ h ↓ is-equiv.g-f e a ])
(is-equiv.adj e a)
(transp-ap-↓ P h (is-equiv.g-f e a) r))
×-isemap-l : ∀ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁} (B : Type j) {h : A₀ → A₁}
→ is-equiv h → is-equiv (×-fmap-l B h)
×-isemap-l B = Σ-isemap-l (λ _ → B)
Σ-emap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k)
→ (e : A ≃ B) → (Σ A (P ∘ –> e) ≃ Σ B P)
Σ-emap-l P (f , e) = _ , Σ-isemap-l P e
×-emap-l : ∀ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁} (B : Type j)
→ (e : A₀ ≃ A₁) → (A₀ × B ≃ A₁ × B)
×-emap-l B = Σ-emap-l (λ _ → B)
Σ-fmap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
→ (∀ x → B x → C x) → (Σ A B → Σ A C)
Σ-fmap-r h (a , b) = (a , h a b)
×-fmap-r : ∀ {i j₀ j₁} (A : Type i) {B₀ : Type j₀} {B₁ : Type j₁}
→ (h : B₀ → B₁) → (A × B₀ → A × B₁)
×-fmap-r A h = Σ-fmap-r (λ _ → h)
Σ-isemap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
{h : ∀ x → B x → C x} → (∀ x → is-equiv (h x)) → is-equiv (Σ-fmap-r h)
Σ-isemap-r {A = A} {B = B} {C = C} {h} k = is-eq _ g f-g g-f
where f = Σ-fmap-r h
g : Σ A C → Σ A B
g (a , c) = (a , is-equiv.g (k a) c)
f-g : ∀ p → f (g p) == p
f-g (a , c) = pair= idp (is-equiv.f-g (k a) c)
g-f : ∀ p → g (f p) == p
g-f (a , b) = pair= idp (is-equiv.g-f (k a) b)
×-isemap-r : ∀ {i j₀ j₁} (A : Type i) {B₀ : Type j₀} {B₁ : Type j₁}
→ {h : B₀ → B₁} → is-equiv h → is-equiv (×-fmap-r A h)
×-isemap-r A e = Σ-isemap-r (λ _ → e)
Σ-emap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
→ (∀ x → B x ≃ C x) → (Σ A B ≃ Σ A C)
Σ-emap-r k = _ , Σ-isemap-r (λ x → snd (k x))
×-emap-r : ∀ {i j₀ j₁} (A : Type i) {B₀ : Type j₀} {B₁ : Type j₁}
→ (e : B₀ ≃ B₁) → (A × B₀ ≃ A × B₁)
×-emap-r A e = Σ-emap-r (λ _ → e)
hfiber-Σ-fmap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
→ (h : ∀ x → B x → C x) → {a : A} → (c : C a)
→ hfiber (Σ-fmap-r h) (a , c) ≃ hfiber (h a) c
hfiber-Σ-fmap-r h {a} c = equiv to from to-from from-to
where to : hfiber (Σ-fmap-r h) (a , c) → hfiber (h a) c
to ((_ , b) , idp) = b , idp
from : hfiber (h a) c → hfiber (Σ-fmap-r h) (a , c)
from (b , idp) = (a , b) , idp
abstract
to-from : (x : hfiber (h a) c) → to (from x) == x
to-from (b , idp) = idp
from-to : (x : hfiber (Σ-fmap-r h) (a , c)) → from (to x) == x
from-to ((_ , b) , idp) = idp
{-
-- 2016/08/20 favonia: no one is using the following two functions.
-- Two ways of simultaneously applying equivalences in each component.
module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁}
{B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where
Σ-emap : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Σ A₀ B₀ ≃ Σ A₁ B₁
Σ-emap u v = Σ A₀ B₀ ≃⟨ Σ-emap-l _ (u ⁻¹) ⁻¹ ⟩
Σ A₁ (B₀ ∘ <– u) ≃⟨ Σ-emap-r v ⟩
Σ A₁ B₁ ≃∎
Σ-emap' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Σ A₀ B₀ ≃ Σ A₁ B₁
Σ-emap' u v = Σ A₀ B₀ ≃⟨ Σ-emap-r v ⟩
Σ A₀ (B₁ ∘ –> u) ≃⟨ Σ-emap-l _ u ⟩
Σ A₁ B₁ ≃∎
-}
×-fmap : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
→ (h : A₀ → A₁) (k : B₀ → B₁) → (A₀ × B₀ → A₁ × B₁)
×-fmap u v = ×-fmap-r _ v ∘ ×-fmap-l _ u
⊙×-fmap : ∀ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}
→ X ⊙→ X' → Y ⊙→ Y' → X ⊙× Y ⊙→ X' ⊙× Y'
⊙×-fmap (f , fpt) (g , gpt) = ×-fmap f g , pair×= fpt gpt
×-isemap : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
{h : A₀ → A₁} {k : B₀ → B₁} → is-equiv h → is-equiv k → is-equiv (×-fmap h k)
×-isemap eh ek = ×-isemap-r _ ek ∘ise ×-isemap-l _ eh
×-emap : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
→ (u : A₀ ≃ A₁) (v : B₀ ≃ B₁) → (A₀ × B₀ ≃ A₁ × B₁)
×-emap u v = ×-emap-r _ v ∘e ×-emap-l _ u
⊙×-emap : ∀ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}
→ X ⊙≃ X' → Y ⊙≃ Y' → X ⊙× Y ⊙≃ X' ⊙× Y'
⊙×-emap (F , F-ise) (G , G-ise) = ⊙×-fmap F G , ×-isemap F-ise G-ise
-- Implementation of [_∙'_] on Σ
Σ-∙' : ∀ {i j} {A : Type i} {B : A → Type j}
{x y z : A} {p : x == y} {p' : y == z}
{u : B x} {v : B y} {w : B z}
(q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ])
→ (pair= p q ∙' pair= p' r) == pair= (p ∙' p') (q ∙'ᵈ r)
Σ-∙' {p = idp} {p' = idp} q idp = idp
-- Implementation of [_∙_] on Σ
Σ-∙ : ∀ {i j} {A : Type i} {B : A → Type j}
{x y z : A} {p : x == y} {p' : y == z}
{u : B x} {v : B y} {w : B z}
(q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ])
→ (pair= p q ∙ pair= p' r) == pair= (p ∙ p') (q ∙ᵈ r)
Σ-∙ {p = idp} {p' = idp} idp r = idp
-- Implementation of [!] on Σ
Σ-! : ∀ {i j} {A : Type i} {B : A → Type j}
{x y : A} {p : x == y}
{u : B x} {v : B y}
(q : u == v [ B ↓ p ])
→ ! (pair= p q) == pair= (! p) (!ᵈ q)
Σ-! {p = idp} idp = idp
-- Implementation of [_∙'_] on ×
×-∙' : ∀ {i j} {A : Type i} {B : Type j}
{x y z : A} (p : x == y) (p' : y == z)
{u v w : B} (q : u == v) (q' : v == w)
→ (pair×= p q ∙' pair×= p' q') == pair×= (p ∙' p') (q ∙' q')
×-∙' idp idp q idp = idp
-- Implementation of [_∙_] on ×
×-∙ : ∀ {i j} {A : Type i} {B : Type j}
{x y z : A} (p : x == y) (p' : y == z)
{u v w : B} (q : u == v) (q' : v == w)
→ (pair×= p q ∙ pair×= p' q') == pair×= (p ∙ p') (q ∙ q')
×-∙ idp idp idp r = idp
-- Implementation of [!] on ×
×-! : ∀ {i j} {A : Type i} {B : Type j}
{x y : A} (p : x == y) {u v : B} (q : u == v)
→ ! (pair×= p q) == pair×= (! p) (! q)
×-! idp idp = idp
-- Special case of [ap-,]
ap-cst,id : ∀ {i j} {A : Type i} (B : A → Type j)
{a : A} {x y : B a} (p : x == y)
→ ap (λ x → _,_ {B = B} a x) p == pair= idp p
ap-cst,id B idp = idp
-- hfiber fst == B
module _ {i j} {A : Type i} {B : A → Type j} where
private
to : ∀ a → hfiber (fst :> (Σ A B → A)) a → B a
to a ((.a , b) , idp) = b
from : ∀ (a : A) → B a → hfiber (fst :> (Σ A B → A)) a
from a b = (a , b) , idp
to-from : ∀ (a : A) (b : B a) → to a (from a b) == b
to-from a b = idp
from-to : ∀ a b′ → from a (to a b′) == b′
from-to a ((.a , b) , idp) = idp
hfiber-fst : ∀ a → hfiber (fst :> (Σ A B → A)) a ≃ B a
hfiber-fst a = to a , is-eq (to a) (from a) (to-from a) (from-to a)
{- Dependent paths in a Σ-type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
where
↓-Σ-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x r} {s' : C x' r'}
(q : r == r' [ B ↓ p ])
→ s == s' [ uncurry C ↓ pair= p q ]
→ (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ]
↓-Σ-in {p = idp} idp t = pair= idp t
↓-Σ-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x r} {s' : C x' r'}
→ (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ]
→ r == r' [ B ↓ p ]
↓-Σ-fst {p = idp} u = fst= u
↓-Σ-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x r} {s' : C x' r'}
→ (u : (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ])
→ s == s' [ uncurry C ↓ pair= p (↓-Σ-fst u) ]
↓-Σ-snd {p = idp} idp = idp
↓-Σ-β-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x r} {s' : C x' r'}
(q : r == r' [ B ↓ p ])
(t : s == s' [ uncurry C ↓ pair= p q ])
→ ↓-Σ-fst (↓-Σ-in q t) == q
↓-Σ-β-fst {p = idp} idp idp = idp
↓-Σ-β-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x r} {s' : C x' r'}
(q : r == r' [ B ↓ p ])
(t : s == s' [ uncurry C ↓ pair= p q ])
→ ↓-Σ-snd (↓-Σ-in q t) == t
[ (λ q' → s == s' [ uncurry C ↓ pair= p q' ]) ↓ ↓-Σ-β-fst q t ]
↓-Σ-β-snd {p = idp} idp idp = idp
↓-Σ-η : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x r} {s' : C x' r'}
(u : (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ])
→ ↓-Σ-in (↓-Σ-fst u) (↓-Σ-snd u) == u
↓-Σ-η {p = idp} idp = idp
{- Dependent paths in a ×-type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
where
↓-×-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : C x} {s' : C x'}
→ r == r' [ B ↓ p ]
→ s == s' [ C ↓ p ]
→ (r , s) == (r' , s') [ (λ x → B x × C x) ↓ p ]
↓-×-in {p = idp} q t = pair×= q t
{- Dependent paths over a ×-type -}
module _ {i j k} {A : Type i} {B : Type j} (C : A → B → Type k)
where
↓-over-×-in : {x x' : A} {p : x == x'} {y y' : B} {q : y == y'}
{u : C x y} {v : C x' y} {w : C x' y'}
→ u == v [ (λ a → C a y) ↓ p ]
→ v == w [ (λ b → C x' b) ↓ q ]
→ u == w [ uncurry C ↓ pair×= p q ]
↓-over-×-in {p = idp} {q = idp} idp idp = idp
↓-over-×-in' : {x x' : A} {p : x == x'} {y y' : B} {q : y == y'}
{u : C x y} {v : C x y'} {w : C x' y'}
→ u == v [ (λ b → C x b) ↓ q ]
→ v == w [ (λ a → C a y') ↓ p ]
→ u == w [ uncurry C ↓ pair×= p q ]
↓-over-×-in' {p = idp} {q = idp} idp idp = idp
module _ where
-- An orphan lemma.
↓-cst×app-in : ∀ {i j k} {A : Type i}
{B : Type j} {C : A → B → Type k}
{a₁ a₂ : A} (p : a₁ == a₂)
{b₁ b₂ : B} (q : b₁ == b₂)
{c₁ : C a₁ b₁}{c₂ : C a₂ b₂}
→ c₁ == c₂ [ uncurry C ↓ pair×= p q ]
→ (b₁ , c₁) == (b₂ , c₂) [ (λ x → Σ B (C x)) ↓ p ]
↓-cst×app-in idp idp idp = idp
{- pair= and pair×= where one argument is reflexivity -}
pair=-idp-l : ∀ {i j} {A : Type i} {B : A → Type j} (a : A) {b₁ b₂ : B a}
(q : b₁ == b₂) → pair= {B = B} idp q == ap (λ y → (a , y)) q
pair=-idp-l _ idp = idp
pair×=-idp-l : ∀ {i j} {A : Type i} {B : Type j} (a : A) {b₁ b₂ : B}
(q : b₁ == b₂) → pair×= idp q == ap (λ y → (a , y)) q
pair×=-idp-l _ idp = idp
pair×=-idp-r : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂)
(b : B) → pair×= p idp == ap (λ x → (x , b)) p
pair×=-idp-r idp _ = idp
pair×=-split-l : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂)
{b₁ b₂ : B} (q : b₁ == b₂)
→ pair×= p q == ap (λ a → (a , b₁)) p ∙ ap (λ b → (a₂ , b)) q
pair×=-split-l idp idp = idp
pair×=-split-r : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂)
{b₁ b₂ : B} (q : b₁ == b₂)
→ pair×= p q == ap (λ b → (a₁ , b)) q ∙ ap (λ a → (a , b₂)) p
pair×=-split-r idp idp = idp
-- Commutativity of products and derivatives.
module _ {i j} {A : Type i} {B : Type j} where
×-comm : Σ A (λ _ → B) ≃ Σ B (λ _ → A)
×-comm = equiv (λ {(a , b) → (b , a)}) (λ {(b , a) → (a , b)}) (λ _ → idp) (λ _ → idp)
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where
Σ₂-×-comm : Σ (Σ A B) (λ ab → C (fst ab)) ≃ Σ (Σ A C) (λ ac → B (fst ac))
Σ₂-×-comm = Σ-assoc ⁻¹ ∘e Σ-emap-r (λ a → ×-comm) ∘e Σ-assoc
module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where
Σ₁-×-comm : Σ A (λ a → Σ B (λ b → C a b)) ≃ Σ B (λ b → Σ A (λ a → C a b))
Σ₁-×-comm = Σ-assoc ∘e Σ-emap-l _ ×-comm ∘e Σ-assoc ⁻¹
| 34.730126 | 104 | 0.401301 |
df0edac7fe15b682d10f2c81ba01952a57ba4c0a | 65 | agda | Agda | agda/Cham/Inference.agda | riz0id/chemical-abstract-machine | 292023fc36fa67ca4a81cff9a875a325a79b9d6f | [
"BSD-3-Clause"
] | null | null | null | agda/Cham/Inference.agda | riz0id/chemical-abstract-machine | 292023fc36fa67ca4a81cff9a875a325a79b9d6f | [
"BSD-3-Clause"
] | null | null | null | agda/Cham/Inference.agda | riz0id/chemical-abstract-machine | 292023fc36fa67ca4a81cff9a875a325a79b9d6f | [
"BSD-3-Clause"
] | null | null | null | {-# OPTIONS --without-K --safe #-}
module Cham.Inference where
| 13 | 34 | 0.661538 |
4a8ada2856f2a51ee2af65e338f658d07c2f46e9 | 504 | agda | Agda | test/interaction/Issue3526-2.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue3526-2.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue3526-2.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --prop #-}
module Issue3526-2 where
open import Agda.Builtin.Equality
record Truth (P : Prop) : Set where
constructor [_]
field
truth : P
open Truth public
data ⊥' : Prop where
⊥ = Truth ⊥'
¬ : Set → Set
¬ A = A → ⊥
unique : {A : Set} (x y : ¬ A) → x ≡ y
unique x y = refl
⊥-elim : (A : Set) → ⊥ → A
⊥-elim A b = {!!}
open import Agda.Builtin.Bool
open import Agda.Builtin.Unit
set : Bool → Set
set false = ⊥
set true = ⊤
set-elim : ∀ b → set b → Set
set-elim b x = {!!}
| 14 | 38 | 0.575397 |
20b11bf6c3192be0fbbf5256593cad4815ac6fd5 | 852 | agda | Agda | Setoids/Subset.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 4 | 2019-08-08T12:44:19.000Z | 2022-01-28T06:04:15.000Z | Setoids/Subset.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 14 | 2019-01-06T21:11:59.000Z | 2020-04-11T11:03:39.000Z | Setoids/Subset.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 1 | 2021-11-29T13:23:07.000Z | 2021-11-29T13:23:07.000Z | {-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Setoids.Setoids
module Setoids.Subset {a b : _} {A : Set a} (S : Setoid {a} {b} A) where
open Setoid S
open Equivalence eq
subset : {c : _} (pred : A → Set c) → Set (a ⊔ b ⊔ c)
subset pred = ({x y : A} → x ∼ y → pred x → pred y)
subsetSetoid : {c : _} {pred : A → Set c} → (subs : subset pred) → Setoid (Sg A pred)
Setoid._∼_ (subsetSetoid subs) (x , predX) (y , predY) = Setoid._∼_ S x y
Equivalence.reflexive (Setoid.eq (subsetSetoid subs)) {a , b} = reflexive
Equivalence.symmetric (Setoid.eq (subsetSetoid subs)) {a , prA} {b , prB} x = symmetric x
Equivalence.transitive (Setoid.eq (subsetSetoid subs)) {a , prA} {b , prB} {c , prC} x y = transitive x y
| 40.571429 | 105 | 0.659624 |
0e23678764864a5dac08faa2981e0a8ea4ea13ff | 1,468 | agda | Agda | Cubical/Algebra/Polynomials/UnivariateList/Polyn-nPoly.agda | thomas-lamiaux/cubical | 58c0b83bb0fed0dc683f3d29b1709effe51c1689 | [
"MIT"
] | null | null | null | Cubical/Algebra/Polynomials/UnivariateList/Polyn-nPoly.agda | thomas-lamiaux/cubical | 58c0b83bb0fed0dc683f3d29b1709effe51c1689 | [
"MIT"
] | null | null | null | Cubical/Algebra/Polynomials/UnivariateList/Polyn-nPoly.agda | thomas-lamiaux/cubical | 58c0b83bb0fed0dc683f3d29b1709effe51c1689 | [
"MIT"
] | null | null | null | {-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Polynomials.UnivariateList.Polyn-nPoly where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Data.Nat renaming (_+_ to _+n_; _·_ to _·n_)
open import Cubical.Data.Vec
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Polynomials.UnivariatePolyList
open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly0-A
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[Am[X]]-Anm[X]
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.AB-An[X]Bn[X]
open import Cubical.Algebra.Polynomials.UnivariateList.Poly1-1Poly
open CommRingEquivs renaming (compCommRingEquiv to _∘-ecr_ ; invCommRingEquiv to inv-ecr)
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- Definition
Equiv-Polyn-nPoly : (A' : CommRing ℓ) → (n : ℕ) → CommRingEquiv (PolyCommRing A' n) (nUnivariatePolyList A' n)
Equiv-Polyn-nPoly A' zero = CRE-Poly0-A A'
Equiv-Polyn-nPoly A' (suc n) = inv-ecr _ _ (CRE-PolyN∘M-PolyN+M A' 1 n)
∘-ecr (lift-equiv-poly _ _ 1 (Equiv-Polyn-nPoly A' n)
∘-ecr CRE-Poly1-Poly: (nUnivariatePolyList A' n))
| 40.777778 | 110 | 0.709809 |
d0064b1c52d105bbf7325b9022f70204022663bd | 4,568 | agda | Agda | Cubical/Data/FinSet/Properties.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 1 | 2022-03-05T00:29:41.000Z | 2022-03-05T00:29:41.000Z | Cubical/Data/FinSet/Properties.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | null | null | null | Cubical/Data/FinSet/Properties.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.Data.FinSet.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Data.Empty renaming (rec to EmptyRec)
open import Cubical.Data.Sigma
open import Cubical.Data.Fin
open import Cubical.Data.SumFin renaming (Fin to SumFin) hiding (discreteFin)
open import Cubical.Data.FinSet.Base
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
open import Cubical.Relation.Nullary.HLevels
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
B : Type ℓ'
-- infix operator to more conveniently compose equivalences
_⋆_ = compEquiv
infixr 30 _⋆_
-- useful implications
EquivPresIsFinSet : A ≃ B → isFinSet A → isFinSet B
EquivPresIsFinSet e = rec isPropIsFinSet (λ (n , p) → ∣ n , compEquiv (invEquiv e) p ∣)
isFinSetFin : {n : ℕ} → isFinSet (Fin n)
isFinSetFin = ∣ _ , pathToEquiv refl ∣
isFinSetUnit : isFinSet Unit
isFinSetUnit = ∣ 1 , Unit≃Fin1 ∣
isFinSet→Discrete : isFinSet A → Discrete A
isFinSet→Discrete = rec isPropDiscrete (λ (_ , p) → EquivPresDiscrete (invEquiv p) discreteFin)
isContr→isFinSet : isContr A → isFinSet A
isContr→isFinSet h = ∣ 1 , isContr→≃Unit* h ⋆ invEquiv (Unit≃Unit* ) ⋆ Unit≃Fin1 ∣
isDecProp→isFinSet : isProp A → Dec A → isFinSet A
isDecProp→isFinSet h (yes p) = isContr→isFinSet (inhProp→isContr p h)
isDecProp→isFinSet h (no ¬p) = ∣ 0 , uninhabEquiv ¬p ¬Fin0 ∣
{-
Alternative definition of finite sets
A set is finite if it is merely equivalent to `Fin n` for some `n`. We
can translate this to code in two ways: a truncated sigma of a nat and
an equivalence, or a sigma of a nat and a truncated equivalence. We
prove that both formulations are equivalent.
-}
isFinSet' : Type ℓ → Type ℓ
isFinSet' A = Σ[ n ∈ ℕ ] ∥ A ≃ Fin n ∥
FinSet' : (ℓ : Level) → Type (ℓ-suc ℓ)
FinSet' ℓ = TypeWithStr _ isFinSet'
isPropIsFinSet' : isProp (isFinSet' A)
isPropIsFinSet' {A = A} (n , equivn) (m , equivm) =
Σ≡Prop (λ _ → isPropPropTrunc) n≡m
where
Fin-n≃Fin-m : ∥ Fin n ≃ Fin m ∥
Fin-n≃Fin-m = rec
isPropPropTrunc
(rec
(isPropΠ λ _ → isPropPropTrunc)
(λ hm hn → ∣ Fin n ≃⟨ invEquiv hn ⟩ A ≃⟨ hm ⟩ Fin m ■ ∣)
equivm
)
equivn
Fin-n≡Fin-m : ∥ Fin n ≡ Fin m ∥
Fin-n≡Fin-m = rec isPropPropTrunc (∣_∣ ∘ ua) Fin-n≃Fin-m
∥n≡m∥ : ∥ n ≡ m ∥
∥n≡m∥ = rec isPropPropTrunc (∣_∣ ∘ Fin-inj n m) Fin-n≡Fin-m
n≡m : n ≡ m
n≡m = rec (isSetℕ n m) (λ p → p) ∥n≡m∥
-- logical equivalence of two definitions
isFinSet→isFinSet' : isFinSet A → isFinSet' A
isFinSet→isFinSet' ∣ n , equiv ∣ = n , ∣ equiv ∣
isFinSet→isFinSet' (squash p q i) = isPropIsFinSet' (isFinSet→isFinSet' p) (isFinSet→isFinSet' q) i
isFinSet'→isFinSet : isFinSet' A → isFinSet A
isFinSet'→isFinSet (n , ∣ isFinSet-A ∣) = ∣ n , isFinSet-A ∣
isFinSet'→isFinSet (n , squash p q i) = isPropIsFinSet (isFinSet'→isFinSet (n , p)) (isFinSet'→isFinSet (n , q)) i
isFinSet≡isFinSet' : isFinSet A ≡ isFinSet' A
isFinSet≡isFinSet' {A = A} = hPropExt isPropIsFinSet isPropIsFinSet' isFinSet→isFinSet' isFinSet'→isFinSet
FinSet→FinSet' : FinSet ℓ → FinSet' ℓ
FinSet→FinSet' (A , isFinSetA) = A , isFinSet→isFinSet' isFinSetA
FinSet'→FinSet : FinSet' ℓ → FinSet ℓ
FinSet'→FinSet (A , isFinSet'A) = A , isFinSet'→isFinSet isFinSet'A
FinSet≃FinSet' : FinSet ℓ ≃ FinSet' ℓ
FinSet≃FinSet' =
isoToEquiv
(iso FinSet→FinSet' FinSet'→FinSet
(λ _ → Σ≡Prop (λ _ → isPropIsFinSet') refl)
(λ _ → Σ≡Prop (λ _ → isPropIsFinSet) refl))
FinSet≡FinSet' : FinSet ℓ ≡ FinSet' ℓ
FinSet≡FinSet' = ua FinSet≃FinSet'
-- cardinality of finite sets
card : FinSet ℓ → ℕ
card = fst ∘ snd ∘ FinSet→FinSet'
-- definitions to reduce problems about FinSet to SumFin
≃Fin : Type ℓ → Type ℓ
≃Fin A = Σ[ n ∈ ℕ ] A ≃ Fin n
≃SumFin : Type ℓ → Type ℓ
≃SumFin A = Σ[ n ∈ ℕ ] A ≃ SumFin n
≃Fin→SumFin : ≃Fin A → ≃SumFin A
≃Fin→SumFin (n , e) = n , compEquiv e (invEquiv (SumFin≃Fin _))
≃SumFin→Fin : ≃SumFin A → ≃Fin A
≃SumFin→Fin (n , e) = n , compEquiv e (SumFin≃Fin _)
transpFamily :
{A : Type ℓ}{B : A → Type ℓ'}
→ ((n , e) : ≃SumFin A) → (x : A) → B x ≃ B (invEq e (e .fst x))
transpFamily {B = B} (n , e) x = pathToEquiv (λ i → B (retEq e x (~ i)))
| 29.856209 | 114 | 0.676226 |
c5a11a07833c6e96f2bc423c7d62f0a7b8a25a65 | 2,681 | agda | Agda | src/Generic/Property/Eq.agda | iblech/Generic | 380554b20e0991290d1864ddf81f0587ec1647ed | [
"MIT"
] | 30 | 2016-07-19T21:10:54.000Z | 2022-02-05T10:19:38.000Z | src/Generic/Property/Eq.agda | iblech/Generic | 380554b20e0991290d1864ddf81f0587ec1647ed | [
"MIT"
] | 9 | 2017-04-06T18:58:09.000Z | 2022-01-04T15:43:14.000Z | src/Generic/Property/Eq.agda | iblech/Generic | 380554b20e0991290d1864ddf81f0587ec1647ed | [
"MIT"
] | 4 | 2017-07-17T07:23:39.000Z | 2021-01-27T12:57:09.000Z | module Generic.Property.Eq where
open import Generic.Core
SemEq : ∀ {i β} {I : Set i} -> Desc I β -> Set
SemEq (var i) = ⊤
SemEq (π i q C) = ⊥
SemEq (D ⊛ E) = SemEq D × SemEq E
mutual
ExtendEq : ∀ {i β} {I : Set i} -> Desc I β -> Set β
ExtendEq (var i) = ⊤
ExtendEq (π i q C) = ExtendEqᵇ i C q
ExtendEq (D ⊛ E) = SemEq D × ExtendEq E
ExtendEqᵇ : ∀ {ι α β γ q} {I : Set ι} i -> Binder α β γ i q I -> α ≤ℓ β -> Set β
ExtendEqᵇ (arg-info v r) (coerce (A , D)) q = Coerce′ q $ RelEq r A × ∀ {x} -> ExtendEq (D x)
instance
{-# TERMINATING #-} -- Why?
DataEq : ∀ {i β} {I : Set i} {D : Data (Desc I β)} {j}
{{eqD : All ExtendEq (consTypes D)}} -> Eq (μ D j)
DataEq {ι} {β} {I} {D₀} = record { _≟_ = decMu } where
mutual
decSem : ∀ D {{eqD : SemEq D}} -> IsSet (⟦ D ⟧ (μ D₀))
decSem (var i) d₁ d₂ = decMu d₁ d₂
decSem (π i q C) {{()}}
decSem (D ⊛ E) {{eqD , eqE}} p₁ p₂ =
decProd (decSem D {{eqD}}) (decSem E {{eqE}}) p₁ p₂
decExtend : ∀ {j} D {{eqD : ExtendEq D}} -> IsSet (Extend D (μ D₀) j)
decExtend (var i) lrefl lrefl = yes refl
decExtend (π i q C) p₁ p₂ = decExtendᵇ i C q p₁ p₂
decExtend (D ⊛ E) {{eqD , eqE}} p₁ p₂ =
decProd (decSem D {{eqD}}) (decExtend E {{eqE}}) p₁ p₂
decExtendᵇ : ∀ {α γ q j} i (C : Binder α β γ i q I) q {{eqC : ExtendEqᵇ i C q}}
-> IsSet (Extendᵇ i C q (μ D₀) j)
decExtendᵇ (arg-info v r) (coerce (A , D)) q {{eqC}} p₁ p₂ =
split q eqC λ eqA eqD ->
decCoerce′ q (decProd (_≟_ {{EqRelValue {{eqA}}}}) (decExtend (D _) {{eqD}})) p₁ p₂
decAny : ∀ {j} (Ds : List (Desc I β)) {{eqD : All ExtendEq Ds}}
-> ∀ d a b ns -> IsSet (Node D₀ (packData d a b Ds ns) j)
decAny [] d a b tt () ()
decAny (D ∷ []) {{eqD , _}} d a b (_ , ns) e₁ e₂ = decExtend D {{eqD}} e₁ e₂
decAny (D ∷ E ∷ Ds) {{eqD , eqDs}} d a b (_ , ns) s₁ s₂ =
decSum (decExtend D {{eqD}}) (decAny (E ∷ Ds) {{eqDs}} d a b ns) s₁ s₂
decMu : ∀ {j} -> IsSet (μ D₀ j)
decMu (node e₁) (node e₂) = dcong node node-inj $ decAny (consTypes D₀)
(dataName D₀)
(parsTele D₀)
(indsTele D₀)
(consNames D₀)
e₁
e₂
| 46.224138 | 95 | 0.419247 |
23307b665dfaacc542141a98fcc6c08a659a4b7c | 444 | agda | Agda | src/data/lib/prim/Agda/Builtin/String.agda | redfish64/autonomic-agda | c0ae7d20728b15d7da4efff6ffadae6fe4590016 | [
"BSD-3-Clause"
] | null | null | null | src/data/lib/prim/Agda/Builtin/String.agda | redfish64/autonomic-agda | c0ae7d20728b15d7da4efff6ffadae6fe4590016 | [
"BSD-3-Clause"
] | null | null | null | src/data/lib/prim/Agda/Builtin/String.agda | redfish64/autonomic-agda | c0ae7d20728b15d7da4efff6ffadae6fe4590016 | [
"BSD-3-Clause"
] | null | null | null |
module Agda.Builtin.String where
open import Agda.Builtin.Bool
open import Agda.Builtin.List
open import Agda.Builtin.Char
postulate String : Set
{-# BUILTIN STRING String #-}
primitive
primStringToList : String → List Char
primStringFromList : List Char → String
primStringAppend : String → String → String
primStringEquality : String → String → Bool
primShowChar : Char → String
primShowString : String → String
| 24.666667 | 47 | 0.736486 |
18010979c3a76485df33a30c3db24bd093d69ab8 | 1,296 | agda | Agda | Graph/Properties/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Graph/Properties/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Graph/Properties/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | open import Type
module Graph.Properties.Proofs where
open import Data.Either.Proofs
open import Functional
open import Function.Equals
open import Lang.Instance
open import Logic
open import Logic.Propositional
open import Logic.Propositional.Theorems
import Lvl
open import Graph
open import Graph.Properties
open import Relator.Equals.Proofs.Equiv
open import Structure.Setoid.Uniqueness
open import Structure.Relator.Properties
open import Type.Properties.Singleton
module _ {ℓ₁ ℓ₂} {V : Type{ℓ₁}} (_⟶_ : Graph{ℓ₁}{ℓ₂}(V)) where
instance
undirect-undirected : Undirected(undirect(_⟶_))
Undirected.reversable undirect-undirected = intro [∨]-symmetry
Undirected.reverse-involution undirect-undirected = intro (_⊜_.proof swap-involution)
-- [++]-visits : ∀{ae be a₁ b₁ a₂ b₂}{e : ae ⟶ be}{w₁ : Walk(_⟶_) a₁ b₁}{w₂ : Walk(_⟶_) a₂ b₂} → (Visits(_⟶_) e w₁) ∨ (Visits(_⟶_) e w₂) → Visits(_⟶_) e (w₁ ++ w₂)
complete-singular-is-undirected : ⦃ CompleteWithLoops(_⟶_) ⦄ → ⦃ Singular(_⟶_) ⦄ → Undirected(_⟶_)
Undirected.reversable complete-singular-is-undirected = intro(const (completeWithLoops(_⟶_)))
Undirected.reverse-involution complete-singular-is-undirected = intro(singular(_⟶_))
-- traceable-is-connected : ⦃ Traceable(_⟶_) ⦄ → Connected(_⟶_)
| 39.272727 | 165 | 0.73071 |
d06d76352ac6af0df137cfb7d5c6a8f611b19ce4 | 551 | agda | Agda | lib/AocIO.agda | Zalastax/adventofcode2017 | 37956e581dc51bf78008d7dd902bb18d2ee481f6 | [
"MIT"
] | null | null | null | lib/AocIO.agda | Zalastax/adventofcode2017 | 37956e581dc51bf78008d7dd902bb18d2ee481f6 | [
"MIT"
] | null | null | null | lib/AocIO.agda | Zalastax/adventofcode2017 | 37956e581dc51bf78008d7dd902bb18d2ee481f6 | [
"MIT"
] | null | null | null | module AocIO where
open import IO.Primitive public
open import Data.String as String
open import Data.List as List
postulate
getLine : IO Costring
getArgs : IO (List String)
getProgName : IO String
{-# COMPILE GHC getLine = getLine #-}
{-# FOREIGN GHC import qualified Data.Text as Text #-}
{-# FOREIGN GHC import qualified Data.Text.IO as Text #-}
{-# FOREIGN GHC import System.Environment (getArgs, getProgName) #-}
{-# COMPILE GHC getArgs = fmap (map Text.pack) getArgs #-}
{-# COMPILE GHC getProgName = fmap Text.pack getProgName #-}
| 32.411765 | 68 | 0.720508 |
20286fff7f1ef296a6ed47cc3778ce20a1cd2c3c | 1,199 | agda | Agda | Cubical/Data/FinInd.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 301 | 2018-10-17T18:00:24.000Z | 2022-03-24T02:10:47.000Z | Cubical/Data/FinInd.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 584 | 2018-10-15T09:49:02.000Z | 2022-03-30T12:09:17.000Z | Cubical/Data/FinInd.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 134 | 2018-11-16T06:11:03.000Z | 2022-03-23T16:22:13.000Z | {-
Definition of finitely indexed types
A type is finitely indexed if, for some `n`, there merely exists a
surjective function from `Fin n` to it. Note that a type doesn't need
to be a set in order for it to be finitely indexed. For example, the
circle is finitely indexed.
This definition is weaker than `isFinSet`.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinInd where
open import Cubical.Data.Nat
open import Cubical.Data.Fin
open import Cubical.Data.Sigma
open import Cubical.Data.FinSet
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Functions.Surjection
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.HITs.S1
private
variable
ℓ : Level
A : Type ℓ
isFinInd : Type ℓ → Type ℓ
isFinInd A = ∃[ n ∈ ℕ ] Fin n ↠ A
isFinSet→isFinInd : isFinSet A → isFinInd A
isFinSet→isFinInd = PT.rec
squash
λ (n , equiv) →
∣ n , invEq equiv , section→isSurjection (retEq equiv) ∣
isFinInd-S¹ : isFinInd S¹
isFinInd-S¹ = ∣ 1 , f , isSurjection-f ∣
where
f : Fin 1 → S¹
f _ = base
isSurjection-f : isSurjection f
isSurjection-f b = PT.map (λ base≡b → fzero , base≡b) (isConnectedS¹ b)
| 24.469388 | 75 | 0.722269 |
dfd189623a5c0576f77442754a644a79e7b9e8bb | 505 | agda | Agda | agda-stdlib/src/Data/Float.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | agda-stdlib/src/Data/Float.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | agda-stdlib/src/Data/Float.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Floating point numbers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Float where
------------------------------------------------------------------------
-- Re-export base definitions and decidability of equality
open import Data.Float.Base public
open import Data.Float.Properties using (_≈?_; _<?_; _≟_; _==_) public
| 31.5625 | 72 | 0.407921 |
2315c9106f2b405056dca3615b0e628628c78ace | 7,748 | agda | Agda | Cubical/HITs/Susp/Properties.agda | ecavallo/cubical | b1d105aeeab1ba9888394c6a919b99a476390b7b | [
"MIT"
] | null | null | null | Cubical/HITs/Susp/Properties.agda | ecavallo/cubical | b1d105aeeab1ba9888394c6a919b99a476390b7b | [
"MIT"
] | null | null | null | Cubical/HITs/Susp/Properties.agda | ecavallo/cubical | b1d105aeeab1ba9888394c6a919b99a476390b7b | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.HITs.Susp.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Path
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Bool
open import Cubical.Data.Sigma
open import Cubical.HITs.Join
open import Cubical.HITs.Susp.Base
open import Cubical.Homotopy.Loopspace
private
variable
ℓ : Level
open Iso
Susp-iso-joinBool : ∀ {ℓ} {A : Type ℓ} → Iso (Susp A) (join A Bool)
fun Susp-iso-joinBool north = inr true
fun Susp-iso-joinBool south = inr false
fun Susp-iso-joinBool (merid a i) = (sym (push a true) ∙ push a false) i
inv Susp-iso-joinBool (inr true ) = north
inv Susp-iso-joinBool (inr false) = south
inv Susp-iso-joinBool (inl _) = north
inv Susp-iso-joinBool (push a true i) = north
inv Susp-iso-joinBool (push a false i) = merid a i
rightInv Susp-iso-joinBool (inr true ) = refl
rightInv Susp-iso-joinBool (inr false) = refl
rightInv Susp-iso-joinBool (inl a) = sym (push a true)
rightInv Susp-iso-joinBool (push a true i) j = push a true (i ∨ ~ j)
rightInv Susp-iso-joinBool (push a false i) j
= hcomp (λ k → λ { (i = i0) → push a true (~ j)
; (i = i1) → push a false k
; (j = i1) → push a false (i ∧ k) })
(push a true (~ i ∧ ~ j))
leftInv Susp-iso-joinBool north = refl
leftInv Susp-iso-joinBool south = refl
leftInv (Susp-iso-joinBool {A = A}) (merid a i) j
= hcomp (λ k → λ { (i = i0) → transp (λ _ → Susp A) (k ∨ j) north
; (i = i1) → transp (λ _ → Susp A) (k ∨ j) (merid a k)
; (j = i1) → merid a (i ∧ k) })
(transp (λ _ → Susp A) j north)
Susp≃joinBool : ∀ {ℓ} {A : Type ℓ} → Susp A ≃ join A Bool
Susp≃joinBool = isoToEquiv Susp-iso-joinBool
Susp≡joinBool : ∀ {ℓ} {A : Type ℓ} → Susp A ≡ join A Bool
Susp≡joinBool = isoToPath Susp-iso-joinBool
congSuspIso : ∀ {ℓ} {A B : Type ℓ} → Iso A B → Iso (Susp A) (Susp B)
fun (congSuspIso is) = suspFun (fun is)
inv (congSuspIso is) = suspFun (inv is)
rightInv (congSuspIso is) north = refl
rightInv (congSuspIso is) south = refl
rightInv (congSuspIso is) (merid a i) j = merid (rightInv is a j) i
leftInv (congSuspIso is) north = refl
leftInv (congSuspIso is) south = refl
leftInv (congSuspIso is) (merid a i) j = merid (leftInv is a j) i
congSuspEquiv : ∀ {ℓ} {A B : Type ℓ} → A ≃ B → Susp A ≃ Susp B
congSuspEquiv {ℓ} {A} {B} h = isoToEquiv (congSuspIso (equivToIso h))
suspToPropElim : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Susp A → Type ℓ'} (a : A)
→ ((x : Susp A) → isProp (B x))
→ B north
→ (x : Susp A) → B x
suspToPropElim a isProp Bnorth north = Bnorth
suspToPropElim {B = B} a isProp Bnorth south = subst B (merid a) Bnorth
suspToPropElim {B = B} a isProp Bnorth (merid a₁ i) =
isOfHLevel→isOfHLevelDep 1 isProp Bnorth (subst B (merid a) Bnorth) (merid a₁) i
suspToPropElim2 : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Susp A → Susp A → Type ℓ'} (a : A)
→ ((x y : Susp A) → isProp (B x y))
→ B north north
→ (x y : Susp A) → B x y
suspToPropElim2 _ _ Bnorth north north = Bnorth
suspToPropElim2 {B = B} a _ Bnorth north south = subst (B north) (merid a) Bnorth
suspToPropElim2 {B = B} a isprop Bnorth north (merid x i) =
isProp→PathP (λ i → isprop north (merid x i))
Bnorth (subst (B north) (merid a) Bnorth) i
suspToPropElim2 {B = B} a _ Bnorth south north = subst (λ x → B x north) (merid a) Bnorth
suspToPropElim2 {B = B} a _ Bnorth south south = subst (λ x → B x x) (merid a) Bnorth
suspToPropElim2 {B = B} a isprop Bnorth south (merid x i) =
isProp→PathP (λ i → isprop south (merid x i))
(subst (λ x → B x north) (merid a) Bnorth)
(subst (λ x → B x x) (merid a) Bnorth) i
suspToPropElim2 {B = B} a isprop Bnorth (merid x i) north =
isProp→PathP (λ i → isprop (merid x i) north)
Bnorth (subst (λ x → B x north) (merid a) Bnorth) i
suspToPropElim2 {B = B} a isprop Bnorth (merid x i) south =
isProp→PathP (λ i → isprop (merid x i) south)
(subst (B north) (merid a) Bnorth)
(subst (λ x → B x x) (merid a) Bnorth) i
suspToPropElim2 {B = B} a isprop Bnorth (merid x i) (merid y j) =
isSet→SquareP (λ i j → isOfHLevelSuc 1 (isprop _ _))
(isProp→PathP (λ i₁ → isprop north (merid y i₁)) Bnorth
(subst (B north) (merid a) Bnorth))
(isProp→PathP (λ i₁ → isprop south (merid y i₁))
(subst (λ x₁ → B x₁ north) (merid a) Bnorth)
(subst (λ x₁ → B x₁ x₁) (merid a) Bnorth))
(isProp→PathP (λ i₁ → isprop (merid x i₁) north) Bnorth
(subst (λ x₁ → B x₁ north) (merid a) Bnorth))
(isProp→PathP (λ i₁ → isprop (merid x i₁) south)
(subst (B north) (merid a) Bnorth)
(subst (λ x₁ → B x₁ x₁) (merid a) Bnorth)) i j
{- Clever proof:
suspToPropElim2 a isProp Bnorth =
suspToPropElim a (λ x → isOfHLevelΠ 1 λ y → isProp x y)
(suspToPropElim a (λ x → isProp north x) Bnorth)
-}
funSpaceSuspIso : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ Iso (Σ[ x ∈ B ] Σ[ y ∈ B ] (A → x ≡ y)) (Susp A → B)
Iso.fun funSpaceSuspIso (x , y , f) north = x
Iso.fun funSpaceSuspIso (x , y , f) south = y
Iso.fun funSpaceSuspIso (x , y , f) (merid a i) = f a i
Iso.inv funSpaceSuspIso f = (f north) , (f south , (λ x → cong f (merid x)))
Iso.rightInv funSpaceSuspIso f = funExt λ {north → refl
; south → refl
; (merid a i) → refl}
Iso.leftInv funSpaceSuspIso _ = refl
toSusp : (A : Pointed ℓ) → typ A → typ (Ω (Susp∙ (typ A)))
toSusp A x = merid x ∙ merid (pt A) ⁻¹
toSuspPointed : (A : Pointed ℓ) → A →∙ Ω (Susp∙ (typ A))
fst (toSuspPointed A) = toSusp A
snd (toSuspPointed A) = rCancel (merid (pt A))
module _ {ℓ ℓ' : Level} {A : Pointed ℓ} {B : Pointed ℓ'} where
fromSusp→toΩ : Susp∙ (typ A) →∙ B → (A →∙ Ω B)
fst (fromSusp→toΩ f) x = sym (snd f) ∙∙ cong (fst f) (toSusp A x) ∙∙ snd f
snd (fromSusp→toΩ f) =
cong (sym (snd f) ∙∙_∙∙ (snd f))
(cong (cong (fst f))
(rCancel (merid (pt A))))
∙ ∙∙lCancel (snd f)
toΩ→fromSusp : A →∙ Ω B → Susp∙ (typ A) →∙ B
fst (toΩ→fromSusp f) north = pt B
fst (toΩ→fromSusp f) south = pt B
fst (toΩ→fromSusp f) (merid a i) = fst f a i
snd (toΩ→fromSusp f) = refl
ΩSuspAdjointIso : Iso (A →∙ Ω B) (Susp∙ (typ A) →∙ B)
fun ΩSuspAdjointIso = toΩ→fromSusp
inv ΩSuspAdjointIso = fromSusp→toΩ
rightInv ΩSuspAdjointIso f =
ΣPathP (funExt
(λ { north → sym (snd f)
; south → sym (snd f) ∙ cong (fst f) (merid (pt A))
; (merid a i) j →
hcomp (λ k → λ { (i = i0) → snd f (~ j ∧ k)
; (i = i1) → compPath-filler'
(sym (snd f))
(cong (fst f) (merid (pt A))) k j
; (j = i1) → fst f (merid a i)})
(fst f (compPath-filler (merid a) (sym (merid (pt A))) (~ j) i))})
, λ i j → snd f (~ i ∨ j))
leftInv ΩSuspAdjointIso f =
→∙Homogeneous≡ (isHomogeneousPath _ _)
(funExt λ x → sym (rUnit _)
∙ cong-∙ (fst (toΩ→fromSusp f)) (merid x) (sym (merid (pt A)))
∙ cong (fst f x ∙_) (cong sym (snd f))
∙ sym (rUnit _))
IsoΩFunSuspFun : Iso (typ (Ω (A →∙ B ∙))) (Susp∙ (typ A) →∙ B)
IsoΩFunSuspFun = compIso (ΩfunExtIso A B) ΩSuspAdjointIso
| 43.774011 | 89 | 0.57731 |
dfbfd8baed9bb721d0efca3774bcc792ba24a612 | 4,564 | agda | Agda | Cubical/Foundations/SIP.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | 1 | 2021-10-31T17:32:49.000Z | 2021-10-31T17:32:49.000Z | Cubical/Foundations/SIP.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | Cubical/Foundations/SIP.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | {-
In this file we apply the cubical machinery to Martin Hötzel-Escardó's
structure identity principle:
https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.SIP where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence renaming (ua-pathToEquiv to ua-pathToEquiv')
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Foundations.Structure public
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ : Level
S : Type ℓ₁ → Type ℓ₂
-- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be
-- a proposition. Indeed this type should correspond to the ways s and t can be identified
-- as S-structures. This we call a standard notion of structure or SNS.
-- We will use a different definition, but the two definitions are interchangeable.
SNS : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃) → Type (ℓ-max (ℓ-max (ℓ-suc ℓ₁) ℓ₂) ℓ₃)
SNS {ℓ₁} S ι = ∀ {X : Type ℓ₁} (s t : S X) → ι (X , s) (X , t) (idEquiv X) ≃ (s ≡ t)
-- We introduce the notation for structure preserving equivalences a
-- bit differently, but this definition doesn't actually change from
-- Escardó's notes.
_≃[_]_ : (A : TypeWithStr ℓ₁ S) (ι : StrEquiv S ℓ₂) (B : TypeWithStr ℓ₁ S) → Type (ℓ-max ℓ₁ ℓ₂)
A ≃[ ι ] B = Σ[ e ∈ typ A ≃ typ B ] (ι A B e)
-- The following PathP version of SNS is a bit easier to work with
-- for the proof of the SIP
UnivalentStr : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃) → Type (ℓ-max (ℓ-max (ℓ-suc ℓ₁) ℓ₂) ℓ₃)
UnivalentStr {ℓ₁} S ι =
{A B : TypeWithStr ℓ₁ S} (e : typ A ≃ typ B)
→ ι A B e ≃ PathP (λ i → S (ua e i)) (str A) (str B)
-- A quick sanity-check that our definition is interchangeable with
-- Escardó's. The direction SNS→UnivalentStr corresponds more or less
-- to a dependent EquivJ formulation of Escardó's homomorphism-lemma.
UnivalentStr→SNS : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃)
→ UnivalentStr S ι → SNS S ι
UnivalentStr→SNS S ι θ {X = X} s t =
ι (X , s) (X , t) (idEquiv X)
≃⟨ θ (idEquiv X) ⟩
PathP (λ i → S (ua (idEquiv X) i)) s t
≃⟨ pathToEquiv (λ j → PathP (λ i → S (uaIdEquiv {A = X} j i)) s t) ⟩
s ≡ t
■
SNS→UnivalentStr : (ι : StrEquiv S ℓ₃) → SNS S ι → UnivalentStr S ι
SNS→UnivalentStr {S = S} ι θ {A = A} {B = B} e = EquivJ P C e (str A) (str B)
where
Y = typ B
P : (X : Type _) → X ≃ Y → Type _
P X e' = (s : S X) (t : S Y) → ι (X , s) (Y , t) e' ≃ PathP (λ i → S (ua e' i)) s t
C : (s t : S Y) → ι (Y , s) (Y , t) (idEquiv Y) ≃ PathP (λ i → S (ua (idEquiv Y) i)) s t
C s t =
ι (Y , s) (Y , t) (idEquiv Y)
≃⟨ θ s t ⟩
s ≡ t
≃⟨ pathToEquiv (λ j → PathP (λ i → S (uaIdEquiv {A = Y} (~ j) i)) s t) ⟩
PathP (λ i → S (ua (idEquiv Y) i)) s t
■
TransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S) → Type (ℓ-max (ℓ-suc ℓ) ℓ₁)
TransportStr {ℓ} {S = S} α =
{X Y : Type ℓ} (e : X ≃ Y) (s : S X) → equivFun (α e) s ≡ subst S (ua e) s
TransportStr→UnivalentStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ TransportStr α → UnivalentStr S (EquivAction→StrEquiv α)
TransportStr→UnivalentStr {S = S} α τ {X , s} {Y , t} e =
equivFun (α e) s ≡ t
≃⟨ pathToEquiv (cong (_≡ t) (τ e s)) ⟩
subst S (ua e) s ≡ t
≃⟨ invEquiv (PathP≃Path _ _ _) ⟩
PathP (λ i → S (ua e i)) s t
■
UnivalentStr→TransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ UnivalentStr S (EquivAction→StrEquiv α) → TransportStr α
UnivalentStr→TransportStr {S = S} α θ e s =
invEq (θ e) (transport-filler (cong S (ua e)) s)
invTransportStr : {S : Type ℓ → Type ℓ₂} (α : EquivAction S) (τ : TransportStr α)
{X Y : Type ℓ} (e : X ≃ Y) (t : S Y) → invEq (α e) t ≡ subst⁻ S (ua e) t
invTransportStr {S = S} α τ e t =
sym (transport⁻Transport (cong S (ua e)) (invEq (α e) t))
∙∙ sym (cong (subst⁻ S (ua e)) (τ e (invEq (α e) t)))
∙∙ cong (subst⁻ S (ua e)) (secEq (α e) t)
--- We can now define an invertible function
---
--- sip : A ≃[ ι ] B → A ≡ B
module _ {S : Type ℓ₁ → Type ℓ₂} {ι : StrEquiv S ℓ₃}
(θ : UnivalentStr S ι) (A B : TypeWithStr ℓ₁ S)
where
sip : A ≃[ ι ] B → A ≡ B
sip (e , p) i = ua e i , θ e .fst p i
SIP : A ≃[ ι ] B ≃ (A ≡ B)
SIP =
sip , isoToIsEquiv (compIso (Σ-cong-iso (invIso univalenceIso) (equivToIso ∘ θ)) ΣPathIsoPathΣ)
sip⁻ : A ≡ B → A ≃[ ι ] B
sip⁻ = invEq SIP
| 36.512 | 99 | 0.610649 |
cb074778afa666bde0170e5a17471343ac14cb2b | 3,270 | agda | Agda | src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda | banacorn/agda | 2a07bfdf2c1c4ae87f428809af0887aceb6632c0 | [
"MIT"
] | null | null | null | src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda | banacorn/agda | 2a07bfdf2c1c4ae87f428809af0887aceb6632c0 | [
"MIT"
] | null | null | null | src/data/lib/prim/Agda/Builtin/Cubical/HCompU.agda | banacorn/agda | 2a07bfdf2c1c4ae87f428809af0887aceb6632c0 | [
"MIT"
] | 1 | 2021-04-18T13:34:07.000Z | 2021-04-18T13:34:07.000Z | {-# OPTIONS --erased-cubical --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Cubical.HCompU where
open import Agda.Primitive
open import Agda.Builtin.Sigma
open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_;
primHComp to hcomp; primTransp to transp; primComp to comp;
itIsOne to 1=1)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to outS; inc to inS)
module Helpers where
-- Homogeneous filling
hfill : ∀ {ℓ} {A : Set ℓ} {φ : I}
(u : ∀ i → Partial φ A)
(u0 : A [ φ ↦ u i0 ]) (i : I) → A
hfill {φ = φ} u u0 i =
hcomp (λ j → \ { (φ = i1) → u (i ∧ j) 1=1
; (i = i0) → outS u0 })
(outS u0)
-- Heterogeneous filling defined using comp
fill : ∀ {ℓ : I → Level} (A : ∀ i → Set (ℓ i)) {φ : I}
(u : ∀ i → Partial φ (A i))
(u0 : A i0 [ φ ↦ u i0 ]) →
∀ i → A i
fill A {φ = φ} u u0 i =
comp (λ j → A (i ∧ j))
(λ j → \ { (φ = i1) → u (i ∧ j) 1=1
; (i = i0) → outS u0 })
(outS {φ = φ} u0)
module _ {ℓ} {A : Set ℓ} where
refl : {x : A} → x ≡ x
refl {x = x} = λ _ → x
sym : {x y : A} → x ≡ y → y ≡ x
sym p = λ i → p (~ i)
cong : ∀ {ℓ'} {B : A → Set ℓ'} {x y : A}
(f : (a : A) → B a) (p : x ≡ y)
→ PathP (λ i → B (p i)) (f x) (f y)
cong f p = λ i → f (p i)
isContr : ∀ {ℓ} → Set ℓ → Set ℓ
isContr A = Σ A \ x → (∀ y → x ≡ y)
fiber : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) (y : B) → Set (ℓ ⊔ ℓ')
fiber {A = A} f y = Σ A \ x → f x ≡ y
open Helpers
primitive
prim^glueU : {la : Level} {φ : I} {T : I → Partial φ (Set la)}
{A : Set la [ φ ↦ T i0 ]} →
PartialP φ (T i1) → outS A → hcomp T (outS A)
prim^unglueU : {la : Level} {φ : I} {T : I → Partial φ (Set la)}
{A : Set la [ φ ↦ T i0 ]} →
hcomp T (outS A) → outS A
-- Needed for transp.
primFaceForall : (I → I) → I
transpProof : ∀ {l} → (e : I → Set l) → (φ : I) → (a : Partial φ (e i0)) → (b : e i1 [ φ ↦ (\ o → transp (\ i → e i) i0 (a o)) ] ) → fiber (transp (\ i → e i) i0) (outS b)
transpProof e φ a b = f , \ j → comp (\ i → e i) (\ i →
\ { (φ = i1) → transp (\ j → e (j ∧ i)) (~ i) (a 1=1)
; (j = i0) → transp (\ j → e (j ∧ i)) (~ i) f
; (j = i1) → g (~ i) })
f
where
b' = outS {u = (\ o → transp (\ i → e i) i0 (a o))} b
g : (k : I) → e (~ k)
g k = fill (\ i → e (~ i)) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ ~ i)) i (a 1=1)
; (φ = i0) → transp (\ j → e (~ j ∨ ~ i)) (~ i) b' }) (inS b') k
f = comp (\ i → e (~ i)) (\ i → \ { (φ = i1) → transp (\ j → e (j ∧ ~ i)) i (a 1=1); (φ = i0) → transp (\ j → e (~ j ∨ ~ i)) (~ i) b' }) b'
{-# BUILTIN TRANSPPROOF transpProof #-}
| 40.875 | 171 | 0.384404 |
23434b998cc8a96bcc2e3df591683718c4a39cd8 | 3,392 | agda | Agda | Cubical/HITs/Colimit/Examples.agda | Rotsor/cubical | d55cd4834ca1f171f58b4a0c46b804ea6d18191f | [
"MIT"
] | null | null | null | Cubical/HITs/Colimit/Examples.agda | Rotsor/cubical | d55cd4834ca1f171f58b4a0c46b804ea6d18191f | [
"MIT"
] | null | null | null | Cubical/HITs/Colimit/Examples.agda | Rotsor/cubical | d55cd4834ca1f171f58b4a0c46b804ea6d18191f | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Colimit.Examples where
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.SumFin
open import Cubical.Data.Graph
open import Cubical.HITs.Colimit.Base
open import Cubical.HITs.Pushout
-- Pushouts are colimits over the graph ⇐⇒
module _ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} where
PushoutDiag : (A → B) → (A → C) → Diag (ℓ-max ℓ (ℓ-max ℓ' ℓ'')) ⇐⇒
(PushoutDiag f g) $ fzero = Lift {j = ℓ-max ℓ ℓ'' } B
(PushoutDiag f g) $ fsuc fzero = Lift {j = ℓ-max ℓ' ℓ'' } A
(PushoutDiag f g) $ fsuc (fsuc fzero) = Lift {j = ℓ-max ℓ ℓ' } C
_<$>_ (PushoutDiag f g) {fsuc fzero} {fzero} tt (lift a) = lift (f a)
_<$>_ (PushoutDiag f g) {fsuc fzero} {fsuc (fsuc fzero)} tt (lift a) = lift (g a)
module _ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {f : A → B} {g : A → C} where
PushoutCocone : Cocone _ (PushoutDiag f g) (Pushout f g)
leg PushoutCocone fzero (lift b) = inl b
leg PushoutCocone (fsuc fzero) (lift a) = inr (g a)
leg PushoutCocone (fsuc (fsuc fzero)) (lift c) = inr c
com PushoutCocone {fsuc fzero} {fzero} tt i (lift a) = push a i
com PushoutCocone {fsuc fzero} {fsuc (fsuc fzero)} tt i (lift a) = inr (g a)
private
module _ ℓq (Y : Type ℓq) where
fwd : (Pushout f g → Y) → Cocone ℓq (PushoutDiag f g) Y
fwd = postcomp PushoutCocone
module _ (C : Cocone ℓq (PushoutDiag f g) Y) where
coml : ∀ a → leg C fzero (lift (f a)) ≡ leg C (fsuc fzero) (lift a)
comr : ∀ a → leg C (fsuc (fsuc fzero)) (lift (g a)) ≡ leg C (fsuc fzero) (lift a)
coml a i = com C {j = fsuc fzero} {k = fzero} tt i (lift a)
comr a i = com C {j = fsuc fzero} {k = fsuc (fsuc fzero)} tt i (lift a)
bwd : Cocone ℓq (PushoutDiag f g) Y → (Pushout f g → Y)
bwd C (inl b) = leg C fzero (lift b)
bwd C (inr c) = leg C (fsuc (fsuc fzero)) (lift c)
bwd C (push a i) = (coml C a ∙ sym (comr C a)) i
bwd-fwd : ∀ F → bwd (fwd F) ≡ F
bwd-fwd F i (inl b) = F (inl b)
bwd-fwd F i (inr c) = F (inr c)
bwd-fwd F i (push a j) = compPath-filler (coml (fwd F) a) (sym (comr (fwd F) a)) (~ i) j
fwd-bwd : ∀ C → fwd (bwd C) ≡ C
leg (fwd-bwd C i) fzero (lift b) = leg C fzero (lift b)
leg (fwd-bwd C i) (fsuc fzero) (lift a) = comr C a i
leg (fwd-bwd C i) (fsuc (fsuc fzero)) (lift c) = leg C (fsuc (fsuc fzero)) (lift c)
com (fwd-bwd C i) {fsuc fzero} {fzero} tt j (lift a) -- coml (fwd-bwd C i) = ...
= compPath-filler (coml C a) (sym (comr C a)) (~ i) j
com (fwd-bwd C i) {fsuc fzero} {fsuc (fsuc fzero)} tt j (lift a) -- comr (fwd-bwd C i) = ...
= comr C a (i ∧ j)
eqv : isEquiv {A = (Pushout f g → Y)} {B = Cocone ℓq (PushoutDiag f g) Y} (postcomp PushoutCocone)
eqv = isoToIsEquiv (iso fwd bwd fwd-bwd bwd-fwd)
isColimPushout : isColimit (PushoutDiag f g) (Pushout f g)
cone isColimPushout = PushoutCocone
univ isColimPushout = eqv
colim≃Pushout : colim (PushoutDiag f g) ≃ Pushout f g
colim≃Pushout = uniqColimit colimIsColimit isColimPushout
| 43.487179 | 104 | 0.576651 |
d04aa38ec38ea816b2c3262847d3827b023f0fa5 | 2,559 | agda | Agda | examples/outdated-and-incorrect/cbs/Path.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/cbs/Path.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/cbs/Path.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Path where
open import Basics hiding (_==_)
open import Proc
import Graph
private open module G = Graph Nat
data Node : Set where
node : Nat -> Node
stop : Node
_==_ : Node -> Node -> Bool
stop == stop = true
node zero == node zero = true
node (suc n) == node (suc m) = node n == node m
_ == _ = false
data U : Set where
int : U
ext : U
data Name : Set where
fwd-edge : Nat -> Nat -> Name
bwd-edge : Nat -> Node -> Name
start : Nat -> Name
finish : Nat -> Name
N : U -> Set
N int = Name
N ext = False
data Msg : Set where
forward : Node -> Node -> Msg
backward : Node -> Msg
T : U -> Set
T int = Msg
T ext = Node
private
module Impl where
private module P = ProcDef U T N
open P hiding (_!_)
P = Proc int
infixr 40 _!_
_!_ : Msg -> P -> P
m ! p = P._!_ (lift m) p
fwd : Nat -> Nat -> Msg
fwd from to = forward (node from) (node to)
fwd-runner : Nat -> Nat -> P
fwd-runner from to = > react
where
react : Msg -> P
react (forward from' to') =
if to' == node from
then fwd from to ! def (bwd-edge from from')
else def (fwd-edge from to)
react (backward _) = o
bwd-runner : Nat -> Node -> P
bwd-runner from w = > react
where
react : Msg -> P
react (backward n) =
if n == w then o
else if n == node from
then backward w ! o
else def (bwd-edge from w)
react (forward _ _) = def (bwd-edge from w)
pitcher : Nat -> P
pitcher n = forward stop (node n) ! o
batter : Nat -> P
batter n = > react
where
react : Msg -> P
react (forward from to) =
if to == node n
then backward from ! o
else def (start n)
react _ = def (start n)
env : Env
env int (fwd-edge from to) = fwd-runner from to
env int (bwd-edge from w) = bwd-runner from w
env int (start n) = batter n
env int (finish n) = pitcher n
env ext ()
edges : Graph -> P
edges [] = o
edges (edge x y :: G) = def (fwd-edge x y) || edges G
φ : Tran ext int
φ = record { upV = up; downV = down }
where
down : Node -> Lift Msg
down x = lift (backward x)
up : Msg -> Lift Node
up (forward _ _) = bot
up (backward x) = lift x
main : Graph -> Nat -> Nat -> Proc ext
main G x y = φ /| def (finish y) || def (start x) || edges G
open Impl public
param : Param
param = record
{ U = U
; T = T
; Name = N
; env = env
}
| 20.804878 | 62 | 0.527941 |
dce10ae403b7b2e782498e896631ca4a4111ae49 | 489 | agda | Agda | test/interaction/Issue3095-fail.agda | alex-mckenna/agda | 78b62cd24bbd570271a7153e44ad280e52ef3e29 | [
"BSD-3-Clause"
] | 1 | 2016-03-17T01:45:59.000Z | 2016-03-17T01:45:59.000Z | test/interaction/Issue3095-fail.agda | andersk/agda | 56928ff709dcb931cb9a48c4790e5ed3739e3032 | [
"BSD-3-Clause"
] | null | null | null | test/interaction/Issue3095-fail.agda | andersk/agda | 56928ff709dcb931cb9a48c4790e5ed3739e3032 | [
"BSD-3-Clause"
] | 1 | 2019-03-05T20:02:38.000Z | 2019-03-05T20:02:38.000Z | -- Andreas, 2018-05-28, issue #3095, fail on attempt to make hidden parent variable visible
data Nat : Set where
suc : {n : Nat} → Nat
data IsSuc : Nat → Set where
isSuc : ∀{n} → IsSuc (suc {n})
test : ∀{m} → IsSuc m → Set
test p = aux p
where
aux : ∀{n} → IsSuc n → Set
aux isSuc = {!.m!} -- Split on .m here
-- Context:
-- p : IsSuc .m
-- .m : Nat
-- .n : Nat
-- Expected error:
-- Cannot split on module parameter .m
-- when checking that the expression ? has type Set
| 21.26087 | 91 | 0.603272 |
d0ee96ab8ae2f32f73f6a4a56b76e66e06c50392 | 1,159 | agda | Agda | src/Categories/Category/Instance/StrictGroupoids.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | src/Categories/Category/Instance/StrictGroupoids.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | null | null | null | src/Categories/Category/Instance/StrictGroupoids.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.StrictGroupoids where
-- The 'strict' category of groupoids.
-- The difference here is that _≈_ is not |NaturalIsomorphism| but |_≡F_|
open import Level
open import Relation.Binary.PropositionalEquality using (refl)
open import Categories.Category using (Category)
open import Categories.Category.Groupoid using (Groupoid)
open import Categories.Category.Instance.Groupoids using (F-resp-⁻¹)
open import Categories.Functor using (Functor; id; _∘F_)
open import Categories.Functor.Equivalence
private
variable
o ℓ e : Level
open Groupoid using (category)
Groupoids : ∀ o ℓ e → Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e)
Groupoids o ℓ e = record
{ Obj = Groupoid o ℓ e
; _⇒_ = λ G H → Functor (category G) (category H)
; _≈_ = _≡F_
; id = id
; _∘_ = _∘F_
; assoc = λ {_ _ _ _ F G H} → ≡F-assoc {F = F} {G} {H}
; sym-assoc = λ {_ _ _ _ F G H} → ≡F-sym-assoc {F = F} {G} {H}
; identityˡ = ≡F-identityˡ
; identityʳ = ≡F-identityʳ
; identity² = ≡F-identity²
; equiv = ≡F-equiv
; ∘-resp-≈ = ∘F-resp-≡F
}
| 31.324324 | 73 | 0.63503 |
4ac1eae2d07c0eab6556c1eac17ff2596960da2b | 2,515 | agda | Agda | LC/Reduction.agda | banacorn/bidirectional | 0c9a6e79c23192b28ddb07315b200a94ee900ca6 | [
"MIT"
] | 2 | 2020-08-25T07:34:40.000Z | 2020-08-25T14:05:01.000Z | LC/Reduction.agda | banacorn/bidirectional | 0c9a6e79c23192b28ddb07315b200a94ee900ca6 | [
"MIT"
] | null | null | null | LC/Reduction.agda | banacorn/bidirectional | 0c9a6e79c23192b28ddb07315b200a94ee900ca6 | [
"MIT"
] | null | null | null | module LC.Reduction where
open import LC.Base
open import LC.Subst
open import Data.Nat
open import Data.Nat.Properties
open import Relation.Nullary
-- β-reduction
infix 3 _β→_
data _β→_ : Term → Term → Set where
β-ƛ-∙ : ∀ {M N} → ((ƛ M) ∙ N) β→ (M [ N ])
β-ƛ : ∀ {M N} → M β→ N → ƛ M β→ ƛ N
β-∙-l : ∀ {L M N} → M β→ N → M ∙ L β→ N ∙ L
β-∙-r : ∀ {L M N} → M β→ N → L ∙ M β→ L ∙ N
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
infix 2 _β→*_
_β→*_ : Term → Term → Set
_β→*_ = Star _β→_
{-# DISPLAY Star _β→_ = _β→*_ #-}
open import Relation.Binary.PropositionalEquality hiding ([_]; preorder)
≡⇒β→* : ∀ {M N} → M ≡ N → M β→* N
≡⇒β→* refl = ε
cong-var : ∀ {x y} → x ≡ y → var x β→* var y
cong-var {x} {y} refl = ε
cong-ƛ : {M N : Term} → M β→* N → ƛ M β→* ƛ N
cong-ƛ = gmap _ β-ƛ
cong-∙-l : {L M N : Term} → M β→* N → M ∙ L β→* N ∙ L
cong-∙-l = gmap _ β-∙-l
cong-∙-r : {L M N : Term} → M β→* N → L ∙ M β→* L ∙ N
cong-∙-r = gmap _ β-∙-r
cong-∙ : {M M' N N' : Term} → M β→* M' → N β→* N' → M ∙ N β→* M' ∙ N'
cong-∙ M→M' N→N' = (cong-∙-l M→M') ◅◅ (cong-∙-r N→N')
open import LC.Subst.Term
cong-lift : {n i : ℕ} {M N : Term} → M β→ N → lift n i M β→* lift n i N
cong-lift (β-ƛ M→N) = cong-ƛ (cong-lift M→N)
cong-lift (β-ƛ-∙ {M} {N}) = β-ƛ-∙ ◅ ≡⇒β→* (lemma M N)
cong-lift (β-∙-l M→N) = cong-∙-l (cong-lift M→N)
cong-lift (β-∙-r M→N) = cong-∙-r (cong-lift M→N)
cong-[]-r : ∀ L {M N i} → M β→ N → L [ M / i ] β→* L [ N / i ]
cong-[]-r (var x) {M} {N} {i} M→N with match x i
... | Under _ = ε
... | Exact _ = cong-lift M→N
... | Above _ _ = ε
cong-[]-r (ƛ L) M→N = cong-ƛ (cong-[]-r L M→N)
cong-[]-r (K ∙ L) M→N = cong-∙ (cong-[]-r K M→N) (cong-[]-r L M→N)
cong-[]-l : ∀ {M N L i} → M β→ N → M [ L / i ] β→* N [ L / i ]
cong-[]-l {ƛ M} (β-ƛ M→N) = cong-ƛ (cong-[]-l M→N)
cong-[]-l {.(ƛ K) ∙ M} {L = L} (β-ƛ-∙ {K}) = β-ƛ-∙ ◅ ≡⇒β→* (subst-lemma K M L)
cong-[]-l {K ∙ M} (β-∙-l M→N) = cong-∙-l (cong-[]-l M→N)
cong-[]-l {K ∙ M} (β-∙-r M→N) = cong-∙-r (cong-[]-l M→N)
cong-[] : {M M' N N' : Term} → M β→* M' → N β→* N' → M [ N ] β→* M' [ N' ]
cong-[] {M} ε ε = ε
cong-[] {M} {N = L} {N'} ε (_◅_ {j = N} L→N N→N') = M[L]→M[N] ◅◅ M[N]→M[N']
where
M[L]→M[N] : M [ L ] β→* M [ N ]
M[L]→M[N] = cong-[]-r M L→N
M[N]→M[N'] : M [ N ] β→* M [ N' ]
M[N]→M[N'] = cong-[] {M} ε N→N'
cong-[] {M} (K→M ◅ M→M') N→N' = cong-[]-l K→M ◅◅ cong-[] M→M' N→N'
| 29.588235 | 79 | 0.438171 |
dc6ef7a1c631933beed92000c1544c40d5843d14 | 634 | agda | Agda | test/interaction/Issue734a.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue734a.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue734a.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module Issue734a where
module M₁ (Z : Set₁) where
postulate
P : Set
Q : Set → Set
module M₂ (X Y : Set) where
module M₁′ = M₁ Set
open M₁′
p : P
p = {!!}
-- Previous and current agda2-goal-and-context:
-- Y : Set
-- X : Set
-- ---------
-- Goal: P
q : Q X
q = {!!}
-- Previous and current agda2-goal-and-context:
-- Y : Set
-- X : Set
-- -----------
-- Goal: Q X
postulate X : Set
pp : M₂.M₁′.P X X
pp = {!!}
-- Previous agda2-goal-and-context:
-- ----------------
-- Goal: M₁.P Set
-- Current agda2-goal-and-context:
-- --------------------
-- Goal: M₂.M₁′.P X X
| 13.208333 | 49 | 0.474763 |
c5eb248ef0ce077c8bb33c1be48058bf71500831 | 217 | agda | Agda | test/interaction/Issue564.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue564.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue564.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module Issue564 where
open import Agda.Primitive using (Level) renaming (lzero to zero)
postulate
A : Level → Set
module M ℓ where
postulate a : A ℓ
postulate
P : A zero → Set
open M zero
p : P a
p = {!!}
| 12.055556 | 65 | 0.668203 |
c5bbd51599da7b39add0b090611ab0144138b759 | 349 | agda | Agda | test/interaction/Issue2589.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue2589.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue2589.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.Nat
-- splitting on a 'with' argument should not expand the ellipsis
foo : Nat → Nat
foo m with 0
... | n = {!n!}
-- splitting on variable hidden by ellipsis should expand the ellipsis
bar : Nat → Nat
bar m with 0
... | n = {!m!}
-- test case with nested with
baz : Nat → Nat
baz m with m
... | n with n
... | p = {!p!}
| 18.368421 | 70 | 0.630372 |
d06600309078b58961a2bddacd8f091a17ccb058 | 239 | agda | Agda | HoTT/Equivalence/Empty.agda | michaelforney/hott | ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508 | [
"0BSD"
] | null | null | null | HoTT/Equivalence/Empty.agda | michaelforney/hott | ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508 | [
"0BSD"
] | null | null | null | HoTT/Equivalence/Empty.agda | michaelforney/hott | ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508 | [
"0BSD"
] | null | null | null | {-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
module HoTT.Equivalence.Empty where
open variables
𝟎-equiv : {A : 𝒰 i} → ¬ A → 𝟎 {i} ≃ A
𝟎-equiv ¬a = 𝟎-rec , qinv→isequiv (𝟎-rec ∘ ¬a , 𝟎-ind , 𝟎-rec ∘ ¬a)
| 21.727273 | 67 | 0.631799 |
d01d571db09094efe8ff066e174a27752ae62e47 | 2,266 | agda | Agda | src/MLib/Algebra/PropertyCode.agda | bch29/agda-matrices | e26ae2e0aa7721cb89865aae78625a2f3fd2b574 | [
"MIT"
] | null | null | null | src/MLib/Algebra/PropertyCode.agda | bch29/agda-matrices | e26ae2e0aa7721cb89865aae78625a2f3fd2b574 | [
"MIT"
] | null | null | null | src/MLib/Algebra/PropertyCode.agda | bch29/agda-matrices | e26ae2e0aa7721cb89865aae78625a2f3fd2b574 | [
"MIT"
] | null | null | null | module MLib.Algebra.PropertyCode where
open import MLib.Prelude
open import MLib.Finite
open import MLib.Algebra.PropertyCode.RawStruct public
open import MLib.Algebra.PropertyCode.Core as Core public
using (Property; Properties; Code; IsSubcode; _∈ₚ_; _⇒ₚ_; ⟦_⟧P)
renaming (⇒ₚ-weaken to weaken)
open Core.PropKind public
open Core.PropertyC using (_on_; _is_for_; _⟨_⟩ₚ_) public
import Relation.Unary as U using (Decidable)
open import Relation.Binary as B using (Setoid)
open import Data.List.All as All using (All; _∷_; []) public
open import Data.List.Any using (Any; here; there)
open import Data.Bool using (_∨_)
open import Category.Applicative
record Struct {k} (code : Code k) c ℓ : Set (sucˡ (c ⊔ˡ ℓ ⊔ˡ k)) where
open Code code public
field
rawStruct : RawStruct K c ℓ
Π : Properties code
open RawStruct rawStruct public
open Properties Π public
field
reify : ∀ {π} → π ∈ₚ Π → ⟦ π ⟧P rawStruct
Hasₚ : (Π′ : Properties code) → Set
Hasₚ Π′ = Π′ ⇒ₚ Π
Has : List (Property K) → Set
Has = Hasₚ ∘ Core.fromList
Has₁ : Property K → Set
Has₁ π = Hasₚ (Core.singleton π)
use : ∀ π ⦃ hasπ : π ∈ₚ Π ⦄ → ⟦ π ⟧P rawStruct
use _ ⦃ hasπ ⦄ = reify hasπ
from : ∀ {Π′} (hasΠ′ : Hasₚ Π′) π ⦃ hasπ : π ∈ₚ Π′ ⦄ → ⟦ π ⟧P rawStruct
from hasΠ′ _ ⦃ hasπ ⦄ = use _ ⦃ Core.⇒ₚ-MP hasπ hasΠ′ ⦄
substruct : ∀ {k′} {code′ : Code k′} → IsSubcode code′ code → Struct code′ c ℓ
substruct isSub = record
{ rawStruct = record
{ Carrier = Carrier
; _≈_ = _≈_
; appOp = appOp ∘ Core.subK→supK isSub
; isRawStruct = isRawStruct′
}
; Π = Core.subcodeProperties isSub Π
; reify = Core.reinterpret isSub rawStruct isRawStruct′ _ ∘ reify ∘ Core.fromSubcode isSub
}
where
isRawStruct′ = record
{ isEquivalence = isEquivalence
; congⁿ = congⁿ ∘ Core.subK→supK isSub
}
toSubstruct :
∀ {k′} {code′ : Code k′} (isSub : IsSubcode code′ code) →
∀ {Π′ : Properties code′} (hasΠ′ : Hasₚ (Core.supcodeProperties isSub Π′)) →
Π′ ⇒ₚ Core.subcodeProperties isSub Π
toSubstruct isSub hasΠ′ = Core.→ₚ-⇒ₚ λ π hasπ →
Core.fromSupcode isSub
(Core.⇒ₚ-→ₚ hasΠ′
(Core.mapProperty (Core.subK→supK isSub) π)
(Core.fromSupcode′ isSub hasπ))
| 29.051282 | 94 | 0.645631 |
cb402aca562b3db4110afe310a1e4ae9d0fc4f2f | 589 | agda | Agda | benchmark/cwf/Chain.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | benchmark/cwf/Chain.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | benchmark/cwf/Chain.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Chain
{U : Set}(T : U -> Set)
(_==_ : {a b : U} -> T a -> T b -> Set)
(refl : {a : U}(x : T a) -> x == x)
(trans : {a b c : U}(x : T a)(y : T b)(z : T c) -> x == y -> y == z -> x == z)
where
infix 30 _∼_
infix 3 proof_
infixl 2 _≡_by_
infix 1 _qed
data _∼_ {a b : U}(x : T a)(y : T b) : Set where
prf : x == y -> x ∼ y
proof_ : {a : U}(x : T a) -> x ∼ x
proof x = prf (refl x)
_≡_by_ : {a b c : U}{x : T a}{y : T b} -> x ∼ y -> (z : T c) -> y == z -> x ∼ z
prf p ≡ z by q = prf (trans _ _ _ p q)
_qed : {a b : U}{x : T a}{y : T b} -> x ∼ y -> x == y
prf p qed = p
| 23.56 | 80 | 0.410866 |
d02407c3b7af4d59ab91723a907584f745859858 | 560 | agda | Agda | test/Fail/Issue610-module-alias.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Fail/Issue610-module-alias.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | null | null | null | test/Fail/Issue610-module-alias.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | 1 | 2019-03-05T20:02:38.000Z | 2019-03-05T20:02:38.000Z | -- Andreas, 2016-02-11, bug reported by sanzhiyan
module Issue610-module-alias where
import Common.Level
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
data A : Set₁ where
set : .Set → A
module M .(x : Set) where
.out : _
out = x
.ack : A → Set
ack (set x) = M.out x
hah : set ⊤ ≡ set ⊥
hah = refl
.moo' : ⊥
moo' = subst (λ x → x) (cong ack hah) _
-- Expected error:
-- .(⊥) !=< ⊥ of type Set
-- when checking that the expression subst (λ x → x) (cong ack hah) _ has type ⊥
baa : .⊥ → ⊥
baa ()
yoink : ⊥
yoink = baa moo'
| 15.135135 | 80 | 0.603571 |
dfeefa1af3e66f5827393f529a82a468873ff2d8 | 2,735 | agda | Agda | Prelude.agda | hazelgrove/hazelnut-agda | a3640d7b0f76cdac193afd382694197729ed6d57 | [
"MIT"
] | null | null | null | Prelude.agda | hazelgrove/hazelnut-agda | a3640d7b0f76cdac193afd382694197729ed6d57 | [
"MIT"
] | null | null | null | Prelude.agda | hazelgrove/hazelnut-agda | a3640d7b0f76cdac193afd382694197729ed6d57 | [
"MIT"
] | null | null | null | module Prelude where
open import Agda.Primitive using (Level; lzero; lsuc) renaming (_⊔_ to lmax)
-- empty type
data ⊥ : Set where
-- from false, derive whatever
abort : ∀ {C : Set} → ⊥ → C
abort ()
-- unit
data ⊤ : Set where
<> : ⊤
-- sums
data _+_ (A B : Set) : Set where
Inl : A → A + B
Inr : B → A + B
-- pairs
infixr 1 _,_
record Σ {l1 l2 : Level} (A : Set l1) (B : A → Set l2) : Set (lmax l1 l2) where
constructor _,_
field
π1 : A
π2 : B π1
open Σ public
-- Sigma types, or dependent pairs, with nice notation.
syntax Σ A (\ x -> B) = Σ[ x ∈ A ] B
_×_ : {l1 : Level} {l2 : Level} → (Set l1) → (Set l2) → Set (lmax l1 l2)
A × B = Σ A λ _ → B
infixr 1 _×_
infixr 1 _+_
-- equality
data _==_ {l : Level} {A : Set l} (M : A) : A → Set l where
refl : M == M
infixr 9 _==_
-- disequality
_≠_ : {l : Level} {A : Set l} → (a b : A) → Set l
a ≠ b = (a == b) → ⊥
{-# BUILTIN EQUALITY _==_ #-}
-- transitivity of equality
_·_ : {l : Level} {α : Set l} {x y z : α} → x == y → y == z → x == z
refl · refl = refl
-- symmetry of equality
! : {l : Level} {α : Set l} {x y : α} → x == y → y == x
! refl = refl
-- ap, in the sense of HoTT, that all functions respect equality in their
-- arguments. named in a slightly non-standard way to avoid naming
-- clashes with hazelnut constructors.
ap1 : {l1 l2 : Level} {α : Set l1} {β : Set l2} {x y : α} (F : α → β)
→ x == y → F x == F y
ap1 F refl = refl
-- transport, in the sense of HoTT, that fibrations respect equality
tr : {l1 l2 : Level} {α : Set l1} {x y : α}
(B : α → Set l2)
→ x == y
→ B x
→ B y
tr B refl x₁ = x₁
-- options
data Maybe (A : Set) : Set where
Some : A → Maybe A
None : Maybe A
-- the some constructor is injective. perhaps unsurprisingly.
someinj : {A : Set} {x y : A} → Some x == Some y → x == y
someinj refl = refl
-- some isn't none.
somenotnone : {A : Set} {x : A} → Some x == None → ⊥
somenotnone ()
-- function extensionality, used to reason about contexts as finite
-- functions.
postulate
funext : {A : Set} {B : A → Set} {f g : (x : A) → (B x)} →
((x : A) → f x == g x) → f == g
-- non-equality is commutative
flip : {A : Set} {x y : A} → (x == y → ⊥) → (y == x → ⊥)
flip neq eq = neq (! eq)
-- two types are said to be equivalent, or isomorphic, if there is a pair
-- of functions between them where both round-trips are stable up to ==
_≃_ : Set → Set → Set
_≃_ A B = Σ[ f ∈ (A → B) ] Σ[ g ∈ (B → A) ]
(((a : A) → g (f a) == a) × (((b : B) → f (g b) == b)))
| 27.079208 | 81 | 0.503839 |
dcc4fdee8e50180e22f376fc20568534841db841 | 1,486 | agda | Agda | src/Delay-monad/Sized.agda | nad/delay-monad | 495f9996673d0f1f34ce202902daaa6c39f8925e | [
"MIT"
] | null | null | null | src/Delay-monad/Sized.agda | nad/delay-monad | 495f9996673d0f1f34ce202902daaa6c39f8925e | [
"MIT"
] | null | null | null | src/Delay-monad/Sized.agda | nad/delay-monad | 495f9996673d0f1f34ce202902daaa6c39f8925e | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- The delay monad, defined coinductively, with a sized type parameter
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Delay-monad.Sized where
open import Equality.Propositional
open import Prelude
open import Prelude.Size
open import Bijection equality-with-J using (_↔_)
-- The delay monad.
mutual
data Delay {a} (A : Size → Type a) (i : Size) : Type a where
now : A i → Delay A i
later : Delay′ A i → Delay A i
record Delay′ {a} (A : Size → Type a) (i : Size) : Type a where
coinductive
field
force : {j : Size< i} → Delay A j
open Delay′ public
module _ {a} {A : Size → Type a} where
mutual
-- A non-terminating computation.
never : ∀ {i} → Delay A i
never = later never′
never′ : ∀ {i} → Delay′ A i
force never′ = never
-- Removes a later constructor, if possible.
drop-later : Delay A ∞ → Delay A ∞
drop-later (now x) = now x
drop-later (later x) = force x
-- An unfolding lemma for Delay.
Delay↔ : ∀ {i} → Delay A i ↔ A i ⊎ Delay′ A i
Delay↔ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (now x) → inj₁ x; (later x) → inj₂ x }
; from = [ now , later ]
}
; right-inverse-of = [ (λ _ → refl) , (λ _ → refl) ]
}
; left-inverse-of = λ { (now _) → refl; (later _) → refl }
}
| 24.360656 | 72 | 0.519515 |
18e948affb321af2fda685b7f446991e06a725a6 | 3,206 | agda | Agda | test/LibSucceed/Issue4312.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2016-05-20T13:58:52.000Z | 2016-05-20T13:58:52.000Z | test/LibSucceed/Issue4312.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/LibSucceed/Issue4312.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2021-04-18T13:34:07.000Z | 2021-04-18T13:34:07.000Z | {-# OPTIONS --without-K --safe #-}
open import Level
record Category (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
eta-equality
infix 4 _≈_ _⇒_
infixr 9 _∘_
field
Obj : Set o
_⇒_ : Obj → Obj → Set ℓ
_≈_ : ∀ {A B} → (A ⇒ B) → (A ⇒ B) → Set e
_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)
CommutativeSquare : ∀ {A B C D} → (f : A ⇒ B) (g : A ⇒ C) (h : B ⇒ D) (i : C ⇒ D) → Set _
CommutativeSquare f g h i = h ∘ f ≈ i ∘ g
infix 10 _[_,_]
_[_,_] : ∀ {o ℓ e} → (C : Category o ℓ e) → (X : Category.Obj C) → (Y : Category.Obj C) → Set ℓ
_[_,_] = Category._⇒_
module Inner {x₁ x₂ x₃} (CC : Category x₁ x₂ x₃) where
open import Level
private
variable
o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ : Level
open import Data.Product using (_×_; Σ; _,_; curry′; proj₁; proj₂; zip; map; <_,_>; swap)
zipWith : ∀ {a b c p q r s} {A : Set a} {B : Set b} {C : Set c} {P : A → Set p} {Q : B → Set q} {R : C → Set r} {S : (x : C) → R x → Set s} (_∙_ : A → B → C) → (_∘_ : ∀ {x y} → P x → Q y → R (x ∙ y)) → (_*_ : (x : C) → (y : R x) → S x y) → (x : Σ A P) → (y : Σ B Q) → S (proj₁ x ∙ proj₁ y) (proj₂ x ∘ proj₂ y)
zipWith _∙_ _∘_ _*_ (a , p) (b , q) = (a ∙ b) * (p ∘ q)
syntax zipWith f g h = f -< h >- g
record Functor (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
eta-equality
private module C = Category C
private module D = Category D
field
F₀ : C.Obj → D.Obj
F₁ : ∀ {A B} (f : C [ A , B ]) → D [ F₀ A , F₀ B ]
Product : (C : Category o ℓ e) (D : Category o′ ℓ′ e′) → Category (o ⊔ o′) (ℓ ⊔ ℓ′) (e ⊔ e′)
Product C D = record
{ Obj = C.Obj × D.Obj
; _⇒_ = C._⇒_ -< _×_ >- D._⇒_
; _≈_ = C._≈_ -< _×_ >- D._≈_
; _∘_ = zip C._∘_ D._∘_
}
where module C = Category C
module D = Category D
Bifunctor : Category o ℓ e → Category o′ ℓ′ e′ → Category o″ ℓ″ e″ → Set _
Bifunctor C D E = Functor (Product C D) E
private
module CC = Category CC
open CC
infix 4 _≅_
record _≅_ (A B : Obj) : Set (x₂) where
field
from : A ⇒ B
to : B ⇒ A
private
variable
X Y Z W : Obj
f g h : X ⇒ Y
record Monoidal : Set (x₁ ⊔ x₂ ⊔ x₃) where
infixr 10 _⊗₀_ _⊗₁_
field
⊗ : Bifunctor CC CC CC
module ⊗ = Functor ⊗
open Functor ⊗
_⊗₀_ : Obj → Obj → Obj
_⊗₀_ = curry′ F₀
-- this is also 'curry', but a very-dependent version
_⊗₁_ : X ⇒ Y → Z ⇒ W → X ⊗₀ Z ⇒ Y ⊗₀ W
f ⊗₁ g = F₁ (f , g)
field
associator : (X ⊗₀ Y) ⊗₀ Z ≅ X ⊗₀ (Y ⊗₀ Z)
module associator {X} {Y} {Z} = _≅_ (associator {X} {Y} {Z})
-- for exporting, it makes sense to use the above long names, but for
-- internal consumption, the traditional (short!) categorical names are more
-- convenient. However, they are not symmetric, even though the concepts are, so
-- we'll use ⇒ and ⇐ arrows to indicate that
private
α⇒ = associator.from
α⇐ = λ {X} {Y} {Z} → associator.to {X} {Y} {Z}
field
assoc-commute-from : CommutativeSquare ((f ⊗₁ g) ⊗₁ h) α⇒ α⇒ (f ⊗₁ (g ⊗₁ h))
assoc-commute-to : CommutativeSquare (f ⊗₁ (g ⊗₁ h)) α⇐ α⇐ ((f ⊗₁ g) ⊗₁ h)
| 29.412844 | 311 | 0.498129 |
4a55f09bdd1af018bea62646a338e27c696c9252 | 659 | agda | Agda | tests/covered/reflnat.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | 3 | 2015-08-10T15:33:56.000Z | 2018-12-06T17:24:25.000Z | tests/covered/reflnat.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | null | null | null | tests/covered/reflnat.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | null | null | null | module reflnat where
data ℕ : Set where
Z : ℕ
S : ℕ -> ℕ
_+_ : ℕ -> ℕ -> ℕ
n + Z = n
n + S m = S (n + m)
infixr 10 _+_
infixr 20 _*_
_*_ : ℕ -> ℕ -> ℕ
n * Z = Z
n * S m = n * m + n
data Bool : Set where
tt : Bool
ff : Bool
data ⊤ : Set where
true : ⊤
data ⊥ : Set where
Atom : Bool -> Set
Atom tt = ⊤
Atom ff = ⊥
_==Bool_ : ℕ -> ℕ -> Bool
Z ==Bool Z = tt
(S n) ==Bool (S m) = n ==Bool m
_ ==Bool _ = ff
-- Z ==Bool (S _) = ff
-- (S _) ==Bool Z = ff
_==_ : ℕ -> ℕ -> Set
n == m = Atom ( n ==Bool m)
Refl : Set
Refl = (n : ℕ) -> n == n
refl : Refl
refl Z = true
refl (S n) = refl n
| 10.983333 | 32 | 0.432473 |
18844cf563d0d89b213cb7833c285e63826dc5ae | 678 | agda | Agda | test/Fail/RecordConstructorsInErrorMessages.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/RecordConstructorsInErrorMessages.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/RecordConstructorsInErrorMessages.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- This file tests that record constructors are used in error
-- messages, if possible.
-- Andreas, 2016-07-20 Repaired this long disfunctional test case.
module RecordConstructorsInErrorMessages where
record R : Set₁ where
constructor con
field
{A} : Set
f : A → A
{B C} D {E} : Set
g : B → C → E
postulate
A : Set
r : R
data _≡_ {A : Set₁} (x : A) : A → Set where
refl : x ≡ x
foo : r ≡ record
{ A = A
; f = λ x → x
; B = A
; C = A
; D = A
; g = λ x _ → x
}
foo = refl
-- EXPECTED ERROR:
-- .R.A r != A of type Set
-- when checking that the expression refl has type
-- r ≡ con (λ x → x) A (λ x _ → x)
| 18.324324 | 66 | 0.547198 |
dffdcf717e22e73b03b14555c46927f47a63ed60 | 3,641 | agda | Agda | BasicIS4/Metatheory/Gentzen-TarskiOvergluedGentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 29 | 2016-07-03T18:51:56.000Z | 2022-01-01T10:29:18.000Z | BasicIS4/Metatheory/Gentzen-TarskiOvergluedGentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | 1 | 2018-06-10T09:11:22.000Z | 2018-06-10T09:11:22.000Z | BasicIS4/Metatheory/Gentzen-TarskiOvergluedGentzen.agda | mietek/hilbert-gentzen | fcd187db70f0a39b894fe44fad0107f61849405c | [
"X11"
] | null | null | null | module BasicIS4.Metatheory.Gentzen-TarskiOvergluedGentzen where
open import BasicIS4.Syntax.Gentzen public
open import BasicIS4.Semantics.TarskiOvergluedGentzen public
-- Internalisation of syntax as syntax representation in a particular model.
module _ {{_ : Model}} where
mutual
[_] : ∀ {A Γ} → Γ ⊢ A → Γ [⊢] A
[ var i ] = [var] i
[ lam t ] = [lam] [ t ]
[ app t u ] = [app] [ t ] [ u ]
[ multibox ts u ] = [multibox] ([⊢]⋆→[⊢⋆] [ ts ]⋆) [ u ]
[ down t ] = [down] [ t ]
[ pair t u ] = [pair] [ t ] [ u ]
[ fst t ] = [fst] [ t ]
[ snd t ] = [snd] [ t ]
[ unit ] = [unit]
[_]⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ [⊢]⋆ Ξ
[_]⋆ {∅} ∙ = ∙
[_]⋆ {Ξ , A} (ts , t) = [ ts ]⋆ , [ t ]
-- Soundness with respect to all models, or evaluation.
mutual
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (lam t) γ = λ η → let γ′ = mono⊩⋆ η γ
in [multicut] (reifyʳ⋆ γ′) [ lam t ] ⅋ λ a →
eval t (γ′ , a)
eval (app t u) γ = eval t γ ⟪$⟫ eval u γ
eval (multibox ts u) γ = λ η → let γ′ = mono⊩⋆ η γ
in [multicut] (reifyʳ⋆ γ′) [ multibox ts u ] ⅋
eval u (eval⋆ ts γ′)
eval (down t) γ = ⟪↓⟫ (eval t γ)
eval (pair t u) γ = eval t γ , eval u γ
eval (fst t) γ = π₁ (eval t γ)
eval (snd t) γ = π₂ (eval t γ)
eval unit γ = ∙
eval⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊨⋆ Ξ
eval⋆ {∅} ∙ γ = ∙
eval⋆ {Ξ , A} (ts , t) γ = eval⋆ ts γ , eval t γ
-- TODO: Correctness of evaluation with respect to conversion.
-- The canonical model.
private
instance
canon : Model
canon = record
{ _⊩ᵅ_ = λ Γ P → Γ ⊢ α P
; mono⊩ᵅ = mono⊢
; _[⊢]_ = _⊢_
; _[⊢⋆]_ = _⊢⋆_
; mono[⊢] = mono⊢
; [var] = var
; [lam] = lam
; [app] = app
; [multibox] = multibox
; [down] = down
; [pair] = pair
; [fst] = fst
; [snd] = snd
; [unit] = unit
; top[⊢⋆] = refl
; pop[⊢⋆] = refl
}
-- Soundness and completeness with respect to the canonical model.
mutual
reflectᶜ : ∀ {A Γ} → Γ ⊢ A → Γ ⊩ A
reflectᶜ {α P} t = t ⅋ t
reflectᶜ {A ▻ B} t = λ η → let t′ = mono⊢ η t
in t′ ⅋ λ a → reflectᶜ (app t′ (reifyᶜ a))
reflectᶜ {□ A} t = λ η → let t′ = mono⊢ η t
in t′ ⅋ reflectᶜ (down t′)
reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t)
reflectᶜ {⊤} t = ∙
reifyᶜ : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ A
reifyᶜ {α P} s = syn s
reifyᶜ {A ▻ B} s = syn (s refl⊆)
reifyᶜ {□ A} s = syn (s refl⊆)
reifyᶜ {A ∧ B} s = pair (reifyᶜ (π₁ s)) (reifyᶜ (π₂ s))
reifyᶜ {⊤} s = unit
reflectᶜ⋆ : ∀ {Ξ Γ} → Γ ⊢⋆ Ξ → Γ ⊩⋆ Ξ
reflectᶜ⋆ {∅} ∙ = ∙
reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t
reifyᶜ⋆ : ∀ {Ξ Γ} → Γ ⊩⋆ Ξ → Γ ⊢⋆ Ξ
reifyᶜ⋆ {∅} ∙ = ∙
reifyᶜ⋆ {Ξ , A} (ts , t) = reifyᶜ⋆ ts , reifyᶜ t
-- Reflexivity and transitivity.
refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ
refl⊩⋆ = reflectᶜ⋆ refl⊢⋆
trans⊩⋆ : ∀ {Γ Γ′ Γ″} → Γ ⊩⋆ Γ′ → Γ′ ⊩⋆ Γ″ → Γ ⊩⋆ Γ″
trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reifyᶜ⋆ ts) (reifyᶜ⋆ us))
-- Completeness with respect to all models, or quotation.
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A
quot s = reifyᶜ (s refl⊩⋆)
-- Normalisation by evaluation.
norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A
norm = quot ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
| 28.445313 | 81 | 0.439165 |
c58baf2e4f66e131d8759e724a44f686fe1fce5e | 2,531 | agda | Agda | examples/outdated-and-incorrect/Warshall.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/Warshall.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/Warshall.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Warshall
(X : Set)
((≤) : X -> X -> Prop)
-- and axioms...
where
id : {A:Set} -> A -> A
id x = x
(∘) : {A B C:Set} -> (B -> C) -> (A -> B) -> A -> C
f ∘ g = \x -> f (g x)
-- Natural numbers --------------------------------------------------------
data Nat : Set where
zero : Nat
suc : Nat -> Nat
(+) : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
-- Finite sets ------------------------------------------------------------
data Zero : Set where
data Suc (A:Set) : Set where
fzero_ : Suc A
fsuc_ : A -> Suc A
mutual
data Fin (n:Nat) : Set where
finI : Fin_ n -> Fin n
Fin_ : Nat -> Set
Fin_ zero = Zero
Fin_ (suc n) = Suc (Fin n)
fzero : {n:Nat} -> Fin (suc n)
fzero = finI fzero_
fsuc : {n:Nat} -> Fin n -> Fin (suc n)
fsuc i = finI (fsuc_ i)
finE : {n:Nat} -> Fin n -> Fin_ n
finE (finI i) = i
infixr 15 ::
-- Vectors ----------------------------------------------------------------
data Nil : Set where
nil_ : Nil
data Cons (Xs:Set) : Set where
cons_ : X -> Xs -> Cons Xs
mutual
data Vec (n:Nat) : Set where
vecI : Vec_ n -> Vec n
Vec_ : Nat -> Set
Vec_ zero = Nil
Vec_ (suc n) = Cons (Vec n)
nil : Vec zero
nil = vecI nil_
(::) : {n:Nat} -> X -> Vec n -> Vec (suc n)
x :: xs = vecI (cons_ x xs)
vecE : {n:Nat} -> Vec n -> Vec_ n
vecE (vecI xs) = xs
vec : (n:Nat) -> X -> Vec n
vec zero _ = nil
vec (suc n) x = x :: vec n x
map : {n:Nat} -> (X -> X) -> Vec n -> Vec n
map {zero} f (vecI nil_) = nil
map {suc n} f (vecI (cons_ x xs)) = f x :: map f xs
(!) : {n:Nat} -> Vec n -> Fin n -> X
(!) {suc n} (vecI (cons_ x _ )) (finI fzero_) = x
(!) {suc n} (vecI (cons_ _ xs)) (finI (fsuc_ i)) = xs ! i
upd : {n:Nat} -> Fin n -> X -> Vec n -> Vec n
upd {suc n} (finI fzero_) x (vecI (cons_ _ xs)) = x :: xs
upd {suc n} (finI (fsuc_ i)) x (vecI (cons_ y xs)) = y :: upd i x xs
tabulate : {n:Nat} -> (Fin n -> X) -> Vec n
tabulate {zero} f = nil
tabulate {suc n} f = f fzero :: tabulate (\x -> f (fsuc x))
postulate
(===) : {n:Nat} -> Vec n -> Vec n -> Prop
module Proof
(F : {n:Nat} -> Vec n -> Vec n)
-- and axioms...
where
stepF : {n:Nat} -> Fin n -> Vec n -> Vec n
stepF i xs = upd i (F xs ! i) xs
unsafeF' : {n:Nat} -> Nat -> Vec (suc n) -> Vec (suc n)
unsafeF' zero = id
unsafeF' (suc m) = unsafeF' m ∘ stepF fzero
unsafeF : {n:Nat} -> Vec n -> Vec n
unsafeF {zero} = id
unsafeF {suc n} = unsafeF' (suc n)
thm : {n:Nat} -> (xs:Vec n) -> F xs === unsafeF xs
thm = ?
| 20.917355 | 75 | 0.467404 |
dc491588b6da84ff68e257a3c8ee7d1859c1ac1b | 8,147 | agda | Agda | Cubical/Foundations/Prelude.agda | scott-fleischman/cubical | 337ce3883449862c2d27380b36a2a7b599ef9f0d | [
"MIT"
] | null | null | null | Cubical/Foundations/Prelude.agda | scott-fleischman/cubical | 337ce3883449862c2d27380b36a2a7b599ef9f0d | [
"MIT"
] | null | null | null | Cubical/Foundations/Prelude.agda | scott-fleischman/cubical | 337ce3883449862c2d27380b36a2a7b599ef9f0d | [
"MIT"
] | null | null | null | {-
This file proves a variety of basic results about paths:
- refl, sym, cong and composition of paths. This is used to set up
equational reasoning.
- Transport, subst and functional extensionality
- J and its computation rule (up to a path)
- Σ-types and contractibility of singletons
- Converting PathP to and from a homogeneous path with transp
- Direct definitions of lower h-levels
- Export natural numbers
- Export universe lifting
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Prelude where
open import Cubical.Core.Primitives public
infixr 30 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
-- Basic theory about paths. These proofs should typically be
-- inlined. This module also makes equational reasoning work with
-- (non-dependent) paths.
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y z : A
refl : x ≡ x
refl {x = x} = λ _ → x
sym : x ≡ y → y ≡ x
sym p i = p (~ i)
symP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} →
(p : PathP A x y) → PathP (λ i → A (~ i)) y x
symP p j = p (~ j)
cong : ∀ (f : (a : A) → B a) (p : x ≡ y) →
PathP (λ i → B (p i)) (f x) (f y)
cong f p i = f (p i)
cong₂ : ∀ {C : (a : A) → (b : B a) → Type ℓ} →
(f : (a : A) → (b : B a) → C a b) →
(p : x ≡ y) →
{u : B x} {v : B y} (q : PathP (λ i → B (p i)) u v) →
PathP (λ i → C (p i) (q i)) (f x u) (f y v)
cong₂ f p q i = f (p i) (q i)
-- The filler of homogeneous path composition:
-- compPath-filler p q = PathP (λ i → x ≡ q i) p (p ∙ q)
compPath-filler : ∀ {x y z : A} → x ≡ y → y ≡ z → I → I → A
compPath-filler {x = x} p q j i =
hfill (λ j → λ { (i = i0) → x
; (i = i1) → q j }) (inS (p i)) j
_∙_ : x ≡ y → y ≡ z → x ≡ z
(p ∙ q) j = compPath-filler p q i1 j
-- The filler of heterogeneous path composition:
-- compPathP-filler p q = PathP (λ i → PathP (λ j → (compPath-filler (λ i → A i) B i j)) x (q i)) p (compPathP p q)
compPathP-filler : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → {B_i1 : Type ℓ} {B : A i1 ≡ B_i1} → {z : B i1} →
(p : PathP A x y) → (q : PathP (λ i → B i) y z) → ∀ (i j : I) → compPath-filler (λ i → A i) B j i
compPathP-filler {A = A} {x = x} {B = B} p q i =
fill (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j }) (inS (p i))
compPathP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} → {z : B i1} →
(p : PathP A x y) → (q : PathP (λ i → B i) y z) → PathP (λ j → ((λ i → A i) ∙ B) j) x z
compPathP p q j = compPathP-filler p q j i1
_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
≡⟨⟩-syntax : (x : A) → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 2 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- another definition of composition, useful for some proofs
compPath'-filler : ∀ {x y z : A} → x ≡ y → y ≡ z → I → I → A
compPath'-filler {z = z} p q j i =
hfill (λ j → λ { (i = i0) → p (~ j)
; (i = i1) → z }) (inS (q i)) j
_□_ : x ≡ y → y ≡ z → x ≡ z
(p □ q) j = compPath'-filler p q i1 j
□≡∙ : (p : x ≡ y) (q : y ≡ z) → p □ q ≡ p ∙ q
□≡∙ {x = x} {y = y} {z = z} p q i j = hcomp (λ k → \ { (i = i0) → compPath'-filler p q k j
; (i = i1) → compPath-filler p q k j
; (j = i0) → p ( ~ i ∧ ~ k)
; (j = i1) → q (k ∨ ~ i) }) (helper i j)
where
helper : PathP (λ i → p (~ i) ≡ q (~ i)) q p
helper i j = hcomp (λ k → \ { (i = i0) → q (k ∧ j)
; (i = i1) → p (~ k ∨ j)
; (j = i0) → p (~ i ∨ ~ k)
; (j = i1) → q (~ i ∧ k) })
y
-- Transport, subst and functional extensionality
-- transport is a special case of transp
transport : {A B : Type ℓ} → A ≡ B → A → B
transport p a = transp (λ i → p i) i0 a
-- Transporting in a constant family is the identity function (up to a
-- path). If we would have regularity this would be definitional.
transportRefl : (x : A) → transport refl x ≡ x
transportRefl {A = A} x i = transp (λ _ → A) i x
-- We want B to be explicit in subst
subst : (B : A → Type ℓ') (p : x ≡ y) → B x → B y
subst B p pa = transport (λ i → B (p i)) pa
substRefl : (px : B x) → subst B refl px ≡ px
substRefl px = transportRefl px
funExt : {f g : (x : A) → B x} → ((x : A) → f x ≡ g x) → f ≡ g
funExt p i x = p x i
-- J for paths and its computation rule
module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
J : (p : x ≡ y) → P y p
J p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
JRefl : J refl ≡ d
JRefl = transportRefl d
-- Contractibility of singletons
singl : (a : A) → Type _
singl {A = A} a = Σ[ x ∈ A ] (a ≡ x)
contrSingl : (p : x ≡ y) → Path (singl x) (x , refl) (y , p)
contrSingl p i = (p i , λ j → p (i ∧ j))
-- Converting to and from a PathP
module _ {A : I → Type ℓ} {x : A i0} {y : A i1} where
toPathP : transp A i0 x ≡ y → PathP A x y
toPathP p i = hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
fromPathP : PathP A x y → transp A i0 x ≡ y
fromPathP p i = transp (λ j → A (i ∨ j)) i (p i)
-- Direct definitions of lower h-levels
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
Square
: ∀{w x y z : A}
→ (p : w ≡ y) (q : w ≡ x) (r : y ≡ z) (s : x ≡ z)
→ Set _
Square p q r s = PathP (λ i → p i ≡ s i) q r
isSet' : Type ℓ → Type ℓ
isSet' A
= {x y z w : A}
→ (p : x ≡ y) (q : z ≡ w) (r : x ≡ z) (s : y ≡ w)
→ Square r p q s
isGroupoid : Type ℓ → Type ℓ
isGroupoid A = ∀ a b → isSet (Path A a b)
Cube
: ∀{w x y z w' x' y' z' : A}
→ {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z}
→ {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'}
→ {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'}
→ (ps : Square a p p' c) (qs : Square a q q' b)
→ (rs : Square c r r' d) (ss : Square b s s' d)
→ (f0 : Square p q r s) (f1 : Square p' q' r' s')
→ Set _
Cube ps qs rs ss f0 f1
= PathP (λ k → Square (ps k) (qs k) (rs k) (ss k)) f0 f1
isGroupoid' : Set ℓ → Set ℓ
isGroupoid' A
= ∀{w x y z w' x' y' z' : A}
→ {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z}
→ {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'}
→ {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'}
→ (fp : Square a p p' c) → (fq : Square a q q' b)
→ (fr : Square c r r' d) → (fs : Square b s s' d)
→ (f0 : Square p q r s) → (f1 : Square p' q' r' s')
→ Cube fp fq fr fs f0 f1
is2Groupoid : Type ℓ → Type ℓ
is2Groupoid A = ∀ a b → isGroupoid (Path A a b)
-- Essential consequences of isProp and isContr
isProp→PathP
: ((x : A) → isProp (B x)) → {a0 a1 : A}
→ (p : a0 ≡ a1) (b0 : B a0) (b1 : B a1)
→ PathP (λ i → B (p i)) b0 b1
isProp→PathP P p b0 b1 = toPathP (P _ _ _)
isProp-PathP-I : ∀ {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ PathP (λ i → B i) b0 b1
isProp-PathP-I hB b0 b1 = toPathP (hB _ _ _)
isPropIsContr : isProp (isContr A)
isPropIsContr z0 z1 j =
( z0 .snd (z1 .fst) j
, λ x i → hcomp (λ k → λ { (i = i0) → z0 .snd (z1 .fst) j
; (i = i1) → z0 .snd x (j ∨ k)
; (j = i0) → z0 .snd x (i ∧ k)
; (j = i1) → z1 .snd x i })
(z0 .snd (z1 .snd x i) j))
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b i =
hcomp (λ j → λ { (i = i0) → p a j
; (i = i1) → p b j }) x
isProp→isSet : isProp A → isSet A
isProp→isSet h a b p q j i =
hcomp (λ k → λ { (i = i0) → h a a k
; (i = i1) → h a b k
; (j = i0) → h a (p i) k
; (j = i1) → h a (q i) k }) a
-- Universe lifting
record Lift {i j} (A : Type i) : Type (ℓ-max i j) where
instance constructor lift
field
lower : A
open Lift public
| 30.513109 | 115 | 0.465202 |
dfb0dd456cdba86282ec86cd097f024986e81d19 | 539 | agda | Agda | test/Fail/Issue691.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/Issue691.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/Issue691.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, 2012-09-07
-- {-# OPTIONS -v tc.polarity:10 -v tc.conv.irr:20 -v tc.conv.elim:25 -v tc.conv.term:10 #-}
module Issue691 where
open import Common.Equality
data Bool : Set where
true false : Bool
assert : (A : Set) → A → Bool → Bool
assert _ _ true = true
assert _ _ false = false
g : Bool -> Bool -> Bool
g x true = true
g x false = true
unsolved : Bool -> Bool
unsolved y =
let X : Bool
X = _
in assert (g X y ≡ g true y) refl X
-- X should be left unsolved
istrue : (unsolved false) ≡ true
istrue = refl
| 19.25 | 92 | 0.636364 |
20a60b2e57aea4ad74acca023799635586da693b | 1,381 | agda | Agda | test/Succeed/Issue892b.agda | redfish64/autonomic-agda | c0ae7d20728b15d7da4efff6ffadae6fe4590016 | [
"BSD-3-Clause"
] | null | null | null | test/Succeed/Issue892b.agda | redfish64/autonomic-agda | c0ae7d20728b15d7da4efff6ffadae6fe4590016 | [
"BSD-3-Clause"
] | null | null | null | test/Succeed/Issue892b.agda | redfish64/autonomic-agda | c0ae7d20728b15d7da4efff6ffadae6fe4590016 | [
"BSD-3-Clause"
] | null | null | null | -- {-# OPTIONS -v scope:20 #-}
module _ (X : Set) where
postulate
X₁ X₂ : Set
data D : Set where
d : D
module Q (x : D) where
module M1 (z : X₁) where
g = x
module M2 (y : D) (z : X₂) where
h = y
open M1 public
-- module Qd = Q d
-- This fails to apply g to d!
module QM2d = Q.M2 d d
module QM2p (x : D) = Q.M2 x x
test-h : X₂ → D
test-h = QM2d.h
test-g₁ : X₁ → D
test-g₁ = QM2d.g
test-g₂ : D → X₁ → D
test-g₂ = QM2p.g
data Nat : Set where
zero : Nat
suc : Nat → Nat
postulate
Lift : Nat → Set
mkLift : ∀ n → Lift n
module TS (T : Nat) where
module Lifted (lift : Lift T) where
postulate f : Nat
record Bla (T : Nat) : Set₁ where
module TST = TS T
module LT = TST.Lifted (mkLift T)
Z : Nat
Z = LT.f
postulate
A : Set
module C (X : Set) where
postulate cA : X
module C′ = C
module C′A = C′ A
dA' : A → A
dA' x = C′A.cA
postulate
B : Set
module TermSubst (X : Set) where
module Lifted (Y : Set) where
f : Set
f = Y
record TermLemmas (Z : Set) : Set₁ where
module TZ = TermSubst A
module TZL = TZ.Lifted B
foo : Set
foo = TZL.f
field Y : Set
module NatCore where
module NatT (X Y : Set) where
Z : Set
Z = X → Y
module NatTrans (Y : Set) where
open NatCore public
module NT = NatTrans
foo : Set → Set
foo X = Eta.Z
module Local where
module Eta = NT.NatT X X
| 14.536842 | 40 | 0.581463 |
df86b08059bdd69fcab788dfb4a90c4a502abda4 | 2,068 | agda | Agda | test/Succeed/Issue1796rewrite.agda | cagix/agda | cc026a6a97a3e517bb94bafa9d49233b067c7559 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue1796rewrite.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue1796rewrite.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, 2016-04-14 issue 1796 for rewrite
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.size.solve:100 #-}
-- {-# OPTIONS -v tc.with.abstract:40 #-}
{-# OPTIONS --sized-types #-}
open import Common.Size
open import Common.Equality
data Either (A B : Set) : Set where
left : A → Either A B
right : B → Either A B
either : {A B : Set} → Either A B →
∀{C : Set} → (A → C) → (B → C) → C
either (left a) l r = l a
either (right b) l r = r b
data Nat : Size → Set where
zero : ∀{i} → Nat (↑ i)
suc : ∀{i} → Nat i → Nat (↑ i)
primrec : ∀{ℓ} (C : Size → Set ℓ)
→ (z : ∀{i} → C i)
→ (s : ∀{i} → Nat i → C i → C (↑ i))
→ ∀{i} → Nat i → C i
primrec C z s zero = z
primrec C z s (suc n) = s n (primrec C z s n)
case : ∀{i} → Nat i
→ ∀{ℓ} (C : Size → Set ℓ)
→ (z : ∀{i} → C i)
→ (s : ∀{i} → Nat i → C (↑ i))
→ C i
case n C z s = primrec C z (λ n r → s n) n
diff : ∀{i} → Nat i → ∀{j} → Nat j → Either (Nat i) (Nat j)
diff = primrec (λ i → ∀{j} → Nat j → Either (Nat i) (Nat j))
-- case zero: the second number is bigger and the difference
right
-- case suc n:
(λ{i} n r m → case m (λ j → Either (Nat (↑ i)) (Nat j))
-- subcase zero: the first number (suc n) is bigger and the difference
(left (suc n))
-- subcase suc m: recurse on (n,m)
r)
gcd : ∀{i} → Nat i → ∀{j} → Nat j → Nat ∞
gcd zero m = m
gcd (suc n) zero = suc n
gcd (suc n) (suc m) = either (diff n m)
(λ n' → gcd n' (suc m))
(λ m' → gcd (suc n) m')
er : ∀{i} → Nat i → Nat ∞
er zero = zero
er (suc n) = suc (er n)
diff-diag-erase : ∀{i} (n : Nat i) → diff (er n) (er n) ≡ right zero
diff-diag-erase zero = refl
diff-diag-erase (suc n) = diff-diag-erase n
gcd-diag-erase : ∀{i} (n : Nat i) → gcd (er n) (er n) ≡ er n
gcd-diag-erase zero = refl
gcd-diag-erase (suc {i} n)
rewrite diff-diag-erase n
-- Before fix: diff-diag-erase {i} n.
-- The {i} was necessary, otherwise rewrite failed
-- because an unsolved size var prevented abstraction.
| gcd-diag-erase n = refl
| 28.328767 | 74 | 0.527563 |
c5825c66a10a1320262bb7d98e70f8f205f8bf25 | 450 | agda | Agda | test/Succeed/Issue4638-Cubical.agda | cagix/agda | cc026a6a97a3e517bb94bafa9d49233b067c7559 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue4638-Cubical.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue4638-Cubical.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --cubical --safe #-}
open import Agda.Builtin.Cubical.Path
open import Agda.Primitive
private
variable
a : Level
A B : Set a
Is-proposition : Set a → Set a
Is-proposition A = (x y : A) → x ≡ y
data ∥_∥ (A : Set a) : Set a where
∣_∣ : A → ∥ A ∥
@0 trivial : Is-proposition ∥ A ∥
rec : @0 Is-proposition B → (A → B) → ∥ A ∥ → B
rec p f ∣ x ∣ = f x
rec p f (trivial x y i) = p (rec p f x) (rec p f y) i
| 21.428571 | 53 | 0.54 |
0e562ebc662e5ccd02c12a3c649a2dff37803af8 | 6,384 | agda | Agda | Cubical/Algebra/Group/EilenbergMacLane1.agda | Schippmunk/cubical | c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a | [
"MIT"
] | null | null | null | Cubical/Algebra/Group/EilenbergMacLane1.agda | Schippmunk/cubical | c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a | [
"MIT"
] | null | null | null | Cubical/Algebra/Group/EilenbergMacLane1.agda | Schippmunk/cubical | c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Group.EilenbergMacLane1 where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.GroupoidLaws renaming (assoc to ∙assoc)
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.SIP
open import Cubical.Data.Unit
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary.Base
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Nullification as Null hiding (rec; elim)
open import Cubical.HITs.Truncation.FromNegOne as Trunc renaming (rec to trRec; elim to trElim)
open import Cubical.HITs.EilenbergMacLane1
private
variable ℓ : Level
module _ (G : Group {ℓ}) where
open Group G
emloop-id : emloop 0g ≡ refl
emloop-id =
-- emloop 0g ≡⟨ rUnit (emloop 0g) ⟩
emloop 0g ≡⟨ rUnit (emloop 0g) ⟩
emloop 0g ∙ refl ≡⟨ cong (emloop 0g ∙_) (rCancel (emloop 0g) ⁻¹) ⟩
emloop 0g ∙ (emloop 0g ∙ (emloop 0g) ⁻¹) ≡⟨ ∙assoc _ _ _ ⟩
(emloop 0g ∙ emloop 0g) ∙ (emloop 0g) ⁻¹ ≡⟨ cong (_∙ emloop 0g ⁻¹) ((emloop-comp G 0g 0g) ⁻¹) ⟩
emloop (0g + 0g) ∙ (emloop 0g) ⁻¹ ≡⟨ cong (λ g → emloop {G = G} g ∙ (emloop 0g) ⁻¹) (rid 0g) ⟩
emloop 0g ∙ (emloop 0g) ⁻¹ ≡⟨ rCancel (emloop 0g) ⟩
refl ∎
emloop-inv : (g : Carrier) → emloop (- g) ≡ (emloop g) ⁻¹
emloop-inv g =
emloop (- g) ≡⟨ rUnit (emloop (- g)) ⟩
emloop (- g) ∙ refl ≡⟨ cong (emloop (- g) ∙_) (rCancel (emloop g) ⁻¹) ⟩
emloop (- g) ∙ (emloop g ∙ (emloop g) ⁻¹) ≡⟨ ∙assoc _ _ _ ⟩
(emloop (- g) ∙ emloop g) ∙ (emloop g) ⁻¹ ≡⟨ cong (_∙ emloop g ⁻¹) ((emloop-comp G (- g) g) ⁻¹) ⟩
emloop (- g + g) ∙ (emloop g) ⁻¹ ≡⟨ cong (λ h → emloop {G = G} h ∙ (emloop g) ⁻¹) (invl g) ⟩
emloop 0g ∙ (emloop g) ⁻¹ ≡⟨ cong (_∙ (emloop g) ⁻¹) emloop-id ⟩
refl ∙ (emloop g) ⁻¹ ≡⟨ (lUnit ((emloop g) ⁻¹)) ⁻¹ ⟩
(emloop g) ⁻¹ ∎
EM₁Groupoid : isGroupoid (EM₁ G)
EM₁Groupoid = emsquash
EM₁Connected : isConnected 2 (EM₁ G)
EM₁Connected = ∣ embase ∣ , h
where
h : (y : hLevelTrunc 2 (EM₁ G)) → ∣ embase ∣ ≡ y
h = trElim (λ y → isOfHLevelSuc 1 (isOfHLevelTrunc 2 ∣ embase ∣ y))
(elimProp G (λ x → isOfHLevelTrunc 2 ∣ embase ∣ ∣ x ∣) refl)
{- since we write composition in diagrammatic order,
and function composition in the other order,
we need right multiplication here -}
rightEquiv : (g : Carrier) → Carrier ≃ Carrier
rightEquiv g = isoToEquiv (iso (_+ g) (_+ - g)
(λ h → (h + - g) + g ≡⟨ (assoc h (- g) g) ⁻¹ ⟩
h + - g + g ≡⟨ cong (h +_) (invl g) ⟩
h + 0g ≡⟨ rid h ⟩ h ∎)
λ h → (h + g) + - g ≡⟨ (assoc h g (- g)) ⁻¹ ⟩
h + g + - g ≡⟨ cong (h +_) (invr g) ⟩
h + 0g ≡⟨ rid h ⟩ h ∎)
compRightEquiv : (g h : Carrier)
→ compEquiv (rightEquiv g) (rightEquiv h) ≡ rightEquiv (g + h)
compRightEquiv g h = equivEq _ _ (funExt (λ x → (assoc x g h) ⁻¹))
CodesSet : EM₁ G → hSet ℓ
CodesSet = rec G (isOfHLevelTypeOfHLevel 2) (Carrier , is-set) RE REComp
where
RE : (g : Carrier) → Path (hSet ℓ) (Carrier , is-set) (Carrier , is-set)
RE g = Σ≡Prop (λ X → isPropIsOfHLevel {A = X} 2) (ua (rightEquiv g))
lemma₁ : (g h : Carrier) → Square
(ua (rightEquiv g)) (ua (rightEquiv (g + h)))
refl (ua (rightEquiv h))
lemma₁ g h = invEq
(Square≃doubleComp (ua (rightEquiv g)) (ua (rightEquiv (g + h)))
refl (ua (rightEquiv h)))
(ua (rightEquiv g) ∙ ua (rightEquiv h)
≡⟨ (uaCompEquiv (rightEquiv g) (rightEquiv h)) ⁻¹ ⟩
ua (compEquiv (rightEquiv g) (rightEquiv h))
≡⟨ cong ua (compRightEquiv g h) ⟩
ua (rightEquiv (g + h)) ∎)
lemma₂ : {A₀₀ A₀₁ : hSet ℓ} (p₀₋ : A₀₀ ≡ A₀₁)
{A₁₀ A₁₁ : hSet ℓ} (p₁₋ : A₁₀ ≡ A₁₁)
(p₋₀ : A₀₀ ≡ A₁₀) (p₋₁ : A₀₁ ≡ A₁₁)
(s : Square (cong fst p₀₋) (cong fst p₁₋) (cong fst p₋₀) (cong fst p₋₁))
→ Square p₀₋ p₁₋ p₋₀ p₋₁
fst (lemma₂ p₀₋ p₁₋ p₋₀ p₋₁ s i j) = s i j
snd (lemma₂ p₀₋ p₁₋ p₋₀ p₋₁ s i j) =
isSet→isSetDep (λ X → isProp→isSet (isPropIsOfHLevel {A = X} 2))
(cong fst p₀₋) (cong fst p₁₋) (cong fst p₋₀) (cong fst p₋₁) s
(cong snd p₀₋) (cong snd p₁₋) (cong snd p₋₀) (cong snd p₋₁) i j
REComp : (g h : Carrier) → Square (RE g) (RE (g + h)) refl (RE h)
REComp g h = lemma₂ (RE g) (RE (g + h)) refl (RE h) (lemma₁ g h)
Codes : EM₁ G → Type ℓ
Codes x = CodesSet x .fst
encode : (x : EM₁ G) → embase ≡ x → Codes x
encode x p = subst Codes p 0g
decode : (x : EM₁ G) → Codes x → embase ≡ x
decode = elimSet G (λ x → isOfHLevelΠ 2 (λ c → EM₁Groupoid (embase) x))
emloop lem₂
where
module _ (g : Carrier) where
lem₁ : (h : Carrier) → PathP (λ i → embase ≡ emloop g i) (emloop h) (emloop (h + g))
lem₁ h = emcomp h g
lem₂ : PathP (λ i → Codes (emloop g i) → embase ≡ emloop g i) emloop emloop
lem₂ = ua→ {A₀ = Carrier} {A₁ = Carrier} {e = rightEquiv g} lem₁
decode-encode : (x : EM₁ G) (p : embase ≡ x) → decode x (encode x p) ≡ p
decode-encode x p = J (λ y q → decode y (encode y q) ≡ q)
(emloop (transport refl 0g) ≡⟨ cong emloop (transportRefl 0g) ⟩
emloop 0g ≡⟨ emloop-id ⟩ refl ∎) p
encode-decode : (x : EM₁ G) (c : Codes x) → encode x (decode x c) ≡ c
encode-decode = elimProp G (λ x → isOfHLevelΠ 1 (λ c → CodesSet x .snd _ _))
λ g → encode embase (decode embase g) ≡⟨ refl ⟩
encode embase (emloop g) ≡⟨ refl ⟩
transport (ua (rightEquiv g)) 0g ≡⟨ uaβ (rightEquiv g) 0g ⟩
0g + g ≡⟨ lid g ⟩
g ∎
ΩEM₁Iso : Iso (Path (EM₁ G) embase embase) Carrier
Iso.fun ΩEM₁Iso = encode embase
Iso.inv ΩEM₁Iso = emloop
Iso.rightInv ΩEM₁Iso = encode-decode embase
Iso.leftInv ΩEM₁Iso = decode-encode embase
ΩEM₁≡ : (Path (EM₁ G) embase embase) ≡ Carrier
ΩEM₁≡ = isoToPath ΩEM₁Iso
| 42 | 101 | 0.58255 |
df32481ec7391291f5ef19e7d2140ea00d19bb0a | 1,706 | agda | Agda | Definition/LogicalRelation/Properties/Universe.agda | fhlkfy/logrel-mltt | ea83fc4f618d1527d64ecac82d7d17e2f18ac391 | [
"MIT"
] | 30 | 2017-05-20T03:05:21.000Z | 2022-03-30T18:01:07.000Z | Definition/LogicalRelation/Properties/Universe.agda | fhlkfy/logrel-mltt | ea83fc4f618d1527d64ecac82d7d17e2f18ac391 | [
"MIT"
] | 4 | 2017-06-22T12:49:23.000Z | 2021-02-22T10:37:24.000Z | Definition/LogicalRelation/Properties/Universe.agda | fhlkfy/logrel-mltt | ea83fc4f618d1527d64ecac82d7d17e2f18ac391 | [
"MIT"
] | 8 | 2017-10-18T14:18:20.000Z | 2021-11-27T15:58:33.000Z | {-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Universe {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped hiding (_∷_)
open import Definition.Typed
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Tools.Nat
private
variable
n : Nat
Γ : Con Term n
-- Helper function for reducible terms of type U for specific type derivations.
univEq′ : ∀ {l A} ([U] : Γ ⊩⟨ l ⟩U) → Γ ⊩⟨ l ⟩ A ∷ U / U-intr [U] → Γ ⊩⟨ ⁰ ⟩ A
univEq′ (noemb (Uᵣ .⁰ 0<1 ⊢Γ)) (Uₜ A₁ d typeA A≡A [A]) = [A]
univEq′ (emb 0<1 x) [A] = univEq′ x [A]
-- Reducible terms of type U are reducible types.
univEq : ∀ {l A} ([U] : Γ ⊩⟨ l ⟩ U) → Γ ⊩⟨ l ⟩ A ∷ U / [U] → Γ ⊩⟨ ⁰ ⟩ A
univEq [U] [A] = univEq′ (U-elim [U])
(irrelevanceTerm [U] (U-intr (U-elim [U])) [A])
-- Helper function for reducible term equality of type U for specific type derivations.
univEqEq′ : ∀ {l l′ A B} ([U] : Γ ⊩⟨ l ⟩U) ([A] : Γ ⊩⟨ l′ ⟩ A)
→ Γ ⊩⟨ l ⟩ A ≡ B ∷ U / U-intr [U]
→ Γ ⊩⟨ l′ ⟩ A ≡ B / [A]
univEqEq′ (noemb (Uᵣ .⁰ 0<1 ⊢Γ)) [A]
(Uₜ₌ A₁ B₁ d d′ typeA typeB A≡B [t] [u] [t≡u]) =
irrelevanceEq [t] [A] [t≡u]
univEqEq′ (emb 0<1 x) [A] [A≡B] = univEqEq′ x [A] [A≡B]
-- Reducible term equality of type U is reducible type equality.
univEqEq : ∀ {l l′ A B} ([U] : Γ ⊩⟨ l ⟩ U) ([A] : Γ ⊩⟨ l′ ⟩ A)
→ Γ ⊩⟨ l ⟩ A ≡ B ∷ U / [U]
→ Γ ⊩⟨ l′ ⟩ A ≡ B / [A]
univEqEq [U] [A] [A≡B] =
let [A≡B]′ = irrelevanceEqTerm [U] (U-intr (U-elim [U])) [A≡B]
in univEqEq′ (U-elim [U]) [A] [A≡B]′
| 36.297872 | 87 | 0.564478 |
18ee8850dd3be541c6427a92ba88311a3e42ed04 | 24,693 | agda | Agda | SemiLinRE.agda | JoeyEremondi/agda-parikh | 1e28103ff7dd1d4f3351ef21397833aa4490b7ea | [
"BSD-3-Clause"
] | null | null | null | SemiLinRE.agda | JoeyEremondi/agda-parikh | 1e28103ff7dd1d4f3351ef21397833aa4490b7ea | [
"BSD-3-Clause"
] | null | null | null | SemiLinRE.agda | JoeyEremondi/agda-parikh | 1e28103ff7dd1d4f3351ef21397833aa4490b7ea | [
"BSD-3-Clause"
] | null | null | null | {-
Joseph Eremondi
Utrecht University Capita Selecta
UU# 4229924
July 22, 2015
-}
module SemiLinRE where
open import Data.Vec
open import Data.Nat
import Data.Fin as Fin
open import Data.List
import Data.List.All
open import Data.Bool
open import Data.Char
open import Data.Maybe
open import Data.Product
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Binary.Core
open import Category.Monad
open import Data.Nat.Properties.Simple
open import Data.Maybe
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Utils
open import Function
import RETypes
open import Data.Sum
open import SemiLin
open import Data.Vec.Equality
open import Data.Nat.Properties.Simple
module VecNatEq = Data.Vec.Equality.DecidableEquality (Relation.Binary.PropositionalEquality.decSetoid Data.Nat._≟_)
--Find the Parikh vector of a given word
--Here cmap is the mapping of each character to its position
--in the Parikh vector
wordParikh : {n : ℕ} -> (Char -> Fin.Fin n) -> (w : List Char) -> Parikh n
wordParikh cmap [] = v0
wordParikh cmap (x ∷ w) = (basis (cmap x)) +v (wordParikh cmap w)
--Show that the Parikh of concatenating two words
--Is the sum of their Parikhs
wordParikhPlus : {n : ℕ}
-> (cmap : Char -> Fin.Fin n)
-> (u : List Char)
-> (v : List Char)
-> wordParikh cmap (u Data.List.++ v) ≡ (wordParikh cmap u) +v (wordParikh cmap v)
wordParikhPlus cmap [] v = sym v0identLeft
wordParikhPlus {n} cmap (x ∷ u) v =
begin
basis (cmap x) +v wordParikh cmap (u ++l v)
≡⟨ cong (λ y → basis (cmap x) +v y) (wordParikhPlus cmap u v) ⟩
basis (cmap x) +v (wordParikh cmap u +v wordParikh cmap v)
≡⟨ sym vAssoc ⟩
((basis (cmap x) +v wordParikh cmap u) +v wordParikh cmap v ∎)
where
_++l_ = Data.List._++_
--The algorithm mapping regular expressions to the Parikh set of
--the language matched by the RE
--We prove this correct below
reSemiLin : {n : ℕ} {null? : RETypes.Null?} -> (Char -> Fin.Fin n) -> RETypes.RE null? -> SemiLinSet n
reSemiLin cmap RETypes.ε = Data.List.[ v0 , 0 , [] ]
reSemiLin cmap RETypes.∅ = []
reSemiLin cmap (RETypes.Lit x) = Data.List.[ basis (cmap x ) , 0 , [] ]
reSemiLin cmap (r1 RETypes.+ r2) = reSemiLin cmap r1 Data.List.++ reSemiLin cmap r2
reSemiLin cmap (r1 RETypes.· r2) = reSemiLin cmap r1 +s reSemiLin cmap r2
reSemiLin cmap (r RETypes.*) = starSemiLin (reSemiLin cmap r)
{-
Show that s* ⊆ s +v s*
Not implemented due to time restrictions,
but should be possible, given that linStarExtend is implemented
in SemiLin.agda
-}
starExtend
: {n : ℕ}
-> (v1 v2 : Parikh n )
-> ( s ss : SemiLinSet n)
-> ss ≡ starSemiLin s
-> InSemiLin v1 s
-> InSemiLin v2 ss
-> InSemiLin (v1 +v v2) (starSemiLin s)
starExtend v1 v2 s ss spf inS inSS = {!!}
{-
Show that s* ⊇ s +v s*
Not completely implemented due to time restrictions,
but should be possible, given that linStarDecomp is implemented
in SemiLin.agda.
There are also some hard parts, for example, dealing with the proofs
that the returned vectors are non-zero (otherwise, we'd just trivially return v0 and v)
-}
starDecomp
: {n : ℕ}
-> (v : Parikh n)
-> (s ss : SemiLinSet n)
-> v ≢ v0
-> ss ≡ starSemiLin s
-> InSemiLin v ss
-> (∃ λ v1 -> ∃ λ v2 -> v1 +v v2 ≡ v × InSemiLin v1 s × InSemiLin v2 ss × v1 ≢ v0 )
starDecomp v s ss vpf spf inSemi = {!!}
{-
starDecomp v sh st .(sh ∷ st) .((v0 , 0 , []) ∷ starSum sh st ∷ []) vnz refl refl (InHead .v .(v0 , 0 , []) .(starSum sh st ∷ []) x) with emptyCombZero v x | vnz (emptyCombZero v x)
starDecomp .v0 sh st .(sh ∷ st) .((v0 , zero , []) ∷ [] Data.List.++ starSum sh st ∷ []) vnz refl refl (InHead .v0 .(v0 , zero , []) .(starSum sh st ∷ []) x) | refl | ()
starDecomp v sh [] .(sh ∷ []) .((v0 , 0 , []) ∷ (proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) ∷ []) vnz refl refl (InTail .v .(v0 , 0 , []) .((proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) ∷ []) (InHead .v .(proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) .[] starComb)) with linStarDecomp v sh _ vnz {!!} refl starComb
starDecomp v sh [] .(sh ∷ []) .((v0 , zero , []) ∷ [] Data.List.++ starSum sh [] ∷ []) vnz refl refl (InTail .v .(v0 , zero , []) .(starSum sh [] ∷ []) (InHead .v .(proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) .[] starComb)) | inj₁ lComb = v , v0 , v0identRight , InHead v sh [] lComb , InHead v0 (v0 , zero , []) _ (v0 , refl) , vnz
starDecomp v sh [] .(sh ∷ []) .((v0 , zero , []) ∷ [] Data.List.++ starSum sh [] ∷ []) vnz refl refl (InTail .v .(v0 , zero , []) .(starSum sh [] ∷ []) (InHead .v .(proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) .[] starComb)) | inj₂ (v1 , v2 , sumPf , comb1 , comb2 , zpf ) = v1 , v2 , sumPf , InHead v1 sh [] comb1 , InTail v2 (v0 , zero , []) _ (InHead v2 _ [] comb2) , zpf
starDecomp v sh [] .(sh ∷ []) .((v0 , 0 , []) ∷ (proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) ∷ []) vnz refl refl (InTail .v .(v0 , 0 , []) .((proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) ∷ []) (InTail .v .(proj₁ sh , suc (proj₁ (proj₂ sh)) , proj₁ sh ∷ proj₂ (proj₂ sh)) .[] ()))
starDecomp v sh (x ∷ st) .(sh ∷ x ∷ st) .((v0 , 0 , []) ∷ (proj₁ x +v proj₁ (starSum sh st) , suc (proj₁ (proj₂ x) + proj₁ (proj₂ (starSum sh st))) , proj₁ x ∷ proj₂ (proj₂ x) Data.Vec.++ proj₂ (proj₂ (starSum sh st))) ∷ []) vnz refl refl (InTail .v .(v0 , 0 , []) .((proj₁ x +v proj₁ (starSum sh st) , suc (proj₁ (proj₂ x) + proj₁ (proj₂ (starSum sh st))) , proj₁ x ∷ proj₂ (proj₂ x) Data.Vec.++ proj₂ (proj₂ (starSum sh st))) ∷ []) inSemi) = {!!} -}
--Stolen from the stdlib
listIdentity : {A : Set} -> (x : List A) -> (x Data.List.++ [] ) ≡ x
listIdentity [] = refl
listIdentity (x ∷ xs) = cong (_∷_ x) (listIdentity xs)
{-
Show that +s is actually the sum of two sets, that is,
if v1 is in S1, and v2 is in S2, then v1 +v v2
is in S1 +s S2
-}
sumPreserved :
{n : ℕ}
-> (u : Parikh n)
-> (v : Parikh n)
-- -> (uv : Parikh n)
-> (su : SemiLinSet n)
-> (sv : SemiLinSet n)
-- -> (suv : SemiLinSet n)
-- -> (uv ≡ u +v v)
-- -> (suv ≡ su +s sv)
-> InSemiLin u su
-> InSemiLin v sv
-> InSemiLin (u +v v) (su +s sv)
sumPreserved u v .((ub , um , uvecs) ∷ st) .((vb , vm , vvecs) ∷ st₁) (InHead .u (ub , um , uvecs) st (uconsts , upf)) (InHead .v (vb , vm , vvecs) st₁ (vconsts , vpf))
rewrite upf | vpf
= InHead (u +v v) (ub +v vb , um + vm , uvecs Data.Vec.++ vvecs) (Data.List.map (_+l_ (ub , um , uvecs)) st₁ Data.List.++
Data.List.foldr Data.List._++_ []
(Data.List.map
(λ z → z +l (vb , vm , vvecs) ∷ Data.List.map (_+l_ z) st₁) st))
((uconsts Data.Vec.++ vconsts) , trans (combSplit ub vb um vm uvecs vvecs uconsts vconsts)
(sym (subst (λ x → u +v v ≡ x +v applyLinComb vb vm vvecs vconsts) (sym upf) (cong (λ x → u +v x) (sym vpf)))) )
sumPreserved u v .(sh ∷ st) .(sh₁ ∷ st₁) (InHead .u sh st x) (InTail .v sh₁ st₁ vIn) =
let
subCall1 : InSemiLin (u +v v) ((sh ∷ []) +s st₁)
subCall1 = sumPreserved u v (sh ∷ []) ( st₁) (InHead u sh [] x) vIn
eqTest : (sh ∷ []) +s ( st₁) ≡ Data.List.map (λ l2 → sh +l l2) st₁
eqTest =
begin
(sh ∷ []) +s (st₁)
≡⟨ refl ⟩
Data.List.map (λ l2 → sh +l l2) ( st₁) Data.List.++ []
≡⟨ listIdentity (Data.List.map (_+l_ sh) st₁) ⟩
Data.List.map (λ l2 → sh +l l2) (st₁)
≡⟨ refl ⟩
(Data.List.map (λ l2 → sh +l l2) st₁ ∎)
newCall = slExtend (u +v v) (Data.List.map (_+l_ sh) st₁) (subst (InSemiLin (u +v v)) eqTest subCall1) (sh +l sh₁) --
in slConcatRight (u +v v) (Data.List.map (λ l2 → sh +l l2) (sh₁ ∷ st₁)) newCall (Data.List.foldr Data.List._++_ []
(Data.List.map (λ z → z +l sh₁ ∷ Data.List.map (_+l_ z) st₁) st))
sumPreserved u v .(sh ∷ st) sv (InTail .u sh st uIn) vIn =
(slConcatLeft (u +v v) (st +s sv) (sumPreserved u v st sv uIn vIn) (Data.List.map (λ x → sh +l x) sv))
--A useful lemma, avoids having to dig into the List monoid instance
rightCons : {A : Set} -> (l : List A) -> (l Data.List.++ [] ≡ l)
rightCons [] = refl
rightCons (x ∷ l) rewrite rightCons l = refl
{-
Show that, if a vector is in the union of two semi-linear sets,
then it must be in one of those sets.
Used in the proof for Union.
Called concat because we represent semi-linear sets as lists,
so union is just concatenating two semi-linear sets
-}
decomposeConcat
: {n : ℕ}
-> (v : Parikh n)
-> (s1 s2 s3 : SemiLinSet n)
-> (s3 ≡ s1 Data.List.++ s2 )
-> InSemiLin v s3
-> InSemiLin v s1 ⊎ InSemiLin v s2
decomposeConcat v [] s2 .s2 refl inSemi = inj₂ inSemi
decomposeConcat v (x ∷ s1) s2 .(x ∷ s1 Data.List.++ s2) refl (InHead .v .x .(s1 Data.List.++ s2) x₁) = inj₁ (InHead v x s1 x₁)
decomposeConcat v (x ∷ s1) s2 .(x ∷ s1 Data.List.++ s2) refl (InTail .v .x .(s1 Data.List.++ s2) inSemi) with decomposeConcat v s1 s2 _ refl inSemi
decomposeConcat v (x₁ ∷ s1) s2 .(x₁ ∷ s1 Data.List.++ s2) refl (InTail .v .x₁ .(s1 Data.List.++ s2) inSemi) | inj₁ x = inj₁ (InTail v x₁ s1 x)
decomposeConcat v (x ∷ s1) s2 .(x ∷ s1 Data.List.++ s2) refl (InTail .v .x .(s1 Data.List.++ s2) inSemi) | inj₂ y = inj₂ y
concatEq : {n : ℕ} -> (l : LinSet n) -> (s : SemiLinSet n) -> (l ∷ []) +s s ≡ (Data.List.map (_+l_ l) s)
concatEq l [] = refl
concatEq l (x ∷ s) rewrite concatEq l s | listIdentity (l ∷ []) = refl
{-
Show that if v is in l1 +l l2, then v = v1 +v v2 for some
v1 in l1 and v2 in l2.
This is the other half of the correcness proof of our sum functions, +l and +s
-}
decomposeLin
: {n : ℕ}
-> (v : Parikh n)
-> (l1 l2 l3 : LinSet n)
-> (l3 ≡ l1 +l l2 )
-> LinComb v l3
-> ∃ λ v1 → ∃ λ v2 -> (v1 +v v2 ≡ v) × (LinComb v1 l1) × (LinComb v2 l2 )
decomposeLin .(applyLinComb (b1 +v b2) (m1 + m2) (vecs1 Data.Vec.++ vecs2) coeffs) (b1 , m1 , vecs1) (b2 , m2 , vecs2) .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) refl (coeffs , refl) with Data.Vec.splitAt m1 coeffs
decomposeLin .(applyLinComb (b1 +v b2) (m1 + m2) (vecs1 Data.Vec.++ vecs2) (coeffs1 Data.Vec.++ coeffs2)) (b1 , m1 , vecs1) (b2 , m2 , vecs2) .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) refl (.(coeffs1 Data.Vec.++ coeffs2) , refl) | coeffs1 , coeffs2 , refl rewrite combSplit b1 b2 m1 m2 vecs1 vecs2 coeffs1 coeffs2
= applyLinComb b1 m1 vecs1 coeffs1 , (applyLinComb b2 m2 vecs2 coeffs2 , (refl , ((coeffs1 , refl) , (coeffs2 , refl))))
{-
Show that our Parikh function is a superset of the actual Parikh image of a Regular Expression.
We do this by showing that, for every word matching an RE, its Parikh vector
is in the Parikh Image of the RE
-}
reParikhCorrect :
{n : ℕ}
-> {null? : RETypes.Null?}
-> (cmap : Char -> Fin.Fin n)
-> (r : RETypes.RE null?)
-> (w : List Char )
-> RETypes.REMatch w r
-> (wordPar : Parikh n)
-> (wordParikh cmap w ≡ wordPar)
-> (langParikh : SemiLinSet n)
-> (langParikh ≡ reSemiLin cmap r )
-> (InSemiLin wordPar langParikh )
reParikhCorrect cmap .RETypes.ε .[] RETypes.EmptyMatch .v0 refl .((v0 , 0 , []) ∷ []) refl = InHead v0 (v0 , zero , []) [] ([] , refl)
reParikhCorrect cmap .(RETypes.Lit c) .(c ∷ []) (RETypes.LitMatch c) .(basis (cmap c) +v v0) refl .((basis (cmap c) , 0 , []) ∷ []) refl =
InHead (basis (cmap c) +v v0) (basis (cmap c) , zero , []) [] (subst (λ x → LinComb x (basis (cmap c) , zero , [])) (sym v0identRight) (v0 , (v0apply (basis (cmap c)) [])))
reParikhCorrect cmap (r1 RETypes.+ .r2) w (RETypes.LeftPlusMatch r2 match) wordPar wpf langParikh lpf =
let
leftParikh = reSemiLin cmap r1
leftInSemi = reParikhCorrect cmap r1 w match wordPar wpf leftParikh refl
--Idea: show that langParikh is leftParikh ++ rightParikh
--And that this means that it must be in the concatentation
extendToConcat : InSemiLin wordPar ((reSemiLin cmap r1 ) Data.List.++ (reSemiLin cmap r2))
extendToConcat = slConcatRight wordPar (reSemiLin cmap r1) leftInSemi (reSemiLin cmap r2)
in subst (λ x → InSemiLin wordPar x) (sym lpf) extendToConcat
reParikhCorrect cmap (.r1 RETypes.+ r2) w (RETypes.RightPlusMatch r1 match) wordPar wpf langParikh lpf = let
rightParikh = reSemiLin cmap r2
rightInSemi = reParikhCorrect cmap r2 w match wordPar wpf rightParikh refl
--Idea: show that langParikh is leftParikh ++ rightParikh
--And that this means that it must be in the concatentation
extendToConcat : InSemiLin wordPar ((reSemiLin cmap r1 ) Data.List.++ (reSemiLin cmap r2))
extendToConcat = slConcatLeft wordPar (reSemiLin cmap r2) rightInSemi (reSemiLin cmap r1)
in subst (λ x → InSemiLin wordPar x) (sym lpf) extendToConcat
reParikhCorrect cmap (r1 RETypes.· r2) s3 (RETypes.ConcatMatch {s1 = s1} {s2 = s2} {spf = spf} match1 match2) .(wordParikh cmap s3) refl ._ refl rewrite (sym spf) | (wordParikhPlus cmap s1 s2) =
let
leftParikh = reSemiLin cmap r1
leftInSemi : InSemiLin (wordParikh cmap s1) leftParikh
leftInSemi = reParikhCorrect cmap r1 s1 match1 (wordParikh cmap s1) refl (reSemiLin cmap r1) refl
rightParikh = reSemiLin cmap r2
rightInSemi : InSemiLin (wordParikh cmap s2) rightParikh
rightInSemi = reParikhCorrect cmap r2 s2 match2 (wordParikh cmap s2) refl (reSemiLin cmap r2) refl
wordParikhIsPlus : (wordParikh cmap s1) +v (wordParikh cmap s2) ≡ (wordParikh cmap (s1 Data.List.++ s2 ))
wordParikhIsPlus = sym (wordParikhPlus cmap s1 s2)
in sumPreserved (wordParikh cmap s1) (wordParikh cmap s2) leftParikh rightParikh leftInSemi rightInSemi
reParikhCorrect cmap (r RETypes.*) [] RETypes.EmptyStarMatch .v0 refl .(starSemiLin (reSemiLin cmap r)) refl = zeroInStar (reSemiLin cmap r) (starSemiLin (reSemiLin cmap r)) refl
reParikhCorrect cmap (r RETypes.*) .(s1 Data.List.++ s2 ) (RETypes.StarMatch {s1 = s1} {s2 = s2} {spf = refl} m1 m2) ._ refl .(starSemiLin (reSemiLin cmap r)) refl rewrite wordParikhPlus cmap s1 s2 =
starExtend (wordParikh cmap s1) (wordParikh cmap s2) (reSemiLin cmap r) _ refl (reParikhCorrect cmap r s1 m1 (wordParikh cmap s1) refl (reSemiLin cmap r) refl) (reParikhCorrect cmap (r RETypes.*) s2 m2 (wordParikh cmap s2) refl (starSemiLin (reSemiLin cmap r)) refl)
{-
Show that if v is in s1 +s s2, then v = v1 +v v2 for some
v1 in s1 and v2 in s2.
This is the other half of the correcness proof of our sum functions, +l and +s
-}
decomposeSum
: {n : ℕ}
-> (v : Parikh n)
-> (s1 s2 s3 : SemiLinSet n)
-> (s3 ≡ s1 +s s2 )
-> InSemiLin v s3
-> ∃ λ (v1 : Parikh n) → ∃ λ (v2 : Parikh n) -> (v1 +v v2 ≡ v) × (InSemiLin v1 s1) × (InSemiLin v2 s2 )
decomposeSum v [] [] .[] refl ()
decomposeSum v [] (x ∷ s2) .[] refl ()
decomposeSum v (x ∷ s1) [] .(Data.List.foldr Data.List._++_ [] (Data.List.map (λ l1 → []) s1)) refl ()
decomposeSum v ((b1 , m1 , vecs1) ∷ s1) ((b2 , m2 , vecs2) ∷ s2) ._ refl (InHead .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) ._ lcomb) =
let
(v1 , v2 , plusPf , comb1 , comb2 ) = decomposeLin v (b1 , m1 , vecs1) (b2 , m2 , vecs2) (b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) refl lcomb
in v1 , v2 , plusPf , InHead v1 (b1 , m1 , vecs1) s1 comb1 , InHead v2 (b2 , m2 , vecs2) s2 comb2
decomposeSum v ((b1 , m1 , vecs1) ∷ s1) ((b2 , m2 , vecs2) ∷ s2) ._ refl (InTail .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) ._ inSemi) with decomposeConcat v (Data.List.map (_+l_ (b1 , m1 , vecs1)) s2) (Data.List.foldr Data.List._++_ []
(Data.List.map
(λ z → z +l (b2 , m2 , vecs2) ∷ Data.List.map (_+l_ z) s2) s1)) (Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++
Data.List.foldr Data.List._++_ []
(Data.List.map
(λ z → z +l (b2 , m2 , vecs2) ∷ Data.List.map (_+l_ z) s2) s1)) refl inSemi
decomposeSum v ((b1 , m1 , vecs1) ∷ s1) ((b2 , m2 , vecs2) ∷ s2) .((b1 , m1 , vecs1) +l (b2 , m2 , vecs2) ∷ Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) refl (InTail .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) .(Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) inSemi) | inj₁ inSub =
let
subCall1 = decomposeSum v ((b1 , m1 , vecs1) ∷ []) s2 _ refl (subst (λ x → InSemiLin v x) (sym (concatEq (b1 , m1 , vecs1) s2)) inSub)
v1 , v2 , pf , xIn , yIn = subCall1
in v1 , (v2 , (pf , (slCons v1 s1 (b1 , m1 , vecs1) xIn , slExtend v2 s2 yIn (b2 , m2 , vecs2))))
decomposeSum v ((b1 , m1 , vecs1) ∷ s1) ((b2 , m2 , vecs2) ∷ s2) .((b1 , m1 , vecs1) +l (b2 , m2 , vecs2) ∷ Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) refl (InTail .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) .(Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) inSemi) | inj₂ inSub =
let
subCall1 = decomposeSum v s1 ((b2 , m2 , vecs2) ∷ s2) _ refl inSub
v1 , v2 , pf , xIn , yIn = subCall1
in v1 , v2 , pf , slExtend v1 s1 xIn (b1 , m1 , vecs1) , yIn
{-
Show that the generated Parikh image is a subset of the actual Parikh image.
We do this by showing that, for every vector in the generated Parikh image,
there's some word matched by the RE whose Parikh vector is that vector.
-}
--We have to convince the compiler that this is terminating
--Since I didn't have time to implement the proofs of non-zero vectors
--Which show that we only recurse on strictly smaller vectors in the Star case
{-# TERMINATING #-}
reParikhComplete : {n : ℕ} -> {null? : RETypes.Null?}
-> (cmap : Char -> Fin.Fin n)
-- -> (imap : Fin.Fin n -> Char)
-- -> (invPf1 : (x : Char ) -> imap (cmap x) ≡ x)
-- -> (invPf2 : (x : Fin.Fin n ) -> cmap (imap x) ≡ x )
-> (r : RETypes.RE null?)
-> (v : Parikh n )
-> (langParikh : SemiLinSet n)
-> langParikh ≡ (reSemiLin cmap r )
-> (InSemiLin v langParikh )
-> ∃ (λ w -> (v ≡ wordParikh cmap w) × (RETypes.REMatch w r) )
reParikhComplete cmap RETypes.ε .v0 .((v0 , 0 , []) ∷ []) refl (InHead .v0 .(v0 , 0 , []) .[] (combConsts , refl)) = [] , refl , RETypes.EmptyMatch
reParikhComplete cmap RETypes.ε v .((v0 , 0 , []) ∷ []) refl (InTail .v .(v0 , 0 , []) .[] ())
--reParikhComplete cmap RETypes.ε v .(sh ∷ st) lpf (InTail .v sh st inSemi) = {!!}
reParikhComplete cmap RETypes.∅ v [] lpf ()
reParikhComplete cmap RETypes.∅ v (h ∷ t) () inSemi
reParikhComplete cmap (RETypes.Lit x) langParikh [] inSemi ()
reParikhComplete cmap (RETypes.Lit x) .(basis (cmap x)) .((basis (cmap x) , 0 , []) ∷ []) refl (InHead .(basis (cmap x)) .(basis (cmap x) , 0 , []) .[] (consts , refl)) = (x ∷ []) , (sym v0identRight , RETypes.LitMatch x)
reParikhComplete cmap (RETypes.Lit x) v .((basis (cmap x) , 0 , []) ∷ []) refl (InTail .v .(basis (cmap x) , 0 , []) .[] ())
--reParikhComplete cmap (RETypes.Lit x) v .((basis (cmap x) , 0 , []) ∷ []) refl (InTail .v .(basis (cmap x) , 0 , []) .[] ())
reParikhComplete {null? = null?} cmap (r1 RETypes.+ r2) v langParikh lpf inSemi with decomposeConcat v (reSemiLin cmap r1) (reSemiLin cmap r2) langParikh lpf inSemi
... | inj₁ in1 =
let
(subw , subPf , subMatch) = reParikhComplete cmap r1 v (reSemiLin cmap r1) refl in1
in subw , (subPf , (RETypes.LeftPlusMatch r2 subMatch))
... | inj₂ in2 =
let
(subw , subPf , subMatch) = reParikhComplete cmap r2 v (reSemiLin cmap r2) refl in2
in subw , (subPf , (RETypes.RightPlusMatch r1 subMatch))
reParikhComplete cmap (r1 RETypes.· r2) v ._ refl inSemi with decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2) (reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi | reParikhComplete cmap r1 (proj₁ (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)
(reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi)) (reSemiLin cmap r1) refl (proj₁ (proj₂ (proj₂ (proj₂ (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)
(reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi))))) | reParikhComplete cmap r2 (proj₁ (proj₂ (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)
(reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi))) (reSemiLin cmap r2) refl (proj₂ (proj₂ (proj₂ (proj₂ (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)
(reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi)))))
reParikhComplete cmap (r1 RETypes.· r2) .(wordParikh cmap w1 +v wordParikh cmap w2) .(Data.List.foldr Data.List._++_ [] (Data.List.map _ (reSemiLin cmap r1))) refl inSemi | .(wordParikh cmap w1) , .(wordParikh cmap w2) , refl , inSemi1 , inSemi2 | w1 , refl , match1 | w2 , refl , match2 = (w1 Data.List.++ w2) , ((sym (wordParikhPlus cmap w1 w2)) , (RETypes.ConcatMatch match1 match2))
reParikhComplete cmap (r RETypes.*) v langParikh lpf inSemi with (reSemiLin cmap r )
reParikhComplete cmap (r RETypes.*) v .((v0 , 0 , []) ∷ []) refl (InHead .v .(v0 , 0 , []) .[] x) | [] = [] , ((sym (proj₂ x)) , RETypes.EmptyStarMatch)
reParikhComplete cmap (r RETypes.*) v .((v0 , 0 , []) ∷ []) refl (InTail .v .(v0 , 0 , []) .[] ()) | []
reParikhComplete cmap (r RETypes.*) v .((v0 , 0 , []) ∷ starSum x rsl ∷ []) refl inSemi | x ∷ rsl =
let
--The first hole is the non-zero proofs that I couldn't work out
--I'm not totally sure about the second, but I think I just need to apply some associativity to inSemi to get it to fit
--into the second hole.
splitVec = starDecomp v (reSemiLin cmap r) _ {!!} refl {!!}
v1 , v2 , vpf , inS , inSS , _ = splitVec
subCall1 = reParikhComplete cmap r v1 _ refl inS
w1 , wpf1 , match = subCall1
subCall2 = reParikhComplete cmap (r RETypes.*) v2 _ refl inSS
w2 , wpf2 , match2 = subCall2
in (w1 Data.List.++ w2) , (trans (sym vpf) (sym (wordParikhPlus cmap w1 w2)) , RETypes.StarMatch match match2)
| 60.226829 | 590 | 0.553922 |
230581f6984d3aa2d3b109a078ec9fa2d7b8bb0f | 488 | agda | Agda | agda/TreeSort/Impl1.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | 6 | 2015-05-21T12:50:35.000Z | 2021-08-24T22:11:15.000Z | agda/TreeSort/Impl1.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | agda/TreeSort/Impl1.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | open import Relation.Binary.Core
module TreeSort.Impl1 {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import BTree {A}
open import Data.List
open import Data.Sum
insert : A → BTree → BTree
insert x leaf = node x leaf leaf
insert x (node y l r)
with tot≤ x y
... | inj₁ x≤y = node y (insert x l) r
... | inj₂ y≤x = node y l (insert x r)
treeSort : List A → BTree
treeSort [] = leaf
treeSort (x ∷ xs) = insert x (treeSort xs)
| 19.52 | 43 | 0.586066 |
0e640b3a95da81aef38c6c3894038523065ffc3a | 24,698 | agda | Agda | src/bijection.agda | shinji-kono/HyperReal-in-agda | 64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891 | [
"MIT"
] | null | null | null | src/bijection.agda | shinji-kono/HyperReal-in-agda | 64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891 | [
"MIT"
] | null | null | null | src/bijection.agda | shinji-kono/HyperReal-in-agda | 64d5f1ec0a6d81b7b9c45a289f669bbf32c9c891 | [
"MIT"
] | null | null | null | module bijection where
open import Level renaming ( zero to Zero ; suc to Suc )
open import Data.Nat
open import Data.Maybe
open import Data.List hiding ([_] ; sum )
open import Data.Nat.Properties
open import Relation.Nullary
open import Data.Empty
open import Data.Unit hiding ( _≤_ )
open import Relation.Binary.Core hiding (_⇔_)
open import Relation.Binary.Definitions
open import Relation.Binary.PropositionalEquality
open import logic
open import nat
-- record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.⊔ m) where
-- field
-- fun← : S → R
-- fun→ : R → S
-- fiso← : (x : R) → fun← ( fun→ x ) ≡ x
-- fiso→ : (x : S ) → fun→ ( fun← x ) ≡ x
--
-- injection : {n m : Level} (R : Set n) (S : Set m) (f : R → S ) → Set (n Level.⊔ m)
-- injection R S f = (x y : R) → f x ≡ f y → x ≡ y
open Bijection
bi-trans : {n m l : Level} (R : Set n) (S : Set m) (T : Set l) → Bijection R S → Bijection S T → Bijection R T
bi-trans R S T rs st = record { fun← = λ x → fun← rs ( fun← st x ) ; fun→ = λ x → fun→ st ( fun→ rs x )
; fiso← = λ x → trans (cong (λ k → fun← rs k) (fiso← st (fun→ rs x))) ( fiso← rs x)
; fiso→ = λ x → trans (cong (λ k → fun→ st k) (fiso→ rs (fun← st x))) ( fiso→ st x) }
bid : {n : Level} (R : Set n) → Bijection R R
bid {n} R = record { fun← = λ x → x ; fun→ = λ x → x ; fiso← = λ _ → refl ; fiso→ = λ _ → refl }
bi-sym : {n m : Level} (R : Set n) (S : Set m) → Bijection R S → Bijection S R
bi-sym R S eq = record { fun← = fun→ eq ; fun→ = fun← eq ; fiso← = fiso→ eq ; fiso→ = fiso← eq }
open import Relation.Binary.Structures
bijIsEquivalence : {n : Level } → IsEquivalence (Bijection {n} {n})
bijIsEquivalence = record { refl = λ {R} → bid R ; sym = λ {R} {S} → bi-sym R S ; trans = λ {R} {S} {T} → bi-trans R S T }
-- ¬ A = A → ⊥
--
-- famous diagnostic function
--
diag : {S : Set } (b : Bijection ( S → Bool ) S) → S → Bool
diag b n = not (fun← b n n)
diagonal : { S : Set } → ¬ Bijection ( S → Bool ) S
diagonal {S} b = diagn1 (fun→ b (λ n → diag b n) ) refl where
diagn1 : (n : S ) → ¬ (fun→ b (λ n → diag b n) ≡ n )
diagn1 n dn = ¬t=f (diag b n ) ( begin
not (diag b n)
≡⟨⟩
not (not fun← b n n)
≡⟨ cong (λ k → not (k n) ) (sym (fiso← b _)) ⟩
not (fun← b (fun→ b (diag b)) n)
≡⟨ cong (λ k → not (fun← b k n) ) dn ⟩
not (fun← b n n)
≡⟨⟩
diag b n
∎ ) where open ≡-Reasoning
b1 : (b : Bijection ( ℕ → Bool ) ℕ) → ℕ
b1 b = fun→ b (diag b)
b-iso : (b : Bijection ( ℕ → Bool ) ℕ) → fun← b (b1 b) ≡ (diag b)
b-iso b = fiso← b _
--
-- ℕ <=> ℕ + 1
--
to1 : {n : Level} {R : Set n} → Bijection ℕ R → Bijection ℕ (⊤ ∨ R )
to1 {n} {R} b = record {
fun← = to11
; fun→ = to12
; fiso← = to13
; fiso→ = to14
} where
to11 : ⊤ ∨ R → ℕ
to11 (case1 tt) = 0
to11 (case2 x) = suc ( fun← b x )
to12 : ℕ → ⊤ ∨ R
to12 zero = case1 tt
to12 (suc n) = case2 ( fun→ b n)
to13 : (x : ℕ) → to11 (to12 x) ≡ x
to13 zero = refl
to13 (suc x) = cong suc (fiso← b x)
to14 : (x : ⊤ ∨ R) → to12 (to11 x) ≡ x
to14 (case1 x) = refl
to14 (case2 x) = cong case2 (fiso→ b x)
open _∧_
record NN ( i : ℕ) (nxn→n : ℕ → ℕ → ℕ) (n→nxn : ℕ → ℕ ∧ ℕ) : Set where
field
j k sum stage : ℕ
nn : j + k ≡ sum
ni : i ≡ j + stage -- not used
k1 : nxn→n j k ≡ i
k0 : n→nxn i ≡ ⟪ j , k ⟫
nn-unique : {j0 k0 : ℕ } → nxn→n j0 k0 ≡ i → ⟪ j , k ⟫ ≡ ⟪ j0 , k0 ⟫
i≤0→i≡0 : {i : ℕ } → i ≤ 0 → i ≡ 0
i≤0→i≡0 {0} z≤n = refl
nxn : Bijection ℕ (ℕ ∧ ℕ)
nxn = record {
fun← = λ p → nxn→n (proj1 p) (proj2 p)
; fun→ = n→nxn
; fiso← = n-id
; fiso→ = λ x → nn-id (proj1 x) (proj2 x)
} where
nxn→n : ℕ → ℕ → ℕ
nxn→n zero zero = zero
nxn→n zero (suc j) = j + suc (nxn→n zero j)
nxn→n (suc i) zero = suc i + suc (nxn→n i zero)
nxn→n (suc i) (suc j) = suc i + suc j + suc (nxn→n i (suc j))
n→nxn : ℕ → ℕ ∧ ℕ
n→nxn zero = ⟪ 0 , 0 ⟫
n→nxn (suc i) with n→nxn i
... | ⟪ x , zero ⟫ = ⟪ zero , suc x ⟫
... | ⟪ x , suc y ⟫ = ⟪ suc x , y ⟫
nxn→n0 : { j k : ℕ } → nxn→n j k ≡ 0 → ( j ≡ 0 ) ∧ ( k ≡ 0 )
nxn→n0 {zero} {zero} eq = ⟪ refl , refl ⟫
nxn→n0 {zero} {(suc k)} eq = ⊥-elim ( nat-≡< (sym eq) (subst (λ k → 0 < k) (+-comm _ k) (s≤s z≤n)))
nxn→n0 {(suc j)} {zero} eq = ⊥-elim ( nat-≡< (sym eq) (s≤s z≤n) )
nxn→n0 {(suc j)} {(suc k)} eq = ⊥-elim ( nat-≡< (sym eq) (s≤s z≤n) )
nid20 : (i : ℕ) → i + (nxn→n 0 i) ≡ nxn→n i 0
nid20 zero = refl -- suc (i + (i + suc (nxn→n 0 i))) ≡ suc (i + suc (nxn→n i 0))
nid20 (suc i) = begin
suc (i + (i + suc (nxn→n 0 i))) ≡⟨ cong (λ k → suc (i + k)) (sym (+-assoc i 1 (nxn→n 0 i))) ⟩
suc (i + ((i + 1) + nxn→n 0 i)) ≡⟨ cong (λ k → suc (i + (k + nxn→n 0 i))) (+-comm i 1) ⟩
suc (i + suc (i + nxn→n 0 i)) ≡⟨ cong ( λ k → suc (i + suc k)) (nid20 i) ⟩
suc (i + suc (nxn→n i 0)) ∎ where open ≡-Reasoning
nid4 : {i j : ℕ} → i + 1 + j ≡ i + suc j
nid4 {zero} {j} = refl
nid4 {suc i} {j} = cong suc (nid4 {i} {j} )
nid5 : {i j k : ℕ} → i + suc (suc j) + suc k ≡ i + suc j + suc (suc k )
nid5 {zero} {j} {k} = begin
suc (suc j) + suc k ≡⟨ +-assoc 1 (suc j) _ ⟩
1 + (suc j + suc k) ≡⟨ +-comm 1 _ ⟩
(suc j + suc k) + 1 ≡⟨ +-assoc (suc j) (suc k) _ ⟩
suc j + (suc k + 1) ≡⟨ cong (λ k → suc j + k ) (+-comm (suc k) 1) ⟩
suc j + suc (suc k) ∎ where open ≡-Reasoning
nid5 {suc i} {j} {k} = cong suc (nid5 {i} {j} {k} )
-- increment in ths same stage
nid2 : (i j : ℕ) → suc (nxn→n i (suc j)) ≡ nxn→n (suc i) j
nid2 zero zero = refl
nid2 zero (suc j) = refl
nid2 (suc i) zero = begin
suc (nxn→n (suc i) 1) ≡⟨ refl ⟩
suc (suc (i + 1 + suc (nxn→n i 1))) ≡⟨ cong (λ k → suc (suc k)) nid4 ⟩
suc (suc (i + suc (suc (nxn→n i 1)))) ≡⟨ cong (λ k → suc (suc (i + suc (suc k)))) (nid3 i) ⟩
suc (suc (i + suc (suc (i + suc (nxn→n i 0))))) ≡⟨ refl ⟩
nxn→n (suc (suc i)) zero ∎ where
open ≡-Reasoning
nid3 : (i : ℕ) → nxn→n i 1 ≡ i + suc (nxn→n i 0)
nid3 zero = refl
nid3 (suc i) = begin
suc (i + 1 + suc (nxn→n i 1)) ≡⟨ cong suc nid4 ⟩
suc (i + suc (suc (nxn→n i 1))) ≡⟨ cong (λ k → suc (i + suc (suc k))) (nid3 i) ⟩
suc (i + suc (suc (i + suc (nxn→n i 0)))) ∎
nid2 (suc i) (suc j) = begin
suc (nxn→n (suc i) (suc (suc j))) ≡⟨ refl ⟩
suc (suc (i + suc (suc j) + suc (nxn→n i (suc (suc j))))) ≡⟨ cong (λ k → suc (suc (i + suc (suc j) + k))) (nid2 i (suc j)) ⟩
suc (suc (i + suc (suc j) + suc (i + suc j + suc (nxn→n i (suc j))))) ≡⟨ cong ( λ k → suc (suc k)) nid5 ⟩
suc (suc (i + suc j + suc (suc (i + suc j + suc (nxn→n i (suc j)))))) ≡⟨ refl ⟩
nxn→n (suc (suc i)) (suc j) ∎ where
open ≡-Reasoning
-- increment ths stage
nid00 : (i : ℕ) → suc (nxn→n i 0) ≡ nxn→n 0 (suc i)
nid00 zero = refl
nid00 (suc i) = begin
suc (suc (i + suc (nxn→n i 0))) ≡⟨ cong (λ k → suc (suc (i + k ))) (nid00 i) ⟩
suc (suc (i + (nxn→n 0 (suc i)))) ≡⟨ refl ⟩
suc (suc (i + (i + suc (nxn→n 0 i)))) ≡⟨ cong suc (sym ( +-assoc 1 i (i + suc (nxn→n 0 i)))) ⟩
suc ((1 + i) + (i + suc (nxn→n 0 i))) ≡⟨ cong (λ k → suc (k + (i + suc (nxn→n 0 i)))) (+-comm 1 i) ⟩
suc ((i + 1) + (i + suc (nxn→n 0 i))) ≡⟨ cong suc (+-assoc i 1 (i + suc (nxn→n 0 i))) ⟩
suc (i + suc (i + suc (nxn→n 0 i))) ∎ where open ≡-Reasoning
-----
--
-- create the invariant NN for all n
--
nn : ( i : ℕ) → NN i nxn→n n→nxn
nn zero = record { j = 0 ; k = 0 ; sum = 0 ; stage = 0 ; nn = refl ; ni = refl ; k1 = refl ; k0 = refl
; nn-unique = λ {j0} {k0} eq → cong₂ (λ x y → ⟪ x , y ⟫) (sym (proj1 (nxn→n0 eq))) (sym (proj2 (nxn→n0 {j0} {k0} eq))) }
nn (suc i) with NN.k (nn i) | inspect NN.k (nn i)
... | zero | record { eq = eq } = record { k = suc (NN.sum (nn i)) ; j = 0 ; sum = suc (NN.sum (nn i)) ; stage = suc (NN.sum (nn i)) + (NN.stage (nn i))
; nn = refl
; ni = nn01 ; k1 = nn02 ; k0 = nn03 ; nn-unique = nn04 } where
---
--- increment the stage
---
sum = NN.sum (nn i)
stage = NN.stage (nn i)
j = NN.j (nn i)
nn01 : suc i ≡ 0 + (suc sum + stage )
nn01 = begin
suc i ≡⟨ cong suc (NN.ni (nn i)) ⟩
suc ((NN.j (nn i) ) + stage ) ≡⟨ cong (λ k → suc (k + stage )) (+-comm 0 _ ) ⟩
suc ((NN.j (nn i) + 0 ) + stage ) ≡⟨ cong (λ k → suc ((NN.j (nn i) + k) + stage )) (sym eq) ⟩
suc ((NN.j (nn i) + NN.k (nn i)) + stage ) ≡⟨ cong (λ k → suc ( k + stage )) (NN.nn (nn i)) ⟩
0 + (suc sum + stage ) ∎ where open ≡-Reasoning
nn02 : nxn→n 0 (suc sum) ≡ suc i
nn02 = begin
sum + suc (nxn→n 0 sum) ≡⟨ sym (+-assoc sum 1 (nxn→n 0 sum)) ⟩
(sum + 1) + nxn→n 0 sum ≡⟨ cong (λ k → k + nxn→n 0 sum ) (+-comm sum 1 )⟩
suc (sum + nxn→n 0 sum) ≡⟨ cong suc (nid20 sum ) ⟩
suc (nxn→n sum 0) ≡⟨ cong (λ k → suc (nxn→n k 0 )) (sym (NN.nn (nn i))) ⟩
suc (nxn→n (NN.j (nn i) + (NN.k (nn i)) ) 0) ≡⟨ cong₂ (λ j k → suc (nxn→n (NN.j (nn i) + j) k )) eq (sym eq) ⟩
suc (nxn→n (NN.j (nn i) + 0 ) (NN.k (nn i))) ≡⟨ cong (λ k → suc ( nxn→n k (NN.k (nn i)))) (+-comm (NN.j (nn i)) 0) ⟩
suc (nxn→n (NN.j (nn i)) (NN.k (nn i))) ≡⟨ cong suc (NN.k1 (nn i) ) ⟩
suc i ∎ where open ≡-Reasoning
nn03 : n→nxn (suc i) ≡ ⟪ 0 , suc (NN.sum (nn i)) ⟫ -- k0 : n→nxn i ≡ ⟪ NN.j (nn i) = sum , NN.k (nn i) = 0 ⟫
nn03 with n→nxn i | inspect n→nxn i
... | ⟪ x , zero ⟫ | record { eq = eq1 } = begin
⟪ zero , suc x ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫) (sym (cong proj1 eq1)) ⟩
⟪ zero , suc (proj1 (n→nxn i)) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫) (cong proj1 (NN.k0 (nn i))) ⟩
⟪ zero , suc (NN.j (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫) (+-comm 0 _ ) ⟩
⟪ zero , suc (NN.j (nn i) + 0) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc (NN.j (nn i) + k) ⟫ ) (sym eq) ⟩
⟪ zero , suc (NN.j (nn i) + NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ zero , suc k ⟫ ) (NN.nn (nn i)) ⟩
⟪ 0 , suc sum ⟫ ∎ where open ≡-Reasoning
... | ⟪ x , suc y ⟫ | record { eq = eq1 } = ⊥-elim ( nat-≡< (sym (cong proj2 (NN.k0 (nn i)))) (begin
suc (NN.k (nn i)) ≡⟨ cong suc eq ⟩
suc 0 ≤⟨ s≤s z≤n ⟩
suc y ≡⟨ sym (cong proj2 eq1) ⟩
proj2 (n→nxn i) ∎ )) where open ≤-Reasoning
-- nid2 : (i j : ℕ) → suc (nxn→n i (suc j)) ≡ nxn→n (suc i) j
nn04 : {j0 k0 : ℕ} → nxn→n j0 k0 ≡ suc i → ⟪ 0 , suc (NN.sum (nn i)) ⟫ ≡ ⟪ j0 , k0 ⟫
nn04 {zero} {suc k0} eq1 = cong (λ k → ⟪ 0 , k ⟫ ) (cong suc (sym nn08)) where -- eq : nxn→n zero (suc k0) ≡ suc i --
nn07 : nxn→n k0 0 ≡ i
nn07 = cong pred ( begin
suc ( nxn→n k0 0 ) ≡⟨ nid00 k0 ⟩
nxn→n 0 (suc k0 ) ≡⟨ eq1 ⟩
suc i ∎ ) where open ≡-Reasoning
nn08 : k0 ≡ sum
nn08 = begin
k0 ≡⟨ cong proj1 (sym (NN.nn-unique (nn i) nn07)) ⟩
NN.j (nn i) ≡⟨ +-comm 0 _ ⟩
NN.j (nn i) + 0 ≡⟨ cong (λ k → NN.j (nn i) + k) (sym eq) ⟩
NN.j (nn i) + NN.k (nn i) ≡⟨ NN.nn (nn i) ⟩
sum ∎ where open ≡-Reasoning
nn04 {suc j0} {k0} eq1 = ⊥-elim ( nat-≡< (cong proj2 (nn06 nn05)) (subst (λ k → k < suc k0) (sym eq) (s≤s z≤n))) where
nn05 : nxn→n j0 (suc k0) ≡ i
nn05 = begin
nxn→n j0 (suc k0) ≡⟨ cong pred ( begin
suc (nxn→n j0 (suc k0)) ≡⟨ nid2 j0 k0 ⟩
nxn→n (suc j0) k0 ≡⟨ eq1 ⟩
suc i ∎ ) ⟩
i ∎ where open ≡-Reasoning
nn06 : nxn→n j0 (suc k0) ≡ i → ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ j0 , suc k0 ⟫
nn06 = NN.nn-unique (nn i)
... | suc k | record {eq = eq} = record { k = k ; j = suc (NN.j (nn i)) ; sum = NN.sum (nn i) ; stage = NN.stage (nn i) ; nn = nn10
; ni = cong suc (NN.ni (nn i)) ; k1 = nn11 ; k0 = nn12 ; nn-unique = nn13 } where
---
--- increment in a stage
---
nn10 : suc (NN.j (nn i)) + k ≡ NN.sum (nn i)
nn10 = begin
suc (NN.j (nn i)) + k ≡⟨ cong (λ x → x + k) (+-comm 1 _) ⟩
(NN.j (nn i) + 1) + k ≡⟨ +-assoc (NN.j (nn i)) 1 k ⟩
NN.j (nn i) + suc k ≡⟨ cong (λ k → NN.j (nn i) + k) (sym eq) ⟩
NN.j (nn i) + NN.k (nn i) ≡⟨ NN.nn (nn i) ⟩
NN.sum (nn i) ∎ where open ≡-Reasoning
nn11 : nxn→n (suc (NN.j (nn i))) k ≡ suc i -- nxn→n ( NN.j (nn i)) (NN.k (nn i) ≡ i
nn11 = begin
nxn→n (suc (NN.j (nn i))) k ≡⟨ sym (nid2 (NN.j (nn i)) k) ⟩
suc (nxn→n (NN.j (nn i)) (suc k)) ≡⟨ cong (λ k → suc (nxn→n (NN.j (nn i)) k)) (sym eq) ⟩
suc (nxn→n ( NN.j (nn i)) (NN.k (nn i))) ≡⟨ cong suc (NN.k1 (nn i)) ⟩
suc i ∎ where open ≡-Reasoning
nn18 : zero < NN.k (nn i)
nn18 = subst (λ k → 0 < k ) ( begin
suc k ≡⟨ sym eq ⟩
NN.k (nn i) ∎ ) (s≤s z≤n ) where open ≡-Reasoning
nn12 : n→nxn (suc i) ≡ ⟪ suc (NN.j (nn i)) , k ⟫ -- n→nxn i ≡ ⟪ NN.j (nn i) , NN.k (nn i) ⟫
nn12 with n→nxn i | inspect n→nxn i
... | ⟪ x , zero ⟫ | record { eq = eq1 } = ⊥-elim ( nat-≡< (sym (cong proj2 eq1))
(subst (λ k → 0 < k ) ( begin
suc k ≡⟨ sym eq ⟩
NN.k (nn i) ≡⟨ cong proj2 (sym (NN.k0 (nn i)) ) ⟩
proj2 (n→nxn i) ∎ ) (s≤s z≤n )) ) where open ≡-Reasoning -- eq1 n→nxn i ≡ ⟪ x , zero ⟫
... | ⟪ x , suc y ⟫ | record { eq = eq1 } = begin -- n→nxn i ≡ ⟪ x , suc y ⟫
⟪ suc x , y ⟫ ≡⟨ refl ⟩
⟪ suc x , pred (suc y) ⟫ ≡⟨ cong (λ k → ⟪ suc (proj1 k) , pred (proj2 k) ⟫) ( begin
⟪ x , suc y ⟫ ≡⟨ sym eq1 ⟩
n→nxn i ≡⟨ NN.k0 (nn i) ⟩
⟪ NN.j (nn i) , NN.k (nn i) ⟫ ∎ ) ⟩
⟪ suc (NN.j (nn i)) , pred (NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ suc (NN.j (nn i)) , pred k ⟫) eq ⟩
⟪ suc (NN.j (nn i)) , k ⟫ ∎ where open ≡-Reasoning
nn13 : {j0 k0 : ℕ} → nxn→n j0 k0 ≡ suc i → ⟪ suc (NN.j (nn i)) , k ⟫ ≡ ⟪ j0 , k0 ⟫
nn13 {zero} {suc k0} eq1 = ⊥-elim ( nat-≡< (sym (cong proj2 nn17)) nn18 ) where -- (nxn→n zero (suc k0)) ≡ suc i
nn16 : nxn→n k0 zero ≡ i
nn16 = cong pred ( subst (λ k → k ≡ suc i) (sym ( nid00 k0 )) eq1 )
nn17 : ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ k0 , zero ⟫
nn17 = NN.nn-unique (nn i) nn16
nn13 {suc j0} {k0} eq1 = begin
⟪ suc (NN.j (nn i)) , pred (suc k) ⟫ ≡⟨ cong (λ k → ⟪ suc (NN.j (nn i)) , pred k ⟫ ) (sym eq) ⟩
⟪ suc (NN.j (nn i)) , pred (NN.k (nn i)) ⟫ ≡⟨ cong (λ k → ⟪ suc (proj1 k) , pred (proj2 k) ⟫) ( begin
⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡⟨ nn15 ⟩
⟪ j0 , suc k0 ⟫ ∎ ) ⟩
⟪ suc j0 , k0 ⟫ ∎ where -- nxn→n (suc j0) k0 ≡ suc i
open ≡-Reasoning
nn14 : nxn→n j0 (suc k0) ≡ i
nn14 = cong pred ( subst (λ k → k ≡ suc i) (sym ( nid2 j0 k0 )) eq1 )
nn15 : ⟪ NN.j (nn i) , NN.k (nn i) ⟫ ≡ ⟪ j0 , suc k0 ⟫
nn15 = NN.nn-unique (nn i) nn14
n-id : (i : ℕ) → nxn→n (proj1 (n→nxn i)) (proj2 (n→nxn i)) ≡ i
n-id i = subst (λ k → nxn→n (proj1 k) (proj2 k) ≡ i ) (sym (NN.k0 (nn i))) (NN.k1 (nn i))
nn-id : (j k : ℕ) → n→nxn (nxn→n j k) ≡ ⟪ j , k ⟫
nn-id j k = begin
n→nxn (nxn→n j k) ≡⟨ NN.k0 (nn (nxn→n j k)) ⟩
⟪ NN.j (nn (nxn→n j k)) , NN.k (nn (nxn→n j k)) ⟫ ≡⟨ NN.nn-unique (nn (nxn→n j k)) refl ⟩
⟪ j , k ⟫ ∎ where open ≡-Reasoning
-- [] 0
-- 0 → 1
-- 1 → 2
-- 01 → 3
-- 11 → 4
-- ...
--
-- binary invariant
--
record LB (n : ℕ) (lton : List Bool → ℕ ) : Set where
field
nlist : List Bool
isBin : lton nlist ≡ n
isUnique : (x : List Bool) → lton x ≡ n → nlist ≡ x -- we don't need this
lb+1 : List Bool → List Bool
lb+1 [] = false ∷ []
lb+1 (false ∷ t) = true ∷ t
lb+1 (true ∷ t) = false ∷ lb+1 t
lb-1 : List Bool → List Bool
lb-1 [] = []
lb-1 (true ∷ t) = false ∷ t
lb-1 (false ∷ t) with lb-1 t
... | [] = true ∷ []
... | x ∷ t1 = true ∷ x ∷ t1
LBℕ : Bijection ℕ ( List Bool )
LBℕ = record {
fun← = λ x → lton x
; fun→ = λ n → LB.nlist (lb n)
; fiso← = λ n → LB.isBin (lb n)
; fiso→ = λ x → LB.isUnique (lb (lton x)) x refl
} where
lton1 : List Bool → ℕ
lton1 [] = 1
lton1 (true ∷ t) = suc (lton1 t + lton1 t)
lton1 (false ∷ t) = lton1 t + lton1 t
lton : List Bool → ℕ
lton x = pred (lton1 x)
lton1>0 : (x : List Bool ) → 0 < lton1 x
lton1>0 [] = a<sa
lton1>0 (true ∷ x₁) = 0<s
lton1>0 (false ∷ t) = ≤-trans (lton1>0 t) x≤x+y
2lton1>0 : (t : List Bool ) → 0 < lton1 t + lton1 t
2lton1>0 t = ≤-trans (lton1>0 t) x≤x+y
lb=3 : {x y : ℕ} → 0 < x → 0 < y → 1 ≤ pred (x + y)
lb=3 {suc x} {suc y} (s≤s 0<x) (s≤s 0<y) = subst (λ k → 1 ≤ k ) (+-comm (suc y) _ ) (s≤s z≤n)
lton-cons>0 : {x : Bool} {y : List Bool } → 0 < lton (x ∷ y)
lton-cons>0 {true} {[]} = refl-≤s
lton-cons>0 {true} {x ∷ y} = ≤-trans ( lb=3 (lton1>0 (x ∷ y)) (lton1>0 (x ∷ y))) px≤x
lton-cons>0 {false} {[]} = refl-≤
lton-cons>0 {false} {x ∷ y} = lb=3 (lton1>0 (x ∷ y)) (lton1>0 (x ∷ y))
lb=0 : {x y : ℕ } → pred x < pred y → suc (x + x ∸ 1) < suc (y + y ∸ 1)
lb=0 {0} {suc y} lt = s≤s (subst (λ k → 0 < k ) (+-comm (suc y) y ) 0<s)
lb=0 {suc x} {suc y} lt = begin
suc (suc ((suc x + suc x) ∸ 1)) ≡⟨ refl ⟩
suc (suc x) + suc x ≡⟨ refl ⟩
suc (suc x + suc x) ≤⟨ <-plus (s≤s lt) ⟩
suc y + suc x <⟨ <-plus-0 {suc x} {suc y} {suc y} (s≤s lt) ⟩
suc y + suc y ≡⟨ refl ⟩
suc ((suc y + suc y) ∸ 1) ∎ where open ≤-Reasoning
lb=2 : {x y : ℕ } → pred x < pred y → suc (x + x ) < suc (y + y )
lb=2 {zero} {suc y} lt = s≤s 0<s
lb=2 {suc x} {suc y} lt = s≤s (lb=0 {suc x} {suc y} lt)
lb=1 : {x y : List Bool} {z : Bool} → lton (z ∷ x) ≡ lton (z ∷ y) → lton x ≡ lton y
lb=1 {x} {y} {true} eq with <-cmp (lton x) (lton y)
... | tri< a ¬b ¬c = ⊥-elim (nat-≡< (cong suc eq) (lb=2 {lton1 x} {lton1 y} a))
... | tri≈ ¬a b ¬c = b
... | tri> ¬a ¬b c = ⊥-elim (nat-≡< (cong suc (sym eq)) (lb=2 {lton1 y} {lton1 x} c))
lb=1 {x} {y} {false} eq with <-cmp (lton x) (lton y)
... | tri< a ¬b ¬c = ⊥-elim (nat-≡< (cong suc eq) (lb=0 {lton1 x} {lton1 y} a))
... | tri≈ ¬a b ¬c = b
... | tri> ¬a ¬b c = ⊥-elim (nat-≡< (cong suc (sym eq)) (lb=0 {lton1 y} {lton1 x} c))
---
--- lton is unique in a head
---
lb-tf : {x y : List Bool } → ¬ (lton (true ∷ x) ≡ lton (false ∷ y))
lb-tf {x} {y} eq with <-cmp (lton1 x) (lton1 y)
... | tri< a ¬b ¬c = ⊥-elim ( nat-≡< eq (lb=01 a)) where
lb=01 : {x y : ℕ } → x < y → x + x < (y + y ∸ 1)
lb=01 {x} {y} x<y = begin
suc (x + x) ≡⟨ refl ⟩
suc x + x ≤⟨ ≤-plus x<y ⟩
y + x ≡⟨ refl ⟩
pred (suc y + x) ≡⟨ cong (λ k → pred ( k + x)) (+-comm 1 y) ⟩
pred ((y + 1) + x ) ≡⟨ cong pred (+-assoc y 1 x) ⟩
pred (y + suc x) ≤⟨ px≤py (≤-plus-0 {suc x} {y} {y} x<y) ⟩
(y + y) ∸ 1 ∎ where open ≤-Reasoning
... | tri> ¬a ¬b c = ⊥-elim ( nat-≡< (sym eq) (lb=02 c) ) where
lb=02 : {x y : ℕ } → x < y → x + x ∸ 1 < y + y
lb=02 {0} {y} lt = ≤-trans lt x≤x+y
lb=02 {suc x} {y} lt = begin
suc ( suc x + suc x ∸ 1 ) ≡⟨ refl ⟩
suc x + suc x ≤⟨ ≤-plus {suc x} (<to≤ lt) ⟩
y + suc x ≤⟨ ≤-plus-0 (<to≤ lt) ⟩
y + y ∎ where open ≤-Reasoning
... | tri≈ ¬a b ¬c = ⊥-elim ( nat-≡< (sym eq) ( begin
suc (lton1 y + lton1 y ∸ 1) ≡⟨ sucprd ( 2lton1>0 y) ⟩
lton1 y + lton1 y ≡⟨ cong (λ k → k + k ) (sym b) ⟩
lton1 x + lton1 x ∎ )) where open ≤-Reasoning
---
--- lton uniqueness
---
lb=b : (x y : List Bool) → lton x ≡ lton y → x ≡ y
lb=b [] [] eq = refl
lb=b [] (x ∷ y) eq = ⊥-elim ( nat-≡< eq (lton-cons>0 {x} {y} ))
lb=b (x ∷ y) [] eq = ⊥-elim ( nat-≡< (sym eq) (lton-cons>0 {x} {y} ))
lb=b (true ∷ x) (false ∷ y) eq = ⊥-elim ( lb-tf {x} {y} eq )
lb=b (false ∷ x) (true ∷ y) eq = ⊥-elim ( lb-tf {y} {x} (sym eq) )
lb=b (true ∷ x) (true ∷ y) eq = cong (λ k → true ∷ k ) (lb=b x y (lb=1 {x} {y} {true} eq))
lb=b (false ∷ x) (false ∷ y) eq = cong (λ k → false ∷ k ) (lb=b x y (lb=1 {x} {y} {false} eq))
lb : (n : ℕ) → LB n lton
lb zero = record { nlist = [] ; isBin = refl ; isUnique = lb05 } where
lb05 : (x : List Bool) → lton x ≡ zero → [] ≡ x
lb05 x eq = lb=b [] x (sym eq)
lb (suc n) with LB.nlist (lb n) | inspect LB.nlist (lb n)
... | [] | record { eq = eq } = record { nlist = false ∷ [] ; isUnique = lb06 ; isBin = lb10 } where
open ≡-Reasoning
lb10 : lton1 (false ∷ []) ∸ 1 ≡ suc n
lb10 = begin
lton (false ∷ []) ≡⟨ refl ⟩
suc 0 ≡⟨ refl ⟩
suc (lton []) ≡⟨ cong (λ k → suc (lton k)) (sym eq) ⟩
suc (lton (LB.nlist (lb n))) ≡⟨ cong suc (LB.isBin (lb n) ) ⟩
suc n ∎
lb06 : (x : List Bool) → pred (lton1 x ) ≡ suc n → false ∷ [] ≡ x
lb06 x eq1 = lb=b (false ∷ []) x (trans lb10 (sym eq1)) -- lton (false ∷ []) ≡ lton x
... | false ∷ t | record { eq = eq } = record { nlist = true ∷ t ; isBin = lb01 ; isUnique = lb09 } where
lb01 : lton (true ∷ t) ≡ suc n
lb01 = begin
lton (true ∷ t) ≡⟨ refl ⟩
lton1 t + lton1 t ≡⟨ sym ( sucprd (2lton1>0 t) ) ⟩
suc (pred (lton1 t + lton1 t )) ≡⟨ refl ⟩
suc (lton (false ∷ t)) ≡⟨ cong (λ k → suc (lton k )) (sym eq) ⟩
suc (lton (LB.nlist (lb n))) ≡⟨ cong suc (LB.isBin (lb n)) ⟩
suc n ∎ where open ≡-Reasoning
lb09 : (x : List Bool) → lton1 x ∸ 1 ≡ suc n → true ∷ t ≡ x
lb09 x eq1 = lb=b (true ∷ t) x (trans lb01 (sym eq1) ) -- lton (true ∷ t) ≡ lton x
... | true ∷ t | record { eq = eq } = record { nlist = lb+1 (true ∷ t) ; isBin = lb02 (true ∷ t) lb03 ; isUnique = lb07 } where
lb03 : lton (true ∷ t) ≡ n
lb03 = begin
lton (true ∷ t) ≡⟨ cong (λ k → lton k ) (sym eq ) ⟩
lton (LB.nlist (lb n)) ≡⟨ LB.isBin (lb n) ⟩
n ∎ where open ≡-Reasoning
add11 : (x1 : ℕ ) → suc x1 + suc x1 ≡ suc (suc (x1 + x1))
add11 zero = refl
add11 (suc x) = cong (λ k → suc (suc k)) (trans (+-comm x _) (cong suc (+-comm _ x)))
lb04 : (t : List Bool) → suc (lton1 t) ≡ lton1 (lb+1 t)
lb04 [] = refl
lb04 (false ∷ t) = refl
lb04 (true ∷ []) = refl
lb04 (true ∷ t0 ) = begin
suc (suc (lton1 t0 + lton1 t0)) ≡⟨ sym (add11 (lton1 t0)) ⟩
suc (lton1 t0) + suc (lton1 t0) ≡⟨ cong (λ k → k + k ) (lb04 t0 ) ⟩
lton1 (lb+1 t0) + lton1 (lb+1 t0) ∎ where
open ≡-Reasoning
lb02 : (t : List Bool) → lton t ≡ n → lton (lb+1 t) ≡ suc n
lb02 [] refl = refl
lb02 t eq1 = begin
lton (lb+1 t) ≡⟨ refl ⟩
pred (lton1 (lb+1 t)) ≡⟨ cong pred (sym (lb04 t)) ⟩
pred (suc (lton1 t)) ≡⟨ sym (sucprd (lton1>0 t)) ⟩
suc (pred (lton1 t)) ≡⟨ refl ⟩
suc (lton t) ≡⟨ cong suc eq1 ⟩
suc n ∎ where open ≡-Reasoning
lb07 : (x : List Bool) → pred (lton1 x ) ≡ suc n → lb+1 (true ∷ t) ≡ x
lb07 x eq1 = lb=b (lb+1 (true ∷ t)) x (trans ( lb02 (true ∷ t) lb03 ) (sym eq1))
| 48.14425 | 159 | 0.422423 |
0e7fa4834c66420bdf98dc6475abc495765d65de | 67,509 | agda | Agda | agda-stdlib/src/Data/Nat/Properties.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | agda-stdlib/src/Data/Nat/Properties.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | agda-stdlib/src/Data/Nat/Properties.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | ------------------------------------------------------------------------
-- The Agda standard library
--
-- A bunch of properties about natural number operations
------------------------------------------------------------------------
-- See README.Data.Nat for some examples showing how this module can be
-- used.
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Properties where
open import Axiom.UniquenessOfIdentityProofs
open import Algebra.Bundles
open import Algebra.Morphism
open import Algebra.Consequences.Propositional
open import Data.Bool.Base using (Bool; false; true; T)
open import Data.Bool.Properties using (T?)
open import Data.Empty
open import Data.Nat.Base
open import Data.Product
open import Data.Sum.Base as Sum
open import Data.Unit using (tt)
open import Function.Base
open import Function.Injection using (_↣_)
open import Level using (0ℓ)
open import Relation.Binary
open import Relation.Binary.Consequences using (flip-Connex)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary hiding (Irrelevant)
open import Relation.Nullary.Decidable using (True; via-injection; map′)
open import Relation.Nullary.Negation using (contradiction)
open import Algebra.Definitions {A = ℕ} _≡_
hiding (LeftCancellative; RightCancellative; Cancellative)
open import Algebra.Definitions
using (LeftCancellative; RightCancellative; Cancellative)
open import Algebra.Structures {A = ℕ} _≡_
------------------------------------------------------------------------
-- Properties of _≡_
------------------------------------------------------------------------
suc-injective : ∀ {m n} → suc m ≡ suc n → m ≡ n
suc-injective refl = refl
≡ᵇ⇒≡ : ∀ m n → T (m ≡ᵇ n) → m ≡ n
≡ᵇ⇒≡ zero zero _ = refl
≡ᵇ⇒≡ (suc m) (suc n) eq = cong suc (≡ᵇ⇒≡ m n eq)
≡⇒≡ᵇ : ∀ m n → m ≡ n → T (m ≡ᵇ n)
≡⇒≡ᵇ zero zero eq = _
≡⇒≡ᵇ (suc m) (suc n) eq = ≡⇒≡ᵇ m n (suc-injective eq)
-- NB: we use the builtin function `_≡ᵇ_` here so that the function
-- quickly decides whether to return `yes` or `no`. It still takes
-- a linear amount of time to generate the proof if it is inspected.
-- We expect the main benefit to be visible in compiled code as the
-- backend erases proofs.
infix 4 _≟_
_≟_ : Decidable {A = ℕ} _≡_
m ≟ n = map′ (≡ᵇ⇒≡ m n) (≡⇒≡ᵇ m n) (T? (m ≡ᵇ n))
≡-irrelevant : Irrelevant {A = ℕ} _≡_
≡-irrelevant = Decidable⇒UIP.≡-irrelevant _≟_
≟-diag : ∀ {m n} (eq : m ≡ n) → (m ≟ n) ≡ yes eq
≟-diag = ≡-≟-identity _≟_
≡-isDecEquivalence : IsDecEquivalence (_≡_ {A = ℕ})
≡-isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = _≟_
}
≡-decSetoid : DecSetoid 0ℓ 0ℓ
≡-decSetoid = record
{ Carrier = ℕ
; _≈_ = _≡_
; isDecEquivalence = ≡-isDecEquivalence
}
0≢1+n : ∀ {n} → 0 ≢ suc n
0≢1+n ()
1+n≢0 : ∀ {n} → suc n ≢ 0
1+n≢0 ()
1+n≢n : ∀ {n} → suc n ≢ n
1+n≢n {suc n} = 1+n≢n ∘ suc-injective
------------------------------------------------------------------------
-- Properties of _<ᵇ_
------------------------------------------------------------------------
<ᵇ⇒< : ∀ m n → T (m <ᵇ n) → m < n
<ᵇ⇒< zero (suc n) m<n = s≤s z≤n
<ᵇ⇒< (suc m) (suc n) m<n = s≤s (<ᵇ⇒< m n m<n)
<⇒<ᵇ : ∀ {m n} → m < n → T (m <ᵇ n)
<⇒<ᵇ (s≤s z≤n) = tt
<⇒<ᵇ (s≤s (s≤s m<n)) = <⇒<ᵇ (s≤s m<n)
------------------------------------------------------------------------
-- Properties of _≤_
------------------------------------------------------------------------
≤-pred : ∀ {m n} → suc m ≤ suc n → m ≤ n
≤-pred (s≤s m≤n) = m≤n
------------------------------------------------------------------------
-- Relational properties of _≤_
≤-reflexive : _≡_ ⇒ _≤_
≤-reflexive {zero} refl = z≤n
≤-reflexive {suc m} refl = s≤s (≤-reflexive refl)
≤-refl : Reflexive _≤_
≤-refl = ≤-reflexive refl
≤-antisym : Antisymmetric _≡_ _≤_
≤-antisym z≤n z≤n = refl
≤-antisym (s≤s m≤n) (s≤s n≤m) = cong suc (≤-antisym m≤n n≤m)
≤-trans : Transitive _≤_
≤-trans z≤n _ = z≤n
≤-trans (s≤s m≤n) (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
≤-total : Total _≤_
≤-total zero _ = inj₁ z≤n
≤-total _ zero = inj₂ z≤n
≤-total (suc m) (suc n) with ≤-total m n
... | inj₁ m≤n = inj₁ (s≤s m≤n)
... | inj₂ n≤m = inj₂ (s≤s n≤m)
≤-irrelevant : Irrelevant _≤_
≤-irrelevant z≤n z≤n = refl
≤-irrelevant (s≤s m≤n₁) (s≤s m≤n₂) = cong s≤s (≤-irrelevant m≤n₁ m≤n₂)
-- NB: we use the builtin function `_<ᵇ_` here so that the function
-- quickly decides whether to return `yes` or `no`. It still takes
-- a linear amount of time to generate the proof if it is inspected.
-- We expect the main benefit to be visible in compiled code as the
-- backend erases proofs.
infix 4 _≤?_ _≥?_
_≤?_ : Decidable _≤_
zero ≤? _ = yes z≤n
suc m ≤? n = map′ (<ᵇ⇒< m n) <⇒<ᵇ (T? (m <ᵇ n))
_≥?_ : Decidable _≥_
_≥?_ = flip _≤?_
------------------------------------------------------------------------
-- Structures
≤-isPreorder : IsPreorder _≡_ _≤_
≤-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ≤-reflexive
; trans = ≤-trans
}
≤-isPartialOrder : IsPartialOrder _≡_ _≤_
≤-isPartialOrder = record
{ isPreorder = ≤-isPreorder
; antisym = ≤-antisym
}
≤-isTotalOrder : IsTotalOrder _≡_ _≤_
≤-isTotalOrder = record
{ isPartialOrder = ≤-isPartialOrder
; total = ≤-total
}
≤-isDecTotalOrder : IsDecTotalOrder _≡_ _≤_
≤-isDecTotalOrder = record
{ isTotalOrder = ≤-isTotalOrder
; _≟_ = _≟_
; _≤?_ = _≤?_
}
------------------------------------------------------------------------
-- Bundles
≤-preorder : Preorder 0ℓ 0ℓ 0ℓ
≤-preorder = record
{ isPreorder = ≤-isPreorder
}
≤-poset : Poset 0ℓ 0ℓ 0ℓ
≤-poset = record
{ isPartialOrder = ≤-isPartialOrder
}
≤-totalOrder : TotalOrder 0ℓ 0ℓ 0ℓ
≤-totalOrder = record
{ isTotalOrder = ≤-isTotalOrder
}
≤-decTotalOrder : DecTotalOrder 0ℓ 0ℓ 0ℓ
≤-decTotalOrder = record
{ isDecTotalOrder = ≤-isDecTotalOrder
}
------------------------------------------------------------------------
-- Other properties of _≤_
s≤s-injective : ∀ {m n} {p q : m ≤ n} → s≤s p ≡ s≤s q → p ≡ q
s≤s-injective refl = refl
≤-step : ∀ {m n} → m ≤ n → m ≤ 1 + n
≤-step z≤n = z≤n
≤-step (s≤s m≤n) = s≤s (≤-step m≤n)
n≤1+n : ∀ n → n ≤ 1 + n
n≤1+n _ = ≤-step ≤-refl
1+n≰n : ∀ {n} → 1 + n ≰ n
1+n≰n (s≤s le) = 1+n≰n le
n≤0⇒n≡0 : ∀ {n} → n ≤ 0 → n ≡ 0
n≤0⇒n≡0 z≤n = refl
------------------------------------------------------------------------
-- Properties of _<_
------------------------------------------------------------------------
-- Relationships between the various relations
<⇒≤ : _<_ ⇒ _≤_
<⇒≤ (s≤s m≤n) = ≤-trans m≤n (≤-step ≤-refl)
<⇒≢ : _<_ ⇒ _≢_
<⇒≢ m<n refl = 1+n≰n m<n
≤⇒≯ : _≤_ ⇒ _≯_
≤⇒≯ (s≤s m≤n) (s≤s n≤m) = ≤⇒≯ m≤n n≤m
<⇒≱ : _<_ ⇒ _≱_
<⇒≱ (s≤s m+1≤n) (s≤s n≤m) = <⇒≱ m+1≤n n≤m
<⇒≯ : _<_ ⇒ _≯_
<⇒≯ (s≤s m<n) (s≤s n<m) = <⇒≯ m<n n<m
≰⇒≮ : _≰_ ⇒ _≮_
≰⇒≮ m≰n 1+m≤n = m≰n (<⇒≤ 1+m≤n)
≰⇒> : _≰_ ⇒ _>_
≰⇒> {zero} z≰n = contradiction z≤n z≰n
≰⇒> {suc m} {zero} _ = s≤s z≤n
≰⇒> {suc m} {suc n} m≰n = s≤s (≰⇒> (m≰n ∘ s≤s))
≰⇒≥ : _≰_ ⇒ _≥_
≰⇒≥ = <⇒≤ ∘ ≰⇒>
≮⇒≥ : _≮_ ⇒ _≥_
≮⇒≥ {_} {zero} _ = z≤n
≮⇒≥ {zero} {suc j} 1≮j+1 = contradiction (s≤s z≤n) 1≮j+1
≮⇒≥ {suc i} {suc j} i+1≮j+1 = s≤s (≮⇒≥ (i+1≮j+1 ∘ s≤s))
≤∧≢⇒< : ∀ {m n} → m ≤ n → m ≢ n → m < n
≤∧≢⇒< {_} {zero} z≤n m≢n = contradiction refl m≢n
≤∧≢⇒< {_} {suc n} z≤n m≢n = s≤s z≤n
≤∧≢⇒< {_} {suc n} (s≤s m≤n) 1+m≢1+n =
s≤s (≤∧≢⇒< m≤n (1+m≢1+n ∘ cong suc))
≤-<-connex : Connex _≤_ _<_
≤-<-connex m n with m ≤? n
... | yes m≤n = inj₁ m≤n
... | no ¬m≤n = inj₂ (≰⇒> ¬m≤n)
≥->-connex : Connex _≥_ _>_
≥->-connex = flip ≤-<-connex
<-≤-connex : Connex _<_ _≤_
<-≤-connex = flip-Connex ≤-<-connex
>-≥-connex : Connex _>_ _≥_
>-≥-connex = flip-Connex ≥->-connex
------------------------------------------------------------------------
-- Relational properties of _<_
<-irrefl : Irreflexive _≡_ _<_
<-irrefl refl (s≤s n<n) = <-irrefl refl n<n
<-asym : Asymmetric _<_
<-asym (s≤s n<m) (s≤s m<n) = <-asym n<m m<n
<-trans : Transitive _<_
<-trans (s≤s i≤j) (s≤s j<k) = s≤s (≤-trans i≤j (≤-trans (n≤1+n _) j<k))
<-transʳ : Trans _≤_ _<_ _<_
<-transʳ m≤n (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
<-transˡ : Trans _<_ _≤_ _<_
<-transˡ (s≤s m≤n) (s≤s n≤o) = s≤s (≤-trans m≤n n≤o)
-- NB: we use the builtin function `_<ᵇ_` here so that the function
-- quickly decides which constructor to return. It still takes a
-- linear amount of time to generate the proof if it is inspected.
-- We expect the main benefit to be visible in compiled code as the
-- backend erases proofs.
<-cmp : Trichotomous _≡_ _<_
<-cmp m n with m ≟ n | T? (m <ᵇ n)
... | yes m≡n | _ = tri≈ (<-irrefl m≡n) m≡n (<-irrefl (sym m≡n))
... | no m≢n | yes m<n = tri< (<ᵇ⇒< m n m<n) m≢n (<⇒≯ (<ᵇ⇒< m n m<n))
... | no m≢n | no m≮n = tri> (m≮n ∘ <⇒<ᵇ) m≢n (≤∧≢⇒< (≮⇒≥ (m≮n ∘ <⇒<ᵇ)) (m≢n ∘ sym))
infix 4 _<?_ _>?_
_<?_ : Decidable _<_
m <? n = suc m ≤? n
_>?_ : Decidable _>_
_>?_ = flip _<?_
<-irrelevant : Irrelevant _<_
<-irrelevant = ≤-irrelevant
<-resp₂-≡ : _<_ Respects₂ _≡_
<-resp₂-≡ = subst (_ <_) , subst (_< _)
------------------------------------------------------------------------
-- Bundles
<-isStrictPartialOrder : IsStrictPartialOrder _≡_ _<_
<-isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = <-irrefl
; trans = <-trans
; <-resp-≈ = <-resp₂-≡
}
<-isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_
<-isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = <-trans
; compare = <-cmp
}
<-strictPartialOrder : StrictPartialOrder 0ℓ 0ℓ 0ℓ
<-strictPartialOrder = record
{ isStrictPartialOrder = <-isStrictPartialOrder
}
<-strictTotalOrder : StrictTotalOrder 0ℓ 0ℓ 0ℓ
<-strictTotalOrder = record
{ isStrictTotalOrder = <-isStrictTotalOrder
}
------------------------------------------------------------------------
-- Other properties of _<_
n≮n : ∀ n → n ≮ n
n≮n n = <-irrefl (refl {x = n})
0<1+n : ∀ {n} → 0 < suc n
0<1+n = s≤s z≤n
n<1+n : ∀ n → n < suc n
n<1+n n = ≤-refl
n≢0⇒n>0 : ∀ {n} → n ≢ 0 → n > 0
n≢0⇒n>0 {zero} 0≢0 = contradiction refl 0≢0
n≢0⇒n>0 {suc n} _ = 0<1+n
m<n⇒n≢0 : ∀ {m n} → m < n → n ≢ 0
m<n⇒n≢0 (s≤s m≤n) ()
m<n⇒m≤1+n : ∀ {m n} → m < n → m ≤ suc n
m<n⇒m≤1+n (s≤s z≤n) = z≤n
m<n⇒m≤1+n (s≤s (s≤s m<n)) = s≤s (m<n⇒m≤1+n (s≤s m<n))
∀[m≤n⇒m≢o]⇒n<o : ∀ n o → (∀ {m} → m ≤ n → m ≢ o) → n < o
∀[m≤n⇒m≢o]⇒n<o _ zero m≤n⇒n≢0 = contradiction refl (m≤n⇒n≢0 z≤n)
∀[m≤n⇒m≢o]⇒n<o zero (suc o) _ = 0<1+n
∀[m≤n⇒m≢o]⇒n<o (suc n) (suc o) m≤n⇒n≢o = s≤s (∀[m≤n⇒m≢o]⇒n<o n o rec)
where
rec : ∀ {m} → m ≤ n → m ≢ o
rec m≤n refl = m≤n⇒n≢o (s≤s m≤n) refl
∀[m<n⇒m≢o]⇒n≤o : ∀ n o → (∀ {m} → m < n → m ≢ o) → n ≤ o
∀[m<n⇒m≢o]⇒n≤o zero n _ = z≤n
∀[m<n⇒m≢o]⇒n≤o (suc n) zero m<n⇒m≢0 = contradiction refl (m<n⇒m≢0 0<1+n)
∀[m<n⇒m≢o]⇒n≤o (suc n) (suc o) m<n⇒m≢o = s≤s (∀[m<n⇒m≢o]⇒n≤o n o rec)
where
rec : ∀ {m} → m < n → m ≢ o
rec x<m refl = m<n⇒m≢o (s≤s x<m) refl
------------------------------------------------------------------------
-- A module for reasoning about the _≤_ and _<_ relations
------------------------------------------------------------------------
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
≤-isPreorder
<-trans
(resp₂ _<_)
<⇒≤
<-transˡ
<-transʳ
public
hiding (step-≈; step-≈˘)
open ≤-Reasoning
------------------------------------------------------------------------
-- Properties of pred
------------------------------------------------------------------------
pred-mono : pred Preserves _≤_ ⟶ _≤_
pred-mono z≤n = z≤n
pred-mono (s≤s le) = le
≤pred⇒≤ : ∀ {m n} → m ≤ pred n → m ≤ n
≤pred⇒≤ {m} {zero} le = le
≤pred⇒≤ {m} {suc n} le = ≤-step le
≤⇒pred≤ : ∀ {m n} → m ≤ n → pred m ≤ n
≤⇒pred≤ {zero} le = le
≤⇒pred≤ {suc m} le = ≤-trans (n≤1+n m) le
<⇒≤pred : ∀ {m n} → m < n → m ≤ pred n
<⇒≤pred (s≤s le) = le
suc[pred[n]]≡n : ∀ {n} → n ≢ 0 → suc (pred n) ≡ n
suc[pred[n]]≡n {zero} n≢0 = contradiction refl n≢0
suc[pred[n]]≡n {suc n} n≢0 = refl
------------------------------------------------------------------------
-- Properties of _+_
------------------------------------------------------------------------
+-suc : ∀ m n → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = cong suc (+-suc m n)
------------------------------------------------------------------------
-- Algebraic properties of _+_
+-assoc : Associative _+_
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
+-identityˡ : LeftIdentity 0 _+_
+-identityˡ _ = refl
+-identityʳ : RightIdentity 0 _+_
+-identityʳ zero = refl
+-identityʳ (suc n) = cong suc (+-identityʳ n)
+-identity : Identity 0 _+_
+-identity = +-identityˡ , +-identityʳ
+-comm : Commutative _+_
+-comm zero n = sym (+-identityʳ n)
+-comm (suc m) n = begin-equality
suc m + n ≡⟨⟩
suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩
suc (n + m) ≡⟨ sym (+-suc n m) ⟩
n + suc m ∎
+-cancelˡ-≡ : LeftCancellative _≡_ _+_
+-cancelˡ-≡ zero eq = eq
+-cancelˡ-≡ (suc m) eq = +-cancelˡ-≡ m (cong pred eq)
+-cancelʳ-≡ : RightCancellative _≡_ _+_
+-cancelʳ-≡ = comm+cancelˡ⇒cancelʳ +-comm +-cancelˡ-≡
+-cancel-≡ : Cancellative _≡_ _+_
+-cancel-≡ = +-cancelˡ-≡ , +-cancelʳ-≡
------------------------------------------------------------------------
-- Structures
+-isMagma : IsMagma _+_
+-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _+_
}
+-isSemigroup : IsSemigroup _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc
}
+-isCommutativeSemigroup : IsCommutativeSemigroup _+_
+-isCommutativeSemigroup = record
{ isSemigroup = +-isSemigroup
; comm = +-comm
}
+-0-isMonoid : IsMonoid _+_ 0
+-0-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity
}
+-0-isCommutativeMonoid : IsCommutativeMonoid _+_ 0
+-0-isCommutativeMonoid = record
{ isMonoid = +-0-isMonoid
; comm = +-comm
}
------------------------------------------------------------------------
-- Raw bundles
+-rawMagma : RawMagma 0ℓ 0ℓ
+-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _+_
}
+-0-rawMonoid : RawMonoid 0ℓ 0ℓ
+-0-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _+_
; ε = 0
}
------------------------------------------------------------------------
-- Bundles
+-magma : Magma 0ℓ 0ℓ
+-magma = record
{ isMagma = +-isMagma
}
+-semigroup : Semigroup 0ℓ 0ℓ
+-semigroup = record
{ isSemigroup = +-isSemigroup
}
+-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
+-commutativeSemigroup = record
{ isCommutativeSemigroup = +-isCommutativeSemigroup
}
+-0-monoid : Monoid 0ℓ 0ℓ
+-0-monoid = record
{ isMonoid = +-0-isMonoid
}
+-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
+-0-commutativeMonoid = record
{ isCommutativeMonoid = +-0-isCommutativeMonoid
}
------------------------------------------------------------------------
-- Other properties of _+_ and _≡_
m≢1+m+n : ∀ m {n} → m ≢ suc (m + n)
m≢1+m+n (suc m) eq = m≢1+m+n m (cong pred eq)
m≢1+n+m : ∀ m {n} → m ≢ suc (n + m)
m≢1+n+m m m≡1+n+m = m≢1+m+n m (trans m≡1+n+m (cong suc (+-comm _ m)))
m+1+n≢m : ∀ m {n} → m + suc n ≢ m
m+1+n≢m (suc m) = (m+1+n≢m m) ∘ suc-injective
m+1+n≢0 : ∀ m {n} → m + suc n ≢ 0
m+1+n≢0 m {n} rewrite +-suc m n = λ()
m+n≡0⇒m≡0 : ∀ m {n} → m + n ≡ 0 → m ≡ 0
m+n≡0⇒m≡0 zero eq = refl
m+n≡0⇒n≡0 : ∀ m {n} → m + n ≡ 0 → n ≡ 0
m+n≡0⇒n≡0 m {n} m+n≡0 = m+n≡0⇒m≡0 n (trans (+-comm n m) (m+n≡0))
------------------------------------------------------------------------
-- Properties of _+_ and _≤_/_<_
+-cancelˡ-≤ : LeftCancellative _≤_ _+_
+-cancelˡ-≤ zero le = le
+-cancelˡ-≤ (suc m) (s≤s le) = +-cancelˡ-≤ m le
+-cancelʳ-≤ : RightCancellative _≤_ _+_
+-cancelʳ-≤ {m} n o le =
+-cancelˡ-≤ m (subst₂ _≤_ (+-comm n m) (+-comm o m) le)
+-cancel-≤ : Cancellative _≤_ _+_
+-cancel-≤ = +-cancelˡ-≤ , +-cancelʳ-≤
+-cancelˡ-< : LeftCancellative _<_ _+_
+-cancelˡ-< m {n} {o} = +-cancelˡ-≤ m ∘ subst (_≤ m + o) (sym (+-suc m n))
+-cancelʳ-< : RightCancellative _<_ _+_
+-cancelʳ-< n o n+m<o+m = +-cancelʳ-≤ (suc n) o n+m<o+m
+-cancel-< : Cancellative _<_ _+_
+-cancel-< = +-cancelˡ-< , +-cancelʳ-<
≤-stepsˡ : ∀ {m n} o → m ≤ n → m ≤ o + n
≤-stepsˡ zero m≤n = m≤n
≤-stepsˡ (suc o) m≤n = ≤-step (≤-stepsˡ o m≤n)
≤-stepsʳ : ∀ {m n} o → m ≤ n → m ≤ n + o
≤-stepsʳ {m} o m≤n = subst (m ≤_) (+-comm o _) (≤-stepsˡ o m≤n)
m≤m+n : ∀ m n → m ≤ m + n
m≤m+n zero n = z≤n
m≤m+n (suc m) n = s≤s (m≤m+n m n)
m≤n+m : ∀ m n → m ≤ n + m
m≤n+m m n = subst (m ≤_) (+-comm m n) (m≤m+n m n)
m≤n⇒m<n∨m≡n : ∀ {m n} → m ≤ n → m < n ⊎ m ≡ n
m≤n⇒m<n∨m≡n {0} {0} _ = inj₂ refl
m≤n⇒m<n∨m≡n {0} {suc n} _ = inj₁ 0<1+n
m≤n⇒m<n∨m≡n {suc m} {suc n} (s≤s m≤n) with m≤n⇒m<n∨m≡n m≤n
... | inj₂ m≡n = inj₂ (cong suc m≡n)
... | inj₁ m<n = inj₁ (s≤s m<n)
m+n≤o⇒m≤o : ∀ m {n o} → m + n ≤ o → m ≤ o
m+n≤o⇒m≤o zero m+n≤o = z≤n
m+n≤o⇒m≤o (suc m) (s≤s m+n≤o) = s≤s (m+n≤o⇒m≤o m m+n≤o)
m+n≤o⇒n≤o : ∀ m {n o} → m + n ≤ o → n ≤ o
m+n≤o⇒n≤o zero n≤o = n≤o
m+n≤o⇒n≤o (suc m) m+n<o = m+n≤o⇒n≤o m (<⇒≤ m+n<o)
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ {_} {m} z≤n o≤p = ≤-trans o≤p (m≤n+m _ m)
+-mono-≤ {_} {_} (s≤s m≤n) o≤p = s≤s (+-mono-≤ m≤n o≤p)
+-monoˡ-≤ : ∀ n → (_+ n) Preserves _≤_ ⟶ _≤_
+-monoˡ-≤ n m≤o = +-mono-≤ m≤o (≤-refl {n})
+-monoʳ-≤ : ∀ n → (n +_) Preserves _≤_ ⟶ _≤_
+-monoʳ-≤ n m≤o = +-mono-≤ (≤-refl {n}) m≤o
+-mono-<-≤ : _+_ Preserves₂ _<_ ⟶ _≤_ ⟶ _<_
+-mono-<-≤ {_} {suc n} (s≤s z≤n) o≤p = s≤s (≤-stepsˡ n o≤p)
+-mono-<-≤ {_} {_} (s≤s (s≤s m<n)) o≤p = s≤s (+-mono-<-≤ (s≤s m<n) o≤p)
+-mono-≤-< : _+_ Preserves₂ _≤_ ⟶ _<_ ⟶ _<_
+-mono-≤-< {_} {n} z≤n o<p = ≤-trans o<p (m≤n+m _ n)
+-mono-≤-< {_} {_} (s≤s m≤n) o<p = s≤s (+-mono-≤-< m≤n o<p)
+-mono-< : _+_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
+-mono-< m≤n = +-mono-≤-< (<⇒≤ m≤n)
+-monoˡ-< : ∀ n → (_+ n) Preserves _<_ ⟶ _<_
+-monoˡ-< n = +-monoˡ-≤ n
+-monoʳ-< : ∀ n → (n +_) Preserves _<_ ⟶ _<_
+-monoʳ-< zero m≤o = m≤o
+-monoʳ-< (suc n) m≤o = s≤s (+-monoʳ-< n m≤o)
m+1+n≰m : ∀ m {n} → m + suc n ≰ m
m+1+n≰m (suc m) le = m+1+n≰m m (≤-pred le)
m<m+n : ∀ m {n} → n > 0 → m < m + n
m<m+n zero n>0 = n>0
m<m+n (suc m) n>0 = s≤s (m<m+n m n>0)
m<n+m : ∀ m {n} → n > 0 → m < n + m
m<n+m m {n} n>0 rewrite +-comm n m = m<m+n m n>0
m+n≮n : ∀ m n → m + n ≮ n
m+n≮n zero n = n≮n n
m+n≮n (suc m) (suc n) (s≤s m+n<n) = m+n≮n m (suc n) (≤-step m+n<n)
m+n≮m : ∀ m n → m + n ≮ m
m+n≮m m n = subst (_≮ m) (+-comm n m) (m+n≮n n m)
------------------------------------------------------------------------
-- Properties of _*_
------------------------------------------------------------------------
*-suc : ∀ m n → m * suc n ≡ m + m * n
*-suc zero n = refl
*-suc (suc m) n = begin-equality
suc m * suc n ≡⟨⟩
suc n + m * suc n ≡⟨ cong (suc n +_) (*-suc m n) ⟩
suc n + (m + m * n) ≡⟨⟩
suc (n + (m + m * n)) ≡⟨ cong suc (sym (+-assoc n m (m * n))) ⟩
suc (n + m + m * n) ≡⟨ cong (λ x → suc (x + m * n)) (+-comm n m) ⟩
suc (m + n + m * n) ≡⟨ cong suc (+-assoc m n (m * n)) ⟩
suc (m + (n + m * n)) ≡⟨⟩
suc m + suc m * n ∎
------------------------------------------------------------------------
-- Algebraic properties of _*_
*-identityˡ : LeftIdentity 1 _*_
*-identityˡ n = +-identityʳ n
*-identityʳ : RightIdentity 1 _*_
*-identityʳ zero = refl
*-identityʳ (suc n) = cong suc (*-identityʳ n)
*-identity : Identity 1 _*_
*-identity = *-identityˡ , *-identityʳ
*-zeroˡ : LeftZero 0 _*_
*-zeroˡ _ = refl
*-zeroʳ : RightZero 0 _*_
*-zeroʳ zero = refl
*-zeroʳ (suc n) = *-zeroʳ n
*-zero : Zero 0 _*_
*-zero = *-zeroˡ , *-zeroʳ
*-comm : Commutative _*_
*-comm zero n = sym (*-zeroʳ n)
*-comm (suc m) n = begin-equality
suc m * n ≡⟨⟩
n + m * n ≡⟨ cong (n +_) (*-comm m n) ⟩
n + n * m ≡⟨ sym (*-suc n m) ⟩
n * suc m ∎
*-distribʳ-+ : _*_ DistributesOverʳ _+_
*-distribʳ-+ m zero o = refl
*-distribʳ-+ m (suc n) o = begin-equality
(suc n + o) * m ≡⟨⟩
m + (n + o) * m ≡⟨ cong (m +_) (*-distribʳ-+ m n o) ⟩
m + (n * m + o * m) ≡⟨ sym (+-assoc m (n * m) (o * m)) ⟩
m + n * m + o * m ≡⟨⟩
suc n * m + o * m ∎
*-distribˡ-+ : _*_ DistributesOverˡ _+_
*-distribˡ-+ = comm+distrʳ⇒distrˡ *-comm *-distribʳ-+
*-distrib-+ : _*_ DistributesOver _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
*-assoc : Associative _*_
*-assoc zero n o = refl
*-assoc (suc m) n o = begin-equality
(suc m * n) * o ≡⟨⟩
(n + m * n) * o ≡⟨ *-distribʳ-+ o n (m * n) ⟩
n * o + (m * n) * o ≡⟨ cong (n * o +_) (*-assoc m n o) ⟩
n * o + m * (n * o) ≡⟨⟩
suc m * (n * o) ∎
------------------------------------------------------------------------
-- Structures
*-isMagma : IsMagma _*_
*-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _*_
}
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-isCommutativeSemigroup : IsCommutativeSemigroup _*_
*-isCommutativeSemigroup = record
{ isSemigroup = *-isSemigroup
; comm = *-comm
}
*-1-isMonoid : IsMonoid _*_ 1
*-1-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _*_ 1
*-1-isCommutativeMonoid = record
{ isMonoid = *-1-isMonoid
; comm = *-comm
}
*-+-isSemiring : IsSemiring _+_ _*_ 0 1
*-+-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-0-isCommutativeMonoid
; *-isMonoid = *-1-isMonoid
; distrib = *-distrib-+
}
; zero = *-zero
}
*-+-isCommutativeSemiring : IsCommutativeSemiring _+_ _*_ 0 1
*-+-isCommutativeSemiring = record
{ isSemiring = *-+-isSemiring
; *-comm = *-comm
}
------------------------------------------------------------------------
-- Bundles
*-rawMagma : RawMagma 0ℓ 0ℓ
*-rawMagma = record
{ _≈_ = _≡_
; _∙_ = _*_
}
*-1-rawMonoid : RawMonoid 0ℓ 0ℓ
*-1-rawMonoid = record
{ _≈_ = _≡_
; _∙_ = _*_
; ε = 1
}
*-magma : Magma 0ℓ 0ℓ
*-magma = record
{ isMagma = *-isMagma
}
*-semigroup : Semigroup 0ℓ 0ℓ
*-semigroup = record
{ isSemigroup = *-isSemigroup
}
*-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
*-commutativeSemigroup = record
{ isCommutativeSemigroup = *-isCommutativeSemigroup
}
*-1-monoid : Monoid 0ℓ 0ℓ
*-1-monoid = record
{ isMonoid = *-1-isMonoid
}
*-1-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
*-1-commutativeMonoid = record
{ isCommutativeMonoid = *-1-isCommutativeMonoid
}
*-+-semiring : Semiring 0ℓ 0ℓ
*-+-semiring = record
{ isSemiring = *-+-isSemiring
}
*-+-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
*-+-commutativeSemiring = record
{ isCommutativeSemiring = *-+-isCommutativeSemiring
}
------------------------------------------------------------------------
-- Other properties of _*_ and _≡_
*-cancelʳ-≡ : ∀ m n {o} → m * suc o ≡ n * suc o → m ≡ n
*-cancelʳ-≡ zero zero eq = refl
*-cancelʳ-≡ (suc m) (suc n) {o} eq =
cong suc (*-cancelʳ-≡ m n (+-cancelˡ-≡ (suc o) eq))
*-cancelˡ-≡ : ∀ {m n} o → suc o * m ≡ suc o * n → m ≡ n
*-cancelˡ-≡ {m} {n} o eq = *-cancelʳ-≡ m n
(subst₂ _≡_ (*-comm (suc o) m) (*-comm (suc o) n) eq)
m*n≡0⇒m≡0∨n≡0 : ∀ m {n} → m * n ≡ 0 → m ≡ 0 ⊎ n ≡ 0
m*n≡0⇒m≡0∨n≡0 zero {n} eq = inj₁ refl
m*n≡0⇒m≡0∨n≡0 (suc m) {zero} eq = inj₂ refl
m*n≡1⇒m≡1 : ∀ m n → m * n ≡ 1 → m ≡ 1
m*n≡1⇒m≡1 (suc zero) n _ = refl
m*n≡1⇒m≡1 (suc (suc m)) (suc zero) ()
m*n≡1⇒m≡1 (suc (suc m)) zero eq =
contradiction (trans (sym $ *-zeroʳ m) eq) λ()
m*n≡1⇒n≡1 : ∀ m n → m * n ≡ 1 → n ≡ 1
m*n≡1⇒n≡1 m n eq = m*n≡1⇒m≡1 n m (trans (*-comm n m) eq)
------------------------------------------------------------------------
-- Other properties of _*_ and _≤_/_<_
*-cancelʳ-≤ : ∀ m n o → m * suc o ≤ n * suc o → m ≤ n
*-cancelʳ-≤ zero _ _ _ = z≤n
*-cancelʳ-≤ (suc m) (suc n) o le =
s≤s (*-cancelʳ-≤ m n o (+-cancelˡ-≤ (suc o) le))
*-cancelˡ-≤ : ∀ {m n} o → suc o * m ≤ suc o * n → m ≤ n
*-cancelˡ-≤ {m} {n} o rewrite *-comm (suc o) m | *-comm (suc o) n = *-cancelʳ-≤ m n o
*-mono-≤ : _*_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
*-mono-≤ z≤n _ = z≤n
*-mono-≤ (s≤s m≤n) u≤v = +-mono-≤ u≤v (*-mono-≤ m≤n u≤v)
*-monoˡ-≤ : ∀ n → (_* n) Preserves _≤_ ⟶ _≤_
*-monoˡ-≤ n m≤o = *-mono-≤ m≤o (≤-refl {n})
*-monoʳ-≤ : ∀ n → (n *_) Preserves _≤_ ⟶ _≤_
*-monoʳ-≤ n m≤o = *-mono-≤ (≤-refl {n}) m≤o
*-mono-< : _*_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
*-mono-< (s≤s z≤n) (s≤s u≤v) = s≤s z≤n
*-mono-< (s≤s (s≤s m≤n)) (s≤s u≤v) =
+-mono-< (s≤s u≤v) (*-mono-< (s≤s m≤n) (s≤s u≤v))
*-monoˡ-< : ∀ n → (_* suc n) Preserves _<_ ⟶ _<_
*-monoˡ-< n (s≤s z≤n) = s≤s z≤n
*-monoˡ-< n (s≤s (s≤s m≤o)) =
+-mono-≤-< (≤-refl {suc n}) (*-monoˡ-< n (s≤s m≤o))
*-monoʳ-< : ∀ n → (suc n *_) Preserves _<_ ⟶ _<_
*-monoʳ-< zero (s≤s m≤o) = +-mono-≤ (s≤s m≤o) z≤n
*-monoʳ-< (suc n) (s≤s m≤o) =
+-mono-≤ (s≤s m≤o) (<⇒≤ (*-monoʳ-< n (s≤s m≤o)))
m≤m*n : ∀ m {n} → 0 < n → m ≤ m * n
m≤m*n m {n} 0<n = begin
m ≡⟨ sym (*-identityʳ m) ⟩
m * 1 ≤⟨ *-monoʳ-≤ m 0<n ⟩
m * n ∎
m<m*n : ∀ {m n} → 0 < m → 1 < n → m < m * n
m<m*n {m@(suc m-1)} {n@(suc (suc n-2))} (s≤s _) (s≤s (s≤s _)) = begin-strict
m <⟨ s≤s (s≤s (m≤n+m m-1 n-2)) ⟩
n + m-1 ≤⟨ +-monoʳ-≤ n (m≤m*n m-1 0<1+n) ⟩
n + m-1 * n ≡⟨⟩
m * n ∎
*-cancelʳ-< : RightCancellative _<_ _*_
*-cancelʳ-< {zero} zero (suc o) _ = 0<1+n
*-cancelʳ-< {suc m} zero (suc o) _ = 0<1+n
*-cancelʳ-< {m} (suc n) (suc o) nm<om =
s≤s (*-cancelʳ-< n o (+-cancelˡ-< m nm<om))
-- Redo in terms of `comm+cancelʳ⇒cancelˡ` when generalised
*-cancelˡ-< : LeftCancellative _<_ _*_
*-cancelˡ-< x {y} {z} rewrite *-comm x y | *-comm x z = *-cancelʳ-< y z
*-cancel-< : Cancellative _<_ _*_
*-cancel-< = *-cancelˡ-< , *-cancelʳ-<
------------------------------------------------------------------------
-- Properties of _^_
------------------------------------------------------------------------
^-identityʳ : RightIdentity 1 _^_
^-identityʳ zero = refl
^-identityʳ (suc n) = cong suc (^-identityʳ n)
^-zeroˡ : LeftZero 1 _^_
^-zeroˡ zero = refl
^-zeroˡ (suc n) = begin-equality
1 ^ suc n ≡⟨⟩
1 * (1 ^ n) ≡⟨ *-identityˡ (1 ^ n) ⟩
1 ^ n ≡⟨ ^-zeroˡ n ⟩
1 ∎
^-distribˡ-+-* : ∀ m n o → m ^ (n + o) ≡ m ^ n * m ^ o
^-distribˡ-+-* m zero o = sym (+-identityʳ (m ^ o))
^-distribˡ-+-* m (suc n) o = begin-equality
m * (m ^ (n + o)) ≡⟨ cong (m *_) (^-distribˡ-+-* m n o) ⟩
m * ((m ^ n) * (m ^ o)) ≡⟨ sym (*-assoc m _ _) ⟩
(m * (m ^ n)) * (m ^ o) ∎
^-semigroup-morphism : ∀ {n} → (n ^_) Is +-semigroup -Semigroup⟶ *-semigroup
^-semigroup-morphism = record
{ ⟦⟧-cong = cong (_ ^_)
; ∙-homo = ^-distribˡ-+-* _
}
^-monoid-morphism : ∀ {n} → (n ^_) Is +-0-monoid -Monoid⟶ *-1-monoid
^-monoid-morphism = record
{ sm-homo = ^-semigroup-morphism
; ε-homo = refl
}
^-*-assoc : ∀ m n o → (m ^ n) ^ o ≡ m ^ (n * o)
^-*-assoc m n zero = cong (m ^_) (sym $ *-zeroʳ n)
^-*-assoc m n (suc o) = begin-equality
(m ^ n) * ((m ^ n) ^ o) ≡⟨ cong ((m ^ n) *_) (^-*-assoc m n o) ⟩
(m ^ n) * (m ^ (n * o)) ≡⟨ sym (^-distribˡ-+-* m n (n * o)) ⟩
m ^ (n + n * o) ≡⟨ cong (m ^_) (sym (*-suc n o)) ⟩
m ^ (n * (suc o)) ∎
m^n≡0⇒m≡0 : ∀ m n → m ^ n ≡ 0 → m ≡ 0
m^n≡0⇒m≡0 m (suc n) eq = [ id , m^n≡0⇒m≡0 m n ]′ (m*n≡0⇒m≡0∨n≡0 m eq)
m^n≡1⇒n≡0∨m≡1 : ∀ m n → m ^ n ≡ 1 → n ≡ 0 ⊎ m ≡ 1
m^n≡1⇒n≡0∨m≡1 m zero _ = inj₁ refl
m^n≡1⇒n≡0∨m≡1 m (suc n) eq = inj₂ (m*n≡1⇒m≡1 m (m ^ n) eq)
------------------------------------------------------------------------
-- Properties of _⊔_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Algebraic properties
⊔-assoc : Associative _⊔_
⊔-assoc zero _ _ = refl
⊔-assoc (suc m) zero o = refl
⊔-assoc (suc m) (suc n) zero = refl
⊔-assoc (suc m) (suc n) (suc o) = cong suc $ ⊔-assoc m n o
⊔-identityˡ : LeftIdentity 0 _⊔_
⊔-identityˡ _ = refl
⊔-identityʳ : RightIdentity 0 _⊔_
⊔-identityʳ zero = refl
⊔-identityʳ (suc n) = refl
⊔-identity : Identity 0 _⊔_
⊔-identity = ⊔-identityˡ , ⊔-identityʳ
⊔-comm : Commutative _⊔_
⊔-comm zero n = sym $ ⊔-identityʳ n
⊔-comm (suc m) zero = refl
⊔-comm (suc m) (suc n) = cong suc (⊔-comm m n)
⊔-sel : Selective _⊔_
⊔-sel zero _ = inj₂ refl
⊔-sel (suc m) zero = inj₁ refl
⊔-sel (suc m) (suc n) with ⊔-sel m n
... | inj₁ m⊔n≡m = inj₁ (cong suc m⊔n≡m)
... | inj₂ m⊔n≡n = inj₂ (cong suc m⊔n≡n)
⊔-idem : Idempotent _⊔_
⊔-idem = sel⇒idem ⊔-sel
⊔-least : ∀ {m n o} → m ≤ o → n ≤ o → m ⊔ n ≤ o
⊔-least {m} {n} m≤o n≤o with ⊔-sel m n
... | inj₁ m⊔n≡m rewrite m⊔n≡m = m≤o
... | inj₂ m⊔n≡n rewrite m⊔n≡n = n≤o
------------------------------------------------------------------------
-- Structures
⊔-isMagma : IsMagma _⊔_
⊔-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _⊔_
}
⊔-isSemigroup : IsSemigroup _⊔_
⊔-isSemigroup = record
{ isMagma = ⊔-isMagma
; assoc = ⊔-assoc
}
⊔-isBand : IsBand _⊔_
⊔-isBand = record
{ isSemigroup = ⊔-isSemigroup
; idem = ⊔-idem
}
⊔-isSemilattice : IsSemilattice _⊔_
⊔-isSemilattice = record
{ isBand = ⊔-isBand
; comm = ⊔-comm
}
⊔-0-isMonoid : IsMonoid _⊔_ 0
⊔-0-isMonoid = record
{ isSemigroup = ⊔-isSemigroup
; identity = ⊔-identity
}
⊔-0-isCommutativeMonoid : IsCommutativeMonoid _⊔_ 0
⊔-0-isCommutativeMonoid = record
{ isMonoid = ⊔-0-isMonoid
; comm = ⊔-comm
}
------------------------------------------------------------------------
-- Bundles
⊔-magma : Magma 0ℓ 0ℓ
⊔-magma = record
{ isMagma = ⊔-isMagma
}
⊔-semigroup : Semigroup 0ℓ 0ℓ
⊔-semigroup = record
{ isSemigroup = ⊔-isSemigroup
}
⊔-band : Band 0ℓ 0ℓ
⊔-band = record
{ isBand = ⊔-isBand
}
⊔-semilattice : Semilattice 0ℓ 0ℓ
⊔-semilattice = record
{ isSemilattice = ⊔-isSemilattice
}
⊔-0-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
⊔-0-commutativeMonoid = record
{ isCommutativeMonoid = ⊔-0-isCommutativeMonoid
}
------------------------------------------------------------------------
-- Other properties of _⊔_ and _≡_
⊔-triangulate : ∀ m n o → m ⊔ n ⊔ o ≡ (m ⊔ n) ⊔ (n ⊔ o)
⊔-triangulate m n o = begin-equality
m ⊔ n ⊔ o ≡⟨ cong (λ v → m ⊔ v ⊔ o) (sym (⊔-idem n)) ⟩
m ⊔ (n ⊔ n) ⊔ o ≡⟨ ⊔-assoc m _ _ ⟩
m ⊔ ((n ⊔ n) ⊔ o) ≡⟨ cong (m ⊔_) (⊔-assoc n _ _) ⟩
m ⊔ (n ⊔ (n ⊔ o)) ≡⟨ sym (⊔-assoc m _ _) ⟩
(m ⊔ n) ⊔ (n ⊔ o) ∎
------------------------------------------------------------------------
-- Other properties of _⊔_ and _≤_/_<_
m≤m⊔n : ∀ m n → m ≤ m ⊔ n
m≤m⊔n zero _ = z≤n
m≤m⊔n (suc m) zero = ≤-refl
m≤m⊔n (suc m) (suc n) = s≤s $ m≤m⊔n m n
n≤m⊔n : ∀ m n → n ≤ m ⊔ n
n≤m⊔n m n = subst (n ≤_) (⊔-comm n m) (m≤m⊔n n m)
m≤n⇒n⊔m≡n : ∀ {m n} → m ≤ n → n ⊔ m ≡ n
m≤n⇒n⊔m≡n z≤n = ⊔-identityʳ _
m≤n⇒n⊔m≡n (s≤s m≤n) = cong suc (m≤n⇒n⊔m≡n m≤n)
m≤n⇒m⊔n≡n : ∀ {m n} → m ≤ n → m ⊔ n ≡ n
m≤n⇒m⊔n≡n {m} m≤n = trans (⊔-comm m _) (m≤n⇒n⊔m≡n m≤n)
n⊔m≡m⇒n≤m : ∀ {m n} → n ⊔ m ≡ m → n ≤ m
n⊔m≡m⇒n≤m n⊔m≡m = subst (_ ≤_) n⊔m≡m (m≤m⊔n _ _)
n⊔m≡n⇒m≤n : ∀ {m n} → n ⊔ m ≡ n → m ≤ n
n⊔m≡n⇒m≤n n⊔m≡n = subst (_ ≤_) n⊔m≡n (n≤m⊔n _ _)
m≤n⇒m≤n⊔o : ∀ {m n} o → m ≤ n → m ≤ n ⊔ o
m≤n⇒m≤n⊔o o m≤n = ≤-trans m≤n (m≤m⊔n _ o)
m≤n⇒m≤o⊔n : ∀ {m n} o → m ≤ n → m ≤ o ⊔ n
m≤n⇒m≤o⊔n n m≤n = ≤-trans m≤n (n≤m⊔n n _)
m⊔n≤o⇒m≤o : ∀ m n {o} → m ⊔ n ≤ o → m ≤ o
m⊔n≤o⇒m≤o m n m⊔n≤o = ≤-trans (m≤m⊔n m n) m⊔n≤o
m⊔n≤o⇒n≤o : ∀ m n {o} → m ⊔ n ≤ o → n ≤ o
m⊔n≤o⇒n≤o m n m⊔n≤o = ≤-trans (n≤m⊔n m n) m⊔n≤o
m<n⇒m<n⊔o : ∀ {m n} o → m < n → m < n ⊔ o
m<n⇒m<n⊔o = m≤n⇒m≤n⊔o
m<n⇒m<o⊔n : ∀ {m n} o → m < n → m < o ⊔ n
m<n⇒m<o⊔n = m≤n⇒m≤o⊔n
m⊔n<o⇒m<o : ∀ m n {o} → m ⊔ n < o → m < o
m⊔n<o⇒m<o m n m⊔n<o = <-transʳ (m≤m⊔n m n) m⊔n<o
m⊔n<o⇒n<o : ∀ m n {o} → m ⊔ n < o → n < o
m⊔n<o⇒n<o m n m⊔n<o = <-transʳ (n≤m⊔n m n) m⊔n<o
⊔-mono-≤ : _⊔_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
⊔-mono-≤ {m} {n} {u} {v} m≤n u≤v with ⊔-sel m u
... | inj₁ m⊔u≡m rewrite m⊔u≡m = ≤-trans m≤n (m≤m⊔n n v)
... | inj₂ m⊔u≡u rewrite m⊔u≡u = ≤-trans u≤v (n≤m⊔n n v)
⊔-monoˡ-≤ : ∀ n → (_⊔ n) Preserves _≤_ ⟶ _≤_
⊔-monoˡ-≤ n m≤o = ⊔-mono-≤ m≤o (≤-refl {n})
⊔-monoʳ-≤ : ∀ n → (n ⊔_) Preserves _≤_ ⟶ _≤_
⊔-monoʳ-≤ n m≤o = ⊔-mono-≤ (≤-refl {n}) m≤o
⊔-mono-< : _⊔_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
⊔-mono-< = ⊔-mono-≤
⊔-pres-≤m : ∀ {m n o} → n ≤ m → o ≤ m → n ⊔ o ≤ m
⊔-pres-≤m {m} n≤m o≤m = subst (_ ≤_) (⊔-idem m) (⊔-mono-≤ n≤m o≤m)
⊔-pres-<m : ∀ {m n o} → n < m → o < m → n ⊔ o < m
⊔-pres-<m {m} n<m o<m = subst (_ <_) (⊔-idem m) (⊔-mono-< n<m o<m)
------------------------------------------------------------------------
-- Other properties of _⊔_ and _+_
+-distribˡ-⊔ : _+_ DistributesOverˡ _⊔_
+-distribˡ-⊔ zero n o = refl
+-distribˡ-⊔ (suc m) n o = cong suc (+-distribˡ-⊔ m n o)
+-distribʳ-⊔ : _+_ DistributesOverʳ _⊔_
+-distribʳ-⊔ = comm+distrˡ⇒distrʳ +-comm +-distribˡ-⊔
+-distrib-⊔ : _+_ DistributesOver _⊔_
+-distrib-⊔ = +-distribˡ-⊔ , +-distribʳ-⊔
m⊔n≤m+n : ∀ m n → m ⊔ n ≤ m + n
m⊔n≤m+n m n with ⊔-sel m n
... | inj₁ m⊔n≡m rewrite m⊔n≡m = m≤m+n m n
... | inj₂ m⊔n≡n rewrite m⊔n≡n = m≤n+m n m
------------------------------------------------------------------------
-- Properties of _⊓_
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Algebraic properties
⊓-assoc : Associative _⊓_
⊓-assoc zero _ _ = refl
⊓-assoc (suc m) zero o = refl
⊓-assoc (suc m) (suc n) zero = refl
⊓-assoc (suc m) (suc n) (suc o) = cong suc $ ⊓-assoc m n o
⊓-zeroˡ : LeftZero 0 _⊓_
⊓-zeroˡ _ = refl
⊓-zeroʳ : RightZero 0 _⊓_
⊓-zeroʳ zero = refl
⊓-zeroʳ (suc n) = refl
⊓-zero : Zero 0 _⊓_
⊓-zero = ⊓-zeroˡ , ⊓-zeroʳ
⊓-comm : Commutative _⊓_
⊓-comm zero n = sym $ ⊓-zeroʳ n
⊓-comm (suc m) zero = refl
⊓-comm (suc m) (suc n) = cong suc (⊓-comm m n)
⊓-sel : Selective _⊓_
⊓-sel zero _ = inj₁ refl
⊓-sel (suc m) zero = inj₂ refl
⊓-sel (suc m) (suc n) with ⊓-sel m n
... | inj₁ m⊓n≡m = inj₁ (cong suc m⊓n≡m)
... | inj₂ m⊓n≡n = inj₂ (cong suc m⊓n≡n)
⊓-idem : Idempotent _⊓_
⊓-idem = sel⇒idem ⊓-sel
⊓-greatest : ∀ {m n o} → m ≥ o → n ≥ o → m ⊓ n ≥ o
⊓-greatest {m} {n} m≥o n≥o with ⊓-sel m n
... | inj₁ m⊓n≡m rewrite m⊓n≡m = m≥o
... | inj₂ m⊓n≡n rewrite m⊓n≡n = n≥o
⊓-distribʳ-⊔ : _⊓_ DistributesOverʳ _⊔_
⊓-distribʳ-⊔ (suc m) (suc n) (suc o) = cong suc $ ⊓-distribʳ-⊔ m n o
⊓-distribʳ-⊔ (suc m) (suc n) zero = cong suc $ refl
⊓-distribʳ-⊔ (suc m) zero o = refl
⊓-distribʳ-⊔ zero n o = begin-equality
(n ⊔ o) ⊓ 0 ≡⟨ ⊓-comm (n ⊔ o) 0 ⟩
0 ⊓ (n ⊔ o) ≡⟨⟩
0 ⊓ n ⊔ 0 ⊓ o ≡⟨ ⊓-comm 0 n ⟨ cong₂ _⊔_ ⟩ ⊓-comm 0 o ⟩
n ⊓ 0 ⊔ o ⊓ 0 ∎
⊓-distribˡ-⊔ : _⊓_ DistributesOverˡ _⊔_
⊓-distribˡ-⊔ = comm+distrʳ⇒distrˡ ⊓-comm ⊓-distribʳ-⊔
⊓-distrib-⊔ : _⊓_ DistributesOver _⊔_
⊓-distrib-⊔ = ⊓-distribˡ-⊔ , ⊓-distribʳ-⊔
⊔-abs-⊓ : _⊔_ Absorbs _⊓_
⊔-abs-⊓ zero n = refl
⊔-abs-⊓ (suc m) zero = refl
⊔-abs-⊓ (suc m) (suc n) = cong suc $ ⊔-abs-⊓ m n
⊓-abs-⊔ : _⊓_ Absorbs _⊔_
⊓-abs-⊔ zero n = refl
⊓-abs-⊔ (suc m) (suc n) = cong suc $ ⊓-abs-⊔ m n
⊓-abs-⊔ (suc m) zero = cong suc $ begin-equality
m ⊓ m ≡⟨ cong (m ⊓_) $ sym $ ⊔-identityʳ m ⟩
m ⊓ (m ⊔ 0) ≡⟨ ⊓-abs-⊔ m zero ⟩
m ∎
⊓-⊔-absorptive : Absorptive _⊓_ _⊔_
⊓-⊔-absorptive = ⊓-abs-⊔ , ⊔-abs-⊓
------------------------------------------------------------------------
-- Structures
⊓-isMagma : IsMagma _⊓_
⊓-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _⊓_
}
⊓-isSemigroup : IsSemigroup _⊓_
⊓-isSemigroup = record
{ isMagma = ⊓-isMagma
; assoc = ⊓-assoc
}
⊓-isBand : IsBand _⊓_
⊓-isBand = record
{ isSemigroup = ⊓-isSemigroup
; idem = ⊓-idem
}
⊓-isSemilattice : IsSemilattice _⊓_
⊓-isSemilattice = record
{ isBand = ⊓-isBand
; comm = ⊓-comm
}
⊔-⊓-isSemiringWithoutOne : IsSemiringWithoutOne _⊔_ _⊓_ 0
⊔-⊓-isSemiringWithoutOne = record
{ +-isCommutativeMonoid = ⊔-0-isCommutativeMonoid
; *-isSemigroup = ⊓-isSemigroup
; distrib = ⊓-distrib-⊔
; zero = ⊓-zero
}
⊔-⊓-isCommutativeSemiringWithoutOne
: IsCommutativeSemiringWithoutOne _⊔_ _⊓_ 0
⊔-⊓-isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = ⊔-⊓-isSemiringWithoutOne
; *-comm = ⊓-comm
}
⊓-⊔-isLattice : IsLattice _⊓_ _⊔_
⊓-⊔-isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ⊓-comm
; ∨-assoc = ⊓-assoc
; ∨-cong = cong₂ _⊓_
; ∧-comm = ⊔-comm
; ∧-assoc = ⊔-assoc
; ∧-cong = cong₂ _⊔_
; absorptive = ⊓-⊔-absorptive
}
⊓-⊔-isDistributiveLattice : IsDistributiveLattice _⊓_ _⊔_
⊓-⊔-isDistributiveLattice = record
{ isLattice = ⊓-⊔-isLattice
; ∨-distribʳ-∧ = ⊓-distribʳ-⊔
}
------------------------------------------------------------------------
-- Bundles
⊓-magma : Magma 0ℓ 0ℓ
⊓-magma = record
{ isMagma = ⊓-isMagma
}
⊓-semigroup : Semigroup 0ℓ 0ℓ
⊓-semigroup = record
{ isSemigroup = ⊔-isSemigroup
}
⊓-band : Band 0ℓ 0ℓ
⊓-band = record
{ isBand = ⊓-isBand
}
⊓-semilattice : Semilattice 0ℓ 0ℓ
⊓-semilattice = record
{ isSemilattice = ⊓-isSemilattice
}
⊔-⊓-commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne 0ℓ 0ℓ
⊔-⊓-commutativeSemiringWithoutOne = record
{ isCommutativeSemiringWithoutOne =
⊔-⊓-isCommutativeSemiringWithoutOne
}
⊓-⊔-lattice : Lattice 0ℓ 0ℓ
⊓-⊔-lattice = record
{ isLattice = ⊓-⊔-isLattice
}
⊓-⊔-distributiveLattice : DistributiveLattice 0ℓ 0ℓ
⊓-⊔-distributiveLattice = record
{ isDistributiveLattice = ⊓-⊔-isDistributiveLattice
}
------------------------------------------------------------------------
-- Other properties of _⊓_ and _≡_
⊓-triangulate : ∀ m n o → m ⊓ n ⊓ o ≡ (m ⊓ n) ⊓ (n ⊓ o)
⊓-triangulate m n o = begin-equality
m ⊓ n ⊓ o ≡⟨ sym (cong (λ v → m ⊓ v ⊓ o) (⊓-idem n)) ⟩
m ⊓ (n ⊓ n) ⊓ o ≡⟨ ⊓-assoc m _ _ ⟩
m ⊓ ((n ⊓ n) ⊓ o) ≡⟨ cong (m ⊓_) (⊓-assoc n _ _) ⟩
m ⊓ (n ⊓ (n ⊓ o)) ≡⟨ sym (⊓-assoc m _ _) ⟩
(m ⊓ n) ⊓ (n ⊓ o) ∎
------------------------------------------------------------------------
-- Other properties of _⊓_ and _≤_/_<_
m⊓n≤m : ∀ m n → m ⊓ n ≤ m
m⊓n≤m zero _ = z≤n
m⊓n≤m (suc m) zero = z≤n
m⊓n≤m (suc m) (suc n) = s≤s $ m⊓n≤m m n
m⊓n≤n : ∀ m n → m ⊓ n ≤ n
m⊓n≤n m n = subst (_≤ n) (⊓-comm n m) (m⊓n≤m n m)
m≤n⇒m⊓n≡m : ∀ {m n} → m ≤ n → m ⊓ n ≡ m
m≤n⇒m⊓n≡m z≤n = refl
m≤n⇒m⊓n≡m (s≤s m≤n) = cong suc (m≤n⇒m⊓n≡m m≤n)
m≤n⇒n⊓m≡m : ∀ {m n} → m ≤ n → n ⊓ m ≡ m
m≤n⇒n⊓m≡m {m} m≤n = trans (⊓-comm _ m) (m≤n⇒m⊓n≡m m≤n)
m⊓n≡m⇒m≤n : ∀ {m n} → m ⊓ n ≡ m → m ≤ n
m⊓n≡m⇒m≤n m⊓n≡m = subst (_≤ _) m⊓n≡m (m⊓n≤n _ _)
m⊓n≡n⇒n≤m : ∀ {m n} → m ⊓ n ≡ n → n ≤ m
m⊓n≡n⇒n≤m m⊓n≡n = subst (_≤ _) m⊓n≡n (m⊓n≤m _ _)
m≤n⇒m⊓o≤n : ∀ {m n} o → m ≤ n → m ⊓ o ≤ n
m≤n⇒m⊓o≤n o m≤n = ≤-trans (m⊓n≤m _ o) m≤n
m≤n⇒o⊓m≤n : ∀ {m n} o → m ≤ n → o ⊓ m ≤ n
m≤n⇒o⊓m≤n n m≤n = ≤-trans (m⊓n≤n n _) m≤n
m≤n⊓o⇒m≤n : ∀ {m} n o → m ≤ n ⊓ o → m ≤ n
m≤n⊓o⇒m≤n n o m≤n⊓o = ≤-trans m≤n⊓o (m⊓n≤m n o)
m≤n⊓o⇒m≤o : ∀ {m} n o → m ≤ n ⊓ o → m ≤ o
m≤n⊓o⇒m≤o n o m≤n⊓o = ≤-trans m≤n⊓o (m⊓n≤n n o)
m<n⇒m⊓o<n : ∀ {m n} o → m < n → m ⊓ o < n
m<n⇒m⊓o<n o m<n = <-transʳ (m⊓n≤m _ o) m<n
m<n⇒o⊓m<n : ∀ {m n} o → m < n → o ⊓ m < n
m<n⇒o⊓m<n o m<n = <-transʳ (m⊓n≤n o _) m<n
m<n⊓o⇒m<n : ∀ {m} n o → m < n ⊓ o → m < n
m<n⊓o⇒m<n = m≤n⊓o⇒m≤n
m<n⊓o⇒m<o : ∀ {m} n o → m < n ⊓ o → m < o
m<n⊓o⇒m<o = m≤n⊓o⇒m≤o
⊓-mono-≤ : _⊓_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
⊓-mono-≤ {m} {n} {u} {v} m≤n u≤v with ⊓-sel n v
... | inj₁ n⊓v≡n rewrite n⊓v≡n = ≤-trans (m⊓n≤m m u) m≤n
... | inj₂ n⊓v≡v rewrite n⊓v≡v = ≤-trans (m⊓n≤n m u) u≤v
⊓-monoˡ-≤ : ∀ n → (_⊓ n) Preserves _≤_ ⟶ _≤_
⊓-monoˡ-≤ n m≤o = ⊓-mono-≤ m≤o (≤-refl {n})
⊓-monoʳ-≤ : ∀ n → (n ⊓_) Preserves _≤_ ⟶ _≤_
⊓-monoʳ-≤ n m≤o = ⊓-mono-≤ (≤-refl {n}) m≤o
⊓-mono-< : _⊓_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
⊓-mono-< = ⊓-mono-≤
m⊓n≤m⊔n : ∀ m n → m ⊓ n ≤ m ⊔ n
m⊓n≤m⊔n zero n = z≤n
m⊓n≤m⊔n (suc m) zero = z≤n
m⊓n≤m⊔n (suc m) (suc n) = s≤s (m⊓n≤m⊔n m n)
⊓-pres-m≤ : ∀ {m n o} → m ≤ n → m ≤ o → m ≤ n ⊓ o
⊓-pres-m≤ {m} m≤n m≤o = subst (_≤ _) (⊓-idem m) (⊓-mono-≤ m≤n m≤o)
⊓-pres-m< : ∀ {m n o} → m < n → m < o → m < n ⊓ o
⊓-pres-m< {m} m<n m<o = subst (_< _) (⊓-idem m) (⊓-mono-< m<n m<o)
------------------------------------------------------------------------
-- Other properties of _⊓_ and _+_
+-distribˡ-⊓ : _+_ DistributesOverˡ _⊓_
+-distribˡ-⊓ zero n o = refl
+-distribˡ-⊓ (suc m) n o = cong suc (+-distribˡ-⊓ m n o)
+-distribʳ-⊓ : _+_ DistributesOverʳ _⊓_
+-distribʳ-⊓ = comm+distrˡ⇒distrʳ +-comm +-distribˡ-⊓
+-distrib-⊓ : _+_ DistributesOver _⊓_
+-distrib-⊓ = +-distribˡ-⊓ , +-distribʳ-⊓
m⊓n≤m+n : ∀ m n → m ⊓ n ≤ m + n
m⊓n≤m+n m n with ⊓-sel m n
... | inj₁ m⊓n≡m rewrite m⊓n≡m = m≤m+n m n
... | inj₂ m⊓n≡n rewrite m⊓n≡n = m≤n+m n m
------------------------------------------------------------------------
-- Properties of _∸_
------------------------------------------------------------------------
0∸n≡0 : LeftZero zero _∸_
0∸n≡0 zero = refl
0∸n≡0 (suc _) = refl
n∸n≡0 : ∀ n → n ∸ n ≡ 0
n∸n≡0 zero = refl
n∸n≡0 (suc n) = n∸n≡0 n
------------------------------------------------------------------------
-- Properties of _∸_ and _≤_/_<_
m∸n≤m : ∀ m n → m ∸ n ≤ m
m∸n≤m n zero = ≤-refl
m∸n≤m zero (suc n) = ≤-refl
m∸n≤m (suc m) (suc n) = ≤-trans (m∸n≤m m n) (n≤1+n m)
m≮m∸n : ∀ m n → m ≮ m ∸ n
m≮m∸n m zero = n≮n m
m≮m∸n (suc m) (suc n) = m≮m∸n m n ∘ ≤-trans (n≤1+n (suc m))
1+m≢m∸n : ∀ {m} n → suc m ≢ m ∸ n
1+m≢m∸n {m} n eq = m≮m∸n m n (≤-reflexive eq)
∸-mono : _∸_ Preserves₂ _≤_ ⟶ _≥_ ⟶ _≤_
∸-mono z≤n (s≤s n₁≥n₂) = z≤n
∸-mono (s≤s m₁≤m₂) (s≤s n₁≥n₂) = ∸-mono m₁≤m₂ n₁≥n₂
∸-mono m₁≤m₂ (z≤n {n = n₁}) = ≤-trans (m∸n≤m _ n₁) m₁≤m₂
∸-monoˡ-≤ : ∀ {m n} o → m ≤ n → m ∸ o ≤ n ∸ o
∸-monoˡ-≤ o m≤n = ∸-mono {u = o} m≤n ≤-refl
∸-monoʳ-≤ : ∀ {m n} o → m ≤ n → o ∸ m ≥ o ∸ n
∸-monoʳ-≤ _ m≤n = ∸-mono ≤-refl m≤n
∸-monoʳ-< : ∀ {m n o} → o < n → n ≤ m → m ∸ n < m ∸ o
∸-monoʳ-< {n = suc n} {zero} (s≤s o<n) (s≤s n<m) = s≤s (m∸n≤m _ n)
∸-monoʳ-< {n = suc n} {suc o} (s≤s o<n) (s≤s n<m) = ∸-monoʳ-< o<n n<m
∸-cancelʳ-≤ : ∀ {m n o} → m ≤ o → o ∸ n ≤ o ∸ m → m ≤ n
∸-cancelʳ-≤ {_} {_} z≤n _ = z≤n
∸-cancelʳ-≤ {suc m} {zero} (s≤s _) o<o∸m = contradiction o<o∸m (m≮m∸n _ m)
∸-cancelʳ-≤ {suc m} {suc n} (s≤s m≤o) o∸n<o∸m = s≤s (∸-cancelʳ-≤ m≤o o∸n<o∸m)
∸-cancelʳ-< : ∀ {m n o} → o ∸ m < o ∸ n → n < m
∸-cancelʳ-< {zero} {n} {o} o<o∸n = contradiction o<o∸n (m≮m∸n o n)
∸-cancelʳ-< {suc m} {zero} {_} o∸n<o∸m = 0<1+n
∸-cancelʳ-< {suc m} {suc n} {suc o} o∸n<o∸m = s≤s (∸-cancelʳ-< o∸n<o∸m)
∸-cancelˡ-≡ : ∀ {m n o} → n ≤ m → o ≤ m → m ∸ n ≡ m ∸ o → n ≡ o
∸-cancelˡ-≡ {_} z≤n z≤n _ = refl
∸-cancelˡ-≡ {o = suc o} z≤n (s≤s _) eq = contradiction eq (1+m≢m∸n o)
∸-cancelˡ-≡ {n = suc n} (s≤s _) z≤n eq = contradiction (sym eq) (1+m≢m∸n n)
∸-cancelˡ-≡ {_} (s≤s n≤m) (s≤s o≤m) eq = cong suc (∸-cancelˡ-≡ n≤m o≤m eq)
∸-cancelʳ-≡ : ∀ {m n o} → o ≤ m → o ≤ n → m ∸ o ≡ n ∸ o → m ≡ n
∸-cancelʳ-≡ z≤n z≤n eq = eq
∸-cancelʳ-≡ (s≤s o≤m) (s≤s o≤n) eq = cong suc (∸-cancelʳ-≡ o≤m o≤n eq)
m∸n≡0⇒m≤n : ∀ {m n} → m ∸ n ≡ 0 → m ≤ n
m∸n≡0⇒m≤n {zero} {_} _ = z≤n
m∸n≡0⇒m≤n {suc m} {suc n} eq = s≤s (m∸n≡0⇒m≤n eq)
m≤n⇒m∸n≡0 : ∀ {m n} → m ≤ n → m ∸ n ≡ 0
m≤n⇒m∸n≡0 {n = n} z≤n = 0∸n≡0 n
m≤n⇒m∸n≡0 {_} (s≤s m≤n) = m≤n⇒m∸n≡0 m≤n
m<n⇒0<n∸m : ∀ {m n} → m < n → 0 < n ∸ m
m<n⇒0<n∸m {zero} {suc n} _ = 0<1+n
m<n⇒0<n∸m {suc m} {suc n} (s≤s m<n) = m<n⇒0<n∸m m<n
m∸n≢0⇒n<m : ∀ {m n} → m ∸ n ≢ 0 → n < m
m∸n≢0⇒n<m {m} {n} m∸n≢0 with n <? m
... | yes n<m = n<m
... | no n≮m = contradiction (m≤n⇒m∸n≡0 (≮⇒≥ n≮m)) m∸n≢0
m>n⇒m∸n≢0 : ∀ {m n} → m > n → m ∸ n ≢ 0
m>n⇒m∸n≢0 {n = suc n} (s≤s m>n) = m>n⇒m∸n≢0 m>n
---------------------------------------------------------------
-- Properties of _∸_ and _+_
+-∸-comm : ∀ {m} n {o} → o ≤ m → (m + n) ∸ o ≡ (m ∸ o) + n
+-∸-comm {zero} _ {zero} _ = refl
+-∸-comm {suc m} _ {zero} _ = refl
+-∸-comm {suc m} n {suc o} (s≤s o≤m) = +-∸-comm n o≤m
∸-+-assoc : ∀ m n o → (m ∸ n) ∸ o ≡ m ∸ (n + o)
∸-+-assoc zero zero o = refl
∸-+-assoc zero (suc n) o = 0∸n≡0 o
∸-+-assoc (suc m) zero o = refl
∸-+-assoc (suc m) (suc n) o = ∸-+-assoc m n o
+-∸-assoc : ∀ m {n o} → o ≤ n → (m + n) ∸ o ≡ m + (n ∸ o)
+-∸-assoc m (z≤n {n = n}) = begin-equality m + n ∎
+-∸-assoc m (s≤s {m = o} {n = n} o≤n) = begin-equality
(m + suc n) ∸ suc o ≡⟨ cong (_∸ suc o) (+-suc m n) ⟩
suc (m + n) ∸ suc o ≡⟨⟩
(m + n) ∸ o ≡⟨ +-∸-assoc m o≤n ⟩
m + (n ∸ o) ∎
m≤n+m∸n : ∀ m n → m ≤ n + (m ∸ n)
m≤n+m∸n zero n = z≤n
m≤n+m∸n (suc m) zero = ≤-refl
m≤n+m∸n (suc m) (suc n) = s≤s (m≤n+m∸n m n)
m+n∸n≡m : ∀ m n → m + n ∸ n ≡ m
m+n∸n≡m m n = begin-equality
(m + n) ∸ n ≡⟨ +-∸-assoc m (≤-refl {x = n}) ⟩
m + (n ∸ n) ≡⟨ cong (m +_) (n∸n≡0 n) ⟩
m + 0 ≡⟨ +-identityʳ m ⟩
m ∎
m+n∸m≡n : ∀ m n → m + n ∸ m ≡ n
m+n∸m≡n m n = trans (cong (_∸ m) (+-comm m n)) (m+n∸n≡m n m)
m+[n∸m]≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n
m+[n∸m]≡n {m} {n} m≤n = begin-equality
m + (n ∸ m) ≡⟨ sym $ +-∸-assoc m m≤n ⟩
(m + n) ∸ m ≡⟨ cong (_∸ m) (+-comm m n) ⟩
(n + m) ∸ m ≡⟨ m+n∸n≡m n m ⟩
n ∎
m∸n+n≡m : ∀ {m n} → n ≤ m → (m ∸ n) + n ≡ m
m∸n+n≡m {m} {n} n≤m = begin-equality
(m ∸ n) + n ≡⟨ sym (+-∸-comm n n≤m) ⟩
(m + n) ∸ n ≡⟨ m+n∸n≡m m n ⟩
m ∎
m∸[m∸n]≡n : ∀ {m n} → n ≤ m → m ∸ (m ∸ n) ≡ n
m∸[m∸n]≡n {m} {_} z≤n = n∸n≡0 m
m∸[m∸n]≡n {suc m} {suc n} (s≤s n≤m) = begin-equality
suc m ∸ (m ∸ n) ≡⟨ +-∸-assoc 1 (m∸n≤m m n) ⟩
suc (m ∸ (m ∸ n)) ≡⟨ cong suc (m∸[m∸n]≡n n≤m) ⟩
suc n ∎
[m+n]∸[m+o]≡n∸o : ∀ m n o → (m + n) ∸ (m + o) ≡ n ∸ o
[m+n]∸[m+o]≡n∸o zero n o = refl
[m+n]∸[m+o]≡n∸o (suc m) n o = [m+n]∸[m+o]≡n∸o m n o
------------------------------------------------------------------------
-- Properties of _∸_ and _*_
*-distribʳ-∸ : _*_ DistributesOverʳ _∸_
*-distribʳ-∸ m zero zero = refl
*-distribʳ-∸ zero zero (suc o) = sym (0∸n≡0 (o * zero))
*-distribʳ-∸ (suc m) zero (suc o) = refl
*-distribʳ-∸ m (suc n) zero = refl
*-distribʳ-∸ m (suc n) (suc o) = begin-equality
(n ∸ o) * m ≡⟨ *-distribʳ-∸ m n o ⟩
n * m ∸ o * m ≡⟨ sym $ [m+n]∸[m+o]≡n∸o m _ _ ⟩
m + n * m ∸ (m + o * m) ∎
*-distribˡ-∸ : _*_ DistributesOverˡ _∸_
*-distribˡ-∸ = comm+distrʳ⇒distrˡ *-comm *-distribʳ-∸
*-distrib-∸ : _*_ DistributesOver _∸_
*-distrib-∸ = *-distribˡ-∸ , *-distribʳ-∸
even≢odd : ∀ m n → 2 * m ≢ suc (2 * n)
even≢odd (suc m) zero eq = contradiction (suc-injective eq) (m+1+n≢0 m)
even≢odd (suc m) (suc n) eq = even≢odd m n (suc-injective (begin-equality
suc (2 * m) ≡⟨ sym (+-suc m _) ⟩
m + suc (m + 0) ≡⟨ suc-injective eq ⟩
suc n + suc (n + 0) ≡⟨ cong suc (+-suc n _) ⟩
suc (suc (2 * n)) ∎))
------------------------------------------------------------------------
-- Properties of _∸_ and _⊓_ and _⊔_
m⊓n+n∸m≡n : ∀ m n → (m ⊓ n) + (n ∸ m) ≡ n
m⊓n+n∸m≡n zero n = refl
m⊓n+n∸m≡n (suc m) zero = refl
m⊓n+n∸m≡n (suc m) (suc n) = cong suc $ m⊓n+n∸m≡n m n
[m∸n]⊓[n∸m]≡0 : ∀ m n → (m ∸ n) ⊓ (n ∸ m) ≡ 0
[m∸n]⊓[n∸m]≡0 zero zero = refl
[m∸n]⊓[n∸m]≡0 zero (suc n) = refl
[m∸n]⊓[n∸m]≡0 (suc m) zero = refl
[m∸n]⊓[n∸m]≡0 (suc m) (suc n) = [m∸n]⊓[n∸m]≡0 m n
∸-distribˡ-⊓-⊔ : ∀ m n o → m ∸ (n ⊓ o) ≡ (m ∸ n) ⊔ (m ∸ o)
∸-distribˡ-⊓-⊔ m zero zero = sym (⊔-idem m)
∸-distribˡ-⊓-⊔ zero zero (suc o) = refl
∸-distribˡ-⊓-⊔ zero (suc n) zero = refl
∸-distribˡ-⊓-⊔ zero (suc n) (suc o) = refl
∸-distribˡ-⊓-⊔ (suc m) (suc n) zero = sym (m≤n⇒m⊔n≡n (≤-step (m∸n≤m m n)))
∸-distribˡ-⊓-⊔ (suc m) zero (suc o) = sym (m≤n⇒n⊔m≡n (≤-step (m∸n≤m m o)))
∸-distribˡ-⊓-⊔ (suc m) (suc n) (suc o) = ∸-distribˡ-⊓-⊔ m n o
∸-distribʳ-⊓ : _∸_ DistributesOverʳ _⊓_
∸-distribʳ-⊓ zero n o = refl
∸-distribʳ-⊓ (suc m) zero o = refl
∸-distribʳ-⊓ (suc m) (suc n) zero = sym (⊓-zeroʳ (n ∸ m))
∸-distribʳ-⊓ (suc m) (suc n) (suc o) = ∸-distribʳ-⊓ m n o
∸-distribˡ-⊔-⊓ : ∀ m n o → m ∸ (n ⊔ o) ≡ (m ∸ n) ⊓ (m ∸ o)
∸-distribˡ-⊔-⊓ m zero zero = sym (⊓-idem m)
∸-distribˡ-⊔-⊓ zero zero o = 0∸n≡0 o
∸-distribˡ-⊔-⊓ zero (suc n) o = 0∸n≡0 (suc n ⊔ o)
∸-distribˡ-⊔-⊓ (suc m) (suc n) zero = sym (m≤n⇒m⊓n≡m (≤-step (m∸n≤m m n)))
∸-distribˡ-⊔-⊓ (suc m) zero (suc o) = sym (m≤n⇒n⊓m≡m (≤-step (m∸n≤m m o)))
∸-distribˡ-⊔-⊓ (suc m) (suc n) (suc o) = ∸-distribˡ-⊔-⊓ m n o
∸-distribʳ-⊔ : _∸_ DistributesOverʳ _⊔_
∸-distribʳ-⊔ zero n o = refl
∸-distribʳ-⊔ (suc m) zero o = refl
∸-distribʳ-⊔ (suc m) (suc n) zero = sym (⊔-identityʳ (n ∸ m))
∸-distribʳ-⊔ (suc m) (suc n) (suc o) = ∸-distribʳ-⊔ m n o
------------------------------------------------------------------------
-- Properties of ∣_-_∣
------------------------------------------------------------------------
m≡n⇒∣m-n∣≡0 : ∀ {m n} → m ≡ n → ∣ m - n ∣ ≡ 0
m≡n⇒∣m-n∣≡0 {zero} refl = refl
m≡n⇒∣m-n∣≡0 {suc m} refl = m≡n⇒∣m-n∣≡0 {m} refl
∣m-n∣≡0⇒m≡n : ∀ {m n} → ∣ m - n ∣ ≡ 0 → m ≡ n
∣m-n∣≡0⇒m≡n {zero} {zero} eq = refl
∣m-n∣≡0⇒m≡n {suc m} {suc n} eq = cong suc (∣m-n∣≡0⇒m≡n eq)
m≤n⇒∣n-m∣≡n∸m : ∀ {m n} → m ≤ n → ∣ n - m ∣ ≡ n ∸ m
m≤n⇒∣n-m∣≡n∸m {_} {zero} z≤n = refl
m≤n⇒∣n-m∣≡n∸m {_} {suc m} z≤n = refl
m≤n⇒∣n-m∣≡n∸m {_} {_} (s≤s m≤n) = m≤n⇒∣n-m∣≡n∸m m≤n
∣m-n∣≡m∸n⇒n≤m : ∀ {m n} → ∣ m - n ∣ ≡ m ∸ n → n ≤ m
∣m-n∣≡m∸n⇒n≤m {zero} {zero} eq = z≤n
∣m-n∣≡m∸n⇒n≤m {suc m} {zero} eq = z≤n
∣m-n∣≡m∸n⇒n≤m {suc m} {suc n} eq = s≤s (∣m-n∣≡m∸n⇒n≤m eq)
∣n-n∣≡0 : ∀ n → ∣ n - n ∣ ≡ 0
∣n-n∣≡0 n = m≡n⇒∣m-n∣≡0 {n} refl
∣m-m+n∣≡n : ∀ m n → ∣ m - m + n ∣ ≡ n
∣m-m+n∣≡n zero n = refl
∣m-m+n∣≡n (suc m) n = ∣m-m+n∣≡n m n
∣m+n-m+o∣≡∣n-o| : ∀ m n o → ∣ m + n - m + o ∣ ≡ ∣ n - o ∣
∣m+n-m+o∣≡∣n-o| zero n o = refl
∣m+n-m+o∣≡∣n-o| (suc m) n o = ∣m+n-m+o∣≡∣n-o| m n o
m∸n≤∣m-n∣ : ∀ m n → m ∸ n ≤ ∣ m - n ∣
m∸n≤∣m-n∣ m n with ≤-total m n
... | inj₁ m≤n = subst (_≤ ∣ m - n ∣) (sym (m≤n⇒m∸n≡0 m≤n)) z≤n
... | inj₂ n≤m = subst (m ∸ n ≤_) (sym (m≤n⇒∣n-m∣≡n∸m n≤m)) ≤-refl
∣m-n∣≤m⊔n : ∀ m n → ∣ m - n ∣ ≤ m ⊔ n
∣m-n∣≤m⊔n zero m = ≤-refl
∣m-n∣≤m⊔n (suc m) zero = ≤-refl
∣m-n∣≤m⊔n (suc m) (suc n) = ≤-step (∣m-n∣≤m⊔n m n)
∣-∣-identityˡ : LeftIdentity 0 ∣_-_∣
∣-∣-identityˡ x = refl
∣-∣-identityʳ : RightIdentity 0 ∣_-_∣
∣-∣-identityʳ zero = refl
∣-∣-identityʳ (suc x) = refl
∣-∣-identity : Identity 0 ∣_-_∣
∣-∣-identity = ∣-∣-identityˡ , ∣-∣-identityʳ
∣-∣-comm : Commutative ∣_-_∣
∣-∣-comm zero zero = refl
∣-∣-comm zero (suc n) = refl
∣-∣-comm (suc m) zero = refl
∣-∣-comm (suc m) (suc n) = ∣-∣-comm m n
∣m-n∣≡[m∸n]∨[n∸m] : ∀ m n → (∣ m - n ∣ ≡ m ∸ n) ⊎ (∣ m - n ∣ ≡ n ∸ m)
∣m-n∣≡[m∸n]∨[n∸m] m n with ≤-total m n
... | inj₂ n≤m = inj₁ $ m≤n⇒∣n-m∣≡n∸m n≤m
... | inj₁ m≤n = inj₂ $ begin-equality
∣ m - n ∣ ≡⟨ ∣-∣-comm m n ⟩
∣ n - m ∣ ≡⟨ m≤n⇒∣n-m∣≡n∸m m≤n ⟩
n ∸ m ∎
private
*-distribˡ-∣-∣-aux : ∀ a m n → m ≤ n → a * ∣ n - m ∣ ≡ ∣ a * n - a * m ∣
*-distribˡ-∣-∣-aux a m n m≤n = begin-equality
a * ∣ n - m ∣ ≡⟨ cong (a *_) (m≤n⇒∣n-m∣≡n∸m m≤n) ⟩
a * (n ∸ m) ≡⟨ *-distribˡ-∸ a n m ⟩
a * n ∸ a * m ≡⟨ sym $′ m≤n⇒∣n-m∣≡n∸m (*-monoʳ-≤ a m≤n) ⟩
∣ a * n - a * m ∣ ∎
*-distribˡ-∣-∣ : _*_ DistributesOverˡ ∣_-_∣
*-distribˡ-∣-∣ a m n with ≤-total m n
... | inj₁ m≤n = begin-equality
a * ∣ m - n ∣ ≡⟨ cong (a *_) (∣-∣-comm m n) ⟩
a * ∣ n - m ∣ ≡⟨ *-distribˡ-∣-∣-aux a m n m≤n ⟩
∣ a * n - a * m ∣ ≡⟨ ∣-∣-comm (a * n) (a * m) ⟩
∣ a * m - a * n ∣ ∎
... | inj₂ n≤m = *-distribˡ-∣-∣-aux a n m n≤m
*-distribʳ-∣-∣ : _*_ DistributesOverʳ ∣_-_∣
*-distribʳ-∣-∣ = comm+distrˡ⇒distrʳ *-comm *-distribˡ-∣-∣
*-distrib-∣-∣ : _*_ DistributesOver ∣_-_∣
*-distrib-∣-∣ = *-distribˡ-∣-∣ , *-distribʳ-∣-∣
m≤n+∣n-m∣ : ∀ m n → m ≤ n + ∣ n - m ∣
m≤n+∣n-m∣ zero n = z≤n
m≤n+∣n-m∣ (suc m) zero = ≤-refl
m≤n+∣n-m∣ (suc m) (suc n) = s≤s (m≤n+∣n-m∣ m n)
m≤n+∣m-n∣ : ∀ m n → m ≤ n + ∣ m - n ∣
m≤n+∣m-n∣ m n = subst (m ≤_) (cong (n +_) (∣-∣-comm n m)) (m≤n+∣n-m∣ m n)
m≤∣m-n∣+n : ∀ m n → m ≤ ∣ m - n ∣ + n
m≤∣m-n∣+n m n = subst (m ≤_) (+-comm n _) (m≤n+∣m-n∣ m n)
------------------------------------------------------------------------
-- Properties of ⌊_/2⌋ and ⌈_/2⌉
------------------------------------------------------------------------
⌊n/2⌋-mono : ⌊_/2⌋ Preserves _≤_ ⟶ _≤_
⌊n/2⌋-mono z≤n = z≤n
⌊n/2⌋-mono (s≤s z≤n) = z≤n
⌊n/2⌋-mono (s≤s (s≤s m≤n)) = s≤s (⌊n/2⌋-mono m≤n)
⌈n/2⌉-mono : ⌈_/2⌉ Preserves _≤_ ⟶ _≤_
⌈n/2⌉-mono m≤n = ⌊n/2⌋-mono (s≤s m≤n)
⌊n/2⌋≤⌈n/2⌉ : ∀ n → ⌊ n /2⌋ ≤ ⌈ n /2⌉
⌊n/2⌋≤⌈n/2⌉ zero = z≤n
⌊n/2⌋≤⌈n/2⌉ (suc zero) = z≤n
⌊n/2⌋≤⌈n/2⌉ (suc (suc n)) = s≤s (⌊n/2⌋≤⌈n/2⌉ n)
⌊n/2⌋+⌈n/2⌉≡n : ∀ n → ⌊ n /2⌋ + ⌈ n /2⌉ ≡ n
⌊n/2⌋+⌈n/2⌉≡n zero = refl
⌊n/2⌋+⌈n/2⌉≡n (suc n) = begin-equality
⌊ suc n /2⌋ + suc ⌊ n /2⌋ ≡⟨ +-comm ⌊ suc n /2⌋ (suc ⌊ n /2⌋) ⟩
suc ⌊ n /2⌋ + ⌊ suc n /2⌋ ≡⟨⟩
suc (⌊ n /2⌋ + ⌊ suc n /2⌋) ≡⟨ cong suc (⌊n/2⌋+⌈n/2⌉≡n n) ⟩
suc n ∎
⌊n/2⌋≤n : ∀ n → ⌊ n /2⌋ ≤ n
⌊n/2⌋≤n zero = z≤n
⌊n/2⌋≤n (suc zero) = z≤n
⌊n/2⌋≤n (suc (suc n)) = s≤s (≤-step (⌊n/2⌋≤n n))
⌊n/2⌋<n : ∀ n → ⌊ suc n /2⌋ < suc n
⌊n/2⌋<n zero = s≤s z≤n
⌊n/2⌋<n (suc n) = s≤s (s≤s (⌊n/2⌋≤n n))
⌈n/2⌉≤n : ∀ n → ⌈ n /2⌉ ≤ n
⌈n/2⌉≤n zero = z≤n
⌈n/2⌉≤n (suc n) = s≤s (⌊n/2⌋≤n n)
⌈n/2⌉<n : ∀ n → ⌈ suc (suc n) /2⌉ < suc (suc n)
⌈n/2⌉<n n = s≤s (⌊n/2⌋<n n)
------------------------------------------------------------------------
-- Properties of _≤′_ and _<′_
------------------------------------------------------------------------
≤′-trans : Transitive _≤′_
≤′-trans m≤n ≤′-refl = m≤n
≤′-trans m≤n (≤′-step n≤o) = ≤′-step (≤′-trans m≤n n≤o)
z≤′n : ∀ {n} → zero ≤′ n
z≤′n {zero} = ≤′-refl
z≤′n {suc n} = ≤′-step z≤′n
s≤′s : ∀ {m n} → m ≤′ n → suc m ≤′ suc n
s≤′s ≤′-refl = ≤′-refl
s≤′s (≤′-step m≤′n) = ≤′-step (s≤′s m≤′n)
≤′⇒≤ : _≤′_ ⇒ _≤_
≤′⇒≤ ≤′-refl = ≤-refl
≤′⇒≤ (≤′-step m≤′n) = ≤-step (≤′⇒≤ m≤′n)
≤⇒≤′ : _≤_ ⇒ _≤′_
≤⇒≤′ z≤n = z≤′n
≤⇒≤′ (s≤s m≤n) = s≤′s (≤⇒≤′ m≤n)
≤′-step-injective : ∀ {m n} {p q : m ≤′ n} → ≤′-step p ≡ ≤′-step q → p ≡ q
≤′-step-injective refl = refl
infix 4 _≤′?_ _<′?_ _≥′?_ _>′?_
_≤′?_ : Decidable _≤′_
m ≤′? n = map′ ≤⇒≤′ ≤′⇒≤ (m ≤? n)
_<′?_ : Decidable _<′_
m <′? n = suc m ≤′? n
_≥′?_ : Decidable _≥′_
_≥′?_ = flip _≤′?_
_>′?_ : Decidable _>′_
_>′?_ = flip _<′?_
m≤′m+n : ∀ m n → m ≤′ m + n
m≤′m+n m n = ≤⇒≤′ (m≤m+n m n)
n≤′m+n : ∀ m n → n ≤′ m + n
n≤′m+n zero n = ≤′-refl
n≤′m+n (suc m) n = ≤′-step (n≤′m+n m n)
⌈n/2⌉≤′n : ∀ n → ⌈ n /2⌉ ≤′ n
⌈n/2⌉≤′n zero = ≤′-refl
⌈n/2⌉≤′n (suc zero) = ≤′-refl
⌈n/2⌉≤′n (suc (suc n)) = s≤′s (≤′-step (⌈n/2⌉≤′n n))
⌊n/2⌋≤′n : ∀ n → ⌊ n /2⌋ ≤′ n
⌊n/2⌋≤′n zero = ≤′-refl
⌊n/2⌋≤′n (suc n) = ≤′-step (⌈n/2⌉≤′n n)
------------------------------------------------------------------------
-- Properties of _≤″_ and _<″_
------------------------------------------------------------------------
m<ᵇn⇒1+m+[n-1+m]≡n : ∀ m n → T (m <ᵇ n) → suc m + (n ∸ suc m) ≡ n
m<ᵇn⇒1+m+[n-1+m]≡n m n lt = m+[n∸m]≡n (<ᵇ⇒< m n lt)
m<ᵇ1+m+n : ∀ m {n} → T (m <ᵇ suc (m + n))
m<ᵇ1+m+n m = <⇒<ᵇ (m≤m+n (suc m) _)
<ᵇ⇒<″ : ∀ {m n} → T (m <ᵇ n) → m <″ n
<ᵇ⇒<″ {m} {n} leq = less-than-or-equal (m+[n∸m]≡n (<ᵇ⇒< m n leq))
<″⇒<ᵇ : ∀ {m n} → m <″ n → T (m <ᵇ n)
<″⇒<ᵇ {m} (less-than-or-equal refl) = <⇒<ᵇ (m≤m+n (suc m) _)
-- equivalence to _≤_
≤″⇒≤ : _≤″_ ⇒ _≤_
≤″⇒≤ {zero} (less-than-or-equal refl) = z≤n
≤″⇒≤ {suc m} (less-than-or-equal refl) =
s≤s (≤″⇒≤ (less-than-or-equal refl))
≤⇒≤″ : _≤_ ⇒ _≤″_
≤⇒≤″ = less-than-or-equal ∘ m+[n∸m]≡n
-- NB: we use the builtin function `_<ᵇ_ : (m n : ℕ) → Bool` here so
-- that the function quickly decides whether to return `yes` or `no`.
-- It still takes a linear amount of time to generate the proof if it
-- is inspected. We expect the main benefit to be visible for compiled
-- code: the backend erases proofs.
infix 4 _<″?_ _≤″?_ _≥″?_ _>″?_
_<″?_ : Decidable _<″_
m <″? n = map′ <ᵇ⇒<″ <″⇒<ᵇ (T? (m <ᵇ n))
_≤″?_ : Decidable _≤″_
zero ≤″? n = yes (less-than-or-equal refl)
suc m ≤″? n = m <″? n
_≥″?_ : Decidable _≥″_
_≥″?_ = flip _≤″?_
_>″?_ : Decidable _>″_
_>″?_ = flip _<″?_
≤″-irrelevant : Irrelevant _≤″_
≤″-irrelevant {m} (less-than-or-equal eq₁)
(less-than-or-equal eq₂)
with +-cancelˡ-≡ m (trans eq₁ (sym eq₂))
... | refl = cong less-than-or-equal (≡-irrelevant eq₁ eq₂)
<″-irrelevant : Irrelevant _<″_
<″-irrelevant = ≤″-irrelevant
>″-irrelevant : Irrelevant _>″_
>″-irrelevant = ≤″-irrelevant
≥″-irrelevant : Irrelevant _≥″_
≥″-irrelevant = ≤″-irrelevant
------------------------------------------------------------------------
-- Properties of _≤‴_
------------------------------------------------------------------------
≤‴⇒≤″ : ∀{m n} → m ≤‴ n → m ≤″ n
≤‴⇒≤″ {m = m} ≤‴-refl = less-than-or-equal {k = 0} (+-identityʳ m)
≤‴⇒≤″ {m = m} (≤‴-step x) = less-than-or-equal (trans (+-suc m _) (_≤″_.proof ind)) where
ind = ≤‴⇒≤″ x
m≤‴m+k : ∀{m n k} → m + k ≡ n → m ≤‴ n
m≤‴m+k {m} {k = zero} refl = subst (λ z → m ≤‴ z) (sym (+-identityʳ m)) (≤‴-refl {m})
m≤‴m+k {m} {k = suc k} proof
= ≤‴-step (m≤‴m+k {k = k} (trans (sym (+-suc m _)) proof))
≤″⇒≤‴ : ∀{m n} → m ≤″ n → m ≤‴ n
≤″⇒≤‴ (less-than-or-equal {k} proof) = m≤‴m+k proof
------------------------------------------------------------------------
-- Other properties
------------------------------------------------------------------------
-- If there is an injection from a type to ℕ, then the type has
-- decidable equality.
eq? : ∀ {a} {A : Set a} → A ↣ ℕ → Decidable {A = A} _≡_
eq? inj = via-injection inj _≟_
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.14
_*-mono_ = *-mono-≤
{-# WARNING_ON_USAGE _*-mono_
"Warning: _*-mono_ was deprecated in v0.14.
Please use *-mono-≤ instead."
#-}
_+-mono_ = +-mono-≤
{-# WARNING_ON_USAGE _+-mono_
"Warning: _+-mono_ was deprecated in v0.14.
Please use +-mono-≤ instead."
#-}
+-right-identity = +-identityʳ
{-# WARNING_ON_USAGE +-right-identity
"Warning: +-right-identity was deprecated in v0.14.
Please use +-identityʳ instead."
#-}
*-right-zero = *-zeroʳ
{-# WARNING_ON_USAGE *-right-zero
"Warning: *-right-zero was deprecated in v0.14.
Please use *-zeroʳ instead."
#-}
distribʳ-*-+ = *-distribʳ-+
{-# WARNING_ON_USAGE distribʳ-*-+
"Warning: distribʳ-*-+ was deprecated in v0.14.
Please use *-distribʳ-+ instead."
#-}
*-distrib-∸ʳ = *-distribʳ-∸
{-# WARNING_ON_USAGE *-distrib-∸ʳ
"Warning: *-distrib-∸ʳ was deprecated in v0.14.
Please use *-distribʳ-∸ instead."
#-}
cancel-+-left = +-cancelˡ-≡
{-# WARNING_ON_USAGE cancel-+-left
"Warning: cancel-+-left was deprecated in v0.14.
Please use +-cancelˡ-≡ instead."
#-}
cancel-+-left-≤ = +-cancelˡ-≤
{-# WARNING_ON_USAGE cancel-+-left-≤
"Warning: cancel-+-left-≤ was deprecated in v0.14.
Please use +-cancelˡ-≤ instead."
#-}
cancel-*-right = *-cancelʳ-≡
{-# WARNING_ON_USAGE cancel-*-right
"Warning: cancel-*-right was deprecated in v0.14.
Please use *-cancelʳ-≡ instead."
#-}
cancel-*-right-≤ = *-cancelʳ-≤
{-# WARNING_ON_USAGE cancel-*-right-≤
"Warning: cancel-*-right-≤ was deprecated in v0.14.
Please use *-cancelʳ-≤ instead."
#-}
strictTotalOrder = <-strictTotalOrder
{-# WARNING_ON_USAGE strictTotalOrder
"Warning: strictTotalOrder was deprecated in v0.14.
Please use <-strictTotalOrder instead."
#-}
isCommutativeSemiring = *-+-isCommutativeSemiring
{-# WARNING_ON_USAGE isCommutativeSemiring
"Warning: isCommutativeSemiring was deprecated in v0.14.
Please use *-+-isCommutativeSemiring instead."
#-}
commutativeSemiring = *-+-commutativeSemiring
{-# WARNING_ON_USAGE commutativeSemiring
"Warning: commutativeSemiring was deprecated in v0.14.
Please use *-+-commutativeSemiring instead."
#-}
isDistributiveLattice = ⊓-⊔-isDistributiveLattice
{-# WARNING_ON_USAGE isDistributiveLattice
"Warning: isDistributiveLattice was deprecated in v0.14.
Please use ⊓-⊔-isDistributiveLattice instead."
#-}
distributiveLattice = ⊓-⊔-distributiveLattice
{-# WARNING_ON_USAGE distributiveLattice
"Warning: distributiveLattice was deprecated in v0.14.
Please use ⊓-⊔-distributiveLattice instead."
#-}
⊔-⊓-0-isSemiringWithoutOne = ⊔-⊓-isSemiringWithoutOne
{-# WARNING_ON_USAGE ⊔-⊓-0-isSemiringWithoutOne
"Warning: ⊔-⊓-0-isSemiringWithoutOne was deprecated in v0.14.
Please use ⊔-⊓-isSemiringWithoutOne instead."
#-}
⊔-⊓-0-isCommutativeSemiringWithoutOne = ⊔-⊓-isCommutativeSemiringWithoutOne
{-# WARNING_ON_USAGE ⊔-⊓-0-isCommutativeSemiringWithoutOne
"Warning: ⊔-⊓-0-isCommutativeSemiringWithoutOne was deprecated in v0.14.
Please use ⊔-⊓-isCommutativeSemiringWithoutOne instead."
#-}
⊔-⊓-0-commutativeSemiringWithoutOne = ⊔-⊓-commutativeSemiringWithoutOne
{-# WARNING_ON_USAGE ⊔-⊓-0-commutativeSemiringWithoutOne
"Warning: ⊔-⊓-0-commutativeSemiringWithoutOne was deprecated in v0.14.
Please use ⊔-⊓-commutativeSemiringWithoutOne instead."
#-}
-- Version 0.15
¬i+1+j≤i = m+1+n≰m
{-# WARNING_ON_USAGE ¬i+1+j≤i
"Warning: ¬i+1+j≤i was deprecated in v0.15.
Please use m+1+n≰m instead."
#-}
≤-steps = ≤-stepsˡ
{-# WARNING_ON_USAGE ≤-steps
"Warning: ≤-steps was deprecated in v0.15.
Please use ≤-stepsˡ instead."
#-}
-- Version 0.17
i∸k∸j+j∸k≡i+j∸k : ∀ i j k → i ∸ (k ∸ j) + (j ∸ k) ≡ i + j ∸ k
i∸k∸j+j∸k≡i+j∸k zero j k = cong (_+ (j ∸ k)) (0∸n≡0 (k ∸ j))
i∸k∸j+j∸k≡i+j∸k (suc i) j zero = cong (λ x → suc i ∸ x + j) (0∸n≡0 j)
i∸k∸j+j∸k≡i+j∸k (suc i) zero (suc k) = begin-equality
i ∸ k + 0 ≡⟨ +-identityʳ _ ⟩
i ∸ k ≡⟨ cong (_∸ k) (sym (+-identityʳ _)) ⟩
i + 0 ∸ k ∎
i∸k∸j+j∸k≡i+j∸k (suc i) (suc j) (suc k) = begin-equality
suc i ∸ (k ∸ j) + (j ∸ k) ≡⟨ i∸k∸j+j∸k≡i+j∸k (suc i) j k ⟩
suc i + j ∸ k ≡⟨ cong (_∸ k) (sym (+-suc i j)) ⟩
i + suc j ∸ k ∎
{-# WARNING_ON_USAGE i∸k∸j+j∸k≡i+j∸k
"Warning: i∸k∸j+j∸k≡i+j∸k was deprecated in v0.17."
#-}
im≡jm+n⇒[i∸j]m≡n : ∀ i j m n → i * m ≡ j * m + n → (i ∸ j) * m ≡ n
im≡jm+n⇒[i∸j]m≡n i j m n eq = begin-equality
(i ∸ j) * m ≡⟨ *-distribʳ-∸ m i j ⟩
(i * m) ∸ (j * m) ≡⟨ cong (_∸ j * m) eq ⟩
(j * m + n) ∸ (j * m) ≡⟨ cong (_∸ j * m) (+-comm (j * m) n) ⟩
(n + j * m) ∸ (j * m) ≡⟨ m+n∸n≡m n (j * m) ⟩
n ∎
{-# WARNING_ON_USAGE im≡jm+n⇒[i∸j]m≡n
"Warning: im≡jm+n⇒[i∸j]m≡n was deprecated in v0.17."
#-}
≤+≢⇒< = ≤∧≢⇒<
{-# WARNING_ON_USAGE ≤+≢⇒<
"Warning: ≤+≢⇒< was deprecated in v0.17.
Please use ≤∧≢⇒< instead."
#-}
-- Version 1.0
≤-irrelevance = ≤-irrelevant
{-# WARNING_ON_USAGE ≤-irrelevance
"Warning: ≤-irrelevance was deprecated in v1.0.
Please use ≤-irrelevant instead."
#-}
<-irrelevance = <-irrelevant
{-# WARNING_ON_USAGE <-irrelevance
"Warning: <-irrelevance was deprecated in v1.0.
Please use <-irrelevant instead."
#-}
-- Version 1.1
i+1+j≢i = m+1+n≢m
{-# WARNING_ON_USAGE i+1+j≢i
"Warning: i+1+j≢i was deprecated in v1.1.
Please use m+1+n≢m instead."
#-}
i+j≡0⇒i≡0 = m+n≡0⇒m≡0
{-# WARNING_ON_USAGE i+j≡0⇒i≡0
"Warning: i+j≡0⇒i≡0 was deprecated in v1.1.
Please use m+n≡0⇒m≡0 instead."
#-}
i+j≡0⇒j≡0 = m+n≡0⇒n≡0
{-# WARNING_ON_USAGE i+j≡0⇒j≡0
"Warning: i+j≡0⇒j≡0 was deprecated in v1.1.
Please use m+n≡0⇒n≡0 instead."
#-}
i+1+j≰i = m+1+n≰m
{-# WARNING_ON_USAGE i+1+j≰i
"Warning: i+1+j≰i was deprecated in v1.1.
Please use m+1+n≰m instead."
#-}
i*j≡0⇒i≡0∨j≡0 = m*n≡0⇒m≡0∨n≡0
{-# WARNING_ON_USAGE i*j≡0⇒i≡0∨j≡0
"Warning: i*j≡0⇒i≡0∨j≡0 was deprecated in v1.1.
Please use m*n≡0⇒m≡0∨n≡0 instead."
#-}
i*j≡1⇒i≡1 = m*n≡1⇒m≡1
{-# WARNING_ON_USAGE i*j≡1⇒i≡1
"Warning: i*j≡1⇒i≡1 was deprecated in v1.1.
Please use m*n≡1⇒m≡1 instead."
#-}
i*j≡1⇒j≡1 = m*n≡1⇒n≡1
{-# WARNING_ON_USAGE i*j≡1⇒j≡1
"Warning: i*j≡1⇒j≡1 was deprecated in v1.1.
Please use m*n≡1⇒n≡1 instead."
#-}
i^j≡0⇒i≡0 = m^n≡0⇒m≡0
{-# WARNING_ON_USAGE i^j≡0⇒i≡0
"Warning: i^j≡0⇒i≡0 was deprecated in v1.1.
Please use m^n≡0⇒m≡0 instead."
#-}
i^j≡1⇒j≡0∨i≡1 = m^n≡1⇒n≡0∨m≡1
{-# WARNING_ON_USAGE i^j≡1⇒j≡0∨i≡1
"Warning: i^j≡1⇒j≡0∨i≡1 was deprecated in v1.1.
Please use m^n≡1⇒n≡0∨m≡1 instead."
#-}
[i+j]∸[i+k]≡j∸k = [m+n]∸[m+o]≡n∸o
{-# WARNING_ON_USAGE [i+j]∸[i+k]≡j∸k
"Warning: [i+j]∸[i+k]≡j∸k was deprecated in v1.1.
Please use [m+n]∸[m+o]≡n∸o instead."
#-}
m≢0⇒suc[pred[m]]≡m = suc[pred[n]]≡n
{-# WARNING_ON_USAGE m≢0⇒suc[pred[m]]≡m
"Warning: m≢0⇒suc[pred[m]]≡m was deprecated in v1.1.
Please use suc[pred[n]]≡n instead."
#-}
n≡m⇒∣n-m∣≡0 = m≡n⇒∣m-n∣≡0
{-# WARNING_ON_USAGE n≡m⇒∣n-m∣≡0
"Warning: n≡m⇒∣n-m∣≡0 was deprecated in v1.1.
Please use m≡n⇒∣m-n∣≡0 instead."
#-}
∣n-m∣≡0⇒n≡m = ∣m-n∣≡0⇒m≡n
{-# WARNING_ON_USAGE ∣n-m∣≡0⇒n≡m
"Warning: ∣n-m∣≡0⇒n≡m was deprecated in v1.1.
Please use ∣m-n∣≡0⇒m≡n instead."
#-}
∣n-m∣≡n∸m⇒m≤n = ∣m-n∣≡m∸n⇒n≤m
{-# WARNING_ON_USAGE ∣n-m∣≡n∸m⇒m≤n
"Warning: ∣n-m∣≡n∸m⇒m≤n was deprecated in v1.1.
Please use ∣m-n∣≡m∸n⇒n≤m instead."
#-}
∣n-n+m∣≡m = ∣m-m+n∣≡n
{-# WARNING_ON_USAGE ∣n-n+m∣≡m
"Warning: ∣n-n+m∣≡m was deprecated in v1.1.
Please use ∣m-m+n∣≡n instead."
#-}
∣n+m-n+o∣≡∣m-o| = ∣m+n-m+o∣≡∣n-o|
{-# WARNING_ON_USAGE ∣n+m-n+o∣≡∣m-o|
"Warning: ∣n+m-n+o∣≡∣m-o| was deprecated in v1.1.
Please use ∣m+n-m+o∣≡∣n-o| instead."
#-}
n∸m≤∣n-m∣ = m∸n≤∣m-n∣
{-# WARNING_ON_USAGE n∸m≤∣n-m∣
"Warning: n∸m≤∣n-m∣ was deprecated in v1.1.
Please use m∸n≤∣m-n∣ instead."
#-}
∣n-m∣≤n⊔m = ∣m-n∣≤m⊔n
{-# WARNING_ON_USAGE ∣n-m∣≤n⊔m
"Warning: ∣n-m∣≤n⊔m was deprecated in v1.1.
Please use ∣m-n∣≤m⊔n instead."
#-}
n≤m+n : ∀ m n → n ≤ m + n
n≤m+n m n = subst (n ≤_) (+-comm n m) (m≤m+n n m)
{-# WARNING_ON_USAGE n≤m+n
"Warning: n≤m+n was deprecated in v1.1.
Please use m≤n+m instead (note, you will need to switch the argument order)."
#-}
n≤m+n∸m : ∀ m n → n ≤ m + (n ∸ m)
n≤m+n∸m m zero = z≤n
n≤m+n∸m zero (suc n) = ≤-refl
n≤m+n∸m (suc m) (suc n) = s≤s (n≤m+n∸m m n)
{-# WARNING_ON_USAGE n≤m+n∸m
"Warning: n≤m+n∸m was deprecated in v1.1.
Please use m≤n+m∸n instead (note, you will need to switch the argument order)."
#-}
∣n-m∣≡[n∸m]∨[m∸n] : ∀ m n → (∣ n - m ∣ ≡ n ∸ m) ⊎ (∣ n - m ∣ ≡ m ∸ n)
∣n-m∣≡[n∸m]∨[m∸n] m n with ≤-total m n
... | inj₁ m≤n = inj₁ $ m≤n⇒∣n-m∣≡n∸m m≤n
... | inj₂ n≤m = inj₂ $ begin-equality
∣ n - m ∣ ≡⟨ ∣-∣-comm n m ⟩
∣ m - n ∣ ≡⟨ m≤n⇒∣n-m∣≡n∸m n≤m ⟩
m ∸ n ∎
{-# WARNING_ON_USAGE ∣n-m∣≡[n∸m]∨[m∸n]
"Warning: ∣n-m∣≡[n∸m]∨[m∸n] was deprecated in v1.1.
Please use ∣m-n∣≡[m∸n]∨[n∸m] instead (note, you will need to switch the argument order)."
#-}
-- Version 1.2
+-*-suc = *-suc
{-# WARNING_ON_USAGE +-*-suc
"Warning: +-*-suc was deprecated in v1.2.
Please use *-suc instead."
#-}
n∸m≤n : ∀ m n → n ∸ m ≤ n
n∸m≤n m n = m∸n≤m n m
{-# WARNING_ON_USAGE n∸m≤n
"Warning: n∸m≤n was deprecated in v1.2.
Please use m∸n≤m instead (note, you will need to switch the argument order)."
#-}
-- Version 1.3
∀[m≤n⇒m≢o]⇒o<n : ∀ n o → (∀ {m} → m ≤ n → m ≢ o) → n < o
∀[m≤n⇒m≢o]⇒o<n = ∀[m≤n⇒m≢o]⇒n<o
{-# WARNING_ON_USAGE n∸m≤∣n-m∣
"Warning: ∀[m≤n⇒m≢o]⇒o<n was deprecated in v1.3.
Please use ∀[m≤n⇒m≢o]⇒n<o instead."
#-}
∀[m<n⇒m≢o]⇒o≤n : ∀ n o → (∀ {m} → m < n → m ≢ o) → n ≤ o
∀[m<n⇒m≢o]⇒o≤n = ∀[m<n⇒m≢o]⇒n≤o
{-# WARNING_ON_USAGE n∸m≤∣n-m∣
"Warning: ∀[m<n⇒m≢o]⇒o≤n was deprecated in v1.3.
Please use ∀[m<n⇒m≢o]⇒n≤o instead."
#-}
| 29.713468 | 89 | 0.473981 |
c5942ce6c1238af1d4aab88608cc8b5b07af1e27 | 823 | agda | Agda | agda/Categories/Pushout.agda | oisdk/combinatorics-paper | 3c176d4690566d81611080e9378f5a178b39b851 | [
"MIT"
] | 6 | 2020-09-11T17:45:41.000Z | 2021-11-16T08:11:34.000Z | agda/Categories/Pushout.agda | oisdk/combinatorics-paper | 3c176d4690566d81611080e9378f5a178b39b851 | [
"MIT"
] | null | null | null | agda/Categories/Pushout.agda | oisdk/combinatorics-paper | 3c176d4690566d81611080e9378f5a178b39b851 | [
"MIT"
] | 1 | 2021-11-11T12:30:21.000Z | 2021-11-11T12:30:21.000Z | {-# OPTIONS --cubical --safe #-}
open import Prelude hiding (A; B)
open import Categories
module Categories.Pushout {ℓ₁ ℓ₂} (C : Category ℓ₁ ℓ₂) where
open Category C
private
variable
A B : Ob
h₁ h₂ j : A ⟶ B
record Pushout (f : X ⟶ Y) (g : X ⟶ Z) : Type (ℓ₁ ℓ⊔ ℓ₂) where
field
{Q} : Ob
i₁ : Y ⟶ Q
i₂ : Z ⟶ Q
commute : i₁ · f ≡ i₂ · g
universal : h₁ · f ≡ h₂ · g → Q ⟶ Codomain h₁
unique : ∀ {eq : h₁ · f ≡ h₂ · g} →
j · i₁ ≡ h₁ → j · i₂ ≡ h₂ →
j ≡ universal eq
universal·i₁≡h₁ : ∀ {eq : h₁ · f ≡ h₂ · g} →
universal eq · i₁ ≡ h₁
universal·i₂≡h₂ : ∀ {eq : h₁ · f ≡ h₂ · g} →
universal eq · i₂ ≡ h₂
HasPushouts : Type (ℓ₁ ℓ⊔ ℓ₂)
HasPushouts = ∀ {X Y Z} → (f : X ⟶ Y) → (g : X ⟶ Z) → Pushout f g
| 24.939394 | 65 | 0.476306 |
235a824b62084edce3febd84b8c52ad2634a5a3e | 316 | agda | Agda | test/Common/Size.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | 4 | 2017-02-24T16:53:22.000Z | 2019-12-23T04:56:23.000Z | test/Common/Size.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | 6 | 2017-02-24T19:27:31.000Z | 2017-02-24T19:38:17.000Z | test/Common/Size.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | 1 | 2022-03-12T11:39:14.000Z | 2022-03-12T11:39:14.000Z | ------------------------------------------------------------------------
-- From the Agda standard library
--
-- Sizes for Agda's sized types
------------------------------------------------------------------------
module Common.Size where
open import Agda.Builtin.Size public renaming (ω to ∞; SizeU to SizeUniv)
| 31.6 | 73 | 0.401899 |
cb61f43baa8e6c9169b9a890009372a7cc2bad7c | 2,912 | agda | Agda | tests/covered/l02.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | 3 | 2015-08-10T15:33:56.000Z | 2018-12-06T17:24:25.000Z | tests/covered/l02.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | null | null | null | tests/covered/l02.agda | andrejtokarcik/agda-semantics | dc333ed142584cf52cc885644eed34b356967d8b | [
"MIT"
] | null | null | null | {-
Computer Aided Formal Reasoning (G53CFR, G54CFR)
Thorsten Altenkirch
Lecture 2: A first taste of Agda
In this lecture we start to explore the Agda system, a functional
programming language based on Type Theory. We start with some
ordinary examples which we could have developed in Haskell as well.
-}
module l02 where
-- module myNat where
{- Agda has no automatically loaded prelude. Hence we can start from
scratch and define the natural numbers. Later we will use the
standard libray. -}
data ℕ : Set where -- to type ℕ we type \bn
zero : ℕ
suc : (m : ℕ) → ℕ -- \-> or \to
{- To process an Agda file we use C-c C-c from emacs. Once Agda has
checked the file the type checker also colours the different
symbols. -}
{- We define addition. Note Agda's syntax for mixfix operations. The
arguments are represented by _s -}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
{- Try to evaluate: (suc (suc zero)) + (suc (suc zero))
by typing in C-c C-n -}
{- Better we import the library definition of ℕ
This way we can type 2 instead of (suc (suc zero))
-}
-- open import Data.Nat
{- We define Lists : -}
data List (A : Set) : Set where
[] : List A
_∷_ : (a : A) → (as : List A) → List A
{- In future we'll use
open import Data.List -}
{- declare the fixity of ∷ (type \::) -}
infixr 5 _∷_
{- Two example lists -}
{-
l1 : List ℕ
l1 = 1 ∷ 2 ∷ 3 ∷ []
l2 : List ℕ
l2 = 4 ∷ 5 ∷ []
-}
{- implementing append (++) -}
_++_ : {A : Set} → List A → List A → List A
[] ++ bs = bs
(a ∷ as) ++ bs = a ∷ (as ++ bs)
{- Note that Agda checks wether a function is terminating.
If we type
(a ∷ as) ++ bs = (a ∷ as) ++ bs
in the 2nd line Agda will complain by coloring the offending
function calls in red.
-}
{- What does the following variant of ++ do ? -}
_++'_ : {A : Set} → List A → List A → List A
as ++' [] = as
as ++' (b ∷ bs) = (b ∷ as) ++' bs
{- Indeed it can be used to define reverse. This way to implement
reverse is often called fast reverse because it is "tail recursive"
which leads to a more efficient execution than the naive
implementation. -}
rev : {A : Set} → List A → List A
rev as = [] ++' as
{- We tried to define a function which accesses the nth element of a list:
_!!_ : {A : Set} → List A → ℕ → A
[] !! n = {!!}
(a ∷ as) !! zero = a
(a ∷ as) !! suc n = as !! n
but there is no way to complete the first line (consider what happens
if A is the empty type!
-}
{- To fix this we handle errors explicitely, using Maybe -}
-- open import Data.Maybe
data Maybe (A : Set) : Set where
just : (x : A) → Maybe A
nothing : Maybe A
{- This version of the function can either return an element of the list
(just a) or an error (nothing).
-}
_!!_ : {A : Set} → List A → ℕ → Maybe A
[] !! n = nothing
(a ∷ as) !! zero = just a
(a ∷ as) !! suc n = as !! n
| 24.266667 | 74 | 0.608516 |
182c65f5d4799af74661321cd765ad8654172fbf | 389 | agda | Agda | Cats/Category/Fun/Facts.agda | JLimperg/cats | 1ad7b243acb622d46731e9ae7029408db6e561f1 | [
"MIT"
] | 24 | 2017-11-03T15:18:57.000Z | 2021-08-06T05:00:46.000Z | Cats/Category/Fun/Facts.agda | JLimperg/cats | 1ad7b243acb622d46731e9ae7029408db6e561f1 | [
"MIT"
] | null | null | null | Cats/Category/Fun/Facts.agda | JLimperg/cats | 1ad7b243acb622d46731e9ae7029408db6e561f1 | [
"MIT"
] | 1 | 2019-03-18T15:35:07.000Z | 2019-03-18T15:35:07.000Z | {-# OPTIONS --without-K --safe #-}
module Cats.Category.Fun.Facts where
open import Cats.Category.Fun.Facts.Iso public using
( ≈→≅ ; ≅→≈ )
open import Cats.Category.Fun.Facts.Limit public using
( complete )
open import Cats.Category.Fun.Facts.Product public using
( hasBinaryProducts ; hasFiniteProducts )
open import Cats.Category.Fun.Facts.Terminal public using
( hasTerminal )
| 32.416667 | 57 | 0.745501 |
0e9fc926a00b48028df26550ca2280dec6c99377 | 867 | agda | Agda | out/CommGroup/Signature.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 39 | 2021-11-09T20:39:55.000Z | 2022-03-19T17:33:12.000Z | out/CommGroup/Signature.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 1 | 2021-11-21T12:19:32.000Z | 2021-11-21T12:19:32.000Z | out/CommGroup/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 CommGroup | CG
type
* : 0-ary
term
unit : * | ε
add : * * -> * | _⊕_ l20
neg : * -> * | ⊖_ r40
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))
(⊖N⊕ᴸ) a |> add (neg (a), a) = unit
(⊖N⊕ᴿ) a |> add (a, neg (a)) = unit
(⊕C) a b |> add(a, b) = add(b, a)
-}
module CommGroup.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 CGₒ : Set where
unitₒ addₒ negₒ : CGₒ
-- Term signature
CG:Sig : Signature CGₒ
CG:Sig = sig λ
{ unitₒ → ⟼₀ *
; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
; negₒ → (⊢₀ *) ⟼₁ *
}
open Signature CG:Sig public
| 18.847826 | 91 | 0.565167 |
230fad8b185bb731c0f6f1e6b64bb9932aaf5594 | 4,536 | agda | Agda | src/fot/FOTC/Program/ABP/CorrectnessProofI.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 11 | 2015-09-03T20:53:42.000Z | 2021-09-12T16:09:54.000Z | src/fot/FOTC/Program/ABP/CorrectnessProofI.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 2 | 2016-10-12T17:28:16.000Z | 2017-01-01T14:34:26.000Z | src/fot/FOTC/Program/ABP/CorrectnessProofI.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 3 | 2016-09-19T14:18:30.000Z | 2018-03-14T08:50:00.000Z | ------------------------------------------------------------------------------
-- The alternating bit protocol (ABP) is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the ABP following the
-- formalization in Dybjer and Sander (1989).
module FOTC.Program.ABP.CorrectnessProofI where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool
open import FOTC.Data.Bool.PropertiesI
open import FOTC.Data.Stream.Type
open import FOTC.Data.Stream.Equality.PropertiesI
open import FOTC.Program.ABP.ABP
open import FOTC.Program.ABP.Lemma1I
open import FOTC.Program.ABP.Lemma2I
open import FOTC.Program.ABP.Fair.Type
open import FOTC.Program.ABP.Terms
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
-- Main theorem.
abpCorrect : ∀ {b os₁ os₂ is} → Bit b → Fair os₁ → Fair os₂ → Stream is →
is ≈ abpTransfer b os₁ os₂ is
abpCorrect {b} {os₁} {os₂} {is} Bb Fos₁ Fos₂ Sis = ≈-coind B h₁ h₂
where
h₁ : ∀ {ks ls} → B ks ls →
∃[ k' ] ∃[ ks' ] ∃[ ls' ] ks ≡ k' ∷ ks' ∧ ls ≡ k' ∷ ls' ∧ B ks' ls'
h₁ {ks} {ls} (b , os₁ , os₂ , as , bs , cs , ds , Sks , Bb , Fos₁ , Fos₂ , h)
with Stream-out Sks
... | (k' , ks' , ks≡k'∷ks' , Sks') =
k' , ks' , ls' , ks≡k'∷ks' , ls≡k'∷ls' , Bks'ls'
where
S-helper : ks ≡ k' ∷ ks' →
S b ks os₁ os₂ as bs cs ds ls →
S b (k' ∷ ks') os₁ os₂ as bs cs ds ls
S-helper h₁ h₂ = subst (λ t → S b t os₁ os₂ as bs cs ds ls) h₁ h₂
S'-lemma₁ : ∃[ os₁' ] ∃[ os₂' ] ∃[ as' ] ∃[ bs' ] ∃[ cs' ] ∃[ ds' ] ∃[ ls' ]
Fair os₁'
∧ Fair os₂'
∧ S' b k' ks' os₁' os₂' as' bs' cs' ds' ls'
∧ ls ≡ k' ∷ ls'
S'-lemma₁ = lemma₁ Bb Fos₁ Fos₂ (S-helper ks≡k'∷ks' h)
-- Following Martin Escardo advice (see Agda mailing list, heap
-- mistery) we use pattern matching instead of ∃ eliminators to
-- project the elements of the existentials.
-- 2011-08-25 update: It does not seems strictly necessary because
-- the Agda issue 415 was fixed.
ls' : D
ls' with S'-lemma₁
... | _ , _ , _ , _ , _ , _ , ls' , _ = ls'
ls≡k'∷ls' : ls ≡ k' ∷ ls'
ls≡k'∷ls' with S'-lemma₁
... | _ , _ , _ , _ , _ , _ , _ , _ , _ , _ , prf = prf
S-lemma₂ : ∃[ os₁'' ] ∃[ os₂'' ] ∃[ as'' ] ∃[ bs'' ] ∃[ cs'' ] ∃[ ds'' ]
Fair os₁''
∧ Fair os₂''
∧ S (not b) ks' os₁'' os₂'' as'' bs'' cs'' ds'' ls'
S-lemma₂ with S'-lemma₁
... | _ , _ , _ , _ , _ , _ , _ , Fos₁' , Fos₂' , s' , _ =
lemma₂ Bb Fos₁' Fos₂' s'
Bks'ls' : B ks' ls'
Bks'ls' with S-lemma₂
... | os₁'' , os₂'' , as'' , bs'' , cs'' , ds'' , Fos₁'' , Fos₂'' , s =
not b , os₁'' , os₂'' , as'' , bs'' , cs'' , ds''
, Sks' , not-Bool Bb , Fos₁'' , Fos₂'' , s
h₂ : B is (abpTransfer b os₁ os₂ is)
h₂ = b
, os₁
, os₂
, has aux₁ aux₂ aux₃ aux₄ aux₅ is
, hbs aux₁ aux₂ aux₃ aux₄ aux₅ is
, hcs aux₁ aux₂ aux₃ aux₄ aux₅ is
, hds aux₁ aux₂ aux₃ aux₄ aux₅ is
, Sis
, Bb
, Fos₁
, Fos₂
, has-eq aux₁ aux₂ aux₃ aux₄ aux₅ is
, hbs-eq aux₁ aux₂ aux₃ aux₄ aux₅ is
, hcs-eq aux₁ aux₂ aux₃ aux₄ aux₅ is
, hds-eq aux₁ aux₂ aux₃ aux₄ aux₅ is
, trans (abpTransfer-eq b os₁ os₂ is)
(transfer-eq aux₁ aux₂ aux₃ aux₄ aux₅ is)
where
aux₁ aux₂ aux₃ aux₄ aux₅ : D
aux₁ = send b
aux₂ = ack b
aux₃ = out b
aux₄ = corrupt os₁
aux₅ = corrupt os₂
------------------------------------------------------------------------------
-- abpTransfer produces a Stream.
abpTransfer-Stream : ∀ {b os₁ os₂ is} →
Bit b →
Fair os₁ →
Fair os₂ →
Stream is →
Stream (abpTransfer b os₁ os₂ is)
abpTransfer-Stream Bb Fos₁ Fos₂ Sis = ≈→Stream₂ (abpCorrect Bb Fos₁ Fos₂ Sis)
------------------------------------------------------------------------------
-- References
--
-- Dybjer, Peter and Sander, Herbert P. (1989). A Functional
-- Programming Approach to the Specification and Verification of
-- Concurrent Systems. Formal Aspects of Computing 1, pp. 303–319.
| 36.580645 | 80 | 0.491402 |
102bb4a31a9912be7855a6fdf7b97af781fbaae6 | 479 | agda | Agda | test/Succeed/Issue679u.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue679u.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue679u.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, Ulf, 2016-06-01, discussing issue #679
-- {-# OPTIONS -v tc.with.strip:20 #-}
postulate anything : {A : Set} → A
data Ty : Set where
_=>_ : (a b : Ty) → Ty
⟦_⟧ : Ty → Set
⟦ a => b ⟧ = ⟦ a ⟧ → ⟦ b ⟧
eq : (a : Ty) → ⟦ a ⟧ → ⟦ a ⟧ → Set
eq (a => b) f g = ∀ {x y : ⟦ a ⟧} → eq a x y → eq b (f x) (g y)
bad : (a : Ty) (x : ⟦ a ⟧) → eq a x x
bad (a => b) f h with b
bad (a => b) f h | _ = anything
-- ERROR WAS: Too few arguments in with clause!
-- Should work now.
| 23.95 | 63 | 0.482255 |
c57f5df53e1046f5683fe9744361ac39c74c318b | 586 | agda | Agda | test/Succeed/Issue366.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue366.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue366.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- 2010-11-21
-- testing correct implementation of eta for records with higher-order fields
module Issue366 where
data Bool : Set where
true false : Bool
record R (A : Set) : Set where
constructor r
field
unR : A
open R
foo : Bool
foo = unR (r (unR (r (λ (_ : Bool) → false))
true))
-- before 2010-11-21, an incorrect implementation of eta-contraction
-- reduced foo to (unR true)
-- Error message was (due to clause compilation):
-- Incomplete pattern matching
data _==_ {A : Set}(a : A) : A -> Set where
refl : a == a
test : foo == false
test = refl
| 19.533333 | 77 | 0.650171 |
4ad7613cf7acd003ff4067c2044b0183711d73d0 | 743 | agda | Agda | test/Succeed/Issue2196.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue2196.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue2196.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, 2016-09-20, issue #2196 reported by mechvel
-- Test case by Ulf
-- {-# OPTIONS -v tc.lhs.dot:40 #-}
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
record _×_ (A B : Set) : Set where
constructor _,_
field fst : A
snd : B
open _×_
EqP₁ : ∀ {A B} (p q : A × B) → Set
EqP₁ (x , y) (z , w) = (x ≡ z) × (y ≡ w)
EqP₂ : ∀ {A B} (p q : A × B) → Set
EqP₂ p q = (fst p ≡ fst q) × (snd p ≡ snd q)
works : {A : Set} (p q : A × A) → EqP₁ p q → Set₁
works (x , y) .(x , y) (refl , refl) = Set
test : {A : Set} (p q : A × A) → EqP₂ p q → Set₁
test (x , y) .(x , y) (refl , refl) = Set
-- ERROR WAS:
-- Failed to infer the value of dotted pattern
-- when checking that the pattern .(x , y) has type .A × .A
| 24.766667 | 59 | 0.51144 |
101be0715035e0a991825b68b30bca259522c65a | 632 | agda | Agda | agda-stdlib/src/Data/Vec/Relation/Equality/DecSetoid.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | agda-stdlib/src/Data/Vec/Relation/Equality/DecSetoid.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | agda-stdlib/src/Data/Vec/Relation/Equality/DecSetoid.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | ------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Vec.Relation.Binary.Equality.DecSetoid directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.Vec.Relation.Equality.DecSetoid
{a ℓ} (DS : DecSetoid a ℓ) where
open import Data.Vec.Relation.Binary.Equality.DecSetoid public
{-# WARNING_ON_IMPORT
"Data.Vec.Relation.Equality.DecSetoid was deprecated in v1.0.
Use Data.Vec.Relation.Binary.Equality.DecSetoid instead."
#-}
| 30.095238 | 72 | 0.583861 |
dc7c69bcae3831dc1293e632d8251f82d478492b | 464 | agda | Agda | test/interaction/Issue2407.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 2 | 2019-10-29T09:40:30.000Z | 2020-09-20T00:28:57.000Z | test/interaction/Issue2407.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/interaction/Issue2407.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z |
-- Jesper, 2017-01-24: if we allow a variable to be instantiated with a value
-- of a supertype, the resulting dot pattern won't be type-correct.
open import Common.Size
data D (i : Size) : (j : Size< ↑ i) → Set where
c : ∀ (j : Size< ↑ i) (k : Size< ↑ j)
→ D i j
→ D j k
→ D i k
split : ∀ i (j : Size< ↑ i) → D i j → Set
split i j x = {!x!} -- split on x
-- Expected: splitting on x succeeds with
-- split i .k (c j k x x₁) = {!!}
| 24.421053 | 77 | 0.549569 |
0e9a7e2cfc1e12c084cce2f6bfabd05ca6874a31 | 1,810 | agda | Agda | Streams/Relations.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | Streams/Relations.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | Streams/Relations.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | module Relations where
open import Level as Level using (zero)
open import Size
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
RelTrans : Set → Set₁
RelTrans B = Rel B Level.zero → Rel B Level.zero
Monotone : ∀{B} → RelTrans B → Set₁
Monotone F = ∀ {R S} → R ⇒ S → F R ⇒ F S
-- | Useful example of a compatible up-to technique: equivalence closure.
data EquivCls {B : Set} (R : Rel B Level.zero) : Rel B Level.zero where
cls-incl : {a b : B} → R a b → EquivCls R a b
cls-refl : {b : B} → EquivCls R b b
cls-sym : {a b : B} → EquivCls R a b → EquivCls R b a
cls-trans : {a b c : B} → EquivCls R a b → EquivCls R b c → EquivCls R a c
-- | The operation of taking the equivalence closure is monotone.
equivCls-monotone : ∀{B} → Monotone {B} EquivCls
equivCls-monotone R≤S (cls-incl xRy) = cls-incl (R≤S xRy)
equivCls-monotone R≤S cls-refl = cls-refl
equivCls-monotone R≤S (cls-sym p) = cls-sym (equivCls-monotone R≤S p)
equivCls-monotone R≤S (cls-trans p q) =
cls-trans (equivCls-monotone R≤S p) (equivCls-monotone R≤S q)
-- | The equivalence closure is indeed a closure operator.
equivCls-expanding : ∀{B R} → R ⇒ EquivCls {B} R
equivCls-expanding p = cls-incl p
equivCls-idempotent : ∀{B R} → EquivCls (EquivCls R) ⇒ EquivCls {B} R
equivCls-idempotent (cls-incl p) = p
equivCls-idempotent cls-refl = cls-refl
equivCls-idempotent (cls-sym p) = cls-sym (equivCls-idempotent p)
equivCls-idempotent (cls-trans p q) =
cls-trans (equivCls-idempotent p) (equivCls-idempotent q)
-- | Equivalence closure gives indeed equivalence relation
equivCls-equiv : ∀{A} → (R : Rel A _) → IsEquivalence (EquivCls R)
equivCls-equiv R = record
{ refl = cls-refl
; sym = cls-sym
; trans = cls-trans
}
| 36.938776 | 76 | 0.683425 |
2378e3234f8a18c77063c5783478f910e6011553 | 90 | agda | Agda | test/interaction/SetInf.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2019-11-27T07:26:06.000Z | 2019-11-27T07:26:06.000Z | test/interaction/SetInf.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/interaction/SetInf.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | {-# OPTIONS --universe-polymorphism #-}
module SetInf where
id : ∀ {A} → A → A
id x = x
| 12.857143 | 39 | 0.588889 |
d0d6d5f8be903c1ab1c0a3477872d93064c0a7f3 | 7,371 | agda | Agda | src/Data/Context/Properties.agda | sstucki/f-omega-int-agda | ae648c9520895a8428a7ad80f47bb55ecf4d50ea | [
"MIT"
] | 12 | 2017-06-13T16:05:35.000Z | 2021-09-27T05:53:06.000Z | src/Data/Context/Properties.agda | sstucki/f-omega-int-agda | ae648c9520895a8428a7ad80f47bb55ecf4d50ea | [
"MIT"
] | 1 | 2021-05-14T08:09:40.000Z | 2021-05-14T08:54:39.000Z | src/Data/Context/Properties.agda | sstucki/f-omega-int-agda | ae648c9520895a8428a7ad80f47bb55ecf4d50ea | [
"MIT"
] | 2 | 2021-05-13T22:29:48.000Z | 2021-05-14T10:25:05.000Z | ------------------------------------------------------------------------
-- Propierties of abstract typing contexts
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Data.Context.Properties where
open import Data.Fin using (Fin; zero; suc; lift; raise)
open import Data.Fin.Substitution.Extra using (Extension)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Product using (_×_; _,_)
open import Data.Vec as Vec using (Vec; []; _∷_)
import Data.Vec.Properties as VecProps
open import Function as Fun using (_∘_; flip)
open import Relation.Binary.PropositionalEquality hiding (subst-∘)
open ≡-Reasoning
open import Relation.Unary using (Pred)
open import Data.Context
open import Data.Context.WellFormed
------------------------------------------------------------------------
-- Properties of abstract contexts and context extensions.
-- Properties of the `map' functions.
module _ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} where
-- pointwise equality is a congruence w.r.t. map and mapExt.
map-cong : ∀ {n} {f g : ∀ {k} → T₁ k → T₂ k} → (∀ {k} → f {k} ≗ g {k}) →
_≗_ {A = Ctx T₁ n} (map f) (map g)
map-cong f≗g [] = refl
map-cong f≗g (_∷_ t Γ) = cong₂ _∷_ (f≗g t) (map-cong f≗g Γ)
mapExt-cong : ∀ {k m n} {f g : ∀ i → T₁ (i + m) → T₂ (i + n)} →
(∀ {i} → f i ≗ g i) →
_≗_ {A = CtxExt T₁ m k} (mapExt {T₂ = T₂} f) (mapExt g)
mapExt-cong f≗g [] = refl
mapExt-cong f≗g (_∷_ {l} t Γ) = cong₂ _∷_ (f≗g {l} t) (mapExt-cong f≗g Γ)
module _ {ℓ} {T : Pred ℕ ℓ} where
-- map and mapExt are functorial.
map-id : ∀ {n} → _≗_ {A = Ctx T n} (map Fun.id) Fun.id
map-id [] = refl
map-id (t ∷ Γ) = cong (t ∷_) (map-id Γ)
mapExt-id : ∀ {m n} → _≗_ {A = CtxExt T m n} (mapExt λ _ t → t) Fun.id
mapExt-id [] = refl
mapExt-id (t ∷ Γ) = cong (t ∷_) (mapExt-id Γ)
module _ {ℓ₁ ℓ₂ ℓ₃} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {T₃ : Pred ℕ ℓ₃} where
map-∘ : ∀ {n} (f : ∀ {k} → T₂ k → T₃ k) (g : ∀ {k} → T₁ k → T₂ k)
(Γ : Ctx T₁ n) → map {T₂ = T₃} (f ∘ g) Γ ≡ map {T₁ = T₂} f (map g Γ)
map-∘ f g [] = refl
map-∘ f g (t ∷ Γ) = cong (_ ∷_) (map-∘ f g Γ)
mapExt-∘ : ∀ {k l m n}
(f : ∀ i → T₂ (i + m) → T₃ (i + n))
(g : ∀ i → T₁ (i + l) → T₂ (i + m)) →
(Γ : CtxExt T₁ l k) →
mapExt {T₂ = T₃} (λ i t → f i (g i t)) Γ ≡
mapExt {T₁ = T₂} f (mapExt g Γ)
mapExt-∘ f g [] = refl
mapExt-∘ f g (t ∷ Γ) = cong (_ ∷_) (mapExt-∘ f g Γ)
-- Lemmas about operations on contexts that require weakening of
-- types.
module WeakenOpsLemmas {ℓ} {T : Pred ℕ ℓ} (extension : Extension T) where
-- The underlyig operations.
open WeakenOps extension
-- Conversion to vector representation commutes with
-- concatenation.
toVec-++ : ∀ {m n} (Δ : CtxExt T m n) (Γ : Ctx T m) →
toVec (Δ ++ Γ) ≡ extToVec Δ (toVec Γ)
toVec-++ [] Γ = refl
toVec-++ (t ∷ Δ) Γ =
cong ((_ ∷_) ∘ Vec.map weaken) (toVec-++ Δ Γ)
-- Lookup commutes with concatenation.
lookup-++ : ∀ {m n} (Δ : CtxExt T m n) (Γ : Ctx T m) x →
lookup (Δ ++ Γ) x ≡ extLookup Δ (toVec Γ) x
lookup-++ Δ Γ x = cong (flip Vec.lookup x) (toVec-++ Δ Γ)
-- We can skip the first element when looking up others.
lookup-suc : ∀ {n} t (Γ : Ctx T n) x →
lookup (t ∷ Γ) (suc x) ≡ weaken (lookup Γ x)
lookup-suc t Γ x = VecProps.lookup-map x weaken (toVec Γ)
extLookup-suc : ∀ {k m n} t (Γ : CtxExt T m n) (ts : Vec (T m) k) x →
extLookup (t ∷ Γ) ts (suc x) ≡ weaken (extLookup Γ ts x)
extLookup-suc t Γ ts x = VecProps.lookup-map x weaken (extToVec Γ ts)
-- We can skip a spliced-in element when looking up others.
lookup-lift : ∀ {k m n} (Γ : CtxExt T m n) t (ts : Vec (T m) k) x →
extLookup Γ ts x ≡ extLookup Γ (t ∷ ts) (lift n suc x)
lookup-lift [] t ts x = refl
lookup-lift (u ∷ Δ) t ts zero = refl
lookup-lift {n = suc n} (u ∷ Δ) t ts (suc x) = begin
extLookup (u ∷ Δ) ts (suc x)
≡⟨ extLookup-suc u Δ ts x ⟩
weaken (extLookup Δ ts x)
≡⟨ cong weaken (lookup-lift Δ t ts x) ⟩
weaken (extLookup Δ (t ∷ ts) (lift n suc x))
≡⟨ sym (extLookup-suc u Δ (t ∷ ts) (lift n suc x)) ⟩
extLookup (u ∷ Δ) (t ∷ ts) (suc (lift n suc x))
∎
-- Lookup in the prefix of a concatenation results in weakening.
lookup-weaken⋆ : ∀ {m} n (Δ : CtxExt T m n) (Γ : Ctx T m) x →
lookup (Δ ++ Γ) (raise n x) ≡ weaken⋆ n (lookup Γ x)
lookup-weaken⋆ zero [] Γ x = refl
lookup-weaken⋆ (suc n) (t ∷ Δ) Γ x = begin
lookup (t ∷ Δ ++ Γ) (suc (raise n x))
≡⟨ VecProps.lookup-map (raise n x) weaken (toVec (Δ ++ Γ)) ⟩
weaken (lookup (Δ ++ Γ) (raise n x))
≡⟨ cong weaken (lookup-weaken⋆ n Δ Γ x) ⟩
weaken (weaken⋆ n (lookup Γ x))
∎
-- Lemmas relating conversions of context extensions to vector
-- representation with conversions of the underling entries.
module ConversionLemmas {T₁ T₂ : ℕ → Set}
(extension₁ : Extension T₁)
(extension₂ : Extension T₂) where
private
module W₁ = WeakenOps extension₁
module W₂ = WeakenOps extension₂
toVec-map : ∀ {n} (f : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) →
(∀ {k} (t : T₁ k) → W₂.weaken (f t) ≡ f (W₁.weaken t)) →
W₂.toVec (map f Γ) ≡ Vec.map f (W₁.toVec Γ)
toVec-map f [] _ = refl
toVec-map f (_∷_ t Γ) hyp = cong₂ _∷_ (hyp t) (begin
Vec.map W₂.weaken (W₂.toVec (map f Γ))
≡⟨ cong (Vec.map W₂.weaken) (toVec-map f Γ hyp) ⟩
(Vec.map W₂.weaken (Vec.map f (W₁.toVec Γ)))
≡⟨ sym (VecProps.map-∘ W₂.weaken f (W₁.toVec Γ)) ⟩
(Vec.map (W₂.weaken ∘ f) (W₁.toVec Γ))
≡⟨ VecProps.map-cong hyp (W₁.toVec Γ) ⟩
(Vec.map (f ∘ W₁.weaken) (W₁.toVec Γ))
≡⟨ VecProps.map-∘ f W₁.weaken (W₁.toVec Γ) ⟩
(Vec.map f (Vec.map W₁.weaken (W₁.toVec Γ)))
∎)
-- Lookup commutes with re-indexing, provided that the reindexing
-- function commutes with weakening.
lookup-map : ∀ {n} (f : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) x →
(∀ {k} (t : T₁ k) → W₂.weaken (f t) ≡ f (W₁.weaken t)) →
W₂.lookup (map f Γ) x ≡ f (W₁.lookup Γ x)
lookup-map f Γ x hyp = begin
W₂.lookup (map f Γ) x
≡⟨ cong (flip Vec.lookup x) (toVec-map f Γ hyp) ⟩
Vec.lookup (Vec.map f (W₁.toVec Γ)) x
≡⟨ VecProps.lookup-map x f (W₁.toVec Γ) ⟩
f (W₁.lookup Γ x)
∎
-- Lemmas about well-formed contexts and context extensions.
module ContextFormationLemmas {t ℓ} {T : Pred ℕ t}
(_⊢_wf : Wf T T ℓ) where
open ContextFormation _⊢_wf
-- Concatenation preserves well-formedness of contexts.
wf-++-wfExt : ∀ {m n} {Δ : CtxExt T m n} {Γ : Ctx T m} →
Γ ⊢ Δ wfExt → Γ wf → Δ ++ Γ wf
wf-++-wfExt [] Γ-wf = Γ-wf
wf-++-wfExt (t-wf ∷ Δ-wfExt) Γ-wf = t-wf ∷ wf-++-wfExt Δ-wfExt Γ-wf
-- Splitting of well-formed contexts.
wf-split : ∀ {m n} {Δ : CtxExt T m n} {Γ : Ctx T m} →
Δ ++ Γ wf → Γ ⊢ Δ wfExt × Γ wf
wf-split {Δ = []} Γ-wf = [] , Γ-wf
wf-split {Δ = t ∷ Δ} (t-wf ∷ Δ++Γ-wf) =
let Δ-wfExt , Γ-wf = wf-split Δ++Γ-wf
in t-wf ∷ Δ-wfExt , Γ-wf
| 37.994845 | 78 | 0.521368 |
df08a5a68aa923693641cb02d52c6e56bf6f38f1 | 617 | agda | Agda | test/Fail/ShapeIrrelevantIndexNoBecauseOfRecursion.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/ShapeIrrelevantIndexNoBecauseOfRecursion.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/ShapeIrrelevantIndexNoBecauseOfRecursion.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --experimental-irrelevance #-}
module ShapeIrrelevantIndexNoBecauseOfRecursion where
data ⊥ : Set where
record ⊤ : Set where
constructor trivial
data Bool : Set where
true false : Bool
True : Bool → Set
True false = ⊥
True true = ⊤
data D : ..(b : Bool) → Set where
c : {b : Bool} → True b → D b
-- because of the irrelevant index,
-- D is in essence an existental type D : Set
-- with constructor c : {b : Bool} → True b → D
fromD : {b : Bool} → D b → True b
fromD (c p) = p -- should fail
cast : .(a b : Bool) → D a → D b
cast _ _ x = x
bot : ⊥
bot = fromD (cast true false (c trivial))
| 20.566667 | 53 | 0.628849 |
dcce79f5b28d082ca607724f9b8a42bcf1c83003 | 4,105 | agda | Agda | LibraBFT/Concrete/Records.agda | cwjnkins/bft-consensus-agda | 71aa2168e4875ffdeece9ba7472ee3cee5fa9084 | [
"UPL-1.0"
] | null | null | null | LibraBFT/Concrete/Records.agda | cwjnkins/bft-consensus-agda | 71aa2168e4875ffdeece9ba7472ee3cee5fa9084 | [
"UPL-1.0"
] | null | null | null | LibraBFT/Concrete/Records.agda | cwjnkins/bft-consensus-agda | 71aa2168e4875ffdeece9ba7472ee3cee5fa9084 | [
"UPL-1.0"
] | null | null | null | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
{-# OPTIONS --allow-unsolved-metas #-}
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types.EpochIndep
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open WithAbsVote
-- Here we have the abstraction functions that connect
-- the datatypes defined in LibraBFT.Impl.Consensus.Types
-- to the abstract records from LibraBFT.Abstract.Records
-- for a given EpochConfig.
--
module LibraBFT.Concrete.Records (𝓔 : EpochConfig) where
open import LibraBFT.Impl.Consensus.Types.EpochDep 𝓔
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 ConcreteVoteEvidence as Abs hiding (bId; qcVotes; Block)
open EpochConfig 𝓔
--------------------------------
-- Abstracting Blocks and QCs --
--------------------------------
α-Block : Block → Abs.Block
α-Block b with ₋bdBlockType (₋bBlockData b)
...| NilBlock = record
{ bId = ₋bId b
; bPrevQC = just (b ^∙ (bBlockData ∙ bdQuorumCert ∙ qcVoteData ∙ vdParent ∙ biId))
; bRound = b ^∙ bBlockData ∙ bdRound
}
...| Genesis = record
{ bId = b ^∙ bId
; bPrevQC = nothing
; bRound = b ^∙ bBlockData ∙ bdRound
}
...| Proposal cmd α = record
{ bId = b ^∙ bId
; bPrevQC = just (b ^∙ bBlockData ∙ bdQuorumCert ∙ qcVoteData ∙ vdParent ∙ biId)
; bRound = b ^∙ bBlockData ∙ bdRound
}
α-VoteData-Block : VoteData → Abs.Block
α-VoteData-Block vd = record
{ bId = vd ^∙ vdProposed ∙ biId
; bPrevQC = just (vd ^∙ vdParent ∙ biId)
; bRound = vd ^∙ vdProposed ∙ biRound
}
α-Vote : (qc : QuorumCert)(valid : MetaIsValidQC qc) → ∀ {as} → as ∈ qcVotes qc → Abs.Vote
α-Vote qc v {as} as∈QC = α-ValidVote (rebuildVote qc as)
(₋ivvMember (All-lookup (₋ivqcMetaVotesValid v) as∈QC))
-- Abstraction of votes produce votes that carry evidence
-- they have been cast.
α-Vote-evidence : (qc : QuorumCert)(valid : MetaIsValidQC qc)
→ ∀{vs} (prf : vs ∈ qcVotes qc)
→ ConcreteVoteEvidence (α-Vote qc valid prf)
α-Vote-evidence qc valid {as} v∈qc
= record { ₋cveVote = rebuildVote qc as
; ₋cveIsValidVote = All-lookup (₋ivqcMetaVotesValid valid) v∈qc
; ₋cveIsAbs = refl
}
α-QC : Σ QuorumCert MetaIsValidQC → Abs.QC
α-QC (qc , valid) = record
{ qCertBlockId = qc ^∙ qcVoteData ∙ vdProposed ∙ biId
; qRound = qc ^∙ qcVoteData ∙ vdProposed ∙ biRound
; qVotes = All-reduce (α-Vote qc valid) All-self
; qVotes-C1 = {! MetaIsValidQC.₋ivqcMetaIsQuorum valid!}
; qVotes-C2 = All-reduce⁺ (α-Vote qc valid) (λ _ → refl) All-self
; qVotes-C3 = All-reduce⁺ (α-Vote qc valid) (λ _ → refl) All-self
; qVotes-C4 = All-reduce⁺ (α-Vote qc valid) (α-Vote-evidence qc valid) All-self
}
-- What does it mean for an (abstract) Block or QC to be represented in a NetworkMsg?
data _α-∈NM_ : Abs.Record → NetworkMsg → Set where
qc∈NM : ∀ {cqc q nm}
→ (valid : MetaIsValidQC cqc)
→ cqc QC∈NM nm
→ q ≡ α-QC (cqc , valid)
→ Abs.Q q α-∈NM nm
b∈NM : ∀ {cb pm nm}
→ nm ≡ P pm
→ pm ^∙ pmProposal ≡ cb
→ Abs.B (α-Block cb) α-∈NM nm
-- Our system model contains a message pool, which is a list of NodeId-NetworkMsg pairs. The
-- following relation expresses that an abstract record r is represented in a given message pool
-- sm.
data _α-Sent_ (r : Abs.Record) (sm : List (NodeId × NetworkMsg)) : Set where
ws : ∀ {p nm} → getEpoch nm ≡ epoch → (p , nm) ∈ sm → r α-∈NM nm → r α-Sent sm
| 40.643564 | 116 | 0.629963 |
c55a0708aada5a31f152bfde5fee09f5218517e3 | 5,959 | agda | Agda | src/plfa/part1/Equality.agda | abolotina/plfa.github.io | 75bef9bb35643160e2d2ab4221a3057f22eb3324 | [
"CC-BY-4.0"
] | null | null | null | src/plfa/part1/Equality.agda | abolotina/plfa.github.io | 75bef9bb35643160e2d2ab4221a3057f22eb3324 | [
"CC-BY-4.0"
] | null | null | null | src/plfa/part1/Equality.agda | abolotina/plfa.github.io | 75bef9bb35643160e2d2ab4221a3057f22eb3324 | [
"CC-BY-4.0"
] | null | null | null |
module Equality where
-- Equality
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
infix 4 _≡_
-- Equality is an equivalence relation
sym : ∀ {A : Set} {x y : A}
→ x ≡ y
-----
→ y ≡ x
sym {A} {x} {.x} refl = refl
trans : ∀ {A : Set} {x y z : A}
→ x ≡ y
→ y ≡ z
-----
→ x ≡ z
trans {A} {x} {.x} {.x} refl refl = refl
-- Congruence and substitution
cong : ∀ {A B : Set} (f : A → B) {x y : A}
→ x ≡ y
---------
→ f x ≡ f y
cong f refl = refl
cong₂ : ∀ {A B C : Set} (f : A → B → C) {u x : A} {v y : B}
→ u ≡ x
→ v ≡ y
-------------
→ f u v ≡ f x y
cong₂ f refl refl = refl
cong-app : ∀ {A B : Set} {f g : A → B}
→ f ≡ g
---------------------
→ ∀ (x : A) → f x ≡ g x
cong-app refl x = refl
subst : ∀ {A : Set} {x y : A} (P : A → Set)
→ x ≡ y
---------
→ P x → P y
subst P refl px = px
open import AuxDefs
data even : ℕ → Set
data odd : ℕ → Set
data even where
even-zero : even zero
even-suc : ∀ {n : ℕ}
→ odd n
------------
→ even (suc n)
data odd where
odd-suc : ∀ {n : ℕ}
→ even n
-----------
→ odd (suc n)
postulate
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
even-comm : ∀ (m n : ℕ)
→ even (m + n)
------------
→ even (n + m)
even-comm m n = subst even (+-comm m n)
-- Chains of equations
module ≡-Reasoning {A : Set} where
infix 1 begin_
infixr 2 _≡⟨⟩_ _≡⟨_⟩_
infix 3 _∎
begin_ : ∀ {x y : A}
→ x ≡ y
-----
→ x ≡ y
begin x≡y = x≡y
_≡⟨⟩_ : ∀ (x : A) {y : A}
→ x ≡ y
-----
→ x ≡ y
x ≡⟨⟩ x≡y = x≡y
_≡⟨_⟩_ : ∀ (x : A) {y z : A}
→ x ≡ y
→ y ≡ z
-----
→ x ≡ z
x ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
_∎ : ∀ (x : A)
-----
→ x ≡ x
x ∎ = refl
open ≡-Reasoning
trans′ : ∀ {A : Set} {x y z : A}
→ x ≡ y
→ y ≡ z
-----
→ x ≡ z
trans′ {A} {x} {y} {z} x≡y y≡z = -- begin (x ≡⟨ x≡y ⟩ (y ≡⟨ y≡z ⟩ (z ∎)))
begin -- ==>
x -- trans x≡y (trans y≡z refl)
≡⟨ x≡y ⟩
y
≡⟨ y≡z ⟩
z
∎
-- Chains of equations, another example
postulate
+-identity : ∀ (m : ℕ) → m + zero ≡ m
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-comm′ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm′ m zero =
begin
m + zero
≡⟨ +-identity m ⟩
m
≡⟨⟩
zero + m
∎
+-comm′ m (suc n) =
begin
m + suc n
≡⟨ +-suc m n ⟩
suc (m + n)
≡⟨ cong suc (+-comm′ m n) ⟩
suc (n + m)
≡⟨⟩
suc n + m
∎
{-
Exercise ≤-Reasoning
The proof of monotonicity from Chapter Relations can be written in a more readable
form by using an analogue of our notation for ≡-Reasoning. Define ≤-Reasoning
analogously, and use it to write out an alternative proof that addition is monotonic
with regard to inequality. Rewrite all of +-monoˡ-≤, +-monoʳ-≤, and +-mono-≤.
-}
-- Rewriting
{-
data even : ℕ → Set
data odd : ℕ → Set
data even where
even-zero : even zero
even-suc : ∀ {n : ℕ}
→ odd n
------------
→ even (suc n)
data odd where
odd-suc : ∀ {n : ℕ}
→ even n
-----------
→ odd (suc n)
-}
{-# BUILTIN EQUALITY _≡_ #-}
even-comm′ : ∀ (m n : ℕ)
→ even (m + n)
------------
→ even (n + m)
even-comm′ m n ev = {!!}
-- Multiple rewrites
+-comm″ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm″ zero n = {!!}
+-comm″ (suc m) n = {!!}
-- With-abstraction (examples from the Agda docs)
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) → (xs : List A) → List A
infixr 5 _∷_
filter : {A : Set} → (A → Bool) → List A → List A
filter p [] = []
filter p (x ∷ xs) with p x
... | true = x ∷ filter p xs
... | false = filter p xs
compare : ℕ → ℕ → Comparison
compare x y with x < y
... | false with y < x
... | false = equal
... | true = greater
compare x y | true = less
compare′ : ℕ → ℕ → Comparison
compare′ x y with x < y | y < x
... | true | _ = less
... | _ | true = greater
... | false | false = equal
-- Rewriting expanded
even-comm″ : ∀ (m n : ℕ)
→ even (m + n)
------------
→ even (n + m)
even-comm″ m n ev with m + n | +-comm m n
... | mn | eq = {!!}
-- Leibniz equality
_≐_ : ∀ {A : Set} (x y : A) → Set₁ -- Set : Set₁, Set₁ : Set₂, and so on
_≐_ {A} x y = ∀ (P : A → Set) → P x → P y
refl-≐ : ∀ {A : Set} {x : A}
→ x ≐ x
refl-≐ P Px = {!!}
trans-≐ : ∀ {A : Set} {x y z : A}
→ x ≐ y
→ y ≐ z
-----
→ x ≐ z
trans-≐ x≐y y≐z P Px = {!!}
sym-≐ : ∀ {A : Set} {x y : A}
→ x ≐ y
-----
→ y ≐ x
sym-≐ {A} {x} {y} x≐y P = Qy
where
Q : A → Set
Q z = P z → P x
Qx : Q x
Qx = refl-≐ P
Qy : Q y
Qy = x≐y Q Qx
-- subst : ∀ {A : Set} {x y : A} (P : A → Set)
-- → x ≡ y
-- ---------
-- → P x → P y
≡-implies-≐ : ∀ {A : Set} {x y : A}
→ x ≡ y
-----
→ x ≐ y
≡-implies-≐ x≡y P = subst P x≡y
≐-implies-≡ : ∀ {A : Set} {x y : A}
→ x ≐ y
-----
→ x ≡ y
≐-implies-≡ {A} {x} {y} x≐y = Qy
where
Q : A → Set
Q z = x ≡ z
Qx : Q x
Qx = refl
Qy : Q y
Qy = x≐y Q Qx
-- Universe polymorphism
open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)
-- lzero : Level
-- lsuc : Level → Level
-- Set₀ ==> Set lzero
-- Set₁ ==> Set (lsuc lzero)
-- Set₂ ==> Set (lsuc (lsuc lzero))
-- Given two levels, returns the larger of the two
-- _⊔_ : Level → Level → Level
data _≡′_ {ℓ : Level} {A : Set ℓ} (x : A) : A → Set ℓ where
refl′ : x ≡′ x
sym′ : ∀ {ℓ : Level} {A : Set ℓ} {x y : A}
→ x ≡′ y
------
→ y ≡′ x
sym′ refl′ = refl′
_≐′_ : ∀ {ℓ : Level} {A : Set ℓ} (x y : A) → Set (lsuc ℓ)
_≐′_ {ℓ} {A} x y = ∀ (P : A → Set ℓ) → P x → P y
_∘_ : ∀ {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃}
→ (B → C) → (A → B) → A → C
(g ∘ f) x = g (f x)
| 16.691877 | 84 | 0.412821 |
0e2b477eeeea3c2689cbeaa9783f05a40bac8151 | 6,480 | agda | Agda | src/Model/Quantification.agda | JLimperg/msc-thesis-code | 104cddc6b65386c7e121c13db417aebfd4b7a863 | [
"MIT"
] | 5 | 2021-04-13T21:31:17.000Z | 2021-06-26T06:37:31.000Z | src/Model/Quantification.agda | JLimperg/msc-thesis-code | 104cddc6b65386c7e121c13db417aebfd4b7a863 | [
"MIT"
] | null | null | null | src/Model/Quantification.agda | JLimperg/msc-thesis-code | 104cddc6b65386c7e121c13db417aebfd4b7a863 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
module Model.Quantification where
open import Model.RGraph as RG using (RGraph)
open import Model.Size as MS using (_<_ ; ⟦_⟧Δ ; ⟦_⟧n ; ⟦_⟧σ)
open import Model.Type.Core
open import Source.Size.Substitution.Theory
open import Source.Size.Substitution.Universe as SS using (Sub⊢ᵤ)
open import Util.HoTT.Equiv
open import Util.HoTT.FunctionalExtensionality
open import Util.HoTT.HLevel
open import Util.Prelude hiding (_∘_)
open import Util.Relation.Binary.PropositionalEquality using
( Σ-≡⁺ ; subst-sym-subst ; subst-subst-sym )
import Source.Size as SS
import Source.Type as ST
open RGraph
open RG._⇒_
open SS.Ctx
open SS.Sub⊢ᵤ
record ⟦∀⟧′ {Δ} n (T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ) (δ : Obj ⟦ Δ ⟧Δ) : Set where
no-eta-equality
field
arr : ∀ m (m<n : m < ⟦ n ⟧n .fobj δ) → Obj T (δ , m , m<n)
param : ∀ m m<n m′ m′<n → eq T _ (arr m m<n) (arr m′ m′<n)
open ⟦∀⟧′ public
⟦∀⟧′Canon : ∀ {Δ} n (T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ) (δ : Obj ⟦ Δ ⟧Δ) → Set
⟦∀⟧′Canon n T δ
= Σ[ f ∈ (∀ m (m<n : m < ⟦ n ⟧n .fobj δ) → Obj T (δ , m , m<n)) ]
(∀ m m<n m′ m′<n → eq T _ (f m m<n) (f m′ m′<n))
⟦∀⟧′≅⟦∀⟧′Canon : ∀ {Δ n T δ} → ⟦∀⟧′ {Δ} n T δ ≅ ⟦∀⟧′Canon n T δ
⟦∀⟧′≅⟦∀⟧′Canon = record
{ forth = λ { record { arr = x ; param = y } → x , y }
; isIso = record
{ back = λ x → record { arr = proj₁ x ; param = proj₂ x }
; back∘forth = λ { record {} → refl }
; forth∘back = λ _ → refl
}
}
abstract
⟦∀⟧′Canon-IsSet : ∀ {Δ n T δ} → IsSet (⟦∀⟧′Canon {Δ} n T δ)
⟦∀⟧′Canon-IsSet {T = T} = Σ-IsSet
(∀-IsSet λ m → ∀-IsSet λ m<n → λ _ _ → T .Obj-IsSet _ _)
(λ f → IsOfHLevel-suc 1 (∀-IsProp λ m → ∀-IsProp λ m<n → ∀-IsProp λ m′
→ ∀-IsProp λ m′<n → T .eq-IsProp))
⟦∀⟧′-IsSet : ∀ {Δ n T δ} → IsSet (⟦∀⟧′ {Δ} n T δ)
⟦∀⟧′-IsSet {Δ} {n} {T} {δ}
= ≅-pres-IsOfHLevel 2 (≅-sym ⟦∀⟧′≅⟦∀⟧′Canon) (⟦∀⟧′Canon-IsSet {Δ} {n} {T} {δ})
⟦∀⟧′-≡⁺ : ∀ {Δ n T δ} (f g : ⟦∀⟧′ {Δ} n T δ)
→ (∀ m m<n → f .arr m m<n ≡ g .arr m m<n)
→ f ≡ g
⟦∀⟧′-≡⁺ {T = T} record{} record{} f≈g = ≅-Injective ⟦∀⟧′≅⟦∀⟧′Canon (Σ-≡⁺
( (funext λ m → funext λ m<n → f≈g m m<n)
, funext λ m → funext λ m<n → funext λ m′ → funext λ m<n′ → T .eq-IsProp _ _))
⟦∀⟧′-resp-≈⟦Type⟧ : ∀ {Δ n T U}
→ T ≈⟦Type⟧ U
→ ∀ {δ} → ⟦∀⟧′ {Δ} n T δ ≅ ⟦∀⟧′ n U δ
⟦∀⟧′-resp-≈⟦Type⟧ T≈U = record
{ forth = λ f → record
{ arr = λ m m<n → T≈U .forth .fobj (f .arr m m<n)
; param = λ m m<n m′ m′<n → T≈U .forth .feq _ (f .param m m<n m′ m′<n)
}
; isIso = record
{ back = λ f → record
{ arr = λ m m<n → T≈U .back .fobj (f .arr m m<n)
; param = λ m m<n m′ m′<n → T≈U .back .feq _ (f .param m m<n m′ m′<n)
}
; back∘forth = λ x → ⟦∀⟧′-≡⁺ _ _ λ m m<n → T≈U .back-forth .≈⁻ _ _
; forth∘back = λ x → ⟦∀⟧′-≡⁺ _ _ λ m m<n → T≈U .forth-back .≈⁻ _ _
}
}
⟦∀⟧ : ∀ {Δ} n (T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ) → ⟦Type⟧ ⟦ Δ ⟧Δ
⟦∀⟧ n T = record
{ ObjHSet = λ δ → HLevel⁺ (⟦∀⟧′ n T δ) ⟦∀⟧′-IsSet
; eqHProp = λ _ f g → ∀-HProp _ λ m → ∀-HProp _ λ m<n → ∀-HProp _ λ m′
→ ∀-HProp _ λ m′<n → T .eqHProp _ (f .arr m m<n) (g .arr m′ m′<n)
; eq-refl = λ f → f .param
}
⟦∀⟧-resp-≈⟦Type⟧ : ∀ {Δ} n {T U : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ}
→ T ≈⟦Type⟧ U
→ ⟦∀⟧ n T ≈⟦Type⟧ ⟦∀⟧ n U
⟦∀⟧-resp-≈⟦Type⟧ n T≈U = record
{ forth = record
{ fobj = ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .forth
; feq = λ δ≈δ′ x≈y a a₁ a₂ a₃ → T≈U .forth .feq _ (x≈y a a₁ a₂ a₃)
}
; back = record
{ fobj = ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .back
; feq = λ δ≈δ′ x≈y a a₁ a₂ a₃ → T≈U .back .feq _ (x≈y a a₁ a₂ a₃)
}
; back-forth = ≈⁺ λ δ x → ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .back∘forth _
; forth-back = ≈⁺ λ δ x → ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .forth∘back _
}
absₛ : ∀ {Δ n} {Γ : ⟦Type⟧ ⟦ Δ ⟧Δ} {T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ}
→ subT ⟦ SS.Wk ⟧σ Γ ⇒ T
→ Γ ⇒ ⟦∀⟧ n T
absₛ {Δ} {n} {Γ} {T} f = record
{ fobj = λ {δ} x → record
{ arr = λ m m<n → f .fobj x
; param = λ m m<n m′ m′<n → f .feq _ (Γ .eq-refl x)
}
; feq = λ _ x≈y m m′ m<nγ m′<nγ′ → f .feq _ x≈y
}
appₛ : ∀ {Δ n m} {Γ : ⟦Type⟧ ⟦ Δ ⟧Δ} {T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ}
→ (m<n : m SS.< n)
→ Γ ⇒ ⟦∀⟧ n T
→ Γ ⇒ subT ⟦ SS.Sing m<n ⟧σ T
appₛ {m = m} {T = T} m<n f = record
{ fobj = λ {δ} x → f .fobj x .arr (⟦ m ⟧n .fobj δ) (MS.⟦<⟧ m<n)
; feq = λ δ≈δ′ {x y} x≈y → f .feq _ x≈y _ _ _ _
}
subT-⟦∀⟧ : ∀ {Δ Ω n σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (T : ⟦Type⟧ ⟦ Ω ∙ n ⟧Δ)
→ ⟦∀⟧ (n [ σ ]ᵤ)
(subT (⟦_⟧σ {Ω = Ω ∙ n} (Lift ⊢σ refl)) T)
≈⟦Type⟧ subT ⟦ ⊢σ ⟧σ (⟦∀⟧ n T)
subT-⟦∀⟧ {Δ} {Ω} {n} {σ} ⊢σ T = record
{ forth = record
{ fobj = λ {γ} f → record
{ arr = λ m m<n
→ transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(f .arr m (subst (m <_) (sym (MS.⟦sub⟧ ⊢σ n)) m<n))
; param = λ m m<n m′ m′<n
→ transportObj-resp-eq T _ _ (f .param _ _ _ _)
}
; feq = λ γ≈γ′ f≈g a a₁ a₂ a₃ → transportObj-resp-eq T _ _ (f≈g _ _ _ _)
}
; back = record
{ fobj = λ {γ} f → record
{ arr = λ m m<n
→ transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(f .arr m (subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n))
; param = λ m m<n m′ m′<n
→ transportObj-resp-eq T _ _ (f .param _ _ _ _)
}
; feq = λ γ≈γ′ f≈g a a₁ a₂ a₃ → transportObj-resp-eq T _ _ (f≈g _ _ _ _)
}
; back-forth = ≈⁺ λ γ f → ⟦∀⟧′-≡⁺ _ _ λ m m<n
→ trans
(transportObj∘transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl))
(trans
(cong
(λ p → transportObj T
(trans
(MS.⟦Δ∙n⟧-≡⁺ Ω n
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) p)
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n)
refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n)
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n)
refl refl))
(f .arr m p))
(subst-sym-subst (MS.⟦sub⟧ ⊢σ n)))
(transportObj-refl T _))
; forth-back = ≈⁺ λ γ f → ⟦∀⟧′-≡⁺ _ _ λ m m<n
→ trans
(transportObj∘transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl))
(trans
(cong
(λ p → transportObj T
(trans
(MS.⟦Δ∙n⟧-≡⁺ Ω n p p refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n p m<n refl refl))
(f .arr m p))
(subst-subst-sym (MS.⟦sub⟧ ⊢σ n)))
(transportObj-refl T _))
}
| 32.238806 | 82 | 0.439352 |
1821abad4bd1c8ec808cdd4a58700db91d725f37 | 3,038 | agda | Agda | Groups/FreeGroup/Word.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 4 | 2019-08-08T12:44:19.000Z | 2022-01-28T06:04:15.000Z | Groups/FreeGroup/Word.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 14 | 2019-01-06T21:11:59.000Z | 2020-04-11T11:03:39.000Z | Groups/FreeGroup/Word.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 1 | 2021-11-29T13:23:07.000Z | 2021-11-29T13:23:07.000Z | {-# OPTIONS --safe --warning=error #-}
open import Setoids.Setoids
open import Groups.SymmetricGroups.Definition
open import Groups.FreeGroup.Definition
open import Decidable.Sets
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import LogicalFormulae
open import Boolean.Definition
module Groups.FreeGroup.Word {a : _} {A : Set a} (decA : DecidableSet A) where
data ReducedWord : Set a
wordLength : ReducedWord → ℕ
firstLetter : (w : ReducedWord) → .(0 <N wordLength w) → FreeCompletion A
data PrependIsValid (w : ReducedWord) (l : FreeCompletion A) : Set a where
wordEmpty : wordLength w ≡ 0 → PrependIsValid w l
wordEnding : .(pr : 0 <N wordLength w) → .(freeCompletionEqual decA l (freeInverse (firstLetter w pr)) ≡ BoolFalse) → PrependIsValid w l
data ReducedWord where
empty : ReducedWord
prependLetter : (letter : FreeCompletion A) → (w : ReducedWord) → PrependIsValid w letter → ReducedWord
firstLetter empty ()
firstLetter (prependLetter letter w x) pr = letter
wordLength empty = 0
wordLength (prependLetter letter w pr) = succ (wordLength w)
prependLetterRefl : {x : FreeCompletion A} {w : ReducedWord} → {pr1 pr2 : PrependIsValid w x} → prependLetter x w pr1 ≡ prependLetter x w pr2
prependLetterRefl {x} {empty} {wordEmpty refl} {wordEmpty refl} = refl
prependLetterRefl {x} {empty} {wordEmpty refl} {wordEnding () x₂}
prependLetterRefl {x} {empty} {wordEnding () x₁} {pr2}
prependLetterRefl {x} {prependLetter letter w x₁} {wordEmpty ()} {pr2}
prependLetterRefl {x} {prependLetter letter w x₁} {wordEnding pr x₂} {wordEmpty ()}
prependLetterRefl {x} {prependLetter letter w x₁} {wordEnding pr2 r2} {wordEnding pr1 r1} = refl
prependLetterInjective : {x : FreeCompletion A} {w1 w2 : ReducedWord} {pr1 : PrependIsValid w1 x} {pr2 : PrependIsValid w2 x} → prependLetter x w1 pr1 ≡ prependLetter x w2 pr2 → w1 ≡ w2
prependLetterInjective {x = x} {empty} {empty} {pr1} {pr2} pr = refl
prependLetterInjective {x = x} {prependLetter l1 w1 x1} {prependLetter .l1 .w1 .x1} {wordEnding pr₁ x₁} {wordEnding pr₂ x₂} refl = refl
prependLetterInjective' : {x y : FreeCompletion A} {w1 w2 : ReducedWord} {pr1 : PrependIsValid w1 x} {pr2 : PrependIsValid w2 y} → prependLetter x w1 pr1 ≡ prependLetter y w2 pr2 → x ≡ y
prependLetterInjective' refl = refl
badPrepend : {x : A} {w : ReducedWord} {pr : PrependIsValid w (ofInv x)} → (PrependIsValid (prependLetter (ofInv x) w pr) (ofLetter x)) → False
badPrepend (wordEmpty ())
badPrepend {x = x} (wordEnding pr bad) with decidableFreeCompletion decA (ofLetter x) (ofLetter x)
badPrepend {x} (wordEnding pr ()) | inl x₁
badPrepend {x} (wordEnding pr bad) | inr pr2 = pr2 refl
badPrepend' : {x : A} {w : ReducedWord} {pr : PrependIsValid w (ofLetter x)} → (PrependIsValid (prependLetter (ofLetter x) w pr) (ofInv x)) → False
badPrepend' (wordEmpty ())
badPrepend' {x = x} (wordEnding pr x₁) with decidableFreeCompletion decA (ofInv x) (ofInv x)
badPrepend' {x} (wordEnding pr ()) | inl x₂
badPrepend' {x} (wordEnding pr x₁) | inr pr2 = pr2 refl
| 52.37931 | 186 | 0.730744 |
4a5161698d4659779b09b67653f8b924c6f277e7 | 16,408 | agda | Agda | Math/Combinatorics/ListFunction/Properties.agda | rei1024/agda-combinatorics | 9fafa35c940ff7b893a80120f6a1f22b0a3917b7 | [
"MIT"
] | 3 | 2019-06-25T08:24:15.000Z | 2020-04-25T07:25:27.000Z | Math/Combinatorics/ListFunction/Properties.agda | rei1024/agda-combinatorics | 9fafa35c940ff7b893a80120f6a1f22b0a3917b7 | [
"MIT"
] | null | null | null | Math/Combinatorics/ListFunction/Properties.agda | rei1024/agda-combinatorics | 9fafa35c940ff7b893a80120f6a1f22b0a3917b7 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Properties of functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --exact-split #-}
module Math.Combinatorics.ListFunction.Properties where
-- agda-stdlib
open import Data.List hiding (_∷ʳ_)
import Data.List.Properties as Lₚ
open import Data.List.Membership.Propositional using (_∈_; _∉_)
import Data.List.Membership.Propositional.Properties as ∈ₚ
open import Data.List.Relation.Binary.BagAndSetEquality
open import Data.List.Relation.Binary.Sublist.Propositional using (_⊆_; []; _∷_; _∷ʳ_)
import Data.List.Relation.Binary.Sublist.Propositional.Properties as Sublistₚ
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
import Data.List.Relation.Unary.All.Properties as Allₚ
open import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
import Data.List.Relation.Unary.Unique.Propositional as UniqueP
import Data.List.Relation.Unary.Unique.Propositional.Properties as UniquePₚ
import Data.List.Relation.Unary.Unique.Setoid as UniqueS
import Data.List.Relation.Unary.Unique.Setoid.Properties as UniqueSₚ
open import Data.Nat
open import Data.Product as Prod using (_×_; _,_; ∃; proj₁; proj₂)
open import Data.Sum using (inj₁; inj₂)
open import Function.Base
open import Function.Equivalence using (_⇔_; equivalence) -- TODO: use new packages
open import Relation.Binary.PropositionalEquality as P
-- agda-combinatorics
open import Math.Combinatorics.Function
open import Math.Combinatorics.Function.Properties
open import Math.Combinatorics.ListFunction
import Math.Combinatorics.ListFunction.Properties.Lemma as Lemma
------------------------------------------------------------------------
-- Properties of `applyEach`
module _ {a} {A : Set a} where
open ≡-Reasoning
length-applyEach : ∀ (f : A → A) (xs : List A) →
length (applyEach f xs) ≡ length xs
length-applyEach f [] = refl
length-applyEach f (x ∷ xs) = begin
1 + length (map (x ∷_) (applyEach f xs))
≡⟨ cong suc $ Lₚ.length-map (x ∷_) (applyEach f xs ) ⟩
1 + length (applyEach f xs)
≡⟨ cong suc $ length-applyEach f xs ⟩
1 + length xs
∎
All-length-applyEach : ∀ (f : A → A) (xs : List A) →
All (λ ys → length ys ≡ length xs) (applyEach f xs)
All-length-applyEach f [] = []
All-length-applyEach f (x ∷ xs) =
refl ∷ (Allₚ.map⁺ $ All.map (cong suc) $ All-length-applyEach f xs)
applyEach-cong : ∀ (f g : A → A) (xs : List A) →
(∀ x → f x ≡ g x) → applyEach f xs ≡ applyEach g xs
applyEach-cong f g [] f≡g = refl
applyEach-cong f g (x ∷ xs) f≡g = begin
(f x ∷ xs) ∷ map (_∷_ x) (applyEach f xs)
≡⟨ cong₂ (λ u v → (u ∷ xs) ∷ map (_∷_ x) v) (f≡g x) (applyEach-cong f g xs f≡g) ⟩
(g x ∷ xs) ∷ map (_∷_ x) (applyEach g xs)
∎
------------------------------------------------------------------------
-- Properties of `combinations`
module _ {a} {A : Set a} where
open ≡-Reasoning
length-combinations : ∀ (k : ℕ) (xs : List A) →
length (combinations k xs) ≡ C (length xs) k
length-combinations 0 xs = refl
length-combinations (suc k) [] = refl
length-combinations (suc k) (x ∷ xs) = begin
length (map (x ∷_) (combinations k xs) ++ combinations (suc k) xs)
≡⟨ Lₚ.length-++ (map (x ∷_) (combinations k xs)) ⟩
length (map (x ∷_) (combinations k xs)) + length (combinations (suc k) xs)
≡⟨ cong₂ _+_ (Lₚ.length-map (x ∷_) (combinations k xs)) refl ⟩
length (combinations k xs) + length (combinations (suc k) xs)
≡⟨ cong₂ _+_ (length-combinations k xs) (length-combinations (suc k) xs) ⟩
C (length xs) k + C (length xs) (suc k)
≡⟨ sym $ C[1+n,1+k]≡C[n,k]+C[n,1+k] (length xs) k ⟩
C (length (x ∷ xs)) (suc k)
∎
All-length-combinations : ∀ (k : ℕ) (xs : List A) →
All (λ ys → length ys ≡ k) (combinations k xs)
All-length-combinations 0 xs = refl ∷ []
All-length-combinations (suc k) [] = []
All-length-combinations (suc k) (x ∷ xs) =
Allₚ.++⁺ (Allₚ.map⁺ $ All.map (cong suc) $ All-length-combinations k xs)
(All-length-combinations (suc k) xs)
∈-length-combinations : ∀ (xs : List A) k ys → xs ∈ combinations k ys → length xs ≡ k
∈-length-combinations xs k ys xs∈combinations[k,ys] =
All.lookup (All-length-combinations k ys) xs∈combinations[k,ys]
combinations-⊆⇒∈ : ∀ {xs ys : List A} → xs ⊆ ys → xs ∈ combinations (length xs) ys
combinations-⊆⇒∈ {[]} {ys} xs⊆ys = here refl
combinations-⊆⇒∈ {x ∷ xs} {y ∷ ys} (.y ∷ʳ x∷xs⊆ys) =
∈ₚ.∈-++⁺ʳ (map (y ∷_) (combinations (length xs) ys)) (combinations-⊆⇒∈ x∷xs⊆ys)
combinations-⊆⇒∈ {x ∷ xs} {.x ∷ ys} (refl ∷ xs⊆ys) =
∈ₚ.∈-++⁺ˡ $ ∈ₚ.∈-map⁺ (x ∷_) $ combinations-⊆⇒∈ xs⊆ys
combinations-∈⇒⊆ : ∀ {xs ys : List A} → xs ∈ combinations (length xs) ys → xs ⊆ ys
combinations-∈⇒⊆ {[]} {ys} _ = Lemma.[]⊆xs ys
combinations-∈⇒⊆ {x ∷ xs} {y ∷ ys} x∷xs∈c[len[x∷xs],y∷ys]
with ∈ₚ.∈-++⁻ (map (y ∷_) (combinations (length xs) ys)) x∷xs∈c[len[x∷xs],y∷ys]
... | inj₁ x∷xs∈map[y∷-][c[len[xs],ys]]
with ∈ₚ.∈-map⁻ (y ∷_) x∷xs∈map[y∷-][c[len[xs],ys]] -- ∷ ∃ λ zs → zs ∈ combinations (length xs) ys × x ∷ xs ≡ y ∷ zs
combinations-∈⇒⊆ {x ∷ xs} {y ∷ ys} _ | inj₁ _
| zs , (zs∈c[len[xs],ys] , x∷xs≡y∷zs) = x≡y ∷ xs⊆ys
where
xs≡zs : xs ≡ zs
xs≡zs = Lₚ.∷-injectiveʳ x∷xs≡y∷zs
x≡y : x ≡ y
x≡y = Lₚ.∷-injectiveˡ x∷xs≡y∷zs
xs⊆ys : xs ⊆ ys
xs⊆ys = combinations-∈⇒⊆ $ subst (λ v → v ∈ combinations (length xs) ys)
(sym xs≡zs) zs∈c[len[xs],ys]
combinations-∈⇒⊆ {x ∷ xs} {y ∷ ys} _ | inj₂ x∷xs∈c[len[x∷xs],ys] = y ∷ʳ x∷xs⊆ys
where
x∷xs⊆ys : x ∷ xs ⊆ ys
x∷xs⊆ys = combinations-∈⇒⊆ x∷xs∈c[len[x∷xs],ys]
combinations-∈⇔⊆ : ∀ {xs ys : List A} → (xs ∈ combinations (length xs) ys) ⇔ (xs ⊆ ys)
combinations-∈⇔⊆ = equivalence combinations-∈⇒⊆ combinations-⊆⇒∈
All-⊆-combinations : ∀ k (xs : List A) → All (_⊆ xs) (combinations k xs)
All-⊆-combinations k xs = All.tabulate λ {ys} ys∈combinations[k,xs] →
combinations-∈⇒⊆ $ subst (λ v → ys ∈ combinations v xs)
(sym $ ∈-length-combinations ys k xs ys∈combinations[k,xs])
ys∈combinations[k,xs]
combinations-∈⇒⊆∧length : ∀ {xs : List A} {k ys} →
xs ∈ combinations k ys → (xs ⊆ ys × length xs ≡ k)
combinations-∈⇒⊆∧length {xs} {k} {ys} xs∈c[k,ys] =
combinations-∈⇒⊆ xs∈c[len[xs],ys] , length[xs]≡k
where
length[xs]≡k : length xs ≡ k
length[xs]≡k = ∈-length-combinations xs k ys xs∈c[k,ys]
xs∈c[len[xs],ys] : xs ∈ combinations (length xs) ys
xs∈c[len[xs],ys] =
subst (λ v → xs ∈ combinations v ys) (sym length[xs]≡k) xs∈c[k,ys]
combinations-⊆∧length⇒∈ : ∀ {xs ys : List A} {k} →
(xs ⊆ ys × length xs ≡ k) → xs ∈ combinations k ys
combinations-⊆∧length⇒∈ {xs} {ys} {k} (xs⊆ys , len[xs]≡k) =
subst (λ v → xs ∈ combinations v ys) len[xs]≡k (combinations-⊆⇒∈ xs⊆ys)
combinations-∈⇔⊆∧length : ∀ {xs : List A} {k} {ys} →
xs ∈ combinations k ys ⇔ (xs ⊆ ys × length xs ≡ k)
combinations-∈⇔⊆∧length =
equivalence combinations-∈⇒⊆∧length combinations-⊆∧length⇒∈
unique-combinations : ∀ k {xs : List A} →
UniqueP.Unique xs → UniqueP.Unique (combinations k xs)
unique-combinations 0 {xs} xs-unique = [] ∷ []
unique-combinations (suc k) {[]} xs-unique = []
unique-combinations (suc k) {x ∷ xs} (All[x≢-]xs ∷ xs-unique) =
UniquePₚ.++⁺ {_} {_} {map (x ∷_) (combinations k xs)} {combinations (suc k) xs}
(UniquePₚ.map⁺ Lₚ.∷-injectiveʳ (unique-combinations k {xs} xs-unique))
(unique-combinations (suc k) {xs} xs-unique)
λ {vs} vs∈map[x∷-]c[k,xs]×vs∈c[1+k,xs] →
let
vs∈map[x∷-]c[k,xs] = proj₁ vs∈map[x∷-]c[k,xs]×vs∈c[1+k,xs]
vs∈c[1+k,xs] = proj₂ vs∈map[x∷-]c[k,xs]×vs∈c[1+k,xs]
proof = ∈ₚ.∈-map⁻ (x ∷_) vs∈map[x∷-]c[k,xs]
us = proj₁ proof
vs≡x∷us : vs ≡ x ∷ us
vs≡x∷us = proj₂ (proj₂ proof)
x∈vs : x ∈ vs
x∈vs = subst (x ∈_) (sym vs≡x∷us) (here refl)
vs⊆xs : vs ⊆ xs
vs⊆xs = proj₁ $ combinations-∈⇒⊆∧length {vs} {suc k} {xs} vs∈c[1+k,xs]
All[x≢-]vs : All (x ≢_) vs
All[x≢-]vs = Sublistₚ.All-resp-⊆ vs⊆xs All[x≢-]xs
x∉vs : x ∉ vs
x∉vs = Allₚ.All¬⇒¬Any All[x≢-]vs
in x∉vs x∈vs
{-
-- unique⇒drop-cons-set : ∀ {a} {A : Set a} {x : A} {xs ys} →
unique-combinations-set : ∀ k {xs : List A} →
UniqueP.Unique xs → UniqueS.Unique ([ set ]-Equality A) (combinations k xs)
unique-combinations-set 0 xs-unique = [] ∷ []
unique-combinations-set (suc k) {[]} xs-unique = []
unique-combinations-set (suc k) {x ∷ xs} (this ∷ xs-unique) =
UniqueSₚ.++⁺ ([ set ]-Equality A)
(UniqueSₚ.map⁺ ([ set ]-Equality A) ([ set ]-Equality A) (λ → {! !}) (unique-combinations-set k {xs} xs-unique))
(unique-combinations-set (suc k) {xs} xs-unique)
{! !}
-- {- x∉xs -} Unique -[ set ] xs → Unique -[ set ] (x ∷ xs)
-}
module _ {a b} {A : Set a} {B : Set b} where
combinations-map : ∀ k (f : A → B) (xs : List A) →
combinations k (map f xs) ≡ map (map f) (combinations k xs)
combinations-map 0 f xs = refl
combinations-map (suc k) f [] = refl
combinations-map (suc k) f (x ∷ xs) = begin
map (f x ∷_) (combinations k (map f xs)) ++ combinations (suc k) (map f xs)
≡⟨ cong₂ _++_ (cong (map (f x ∷_)) (combinations-map k f xs)) (combinations-map (suc k) f xs) ⟩
map (f x ∷_) (map (map f) (combinations k xs)) ++ map (map f) (combinations (suc k) xs)
≡⟨ cong (_++ map (map f) (combinations (suc k) xs)) $ Lemma.lemma₁ f x (combinations k xs) ⟩
map (map f) (map (x ∷_) (combinations k xs)) ++ map (map f) (combinations (suc k) xs)
≡⟨ sym $ Lₚ.map-++-commute (map f) (map (x ∷_) (combinations k xs)) (combinations (suc k) xs) ⟩
map (map f) (map (x ∷_) (combinations k xs) ++ combinations (suc k) xs)
∎
where open ≡-Reasoning
------------------------------------------------------------------------
-- Properties of `combinationsWithComplement`
module _ {a} {A : Set a} where
open ≡-Reasoning
map-proj₁-combinationsWithComplement : ∀ k (xs : List A) →
map proj₁ (combinationsWithComplement k xs) ≡ combinations k xs
map-proj₁-combinationsWithComplement 0 xs = refl
map-proj₁-combinationsWithComplement (suc k) [] = refl
map-proj₁-combinationsWithComplement (suc k) (x ∷ xs) = begin
map proj₁ (map f ys ++ map g zs)
≡⟨ Lₚ.map-++-commute proj₁ (map f ys) (map g zs) ⟩
map proj₁ (map f ys) ++ map proj₁ (map g zs)
≡⟨ sym $ Lₚ.map-compose ys ⟨ cong₂ _++_ ⟩ Lₚ.map-compose zs ⟩
map (proj₁ ∘′ f) ys ++ map (λ v → proj₁ (g v)) zs
≡⟨ Lₚ.map-cong lemma₁ ys ⟨ cong₂ _++_ ⟩ Lₚ.map-cong lemma₂ zs ⟩
map ((x ∷_) ∘′ proj₁) ys ++ map proj₁ zs
≡⟨ cong (_++ map proj₁ zs) $ Lₚ.map-compose ys ⟩
map (x ∷_) (map proj₁ ys) ++ map proj₁ zs
≡⟨ cong (map (x ∷_)) (map-proj₁-combinationsWithComplement k xs) ⟨ cong₂ _++_ ⟩ map-proj₁-combinationsWithComplement (suc k) xs ⟩
map (x ∷_) (combinations k xs) ++ combinations (suc k) xs
∎
where
ys = combinationsWithComplement k xs
zs = combinationsWithComplement (suc k) xs
f g : List A × List A → List A × List A
f = Prod.map₁ (x ∷_)
g = Prod.map₂ (x ∷_)
lemma₁ : ∀ (t : List A × List A) → proj₁ (Prod.map₁ (x ∷_) t) ≡ x ∷ proj₁ t
lemma₁ t = Lemma.proj₁-map₁ (x ∷_) t
lemma₂ : ∀ (t : List A × List A) → Lemma.proj₁′ {_} {_} {_} {List A} (Prod.map₂ (x ∷_) t) ≡ proj₁ t
lemma₂ t = Lemma.proj₁-map₂ (x ∷_) t
length-combinationsWithComplement : ∀ k (xs : List A) →
length (combinationsWithComplement k xs) ≡ C (length xs) k
length-combinationsWithComplement k xs = begin
length (combinationsWithComplement k xs)
≡⟨ sym $ Lₚ.length-map proj₁ (combinationsWithComplement k xs) ⟩
length (map proj₁ (combinationsWithComplement k xs))
≡⟨ cong length $ map-proj₁-combinationsWithComplement k xs ⟩
length (combinations k xs)
≡⟨ length-combinations k xs ⟩
C (length xs) k
∎
------------------------------------------------------------------------
-- Properties of `splits₂`
module _ {a} {A : Set a} where
open ≡-Reasoning
open Prod using (map₁; map₂)
length-splits₂ : ∀ (xs : List A) → length (splits₂ xs) ≡ 1 + length xs
length-splits₂ [] = refl
length-splits₂ (x ∷ xs) = begin
1 + length (map (map₁ (x ∷_)) (splits₂ xs))
≡⟨ cong (1 +_) $ Lₚ.length-map (map₁ (x ∷_)) (splits₂ xs) ⟩
1 + length (splits₂ xs)
≡⟨ cong (1 +_) $ length-splits₂ xs ⟩
1 + length (x ∷ xs)
∎
splits₂-defn : ∀ (xs : List A) → splits₂ xs ≡ zip (inits xs) (tails xs)
splits₂-defn [] = refl
splits₂-defn (x ∷ xs) = begin
splits₂ (x ∷ xs) ≡⟨⟩
([] , x ∷ xs) ∷ map (map₁ (x ∷_)) (splits₂ xs)
≡⟨ cong (([] , x ∷ xs) ∷_) (begin
map (map₁ (x ∷_)) (splits₂ xs)
≡⟨ cong (map (map₁ (x ∷_))) $ splits₂-defn xs ⟩
map (map₁ (x ∷_)) (zip is ts)
≡⟨ Lₚ.map-zipWith _,_ (map₁ (x ∷_)) is ts ⟩
zipWith (λ ys zs → map₁ (x ∷_) (ys , zs)) is ts
≡⟨ sym $ Lₚ.zipWith-map _,_ (x ∷_) id is ts ⟩
zip (map (x ∷_) is) (map id ts)
≡⟨ cong (zip (map (x ∷_) is)) $ Lₚ.map-id ts ⟩
zip (map (x ∷_) is) ts
∎) ⟩
([] , x ∷ xs) ∷ zip (map (x ∷_) is) ts
∎
where
is = inits xs
ts = tails xs
All-++-splits₂ : (xs : List A) →
All (Prod.uncurry (λ ys zs → ys ++ zs ≡ xs)) (splits₂ xs)
All-++-splits₂ [] = refl ∷ []
All-++-splits₂ (x ∷ xs) =
All._∷_ refl $ Allₚ.map⁺ $ All.map (cong (x ∷_)) $ All-++-splits₂ xs
splits₂-∈⇒++ : {xs ys zs : List A} → (ys , zs) ∈ splits₂ xs → ys ++ zs ≡ xs
splits₂-∈⇒++ {xs = xs} = All.lookup (All-++-splits₂ xs)
private
[],xs∈splits₂[xs] : (xs : List A) → ([] , xs) ∈ splits₂ xs
[],xs∈splits₂[xs] [] = here refl
[],xs∈splits₂[xs] (x ∷ xs) = here refl
∈-split₂-++ : (xs ys : List A) → (xs , ys) ∈ splits₂ (xs ++ ys)
∈-split₂-++ [] ys = [],xs∈splits₂[xs] ys
∈-split₂-++ (x ∷ xs) ys =
Any.there $ ∈ₚ.∈-map⁺ (map₁ (x ∷_)) $ ∈-split₂-++ xs ys
splits₂-++⇒∈ : {xs ys zs : List A} → xs ++ ys ≡ zs → (xs , ys) ∈ splits₂ zs
splits₂-++⇒∈ {xs} {ys} {zs} xs++ys≡zs =
subst (λ v → (xs , ys) ∈ splits₂ v) xs++ys≡zs (∈-split₂-++ xs ys)
splits₂-∈⇔++ : {xs ys zs : List A} → (xs , ys) ∈ splits₂ zs ⇔ xs ++ ys ≡ zs
splits₂-∈⇔++ = equivalence splits₂-∈⇒++ splits₂-++⇒∈
module _ {a b} {A : Set a} {B : Set b} where
open ≡-Reasoning
{-
splits₂-map : ∀ (f : A → B) (xs : List A) →
splits₂ (map f xs) ≡ map (Prod.map (map f) (map f)) (splits₂ xs)
splits₂-map f [] = refl
splits₂-map f (x ∷ xs) = {! !}
-}
-- length[xs]<k⇒combinations[k,xs]≡[]
-- All-unique-combinations : UniqueP.Unique xs → All (UniqueP.Unique) (combinations k xs)
-- All-unique-combinations-set : UniqueP.Unique xs → All (UniqueS.Unique [ set ]-Equality A) (combinations k xs)
-- unique-combinations-PW : UniqueS.Unique S xs → UniqueS.Unique (Equality S) (combinations k xs)
-- unique-combinations-set : UniqueP.Unique xs → Unique (_-[ set ]_) (combinations k xs)
-- sorted-combinations : Sorted _<_ xs → Sorted {- Lex._<_ _<_ -} (combinations k xs)
-- All-sorted-combinations : Sorted _<_ xs → All (Sorted _<_) (combinations k xs)
-- filter-combinations = filter P ∘ combinations k xs
-- each-disjoint-combinationsWithComplement : Unique zs → (xs , ys) ∈ combinationsWithComplement k zs → Disjoint xs ys
-- combinationsWithComplement-∈⇒⊆ : (xs , ys) ∈ combinationsWithComplement (length xs) zs → xs ⊆ zs × ys ⊆ zs
-- length-splits : length (splits k xs) ≡ C (length xs + k ∸ 1) (length xs)
-- length-partitionsAll : length (partitionsAll xs) ≡ B (length xs)
-- length-insertEverywhere : length (insertEverywhere x xs) ≡ 1 + length xs
-- All-length-insertEverywhere : All (λ ys → length ys ≡ 1 + length xs) (insertEverywhere x xs)
-- length-permutations : length (permutations xs) ≡ length xs !
| 46.613636 | 135 | 0.56058 |
4afa5d704094e9b8569ba6138977517aa5465585 | 5,662 | agda | Agda | Cubical/HITs/SetQuotients/Properties.agda | scott-fleischman/cubical | 337ce3883449862c2d27380b36a2a7b599ef9f0d | [
"MIT"
] | null | null | null | Cubical/HITs/SetQuotients/Properties.agda | scott-fleischman/cubical | 337ce3883449862c2d27380b36a2a7b599ef9f0d | [
"MIT"
] | null | null | null | Cubical/HITs/SetQuotients/Properties.agda | scott-fleischman/cubical | 337ce3883449862c2d27380b36a2a7b599ef9f0d | [
"MIT"
] | null | null | null | {-
Set quotients:
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.SetQuotients.Properties where
open import Cubical.HITs.SetQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.HAEquiv
open import Cubical.Foundations.Univalence
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary.Base
open import Cubical.HITs.PropositionalTruncation
open import Cubical.HITs.SetTruncation
-- Type quotients
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ'
B : A / R → Type ℓ''
elimEq/ : (Bprop : (x : A / R ) → isProp (B x))
{x y : A / R}
(eq : x ≡ y)
(bx : B x)
(by : B y) →
PathP (λ i → B (eq i)) bx by
elimEq/ {B = B} Bprop {x = x} =
J (λ y eq → ∀ bx by → PathP (λ i → B (eq i)) bx by) (λ bx by → Bprop x bx by)
elimSetQuotientsProp : ((x : A / R ) → isProp (B x)) →
(f : (a : A) → B ( [ a ])) →
(x : A / R) → B x
elimSetQuotientsProp Bprop f [ x ] = f x
elimSetQuotientsProp Bprop f (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep {n = 2} (λ x → isProp→isSet (Bprop x))
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elimSetQuotientsProp Bprop f
elimSetQuotientsProp Bprop f (eq/ a b r i) = elimEq/ Bprop (eq/ a b r) (f a) (f b) i
-- lemma 6.10.2 in hott book
-- TODO: defined truncated Sigma as ∃
[]surjective : (x : A / R) → ∥ Σ[ a ∈ A ] [ a ] ≡ x ∥
[]surjective = elimSetQuotientsProp (λ x → squash) (λ a → ∣ a , refl ∣)
elimSetQuotients : {B : A / R → Type ℓ} →
(Bset : (x : A / R) → isSet (B x)) →
(f : (a : A) → (B [ a ])) →
(feq : (a b : A) (r : R a b) →
PathP (λ i → B (eq/ a b r i)) (f a) (f b)) →
(x : A / R) → B x
elimSetQuotients Bset f feq [ a ] = f a
elimSetQuotients Bset f feq (eq/ a b r i) = feq a b r i
elimSetQuotients Bset f feq (squash/ x y p q i j) =
isOfHLevel→isOfHLevelDep {n = 2} Bset
(g x) (g y) (cong g p) (cong g q) (squash/ x y p q) i j
where
g = elimSetQuotients Bset f feq
setQuotUniversal : {B : Type ℓ} (Bset : isSet B) →
(A / R → B) ≃ (Σ[ f ∈ (A → B) ] ((a b : A) → R a b → f a ≡ f b))
setQuotUniversal Bset = isoToEquiv (iso intro elim elimRightInv elimLeftInv)
where
intro = λ g → (λ a → g [ a ]) , λ a b r i → g (eq/ a b r i)
elim = λ h → elimSetQuotients (λ x → Bset) (fst h) (snd h)
elimRightInv : ∀ h → intro (elim h) ≡ h
elimRightInv h = refl
elimLeftInv : ∀ g → elim (intro g) ≡ g
elimLeftInv = λ g → funExt (λ x → elimPropTrunc {P = λ sur → elim (intro g) x ≡ g x}
(λ sur → Bset (elim (intro g) x) (g x))
(λ sur → cong (elim (intro g)) (sym (snd sur)) ∙ (cong g (snd sur))) ([]surjective x)
)
open BinaryRelation
effective : (Rprop : isPropValued R) (Requiv : isEquivRel R) (a b : A) → [ a ] ≡ [ b ] → R a b
effective {A = A} {R = R} Rprop (EquivRel R/refl R/sym R/trans) a b p = transport aa≡ab (R/refl _)
where
helper : A / R → hProp _
helper = elimSetQuotients (λ _ → isSetHProp) (λ c → (R a c , Rprop a c))
(λ c d cd → ΣProp≡ (λ _ → isPropIsProp)
(ua (PropEquiv→Equiv (Rprop a c) (Rprop a d)
(λ ac → R/trans _ _ _ ac cd) (λ ad → R/trans _ _ _ ad (R/sym _ _ cd)))))
aa≡ab : R a a ≡ R a b
aa≡ab i = fst (helper (p i))
isEquivRel→isEffective : isPropValued R → isEquivRel R → isEffective R
isEquivRel→isEffective {R = R} Rprop Req a b = isoToEquiv (iso intro elim intro-elim elim-intro)
where
intro : [ a ] ≡ [ b ] → R a b
intro = effective Rprop Req a b
elim : R a b → [ a ] ≡ [ b ]
elim = eq/ a b
intro-elim : ∀ x → intro (elim x) ≡ x
intro-elim ab = Rprop a b _ _
elim-intro : ∀ x → elim (intro x) ≡ x
elim-intro eq = squash/ _ _ _ _
discreteSetQuotients : Discrete A → isPropValued R → isEquivRel R → (∀ a₀ a₁ → Dec (R a₀ a₁)) → Discrete (A / R)
discreteSetQuotients {A = A} {R = R} Adis Rprop Req Rdec =
elimSetQuotients ((λ a₀ → isSetPi (λ a₁ → isProp→isSet (isPropDec (squash/ a₀ a₁)))))
discreteSetQuotients' discreteSetQuotients'-eq
where
discreteSetQuotients' : (a : A) (y : A / R) → Dec ([ a ] ≡ y)
discreteSetQuotients' a₀ = elimSetQuotients ((λ a₁ → isProp→isSet (isPropDec (squash/ [ a₀ ] a₁)))) dis dis-eq
where
dis : (a₁ : A) → Dec ([ a₀ ] ≡ [ a₁ ])
dis a₁ with Rdec a₀ a₁
... | (yes p) = yes (eq/ a₀ a₁ p)
... | (no ¬p) = no λ eq → ¬p (effective Rprop Req a₀ a₁ eq )
dis-eq : (a b : A) (r : R a b) →
PathP (λ i → Dec ([ a₀ ] ≡ eq/ a b r i)) (dis a) (dis b)
dis-eq a b ab = J (λ b ab → ∀ k → PathP (λ i → Dec ([ a₀ ] ≡ ab i)) (dis a) k)
(λ k → isPropDec (squash/ _ _) _ _) (eq/ a b ab) (dis b)
discreteSetQuotients'-eq : (a b : A) (r : R a b) →
PathP (λ i → (y : A / R) → Dec (eq/ a b r i ≡ y))
(discreteSetQuotients' a) (discreteSetQuotients' b)
discreteSetQuotients'-eq a b ab =
J (λ b ab → ∀ k → PathP (λ i → (y : A / R) → Dec (ab i ≡ y))
(discreteSetQuotients' a) k)
(λ k → funExt (λ x → isPropDec (squash/ _ _) _ _)) (eq/ a b ab) (discreteSetQuotients' b)
| 37.746667 | 142 | 0.536206 |
0e9b67207f7b2bccce6d43c696efcb23b9f508d6 | 801 | agda | Agda | Examples/Bool.agda | nad/pretty | b956803ba90b6c5f57bbbaab01bb18485d948492 | [
"MIT"
] | null | null | null | Examples/Bool.agda | nad/pretty | b956803ba90b6c5f57bbbaab01bb18485d948492 | [
"MIT"
] | null | null | null | Examples/Bool.agda | nad/pretty | b956803ba90b6c5f57bbbaab01bb18485d948492 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Booleans
------------------------------------------------------------------------
{-# OPTIONS --guardedness #-}
module Examples.Bool where
open import Codata.Musical.Notation
open import Data.Bool
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Grammar.Infinite using (Grammar)
import Pretty
open import Renderer
module _ where
open Grammar.Infinite
bool : Grammar Bool
bool = true <$ string′ "true"
∣ false <$ string′ "false"
open Pretty
bool-printer : Pretty-printer bool
bool-printer true = left (<$ text)
bool-printer false = right (<$ text)
test₁ : render 4 (bool-printer true) ≡ "true"
test₁ = refl
test₂ : render 0 (bool-printer false) ≡ "false"
test₂ = refl
| 22.25 | 72 | 0.585518 |
185f44aa68e55f43c245bf6e23a39de449883e89 | 3,175 | agda | Agda | src/Compatibility.agda | nad/chi | 30966769b8cbd46aa490b6964a4aa0e67a7f9ab1 | [
"MIT"
] | 2 | 2020-05-21T22:58:07.000Z | 2020-10-20T16:27:00.000Z | src/Compatibility.agda | nad/chi | 30966769b8cbd46aa490b6964a4aa0e67a7f9ab1 | [
"MIT"
] | 1 | 2020-05-21T23:29:54.000Z | 2020-06-08T11:08:25.000Z | src/Compatibility.agda | nad/chi | 30966769b8cbd46aa490b6964a4aa0e67a7f9ab1 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Compatibility lemmas
------------------------------------------------------------------------
open import Atom
module Compatibility (atoms : χ-atoms) where
open import Bag-equivalence hiding (trans)
open import Equality.Propositional
open import Prelude hiding (const)
open import Tactic.By
open import List equality-with-J using (map)
open import Chi atoms
open import Constants atoms
open import Reasoning atoms
open import Values atoms
open χ-atoms atoms
-- A compatibility lemma that does not hold.
¬-⇓-[←]-right :
¬ (∀ {e′ v′} e x {v} →
e′ ⇓ v′ → e [ x ← v′ ] ⇓ v → e [ x ← e′ ] ⇓ v)
¬-⇓-[←]-right hyp = ¬e[x←e′]⇓v (hyp e x e′⇓v′ e[x←v′]⇓v)
where
x : Var
x = v-x
e′ v′ e v : Exp
e′ = apply (lambda v-x (var v-x)) (const c-true [])
v′ = const c-true []
e = lambda v-y (var v-x)
v = lambda v-y (const c-true [])
e′⇓v′ : e′ ⇓ v′
e′⇓v′ = apply lambda (const [])
(case v-x V.≟ v-x
return (λ b → if b then const c-true []
else var v-x ⇓ v′) of (λ where
(yes _) → const []
(no x≢x) → ⊥-elim (x≢x refl)))
lemma : ∀ v → e [ x ← v ] ≡ lambda v-y v
lemma _ with v-x V.≟ v-y
... | yes x≡y = ⊥-elim (V.distinct-codes→distinct-names (λ ()) x≡y)
... | no _ with v-x V.≟ v-x
... | yes _ = refl
... | no x≢x = ⊥-elim (x≢x refl)
e[x←v′]⇓v : e [ x ← v′ ] ⇓ v
e[x←v′]⇓v =
e [ x ← v′ ] ≡⟨ lemma _ ⟩⟶
lambda v-y v′ ⇓⟨ lambda ⟩■
v
¬e[x←e′]⇓v : ¬ e [ x ← e′ ] ⇓ v
¬e[x←e′]⇓v p with _[_←_] e x e′ | lemma e′
¬e[x←e′]⇓v () | ._ | refl
mutual
-- Contexts.
data Context : Type where
∙ : Context
apply←_ : Context → {e : Exp} → Context
apply→_ : {e : Exp} → Context → Context
const : {c : Const} → Context⋆ → Context
case : Context → {bs : List Br} → Context
data Context⋆ : Type where
here : Context → {es : List Exp} → Context⋆
there : {e : Exp} → Context⋆ → Context⋆
mutual
-- Filling a context's hole (∙) with an expression.
infix 6 _[_] _[_]⋆
_[_] : Context → Exp → Exp
∙ [ e ] = e
apply←_ c {e = e′} [ e ] = apply (c [ e ]) e′
apply→_ {e = e′} c [ e ] = apply e′ (c [ e ])
const {c = c′} c [ e ] = const c′ (c [ e ]⋆)
case c {bs = bs} [ e ] = case (c [ e ]) bs
_[_]⋆ : Context⋆ → Exp → List Exp
here c {es = es} [ e ]⋆ = (c [ e ]) ∷ es
there {e = e′} c [ e ]⋆ = e′ ∷ (c [ e ]⋆)
mutual
-- If e₁ terminates with v₁ and c [ v₁ ] terminates with v₂, then
-- c [ e₁ ] also terminates with v₂.
[]⇓ :
∀ c {e₁ v₁ v₂} →
e₁ ⇓ v₁ → c [ v₁ ] ⇓ v₂ → c [ e₁ ] ⇓ v₂
[]⇓ ∙ {e₁} {v₁} {v₂} p q =
e₁ ⇓⟨ p ⟩
v₁ ⇓⟨ q ⟩■
v₂
[]⇓ (apply← c) p (apply q r s) = apply ([]⇓ c p q) r s
[]⇓ (apply→ c) p (apply q r s) = apply q ([]⇓ c p r) s
[]⇓ (const c) p (const ps) = const ([]⇓⋆ c p ps)
[]⇓ (case c) p (case q r s t) = case ([]⇓ c p q) r s t
[]⇓⋆ :
∀ c {e v vs} →
e ⇓ v → c [ v ]⋆ ⇓⋆ vs → c [ e ]⋆ ⇓⋆ vs
[]⇓⋆ (here c) p (q ∷ qs) = []⇓ c p q ∷ qs
[]⇓⋆ (there c) p (q ∷ qs) = q ∷ []⇓⋆ c p qs
| 26.680672 | 72 | 0.444724 |
dc9f58ea72af0d970a51988f0af84af77501e11d | 10,751 | agda | Agda | lib/types/Pi.agda | sattlerc/HoTT-Agda | c8fb8da3354fc9e0c430ac14160161759b4c5b37 | [
"MIT"
] | null | null | null | lib/types/Pi.agda | sattlerc/HoTT-Agda | c8fb8da3354fc9e0c430ac14160161759b4c5b37 | [
"MIT"
] | null | null | null | lib/types/Pi.agda | sattlerc/HoTT-Agda | c8fb8da3354fc9e0c430ac14160161759b4c5b37 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Paths
module lib.types.Pi where
Π-level : ∀ {i j} {A : Type i} {B : A → Type j} {n : ℕ₋₂}
→ (((x : A) → has-level n (B x)) → has-level n (Π A B))
Π-level {n = ⟨-2⟩} p =
((λ x → fst (p x)) , (λ f → λ= (λ x → snd (p x) (f x))))
Π-level {n = S n} p = λ f g →
equiv-preserves-level λ=-equiv
(Π-level (λ x → p x (f x) (g x)))
module _ {i j} {A : Type i} {B : A → Type j} where
abstract
Π-is-prop : ((x : A) → is-prop (B x)) → is-prop (Π A B)
Π-is-prop = Π-level
Π-is-set : ((x : A) → is-set (B x)) → is-set (Π A B)
Π-is-set = Π-level
module _ {i j} {A : Type i} {B : Type j} where
abstract
→-level : {n : ℕ₋₂} → (has-level n B → has-level n (A → B))
→-level p = Π-level (λ _ → p)
→-is-set : is-set B → is-set (A → B)
→-is-set = →-level
→-is-prop : is-prop B → is-prop (A → B)
→-is-prop = →-level
{- Equivalences in a Π-type -}
equiv-Π-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) {h : A → B}
→ is-equiv h → Π A (P ∘ h) ≃ Π B P
equiv-Π-l {A = A} {B = B} P {h = h} e = equiv f g f-g g-f where
w : A ≃ B
w = (h , e)
f : Π A (P ∘ h) → Π B P
f u b = transport P (<–-inv-r w b) (u (<– w b))
g : Π B P → Π A (P ∘ h)
g v a = v (–> w a)
f-g : ∀ v → f (g v) == v
f-g v = λ= λ b → to-transp (apd v (<–-inv-r w b))
g-f : ∀ u → g (f u) == u
g-f u = λ= λ a → to-transp $ transport (λ p → u _ == _ [ P ↓ p ])
(is-equiv.adj e a)
(↓-ap-in P (–> w)
(apd u $ <–-inv-l w a))
equiv-Π-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
→ (∀ x → B x ≃ C x) → Π A B ≃ Π A C
equiv-Π-r {A = A} {B = B} {C = C} k = equiv f g f-g g-f
where f : Π A B → Π A C
f c x = –> (k x) (c x)
g : Π A C → Π A B
g d x = <– (k x) (d x)
f-g : ∀ d → f (g d) == d
f-g d = λ= (λ x → <–-inv-r (k x) (d x))
g-f : ∀ c → g (f c) == c
g-f c = λ= (λ x → <–-inv-l (k x) (c x))
module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁}
{B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where
equiv-Π : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Π A₀ B₀ ≃ Π A₁ B₁
equiv-Π u v = Π A₀ B₀ ≃⟨ equiv-Π-l _ (snd (u ⁻¹)) ⁻¹ ⟩
Π A₁ (B₀ ∘ <– u) ≃⟨ equiv-Π-r v ⟩
Π A₁ B₁ ≃∎
equiv-Π' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Π A₀ B₀ ≃ Π A₁ B₁
equiv-Π' u v = Π A₀ B₀ ≃⟨ equiv-Π-r v ⟩
Π A₀ (B₁ ∘ –> u) ≃⟨ equiv-Π-l _ (snd u) ⟩
Π A₁ B₁ ≃∎
{- Dependent paths in a Π-type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
where
↓-Π-in : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
→ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
↓-Π-in {p = idp} f = λ= (λ x → f (idp {a = x}))
↓-Π-out : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
↓-Π-out {p = idp} q idp = app= q _
↓-Π-β : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (f : {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
→ {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ ↓-Π-out (↓-Π-in f) q == f q
↓-Π-β {p = idp} f idp = app=-β (λ x → f (idp {a = x})) _
{- Dependent paths in a Π-type where the codomain is not dependent on anything
Right now, this is defined in terms of the previous one. Maybe it’s a good idea,
maybe not.
-}
module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x x' : A}
{p : x == x'} {u : B x → C} {u' : B x' → C} where
↓-app→cst-in :
({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t')
→ (u == u' [ (λ x → B x → C) ↓ p ])
↓-app→cst-in f = ↓-Π-in (λ q → ↓-cst-in (f q))
↓-app→cst-out :
(u == u' [ (λ x → B x → C) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t')
↓-app→cst-out r q = ↓-cst-out (↓-Π-out r q)
↓-app→cst-β :
(f : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t'))
→ {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ ↓-app→cst-out (↓-app→cst-in f) q == f q
↓-app→cst-β f q =
↓-app→cst-out (↓-app→cst-in f) q
=⟨ idp ⟩
↓-cst-out (↓-Π-out (↓-Π-in (λ qq → ↓-cst-in (f qq))) q)
=⟨ ↓-Π-β (λ qq → ↓-cst-in (f qq)) q |in-ctx
↓-cst-out ⟩
↓-cst-out (↓-cst-in {p = pair= p q} (f q))
=⟨ ↓-cst-β (pair= p q) (f q) ⟩
f q ∎
{- Dependent paths in an arrow type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
{x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} where
↓-→-in :
({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ C ↓ p ])
→ (u == u' [ (λ x → B x → C x) ↓ p ])
↓-→-in f = ↓-Π-in (λ q → ↓-cst2-in p q (f q))
↓-→-out :
(u == u' [ (λ x → B x → C x) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ C ↓ p ])
↓-→-out r q = ↓-cst2-out p q (↓-Π-out r q)
-- Dependent paths in a Π-type where the domain is constant
module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where
↓-cst→app-in : {x x' : A} {p : x == x'}
{u : (b : B) → C x b} {u' : (b : B) → C x' b}
→ ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ])
→ (u == u' [ (λ x → (b : B) → C x b) ↓ p ])
↓-cst→app-in {p = idp} f = λ= f
↓-cst→app-out : {x x' : A} {p : x == x'}
{u : (b : B) → C x b} {u' : (b : B) → C x' b}
→ (u == u' [ (λ x → (b : B) → C x b) ↓ p ])
→ ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ])
↓-cst→app-out {p = idp} q = app= q
split-ap2 : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} (f : Σ A B → C)
{x y : A} (p : x == y)
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ ap f (pair= p q) == ↓-app→cst-out (apd (curry f) p) q
split-ap2 f idp idp = idp
{-
Interaction of [apd] with function composition.
The basic idea is that [apd (g ∘ f) p == apd g (apd f p)] but the version here
is well-typed. Note that we assume a propositional equality [r] between
[apd f p] and [q].
-}
apd-∘ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
(g : {a : A} → Π (B a) (C a)) (f : Π A B) {x y : A} (p : x == y)
{q : f x == f y [ B ↓ p ]} (r : apd f p == q)
→ apd (g ∘ f) p == ↓-apd-out C r (apd↓ g q)
apd-∘ g f idp idp = idp
{- When [g] is nondependent, it’s much simpler -}
apd-∘' : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y)
→ apd (g ∘ f) p == ap↓ g (apd f p)
apd-∘' g f idp = idp
∘'-apd : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y)
→ ap↓ g (apd f p) == apd (g ∘ f) p
∘'-apd g f idp = idp
{- 2-dimensional coherence conditions -}
-- postulate
-- lhs :
-- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B}
-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
-- (k : (u ◃ apd g p) == (apd f p ▹ v))
-- (h : {a : A} → B a → C a)
-- → ap h u ◃ apd (h ∘ g) p == ap↓ h (u ◃ apd g p)
-- rhs :
-- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B}
-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
-- (k : (u ◃ apd g p) == (apd f p ▹ v))
-- (h : {a : A} → B a → C a)
-- → ap↓ h (apd f p ▹ v) == apd (h ∘ f) p ▹ ap h v
-- ap↓-↓-=-in :
-- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B}
-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
-- (k : (u ◃ apd g p) == (apd f p ▹ v))
-- (h : {a : A} → B a → C a)
-- → ap↓ (λ {a} → ap (h {a = a})) (↓-=-in {p = p} {u = u} {v = v} k)
-- == ↓-=-in (lhs {f = f} {g = g} k h ∙ ap (ap↓ (λ {a} → h {a = a})) k
-- ∙ rhs {f = f} {g = g} k h)
{-
Commutation of [ap↓ (ap h)] and [↓-swap!]. This is "just" J, but it’s not as
easy as it seems.
-}
module Ap↓-swap! {i j k ℓ} {A : Type i} {B : Type j} {C : Type k}
{D : Type ℓ} (h : C → D) (f : A → C) (g : B → C)
{a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
(r : f a == g b') (s : f a' == g b)
(t : r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
where
lhs : ap h (ap f p ∙' s) == ap (h ∘ f) p ∙' ap h s
lhs = ap-∙' h (ap f p) s ∙ (ap (λ u → u ∙' ap h s) (∘-ap h f p))
rhs : ap h (s ∙ ap g q) == ap h s ∙ ap (h ∘ g) q
rhs = ap-∙ h s (ap g q) ∙ (ap (λ u → ap h s ∙ u) (∘-ap h g q))
β : ap↓ (ap h) (↓-swap! f g r s t) ==
lhs ◃ ↓-swap! (h ∘ f) (h ∘ g) (ap h r) (ap h s) (ap↓ (ap h) t ▹ rhs)
β with a | a' | p | b | b' | q | r | s | t
β | a | .a | idp | b | .b | idp | r | s | t = coh r s t where
T : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → Type _
T r s t =
ap (ap h) (∙'-unit-l s ∙ ! (∙-unit-r s) ∙ ! t) ==
(ap-∙' h idp s ∙ idp)
∙
(∙'-unit-l (ap h s) ∙
! (∙-unit-r (ap h s)) ∙
!
(ap (ap h) t ∙'
(ap-∙ h s idp ∙ idp)))
coh' : {x x' : C} {r s : x == x'} (t : r == s) → T r s (t ∙ ! (∙-unit-r s))
coh' {r = idp} {s = .idp} idp = idp
coh : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → T r s t
coh r s t = transport (λ t → T r s t) (coh2 t (∙-unit-r s)) (coh' (t ∙ ∙-unit-r s)) where
coh2 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → (p ∙ q) ∙ ! q == p
coh2 idp idp = idp
-- module _ {i j k} {A : Type i} {B B' : Type j} {C : Type k} (f : A → C) (g' : B' → B) (g : B → C) where
-- abc : {a a' : A} {p : a == a'} {c c' : B'} {q' : c == c'} {q : g' c == g' c'}
-- (r : f a == g (g' c')) (s : f a' == g (g' c))
-- (t : q == ap g' q')
-- (α : r == s ∙ ap g q [ (λ x → f x == g (g' c')) ↓ p ])
-- → {!(↓-swap! f g r s α ▹ ?) ∙'2ᵈ ?!} == ↓-swap! f (g ∘ g') {p = p} {q = q'} r s (α ▹ ap (λ u → s ∙ u) (ap (ap g) t ∙ ∘-ap g g' q'))
-- abc = {!!}
{- Functoriality of application and function extensionality -}
∙-app= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B}
(α : f == g) (β : g == h)
→ α ∙ β == λ= (λ x → app= α x ∙ app= β x)
∙-app= idp β = λ=-η β
∙-λ= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B}
(α : (x : A) → f x == g x) (β : (x : A) → g x == h x)
→ λ= α ∙ λ= β == λ= (λ x → α x ∙ β x)
∙-λ= α β = ∙-app= (λ= α) (λ= β)
∙ ap λ= (λ= (λ x → ap (λ w → w ∙ app= (λ= β) x) (app=-β α x)
∙ ap (λ w → α x ∙ w) (app=-β β x)))
| 36.320946 | 139 | 0.365733 |
c532222d2970f871d277845ba5ed5cf2a8f67890 | 5,222 | agda | Agda | SOAS/ContextMaps/CategoryOfRenamings.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 39 | 2021-11-09T20:39:55.000Z | 2022-03-19T17:33:12.000Z | SOAS/ContextMaps/CategoryOfRenamings.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 1 | 2021-11-21T12:19:32.000Z | 2021-11-21T12:19:32.000Z | SOAS/ContextMaps/CategoryOfRenamings.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 4 | 2021-11-09T20:39:59.000Z | 2022-01-24T12:49:17.000Z |
-- The category of contexts and renamings
module SOAS.ContextMaps.CategoryOfRenamings {T : Set} where
open import SOAS.Common
open import SOAS.Context {T}
open import SOAS.Variable
open import SOAS.ContextMaps.Combinators (ℐ {T})
open import Categories.Functor.Bifunctor
open import Categories.Object.Initial
open import Categories.Object.Coproduct
open import Categories.Category.Cocartesian
import Categories.Morphism
-- The category of contexts and renamings, defined as the Lawvere theory
-- associated with the clone of variables. In elementary terms it has
-- contexts Γ, Δ as objects, and renamings Γ ↝ Δ ≜ Γ ~[ ℐ → ℐ ]↝ Δ as arrows.
𝔽 : Category 0ℓ 0ℓ 0ℓ
𝔽 = categoryHelper (record
{ Obj = Ctx
; _⇒_ = _↝_
; _≈_ = λ {Γ} ρ₁ ρ₂ → ∀{α : T}{v : ℐ α Γ} → ρ₁ v ≡ ρ₂ v
; id = λ x → x
; _∘_ = λ ϱ ρ v → ϱ (ρ v)
; assoc = refl
; identityˡ = refl
; identityʳ = refl
; equiv = record { refl = refl ; sym = λ p → sym p ; trans = λ p q → trans p q }
; ∘-resp-≈ = λ{ {f = ρ₁} p₁ p₂ → trans (cong ρ₁ p₂) p₁ }
})
module 𝔽 = Category 𝔽 using (op) renaming ( _∘_ to _∘ᵣ_
; _≈_ to _≈ᵣ_
; id to idᵣ
; ∘-resp-≈ to ∘-resp-≈ᵣ )
open 𝔽 public
id′ᵣ : (Γ : Ctx) → Γ ↝ Γ
id′ᵣ Γ = idᵣ {Γ}
-- Category of context is co-Cartesian, given by the empty initial context and
-- context concatenation as the monoidal product.
𝔽:Cocartesian : Cocartesian 𝔽
𝔽:Cocartesian = record
{ initial = record
{ ⊥ = ∅
; ⊥-is-initial = record { ! = λ{()} ; !-unique = λ{ f {_} {()}} }
}
; coproducts = record { coproduct = λ {Γ}{Δ} → record
{ A+B = Γ ∔ Δ
; i₁ = expandʳ Δ
; i₂ = expandˡ Γ
; [_,_] = copair
; inject₁ = λ{ {Θ}{ρ}{ϱ} → i₁-commute ρ ϱ _ }
; inject₂ = λ{ {Θ}{ρ}{ϱ} → i₂-commute ρ ϱ _ }
; unique = λ{ p₁ p₂ → unique {Γ}{Δ} _ _ _ p₁ p₂ _ }
} }
}
where
in₁ : (Γ Δ : Ctx) → Γ ↝ Γ ∔ Δ
in₁ (α ∙ Γ) Δ new = new
in₁ (α ∙ Γ) Δ (old v) = old (in₁ Γ Δ v)
in₂ : (Γ Δ : Ctx) → Δ ↝ Γ ∔ Δ
in₂ ∅ Δ v = v
in₂ (α ∙ Γ) Δ v = old (in₂ Γ Δ v)
i₁-commute : {Γ Δ Θ : Ctx}{α : T}(ρ : Γ ↝ Θ)(ϱ : Δ ↝ Θ)(v : ℐ α Γ)
→ copair ρ ϱ (expandʳ Δ v) ≡ ρ v
i₁-commute ρ ϱ new = refl
i₁-commute ρ ϱ (old v) = i₁-commute (ρ ∘ old) ϱ v
i₂-commute : {Γ Δ Θ : Ctx}{α : T}(ρ : Γ ↝ Θ)(ϱ : Δ ↝ Θ)(v : ℐ α Δ)
→ copair ρ ϱ (expandˡ Γ v) ≡ ϱ v
i₂-commute {∅} ρ ϱ v = refl
i₂-commute {α ∙ Γ} ρ ϱ v = i₂-commute (ρ ∘ old) ϱ v
unique : {Γ Δ Θ : Ctx}{α : T}(ρ : Γ ↝ Θ)(ϱ : Δ ↝ Θ)(π : Γ ∔ Δ ↝ Θ)
→ (π ∘ᵣ expandʳ Δ ≈ᵣ ρ)
→ (π ∘ᵣ expandˡ Γ ≈ᵣ ϱ)
→ (v : ℐ α (Γ ∔ Δ)) → copair ρ ϱ v ≡ π v
unique {∅} ρ ϱ π p₁ p₂ v = sym p₂
unique {α ∙ Γ} ρ ϱ π p₁ p₂ new = sym p₁
unique {α ∙ Γ} ρ ϱ π p₁ p₂ (old v) = unique (ρ ∘ old) ϱ (π ∘ old) p₁ p₂ v
module 𝔽:Co = Cocartesian 𝔽:Cocartesian
module ∔ = BinaryCoproducts (Cocartesian.coproducts 𝔽:Cocartesian)
-- | Special operations coming from the coproduct structure
-- Concatenation is a bifunctor
∔:Bifunctor : Bifunctor 𝔽 𝔽 𝔽
∔:Bifunctor = 𝔽:Co.-+-
-- Left context concatenation functor Γ ∔ (-) : 𝔽 ⟶ 𝔽, for any context Γ
_∔F– : Ctx → Functor 𝔽 𝔽
Γ ∔F– = Γ ∔.+-
-- Right context concatenation functor (-) ∔ Δ : 𝔽 ⟶ 𝔽, for any context Δ
–∔F_ : Ctx → Functor 𝔽 𝔽
–∔F Δ = ∔.-+ Δ
-- Functorial mapping and injections
_∣∔∣_ : {Γ₁ Γ₂ Δ₁ Δ₂ : Ctx}(ρ : Γ₁ ↝ Γ₂)(ϱ : Δ₁ ↝ Δ₂) → (Γ₁ ∔ Δ₁) ↝ (Γ₂ ∔ Δ₂)
_∣∔∣_ = ∔._+₁_
_∣∔_ : {Γ₁ Γ₂ : Ctx}(ρ : Γ₁ ↝ Γ₂)(Δ : Ctx) → (Γ₁ ∔ Δ) ↝ (Γ₂ ∔ Δ)
ρ ∣∔ Δ = ρ ∣∔∣ id′ᵣ Δ
_∔∣_ : {Δ₁ Δ₂ : Ctx}(Γ : Ctx)(ϱ : Δ₁ ↝ Δ₂) → (Γ ∔ Δ₁) ↝ (Γ ∔ Δ₂)
Γ ∔∣ ϱ = id′ᵣ Γ ∣∔∣ ϱ
inl : (Γ {Δ} : Ctx) → Γ ↝ Γ ∔ Δ
inl Γ {Δ} v = ∔.i₁ {Γ}{Δ} v
inr : (Γ {Δ} : Ctx) → Δ ↝ Γ ∔ Δ
inr Γ {Δ} v = ∔.i₂ {Γ}{Δ} v
-- Left context concatenation represents weakening a variable in Γ by an
-- arbitrary new context Θ to get a variable in context (Θ ∔ Γ).
module Concatˡ Γ = Functor (Γ ∔F–)
using () renaming ( F₁ to _∔ᵣ_
; identity to ∔identity
; homomorphism to ∔homomorphism
; F-resp-≈ to ∔F-resp-≈)
open Concatˡ public
-- Context extension represents weakening by a single type, and it's a special
-- case of context concatenation with a singleton context.
module Ext τ = Functor (⌊ τ ⌋ ∔F–)
using () renaming ( F₁ to _∙ᵣ_
; identity to ∙identity
; homomorphism to ∙homomorphism
; F-resp-≈ to ∙F-resp-≈)
open Ext public
-- The two coincide (since add is a special case of copair)
-- but not definitionally: ∙ᵣ is the parallel sum of id : ⌊ τ ⌋ ↝ ⌊ τ ⌋ and ρ : Γ ↝ Δ
-- (i.e. the copairing of expandʳ ⌊ τ ⌋ Δ : ⌊ τ ⌋ ↝ τ ∙ Δ and old ∘ ρ : Γ ↝ τ ∙ Δ)
-- while liftᵣ is the copairing of new : ⌊ τ ⌋ ↝ τ ∙ Δ and old ∘ ρ : Γ ↝ τ ∙ Δ
∙ᵣ-as-add : {α τ : T}{Γ Δ : Ctx} → (ρ : Γ ↝ Δ)(v : ℐ α (τ ∙ Γ))
→ add new (old ∘ ρ) v ≡ (τ ∙ᵣ ρ) v
∙ᵣ-as-add ρ new = refl
∙ᵣ-as-add ρ (old v) = refl
-- Making this a definitional equality simplifies things significantly
-- Right context concatenation is possible but rarely needed.
module Concatʳ Δ = Functor (–∔F Δ )
| 33.474359 | 85 | 0.540214 |
20182b23e108ba26098d869de55181c5232f1713 | 14,346 | agda | Agda | docs/fomega/mutual-term-level-recursion/FixN.agda | NinjaTrappeur/plutus | 23fd661817f2ab2f14c10e97b90166bf26d7fd4f | [
"MIT"
] | null | null | null | docs/fomega/mutual-term-level-recursion/FixN.agda | NinjaTrappeur/plutus | 23fd661817f2ab2f14c10e97b90166bf26d7fd4f | [
"MIT"
] | null | null | null | docs/fomega/mutual-term-level-recursion/FixN.agda | NinjaTrappeur/plutus | 23fd661817f2ab2f14c10e97b90166bf26d7fd4f | [
"MIT"
] | null | null | null | {-# OPTIONS --type-in-type #-}
{-# OPTIONS --no-termination-check #-}
-- In this post we'll consider how to define and generalize fixed-point combinators for families of
-- mutually recursive functions. Both in the lazy and strict settings.
module FixN where
open import Function
open import Relation.Binary.PropositionalEquality
open import Data.Nat.Base
open import Data.Bool.Base
-- This module is parameterized by `even` and `odd` functions and defines the `Test` type
-- which is used below for testing particular `even` and `odd`.
module Test (even : ℕ -> Bool) (odd : ℕ -> Bool) where
open import Data.List.Base
open import Data.Product using (_,′_)
Test : Set
Test =
( map even (0 ∷ 1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ [])
,′ map odd (0 ∷ 1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ [])
)
≡ ( true ∷ false ∷ true ∷ false ∷ true ∷ false ∷ []
,′ false ∷ true ∷ false ∷ true ∷ false ∷ true ∷ []
)
-- Brings `Test : (ℕ -> Bool) -> (ℕ -> Bool) -> Set` in scope.
open Test
module Classic where
open import Data.Product
-- We can use the most straightforward fixed-point operator in order to get mutual recursion.
{-# TERMINATING #-}
fix : {A : Set} -> (A -> A) -> A
fix f = f (fix f)
-- We instantiate `fix` to be defined over a pair of functions. I.e. a generic fixed-point
-- combinator for a family of two mutually recursive functions has this type signature:
-- `∀ {A B} -> (A × B -> A × B) -> A × B` which is an instance of `∀ {A} -> (A -> A) -> A`.
-- Here is the even-and-odd example.
-- `even` is denoted as the first element of the resulting tuple, `odd` is the second.
evenAndOdd : (ℕ -> Bool) × (ℕ -> Bool)
evenAndOdd = fix $ λ p ->
-- `even` returns `true` on `0` and calls `odd` on `suc`
(λ { 0 -> true ; (suc n) -> proj₂ p n })
-- `odd` returns `false` on `0` and calls `even` on `suc`
, (λ { 0 -> false ; (suc n) -> proj₁ p n })
even : ℕ -> Bool
even = proj₁ evenAndOdd
odd : ℕ -> Bool
odd = proj₂ evenAndOdd
test : Test even odd
test = refl
-- And that's all.
-- This Approach
-- 1. relies on laziness
-- 2. relies on tuples
-- 3. allows to encode a family of arbitrary number of mutually recursive functions
-- of possibly distinct types
-- There is one pitfall, though, if we write this in Haskell:
-- evenAndOdd :: ((Int -> Bool), (Int -> Bool))
-- evenAndOdd = fix $ \(even, odd) ->
-- ( (\n -> n == 0 || odd (n - 1))
-- , (\n -> n /= 0 && even (n - 1))
-- )
-- we'll get an infinite loop, because matching over tuples is strict in Haskell (in Agda it's lazy)
-- which means that in order to return a tuple, you must first compute it to whnf, which is a loop.
-- This is what the author of [1] stumpled upon. The fix is simple, though: just use lazy matching
-- (aka irrefutable pattern) like this:
-- evenAndOdd = fix $ \(~(even, odd)) -> ...
-- In general, that's a good approach for a lazy language, but Plutus Core is a strict one (so far),
-- so we need something else. Besides, we can do some pretty cool generalizations, so let's do them.
module PartlyUncurried2 where
open import Data.Product
-- It is clear that we can transform
-- ∀ {A B} -> (A × B -> A × B) -> A × B
-- into
-- ∀ {A B R} -> (A × B -> A × B) -> (A -> B -> R) -> R
-- by Church-encoding `A × B` into `∀ {R} -> (A -> B -> R) -> R`.
-- However in our case we can also transform
-- A × B -> A × B
-- into
-- ∀ {Q} -> (A -> B -> Q) -> A -> B -> Q
-- Ignoring the former transformation right now, but performing the latter we get the following:
fix2 : ∀ {A B} -> (∀ {Q} -> (A -> B -> Q) -> A -> B -> Q) -> A × B
fix2 f = f (λ x y -> x) (proj₁ (fix2 f)) (proj₂ (fix2 f))
, f (λ x y -> y) (proj₁ (fix2 f)) (proj₂ (fix2 f))
-- `f` is what was of the `A × B -> A × B` type previously, but now instead of receiving a tuple
-- and defining a tuple, `f` receives a selector and two values of types `A` and `B`. The values
-- represent the functions being defined, while the selector is needed in order to select one of
-- these functions.
-- Consider the example:
evenAndOdd : (ℕ -> Bool) × (ℕ -> Bool)
evenAndOdd = fix2 $ λ select even odd -> select
(λ { 0 -> true ; (suc n) -> odd n })
(λ { 0 -> false ; (suc n) -> even n })
-- `select` is only instantiated to either `λ x y -> x` or `λ x y -> y` which allow us
-- to select the branch we want to go in. When defining the `even` function, we want to go in
-- the first branch and thus instantiate `select` with `λ x y -> x`. When defining `odd`,
-- we want the second branch and thus instantiate `select` with `λ x y -> y`.
-- All these instantiations happen in the `fix2` function itself.
-- It is instructive to inline `fix2` and `select` along with the particular selectors. We get:
evenAndOdd-inlined : (ℕ -> Bool) × (ℕ -> Bool)
evenAndOdd-inlined = defineEven (proj₁ evenAndOdd-inlined) (proj₂ evenAndOdd-inlined)
, defineOdd (proj₁ evenAndOdd-inlined) (proj₂ evenAndOdd-inlined)
where
defineEven : (ℕ -> Bool) -> (ℕ -> Bool) -> ℕ -> Bool
defineEven even odd = λ { 0 -> true ; (suc n) -> odd n }
defineOdd : (ℕ -> Bool) -> (ℕ -> Bool) -> ℕ -> Bool
defineOdd even odd = λ { 0 -> false ; (suc n) -> even n }
-- I.e. each definition is parameterized by both functions and this is just the same fixed point
-- of a tuple of functions that we've seen before.
test : Test (proj₁ evenAndOdd) (proj₂ evenAndOdd)
test = refl
test-inlined : Test (proj₁ evenAndOdd-inlined) (proj₂ evenAndOdd-inlined)
test-inlined = refl
module Uncurried where
-- We can now do another twist and turn `A × B` into `∀ {R} -> (A -> B -> R) -> R` which finally
-- allows us to get rid of tuples:
fix2 : {A B R : Set} -> (∀ {Q} -> (A -> B -> Q) -> A -> B -> Q) -> (A -> B -> R) -> R
fix2 f k = k (fix2 f (f λ x y -> x)) (fix2 f (f λ x y -> y))
-- `k` is the continuation that represents a Church-encoded tuple returned as the result.
-- But... if `k` is just another way to construct a tuple, how are we not keeping `f` outside of
-- recursion? Previously it was `fix f = f (fix f)` or
-- fix2 f = f (λ x y -> x) (proj₁ (fix2 f)) (proj₂ (fix2 f))
-- , f (λ x y -> y) (proj₁ (fix2 f)) (proj₂ (fix2 f))
-- i.e. `f` is always an outermost call and recursive calls are somewhere inside. But in the
-- definition above `f` is inside the recursive call. How is that? Watch the hands:
-- fix2 f k [1]
-- = k (fix2 f (f λ x y -> x)) (fix2 f (f λ x y -> y)) [2]
-- ~ k (fix2 f (f (λ x y -> x))) (fix2 f (f (λ x y -> y))) [3]
-- ~ k (f (λ x y -> x) (fix2 f (f λ x y -> x)) (fix2 f (f λ x y -> y)))
-- (f (λ x y -> y) (fix2 f (f λ x y -> y)) (fix2 f (f λ x y -> y)))
-- [1] unfold the definition of `fix2`
-- [2] add parens around selectors for clarity
-- [3] unfold the definition of `fix` in both the arguments of `k`
-- The result is very similar to the one from the previous section
-- (quoted in the snippet several lines above).
-- And the test:
evenAndOdd : ∀ {R} -> ((ℕ -> Bool) -> (ℕ -> Bool) -> R) -> R
evenAndOdd = fix2 $ λ select even odd -> select
(λ { 0 -> true ; (suc n) -> odd n })
(λ { 0 -> false ; (suc n) -> even n })
test : Test (evenAndOdd λ x y -> x) (evenAndOdd λ x y -> y)
test = refl
-- It is straighforward to define a fixed-point combinator for a family of three mutually
-- recursive functions:
fix3 : {A B C R : Set} -> (∀ {Q} -> (A -> B -> C -> Q) -> A -> B -> C -> Q) -> (A -> B -> C -> R) -> R
fix3 f k = k (fix3 f (f λ x y z -> x)) (fix3 f (f λ x y z -> y)) (fix3 f (f λ x y z -> z))
-- The pattern is clear and we can abstract it.
module UncurriedGeneral where
-- The type signatures of the fixed point combinators from the above
-- ∀ {A B} -> (∀ {Q} -> (A -> B -> Q) -> A -> B -> Q) -> ∀ {R} -> (A -> B -> R) -> R
-- ∀ {A B C} -> (∀ {Q} -> (A -> B -> C -> Q) -> A -> B -> C -> Q) -> ∀ {R} -> (A -> B -> C -> R) -> R
-- (`∀ {R}` is moved slightly righter than what it was previously, because it helps readability below)
-- can be generalized to
-- ∀ {F} -> (∀ {Q} -> F Q -> F Q) -> ∀ {R} -> F R -> R
-- with `F` being `λ X -> A -> B -> X` in the first case and `λ X -> A -> B -> C -> X` in the second.
-- That's fact (1).
-- Now let's look at the definitions. There we see
-- fix2 f k = k (fix2 f (f λ x y -> x)) (fix2 f (f λ x y -> y))
-- fix3 f k = k (fix3 f (f λ x y z -> x)) (fix3 f (f λ x y z -> y)) (fix3 f (f λ x y z -> z))
-- i.e. each recursive call is parameterized by the `f` that never changes, but also by
-- the `f` applied to a selector and selectors do change. Thus the
-- λ selector -> fix2 f (f selector)
-- λ selector -> fix3 f (f selector)
-- parts can be abstracted into something like
-- λ selector -> fixSome f (f selector)
-- where `fixSome` can be both `fix2` and `fix3` depending on what you instantiate it with.
-- Then we only need combinators that duplicate the recursive case an appropriate number of times
-- (2 for `fix2` and 3 for `fix3`) and supply a selector to each of the duplicates. That's fact (2).
-- And those combinators have to be of the same type, so we can pass them to the generic
-- fixed-point combinator we're deriving.
-- To infer the type of those combinators we start by looking at the types of
-- λ selector -> fix2 f (f selector)
-- λ selector -> fix3 f (f selector)
-- which are
-- ∀ {Q} -> (A -> B -> Q) -> Q
-- ∀ {Q} -> (A -> B -> C -> Q) -> Q
-- correspondingly. I.e. the unifying type of
-- λ selector -> fixSome f (f selector)
-- is `∀ {Q} -> F Q -> Q`.
-- Therefore, the combinators receive something of type `∀ {Q} -> F Q -> Q` and return something of
-- type `∀ {R} -> F R -> R` (the same type, just alpha-converted for convenience), because that's
-- what `fix2` and `fix3` and thus the generic fixed-point combinator return.
-- I.e. the whole unifying type of those combinators is
-- (∀ {R} -> (∀ {Q} -> F Q -> Q) -> F R -> R)
-- That's fact (3).
-- Assembling everything together, we arrive at
fixBy : {F : Set -> Set}
-> ((∀ {Q} -> F Q -> Q) -> ∀ {R} -> F R -> R) -- by fact (3)
-> (∀ {Q} -> F Q -> F Q) -> ∀ {R} -> F R -> R -- by fact (1)
fixBy by f = by (fixBy by f ∘ f) -- by fact (2)
-- Let's now implement particular `by`s:
by2 : {A B : Set} -> (∀ {Q} -> (A -> B -> Q) -> Q) -> {R : Set} -> (A -> B -> R) -> R
by2 r k = k (r λ x y -> x) (r λ x y -> y)
by3 : {A B C : Set} -> (∀ {Q} -> (A -> B -> C -> Q) -> Q) -> {R : Set} -> (A -> B -> C -> R) -> R
by3 r k = k (r λ x y z -> x) (r λ x y z -> y) (r λ x y z -> z)
-- and fixed-points combinators from the previous section in terms of what we derived in this one:
fix2 : ∀ {A B} -> (∀ {Q} -> (A -> B -> Q) -> A -> B -> Q) -> ∀ {R} -> (A -> B -> R) -> R
fix2 = fixBy by2
fix3 : ∀ {A B C} -> (∀ {Q} -> (A -> B -> C -> Q) -> A -> B -> C -> Q) -> ∀ {R} -> (A -> B -> C -> R) -> R
fix3 = fixBy by3
-- That's it. One `fixBy` to rule them all. The final test:
evenAndOdd : ∀ {R} -> ((ℕ -> Bool) -> (ℕ -> Bool) -> R) -> R
evenAndOdd = fix2 $ λ select even odd -> select
(λ { 0 -> true ; (suc n) -> odd n })
(λ { 0 -> false ; (suc n) -> even n })
test : Test (evenAndOdd λ x y -> x) (evenAndOdd λ x y -> y)
test = refl
module LazinessStrictness where
open UncurriedGeneral using (fixBy)
-- So what about strictness? `fixBy` is generic enough to allow both lazy and strict derivatives.
-- The version of strict `fix2` looks like this in Haskell:
-- apply :: (a -> b) -> a -> b
-- apply = ($!)
-- fix2
-- :: ((a1 -> b1) -> (a2 -> b2) -> a1 -> b1)
-- -> ((a1 -> b1) -> (a2 -> b2) -> a2 -> b2)
-- -> ((a1 -> b1) -> (a2 -> b2) -> r) -> r
-- fix2 f g k = k
-- (\x1 -> f `apply` fix2 f g (\x y -> x) `apply` fix2 f g (\x y -> y) `apply` x1)
-- (\x2 -> g `apply` fix2 f g (\x y -> x) `apply` fix2 f g (\x y -> y) `apply` x2)
-- This is just like the Z combinator is of type `((a -> b) -> a -> b) -> a -> b`, so that it can
-- be used to get fixed points of functions in a strict language where the Y combinator loops forever.
-- The version of `fix2` that works in a strict language can be defined as follows:
by2' : {A₁ B₁ A₂ B₂ : Set}
-> (∀ {Q} -> ((A₁ -> B₁) -> (A₂ -> B₂) -> Q) -> Q)
-> {R : Set} -> ((A₁ -> B₁) -> (A₂ -> B₂) -> R) -> R
by2' r k = k (λ x₁ -> r λ f₁ f₂ -> f₁ x₁) (λ x₂ -> r λ f₁ f₂ -> f₂ x₂)
fix2' : {A₁ B₁ A₂ B₂ : Set}
-> (∀ {Q} -> ((A₁ -> B₁) -> (A₂ -> B₂) -> Q) -> (A₁ -> B₁) -> (A₂ -> B₂) -> Q)
-> {R : Set} -> ((A₁ -> B₁) -> (A₂ -> B₂) -> R) -> R
fix2' = fixBy by2'
-- The difference is that in
by2 : {A B : Set} -> (∀ {Q} -> (A -> B -> Q) -> Q) -> {R : Set} -> (A -> B -> R) -> R
by2 r k = k (r λ x y -> x) (r λ x y -> y)
-- both calls to `r` are forced before `k` returns, while in `by2'` additional lambdas that bind
-- `x₁` and `x₂` block the recursive calls from being forced, so `k` at some point can decide not to
-- recurse anymore (i.e. not to force recursive calls) and return a result instead.
module ComputeUncurriedGeneral where
-- You might wonder whether we can define a single `fixN` which receives a natural number and
-- computes the appropriate fixed-point combinator of mutually recursive functions. E.g.
-- fixN 2 ~> fix2
-- fixN 3 ~> fix3
-- So that we do not even need to specify `by2` and `by3` by ourselves. Yes we can do that, see [2]
-- (the naming is slightly different there).
-- Moreover, we can assign a type to `fixN` in pure System Fω, see [3].
module References where
-- [1] "Mutual Recursion in Final Encoding", Andreas Herrmann
-- https://aherrmann.github.io/programming/2016/05/28/mutual-recursion-in-final-encoding/
-- [2] https://gist.github.com/effectfully/b3185437da14322c775f4a7691b6fe1f#file-mutualfixgenericcompute-agda
-- [3] https://gist.github.com/effectfully/b3185437da14322c775f4a7691b6fe1f#file-mutualfixgenericcomputenondep-agda
| 40.411268 | 117 | 0.55918 |
c595b2b8a2a89196e67ed2a761fba4904b804cb6 | 3,623 | agda | Agda | Categories/Bicategory/Helpers.agda | copumpkin/categories | 36f4181d751e2ecb54db219911d8c69afe8ba892 | [
"BSD-3-Clause"
] | 98 | 2015-04-15T14:57:33.000Z | 2022-03-08T05:20:36.000Z | Categories/Bicategory/Helpers.agda | copumpkin/categories | 36f4181d751e2ecb54db219911d8c69afe8ba892 | [
"BSD-3-Clause"
] | 19 | 2015-05-23T06:47:10.000Z | 2019-08-09T16:31:40.000Z | Categories/Bicategory/Helpers.agda | copumpkin/categories | 36f4181d751e2ecb54db219911d8c69afe8ba892 | [
"BSD-3-Clause"
] | 23 | 2015-02-05T13:03:09.000Z | 2021-11-11T13:50:56.000Z | {-# OPTIONS --universe-polymorphism #-}
module Categories.Bicategory.Helpers where
-- quite a bit of the code below is taken from Categories.2-Category
open import Data.Nat using (_+_)
open import Function using (flip)
open import Data.Product using (_,_; curry)
open import Categories.Category
open import Categories.Categories using (Categories)
import Categories.Functor
open import Categories.Terminal using (OneC; One; unit)
open import Categories.Object.Terminal using (module Terminal)
open import Categories.Bifunctor hiding (identityˡ; identityʳ; assoc) renaming (id to idF; _≡_ to _≡F_; _∘_ to _∘F_)
open import Categories.NaturalIsomorphism
open import Categories.NaturalTransformation using (NaturalTransformation) renaming (_≡_ to _≡ⁿ_; id to idⁿ)
open import Categories.Product using (Product; assocʳ; πˡ; πʳ)
module BicategoryHelperFunctors {o ℓ t e} (Obj : Set o) (_⇒_ : (A B : Obj) → Category ℓ t e)
(—⊗— : {A B C : Obj} → Bifunctor (B ⇒ C) (A ⇒ B) (A ⇒ C))
(id : {A : Obj} → Functor {ℓ} {t} {e} OneC (A ⇒ A)) where
open Terminal (One {ℓ} {t} {e})
_∘_ : {A B C : Obj} {L R : Category ℓ t e} → Functor L (B ⇒ C) → Functor R (A ⇒ B) → Bifunctor L R (A ⇒ C)
_∘_ {A} {B} {C} F G = reduce-× {D₁ = B ⇒ C} {D₂ = A ⇒ B} —⊗— F G
-- convenience!
module _⇒_ (A B : Obj) = Category (A ⇒ B)
open _⇒_ public using () renaming (Obj to _⇒₁_)
private module imp⇒ {X Y : Obj} = Category (X ⇒ Y)
open imp⇒ public using () renaming (_⇒_ to _⇒₂_; id to id₂; _∘_ to _•_; _≡_ to _≡₂_)
id₁ : ∀ {A} → A ⇒₁ A
id₁ {A} = Functor.F₀ (id {A}) unit
id₁₂ : ∀ {A} → id₁ {A} ⇒₂ id₁ {A}
id₁₂ {A} = id₂ {A = id₁ {A}}
infixr 9 _∘₁_
_∘₁_ : ∀ {A B C} → B ⇒₁ C → A ⇒₁ B → A ⇒₁ C
_∘₁_ = curry (Functor.F₀ —⊗—)
-- horizontal composition
infixr 9 _∘₂_
_∘₂_ : ∀ {A B C} {g g′ : B ⇒₁ C} {f f′ : A ⇒₁ B} (β : g ⇒₂ g′) (α : f ⇒₂ f′) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f′)
_∘₂_ = curry (Functor.F₁ —⊗—)
-- left whiskering
infixl 9 _◃_
_◃_ : ∀ {A B C} {g g′ : B ⇒₁ C} → g ⇒₂ g′ → (f : A ⇒₁ B) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f)
β ◃ f = β ∘₂ id₂
-- right whiskering
infixr 9 _▹_
_▹_ : ∀ {A B C} (g : B ⇒₁ C) → {f f′ : A ⇒₁ B} → f ⇒₂ f′ → (g ∘₁ f) ⇒₂ (g ∘₁ f′)
g ▹ α = id₂ ∘₂ α
module Coherence
(identityˡ : {A B : Obj} → NaturalIsomorphism (id ∘ idF {C = A ⇒ B}) (πʳ {C = ⊤} {A ⇒ B}))
(identityʳ : {A B : Obj} → NaturalIsomorphism (idF {C = A ⇒ B} ∘ id) (πˡ {C = A ⇒ B}))
(assoc : {A B C D : Obj} → NaturalIsomorphism (idF ∘ —⊗—) ((—⊗— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B)) ) where
open Categories.NaturalTransformation.NaturalTransformation
-- left/right are inverted between in certain situations!
-- private so as to not clash with the ones in Bicategory itself
private
ρᵤ : {A B : Obj} (f : A ⇒₁ B) → (id₁ ∘₁ f) ⇒₂ f
ρᵤ f = η (NaturalIsomorphism.F⇒G identityˡ) (unit , f)
λᵤ : {A B : Obj} (f : A ⇒₁ B) → (f ∘₁ id₁) ⇒₂ f
λᵤ f = η (NaturalIsomorphism.F⇒G identityʳ) (f , unit)
α : {A B C D : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) (h : C ⇒₁ D) →
(h ∘₁ (g ∘₁ f)) ⇒₂ ((h ∘₁ g) ∘₁ f)
α f g h = η (NaturalIsomorphism.F⇒G assoc) (h , g , f)
-- Triangle identity. Look how closely it matches with the one on
-- http://ncatlab.org/nlab/show/bicategory
Triangle : {A B C : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) → Set e
Triangle f g = (g ▹ ρᵤ f) ≡₂ ((λᵤ g ◃ f) • (α f id₁ g))
-- Pentagon identity. Ditto.
Pentagon : {A B C D E : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) (h : C ⇒₁ D) (i : D ⇒₁ E) → Set e
Pentagon f g h i = ((α g h i ◃ f) • (α f (h ∘₁ g) i)) • (i ▹ α f g h) ≡₂ (α f g (i ∘₁ h) • α (g ∘₁ f) h i)
| 41.170455 | 120 | 0.557825 |
c51138e15fa1d5375f9b1ff941cf2033b8f10dec | 1,022 | agda | Agda | test/Fail/Issue970.agda | pthariensflame/agda | 222c4c64b2ccf8e0fc2498492731c15e8fef32d4 | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Fail/Issue970.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | null | null | null | test/Fail/Issue970.agda | Blaisorblade/Agda | 802a28aa8374f15fe9d011ceb80317fdb1ec0949 | [
"BSD-3-Clause"
] | 1 | 2019-03-05T20:02:38.000Z | 2019-03-05T20:02:38.000Z |
data Dec (A : Set) : Set where
yes : A → Dec A
no : Dec A
record ⊤ : Set where constructor tt
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
subst : ∀ {A}(P : A → Set){x y} → x ≡ y → P x → P y
subst P refl px = px
cong : ∀ {A B}(f : A → B){x y} → x ≡ y → f x ≡ f y
cong f refl = refl
postulate _≟_ : (n n' : ⊤) → Dec (n ≡ n')
record _×_ A B : Set where
constructor _,_
field proj₁ : A
proj₂ : B
open _×_
data Maybe : Set where
nothing : Maybe
data Blah (a : Maybe × ⊤) : Set where
blah : {b : Maybe × ⊤} → Blah b → Blah a
update : {A : Set} → ⊤ → A → A
update n m with n ≟ n
update n m | yes p = m
update n m | no = m
lem-upd : ∀ {A} n (m : A) → update n m ≡ m
lem-upd n m with n ≟ n
... | yes p = refl
... | no = refl
bug : {x : Maybe × ⊤} → proj₁ x ≡ nothing → Blah x
bug ia = blah (bug (subst {⊤}
(λ _ → proj₁ {B = ⊤}
(update tt (nothing , tt)) ≡ nothing)
refl (cong proj₁ (lem-upd _ _))))
| 21.744681 | 72 | 0.476517 |
2379e1251c1d1e1be575ac976b768729a68a606a | 1,951 | agda | Agda | Data/Nat/Order.agda | oisdk/agda-playground | 97a3aab1282b2337c5f43e2cfa3fa969a94c11b7 | [
"MIT"
] | 6 | 2020-09-11T17:45:41.000Z | 2021-11-16T08:11:34.000Z | Data/Nat/Order.agda | oisdk/agda-playground | 97a3aab1282b2337c5f43e2cfa3fa969a94c11b7 | [
"MIT"
] | null | null | null | Data/Nat/Order.agda | oisdk/agda-playground | 97a3aab1282b2337c5f43e2cfa3fa969a94c11b7 | [
"MIT"
] | 1 | 2021-11-11T12:30:21.000Z | 2021-11-11T12:30:21.000Z | {-# OPTIONS --cubical --safe --postfix-projections #-}
module Data.Nat.Order where
open import Prelude
open import Data.Nat.Properties
open import Relation.Binary
<-trans : Transitive _<_
<-trans {zero} {suc y} {suc z} x<y y<z = tt
<-trans {suc x} {suc y} {suc z} x<y y<z = <-trans {x} {y} {z} x<y y<z
<-asym : Asymmetric _<_
<-asym {suc x} {suc y} x<y y<x = <-asym {x} {y} x<y y<x
<-irrefl : Irreflexive _<_
<-irrefl {suc x} = <-irrefl {x = x}
<-conn : Connected _<_
<-conn {zero} {zero} x≮y y≮x = refl
<-conn {zero} {suc y} x≮y y≮x = ⊥-elim (x≮y tt)
<-conn {suc x} {zero} x≮y y≮x = ⊥-elim (y≮x tt)
<-conn {suc x} {suc y} x≮y y≮x = cong suc (<-conn x≮y y≮x)
≤-antisym : Antisymmetric _≤_
≤-antisym {zero} {zero} x≤y y≤x = refl
≤-antisym {suc x} {suc y} x≤y y≤x = cong suc (≤-antisym x≤y y≤x)
ℕ-≰⇒> : ∀ x y → ¬ (x ≤ y) → y < x
ℕ-≰⇒> x y x≰y with y <ᴮ x
... | false = x≰y tt
... | true = tt
ℕ-≮⇒≥ : ∀ x y → ¬ (x < y) → y ≤ x
ℕ-≮⇒≥ x y x≮y with x <ᴮ y
... | false = tt
... | true = x≮y tt
totalOrder : TotalOrder ℕ ℓzero ℓzero
totalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder._<_ = _<_
totalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder.trans {x} {y} {z} = <-trans {x} {y} {z}
totalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder.irrefl {x} = <-irrefl {x = x}
totalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.conn = <-conn
totalOrder .TotalOrder.partialOrder .PartialOrder.preorder .Preorder._≤_ = _≤_
totalOrder .TotalOrder.partialOrder .PartialOrder.preorder .Preorder.refl {x} = ≤-refl x
totalOrder .TotalOrder.partialOrder .PartialOrder.preorder .Preorder.trans {x} {y} {z} = ≤-trans x y z
totalOrder .TotalOrder.partialOrder .PartialOrder.antisym = ≤-antisym
totalOrder .TotalOrder._<?_ x y = T? (x <ᴮ y)
totalOrder .TotalOrder.≰⇒> {x} {y} = ℕ-≰⇒> x y
totalOrder .TotalOrder.≮⇒≥ {x} {y} = ℕ-≮⇒≥ x y
| 38.254902 | 132 | 0.651461 |
4a64e279e64489e5f4ab1c771659db3bde235eaf | 1,883 | agda | Agda | src/Control/Bug-Loop.agda | andreasabel/cubical | 914f655c7c0417754c2ffe494d3f6ea7a357b1c3 | [
"MIT"
] | null | null | null | src/Control/Bug-Loop.agda | andreasabel/cubical | 914f655c7c0417754c2ffe494d3f6ea7a357b1c3 | [
"MIT"
] | null | null | null | src/Control/Bug-Loop.agda | andreasabel/cubical | 914f655c7c0417754c2ffe494d3f6ea7a357b1c3 | [
"MIT"
] | null | null | null | {-# OPTIONS --copatterns #-}
{-# OPTIONS -v tc.constr.findInScope:15 #-}
-- One-place functors (decorations) on Set
module Control.Bug-Loop where
open import Function using (id; _∘_)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Control.Functor
open IsFunctor {{...}}
record IsDecoration (D : Set → Set) : Set₁ where
field
traverse : ∀ {F} {{ functor : IsFunctor F }} {A B} →
(A → F B) → D A → F (D B)
traverse-id : ∀ {A} →
traverse {F = λ A → A} {A = A} id ≡ id
traverse-∘ :
∀ {F G} {{ funcF : IsFunctor F}} {{ funcG : IsFunctor G}} →
∀ {A B C} {f : A → F B} {g : B → G C} →
traverse ((map g) ∘ f) ≡ map {{funcF}} (traverse g) ∘ traverse f
isFunctor : IsFunctor D
isFunctor = record
{ ops = record { map = traverse }
; laws = record { map-id = traverse-id
; map-∘ = traverse-∘
}
}
open IsDecoration
idIsDecoration : IsDecoration (λ A → A)
traverse idIsDecoration f = f
traverse-id idIsDecoration = refl
traverse-∘ idIsDecoration = refl
compIsDecoration : ∀ {D E} → IsDecoration D → IsDecoration E → IsDecoration (λ A → D (E A))
traverse (compIsDecoration d e) f = traverse d (traverse e f)
traverse-id (compIsDecoration d e) = begin
traverse d (traverse e id)
≡⟨ cong (traverse d) (traverse-id e) ⟩
traverse d id
≡⟨ traverse-id d ⟩
id
∎
traverse-∘ (compIsDecoration d e) {{funcF = funcF}} {{funcG = funcG}} {f = f} {g = g} = begin
traverse (compIsDecoration d e) (map g ∘ f)
≡⟨⟩
traverse d (traverse e (map g ∘ f))
≡⟨ cong (traverse d) (traverse-∘ e) ⟩
traverse d (map (traverse e g) ∘ traverse e f)
≡⟨ traverse-∘ d ⟩
map (traverse d (traverse e g)) ∘ traverse d (traverse e f)
≡⟨⟩
map (traverse (compIsDecoration d e) g) ∘ traverse (compIsDecoration d e) f
∎
| 28.104478 | 93 | 0.589485 |
4a1badb9162f5d08724331487633a56c6540c3e7 | 158 | agda | Agda | test/Succeed/Issue204.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue204.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue204.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --universe-polymorphism #-}
module Issue204 where
open import Issue204.Dependency
postulate
ℓ : Level
r : R ℓ
d : D ℓ
open R r
open M d
| 11.285714 | 39 | 0.677215 |
0e954ccfad75428640cd94d3664ec3b4d36314c5 | 3,062 | agda | Agda | agda-stdlib-0.9/src/Data/Star/Decoration.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/Data/Star/Decoration.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | null | null | null | agda-stdlib-0.9/src/Data/Star/Decoration.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | null | null | null | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Decorated star-lists
------------------------------------------------------------------------
module Data.Star.Decoration where
open import Data.Star
open import Relation.Binary
open import Function
open import Data.Unit
open import Level
-- A predicate on relation "edges" (think of the relation as a graph).
EdgePred : {I : Set} → Rel I zero → Set₁
EdgePred T = ∀ {i j} → T i j → Set
data NonEmptyEdgePred {I : Set}
(T : Rel I zero) (P : EdgePred T) : Set where
nonEmptyEdgePred : ∀ {i j} {x : T i j}
(p : P x) → NonEmptyEdgePred T P
-- Decorating an edge with more information.
data DecoratedWith {I : Set} {T : Rel I zero} (P : EdgePred T)
: Rel (NonEmpty (Star T)) zero where
↦ : ∀ {i j k} {x : T i j} {xs : Star T j k}
(p : P x) → DecoratedWith P (nonEmpty (x ◅ xs)) (nonEmpty xs)
edge : ∀ {I} {T : Rel I zero} {P : EdgePred T} {i j} →
DecoratedWith {T = T} P i j → NonEmpty T
edge (↦ {x = x} p) = nonEmpty x
decoration : ∀ {I} {T : Rel I zero} {P : EdgePred T} {i j} →
(d : DecoratedWith {T = T} P i j) →
P (NonEmpty.proof (edge d))
decoration (↦ p) = p
-- Star-lists decorated with extra information. All P xs means that
-- all edges in xs satisfy P.
All : ∀ {I} {T : Rel I zero} → EdgePred T → EdgePred (Star T)
All P {j = j} xs =
Star (DecoratedWith P) (nonEmpty xs) (nonEmpty {y = j} ε)
-- We can map over decorated vectors.
gmapAll : ∀ {I} {T : Rel I zero} {P : EdgePred T}
{J} {U : Rel J zero} {Q : EdgePred U}
{i j} {xs : Star T i j}
(f : I → J) (g : T =[ f ]⇒ U) →
(∀ {i j} {x : T i j} → P x → Q (g x)) →
All P xs → All {T = U} Q (gmap f g xs)
gmapAll f g h ε = ε
gmapAll f g h (↦ x ◅ xs) = ↦ (h x) ◅ gmapAll f g h xs
-- Since we don't automatically have gmap id id xs ≡ xs it is easier
-- to implement mapAll in terms of map than in terms of gmapAll.
mapAll : ∀ {I} {T : Rel I zero} {P Q : EdgePred T} {i j} {xs : Star T i j} →
(∀ {i j} {x : T i j} → P x → Q x) →
All P xs → All Q xs
mapAll {P = P} {Q} f ps = map F ps
where
F : DecoratedWith P ⇒ DecoratedWith Q
F (↦ x) = ↦ (f x)
-- We can decorate star-lists with universally true predicates.
decorate : ∀ {I} {T : Rel I zero} {P : EdgePred T} {i j} →
(∀ {i j} (x : T i j) → P x) →
(xs : Star T i j) → All P xs
decorate f ε = ε
decorate f (x ◅ xs) = ↦ (f x) ◅ decorate f xs
-- We can append Alls. Unfortunately _◅◅_ does not quite work.
infixr 5 _◅◅◅_ _▻▻▻_
_◅◅◅_ : ∀ {I} {T : Rel I zero} {P : EdgePred T}
{i j k} {xs : Star T i j} {ys : Star T j k} →
All P xs → All P ys → All P (xs ◅◅ ys)
ε ◅◅◅ ys = ys
(↦ x ◅ xs) ◅◅◅ ys = ↦ x ◅ xs ◅◅◅ ys
_▻▻▻_ : ∀ {I} {T : Rel I zero} {P : EdgePred T}
{i j k} {xs : Star T j k} {ys : Star T i j} →
All P xs → All P ys → All P (xs ▻▻ ys)
_▻▻▻_ = flip _◅◅◅_
| 33.282609 | 76 | 0.500327 |
189861b0384510ca3c80c7c7d6c82af5a8e9d0e8 | 3,080 | agda | Agda | src/Data/ByteString.agda | semenov-vladyslav/bytes-agda | 98a53f35fca27e3379cf851a9a6bdfe5bd8c9626 | [
"MIT"
] | null | null | null | src/Data/ByteString.agda | semenov-vladyslav/bytes-agda | 98a53f35fca27e3379cf851a9a6bdfe5bd8c9626 | [
"MIT"
] | null | null | null | src/Data/ByteString.agda | semenov-vladyslav/bytes-agda | 98a53f35fca27e3379cf851a9a6bdfe5bd8c9626 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
module Data.ByteString where
import Data.ByteString.Primitive as Prim
import Data.ByteString.Utf8 as Utf8
open import Data.Word8 using (Word8)
open import Data.Nat using (ℕ)
open import Data.Colist using (Colist)
open import Data.List using (List)
open import Data.String using (String)
open import Data.Bool using (Bool; true; false)
open import Data.Product using (_×_)
open import Data.Tuple using (Pair→×)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)
data ByteStringKind : Set where
Lazy Strict : ByteStringKind
ByteString : ByteStringKind → Set
ByteString Lazy = Prim.ByteStringLazy
ByteString Strict = Prim.ByteStringStrict
empty : ∀ {k} → ByteString k
empty {Lazy} = Prim.emptyLazy
empty {Strict} = Prim.emptyStrict
null : ∀ {k} → ByteString k → Bool
null {Lazy} = Prim.nullLazy
null {Strict} = Prim.nullStrict
length : ∀ {k} → ByteString k → ℕ
length {Lazy} bs = Prim.int64Toℕ (Prim.lengthLazy bs)
length {Strict} bs = Prim.IntToℕ (Prim.lengthStrict bs)
unsafeHead : ∀ {k} → ByteString k → Word8
unsafeHead {Lazy} = Prim.headLazy
unsafeHead {Strict} = Prim.headStrict
unsafeTail : ∀ {k} → ByteString k → ByteString k
unsafeTail {Lazy} = Prim.tailLazy
unsafeTail {Strict} = Prim.tailStrict
unsafeIndex : ∀ {k} → ByteString k → ℕ → Word8
unsafeIndex {Lazy} bs ix = Prim.indexLazy bs (Prim.ℕToInt64 ix)
unsafeIndex {Strict} bs ix = Prim.indexStrict bs (Prim.ℕToInt ix)
unsafeSplitAt : ∀ {k} → ℕ → ByteString k → (ByteString k) × (ByteString k)
unsafeSplitAt {Lazy} ix bs = Pair→× (Prim.splitAtLazy (Prim.ℕToInt64 ix) bs)
unsafeSplitAt {Strict} ix bs = Pair→× (Prim.splitAtStrict (Prim.ℕToInt ix) bs)
ByteStringRep : ByteStringKind → Set
ByteStringRep Lazy = Colist Word8
ByteStringRep Strict = List Word8
unpack : ∀ {k} → ByteString k → ByteStringRep k
unpack {Lazy} = Prim.Colist←Lazy
unpack {Strict} = Prim.List←Strict
pack : ∀ {k} → ByteStringRep k → ByteString k
pack {Lazy} = Prim.Colist→Lazy
pack {Strict} = Prim.List→Strict
infix 4 _≟_
_≟_ : ∀ {k} → Decidable {A = ByteString k} _≡_
_≟_ {Lazy} s₁ s₂ with Prim.lazy≟lazy s₁ s₂
... | true = yes trustMe
... | false = no whatever
where postulate whatever : _
_≟_ {Strict} s₁ s₂ with Prim.strict≟strict s₁ s₂
... | true = yes trustMe
... | false = no whatever
where postulate whatever : _
-- behind _==_ is the same idea as in Data.String
infix 4 _==_
_==_ : ∀ {k} → ByteString k → ByteString k → Bool
_==_ {k} s₁ s₂ = ⌊ s₁ ≟ s₂ ⌋
_++_ : ByteString Lazy → ByteString Lazy → ByteString Lazy
_++_ = Prim.appendLazy
fromChunks : List (ByteString Strict) → ByteString Lazy
fromChunks = Prim.fromChunks
toChunks : ByteString Lazy → List (ByteString Strict)
toChunks = Prim.toChunks
toLazy : ByteString Strict → ByteString Lazy
toLazy = Prim.toLazy
toStrict : ByteString Lazy → ByteString Strict
toStrict = Prim.toStrict
| 29.333333 | 78 | 0.727922 |
d096e15e2f67090b5493f6f6ffec49dc2f8823d9 | 4,710 | agda | Agda | Streams/StreamEnc.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | Streams/StreamEnc.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | Streams/StreamEnc.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | module StreamEnc where
open import Data.Unit hiding (_≤_)
open import Data.Nat
open import Data.Product
open import Data.Sum
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
≤-step : ∀{k n} → k ≤ n → k ≤ suc n
≤-step z≤n = z≤n
≤-step (s≤s p) = s≤s (≤-step p)
pred-≤ : ∀{k n} → suc k ≤ n → k ≤ n
pred-≤ (s≤s p) = ≤-step p
Str : Set → Set
Str A = ℕ → A
hd : ∀{A} → Str A → A
hd s = s 0
tl : ∀{A} → Str A → Str A
tl s n = s (suc n)
_ω : ∀{A} → A → Str A
(a ω) n = a
_∷_ : ∀{A} → A → Str A → Str A
(a ∷ s) 0 = a
(a ∷ s) (suc n) = s n
module Mealy (A B : Set) where
M : Set → Set
M X = A → B × X
M₁ : {X Y : Set} → (X → Y) → M X → M Y
M₁ f g a =
let (b , x) = g a
in (b , f x)
𝓜 : Set
𝓜 = Str A → Str B
d : 𝓜 → M 𝓜
d f a = (f (a ω) 0 , (λ s n → f (a ∷ s) (suc n)))
corec : ∀{X} → (c : X → M X) → X → 𝓜
corec c x s zero = proj₁ (c x (hd s))
corec c x s (suc n) = corec c (proj₂ (c x (hd s))) (tl s) n
compute' : ∀{X} (c : X → M X) (x : X) →
∀ a → d (corec c x) a ≡ M₁ (corec c) (c x) a
compute' c x a =
begin
d (corec c x) a
≡⟨ refl ⟩
((corec c x) (a ω) 0 , λ s n → (corec c x) (a ∷ s) (suc n))
≡⟨ refl ⟩
(proj₁ (c x (hd (a ω)))
, λ s n → corec c (proj₂ (c x (hd (a ∷ s)))) (tl (a ∷ s)) n)
≡⟨ refl ⟩
(proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) (λ n → s n) n)
≡⟨ refl ⟩
(proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) s n)
≡⟨ refl ⟩
(proj₁ (c x a) , λ s → corec c (proj₂ (c x a)) s)
≡⟨ refl ⟩
(proj₁ (c x a) , corec c (proj₂ (c x a)))
≡⟨ refl ⟩
M₁ (corec c) (c x) a
∎
compute : ∀{X} (c : X → M X) (x : X) →
d (corec c x) ≡ M₁ (corec c) (c x)
compute c x =
begin
d (corec c x)
≡⟨ refl ⟩
(λ a → d (corec c x) a)
≡⟨ refl ⟩ -- Same as in compute'
(λ a → M₁ (corec c) (c x) a)
≡⟨ refl ⟩
M₁ (corec c) (c x)
∎
module MealyT (A B : Set) (a₀ : A) where
M : Set → Set
M X = ⊤ ⊎ (A → B × X)
M₁ : {X Y : Set} → (X → Y) → M X → M Y
M₁ f (inj₁ x) = inj₁ x
M₁ f (inj₂ g) =
inj₂ (λ a →
let (b , x) = g a
in (b , f x))
Mono : (Str A → Str (⊤ ⊎ B)) → Set
-- Mono f = ∀ n → (∃ λ s → ∃ λ b → f s n ≡ inj₂ b) →
-- ∀ s → ∀ k → k ≤ n → (∃ λ b → f s k ≡ inj₂ b)
Mono f = ∀ n → ∀ s₁ b₁ → f s₁ n ≡ inj₂ b₁ →
∀ s → ∀ k → k ≤ n → (∃ λ b → f s k ≡ inj₂ b)
𝓜₁ : Set
𝓜₁ = Str A → Str (⊤ ⊎ B)
𝓜 : Set
𝓜 = Σ[ f ∈ 𝓜₁ ] (Mono f)
d : 𝓜 → M 𝓜
d (f , m) = F (f (a₀ ω) 0) refl
where
F : (u : ⊤ ⊎ B) → (f (a₀ ω) 0) ≡ u → M 𝓜
F (inj₁ tt) _ = inj₁ tt
F (inj₂ b) p = inj₂ (λ a →
let (b' , p') = m 0 (a₀ ω) b p (a ω) 0 z≤n
f' = λ s n → f (a ∷ s) (suc n)
m' : Mono f'
m' = λ {n s₁ b₁ p₁ s k k≤n →
m (suc n) (a ∷ s₁) b₁ p₁ (a ∷ s) (suc k) (s≤s k≤n)}
in b' , f' , m')
corec₁ : ∀{X} → (c : X → M X) → X → 𝓜₁
corec₁ c x s n with c x
corec₁ c x s n | inj₁ tt = inj₁ tt
corec₁ c x s zero | inj₂ g = inj₂ (proj₁ (g (hd s)))
corec₁ c x s (suc n) | inj₂ g = corec₁ c (proj₂ (g (hd s))) (tl s) n
corec₂ : ∀{X} → (c : X → M X) (x : X) → Mono (corec₁ c x)
corec₂ c x n s₁ b₁ p₁ s k k≤n with c x
corec₂ c x n s₁ b₁ () s k k≤n | inj₁ tt
corec₂ c x n s₁ b₁ p₁ s zero k≤n | inj₂ g = (proj₁ (g (hd s)) , refl)
corec₂ c x n s₁ b₁ p₁ s (suc k) sk≤n | inj₂ g = {!!}
-- corec₂ c
-- (proj₂ (g (hd s)))
-- n
-- (tl s)
-- (proj₁ (g (hd s)))
-- {!!}
-- (tl s) k (pred-≤ sk≤n)
-- compute' : ∀{X} (c : X → M X) (x : X) →
-- ∀ a → d (corec c x) a ≡ M₁ (corec c) (c x) a
-- compute' c x a =
-- begin
-- d (corec c x) a
-- ≡⟨ refl ⟩
-- ((corec c x) (a ω) 0 , λ s n → (corec c x) (a ∷ s) (suc n))
-- ≡⟨ refl ⟩
-- (proj₁ (c x (hd (a ω)))
-- , λ s n → corec c (proj₂ (c x (hd (a ∷ s)))) (tl (a ∷ s)) n)
-- ≡⟨ refl ⟩
-- (proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) (λ n → s n) n)
-- ≡⟨ refl ⟩
-- (proj₁ (c x a) , λ s n → corec c (proj₂ (c x a)) s n)
-- ≡⟨ refl ⟩
-- (proj₁ (c x a) , λ s → corec c (proj₂ (c x a)) s)
-- ≡⟨ refl ⟩
-- (proj₁ (c x a) , corec c (proj₂ (c x a)))
-- ≡⟨ refl ⟩
-- M₁ (corec c) (c x) a
-- ∎
-- compute : ∀{X} (c : X → M X) (x : X) →
-- d (corec c x) ≡ M₁ (corec c) (c x)
-- compute c x =
-- begin
-- d (corec c x)
-- ≡⟨ refl ⟩
-- (λ a → d (corec c x) a)
-- ≡⟨ refl ⟩ -- Same as in compute'
-- (λ a → M₁ (corec c) (c x) a)
-- ≡⟨ refl ⟩
-- M₁ (corec c) (c x)
-- ∎
| 26.460674 | 73 | 0.395329 |
d0f3fcada2a1b2eb4693ccf9aeb5c9e83bdf41fe | 418 | agda | Agda | test/Fail/Issue1114.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/Issue1114.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/Issue1114.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --experimental-irrelevance #-}
-- Andreas, 2015-05-18 Irrelevant module parameters
-- should not be resurrected in module body.
postulate
A : Set
module M .(a : A) where
bad : (..(_ : A) -> Set) -> Set
bad f = f a
-- SHOULD FAIL: variable a is declared irrelevant,
-- so it cannot be used here.
-- This fails of course:
-- fail : .(a : A) -> (..(_ : A) -> Set) -> Set
-- fail a f = f a
| 22 | 54 | 0.590909 |
c5801b130b04597d30f7f70bf1e73144cdd7e66b | 95 | agda | Agda | test/Fail/Issue1209-3.agda | caryoscelus/agda | 98d6f195fe672e54ef0389b4deb62e04e3e98327 | [
"BSD-3-Clause"
] | null | null | null | test/Fail/Issue1209-3.agda | caryoscelus/agda | 98d6f195fe672e54ef0389b4deb62e04e3e98327 | [
"BSD-3-Clause"
] | null | null | null | test/Fail/Issue1209-3.agda | caryoscelus/agda | 98d6f195fe672e54ef0389b4deb62e04e3e98327 | [
"BSD-3-Clause"
] | null | null | null | -- This combination should not be allowed:
{-# OPTIONS --guardedness --sized-types --safe #-}
| 23.75 | 50 | 0.684211 |
20e8a7f9eba112b5bfc7bc9aeb7f1a919879c47e | 624 | agda | Agda | Base/Denotation/Notation.agda | inc-lc/ilc-agda | 39bb081c6f192bdb87bd58b4a89291686d2d7d03 | [
"MIT"
] | 10 | 2015-03-04T06:09:20.000Z | 2019-07-19T07:06:59.000Z | Base/Denotation/Notation.agda | inc-lc/ilc-agda | 39bb081c6f192bdb87bd58b4a89291686d2d7d03 | [
"MIT"
] | 6 | 2015-07-01T18:09:31.000Z | 2017-05-04T13:53:59.000Z | Base/Denotation/Notation.agda | inc-lc/ilc-agda | 39bb081c6f192bdb87bd58b4a89291686d2d7d03 | [
"MIT"
] | 1 | 2016-02-18T12:26:44.000Z | 2016-02-18T12:26:44.000Z | ------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Overloading ⟦_⟧ notation
--
-- This module defines a general mechanism for overloading the
-- ⟦_⟧ notation, using Agda’s instance arguments.
------------------------------------------------------------------------
module Base.Denotation.Notation where
open import Level
record Meaning (Syntax : Set) {ℓ : Level} : Set (suc ℓ) where
constructor
meaning
field
{Semantics} : Set ℓ
⟨_⟩⟦_⟧ : Syntax → Semantics
open Meaning {{...}} public
renaming (⟨_⟩⟦_⟧ to ⟦_⟧)
open Meaning public
using (⟨_⟩⟦_⟧)
| 24 | 72 | 0.516026 |
Subsets and Splits