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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4a1d5e8a5493ac3bf95714a071fe33bcdf42fa99 | 178 | agda | Agda | Cubical/HITs/ListedFiniteSet.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 301 | 2018-10-17T18:00:24.000Z | 2022-03-24T02:10:47.000Z | Cubical/HITs/ListedFiniteSet.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 584 | 2018-10-15T09:49:02.000Z | 2022-03-30T12:09:17.000Z | Cubical/HITs/ListedFiniteSet.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 134 | 2018-11-16T06:11:03.000Z | 2022-03-23T16:22:13.000Z | {-# OPTIONS --safe #-}
module Cubical.HITs.ListedFiniteSet where
open import Cubical.HITs.ListedFiniteSet.Base public
open import Cubical.HITs.ListedFiniteSet.Properties public
| 29.666667 | 58 | 0.820225 |
dc67728d6b964f20dfaf3496797d011f2e64312f | 17,049 | agda | Agda | src-cbpv/GradedCBPVSup.agda | andreasabel/ipl | 9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a | [
"Unlicense"
] | 19 | 2018-05-16T08:08:51.000Z | 2021-04-27T19:10:49.000Z | src-cbpv/GradedCBPVSup.agda | andreasabel/ipl | 9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a | [
"Unlicense"
] | null | null | null | src-cbpv/GradedCBPVSup.agda | andreasabel/ipl | 9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a | [
"Unlicense"
] | 2 | 2018-11-13T16:01:46.000Z | 2021-02-25T20:39:03.000Z | {-# OPTIONS --rewriting #-}
-- Normalization by Evaluation for Graded Call-By-Push-Value.
-- With supremum of effects.
module GradedCBPVSup where
-- Imports from the Agda standard library.
open import Library hiding (_×̇_)
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
pattern here! = here refl
-- We postulate a set of generic value types.
-- There are no operations defined on these types, thus,
-- they play the type of (universal) type variables.
postulate
Base : Set
variable
o : Base
-- Variants (Σ) (and records (Π), resp.) can in principle have any number of
-- constructors (fields, resp.), including infinitely one.
-- In general, the constructor (field, resp.) names are given by a set I.
-- However, I : Set would make syntax already a big type, living in Set₁.
-- To keep it in Set₀, we only consider variants (records) with finitely
-- many constructors (fields), thus, I : ℕ.
-- Branching over I is then realized as functions out of El I, where
-- El I = { i | i < I} = Fin I.
set = ℕ
El = Fin
-- Let I range over arities (constructor/field sets) and i over
-- constructor/field names.
variable
I : set
i : El I
-- We postulate an effect algebra which is an additively written
-- monoid with supremum.
postulate
Eff : Set
∅ : Eff
_+_ : (e e' : Eff) → Eff
_∨_ : (e e' : Eff) → Eff
sup : {I : set} (es : El I → Eff) → Eff
variable
e e' e₁ e₂ e₃ : Eff
es : El I → Eff
postulate
+-unitˡ : ∅ + e ≡ e
+-unitʳ : e + ∅ ≡ e
+-assoc : (e₁ + e₂) + e₃ ≡ e₁ + (e₂ + e₃)
+-supʳ : sup es + e ≡ sup λ i → es i + e
sup-k : sup {I = I} (λ _ → e) ≡ e
{-# REWRITE +-unitˡ +-unitʳ +-assoc +-supʳ sup-k #-}
-- The types of CBPV are classified into value types P : Ty⁺ which we
-- refer to as positive types, and computation types N : Ty⁻ which we
-- refer to as negative types.
mutual
-- Value types
data Ty⁺ : Set where
base : (o : Base) → Ty⁺ -- Base type.
_×̇_ : (P₁ P₂ : Ty⁺) → Ty⁺ -- Finite product (tensor).
Σ̇ : (I : set) (Ps : El I → Ty⁺) → Ty⁺ -- Variant (sum).
[_] : (e : Eff) (N : Ty⁻) → Ty⁺ -- Thunk (U).
-- Remembers effects.
-- Computation types
data Ty⁻ : Set where
◇̇ : (P : Ty⁺) → Ty⁻ -- Comp (F).
Π̇ : (I : set) (Ns : El I → Ty⁻) → Ty⁻ -- Record (lazy product).
_⇒̇_ : (P : Ty⁺) (N : Ty⁻) → Ty⁻ -- Function type.
-- In CBPV, a variable stands for a value.
-- Thus, environments only contain values,
-- and typing contexts only value types.
-- We use introduce syntax in an intrinsically well-typed way
-- with variables being de Bruijn indices into the typing context.
-- Thus, contexts are just lists of types.
Cxt = List Ty⁺
variable
Γ Δ Φ : Cxt
J : Cxt → Set
P P₁ P₂ P' P′ Q : Ty⁺
N N₁ N₂ N' N′ : Ty⁻
Ps : El I → Ty⁺
Ns : El I → Ty⁻
-- Generic values
module _ (Var : Ty⁺ → Cxt → Set) (Comp : Eff → Ty⁻ → Cxt → Set) where
-- Right non-invertible
data Val' : (P : Ty⁺) (Γ : Cxt) → Set where
var : (x : Var P Γ) → Val' P Γ
pair : (v₁ : Val' P₁ Γ) (v₂ : Val' P₂ Γ) → Val' (P₁ ×̇ P₂) Γ
inj : (i : _) (v : Val' (Ps i) Γ) → Val' (Σ̇ I Ps) Γ
thunk : (t : Comp e N Γ) → Val' ([ e ] N) Γ
-- Terms
mutual
Val = Val' _∈_ Comp
data Comp : (e : Eff) (N : Ty⁻) (Γ : Cxt) → Set where
-- introductions
ret : (v : Val P Γ) → Comp ∅ (◇̇ P) Γ
rec : (t : ∀ i → Comp (es i) (Ns i) Γ) → Comp (sup es) (Π̇ I Ns) Γ
abs : (t : Comp e N (P ∷ Γ)) → Comp e (P ⇒̇ N) Γ
-- positive eliminations
split : (v : Val (P₁ ×̇ P₂) Γ) (t : Comp e N (P₂ ∷ P₁ ∷ Γ)) → Comp e N Γ
case : (v : Val (Σ̇ I Ps) Γ) (t : ∀ i → Comp (es i) N (Ps i ∷ Γ)) → Comp (sup es) N Γ
bind : (u : Comp e₁ (◇̇ P) Γ) (t : Comp e₂ N (P ∷ Γ)) → Comp (e₁ + e₂) N Γ
-- cut
letv : (v : Val P Γ) (t : Comp e N (P ∷ Γ)) → Comp e N Γ
-- negative eliminations
force : (v : Val ([ e ] N) Γ) → Comp e N Γ
prj : (i : _) (t : Comp e (Π̇ I Ns) Γ) → Comp e (Ns i) Γ
app : (t : Comp e (P ⇒̇ N) Γ) (v : Val P Γ) → Comp e N Γ
-- Normal forms
------------------------------------------------------------------------
-- Normal values only reference variables of base type
NVar : (P : Ty⁺) (Γ : Cxt) → Set
NVar (base o) Γ = base o ∈ Γ
NVar _ _ = ⊥
-- Negative neutrals
module _ (Val : Ty⁺ → Cxt → Set) where
-- Right non-invertible
-- Propagates the effect from the head variable, a thunk.
data Ne' (e : Eff) : (N : Ty⁻) (Γ : Cxt) → Set where
force : (x : [ e ] N ∈ Γ) → Ne' e N Γ
prj : (i : El I) (t : Ne' e (Π̇ I Ns) Γ) → Ne' e (Ns i) Γ
app : (t : Ne' e (P ⇒̇ N) Γ) (v : Val P Γ) → Ne' e N Γ
mutual
NVal = Val' NVar Nf
Ne = Ne' NVal
-- Cover monad (generalized case tree).
-- Collects effects from all bind nodes.
data ◇ (J : Cxt → Set) : (e : Eff) (Γ : Cxt) → Set where
return : (j : J Γ) → ◇ J ∅ Γ
bind : (u : Ne e₁ (◇̇ P) Γ) (t : ◇ J e₂ (P ∷ Γ)) → ◇ J (e₁ + e₂) Γ
case : (x : Σ̇ I Ps ∈ Γ) (t : ∀ i → ◇ J (es i) (Ps i ∷ Γ)) → ◇ J (sup es) Γ
split : (x : (P₁ ×̇ P₂) ∈ Γ) (t : ◇ J e (P₂ ∷ P₁ ∷ Γ)) → ◇ J e Γ
⟨_⟩ : ∀ e J Γ → Set
⟨ e ⟩ J Γ = ◇ J e Γ
-- syntax ◇ J e = ⟨ e ⟩ J
-- Right invertible.
data Nf : (e : Eff) (N : Ty⁻) (Γ : Cxt) → Set where
-- ne is only needed for negative base types
-- ne : let N = ◇̇ (base o) in (n : ◇ (Ne e₁ N) e₂ Γ) → Nf (e₂ + e₁) N Γ -- UNUSED
ret : (v : ◇ (NVal P) e Γ) → Nf e (◇̇ P) Γ -- Invoke RFoc
rec : ∀{es} (ts : ∀ i → Nf (es i) (Ns i) Γ) → Nf (sup es) (Π̇ I Ns) Γ
abs : (t : Nf e N (P ∷ Γ)) → Nf e (P ⇒̇ N) Γ
-- NComp is obsolete thanks to the Cover monad ◇.
data NComp : (e : Eff) (Q : Ty⁺) (Γ : Cxt) → Set where
-- Base cases
ret : (v : NVal Q Γ) → NComp ∅ Q Γ -- Invoke RFoc
ne : (n : Ne e (◇̇ Q) Γ) → NComp e Q Γ -- Finish with LFoc
-- e.g. app (force f) x
-- Use lemma LFoc
bind : (u : Ne e₁ (◇̇ P) Γ) (t : NComp e₂ Q (P ∷ Γ)) → NComp (e₁ + e₂) Q Γ
-- Left invertible
split : (x : (P₁ ×̇ P₂) ∈ Γ) (t : NComp e Q (P₂ ∷ P₁ ∷ Γ)) → NComp e Q Γ
case : (x : Σ̇ I Ps ∈ Γ) (t : ∀ i → NComp (es i) Q (Ps i ∷ Γ)) → NComp (sup es) Q Γ
-- Context-indexed sets
------------------------------------------------------------------------
PSet = (Γ : Cxt) → Set
NSet = (e : Eff) (Γ : Cxt) → Set
variable
C A A' A₁ A₂ : PSet
B B' B₁ B₂ : NSet
F G As : (i : El I) → PSet
Bs Bs' Bs₁ Bs₂ : (i : El I) → NSet
-- Constructions on PSet
1̂ : PSet
1̂ Γ = ⊤
_×̂_ : (A₁ A₂ : PSet) → PSet
(A₁ ×̂ A₂) Γ = A₁ Γ × A₂ Γ
Σ̂ : (I : set) (As : El I → PSet) → PSet
(Σ̂ I F) Γ = ∃ λ i → F i Γ
_⇒̂_ : (A₁ A₂ : PSet) → PSet
(A₁ ⇒̂ A₂) Γ = A₁ Γ → A₂ Γ
Π̂ : (I : set) (As : El I → PSet) → PSet
(Π̂ I As) Γ = ∀ i → As i Γ
⟪_⟫ : (P : Ty⁺) (A : PSet) → PSet
⟪ P ⟫ A Γ = A (P ∷ Γ)
-- Constructions on NSet
_⇒ⁿ_ : (A : PSet) (B : NSet) → NSet
(A ⇒ⁿ B) e Γ = A Γ → B e Γ
Πⁿ : (I : set) (Bs : El I → NSet) → NSet
(Πⁿ I Bs) e Γ = ∀ i → Bs i e Γ
-- Morphisms between ISets
_→̇_ : (A₁ A₂ : PSet) → Set
A₁ →̇ A₂ = ∀{Γ} → A₁ Γ → A₂ Γ
_→̈_ : (B₁ B₂ : NSet) → Set
B₁ →̈ B₂ = ∀{e Γ} → B₁ e Γ → B₂ e Γ
⟨_⊙_⟩→̇_ : (P Q R : PSet) → Set
⟨ P ⊙ Q ⟩→̇ R = ∀{Γ} → P Γ → Q Γ → R Γ
⟨_⊙_⊙_⟩→̇_ : (P Q R S : PSet) → Set
⟨ P ⊙ Q ⊙ R ⟩→̇ S = ∀{Γ} → P Γ → Q Γ → R Γ → S Γ
Map : (F : (PSet) → PSet) → Set₁
Map F = ∀{A B : PSet} (f : A →̇ B) → F A →̇ F B
Π-map : (∀ i {e} → Bs i e →̇ Bs' i e) → ∀{e} → Πⁿ I Bs e →̇ Πⁿ I Bs' e
Π-map f r i = f i (r i)
-- -- Introductions and eliminations for ×̂
-- p̂air : ⟨ A ⊙ B ⟩→̇ (A ×̂ B)
-- p̂air a b = λ
-- Monotonicity
------------------------------------------------------------------------
-- Monotonization □ is a monoidal comonad
□ : (A : PSet) → PSet
□ A Γ = ∀{Δ} (τ : Γ ⊆ Δ) → A Δ
extract : □ A →̇ A
extract a = a ⊆-refl
duplicate : □ A →̇ □ (□ A)
duplicate a τ τ′ = a (⊆-trans τ τ′)
□-map : Map □
□-map f a τ = f (a τ)
extend : (□ A →̇ C) → □ A →̇ □ C
extend f = □-map f ∘ duplicate
□-weak : □ A →̇ ⟪ P ⟫ (□ A)
□-weak a τ = a (⊆-trans (_ ∷ʳ ⊆-refl) τ)
□-weak' : □ A →̇ □ (⟪ P ⟫ A)
□-weak' a τ = a (_ ∷ʳ τ)
□-sum : Σ̂ I (□ ∘ F) →̇ □ (Σ̂ I F)
□-sum (i , a) τ = i , a τ
-- Monoidality:
□-unit : 1̂ →̇ □ 1̂
□-unit = _
□-pair : ⟨ □ A₁ ⊙ □ A₂ ⟩→̇ □ (A₁ ×̂ A₂)
□-pair a b τ = (a τ , b τ)
-- -- Strong functoriality
Map! : (F : PSet → PSet) → Set₁
Map! F = ∀{A C} → ⟨ □ (λ Γ → A Γ → C Γ) ⊙ F A ⟩→̇ F C
-- Monotonicity
Mon : (A : PSet) → Set
Mon A = A →̇ □ A
monVar : Mon (P ∈_)
monVar x τ = ⊆-lookup τ x
-- Positive ISets are monotone
□-mon : Mon (□ A)
□-mon = duplicate
1-mon : Mon 1̂
1-mon = □-unit
×-mon : Mon A₁ → Mon A₂ → Mon (A₁ ×̂ A₂)
×-mon mA mB (a , b) = □-pair (mA a) (mB b)
Σ-mon : ((i : El I) → Mon (F i)) → Mon (Σ̂ I F)
Σ-mon m (i , a) = □-sum (i , m i a)
□-intro : Mon A → (A →̇ C) → (A →̇ □ C)
□-intro mA f = □-map f ∘ mA
-- Cover monad: a strong graded monad
------------------------------------------------------------------------
-- join needs effect algebra laws: +-unitˡ +-assoc +-supʳ.
join : ⟨ e₁ ⟩ (⟨ e₂ ⟩ A) →̇ ⟨ e₁ + e₂ ⟩ A
join (return c) = c
join (bind u c) = bind u (join c)
join (case x t) = case x (join ∘ t)
join (split x c) = split x (join c)
◇-map : Map ⟨ e ⟩
◇-map f (return j) = return (f j)
◇-map f (bind u a) = bind u (◇-map f a)
◇-map f (case x t) = case x (λ i → ◇-map f (t i))
◇-map f (split x a) = split x (◇-map f a)
◇-map! : Map! ⟨ e ⟩
◇-map! f (return j) = return (extract f j)
◇-map! f (bind u a) = bind u (◇-map! (□-weak f) a)
◇-map! f (case x t) = case x (λ i → ◇-map! (□-weak f) (t i))
◇-map! f (split x a) = split x (◇-map! (□-weak (□-weak f)) a)
◇-bind : A →̇ ⟨ e₂ ⟩ C → ⟨ e₁ ⟩ A →̇ ⟨ e₁ + e₂ ⟩ C
◇-bind f = join ∘ ◇-map f
◇-record : (⟨ e ⟩ ∘ Πⁿ I Bs) →̈ Πⁿ I (λ i → ⟨ e ⟩ ∘ Bs i)
◇-record c i = ◇-map (_$ i) c
◇-fun : Mon A → (⟨ e ⟩ ∘ A ⇒ⁿ B) →̈ (A ⇒ⁿ (⟨ e ⟩ ∘ B))
◇-fun mA c a = ◇-map! (λ τ f → f (mA a τ)) c
-- Monoidal functoriality
◇-pair : ⟨ □ (⟨ e₁ ⟩ A₁) ⊙ ⟨ e₂ ⟩ (□ A₂) ⟩→̇ ⟨ e₂ + e₁ ⟩ (A₁ ×̂ A₂)
◇-pair ca = join ∘ ◇-map! λ τ b → ◇-map! (λ τ′ a → a , b τ′) (ca τ)
_⋉_ = ◇-pair
□◇-pair' : ⟨ □ (⟨ e₁ ⟩ A₁) ⊙ □ (⟨ e₂ ⟩ (□ A₂)) ⟩→̇ □ (⟨ e₂ + e₁ ⟩ (A₁ ×̂ A₂))
□◇-pair' ca cb τ = ◇-pair (□-mon ca τ) (cb τ)
□◇-pair : Mon A₂ → ⟨ □ (⟨ e₁ ⟩ A₁) ⊙ □ (⟨ e₂ ⟩ A₂) ⟩→̇ □ (⟨ e₂ + e₁ ⟩ (A₁ ×̂ A₂))
□◇-pair mB ca cb τ = join $
◇-map! (λ τ₁ b → ◇-map! (λ τ₂ a → a , mB b τ₂) (ca (⊆-trans τ τ₁))) (cb τ)
◇□-pair' : ⟨ ⟨ e₁ ⟩ (□ A₁) ⊙ □ (⟨ e₂ ⟩ (□ A₂)) ⟩→̇ ⟨ e₁ + e₂ ⟩ (□ (A₁ ×̂ A₂))
◇□-pair' ca cb = join (◇-map! (λ τ a → ◇-map! (λ τ₁ b {_} τ₂ → a (⊆-trans τ₁ τ₂) , b τ₂) (cb τ)) ca)
-- Without the abstraction over {_}, there is an incomprehensible error.
◇□-pair : ⟨ □ (⟨ e₁ ⟩ (□ A₁)) ⊙ ⟨ e₂ ⟩ (□ A₂) ⟩→̇ ⟨ e₂ + e₁ ⟩ (□ (A₁ ×̂ A₂))
◇□-pair ca cb = join (◇-map! (λ τ b → ◇-map! (λ τ₁ a {_} τ₂ → a τ₂ , b (⊆-trans τ₁ τ₂)) (ca τ)) cb)
-- Without the abstraction over {_}, there is an incomprehensible error.
-- Runnability
Run : (B : NSet) → Set
Run B = ∀{e₁ e₂} → ⟨ e₁ ⟩ (B e₂) →̇ B (e₁ + e₂)
-- Negative ISets are runnable
◇-run : Run (◇ A)
◇-run = join
Π-run : (∀ i → Run (Bs i)) → Run (Πⁿ I Bs)
Π-run f c i = f i (◇-map (_$ i) c)
-- Π-run f x i = Π-map {!λ j → f j!} {!!} {!!}
-- Π-run f = {!Π-map f!} ∘ ◇-record
⇒-run : Mon A → Run B → Run (A ⇒ⁿ B)
⇒-run {B = B} mA rB f = rB ∘ ◇-fun {B = B} mA f
-- Bind for the ◇ monad
◇-elim : Run B → (A →̇ B e₂) → ⟨ e₁ ⟩ A →̇ B (e₁ + e₂)
◇-elim rB f = rB ∘ ◇-map f
◇-elim! : Run B → ⟨ □ (A ⇒̂ B e₂) ⊙ ⟨ e₁ ⟩ A ⟩→̇ B (e₁ + e₂)
◇-elim! rB f = rB ∘ ◇-map! f
◇-elim-□ : Run B → ⟨ □ (A ⇒̂ B e₂) ⊙ □ (⟨ e₁ ⟩ A) ⟩→̇ □ (B (e₁ + e₂))
◇-elim-□ {B = B} rB f c = □-map (uncurry (◇-elim! {B = B} rB)) (□-pair (□-mon f) c)
◇-elim-□-alt : Run B → ⟨ □ (A ⇒̂ B e₂) ⊙ □ (⟨ e₁ ⟩ A) ⟩→̇ □ (B (e₁ + e₂))
◇-elim-□-alt {B = B} rB f c τ = ◇-elim! {B = B} rB (□-mon f τ) (c τ)
bind! : Mon C → Run B → (C →̇ ⟨ e₁ ⟩ A) → (C →̇ (A ⇒̂ B e₂)) → C →̇ B (e₁ + e₂)
bind! {B = B} mC rB f k γ = ◇-elim! {B = B} rB (λ τ a → k (mC γ τ) a) (f γ)
-- Type interpretation
------------------------------------------------------------------------
mutual
⟦_⟧⁺ : Ty⁺ → PSet
⟦ base o ⟧⁺ = base o ∈_
⟦ P₁ ×̇ P₂ ⟧⁺ = ⟦ P₁ ⟧⁺ ×̂ ⟦ P₂ ⟧⁺
⟦ Σ̇ I P ⟧⁺ = Σ̂ I λ i → ⟦ P i ⟧⁺
⟦ [ e ] N ⟧⁺ = □ (⟦ N ⟧⁻ e)
⟦_⟧⁻ : Ty⁻ → NSet
⟦ ◇̇ P ⟧⁻ = ◇ ⟦ P ⟧⁺
⟦ Π̇ I N ⟧⁻ = Πⁿ I λ i → ⟦ N i ⟧⁻
⟦ P ⇒̇ N ⟧⁻ = ⟦ P ⟧⁺ ⇒ⁿ ⟦ N ⟧⁻
⟦_⟧ᶜ : Cxt → PSet
⟦_⟧ᶜ Γ Δ = All (λ P → ⟦ P ⟧⁺ Δ) Γ
-- ⟦ [] ⟧ᶜ = 1̂
-- ⟦ P ∷ Γ ⟧ᶜ = ⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺
-- Positive types are monotone.
mon⁺ : (P : Ty⁺) → Mon ⟦ P ⟧⁺
mon⁺ (base o) = monVar
mon⁺ (P₁ ×̇ P₂) = ×-mon (mon⁺ P₁) (mon⁺ P₂)
mon⁺ (Σ̇ I P) = Σ-mon (mon⁺ ∘ P)
mon⁺ ([ e ] N) = □-mon
monᶜ : (Γ : Cxt) → Mon ⟦ Γ ⟧ᶜ
monᶜ Γ γ τ = All.map (λ {P} v → mon⁺ P v τ) γ
-- Negative types are runnable.
run⁻ : (N : Ty⁻) → Run ⟦ N ⟧⁻
run⁻ (◇̇ P) = ◇-run
run⁻ (Π̇ I N) = Π-run (run⁻ ∘ N)
run⁻ (P ⇒̇ N) = ⇒-run {B = ⟦ N ⟧⁻} (mon⁺ P) (run⁻ N)
-- monᶜ [] = 1-mon
-- monᶜ (P ∷ Γ) = ×-mon (monᶜ Γ) (mon⁺ P)
-- Interpretation
------------------------------------------------------------------------
mutual
⦅_⦆⁺ : Val P Γ → ⟦ Γ ⟧ᶜ →̇ ⟦ P ⟧⁺
⦅ var x ⦆⁺ = λ γ → All.lookup γ x
⦅ pair v₁ v₂ ⦆⁺ = < ⦅ v₁ ⦆⁺ , ⦅ v₂ ⦆⁺ >
⦅ inj i v ⦆⁺ = (i ,_) ∘ ⦅ v ⦆⁺
⦅ thunk t ⦆⁺ = □-intro (monᶜ _) ⦅ t ⦆⁻
λ⦅_⦆⁻ : Comp e N (P ∷ Γ) → ⟦ Γ ⟧ᶜ →̇ ⟦ P ⇒̇ N ⟧⁻ e
λ⦅ t ⦆⁻ γ a = ⦅ t ⦆⁻ (a ∷ γ)
⦅_⦆⁻ : Comp e N Γ → ⟦ Γ ⟧ᶜ →̇ ⟦ N ⟧⁻ e
⦅ ret v ⦆⁻ = return ∘ ⦅ v ⦆⁺
⦅ rec t ⦆⁻ = flip λ i → {! ⦅ t i ⦆⁻ !} -- need effect subsumption es i ≤ sup es
⦅ abs t ⦆⁻ = λ⦅ t ⦆⁻
⦅ split v t ⦆⁻ γ = let (a₁ , a₂) = ⦅ v ⦆⁺ γ in ⦅ t ⦆⁻ (a₂ ∷ (a₁ ∷ γ))
⦅ case v t ⦆⁻ γ = let (i , a) = ⦅ v ⦆⁺ γ in {! ⦅ t i ⦆⁻ (a ∷ γ) !} -- eff sub
⦅ bind {Γ = Γ} {N = N} t t₁ ⦆⁻ = bind! {B = ⟦ N ⟧⁻} (monᶜ Γ) (run⁻ N) ⦅ t ⦆⁻ λ⦅ t₁ ⦆⁻
⦅ force v ⦆⁻ = extract ∘ ⦅ v ⦆⁺
⦅ prj i t ⦆⁻ = (_$ i) ∘ ⦅ t ⦆⁻
⦅ app t v ⦆⁻ = ⦅ t ⦆⁻ ˢ ⦅ v ⦆⁺
⦅ letv v t ⦆⁻ = λ⦅ t ⦆⁻ ˢ ⦅ v ⦆⁺
-- Reflection and reification
mutual
fresh□◇□ : ∀ P {Γ} → ⟪ P ⟫ (□ (⟨ ∅ ⟩ (□ ⟦ P ⟧⁺))) Γ
fresh□◇□ P = reflect⁺□ P ∘ monVar here!
fresh□ : ∀ P {Γ} → ⟪ P ⟫ (□ (⟨ ∅ ⟩ ⟦ P ⟧⁺)) Γ
fresh□ P = ◇-map extract ∘ reflect⁺□ P ∘ monVar here!
fresh□ P = reflect⁺ P ∘ monVar here!
fresh : ∀ {P Γ} → ⟪ P ⟫ (⟨ ∅ ⟩ ⟦ P ⟧⁺) Γ
fresh {P} = ◇-map extract (reflect⁺□ P here!)
fresh {P} = reflect⁺ P here!
fresh◇ : ∀ {P Γ} → ⟪ P ⟫ (⟨ ∅ ⟩ (□ ⟦ P ⟧⁺)) Γ
fresh◇ {P} = reflect⁺□ P here!
fresh◇ {P} = ◇-map (mon⁺ P) fresh
-- saves us use of Mon P in freshᶜ
reflect⁺□ : (P : Ty⁺) → (P ∈_) →̇ (⟨ ∅ ⟩ (□ ⟦ P ⟧⁺))
reflect⁺□ (base o) x = return (monVar x)
reflect⁺□ (P₁ ×̇ P₂) x = split x (◇□-pair (reflect⁺□ P₁ ∘ monVar (there here!)) fresh◇)
reflect⁺□ (Σ̇ I Ps) x = case x λ i → ◇-map (□-map (i ,_)) fresh◇
reflect⁺□ ([ e ] N) x = return (□-mon (reflect⁻ N ∘ force ∘ monVar x))
reflect⁺ : (P : Ty⁺) → (P ∈_) →̇ (⟨ ∅ ⟩ ⟦ P ⟧⁺)
reflect⁺ (base o) x = return x
reflect⁺ (P₁ ×̇ P₂) x = split x (□-weak (fresh□ P₁) ⋉ fresh◇)
reflect⁺ (Σ̇ I Ps) x = case x λ i → ◇-map (i ,_) fresh
reflect⁺ ([ e ] N) x = return λ τ → reflect⁻ N (force (monVar x τ))
reflect⁻ : (N : Ty⁻) → Ne e N →̇ ⟦ N ⟧⁻ e
reflect⁻ (◇̇ P) u = bind u fresh
reflect⁻ (Π̇ I Ns) u = λ i → reflect⁻ (Ns i) (prj i u)
reflect⁻ (P ⇒̇ N) u = λ a → reflect⁻ N (app u (reify⁺ P a))
reify⁺ : (P : Ty⁺) → ⟦ P ⟧⁺ →̇ NVal P
reify⁺ (base o) = var
reify⁺ (P₁ ×̇ P₂) (a₁ , a₂) = pair (reify⁺ P₁ a₁) (reify⁺ P₂ a₂)
reify⁺ (Σ̇ I Ps) (i , a ) = inj i (reify⁺ (Ps i) a)
reify⁺ ([ e ] N) a = thunk (reify⁻ N a)
reify⁻ : (N : Ty⁻) → □ (⟦ N ⟧⁻ e) →̇ Nf e N
reify⁻ (◇̇ P) f = ret (◇-map (reify⁺ P) (extract f))
reify⁻ {e = e} (Π̇ I Ns) f = rec {es = λ i → e} λ i → reify⁻ (Ns i) (□-map (_$ i) f)
reify⁻ (P ⇒̇ N) f = abs $ reify⁻ N $ ◇-elim-□ {B = ⟦ N ⟧⁻} (run⁻ N) (□-weak f) $ fresh□ P
ext : (⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺) →̇ ⟦ P ∷ Γ ⟧ᶜ
ext (γ , a) = a ∷ γ
◇-ext : ⟨ e ⟩ (⟦ Γ ⟧ᶜ ×̂ ⟦ P ⟧⁺) →̇ ⟨ e ⟩ ⟦ P ∷ Γ ⟧ᶜ
◇-ext = ◇-map ext
-- Without the use of ◇-mon!
freshᶜ : (Γ : Cxt) → □ (⟨ ∅ ⟩ ⟦ Γ ⟧ᶜ) Γ
freshᶜ [] = λ τ → return []
freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair' (□-weak (freshᶜ Γ)) (fresh□◇□ P)
freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair (mon⁺ P) (□-weak (freshᶜ Γ)) (fresh□ P)
freshᶜ (P ∷ Γ) = ◇-ext ∘ □◇-pair' (□-weak (freshᶜ Γ)) (◇-map (mon⁺ P) ∘ (fresh□ P))
freshᶜ (P ∷ Γ) = ◇-ext ∘ λ τ →
(□-weak (□-mon (freshᶜ Γ)) τ)
⋉ ◇-map (mon⁺ P) (fresh□ P τ)
norm : Comp e N →̇ Nf e N
norm {N = N} {Γ = Γ} t = reify⁻ N $ □-map (run⁻ N ∘ ◇-map ⦅ t ⦆⁻) $ freshᶜ Γ
norm {N = N} {Γ = Γ} t = reify⁻ N $ run⁻ N ∘ ◇-map ⦅ t ⦆⁻ ∘ freshᶜ Γ
-- -}
-- -}
-- -}
-- -}
-- -}
-- -}
| 29.858144 | 100 | 0.436565 |
c50ffa5cd957bd24dae5e6d58f6dbd39d08d4d60 | 568 | agda | Agda | archive/agda-3/src/Test/Test5.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | archive/agda-3/src/Test/Test5.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | 1 | 2019-04-29T00:35:04.000Z | 2019-05-11T23:33:04.000Z | archive/agda-3/src/Test/Test5.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null |
open import Everything
module Test.Test5
{𝔵} {𝔛 : Ø 𝔵}
{𝔞} {𝔒₁ : 𝔛 → Ø 𝔞}
{𝔟} {𝔒₂ : 𝔛 → Ø 𝔟}
{ℓ}
{ℓ̇} (_↦_ : ∀ {x} → 𝔒₂ x → 𝔒₂ x → Ø ℓ̇)
⦃ _ : [ExtensibleType] _↦_ ⦄
⦃ _ : Smap!.class (Arrow 𝔒₁ 𝔒₂) (Extension 𝔒₂) ⦄
⦃ _ : Surjextensionality!.class (Arrow 𝔒₁ 𝔒₂) (Pointwise _↦_) (Extension 𝔒₂) (Pointwise _↦_) ⦄
-- ⦃ _ : [𝓢urjectivity] (Arrow 𝔒₁ 𝔒₂) (Extension $ ArrowExtensionṖroperty ℓ 𝔒₁ 𝔒₂ _↦_) ⦄
where
test[∙] : ∀ {x y} → ArrowExtensionṖroperty ℓ 𝔒₁ 𝔒₂ _↦_ x → Arrow 𝔒₁ 𝔒₂ x y → ArrowExtensionṖroperty ℓ 𝔒₁ 𝔒₂ _↦_ y
test[∙] P f = f ◃ P
| 33.411765 | 117 | 0.575704 |
4a22e3e65870ba8d94c94a58f73c60777a14a112 | 8,493 | agda | Agda | src/Tactic/Nat/Simpl/Lemmas.agda | L-TChen/agda-prelude | 158d299b1b365e186f00d8ef5b8c6844235ee267 | [
"MIT"
] | 111 | 2015-01-05T11:28:15.000Z | 2022-02-12T23:29:26.000Z | src/Tactic/Nat/Simpl/Lemmas.agda | L-TChen/agda-prelude | 158d299b1b365e186f00d8ef5b8c6844235ee267 | [
"MIT"
] | 59 | 2016-02-09T05:36:44.000Z | 2022-01-14T07:32:36.000Z | src/Tactic/Nat/Simpl/Lemmas.agda | L-TChen/agda-prelude | 158d299b1b365e186f00d8ef5b8c6844235ee267 | [
"MIT"
] | 24 | 2015-03-12T18:03:45.000Z | 2021-04-22T06:10:41.000Z |
module Tactic.Nat.Simpl.Lemmas where
open import Prelude
open import Tactic.Nat.NF
open import Tactic.Nat.Exp
open import Container.Bag
open import Tactic.Nat.Auto
open import Prelude.Nat.Properties
open import Container.List.Properties
open import Tactic.Nat.Auto.Lemmas
product1-sound : ∀ xs → product1 xs ≡ productR xs
product1-sound [] = refl
product1-sound (x ∷ xs)
rewrite sym (cong (λ x → foldl _*_ x xs) (mul-one-r x))
| foldl-assoc _*_ mul-assoc x 1 xs
| foldl-foldr _*_ 1 mul-assoc add-zero-r mul-one-r xs
= refl
map-eq : ∀ {c b} {A : Set c} {B : Set b} (f g : A → B) →
(∀ x → f x ≡ g x) → ∀ xs → map f xs ≡ map g xs
map-eq f g f=g [] = refl
map-eq f g f=g (x ∷ xs) rewrite f=g x | map-eq f g f=g xs = refl
fst-*** : ∀ {a b} {A₁ A₂ : Set a} {B₁ B₂ : Set b}
(f : A₁ → B₁) (g : A₂ → B₂) (p : A₁ × A₂) →
fst ((f *** g) p) ≡ f (fst p)
fst-*** f g (x , y) = refl
snd-*** : ∀ {a b} {A₁ A₂ : Set a} {B₁ B₂ : Set b}
(f : A₁ → B₁) (g : A₂ → B₂) (p : A₁ × A₂) →
snd ((f *** g) p) ≡ g (snd p)
snd-*** f g (x , y) = refl
eta : ∀ {a b} {A : Set a} {B : Set b} (p : A × B) → p ≡ (fst p , snd p)
eta (x , y) = refl
private
shuffle₁ : (a b c : Nat) → a + (b + c) ≡ b + (a + c)
shuffle₁ a b c = auto
module _ {Atom : Set} {{_ : Ord Atom}} where
NFEqS : NF Atom × NF Atom → Env Atom → Set
NFEqS (nf₁ , nf₂) ρ = ⟦ nf₁ ⟧ns ρ ≡ ⟦ nf₂ ⟧ns ρ
NFEq : NF Atom × NF Atom → Env Atom → Set
NFEq (nf₁ , nf₂) ρ = ⟦ nf₁ ⟧n ρ ≡ ⟦ nf₂ ⟧n ρ
ts-sound : ∀ x (ρ : Env Atom) → ⟦ x ⟧ts ρ ≡ ⟦ x ⟧t ρ
ts-sound (0 , x) ρ = mul-zero-r (product1 (map ρ x))
ts-sound (1 , x) ρ = product1-sound (map ρ x) ⟨≡⟩ʳ add-zero-r _
ts-sound (suc (suc i) , x) ρ
rewrite sym (product1-sound (map ρ x))
= auto
private
et : Env Atom → Nat × Tm Atom → Nat
et = flip ⟦_⟧t
ets : Env Atom → Nat × Tm Atom → Nat
ets = flip ⟦_⟧ts
plus-nf : Nat → Env Atom → NF Atom → Nat
plus-nf = λ a ρ xs → a + ⟦ xs ⟧n ρ
ns-sound : ∀ nf (ρ : Env Atom) → ⟦ nf ⟧ns ρ ≡ ⟦ nf ⟧n ρ
ns-sound [] ρ = refl
ns-sound (x ∷ nf) ρ
rewrite sym (foldl-map-fusion _+_ (ets ρ) (ets ρ x) nf)
| ts-sound x ρ
| map-eq (ets ρ) (et ρ) (flip ts-sound ρ) nf
| sym (foldl-foldr _+_ 0 add-assoc (λ _ → refl) add-zero-r (map (et ρ) nf))
| sym (foldl-assoc _+_ add-assoc (et ρ x) 0 (map (et ρ) nf))
| add-zero-r (et ρ x)
= refl
private
lem-sound : ∀ a b ρ f g (xs : NF Atom × NF Atom) →
a + ⟦ fst ((f *** g) xs) ⟧n ρ ≡ b + ⟦ snd ((f *** g) xs) ⟧n ρ →
a + ⟦ f (fst xs) ⟧n ρ ≡ b + ⟦ g (snd xs) ⟧n ρ
lem-sound a b ρ f g xs H =
cong (plus-nf a ρ) (fst-*** f g xs)
ʳ⟨≡⟩ H
⟨≡⟩ cong (plus-nf b ρ) (snd-*** f g xs)
cancel-sound′ : ∀ a b nf₁ nf₂ (ρ : Env Atom) →
a + ⟦ fst (cancel nf₁ nf₂) ⟧n ρ ≡ b + ⟦ snd (cancel nf₁ nf₂) ⟧n ρ →
a + ⟦ nf₁ ⟧n ρ ≡ b + ⟦ nf₂ ⟧n ρ
cancel-sound′ a b [] [] ρ H = H
cancel-sound′ a b [] (x ∷ nf₂) ρ H = H
cancel-sound′ a b (x ∷ nf₁) [] ρ H = H
cancel-sound′ a b ((i , x) ∷ nf₁) ((j , y) ∷ nf₂) ρ H
with cancel-sound′ (a + et ρ (i , x)) b nf₁ ((j , y) ∷ nf₂) ρ | compare x y
... | ih | less _ = add-assoc a _ _ ⟨≡⟩ ih
(add-assoc a _ _ ʳ⟨≡⟩ lem-sound a b ρ (_∷_ (i , x)) id (cancel nf₁ ((j , y) ∷ nf₂)) H)
... | _ | greater _ =
cancel-sound′ a (b + et ρ (j , y)) ((i , x) ∷ nf₁) nf₂ ρ
(lem-sound a b ρ id (_∷_ (j , y)) (cancel ((i , x) ∷ nf₁) nf₂) H ⟨≡⟩ add-assoc b _ _)
⟨≡⟩ʳ add-assoc b _ _
cancel-sound′ a b ((i , x) ∷ nf₁) ((j , .x) ∷ nf₂) ρ H | _ | equal refl
with compare i j
cancel-sound′ a b ((i , x) ∷ nf₁) ((.(suc k + i) , .x) ∷ nf₂) ρ H | _ | equal refl | less (diff! k) =
shuffle₁ a (et ρ (i , x)) _
⟨≡⟩ cong (et ρ (i , x) +_) (cancel-sound′ a (b + et ρ (suc k , x)) nf₁ nf₂ ρ
(lem-sound a b ρ id (_∷_ (suc k , x)) (cancel nf₁ nf₂) H ⟨≡⟩ add-assoc b _ _))
⟨≡⟩ auto
cancel-sound′ a b ((.(suc k + j) , x) ∷ nf₁) ((j , .x) ∷ nf₂) ρ H | _ | equal refl | greater (diff! k) =
sym (shuffle₁ b (et ρ (j , x)) _
⟨≡⟩ cong (et ρ (j , x) +_) (sym (cancel-sound′ (a + et ρ (suc k , x)) b nf₁ nf₂ ρ
(add-assoc a _ _ ʳ⟨≡⟩ lem-sound a b ρ (_∷_ (suc k , x)) id (cancel nf₁ nf₂) H)))
⟨≡⟩ auto)
cancel-sound′ a b ((i , x) ∷ nf₁) ((.i , .x) ∷ nf₂) ρ H | _ | equal refl | equal refl =
shuffle₁ a (et ρ (i , x)) _
⟨≡⟩ cong (et ρ (i , x) +_) (cancel-sound′ a b nf₁ nf₂ ρ H)
⟨≡⟩ shuffle₁ (et ρ (i , x)) b _
cancel-sound-s′ : ∀ a b nf₁ nf₂ (ρ : Env Atom) →
a + ⟦ fst (cancel nf₁ nf₂) ⟧ns ρ ≡ b + ⟦ snd (cancel nf₁ nf₂) ⟧ns ρ →
a + ⟦ nf₁ ⟧ns ρ ≡ b + ⟦ nf₂ ⟧ns ρ
cancel-sound-s′ a b nf₁ nf₂ ρ eq =
(a +_) $≡ ns-sound nf₁ ρ ⟨≡⟩
cancel-sound′ a b nf₁ nf₂ ρ
((a +_) $≡ ns-sound (fst (cancel nf₁ nf₂)) ρ ʳ⟨≡⟩
eq ⟨≡⟩ (b +_) $≡ ns-sound (snd (cancel nf₁ nf₂)) ρ) ⟨≡⟩ʳ
(b +_) $≡ ns-sound nf₂ ρ
cancel-sound : ∀ nf₁ nf₂ ρ → NFEqS (cancel nf₁ nf₂) ρ → NFEq (nf₁ , nf₂) ρ
cancel-sound nf₁ nf₂ ρ H rewrite cong (λ p → NFEqS p ρ) (eta (cancel nf₁ nf₂)) =
(cancel-sound′ 0 0 nf₁ nf₂ ρ
(ns-sound (fst (cancel nf₁ nf₂)) ρ
ʳ⟨≡⟩ H ⟨≡⟩
ns-sound (snd (cancel nf₁ nf₂)) ρ))
private
prod : Env Atom → List Atom → Nat
prod ρ x = productR (map ρ x)
private
lem-complete : ∀ a b ρ f g (xs : NF Atom × NF Atom) →
a + ⟦ f (fst xs) ⟧n ρ ≡ b + ⟦ g (snd xs) ⟧n ρ →
a + ⟦ fst ((f *** g) xs) ⟧n ρ ≡ b + ⟦ snd ((f *** g) xs) ⟧n ρ
lem-complete a b ρ f g xs H =
cong (plus-nf a ρ) (fst-*** f g xs)
⟨≡⟩ H
⟨≡⟩ʳ cong (plus-nf b ρ) (snd-*** f g xs)
cancel-complete′ : ∀ a b nf₁ nf₂ (ρ : Env Atom) →
a + ⟦ nf₁ ⟧n ρ ≡ b + ⟦ nf₂ ⟧n ρ →
a + ⟦ fst (cancel nf₁ nf₂) ⟧n ρ ≡ b + ⟦ snd (cancel nf₁ nf₂) ⟧n ρ
cancel-complete′ a b [] [] ρ H = H
cancel-complete′ a b [] (x ∷ nf₂) ρ H = H
cancel-complete′ a b (x ∷ nf₁) [] ρ H = H
cancel-complete′ a b ((i , x) ∷ nf₁) ((j , y) ∷ nf₂) ρ H
with cancel-complete′ (a + et ρ (i , x)) b nf₁ ((j , y) ∷ nf₂) ρ | compare x y
... | ih | less lt =
lem-complete a b ρ (_∷_ (i , x)) id (cancel nf₁ ((j , y) ∷ nf₂))
(add-assoc a _ _
⟨≡⟩ ih
(add-assoc a _ _ ʳ⟨≡⟩ H))
... | _ | greater _ =
lem-complete a b ρ id (_∷_ (j , y)) (cancel ((i , x) ∷ nf₁) nf₂)
(cancel-complete′ a (b + et ρ (j , y)) ((i , x) ∷ nf₁) nf₂ ρ
(H ⟨≡⟩ add-assoc b _ _)
⟨≡⟩ʳ add-assoc b _ _)
cancel-complete′ a b ((i , x) ∷ nf₁) ((j , .x) ∷ nf₂) ρ H | _ | equal refl with compare i j
cancel-complete′ a b ((i , x) ∷ nf₁) ((.(suc (k + i)) , .x) ∷ nf₂) ρ H | _ | equal refl | less (diff! k) =
lem-complete a b ρ id (_∷_ (suc k , x)) (cancel nf₁ nf₂)
(cancel-complete′ a (b + suc k * prod ρ x) nf₁ nf₂ ρ
(add-inj₂ (i * prod ρ x) _ _
(shuffle₁ (i * prod ρ x) a _
⟨≡⟩ H ⟨≡⟩ auto))
⟨≡⟩ʳ add-assoc b _ _)
cancel-complete′ a b ((.(suc (k + j)) , x) ∷ nf₁) ((j , .x) ∷ nf₂) ρ H | _ | equal refl | greater (diff! k) =
lem-complete a b ρ (_∷_ (suc k , x)) id (cancel nf₁ nf₂)
(add-assoc a _ _ ⟨≡⟩
cancel-complete′ (a + suc k * prod ρ x) b nf₁ nf₂ ρ
(add-inj₂ (j * prod ρ x) _ _
(sym (shuffle₁ (j * prod ρ x) b _ ⟨≡⟩ʳ
auto ʳ⟨≡⟩ H))))
cancel-complete′ a b ((i , x) ∷ nf₁) ((.i , .x) ∷ nf₂) ρ H | _ | equal refl | equal refl =
cancel-complete′ a b nf₁ nf₂ ρ
(add-inj₂ (i * prod ρ x) _ _
(shuffle₁ a (i * prod ρ x) _ ʳ⟨≡⟩ H ⟨≡⟩ shuffle₁ b (i * prod ρ x) _))
cancel-complete-s′ : ∀ a b nf₁ nf₂ (ρ : Env Atom) →
a + ⟦ nf₁ ⟧ns ρ ≡ b + ⟦ nf₂ ⟧ns ρ →
a + ⟦ fst (cancel nf₁ nf₂) ⟧ns ρ ≡ b + ⟦ snd (cancel nf₁ nf₂) ⟧ns ρ
cancel-complete-s′ a b nf₁ nf₂ ρ eq =
(a +_) $≡ ns-sound (fst (cancel nf₁ nf₂)) ρ ⟨≡⟩
cancel-complete′ a b nf₁ nf₂ ρ
((a +_) $≡ ns-sound nf₁ ρ ʳ⟨≡⟩
eq ⟨≡⟩ (b +_) $≡ ns-sound nf₂ ρ) ⟨≡⟩ʳ
(b +_) $≡ ns-sound (snd (cancel nf₁ nf₂)) ρ
cancel-complete : ∀ nf₁ nf₂ ρ → NFEq (nf₁ , nf₂) ρ → NFEqS (cancel nf₁ nf₂) ρ
cancel-complete nf₁ nf₂ ρ H rewrite cong (λ p → NFEqS p ρ) (eta (cancel nf₁ nf₂)) =
ns-sound (fst (cancel nf₁ nf₂)) ρ
⟨≡⟩ cancel-complete′ 0 0 nf₁ nf₂ ρ H
⟨≡⟩ʳ ns-sound (snd (cancel nf₁ nf₂)) ρ
| 42.044554 | 111 | 0.477334 |
238280a4272d90264c6c87906d6c70529f5026d1 | 3,587 | agda | Agda | LibraBFT/Abstract/System.agda | lisandrasilva/bft-consensus-agda-1 | b7dd98dd90d98fbb934ef8cb4f3314940986790d | [
"UPL-1.0"
] | null | null | null | LibraBFT/Abstract/System.agda | lisandrasilva/bft-consensus-agda-1 | b7dd98dd90d98fbb934ef8cb4f3314940986790d | [
"UPL-1.0"
] | null | null | null | LibraBFT/Abstract/System.agda | lisandrasilva/bft-consensus-agda-1 | b7dd98dd90d98fbb934ef8cb4f3314940986790d | [
"UPL-1.0"
] | null | null | null | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Abstract.Types
-- This module defines and abstract view if a system, encompassing only a predicate for Records,
-- another for Votes and a proof that, if a Vote is included in a QC in the system, then and
-- equivalent Vote is also in the system. It further defines a notion "Complete", which states that
-- if an honest vote is included in a QC in the system, then there is a RecordChain up to the block
-- that the QC extends, such that all Records in the RecordChain are also in the system. The latter
-- property is used to extend correctness conditions on RecordChains to correctness conditions that
-- require only a short suffix of a RecordChain.
module LibraBFT.Abstract.System
(𝓔 : EpochConfig)
(UID : Set)
(_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁))
(𝓥 : VoteEvidence 𝓔 UID)
where
open import LibraBFT.Abstract.Records 𝓔 UID _≟UID_ 𝓥
open import LibraBFT.Abstract.Records.Extends 𝓔 UID _≟UID_ 𝓥
open import LibraBFT.Abstract.RecordChain 𝓔 UID _≟UID_ 𝓥
-- Since the invariants we want to specify (votes-once and locked-round-rule),
-- are predicates over a /System State/, we must factor out the necessary
-- functionality.
--
-- An /AbsSystemState/ supports a few different notions; namely,
record AbsSystemState (ℓ : Level) : Set (ℓ+1 ℓ) where
field
-- A notion of membership of records
InSys : Record → Set ℓ
-- A predicate about whether votes have been transfered
-- amongst participants
HasBeenSent : Vote → Set ℓ
-- Such that, the votes that belong to honest participants inside a
-- QC that exists in the system must have been sent
∈QC⇒HasBeenSent : ∀{q α} → InSys (Q q) → Meta-Honest-Member 𝓔 α
→ (va : α ∈QC q) → HasBeenSent (∈QC-Vote q va)
module All-InSys-props {ℓ}(InSys : Record → Set ℓ) where
All-InSys : ∀ {o r} → RecordChainFrom o r → Set ℓ
All-InSys rc = {r' : Record} → r' ∈RC-simple rc → InSys r'
All-InSys⇒last-InSys : ∀ {r} → {rc : RecordChain r} → All-InSys rc → InSys r
All-InSys⇒last-InSys {rc = empty} a∈s = a∈s here
All-InSys⇒last-InSys {r = r'} {step {r' = .r'} rc ext} a∈s = a∈s here
All-InSys-unstep : ∀ {o r r' rc ext } → All-InSys (step {o} {r} {r'} rc ext) → All-InSys rc
All-InSys-unstep {ext = ext} a∈s r'∈RC = a∈s (there ext r'∈RC)
All-InSys-step : ∀ {r r' }{rc : RecordChain r}
→ All-InSys rc → (ext : r ← r') → InSys r'
→ All-InSys (step rc ext)
All-InSys-step hyp ext r here = r
All-InSys-step hyp ext r (there .ext r∈rc) = hyp r∈rc
-- We say an /AbsSystemState/ is /Complete/ when we can construct a record chain
-- from any vote by an honest participant. This essentially says that whenever
-- an honest participant casts a vote, they have checked that the voted-for
-- block is in a RecordChain whose records are all in the system.
Complete : ∀{ℓ} → AbsSystemState ℓ → Set ℓ
Complete sys = ∀{α q }
→ Meta-Honest-Member 𝓔 α
→ (va : α ∈QC q)
→ InSys (Q q)
→ ∃[ b ] (B b ← Q q
× Σ (RecordChain (B b))
(λ rc → All-InSys rc))
where open AbsSystemState sys
open All-InSys-props InSys
| 44.8375 | 111 | 0.638974 |
209f81d43eec8e1809188b41a32aec02dec25fd7 | 317 | agda | Agda | test/interaction/Highlighting.agda | larrytheliquid/agda | 477c8c37f948e6038b773409358fd8f38395f827 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | test/interaction/Highlighting.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/interaction/Highlighting.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | 1 | 2022-03-12T11:35:18.000Z | 2022-03-12T11:35:18.000Z | module Highlighting where
Set-one : Set₂
Set-one = Set₁
record R (A : Set) : Set-one where
constructor con
field X : Set
F : Set → Set → Set
F A B = B
field P : F A X → Set
Q : F A X → Set
Q = Q
postulate P : _
open import Highlighting.M
data D (A : Set) : Set-one where
d : let X = D in X A
| 12.68 | 34 | 0.589905 |
cb70662292bf43ed1bd6237d7088a8530c954fff | 339 | agda | Agda | test/Compiler/simple/Issue561/Core.agda | zliu41/agda | 73405f70bced057d24dd4bf122d53f9548544aba | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Compiler/simple/Issue561/Core.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Compiler/simple/Issue561/Core.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module Issue561.Core where
postulate Char : Set
{-# BUILTIN CHAR Char #-}
open import Agda.Builtin.IO public
postulate
return : ∀ {a} {A : Set a} → A → IO A
{-# COMPILE GHC return = \_ _ -> return #-}
{-# COMPILE JS return =
function(u0) { return function(u1) { return function(x) { return function(cb) { cb(x); }; }; }; } #-}
| 22.6 | 105 | 0.610619 |
23e22ecd162430b4a8d86a87828a884c47480f20 | 21,739 | agda | Agda | Cubical/HITs/Truncation/Properties.agda | cangiuli/cubical | d103ec455d41cccf9b13a4803e7d3cf462e00067 | [
"MIT"
] | null | null | null | Cubical/HITs/Truncation/Properties.agda | cangiuli/cubical | d103ec455d41cccf9b13a4803e7d3cf462e00067 | [
"MIT"
] | null | null | null | Cubical/HITs/Truncation/Properties.agda | cangiuli/cubical | d103ec455d41cccf9b13a4803e7d3cf462e00067 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Truncation.Properties where
open import Cubical.Data.NatMinusOne
open import Cubical.HITs.Truncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Equiv.PathSplit
open isPathSplitEquiv
open import Cubical.Modalities.Modality
open Modality
open import Cubical.Data.Empty.Base as ⊥ renaming (rec to ⊥rec ; elim to ⊥elim)
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Data.Unit
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.S1
open import Cubical.HITs.Susp
open import Cubical.HITs.Nullification as Null hiding (rec; elim)
open import Cubical.HITs.PropositionalTruncation as PropTrunc
renaming (∥_∥ to ∥_∥₁; ∣_∣ to ∣_∣₁; squash to squash₁) using ()
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂; ∣_∣₂; squash₂)
open import Cubical.HITs.GroupoidTruncation as GpdTrunc using (∥_∥₃; ∣_∣₃; squash₃)
open import Cubical.HITs.2GroupoidTruncation as 2GpdTrunc using (∥_∥₄; ∣_∣₄; squash₄)
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
sphereFill : (n : ℕ) (f : S₊ n → A) → Type _
sphereFill {A = A} n f = Σ[ top ∈ A ] ((x : S₊ n) → top ≡ f x)
isSphereFilled : ℕ → Type ℓ → Type ℓ
isSphereFilled n A = (f : S₊ n → A) → sphereFill n f
isSphereFilled∥∥ : {n : ℕ} → isSphereFilled n (HubAndSpoke A n)
isSphereFilled∥∥ f = (hub f) , (spoke f)
isSphereFilled→isOfHLevel : (n : ℕ) → isSphereFilled n A → isOfHLevel (suc n) A
isSphereFilled→isOfHLevel {A = A} zero h x y = sym (snd (h f) true) ∙ snd (h f) false
where
f : Bool → A
f true = x
f false = y
isSphereFilled→isOfHLevel {A = A} (suc zero) h x y =
J (λ y q → (p : x ≡ y) → q ≡ p) (helper x)
where
helper : (x : A) (p : x ≡ x) → refl ≡ p
helper x p i j =
hcomp (λ k → λ { (i = i0) → h S¹→A .snd base k
; (i = i1) → p j
; (j = i0) → h S¹→A .snd base (i ∨ k)
; (j = i1) → h S¹→A .snd base (i ∨ k)})
(h S¹→A .snd (loop j) i)
where
S¹→A : S¹ → A
S¹→A base = x
S¹→A (loop i) = p i
isSphereFilled→isOfHLevel {A = A} (suc (suc n)) h x y =
isSphereFilled→isOfHLevel (suc n) (helper h x y)
where
helper : {n : ℕ} → isSphereFilled (suc (suc n)) A → (x y : A) → isSphereFilled (suc n) (x ≡ y)
helper {n = n} h x y f = sym (snd (h f') north) ∙ (snd (h f') south) , r
where
f' : Susp (S₊ (suc n)) → A
f' north = x
f' south = y
f' (merid u i) = f u i
r : (s : S₊ (suc n)) → sym (snd (h f') north) ∙ (snd (h f') south) ≡ f s
r s i j = hcomp
(λ k →
λ { (i = i1) → snd (h f') (merid s j) k
; (j = i0) → snd (h f') north (k ∨ (~ i))
; (j = i1) → snd (h f') south k
})
(snd (h f') north (~ i ∧ ~ j))
isOfHLevel→isSphereFilled : (n : ℕ) → isOfHLevel (suc n) A → isSphereFilled n A
isOfHLevel→isSphereFilled zero h f = (f true) , (λ _ → h _ _)
isOfHLevel→isSphereFilled {A = A} (suc zero) h f = (f base) , toPropElim (λ _ → h _ _) refl
isOfHLevel→isSphereFilled {A = A} (suc (suc n)) h =
helper λ x y → isOfHLevel→isSphereFilled (suc n) (h x y)
where
helper : {n : ℕ} → ((x y : A) → isSphereFilled (suc n) (x ≡ y))
→ isSphereFilled (suc (suc n)) A
helper {n = n} h f = f north , r
where
r : (x : S₊ (suc (suc n))) → f north ≡ f x
r north = refl
r south = h (f north) (f south) (λ x → cong f (merid x)) .fst
r (merid x i) j = hcomp (λ k → λ { (i = i0) → f north
; (i = i1) → h (f north) (f south) (λ x → cong f (merid x)) .snd x (~ k) j
; (j = i0) → f north
; (j = i1) → f (merid x i) }) (f (merid x (i ∧ j)))
isOfHLevelTrunc : (n : ℕ) → isOfHLevel n (∥ A ∥ n)
isOfHLevelTrunc zero = isOfHLevelUnit* 0
isOfHLevelTrunc (suc n) = isSphereFilled→isOfHLevel n isSphereFilled∥∥
rec : {n : HLevel}
{B : Type ℓ'} →
isOfHLevel (suc n) B →
(A → B) →
hLevelTrunc (suc n) A →
B
rec h g ∣ x ∣ = g x
rec {n = n} {B = B} hB g (hub f) = isOfHLevel→isSphereFilled n hB (λ x → rec hB g (f x)) .fst
rec {n = n} hB g (spoke f x i) =
isOfHLevel→isSphereFilled n hB (λ x → rec hB g (f x)) .snd x i
elim : {n : ℕ}
{B : ∥ A ∥ (suc n) → Type ℓ'}
(hB : (x : ∥ A ∥ (suc n)) → isOfHLevel (suc n) (B x))
(g : (a : A) → B (∣ a ∣))
(x : ∥ A ∥ (suc n)) →
B x
elim hB g (∣ a ∣ ) = g a
elim {B = B} hB g (hub f) =
isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (elim hB g (f x)) ) .fst
elim {B = B} hB g (spoke f x i) =
toPathP {A = λ i → B (spoke f x (~ i))}
(sym (isOfHLevel→isSphereFilled _ (hB (hub f)) (λ x → subst B (sym (spoke f x)) (elim hB g (f x))) .snd x))
(~ i)
elim2 : {n : ℕ}
{B : ∥ A ∥ (suc n) → ∥ A ∥ (suc n) → Type ℓ'}
(hB : ((x y : ∥ A ∥ (suc n)) → isOfHLevel (suc n) (B x y)))
(g : (a b : A) → B ∣ a ∣ ∣ b ∣)
(x y : ∥ A ∥ (suc n)) →
B x y
elim2 {n = n} hB g = elim (λ _ → isOfHLevelΠ (suc n) (λ _ → hB _ _)) λ a →
elim (λ _ → hB _ _) (λ b → g a b)
elim3 : {n : ℕ}
{B : (x y z : ∥ A ∥ (suc n)) → Type ℓ'}
(hB : ((x y z : ∥ A ∥ (suc n)) → isOfHLevel (suc n) (B x y z)))
(g : (a b c : A) → B (∣ a ∣) ∣ b ∣ ∣ c ∣)
(x y z : ∥ A ∥ (suc n)) →
B x y z
elim3 {n = n} hB g = elim2 (λ _ _ → isOfHLevelΠ (suc n) (hB _ _)) λ a b →
elim (λ _ → hB _ _ _) (λ c → g a b c)
isContr→isContr∥ : (n : ℕ) → isContr A → isContr (∥ A ∥ n)
isContr→isContr∥ zero _ = tt* , (λ _ _ → tt*)
isContr→isContr∥ (suc n) contr = ∣ fst contr ∣ , (elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(λ a i → ∣ snd contr a i ∣))
isOfHLevelMin→isOfHLevel : {n m : ℕ} → isOfHLevel (min n m) A → isOfHLevel n A × isOfHLevel m A
isOfHLevelMin→isOfHLevel {n = zero} {m = m} h = h , isContr→isOfHLevel m h
isOfHLevelMin→isOfHLevel {n = suc n} {m = zero} h = (isContr→isOfHLevel (suc n) h) , h
isOfHLevelMin→isOfHLevel {A = A} {n = suc n} {m = suc m} h =
subst (λ x → isOfHLevel x A) (helper n m)
(isOfHLevelPlus (suc n ∸ (suc (min n m))) h)
, subst (λ x → isOfHLevel x A) ((λ i → m ∸ (minComm n m i) + suc (minComm n m i)) ∙ helper m n)
(isOfHLevelPlus (suc m ∸ (suc (min n m))) h)
where
helper : (n m : ℕ) → n ∸ min n m + suc (min n m) ≡ suc n
helper zero zero = refl
helper zero (suc m) = refl
helper (suc n) zero = cong suc (+-comm n 1)
helper (suc n) (suc m) = +-suc _ _ ∙ cong suc (helper n m)
ΣTruncElim : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {n m : ℕ}
{B : (x : ∥ A ∥ (suc n)) → Type ℓ'}
{C : (Σ[ a ∈ (∥ A ∥ (suc n)) ] (∥ B a ∥ (suc m))) → Type ℓ''}
→ ((x : (Σ[ a ∈ (∥ A ∥ (suc n)) ] (∥ B a ∥ (suc m)))) → isOfHLevel (min (suc n) (suc m)) (C x))
→ ((a : A) (b : B (∣ a ∣)) → C (∣ a ∣ , ∣ b ∣))
→ (x : (Σ[ a ∈ (∥ A ∥ (suc n)) ] (∥ B a ∥ (suc m)))) → (C x)
ΣTruncElim {n = n} {m = m} {B = B} {C = C} hB g (a , b) =
elim {B = λ a → (b : (∥ B a ∥ (suc m))) → C (a , b)}
(λ x → isOfHLevelΠ (suc n) λ b → isOfHLevelMin→isOfHLevel (hB (x , b)) .fst )
(λ a → elim (λ _ → isOfHLevelMin→isOfHLevel (hB (∣ a ∣ , _)) .snd) λ b → g a b)
a b
truncIdempotentIso : (n : ℕ) → isOfHLevel n A → Iso (∥ A ∥ n) A
truncIdempotentIso zero hA = isContr→Iso (isOfHLevelUnit* 0) hA
Iso.fun (truncIdempotentIso (suc n) hA) = rec hA λ a → a
Iso.inv (truncIdempotentIso (suc n) hA) = ∣_∣
Iso.rightInv (truncIdempotentIso (suc n) hA) _ = refl
Iso.leftInv (truncIdempotentIso (suc n) hA) = elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ _ → refl
truncIdempotent≃ : (n : ℕ) → isOfHLevel n A → ∥ A ∥ n ≃ A
truncIdempotent≃ n hA = isoToEquiv (truncIdempotentIso n hA)
truncIdempotent : (n : ℕ) → isOfHLevel n A → ∥ A ∥ n ≡ A
truncIdempotent n hA = ua (truncIdempotent≃ n hA)
HLevelTruncModality : ∀ {ℓ} (n : HLevel) → Modality ℓ
isModal (HLevelTruncModality n) = isOfHLevel n
isModalIsProp (HLevelTruncModality n) = isPropIsOfHLevel n
◯ (HLevelTruncModality n) = hLevelTrunc n
◯-isModal (HLevelTruncModality n) = isOfHLevelTrunc n
η (HLevelTruncModality zero) _ = tt*
η (HLevelTruncModality (suc n)) = ∣_∣
◯-elim (HLevelTruncModality zero) cB _ tt* = cB tt* .fst
◯-elim (HLevelTruncModality (suc n)) = elim
◯-elim-β (HLevelTruncModality zero) cB f a = cB tt* .snd (f a)
◯-elim-β (HLevelTruncModality (suc n)) = λ _ _ _ → refl
◯-=-isModal (HLevelTruncModality zero) x y = (isOfHLevelUnit* 1 x y) , (isOfHLevelUnit* 2 x y _)
◯-=-isModal (HLevelTruncModality (suc n)) = isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n))
-- universal property
univTrunc : ∀ {ℓ} (n : HLevel) {B : TypeOfHLevel ℓ n} → Iso (hLevelTrunc n A → B .fst) (A → B .fst)
univTrunc zero {B , lev} = isContr→Iso (isOfHLevelΠ 0 (λ _ → lev)) (isOfHLevelΠ 0 λ _ → lev)
Iso.fun (univTrunc (suc n) {B , lev}) g a = g ∣ a ∣
Iso.inv (univTrunc (suc n) {B , lev}) = rec lev
Iso.rightInv (univTrunc (suc n) {B , lev}) b = refl
Iso.leftInv (univTrunc (suc n) {B , lev}) b = funExt (elim (λ x → isOfHLevelPath _ lev _ _)
λ a → refl)
-- functorial action
map : {n : HLevel} {B : Type ℓ'} (g : A → B)
→ hLevelTrunc n A → hLevelTrunc n B
map {n = zero} g = λ _ → tt*
map {n = suc n} g = rec (isOfHLevelTrunc _) (λ a → ∣ g a ∣)
mapCompIso : {n : HLevel} {B : Type ℓ'} → (Iso A B) → Iso (hLevelTrunc n A) (hLevelTrunc n B)
mapCompIso {n = zero} {B} _ = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevelUnit* 0)
Iso.fun (mapCompIso {n = (suc n)} g) = map (Iso.fun g)
Iso.inv (mapCompIso {n = (suc n)} g) = map (Iso.inv g)
Iso.rightInv (mapCompIso {n = (suc n)} g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ b → cong ∣_∣ (Iso.rightInv g b)
Iso.leftInv (mapCompIso {n = (suc n)} g) = elim (λ x → isOfHLevelPath _ (isOfHLevelTrunc _) _ _) λ a → cong ∣_∣ (Iso.leftInv g a)
mapId : {n : HLevel} → ∀ t → map {n = n} (idfun A) t ≡ t
mapId {n = 0} tt* = refl
mapId {n = (suc n)} =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) (λ _ → refl)
-- equivalences to prop/set/groupoid truncations
propTruncTrunc1Iso : Iso ∥ A ∥₁ (∥ A ∥ 1)
Iso.fun propTruncTrunc1Iso = PropTrunc.rec (isOfHLevelTrunc 1) ∣_∣
Iso.inv propTruncTrunc1Iso = rec squash₁ ∣_∣₁
Iso.rightInv propTruncTrunc1Iso = elim (λ _ → isOfHLevelPath 1 (isOfHLevelTrunc 1) _ _) (λ _ → refl)
Iso.leftInv propTruncTrunc1Iso = PropTrunc.elim (λ _ → isOfHLevelPath 1 squash₁ _ _) (λ _ → refl)
propTrunc≃Trunc1 : ∥ A ∥₁ ≃ ∥ A ∥ 1
propTrunc≃Trunc1 = isoToEquiv propTruncTrunc1Iso
propTrunc≡Trunc1 : ∥ A ∥₁ ≡ ∥ A ∥ 1
propTrunc≡Trunc1 = ua propTrunc≃Trunc1
setTruncTrunc2Iso : Iso ∥ A ∥₂ (∥ A ∥ 2)
Iso.fun setTruncTrunc2Iso = SetTrunc.rec (isOfHLevelTrunc 2) ∣_∣
Iso.inv setTruncTrunc2Iso = rec squash₂ ∣_∣₂
Iso.rightInv setTruncTrunc2Iso = elim (λ _ → isOfHLevelPath 2 (isOfHLevelTrunc 2) _ _) (λ _ → refl)
Iso.leftInv setTruncTrunc2Iso = SetTrunc.elim (λ _ → isOfHLevelPath 2 squash₂ _ _) (λ _ → refl)
setTrunc≃Trunc2 : ∥ A ∥₂ ≃ ∥ A ∥ 2
setTrunc≃Trunc2 = isoToEquiv setTruncTrunc2Iso
propTrunc≡Trunc2 : ∥ A ∥₂ ≡ ∥ A ∥ 2
propTrunc≡Trunc2 = ua setTrunc≃Trunc2
groupoidTruncTrunc3Iso : Iso ∥ A ∥₃ (∥ A ∥ 3)
Iso.fun groupoidTruncTrunc3Iso = GpdTrunc.rec (isOfHLevelTrunc 3) ∣_∣
Iso.inv groupoidTruncTrunc3Iso = rec squash₃ ∣_∣₃
Iso.rightInv groupoidTruncTrunc3Iso = elim (λ _ → isOfHLevelPath 3 (isOfHLevelTrunc 3) _ _) (λ _ → refl)
Iso.leftInv groupoidTruncTrunc3Iso = GpdTrunc.elim (λ _ → isOfHLevelPath 3 squash₃ _ _) (λ _ → refl)
groupoidTrunc≃Trunc3 : ∥ A ∥₃ ≃ ∥ A ∥ 3
groupoidTrunc≃Trunc3 = isoToEquiv groupoidTruncTrunc3Iso
groupoidTrunc≡Trunc3 : ∥ A ∥₃ ≡ ∥ A ∥ 3
groupoidTrunc≡Trunc3 = ua groupoidTrunc≃Trunc3
2GroupoidTruncTrunc4Iso : Iso ∥ A ∥₄ (∥ A ∥ 4)
Iso.fun 2GroupoidTruncTrunc4Iso = 2GpdTrunc.rec (isOfHLevelTrunc 4) ∣_∣
Iso.inv 2GroupoidTruncTrunc4Iso = rec squash₄ ∣_∣₄
Iso.rightInv 2GroupoidTruncTrunc4Iso = elim (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _) (λ _ → refl)
Iso.leftInv 2GroupoidTruncTrunc4Iso = 2GpdTrunc.elim (λ _ → isOfHLevelPath 4 squash₄ _ _) (λ _ → refl)
2GroupoidTrunc≃Trunc4 : ∥ A ∥₄ ≃ ∥ A ∥ 4
2GroupoidTrunc≃Trunc4 = isoToEquiv 2GroupoidTruncTrunc4Iso
2GroupoidTrunc≡Trunc4 : ∥ A ∥₄ ≡ ∥ A ∥ 4
2GroupoidTrunc≡Trunc4 = ua 2GroupoidTrunc≃Trunc4
isContr→isContrTrunc : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A → isContr (hLevelTrunc n A)
isContr→isContrTrunc zero contr = isOfHLevelUnit* 0
isContr→isContrTrunc (suc n) contr =
∣ fst contr ∣ , (elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → cong ∣_∣ (snd contr a))
truncOfProdIso : (n : ℕ) → Iso (hLevelTrunc n (A × B)) (hLevelTrunc n A × hLevelTrunc n B)
truncOfProdIso 0 = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevel× 0 (isOfHLevelUnit* 0) (isOfHLevelUnit* 0))
Iso.fun (truncOfProdIso (suc n)) = rec (isOfHLevelΣ (suc n) (isOfHLevelTrunc (suc n)) (λ _ → isOfHLevelTrunc (suc n))) λ {(a , b) → ∣ a ∣ , ∣ b ∣}
Iso.inv (truncOfProdIso (suc n)) (a , b) = rec (isOfHLevelTrunc (suc n))
(λ a → rec (isOfHLevelTrunc (suc n))
(λ b → ∣ a , b ∣)
b)
a
Iso.rightInv (truncOfProdIso (suc n)) (a , b) =
elim {B = λ a → Iso.fun (truncOfProdIso (suc n)) (Iso.inv (truncOfProdIso (suc n)) (a , b)) ≡ (a , b)}
(λ _ → isOfHLevelPath (suc n) (isOfHLevelΣ (suc n) (isOfHLevelTrunc (suc n)) (λ _ → isOfHLevelTrunc (suc n))) _ _)
(λ a → elim {B = λ b → Iso.fun (truncOfProdIso (suc n)) (Iso.inv (truncOfProdIso (suc n)) (∣ a ∣ , b)) ≡ (∣ a ∣ , b)}
(λ _ → isOfHLevelPath (suc n) (isOfHLevelΣ (suc n) (isOfHLevelTrunc (suc n)) (λ _ → isOfHLevelTrunc (suc n))) _ _)
(λ b → refl) b) a
Iso.leftInv (truncOfProdIso (suc n)) = elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → refl
---- ∥ Ω A ∥ ₙ ≡ Ω ∥ A ∥ₙ₊₁ ----
{- Proofs of Theorem 7.3.12. and Corollary 7.3.13. in the HoTT book -}
module ΩTrunc where
{- We define the fibration P to show a more general result -}
P : {X : Type ℓ} {n : HLevel} → ∥ X ∥ (2 + n) → ∥ X ∥ (2 + n) → Type ℓ
P {n = n} x y = elim2 (λ _ _ → isOfHLevelTypeOfHLevel (suc n))
(λ a b → ∥ a ≡ b ∥ (suc n) , isOfHLevelTrunc (suc n)) x y .fst
{- We will need P to be of hLevel n + 3 -}
hLevelP : {X : Type ℓ} {n : HLevel} (a b : ∥ X ∥ (2 + n)) → isOfHLevel ((2 + n)) (P a b)
hLevelP {n = n} =
elim2 (λ x y → isProp→isOfHLevelSuc (suc n) (isPropIsOfHLevel (2 + n)))
(λ a b → isOfHLevelSuc (suc n) (isOfHLevelTrunc (suc n)))
{- decode function from P x y to x ≡ y -}
decode-fun : {X : Type ℓ} {n : HLevel} (x y : ∥ X ∥ (2 + n)) → P x y → x ≡ y
decode-fun {n = n} =
elim2 (λ u v → isOfHLevelΠ (2 + n)
(λ _ → isOfHLevelSuc (2 + n) (isOfHLevelTrunc (2 + n)) u v))
decode*
where
decode* : ∀ {n : HLevel} (u v : B)
→ P {n = n} ∣ u ∣ ∣ v ∣ → Path (∥ B ∥ (2 + n)) ∣ u ∣ ∣ v ∣
decode* {B = B} {n = zero} u v = rec (isOfHLevelTrunc 2 _ _) (cong ∣_∣)
decode* {n = suc n} u v =
rec (isOfHLevelTrunc (3 + n) ∣ u ∣ ∣ v ∣) (cong ∣_∣)
{- auxiliary function r used to define encode -}
r : {X : Type ℓ} {n : HLevel} (u : ∥ X ∥ (2 + n)) → P u u
r = elim (λ x → hLevelP x x) (λ a → ∣ refl ∣)
{- encode function from x ≡ y to P x y -}
encode-fun : {X : Type ℓ} {n : HLevel} (x y : ∥ X ∥ (2 + n)) → x ≡ y → P x y
encode-fun x y p = subst (P x) p (r x)
{- We need the following two lemmas on the functions behaviour for refl -}
dec-refl : {X : Type ℓ} {n : HLevel} (x : ∥ X ∥ (2 + n)) → decode-fun x x (r x) ≡ refl
dec-refl {n = zero} =
elim (λ _ → isOfHLevelSuc 2 (isOfHLevelSuc 1 (isOfHLevelTrunc 2 _ _)) _ _) λ _ → refl
dec-refl {n = suc n} =
elim (λ x → isOfHLevelSuc (2 + n)
(isOfHLevelSuc (2 + n)
(isOfHLevelTrunc (3 + n) x x)
(decode-fun x x (r x)) refl))
(λ _ → refl)
enc-refl : {X : Type ℓ} {n : HLevel} (x : ∥ X ∥ (2 + n)) → encode-fun x x refl ≡ r x
enc-refl x j = transp (λ _ → P x x) j (r x)
{- decode-fun is a right-inverse -}
P-rinv : {X : Type ℓ} {n : HLevel} (u v : ∥ X ∥ (2 + n)) (x : Path (∥ X ∥ (2 + n)) u v)
→ decode-fun u v (encode-fun u v x) ≡ x
P-rinv u v = J (λ y p → decode-fun u y (encode-fun u y p) ≡ p)
(cong (decode-fun u u) (enc-refl u) ∙ dec-refl u)
{- decode-fun is a left-inverse -}
P-linv : {X : Type ℓ} {n : HLevel} (u v : ∥ X ∥ (2 + n)) (x : P u v)
→ encode-fun u v (decode-fun u v x) ≡ x
P-linv {n = n} =
elim2 (λ x y → isOfHLevelΠ (2 + n)
(λ z → isOfHLevelSuc (2 + n) (hLevelP x y) _ _))
helper
where
helper : {X : Type ℓ} {n : HLevel} (a b : X) (p : P {n = n} ∣ a ∣ ∣ b ∣)
→ encode-fun _ _ (decode-fun ∣ a ∣ ∣ b ∣ p) ≡ p
helper {n = zero} a b =
elim (λ _ → isOfHLevelPath 1 (isOfHLevelTrunc 1) _ _)
(J (λ y p → encode-fun ∣ a ∣ ∣ y ∣ (decode-fun _ _ ∣ p ∣) ≡ ∣ p ∣)
(enc-refl ∣ a ∣))
helper {n = suc n} a b =
elim (λ x → hLevelP {n = suc n} ∣ a ∣ ∣ b ∣ _ _)
(J (λ y p → encode-fun {n = (suc n)} ∣ a ∣ ∣ y ∣ (decode-fun _ _ ∣ p ∣) ≡ ∣ p ∣)
(enc-refl ∣ a ∣))
{- The final Iso established -}
IsoFinal : {B : Type ℓ} (n : HLevel) (x y : ∥ B ∥ (2 + n)) → Iso (x ≡ y) (P x y)
Iso.fun (IsoFinal _ x y) = encode-fun x y
Iso.inv (IsoFinal _ x y) = decode-fun x y
Iso.rightInv (IsoFinal _ x y) = P-linv x y
Iso.leftInv (IsoFinal _ x y) = P-rinv x y
PathIdTruncIso : {a b : A} (n : HLevel) → Iso (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ b ∣) (∥ a ≡ b ∥ n)
PathIdTruncIso zero = isContr→Iso ((isOfHLevelTrunc 1 _ _)
, isOfHLevelPath 1 (isOfHLevelTrunc 1) ∣ _ ∣ ∣ _ ∣ _) (isOfHLevelUnit* 0)
PathIdTruncIso (suc n) = ΩTrunc.IsoFinal n ∣ _ ∣ ∣ _ ∣
PathIdTrunc : {a b : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ b ∣) ≡ (∥ a ≡ b ∥ n)
PathIdTrunc n = isoToPath (PathIdTruncIso n)
PathΩ : {a : A} (n : HLevel) → (Path (∥ A ∥ (suc n)) ∣ a ∣ ∣ a ∣) ≡ (∥ a ≡ a ∥ n)
PathΩ n = PathIdTrunc n
{- Special case using direct defs of truncations -}
PathIdTrunc₀Iso : {a b : A} → Iso (∣ a ∣₂ ≡ ∣ b ∣₂) ∥ a ≡ b ∥₁
PathIdTrunc₀Iso = compIso (congIso setTruncTrunc2Iso)
(compIso (ΩTrunc.IsoFinal _ ∣ _ ∣ ∣ _ ∣)
(invIso propTruncTrunc1Iso))
-------------------------
truncOfTruncIso : (n m : HLevel) → Iso (hLevelTrunc n A) (hLevelTrunc n (hLevelTrunc (m + n) A))
truncOfTruncIso zero m = isContr→Iso (isOfHLevelUnit* 0) (isOfHLevelUnit* 0)
Iso.fun (truncOfTruncIso (suc n) zero) = rec (isOfHLevelTrunc (suc n)) λ a → ∣ ∣ a ∣ ∣
Iso.fun (truncOfTruncIso (suc n) (suc m)) = rec (isOfHLevelTrunc (suc n)) λ a → ∣ ∣ a ∣ ∣
Iso.inv (truncOfTruncIso (suc n) zero) = rec (isOfHLevelTrunc (suc n))
(rec (isOfHLevelTrunc (suc n))
λ a → ∣ a ∣)
Iso.inv (truncOfTruncIso (suc n) (suc m)) = rec (isOfHLevelTrunc (suc n))
(rec (isOfHLevelPlus (suc m) (isOfHLevelTrunc (suc n)))
λ a → ∣ a ∣)
Iso.rightInv (truncOfTruncIso (suc n) zero) =
elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _ )
(elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _ )
λ a → refl)
Iso.rightInv (truncOfTruncIso (suc n) (suc m)) =
elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _ )
(elim (λ x → isOfHLevelPath ((suc m) + (suc n)) (isOfHLevelPlus (suc m) (isOfHLevelTrunc (suc n))) _ _ )
λ a → refl)
Iso.leftInv (truncOfTruncIso (suc n) zero) = elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → refl
Iso.leftInv (truncOfTruncIso (suc n) (suc m)) = elim (λ x → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ a → refl
truncOfTruncEq : (n m : ℕ) → (hLevelTrunc n A) ≃ (hLevelTrunc n (hLevelTrunc (m + n) A))
truncOfTruncEq n m = isoToEquiv (truncOfTruncIso n m)
truncOfTruncIso2 : (n m : HLevel) → Iso (hLevelTrunc (m + n) (hLevelTrunc n A)) (hLevelTrunc n A)
truncOfTruncIso2 n m = truncIdempotentIso (m + n) (isOfHLevelPlus m (isOfHLevelTrunc n))
truncOfΣIso : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} {B : A → Type ℓ'}
→ Iso (hLevelTrunc n (Σ A B)) (hLevelTrunc n (Σ A λ x → hLevelTrunc n (B x)))
truncOfΣIso zero = idIso
Iso.fun (truncOfΣIso (suc n)) = map λ {(a , b) → a , ∣ b ∣}
Iso.inv (truncOfΣIso (suc n)) =
rec (isOfHLevelTrunc (suc n))
(uncurry λ a → rec (isOfHLevelTrunc (suc n)) λ b → ∣ a , b ∣)
Iso.rightInv (truncOfΣIso (suc n)) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
(uncurry λ a → elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _)
λ b → refl)
Iso.leftInv (truncOfΣIso (suc n)) =
elim (λ _ → isOfHLevelPath (suc n) (isOfHLevelTrunc (suc n)) _ _) λ {(a , b) → refl}
| 47.465066 | 146 | 0.556327 |
398748dcb3eda8d2d87374ee6dc9898d3571588b | 24 | agda | Agda | test/interaction/Issue2536-1.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue2536-1.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue2536-1.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | id : Set → Set
id A = A
| 8 | 14 | 0.5 |
4a6bbdb7e83937510c75ae59b7e601883c14021a | 528 | agda | Agda | test/Foo.agda | andreasabel/agda2lagda | 93d317c87bddf973e3fa6abd5bf24dcfa9a797f0 | [
"Unlicense"
] | 11 | 2020-10-01T12:10:15.000Z | 2021-08-16T07:28:10.000Z | test/Foo.agda | andreasabel/agda2lagda | 93d317c87bddf973e3fa6abd5bf24dcfa9a797f0 | [
"Unlicense"
] | null | null | null | test/Foo.agda | andreasabel/agda2lagda | 93d317c87bddf973e3fa6abd5bf24dcfa9a797f0 | [
"Unlicense"
] | null | null | null | -- Sample non-literate Agda program
-- ================================
--
-- A remark to test bulleted lists:
--
-- * This file serves as example for agda2lagda.
--
-- * The content may be non-sensical.
--
-- Indeed!
module Foo where
-- Some data type.
data D : Set where
c : D
-- A function.
foo : D → D
foo c = c -- basically, the identity
{- This part is commented out.
{-
bar : D → Set
bar x = D
-- -}
-- -}
-- A subheading
---------------
module Submodule where
postulate
zeta : D
-- That's it.
-- Bye.
| 13.2 | 48 | 0.551136 |
c5f61abd5a97d2d055a50889f55cd0d0e0ae41c3 | 14,088 | agda | Agda | TotalParserCombinators/Congruence/Sound.agda | nad/parser-combinators | 76774f54f466cfe943debf2da731074fe0c33644 | [
"MIT"
] | 1 | 2020-07-03T08:56:13.000Z | 2020-07-03T08:56:13.000Z | TotalParserCombinators/Congruence/Sound.agda | nad/parser-combinators | 76774f54f466cfe943debf2da731074fe0c33644 | [
"MIT"
] | null | null | null | TotalParserCombinators/Congruence/Sound.agda | nad/parser-combinators | 76774f54f466cfe943debf2da731074fe0c33644 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- The parser equivalence proof language is sound
------------------------------------------------------------------------
module TotalParserCombinators.Congruence.Sound where
open import Category.Monad
open import Codata.Musical.Notation
open import Data.List
open import Data.List.Membership.Propositional using (_∈_)
import Data.List.Categorical as ListMonad
open import Data.List.Relation.Binary.BagAndSetEquality
renaming (_∼[_]_ to _List-∼[_]_)
open import Data.Maybe hiding (_>>=_)
open import Data.Product
open import Function
import Function.Related as Related
open import Level
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
open Related using (SK-sym)
open Related.EquationalReasoning
renaming (_∼⟨_⟩_ to _∼⟨_⟩′_; _∎ to _∎′)
open RawMonad {f = zero} ListMonad.monad
using () renaming (_⊛_ to _⊛′_; _>>=_ to _>>=′_)
private
module BSOrd {k} {A : Set} = Preorder ([ k ]-Order A)
open import TotalParserCombinators.Derivative using (D)
open import TotalParserCombinators.CoinductiveEquality as CE
using (_∼[_]c_; _∷_)
open import TotalParserCombinators.Congruence
open import TotalParserCombinators.Laws
open import TotalParserCombinators.Lib using (return⋆)
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics using (_∼[_]_)
------------------------------------------------------------------------
-- Some lemmas
private
⊛flatten-lemma : ∀ {k} {R₁ R₂ : Set} {fs₁ fs₂ : List (R₁ → R₂)}
(xs₁ xs₂ : Maybe (List R₁)) →
fs₁ List-∼[ k ] fs₂ →
flatten xs₁ List-∼[ k ] flatten xs₂ →
fs₁ ⊛flatten xs₁ List-∼[ k ] fs₂ ⊛flatten xs₂
⊛flatten-lemma {k} {fs₁ = fs₁} {fs₂} xs₁ xs₂ fs₁≈fs₂ = helper xs₁ xs₂
where
helper : ∀ xs₁ xs₂ →
flatten xs₁ List-∼[ k ] flatten xs₂ →
fs₁ ⊛flatten xs₁ List-∼[ k ] fs₂ ⊛flatten xs₂
helper nothing nothing []∼[] = BSOrd.refl
helper (just xs₁) (just xs₂) xs₁≈xs₂ = ⊛-cong fs₁≈fs₂ xs₁≈xs₂
helper nothing (just xs₂) []≈xs₂ {x} =
x ∈ [] ↔⟨ BSOrd.reflexive $ P.sym $
ListMonad.Applicative.right-zero fs₂ ⟩
x ∈ (fs₂ ⊛′ []) ∼⟨ ⊛-cong (BSOrd.refl {x = fs₂}) []≈xs₂ ⟩′
x ∈ (fs₂ ⊛′ xs₂) ∎′
helper (just xs₁) nothing xs₁∼[] {x} =
x ∈ (fs₁ ⊛′ xs₁) ∼⟨ ⊛-cong (BSOrd.refl {x = fs₁}) xs₁∼[] ⟩′
x ∈ (fs₁ ⊛′ []) ↔⟨ BSOrd.reflexive $
ListMonad.Applicative.right-zero fs₁ ⟩
x ∈ [] ∎′
[]-⊛flatten : ∀ {A B : Set} (xs : Maybe (List A)) →
[] ⊛flatten xs List-∼[ bag ] [] {A = B}
[]-⊛flatten nothing = BSOrd.refl
[]-⊛flatten (just xs) = BSOrd.refl
bind-lemma : ∀ {k} {R₁ R₂ : Set} {xs₁ xs₂ : Maybe (List R₁)}
(f₁ f₂ : Maybe (R₁ → List R₂)) →
flatten xs₁ List-∼[ k ] flatten xs₂ →
(∀ x → apply f₁ x List-∼[ k ] apply f₂ x) →
bind xs₁ f₁ List-∼[ k ] bind xs₂ f₂
bind-lemma {k} {xs₁ = xs₁} {xs₂} f₁ f₂ xs₁≈xs₂ = helper f₁ f₂
where
helper : ∀ f₁ f₂ →
(∀ x → apply f₁ x List-∼[ k ] apply f₂ x) →
bind xs₁ f₁ List-∼[ k ] bind xs₂ f₂
helper nothing nothing []∼[] = BSOrd.refl
helper (just f₁) (just f₂) f₁≈f₂ = >>=-cong xs₁≈xs₂ f₁≈f₂
helper nothing (just f₂) []≈f₂ {x} =
x ∈ [] ∼⟨ BSOrd.reflexive $ P.sym $
ListMonad.MonadProperties.right-zero (flatten xs₂) ⟩′
x ∈ (flatten xs₂ >>=′ λ _ → []) ∼⟨ >>=-cong (BSOrd.refl {x = flatten xs₂}) []≈f₂ ⟩′
x ∈ (flatten xs₂ >>=′ f₂) ∎′
helper (just f₁) nothing f₁∼[] {x} =
x ∈ (flatten xs₁ >>=′ f₁) ∼⟨ >>=-cong (BSOrd.refl {x = flatten xs₁}) f₁∼[] ⟩′
x ∈ (flatten xs₁ >>=′ λ _ → []) ∼⟨ BSOrd.reflexive $
ListMonad.MonadProperties.right-zero (flatten xs₁) ⟩′
x ∈ [] ∎′
bind-nothing : ∀ {A B : Set} (f : Maybe (A → List B)) →
bind nothing f List-∼[ bag ] []
bind-nothing nothing = BSOrd.refl
bind-nothing (just f) = BSOrd.refl
------------------------------------------------------------------------
-- Equality is closed under initial-bag
initial-bag-cong :
∀ {k Tok R xs₁ xs₂} {p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → initial-bag p₁ List-∼[ k ] initial-bag p₂
initial-bag-cong (xs₁≈xs₂ ∷ Dp₁≈Dp₂) = xs₁≈xs₂
initial-bag-cong (p ∎) = BSOrd.refl
initial-bag-cong (p₁ ∼⟨ p₁≈p₂ ⟩ p₂≈p₃) = _ ∼⟨ initial-bag-cong p₁≈p₂ ⟩′ initial-bag-cong p₂≈p₃
initial-bag-cong (p₁ ≅⟨ p₁≅p₂ ⟩ p₂≈p₃) = _ ↔⟨ initial-bag-cong p₁≅p₂ ⟩ initial-bag-cong p₂≈p₃
initial-bag-cong (sym p₁≈p₂) = SK-sym (initial-bag-cong p₁≈p₂)
initial-bag-cong (return x₁≡x₂) = BSOrd.reflexive $ P.cong [_] x₁≡x₂
initial-bag-cong fail = BSOrd.refl
initial-bag-cong token = BSOrd.refl
initial-bag-cong (p₁≈p₃ ∣ p₂≈p₄) = ++-cong (initial-bag-cong p₁≈p₃) (initial-bag-cong p₂≈p₄)
initial-bag-cong (f₁≗f₂ <$> p₁≈p₂) = map-cong f₁≗f₂ $ initial-bag-cong p₁≈p₂
initial-bag-cong (nonempty p₁≈p₂) = BSOrd.refl
initial-bag-cong (cast {xs₁ = xs₁} {xs₂ = xs₂}
{xs₁′ = xs₁′} {xs₂′ = xs₂′}
{xs₁≈xs₁′ = xs₁≈xs₁′} {xs₂≈xs₂′ = xs₂≈xs₂′}
p₁≈p₂) {x} =
x ∈ xs₁′ ↔⟨ SK-sym xs₁≈xs₁′ ⟩
x ∈ xs₁ ∼⟨ initial-bag-cong p₁≈p₂ ⟩′
x ∈ xs₂ ↔⟨ xs₂≈xs₂′ ⟩
x ∈ xs₂′ ∎′
initial-bag-cong ([ nothing - _ ] p₁≈p₃ ⊛ p₂≈p₄) = BSOrd.refl
initial-bag-cong ([ just (xs₁ , xs₂) - just _ ] p₁≈p₃ ⊛ p₂≈p₄) = ⊛flatten-lemma xs₁ xs₂
(initial-bag-cong p₁≈p₃) (initial-bag-cong p₂≈p₄)
initial-bag-cong ([ just (xs₁ , xs₂) - nothing ] p₁≈p₃ ⊛ p₂≈p₄) {x} =
x ∈ [] ⊛flatten xs₁ ↔⟨ []-⊛flatten xs₁ ⟩
x ∈ [] ↔⟨ SK-sym $ []-⊛flatten xs₂ ⟩
x ∈ [] ⊛flatten xs₂ ∎′
initial-bag-cong ([ nothing - _ ] p₁≈p₃ >>= p₂≈p₄) = BSOrd.refl
initial-bag-cong ([ just (f₁ , f₂) - just _ ] p₁≈p₃ >>= p₂≈p₄) = bind-lemma f₁ f₂
(initial-bag-cong p₁≈p₃) (λ x → initial-bag-cong (p₂≈p₄ x))
initial-bag-cong ([ just (f₁ , f₂) - nothing ] p₁≈p₃ >>= p₂≈p₄) {x} =
x ∈ bind nothing f₁ ↔⟨ bind-nothing f₁ ⟩
x ∈ [] ↔⟨ SK-sym $ bind-nothing f₂ ⟩
x ∈ bind nothing f₂ ∎′
------------------------------------------------------------------------
-- Equality is closed under D
D-cong : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → ∀ {t} → D t p₁ ∼[ k ]P D t p₂
D-cong (xs₁≈xs₂ ∷ Dp₁≈Dp₂) {t} = ♭ (Dp₁≈Dp₂ t)
D-cong (p ∎) {t} = D t p ∎
D-cong (p₁ ∼⟨ p₁≈p₂ ⟩ p₂≈p₃) {t} = D t p₁ ∼⟨ D-cong p₁≈p₂ ⟩ D-cong p₂≈p₃
D-cong (p₁ ≅⟨ p₁≅p₂ ⟩ p₂≈p₃) {t} = D t p₁ ≅⟨ D-cong p₁≅p₂ ⟩ D-cong p₂≈p₃
D-cong (sym p₁≈p₂) = _∼[_]P_.sym (D-cong p₁≈p₂)
D-cong (return x₁≡x₂) = fail ∎
D-cong fail = fail ∎
D-cong token {t} = return t ∎
D-cong (p₁≈p₃ ∣ p₂≈p₄) = D-cong p₁≈p₃ ∣ D-cong p₂≈p₄
D-cong (f₁≗f₂ <$> p₁≈p₂) = f₁≗f₂ <$> D-cong p₁≈p₂
D-cong (nonempty p₁≈p₂) = D-cong p₁≈p₂
D-cong (cast p₁≈p₂) = D-cong p₁≈p₂
D-cong ([_-_]_⊛_ nothing nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) ⊛ ♭ p₂≈p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_⊛_ nothing (just (fs₁ , fs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ≅⟨ D.D-⊛ p₁ p₂ ⟩
D t (♭ p₁) ⊛ ♭? p₂ ∣ return⋆ (flatten fs₁) ⊛ D t (♭? p₂) ≅⟨ [ ○ - ◌ - ○ - ○ ] D t (♭ p₁) ∎ ⊛ (♭? p₂ ∎) ∣ (_ ∎) ⟩
♯ D t (♭ p₁) ⊛ ♭? p₂ ∣ return⋆ (flatten fs₁) ⊛ D t (♭? p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) ⊛ p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ]
Return⋆.cong (initial-bag-cong (♭ p₁≈p₃)) ⊛ D-cong p₂≈p₄ ⟩
♯ D t (♭ p₃) ⊛ ♭? p₄ ∣ return⋆ (flatten fs₂) ⊛ D t (♭? p₄) ≅⟨ [ ◌ - ○ - ○ - ○ ] D t (♭ p₃) ∎ ⊛ (♭? p₄ ∎) ∣ (_ ∎) ⟩
D t (♭ p₃) ⊛ ♭? p₄ ∣ return⋆ (flatten fs₂) ⊛ D t (♭? p₄) ≅⟨ _∼[_]P_.sym $ D.D-⊛ p₃ p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_⊛_ (just _) nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ≅⟨ D.D-⊛ p₁ p₂ ⟩
D t (♭? p₁) ⊛ ♭ p₂ ∣ return⋆ [] ⊛ D t (♭ p₂) ≅⟨ (D t (♭? p₁) ⊛ ♭ p₂ ∎) ∣
[ ○ - ○ - ○ - ◌ ] return⋆ [] ∎ ⊛ (D t (♭ p₂) ∎) ⟩
D t (♭? p₁) ⊛ ♭ p₂ ∣ return⋆ [] ⊛ ♯ D t (♭ p₂) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ ⊛ ♭ p₂≈p₄ ∣
[ just (○ , ○) - nothing ] (return⋆ [] ∎) ⊛ ♯ D-cong (♭ p₂≈p₄) ⟩
D t (♭? p₃) ⊛ ♭ p₄ ∣ return⋆ [] ⊛ ♯ D t (♭ p₄) ≅⟨ (D t (♭? p₃) ⊛ ♭ p₄ ∎) ∣
[ ○ - ○ - ◌ - ○ ] return⋆ [] ∎ ⊛ (D t (♭ p₄) ∎) ⟩
D t (♭? p₃) ⊛ ♭ p₄ ∣ return⋆ [] ⊛ D t (♭ p₄) ≅⟨ _∼[_]P_.sym $ D.D-⊛ p₃ p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_⊛_ (just _) (just (fs₁ , fs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ ⊛ p₂) ≅⟨ D.D-⊛ p₁ p₂ ⟩
D t (♭? p₁) ⊛ ♭? p₂ ∣ return⋆ (flatten fs₁) ⊛ D t (♭? p₂) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ ⊛ p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ] Return⋆.cong (initial-bag-cong p₁≈p₃) ⊛
D-cong p₂≈p₄ ⟩
D t (♭? p₃) ⊛ ♭? p₄ ∣ return⋆ (flatten fs₂) ⊛ D t (♭? p₄) ≅⟨ _∼[_]P_.sym $ D.D-⊛ p₃ p₄ ⟩
D t (p₃ ⊛ p₄) ∎
D-cong ([_-_]_>>=_ nothing nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) >>= (♭ ∘ p₂≈p₄) ⟩
D t (p₃ >>= p₄) ∎
D-cong ([_-_]_>>=_ nothing (just (xs₁ , xs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ≅⟨ D.D->>= p₁ p₂ ⟩
D t (♭ p₁) >>= (♭? ∘ p₂) ∣ return⋆ (flatten xs₁) >>= (D t ∘ ♭? ∘ p₂) ≅⟨ [ ○ - ◌ - ○ - ○ ] D t (♭ p₁) ∎ >>= (λ x → ♭? (p₂ x) ∎) ∣
(_ ∎) ⟩
♯ D t (♭ p₁) >>= (♭? ∘ p₂) ∣ return⋆ (flatten xs₁) >>= (D t ∘ ♭? ∘ p₂) ∼⟨ [ nothing - just (○ , ○) ] ♯ D-cong (♭ p₁≈p₃) >>= p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ]
Return⋆.cong (initial-bag-cong (♭ p₁≈p₃)) >>=
(λ x → D-cong (p₂≈p₄ x)) ⟩
♯ D t (♭ p₃) >>= (♭? ∘ p₄) ∣ return⋆ (flatten xs₂) >>= (D t ∘ ♭? ∘ p₄) ≅⟨ [ ◌ - ○ - ○ - ○ ] D t (♭ p₃) ∎ >>= (λ x → ♭? (p₄ x) ∎) ∣
(_ ∎) ⟩
D t (♭ p₃) >>= (♭? ∘ p₄) ∣ return⋆ (flatten xs₂) >>= (D t ∘ ♭? ∘ p₄) ≅⟨ _∼[_]P_.sym $ D.D->>= p₃ p₄ ⟩
D t (p₃ >>= p₄) ∎
D-cong ([_-_]_>>=_ (just _) nothing {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ≅⟨ D.D->>= p₁ p₂ ⟩
D t (♭? p₁) >>= (♭ ∘ p₂) ∣ return⋆ [] >>= (D t ∘ ♭ ∘ p₂) ≅⟨ (D t (♭? p₁) >>= (♭ ∘ p₂) ∎) ∣
[ ○ - ○ - ○ - ◌ ] return⋆ [] ∎ >>= (λ x → D t (♭ (p₂ x)) ∎) ⟩
D t (♭? p₁) >>= (♭ ∘ p₂) ∣ return⋆ [] >>= (λ x → ♯ D t (♭ (p₂ x))) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ >>= (♭ ∘ p₂≈p₄) ∣
[ just (○ , ○) - nothing ] (return⋆ [] ∎) >>=
(λ x → ♯ D-cong (♭ (p₂≈p₄ x))) ⟩
D t (♭? p₃) >>= (♭ ∘ p₄) ∣ return⋆ [] >>= (λ x → ♯ D t (♭ (p₄ x))) ≅⟨ (D t (♭? p₃) >>= (♭ ∘ p₄) ∎) ∣
[ ○ - ○ - ◌ - ○ ] return⋆ [] ∎ >>= (λ x → D t (♭ (p₄ x)) ∎) ⟩
D t (♭? p₃) >>= (♭ ∘ p₄) ∣ return⋆ [] >>= (D t ∘ ♭ ∘ p₄) ≅⟨ _∼[_]P_.sym $ D.D->>= p₃ p₄ ⟩
D t (p₃ >>= p₄) ∎
D-cong ([_-_]_>>=_ (just _) (just (xs₁ , xs₂)) {p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄) {t} =
D t (p₁ >>= p₂) ≅⟨ D.D->>= p₁ p₂ ⟩
D t (♭? p₁) >>= (♭? ∘ p₂) ∣ return⋆ (flatten xs₁) >>= (D t ∘ ♭? ∘ p₂) ∼⟨ [ just (○ , ○) - just (○ , ○) ] D-cong p₁≈p₃ >>= p₂≈p₄ ∣
[ just (○ , ○) - just (○ , ○) ]
Return⋆.cong (initial-bag-cong p₁≈p₃) >>=
(λ x → D-cong (p₂≈p₄ x)) ⟩
D t (♭? p₃) >>= (♭? ∘ p₄) ∣ return⋆ (flatten xs₂) >>= (D t ∘ ♭? ∘ p₄) ≅⟨ _∼[_]P_.sym $ D.D->>= p₃ p₄ ⟩
D t (p₃ >>= p₄) ∎
------------------------------------------------------------------------
-- Soundness
sound : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁}
{p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → p₁ ∼[ k ] p₂
sound = CE.sound ∘ sound′
where
sound′ : ∀ {k Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁}
{p₂ : Parser Tok R xs₂} →
p₁ ∼[ k ]P p₂ → p₁ ∼[ k ]c p₂
sound′ p₁≈p₂ = initial-bag-cong p₁≈p₂ ∷ λ t → ♯ sound′ (D-cong p₁≈p₂)
| 58.456432 | 135 | 0.389338 |
dcde433233e311310d93d0affaa71e0bb31849fd | 435 | agda | Agda | archive/agda-3/src/Test/Test1.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | archive/agda-3/src/Test/Test1.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | 1 | 2019-04-29T00:35:04.000Z | 2019-05-11T23:33:04.000Z | archive/agda-3/src/Test/Test1.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | {-# OPTIONS --allow-unsolved-metas #-} -- FIXME
open import Everything
module Test.Test1 where
test-functor-transextensionality : ∀
{𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂}
⦃ functor : Functor 𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂ ⦄
(open Functor functor)
→ {!Transextensionality!.type _∼₁_ _∼̇₁_!}
test-functor-transextensionality = transextensionality
-- test-functor-transextensionality ⦃ functor ⦄ = let open Functor ⦃ … ⦄ in transextensionality1
| 31.071429 | 98 | 0.705747 |
0e09b13a713739e33e0bb5341e26809e487b383f | 1,853 | agda | Agda | SOAS/Metatheory/Semantics.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 39 | 2021-11-09T20:39:55.000Z | 2022-03-19T17:33:12.000Z | SOAS/Metatheory/Semantics.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 1 | 2021-11-21T12:19:32.000Z | 2021-11-21T12:19:32.000Z | SOAS/Metatheory/Semantics.agda | JoeyEremondi/agda-soas | ff1a985a6be9b780d3ba2beff68e902394f0a9d8 | [
"MIT"
] | 4 | 2021-11-09T20:39:59.000Z | 2022-01-24T12:49:17.000Z |
open import SOAS.Common
open import SOAS.Families.Core
open import Categories.Object.Initial
open import SOAS.Coalgebraic.Strength
import SOAS.Metatheory.MetaAlgebra
-- Initial-algebra semantics
module SOAS.Metatheory.Semantics {T : Set}
(⅀F : Functor 𝔽amiliesₛ 𝔽amiliesₛ) (⅀:Str : Strength ⅀F)
(𝔛 : Familyₛ) (open SOAS.Metatheory.MetaAlgebra ⅀F 𝔛)
(𝕋:Init : Initial 𝕄etaAlgebras)
where
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Construction.Structure as Structure
open import SOAS.Abstract.Hom
import SOAS.Abstract.Coalgebra as →□ ; open →□.Sorted
import SOAS.Abstract.Box as □ ; open □.Sorted
open import SOAS.Metatheory.Algebra ⅀F
open Strength ⅀:Str
private
variable
Γ Δ Θ Π : Ctx
α β : T
𝒫 𝒬 𝒜 : Familyₛ
open Initial 𝕋:Init
open Object ⊥ public renaming (𝐶 to 𝕋 ; ˢ to 𝕋ᵃ)
open MetaAlg 𝕋ᵃ public renaming (𝑎𝑙𝑔 to 𝕒𝕝𝕘 ; 𝑣𝑎𝑟 to 𝕧𝕒𝕣 ; 𝑚𝑣𝑎𝑟 to 𝕞𝕧𝕒𝕣 ;
𝑚≈₁ to 𝕞≈₁ ; 𝑚≈₂ to 𝕞≈₂)
module Semantics (𝒜ᵃ : MetaAlg 𝒜) where
open Morphism (! {𝒜 ⋉ 𝒜ᵃ}) public renaming (𝑓 to 𝕤𝕖𝕞 ; ˢ⇒ to 𝕤𝕖𝕞ᵃ⇒)
open MetaAlg⇒ 𝕤𝕖𝕞ᵃ⇒ public renaming (⟨𝑎𝑙𝑔⟩ to ⟨𝕒⟩ ; ⟨𝑣𝑎𝑟⟩ to ⟨𝕧⟩ ; ⟨𝑚𝑣𝑎𝑟⟩ to ⟨𝕞⟩)
open MetaAlg 𝒜ᵃ
module 𝒜 = MetaAlg 𝒜ᵃ
eq : {g h : 𝕋 ⇾̣ 𝒜} (gᵃ : MetaAlg⇒ 𝕋ᵃ 𝒜ᵃ g) (hᵃ : MetaAlg⇒ 𝕋ᵃ 𝒜ᵃ h) (t : 𝕋 α Γ)
→ g t ≡ h t
eq {g = g}{h} gᵃ hᵃ t = !-unique₂ (g ⋉ gᵃ) (h ⋉ hᵃ) {x = t}
-- The interpretation is equal to any other pointed meta-Λ-algebra
𝕤𝕖𝕞! : {g : 𝕋 ⇾̣ 𝒜}(gᵃ : MetaAlg⇒ 𝕋ᵃ 𝒜ᵃ g)(t : 𝕋 α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕤𝕖𝕞! {g = g} gᵃ t = !-unique (g ⋉ gᵃ) {x = t}
-- Corollaries: every meta-algebra endo-homomorphism is the identity, including 𝕤𝕖𝕞
eq-id : {g : 𝕋 ⇾̣ 𝕋} (gᵃ : MetaAlg⇒ 𝕋ᵃ 𝕋ᵃ g) (t : 𝕋 α Γ) →
g t ≡ t
eq-id gᵃ t = Semantics.eq 𝕋ᵃ gᵃ (idᵃ 𝕋ᵃ) t
𝕤𝕖𝕞-id : {t : 𝕋 α Γ} → Semantics.𝕤𝕖𝕞 𝕋ᵃ t ≡ t
𝕤𝕖𝕞-id {t = t} = eq-id (Semantics.𝕤𝕖𝕞ᵃ⇒ 𝕋ᵃ) t
| 30.377049 | 83 | 0.637345 |
dc1f2e0b54a58c284b6f32c0d2cce8cf2ec1564a | 10,597 | agda | Agda | Cubical/Talks/EPA2020.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | 1 | 2022-03-05T00:29:41.000Z | 2022-03-05T00:29:41.000Z | Cubical/Talks/EPA2020.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | null | null | null | Cubical/Talks/EPA2020.agda | FernandoLarrain/cubical | 9acdecfa6437ec455568be4e5ff04849cc2bc13b | [
"MIT"
] | null | null | null | {-
Cubical Agda - A Dependently Typed PL with Univalence and HITs
==============================================================
Anders Mörtberg
Every Proof Assistant - September 17, 2020
Link to slides: https://staff.math.su.se/anders.mortberg/slides/EPA2020.pdf
Link to video: https://vimeo.com/459020971
-}
-- To make Agda cubical add the --cubical option.
-- This is implicitly added for files in the cubical library via the cubical.agda-lib file.
{-# OPTIONS --safe #-}
module Cubical.Talks.EPA2020 where
-- The "Foundations" package contain a lot of important results (in
-- particular the univalence theorem)
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Data.Int
open import Cubical.Data.Prod.Base
-- The interval in Cubical Agda is written I and the endpoints i0 and i1.
apply0 : (A : Type) (p : I → A) → A
apply0 A p = p i0
-- We omit the universe level ℓ for simplicity in this talk. In the
-- library everything is maximally universe polymorphic.
-- We can write functions out of the interval using λ-abstraction:
refl' : {A : Type} (x : A) → x ≡ x
refl' x = λ i → x
-- In fact, x ≡ y is short for PathP (λ _ → A) x y
refl'' : {A : Type} (x : A) → PathP (λ _ → A) x x
refl'' x = λ _ → x
-- In general PathP A x y has A : I → Type, x : A i0 and y : A i1
-- PathP = Dependent paths (Path over a Path)
-- We cannot pattern-match on interval variables as I is not inductively defined
-- foo : {A : Type} → I → A
-- foo r = {!r!} -- Try typing C-c C-c
-- cong has a direct proof
cong' : {A B : Type} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y
cong' f p i = f (p i)
-- function extensionality also has a direct proof.
-- It also has computational content: swap the arguments.
funExt' : {A B : Type} {f g : A → B} (p : (x : A) → f x ≡ g x) → f ≡ g
funExt' p i x = p x i
-- Transport is more complex as ≡ isn't inductively defined (so we
-- can't define it by pattern-matching on p)
transport' : {A B : Type} → A ≡ B → A → B
transport' p a = transp (λ i → p i) i0 a
-- This lets us define subst (which is called "transport" in the HoTT book)
subst' : {A : Type} (P : A → Type) {x y : A} (p : x ≡ y) → P x → P y
subst' P p pa = transport (λ i → P (p i)) pa
-- The transp operation reduces differently for different types
-- formers. For paths it reduces to another primitive operation called
-- hcomp.
-- We can also define the J eliminator (aka path induction)
J' : {A : Type} {B : A → Type} {x : A}
(P : (z : A) → x ≡ z → Type)
(d : P x refl) {y : A} (p : x ≡ y) → P y p
J' P d p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
-- So J is provable, but it doesn't satisfy computation rule
-- definitionally. This is almost never a problem in practice as the
-- cubical primitives satisfy many new definitional equalities.
-- Another key concept in HoTT/UF is the Univalence Axiom. In Cubical
-- Agda this is provable, we hence refer to it as the Univalence
-- Theorem.
-- The univalence theorem: equivalences of types give paths of types
ua' : {A B : Type} → A ≃ B → A ≡ B
ua' = ua
-- Any isomorphism of types gives rise to an equivalence
isoToEquiv' : {A B : Type} → Iso A B → A ≃ B
isoToEquiv' = isoToEquiv
-- And hence to a path
isoToPath' : {A B : Type} → Iso A B → A ≡ B
isoToPath' e = ua' (isoToEquiv' e)
-- ua satisfies the following computation rule
-- This suffices to be able to prove the standard formulation of univalence.
uaβ' : {A B : Type} (e : A ≃ B) (x : A)
→ transport (ua' e) x ≡ fst e x
uaβ' e x = transportRefl (equivFun e x)
-- Time for an example!
-- Booleans
data Bool : Type where
false true : Bool
not : Bool → Bool
not false = true
not true = false
notPath : Bool ≡ Bool
notPath = isoToPath' (iso not not rem rem)
where
rem : (b : Bool) → not (not b) ≡ b
rem false = refl
rem true = refl
_ : transport notPath true ≡ false
_ = refl
-- Another example, integers:
sucPath : ℤ ≡ ℤ
sucPath = isoToPath' (iso sucℤ predℤ sucPred predSuc)
_ : transport sucPath (pos 0) ≡ pos 1
_ = refl
_ : transport (sucPath ∙ sucPath) (pos 0) ≡ pos 2
_ = refl
_ : transport (sym sucPath) (pos 0) ≡ negsuc 0
_ = refl
-----------------------------------------------------------------------------
-- Higher inductive types
-- The following definition of finite multisets is due to Vikraman
-- Choudhury and Marcelo Fiore.
infixr 5 _∷_
data FMSet (A : Type) : Type where
[] : FMSet A
_∷_ : (x : A) → (xs : FMSet A) → FMSet A
comm : (x y : A) (xs : FMSet A) → x ∷ y ∷ xs ≡ y ∷ x ∷ xs
-- trunc : (xs ys : FMSet A) (p q : xs ≡ ys) → p ≡ q
-- We need to add the trunc constructor for FMSets to be sets, omitted
-- here for simplicity.
_++_ : ∀ {A : Type} (xs ys : FMSet A) → FMSet A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ xs ++ ys
comm x y xs i ++ ys = comm x y (xs ++ ys) i
-- trunc xs zs p q i j ++ ys =
-- trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j
unitr-++ : {A : Type} (xs : FMSet A) → xs ++ [] ≡ xs
unitr-++ [] = refl
unitr-++ (x ∷ xs) = cong (x ∷_) (unitr-++ xs)
unitr-++ (comm x y xs i) j = comm x y (unitr-++ xs j) i
-- unitr-++ (trunc xs ys x y i j) = {!!}
-- This is a special case of set quotients! Very useful for
-- programming and set level mathematics
data _/_ (A : Type) (R : A → A → Type) : Type where
[_] : A → A / R
eq/ : (a b : A) → R a b → [ a ] ≡ [ b ]
trunc : (a b : A / R) (p q : a ≡ b) → p ≡ q
-- Proving that they are effective ((a b : A) → [ a ] ≡ [ b ] → R a b)
-- requires univalence for propositions.
-------------------------------------------------------------------------
-- Topological examples of things that are not sets
-- We can define the circle as the following simple data declaration:
data S¹ : Type where
base : S¹
loop : base ≡ base
-- We can write functions on S¹ using pattern-matching equations:
double : S¹ → S¹
double base = base
double (loop i) = (loop ∙ loop) i
helix : S¹ → Type
helix base = ℤ
helix (loop i) = sucPathℤ i
ΩS¹ : Type
ΩS¹ = base ≡ base
winding : ΩS¹ → ℤ
winding p = subst helix p (pos 0)
_ : winding (λ i → double ((loop ∙ loop) i)) ≡ pos 4
_ = refl
-- We can define the Torus as:
data Torus : Type where
point : Torus
line1 : point ≡ point
line2 : point ≡ point
square : PathP (λ i → line1 i ≡ line1 i) line2 line2
-- And prove that it is equivalent to two circle:
t2c : Torus → S¹ × S¹
t2c point = (base , base)
t2c (line1 i) = (loop i , base)
t2c (line2 j) = (base , loop j)
t2c (square i j) = (loop i , loop j)
c2t : S¹ × S¹ → Torus
c2t (base , base) = point
c2t (loop i , base) = line1 i
c2t (base , loop j) = line2 j
c2t (loop i , loop j) = square i j
c2t-t2c : (t : Torus) → c2t (t2c t) ≡ t
c2t-t2c point = refl
c2t-t2c (line1 _) = refl
c2t-t2c (line2 _) = refl
c2t-t2c (square _ _) = refl
t2c-c2t : (p : S¹ × S¹) → t2c (c2t p) ≡ p
t2c-c2t (base , base) = refl
t2c-c2t (base , loop _) = refl
t2c-c2t (loop _ , base) = refl
t2c-c2t (loop _ , loop _) = refl
-- Using univalence we get the following equality:
Torus≡S¹×S¹ : Torus ≡ S¹ × S¹
Torus≡S¹×S¹ = isoToPath' (iso t2c c2t t2c-c2t c2t-t2c)
windingTorus : point ≡ point → ℤ × ℤ
windingTorus l = ( winding (λ i → proj₁ (t2c (l i)))
, winding (λ i → proj₂ (t2c (l i))))
_ : windingTorus (line1 ∙ sym line2) ≡ (pos 1 , negsuc 0)
_ = refl
-- We have many more topological examples, including Klein bottle, RP^n,
-- higher spheres, suspensions, join, wedges, smash product:
open import Cubical.HITs.KleinBottle
open import Cubical.HITs.RPn
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.HITs.Susp
open import Cubical.HITs.Join
open import Cubical.HITs.Wedge
open import Cubical.HITs.SmashProduct
-- There's also a proof of the "3x3 lemma" for pushouts in less than
-- 200LOC. In HoTT-Agda this took about 3000LOC. For details see:
-- https://github.com/HoTT/HoTT-Agda/tree/master/theorems/homotopy/3x3
open import Cubical.HITs.Pushout
-- We also defined the Hopf fibration and proved that its total space
-- is S³ in about 300LOC:
open import Cubical.Homotopy.Hopf
open S¹Hopf
-- There is also some integer cohomology:
open import Cubical.ZCohomology.Everything
-- To compute cohomology groups of various spaces we need a bunch of
-- interesting theorems: Freudenthal suspension theorem,
-- Mayer-Vietoris sequence...
open import Cubical.Homotopy.Freudenthal
open import Cubical.ZCohomology.MayerVietorisUnreduced
-------------------------------------------------------------------------
-- The structure identity principle
-- A more efficient version of finite multisets based on association lists
open import Cubical.HITs.AssocList.Base
-- data AssocList (A : Type) : Type where
-- ⟨⟩ : AssocList A
-- ⟨_,_⟩∷_ : (a : A) (n : ℕ) (xs : AssocList A) → AssocList A
-- per : (a b : A) (m n : ℕ) (xs : AssocList A)
-- → ⟨ a , m ⟩∷ ⟨ b , n ⟩∷ xs ≡ ⟨ b , n ⟩∷ ⟨ a , m ⟩∷ xs
-- agg : (a : A) (m n : ℕ) (xs : AssocList A)
-- → ⟨ a , m ⟩∷ ⟨ a , n ⟩∷ xs ≡ ⟨ a , m + n ⟩∷ xs
-- del : (a : A) (xs : AssocList A) → ⟨ a , 0 ⟩∷ xs ≡ xs
-- trunc : (xs ys : AssocList A) (p q : xs ≡ ys) → p ≡ q
-- Programming and proving is more complicated with AssocList compared
-- to FMSet. This kind of example occurs everywhere in programming and
-- mathematics: one representation is easier to work with, but not
-- efficient, while another is efficient but difficult to work with.
-- Solution: substitute using univalence
substIso : {A B : Type} (P : Type → Type) (e : Iso A B) → P A → P B
substIso P e = subst P (isoToPath e)
-- Can transport for example Monoid structure from FMSet to AssocList
-- this way, but the achieved Monoid structure is not very efficient
-- to work with. A better solution is to prove that FMSet and
-- AssocList are equal *as monoids*, but how to do this?
-- Solution: structure identity principle (SIP)
-- This is a very useful consequence of univalence
open import Cubical.Foundations.SIP
sip' : {ℓ : Level} {S : Type ℓ → Type ℓ} {ι : StrEquiv S ℓ}
(θ : UnivalentStr S ι) (A B : TypeWithStr ℓ S) → A ≃[ ι ] B → A ≡ B
sip' = sip
-- The tricky thing is to prove that (S,ι) is a univalent structure.
-- Luckily we provide automation for this in the library, see for example:
open import Cubical.Algebra.Monoid.Base
-- Another cool application of the SIP: matrices represented as
-- functions out of pairs of Fin's and vectors are equal as abelian
-- groups:
open import Cubical.Algebra.Matrix
-- The end, back to slides!
| 30.805233 | 91 | 0.629329 |
39a88769e3a876207b8d1af3b0f2fd860796400b | 1,283 | agda | Agda | agda/Avionics/Probability.agda | RPI-WCL/safety-envelopes-sentinels | 896e67a2ad21041a1c9ef5f3ad6318c67d730341 | [
"BSD-3-Clause"
] | null | null | null | agda/Avionics/Probability.agda | RPI-WCL/safety-envelopes-sentinels | 896e67a2ad21041a1c9ef5f3ad6318c67d730341 | [
"BSD-3-Clause"
] | null | null | null | agda/Avionics/Probability.agda | RPI-WCL/safety-envelopes-sentinels | 896e67a2ad21041a1c9ef5f3ad6318c67d730341 | [
"BSD-3-Clause"
] | null | null | null | {-# OPTIONS --allow-unsolved-metas #-}
module Avionics.Probability where
open import Data.Nat using (ℕ; zero; suc)
open import Relation.Unary using (_∈_)
open import Avionics.Real using (
ℝ; _+_; _-_; _*_; _÷_; _^_; √_; 1/_; _^2;
-1/2; π; e; 2ℝ;
⟨0,∞⟩; [0,∞⟩; [0,1])
--postulate
-- Vec : Set → ℕ → Set
-- Mat : Set → ℕ → ℕ → Set
record Dist (Input : Set) : Set where
field
pdf : Input → ℝ
cdf : Input → ℝ
pdf→[0,∞⟩ : ∀ x → pdf x ∈ [0,∞⟩
cdf→[0,1] : ∀ x → cdf x ∈ [0,1]
--∫pdf≡cdf : ∫ pdf ≡ cdf
--∫pdf[-∞,∞]≡1ℝ : ∫ pdf [ -∞ , ∞ ] ≡ 1ℝ
record NormalDist : Set where
constructor ND
field
μ : ℝ
σ : ℝ
dist : Dist ℝ
dist = record
{
pdf = pdf
; cdf = ?
; pdf→[0,∞⟩ = ?
; cdf→[0,1] = ?
}
where
√2π = (√ (2ℝ * π))
1/⟨σ√2π⟩ = (1/ (σ * √2π))
pdf : ℝ → ℝ
pdf x = 1/⟨σ√2π⟩ * e ^ (-1/2 * (⟨x-μ⟩÷σ ^2))
where
⟨x-μ⟩÷σ = ((x - μ) ÷ σ)
--MultiNormal : ∀ {n : ℕ} → Vec ℝ n → Mat ℝ n n → Dist (Vec ℝ n)
--MultiNormal {n} means cov = record
-- {
-- pdf = ?
-- ; cdf = ?
-- }
--Things to prove using this approach
--_ : ∀ (mean1 std1 mean2 std2 x)
-- → Dist.pdf (Normal mean1 std1) x + Dist.pdf (Normal mean2 std2) x ≡ Dist.pdf (Normal (mean1 + mean2) (...))
| 21.745763 | 111 | 0.47311 |
23f78c7361920216f7bc36d72f3a782430067d85 | 784 | agda | Agda | Cubical/Data/InfNat/Base.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | 1 | 2020-03-23T23:52:11.000Z | 2020-03-23T23:52:11.000Z | Cubical/Data/InfNat/Base.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | Cubical/Data/InfNat/Base.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Data.InfNat.Base where
open import Cubical.Data.Nat as ℕ using (ℕ)
open import Cubical.Core.Primitives
data ℕ+∞ : Type₀ where
∞ : ℕ+∞
fin : ℕ → ℕ+∞
suc : ℕ+∞ → ℕ+∞
suc ∞ = ∞
suc (fin n) = fin (ℕ.suc n)
zero : ℕ+∞
zero = fin ℕ.zero
caseInfNat : ∀ {ℓ} → {A : Type ℓ} → (aF aI : A) → ℕ+∞ → A
caseInfNat aF aI (fin n) = aF
caseInfNat aF aI ∞ = aI
infixl 6 _+_
_+_ : ℕ+∞ → ℕ+∞ → ℕ+∞
∞ + m = ∞
fin n + ∞ = ∞
fin n + fin m = fin (n ℕ.+ m)
infixl 7 _*_
_*_ : ℕ+∞ → ℕ+∞ → ℕ+∞
fin m * fin n = fin (m ℕ.* n)
∞ * fin ℕ.zero = zero
fin ℕ.zero * ∞ = zero
∞ * ∞ = ∞
∞ * fin (ℕ.suc _) = ∞
fin (ℕ.suc _) * ∞ = ∞
| 21.189189 | 57 | 0.443878 |
0e6e6d4c1efa85657fc648cb181a7103dce2b49a | 2,298 | agda | Agda | vendor/stdlib/src/Data/List/Equality.agda | isabella232/Lemmachine | 8ef786b40e4a9ab274c6103dc697dcb658cf3db3 | [
"MIT"
] | 56 | 2015-01-20T02:11:42.000Z | 2021-12-21T17:02:19.000Z | vendor/stdlib/src/Data/List/Equality.agda | larrytheliquid/Lemmachine | 8ef786b40e4a9ab274c6103dc697dcb658cf3db3 | [
"MIT"
] | 1 | 2022-03-12T12:17:51.000Z | 2022-03-12T12:17:51.000Z | vendor/stdlib/src/Data/List/Equality.agda | isabella232/Lemmachine | 8ef786b40e4a9ab274c6103dc697dcb658cf3db3 | [
"MIT"
] | 3 | 2015-07-21T16:37:58.000Z | 2022-03-12T11:54:10.000Z | ------------------------------------------------------------------------
-- List equality
------------------------------------------------------------------------
module Data.List.Equality where
open import Data.List
open import Relation.Nullary
open import Relation.Binary
module Equality (S : Setoid) where
open Setoid S renaming (_≈_ to _≊_)
infixr 5 _∷_
infix 4 _≈_
data _≈_ : List carrier → List carrier → Set where
[] : [] ≈ []
_∷_ : ∀ {x xs y ys} (x≈y : x ≊ y) (xs≈ys : xs ≈ ys) →
x ∷ xs ≈ y ∷ ys
setoid : Setoid
setoid = record
{ carrier = List carrier
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl'
; sym = sym'
; trans = trans'
}
}
where
refl' : Reflexive _≈_
refl' {[]} = []
refl' {x ∷ xs} = refl ∷ refl' {xs}
sym' : Symmetric _≈_
sym' [] = []
sym' (x≈y ∷ xs≈ys) = sym x≈y ∷ sym' xs≈ys
trans' : Transitive _≈_
trans' [] [] = []
trans' (x≈y ∷ xs≈ys) (y≈z ∷ ys≈zs) =
trans x≈y y≈z ∷ trans' xs≈ys ys≈zs
open Setoid setoid public hiding (_≈_)
module DecidableEquality (D : DecSetoid) where
open DecSetoid D hiding (_≈_)
open Equality setoid renaming (setoid to List-setoid)
decSetoid : DecSetoid
decSetoid = record
{ isDecEquivalence = record
{ isEquivalence = Setoid.isEquivalence List-setoid
; _≟_ = dec
}
}
where
dec : Decidable _≈_
dec [] [] = yes []
dec (x ∷ xs) (y ∷ ys) with x ≟ y | dec xs ys
... | yes x≈y | yes xs≈ys = yes (x≈y ∷ xs≈ys)
... | no ¬x≈y | _ = no helper
where
helper : ¬ _≈_ (x ∷ xs) (y ∷ ys)
helper (x≈y ∷ _) = ¬x≈y x≈y
... | _ | no ¬xs≈ys = no helper
where
helper : ¬ _≈_ (x ∷ xs) (y ∷ ys)
helper (_ ∷ xs≈ys) = ¬xs≈ys xs≈ys
dec [] (y ∷ ys) = no λ()
dec (x ∷ xs) [] = no λ()
open DecSetoid decSetoid public
module PropositionalEquality {A : Set} where
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_) renaming (refl to ≡-refl)
open Equality (PropEq.setoid A) public
≈⇒≡ : _≈_ ⇒ _≡_
≈⇒≡ [] = ≡-refl
≈⇒≡ (≡-refl ∷ xs≈ys) with ≈⇒≡ xs≈ys
≈⇒≡ (≡-refl ∷ xs≈ys) | ≡-refl = ≡-refl
| 25.820225 | 72 | 0.477807 |
dfbcf7e8a17efef13e33d9812d44058cc0f7f4ef | 674 | agda | Agda | test/Fail/ShapeIrrelevantParameterNoBecauseOfRecursion.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/ShapeIrrelevantParameterNoBecauseOfRecursion.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/ShapeIrrelevantParameterNoBecauseOfRecursion.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 ShapeIrrelevantParameterNoBecauseOfRecursion where
data ⊥ : Set where
record ⊤ : Set where
data Bool : Set where
true false : Bool
True : Bool → Set
True false = ⊥
True true = ⊤
data D ..(b : Bool) : Set where
c : True b → D b -- should fail
-- Jesper, 2017-09-14: I think the definition of D is fine, but the definition
-- of cast below should fail since `D a` and `D b` are different types.
-- Jesper, 2018-11-15: I disagree with Jesper!2017, D should be rejected.
fromD : {b : Bool} → D b → True b
fromD (c p) = p
cast : .(a b : Bool) → D a → D b
cast _ _ x = x
bot : ⊥
bot = fromD (cast true false (c _))
| 22.466667 | 78 | 0.651335 |
20ae99d8b2d4486f41f17bad0d8cfebff614daf6 | 2,786 | agda | Agda | src/LibraBFT/Impl/IO/OBM/Properties/Start.agda | LaudateCorpus1/bft-consensus-agda | a4674fc473f2457fd3fe5123af48253cfb2404ef | [
"UPL-1.0"
] | null | null | null | src/LibraBFT/Impl/IO/OBM/Properties/Start.agda | LaudateCorpus1/bft-consensus-agda | a4674fc473f2457fd3fe5123af48253cfb2404ef | [
"UPL-1.0"
] | null | null | null | src/LibraBFT/Impl/IO/OBM/Properties/Start.agda | LaudateCorpus1/bft-consensus-agda | a4674fc473f2457fd3fe5123af48253cfb2404ef | [
"UPL-1.0"
] | null | null | null | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
open import LibraBFT.Concrete.Records
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Impl.Consensus.ConsensusProvider as ConsensusProvider
open import LibraBFT.Impl.Consensus.Properties.ConsensusProvider as ConsensusProviderProps
import LibraBFT.Impl.IO.OBM.GenKeyFile as GenKeyFile
open import LibraBFT.Impl.IO.OBM.InputOutputHandlers
open import LibraBFT.Impl.IO.OBM.Start
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.NetworkMsg
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.PKCS
open import Util.Prelude
open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms
open Invariants
open RoundManagerTransProps
open InitProofDefs
module LibraBFT.Impl.IO.OBM.Properties.Start where
module startViaConsensusProviderSpec
(now : Instant)
(nfl : GenKeyFile.NfLiwsVsVvPe)
(txTDS : TxTypeDependentStuffForNetwork)
where
-- It is somewhat of an overkill to write a separate contract for the last step,
-- but keeping it explicit for pedagogical reasons
contract-step₁ : ∀ (tup : (NodeConfig × OnChainConfigPayload × LedgerInfoWithSignatures × SK × ProposerElection))
→ EitherD-weakestPre (startViaConsensusProvider-ed.step₁ now nfl txTDS tup) (InitContract nothing)
contract-step₁ (nodeConfig , payload , liws , sk , pe) =
startConsensusSpec.contract' nodeConfig now payload liws sk ObmNeedFetch∙new
(txTDS ^∙ ttdsnProposalGenerator) (txTDS ^∙ ttdsnStateComputer)
contract' : EitherD-weakestPre (startViaConsensusProvider-ed-abs now nfl txTDS) (InitContract nothing)
contract' rewrite startViaConsensusProvider-ed-abs-≡ =
-- TODO-2: this is silly; perhaps we should have an EitherD-⇒-bind-const or something for when
-- we don't need to know anything about the values returned by part before the bind?
EitherD-⇒-bind (ConsensusProvider.obmInitialData-ed-abs nfl)
(EitherD-vacuous (ConsensusProvider.obmInitialData-ed-abs nfl))
P⇒Q
where
P⇒Q : EitherD-Post-⇒ (const Unit) (EitherD-weakestPre-bindPost _ (InitContract nothing))
P⇒Q (Left _) _ = tt
P⇒Q (Right tup') _ c refl = contract-step₁ tup'
| 48.034483 | 115 | 0.753769 |
0ece5c884cadcbc10ccb7846f8df14d3dfec964c | 185 | agda | Agda | Cubical/Data/DescendingList.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | Cubical/Data/DescendingList.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | Cubical/Data/DescendingList.agda | limemloh/cubical | df4ef7edffd1c1deb3d4ff342c7178e9901c44f1 | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --safe #-}
module Cubical.Data.DescendingList where
open import Cubical.Data.DescendingList.Base public
open import Cubical.Data.DescendingList.Properties public
| 30.833333 | 57 | 0.810811 |
cbc389bd2033dd620b687c3d3fd2bb7756a3339e | 442 | agda | Agda | test/Succeed/Issue3134.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue3134.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue3134.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
open import Agda.Builtin.Equality
postulate
⊤ ⊥ : Set
_&_ : Set → Set → Set
_≤_ : Nat → Nat → Set
{-# TERMINATING #-}
_∣_ : Nat → Nat → Set
m ∣ zero = ⊤
zero ∣ suc n = ⊥
suc m ∣ suc n = (suc m ≤ suc n) & (suc m ∣ (n - m))
variable m n : Nat
postulate
divide-to-nat : n ∣ m → Nat
trivial : m ≡ n
divide-to-nat-correct : (e : m ∣ n) → divide-to-nat e * n ≡ m
divide-to-nat-correct e = trivial
| 18.416667 | 61 | 0.570136 |
1881f05bd1ec35505d7144fd0a1364127236e3c2 | 466 | agda | Agda | test/Succeed/Issue353.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue353.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue353.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- {-# OPTIONS -v tc.polarity:10 #-}
module Issue353 where
data Func : Set₁ where
K : (A : Set) → Func
-- Doesn't work.
module M where
const : ∀ {A B : Set₁} → A → B → A
const x = λ _ → x
⟦_⟧ : Func → Set → Set
⟦ K A ⟧ X = const A X
data μ (F : Func) : Set where
⟨_⟩ : ⟦ F ⟧ (μ F) → μ F
-- Error: μ is not strictly positive, because it occurs in the second
-- argument to ⟦_⟧ in the type of the constructor ⟨_⟩ in the
-- definition of μ.
| 21.181818 | 71 | 0.564378 |
dc9924299a6d2c4aab8aa21fae49aa8d8977250f | 753 | agda | Agda | Sets/IterativeSet.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Sets/IterativeSet.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Sets/IterativeSet.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | module Sets.IterativeSet where
import Lvl
open import Logic
open import Type
module _ where
private variable {ℓ ℓ₁ ℓ₂} : Lvl.Level
-- A model of constructive set theory (CZF) by using W-types (iterative sets).
-- The interpretation of Iset being a type of sets comes from the idea that the image of `elem` is a set of elements.
record Iset : Type{Lvl.𝐒(ℓ)} where
constructor set
inductive
pattern
field
{Index} : Type{ℓ}
elem : Index → Iset{ℓ}
open Iset
Iset-index-induction : ∀{P : Iset{ℓ₁} → Stmt{ℓ₂}} → (∀{A : Iset{ℓ₁}} → (∀{i : Index(A)} → P(elem(A)(i))) → P(A)) → (∀{A : Iset{ℓ₁}} → P(A))
Iset-index-induction {P = P} proof {set elem} = proof{_} \{i} → Iset-index-induction{P = P} proof {elem(i)}
| 32.73913 | 141 | 0.63081 |
101f2d65360cc65c0e445e87bb5b037c4510928a | 1,684 | agda | Agda | code/SizeLoop.agda | ionathanch/msc-thesis | 8fe15af8f9b5021dc50bcf96665e0988abf28f3c | [
"CC-BY-4.0"
] | null | null | null | code/SizeLoop.agda | ionathanch/msc-thesis | 8fe15af8f9b5021dc50bcf96665e0988abf28f3c | [
"CC-BY-4.0"
] | null | null | null | code/SizeLoop.agda | ionathanch/msc-thesis | 8fe15af8f9b5021dc50bcf96665e0988abf28f3c | [
"CC-BY-4.0"
] | null | null | null | {-
A counterexample from Section 5.1 of Andreas Abel's dissertation [1],
showing that the types of recursive functions must be (semi-)continuous,
i.e. `loop` below should be disallowed.
In the example, `loop` is not used as-is, but rather the size involved
is instantiated to the infinite size in order to pass in `plus2`.
The conditions on ω-instantiating from John Hughes' paper [2] is
essentially a stricter condition than Abel's semi-continuity on where
size variables may appear in the type.
[1] A Polymorphic Lambda-Calculus with Sized Higher-Order Types
[2] Proving the Correctness of Reactive Systems using Sized Types
-}
data Size : Set where
∘ : Size
↑_ : Size → Size
data Nat : Size → Set where
zero : ∀ {s} → Nat (↑ s)
succ : ∀ {s} → Nat s → Nat (↑ s)
data NatInf : Set where
⟦_⟧ : ∀ {s} → Nat s → NatInf
zero∘ : Nat (↑ ∘)
zero∘ = zero {∘}
shift : ∀ {s} → (NatInf → Nat (↑ (↑ s))) → NatInf → Nat (↑ s)
shift f ⟦ n ⟧ with f ⟦ succ n ⟧
... | zero = zero
... | succ m = m
plus2 : NatInf → NatInf
plus2 ⟦ n ⟧ = ⟦ succ (succ n) ⟧
loop : ∀ {s} → Nat s → (NatInf → Nat (↑ s)) → NatInf
loop _ f with f ⟦ zero∘ ⟧
... | zero = ⟦ zero∘ ⟧
... | succ zero = ⟦ zero∘ ⟧
... | succ (succ k) = loop k (shift f)
{-
Interpreting Nat^∞ as a size-paired natural, we need to somehow
derive an infinity-instantiated version (`loopInf`) using `loop`,
but we cannot produce a `NatInf → Nat (↑ s)` out of `NatInf → NatInf`:
doing so amounts to proving `∃s. Nat s → ∀s. Nat s`.
-}
-- loop cannot be instantiated with an infinite size
postulate loopInf : NatInf → (NatInf → NatInf) → NatInf
uhoh : NatInf
uhoh = loopInf ⟦ zero∘ ⟧ plus2
| 30.071429 | 74 | 0.635392 |
398aec7a1c4de554f55cbf0e9a1a85ef7cfdf95a | 1,043 | agda | Agda | src/Algebra/LabelledGraph/Reasoning.agda | algebraic-graphs/alga-theory | 0fdb96c0233d9be83eba637f0434d0fd22aefb1d | [
"MIT"
] | 60 | 2017-12-27T14:57:04.000Z | 2022-03-22T23:05:29.000Z | src/Algebra/LabelledGraph/Reasoning.agda | algebraic-graphs/alga-theory | 0fdb96c0233d9be83eba637f0434d0fd22aefb1d | [
"MIT"
] | 3 | 2018-04-12T16:25:13.000Z | 2018-06-23T13:54:02.000Z | src/Algebra/LabelledGraph/Reasoning.agda | algebraic-graphs/alga-theory | 0fdb96c0233d9be83eba637f0434d0fd22aefb1d | [
"MIT"
] | 6 | 2017-12-17T20:48:20.000Z | 2019-05-09T23:53:28.000Z | module Algebra.LabelledGraph.Reasoning where
open import Algebra.Dioid
open import Algebra.LabelledGraph
-- Standard syntax sugar for writing equational proofs
infix 4 _≈_
data _≈_ {A B eq} {d : Dioid B eq} (x y : LabelledGraph d A) : Set where
prove : x ≡ y -> x ≈ y
infix 1 begin_
begin_ : ∀ {A B eq} {d : Dioid B eq} {x y : LabelledGraph d A} -> x ≈ y -> x ≡ y
begin prove p = p
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : ∀ {A B eq} {d : Dioid B eq} (x : LabelledGraph d A) {y z : LabelledGraph d A} -> x ≡ y -> y ≈ z -> x ≈ z
_ ≡⟨ p ⟩ prove q = prove (transitivity p q)
infix 3 _∎
_∎ : ∀ {A B eq} {d : Dioid B eq} (x : LabelledGraph d A) -> x ≈ x
_∎ _ = prove reflexivity
infixl 8 _>>_
_>>_ : ∀ {A B eq} {d : Dioid B eq} {x y z : LabelledGraph d A} -> x ≡ y -> y ≡ z -> x ≡ z
_>>_ = transitivity
L : ∀ {A B eq} {d : Dioid B eq} {x y z : LabelledGraph d A} {r : B} -> x ≡ y -> x [ r ]> z ≡ y [ r ]> z
L = left-congruence
R : ∀ {A B eq} {d : Dioid B eq} {x y z : LabelledGraph d A} {r : B} -> x ≡ y -> z [ r ]> x ≡ z [ r ]> y
R = right-congruence
| 32.59375 | 113 | 0.563758 |
107e39e07959ea91c2f80a85579617eb7aaa222d | 2,069 | agda | Agda | agda-stdlib/src/Data/List/Kleene/AsList.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | agda-stdlib/src/Data/List/Kleene/AsList.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | agda-stdlib/src/Data/List/Kleene/AsList.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | ------------------------------------------------------------------------
-- The Agda standard library
--
-- A different interface to the Kleene lists, designed to mimic
-- Data.List.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Kleene.AsList where
open import Level as Level using (Level)
private
variable
a b c : Level
A : Set a
B : Set b
C : Set c
import Data.List.Kleene.Base as Kleene
------------------------------------------------------------------------
-- Here we import half of the functions from Data.KleeneList: the half
-- for possibly-empty lists.
open import Data.List.Kleene.Base public
using ([])
renaming
( _* to List
; foldr* to foldr
; foldl* to foldl
; _++*_ to _++_
; map* to map
; mapMaybe* to mapMaybe
; pure* to pure
; _<*>*_ to _<*>_
; _>>=*_ to _>>=_
; mapAccumˡ* to mapAccumˡ
; mapAccumʳ* to mapAccumʳ
; _[_]* to _[_]
; applyUpTo* to applyUpTo
; upTo* to upTo
; zipWith* to zipWith
; unzipWith* to unzipWith
; partitionSumsWith* to partitionSumsWith
; reverse* to reverse
)
------------------------------------------------------------------------
-- A pattern which mimics Data.List._∷_
infixr 5 _∷_
pattern _∷_ x xs = Kleene.∹ x Kleene.& xs
------------------------------------------------------------------------
-- The following functions change the type of the list (from ⁺ to * or vice
-- versa) in Data.KleeneList, so we reimplement them here to keep the
-- type the same.
scanr : (A → B → B) → B → List A → List B
scanr f b xs = Kleene.∹ Kleene.scanr* f b xs
scanl : (B → A → B) → B → List A → List B
scanl f b xs = Kleene.∹ Kleene.scanl* f b xs
tails : List A → List (List A)
tails xs = foldr (λ x xs → (Kleene.∹ x) ∷ xs) ([] ∷ []) (Kleene.tails* xs)
| 29.985507 | 75 | 0.455776 |
10666ba728d368d4ddbb4dbddef755e4f1c9301a | 3,671 | agda | Agda | examples/outdated-and-incorrect/cbs/Proof.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/Proof.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/Proof.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Proof where
open import Basics hiding (_==_)
open import Proc
open import Path
import Graph
private
open module G = Graph Nat
open module P = Process param hiding (U; T; _!_)
{-
Soundness:
if we get an answer there is a path
Completeness:
if there is a path we get an answer
-}
infix 18 _encodes_
data _encodes_ {G : Graph} :
{x y : Nat} -> List Node -> Path G x y -> Set where
nul-path : {x : Nat} -> stop :: [] encodes nul {x = x}
step-path : {x y z : Nat}{xs : List Node}
{step : Step G x y}{path : Path G y z} ->
xs encodes path ->
node y :: xs encodes step <> path
test : {G : Graph}{a b c : Nat}
{ab : Step G a b}{bc : Step G b c} ->
node b :: node c :: stop :: [] encodes
ab <> bc <> nul
test = step-path (step-path nul-path)
target : {G : Graph}{x y : Nat} -> Step G x y -> Nat
target {y = y} _ = y
encoding : {G : Graph}{x y : Nat} -> Path G x y -> List Node
encoding nul = stop :: []
encoding (step <> path) = node (target step) :: encoding path
lem-encode : {G : Graph}{x y : Nat}(path : Path G x y) ->
encoding path encodes path
lem-encode nul = nul-path
lem-encode (step <> path) = step-path (lem-encode path)
data WellFormed : List Node -> Set where
good-stop : WellFormed (stop :: [])
good-:: : forall {x xs} -> WellFormed xs -> WellFormed (node x :: xs)
data MalFormed : List Node -> Set where
bad-[] : MalFormed []
bad-:: : forall {x xs} -> MalFormed xs -> MalFormed (node x :: xs)
bad-stop : forall {x xs} -> MalFormed (stop :: x :: xs)
module Theorems (G : Graph)(start end : Nat) where
mainp = main G start end
Complete : Set
Complete = (path : Path G start end) ->
∃ \q -> Silent q /\
mainp -! encoding path !->* q
Sound : Set
Sound = forall q xs -> Silent q -> WellFormed xs ->
mainp -! xs !->* q ->
∃ \(path : Path G start end) -> xs encodes path
Sound-Fail : Set
Sound-Fail = forall q xs -> Silent q -> MalFormed xs ->
mainp -! xs !->* q -> Path G start end -> False
silent-edges : {a : U} -> Graph -> Proc a
silent-edges [] = o
silent-edges (_ :: G) = o || silent-edges G
silent-silent-edges : {a : U}(G : Graph) -> Silent (silent-edges {a} G)
silent-silent-edges [] = silent-o
silent-silent-edges (_ :: G) = silent-|| silent-o (silent-silent-edges G)
module Proofs (G : Graph) where
private open module T = Theorems G
complete : (start end : Nat) -> Complete start end
complete x .x nul =
∃-intro q (silent-q , run)
where
edg₁ = {! !}
edg₂ = {! !}
edg₃ = silent-edges G
silent-edg₃ : Silent edg₃
silent-edg₃ = silent-silent-edges G
q = φ /| o || o || edg₃
silent-q : Silent q
silent-q = silent-/| (silent-|| silent-o (silent-|| silent-o silent-edg₃))
rx-edg₁ : edges G -[ lift (forward stop (node x)) ]-> edg₁
rx-edg₁ = {! !}
rx-edg₂ : edg₁ -[ {! !} ]-> edg₂
rx-edg₂ = {! !}
run-edg₃ : φ /| o || o || edg₂ -! [] !->* φ /| o || o || edg₃
run-edg₃ = {! !}
tx-batter : (n : Nat) ->
if node n == node n
then backward stop ! o
else def (start x)
-! lift (backward stop) !-> o
tx-batter zero = tx-!
tx-batter (suc n) = tx-batter n
run : mainp x x -! stop :: [] !->* q
run = (tx-/| (tx-!|
(tx-def tx-!)
(rx-|| (rx-def rx->) rx-edg₁)))
>*>
(tx-/| (tx-|! rx-o (tx-!| (tx-batter x) rx-edg₂)))
>!>
run-edg₃
| 27.601504 | 80 | 0.517298 |
d030e1dbec3b9dda2e98e0782c16d5980adc2d8f | 312 | agda | Agda | test/succeed/IndexOnBuiltin.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2019-11-27T04:41:05.000Z | 2019-11-27T04:41:05.000Z | test/succeed/IndexOnBuiltin.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/succeed/IndexOnBuiltin.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | module IndexOnBuiltin where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
data Fin : Nat -> Set where
fz : {n : Nat} -> Fin (suc n)
fs : {n : Nat} -> Fin n -> Fin (suc n)
f : Fin 2 -> Fin 1
f fz = fz
f (fs i) = i
| 16.421053 | 40 | 0.538462 |
cb0cefeb35679421ec05bde7c494006e45cdebf0 | 1,384 | agda | Agda | test/Succeed/Issue2101.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Succeed/Issue2101.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/Succeed/Issue2101.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z | -- Andreas, 2016-07-17 issue 2101 reported by Serge Mechveliani.
-- It should be possible to place a single function with a where block
-- inside `abstract`.
-- This will work if type signatures inside a where-block
-- are considered private, since in private type signatures,
-- abstract definitions are transparent.
-- (Unlike in public type signatures.)
record Wrap (A : Set) : Set where
field unwrap : A
postulate
P : ∀{A : Set} → A → Set
module AbstractPrivate (A : Set) where
abstract
B : Set
B = Wrap A
postulate
b : B
private -- this makes abstract defs transparent in type signatures
postulate
test : P (Wrap.unwrap b) -- should succeed
abstract
unnamedWhere : (A : Set) → Set
unnamedWhere A = A
where -- the following definitions are private!
B : Set
B = Wrap A
postulate
b : B
test : P (Wrap.unwrap b) -- should succeed
namedWherePrivate : (A : Set) → Set
namedWherePrivate A = A
module MP where
B : Set
B = Wrap A
private
postulate
b : B
test : P (Wrap.unwrap b) -- should succeed
namedWhereAnonymous : (A : Set) → Set
namedWhereAnonymous A = A
module _ where -- the definitions in this module are not private!
B : Set
B = Wrap A
private
postulate
b : B
test : P (Wrap.unwrap b) -- should succeed
| 21.968254 | 70 | 0.631503 |
395aa45da6e443c6d6a7400031f40cf1c078fbd9 | 1,937 | agda | Agda | src/Examples/Sorting/Comparable.agda | jonsterling/agda-calf | e51606f9ca18d8b4cf9a63c2d6caa2efc5516146 | [
"Apache-2.0"
] | 29 | 2021-07-14T03:18:28.000Z | 2022-03-22T20:35:11.000Z | src/Examples/Sorting/Comparable.agda | jonsterling/agda-calf | e51606f9ca18d8b4cf9a63c2d6caa2efc5516146 | [
"Apache-2.0"
] | null | null | null | src/Examples/Sorting/Comparable.agda | jonsterling/agda-calf | e51606f9ca18d8b4cf9a63c2d6caa2efc5516146 | [
"Apache-2.0"
] | 2 | 2021-10-06T10:28:24.000Z | 2022-01-29T08:12:01.000Z | {-# OPTIONS --prop --rewriting #-}
open import Calf.CostMonoid
open import Data.Nat using (ℕ)
module Examples.Sorting.Comparable
(costMonoid : CostMonoid) (fromℕ : ℕ → CostMonoid.ℂ costMonoid) where
open CostMonoid costMonoid using (ℂ)
open import Calf costMonoid
open import Calf.Types.Bool
open import Calf.Types.Bounded costMonoid
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; module ≡-Reasoning)
open import Data.Product using (_×_; _,_; proj₁; proj₂; ∃)
open import Function
record Comparable : Set₁ where
field
A : tp pos
_≤_ : val A → val A → Set
_≤ᵇ_ : val A → val A → cmp (F bool)
≤ᵇ-reflects-≤ : ∀ {x y b} → ◯ ((x ≤ᵇ y) ≡ ret b → Reflects (x ≤ y) b)
≤-refl : Reflexive _≤_
≤-trans : Transitive _≤_
≤-total : Total _≤_
≤-antisym : Antisymmetric _≡_ _≤_
h-cost : (x y : val A) → IsBounded bool (x ≤ᵇ y) (fromℕ 1)
NatComparable : Comparable
NatComparable = record
{ A = nat
; _≤_ = _≤_
; _≤ᵇ_ = λ x y → step (F bool) (fromℕ 1) (ret (x ≤ᵇ y))
; ≤ᵇ-reflects-≤ = reflects
; ≤-refl = ≤-refl
; ≤-trans = ≤-trans
; ≤-total = ≤-total
; ≤-antisym = ≤-antisym
; h-cost = λ _ _ →
bound/relax
(λ u → CostMonoid.≤-reflexive costMonoid (CostMonoid.+-identityʳ costMonoid (fromℕ 1)))
(bound/step (fromℕ 1) (CostMonoid.zero costMonoid) bound/ret)
}
where
open import Calf.Types.Nat
open import Data.Nat
open import Data.Nat.Properties
ret-injective : ∀ {𝕊 v₁ v₂} → ret {U (meta 𝕊)} v₁ ≡ ret {U (meta 𝕊)} v₂ → v₁ ≡ v₂
ret-injective {𝕊} = Eq.cong (λ e → bind {U (meta 𝕊)} (meta 𝕊) e id)
reflects : ∀ {m n b} → ◯ (step (F bool) (fromℕ 1) (ret (m ≤ᵇ n)) ≡ ret {bool} b → Reflects (m ≤ n) b)
reflects {m} {n} {b} u h with ret-injective (Eq.subst (_≡ ret b) (step/ext (F bool) (ret (m ≤ᵇ n)) (fromℕ 1) u) h)
... | refl = ≤ᵇ-reflects-≤ m n
| 31.754098 | 118 | 0.617966 |
cb871915319534c4077375a3c69f969df259fc6c | 662 | agda | Agda | test/Succeed/Issue2484-3.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 2 | 2019-10-29T09:40:30.000Z | 2020-09-20T00:28:57.000Z | test/Succeed/Issue2484-3.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/Succeed/Issue2484-3.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z | module _ (_ : Set) where
open import Agda.Builtin.Size
postulate
I : Set
record ∃ (B : I → Set) : Set where
constructor _,_
field
proj₁ : I
proj₂ : B proj₁
mutual
data P (i : Size) (x y : I) : Set where
⟨_⟩ : ∃ (Q i x) → P i x y
record Q (i : Size) (x y : I) : Set where
coinductive
field
force : {j : Size< i} → P j x y
postulate
map : (B : I → Set) → (∀ x → B x → B x) → ∃ B → ∃ B
lemma : ∀ x y i → Q i x y → Q i x y
p : ∀ x i → P i x x
q′ : ∀ x i → ∃ λ y → Q i x y
q : ∀ x i → Q i x x
q′ x i = x , q x i
p x i = ⟨ map _ (λ y → lemma x y _) (q′ x _) ⟩
Q.force (q x i) {j} = p _ _
| 18.914286 | 60 | 0.453172 |
dcb6e3331b852ada164f61679cbde3736594f220 | 71 | agda | Agda | test/Fail/IndentedCheckingMessages.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/IndentedCheckingMessages.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/IndentedCheckingMessages.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module IndentedCheckingMessages where
import A.M
Foo : Set
Foo = Foo
| 10.142857 | 37 | 0.774648 |
10f3954b1bca967aad685d54960e8cdfd9daeb1e | 30 | agda | Agda | Categories/Topos.agda | copumpkin/categories | 36f4181d751e2ecb54db219911d8c69afe8ba892 | [
"BSD-3-Clause"
] | 98 | 2015-04-15T14:57:33.000Z | 2022-03-08T05:20:36.000Z | Categories/Topos.agda | p-pavel/categories | e41aef56324a9f1f8cf3cd30b2db2f73e01066f2 | [
"BSD-3-Clause"
] | 19 | 2015-05-23T06:47:10.000Z | 2019-08-09T16:31:40.000Z | Categories/Topos.agda | p-pavel/categories | e41aef56324a9f1f8cf3cd30b2db2f73e01066f2 | [
"BSD-3-Clause"
] | 23 | 2015-02-05T13:03:09.000Z | 2021-11-11T13:50:56.000Z | module Categories.Topos where
| 15 | 29 | 0.866667 |
23f2816284495c7828793df5804b81a580c84e57 | 7,732 | agda | Agda | README/DependentlyTyped/NBE.agda | nad/dependently-typed-syntax | 498f8aefc570f7815fd1d6616508eeb92c52abce | [
"MIT"
] | 5 | 2020-04-16T12:14:44.000Z | 2020-07-08T22:51:36.000Z | README/DependentlyTyped/NBE.agda | nad/dependently-typed-syntax | 498f8aefc570f7815fd1d6616508eeb92c52abce | [
"MIT"
] | null | null | null | README/DependentlyTyped/NBE.agda | nad/dependently-typed-syntax | 498f8aefc570f7815fd1d6616508eeb92c52abce | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- Normalisation by evaluation
------------------------------------------------------------------------
import Axiom.Extensionality.Propositional as E
import Level
open import Data.Universe
-- The code makes use of the assumption that propositional equality of
-- functions is extensional.
module README.DependentlyTyped.NBE
(Uni₀ : Universe Level.zero Level.zero)
(ext : E.Extensionality Level.zero Level.zero)
where
open import Data.Empty
open import Data.Product renaming (curry to c)
open import deBruijn.Substitution.Data
open import Function hiding (_∋_) renaming (const to k)
import README.DependentlyTyped.NormalForm as NF
open NF Uni₀ renaming ([_] to [_]n)
import README.DependentlyTyped.Term as Term; open Term Uni₀
import README.DependentlyTyped.Term.Substitution as S; open S Uni₀
import Relation.Binary.PropositionalEquality as P
open import Relation.Nullary using (¬_)
open P.≡-Reasoning
-- The values that are used by the NBE algorithm.
import README.DependentlyTyped.NBE.Value as Value
open Value Uni₀ public
-- Weakening for the values.
import README.DependentlyTyped.NBE.Weakening as Weakening
open Weakening Uni₀ ext public
-- Application.
infix 9 [_]_·̌_
[_]_·̌_ : ∀ {Γ sp₁ sp₂} σ →
V̌alue Γ (π sp₁ sp₂ , σ) → (v : V̌alue Γ (fst σ)) →
V̌alue Γ (snd σ /̂ ŝub ⟦̌ v ⟧)
[ _ ] f ·̌ v = proj₁ f ε v
abstract
-- Lifting can be expressed using žero.
∘̂-ŵk-▻̂-žero : ∀ {Γ Δ} (ρ̂ : Γ ⇨̂ Δ) σ →
ρ̂ ∘̂ ŵk ▻̂[ σ ] ⟦ žero _ (proj₂ σ /̂I ρ̂) ⟧n ≅-⇨̂ ρ̂ ↑̂ σ
∘̂-ŵk-▻̂-žero ρ̂ σ = begin
[ ρ̂ ∘̂ ŵk ▻̂ ⟦ žero _ _ ⟧n ] ≡⟨ ▻̂-cong P.refl P.refl (ňeutral-to-normal-identity _ (var zero)) ⟩
[ ρ̂ ∘̂ ŵk ▻̂ ⟦ var zero ⟧ ] ≡⟨ P.refl ⟩
[ ρ̂ ↑̂ ] ∎
mutual
-- Evaluation.
eval : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} →
Γ ⊢ σ → Sub V̌al ρ̂ → V̌alue Δ (σ /̂ ρ̂)
eval (var x) ρ = x /∋ ρ
eval (ƛ t) ρ = (eval[ƛ t ] ρ) , eval[ƛ t ] ρ well-behaved
eval (t₁ · t₂) ρ = eval[ t₁ · t₂ ] ρ
-- Some abbreviations.
eval[ƛ_] : ∀ {Γ Δ σ τ} {ρ̂ : Γ ⇨̂ Δ} →
Γ ▻ σ ⊢ τ → Sub V̌al ρ̂ → V̌alue-π Δ _ _ (IType-π σ τ /̂I ρ̂)
eval[ƛ t ] ρ Γ₊ v = eval t (V̌al-subst.wk-subst₊ Γ₊ ρ ▻ v)
eval[_·_] : ∀ {Γ Δ sp₁ sp₂ σ} {ρ̂ : Γ ⇨̂ Δ} →
Γ ⊢ (π sp₁ sp₂ , σ) → (t₂ : Γ ⊢ fst σ) → Sub V̌al ρ̂ →
V̌alue Δ (snd σ /̂ ŝub ⟦ t₂ ⟧ ∘̂ ρ̂)
eval[_·_] {σ = σ} t₁ t₂ ρ =
cast ([ σ /I ρ ] eval t₁ ρ ·̌ eval t₂ ρ)
where
cast = P.subst (λ v → V̌alue _ (snd σ /̂ ⟦ ρ ⟧⇨ ↑̂ /̂ ŝub v))
(≅-Value-⇒-≡ $ P.sym $ eval-lemma t₂ ρ)
abstract
-- The ƛ case is well-behaved.
eval[ƛ_]_well-behaved :
∀ {Γ Δ σ τ} {ρ̂ : Γ ⇨̂ Δ} (t : Γ ▻ σ ⊢ τ) (ρ : Sub V̌al ρ̂) →
W̌ell-behaved _ _ (IType-π σ τ /I ρ) (eval[ƛ t ] ρ)
eval[ƛ_]_well-behaved {σ = σ} {τ = τ} t ρ Γ₊ v =
let υ = IType-π σ τ /I ρ in begin
[ (⟦̌ υ ∣ eval[ƛ t ] ρ ⟧-π /̂Val ŵk₊ Γ₊) ˢ ⟦̌ v ⟧ ] ≡⟨ ˢ-cong (/̂Val-cong (P.sym $ eval-lemma-ƛ t ρ) P.refl) P.refl ⟩
[ (c ⟦ t ⟧ /̂Val ⟦ ρ ⟧⇨ ∘̂ ŵk₊ Γ₊) ˢ ⟦̌ v ⟧ ] ≡⟨ P.refl ⟩
[ ⟦ t ⟧ /̂Val (⟦ ρ ⟧⇨ ∘̂ ŵk₊ Γ₊ ▻̂ ⟦̌ v ⟧) ] ≡⟨ eval-lemma t _ ⟩
[ ⟦̌ eval t (V̌al-subst.wk-subst₊ Γ₊ ρ ▻ v) ⟧ ] ∎
-- An unfolding lemma.
eval-· :
∀ {Γ Δ sp₁ sp₂ σ} {ρ̂ : Γ ⇨̂ Δ}
(t₁ : Γ ⊢ π sp₁ sp₂ , σ) (t₂ : Γ ⊢ fst σ) (ρ : Sub V̌al ρ̂) →
eval[ t₁ · t₂ ] ρ ≅-V̌alue [ σ /I ρ ] eval t₁ ρ ·̌ eval t₂ ρ
eval-· {σ = σ} t₁ t₂ ρ =
drop-subst-V̌alue (λ v → snd σ /̂ ⟦ ρ ⟧⇨ ↑̂ /̂ ŝub v)
(≅-Value-⇒-≡ $ P.sym $ eval-lemma t₂ ρ)
-- The evaluator is correct (with respect to the standard
-- semantics).
eval-lemma : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (t : Γ ⊢ σ) (ρ : Sub V̌al ρ̂) →
⟦ t ⟧ /Val ρ ≅-Value ⟦̌ eval t ρ ⟧
eval-lemma (var x) ρ = V̌al-subst./̂∋-⟦⟧⇨ x ρ
eval-lemma (ƛ t) ρ = eval-lemma-ƛ t ρ
eval-lemma (_·_ {σ = σ} t₁ t₂) ρ = begin
[ ⟦ t₁ · t₂ ⟧ /Val ρ ] ≡⟨ P.refl ⟩
[ (⟦ t₁ ⟧ /Val ρ) ˢ (⟦ t₂ ⟧ /Val ρ) ] ≡⟨ ˢ-cong (eval-lemma t₁ ρ) (eval-lemma t₂ ρ) ⟩
[ ⟦̌_⟧ {σ = σ /I ρ} (eval t₁ ρ) ˢ ⟦̌ eval t₂ ρ ⟧ ] ≡⟨ proj₂ (eval t₁ ρ) ε (eval t₂ ρ) ⟩
[ ⟦̌ [ σ /I ρ ] eval t₁ ρ ·̌ eval t₂ ρ ⟧ ] ≡⟨ ⟦̌⟧-cong (P.sym $ eval-· t₁ t₂ ρ) ⟩
[ ⟦̌ eval[ t₁ · t₂ ] ρ ⟧ ] ∎
private
eval-lemma-ƛ :
∀ {Γ Δ σ τ} {ρ̂ : Γ ⇨̂ Δ} (t : Γ ▻ σ ⊢ τ) (ρ : Sub V̌al ρ̂) →
⟦ ƛ t ⟧ /Val ρ ≅-Value ⟦̌ IType-π σ τ /I ρ ∣ eval[ƛ t ] ρ ⟧-π
eval-lemma-ƛ {σ = σ} {τ = τ} t ρ =
let υ = IType-π σ τ /I ρ
ρ↑ = V̌al-subst.wk-subst₊ (σ / ρ ◅ ε) ρ ▻ v̌ar ⊙ zero
in begin
[ c ⟦ t ⟧ /Val ρ ] ≡⟨ P.refl ⟩
[ c (⟦ t ⟧ /̂Val ⟦ ρ ⟧⇨ ↑̂) ] ≡⟨ curry-cong $ /̂Val-cong (P.refl {x = [ ⟦ t ⟧ ]})
(P.sym $ ∘̂-ŵk-▻̂-žero ⟦ ρ ⟧⇨ _) ⟩
[ c (⟦ t ⟧ /Val ρ↑) ] ≡⟨ curry-cong (eval-lemma t ρ↑) ⟩
[ c ⟦̌ eval t ρ↑ ⟧ ] ≡⟨ P.sym $ unfold-⟦̌∣⟧-π υ (eval[ƛ t ] ρ) ⟩
[ ⟦̌ υ ∣ eval[ƛ t ] ρ ⟧-π ] ∎
-- Normalisation.
normalise : ∀ {Γ σ} → Γ ⊢ σ → Γ ⊢ σ ⟨ no ⟩
normalise t = řeify _ (eval t V̌al-subst.id)
-- Normalisation is semantics-preserving.
normalise-lemma : ∀ {Γ σ} (t : Γ ⊢ σ) → ⟦ t ⟧ ≅-Value ⟦ normalise t ⟧n
normalise-lemma t = eval-lemma t V̌al-subst.id
-- Some congruence lemmas.
·̌-cong :
∀ {Γ₁ sp₁₁ sp₂₁ σ₁}
{f₁ : V̌alue Γ₁ (π sp₁₁ sp₂₁ , σ₁)} {v₁ : V̌alue Γ₁ (fst σ₁)}
{Γ₂ sp₁₂ sp₂₂ σ₂}
{f₂ : V̌alue Γ₂ (π sp₁₂ sp₂₂ , σ₂)} {v₂ : V̌alue Γ₂ (fst σ₂)} →
σ₁ ≅-IType σ₂ → _≅-V̌alue_ {σ₁ = -, σ₁} f₁ {σ₂ = -, σ₂} f₂ →
v₁ ≅-V̌alue v₂ →
[ σ₁ ] f₁ ·̌ v₁ ≅-V̌alue [ σ₂ ] f₂ ·̌ v₂
·̌-cong P.refl P.refl P.refl = P.refl
eval-cong :
∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {t₁ : Γ₁ ⊢ σ₁} {ρ₁ : Sub V̌al ρ̂₁}
{Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {t₂ : Γ₂ ⊢ σ₂} {ρ₂ : Sub V̌al ρ̂₂} →
t₁ ≅-⊢ t₂ → ρ₁ ≅-⇨ ρ₂ → eval t₁ ρ₁ ≅-V̌alue eval t₂ ρ₂
eval-cong P.refl P.refl = P.refl
normalise-cong :
∀ {Γ₁ σ₁} {t₁ : Γ₁ ⊢ σ₁}
{Γ₂ σ₂} {t₂ : Γ₂ ⊢ σ₂} →
t₁ ≅-⊢ t₂ → normalise t₁ ≅-⊢n normalise t₂
normalise-cong P.refl = P.refl
abstract
-- Note that we can /not/ prove that normalise takes semantically
-- equal terms to identical normal forms, assuming extensionality
-- and the existence of a universe code which decodes to an empty
-- type:
normal-forms-not-unique :
E.Extensionality Level.zero Level.zero →
(∃ λ (bot : U₀) → ¬ El₀ bot) →
¬ (∀ {Γ σ} (t₁ t₂ : Γ ⊢ σ) →
⟦ t₁ ⟧ ≅-Value ⟦ t₂ ⟧ → normalise t₁ ≅-⊢n normalise t₂)
normal-forms-not-unique ext (bot , empty) hyp = ⊥-elim (x₁≇x₂ x₁≅x₂)
where
Γ : Ctxt
Γ = ε ▻ (⋆ , _) ▻ (⋆ , _) ▻ (el , k bot)
x₁ : Γ ∋ (⋆ , _)
x₁ = suc (suc zero)
x₂ : Γ ∋ (⋆ , _)
x₂ = suc zero
x₁≇x₂ : ¬ (ne ⋆ (var x₁) ≅-⊢n ne ⋆ (var x₂))
x₁≇x₂ ()
⟦x₁⟧≡⟦x₂⟧ : ⟦ var x₁ ⟧ ≅-Value ⟦ var x₂ ⟧
⟦x₁⟧≡⟦x₂⟧ = P.cong [_] (ext λ γ → ⊥-elim $ empty $ proj₂ γ)
norm-x₁≅norm-x₂ : normalise (var x₁) ≅-⊢n normalise (var x₂)
norm-x₁≅norm-x₂ = hyp (var x₁) (var x₂) ⟦x₁⟧≡⟦x₂⟧
lemma : (x : Γ ∋ (⋆ , _)) → normalise (var x) ≅-⊢n ne ⋆ (var x)
lemma x = begin
[ normalise (var x) ]n ≡⟨ P.refl ⟩
[ ne ⋆ (x /∋ V̌al-subst.id) ]n ≡⟨ ne-cong $ ≅-Value-⋆-⇒-≅-⊢n $ V̌al-subst./∋-id x ⟩
[ ne ⋆ (var x) ]n ∎
x₁≅x₂ : ne ⋆ (var x₁) ≅-⊢n ne ⋆ (var x₂)
x₁≅x₂ = begin
[ ne ⋆ (var x₁) ]n ≡⟨ P.sym $ lemma x₁ ⟩
[ normalise (var x₁) ]n ≡⟨ norm-x₁≅norm-x₂ ⟩
[ normalise (var x₂) ]n ≡⟨ lemma x₂ ⟩
[ ne ⋆ (var x₂) ]n ∎
| 35.46789 | 125 | 0.474392 |
4a6e719d59c1cdf7109b53da90597f880b8bcb25 | 1,483 | agda | Agda | notes/FOT/FOTC/Program/Mirror/Induction/InductionPrinciples.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 11 | 2015-09-03T20:53:42.000Z | 2021-09-12T16:09:54.000Z | notes/FOT/FOTC/Program/Mirror/Induction/InductionPrinciples.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 2 | 2016-10-12T17:28:16.000Z | 2017-01-01T14:34:26.000Z | notes/FOT/FOTC/Program/Mirror/Induction/InductionPrinciples.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 3 | 2016-09-19T14:18:30.000Z | 2018-03-14T08:50:00.000Z | ------------------------------------------------------------------------------
-- Induction principles for Tree and Forest
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Mirror.Induction.InductionPrinciples where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
-- These induction principles *not cover* the mutual structure of the
-- types Tree and Rose (Bertot and Casterán, 2004, p. 401).
-- Induction principle for Tree.
Tree-ind : (A : D → Set) →
(∀ d {ts} → Forest ts → A (node d ts)) →
∀ {t} → Tree t → A t
Tree-ind A h (tree d Fts) = h d Fts
-- Induction principle for Forest.
Forest-ind : (A : D → Set) →
A [] →
(∀ {t ts} → Tree t → Forest ts → A ts → A (t ∷ ts)) →
∀ {ts} → Forest ts → A ts
Forest-ind A A[] h fnil = A[]
Forest-ind A A[] h (fcons Tt Fts) = h Tt Fts (Forest-ind A A[] h Fts)
------------------------------------------------------------------------------
-- References
--
-- Bertot, Yves and Castéran, Pierre (2004). Interactive Theorem
-- Proving and Program Development. Coq’Art: The Calculus of Inductive
-- Constructions. Springer.
| 37.075 | 78 | 0.47269 |
d0c0673d7807830d72daa03b51cea3fc559f057b | 326 | agda | Agda | README.agda | jonaprieto/agda-prop | a1730062a6aaced2bb74878c1071db06477044ae | [
"MIT"
] | 13 | 2017-05-01T16:45:41.000Z | 2022-01-17T03:33:12.000Z | README.agda | jonaprieto/agda-prop | a1730062a6aaced2bb74878c1071db06477044ae | [
"MIT"
] | 18 | 2017-03-08T14:33:10.000Z | 2017-12-18T16:34:21.000Z | README.agda | jonaprieto/agda-prop | a1730062a6aaced2bb74878c1071db06477044ae | [
"MIT"
] | 2 | 2017-03-30T16:41:56.000Z | 2017-12-01T17:01:25.000Z | open import Data.Nat using ( ℕ )
module README ( n : ℕ ) where
------------------------------------------------------------------------------
-- Agda-Prop Library.
-- Deep Embedding for Propositional Logic.
------------------------------------------------------------------------------
open import Data.PropFormula n public | 32.6 | 78 | 0.377301 |
dc90a3f57fee49eafa8283522ef59dee01f7b1d5 | 2,216 | agda | Agda | Syntax/Implication.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Syntax/Implication.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Syntax/Implication.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | -- Example:
-- postulate ℓ : Lvl.Level
-- postulate A B C D : Type{ℓ}
-- postulate a : A
-- postulate ab : A → B
-- postulate bc : B → C
-- postulate cd : C → D
--
-- ad : A → D
-- ad =
-- A ⇒-[ ab ]
-- B ⇒-[ bc ]
-- C ⇒-[ cd ]
-- D ⇒-end
--
-- d : D
-- d =
-- a ⇒
-- A ⇒-[ ab ]
-- B ⇒-[ bc ]
-- C ⇒-[ cd ]
-- D ⇒-end
module Syntax.Implication where
open import Functional using (const ; id ; _∘_ ; _∘₂_ ; _∘₃_ ; swap)
open import Logic.Propositional
import Lvl
import Syntax.Implication.Dependent as Dependent
open import Type
private variable ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ : Lvl.Level
open Dependent using (_⇒-end ; _⇒_) public
_⇒-start_ : ∀{X : Type{ℓ₁}}{Y : Type{ℓ₂}} → X → (X → Y) → Y
_⇒-start_ x xy = xy x
infixr 0.98 _⇒-start_
{-# INLINE _⇒-start_ #-}
_⇒-[_]_ : ∀(X : Type{ℓ₁}){Y : Type{ℓ₂}}{Z : Type{ℓ₃}} → (X → Y) → (Y → Z) → (X → Z)
_⇒-[_]_ _ = swap(_∘_)
infixr 0.98 _⇒-[_]_
{-# INLINE _⇒-[_]_ #-}
_⇒-[]_ : ∀(X : Type{ℓ₁}){Y : Type{ℓ₂}} → (X → Y) → (X → Y)
_⇒-[]_ _ = id
infixr 0.98 _⇒-[]_
{-# INLINE _⇒-[]_ #-}
•_•_⇒₂-[_]_ : ∀{X₁ : Type{ℓ₁}}{X₂ : Type{ℓ₂}}{Y : Type{ℓ₃}}{Z : Type{ℓ₄}} → X₁ → X₂ → (X₁ → X₂ → Y) → (Y → Z) → Z
•_•_⇒₂-[_]_ x₁ x₂ g f = (f ∘₂ g) x₁ x₂
infixr 0.97 •_•_⇒₂-[_]_
{-# INLINE •_•_⇒₂-[_]_ #-}
•_•_•_⇒₃-[_]_ : ∀{X₁ : Type{ℓ₁}}{X₂ : Type{ℓ₂}}{X₃ : Type{ℓ₃}}{Y : Type{ℓ₄}}{Z : Type{ℓ₅}} → X₁ → X₂ → X₃ → (X₁ → X₂ → X₃ → Y) → (Y → Z) → Z
•_•_•_⇒₃-[_]_ x₁ x₂ x₃ g f = (f ∘₃ g) x₁ x₂ x₃
infixr 0.97 •_•_•_⇒₃-[_]_
{-# INLINE •_•_•_⇒₃-[_]_ #-}
_⇔-end : ∀(X : Type{ℓ₁}) → (X ↔ X)
_⇔-end _ = [↔]-intro id id
infixr 0.99 _⇔-end
{-# INLINE _⇔-end #-}
_⇔_ = Functional.apply
infixl 0.97 _⇔_
{-# INLINE _⇔_ #-}
_⇔-[_]_ : ∀(X : Type{ℓ₁}){Y : Type{ℓ₂}}{Z : Type{ℓ₃}} → (X ↔ Y) → (Y ↔ Z) → (X ↔ Z)
_⇔-[_]_ _ ([↔]-intro pₗ pᵣ) ([↔]-intro qₗ qᵣ) = [↔]-intro (pₗ ∘ qₗ) (qᵣ ∘ pᵣ)
infixr 0.98 _⇔-[_]_
{-# INLINE _⇔-[_]_ #-}
_⇔-[_]-sym_ : ∀(X : Type{ℓ₁}){Y : Type{ℓ₂}}{Z : Type{ℓ₃}} → (Y ↔ X) → (Y ↔ Z) → (X ↔ Z)
_⇔-[_]-sym_ X ([↔]-intro pₗ pᵣ) q = X ⇔-[ ([↔]-intro pᵣ pₗ) ] q
infixr 0.98 _⇔-[_]-sym_
{-# INLINE _⇔-[_]-sym_ #-}
_⇔-[]_ : ∀(X : Type{ℓ₁}){Y : Type{ℓ₂}} → (X ↔ Y) → (X ↔ Y)
_⇔-[]_ _ = id
infixr 0.98 _⇔-[]_
{-# INLINE _⇔-[]_ #-}
| 26.698795 | 140 | 0.466606 |
230a2144d37701d0bd970977aae5530d7fda0f97 | 8,258 | agda | Agda | LibraBFT/Abstract/Records.agda | oracle/bft-consensus-agda | 49f8b1b70823be805d84ffc3157c3b880edb1e92 | [
"UPL-1.0"
] | 4 | 2020-12-16T19:43:41.000Z | 2021-12-18T19:24:05.000Z | LibraBFT/Abstract/Records.agda | oracle/bft-consensus-agda | 49f8b1b70823be805d84ffc3157c3b880edb1e92 | [
"UPL-1.0"
] | 72 | 2021-02-04T05:04:33.000Z | 2022-03-25T05:36:11.000Z | LibraBFT/Abstract/Records.agda | oracle/bft-consensus-agda | 49f8b1b70823be805d84ffc3157c3b880edb1e92 | [
"UPL-1.0"
] | 6 | 2020-12-16T19:43:52.000Z | 2022-02-18T01:04:32.000Z | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Abstract.Types.EpochConfig
open import LibraBFT.Base.Types
open import LibraBFT.Lemmas
open import LibraBFT.Prelude
open WithAbsVote
-- This module defines abstract records (the initial or "genesis" record, blocks, and quorum
-- certificates), along with related definitions and properties.
module LibraBFT.Abstract.Records
(UID : Set)
(_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁)) -- Needed to prove ≟Block and ≈?QC
(NodeId : Set)
(𝓔 : EpochConfig UID NodeId)
(𝓥 : VoteEvidence UID NodeId 𝓔)
where
open import LibraBFT.Abstract.Types UID NodeId
open EpochConfig 𝓔
-- Abstract blocks do /not/ need to carry the state hash. Since the
-- state hash of a concrete block is supposed to be hashed in the
-- UID of an abstract one; the connection between states is implicit.
-- Our proofs all work modulo injectivity of UID anyway.
record Block : Set where
constructor Block∙new
field
bRound : Round
bId : UID
bPrevQC : Maybe UID -- 'nothing' indicates it extends the genesis block.
open Block public
Block-η : {b b' : Block}
→ bRound b ≡ bRound b'
→ bId b ≡ bId b'
→ bPrevQC b ≡ bPrevQC b'
→ b ≡ b'
Block-η refl refl refl = refl
-- We define a Vote as an AbsVoteData applied
-- to the correct parameters; This helps in defining
-- and manipulating the 𝓥 vote evidence predicate.
Vote : Set
Vote = AbsVoteData UID NodeId 𝓔
vRound : Vote → Round
vRound = abs-vRound
vMember : Vote → EpochConfig.Member 𝓔
vMember = abs-vMember
vBlockUID : Vote → UID
vBlockUID = abs-vBlockUID
Vote-η : {v v' : Vote}
→ vRound v ≡ vRound v' → vMember v ≡ vMember v'
→ vBlockUID v ≡ vBlockUID v'
→ v ≡ v'
Vote-η refl refl refl = refl
-- * Quorum Certificates
--
-- A valid quorum certificate contains at least 'QuorumSize ec'
-- votes from different authors.
record QC : Set where
constructor QC∙new
field
qRound : Round
qCertBlockId : UID -- this is the id for the block it certifies.
qVotes : List Vote
-- The voters form a quorum
qVotes-C1 : IsQuorum (List-map vMember qVotes)
-- All votes are for the same blockId
qVotes-C2 : All (λ v → vBlockUID v ≡ qCertBlockId) qVotes
-- Likewise for rounds
qVotes-C3 : All (λ v → vRound v ≡ qRound) qVotes
-- And we have evidence for all votes
qVotes-C4 : All 𝓥 qVotes
open QC public
------------------------
-- QC's make a setoid --
------------------------
-- Two QC's are said to be equivalent if they have the same ID;
-- that is, they certify the same block. As we are talking about
-- /abstract/ QCs, we have proofs that both have at least QuorumSize
-- votes for /the same block/!
--
-- It might be tempting to want qRound q₀ ≡ qRound q₁ in here,
-- but the proof of ←-≈Rec in LibraBFT.Abstract.Records.Extends
-- would be impossible.
_≈QC_ : QC → QC → Set
q₀ ≈QC q₁ = qCertBlockId q₀ ≡ qCertBlockId q₁
_≈QC?_ : (q₀ q₁ : QC) → Dec (q₀ ≈QC q₁)
q₀ ≈QC? q₁ with qCertBlockId q₀ ≟UID qCertBlockId q₁
...| yes refl = yes refl
...| no neq = no λ x → neq x
≈QC-refl : Reflexive _≈QC_
≈QC-refl = refl
≈QC-sym : Symmetric _≈QC_
≈QC-sym refl = refl
≈QC-trans : Transitive _≈QC_
≈QC-trans refl x = x
QC-setoid : Setoid ℓ0 ℓ0
QC-setoid = record
{ Carrier = QC
; _≈_ = _≈QC_
; isEquivalence = record
{ refl = λ {q} → ≈QC-refl {q}
; sym = λ {q} {u} → ≈QC-sym {q} {u}
; trans = λ {q} {u} {l} → ≈QC-trans {q} {u} {l}
}
}
-- Accessing common fields in different Records types is a nuissance; yet, Blocks,
-- votes and QC's all have three important common fields: author, round and maybe the
-- ID of a previous record. Therefore we declare a type-class that provide "getters"
-- for commonly used fields.
record HasRound (A : Set) : Set where
constructor is-librabft-record
field
getRound : A → Round
open HasRound {{...}} public
instance
block-is-record : HasRound Block
block-is-record = is-librabft-record bRound
vote-is-record : HasRound Vote
vote-is-record = is-librabft-record vRound
qc-is-record : HasRound QC
qc-is-record = is-librabft-record qRound
_≟Block_ : (b₀ b₁ : Block) → Dec (b₀ ≡ b₁)
b₀ ≟Block b₁
with bRound b₀ ≟ bRound b₁
...| no neq = no λ x → neq (cong bRound x)
...| yes r≡
with (bId b₀) ≟UID (bId b₁)
...| no neq = no λ x → neq (cong bId x)
...| yes i≡
with Maybe-≡-dec {A = UID} _≟UID_ (bPrevQC b₀) (bPrevQC b₁)
...| no neq = no λ x → neq (cong bPrevQC x)
...| yes p≡ = yes (Block-η r≡ i≡ p≡)
qcVotes : QC → List Vote
qcVotes = qVotes
-- Now we can state whether an author has voted in a given QC.
_∈QC_ : Member → QC → Set
a ∈QC qc = Any (λ v → vMember v ≡ a) (qcVotes qc)
∈QC-Member : ∀{α}(q : QC)(v : α ∈QC q)
→ α ≡ vMember (List-lookup (qcVotes q) (Any-index v))
∈QC-Member {α} q v = aux v
where
aux : ∀{vs}(p : Any (λ v → vMember v ≡ α) vs)
→ α ≡ vMember (List-lookup vs (Any-index p))
aux (here px) = sym px
aux (there p) = aux p
-- Gets the vote of a ∈QC
-- TODO-1: make q explicit; a implicit
∈QC-Vote : {a : Member} (q : QC) → (a ∈QC q) → Vote
∈QC-Vote q a∈q = Any-lookup a∈q
∈QC-Vote-correct : ∀ q → {a : Member} → (p : a ∈QC q)
→ (∈QC-Vote {a} q p) ∈ qcVotes q
∈QC-Vote-correct q a∈q = Any-lookup-correct a∈q
-- Same vote in two QC's means the QCs are equivalent
∈QC-Vote-≈ : {v : Vote}{q q' : QC}
→ v ∈ qcVotes q → v ∈ qcVotes q'
→ q ≈QC q'
∈QC-Vote-≈ {v} {q} {q'} vq vq'
= trans (sym (All-lookup (qVotes-C2 q) vq))
(All-lookup (qVotes-C2 q') vq')
-- A record is either one of the types introduced above or the initial/genesis record.
data Record : Set where
I : Record
B : Block → Record
Q : QC → Record
-- Records are equivalent if and only if they are either not
-- QCs and propositionally equal or they are equivalent qcs.
data _≈Rec_ : Record → Record → Set where
eq-I : I ≈Rec I
eq-Q : ∀{q₀ q₁} → q₀ ≈QC q₁ → Q q₀ ≈Rec Q q₁
eq-B : ∀{b₀ b₁} → b₀ ≡ b₁ → B b₀ ≈Rec B b₁
≈Rec-refl : Reflexive _≈Rec_
≈Rec-refl {I} = eq-I
≈Rec-refl {B x} = eq-B refl
≈Rec-refl {Q x} = eq-Q (≈QC-refl {x})
≈Rec-sym : Symmetric _≈Rec_
≈Rec-sym {I} eq-I = eq-I
≈Rec-sym {B x} (eq-B prf) = eq-B (sym prf)
≈Rec-sym {Q x} {Q y} (eq-Q prf) = eq-Q (≈QC-sym {x} {y} prf)
≈Rec-trans : Transitive _≈Rec_
≈Rec-trans {I} eq-I eq-I = eq-I
≈Rec-trans {B x} (eq-B p₀) (eq-B p₁) = eq-B (trans p₀ p₁)
≈Rec-trans {Q x} {Q y} {Q z} (eq-Q p₀) (eq-Q p₁) = eq-Q (≈QC-trans {x} {y} {z} p₀ p₁)
Rec-setoid : Setoid ℓ0 ℓ0
Rec-setoid = record
{ Carrier = Record
; _≈_ = _≈Rec_
; isEquivalence = record
{ refl = λ {q} → ≈Rec-refl {q}
; sym = λ {q} {u} → ≈Rec-sym {q} {u}
; trans = λ {q} {u} {l} → ≈Rec-trans {q} {u} {l}
}
}
-- Record unique ids carry whether the abstract id was assigned
-- to a QC or a Block; this can be useful to avoid having to deal
-- with 'blockId ≟ initialAgreedID' in order to decide whether
-- a block is the genesis block or not.
data TypedUID : Set where
id-I : TypedUID
id-B∨Q : UID -> TypedUID
id-I≢id-B∨Q : ∀{id} → id-I ≡ id-B∨Q id → ⊥
id-I≢id-B∨Q ()
id-B∨Q-inj : ∀{u₁ u₂} → id-B∨Q u₁ ≡ id-B∨Q u₂ → u₁ ≡ u₂
id-B∨Q-inj refl = refl
uid : Record → TypedUID
uid I = id-I
uid (B b) = id-B∨Q (bId b)
uid (Q q) = id-B∨Q (qCertBlockId q)
-- Each record has a round
round : Record → Round
round I = 0
round (B b) = getRound b
round (Q q) = getRound q
| 32.511811 | 111 | 0.581012 |
189b4fb2aeabf0ad7fcda56f7107fe1841b0f6a6 | 10,168 | agda | Agda | src/M.agda | nad/equality | 402b20615cfe9ca944662380d7b2d69b0f175200 | [
"MIT"
] | 3 | 2020-05-21T22:58:50.000Z | 2021-09-02T17:18:15.000Z | src/M.agda | nad/equality | 402b20615cfe9ca944662380d7b2d69b0f175200 | [
"MIT"
] | null | null | null | src/M.agda | nad/equality | 402b20615cfe9ca944662380d7b2d69b0f175200 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- M-types
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types #-}
open import Equality
module M
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq as Bijection using (_↔_)
open Derived-definitions-and-properties eq
import Equivalence eq as Eq
open import Function-universe eq hiding (_∘_)
open import Function-universe.Size eq
open import H-level eq
open import H-level.Closure eq
open import Prelude
open import Prelude.Size
------------------------------------------------------------------------
-- M-types
mutual
data M {a b} (A : Type a) (B : A → Type b) (i : Size) :
Type (a ⊔ b) where
dns : (x : A) (f : B x → M′ A B i) → M A B i
record M′ {a b} (A : Type a) (B : A → Type b) (i : Size) :
Type (a ⊔ b) where
coinductive
field
force : {j : Size< i} → M A B j
open M′ public
-- Projections.
pɐǝɥ : ∀ {a b i} {A : Type a} {B : A → Type b} →
M A B i → A
pɐǝɥ (dns x f) = x
lıɐʇ : ∀ {a b i} {j : Size< i} {A : Type a} {B : A → Type b} →
(x : M A B i) → B (pɐǝɥ x) → M A B j
lıɐʇ (dns x f) y = force (f y)
------------------------------------------------------------------------
-- Equality
-- M-types are isomorphic to Σ-types containing M-types (almost).
M-unfolding : ∀ {a b} {i} {A : Type a} {B : A → Type b} →
M A B i ↔ ∃ λ (x : A) → B x → M′ A B i
M-unfolding = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (dns x f) → x , f }
; from = uncurry dns
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (dns x f) → refl (dns x f) }
}
abstract
-- Equality between elements of an M-type can be proved using a pair
-- of equalities (assuming extensionality and a kind of η law).
--
-- Note that, because the equality type former is not sized, this
-- lemma is perhaps not very useful.
M-≡,≡↔≡ :
∀ {a b i} {A : Type a} {B : A → Type b} →
Extensionality b (a ⊔ b) →
(∀ {x} {f g : B x → M′ A B i} →
_≡_ {A = B x → {j : Size< i} → M A B j}
(force ∘ f) (force ∘ g) ↔
f ≡ g) →
∀ {x y} {f : B x → M′ A B i} {g : B y → M′ A B i} →
(∃ λ (p : x ≡ y) → ∀ b {j : Size< i} →
force (f b) {j = j} ≡ force (g (subst B p b))) ↔
_≡_ {A = M A B i} (dns x f) (dns y g)
M-≡,≡↔≡ {a} {i = i} {A} {B} ext η {x} {y} {f} {g} =
(∃ λ (p : x ≡ y) → ∀ b {j : Size< i} →
force (f b) {j = j} ≡ force (g (subst B p b))) ↝⟨ ∃-cong lemma ⟩
(∃ λ (p : x ≡ y) → subst (λ x → B x → M′ A B i) p f ≡ g) ↝⟨ Bijection.Σ-≡,≡↔≡ ⟩
(_≡_ {A = ∃ λ (x : A) → B x → M′ A B i} (x , f) (y , g)) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ M-unfolding) ⟩□
(dns x f ≡ dns y g) □
where
lemma : (p : x ≡ y) →
((b : B x) {j : Size< i} →
f b .force {j = j} ≡ g (subst B p b) .force) ↔
(subst (λ x → B x → M′ A B i) p f ≡ g)
lemma p = elim
(λ {x y} p → (f : B x → M′ A B i) (g : B y → M′ A B i) →
(∀ b {j : Size< i} → f b .force {j = j} ≡
g (subst B p b) .force) ↔
(subst (λ x → B x → M′ A B i) p f ≡ g))
(λ x f g →
(∀ b {j : Size< i} → f b .force {j = j} ≡
g (subst B (refl x) b) .force) ↝⟨ subst (λ h → (∀ b {j : Size< i} → f b .force ≡ g (h b) .force) ↔
(∀ b {j : Size< i} → f b .force ≡ g b .force))
(sym (apply-ext (lower-extensionality lzero a ext)
(subst-refl B)))
Bijection.id ⟩
(∀ b {j : Size< i} → f b .force {j = j} ≡ g b .force) ↔⟨ ∀-cong ext (λ _ → implicit-Π-size-≃-Π-size) ⟩
(∀ b (j : Size< i) → f b .force {j = j} ≡ g b .force) ↔⟨ ∀-cong ext (λ _ → Π-size-≃) ⟩
(∀ b (j : Size< i in-type) → f b .force {j = size j} ≡
g b .force {j = size j}) ↔⟨ ∀-cong ext (λ _ → Eq.extensionality-isomorphism
(lower-extensionality _ lzero ext)) ⟩
((b : B x) → _≡_ {A = (j : Size< i in-type) → M A B (size j)}
(λ j → f b .force {j = size j})
(λ j → g b .force {j = size j})) ↔⟨ ∀-cong ext (λ _ → Eq.≃-≡ $ Eq.↔⇒≃ Bijection.implicit-Π↔Π) ⟩
((b : B x) → _≡_ {A = {j : Size< i in-type} → M A B (size j)}
(λ {j} → f b .force {j = size j})
(λ {j} → g b .force {j = size j})) ↔⟨ ∀-cong ext (λ _ → Eq.≃-≡ implicit-Π-size-≃) ⟩
((b : B x) → _≡_ {A = {j : Size< i} → M A B j}
(λ { {j} → f b .force {j = j} })
(λ { {j} → g b .force {j = j} })) ↔⟨ Eq.extensionality-isomorphism ext ⟩
(force ∘ f ≡ force ∘ g) ↝⟨ η ⟩
(f ≡ g) ↝⟨ subst (λ h → (f ≡ g) ↔ (h ≡ g))
(sym $ subst-refl (λ x' → B x' → M′ A B i) f)
Bijection.id ⟩□
(subst (λ x → B x → M′ A B i) (refl x) f ≡ g) □)
p f g
------------------------------------------------------------------------
-- Bisimilarity and bisimilarity for bisimilarity
-- Bisimilarity.
mutual
infix 4 [_]_≡M_ [_]_≡M′_
data [_]_≡M_ {a b} {A : Type a} {B : A → Type b}
(i : Size) (x y : M A B ∞) : Type (a ⊔ b) where
dns : (p : pɐǝɥ x ≡ pɐǝɥ y) →
(∀ b → [ i ] lıɐʇ x b ≡M′ lıɐʇ y (subst B p b)) →
[ i ] x ≡M y
record [_]_≡M′_ {a b} {A : Type a} {B : A → Type b}
(i : Size) (x y : M A B ∞) : Type (a ⊔ b) where
coinductive
field
force : {j : Size< i} → [ j ] x ≡M y
open [_]_≡M′_ public
-- Projections.
pɐǝɥ≡ :
∀ {a b i} {A : Type a} {B : A → Type b} {x y : M A B ∞} →
[ i ] x ≡M y → pɐǝɥ x ≡ pɐǝɥ y
pɐǝɥ≡ (dns p q) = p
lıɐʇ≡ :
∀ {a b i} {A : Type a} {B : A → Type b} {x y : M A B ∞} →
(p : [ i ] x ≡M y) →
∀ b {j : Size< i} → [ j ] lıɐʇ x b ≡M lıɐʇ y (subst B (pɐǝɥ≡ p) b)
lıɐʇ≡ (dns p q) y = force (q y)
-- Equality implies bisimilarity.
≡⇒≡M : ∀ {a b i} {A : Type a} {B : A → Type b} {x y : M A B ∞} →
x ≡ y → [ i ] x ≡M y
≡⇒≡M {i = i} {B = B} {dns x f} {dns y g} p =
dns (proj₁ q) helper
where
q = elim (λ {m m′} m≡m′ →
∃ λ (x≡y : pɐǝɥ m ≡ pɐǝɥ m′) →
∀ b → lıɐʇ m b ≡ lıɐʇ m′ (subst B x≡y b))
(λ m → refl (pɐǝɥ m) , λ b →
lıɐʇ m b ≡⟨ cong (lıɐʇ m) (sym $ subst-refl B _) ⟩∎
lıɐʇ m (subst B (refl (pɐǝɥ m)) b) ∎)
p
helper :
∀ b →
[ i ] lıɐʇ (dns x f) b ≡M′ lıɐʇ (dns y g) (subst B (proj₁ q) b)
force (helper b) = ≡⇒≡M (proj₂ q b)
-- Bisimilarity for the bisimilarity type.
mutual
data [_]_≡≡M_ {a b} {A : Type a} {B : A → Type b} {x y : M A B ∞}
(i : Size) (p q : [ ∞ ] x ≡M y) : Type (a ⊔ b) where
dns : (r : pɐǝɥ≡ p ≡ pɐǝɥ≡ q) →
(∀ b → [ i ] lıɐʇ≡ p b ≡≡M′
subst (λ p → [ ∞ ] lıɐʇ x b ≡M
lıɐʇ y (subst B p b))
(sym r)
(lıɐʇ≡ q b)) →
[ i ] p ≡≡M q
record [_]_≡≡M′_ {a b} {A : Type a} {B : A → Type b} {x y : M A B ∞}
(i : Size) (p q : [ ∞ ] x ≡M y) : Type (a ⊔ b) where
coinductive
field
force : {j : Size< i} → [ j ] p ≡≡M q
open [_]_≡≡M′_ public
------------------------------------------------------------------------
-- Closure under various h-levels
abstract
-- If we assume a notion of extensionality (bisimilarity implies
-- equality) then Contractible is closed under M.
M-closure-contractible :
∀ {a b} {A : Type a} {B : A → Type b} →
({x y : M A B ∞} → [ ∞ ] x ≡M y → x ≡ y) →
Contractible A → Contractible (M A B ∞)
M-closure-contractible {A = A} {B} ext (z , irrA) = (x , ext ∘ irr)
where
x : ∀ {i} → M A B i
x = dns z λ _ → λ { .force → x }
irr : ∀ {i} y → [ i ] x ≡M y
irr {i} (dns x′ f) = dns (irrA x′) helper
where
helper : ∀ y → [ i ] x ≡M′ force (f (subst B (irrA x′) y))
force (helper _) = irr _
-- The same applies to Is-proposition.
M-closure-propositional :
∀ {a b} {A : Type a} {B : A → Type b} →
({x y : M A B ∞} → [ ∞ ] x ≡M y → x ≡ y) →
Is-proposition A → Is-proposition (M A B ∞)
M-closure-propositional {A = A} {B} ext p =
λ x y → ext $ irrelevant x y
where
irrelevant : ∀ {i} (x y : M A B ∞) → [ i ] x ≡M y
irrelevant {i} (dns x f) (dns y g) = dns (p x y) helper
where
helper :
(y′ : B x) →
[ i ] force (f y′) ≡M′ force (g (subst B (p x y) y′))
force (helper _) = irrelevant _ _
-- If we assume that we have another notion of extensionality, then
-- Is-set is closed under M.
M-closure-set :
∀ {a b} {A : Type a} {B : A → Type b} →
({x y : M A B ∞} {p q : x ≡ y} → [ ∞ ] ≡⇒≡M p ≡≡M ≡⇒≡M q → p ≡ q) →
Is-set A → Is-set (M A B ∞)
M-closure-set {A = A} {B} ext s =
λ p q → ext $ uip (≡⇒≡M p) (≡⇒≡M q)
where
uip : ∀ {i} {x y : M A B ∞} (p q : [ ∞ ] x ≡M y) → [ i ] p ≡≡M q
uip {i} {x} {y} (dns p f) (dns q g) = dns (s p q) helper
where
helper :
(b : B (pɐǝɥ x)) →
[ i ] force (f b) ≡≡M′
subst (λ eq → [ ∞ ] lıɐʇ x b ≡M lıɐʇ y (subst B eq b))
(sym (s p q))
(force (g b))
force (helper _) = uip _ _
| 36.974545 | 139 | 0.380016 |
1c10510d44e0775ad2a859ad05a6d61731b10add | 937 | agda | Agda | notes/thesis/report/FOTC/Even.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 11 | 2015-09-03T20:53:42.000Z | 2021-09-12T16:09:54.000Z | notes/thesis/report/FOTC/Even.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 2 | 2016-10-12T17:28:16.000Z | 2017-01-01T14:34:26.000Z | notes/thesis/report/FOTC/Even.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 3 | 2016-09-19T14:18:30.000Z | 2018-03-14T08:50:00.000Z | ------------------------------------------------------------------------------
-- Even predicate
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Even where
open import FOTC.Base
open import FOTC.Data.Nat.Type
------------------------------------------------------------------------------
data Even : D → Set where
ezero : Even zero
enext : ∀ {n} → Even n → Even (succ₁ (succ₁ n))
Even-ind : (A : D → Set) →
A zero →
(∀ {n} → A n → A (succ₁ (succ₁ n))) →
∀ {n} → Even n → A n
Even-ind A A0 h ezero = A0
Even-ind A A0 h (enext En) = h (Even-ind A A0 h En)
Even→N : ∀ {n} → Even n → N n
Even→N ezero = nzero
Even→N (enext En) = nsucc (nsucc (Even→N En))
| 30.225806 | 78 | 0.38207 |
104a9feaf915851e9d3b2e96d604fff0decda834 | 580 | agda | Agda | test/Succeed/Issue1592a.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Succeed/Issue1592a.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/Succeed/Issue1592a.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z | -- Andreas 2015-01-07 fixing polarity of projection-like functions
-- {-# OPTIONS -v tc.polarity:20 -v tc.proj.like:10 #-}
-- {-# OPTIONS -v tc.conv.elim:25 --show-implicit #-}
open import Common.Size
-- List covariant covariant
data List (i : Size) (A : Set) : Set where
[] : List i A
cons : ∀{j : Size< i} → A → List j A → List i A
-- Id mixed mixed mixed covariant
-- Id is projection-like in argument l
Id : ∀{i A} (l : List i A) → Set → Set
Id [] X = X
Id (cons _ _) X = X
-- should pass
cast : ∀{i A} (l : List i A) → Id l (List i A) → Id l (List ∞ A)
cast l x = x
| 26.363636 | 66 | 0.6 |
c53c8f55165034237128f22ec9bed845fe614f4c | 403 | agda | Agda | examples/outdated-and-incorrect/lattice/Chain.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/lattice/Chain.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/lattice/Chain.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
module Chain
{ A : Set }
(_==_ : A -> A -> Set )
(refl : (x : A) -> x == x)
(trans : (x y z : A) -> x == y -> y == z -> x == z)
where
infix 2 chain>_
infixl 2 _===_
infix 3 _by_
chain>_ : (x : A) -> x == x
chain> x = refl _
_===_ : {x y z : A} -> x == y -> y == z -> x == z
xy === yz = trans _ _ _ xy yz
_by_ : {x : A}(y : A) -> x == y -> x == y
y by eq = eq
| 18.318182 | 55 | 0.369727 |
4a19b0cb190859c8676e0d731bd59ce28857d58d | 992 | agda | Agda | test/Succeed/Issue2607b.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue2607b.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue2607b.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --overlapping-instances #-}
postulate
Nat : Set
Fin : Nat → Set
Finnat : Nat → Set
fortytwo : Nat
finnatic : Finnat fortytwo
_==_ : Finnat fortytwo → Finnat fortytwo → Set
record Fixer : Set where
field fix : ∀ {x} → Finnat x → Finnat fortytwo
open Fixer {{...}}
postulate
Fixidentity : {{_ : Fixer}} → Set
instance
fixidentity : {{fx : Fixer}} {{fxi : Fixidentity}} {f : Finnat fortytwo} → fix f == f
InstanceWrapper : Set
iwrap : InstanceWrapper
instance
IrrFixerInstance : .{{_ : InstanceWrapper}} → Fixer
instance
FixerInstance : Fixer
FixerInstance = IrrFixerInstance {{iwrap}}
instance
postulate FixidentityInstance : Fixidentity
it : ∀ {a} {A : Set a} {{x : A}} → A
it {{x}} = x
fails : Fixer.fix FixerInstance finnatic == finnatic
fails = fixidentity
works : Fixer.fix FixerInstance finnatic == finnatic
works = fixidentity {{fx = it}}
works₂ : Fixer.fix FixerInstance finnatic == finnatic
works₂ = fixidentity {{fxi = it}}
| 23.069767 | 89 | 0.671371 |
c5ff4733926626f30baed18a671612fefd6eaf2f | 2,482 | agda | Agda | src/Categories/Object/Duality.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | src/Categories/Object/Duality.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | null | null | null | src/Categories/Object/Duality.agda | turion/agda-categories | ad0f94b6cf18d8a448b844b021aeda58e833d152 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | {-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Properties relating Initial and Terminal Objects,
-- and Product / Coproduct via op
module Categories.Object.Duality {o ℓ e} (C : Category o ℓ e) where
open Category C
open import Level
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open import Categories.Morphism C
open import Categories.Object.Terminal op
open import Categories.Object.Initial C
open import Categories.Object.Product op
open import Categories.Object.Coproduct C
IsInitial⇒coIsTerminal : ∀ {X} → IsInitial X → IsTerminal X
IsInitial⇒coIsTerminal is⊥ = record
{ ! = !
; !-unique = !-unique
}
where open IsInitial is⊥
⊥⇒op⊤ : Initial → Terminal
⊥⇒op⊤ i = record
{ ⊤ = ⊥
; ⊤-is-terminal = IsInitial⇒coIsTerminal ⊥-is-initial
}
where open Initial i
coIsTerminal⇒IsInitial : ∀ {X} → IsTerminal X → IsInitial X
coIsTerminal⇒IsInitial is⊤ = record
{ ! = !
; !-unique = !-unique
}
where open IsTerminal is⊤
op⊤⇒⊥ : Terminal → Initial
op⊤⇒⊥ t = record
{ ⊥ = ⊤
; ⊥-is-initial = coIsTerminal⇒IsInitial ⊤-is-terminal
}
where open Terminal t
Coproduct⇒coProduct : ∀ {A B} → Coproduct A B → Product A B
Coproduct⇒coProduct A+B = record
{ A×B = A+B.A+B
; π₁ = A+B.i₁
; π₂ = A+B.i₂
; ⟨_,_⟩ = A+B.[_,_]
; project₁ = A+B.inject₁
; project₂ = A+B.inject₂
; unique = A+B.unique
}
where
module A+B = Coproduct A+B
coProduct⇒Coproduct : ∀ {A B} → Product A B → Coproduct A B
coProduct⇒Coproduct A×B = record
{ A+B = A×B.A×B
; i₁ = A×B.π₁
; i₂ = A×B.π₂
; [_,_] = A×B.⟨_,_⟩
; inject₁ = A×B.project₁
; inject₂ = A×B.project₂
; unique = A×B.unique
}
where
module A×B = Product A×B
private
coIsTerminal⟺IsInitial : ∀ {X} (⊥ : IsInitial X) →
coIsTerminal⇒IsInitial (IsInitial⇒coIsTerminal ⊥) ≡ ⊥
coIsTerminal⟺IsInitial _ = ≡.refl
IsInitial⟺coIsTerminal : ∀ {X} (⊤ : IsTerminal X) →
IsInitial⇒coIsTerminal (coIsTerminal⇒IsInitial ⊤) ≡ ⊤
IsInitial⟺coIsTerminal _ = ≡.refl
⊥⟺op⊤ : (⊤ : Terminal) → ⊥⇒op⊤ (op⊤⇒⊥ ⊤) ≡ ⊤
⊥⟺op⊤ _ = ≡.refl
op⊤⟺⊥ : (⊥ : Initial) → op⊤⇒⊥ (⊥⇒op⊤ ⊥) ≡ ⊥
op⊤⟺⊥ _ = ≡.refl
Coproduct⟺coProduct : ∀ {A B} (p : Product A B) → Coproduct⇒coProduct (coProduct⇒Coproduct p) ≡ p
Coproduct⟺coProduct _ = ≡.refl
coProduct⟺Coproduct : ∀ {A B} (p : Coproduct A B) → coProduct⇒Coproduct (Coproduct⇒coProduct p) ≡ p
coProduct⟺Coproduct _ = ≡.refl
| 26.126316 | 101 | 0.622885 |
2356b644c5eb0850b67836a08224f03bf39b0819 | 5,125 | agda | Agda | Natural.agda | kands-code/agda-exercise | b3c9c4f678feac75af6f30d0dd941ab58b9f40dd | [
"MIT"
] | null | null | null | Natural.agda | kands-code/agda-exercise | b3c9c4f678feac75af6f30d0dd941ab58b9f40dd | [
"MIT"
] | null | null | null | Natural.agda | kands-code/agda-exercise | b3c9c4f678feac75af6f30d0dd941ab58b9f40dd | [
"MIT"
] | null | null | null | module Natural where
open import Agda.Builtin.Equality
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
-- seven = suc (suc (suc (suc (suc (suc (suc zero))))))
{-# BUILTIN NATURAL ℕ #-}
_+_ : ℕ → ℕ → ℕ
infixl 6 _+_
zero + b = b
(suc a) + b = suc (a + b)
{-# BUILTIN NATPLUS _+_ #-}
+-id : ∀ (a : ℕ) → a + zero ≡ zero + a
+-id zero = refl
+-id (suc a) rewrite +-id a = refl
+-comm : ∀ (a b : ℕ) → a + b ≡ b + a
+-comm zero b rewrite +-id b = refl
+-comm (suc a) zero rewrite +-id (suc a) = refl
+-comm (suc a) (suc b)
rewrite +-comm a (suc b)
| +-comm b (suc a)
| +-comm a b = refl
+-asso : ∀ (a b c : ℕ) → a + b + c ≡ a + (b + c)
+-asso zero b c = refl
+-asso (suc a) zero c
rewrite +-id (suc a)
| +-id a = refl
+-asso (suc a) (suc b) zero
rewrite +-id (suc a + suc b)
| +-id b = refl
+-asso (suc a) (suc b) (suc c)
rewrite (+-comm a (suc b))
| +-comm (b + a) (suc c)
| +-comm b a
| +-comm c (a + b)
| +-comm b (suc c)
| +-comm a (suc (suc (c + b)))
| +-comm c b
| +-comm (b + c) a
| +-asso a b c = refl
+-rear : ∀ (a b c d : ℕ) → a + b + (c + d) ≡ a + (b + c) + d
+-rear zero b c d rewrite +-asso b c d = refl
+-rear (suc a) b c d
rewrite (+-asso (suc a) b (c + d))
| +-asso a (b + c) d
| +-asso b c d = refl
+-swap : ∀ (a b c : ℕ) → a + (b + c) ≡ b + (a + c)
+-swap a b c
rewrite (+-comm a (b + c))
| +-comm b (a + c)
| +-asso a c b
| +-comm c b
| +-comm a (b + c) = refl
_*_ : ℕ → ℕ → ℕ
infixl 7 _*_
zero * b = zero
suc a * b = b + a * b
{-# BUILTIN NATTIMES _*_ #-}
*-id : ∀ (a : ℕ) → a * (suc zero) ≡ (suc zero) * a
*-id zero = refl
*-id (suc a)
rewrite +-comm (suc zero) a
| *-id a = refl
*-z : ∀ (a : ℕ) → a * zero ≡ zero * a
*-z zero = refl
*-z (suc a) rewrite *-z a = refl
*-comm : ∀ (a b : ℕ) → a * b ≡ b * a
*-comm zero b rewrite *-z b = refl
*-comm (suc a) zero rewrite *-z a = refl
*-comm (suc a) (suc b)
rewrite (*-comm a (suc b))
| (*-comm b (suc a))
| (*-comm a b )
| (+-comm b (a + b * a))
| (+-comm a (b + b * a))
| (+-comm a (b * a))
| (+-comm b (b * a))
| (+-asso (b * a) a b)
| (+-asso (b * a) b a)
| (+-comm a b) = refl
*-+-dist-r : ∀ (a b c : ℕ) → (a + b) * c ≡ a * c + b * c
*-+-dist-r zero b c = refl
*-+-dist-r (suc a) zero c
rewrite (+-comm (suc a) zero)
| +-comm a zero
| +-asso c (a * c) zero
| +-comm (a * c) zero = refl
*-+-dist-r (suc a) (suc b) c
rewrite (+-comm a (suc b))
| +-rear c (a * c) c (b * c)
| +-comm (a * c) c
| +-asso c (c + a * c) (b * c)
| +-asso c (a * c) (b * c)
| +-comm (a * c) (b * c)
| *-+-dist-r b a c = refl
*-+-dist-l : ∀ (a b c : ℕ) → a * (b + c) ≡ a * b + a * c
*-+-dist-l a zero c rewrite (*-z a) = refl
*-+-dist-l a (suc b) zero
rewrite (+-comm (suc b) zero)
| *-z a
| +-comm (a * suc b) zero = refl
*-+-dist-l a (suc b) (suc c)
rewrite (+-comm b (suc c))
| *-comm a (suc (suc (c + b)))
| *-comm a (suc b)
| *-comm a (suc c)
| +-rear a (b * a) a (c * a)
| +-comm (b * a) a
| +-asso a (a + b * a) (c * a)
| +-asso a (b * a) (c * a)
| +-comm (b * a) (c * a)
| *-comm (c + b) a
| *-comm c a
| *-comm b a
| *-+-dist-l a c b = refl
*-asso : ∀ (a b c : ℕ) → a * b * c ≡ a * (b * c)
*-asso zero b c = refl
*-asso (suc a) zero c rewrite (*-asso a zero c) = refl
*-asso (suc a) (suc b) c
rewrite (*-+-dist-r (suc b) (a * suc b) c)
| *-asso a (suc b) c = refl
_^_ : ℕ → ℕ → ℕ
m ^ zero = suc zero
m ^ (suc n) = m * (m ^ n)
^-dist-+-*-l : ∀ (a b c : ℕ) → a ^ (b + c) ≡ (a ^ b) * (a ^ c)
^-dist-+-*-l a zero c
rewrite (+-comm zero (a ^ c))
| +-asso (a ^ c) zero zero = refl
^-dist-+-*-l a (suc b) c
rewrite *-asso a (a ^ b) (a ^ c)
| ^-dist-+-*-l a b c = refl
^-dist-*-r : ∀ (a b c : ℕ) → (a * b) ^ c ≡ (a ^ c) * (b ^ c)
^-dist-*-r a b zero rewrite (+-comm (suc zero) zero) = refl
^-dist-*-r a b (suc c)
rewrite (*-asso a (a ^ c) (b * (b ^ c)))
| *-comm (a ^ c) (b * (b ^ c))
| *-asso b (b ^ c) (a ^ c)
| *-comm (b ^ c) (a ^ c)
| *-asso a b ((a * b) ^ c)
| ^-dist-*-r a b c = refl
^-asso-* : ∀ (a b c : ℕ) → (a ^ b) ^ c ≡ a ^ (b * c)
^-asso-* a b zero rewrite (*-comm b zero) = refl
^-asso-* a b (suc c)
rewrite (*-comm b (suc c))
| ^-dist-+-*-l a b (c * b)
| *-comm c b
| ^-asso-* a b c = refl
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (n O) = n I
inc (n I) = (inc n) O
to : ℕ → Bin
to zero = ⟨⟩ O
to (suc n) = inc (to n)
from : Bin → ℕ
from ⟨⟩ = zero
from (n O) = 2 * (from n)
from (n I) = suc (2 * (from n))
thm₁ : ∀ (b : Bin) → from (inc b) ≡ suc (from b)
thm₁ ⟨⟩ = refl
thm₁ (a O) = refl
thm₁ (a I)
rewrite thm₁ a
| +-comm (suc (from a)) zero
| +-comm (from a) zero
| +-comm (from a) (suc (from a)) = refl
-- thm₂ : ∀ (b : Bin) → to (from b) = b
-- 这是错误的,因为 Bin 中的 (⟨⟩ O) 和 (⟨⟩)
-- 都和 自然数 的 0 对应
-- from 并非单射
thm₃ : ∀ (n : ℕ) → from (to n) ≡ n
thm₃ zero = refl
thm₃ (suc n)
rewrite thm₁ (to (suc n))
| thm₁ (to n)
| thm₃ n = refl | 24.404762 | 63 | 0.431805 |
df51a812afc788d77152c7daac1f461fedca6dce | 782 | agda | Agda | test/Succeed/Issue937.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue937.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue937.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --copatterns #-}
-- {-# OPTIONS -v interaction.give:20 -v tc.cc:60 -v reify.clause:60 -v tc.section.check:10 -v tc:90 #-}
-- {-# OPTIONS -v tc.lhs:20 #-}
module Issue937 where
open import Common.Equality
data Nat : Set where
zero : Nat
suc : Nat → Nat
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
data _≤_ : Nat → Nat → Set where
z≤n : ∀ {n} → zero ≤ n
s≤s : ∀ {m n} (m≤n : m ≤ n) → suc m ≤ suc n
_<_ : Nat → Nat → Set
m < n = suc m ≤ n
ex : Σ Nat (λ n → zero < n)
proj₁ ex = suc zero
proj₂ ex = s≤s z≤n
module _ (A : Set) where
ex'' : Σ Nat (λ n → zero < n)
proj₁ ex'' = suc zero
proj₂ ex'' = s≤s z≤n
test : ex'' Nat ≡ (suc zero , s≤s z≤n)
test = refl
| 20.051282 | 104 | 0.544757 |
cb71a2231d2d2b7b6e5dc8c74cb35dede9865ee2 | 12,861 | agda | Agda | Cubical/HITs/Ints/BiInvInt/Base.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/HITs/Ints/BiInvInt/Base.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/HITs/Ints/BiInvInt/Base.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | 1 | 2021-11-22T02:02:01.000Z | 2021-11-22T02:02:01.000Z | {-
Definition of the integers as a HIT ported from the redtt library:
https://github.com/RedPRL/redtt/blob/master/library/cool/biinv-int.red
For the naive, but incorrect, way to define the integers as a HIT, see HITs.IsoInt
This file contains:
- definition of BiInvInt
- proof that Int ≡ BiInvInt
- [discreteBiInvInt] and [isSetBiInvInt]
- versions of the point constructors of BiInvInt which satisfy the path constructors judgmentally
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.BiInvInt.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Data.Nat
open import Cubical.Data.Int
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Equiv.BiInvertible
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Relation.Nullary
data BiInvInt : Type₀ where
zero : BiInvInt
suc : BiInvInt -> BiInvInt
-- suc is a bi-invertible equivalence:
predr : BiInvInt -> BiInvInt
suc-predr : ∀ z -> suc (predr z) ≡ z
predl : BiInvInt -> BiInvInt
predl-suc : ∀ z -> predl (suc z) ≡ z
suc-biinvequiv : BiInvEquiv BiInvInt BiInvInt
suc-biinvequiv = record { fun = suc ; invr = predr ; invr-rightInv = suc-predr
; invl = predl ; invl-leftInv = predl-suc }
predr-suc : ∀ z -> predr (suc z) ≡ z
predr-suc = BiInvEquiv.invr-leftInv suc-biinvequiv
-- since we want to use suc-adj and pred-adj (defined below) later on, we will need the
-- definition of suc-predl taken from HAEquiv instead of from BiInvEquiv
suc-haequiv : HAEquiv BiInvInt BiInvInt
suc-haequiv = biInvEquiv→HAEquiv suc-biinvequiv
suc-predl : ∀ z -> suc (predl z) ≡ z
suc-predl = isHAEquiv.ret (snd suc-haequiv)
-- predr and predl (as well as suc-predr and suc-predl - up to a path) are indistinguishable,
-- so we can safely define 'pred' to just be predl
predl≡predr : ∀ z -> predl z ≡ predr z
predl≡predr z i = cong fst (isContr→isProp (isContr-hasSection (biInvEquiv→Equiv-left suc-biinvequiv))
(predl , suc-predl) (predr , suc-predr)) i z
suc-predl≡predr : ∀ z -> PathP (λ j → suc (predl≡predr z j) ≡ z) (suc-predl z) (suc-predr z)
suc-predl≡predr z i = cong snd (isContr→isProp (isContr-hasSection (biInvEquiv→Equiv-left suc-biinvequiv))
(predl , suc-predl) (predr , suc-predr)) i z
pred : BiInvInt -> BiInvInt
pred = predl
suc-pred = suc-predl
pred-suc = predl-suc
-- these paths from HAEquiv will be useful later
suc-adj : ∀ z → (λ i → suc (pred-suc z i)) ≡ suc-pred (suc z)
pred-adj : ∀ z → (λ i → pred (suc-pred z i)) ≡ pred-suc (pred z)
suc-adj z = isHAEquiv.com (snd suc-haequiv) z
pred-adj z = isHAEquiv.com-op (snd suc-haequiv) z
-- Int ≡ BiInvInt
fwd : Int -> BiInvInt
fwd (pos zero) = zero
fwd (pos (suc n)) = suc (fwd (pos n))
fwd (negsuc zero) = pred zero
fwd (negsuc (suc n)) = pred (fwd (negsuc n))
bwd : BiInvInt -> Int
bwd zero = pos zero
bwd (suc z) = sucInt (bwd z)
bwd (predr z) = predInt (bwd z)
bwd (suc-predr z i) = sucPred (bwd z) i
bwd (predl z) = predInt (bwd z)
bwd (predl-suc z i) = predSuc (bwd z) i
bwd-fwd : ∀ (x : Int) -> bwd (fwd x) ≡ x
bwd-fwd (pos zero) = refl
bwd-fwd (pos (suc n)) = cong sucInt (bwd-fwd (pos n))
bwd-fwd (negsuc zero) = refl
bwd-fwd (negsuc (suc n)) = cong predInt (bwd-fwd (negsuc n))
fwd-sucInt : ∀ (x : Int) → fwd (sucInt x) ≡ suc (fwd x)
fwd-sucInt (pos n) = refl
fwd-sucInt (negsuc zero) = sym (suc-pred (fwd (pos zero)))
fwd-sucInt (negsuc (suc n)) = sym (suc-pred (fwd (negsuc n)))
fwd-predInt : ∀ (x : Int) → fwd (predInt x) ≡ pred (fwd x)
fwd-predInt (pos zero) = refl
fwd-predInt (pos (suc n)) = sym (predl-suc (fwd (pos n)))
fwd-predInt (negsuc n) = refl
private
sym-filler : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y)
→ Square {- (i = i0) -} (sym p)
{- (i = i1) -} refl
{- (j = i0) -} refl
{- (j = i1) -} p
sym-filler {y = y} p i j = hcomp (λ k → λ { (j = i0) → y
; (i = i0) → p ((~ j) ∨ (~ k))
; (i = i1) → y
; (j = i1) → p (i ∨ (~ k)) }) y
fwd-sucPred : ∀ (x : Int)
→ Square {- (i = i0) -} (fwd-sucInt (predInt x) ∙ (λ i → suc (fwd-predInt x i)))
{- (i = i1) -} (λ _ → fwd x)
{- (j = i0) -} (λ i → fwd (sucPred x i))
{- (j = i1) -} (suc-pred (fwd x))
fwd-sucPred (pos zero) i j
= hcomp (λ k → λ { (j = i0) → fwd (pos zero)
; (i = i0) → rUnit (sym (suc-pred (fwd (pos zero)))) k j
-- because fwd-sucInt (predInt (pos zero)) ≡ sym (suc-pred (fwd (pos zero)))
; (i = i1) → fwd (pos zero)
; (j = i1) → suc-pred (fwd (pos zero)) i
})
(sym-filler (suc-pred (fwd (pos zero))) i j)
fwd-sucPred (pos (suc n)) i j
= hcomp (λ k → λ { (j = i0) → suc (fwd (pos n))
; (i = i0) → lUnit (λ i → suc (sym (predl-suc (fwd (pos n))) i)) k j
-- because fwd-predInt (pos (suc n)) ≡ sym (predl-suc (fwd (pos n)))
; (i = i1) → suc (fwd (pos n))
; (j = i1) → suc-adj (fwd (pos n)) k i
})
(suc (sym-filler (pred-suc (fwd (pos n))) i j))
fwd-sucPred (negsuc n) i j
= hcomp (λ k → λ { (j = i0) → fwd (negsuc n)
; (i = i0) → rUnit (sym (suc-pred (fwd (negsuc n)))) k j
-- because fwd-sucInt (predInt (negsuc n)) ≡ sym (suc-pred (fwd (negsuc n)))
; (i = i1) → fwd (negsuc n)
; (j = i1) → suc-pred (fwd (negsuc n)) i
})
(sym-filler (suc-pred (fwd (negsuc n))) i j)
fwd-predSuc : ∀ (x : Int)
→ Square {- (i = i0) -} (fwd-predInt (sucInt x) ∙ (λ i → pred (fwd-sucInt x i)))
{- (i = i1) -} (λ _ → fwd x)
{- (j = i0) -} (λ i → fwd (predSuc x i))
{- (j = i1) -} (pred-suc (fwd x))
fwd-predSuc (pos n) i j
= hcomp (λ k → λ { (j = i0) → fwd (pos n)
; (i = i0) → rUnit (sym (pred-suc (fwd (pos n)))) k j
-- because fwd-predInt (sucInt (pos n)) ≡ sym (pred-suc (fwd (pos n)))
; (i = i1) → fwd (pos n)
; (j = i1) → pred-suc (fwd (pos n)) i
})
(sym-filler (pred-suc (fwd (pos n))) i j)
fwd-predSuc (negsuc zero) i j
= hcomp (λ k → λ { (j = i0) → fwd (negsuc zero)
; (i = i0) → lUnit (λ i → pred (sym (suc-pred (fwd (pos zero))) i)) k j
-- because fwd-sucInt (negsuc zero) ≡ sym (suc-pred (fwd (pos zero)))
; (i = i1) → fwd (negsuc zero)
; (j = i1) → pred-adj (fwd (pos zero)) k i
})
(pred (sym-filler (suc-pred (fwd (pos zero))) i j))
fwd-predSuc (negsuc (suc n)) i j
= hcomp (λ k → λ { (j = i0) → fwd (negsuc (suc n))
; (i = i0) → lUnit (λ i → pred (sym (suc-pred (fwd (negsuc n))) i)) k j
-- because fwd-sucInt (negsuc (suc n)) ≡ sym (suc-pred (fwd (negsuc n)))
; (i = i1) → fwd (negsuc (suc n))
; (j = i1) → pred-adj (fwd (negsuc n)) k i
})
(pred (sym-filler (suc-pred (fwd (negsuc n))) i j))
fwd-bwd : ∀ (z : BiInvInt) -> fwd (bwd z) ≡ z
fwd-bwd zero = refl
fwd-bwd (suc z) = fwd-sucInt (bwd z) ∙ (λ i → suc (fwd-bwd z i))
fwd-bwd (predr z) = fwd-predInt (bwd z) ∙ (λ i → predl≡predr (fwd-bwd z i) i)
fwd-bwd (predl z) = fwd-predInt (bwd z) ∙ (λ i → pred (fwd-bwd z i))
fwd-bwd (suc-predr z i) j
= hcomp (λ k → λ { (j = i0) → fwd (sucPred (bwd z) i)
; (i = i0) → (fwd-sucInt (predInt (bwd z))
∙ (λ i → suc (compPath-filler (fwd-predInt (bwd z))
(λ i' → predl≡predr (fwd-bwd z i') i')
k i))) j
; (i = i1) → fwd-bwd z (j ∧ k)
; (j = i1) → suc-predl≡predr (fwd-bwd z k) k i })
(fwd-sucPred (bwd z) i j)
fwd-bwd (predl-suc z i) j
= hcomp (λ k → λ { (j = i0) → fwd (predSuc (bwd z) i)
; (i = i0) → (fwd-predInt (sucInt (bwd z))
∙ (λ i → pred (compPath-filler (fwd-sucInt (bwd z))
(λ i' → suc (fwd-bwd z i'))
k i))) j
; (i = i1) → fwd-bwd z (j ∧ k)
; (j = i1) → pred-suc (fwd-bwd z k) i })
(fwd-predSuc (bwd z) i j)
Int≡BiInvInt : Int ≡ BiInvInt
Int≡BiInvInt = isoToPath (iso fwd bwd fwd-bwd bwd-fwd)
discreteBiInvInt : Discrete BiInvInt
discreteBiInvInt = subst Discrete Int≡BiInvInt discreteInt
isSetBiInvInt : isSet BiInvInt
isSetBiInvInt = subst isSet Int≡BiInvInt isSetInt
-- suc' is equal to suc (suc≡suc') but cancels pred *exactly* (see suc'-pred)
suc'ᵖ : (z : BiInvInt) -> Σ BiInvInt (suc z ≡_)
suc' = fst ∘ suc'ᵖ
suc≡suc' = snd ∘ suc'ᵖ
suc'ᵖ zero = suc zero , refl
suc'ᵖ (suc z) = suc (suc z) , refl
suc'ᵖ (predr z) = z , suc-predr z
suc'ᵖ (suc-predr z i) = let filler : I → I → BiInvInt
filler j i = hfill (λ j → λ { (i = i0) → suc (suc (predr z))
; (i = i1) → suc≡suc' z j })
(inS (suc (suc-predr z i))) j
in filler i1 i , λ j → filler j i
suc'ᵖ (predl z) = z , suc-predl z
suc'ᵖ (predl-suc z i) = let filler : I → I → BiInvInt
filler j i = hfill (λ j → λ { (i = i0) → suc-predl (suc z) j
; (i = i1) → suc≡suc' z j })
(inS (suc (predl-suc z i))) j
in filler i1 i , λ j → filler j i
private
suc'-pred : ∀ z → suc' (pred z) ≡ z
suc'-pred z = refl
-- pred' is equal to pred (pred≡pred') but cancels suc *exactly* (see pred'-suc)
predr'ᵖ : (z : BiInvInt) -> Σ BiInvInt (predr z ≡_)
predr' = fst ∘ predr'ᵖ
predr≡predr' = snd ∘ predr'ᵖ
predr'ᵖ zero = predr zero , refl
predr'ᵖ (suc z) = z , predr-suc z
predr'ᵖ (predr z) = predr (predr z) , refl
predr'ᵖ (suc-predr z i) = let filler : I → I → BiInvInt
filler j i = hfill (λ j → λ { (i = i0) → predr-suc (predr z) j
; (i = i1) → predr≡predr' z j })
(inS (predr (suc-predr z i))) j
in filler i1 i , λ j → filler j i
predr'ᵖ (predl z) = predr (predl z) , refl
predr'ᵖ (predl-suc z i) = let filler : I → I → BiInvInt
filler j i = hfill (λ j → λ { (i = i0) → predr (predl (suc z))
; (i = i1) → predr≡predr' z j })
(inS (predr (predl-suc z i))) j
in filler i1 i , λ j → filler j i
predl'ᵖ : (z : BiInvInt) -> Σ BiInvInt (predl z ≡_)
predl' = fst ∘ predl'ᵖ
predl≡predl' = snd ∘ predl'ᵖ
predl'ᵖ zero = predl zero , refl
predl'ᵖ (suc z) = z , predl-suc z
predl'ᵖ (predr z) = predl (predr z) , refl
predl'ᵖ (suc-predr z i) = let filler : I → I → BiInvInt
filler j i = hfill (λ j → λ { (i = i0) → predl-suc (predr z) j
; (i = i1) → predl≡predl' z j })
(inS (predl (suc-predr z i))) j
in filler i1 i , λ j → filler j i
predl'ᵖ (predl z) = predl (predl z) , refl
predl'ᵖ (predl-suc z i) = let filler : I → I → BiInvInt
filler j i = hfill (λ j → λ { (i = i0) → predl (predl (suc z))
; (i = i1) → predl≡predl' z j })
(inS (predl (predl-suc z i))) j
in filler i1 i , λ j → filler j i
private
predr'-suc : ∀ z → predr' (suc z) ≡ z
predr'-suc z = refl
predl'-suc : ∀ z → predl' (suc z) ≡ z
predl'-suc z = refl
| 41.353698 | 108 | 0.479356 |
1812d3eff3ee73c3d37ba8dc96e38937fe856be2 | 4,860 | agda | Agda | PiFrac/Category.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | PiFrac/Category.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | PiFrac/Category.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | module PiFrac.Category where
open import Categories.Category.Monoidal
open import Categories.Category.Monoidal.Braided
open import Categories.Category.Monoidal.Symmetric
open import Categories.Category.Monoidal.Rigid
open import Categories.Category.Monoidal.CompactClosed
open import Categories.Functor.Bifunctor
open import Categories.Category
open import Categories.Category.Product
open import Categories.Category.Groupoid
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Data.Maybe
open import Relation.Binary.Core
open import Relation.Binary hiding (Symmetric)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Function using (_∘_)
open import PiFrac.Syntax
open import PiFrac.Opsem
open import PiFrac.Interp
open import PiFrac.Properties
Pi∙ : Category _ _ _
Pi∙ = record
{ Obj = Σ[ t ∈ 𝕌 ] ⟦ t ⟧
; _⇒_ = λ (A , a) (B , b) → Σ[ c ∈ (A ↔ B) ] (interp c a ≡ just b)
; _≈_ = λ {(A , a)} {(B , b)} (c , eq) (c' , eq) → ⊤
; id = id↔ , refl
; _∘_ = λ (c₂ , eq₂) (c₁ , eq₁) → comp (c₁ , eq₁) (c₂ , eq₂)
; assoc = tt
; sym-assoc = tt
; identityˡ = tt
; identityʳ = tt
; identity² = tt
; equiv = record { refl = tt ; sym = λ _ → tt ; trans = λ _ _ → tt }
; ∘-resp-≈ = λ _ _ → tt
}
where
comp : ∀ {A B C a b c} → Σ[ c₁ ∈ (A ↔ B) ] (interp c₁ a ≡ just b) → Σ[ c₂ ∈ (B ↔ C) ] (interp c₂ b ≡ just c)
→ Σ[ c' ∈ (A ↔ C) ] (interp c' a ≡ just c)
comp {c = c} (c₁ , eq₁) (c₂ , eq₂) = (c₁ ⨾ c₂) , subst (λ x → (x >>= interp c₂) ≡ just c) (sym eq₁) eq₂
Pi∙Groupoid : Groupoid _ _ _
Pi∙Groupoid = record { category = Pi∙
; isGroupoid = record { _⁻¹ = λ (c , eq) → ! c , interp! c _ _ eq
; iso = record { isoˡ = tt
; isoʳ = tt } } }
Pi∙Monoidal : Monoidal Pi∙
Pi∙Monoidal = record
{ ⊗ = record
{ F₀ = λ ((A , a) , (B , b)) → (A ×ᵤ B) , (a , b)
; F₁ = λ {((A , a) , (B , b))} {((C , c) , (D , d))} ((c₁ , eq₁) , (c₂ , eq₂)) →
(c₁ ⊗ c₂) , subst (λ x → (x >>= (λ v₁' → interp c₂ b >>= λ v₂' → just (v₁' , v₂'))) ≡ just (c , d))
(sym eq₁) (subst (λ x → (x >>= λ v₂' → just (c , v₂')) ≡ just (c , d)) (sym eq₂) refl)
; identity = tt
; homomorphism = tt
; F-resp-≈ = λ _ → tt
}
; unit = (𝟙 , tt)
; unitorˡ = record { from = unite⋆l , refl
; to = uniti⋆l , refl
; iso = record { isoˡ = tt ; isoʳ = tt } }
; unitorʳ = record { from = unite⋆r , refl
; to = uniti⋆r , refl
; iso = record { isoˡ = tt ; isoʳ = tt } }
; associator = record { from = assocr⋆ , refl
; to = assocl⋆ , refl
; iso = record { isoˡ = tt ; isoʳ = tt } }
; unitorˡ-commute-from = tt
; unitorˡ-commute-to = tt
; unitorʳ-commute-from = tt
; unitorʳ-commute-to = tt
; assoc-commute-from = tt
; assoc-commute-to = tt
; triangle = tt
; pentagon = tt
}
Pi∙Braided : Braided Pi∙Monoidal
Pi∙Braided = record { braiding = record { F⇒G = record { η = λ _ → swap⋆ , refl
; commute = λ _ → tt
; sym-commute = λ _ → tt }
; F⇐G = record { η = λ _ → swap⋆ , refl
; commute = λ _ → tt
; sym-commute = λ _ → tt }
; iso = λ X → record { isoˡ = tt ; isoʳ = tt } }
; hexagon₁ = tt
; hexagon₂ = tt }
Pi∙Symmetric : Symmetric Pi∙Monoidal
Pi∙Symmetric = record { braided = Pi∙Braided
; commutative = tt}
Pi∙Rigid : LeftRigid Pi∙Monoidal
Pi∙Rigid = record { _⁻¹ = λ {(A , a) → 𝟙/ a , ↻}
; η = λ {(X , x)} → ηₓ x , refl
; ε = λ {(X , x)} → (swap⋆ ⨾ εₓ x) , εₓ≡
; snake₁ = tt
; snake₂ = tt}
where
εₓ≡ : ∀ {X} {x : ⟦ X ⟧} → interp (swap⋆ ⨾ εₓ x) (↻ , x) ≡ just tt
εₓ≡ {X} {x} with x ≟ x
... | yes refl = refl
... | no neq = ⊥-elim (neq refl)
Pi∙CompactClosed : CompactClosed Pi∙Monoidal
Pi∙CompactClosed = record { symmetric = Pi∙Symmetric
; rigid = inj₁ Pi∙Rigid }
| 43.00885 | 129 | 0.445062 |
201ac71e304a024836603e6cf5326769f6145419 | 1,120 | agda | Agda | test/asset/agda-stdlib-1.0/Data/Bool/Base.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | test/asset/agda-stdlib-1.0/Data/Bool/Base.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | test/asset/agda-stdlib-1.0/Data/Bool/Base.agda | omega12345/agda-mode | 0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71 | [
"MIT"
] | null | null | null | ------------------------------------------------------------------------
-- The Agda standard library
--
-- The type for booleans and some operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Bool.Base where
open import Data.Unit.Base using (⊤)
open import Data.Empty
open import Relation.Nullary
infixr 6 _∧_
infixr 5 _∨_ _xor_
infix 0 if_then_else_
------------------------------------------------------------------------
-- The boolean type
open import Agda.Builtin.Bool public
------------------------------------------------------------------------
-- Some operations
not : Bool → Bool
not true = false
not false = true
-- A function mapping true to an inhabited type and false to an empty
-- type.
T : Bool → Set
T true = ⊤
T false = ⊥
if_then_else_ : ∀ {a} {A : Set a} → Bool → A → A → A
if true then t else f = t
if false then t else f = f
_∧_ : Bool → Bool → Bool
true ∧ b = b
false ∧ b = false
_∨_ : Bool → Bool → Bool
true ∨ b = true
false ∨ b = b
_xor_ : Bool → Bool → Bool
true xor b = not b
false xor b = b
| 21.132075 | 72 | 0.485714 |
4a5a0c51cf7e76b0dfcaa2ddfe9ac8e8f9ecee2b | 349 | agda | Agda | test/fail/Issue256.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2019-11-27T04:41:05.000Z | 2019-11-27T04:41:05.000Z | test/fail/Issue256.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/fail/Issue256.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | {-# OPTIONS --universe-polymorphism #-}
module Issue256 where
open import Imports.Level
const : ∀ {a b} {A : Set a} {B : Set b} → A → B → A
const x = λ _ → x
level : ∀ {ℓ} → Set ℓ → Level
level {ℓ} _ = ℓ
-- termination check should fail for the following definition
ℓ : Level
ℓ = const zero (Set ℓ)
-- A : Set (suc {!ℓ!})
-- A = Set (level A)
| 18.368421 | 61 | 0.598854 |
4a8264dcd0852a13c8c5775a80b9d1b898c57589 | 647 | agda | Agda | Eq.agda | brunoczim/ual | ea0260e1a0612ba581e4283dfb187f531a944dfd | [
"MIT"
] | null | null | null | Eq.agda | brunoczim/ual | ea0260e1a0612ba581e4283dfb187f531a944dfd | [
"MIT"
] | null | null | null | Eq.agda | brunoczim/ual | ea0260e1a0612ba581e4283dfb187f531a944dfd | [
"MIT"
] | null | null | null | module Ual.Eq where
open import Agda.Primitive
open import Ual.Void
record Eq {a} (A : Set a) : Set (lsuc a) where
infix 30 _==_
infix 30 _≠_
field
_==_ : A → A → Set
self : {x : A} → x == x
sym : {x y : A} → x == y → y == x
trans : {x y z : A} → x == y → y == z → x == z
_≠_ : A → A → Set
x ≠ y = ¬ (x == y)
open Eq ⦃ ... ⦄ public
data Equality {a} {A : Set a} ⦃ eqA : Eq A ⦄ : A → A → Set where
equal : {x y : A} → x == y → Equality x y
notEqual : {x y : A} → x ≠ y → Equality x y
record Test {a} (A : Set a) : Set (lsuc a) where
field
⦃ eqA ⦄ : Eq A
test : (x : A) → (y : A) → Equality x y
| 23.962963 | 64 | 0.469861 |
4a3c3d8917e5ebeaf1a876d64a81c495a0520bee | 1,193 | agda | Agda | public/cloc-1.82/tests/inputs/Lookup.agda | josema62/Memoria | 93ebd98095434bc76d85d3fe8f32c913ed451e43 | [
"MIT"
] | 1 | 2021-12-28T12:50:26.000Z | 2021-12-28T12:50:26.000Z | public/cloc-1.82/tests/inputs/Lookup.agda | josema62/Memoria | 93ebd98095434bc76d85d3fe8f32c913ed451e43 | [
"MIT"
] | null | null | null | public/cloc-1.82/tests/inputs/Lookup.agda | josema62/Memoria | 93ebd98095434bc76d85d3fe8f32c913ed451e43 | [
"MIT"
] | null | null | null | {-
https://raw.githubusercontent.com/agda/agda/master/examples/Lookup.agda
-}
module Lookup where
data Bool : Set where
false : Bool
true : Bool
data IsTrue : Bool -> Set where
isTrue : IsTrue true
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
module Map {- comment -}
(Key : Set)
(_==_ : Key -> Key -> Bool)
(Code : Set)
(Val : Code -> Set) where
infixr 40 _⟼_,_
infix 20 _∈_
data Map : List Code -> Set where
ε : Map []
_⟼_,_ : forall {c cs} ->
Key -> Val c -> Map cs -> Map (c :: cs)
_∈_ : forall {cs} -> Key -> Map cs -> Bool
k ∈ ε = false
k ∈ (k' ⟼ _ , m) with k == k'
... | true = true
... | false = k ∈ m
Lookup : forall {cs} -> (k : Key)(m : Map cs) -> IsTrue (k ∈ m) -> Set
Lookup k ε ()
Lookup k (_⟼_,_ {c} k' _ m) p with k == k'
... | true = Val c
... | false = Lookup k m p
lookup : {cs : List Code}(k : Key)(m : Map cs)(p : IsTrue (k ∈ m)) ->
Lookup k m p
lookup k ε ()
lookup k (k' ⟼ v , m) p with k == k'
... | true = v
... | false = lookup k m p
| 22.942308 | 72 | 0.479464 |
cbf2c03f0d5ffb5042a9da359738463ad2595ba2 | 115,097 | agda | Agda | complexity/complexity-final/submit/Interp-WithLet.agda | benhuds/Agda | 2404a6ef2688f879bda89860bb22f77664ad813e | [
"MIT"
] | 2 | 2016-04-26T20:22:22.000Z | 2019-08-08T12:27:18.000Z | complexity/complexity-final/submit/Interp-WithLet.agda | benhuds/Agda | 2404a6ef2688f879bda89860bb22f77664ad813e | [
"MIT"
] | 1 | 2020-03-23T08:39:04.000Z | 2020-05-12T00:32:45.000Z | complexity/complexity-final/submit/Interp-WithLet.agda | benhuds/Agda | 2404a6ef2688f879bda89860bb22f77664ad813e | [
"MIT"
] | null | null | null | {- NEW INTERP WITHOUT RREC -}
open import Preliminaries
open import Preorder
open import Complexity
module Interp-WithLet where
-- interpret complexity types as preorders
[_]t : CTp → PREORDER
[ unit ]t = unit-p
[ nat ]t = Nat , ♭nat-p
[ τ ->c τ₁ ]t = [ τ ]t ->p [ τ₁ ]t
[ τ ×c τ₁ ]t = [ τ ]t ×p [ τ₁ ]t
[ list τ ]t = (List (fst [ τ ]t)) , list-p (snd [ τ ]t)
[ bool ]t = Bool , bool-p
[ C ]t = Nat , nat-p
[ rnat ]t = Nat , nat-p
[_]tm : ∀ {A} → CTpM A → Preorder-max-str (snd [ A ]t)
[ runit ]tm = unit-pM
[ rnat-max ]tm = nat-pM
[ e ×cm e₁ ]tm = axb-pM [ e ]tm [ e₁ ]tm
[ _->cm_ {τ1} e ]tm = mono-pM [ e ]tm
-- interpret contexts as preorders
[_]c : Ctx → PREORDER
[ [] ]c = unit-p
[ τ :: Γ ]c = [ Γ ]c ×p [ τ ]t
lookup : ∀{Γ τ} → τ ∈ Γ → el ([ Γ ]c ->p [ τ ]t)
lookup (i0 {Γ} {τ}) = snd' id
lookup (iS {Γ} {τ} {τ1} x) = comp (fst' id) (lookup x)
interpE : ∀{Γ τ} → Γ |- τ → el ([ Γ ]c ->p [ τ ]t)
sound : ∀ {Γ τ} (e e' : Γ |- τ) → e ≤s e' → PREORDER≤ ([ Γ ]c ->p [ τ ]t) (interpE e) (interpE e')
interpE unit = monotone (λ x → <>) (λ x y x₁ → <>)
interpE 0C = monotone (λ x → Z) (λ x y x₁ → <>)
interpE 1C = monotone (λ x → S Z) (λ x y x₁ → <>)
interpE (plusC e e₁) =
monotone (λ x → Monotone.f (interpE e) x + Monotone.f (interpE e₁) x)
(λ x y x₁ → plus-lem (Monotone.f (interpE e) x) (Monotone.f (interpE e₁) x) (Monotone.f (interpE e) y) (Monotone.f (interpE e₁) y)
(Monotone.is-monotone (interpE e) x y x₁) (Monotone.is-monotone (interpE e₁) x y x₁))
interpE (var x) = lookup x
interpE z = monotone (λ x → Z) (λ x y x₁ → <>)
interpE (s e) = monotone (λ x → S (Monotone.f (interpE e) x)) (λ x y x₁ → Monotone.is-monotone (interpE e) x y x₁)
interpE {Γ} {τ} (rec e e₁ e₂) = comp (pair' id (interpE e)) (♭rec' (interpE e₁) (interpE e₂))
interpE (lam e) = lam' (interpE e)
interpE (app e e₁) = app' (interpE e) (interpE e₁)
interpE (prod e e₁) = pair' (interpE e) (interpE e₁)
interpE (l-proj e) = fst' (interpE e)
interpE (r-proj e) = snd' (interpE e)
interpE nil = nil'
interpE (e ::c e₁) = cons' (interpE e) (interpE e₁)
interpE (listrec e e₁ e₂) = comp (pair' id (interpE e)) (lrec' (interpE e₁) (interpE e₂))
interpE true = monotone (λ x → True) (λ x y x₁ → <>)
interpE false = monotone (λ x → False) (λ x y x₁ → <>)
interpE (letc e e') = app' (lam' (interpE e)) (interpE e')
interpE {Γ} {τ'} (max τ e1 e2) =
monotone (λ x → Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) x) (Monotone.f (interpE e2) x))
(λ x y x₁ → Preorder-max-str.max-lub [ τ ]tm (Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y))
(Monotone.f (interpE e1) x) (Monotone.f (interpE e2) x)
(Preorder-str.trans (snd [ τ' ]t) (Monotone.f (interpE e1) x) (Monotone.f (interpE e1) y)
(Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y))
(Monotone.is-monotone (interpE e1) x y x₁) (Preorder-max-str.max-l [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y)))
(Preorder-str.trans (snd [ τ' ]t) (Monotone.f (interpE e2) x) (Monotone.f (interpE e2) y)
(Preorder-max-str.max [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y))
(Monotone.is-monotone (interpE e2) x y x₁) (Preorder-max-str.max-r [ τ ]tm (Monotone.f (interpE e1) y) (Monotone.f (interpE e2) y))))
throw-r : ∀ {Γ Γ' τ} → rctx Γ (τ :: Γ') → rctx Γ Γ'
throw-r d = λ x → d (iS x)
interpR : ∀ {Γ Γ'} → rctx Γ Γ' → MONOTONE [ Γ ]c [ Γ' ]c
interpR {Γ' = []} ρ = monotone (λ _ → <>) (λ x y x₁ → <>)
interpR {Γ' = τ :: Γ'} ρ = monotone (λ x → (Monotone.f (interpR (throw-r ρ)) x) , (Monotone.f (lookup (ρ i0)) x))
(λ x y x₁ → (Monotone.is-monotone (interpR (throw-r ρ)) x y x₁) , (Monotone.is-monotone (lookup (ρ i0)) x y x₁))
throw-s : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ'
throw-s d = λ x → d (iS x)
interpS : ∀ {Γ Γ'} → sctx Γ Γ' → el ([ Γ ]c ->p [ Γ' ]c)
interpS {Γ' = []} Θ = monotone (λ _ → <>) (λ x y x₁ → <>)
interpS {Γ' = τ :: Γ'} Θ = monotone (λ x → Monotone.f (interpS (throw-s Θ)) x , Monotone.f (interpE (Θ i0)) x)
(λ x y x₁ → Monotone.is-monotone (interpS (throw-s Θ)) x y x₁ , (Monotone.is-monotone (interpE (Θ i0)) x y x₁))
ren-eq-l-lam : ∀ {Γ Γ' τ1} (ρ : rctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t)
→ Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpR (throw-r (r-extend {_} {_} {τ1} ρ))) (k , x)) (Monotone.f (interpR ρ) k)
ren-eq-l-lam {Γ' = []} ρ k x = <>
ren-eq-l-lam {Γ' = x :: Γ'} ρ k x₁ =
(ren-eq-l-lam (throw-r ρ) k x₁) ,
(Preorder-str.refl (snd [ x ]t) (Monotone.f (lookup (ρ i0)) k))
ren-eq-l : ∀ {Γ Γ' τ} → (ρ : rctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
ren-eq-l ρ unit k = <>
ren-eq-l ρ 0C k = <>
ren-eq-l ρ 1C k = <>
ren-eq-l ρ (plusC e e₁) k =
plus-lem (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k)
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(ren-eq-l ρ e k) (ren-eq-l ρ e₁ k)
ren-eq-l {τ = τ} ρ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (lookup (ρ i0)) k)
ren-eq-l {τ = τ} ρ (var (iS x)) k = ren-eq-l (throw-r ρ) (var x) k
ren-eq-l ρ z k = <>
ren-eq-l ρ (s e) k = ren-eq-l ρ e k
ren-eq-l {Γ} {Γ'} {τ = τ} ρ (rec e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(natrec (Monotone.f (interpE (ren e₁ ρ)) k)
(λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n))
(Monotone.f (interpE (ren e ρ)) k))
(natrec (Monotone.f (interpE (ren e₁ ρ)) k)
(λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(natrec (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(♭h-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend ρ))))
(k , (Monotone.f (interpE (ren e ρ)) k))
(k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(ren-eq-l ρ e k))
(♭h-cong
(interpE (ren e₁ ρ))
(monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₁)
(Monotone.f (interpR ρ) x)
(Monotone.f (interpR ρ) y)
(Monotone.is-monotone (interpR ρ) x y x₁)))
(interpE (ren e₂ (r-extend (r-extend ρ))))
(monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst v)) , snd (fst v)) , snd v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x)
((Monotone.f (interpR ρ) (fst (fst y)) , snd (fst y)) , snd y)
(((Monotone.is-monotone (interpR ρ) (fst (fst x)) (fst (fst y)) (fst (fst x₁))) ,
(snd (fst x₁))) ,
(snd x₁))))
(k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(λ x → ren-eq-l ρ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) x)
(Monotone.f (interpE e₂) (Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x))
(Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x))
(ren-eq-l (r-extend (r-extend ρ)) e₂ x)
(Monotone.is-monotone (interpE e₂)
(Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x)
((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x)
((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) x)
(Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst x) , snd (fst x)))
(Monotone.f (interpR ρ) (fst (fst x)))
(ren-eq-l-lam {τ :: Γ} {Γ'} (throw-r (r-extend ρ)) (fst x) (snd x))
(ren-eq-l-lam ρ (fst (fst x)) (snd (fst x))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) ,
(♭nat-refl (snd x))))))
ren-eq-l {Γ} {τ = τ1 ->c τ2} ρ (lam e) k x =
Preorder-str.trans (snd [ τ2 ]t)
(Monotone.f (Monotone.f (interpE (ren (lam e) ρ)) k) x)
(Monotone.f (interpE e) (Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x)))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k , x))
(ren-eq-l (r-extend ρ) e (k , x))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x))
(Monotone.f (interpR ρ) k , x)
(ren-eq-l-lam ρ k x ,
(Preorder-str.refl (snd [ τ1 ]t) x)))
ren-eq-l {Γ} {τ = τ} ρ (app e e₁) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k))
(Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))
(Monotone.f (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))
(Monotone.is-monotone (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (ren-eq-l ρ e₁ k))
(ren-eq-l ρ e k (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))
ren-eq-l ρ (prod e e₁) k = (ren-eq-l ρ e k) , (ren-eq-l ρ e₁ k)
ren-eq-l ρ (l-proj e) k = fst (ren-eq-l ρ e k)
ren-eq-l ρ (r-proj e) k = snd (ren-eq-l ρ e k)
ren-eq-l ρ nil k = <>
ren-eq-l ρ (e ::c e₁) k = (ren-eq-l ρ e k) , (ren-eq-l ρ e₁ k)
ren-eq-l {Γ} {Γ'} {τ = τ} ρ (listrec {.Γ'} {τ'} e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(lrec (Monotone.f (interpE (ren e ρ)) k)
(Monotone.f (interpE (ren e₁ ρ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e₁ ρ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) k , x₃) , x₂) , x₁)))
(listrec-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend (r-extend ρ)))))
(k , (Monotone.f (interpE (ren e ρ)) k))
(k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
((Preorder-str.refl (snd [ Γ ]c) k) , (ren-eq-l ρ e k)))
(lrec-cong
(interpE (ren e₁ ρ))
(monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k₁))
(λ x y x₁ →
Monotone.is-monotone (interpE e₁)
(Monotone.f (interpR ρ) x) (Monotone.f (interpR ρ) y)
(Monotone.is-monotone (interpR ρ) x y x₁)))
(interpE (ren e₂ (r-extend (r-extend (r-extend ρ)))))
(monotone (λ x → Monotone.f (interpE e₂) ((((Monotone.f (interpR ρ) (fst (fst (fst x)))) , (snd (fst (fst x)))) , (snd (fst x))) , (snd x)))
(λ x y x₁ → Monotone.is-monotone (interpE e₂)
(((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(((Monotone.f (interpR ρ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y)
((((Monotone.is-monotone (interpR ρ) (fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁)))) ,
(snd (fst (fst x₁)))) ,
(snd (fst x₁))) ,
(snd x₁))))
(k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(λ x → ren-eq-l ρ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) x)
(Monotone.f (interpE e₂) (Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x))
(Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(ren-eq-l (r-extend (r-extend (r-extend ρ))) e₂ x)
(Monotone.is-monotone (interpE e₂)
(Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x)
(((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x)
(Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x))))
(Monotone.f (interpR ρ) (fst (fst (fst x))))
(Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x)
(Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) (fst x))
(Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x))))
(ren-eq-l-lam (λ x₁ → iS (iS (ρ x₁))) (fst x) (snd x))
(ren-eq-l-lam (λ x₁ → iS (ρ x₁)) (fst (fst x)) (snd (fst x))))
(ren-eq-l-lam ρ (fst (fst (fst x))) (snd (fst (fst x)))) ,
Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x)))) ,
l-refl (snd [ τ' ]t) (snd (fst x))) ,
Preorder-str.refl (snd [ τ' ]t) (snd x)))))
ren-eq-l ρ true k = <>
ren-eq-l ρ false k = <>
ren-eq-l {Γ} {Γ'} {τ = τ} ρ (letc {.Γ'} {ρ'} e e') k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e (r-extend ρ)))
(k , Monotone.f (interpE (ren e' ρ)) k))
(Monotone.f (interpE e) (Monotone.f (interpR (r-extend {_} {_} {ρ'} ρ)) (k , Monotone.f (interpE (ren e' ρ)) k)))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k , Monotone.f (interpE e') (Monotone.f (interpR ρ) k)))
(ren-eq-l (r-extend ρ) e (k , Monotone.f (interpE (ren e' ρ)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpR (r-extend {_} {_} {ρ'} ρ))
(k , Monotone.f (interpE (ren e' ρ)) k))
(Monotone.f (interpR ρ) k ,
Monotone.f (interpE e') (Monotone.f (interpR ρ) k))
(ren-eq-l-lam ρ k (Monotone.f (interpE (ren e' ρ)) k) , ren-eq-l ρ e' k))
ren-eq-l {τ = τ} ρ (max x e e₁) k =
Preorder-max-str.max-lub [ x ]tm
(Monotone.f (interpE (max x e e₁)) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e ρ)) k)
(Monotone.f (interpE (ren e₁ ρ)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e ρ)) k)
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (max x e e₁)) (Monotone.f (interpR ρ) k))
(ren-eq-l ρ e k)
(Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e₁ ρ)) k)
(Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (max x e e₁)) (Monotone.f (interpR ρ) k))
(ren-eq-l ρ e₁ k)
(Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))))
ren-eq-r-lam : ∀ {Γ Γ' τ1} (ρ : rctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t)
→ Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpR ρ) k) (Monotone.f (interpR (throw-r (r-extend {_} {_} {τ1} ρ))) (k , x))
ren-eq-r-lam {Γ' = []} ρ k x = <>
ren-eq-r-lam {Γ' = x :: Γ'} ρ k x₁ =
(ren-eq-r-lam (throw-r ρ) k x₁) ,
(Preorder-str.refl (snd [ x ]t) (Monotone.f (lookup (ρ i0)) k))
ren-eq-r : ∀ {Γ Γ' τ} → (ρ : rctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e ρ)) k)
ren-eq-r ρ unit k = <>
ren-eq-r ρ 0C k = <>
ren-eq-r ρ 1C k = <>
ren-eq-r ρ (plusC e e₁) k =
plus-lem (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k)
(ren-eq-r ρ e k) (ren-eq-r ρ e₁ k)
ren-eq-r {τ = τ} ρ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (lookup (ρ i0)) k)
ren-eq-r {τ = τ} ρ (var (iS x)) k = ren-eq-r (throw-r ρ) (var x) k
ren-eq-r ρ z k = <>
ren-eq-r ρ (s e) k = ren-eq-r ρ e k
ren-eq-r {Γ} {Γ'} {τ} ρ (rec e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(natrec (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(natrec (Monotone.f (interpE (ren e₁ ρ)) k)
(λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(natrec (Monotone.f (interpE (ren e₁ ρ)) k)
(λ n x₂ → Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) ((k , x₂) , n))
(Monotone.f (interpE (ren e ρ)) k))
(♭h-cong
(monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₁) (Monotone.f (interpR ρ) x)
(Monotone.f (interpR ρ) y)
(Monotone.is-monotone (interpR ρ) x y x₁)))
(interpE (ren e₁ ρ))
(monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst v)) , snd (fst v)) , snd v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x)
((Monotone.f (interpR ρ) (fst (fst y)) , snd (fst y)) , snd y)
((Monotone.is-monotone (interpR ρ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) ,
snd (fst x₁)) ,
snd x₁)))
(interpE (ren e₂ (r-extend (r-extend ρ))))
(k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(λ x → ren-eq-r ρ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e₂) ((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x))
(Monotone.f (interpE e₂) (Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x))
(Monotone.f (interpE (ren e₂ (r-extend (r-extend ρ)))) x)
(Monotone.is-monotone (interpE e₂)
((Monotone.f (interpR ρ) (fst (fst x)) , snd (fst x)) , snd x)
(Monotone.f (interpR {nat :: τ :: Γ} {_ :: _ :: Γ'} (r-extend (r-extend ρ))) x)
(((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpR ρ) (fst (fst x)))
(Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst x) , snd (fst x)))
(Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) x)
(ren-eq-r-lam ρ (fst (fst x)) (snd (fst x)))
(ren-eq-r-lam {τ :: Γ} {Γ'} (throw-r (r-extend ρ)) (fst x) (snd x))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) ,
(♭nat-refl (snd x))))
(ren-eq-r (r-extend (r-extend ρ)) e₂ x)))
(♭h-fix-args (interpE (ren e₁ ρ))
(interpE (ren e₂ (r-extend (r-extend ρ))))
(k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(k , Monotone.f (interpE (ren e ρ)) k) (ren-eq-r ρ e k))
ren-eq-r {Γ} {τ = τ1 ->c τ2} ρ (lam e) k x =
Preorder-str.trans (snd [ τ2 ]t)
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k , x))
(Monotone.f (interpE e) (Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x)))
(Monotone.f (Monotone.f (interpE (ren (lam e) ρ)) k) x)
((Monotone.is-monotone (interpE e)
(Monotone.f (interpR ρ) k , x)
(Monotone.f (interpR (r-extend {_} {_} {τ1} ρ)) (k , x))
(ren-eq-r-lam ρ k x ,
(Preorder-str.refl (snd [ τ1 ]t) x))))
(ren-eq-r (r-extend ρ) e (k , x))
ren-eq-r {Γ} {τ = τ} ρ (app e e₁) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))
(Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))
(Monotone.f (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k))
(ren-eq-r ρ e k (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)))
(Monotone.is-monotone (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k)) (Monotone.f (interpE (ren e₁ ρ)) k) (ren-eq-r ρ e₁ k))
ren-eq-r ρ (prod e e₁) k = (ren-eq-r ρ e k) , (ren-eq-r ρ e₁ k)
ren-eq-r ρ (l-proj e) k = fst (ren-eq-r ρ e k)
ren-eq-r ρ (r-proj e) k = snd (ren-eq-r ρ e k)
ren-eq-r ρ nil k = <>
ren-eq-r ρ (e ::c e₁) k = (ren-eq-r ρ e k) , (ren-eq-r ρ e₁ k)
ren-eq-r {Γ} {Γ'} {τ} ρ (listrec {.Γ'} {τ'} e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e₁ ρ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE (ren e ρ)) k)
(Monotone.f (interpE (ren e₁ ρ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) (((k , x₃) , x₂) , x₁)))
(lrec-cong
(monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k₁))
(λ x y x₁ →
Monotone.is-monotone (interpE e₁)
(Monotone.f (interpR ρ) x)
(Monotone.f (interpR ρ) y)
(Monotone.is-monotone (interpR ρ) x y x₁)))
(interpE (ren e₁ ρ))
(monotone (λ x → Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
(((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(((Monotone.f (interpR ρ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y)
(((Monotone.is-monotone (interpR ρ)
(fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁))) ,
snd (fst (fst x₁))) ,
snd (fst x₁)) ,
snd x₁)))
(interpE (ren e₂ (r-extend (r-extend (r-extend ρ)))))
(k , (Monotone.f (interpE e) (Monotone.f (interpR ρ) k)))
(λ x → ren-eq-r ρ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e₂) (((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(Monotone.f (interpE e₂) (Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x))
(Monotone.f (interpE (ren e₂ (r-extend (r-extend (r-extend ρ))))) x)
(Monotone.is-monotone (interpE e₂)
(((Monotone.f (interpR ρ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(Monotone.f (interpR {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (r-extend (r-extend (r-extend ρ)))) x)
((((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpR ρ) (fst (fst (fst x))))
(Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x))))
(Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x)
(ren-eq-r-lam ρ (fst (fst (fst x))) (snd (fst (fst x))))
(Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpR {τ :: Γ} {Γ'} (throw-r (r-extend ρ))) (fst (fst (fst x)) , snd (fst (fst x))))
(Monotone.f (interpR (λ x₁ → iS (iS (ρ x₁)))) (fst x))
(Monotone.f (interpR (λ x₁ → iS (iS (iS (ρ x₁))))) x)
(ren-eq-r-lam (λ x₁ → iS (ρ x₁)) (fst (fst x)) (snd (fst x)))
(ren-eq-r-lam (λ x₁ → iS (iS (ρ x₁))) (fst x) (snd x)))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x))))) ,
(l-refl (snd [ τ' ]t) (snd (fst x)))) ,
(Preorder-str.refl (snd [ τ' ]t) (snd x))))
(ren-eq-r (r-extend (r-extend (r-extend ρ))) e₂ x)))
(listrec-fix-args (interpE (ren e₁ ρ)) (interpE (ren e₂ (r-extend (r-extend (r-extend ρ)))))
(k , Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(k , Monotone.f (interpE (ren e ρ)) k)
(Preorder-str.refl (snd [ Γ ]c) k , ren-eq-r ρ e k))
ren-eq-r ρ true k = <>
ren-eq-r ρ false k = <>
ren-eq-r {Γ} {Γ'} {τ = τ} ρ (letc {.Γ'} {ρ'} e e') k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k , Monotone.f (interpE e') (Monotone.f (interpR ρ) k)))
(Monotone.f (interpE e) (Monotone.f (interpR (r-extend {_} {_} {ρ'} ρ)) (k , Monotone.f (interpE (ren e' ρ)) k)))
(Monotone.f (interpE (ren e (r-extend ρ)))
(k , Monotone.f (interpE (ren e' ρ)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpR ρ) k ,
Monotone.f (interpE e') (Monotone.f (interpR ρ) k))
(Monotone.f (interpR (r-extend {_} {_} {ρ'} ρ))
(k , Monotone.f (interpE (ren e' ρ)) k))
(ren-eq-r-lam ρ k (Monotone.f (interpE (ren e' ρ)) k) , ren-eq-r ρ e' k))
(ren-eq-r (r-extend ρ) e (k , Monotone.f (interpE (ren e' ρ)) k))
ren-eq-r {τ = τ} ρ (max x e e₁) k =
Preorder-max-str.max-lub [ x ]tm
(Monotone.f (interpE (ren (max x e e₁) ρ)) k)
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e ρ)) k)
(Monotone.f (interpE (ren (max x e e₁) ρ)) k)
(ren-eq-r ρ e k)
(Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k)))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e₁) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e₁ ρ)) k)
(Monotone.f (interpE (ren (max x e e₁) ρ)) k)
(ren-eq-r ρ e₁ k)
(Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE (ren e ρ)) k) (Monotone.f (interpE (ren e₁ ρ)) k)))
ids-lem-l : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k) k
ids-lem-l {[]} k = <>
ids-lem-l {x :: Γ} (k1 , k2) =
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {x :: Γ} {Γ} (throw-r (λ x₂ → x₂))) (k1 , k2))
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k1)
k1
(ren-eq-l-lam {Γ} {Γ} (λ x₂ → x₂) k1 k2)
(ids-lem-l {Γ} k1)) ,
(Preorder-str.refl (snd [ x ]t) k2)
subst-eq-l-lam : ∀ {Γ Γ' τ1} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t)
→ Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS (throw-s (s-extend {_} {_} {τ1} Θ))) (k , x)) (Monotone.f (interpS Θ) k)
subst-eq-l-lam {Γ' = []} Θ k x = <>
subst-eq-l-lam {Γ} {Γ' = x :: Γ'} {τ1} Θ k x₁ =
(subst-eq-l-lam (throw-s Θ) k x₁) ,
Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (ren (Θ i0) iS)) (k , x₁))
(Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)))
(snd (Monotone.f (interpS Θ) k))
(ren-eq-l iS (Θ i0) (k , x₁))
(Monotone.is-monotone (interpE (Θ i0)) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)) k
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁))
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
k
(ren-eq-l-lam {Γ} {Γ} (λ x₂ → x₂) k x₁)
(ids-lem-l {Γ} k)))
subst-eq-l : ∀ {Γ Γ' τ} → (Θ : sctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
subst-eq-l Θ unit k = <>
subst-eq-l Θ 0C k = <>
subst-eq-l Θ 1C k = <>
subst-eq-l Θ (plusC e e₁) k =
plus-lem (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(subst-eq-l Θ e k) (subst-eq-l Θ e₁ k)
subst-eq-l {τ = τ} Θ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE (Θ i0)) k)
subst-eq-l {τ = τ} Θ (var (iS x)) k = subst-eq-l (throw-s Θ) (var x) k
subst-eq-l Θ z k = <>
subst-eq-l Θ (s e) k = subst-eq-l Θ e k
subst-eq-l {Γ} {Γ'} {τ} Θ (rec e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(natrec (Monotone.f (interpE (subst e₁ Θ)) k)
(λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n))
(Monotone.f (interpE (subst e Θ)) k))
(natrec (Monotone.f (interpE (subst e₁ Θ)) k)
(λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))
(natrec (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))
(♭h-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend Θ))))
(k , Monotone.f (interpE (subst e Θ)) k)
(k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(subst-eq-l Θ e k))
(♭h-cong
(interpE (subst e₁ Θ))
(monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁)))
(interpE (subst e₂ (s-extend (s-extend Θ))))
(monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst v)) , snd (fst v)) , snd v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x)
((Monotone.f (interpS Θ) (fst (fst y)) , snd (fst y)) , snd y)
((Monotone.is-monotone (interpS Θ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) ,
snd (fst x₁)) ,
snd x₁)))
(k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(λ x → subst-eq-l Θ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) x)
(Monotone.f (interpE e₂) (Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x))
(Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x))
(subst-eq-l (s-extend (s-extend Θ)) e₂ x)
(Monotone.is-monotone (interpE e₂)
(Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x)
((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x)
(((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) x)
(Monotone.f (interpS (λ x₁ → ren (Θ x₁) iS)) (fst x))
(Monotone.f (interpS Θ) (fst (fst x)))
(subst-eq-l-lam {τ :: Γ} {Γ'} (λ x₁ → ren (Θ x₁) iS) (fst x) (snd x))
(subst-eq-l-lam Θ (fst (fst x)) (snd (fst x)))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) ,
(♭nat-refl (snd x))))))
subst-eq-l {Γ} {τ = τ1 ->c τ2} Θ (lam e) k x =
Preorder-str.trans (snd [ τ2 ]t)
(Monotone.f (Monotone.f (interpE (subst (lam e) Θ)) k) x)
(Monotone.f (interpE e) (Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x)))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k , x))
(subst-eq-l (s-extend Θ) e (k , x))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x))
(Monotone.f (interpS Θ) k , x)
(subst-eq-l-lam Θ k x ,
(Preorder-str.refl (snd [ τ1 ]t) x)))
subst-eq-l {Γ} {τ = τ} Θ (app e e₁) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k))
(Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))
(Monotone.f (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))
(Monotone.is-monotone (Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE (subst e₁ Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (subst-eq-l Θ e₁ k))
(subst-eq-l Θ e k (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))
subst-eq-l Θ (prod e e₁) k = (subst-eq-l Θ e k) , (subst-eq-l Θ e₁ k)
subst-eq-l Θ (l-proj e) k = fst (subst-eq-l Θ e k)
subst-eq-l Θ (r-proj e) k = snd (subst-eq-l Θ e k)
subst-eq-l Θ nil k = <>
subst-eq-l Θ (e ::c e₁) k = (subst-eq-l Θ e k) , (subst-eq-l Θ e₁ k)
subst-eq-l {Γ} {Γ'} {τ} Θ (listrec {.Γ'} {τ'} e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(lrec (Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE (subst e₁ Θ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e₁ Θ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) k , x₃) , x₂) , x₁)))
(listrec-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend (s-extend Θ)))))
(k , Monotone.f (interpE (subst e Θ)) k)
(k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Preorder-str.refl (snd [ Γ ]c) k , subst-eq-l Θ e k))
(lrec-cong
(interpE (subst e₁ Θ))
(monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k₁))
(λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁)))
(interpE (subst e₂ (s-extend (s-extend (s-extend Θ)))))
(monotone (λ x → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
(((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(((Monotone.f (interpS Θ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y)
(((Monotone.is-monotone (interpS Θ) (fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁))) ,
snd (fst (fst x₁))) ,
snd (fst x₁)) ,
snd x₁)))
(k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(λ x → subst-eq-l Θ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) x)
(Monotone.f (interpE e₂) (Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x))
(Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(subst-eq-l (s-extend (s-extend (s-extend Θ))) e₂ x)
(Monotone.is-monotone (interpE e₂)
(Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x)
(((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
((((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x)
(Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x)))
(Monotone.f (interpS Θ) (fst (fst (fst x))))
(Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x)
(Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) (fst x))
(Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x)))
(subst-eq-l-lam (λ x₁ → ren (ren (Θ x₁) iS) iS) (fst x) (snd x))
(subst-eq-l-lam (λ x₁ → ren (Θ x₁) iS) (fst (fst x)) (snd (fst x))))
(subst-eq-l-lam {Γ} {Γ'} Θ (fst (fst (fst x))) (snd (fst (fst x))))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x))))) ,
(l-refl (snd [ τ' ]t) (snd (fst x)))) ,
(Preorder-str.refl (snd [ τ' ]t) (snd x))))))
subst-eq-l Θ true k = <>
subst-eq-l Θ false k = <>
subst-eq-l {Γ} {Γ'} {τ = τ} Θ (letc {.Γ'} {ρ'} e e') k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (s-extend Θ))) (k , Monotone.f (interpE (subst e' Θ)) k))
(Monotone.f (interpE e) (Monotone.f (interpS (s-extend {_} {_} {ρ'} Θ)) (k , Monotone.f (interpE (subst e' Θ)) k)))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k , Monotone.f (interpE e') (Monotone.f (interpS Θ) k)))
(subst-eq-l (s-extend Θ) e (k , Monotone.f (interpE (subst e' Θ)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (s-extend {_} {_} {ρ'} Θ)) (k , Monotone.f (interpE (subst e' Θ)) k))
(Monotone.f (interpS Θ) k , Monotone.f (interpE e') (Monotone.f (interpS Θ) k))
((subst-eq-l-lam Θ k (Monotone.f (interpE (subst e' Θ)) k)) , (subst-eq-l Θ e' k)))
subst-eq-l {τ = τ} Θ (max x e e₁) k =
Preorder-max-str.max-lub [ x ]tm
(Monotone.f (interpE (max x e e₁)) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE (subst e₁ Θ)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (max x e e₁)) (Monotone.f (interpS Θ) k))
(subst-eq-l Θ e k)
(Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e₁ Θ)) k)
(Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (max x e e₁)) (Monotone.f (interpS Θ) k))
(subst-eq-l Θ e₁ k)
(Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))))
ids-lem-r : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) k (Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
ids-lem-r {[]} k = <>
ids-lem-r {x :: Γ} (k1 , k2) =
(Preorder-str.trans (snd [ Γ ]c)
k1
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k1)
(Monotone.f (interpR {x :: Γ} {Γ} (throw-r (λ x₂ → x₂))) (k1 , k2))
(ids-lem-r {Γ} k1)
(ren-eq-r-lam {Γ} {Γ} (λ x₂ → x₂) k1 k2)) ,
(Preorder-str.refl (snd [ x ]t) k2)
subst-eq-r-lam : ∀ {Γ Γ' τ1} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (x : fst [ τ1 ]t)
→ Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS (throw-s (s-extend {_} {_} {τ1} Θ))) (k , x))
subst-eq-r-lam {Γ' = []} Θ k x = <>
subst-eq-r-lam {Γ} {Γ' = x :: Γ'} {τ1} Θ k x₁ =
(subst-eq-r-lam (throw-s Θ) k x₁) ,
Preorder-str.trans (snd [ x ]t)
(snd (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁)))
(Monotone.f (interpE (ren (Θ i0) iS)) (k , x₁))
(Monotone.is-monotone (interpE (Θ i0))
k
(Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁))
(Preorder-str.trans (snd [ Γ ]c)
k
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
(Monotone.f (interpR {τ1 :: Γ} {Γ} iS) (k , x₁))
(ids-lem-r {Γ} k)
(ren-eq-r-lam {Γ} {Γ} (λ x₂ → x₂) k x₁)))
(ren-eq-r iS (Θ i0) (k , x₁))
subst-eq-r : ∀ {Γ Γ' τ} → (Θ : sctx Γ Γ') → (e : Γ' |- τ) → (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ τ ]t) (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e Θ)) k)
subst-eq-r Θ unit k = <>
subst-eq-r Θ 0C k = <>
subst-eq-r Θ 1C k = <>
subst-eq-r Θ (plusC e e₁) k =
plus-lem (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k)
(subst-eq-r Θ e k) (subst-eq-r Θ e₁ k)
subst-eq-r {τ = τ} Θ (var i0) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE (Θ i0)) k)
subst-eq-r {τ = τ} Θ (var (iS x)) k = subst-eq-r (throw-s Θ) (var x) k
subst-eq-r Θ z k = <>
subst-eq-r Θ (s e) k = subst-eq-r Θ e k
subst-eq-r {Γ} {Γ'} {τ} Θ (rec e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(natrec (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(λ n x₂ → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))
(natrec (Monotone.f (interpE (subst e₁ Θ)) k)
(λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))
(natrec (Monotone.f (interpE (subst e₁ Θ)) k)
(λ n x₂ → Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) ((k , x₂) , n))
(Monotone.f (interpE (subst e Θ)) k))
(♭h-cong
(monotone (λ v → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) v))
(λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁)))
(interpE (subst e₁ Θ))
(monotone (λ v → Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst v)) , snd (fst v)) , snd v))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x)
((Monotone.f (interpS Θ) (fst (fst y)) , snd (fst y)) , snd y)
((Monotone.is-monotone (interpS Θ) (fst (fst x)) (fst (fst y)) (fst (fst x₁)) ,
snd (fst x₁)) ,
snd x₁)))
(interpE (subst e₂ (s-extend (s-extend Θ))))
(k , (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))
(λ x → subst-eq-r Θ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e₂) ((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x))
(Monotone.f (interpE e₂) (Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x))
(Monotone.f (interpE (subst e₂ (s-extend (s-extend Θ)))) x)
(Monotone.is-monotone (interpE e₂)
((Monotone.f (interpS Θ) (fst (fst x)) , snd (fst x)) , snd x)
(Monotone.f (interpS {nat :: τ :: Γ} {_ :: _ :: Γ'} (s-extend (s-extend Θ))) x)
(((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS Θ) (fst (fst x)))
(Monotone.f (interpS (λ x₁ → ren (Θ x₁) iS)) (fst x))
(Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) x)
(subst-eq-r-lam Θ (fst (fst x)) (snd (fst x)))
(subst-eq-r-lam {τ :: Γ} {Γ'} (λ x₁ → ren (Θ x₁) iS) (fst x) (snd x))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst x)))) ,
(♭nat-refl (snd x))))
(subst-eq-r (s-extend (s-extend Θ)) e₂ x)))
(♭h-fix-args (interpE (subst e₁ Θ))
(interpE (subst e₂ (s-extend (s-extend Θ))))
(k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(k , Monotone.f (interpE (subst e Θ)) k)
(subst-eq-r Θ e k))
subst-eq-r {Γ} {τ = τ1 ->c τ2} Θ (lam e) k x =
Preorder-str.trans (snd [ τ2 ]t)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k , x))
(Monotone.f (interpE e) (Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x)))
(Monotone.f (Monotone.f (interpE (subst (lam e) Θ)) k) x)
((Monotone.is-monotone (interpE e)
(Monotone.f (interpS Θ) k , x)
(Monotone.f (interpS (s-extend {_} {_} {τ1} Θ)) (k , x))
(subst-eq-r-lam Θ k x ,
(Preorder-str.refl (snd [ τ1 ]t) x))))
(subst-eq-r (s-extend Θ) e (k , x))
subst-eq-r {Γ} {τ = τ} Θ (app e e₁) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))
(Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))
(Monotone.f (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k))
(subst-eq-r Θ e k (Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)))
(Monotone.is-monotone (Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k)) (Monotone.f (interpE (subst e₁ Θ)) k) (subst-eq-r Θ e₁ k))
subst-eq-r Θ (prod e e₁) k = (subst-eq-r Θ e k) , (subst-eq-r Θ e₁ k)
subst-eq-r Θ (l-proj e) k = fst (subst-eq-r Θ e k)
subst-eq-r Θ (r-proj e) k = snd (subst-eq-r Θ e k)
subst-eq-r Θ nil k = <>
subst-eq-r Θ (e ::c e₁) k = (subst-eq-r Θ e k) , (subst-eq-r Θ e₁ k)
subst-eq-r {Γ} {Γ'} {τ} Θ (listrec {.Γ'} {τ'} e e₁ e₂) k =
Preorder-str.trans (snd [ τ ]t)
(lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(λ x₁ x₂ x₃ → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e₁ Θ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁)))
(lrec (Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE (subst e₁ Θ)) k)
(λ x₁ x₂ x₃ → Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) (((k , x₃) , x₂) , x₁)))
(lrec-cong
(monotone (λ k₁ → Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k₁))
(λ x y x₁ → Monotone.is-monotone (interpE e₁) (Monotone.f (interpS Θ) x) (Monotone.f (interpS Θ) y) (Monotone.is-monotone (interpS Θ) x y x₁)))
(interpE (subst e₁ Θ))
(monotone (λ x → Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(λ x y x₁ →
Monotone.is-monotone (interpE e₂)
(((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(((Monotone.f (interpS Θ) (fst (fst (fst y))) , snd (fst (fst y))) , snd (fst y)) , snd y)
(((Monotone.is-monotone (interpS Θ)
(fst (fst (fst x))) (fst (fst (fst y))) (fst (fst (fst x₁))) , snd (fst (fst x₁))) , snd (fst x₁)) , snd x₁)))
(interpE (subst e₂ (s-extend (s-extend (s-extend Θ)))))
(k , (Monotone.f (interpE e) (Monotone.f (interpS Θ) k)))
(λ x → subst-eq-r Θ e₁ x)
(λ x →
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e₂) (((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x))
(Monotone.f (interpE e₂) (Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x))
(Monotone.f (interpE (subst e₂ (s-extend (s-extend (s-extend Θ))))) x)
(Monotone.is-monotone (interpE e₂)
(((Monotone.f (interpS Θ) (fst (fst (fst x))) , snd (fst (fst x))) , snd (fst x)) , snd x)
(Monotone.f (interpS {τ' :: list τ' :: τ :: Γ} {_ :: _ :: _ :: Γ'} (s-extend (s-extend (s-extend Θ)))) x)
((((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS Θ) (fst (fst (fst x))))
(Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x)))
(Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x)
(subst-eq-r-lam {Γ} {Γ'} Θ (fst (fst (fst x))) (snd (fst (fst x))))
(Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS {τ :: Γ} {Γ'} (throw-s (s-extend Θ))) (fst (fst x)))
(Monotone.f (interpS (λ x₁ → ren (ren (Θ x₁) iS) iS)) (fst x))
(Monotone.f (interpS (λ x₁ → ren (ren (ren (Θ x₁) iS) iS) iS)) x)
(subst-eq-r-lam (λ x₁ → ren (Θ x₁) iS) (fst (fst x)) (snd (fst x)))
(subst-eq-r-lam (λ x₁ → ren (ren (Θ x₁) iS) iS) (fst x) (snd x)))) ,
(Preorder-str.refl (snd [ τ ]t) (snd (fst (fst x))))) ,
(l-refl (snd [ τ' ]t) (snd (fst x)))) ,
(Preorder-str.refl (snd [ τ' ]t) (snd x))))
(subst-eq-r (s-extend (s-extend (s-extend Θ))) e₂ x)))
(listrec-fix-args (interpE (subst e₁ Θ)) (interpE (subst e₂ (s-extend (s-extend (s-extend Θ)))))
(k , Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(k , Monotone.f (interpE (subst e Θ)) k)
(Preorder-str.refl (snd [ Γ ]c) k , subst-eq-r Θ e k))
subst-eq-r Θ true k = <>
subst-eq-r Θ false k = <>
subst-eq-r {Γ} {Γ'} {τ = τ} Θ (letc {.Γ'} {ρ'} e e') k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k , Monotone.f (interpE e') (Monotone.f (interpS Θ) k)))
(Monotone.f (interpE e) (Monotone.f (interpS (s-extend {_} {_} {ρ'} Θ)) (k , Monotone.f (interpE (subst e' Θ)) k)))
(Monotone.f (interpE (subst e (s-extend Θ))) (k , Monotone.f (interpE (subst e' Θ)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS Θ) k , Monotone.f (interpE e') (Monotone.f (interpS Θ) k))
(Monotone.f (interpS (s-extend {_} {_} {ρ'} Θ)) (k , Monotone.f (interpE (subst e' Θ)) k))
((subst-eq-r-lam Θ k (Monotone.f (interpE (subst e' Θ)) k)) , (subst-eq-r Θ e' k)))
(subst-eq-r (s-extend Θ) e (k , Monotone.f (interpE (subst e' Θ)) k))
subst-eq-r {τ = τ} Θ (max x e e₁) k =
Preorder-max-str.max-lub [ x ]tm
(Monotone.f (interpE (subst (max x e e₁) Θ)) k)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE (subst (max x e e₁) Θ)) k)
(subst-eq-r Θ e k)
(Preorder-max-str.max-l [ x ]tm (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k)))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e₁) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e₁ Θ)) k)
(Monotone.f (interpE (subst (max x e e₁) Θ)) k)
(subst-eq-r Θ e₁ k)
(Preorder-max-str.max-r [ x ]tm (Monotone.f (interpE (subst e Θ)) k) (Monotone.f (interpE (subst e₁ Θ)) k)))
interp-rr-l : ∀ {Γ Γ' Γ''} (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k))
(Monotone.f (interpR (λ x → ρ1 (ρ2 x))) k)
interp-rr-l {Γ'' = []} ρ1 ρ2 k = <>
interp-rr-l {Γ'' = x :: Γ''} ρ1 ρ2 k = (interp-rr-l ρ1 (throw-r ρ2) k) , (ren-eq-r ρ1 (var (ρ2 i0)) k)
interp-rr-r : ∀ {Γ Γ' Γ''} (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpR (λ x → ρ1 (ρ2 x))) k)
(Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k))
interp-rr-r {Γ'' = []} ρ1 ρ2 k = <>
interp-rr-r {Γ'' = x :: Γ''} ρ1 ρ2 k = (interp-rr-r ρ1 (throw-r ρ2) k) , (ren-eq-l ρ1 (var (ρ2 i0)) k)
interp-rs-l : ∀ {Γ Γ' Γ''} (ρ : rctx Γ Γ') (Θ : sctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))
(Monotone.f (interpS (λ x → ren (Θ x) ρ)) k)
interp-rs-l {Γ'' = []} ρ Θ k = <>
interp-rs-l {Γ'' = x :: Γ''} ρ Θ k = (interp-rs-l ρ (throw-s Θ) k) , (ren-eq-r ρ (Θ i0) k)
interp-rs-r : ∀ {Γ Γ' Γ''} (ρ : rctx Γ Γ') (Θ : sctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpS (λ x → ren (Θ x) ρ)) k)
(Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))
interp-rs-r {Γ'' = []} ρ Θ k = <>
interp-rs-r {Γ'' = x :: Γ''} ρ Θ k = (interp-rs-r ρ (throw-s Θ) k) , (ren-eq-l ρ (Θ i0) k)
interp-sr-l : ∀ {Γ Γ' Γ''} (Θ : sctx Γ Γ') (ρ : rctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k))
(Monotone.f (interpS (λ x → Θ (ρ x))) k)
interp-sr-l {Γ'' = []} Θ ρ k = <>
interp-sr-l {Γ'' = x :: Γ''} Θ ρ k = (interp-sr-l Θ (throw-r ρ) k) , (subst-eq-r Θ (var (ρ i0)) k)
interp-sr-r : ∀ {Γ Γ' Γ''} (Θ : sctx Γ Γ') (ρ : rctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpS (λ x → Θ (ρ x))) k)
(Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k))
interp-sr-r {Γ'' = []} Θ ρ k = <>
interp-sr-r {Γ'' = x :: Γ''} Θ ρ k = (interp-sr-r Θ (throw-r ρ) k) , (subst-eq-l Θ (var (ρ i0)) k)
interp-ss-l : ∀ {Γ Γ' Γ''} (Θ1 : sctx Γ Γ') (Θ2 : sctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpS (λ x → subst (Θ2 x) Θ1)) k)
(Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k))
interp-ss-l {Γ'' = []} Θ1 Θ2 k = <>
interp-ss-l {Γ'' = x :: Γ''} Θ1 Θ2 k = (interp-ss-l Θ1 (throw-s Θ2) k) , (subst-eq-l Θ1 (Θ2 i0) k)
interp-ss-r : ∀ {Γ Γ' Γ''} (Θ1 : sctx Γ Γ') (Θ2 : sctx Γ' Γ'') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ'' ]c)
(Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k))
(Monotone.f (interpS (λ x → subst (Θ2 x) Θ1)) k)
interp-ss-r {Γ'' = []} Θ1 Θ2 k = <>
interp-ss-r {Γ'' = x :: Γ''} Θ1 Θ2 k = (interp-ss-r Θ1 (throw-s Θ2) k) , (subst-eq-r Θ1 (Θ2 i0) k)
lam-s-lem : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) (Monotone.f (interpS {Γ} {Γ} ids) k) k
lam-s-lem {[]} k = <>
lam-s-lem {x :: Γ} (k1 , k2) =
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpS {x :: Γ} {Γ} (throw-s ids)) (k1 , k2))
(Monotone.f (interpS {Γ} {Γ} ids) k1)
k1
(subst-eq-l-lam {Γ} {Γ} ids k1 (Monotone.f (interpE {x :: Γ} {x} (ids i0)) (k1 , k2)))
(lam-s-lem {Γ} k1)) ,
(Preorder-str.refl (snd [ x ]t) k2)
lam-s-lem-r : ∀ {Γ} (k : fst [ Γ ]c) → Preorder-str.≤ (snd [ Γ ]c) k (Monotone.f (interpS {Γ} {Γ} ids) k)
lam-s-lem-r {[]} k = <>
lam-s-lem-r {x :: Γ} (k1 , k2) =
(Preorder-str.trans (snd [ Γ ]c)
k1
(Monotone.f (interpS {Γ} {Γ} ids) k1)
(Monotone.f (interpS {x :: Γ} {Γ} (throw-s ids)) (k1 , k2))
(lam-s-lem-r {Γ} k1)
(subst-eq-r-lam {Γ} {Γ} ids k1 (Monotone.f (interpE {x :: Γ} {x} (ids i0)) (k1 , k2)))) ,
(Preorder-str.refl (snd [ x ]t) k2)
interp-subst-comp-l : ∀ {Γ Γ' τ'} (Θ : sctx Γ Γ') (v : Γ |- τ') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k)
(Monotone.f (interpS (λ x → Θ x)) k)
interp-subst-comp-l {Γ' = []} Θ v k = <>
interp-subst-comp-l {Γ} {Γ' = x :: Γ'} {τ'} Θ v k =
(interp-subst-comp-l (throw-s Θ) v k) ,
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v))) k)
(Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k))
(Monotone.f (interpE (Θ i0)) k)
(subst-eq-l (lem3' ids v) (ren (Θ i0) iS) k)
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k))
(Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)))
(Monotone.f (interpE (Θ i0)) k)
(ren-eq-l iS (Θ i0) (Monotone.f (interpS (lem3' ids v)) k))
(Monotone.is-monotone (interpE (Θ i0))
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))
k
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
k
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (k , Monotone.f (interpE v) k))
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
(Monotone.is-monotone (interpR {τ' :: Γ} {Γ} iS)
(Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)
(k , Monotone.f (interpE v) k)
(lam-s-lem {Γ} k , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k))))
(ren-eq-l-lam {Γ} {Γ} {τ'} (λ x₂ → x₂) k (Monotone.f (interpE v) k)))
(ids-lem-l {Γ} k)))))
interp-subst-comp-r : ∀ {Γ Γ' τ'} (Θ : sctx Γ Γ') (v : Γ |- τ') (k : fst [ Γ ]c)
→ Preorder-str.≤ (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → Θ x)) k)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k)
interp-subst-comp-r {Γ' = []} Θ v k = <>
interp-subst-comp-r {Γ} {Γ' = x :: Γ'} {τ'} Θ v k =
(interp-subst-comp-r (throw-s Θ) v k) ,
Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (Θ i0)) k)
(Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k))
(Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v))) k)
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (Θ i0)) k)
(Monotone.f (interpE (Θ i0)) (Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)))
(Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v)) k))
(Monotone.is-monotone (interpE (Θ i0))
k
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))
(Preorder-str.trans (snd [ Γ ]c)
k
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))
(ids-lem-r {Γ} k)
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {Γ} {Γ} (λ x₂ → x₂)) k)
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (k , Monotone.f (interpE v) k))
(Monotone.f (interpR {τ' :: Γ} {Γ} iS) (Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k))
(ren-eq-r-lam {Γ} {Γ} {τ'} (λ x₂ → x₂) k (Monotone.f (interpE v) k))
(Monotone.is-monotone (interpR {τ' :: Γ} {Γ} iS)
(k , Monotone.f (interpE v) k)
(Monotone.f (interpS {Γ} {τ' :: Γ} (lem3' ids v)) k)
(lam-s-lem-r {Γ} k , Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k))))))
(ren-eq-r iS (Θ i0) (Monotone.f (interpS (lem3' ids v)) k)))
(subst-eq-r (lem3' ids v) (ren (Θ i0) iS) k)
interp-subst-comp2-l : ∀ {Γ Γ' τ' τ''} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v1 : Γ |- τ') (v2 : Γ |- τ'')
→ Preorder-str.≤ (snd [ Γ' ]c)
(Monotone.f (interpS {τ' :: τ'' :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS))
((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k)
interp-subst-comp2-l {Γ' = []} Θ k v1 v2 = <>
interp-subst-comp2-l {Γ} {Γ' = x :: Γ'} {τ'} {τ''} Θ k v1 v2 =
(interp-subst-comp2-l (throw-s Θ) k v1 v2) ,
Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (ren (ren (Θ i0) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpE (ren (Θ i0) iS))
(Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
(Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k)
(ren-eq-l iS (ren (Θ i0) iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (ren (Θ i0) iS))
(Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
(Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v2)) k))
(Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k)
(Monotone.is-monotone (interpE (ren (Θ i0) iS))
(Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS (lem3' ids v2)) k)
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Monotone.f (interpS {Γ} ids) k)
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpR {τ'' :: Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k))
(Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(ren-eq-l-lam {τ'' :: Γ} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k))
(ren-eq-l-lam {Γ} {Γ} {τ''} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v2) k)))
(interp-sr-l {Γ} ids (λ x₁ → x₁) k) ,
Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k)))
(subst-eq-r (lem3' ids v2) (ren (Θ i0) iS) k))
interp-subst-comp2-r : ∀ {Γ Γ' τ' τ''} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v1 : Γ |- τ') (v2 : Γ |- τ'')
→ Preorder-str.≤ (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k)
(Monotone.f (interpS {τ' :: τ'' :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS))
((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
interp-subst-comp2-r {Γ' = []} Θ k v1 v2 = <>
interp-subst-comp2-r {Γ} {Γ' = x :: Γ'} {τ'} {τ''} Θ k v1 v2 =
(interp-subst-comp2-r (throw-s Θ) k v1 v2) ,
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k)
(Monotone.f (interpE (ren (Θ i0) iS))
(Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
(Monotone.f (interpE (ren (ren (Θ i0) iS) iS))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (subst (ren (Θ i0) iS) (lem3' ids v2))) k)
(Monotone.f (interpE (ren (Θ i0) iS)) (Monotone.f (interpS (lem3' ids v2)) k))
(Monotone.f (interpE (ren (Θ i0) iS))
(Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
(subst-eq-l (lem3' ids v2) (ren (Θ i0) iS) k)
(Monotone.is-monotone (interpE (ren (Θ i0) iS))
(Monotone.f (interpS (lem3' ids v2)) k)
(Monotone.f (interpR {τ' :: τ'' :: Γ} iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
((Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpS {Γ} ids) k)
(Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(interp-sr-r {Γ} ids (λ x₁ → x₁) k)
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {Γ} {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Monotone.f (interpR {τ'' :: Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k))
(Monotone.f (interpR {τ' :: τ'' :: Γ} (λ x₁ → iS (iS x₁))) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(ren-eq-r-lam {Γ} {Γ} {τ''} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v2) k))
(ren-eq-r-lam {τ'' :: Γ} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k)))) ,
(Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k)))))
(ren-eq-r iS (ren (Θ i0) iS) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
interp-subst-comp3-l : ∀ {Γ Γ' τ1 τ2 τ3} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v3 : Γ |- τ3) (v2 : Γ |- τ2) (v1 : Γ |- τ1)
→ Preorder-str.≤ (snd [ Γ' ]c)
(Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (ren (Θ x) iS) iS) iS))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS {τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
interp-subst-comp3-l {Γ' = []} Θ k v3 v2 v1 = <>
interp-subst-comp3-l {Γ} {Γ' = x :: Γ'} {τ1} {τ2} {τ3} Θ k v3 v2 v1 =
(interp-subst-comp3-l (throw-s Θ) k v3 v2 v1) ,
(Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (ren (ren (ren (Θ i0) iS) iS) iS))
(((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpE (ren (ren (Θ i0) iS) iS))
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS)
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
(Monotone.f (interpE (ren (ren (Θ i0) iS) iS))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(ren-eq-l iS (ren (ren (Θ i0) iS) iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.is-monotone (interpE (ren (ren (Θ i0) iS) iS))
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS)
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)
((Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁))))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Monotone.f (interpS {Γ} ids) k)
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁))))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k))
(Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁))))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpR {τ2 :: τ3 :: Γ} (throw-r (r-extend iS)))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k))
(fst (ren-eq-l-lam {τ2 :: τ3 :: Γ} {τ3 :: Γ} {τ1} (λ x₁ → iS x₁)
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k)))
(ren-eq-l-lam {τ3 :: Γ} {Γ} {τ2} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) (Monotone.f (interpE v2) k)))
(ren-eq-l-lam {Γ} {Γ} {τ3} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v3) k)))
(interp-sr-l {Γ} ids (λ x₁ → x₁) k) ,
Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k)) ,
Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k))))
interp-subst-comp3-r : ∀ {Γ Γ' τ1 τ2 τ3} (Θ : sctx Γ Γ') (k : fst [ Γ ]c) (v3 : Γ |- τ3) (v2 : Γ |- τ2) (v1 : Γ |- τ1)
→ Preorder-str.≤ (snd [ Γ' ]c)
(Monotone.f (interpS {τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (Θ x) iS) iS))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {Γ'} (λ x → ren (ren (ren (Θ x) iS) iS) iS))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
interp-subst-comp3-r {Γ' = []} Θ k v3 v2 v1 = <>
interp-subst-comp3-r {Γ} {Γ' = x :: Γ'} {τ1} {τ2} {τ3} Θ k v3 v2 v1 =
(interp-subst-comp3-r (throw-s Θ) k v3 v2 v1) ,
Preorder-str.trans (snd [ x ]t)
(Monotone.f (interpE (ren (ren (Θ i0) iS) iS))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(Monotone.f (interpE (ren (ren (Θ i0) iS) iS))
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS)
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k)))
(Monotone.f (interpE (ren (ren (ren (Θ i0) iS) iS) iS))
(((Monotone.f (interpS {Γ} {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.is-monotone (interpE (ren (ren (Θ i0) iS) iS))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k)
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {τ2 :: τ3 :: Γ} iS)
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(((Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpS {Γ} ids) k)
(Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁))))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(interp-sr-r {Γ} ids (λ x₁ → x₁) k)
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {Γ} (λ x₁ → x₁)) (Monotone.f (interpS {Γ} ids) k))
(Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k))
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁))))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(ren-eq-r-lam {Γ} {Γ} {τ3} (λ x₁ → x₁) (Monotone.f (interpS {Γ} ids) k) (Monotone.f (interpE v3) k))
(Preorder-str.trans (snd [ Γ ]c)
(Monotone.f (interpR {τ3 :: Γ} {Γ} (throw-r (r-extend (λ x₁ → x₁)))) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k))
(Monotone.f (interpR {τ2 :: τ3 :: Γ} (throw-r (r-extend iS)))
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(Monotone.f (interpR {τ1 :: τ2 :: τ3 :: Γ} {Γ} (λ x₁ → iS (iS (iS x₁))))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(ren-eq-r-lam {τ3 :: Γ} {Γ} {τ2} (λ x₁ → iS x₁) (Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) (Monotone.f (interpE v2) k))
(fst (ren-eq-r-lam {τ2 :: τ3 :: Γ} {τ3 :: Γ} {τ1} (λ x₁ → iS x₁)
((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) (Monotone.f (interpE v1) k)))))) ,
(Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k))) ,
(Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k))))
(ren-eq-r iS (ren (ren (Θ i0) iS) iS) (((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
s-cong2-lem : ∀ {Γ Γ'} (Θ Θ' : sctx Γ Γ') (k : fst [ Γ ]c)
(x : (τ₁ : CTp) (x₁ : τ₁ ∈ Γ') → Preorder-str.≤ (snd [ τ₁ ]t) (Monotone.f (interpE (Θ x₁)) k) (Monotone.f (interpE (Θ' x₁)) k))
→ Preorder-str.≤ (snd [ Γ' ]c) (Monotone.f (interpS Θ) k) (Monotone.f (interpS Θ') k)
s-cong2-lem {Γ' = []} Θ Θ' x k = <>
s-cong2-lem {Γ' = x :: Γ'} Θ Θ' x₁ k = (s-cong2-lem (throw-s Θ) (throw-s Θ') x₁ (λ τ₁ x₂ → k τ₁ (iS x₂))) , k x i0
sound {_} {τ} e .e refl-s k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k)
sound {Γ} {τ} e e' (trans-s {.Γ} {.τ} {.e} {e''} {.e'} d d₁) k =
Preorder-str.trans (snd [ τ ]t) (Monotone.f (interpE e) k) (Monotone.f (interpE e'') k) (Monotone.f (interpE e') k) (sound e e'' d k) (sound e'' e' d₁ k)
sound {_} {τ} e .e (cong-refl Refl) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k)
sound {_} {._} ._ ._ (lt {._}) k = <>
sound {_} {τ} (letc e e') .(app (lam e) e') letc-app-l k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) (k , Monotone.f (interpE e') k))
sound {_} {τ} (app (lam e) e') .(letc e e') letc-app-r k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) (k , Monotone.f (interpE e') k))
sound .(plusC 0C e') e' +-unit-l k = Preorder-str.refl (snd [ C ]t) (Monotone.f (interpE e') k)
sound e .(plusC 0C e) +-unit-l' k = Preorder-str.refl (snd [ C ]t) (Monotone.f (interpE e) k)
sound {_} {.C} .(plusC e' 0C) e' +-unit-r k = +-unit (Monotone.f (interpE e') k)
sound e .(plusC e 0C) +-unit-r' k = plus-lem' (Monotone.f (interpE e) k) (Monotone.f (interpE e) k) Z (nat-refl (Monotone.f (interpE e) k))
sound {Γ} {.C} ._ ._ (+-assoc {.Γ} {e1} {e2} {e3}) k = plus-assoc (Monotone.f (interpE e1) k) (Monotone.f (interpE e2) k) (Monotone.f (interpE e3) k)
sound {Γ} {.C} ._ ._ (+-assoc' {.Γ} {e1} {e2} {e3}) k = plus-assoc' (Monotone.f (interpE e1) k) (Monotone.f (interpE e2) k) (Monotone.f (interpE e3) k)
sound {Γ} {.C} ._ ._ (refl-+ {.Γ} {e0} {e1}) k = +-comm (Monotone.f (interpE e0) k) (Monotone.f (interpE e1) k)
sound {Γ} {C} ._ ._ (cong-+ {.Γ} {e0} {e1} {e0'} {e1'} d d₁) k = --also called plus-s. should really delete this rule so we don't have duplicates
plus-lem (Monotone.f (interpE e0) k) (Monotone.f (interpE e1) k) (Monotone.f (interpE e0') k) (Monotone.f (interpE e1') k)
(sound e0 e0' d k) (sound e1 e1' d₁ k)
sound {Γ} {τ} ._ ._ (cong-lproj {.Γ} {.τ} {_} {e} {e'} d) k = fst (sound e e' d k)
sound {Γ} {τ} ._ ._ (cong-rproj {.Γ} {_} {.τ} {e} {e'} d) k = snd (sound e e' d k)
sound {Γ} {τ} ._ ._ (cong-app {.Γ} {τ'} {.τ} {e} {e'} {e1} d) k = sound e e' d k (Monotone.f (interpE e1) k)
sound {Γ} {τ} ._ ._ (ren-cong {.Γ} {Γ'} {.τ} {e1} {e2} {ρ} d) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e1 ρ)) k)
(Monotone.f (interpE e1) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e2 ρ)) k)
(ren-eq-l ρ e1 k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e1) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE e2) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren e2 ρ)) k)
(sound e1 e2 d (Monotone.f (interpR ρ) k))
(ren-eq-r ρ e2 k))
sound {Γ} {τ} ._ ._ (subst-cong {.Γ} {Γ'} {.τ} {e1} {e2} {Θ} d) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 Θ)) k)
(Monotone.f (interpE e1) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e2 Θ)) k)
(subst-eq-l Θ e1 k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e1) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e2) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e2 Θ)) k)
(sound e1 e2 d (Monotone.f (interpS Θ) k))
(subst-eq-r Θ e2 k))
sound {Γ} {τ} ._ ._ (subst-cong2 {.Γ} {Γ'} {.τ} {Θ} {Θ'} {e} x) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e Θ)) k)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e Θ')) k) (subst-eq-l Θ e k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e) (Monotone.f (interpS Θ') k))
(Monotone.f (interpE (subst e Θ')) k)
(Monotone.is-monotone (interpE e) (Monotone.f (interpS Θ) k)
(Monotone.f (interpS Θ') k) (s-cong2-lem Θ Θ' k (λ τ1 x1 → sound _ _ (x _ x1) k)))
(subst-eq-r Θ' e k))
sound {Γ} {τ} ._ ._ (cong-rec {.Γ} {.τ} {e} {e'} {e0} {e1} d) k =
♭h-fix-args (interpE e0) (interpE e1) (k , Monotone.f (interpE e) k) (k , Monotone.f (interpE e') k) (sound e e' d k)
sound {Γ} {τ} ._ ._ (cong-listrec {.Γ} {τ'} {.τ} {e} {e'} {e0} {e1} d) k =
listrec-fix-args (interpE e0) (interpE e1) (k , (Monotone.f (interpE e) k)) (k , Monotone.f (interpE e') k) ((Preorder-str.refl (snd [ Γ ]c) k) , (sound e e' d k))
sound {Γ} {τ} ._ ._ (lam-s {.Γ} {τ'} {.τ} {e} {e2}) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (q e2))) k)
(Monotone.f (interpE e) (Monotone.f (interpS (q e2)) k))
(Monotone.f (interpE e) (k , Monotone.f (interpE e2) k))
(subst-eq-l (q e2) e k)
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (q e2)) k)
(k , Monotone.f (interpE e2) k)
(lam-s-lem {Γ} k , (Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE e2) k))))
sound {Γ} {τ} e ._ (l-proj-s {.Γ}) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k)
sound {Γ} {τ} e ._ (r-proj-s {.Γ}) k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k)
sound {_} {τ} e ._ rec-steps-z k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k)
sound {Γ} {τ} ._ ._ (rec-steps-s {.Γ} {.τ} {e} {e0} {e1}) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids (rec e e0 e1)) e))) k)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids (rec e e0 e1)) e)) k))
(Monotone.f (interpE e1)
((k , natrec (Monotone.f (interpE e0) k) (λ n x₂ → Monotone.f (interpE e1) ((k , x₂) , n)) (Monotone.f (interpE e) k)) , Monotone.f (interpE e) k))
(subst-eq-l (lem3' (lem3' ids (rec e e0 e1)) e) e1 k)
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS (lem3' (lem3' ids (rec e e0 e1)) e)) k)
((k , natrec (Monotone.f (interpE e0) k)
(λ n x₂ → Monotone.f (interpE e1) ((k , x₂) , n)) (Monotone.f (interpE e) k)) , Monotone.f (interpE e) k)
((lam-s-lem {Γ} k ,
(Preorder-str.refl (snd [ τ ]t) (natrec (Monotone.f (interpE e0) k) (λ n x₂ → Monotone.f (interpE e1) ((k , x₂) , n)) (Monotone.f (interpE e) k)))) ,
(♭nat-refl (Monotone.f (interpE e) k))))
sound {Γ} {τ} e ._ listrec-steps-nil k = Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE e) k)
sound {Γ} {τ} ._ ._ (listrec-steps-cons {.Γ} {τ'} {.τ} {h} {t} {e0} {e1}) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h))) k)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h)) k))
(Monotone.f (interpE e1)
(((k ,
lrec (Monotone.f (interpE t) k) (Monotone.f (interpE e0) k) (λ x₁ x₂ x₃ → Monotone.f (interpE e1) (((k , x₃) , x₂) , x₁))) ,
Monotone.f (interpE t) k) ,
Monotone.f (interpE h) k))
(subst-eq-l (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h) e1 k)
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS (lem3' (lem3' (lem3' ids (listrec t e0 e1)) t) h)) k)
(((k , lrec (Monotone.f (interpE t) k) (Monotone.f (interpE e0) k) (λ x₁ x₂ x₃ → Monotone.f (interpE e1) (((k , x₃) , x₂) , x₁))) ,
Monotone.f (interpE t) k) , Monotone.f (interpE h) k)
(((lam-s-lem {Γ} k ,
(Preorder-str.refl (snd [ τ ]t) (lrec (Monotone.f (interpE t) k) (Monotone.f (interpE e0) k) (λ x₁ x₂ x₃ → Monotone.f (interpE e1) (((k , x₃) , x₂) , x₁))))) ,
(l-refl (snd [ τ' ]t) (Monotone.f (interpE t) k))) ,
(Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE h) k))))
sound {Γ} {τ} .(ren (ren e ρ2) ρ1) ._ (ren-comp-l ρ1 ρ2 e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren (ren e ρ2) ρ1)) k)
(Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k))
(Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k)
(ren-eq-l ρ1 (ren e ρ2) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k))
(Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k))
(Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k))
(Monotone.f (interpE e) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k)))
(Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k))
(ren-eq-l ρ2 e (Monotone.f (interpR ρ1) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k))
(Monotone.f (interpR (ρ1 ∙rr ρ2)) k)
(interp-rr-l ρ1 ρ2 k)))
(ren-eq-r (ρ1 ∙rr ρ2) e k))
sound {Γ} {τ} ._ .(ren (ren e ρ2) ρ1) (ren-comp-r ρ1 ρ2 e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k)
(Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k))
(Monotone.f (interpE (ren (ren e ρ2) ρ1)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e (ρ1 ∙rr ρ2))) k)
(Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k))
(Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k))
(ren-eq-l (ρ1 ∙rr ρ2) e k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpR (ρ1 ∙rr ρ2)) k))
(Monotone.f (interpE e) (Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k)))
(Monotone.f (interpE (ren e ρ2)) (Monotone.f (interpR ρ1) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpR (ρ1 ∙rr ρ2)) k)
(Monotone.f (interpR ρ2) (Monotone.f (interpR ρ1) k))
(interp-rr-r ρ1 ρ2 k))
(ren-eq-r ρ2 e (Monotone.f (interpR ρ1) k))))
(ren-eq-r ρ1 (ren e ρ2) k)
sound {Γ} {τ} e ._ (subst-id-l .e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) k)
(Monotone.f (interpE e) (Monotone.f (interpS {Γ} {Γ} ids) k))
(Monotone.f (interpE (subst e ids)) k)
(Monotone.is-monotone (interpE e) k (Monotone.f (interpS {Γ} {Γ} ids) k) (lam-s-lem-r {Γ} k))
(subst-eq-r ids e k)
sound {Γ} {τ} ._ e' (subst-id-r .e') k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e' ids)) k)
(Monotone.f (interpE e') (Monotone.f (interpS {Γ} {Γ} ids) k))
(Monotone.f (interpE e') k)
(subst-eq-l ids e' k)
(Monotone.is-monotone (interpE e') (Monotone.f (interpS {Γ} {Γ} ids) k) k (lam-s-lem {Γ} k))
sound {Γ} {τ} .(ren (subst e Θ) ρ) ._ (subst-rs-l ρ Θ e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren (subst e Θ) ρ)) k)
(Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (subst e (ρ rs Θ))) k)
(ren-eq-l ρ (subst e Θ) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)))
(Monotone.f (interpE (subst e (ρ rs Θ))) k)
(subst-eq-l Θ e (Monotone.f (interpR ρ) k))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)))
(Monotone.f (interpE e) (Monotone.f (interpS (ρ rs Θ)) k))
(Monotone.f (interpE (subst e (ρ rs Θ))) k)
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))
(Monotone.f (interpS (ρ rs Θ)) k)
(interp-rs-l ρ Θ k))
(subst-eq-r (ρ rs Θ) e k)))
sound {Γ} {τ} ._ .(ren (subst e Θ) ρ) (subst-rs-r ρ Θ e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (ρ rs Θ))) k)
(Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k))
(Monotone.f (interpE (ren (subst e Θ) ρ)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (ρ rs Θ))) k)
(Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)))
(Monotone.f (interpE (subst e Θ)) (Monotone.f (interpR ρ) k))
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (ρ rs Θ))) k)
(Monotone.f (interpE e) (Monotone.f (interpS (ρ rs Θ)) k))
(Monotone.f (interpE e) (Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k)))
(subst-eq-l (ρ rs Θ) e k)
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (ρ rs Θ)) k)
(Monotone.f (interpS Θ) (Monotone.f (interpR ρ) k))
(interp-rs-r ρ Θ k)))
(subst-eq-r Θ e (Monotone.f (interpR ρ) k)))
(ren-eq-r ρ (subst e Θ) k)
sound {Γ} {τ} .(subst (ren e ρ) Θ) ._ (subst-sr-l Θ ρ e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (ren e ρ) Θ)) k)
(Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e (Θ sr ρ))) k)
(subst-eq-l Θ (ren e ρ) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k))
(Monotone.f (interpE (subst e (Θ sr ρ))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k)))
(Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k))
(ren-eq-l ρ e (Monotone.f (interpS Θ) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k))
(Monotone.f (interpS (Θ sr ρ)) k)
(interp-sr-l Θ ρ k)))
(subst-eq-r (Θ sr ρ) e k))
sound {Γ} {τ} ._ .(subst (ren e ρ) Θ) (subst-sr-r Θ ρ e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (Θ sr ρ))) k)
(Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst (ren e ρ) Θ)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (Θ sr ρ))) k)
(Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k))
(Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k))
(subst-eq-l (Θ sr ρ) e k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS (Θ sr ρ)) k))
(Monotone.f (interpE e) (Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k)))
(Monotone.f (interpE (ren e ρ)) (Monotone.f (interpS Θ) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (Θ sr ρ)) k)
(Monotone.f (interpR ρ) (Monotone.f (interpS Θ) k))
(interp-sr-r Θ ρ k))
(ren-eq-r ρ e (Monotone.f (interpS Θ) k))))
(subst-eq-r Θ (ren e ρ) k)
sound {Γ} {τ} ._ .(subst (subst e Θ2) Θ1) (subst-ss-l Θ1 Θ2 e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (Θ1 ss Θ2))) k)
(Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k))
(Monotone.f (interpE (subst (subst e Θ2) Θ1)) k)
(subst-eq-l (Θ1 ss Θ2) e k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k))
(Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k))
(Monotone.f (interpE (subst (subst e Θ2) Θ1)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k))
(Monotone.f (interpE e) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k)))
(Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (Θ1 ss Θ2)) k)
(Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k))
(interp-ss-l Θ1 Θ2 k))
(subst-eq-r Θ2 e (Monotone.f (interpS Θ1) k)))
(subst-eq-r Θ1 (subst e Θ2) k))
sound {Γ} {τ} .(subst (subst e Θ2) Θ1) ._ (subst-ss-r Θ1 Θ2 e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e Θ2) Θ1)) k)
(Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k))
(Monotone.f (interpE (subst e (Θ1 ss Θ2))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e Θ2) Θ1)) k)
(Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k))
(Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k))
(subst-eq-l Θ1 (subst e Θ2) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e Θ2)) (Monotone.f (interpS Θ1) k))
(Monotone.f (interpE e) (Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k)))
(Monotone.f (interpE e) (Monotone.f (interpS (Θ1 ss Θ2)) k))
(subst-eq-l Θ2 e (Monotone.f (interpS Θ1) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS Θ2) (Monotone.f (interpS Θ1) k))
(Monotone.f (interpS (Θ1 ss Θ2)) k)
(interp-ss-r Θ1 Θ2 k))))
(subst-eq-r (Θ1 ss Θ2) e k)
sound {Γ} {τ} ._ .(subst e (lem3' Θ v)) (subst-compose-l {.Γ} {Γ'} {τ'} Θ v e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e (s-extend Θ)) (q v))) k)
(Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k))
(Monotone.f (interpE (subst e (lem3' Θ v))) k)
(subst-eq-l (q v) (subst e (s-extend Θ)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k))
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k))
(Monotone.f (interpE (subst e (lem3' Θ v))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k))
(Monotone.f (interpE e) (Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k)))
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k))
(subst-eq-l (s-extend Θ) e (Monotone.f (interpS (q v)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k))
(Monotone.f (interpS (lem3' Θ v)) k)
(Preorder-str.trans (snd [ Γ' ]c)
(fst (Monotone.f (interpS (s-extend Θ)) (Monotone.f (interpS (q v)) k)))
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k)
(Monotone.f (interpS Θ) k)
(fst (interp-ss-r (q v) (s-extend Θ) k))
(interp-subst-comp-l Θ v k) ,
Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k))))
(subst-eq-r (lem3' Θ v) e k))
sound {Γ} {τ} .(subst e (lem3' Θ v)) ._ (subst-compose-r {.Γ} {Γ'} {τ'} Θ v e) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (lem3' Θ v))) k)
(Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k))
(Monotone.f (interpE (subst (subst e (s-extend Θ)) (q v))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (lem3' Θ v))) k)
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k))
(Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k))
(subst-eq-l (lem3' Θ v) e k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' Θ v)) k))
(Monotone.f (interpE e) (Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k)))
(Monotone.f (interpE (subst e (s-extend Θ))) (Monotone.f (interpS (q v)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (lem3' Θ v)) k)
(Monotone.f (interpS {τ' :: Γ} {τ' :: Γ'} (s-extend {Γ} {Γ'} Θ)) (Monotone.f (interpS {Γ} {τ' :: Γ} (q v)) k))
((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS Θ) k)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v))) k)
(fst (Monotone.f (interpS (s-extend Θ)) (Monotone.f (interpS (q v)) k)))
(interp-subst-comp-r Θ v k)
(fst (interp-ss-l (q v) (s-extend Θ) k))) ,
(Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v) k))))
(subst-eq-r (s-extend Θ) e (Monotone.f (interpS (q v)) k))))
(subst-eq-r (q v) (subst e (s-extend Θ)) k)
sound {Γ} {τ} ._ .(subst e1 (lem3' (lem3' Θ v2) v1)) (subst-compose2-l {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(subst-eq-l (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE e1) (Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(subst-eq-l (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpS (lem4' Θ v1 v2)) k)
((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k)
(Monotone.f (interpS Θ) k)
(interp-subst-comp2-l Θ k v1 v2)
(interp-subst-comp-l Θ v2 k) ,
Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k)) ,
Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v1) k))))
(subst-eq-r (lem4' Θ v1 v2) e1 k))
sound {Γ} {τ} .(subst e1 (lem3' (lem3' Θ v2) v1)) ._ (subst-compose2-r {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(subst-eq-l (lem4' Θ v1 v2) e1 k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(Monotone.f (interpE e1) (Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)))
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS (lem4' Θ v1 v2)) k)
(Monotone.f (interpS {τ' :: τ'' :: Γ} {τ' :: τ'' :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))
(((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS Θ) k)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k)
(Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(interp-subst-comp-r Θ v2 k)
(interp-subst-comp2-r Θ k v1 v2)) ,
(Preorder-str.refl (snd [ τ'' ]t) (Monotone.f (interpE v2) k))) ,
(Preorder-str.refl (snd [ τ' ]t) (Monotone.f (interpE v1) k))))
(subst-eq-r (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k))))
(subst-eq-r (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k)
sound {Γ} {τ} ._ .(subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) (subst-compose3-l {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e1 (lem3' (lem3' ids v2) v1)) Θ)) k)
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k)
(subst-eq-l Θ (subst e1 (lem3' (lem3' ids v2) v1)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k))
(Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k)))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k))
(subst-eq-l (lem3' (lem3' ids v2) v1) e1 (Monotone.f (interpS Θ) k))
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k))
(Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k)
(((interp-ss-r Θ ids k) ,
(subst-eq-r Θ v2 k)) ,
(subst-eq-r Θ v1 k))))
(subst-eq-r (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)) e1 k))
sound {Γ} {τ} .(subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) ._ (subst-compose3-r {.Γ} {Γ'} {.τ} {τ'} {τ''} Θ e1 v1 v2) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k)
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k))
(Monotone.f (interpE (subst (subst e1 (lem3' (lem3' ids v2) v1)) Θ)) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)))) k)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k))
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k))
(subst-eq-l (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ)) e1 k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k)))
(Monotone.f (interpE (subst e1 (lem3' (lem3' ids v2) v1))) (Monotone.f (interpS Θ) k))
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS (lem3' (lem3' Θ (subst v2 Θ)) (subst v1 Θ))) k)
(Monotone.f (interpS (lem3' (lem3' ids v2) v1)) (Monotone.f (interpS Θ) k))
(((interp-ss-l Θ ids k) ,
(subst-eq-l Θ v2 k)) ,
(subst-eq-l Θ v1 k)))
(subst-eq-r (lem3' (lem3' ids v2) v1) e1 (Monotone.f (interpS Θ) k))))
(subst-eq-r Θ (subst e1 (lem3' (lem3' ids v2) v1)) k)
sound {Γ} {τ} ._ .(subst e1 (lem3' (lem3' Θ v2) v1)) (subst-compose4-l {.Γ} {Γ'} Θ v1 v2 e1) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(subst-eq-l (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE e1) (Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)))
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(subst-eq-l (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpS (lem4' Θ v1 v2)) k)
((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k)
(Monotone.f (interpS Θ) k)
(interp-subst-comp2-l Θ k v1 v2)
(interp-subst-comp-l Θ v2 k) ,
Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE v2) k)) ,
Preorder-str.refl (snd [ nat ]t) (Monotone.f (interpE v1) k))))
(subst-eq-r (lem4' Θ v1 v2) e1 k))
sound {Γ} {τ} .(subst e1 (lem3' (lem3' Θ v2) v1)) ._ (subst-compose4-r {.Γ} {Γ'} Θ v1 v2 e1) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.f (interpE (subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e1 (lem4' Θ v1 v2))) k)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(subst-eq-l (lem4' Θ v1 v2) e1 k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e1) (Monotone.f (interpS (lem4' Θ v1 v2)) k))
(Monotone.f (interpE e1) (Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k)))
(Monotone.f (interpE (subst e1 (s-extend (s-extend Θ)))) (Monotone.f (interpS (lem4 v1 v2)) k))
(Monotone.is-monotone (interpE e1)
(Monotone.f (interpS (lem4' Θ v1 v2)) k)
(Monotone.f (interpS {nat :: τ :: Γ} {nat :: τ :: Γ'} (s-extend (s-extend Θ))) (Monotone.f (interpS (lem4 v1 v2)) k))
(((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS Θ) k)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v2))) k)
(Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(interp-subst-comp-r Θ v2 k)
(interp-subst-comp2-r Θ k v1 v2)) ,
(Preorder-str.refl (snd [ τ ]t) (Monotone.f (interpE v2) k))) ,
(Preorder-str.refl (snd [ nat ]t) (Monotone.f (interpE v1) k))))
(subst-eq-r (s-extend (s-extend Θ)) e1 (Monotone.f (interpS (lem4 v1 v2)) k))))
(subst-eq-r (lem4 v1 v2) (subst e1 (s-extend (s-extend Θ))) k)
sound {Γ} {τ} ._ .(subst e (lem3' (lem3' (lem3' Θ v3) v2) v1)) (subst-compose5-l {.Γ} {Γ'} {.τ} {τ1} {τ2} {τ3} Θ e v1 v2 v3) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst (subst e (s-extend (s-extend (s-extend Θ)))) (lem3' (lem3' (lem3' ids v3) v2) v1))) k)
(Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k)
(subst-eq-l (lem3' (lem3' (lem3' ids v3) v2) v1) (subst e (s-extend (s-extend (s-extend Θ)))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k))
(Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.f (interpE e) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ))))
(Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k)))
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k))
(subst-eq-l (s-extend (s-extend (s-extend Θ))) e (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ))))
(Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k)
((((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k ,
Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k)
(Monotone.f (interpS Θ) k)
(Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS)) (((Monotone.f (interpS {Γ} ids) k ,
Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k)
(interp-subst-comp3-l Θ k v3 v2 v1)
(interp-subst-comp2-l Θ k v2 v3))
(interp-subst-comp-l Θ v3 k)) ,
(Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k))) ,
(Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k))) ,
(Preorder-str.refl (snd [ τ1 ]t) (Monotone.f (interpE v1) k)))))
(subst-eq-r (lem3' (lem3' (lem3' Θ v3) v2) v1) e k))
sound {Γ} {τ} .(subst e (lem3' (lem3' (lem3' Θ v3) v2) v1)) ._ (subst-compose5-r {.Γ} {Γ'} {.τ} {τ1} {τ2} {τ3} Θ e v1 v2 v3) k =
Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k)
(Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.f (interpE (subst (subst e (s-extend (s-extend (s-extend Θ)))) (lem3' (lem3' (lem3' ids v3) v2) v1))) k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE (subst e (lem3' (lem3' (lem3' Θ v3) v2) v1))) k)
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k))
(Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(subst-eq-l (lem3' (lem3' (lem3' Θ v3) v2) v1) e k)
(Preorder-str.trans (snd [ τ ]t)
(Monotone.f (interpE e) (Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k))
(Monotone.f (interpE e) (Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ))))
(Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k)))
(Monotone.f (interpE (subst e (s-extend (s-extend (s-extend Θ))))) (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
(Monotone.is-monotone (interpE e)
(Monotone.f (interpS (lem3' (lem3' (lem3' Θ v3) v2) v1)) k)
(Monotone.f (interpS {τ1 :: τ2 :: τ3 :: Γ} {τ1 :: τ2 :: τ3 :: Γ'} (s-extend (s-extend (s-extend Θ))))
(Monotone.f (interpS {Γ} {τ1 :: τ2 :: τ3 :: Γ} (lem3' (lem3' (lem3' ids v3) v2) v1)) k))
((((Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS Θ) k)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k)
(Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(interp-subst-comp-r Θ v3 k)
(Preorder-str.trans (snd [ Γ' ]c)
(Monotone.f (interpS (λ x → subst (ren (Θ x) iS) (lem3' ids v3))) k)
(Monotone.f (interpS (λ x → ren (ren (Θ x) iS) iS)) ((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k))
(Monotone.f (interpS (λ x → ren (ren (ren (Θ x) iS) iS) iS))
(((Monotone.f (interpS {Γ} ids) k , Monotone.f (interpE v3) k) , Monotone.f (interpE v2) k) , Monotone.f (interpE v1) k))
(interp-subst-comp2-r Θ k v2 v3)
(interp-subst-comp3-r Θ k v3 v2 v1))) ,
(Preorder-str.refl (snd [ τ3 ]t) (Monotone.f (interpE v3) k))) ,
(Preorder-str.refl (snd [ τ2 ]t) (Monotone.f (interpE v2) k))) ,
(Preorder-str.refl (snd [ τ1 ]t) (Monotone.f (interpE v1) k))))
(subst-eq-r (s-extend (s-extend (s-extend Θ))) e (Monotone.f (interpS (lem3' (lem3' (lem3' ids v3) v2) v1)) k))))
(subst-eq-r (lem3' (lem3' (lem3' ids v3) v2) v1) (subst e (s-extend (s-extend (s-extend Θ)))) k)
| 66.645628 | 172 | 0.510187 |
2377d1eb8d548ba65cd0f1e56248495f0bdf286a | 3,995 | agda | Agda | src/Implicits/Resolution/GenericFinite/Algorithm.agda | metaborg/ts.agda | 7fe638b87de26df47b6437f5ab0a8b955384958d | [
"MIT"
] | 4 | 2019-04-05T17:57:11.000Z | 2021-05-07T04:08:41.000Z | src/Implicits/Resolution/GenericFinite/Algorithm.agda | metaborg/ts.agda | 7fe638b87de26df47b6437f5ab0a8b955384958d | [
"MIT"
] | null | null | null | src/Implicits/Resolution/GenericFinite/Algorithm.agda | metaborg/ts.agda | 7fe638b87de26df47b6437f5ab0a8b955384958d | [
"MIT"
] | null | null | null | open import Prelude renaming (_<_ to _N<_)
module Implicits.Resolution.GenericFinite.Algorithm where
open import Induction.WellFounded
open import Induction.Nat
open import Data.Vec
open import Data.List
open import Data.Fin.Substitution
open import Data.Nat.Base using (_<′_)
open import Data.Maybe
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
open import Relation.Binary using (module DecTotalOrder)
open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans)
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Implicits.Resolution.GenericFinite.Resolution
open import Implicits.Resolution.GenericFinite.TerminationCondition
open import Implicits.Resolution.Termination
private
module M = MetaTypeMetaSubst
module Lemmas where
m<-Acc : ∀ {m ν} → MetaType m ν → Set
m<-Acc {m} {ν} r = Acc _m<_ (m , ν , r)
ρ<-Acc : ∀ {ν} → Type ν → Set
ρ<-Acc {ν} r = Acc _ρ<_ (ν , r)
module Arg<-well-founded where
open Lexicographic (_N<_) (const _ρ<_)
open import Induction.Nat
open import Data.Nat.Properties
module image = Subrelation {A = ℕ} {_N<_} {_<′_} ≤⇒≤′
arg<-well-founded : Well-founded _<_
arg<-well-founded = well-founded (image.well-founded <-well-founded) ρ<-well-founded
_arg<_ = _<_
-- Accessibility of the 'goal' type during resolution.
-- Either the *head* of the goal shrinks (Oliveira's termination condition)
-- Or the head size remains equal and the goal shrinks in an absolute sense.
Arg<-Acc : ∀ {ν} → Type ν → Set
Arg<-Acc a = Acc _arg<_ (h|| a || , (, a))
open Arg<-well-founded using (Arg<-Acc; arg<-well-founded) public
open Lemmas
module ResolutionAlgorithm (cond : TerminationCondition) where
open TerminationCondition cond
open ResolutionRules cond
mutual
match' : ∀ {m ν} (Δ : ICtx ν) (Φ : TCtx) τ → (r : MetaType m ν) →
T-Acc Φ →
m<-Acc r →
Maybe (Sub (flip MetaType ν) m zero)
match' Δ Φ τ (simpl x) f g = mgu (simpl x) τ
match' Δ Φ τ (a ⇒ b) f (acc g) with match' Δ Φ τ b f (g _ (b-m<-a⇒b a b))
match' Δ Φ τ (a ⇒ b) f (acc g) | nothing = nothing
match' Δ Φ τ (a ⇒ b) f (acc g) | just u
with (step Φ Δ (from-meta (a M./ u)) (from-meta (b M./ u)) τ) <? Φ
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | yes Φ<
with resolve' Δ (step Φ Δ (from-meta (a M./ u)) (from-meta (b M./ u)) τ)
(from-meta (a M./ u)) (f _ Φ<)
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | yes Φ< | true = just u
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | yes Φ< | false = nothing
match' Δ Φ τ (a ⇒ b) (acc f) (acc g) | just u | no φ> = nothing
match' Δ Φ τ (∀' a) f (acc g) with match' Δ Φ τ (open-meta a) f (g _ (open-meta-a-m<-∀'a a))
match' Δ Φ τ (∀' a) f (acc g) | just p = just (tail p)
match' Δ Φ τ (∀' r) f (acc g) | nothing = nothing
-- match defers to match', which concerns itself with MetaTypes.
-- If match' finds a match, we can use the fact that we have zero unification variables open here
-- to show that we found the right thing.
match : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) τ r → T-Acc Φ → Bool
match Δ Φ τ a f = is-just (match' Δ Φ τ (to-meta {zero} a) f (m<-well-founded _))
match1st : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) (ρs : ICtx ν) → (τ : SimpleType ν) → T-Acc Φ → Bool
match1st Δ Φ [] τ Φ↓ = false
match1st Δ Φ (x ∷ xs) τ Φ↓ with match Δ Φ τ x Φ↓
match1st Δ Φ (x ∷ xs) τ Φ↓ | true = true
match1st Δ Φ (x ∷ xs) τ Φ↓ | false = match1st Δ Φ xs τ Φ↓
resolve' : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) r → T-Acc Φ → Bool
resolve' Δ Φ (simpl x) Φ↓ = match1st Δ Φ Δ x Φ↓
resolve' Δ Φ (a ⇒ b) Φ↓ = resolve' (a ∷ Δ) Φ b Φ↓
resolve' Δ Φ (∀' r) Φ↓ = resolve' (ictx-weaken Δ) Φ r Φ↓
resolve : ∀ {ν} (Δ : ICtx ν) (Φ : TCtx) r → Bool
resolve Δ Φ r = resolve' Δ Φ r (wf-< Φ)
| 38.786408 | 101 | 0.614268 |
cbfd8af310ac7adbb38daa45aa5038b64fa18b41 | 246 | agda | Agda | Inductive/Examples/Unit.agda | mr-ohman/general-induction | dc157acda597a2c758e82b5637e4fd6717ccec3f | [
"MIT"
] | null | null | null | Inductive/Examples/Unit.agda | mr-ohman/general-induction | dc157acda597a2c758e82b5637e4fd6717ccec3f | [
"MIT"
] | null | null | null | Inductive/Examples/Unit.agda | mr-ohman/general-induction | dc157acda597a2c758e82b5637e4fd6717ccec3f | [
"MIT"
] | null | null | null | module Inductive.Examples.Unit where
open import Inductive
open import Tuple
open import Data.Fin
open import Data.Product
open import Data.List
open import Data.Vec
⊤ : Set
⊤ = Inductive (([] , []) ∷ [])
unit : ⊤
unit = construct zero [] []
| 15.375 | 36 | 0.699187 |
4a1572d181db3826c806c2a2ad2ad68df8aca789 | 444 | agda | Agda | test/Fail/Issue1209-4.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/Issue1209-4.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/Issue1209-4.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | {-# OPTIONS --safe --no-sized-types #-}
open import Agda.Builtin.Size
record Stream (A : Set) (i : Size) : Set where
coinductive
field
head : A
tail : {j : Size< i} → Stream A j
open Stream
destroy-guardedness : ∀ {A i} → Stream A i → Stream A i
destroy-guardedness xs .head = xs .head
destroy-guardedness xs .tail = xs .tail
repeat : ∀ {A i} → A → Stream A i
repeat x .head = x
repeat x .tail = destroy-guardedness (repeat x)
| 22.2 | 55 | 0.646396 |
cb42725ccb89e4e1ee0f6e590e1610bcc6f8d9bb | 1,121 | agda | Agda | src/fot/LTC-PCF/Base/Properties.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 11 | 2015-09-03T20:53:42.000Z | 2021-09-12T16:09:54.000Z | src/fot/LTC-PCF/Base/Properties.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 2 | 2016-10-12T17:28:16.000Z | 2017-01-01T14:34:26.000Z | src/fot/LTC-PCF/Base/Properties.agda | asr/fotc | 2fc9f2b81052a2e0822669f02036c5750371b72d | [
"MIT"
] | 3 | 2016-09-19T14:18:30.000Z | 2018-03-14T08:50:00.000Z | ------------------------------------------------------------------------------
-- LTC-PCF terms properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Base.Properties where
open import LTC-PCF.Base
------------------------------------------------------------------------------
-- Congruence properties
·-leftCong : ∀ {m n o} → m ≡ n → m · o ≡ n · o
·-leftCong refl = refl
·-rightCong : ∀ {m n o} → n ≡ o → m · n ≡ m · o
·-rightCong refl = refl
succCong : ∀ {m n} → m ≡ n → succ₁ m ≡ succ₁ n
succCong refl = refl
predCong : ∀ {m n} → m ≡ n → pred₁ m ≡ pred₁ n
predCong refl = refl
------------------------------------------------------------------------------
S≢0 : ∀ {n} → succ₁ n ≢ zero
S≢0 S≡0 = 0≢S (sym S≡0)
-- We added Common.Relation.Binary.PropositionalEquality.cong, so this
-- theorem is not necessary.
-- x≡y→Sx≡Sy : ∀ {m n} → m ≡ n → succ₁ m ≡
-- succ₁ n x≡y→Sx≡Sy refl = refl
| 29.5 | 78 | 0.409456 |
1027768d379b3561dbba2677335e95106e5f7b27 | 4,792 | agda | Agda | agda/BBHeap/Insert.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | 6 | 2015-05-21T12:50:35.000Z | 2021-08-24T22:11:15.000Z | agda/BBHeap/Insert.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | agda/BBHeap/Insert.agda | bgbianchi/sorting | b8d428bccbdd1b13613e8f6ead6c81a8f9298399 | [
"MIT"
] | null | null | null | open import Relation.Binary.Core
module BBHeap.Insert {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_
open import BBHeap.Properties _≤_
open import BBHeap.Subtyping.Properties _≤_ trans≤
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Bound.Lower.Order.Properties _≤_ trans≤
open import Data.Sum renaming (_⊎_ to _∨_)
open import Order.Total _≤_ tot≤
mutual
insert : {b : Bound}{x : A} → LeB b (val x) → BBHeap b → BBHeap b
insert b≤x leaf = left b≤x lf⋘
insert {x = x} b≤x (left {x = y} b≤y l⋘r)
with tot≤ x y
... | inj₁ x≤y
with lemma-insert⋘ (lexy refl≤) l⋘r
... | inj₁ lᵢ⋘r = left b≤x (subtyping⋘ (lexy x≤y) (lexy x≤y) lᵢ⋘r)
... | inj₂ lᵢ⋗r = right b≤x (subtyping⋙ (lexy x≤y) (lexy x≤y) (lemma⋗ lᵢ⋗r))
insert {x = x} b≤x (left {x = y} b≤y l⋘r) | inj₂ y≤x
with lemma-insert⋘ (lexy y≤x) l⋘r
... | inj₁ lᵢ⋘r = left b≤y lᵢ⋘r
... | inj₂ lᵢ⋗r = right b≤y (lemma⋗ lᵢ⋗r)
insert {x = x} b≤x (right {x = y} b≤y l⋙r)
with tot≤ x y
... | inj₁ x≤y
with lemma-insert⋙ (lexy refl≤) l⋙r
... | inj₁ l⋙rᵢ = right b≤x (subtyping⋙ (lexy x≤y) (lexy x≤y) l⋙rᵢ)
... | inj₂ l≃rᵢ = left b≤x (subtyping⋘ (lexy x≤y) (lexy x≤y) (lemma≃ l≃rᵢ))
insert {x = x} b≤x (right {x = y} b≤y l⋙r) | inj₂ y≤x
with lemma-insert⋙ (lexy y≤x) l⋙r
... | inj₁ l⋙rᵢ = right b≤y l⋙rᵢ
... | inj₂ l≃rᵢ = left b≤y (lemma≃ l≃rᵢ)
lemma-insert⋘ : {b b' : Bound}{x : A}{h : BBHeap b}{h' : BBHeap b'} → (b≤x : LeB b (val x)) → h ⋘ h' → insert b≤x h ⋘ h' ∨ insert b≤x h ⋗ h'
lemma-insert⋘ b≤x lf⋘ = inj₂ (⋗lf b≤x)
lemma-insert⋘ {x = x} b≤x (ll⋘ {x = y} b≤y b'≤y' l⋘r l'⋘r' l'≃r' r≃l')
with tot≤ x y
... | inj₁ x≤y
with lemma-insert⋘ (lexy refl≤) l⋘r
... | inj₁ lᵢ⋘r = inj₁ (ll⋘ b≤x b'≤y' (subtyping⋘ (lexy x≤y) (lexy x≤y) lᵢ⋘r) l'⋘r' l'≃r' (subtyping≃l (lexy x≤y) r≃l'))
... | inj₂ lᵢ⋗r = inj₁ (lr⋘ b≤x b'≤y' (subtyping⋙ (lexy x≤y) (lexy x≤y) (lemma⋗ lᵢ⋗r)) l'⋘r' l'≃r' (subtyping⋗l (lexy x≤y) (lemma⋗≃ lᵢ⋗r r≃l')))
lemma-insert⋘ {x = x} b≤x (ll⋘ {x = y} b≤y b'≤y' l⋘r l'⋘r' l'≃r' r≃l') | inj₂ y≤x
with lemma-insert⋘ (lexy y≤x) l⋘r
... | inj₁ lᵢ⋘r = inj₁ (ll⋘ b≤y b'≤y' lᵢ⋘r l'⋘r' l'≃r' r≃l')
... | inj₂ lᵢ⋗r = inj₁ (lr⋘ b≤y b'≤y' (lemma⋗ lᵢ⋗r) l'⋘r' l'≃r' (lemma⋗≃ lᵢ⋗r r≃l'))
lemma-insert⋘ {x = x} b≤x (lr⋘ {x = y} b≤y b'≤y' l⋙r l'⋘r' l'≃r' l⋗l')
with tot≤ x y
... | inj₁ x≤y
with lemma-insert⋙ (lexy refl≤) l⋙r
... | inj₁ l⋙rᵢ = inj₁ (lr⋘ b≤x b'≤y' (subtyping⋙ (lexy x≤y) (lexy x≤y) l⋙rᵢ) l'⋘r' l'≃r' (subtyping⋗l (lexy x≤y) l⋗l'))
... | inj₂ l≃rᵢ = inj₂ (⋗nd b≤x b'≤y' (subtyping⋘ (lexy x≤y) (lexy x≤y) (lemma≃ l≃rᵢ)) l'⋘r' (subtyping≃ (lexy x≤y) (lexy x≤y) l≃rᵢ) l'≃r' (subtyping⋗l (lexy x≤y) l⋗l'))
lemma-insert⋘ {x = x} b≤x (lr⋘ {x = y} b≤y b'≤y' l⋙r l'⋘r' l'≃r' l⋗l') | inj₂ y≤x
with lemma-insert⋙ (lexy y≤x) l⋙r
... | inj₁ l⋙rᵢ = inj₁ (lr⋘ b≤y b'≤y' l⋙rᵢ l'⋘r' l'≃r' l⋗l')
... | inj₂ l≃rᵢ = inj₂ (⋗nd b≤y b'≤y' (lemma≃ l≃rᵢ) l'⋘r' l≃rᵢ l'≃r' l⋗l')
lemma-insert⋙ : {b b' : Bound}{x : A}{h : BBHeap b}{h' : BBHeap b'} → (b'≤x : LeB b' (val x)) → h ⋙ h' → h ⋙ insert b'≤x h' ∨ h ≃ insert b'≤x h'
lemma-insert⋙ {x = x} b'≤x (⋙lf {x = y} b≤y) = inj₂ (≃nd b≤y b'≤x lf⋘ lf⋘ ≃lf ≃lf ≃lf)
lemma-insert⋙ {x = x} b'≤x (⋙rl {x' = y'} b≤y b'≤y' l⋘r l≃r l'⋘r' l⋗r')
with tot≤ x y'
... | inj₁ x≤y'
with lemma-insert⋘ (lexy refl≤) l'⋘r'
... | inj₁ l'ᵢ⋘r' = inj₁ (⋙rl b≤y b'≤x l⋘r l≃r (subtyping⋘ (lexy x≤y') (lexy x≤y') l'ᵢ⋘r') (subtyping⋗r (lexy x≤y') l⋗r'))
... | inj₂ l'ᵢ⋗r' = inj₁ (⋙rr b≤y b'≤x l⋘r l≃r (subtyping⋙ (lexy x≤y') (lexy x≤y') (lemma⋗ l'ᵢ⋗r')) (subtyping≃r (lexy x≤y') (lemma⋗⋗ l⋗r' l'ᵢ⋗r')))
lemma-insert⋙ {x = x} b'≤x (⋙rl {x' = y'} b≤y b'≤y' l⋘r l≃r l'⋘r' l⋗r') | inj₂ y'≤x
with lemma-insert⋘ (lexy y'≤x) l'⋘r'
... | inj₁ l'ᵢ⋘r' = inj₁ (⋙rl b≤y b'≤y' l⋘r l≃r l'ᵢ⋘r' l⋗r')
... | inj₂ l'ᵢ⋗r' = inj₁ (⋙rr b≤y b'≤y' l⋘r l≃r (lemma⋗ l'ᵢ⋗r') (lemma⋗⋗ l⋗r' l'ᵢ⋗r'))
lemma-insert⋙ {x = x} b'≤x (⋙rr {x' = y'} b≤y b'≤y' l⋘r l≃r l'⋙r' l≃l')
with tot≤ x y'
... | inj₁ x≤y'
with lemma-insert⋙ (lexy refl≤) l'⋙r'
... | inj₁ l'⋙r'ᵢ = inj₁ (⋙rr b≤y b'≤x l⋘r l≃r (subtyping⋙ (lexy x≤y') (lexy x≤y') l'⋙r'ᵢ) (subtyping≃r (lexy x≤y') l≃l'))
... | inj₂ l'≃r'ᵢ = inj₂ (≃nd b≤y b'≤x l⋘r (subtyping⋘ (lexy x≤y') (lexy x≤y') (lemma≃ l'≃r'ᵢ)) l≃r (subtyping≃ (lexy x≤y') (lexy x≤y') l'≃r'ᵢ) (subtyping≃r (lexy x≤y') l≃l'))
lemma-insert⋙ {x = x} b'≤x (⋙rr {x' = y'} b≤y b'≤y' l⋘r l≃r l'⋙r' l≃l') | inj₂ y'≤x
with lemma-insert⋙ (lexy y'≤x) l'⋙r'
... | inj₁ l'⋙r'ᵢ = inj₁ (⋙rr b≤y b'≤y' l⋘r l≃r l'⋙r'ᵢ l≃l')
... | inj₂ l'≃r'ᵢ = inj₂ (≃nd b≤y b'≤y' l⋘r (lemma≃ l'≃r'ᵢ) l≃r l'≃r'ᵢ l≃l')
| 55.72093 | 177 | 0.501461 |
2042b2c14737b7d571ace0e3f5c55332746b30f7 | 1,692 | agda | Agda | archive/agda-3/src/Oscar/Class/Surjidentity.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | archive/agda-3/src/Oscar/Class/Surjidentity.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | 1 | 2019-04-29T00:35:04.000Z | 2019-05-11T23:33:04.000Z | archive/agda-3/src/Oscar/Class/Surjidentity.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Surjection
open import Oscar.Class.Smap
open import Oscar.Class.Reflexivity
open import Oscar.Data.Proposequality
module Oscar.Class.Surjidentity where
module _
{𝔬₁ 𝔯₁ 𝔬₂ 𝔯₂ ℓ₂}
{𝔒₁ : Ø 𝔬₁}
{𝔒₂ : Ø 𝔬₂}
where
module Surjidentity
{μ : Surjection.type 𝔒₁ 𝔒₂}
(_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
(_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(§ : Smap.type _∼₁_ _∼₂_ μ μ)
(ε₁ : Reflexivity.type _∼₁_)
(ε₂ : Reflexivity.type _∼₂_)
= ℭLASS ((λ {x} {y} → § {x} {y}) , (λ {x} → ε₁ {x}) , (λ {x y} → _∼̇₂_ {x} {y}) , (λ {x} → ε₂ {x})) (∀ {x} → § (ε₁ {x}) ∼̇₂ ε₂)
module _
{μ : Surjection.type 𝔒₁ 𝔒₂}
{_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁}
{_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂}
{_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂}
{§ : Smap.type _∼₁_ _∼₂_ μ μ}
{ε₁ : Reflexivity.type _∼₁_}
{ε₂ : Reflexivity.type _∼₂_}
where
surjidentity = Surjidentity.method _∼₁_ _∼₂_ _∼̇₂_ (λ {x} {y} → § {x} {y}) (λ {x} → ε₁ {x}) (λ {x} → ε₂ {x})
module Surjidentity!
(∼₁ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
(∼₂ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(∼̇₂ : ∀ {x y} → ∼₂ x y → ∼₂ x y → Ø ℓ₂)
⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄
⦃ _ : Smap!.class ∼₁ ∼₂ ⦄
⦃ _ : Reflexivity.class ∼₁ ⦄
⦃ _ : Reflexivity.class ∼₂ ⦄
= Surjidentity {surjection} ∼₁ ∼₂ ∼̇₂ § ε ε
module _
(_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂}
(_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄
⦃ _ : Smap!.class _∼₁_ _∼₂_ ⦄
⦃ _ : Reflexivity.class _∼₁_ ⦄
⦃ _ : Reflexivity.class _∼₂_ ⦄
where
surjidentity[_,_] = Surjidentity.method {surjection} _∼₁_ _∼₂_ _∼̇₂_ § ε ε
| 31.333333 | 131 | 0.518913 |
4aad91ece69147364b6845da78b574b39ebf2330 | 947 | agda | Agda | Lists/Concat.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 4 | 2019-08-08T12:44:19.000Z | 2022-01-28T06:04:15.000Z | Lists/Concat.agda | Smaug123/agdaproofs | 0f4230011039092f58f673abcad8fb0652e6b562 | [
"MIT"
] | 14 | 2019-01-06T21:11:59.000Z | 2020-04-11T11:03:39.000Z | Lists/Concat.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 LogicalFormulae
open import Lists.Definition
open import Lists.Length
open import Numbers.Naturals.Semiring
module Lists.Concat where
appendEmptyList : {a : _} → {A : Set a} → (l : List A) → (l ++ [] ≡ l)
appendEmptyList [] = refl
appendEmptyList (x :: l) = applyEquality (_::_ x) (appendEmptyList l)
concatAssoc : {a : _} → {A : Set a} → (x : List A) → (y : List A) → (z : List A) → ((x ++ y) ++ z) ≡ x ++ (y ++ z)
concatAssoc [] m n = refl
concatAssoc (x :: l) m n = applyEquality (_::_ x) (concatAssoc l m n)
canMovePrepend : {a : _} → {A : Set a} → (l : A) → (x : List A) (y : List A) → ((l :: x) ++ y ≡ l :: (x ++ y))
canMovePrepend l [] n = refl
canMovePrepend l (x :: m) n = refl
lengthConcat : {a : _} {A : Set a} (l1 l2 : List A) → length (l1 ++ l2) ≡ length l1 +N length l2
lengthConcat [] l2 = refl
lengthConcat (x :: l1) l2 = applyEquality succ (lengthConcat l1 l2)
| 37.88 | 114 | 0.596621 |
39c25590e7a8d0f7797cc77b259e18d825464ec3 | 11,197 | agda | Agda | theorems/homotopy/VanKampen.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | null | null | null | theorems/homotopy/VanKampen.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | null | null | null | theorems/homotopy/VanKampen.agda | mikeshulman/HoTT-Agda | e7d663b63d89f380ab772ecb8d51c38c26952dbb | [
"MIT"
] | 1 | 2018-12-26T21:31:57.000Z | 2018-12-26T21:31:57.000Z | {-# OPTIONS --without-K --rewriting #-}
open import HoTT
import homotopy.RelativelyConstantToSetExtendsViaSurjection as SurjExt
module homotopy.VanKampen {i j k l}
(span : Span {i} {j} {k})
{D : Type l} (h : D → Span.C span) (h-is-surj : is-surj h) where
open Span span
open import homotopy.vankampen.CodeAP span h h-is-surj
open import homotopy.vankampen.CodeBP span h h-is-surj
open import homotopy.vankampen.Code span h h-is-surj
-- favonia: [pPP] means path from [P] to [P].
encode-idp : ∀ p → code p p
encode-idp = Pushout-elim {P = λ p → code p p}
(λ a → q[ ⟧a idp₀ ]) (λ b → q[ ⟧b idp₀ ]) lemma where
abstract
lemma : ∀ c → q[ ⟧a idp₀ ] == q[ ⟧b idp₀ ] [ (λ p → code p p) ↓ glue c ]
lemma = SurjExt.ext
(λ c → ↓-preserves-set SetQuot-is-set)
h h-is-surj
(λ d → from-transp (λ p → code p p) (glue (h d)) $
transport (λ p → code p p) (glue (h d)) q[ ⟧a idp₀ ]
=⟨ ap (λ pPP → coe pPP q[ pc-a idp₀ ]) ((! (ap2-diag code (glue (h d)))) ∙ ap2-out code (glue (h d)) (glue (h d))) ⟩
coe (ap (λ p₀ → code p₀ (left (f (h d)))) (glue (h d)) ∙ ap (codeBP (g (h d))) (glue (h d))) q[ ⟧a idp₀ ]
=⟨ coe-∙ (ap (λ p₀ → code p₀ (left (f (h d)))) (glue (h d))) (ap (codeBP (g (h d))) (glue (h d))) q[ pc-a idp₀ ] ⟩
transport (codeBP (g (h d))) (glue (h d)) (transport (λ p₀ → code p₀ (left (f (h d)))) (glue (h d)) q[ ⟧a idp₀ ])
=⟨ transp-cPA-glue d (⟧a idp₀) |in-ctx transport (λ p₁ → code (right (g (h d))) p₁) (glue (h d)) ⟩
transport (codeBP (g (h d))) (glue (h d)) q[ ⟧b idp₀ bb⟦ d ⟧a idp₀ ]
=⟨ transp-cBP-glue d (⟧b idp₀ bb⟦ d ⟧a idp₀) ⟩
q[ ⟧b idp₀ bb⟦ d ⟧a idp₀ ba⟦ d ⟧b idp₀ ]
=⟨ quot-rel (pcBBr-idp₀-idp₀ (pc-b idp₀)) ⟩
q[ ⟧b idp₀ ]
=∎)
(λ _ _ _ → prop-has-all-paths-↓ $ ↓-level SetQuot-is-set)
encode : ∀ {p₀ p₁} → p₀ =₀ p₁ → code p₀ p₁
encode {p₀} {p₁} pPP = transport₀ (code p₀) (code-is-set {p₀} {p₁}) pPP (encode-idp p₀)
abstract
decode-encode-idp : ∀ p → decode {p} {p} (encode-idp p) == idp₀
decode-encode-idp = Pushout-elim
{P = λ p → decode {p} {p} (encode-idp p) == idp₀}
(λ _ → idp) (λ _ → idp)
(λ c → prop-has-all-paths-↓ (Trunc-level {n = 0} idp₀ (idp₀ :> Trunc 0 (right (g c) == _))))
decode-encode' : ∀ {p₀ p₁} (pPP : p₀ == p₁) → decode {p₀} {p₁} (encode [ pPP ]) == [ pPP ]
decode-encode' idp = decode-encode-idp _
decode-encode : ∀ {p₀ p₁} (pPP : p₀ =₀ p₁) → decode {p₀} {p₁} (encode pPP) == pPP
decode-encode = Trunc-elim (λ _ → =-preserves-set Trunc-level) decode-encode'
abstract
transp-idcAA-r : ∀ {a₀ a₁} (p : a₀ == a₁) -- [idc] = identity code
→ transport (codeAA a₀) p q[ ⟧a idp₀ ] == q[ ⟧a [ p ] ]
transp-idcAA-r idp = idp
encode-decodeAA : ∀ {a₀ a₁} (c : precodeAA a₀ a₁)
→ encode (decodeAA q[ c ]) == q[ c ]
encode-decodeAB : ∀ {a₀ b₁} (c : precodeAB a₀ b₁)
→ encode (decodeAB q[ c ]) == q[ c ]
encode-decodeAA {a₀} (pc-a pA) = Trunc-elim
{P = λ pA → encode (decodeAA q[ ⟧a pA ]) == q[ ⟧a pA ]}
(λ _ → =-preserves-set SetQuot-is-set)
(λ pA →
transport (codeAP a₀) (ap left pA) q[ ⟧a idp₀ ]
=⟨ ap (λ e → coe e q[ ⟧a idp₀ ]) (∘-ap (codeAP a₀) left pA) ⟩
transport (codeAA a₀) pA q[ ⟧a idp₀ ]
=⟨ transp-idcAA-r pA ⟩
q[ ⟧a [ pA ] ]
=∎)
pA
encode-decodeAA {a₀} (pc-aba d pc pA) = Trunc-elim
{P = λ pA → encode (decodeAA q[ pc ab⟦ d ⟧a pA ]) == q[ pc ab⟦ d ⟧a pA ]}
(λ _ → =-preserves-set SetQuot-is-set)
(λ pA →
encode (decodeAB q[ pc ] ∙₀' [ ! (glue (h d)) ∙' ap left pA ])
=⟨ transp₀-∙₀' (λ p₁ → code-is-set {left a₀} {p₁}) (decodeAB q[ pc ]) [ ! (glue (h d)) ∙' ap left pA ] (encode-idp (left a₀)) ⟩
transport (codeAP a₀) (! (glue (h d)) ∙' ap left pA) (encode (decodeAB q[ pc ]))
=⟨ ap (transport (codeAP a₀) (! (glue (h d)) ∙' ap left pA)) (encode-decodeAB pc) ⟩
transport (codeAP a₀) (! (glue (h d)) ∙' ap left pA) q[ pc ]
=⟨ transp-∙' {B = codeAP a₀} (! (glue (h d))) (ap left pA) q[ pc ] ⟩
transport (codeAP a₀) (ap left pA) (transport (codeAP a₀) (! (glue (h d))) q[ pc ])
=⟨ ap (transport (codeAP a₀) (ap left pA)) (transp-cAP-!glue d pc) ⟩
transport (codeAP a₀) (ap left pA) q[ pc ab⟦ d ⟧a idp₀ ]
=⟨ ap (λ e → coe e q[ pc ab⟦ d ⟧a idp₀ ]) (∘-ap (codeAP a₀) left pA) ⟩
transport (codeAA a₀) pA q[ pc ab⟦ d ⟧a idp₀ ]
=⟨ transp-cAA-r d pA (pc ab⟦ d ⟧a idp₀) ⟩
q[ pc ab⟦ d ⟧a idp₀ aa⟦ d ⟧b idp₀ ab⟦ d ⟧a [ pA ] ]
=⟨ quot-rel (pcAAr-cong (pcABr-idp₀-idp₀ pc) [ pA ]) ⟩
q[ pc ab⟦ d ⟧a [ pA ] ]
=∎)
pA
encode-decodeAB {a₀} (pc-aab d pc pB) = Trunc-elim
{P = λ pB → encode (decodeAB q[ pc aa⟦ d ⟧b pB ]) == q[ pc aa⟦ d ⟧b pB ]}
(λ _ → =-preserves-set SetQuot-is-set)
(λ pB →
encode (decodeAA q[ pc ] ∙₀' [ glue (h d) ∙' ap right pB ])
=⟨ transp₀-∙₀' (λ p₁ → code-is-set {left a₀} {p₁}) (decodeAA q[ pc ]) [ glue (h d) ∙' ap right pB ] (encode-idp (left a₀)) ⟩
transport (codeAP a₀) (glue (h d) ∙' ap right pB) (encode (decodeAA q[ pc ]))
=⟨ ap (transport (codeAP a₀) (glue (h d) ∙' ap right pB)) (encode-decodeAA pc) ⟩
transport (codeAP a₀) (glue (h d) ∙' ap right pB) q[ pc ]
=⟨ transp-∙' {B = codeAP a₀} (glue (h d)) (ap right pB) q[ pc ] ⟩
transport (codeAP a₀) (ap right pB) (transport (codeAP a₀) (glue (h d)) q[ pc ])
=⟨ ap (transport (codeAP a₀) (ap right pB)) (transp-cAP-glue d pc) ⟩
transport (codeAP a₀) (ap right pB) q[ pc aa⟦ d ⟧b idp₀ ]
=⟨ ap (λ e → coe e q[ pc aa⟦ d ⟧b idp₀ ]) (∘-ap (codeAP a₀) right pB) ⟩
transport (codeAB a₀) pB q[ pc aa⟦ d ⟧b idp₀ ]
=⟨ transp-cAB-r d pB (pc aa⟦ d ⟧b idp₀) ⟩
q[ pc aa⟦ d ⟧b idp₀ ab⟦ d ⟧a idp₀ aa⟦ d ⟧b [ pB ] ]
=⟨ quot-rel (pcABr-cong (pcAAr-idp₀-idp₀ pc) [ pB ]) ⟩
q[ pc aa⟦ d ⟧b [ pB ] ]
=∎)
pB
abstract
transp-idcBB-r : ∀ {b₀ b₁} (p : b₀ == b₁) -- [idc] = identity code
→ transport (codeBB b₀) p q[ ⟧b idp₀ ] == q[ ⟧b [ p ] ]
transp-idcBB-r idp = idp
encode-decodeBA : ∀ {b₀ a₁} (c : precodeBA b₀ a₁)
→ encode (decodeBA q[ c ]) == q[ c ]
encode-decodeBB : ∀ {b₀ b₁} (c : precodeBB b₀ b₁)
→ encode (decodeBB q[ c ]) == q[ c ]
encode-decodeBA {b₀} (pc-bba d pc pA) = Trunc-elim
{P = λ pA → encode (decodeBA q[ pc bb⟦ d ⟧a pA ]) == q[ pc bb⟦ d ⟧a pA ]}
(λ _ → =-preserves-set SetQuot-is-set)
(λ pA →
encode (decodeBB q[ pc ] ∙₀' [ ! (glue (h d)) ∙' ap left pA ])
=⟨ transp₀-∙₀' (λ p₁ → code-is-set {right b₀} {p₁}) (decodeBB q[ pc ]) [ ! (glue (h d)) ∙' ap left pA ] (encode-idp (right b₀)) ⟩
transport (codeBP b₀) (! (glue (h d)) ∙' ap left pA) (encode (decodeBB q[ pc ]))
=⟨ ap (transport (codeBP b₀) (! (glue (h d)) ∙' ap left pA)) (encode-decodeBB pc) ⟩
transport (codeBP b₀) (! (glue (h d)) ∙' ap left pA) q[ pc ]
=⟨ transp-∙' {B = codeBP b₀} (! (glue (h d))) (ap left pA) q[ pc ] ⟩
transport (codeBP b₀) (ap left pA) (transport (codeBP b₀) (! (glue (h d))) q[ pc ])
=⟨ ap (transport (codeBP b₀) (ap left pA)) (transp-cBP-!glue d pc) ⟩
transport (codeBP b₀) (ap left pA) q[ pc bb⟦ d ⟧a idp₀ ]
=⟨ ap (λ e → coe e q[ pc bb⟦ d ⟧a idp₀ ]) (∘-ap (codeBP b₀) left pA) ⟩
transport (codeBA b₀) pA q[ pc bb⟦ d ⟧a idp₀ ]
=⟨ transp-cBA-r d pA (pc bb⟦ d ⟧a idp₀) ⟩
q[ pc bb⟦ d ⟧a idp₀ ba⟦ d ⟧b idp₀ bb⟦ d ⟧a [ pA ] ]
=⟨ quot-rel (pcBAr-cong (pcBBr-idp₀-idp₀ pc) [ pA ]) ⟩
q[ pc bb⟦ d ⟧a [ pA ] ]
=∎)
pA
encode-decodeBB {b₀} (pc-b pB) = Trunc-elim
{P = λ pB → encode (decodeBB q[ ⟧b pB ]) == q[ ⟧b pB ]}
(λ _ → =-preserves-set SetQuot-is-set)
(λ pB →
transport (codeBP b₀) (ap right pB) q[ ⟧b idp₀ ]
=⟨ ap (λ e → coe e q[ ⟧b idp₀ ]) (∘-ap (codeBP b₀) right pB) ⟩
transport (codeBB b₀) pB q[ ⟧b idp₀ ]
=⟨ transp-idcBB-r pB ⟩
q[ ⟧b [ pB ] ]
=∎)
pB
encode-decodeBB {b₀} (pc-bab d pc pB) = Trunc-elim
{P = λ pB → encode (decodeBB q[ pc ba⟦ d ⟧b pB ]) == q[ pc ba⟦ d ⟧b pB ]}
(λ _ → =-preserves-set SetQuot-is-set)
(λ pB →
encode (decodeBA q[ pc ] ∙₀' [ glue (h d) ∙' ap right pB ])
=⟨ transp₀-∙₀' (λ p₁ → code-is-set {right b₀} {p₁}) (decodeBA q[ pc ]) [ glue (h d) ∙' ap right pB ] (encode-idp (right b₀)) ⟩
transport (codeBP b₀) (glue (h d) ∙' ap right pB) (encode (decodeBA q[ pc ]))
=⟨ ap (transport (codeBP b₀) (glue (h d) ∙' ap right pB)) (encode-decodeBA pc) ⟩
transport (codeBP b₀) (glue (h d) ∙' ap right pB) q[ pc ]
=⟨ transp-∙' {B = codeBP b₀} (glue (h d)) (ap right pB) q[ pc ] ⟩
transport (codeBP b₀) (ap right pB) (transport (codeBP b₀) (glue (h d)) q[ pc ])
=⟨ ap (transport (codeBP b₀) (ap right pB)) (transp-cBP-glue d pc) ⟩
transport (codeBP b₀) (ap right pB) q[ pc ba⟦ d ⟧b idp₀ ]
=⟨ ap (λ e → coe e q[ pc ba⟦ d ⟧b idp₀ ]) (∘-ap (codeBP b₀) right pB) ⟩
transport (codeBB b₀) pB q[ pc ba⟦ d ⟧b idp₀ ]
=⟨ transp-cBB-r d pB (pc ba⟦ d ⟧b idp₀) ⟩
q[ pc ba⟦ d ⟧b idp₀ bb⟦ d ⟧a idp₀ ba⟦ d ⟧b [ pB ] ]
=⟨ quot-rel (pcBBr-cong (pcBAr-idp₀-idp₀ pc) [ pB ]) ⟩
q[ pc ba⟦ d ⟧b [ pB ] ]
=∎)
pB
abstract
encode-decode : ∀ {p₀ p₁} (cPP : code p₀ p₁)
→ encode {p₀} {p₁} (decode {p₀} {p₁} cPP) == cPP
encode-decode {p₀} {p₁} = Pushout-elim
{P = λ p₀ → ∀ p₁ → (cPP : code p₀ p₁) → encode (decode {p₀} {p₁} cPP) == cPP}
(λ a₀ → Pushout-elim
(λ a₁ → SetQuot-elim
{P = λ cPP → encode (decodeAA cPP) == cPP}
(λ _ → =-preserves-set SetQuot-is-set)
(encode-decodeAA {a₀} {a₁})
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _)))
(λ b₁ → SetQuot-elim
{P = λ cPP → encode (decodeAB cPP) == cPP}
(λ _ → =-preserves-set SetQuot-is-set)
(encode-decodeAB {a₀} {b₁})
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _)))
(λ _ → prop-has-all-paths-↓ $ Π-is-prop λ cPP → SetQuot-is-set _ _))
(λ b₀ → Pushout-elim
(λ a₁ → SetQuot-elim
{P = λ cPP → encode (decodeBA cPP) == cPP}
(λ _ → =-preserves-set SetQuot-is-set)
(encode-decodeBA {b₀} {a₁})
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _)))
(λ b₁ → SetQuot-elim
{P = λ cPP → encode (decodeBB cPP) == cPP}
(λ _ → =-preserves-set SetQuot-is-set)
(encode-decodeBB {b₀} {b₁})
(λ _ → prop-has-all-paths-↓ (SetQuot-is-set _ _)))
(λ _ → prop-has-all-paths-↓ $ Π-is-prop λ cPP → SetQuot-is-set _ _))
(λ _ → prop-has-all-paths-↓ $ Π-is-prop λ p₁ → Π-is-prop λ cPP → codeBP-is-set {p₁ = p₁} _ _)
p₀ p₁
vankampen : ∀ p₀ p₁ → (p₀ =₀ p₁) ≃ code p₀ p₁
vankampen p₀ p₁ = equiv (encode {p₀} {p₁}) (decode {p₀} {p₁}) (encode-decode {p₀} {p₁}) (decode-encode {p₀} {p₁})
| 51.837963 | 139 | 0.504599 |
18486bc200479d8da5769c7bd1616519d0f1bd7d | 2,946 | agda | Agda | src/Web/Semantic/DL/Category/Properties/Composition/RespectsWiring.agda | agda/agda-web-semantic | 8ddbe83965a616bff6fc7a237191fa261fa78bab | [
"MIT"
] | 9 | 2015-09-13T17:46:41.000Z | 2020-03-14T14:21:08.000Z | src/Web/Semantic/DL/Category/Properties/Composition/RespectsWiring.agda | bblfish/agda-web-semantic | 38fbc3af7062ba5c3d7d289b2b4bcfb995d99057 | [
"MIT"
] | 4 | 2018-11-14T02:32:28.000Z | 2021-01-04T20:57:19.000Z | src/Web/Semantic/DL/Category/Properties/Composition/RespectsWiring.agda | bblfish/agda-web-semantic | 38fbc3af7062ba5c3d7d289b2b4bcfb995d99057 | [
"MIT"
] | 3 | 2017-12-03T14:52:09.000Z | 2022-03-12T11:40:03.000Z | open import Data.Product using ( proj₁ ; proj₂ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; sym ; cong )
open import Relation.Unary using ( _⊆_ )
open import Web.Semantic.DL.ABox using ( ABox ; ⟨ABox⟩ ; Assertions )
open import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind )
open import Web.Semantic.DL.ABox.Model using ( _⊨a_ ; bnodes ; _,_ )
open import Web.Semantic.DL.Category.Object using ( Object ; IN ; fin ; iface )
open import Web.Semantic.DL.Category.Morphism using ( impl ; _≣_ ; _⊑_ ; _,_ )
open import Web.Semantic.DL.Category.Composition using ( _∙_ )
open import Web.Semantic.DL.Category.Properties.Composition.Lemmas using
( compose-left ; compose-right ; compose-resp-⊨a )
open import Web.Semantic.DL.Category.Wiring using
( wiring ; wires-≈ ; wires-≈⁻¹ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.DL.TBox.Interp using
( Δ ; _⊨_≈_ ; ≈-refl ; ≈-refl′ ; ≈-trans )
open import Web.Semantic.Util using
( _∘_ ; False ; elim ; _⊕_⊕_ ; inode ; bnode ; enode )
module Web.Semantic.DL.Category.Properties.Composition.RespectsWiring
{Σ : Signature} {S T : TBox Σ} where
compose-resp-wiring : ∀ (A B C : Object S T) →
(f : IN B → IN A) →
(f✓ : Assertions (⟨ABox⟩ f (iface B)) ⊆ Assertions (iface A)) →
(g : IN C → IN B) →
(g✓ : Assertions (⟨ABox⟩ g (iface C)) ⊆ Assertions (iface B)) →
(h : IN C → IN A) →
(h✓ : Assertions (⟨ABox⟩ h (iface C)) ⊆ Assertions (iface A)) →
(∀ x → f (g x) ≡ h x) →
(wiring A B f f✓ ∙ wiring B C g g✓ ≣ wiring A C h h✓)
compose-resp-wiring A B C f f✓ g g✓ h h✓ fg≡h =
(LHS⊑RHS , RHS⊑LHS) where
LHS⊑RHS : wiring A B f f✓ ∙ wiring B C g g✓ ⊑ wiring A C h h✓
LHS⊑RHS I I⊨STA I⊨F = (elim , I⊨RHS) where
lemma : ∀ x → ⌊ I ⌋ ⊨ ind I (inode (h x)) ≈ ind I (enode x)
lemma x = ≈-trans ⌊ I ⌋
(≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (sym (fg≡h x))))
(≈-trans ⌊ I ⌋
(wires-≈ f (proj₂ (fin B) (g x))
(compose-left (wiring A B f f✓) (wiring B C g g✓) I I⊨F))
(wires-≈ g (proj₂ (fin C) x)
(compose-right (wiring A B f f✓) (wiring B C g g✓) I I⊨F)))
I⊨RHS : bnodes I elim ⊨a impl (wiring A C h h✓)
I⊨RHS = wires-≈⁻¹ h lemma (proj₁ (fin C))
RHS⊑LHS : wiring A C h h✓ ⊑ wiring A B f f✓ ∙ wiring B C g g✓
RHS⊑LHS I I⊨STA I⊨F = (i , I⊨LHS) where
i : (False ⊕ IN B ⊕ False) → Δ ⌊ I ⌋
i (inode ())
i (bnode y) = ind I (inode (f y))
i (enode ())
lemma : ∀ x → ⌊ I ⌋ ⊨ ind I (inode (f (g x))) ≈ ind I (enode x)
lemma x = ≈-trans ⌊ I ⌋
(≈-refl′ ⌊ I ⌋ (cong (ind I ∘ inode) (fg≡h x)))
(wires-≈ h (proj₂ (fin C) x) I⊨F)
I⊨LHS : bnodes I i ⊨a impl (wiring A B f f✓ ∙ wiring B C g g✓)
I⊨LHS = compose-resp-⊨a (wiring A B f f✓) (wiring B C g g✓) (bnodes I i)
(wires-≈⁻¹ f (λ x → ≈-refl ⌊ I ⌋) (proj₁ (fin B)))
(wires-≈⁻¹ g lemma (proj₁ (fin C)))
| 43.323529 | 79 | 0.580109 |
2331b6e54529447e807efcc1cd97f23d2cd80ae7 | 3,349 | agda | Agda | Cubical/Experiments/IntegerMatrix.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | 1 | 2021-10-31T17:32:49.000Z | 2021-10-31T17:32:49.000Z | Cubical/Experiments/IntegerMatrix.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | Cubical/Experiments/IntegerMatrix.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | {-
Normalize Integer Matrices
-}
{-# OPTIONS --safe #-}
module Cubical.Experiments.IntegerMatrix where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.Int
open import Cubical.Data.FinData
open import Cubical.Data.List
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Int
renaming (ℤ to ℤRing)
open import Cubical.Algebra.Matrix
open import Cubical.Algebra.Matrix.CommRingCoefficient
open import Cubical.Algebra.IntegerMatrix.Smith
open import Cubical.Algebra.IntegerMatrix.Diagonalization
private
variable
m n : ℕ
open Coefficient ℤRing
-- Get divisors directly
open isSmithNormal
open Smith
open isDiagonal
open Diag
getElemDiv : Mat m n → List ℤ
getElemDiv M = smith M .isnormal .divs .fst
getDiagDiv : Mat m n → List ℤ
getDiagDiv M = diagonalize M .isdiag .divs .fst
-- Constructing matrices
makeMat2×2 : ℤ → ℤ → ℤ → ℤ → Mat 2 2
makeMat2×2 a00 _ _ _ zero zero = a00
makeMat2×2 _ a01 _ _ zero one = a01
makeMat2×2 _ _ a10 _ one zero = a10
makeMat2×2 _ _ _ a11 one one = a11
makeMat3×3 : ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → ℤ → Mat 3 3
makeMat3×3 a00 _ _ _ _ _ _ _ _ zero zero = a00
makeMat3×3 _ a01 _ _ _ _ _ _ _ zero one = a01
makeMat3×3 _ _ a02 _ _ _ _ _ _ zero two = a02
makeMat3×3 _ _ _ a10 _ _ _ _ _ one zero = a10
makeMat3×3 _ _ _ _ a11 _ _ _ _ one one = a11
makeMat3×3 _ _ _ _ _ a12 _ _ _ one two = a12
makeMat3×3 _ _ _ _ _ _ a20 _ _ two zero = a20
makeMat3×3 _ _ _ _ _ _ _ a21 _ two one = a21
makeMat3×3 _ _ _ _ _ _ _ _ a22 two two = a22
-- The Tests
-- One can add flag "-vprofile.interactive:10" to this file,
-- then C-c C-n to run these tests and also get the time.
-- It turns out that, "smith" is much slower than "diagonalize"
-- and it doesn't work even for simple 3×3-matrices.
-- The "diagonalize" works only for very simple 3×3-matrices.
-- One subtle point is, if one only do one-step in Smith normalization
-- and simply add the time cost in each steps,
-- the result is far less than running the whole function "smith".
-- So the recursive procedure slows down the procedure
-- for some reasons I don't fully understand.
-- Also, the performance of "smith" is very bad at certain trivial cases,
-- much worse than some non-trivial cases.
mat1 = makeMat2×2
1 0
0 1
-- Time: 528ms
test1 = getElemDiv mat1
-- Time: 51ms
test1' = getDiagDiv mat1
mat2 = makeMat2×2
2 0
0 1
-- Time: 89,437ms
-- Why so slow?
test2 = getElemDiv mat2
-- Time: 51ms
test2' = getDiagDiv mat2
mat3 = makeMat2×2
2 1
3 5
-- Time: 3,308ms
test3 = getElemDiv mat3
-- Time: 1,887ms
test3' = getDiagDiv mat3
mat4 = makeMat2×2
4 2
2 4
-- Time: 3,284ms
test4 = getElemDiv mat4
-- Time: 1,942ms
test4' = getDiagDiv mat4
mat5 = makeMat3×3
1 0 0
0 0 0
0 0 0
-- Time: 9,400ms
test5 = getElemDiv mat5
-- Time: 337ms
test5' = getDiagDiv mat5
mat6 = makeMat3×3
1 0 0
0 1 0
0 0 1
-- Time: ???
-- It doesn't work out already.
test6 = getElemDiv mat6
-- Time: 8,598ms
test6' = getDiagDiv mat6
mat7 = makeMat3×3
1 1 0
3 2 1
2 0 1
-- Time: ???
test7 = getElemDiv mat7
-- Time: 14,149ms
test7' = getDiagDiv mat7
mat8 = makeMat3×3
2 3 1
2 2 3
1 1 0
-- Time: ???
test8 = getElemDiv mat8
-- Time: ???
-- Not working either.
test8' = getDiagDiv mat8
| 22.326667 | 73 | 0.681696 |
dff9f50b3ab5808f51b017dda63a1408f284979f | 7,225 | agda | Agda | src/Data/Fin/Subset/Properties/Cardinality.agda | tizmd/agda-finitary | abacd166f63582b7395d9cc10b6323c0f69649e5 | [
"MIT"
] | null | null | null | src/Data/Fin/Subset/Properties/Cardinality.agda | tizmd/agda-finitary | abacd166f63582b7395d9cc10b6323c0f69649e5 | [
"MIT"
] | null | null | null | src/Data/Fin/Subset/Properties/Cardinality.agda | tizmd/agda-finitary | abacd166f63582b7395d9cc10b6323c0f69649e5 | [
"MIT"
] | null | null | null | module Data.Fin.Subset.Properties.Cardinality where
open import Data.Nat as ℕ using (ℕ)
open import Data.Nat.Properties as NP
open import Data.Empty using (⊥-elim)
open import Data.Fin
open import Data.Fin.Subset
open import Data.Fin.Subset.Properties
open import Data.Vec using (_∷_; [])
open import Data.Vec.Any using (here ; there)
open import Data.Vec.Properties as VP
open import Data.Product
open import Data.Sum
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as Eq
open import Relation.Nullary.Negation
open import Function
-- some trivial lemma
∣p∣≡0→≡⊥ : ∀ {n}(p : Subset n) → ∣ p ∣ ≡ 0 → p ≡ ⊥
∣p∣≡0→≡⊥ {ℕ.zero} [] refl = refl
∣p∣≡0→≡⊥ {ℕ.suc n} (outside ∷ p) eq = cong (outside ∷_) (∣p∣≡0→≡⊥ p eq)
∣p∣≡0→≡⊥ {ℕ.suc n} (inside ∷ p) ()
∣p∣≡n→≡⊤ : ∀ {n}(p : Subset n) → ∣ p ∣ ≡ n → p ≡ ⊤
∣p∣≡n→≡⊤ {ℕ.zero} [] refl = refl
∣p∣≡n→≡⊤ {ℕ.suc n} (outside ∷ p) eq = ⊥-elim (1+n≰n (≤-respˡ-≈ eq (∣p∣≤n p)))
where
open IsPartialOrder NP.≤-isPartialOrder using (≤-respˡ-≈)
∣p∣≡n→≡⊤ {ℕ.suc n} (inside ∷ p) eq = cong (inside ∷_) (∣p∣≡n→≡⊤ p (NP.suc-injective eq))
∣p∣≡1→≡⁅x⁆ : ∀ {n}(p : Subset n) → ∣ p ∣ ≡ 1 → ∃ λ x → p ≡ ⁅ x ⁆
∣p∣≡1→≡⁅x⁆ {ℕ.zero} [] ()
∣p∣≡1→≡⁅x⁆ {ℕ.suc n} (outside ∷ p) eq with ∣p∣≡1→≡⁅x⁆ p eq
... | x , q = suc x , cong (outside ∷_) q
∣p∣≡1→≡⁅x⁆ {ℕ.suc n} (inside ∷ p) eq rewrite ∣p∣≡0→≡⊥ p (NP.suc-injective eq) = zero , refl
-- union
≤∪ˡ : ∀ {n} {p} (q : Subset n) → ∣ p ∣ ℕ.≤ ∣ p ∪ q ∣
≤∪ˡ {n}{p} q = p⊆q⇒∣p∣<∣q∣ (p⊆p∪q {p = p} q)
≤∪ʳ : ∀ {n} (p q : Subset n) → ∣ q ∣ ℕ.≤ ∣ p ∪ q ∣
≤∪ʳ p q = p⊆q⇒∣p∣<∣q∣ (q⊆p∪q p q)
∪≤ : ∀ {n} (p q : Subset n) → ∣ p ∪ q ∣ ℕ.≤ ∣ p ∣ ℕ.+ ∣ q ∣
∪≤ {ℕ.zero} [] [] = ℕ.z≤n
∪≤ {ℕ.suc n} (outside ∷ p) (outside ∷ q) = ∪≤ p q
∪≤ {ℕ.suc n} (outside ∷ p) (inside ∷ q) rewrite +-suc ∣ p ∣ ∣ q ∣ = ℕ.s≤s (∪≤ p q)
∪≤ {ℕ.suc n} (inside ∷ p) (outside ∷ q) = ℕ.s≤s (∪≤ p q)
∪≤ {ℕ.suc n} (inside ∷ p) (inside ∷ q) = ℕ.s≤s (NP.≤-trans (∪≤ p q) (NP.+-mono-≤ (≤-refl {∣ p ∣}) (n≤1+n _)))
disjoint-∪≡+ : ∀ {n} (p q : Subset n) → p ∩ q ≡ ⊥ → ∣ p ∪ q ∣ ≡ ∣ p ∣ ℕ.+ ∣ q ∣
disjoint-∪≡+ {ℕ.zero} [] [] refl = refl
disjoint-∪≡+ {ℕ.suc n} (outside ∷ p) (outside ∷ q) dis = disjoint-∪≡+ p q (VP.∷-injectiveʳ dis)
disjoint-∪≡+ {ℕ.suc n} (outside ∷ p) (inside ∷ q) dis =
Eq.trans (Eq.cong ℕ.suc (disjoint-∪≡+ p q (VP.∷-injectiveʳ dis))) (Eq.sym (NP.+-suc _ _))
disjoint-∪≡+ {ℕ.suc n} (inside ∷ p) (outside ∷ q) dis = Eq.cong ℕ.suc (disjoint-∪≡+ p q (VP.∷-injectiveʳ dis))
disjoint-∪≡+ {ℕ.suc n} (inside ∷ p) (inside ∷ q) ()
x∈p⇒⁅x⁆∪p≡p : ∀ {n} (x : Fin n)(p : Subset n) → x ∈ p → ⁅ x ⁆ ∪ p ≡ p
x∈p⇒⁅x⁆∪p≡p x p x∈p = ⊆-antisym from to
where
from : ∀ {y} → y ∈ ⁅ x ⁆ ∪ p → y ∈ p
from h with x∈p∪q⁻ ⁅ x ⁆ p h
from h | inj₁ y∈⁅x⁆ rewrite x∈⁅y⁆⇒x≡y _ y∈⁅x⁆ = x∈p
from h | inj₂ y∈p = y∈p
to : ∀ {y} → y ∈ p → y ∈ ⁅ x ⁆ ∪ p
to h = x∈p∪q⁺ (inj₂ h)
∣⁅x⁆∪p∣≡1+∣p∣⇒x∉p : ∀ {n}(x : Fin n)(p : Subset n) → ∣ ⁅ x ⁆ ∪ p ∣ ≡ 1 ℕ.+ ∣ p ∣ → x ∉ p
∣⁅x⁆∪p∣≡1+∣p∣⇒x∉p x p h x∈p rewrite x∈p⇒⁅x⁆∪p≡p x p x∈p = contradiction h lemma
where
lemma : ∀ {n} → n ≢ ℕ.suc n
lemma ()
∣⁅x⁆∪⁅y⁆∣≡2⇒x≢y : ∀ {n}(x y : Fin n) → ∣ ⁅ x ⁆ ∪ ⁅ y ⁆ ∣ ≡ 2 → x ≢ y
∣⁅x⁆∪⁅y⁆∣≡2⇒x≢y x .x h refl with ∣⁅x⁆∪p∣≡1+∣p∣⇒x∉p x ⁅ x ⁆ (trans h (cong ℕ.suc (sym (∣⁅x⁆∣≡1 x))))
... | x∉⁅y⁆ = contradiction (x∈⁅x⁆ _) x∉⁅y⁆
module _ {n : ℕ} where
open import Algebra.Structures {A = Subset n} _≡_
open IsBooleanAlgebra (∪-∩-isBooleanAlgebra n) renaming (∧-complementʳ to ∩-complementʳ; ∨-complementʳ to ∪-complementʳ)
∣p∣+∣∁p∣≡n : ∀ (p : Subset n) → ∣ p ∣ ℕ.+ ∣ ∁ p ∣ ≡ n
∣p∣+∣∁p∣≡n p = ∣ p ∣ ℕ.+ ∣ ∁ p ∣
≡⟨ Eq.sym (disjoint-∪≡+ _ _ (∩-complementʳ p)) ⟩ _
≡⟨ Eq.cong ∣_∣ (∪-complementʳ p) ⟩ _
≡⟨ ∣⊤∣≡n _ ⟩ n ∎
where
open Eq.≡-Reasoning
∩≤ˡ : ∀ {n} (a b : Subset n) → ∣ a ∩ b ∣ ℕ.≤ ∣ a ∣
∩≤ˡ {n} a b = p⊆q⇒∣p∣<∣q∣ (p∩q⊆p a b)
∩≤ʳ : ∀ {n} (a b : Subset n) → ∣ a ∩ b ∣ ℕ.≤ ∣ b ∣
∩≤ʳ {n} a b = p⊆q⇒∣p∣<∣q∣ (p∩q⊆q a b)
∣p∣<∣q∣⇒∣∁q∣<∣∁p∣ : ∀ {n} (p q : Subset n) → ∣ p ∣ ℕ.< ∣ q ∣ → ∣ ∁ q ∣ ℕ.< ∣ ∁ p ∣
∣p∣<∣q∣⇒∣∁q∣<∣∁p∣ p q p<q = NP.+-cancelˡ-< ∣ q ∣
(begin-strict ∣ q ∣ ℕ.+ ∣ ∁ q ∣ ≡⟨ ∣p∣+∣∁p∣≡n q ⟩ _ ≡⟨ sym (∣p∣+∣∁p∣≡n p) ⟩ ∣ p ∣ ℕ.+ ∣ ∁ p ∣ <⟨ NP.+-monoˡ-< _ p<q ⟩ ∣ q ∣ ℕ.+ ∣ ∁ p ∣ ∎)
where
open NP.≤-Reasoning
-- intersection
{-
private
open import Relation.Nullary.Negation using (contraposition)
p∩∁q≡⊥→p⊆q : ∀ {n} {p q : Subset n} → p ∩ ∁ q ≡ ⊥ → p ⊆ q
p∩∁q≡⊥→p⊆q {zero} {[]} {[]} refl ()
p∩∁q≡⊥→p⊆q {suc n} {true ∷ p} {outside ∷ q} () here
p∩∁q≡⊥→p⊆q {suc n} {inside ∷ p} {inside ∷ q} eq here = here
p∩∁q≡⊥→p⊆q {suc n} {true ∷ p} {_ ∷ q} eq (there x∈p) with ∷-injective eq
... | _ , teq = there (p∩∁q≡⊥→p⊆q teq x∈p)
p∩∁q≡⊥→p⊆q {suc n} {outside ∷ p} {_ ∷ q} eq (there x∈p) with ∷-injective eq
... | _ , teq = there (p∩∁q≡⊥→p⊆q teq x∈p)
p∩q≡p→p⊆q : ∀ {n} {p q : Subset n} → p ∩ q ≡ p → p ⊆ q
p∩q≡p→p⊆q {zero} {[]} {[]} refl ()
p∩q≡p→p⊆q {suc n} {inside ∷ p} {x ∷ q} eq here with ∷-injective eq
p∩q≡p→p⊆q {suc n} {inside ∷ p} {.inside ∷ q} eq here | refl , _ = here
p∩q≡p→p⊆q {suc n} {inside ∷ p} {_ ∷ q} eq (there x∈p) with ∷-injective eq
... | _ , teq = there (p∩q≡p→p⊆q teq x∈p)
p∩q≡p→p⊆q {suc n} {outside ∷ p} {_ ∷ q} eq (there x∈p) with ∷-injective eq
... | _ , teq = there (p∩q≡p→p⊆q teq x∈p)
p⊈q→p∩q≢p : ∀ {n} {p q : Subset n} → p ⊈ q → p ∩ q ≢ p
p⊈q→p∩q≢p = contraposition p∩q≡p→p⊆q
split-size : ∀ {n} {a} (b : Subset n) → ∣ a ∣ ≡ ∣ a ∩ b ∣ ℕ.+ ∣ a ∩ ∁ b ∣
split-size {n}{a} b = ∣a∣≡∣a∩b∣+∣a∩∁b∣
where
open P.≡-Reasoning
a∩b∩a∩∁b≡⊥ : (a ∩ b) ∩ (a ∩ ∁ b) ≡ ⊥
a∩b∩a∩∁b≡⊥ = begin
(a ∩ b) ∩ (a ∩ ∁ b) ≡⟨ ∩-assoc _ _ _ ⟩ _
≡⟨ cong (a ∩_ ) (sym (∩-assoc _ _ _)) ⟩ _
≡⟨ cong (a ∩_ ) (cong (_∩ _) (∩-comm _ _)) ⟩ _
≡⟨ cong (a ∩_ ) (∩-assoc _ _ _) ⟩ _
≡⟨ cong (a ∩_ ) (cong (a ∩_) (∩-complementʳ _)) ⟩ _
≡⟨ cong (a ∩_ ) (∩-zeroʳ _) ⟩ _
≡⟨ ∩-zeroʳ _ ⟩ ⊥
∎
a≡a∩b∪a∩∁b : a ≡ (a ∩ b) ∪ (a ∩ ∁ b)
a≡a∩b∪a∩∁b = begin
a ≡⟨ sym (∩-identityʳ _) ⟩ a ∩ ⊤
≡⟨ cong (_ ∩_) (sym (∪-complementʳ _)) ⟩ a ∩ (b ∪ ∁ b)
≡⟨ (proj₁ ∪-∩-distrib) _ _ _ ⟩ (a ∩ b) ∪ (a ∩ ∁ b)
∎
∣a∣≡∣a∩b∣+∣a∩∁b∣ : ∣ a ∣ ≡ ∣ a ∩ b ∣ ℕ.+ ∣ a ∩ ∁ b ∣
∣a∣≡∣a∩b∣+∣a∩∁b∣ = begin
∣ a ∣ ≡⟨ cong size a≡a∩b∪a∩∁b ⟩ ∣ (a ∩ b) ∪ (a ∩ ∁ b) ∣
≡⟨ disjoint-∪≡ a∩b∩a∩∁b≡⊥ ⟩ ∣ a ∩ b ∣ ℕ.+ ∣ a ∩ ∁ b ∣
∎
⊈→∩<ˡ : ∀ {n} {a b : Subset n} → a ⊈ b → ∣ a ∩ b ∣ ℕ.< ∣ a ∣
⊈→∩<ˡ {n}{a}{b} a⊈b = ≤+≢⇒< (∩≤ˡ a b) lemma
where
open P.≡-Reasoning
n+m≡n→m≡0 : ∀ {n m} → n ℕ.+ m ≡ n → m ≡ 0
n+m≡n→m≡0 {n}{m} eq = +-cancelˡ-≡ n (P.trans eq (sym (+-identityʳ n)))
lemma : ∣ a ∩ b ∣ ≢ ∣ a ∣
lemma eq = (contraposition p∩∁q≡⊥→p⊆q a⊈b) (size0 (n+m≡n→m≡0 (sym (P.trans eq (split-size b)))))
-}
| 41.763006 | 141 | 0.424913 |
10380419b26b51991cebef1380a603d499af5036 | 2,607 | agda | Agda | src/Web/Semantic/Everything.agda | agda/agda-web-semantic | 8ddbe83965a616bff6fc7a237191fa261fa78bab | [
"MIT"
] | 9 | 2015-09-13T17:46:41.000Z | 2020-03-14T14:21:08.000Z | src/Web/Semantic/Everything.agda | bblfish/agda-web-semantic | 38fbc3af7062ba5c3d7d289b2b4bcfb995d99057 | [
"MIT"
] | 4 | 2018-11-14T02:32:28.000Z | 2021-01-04T20:57:19.000Z | src/Web/Semantic/Everything.agda | bblfish/agda-web-semantic | 38fbc3af7062ba5c3d7d289b2b4bcfb995d99057 | [
"MIT"
] | 3 | 2017-12-03T14:52:09.000Z | 2022-03-12T11:40:03.000Z | -- A module which imports every Web.Semantic module.
module Web.Semantic.Everything where
import Web.Semantic.DL.ABox
import Web.Semantic.DL.ABox.Interp
import Web.Semantic.DL.ABox.Interp.Meet
import Web.Semantic.DL.ABox.Interp.Morphism
import Web.Semantic.DL.ABox.Model
import Web.Semantic.DL.ABox.Skolemization
import Web.Semantic.DL.Category
import Web.Semantic.DL.Category.Composition
import Web.Semantic.DL.Category.Morphism
import Web.Semantic.DL.Category.Object
import Web.Semantic.DL.Category.Properties
import Web.Semantic.DL.Category.Properties.Composition
import Web.Semantic.DL.Category.Properties.Composition.Assoc
import Web.Semantic.DL.Category.Properties.Composition.LeftUnit
import Web.Semantic.DL.Category.Properties.Composition.Lemmas
import Web.Semantic.DL.Category.Properties.Composition.RespectsEquiv
import Web.Semantic.DL.Category.Properties.Composition.RespectsWiring
import Web.Semantic.DL.Category.Properties.Composition.RightUnit
import Web.Semantic.DL.Category.Properties.Equivalence
import Web.Semantic.DL.Category.Properties.Tensor
import Web.Semantic.DL.Category.Properties.Tensor.AssocNatural
import Web.Semantic.DL.Category.Properties.Tensor.Coherence
import Web.Semantic.DL.Category.Properties.Tensor.Functor
import Web.Semantic.DL.Category.Properties.Tensor.Isomorphisms
import Web.Semantic.DL.Category.Properties.Tensor.Lemmas
import Web.Semantic.DL.Category.Properties.Tensor.RespectsEquiv
import Web.Semantic.DL.Category.Properties.Tensor.RespectsWiring
import Web.Semantic.DL.Category.Properties.Tensor.SymmNatural
import Web.Semantic.DL.Category.Properties.Tensor.UnitNatural
import Web.Semantic.DL.Category.Tensor
import Web.Semantic.DL.Category.Unit
import Web.Semantic.DL.Category.Wiring
import Web.Semantic.DL.Concept
import Web.Semantic.DL.Concept.Model
import Web.Semantic.DL.Concept.Skolemization
import Web.Semantic.DL.FOL
import Web.Semantic.DL.FOL.Model
import Web.Semantic.DL.Integrity
import Web.Semantic.DL.Integrity.Closed
import Web.Semantic.DL.Integrity.Closed.Alternate
import Web.Semantic.DL.Integrity.Closed.Properties
import Web.Semantic.DL.KB
import Web.Semantic.DL.KB.Model
import Web.Semantic.DL.KB.Skolemization
import Web.Semantic.DL.Role
import Web.Semantic.DL.Role.Model
import Web.Semantic.DL.Role.Skolemization
import Web.Semantic.DL.Sequent
import Web.Semantic.DL.Sequent.Model
import Web.Semantic.DL.Signature
import Web.Semantic.DL.TBox
import Web.Semantic.DL.TBox.Interp
import Web.Semantic.DL.TBox.Interp.Morphism
import Web.Semantic.DL.TBox.Minimizable
import Web.Semantic.DL.TBox.Model
import Web.Semantic.DL.TBox.Skolemization
| 42.737705 | 69 | 0.853088 |
20a905348f3d5a6cde748e27c16c25f7e8915734 | 149 | agda | Agda | test/fail/AgdalightTelescopeSyntax.agda | asr/agda-kanso | aa10ae6a29dc79964fe9dec2de07b9df28b61ed5 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | test/fail/AgdalightTelescopeSyntax.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | test/fail/AgdalightTelescopeSyntax.agda | np/agda-git-experiment | 20596e9dd9867166a64470dd24ea68925ff380ce | [
"MIT"
] | null | null | null | module AgdalightTelescopeSyntax where
postulate
A : Set
B : A -> Set
g : (x y : A; z : B x) -> A
-- this is Agdalight syntax, should not parse | 21.285714 | 45 | 0.644295 |
d0b56f25578c1af6c0970e5f5660198eb27d2a93 | 911 | agda | Agda | archive/agda-3/src/Test/UnifiesSubstitunction.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | archive/agda-3/src/Test/UnifiesSubstitunction.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | 1 | 2019-04-29T00:35:04.000Z | 2019-05-11T23:33:04.000Z | archive/agda-3/src/Test/UnifiesSubstitunction.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null |
open import Everything
module Test.UnifiesSubstitunction {𝔭} (𝔓 : Ø 𝔭) where
open Substitunction 𝔓
open Term 𝔓
open Substitist 𝔓
≡-Unifies₀-Term : ∀ {m} → Term m → Term m → Ṗroperty ∅̂ (Arrow Fin Term m)
≡-Unifies₀-Term = ≡-surjcollation
≡-Unifies₀-Term' : ∀ {m} → Term m → Term m → Ṗroperty ∅̂ (Arrow Fin Term m)
≡-Unifies₀-Term' = ≡-surjcollation[ Term ]⟦ Substitunction ⟧
≡-Unifies₀-Terms : ∀ {N m} → Terms N m → Terms N m → Ṗroperty ∅̂ (Arrow Fin Term m)
≡-Unifies₀-Terms = λ x → ≡-surjcollation x
≡-ExtensionalUnifies-Term : ∀ {m} → Term m → Term m → ArrowExtensionṖroperty ∅̂ Fin Term _≡_ m
≡-ExtensionalUnifies-Term = Surjextenscollation.method Substitunction _≡̇_
≡-ExtensionalUnifies-Terms : ∀ {N m} → Terms N m → Terms N m → LeftExtensionṖroperty ∅̂ (Arrow Fin Term) (Pointwise Proposequality) m
≡-ExtensionalUnifies-Terms = surjextenscollation⟦ Pointwise _≡_ ⟧
| 37.958333 | 136 | 0.675082 |
180afb6f3a8b171701d088ac389396a55f659ab1 | 14,572 | agda | Agda | Cubical/Categories/Constructions/Slice.agda | maxdore/cubical | ef62b84397396d48135d73ba7400b71c721ddc94 | [
"MIT"
] | null | null | null | Cubical/Categories/Constructions/Slice.agda | maxdore/cubical | ef62b84397396d48135d73ba7400b71c721ddc94 | [
"MIT"
] | null | null | null | Cubical/Categories/Constructions/Slice.agda | maxdore/cubical | ef62b84397396d48135d73ba7400b71c721ddc94 | [
"MIT"
] | 1 | 2021-03-12T20:08:45.000Z | 2021-03-12T20:08:45.000Z | {-# OPTIONS --safe #-}
open import Cubical.Categories.Category
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open Iso
open import Cubical.Foundations.HLevels
open Precategory
open import Cubical.Core.Glue
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport using (transpFill)
module Cubical.Categories.Constructions.Slice {ℓ ℓ' : Level} (C : Precategory ℓ ℓ') (c : C .ob) {{isC : isCategory C}} where
open import Cubical.Data.Sigma
-- just a helper to prevent redundency
TypeC : Type (ℓ-suc (ℓ-max ℓ ℓ'))
TypeC = Type (ℓ-max ℓ ℓ')
-- Components of a slice category
record SliceOb : TypeC where
constructor sliceob
field
{S-ob} : C .ob
S-arr : C [ S-ob , c ]
open SliceOb public
record SliceHom (a b : SliceOb) : Type ℓ' where
constructor slicehom
field
S-hom : C [ S-ob a , S-ob b ]
-- commutative diagram
S-comm : S-hom ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a
open SliceHom public
-- Helpers for working with equality
-- can probably replace these by showing that SliceOb is isomorphic to Sigma and
-- that paths are isomorphic to Sigma? But sounds like that would need a lot of transp
SliceOb-≡-intro : ∀ {a b} {f g}
→ (p : a ≡ b)
→ PathP (λ i → C [ p i , c ]) f g
→ sliceob {a} f ≡ sliceob {b} g
SliceOb-≡-intro p q = λ i → sliceob {p i} (q i)
module _ {xf yg : SliceOb} where
private
x = xf .S-ob
f = xf .S-arr
y = yg .S-ob
g = yg .S-arr
-- a path between slice objects is the "same" as a pair of paths between C obs and C arrows
SOPathIsoPathΣ : Iso (xf ≡ yg) (Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g)
SOPathIsoPathΣ .fun p = (λ i → (p i) .S-ob) , (λ i → (p i) .S-arr)
SOPathIsoPathΣ .inv (p , q) i = sliceob {p i} (q i)
SOPathIsoPathΣ .rightInv _ = refl
SOPathIsoPathΣ .leftInv _ = refl
SOPath≃PathΣ = isoToEquiv SOPathIsoPathΣ
SOPath≡PathΣ = ua (isoToEquiv SOPathIsoPathΣ)
-- intro and elim for working with SliceHom equalities (is there a better way to do this?)
SliceHom-≡-intro : ∀ {a b} {f g} {c₁} {c₂}
→ (p : f ≡ g)
→ PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
→ slicehom f c₁ ≡ slicehom g c₂
SliceHom-≡-intro p q = λ i → slicehom (p i) (q i)
SliceHom-≡-elim : ∀ {a b} {f g} {c₁} {c₂}
→ slicehom f c₁ ≡ slicehom g c₂
→ Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
SliceHom-≡-elim r = (λ i → S-hom (r i)) , λ i → S-comm (r i)
SliceHom-≡-intro' : ∀ {a b} {f g : C [ a .S-ob , b .S-ob ]} {c₁} {c₂}
→ (p : f ≡ g)
→ slicehom f c₁ ≡ slicehom g c₂
SliceHom-≡-intro' {a} {b} {f} {g} {c₁} {c₂} p i = slicehom (p i) (c₁≡c₂ i)
where
c₁≡c₂ : PathP (λ i → (p i) ⋆⟨ C ⟩ (b .S-arr) ≡ a .S-arr) c₁ c₂
c₁≡c₂ = isOfHLevel→isOfHLevelDep 1 (λ _ → isC .isSetHom _ _) c₁ c₂ p
-- SliceHom is isomorphic to the Sigma type with the same components
SliceHom-Σ-Iso : ∀ {a b}
→ Iso (SliceHom a b) (Σ[ h ∈ C [ S-ob a , S-ob b ] ] h ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a)
SliceHom-Σ-Iso .fun (slicehom h c) = h , c
SliceHom-Σ-Iso .inv (h , c) = slicehom h c
SliceHom-Σ-Iso .rightInv = λ x → refl
SliceHom-Σ-Iso .leftInv = λ x → refl
-- Precategory definition
SliceCat : Precategory _ _
SliceCat .ob = SliceOb
SliceCat .Hom[_,_] = SliceHom
SliceCat .id (sliceob {x} f) = slicehom (C .id x) (C .⋆IdL _)
SliceCat ._⋆_ {sliceob j} {sliceob k} {sliceob l} (slicehom f p) (slicehom g p') =
slicehom
(f ⋆⟨ C ⟩ g)
( f ⋆⟨ C ⟩ g ⋆⟨ C ⟩ l
≡⟨ C .⋆Assoc _ _ _ ⟩
f ⋆⟨ C ⟩ (g ⋆⟨ C ⟩ l)
≡⟨ cong (λ v → f ⋆⟨ C ⟩ v) p' ⟩
f ⋆⟨ C ⟩ k
≡⟨ p ⟩
j
∎)
SliceCat .⋆IdL (slicehom S-hom S-comm) =
SliceHom-≡-intro (⋆IdL C _) (toPathP (isC .isSetHom _ _ _ _))
SliceCat .⋆IdR (slicehom S-hom S-comm) =
SliceHom-≡-intro (⋆IdR C _) (toPathP (isC .isSetHom _ _ _ _))
SliceCat .⋆Assoc f g h =
SliceHom-≡-intro (⋆Assoc C _ _ _) (toPathP (isC .isSetHom _ _ _ _))
-- SliceCat is a Category
instance
isCatSlice : isCategory SliceCat
isCatSlice .isSetHom {a} {b} (slicehom f c₁) (slicehom g c₂) p q = cong isoP p'≡q'
where
-- paths between SliceHoms are equivalent to the projection paths
p' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
p' = SliceHom-≡-elim p
q' : Σ[ p ∈ f ≡ g ] PathP (λ i → (p i) ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a) c₁ c₂
q' = SliceHom-≡-elim q
-- we want all paths between (dependent) paths of this type to be equal
B = λ v → v ⋆⟨ C ⟩ (S-arr b) ≡ S-arr a
-- need the groupoidness for dependent paths
homIsGroupoidDep : isOfHLevelDep 2 B
homIsGroupoidDep = isOfHLevel→isOfHLevelDep 2 (λ v x y → isSet→isGroupoid (isC .isSetHom) _ _ x y)
-- we first prove that the projected paths are equal
p'≡q' : p' ≡ q'
p'≡q' = ΣPathP ((isC .isSetHom _ _ _ _) , toPathP (homIsGroupoidDep _ _ _ _ _))
-- and then we can use equivalence to lift these paths up
-- to actual SliceHom paths
isoP = λ g → cong (inv SliceHom-Σ-Iso) (fun (ΣPathIsoPathΣ) g)
-- SliceCat is univalent if C is univalent
module _ ⦃ isU : isUnivalent C ⦄ where
open CatIso
open Iso
module _ { xf yg : SliceOb } where
private
x = xf .S-ob
y = yg .S-ob
-- names for the equivalences/isos
pathIsoEquiv : (x ≡ y) ≃ (CatIso x y)
pathIsoEquiv = univEquiv isU x y
isoPathEquiv : (CatIso x y) ≃ (x ≡ y)
isoPathEquiv = invEquiv pathIsoEquiv
pToIIso' : Iso (x ≡ y) (CatIso x y)
pToIIso' = equivToIso pathIsoEquiv
-- the iso in SliceCat we're given induces an iso in C between x and y
module _ ( cIso@(catiso kc lc s r) : CatIso {C = SliceCat} xf yg ) where
extractIso' : CatIso {C = C} x y
extractIso' .mor = kc .S-hom
extractIso' .inv = lc .S-hom
extractIso' .sec i = (s i) .S-hom
extractIso' .ret i = (r i) .S-hom
instance
preservesUnivalenceSlice : isUnivalent SliceCat
-- we prove the equivalence by going through Iso
preservesUnivalenceSlice .univ xf@(sliceob {x} f) yg@(sliceob {y} g) = isoToIsEquiv sIso
where
-- this is just here because the type checker can't seem to infer xf and yg
pToIIso : Iso (x ≡ y) (CatIso x y)
pToIIso = pToIIso' {xf = xf} {yg}
-- the meat of the proof
sIso : Iso (xf ≡ yg) (CatIso xf yg)
sIso .fun p = pathToIso xf yg p -- we use the normal pathToIso via path induction to get an isomorphism
sIso .inv is@(catiso kc lc s r) = SliceOb-≡-intro x≡y (symP (sym (lc .S-comm) ◁ lf≡f))
where
-- we get a path between xf and yg by combining paths between
-- x and y, and f and g
-- 1. x≡y follows from univalence of C
-- 2. f≡g is more tricky; by commutativity, we know that g ≡ l ⋆ f
-- so we want l to be id; we get this by showing: id ≡ pathToIso x y x≡y ≡ l
-- where the first step follows from path induction, and the second from univalence of C
-- morphisms in C from kc and lc
k = kc .S-hom
l = lc .S-hom
-- extract out the iso between x and y
extractIso : CatIso {C = C} x y
extractIso = extractIso' is
-- and we can use univalence of C to get x ≡ y
x≡y : x ≡ y
x≡y = pToIIso .inv extractIso
-- to show that f ≡ g, we show that l ≡ id
-- by using C's isomorphism
pToI≡id : PathP (λ i → C [ x≡y (~ i) , x ]) (pathToIso {C = C} x y x≡y .inv) (C .id x)
pToI≡id = J (λ y p → PathP (λ i → C [ p (~ i) , x ]) (pathToIso {C = C} x y p .inv) (C .id x))
(λ j → JRefl pToIFam pToIBase j .inv)
x≡y
where
idx = C .id x
pToIFam = (λ z _ → CatIso {C = C} x z)
pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx)
l≡pToI : l ≡ pathToIso {C = C} x y x≡y .inv
l≡pToI i = pToIIso .rightInv extractIso (~ i) .inv
l≡id : PathP (λ i → C [ x≡y (~ i) , x ]) l (C .id x)
l≡id = l≡pToI ◁ pToI≡id
lf≡f : PathP (λ i → C [ x≡y (~ i) , c ]) (l ⋆⟨ C ⟩ f) f
lf≡f = (λ i → (l≡id i) ⋆⟨ C ⟩ f) ▷ C .⋆IdL _
sIso .rightInv is@(catiso kc lc s r) i = catiso (kc'≡kc i) (lc'≡lc i) (s'≡s i) (r'≡r i)
-- we prove rightInv using a combination of univalence and the fact that homs are an h-set
where
kc' = (sIso .fun) (sIso .inv is) .mor
lc' = (sIso .fun) (sIso .inv is) .inv
k' = kc' .S-hom
l' = lc' .S-hom
k = kc .S-hom
l = lc .S-hom
extractIso : CatIso {C = C} x y
extractIso = extractIso' is
-- we do the equality component wise
-- mor
k'≡k : k' ≡ k
k'≡k i = (pToIIso .rightInv extractIso) i .mor
kcom'≡kcom : PathP (λ j → (k'≡k j) ⋆⟨ C ⟩ g ≡ f) (kc' .S-comm) (kc .S-comm)
kcom'≡kcom = isSetHomP1 _ _ λ i → (k'≡k i) ⋆⟨ C ⟩ g
kc'≡kc : kc' ≡ kc
kc'≡kc i = slicehom (k'≡k i) (kcom'≡kcom i)
-- inv
l'≡l : l' ≡ l
l'≡l i = (pToIIso .rightInv extractIso) i .inv
lcom'≡lcom : PathP (λ j → (l'≡l j) ⋆⟨ C ⟩ f ≡ g) (lc' .S-comm) (lc .S-comm)
lcom'≡lcom = isSetHomP1 _ _ λ i → (l'≡l i) ⋆⟨ C ⟩ f
lc'≡lc : lc' ≡ lc
lc'≡lc i = slicehom (l'≡l i) (lcom'≡lcom i)
-- sec
s' = (sIso .fun) (sIso .inv is) .sec
s'≡s : PathP (λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i ≡ SliceCat .id _) s' s
s'≡s = isSetHomP1 _ _ λ i → lc'≡lc i ⋆⟨ SliceCat ⟩ kc'≡kc i
-- ret
r' = (sIso .fun) (sIso .inv is) .ret
r'≡r : PathP (λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i ≡ SliceCat .id _) r' r
r'≡r = isSetHomP1 _ _ λ i → kc'≡kc i ⋆⟨ SliceCat ⟩ lc'≡lc i
sIso .leftInv p = p'≡p
-- to show that the round trip is equivalent to the identity
-- we show that this is true for each component (S-ob, S-arr)
-- and then combine
-- specifically, we show that p'Ob≡pOb and p'Mor≡pMor
-- and it follows that p'≡p
where
p' = (sIso .inv) (sIso .fun p)
pOb : x ≡ y
pOb i = (p i) .S-ob
p'Ob : x ≡ y
p'Ob i = (p' i) .S-ob
pMor : PathP (λ i → C [ pOb i , c ]) f g
pMor i = (p i) .S-arr
p'Mor : PathP (λ i → C [ p'Ob i , c ]) f g
p'Mor i = (p' i) .S-arr
-- we first show that it's equivalent to use sIso first then extract, or to extract first than use pToIIso
extractCom : extractIso' (sIso .fun p) ≡ pToIIso .fun pOb
extractCom = J (λ yg' p̃ → extractIso' (pathToIso xf yg' p̃) ≡ pToIIso' {xf = xf} {yg'} .fun (λ i → (p̃ i) .S-ob))
(cong extractIso' (JRefl pToIFam' pToIBase') ∙ sym (JRefl pToIFam pToIBase))
p
where
idx = C .id x
pToIFam = (λ z _ → CatIso {C = C} x z)
pToIBase = catiso (C .id x) idx (C .⋆IdL idx) (C .⋆IdL idx)
idxf = SliceCat .id xf
pToIFam' = (λ z _ → CatIso {C = SliceCat} xf z)
pToIBase' = catiso (SliceCat .id xf) idxf (SliceCat .⋆IdL idxf) (SliceCat .⋆IdL idxf)
-- why does this not follow definitionally?
-- from extractCom, we get that performing the roundtrip on pOb gives us back p'Ob
ppp : p'Ob ≡ (pToIIso .inv) (pToIIso .fun pOb)
ppp = cong (pToIIso .inv) extractCom
-- apply univalence of C
-- this gives us the first component that we want
p'Ob≡pOb : p'Ob ≡ pOb
p'Ob≡pOb = ppp ∙ pToIIso .leftInv pOb
-- isSetHom gives us the second component, path between morphisms
p'Mor≡pMor : PathP (λ j → PathP (λ i → C [ (p'Ob≡pOb j) i , c ]) f g) p'Mor pMor
p'Mor≡pMor = isSetHomP2l _ _ p'Mor pMor p'Ob≡pOb
-- we can use the above paths to show that p' ≡ p
p'≡p : p' ≡ p
p'≡p i = comp (λ i' → SOPath≡PathΣ {xf = xf} {yg} (~ i'))
(λ j → λ { (i = i0) → left (~ j) ; (i = i1) → right (~ j) })
(p'Σ≡pΣ i)
where
-- we break up p' and p into their constituent paths
-- first via transport and then via our component definitions from before
-- we show that p'ΣT ≡ p'Σ (and same for p) via univalence
-- and p'Σ≡pΣ follows from our work from above
p'ΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
p'ΣT = transport SOPath≡PathΣ p'
p'Σ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
p'Σ = (p'Ob , p'Mor)
pΣT : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
pΣT = transport SOPath≡PathΣ p
pΣ : Σ[ p ∈ x ≡ y ] PathP (λ i → C [ p i , c ]) f g
pΣ = (pOb , pMor)-- transport SOPathP≡PathPSO p
-- using the computation rule to ua
p'ΣT≡p'Σ : p'ΣT ≡ p'Σ
p'ΣT≡p'Σ = uaβ SOPath≃PathΣ p'
pΣT≡pΣ : pΣT ≡ pΣ
pΣT≡pΣ = uaβ SOPath≃PathΣ p
p'Σ≡pΣ : p'Σ ≡ pΣ
p'Σ≡pΣ = ΣPathP (p'Ob≡pOb , p'Mor≡pMor)
-- two sides of the square we're connecting
left : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p' p'Σ
left = transport-filler SOPath≡PathΣ p' ▷ p'ΣT≡p'Σ
right : PathP (λ i → SOPath≡PathΣ {xf = xf} {yg} i) p pΣ
right = transport-filler SOPath≡PathΣ p ▷ pΣT≡pΣ
-- properties
-- TODO: move to own file
open isIsoC renaming (inv to invC)
-- make a slice isomorphism from just the hom
sliceIso : ∀ {a b} (f : C [ a .S-ob , b .S-ob ]) (c : (f ⋆⟨ C ⟩ b .S-arr) ≡ a .S-arr)
→ isIsoC {C = C} f
→ isIsoC {C = SliceCat} (slicehom f c)
sliceIso f c isof .invC = slicehom (isof .invC) (sym (invMoveL (isIso→areInv isof) c))
sliceIso f c isof .sec = SliceHom-≡-intro' (isof .sec)
sliceIso f c isof .ret = SliceHom-≡-intro' (isof .ret)
| 37.947917 | 126 | 0.522372 |
dc3f0d4782fc14c1cd3b9eb176646641c903aee7 | 5,833 | agda | Agda | src/FOmegaInt/Typing/Inversion.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | 12 | 2017-06-13T16:05:35.000Z | 2021-09-27T05:53:06.000Z | src/FOmegaInt/Typing/Inversion.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | 1 | 2021-05-14T08:09:40.000Z | 2021-05-14T08:54:39.000Z | src/FOmegaInt/Typing/Inversion.agda | Blaisorblade/f-omega-int-agda | ae20dac2a5e0c18dff2afda4c19954e24d73a24f | [
"MIT"
] | 2 | 2021-05-13T22:29:48.000Z | 2021-05-14T10:25:05.000Z | ------------------------------------------------------------------------
-- Inversion of (sub)typing in Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Typing.Inversion where
open import Data.Product using (_,_; proj₁; proj₂; _×_; map)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Relation.Nullary using (¬_)
open import FOmegaInt.Syntax
open import FOmegaInt.Typing
open import FOmegaInt.Typing.Validity
open import FOmegaInt.Kinding.Declarative.Normalization
open import FOmegaInt.Kinding.Canonical.Equivalence
using (sound-<:; sound-<∷; complete-<∷; complete-<:-⋯)
import FOmegaInt.Kinding.Canonical.Inversion as CanInv
open Syntax
open TermCtx hiding (map)
open Typing
open Substitution using (_[_]; weaken)
open WfCtxOps using (lookup-tp)
open TypedSubstitution
open TypedNarrowing
------------------------------------------------------------------------
-- Generation/inversion of typing.
infix 4 _⊢Tm-gen_∈_
-- The possible types of a term (i.e. the possible results of
-- generating/inverting _⊢Tp_∈_).
data _⊢Tm-gen_∈_ {n} (Γ : Ctx n) : Term n → Term n → Set where
∈-var : ∀ {a b} x → Γ ctx → lookup Γ x ≡ tp a → Γ ⊢ a <: b ∈ * →
Γ ⊢Tm-gen var x ∈ b
∈-∀-i : ∀ {k a b c} → Γ ⊢ k kd → kd k ∷ Γ ⊢Tm a ∈ b → Γ ⊢ Π k b <: c ∈ * →
Γ ⊢Tm-gen Λ k a ∈ c
∈-→-i : ∀ {a b c d} → Γ ⊢Tp a ∈ * → tp a ∷ Γ ⊢Tm b ∈ weaken c →
Γ ⊢ a ⇒ c <: d ∈ * → Γ ⊢Tm-gen ƛ a b ∈ d
∈-∀-e : ∀ {a b k c d} → Γ ⊢Tm a ∈ Π k c → Γ ⊢Tp b ∈ k → Γ ⊢ c [ b ] <: d ∈ * →
Γ ⊢Tm-gen a ⊡ b ∈ d
∈-→-e : ∀ {a b c d e} → Γ ⊢Tm a ∈ c ⇒ d → Γ ⊢Tm b ∈ c → Γ ⊢ d <: e ∈ * →
Γ ⊢Tm-gen a · b ∈ e
-- Generation/inversion of typing.
Tm∈-gen : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tm a ∈ b → Γ ⊢Tm-gen a ∈ b
Tm∈-gen (∈-var x Γ-ctx Γ[x]≡kd-a) =
∈-var x Γ-ctx Γ[x]≡kd-a (<:-refl (Tm∈-valid (∈-var x Γ-ctx Γ[x]≡kd-a)))
Tm∈-gen (∈-∀-i k-kd a∈b) =
∈-∀-i k-kd a∈b (<:-refl (Tm∈-valid (∈-∀-i k-kd a∈b)))
Tm∈-gen (∈-→-i a∈* b∈c c∈*) =
∈-→-i a∈* b∈c (<:-refl (Tm∈-valid (∈-→-i a∈* b∈c c∈*)))
Tm∈-gen (∈-∀-e a∈∀kc b∈k) =
∈-∀-e a∈∀kc b∈k (<:-refl (Tm∈-valid (∈-∀-e a∈∀kc b∈k)))
Tm∈-gen (∈-→-e a∈c⇒d b∈c) =
∈-→-e a∈c⇒d b∈c (<:-refl (Tm∈-valid (∈-→-e a∈c⇒d b∈c)))
Tm∈-gen (∈-⇑ a∈b b<:c) with Tm∈-gen a∈b
Tm∈-gen (∈-⇑ x∈b c<:d) | ∈-var x Γ-ctx Γ[x]≡kd-a a<:b =
∈-var x Γ-ctx Γ[x]≡kd-a (<:-trans a<:b c<:d)
Tm∈-gen (∈-⇑ Λka∈b b<:c) | ∈-∀-i k-kd a∈d ∀kd<:b =
∈-∀-i k-kd a∈d (<:-trans ∀kd<:b b<:c)
Tm∈-gen (∈-⇑ ƛab∈c c<:d) | ∈-→-i a∈* b∈c a⇒c<:d =
∈-→-i a∈* b∈c (<:-trans a⇒c<:d c<:d)
Tm∈-gen (∈-⇑ a·b∈e e<:f) | ∈-∀-e a∈Πcd b∈c d[b]<:e =
∈-∀-e a∈Πcd b∈c (<:-trans d[b]<:e e<:f)
Tm∈-gen (∈-⇑ a·b∈e e<:f) | ∈-→-e a∈c⇒d b∈c d<:e =
∈-→-e a∈c⇒d b∈c (<:-trans d<:e e<:f)
------------------------------------------------------------------------
-- Inversion of subtyping (in the empty context).
-- NOTE. The following two lemmas only hold in the empty context
-- because we can not invert instances of the interval projection
-- rules (<:-⟨| and (<:-|⟩) in arbitrary contexts. This is because
-- instances of these rules can reflect arbitrary subtyping
-- assumptions into the subtyping relation. Consider, e.g.
--
-- Γ, X :: ⊤..⊥ ctx Γ(X) = ⊥..⊤
-- ------------------------------- (∈-var)
-- Γ, X :: ⊤..⊥ ⊢ X :: ⊤..⊥
-- -------------------------- (<:-⟨|, <:-|⟩)
-- Γ, X :: ⊤..⊥ ⊢ ⊤ <: X <: ⊥
--
-- Which allows us to prove that ⊤ <: ⊥ using (<:-trans) under the
-- assumption (X : ⊤..⊥). On the other hand, it is impossible to give
-- a transitivity-free proof of ⊤ <: ⊥. In general, it is therefore
-- impossible to invert subtyping statements in non-empty contexts,
-- i.e. one cannot prove lemmas like (<:-→-inv) or (<:-∀-inv) below
-- for arbitrary contexts.
<:-∀-inv : ∀ {k₁ k₂ : Kind Term 0} {a₁ a₂} → [] ⊢ Π k₁ a₁ <: Π k₂ a₂ ∈ * →
[] ⊢ k₂ <∷ k₁ × kd k₂ ∷ [] ⊢ a₁ <: a₂ ∈ *
<:-∀-inv ∀k₁a₁<:∀k₂a₂∈* =
let nf-∀k₁a₁<:nf-∀k₂a₂ = complete-<:-⋯ ∀k₁a₁<:∀k₂a₂∈*
nf-k₂<∷nf-k₁ , nf-a₁<:nf-a₂ = CanInv.<:-∀-inv nf-∀k₁a₁<:nf-∀k₂a₂
∀k₁a₁∈* , ∀k₂a₂∈* = <:-valid ∀k₁a₁<:∀k₂a₂∈*
k₁≅nf-k₁∈* , a₁≃nf-a₁∈* = Tp∈-∀-≃-⌞⌟-nf ∀k₁a₁∈*
k₂≅nf-k₂∈* , a₂≃nf-a₂∈* = Tp∈-∀-≃-⌞⌟-nf ∀k₂a₂∈*
k₂<∷nf-k₂∈* = ≅⇒<∷ k₂≅nf-k₂∈*
k₂<∷k₁ = <∷-trans (<∷-trans k₂<∷nf-k₂∈* (sound-<∷ nf-k₂<∷nf-k₁))
(≅⇒<∷ (≅-sym k₁≅nf-k₁∈*))
in k₂<∷k₁ ,
<:-trans (<:-trans (⇓-<: k₂<∷k₁ (≃⇒<: a₁≃nf-a₁∈*))
(⇓-<: k₂<∷nf-k₂∈* (sound-<: nf-a₁<:nf-a₂)))
(≃⇒<: (≃-sym a₂≃nf-a₂∈*))
<:-→-inv : ∀ {a₁ a₂ b₁ b₂ : Term 0} → [] ⊢ a₁ ⇒ b₁ <: a₂ ⇒ b₂ ∈ * →
[] ⊢ a₂ <: a₁ ∈ * × [] ⊢ b₁ <: b₂ ∈ *
<:-→-inv a₁⇒b₁<:a₂⇒b₂∈* =
let nf-a₁⇒b₁<:nf-a₂⇒b₂ = complete-<:-⋯ a₁⇒b₁<:a₂⇒b₂∈*
nf-a₂<:nf-a₁ , nf-b₁<:nf-b₂ = CanInv.<:-→-inv nf-a₁⇒b₁<:nf-a₂⇒b₂
a₁⇒b₁∈* , a₂⇒b₂∈* = <:-valid a₁⇒b₁<:a₂⇒b₂∈*
a₁≃nf-a₁∈* , b₁≃nf-b₁∈* = Tp∈-→-≃-⌞⌟-nf a₁⇒b₁∈*
a₂≃nf-a₂∈* , b₂≃nf-b₂∈* = Tp∈-→-≃-⌞⌟-nf a₂⇒b₂∈*
in <:-trans (<:-trans (≃⇒<: a₂≃nf-a₂∈*) (sound-<: nf-a₂<:nf-a₁))
(≃⇒<: (≃-sym a₁≃nf-a₁∈*)) ,
<:-trans (<:-trans (≃⇒<: b₁≃nf-b₁∈*) (sound-<: nf-b₁<:nf-b₂))
(≃⇒<: (≃-sym b₂≃nf-b₂∈*))
-- ⊤ is not a subtype of ⊥.
⊤-≮:-⊥ : ∀ {a : Term 0} → ¬ [] ⊢ ⊤ <: ⊥ ∈ *
⊤-≮:-⊥ ⊤<:⊥ with CanInv.⊤-<:-max (complete-<:-⋯ ⊤<:⊥)
⊤-≮:-⊥ ⊤<:⊥ | ()
-- Arrows are not canonical subtypes of universals and vice-versa.
⇒-≮:-Π : ∀ {a₁ b₁ : Term 0} {k₂ a₂} → ¬ [] ⊢ a₁ ⇒ b₁ <: Π k₂ a₂ ∈ *
⇒-≮:-Π a₁⇒b₁<:∀k₂a₂∈* = CanInv.⇒-≮:-Π (complete-<:-⋯ a₁⇒b₁<:∀k₂a₂∈*)
Π-≮:-⇒ : ∀ {k₁ a₁} {a₂ b₂ : Term 0} → ¬ [] ⊢ Π k₁ a₁ <: a₂ ⇒ b₂ ∈ *
Π-≮:-⇒ ∀k₁a₁<:a₂⇒b₂∈* = CanInv.Π-≮:-⇒ (complete-<:-⋯ ∀k₁a₁<:a₂⇒b₂∈*)
| 42.268116 | 80 | 0.454655 |
1c500609e4d4316c507da27fe4f65329ee7d750c | 2,638 | agda | Agda | nicolai/pseudotruncations/pointed-O-Sphere.agda | nicolaikraus/HoTT-Agda | 939a2d83e090fcc924f69f7dfa5b65b3b79fe633 | [
"MIT"
] | 1 | 2021-06-30T00:17:55.000Z | 2021-06-30T00:17:55.000Z | nicolai/pseudotruncations/pointed-O-Sphere.agda | nicolaikraus/HoTT-Agda | 939a2d83e090fcc924f69f7dfa5b65b3b79fe633 | [
"MIT"
] | null | null | null | nicolai/pseudotruncations/pointed-O-Sphere.agda | nicolaikraus/HoTT-Agda | 939a2d83e090fcc924f69f7dfa5b65b3b79fe633 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NType2
open import lib.PathGroupoid
open import lib.types.Bool
open import lib.types.IteratedSuspension
open import lib.types.Lift
open import lib.types.LoopSpace
open import lib.types.Nat
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.Suspension
open import lib.types.TLevel
open import lib.types.Unit
open SuspensionRec public using () renaming (f to Susp-rec)
open import nicolai.pseudotruncations.Preliminary-definitions
open import nicolai.pseudotruncations.Liblemmas
module nicolai.pseudotruncations.pointed-O-Sphere where
{- helper file for some technical things -}
module _ {i} where
bool = fst (⊙Sphere {i} O)
tt₀ : bool
tt₀ = snd (⊙Sphere {i} O)
ff₀ : bool
ff₀ = lift false
module bool-neutral
{i j}
(P : bool {i} → Type j)
(p₀ : P tt₀) where
bool-pair : (P tt₀ × P ff₀) ≃ ((b : bool) → P b)
bool-pair = equiv (λ tf → (λ { (lift true) → fst tf ; (lift false) → snd tf }))
(λ f → (f tt₀ , f ff₀))
(λ f → λ= (λ { (lift true) → idp ; (lift false) → idp }))
(λ tf → idp)
pair-red : Σ (P tt₀ × P ff₀) (λ tf → fst tf == p₀) → P ff₀
pair-red ((pt , pf) , q) = pf
sing-exp : P ff₀ → Σ (P tt₀ × P ff₀) (λ tf → fst tf == p₀)
sing-exp pf = ((p₀ , pf) , idp)
red-exp : (pf : P ff₀) → pair-red (sing-exp pf) == pf
red-exp _ = idp
exp-red : (x : Σ (P tt₀ × P ff₀) (λ tf → fst tf == p₀)) → sing-exp (pair-red x) == x
exp-red ((.p₀ , pf) , idp) = idp
{- I tried to do it with pattern matching, but this does not introduce
a dot [.] before [p₀]. Thus, is fails. Is this a bug? -}
pair-one-determined : Σ (P tt₀ × P ff₀) (λ tf → fst tf == p₀) ≃ P ff₀
pair-one-determined = equiv pair-red sing-exp red-exp exp-red
{- This reduction result is (on paper) trivial, but for our formalization
quite powerful! -}
reduction : (Σ ((b : bool) → P b) λ g → g tt₀ == p₀) ≃ P ff₀
reduction = (Σ ((b : bool) → P b) λ g → g tt₀ == p₀)
≃⟨ equiv-Σ-fst {A = P tt₀ × P ff₀}
{B = (b : bool) → P b}
(λ g → g tt₀ == p₀)
{h = fst bool-pair}
(snd bool-pair) ⁻¹ ⟩
Σ (P tt₀ × P ff₀) ((λ g → g tt₀ == p₀) ∘ fst bool-pair)
≃⟨ ide _ ⟩
Σ (P tt₀ × P ff₀) (λ tf → fst tf == p₀)
≃⟨ pair-one-determined ⟩
P ff₀
≃∎
| 31.035294 | 86 | 0.543215 |
dc2e62faae68467252b56000acc7ddcbdcdc801f | 1,297 | agda | Agda | LibraBFT/Impl/Consensus/ChainedBFT/EventProcessor/Properties.agda | haroldcarr/bft-consensus-agda | 34e4627855fb198665d0c98f377403a906ba75d7 | [
"UPL-1.0"
] | null | null | null | LibraBFT/Impl/Consensus/ChainedBFT/EventProcessor/Properties.agda | haroldcarr/bft-consensus-agda | 34e4627855fb198665d0c98f377403a906ba75d7 | [
"UPL-1.0"
] | null | null | null | LibraBFT/Impl/Consensus/ChainedBFT/EventProcessor/Properties.agda | haroldcarr/bft-consensus-agda | 34e4627855fb198665d0c98f377403a906ba75d7 | [
"UPL-1.0"
] | null | null | null | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
-- This module contains properties that are only about the behavior of the handlers, nothing to do
-- with system state
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Base.ByteString
open import LibraBFT.Base.Types
open import LibraBFT.Hash
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Util
module LibraBFT.Impl.Consensus.ChainedBFT.EventProcessor.Properties
(hash : BitString → Hash)
(hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y)
where
open import LibraBFT.Impl.Consensus.ChainedBFT.EventProcessor hash hash-cr
-- The quorum certificates sent in SyncInfo with votes are those from the peer state
procPMCerts≡ : ∀ {ts pm pre vm αs}
→ (SendVote vm αs) ∈ LBFT-outs (processProposalMsg ts pm) pre
→ vm ^∙ vmSyncInfo ≡ mkSyncInfo (₋epHighestQC pre) (₋epHighestCommitQC pre)
procPMCerts≡ (there x) = ⊥-elim (¬Any[] x) -- processProposalMsg sends only one vote
procPMCerts≡ (here refl) = refl
| 40.53125 | 111 | 0.737857 |
c5d1d8a5c7048a2269ad44c6867cd7b42563c4eb | 39,444 | agda | Agda | combinations-of-lift-and-list.agda | Saizan/Agda-proofs | add34af6c5c0c106c7aaa2d9612d54e041ab5d3b | [
"MIT"
] | null | null | null | combinations-of-lift-and-list.agda | Saizan/Agda-proofs | add34af6c5c0c106c7aaa2d9612d54e041ab5d3b | [
"MIT"
] | null | null | null | combinations-of-lift-and-list.agda | Saizan/Agda-proofs | add34af6c5c0c106c7aaa2d9612d54e041ab5d3b | [
"MIT"
] | null | null | null | {-# OPTIONS --cubical --guarded -W ignore #-}
module combinations-of-lift-and-list where
open import Clocked.Primitives
open import Cubical.Foundations.Prelude
open import Cubical.Data.List as List
open import Cubical.Data.List.Properties
open import Cubical.Data.Sum using (_⊎_; inl; inr)
--**********************************************************************--
--**********************************************************************--
-- Combining the monads Lift and List freely and via a distributive law --
--**********************************************************************--
--**********************************************************************--
-- In this document I want to define a monad, called ListLift, that is the free combination of the Lift monad and the List monad.
-- In order to do so, I will first define the Lift monad and the List monad, and check that they are indeed monads (Step 1 and 2).
-- Then I define the LiftList monad, check that it is a monad (Step 3), and finally check that it is the free monad on the algebra
-- structures of a delay algebra and a monoid (Step 4).
-- In addition to the free combination of the List and the Lift monads, I also compose the two monads to form the monad
-- LcL : A → Lift(List A). This composition uses a distributive law, which I prove does indeed satisfy all the axioms for a
-- distributive law.
--************************--
-- Step 1: The Lift monad --
--************************--
-- Defining the monad myLift.
--(note that the return/unit is just x → nowL x)
data myLift (A : Set) (κ : Cl) : Set where
nowL : A → (myLift A κ)
stepL : ▹ κ (myLift A κ) → (myLift A κ)
bindL : {A B : Set} (κ : Cl) → (A → (myLift B κ)) → myLift A κ → myLift B κ
bindL κ f (nowL a) = f a
bindL κ f (stepL x) = stepL \(α) → bindL κ f (x α)
identity : {A : Set} → A → A
identity x = x
MultL : {A : Set} (κ : Cl) → (myLift (myLift A κ) κ) → (myLift A κ)
MultL κ = bindL κ identity
mapL : {A B : Set} (κ : Cl) → (A → B) → (myLift A κ) → (myLift B κ)
mapL κ f (nowL x) = nowL (f x)
mapL κ f (stepL x) = stepL (\ α → mapL κ f (x α))
--checking that it is indeed a monad
-- needs to satisfy three monad laws:
-- unit is a left-identity for bind: bind (f, return) = f
-- unit is a right-identity for bind: bind (return, x) = x
-- bind is associative: bind (\x > bind (g, f(x)), x) = bind(g,bind(f, x))
-- The first of these is satisfied by definition
-- The other two laws we check here below
-- unit law, two versions to learn and remember to ways of doing guarded recursion in agda:
unitlawL : {A : Set}(κ : Cl) → ∀(x : (myLift A κ)) → (bindL {A} κ nowL x) ≡ x
unitlawL κ (nowL x) = refl
unitlawL κ (stepL x) = cong stepL (later-ext (\ α → unitlawL κ (x α)))
unitlawL' : {A : Set}(κ : Cl) → ∀(x : (myLift A κ)) → (bindL {A} κ nowL x) ≡ x
unitlawL' κ (nowL x) = refl
unitlawL' κ (stepL x) = \ i → stepL (\ α → unitlawL' κ (x α) i )
-- associative law:
associativelawL : {A B C : Set}(κ : Cl) → ∀(f : A → (myLift B κ)) → ∀ (g : B → (myLift C κ)) →
∀ (y : (myLift A κ)) → (bindL κ (\ x → (bindL κ g (f x))) y) ≡ (bindL κ g (bindL κ f y))
associativelawL κ f g (nowL x) = refl
associativelawL κ f g (stepL x) = cong stepL (((later-ext (\ α → associativelawL κ f g (x α)))))
-- Some properties that will be useful later:
-- interaction of mapL and MultL:
MultMap : {A B : Set} (κ : Cl) → ∀(x : myLift (myLift A κ) κ) → ∀(f : A → B) → mapL κ f (MultL κ x) ≡ MultL κ (mapL κ (mapL κ f) x)
MultMap κ (nowL x) f = refl
MultMap κ (stepL x) f = \ i → stepL (\ α → MultMap κ (x α) f i)
-- mapmap for mapL
mapmapL : {A B C : Set} (κ : Cl) → ∀(f : A → B) → ∀(g : B → C) → ∀(x : myLift A κ) → mapL κ g (mapL κ f x) ≡ mapL κ (\ y → g(f y)) x
mapmapL κ f g (nowL x) = refl
mapmapL κ f g (stepL x) = (\ i → stepL (\ α → mapmapL κ f g (x α) i ))
--************************--
-- Step 2: The List monad --
--************************--
-- Defining the monad List
--List is already defined, but we define a unit and multiplication for it, so it becomes a monad
List-unit : {A : Set} → A → List A
List-unit x = [ x ]
List-mult : {A : Set} → List (List A) → List A
List-mult {A} = foldr _++_ []
List-bind : {A B : Set} → (A → List B) → List A → List B
List-bind f [] = []
List-bind f (x ∷ xs) = (f x) ++ (List-bind f xs)
-- and some other useful functions for later
safe-head : {A : Set} → A → List A → A
safe-head x [] = x
safe-head _ (x ∷ _) = x
tail : {A : Set} → List A → List A
tail [] = []
tail (x ∷ xs) = xs
-- Proving that this forms a monad
-- satisfying the laws:
-- List-mult (List-unit L) = L
-- List-mult (map List-unit L) = L
-- List-mult (List-Mult L) = List-mult (map List-mult L)
-- and both the unit and the multiplication are natural transformations
-- List-mult (List-unit L) = L
List-unitlaw1 : {A : Set} → ∀(L : List A) → List-mult (List-unit L) ≡ L
List-unitlaw1 [] = refl
List-unitlaw1 (x ∷ L) = cong (_++_ [ x ]) (List-unitlaw1 L)
-- List-mult (map List-unit L) = L
List-unitlaw2 : {A : Set} → ∀(L : List A) → List-mult (map List-unit L) ≡ L
List-unitlaw2 [] = refl
List-unitlaw2 (x ∷ L) = cong (_++_ [ x ]) (List-unitlaw2 L )
-- List-mult (List-Mult L) = List-mult (map List-mult L)
lemma : {A : Set} → ∀(L₁ L₂ : List (List A)) -> List-mult (L₁ ++ L₂) ≡ (List-mult L₁) ++ (List-mult L₂)
lemma [] L₂ = refl
lemma (L₁ ∷ L₃) L₂ = L₁ ++ List-mult (L₃ ++ L₂)
≡⟨ cong (L₁ ++_) (lemma L₃ L₂) ⟩
L₁ ++ ((List-mult L₃) ++ (List-mult L₂))
≡⟨ sym (++-assoc L₁ (List-mult L₃) (List-mult L₂)) ⟩
(L₁ ++ List-mult L₃) ++ List-mult L₂
≡⟨ refl ⟩
(List-mult (L₁ ∷ L₃)) ++ (List-mult L₂) ∎
List-multlaw : {A : Set} -> ∀(L : List (List (List A))) -> List-mult (List-mult L) ≡ List-mult (map List-mult L)
List-multlaw [] = refl
List-multlaw (L ∷ L₁) = List-mult (L ++ List-mult L₁)
≡⟨ lemma L (List-mult L₁) ⟩
(List-mult L ++ List-mult (List-mult L₁))
≡⟨ cong (List-mult L ++_) (List-multlaw L₁) ⟩
List-mult L ++ List-mult (map List-mult L₁) ∎
-- the unit is a natural transformation:
nattrans-Listunit : {A B : Set} → ∀(f : A → B) → ∀(x : A) → map f (List-unit x) ≡ List-unit (f x)
nattrans-Listunit f x = refl
-- the multiplication is a natural transformation:
lemma-map++ : {A B : Set} → ∀(f : A → B) → ∀(xs ys : List A) → map f (xs ++ ys) ≡ (map f xs) ++ (map f ys)
lemma-map++ f [] ys = refl
lemma-map++ f (x ∷ xs) ys = cong ((f x) ∷_) (lemma-map++ f xs ys)
nattrans-Listmult : {A B : Set} → ∀(f : A → B) → ∀(xss : List (List A)) → map f (List-mult xss) ≡ List-mult (map (map f) xss)
nattrans-Listmult f [] = refl
nattrans-Listmult f (xs ∷ xss) = map f (xs ++ List-mult xss)
≡⟨ lemma-map++ f xs (List-mult xss) ⟩
map f xs ++ map f (List-mult xss)
≡⟨ cong (map f xs ++_) (nattrans-Listmult f xss) ⟩
map f xs ++ List-mult (map (map f) xss) ∎
--****************************--
-- Step 3: The ListLift monad --
--****************************--
--Now that we have a list monad and a lift monad, I want to show that the following combination of the two is again a monad:
--ListLift : (A : Set) → (κ : Cl) → Set
--ListLift A κ = List (A ⊎ (▹ κ (ListLift A κ)))
data ListLift (A : Set) (κ : Cl) : Set where
conLL : List (A ⊎ (▹ κ (ListLift A κ))) -> ListLift A κ
--***algebraic structure for ListLift***--
--nowLL and stepLL turn ListLift into a delay algebra structure:
nowLL : {A : Set} (κ : Cl) → A → (ListLift A κ)
nowLL κ a = conLL [ (inl a) ]
stepLL : {A : Set} (κ : Cl) → ▹ κ (ListLift A κ) → (ListLift A κ)
stepLL κ a = conLL [ (inr a) ]
--union, derived from list concatenation, turns ListLift into a monoid:
_∪_ : {A : Set} {κ : Cl} → (ListLift A κ) → (ListLift A κ) → (ListLift A κ)
_∪_ {A} {κ} (conLL x) (conLL y) = conLL (x ++ y)
--proof that this union does indeed provide a monoid structure:
conLLempty-rightunit : {A : Set} (κ : Cl) → ∀ (xs : (ListLift A κ)) → xs ∪ conLL [] ≡ xs
conLLempty-rightunit κ (conLL x) = conLL (x ++ []) ≡⟨ cong conLL (++-unit-r x) ⟩ conLL x ∎
conLLempty-leftunit : {A : Set} (κ : Cl) → ∀ (xs : (ListLift A κ)) → conLL [] ∪ xs ≡ xs
conLLempty-leftunit κ (conLL x) = refl
assoc∪ : {A : Set} {κ : Cl} → ∀(xs ys zs : (ListLift A κ)) → (xs ∪ ys) ∪ zs ≡ xs ∪ (ys ∪ zs)
assoc∪ {A} {κ} (conLL x) (conLL x₁) (conLL x₂) = cong conLL (++-assoc x x₁ x₂)
--a bind operator to make ListLift into a monad
bindLL : {A B : Set} (κ : Cl) → (A → (ListLift B κ)) → ListLift A κ → ListLift B κ
bindLL κ f (conLL []) = conLL []
bindLL κ f (conLL (inl x ∷ x₁)) = (f x) ∪ bindLL κ f (conLL x₁)
bindLL κ f (conLL (inr x ∷ x₁)) = (stepLL κ (\ α → bindLL κ f (x α))) ∪ bindLL κ f (conLL x₁)
--bind commutes with ∪
bindLL∪ : {A B : Set} (κ : Cl) → ∀(f : A → (ListLift B κ)) → ∀(xs ys : (ListLift A κ)) → bindLL κ f (xs ∪ ys) ≡ (bindLL κ f xs) ∪ (bindLL κ f ys)
bindLL∪ κ f xs (conLL []) = bindLL κ f (xs ∪ conLL []) ≡⟨ cong (bindLL κ f) (conLLempty-rightunit κ xs) ⟩
bindLL κ f xs ≡⟨ sym (conLLempty-rightunit κ (bindLL κ f xs)) ⟩
(bindLL κ f xs ∪ conLL [])∎
bindLL∪ κ f (conLL []) (conLL (x ∷ x₁)) = bindLL κ f (conLL (x ∷ x₁))
≡⟨ sym (conLLempty-leftunit κ (bindLL κ f (conLL (x ∷ x₁)))) ⟩
(conLL [] ∪ bindLL κ f (conLL (x ∷ x₁))) ∎
bindLL∪ κ f (conLL (inl x₂ ∷ x₃)) (conLL (x ∷ x₁)) = (f x₂ ∪ bindLL κ f ((conLL x₃) ∪ (conLL (x ∷ x₁)))) ≡⟨ cong (f x₂ ∪_) (bindLL∪ κ f (conLL x₃) (conLL (x ∷ x₁))) ⟩
(f x₂ ∪ (bindLL κ f (conLL x₃) ∪ bindLL κ f (conLL (x ∷ x₁))))
≡⟨ sym (assoc∪ (f x₂) (bindLL κ f (conLL x₃)) (bindLL κ f (conLL (x ∷ x₁)))) ⟩
((f x₂ ∪ bindLL κ f (conLL x₃)) ∪ bindLL κ f (conLL (x ∷ x₁))) ∎
bindLL∪ κ f (conLL (inr x₂ ∷ x₃)) (conLL (x ∷ x₁)) = (conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪ bindLL κ f ((conLL x₃) ∪ (conLL (x ∷ x₁))))
≡⟨ cong (conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪_) (bindLL∪ κ f (conLL x₃) (conLL (x ∷ x₁))) ⟩
(conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪ ((bindLL κ f (conLL x₃) ∪ bindLL κ f (conLL (x ∷ x₁)))))
≡⟨ sym (assoc∪ (conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ [])) (bindLL κ f (conLL x₃)) (bindLL κ f (conLL (x ∷ x₁)))) ⟩
((conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪ bindLL κ f (conLL x₃)) ∪ bindLL κ f (conLL (x ∷ x₁))) ∎
--and a map function to prove naturality of bind and now
mapLL : {A B : Set} (κ : Cl) → (f : A → B) → (ListLift A κ) → (ListLift B κ)
mapLL κ f (conLL []) = conLL []
mapLL κ f (conLL (inl x ∷ x₁)) = conLL ([ inl (f x) ]) ∪ mapLL κ f (conLL x₁)
mapLL κ f (conLL (inr x ∷ x₁)) = (stepLL κ (\ α → mapLL κ f (x α))) ∪ mapLL κ f (conLL x₁)
--***proving that ListLift is a monad***--
--bindLL and nowLL need to be natural transformations
nattrans-nowLL : {A B : Set} (κ : Cl) → ∀(f : A → B) → ∀(x : A) → mapLL κ f (nowLL κ x) ≡ nowLL κ (f x)
nattrans-nowLL {A}{B} κ f x = refl
--TODO: bind is a natural transformation
-- bindLL and nowLL also need to satisfy three monad laws:
-- unit is a left-identity for bind: bind (f, nowLL) = f
-- unit is a right-identity for bind: bind (nowLL, x) = x
-- bind is associative: bind (\x > bind (g, f(x)), x) = bind(g,bind(f, x))
-- unit is a left-identity for bind
unitlawLL1 : {A B : Set} (κ : Cl) → ∀ (f : A → (ListLift B κ)) → ∀ (x : A) → (bindLL {A} κ f (nowLL κ x)) ≡ f x
unitlawLL1 κ f x = (f x ∪ conLL []) ≡⟨ conLLempty-rightunit κ (f x) ⟩ f x ∎
-- unit is a right-identity for bind
unitlawLL2 : {A : Set}(κ : Cl) → ∀(x : (ListLift A κ)) → (bindLL κ (nowLL κ) x) ≡ x
unitlawLL2 κ (conLL []) = refl
unitlawLL2 κ (conLL (inl x ∷ x₁)) = (conLL ([ inl x ]) ∪ bindLL κ (nowLL κ) (conLL x₁)) ≡⟨ cong (conLL ([ inl x ]) ∪_ ) (unitlawLL2 κ (conLL x₁)) ⟩
(conLL ([ inl x ]) ∪ conLL x₁) ≡⟨ refl ⟩
conLL (inl x ∷ x₁) ∎
unitlawLL2 κ (conLL (inr x ∷ x₁)) = (stepLL κ (\ α → bindLL κ (nowLL κ) (x α))) ∪ bindLL κ (nowLL κ) (conLL x₁)
≡⟨ cong ((stepLL κ (\ α → bindLL κ (nowLL κ) (x α))) ∪_) (unitlawLL2 κ (conLL x₁)) ⟩
(stepLL κ (\ α → bindLL κ (nowLL κ) (x α))) ∪ conLL x₁
≡⟨ cong (_∪ conLL x₁) (\ i → stepLL κ (\ α → unitlawLL2 κ (x α) i ) ) ⟩
conLL ([ inr x ]) ∪ conLL x₁
≡⟨ refl ⟩
conLL (inr x ∷ x₁) ∎
-- bind is associative
assoclawLL : {A B C : Set}(κ : Cl) → ∀(f : A → (ListLift B κ)) → ∀ (g : B → (ListLift C κ)) → ∀ (x : (ListLift A κ))
→ (bindLL κ (\ y → (bindLL κ g (f y))) x) ≡ (bindLL κ g (bindLL κ f x))
assoclawLL {A} {B} {C} κ f g (conLL []) = refl
assoclawLL {A} {B} {C} κ f g (conLL (inl x ∷ x₁)) = (bindLL κ g (f x) ∪ bindLL κ (λ y → bindLL κ g (f y)) (conLL x₁))
≡⟨ cong (bindLL κ g (f x) ∪_) (assoclawLL κ f g (conLL x₁)) ⟩
(bindLL κ g (f x) ∪ bindLL κ g (bindLL κ f (conLL x₁)))
≡⟨ sym (bindLL∪ κ g (f x) (bindLL κ f (conLL x₁))) ⟩
bindLL κ g (f x ∪ bindLL κ f (conLL x₁)) ∎
assoclawLL {A} {B} {C} κ f g (conLL (inr x ∷ x₁)) = (conLL (inr (λ α → bindLL κ (λ y → bindLL κ g (f y)) (x α)) ∷ []) ∪ bindLL κ (λ y → bindLL κ g (f y)) (conLL x₁))
≡⟨ cong (conLL (inr (λ α → bindLL κ (λ y → bindLL κ g (f y)) (x α)) ∷ []) ∪_) (assoclawLL κ f g (conLL x₁)) ⟩
(conLL (inr (λ α → bindLL κ (λ y → bindLL κ g (f y)) (x α)) ∷ []) ∪ (bindLL κ g (bindLL κ f (conLL x₁))))
≡⟨ cong (_∪ (bindLL κ g (bindLL κ f (conLL x₁)))) (\ i → stepLL κ (\ α → assoclawLL κ f g (x α) i ) ) ⟩
((bindLL κ g (conLL (inr (λ α → bindLL κ f (x α)) ∷ []))) ∪ (bindLL κ g (bindLL κ f (conLL x₁))) )
≡⟨ sym (bindLL∪ κ g (conLL (inr (λ α → bindLL κ f (x α)) ∷ [])) (bindLL κ f (conLL x₁))) ⟩
bindLL κ g (conLL (inr (λ α → bindLL κ f (x α)) ∷ []) ∪ bindLL κ f (conLL x₁)) ∎
-- If I want to do it via fixpoints instead:
module WithFix where
LiftList : (A : Set) → (κ : Cl) → Set
LiftList A κ = fix (\ (X : ▹ κ Set) → List(A ⊎ (▸ κ \ α → (X α))))
nowLLfix : {A : Set} (κ : Cl) → A → (LiftList A κ)
nowLLfix κ a = [ (inl a) ]
stepLLfix : {A : Set} (κ : Cl) → ▹ κ (LiftList A κ) → (LiftList A κ)
stepLLfix {A} κ a = transport
(λ i →
fix-eq (λ (X : ▹ κ Type) → List (A ⊎ (▸ κ (λ α → X α)))) (~ i))
[ (inr a) ]
--***********************************************************************--
-- Step 4: The ListLift monad as the free delay-algebra and monoid monad --
--***********************************************************************--
-- We already know that (ListLift, stepLL) forms a delay algebra structure
-- and (Listlift, conLL [], _∪_) forms a monoid.
-- What we need to show is that ListLift is the free monad with these properties.
-- That is, for a set A, and any other structure (B, δ, ε, _·_) where (B, δ) is a delay algebra and (B, ε, _·_) a monoid
-- given a function f : A → B, there is a unique function ListLift A → B extending f that preserves the algebra structures.
record IsDelayalg {A : Set}(κ : Cl)(nextA : ▹ κ A → A) : Set where
constructor isdelayalg
record IsMonoid {A : Set} (ε : A) (_·_ : A → A → A) : Set where
constructor ismonoid
field
assoc : (x y z : A) → (x · y) · z ≡ x · (y · z)
leftid : (x : A) → ε · x ≡ x
rightid : (x : A) → x · ε ≡ x
record DelayMonoidData (A : Set) (κ : Cl) : Set where
constructor dmdata
field
nextA : ▹ κ A → A
ε : A
_·_ : A → A → A
record IsDelayMonoid {A : Set}(κ : Cl) (dm : DelayMonoidData A κ) : Set where
constructor isdelaymonoid
open DelayMonoidData dm
field
isMonoid : IsMonoid (ε) (_·_)
isDelayalg : IsDelayalg κ (nextA)
open IsMonoid isMonoid public
open IsDelayalg isDelayalg public
record IsPreservingDM {A B : Set}(κ : Cl) dmA dmB (g : A → B) : Set where
constructor ispreservingDM
open DelayMonoidData dmA renaming (ε to εA)
open DelayMonoidData dmB renaming (ε to εB; nextA to nextB; _·_ to _*_)
field
unit-preserve : g (εA) ≡ εB
next-preserve : (x : ▹ κ A) → g (nextA x) ≡ nextB (\ α → g (x α))
union-preserve : (x y : A) → g (x · y) ≡ (g x) * (g y)
record IsExtending {A B : Set}{κ : Cl} (f : A → B) (h : (ListLift A κ) → B) : Set where
constructor isextending
field
extends : (x : A) → h (nowLL κ x) ≡ (f x)
--fold defines the function we are after
fold : {A B : Set}{κ : Cl} → isSet A → isSet B → ∀ dm → IsDelayMonoid {B} κ dm → (A → B) → (ListLift A κ) → B
fold setA setB (dmdata nextB ε _·_) isDMB f (conLL []) = ε
fold setA setB dm@(dmdata nextB ε _·_) isDMB f (conLL (inl x ∷ x₁)) = (f x) · fold setA setB dm isDMB f (conLL x₁)
fold setA setB dm@(dmdata nextB ε _·_) isDMB f (conLL (inr x ∷ x₁)) = (nextB (\ α → fold setA setB dm isDMB f (x α))) · fold setA setB dm isDMB f (conLL x₁)
--fold extends the function f : A → B
-- direct proof:
fold-extends-f : {A B : Set}{κ : Cl} → ∀(setA : isSet A) → ∀(setB : isSet B) → ∀ dm → ∀(isDMB : IsDelayMonoid {B} κ dm) →
∀ (f : A → B) → ∀ (x : A) → fold setA setB dm isDMB f (nowLL κ x) ≡ f x
fold-extends-f setA setB dm isDMB f x = IsDelayMonoid.rightid isDMB (f x)
-- or via the record "IsExtending":
fold-extends : {A B : Set}{κ : Cl} → ∀(setA : isSet A) → ∀(setB : isSet B) → ∀ dm → ∀(isDMB : IsDelayMonoid {B} κ dm) →
∀ (f : A → B) → IsExtending f (fold setA setB dm isDMB f)
IsExtending.extends (fold-extends setA setB dm isDMB f) x = IsDelayMonoid.rightid isDMB (f x)
module _ {A B : Set}{κ : Cl} (setA : isSet A) (setB : isSet B) (dm : _) (isDMB : IsDelayMonoid {B} κ dm)
(f : A → B)
where
open IsPreservingDM
open DelayMonoidData dm renaming (nextA to nextB)
--fold preseves the DelayMonoid structure
fold-preserves : IsPreservingDM {ListLift A κ}{B} κ (dmdata (stepLL κ) (conLL []) _∪_) dm (fold setA setB dm isDMB f)
unit-preserve fold-preserves = refl
next-preserve fold-preserves x = IsDelayMonoid.rightid isDMB (nextB (λ α → fold setA setB dm isDMB f (x α)))
union-preserve fold-preserves (conLL xs) (conLL ys) = lemma-union xs ys
where
lemma-union : ∀ xs ys → fold setA setB dm isDMB f (conLL xs ∪ conLL ys) ≡
(fold setA setB dm isDMB f (conLL xs) ·
fold setA setB dm isDMB f (conLL ys))
lemma-union [] y = sym (IsDelayMonoid.leftid isDMB
(fold setA setB dm isDMB f (conLL y)))
lemma-union (inl x ∷ x₁) y = (f x · fold setA setB dm isDMB f (conLL (x₁ ++ y)))
≡⟨ cong (f x ·_) (lemma-union x₁ y) ⟩
((f x · (fold setA setB dm isDMB f (conLL x₁) ·
fold setA setB dm isDMB f (conLL y))))
≡⟨ sym (IsDelayMonoid.assoc isDMB (f x)
(fold setA setB dm isDMB f (conLL x₁))
(fold setA setB dm isDMB f (conLL y))) ⟩
((f x · fold setA setB dm isDMB f (conLL x₁)) ·
fold setA setB dm isDMB f (conLL y)) ∎
lemma-union (inr x ∷ x₁) y =
(nextB (λ α → fold setA setB dm isDMB f (x α)) ·
fold setA setB dm isDMB f (conLL (x₁ ++ y)))
≡⟨ cong (nextB (λ α → fold setA setB dm isDMB f (x α)) ·_)
(lemma-union
x₁ y) ⟩
( (nextB (λ α → fold setA setB dm isDMB f (x α)) ·
(fold setA setB dm isDMB f (conLL x₁) ·
fold setA setB dm isDMB f (conLL y))))
≡⟨ sym (IsDelayMonoid.assoc isDMB
(nextB (λ α → fold setA setB dm isDMB f (x α)))
(fold setA setB dm isDMB f (conLL x₁))
(fold setA setB dm isDMB f (conLL y))) ⟩
((nextB (λ α → fold setA setB dm isDMB f (x α)) ·
fold setA setB dm isDMB f (conLL x₁)) ·
fold setA setB dm isDMB f (conLL y)) ∎
--and fold is unique in doing so. That is, for any function h that both preserves the algebra structure and extends the function f : A → B,
-- h is equivalent to fold.
module _ {A B : Set} {κ : Cl} (h : ListLift A κ → B)
(setA : isSet A) (setB : isSet B) (dm : _) (isDMB : IsDelayMonoid {B} κ dm)
(f : A → B) (isPDM : IsPreservingDM {ListLift A κ}{B} κ (dmdata (stepLL κ) (conLL []) _∪_ ) dm h)
(isExt : IsExtending f h) where
open DelayMonoidData dm renaming (nextA to nextB)
fold-uniquenessLL : (x : (ListLift A κ)) → h x ≡ (fold setA setB dm isDMB f x)
fold-uniquenessLL (conLL []) = h (conLL [])
≡⟨ IsPreservingDM.unit-preserve isPDM ⟩
ε
≡⟨ refl ⟩
fold setA setB dm isDMB f (conLL []) ∎
fold-uniquenessLL (conLL (inl x ∷ x₁)) = h (conLL (inl x ∷ x₁))
≡⟨ refl ⟩
h ((conLL [ inl x ]) ∪ (conLL x₁))
≡⟨ IsPreservingDM.union-preserve isPDM (conLL [ inl x ]) (conLL x₁) ⟩
((h (conLL [ inl x ])) ·
(h (conLL x₁)) )
≡⟨ cong (_· (h (conLL x₁)) ) (IsExtending.extends isExt x) ⟩
(f x · (h (conLL x₁)))
≡⟨ cong (f x ·_)(fold-uniquenessLL (conLL x₁)) ⟩
(f x · fold setA setB dm isDMB f (conLL x₁)) ∎
fold-uniquenessLL (conLL (inr x ∷ x₁)) = h (conLL (inr x ∷ x₁))
≡⟨ cong (h ) refl ⟩
h ((conLL [ inr x ]) ∪ (conLL x₁))
≡⟨ IsPreservingDM.union-preserve isPDM (conLL [ inr x ]) (conLL x₁) ⟩
(h (conLL [ inr x ])) ·
(h (conLL x₁))
≡⟨ cong (_· h (conLL x₁)) refl ⟩
((h (stepLL κ x)) ·
(h (conLL x₁)) )
≡⟨ cong (_· h (conLL x₁)) (IsPreservingDM.next-preserve isPDM x) ⟩
(((nextB (λ α → h (x α))) · (h (conLL x₁))))
≡⟨ cong (_· h (conLL x₁)) (cong (nextB)
(later-ext (\ α → fold-uniquenessLL (x α)))) ⟩
((nextB (λ α → fold setA setB dm isDMB f (x α))) · (h (conLL x₁)))
≡⟨ cong (nextB (λ α → fold setA setB dm isDMB f (x α)) ·_)
(fold-uniquenessLL (conLL x₁)) ⟩
(nextB (λ α → fold setA setB dm isDMB f (x α)) ·
fold setA setB dm isDMB f (conLL x₁)) ∎
--************************************************--
-- Composing Lift and List via a distributive law --
--************************************************--
--We now define a composite monad of the List and Lift monads, formed via a distributive law.
LcL : (A : Set) → (κ : Cl) → Set
LcL A κ = myLift (List A) κ
-- the unit of this monad is simply the composit of the units for Lift (nowL x) and List ([x])
nowLcL : {A : Set} {κ : Cl} → A → (LcL A κ)
nowLcL x = nowL [ x ]
-- LcL is a monad via a distributive law, distributing List over Lift.
-- Here is the distributive law:
distlawLcL : {A : Set} (κ : Cl) → List (myLift A κ) → (LcL A κ)
distlawLcL κ [] = nowL []
distlawLcL κ (nowL x ∷ xs) = MultL κ (nowL (mapL κ (([ x ]) ++_) (distlawLcL κ xs)))
distlawLcL κ (stepL x ∷ xs) = stepL (\ α → distlawLcL κ ((x α) ∷ xs))
--proof that distlawLcL is indeed a distributive law:
--unit laws:
unitlawLcL1 : {A : Set} (κ : Cl) → ∀(x : myLift A κ) → (distlawLcL κ (List-unit x )) ≡ mapL κ List-unit x
unitlawLcL1 κ (nowL x) = refl
unitlawLcL1 κ (stepL x) = (\ i → stepL (\ α → unitlawLcL1 κ (x α) i ))
unitlawLcL2 : {A : Set} (κ : Cl) → ∀(xs : List A) → (distlawLcL κ (map nowL xs)) ≡ nowL xs
unitlawLcL2 κ [] = refl
unitlawLcL2 κ (x ∷ xs) = mapL κ (λ ys → x ∷ ys) (distlawLcL κ (map nowL xs))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (unitlawLcL2 κ xs) ⟩
mapL κ (λ ys → x ∷ ys) (nowL xs)
≡⟨ refl ⟩
nowL (x ∷ xs) ∎
--multiplication laws:
-- In the proof of the first multiplication law, I need a lemma about list concatenation,
-- namely that putting a singleton list in front of a list of lists, and concatening the result
-- yields the same list as putting the element of the signleton in front of the first list in the list of lists,
-- and then concatenating the result.
-- The lemma is split into two parts, first the general result as described in words here,
-- followed by the specific situation in which I need it in the proofs below.
lemma7a : {A : Set} → ∀(x : A) → ∀(xss : (List (List A))) → List-mult ((x ∷ safe-head [] xss) ∷ tail xss ) ≡ List-mult (([ x ]) ∷ xss)
lemma7a x [] = refl
lemma7a x (xs ∷ xss) = refl
lemma7b : {A : Set} (κ : Cl) → ∀(y : myLift (List (List A)) κ) → ∀(x : A) →
mapL κ (λ xss → List-mult ((x ∷ safe-head [] xss) ∷ tail xss)) y ≡ mapL κ (λ xss → List-mult (([ x ]) ∷ xss)) y
lemma7b κ (nowL xss) x = cong nowL (lemma7a x xss)
lemma7b κ (stepL xss) x = (\ i → stepL (\ α → lemma7b κ (xss α) x i ))
-- in addition, I need this rather technical lemma that allows me to pull a mapL through the distributive law.
-- without it, I could not finish the proof.
lemma8 : {A : Set} (κ : Cl) → ∀(x : A) → ∀(xs : myLift (List A) κ) → ∀(xss : List (myLift (List A) κ)) →
mapL κ (λ yss → ((x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (xs ∷ xss)) ≡ distlawLcL κ (mapL κ (λ ys → x ∷ ys) xs ∷ xss)
lemma8 κ x (nowL ys) [] = refl
lemma8 κ x (stepL ys) [] = (\ i → stepL (λ α → lemma8 κ x (ys α) [] i ))
lemma8 κ x (nowL []) (zs ∷ xss) = mapL κ (λ yss → (x ∷ safe-head [] yss) ∷ tail yss) (mapL κ (λ zss → [] ∷ zss) (distlawLcL κ (zs ∷ xss)))
≡⟨ mapmapL κ ((λ zss → [] ∷ zss)) ((λ yss → (x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (zs ∷ xss)) ⟩
mapL κ (λ yss → (x ∷ safe-head [] ([] ∷ yss)) ∷ tail ([] ∷ yss)) (distlawLcL κ (zs ∷ xss))
≡⟨ refl ⟩
mapL κ (λ yss → (x ∷ []) ∷ yss) (distlawLcL κ (zs ∷ xss)) ∎
lemma8 κ x (nowL (y ∷ ys)) (zs ∷ xss) = mapL κ (λ yss → (x ∷ safe-head [] yss) ∷ tail yss) (mapL κ (λ zss → (y ∷ ys) ∷ zss) (distlawLcL κ (zs ∷ xss)))
≡⟨ mapmapL κ ((λ zss → (y ∷ ys) ∷ zss)) ((λ yss → (x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (zs ∷ xss)) ⟩
mapL κ (λ yss → (x ∷ safe-head []((y ∷ ys) ∷ yss)) ∷ tail((y ∷ ys) ∷ yss)) (distlawLcL κ (zs ∷ xss))
≡⟨ refl ⟩
mapL κ (λ yss → (x ∷ y ∷ ys) ∷ yss) (distlawLcL κ (zs ∷ xss)) ∎
lemma8 κ x (stepL ys) (zs ∷ xss) = (\ i → stepL (λ α → lemma8 κ x (ys α) (zs ∷ xss) i ))
--now we are ready to prove the multiplication laws:
multlawLcL1 : {A : Set} (κ : Cl) → ∀(xss : List (List (myLift A κ))) → distlawLcL κ (List-mult xss) ≡
mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) xss))
multlawLcL1 κ [] = refl
multlawLcL1 κ ([] ∷ xss) = distlawLcL κ (List-mult xss)
≡⟨ multlawLcL1 κ xss ⟩
mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ refl ⟩
mapL κ (λ ys → List-mult ([] ∷ ys)) (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ sym (mapmapL κ (\ ys → [] ∷ ys) List-mult ((distlawLcL κ (map (distlawLcL κ) xss)))) ⟩
mapL κ List-mult (mapL κ (λ ys → [] ∷ ys) (distlawLcL κ (map (distlawLcL κ) xss))) ∎
multlawLcL1 κ ((nowL x ∷ []) ∷ xss) = mapL κ (λ ys → x ∷ ys) (distlawLcL κ (List-mult xss))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (multlawLcL1 κ xss) ⟩
mapL κ (λ ys → x ∷ ys) (mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) xss)))
≡⟨ mapmapL κ List-mult (λ ys → x ∷ ys) (distlawLcL κ (map (distlawLcL κ) xss)) ⟩
mapL κ (λ ys → x ∷ List-mult ys) (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ refl ⟩
mapL κ (λ ys → List-mult (([ x ]) ∷ ys)) (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ sym( mapmapL κ (λ ys → ([ x ]) ∷ ys) List-mult (distlawLcL κ (map (distlawLcL κ) xss))) ⟩
mapL κ List-mult (mapL κ (λ ys → ([ x ]) ∷ ys) (distlawLcL κ (map (distlawLcL κ) xss))) ∎
multlawLcL1 κ ((nowL x ∷ y ∷ xs) ∷ xss) = mapL κ (λ ys → x ∷ ys) (distlawLcL κ (List-mult ((y ∷ xs) ∷ xss)))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (multlawLcL1 κ ((y ∷ xs) ∷ xss)) ⟩
mapL κ (λ ys → x ∷ ys) (mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) ((y ∷ xs) ∷ xss))))
≡⟨ mapmapL κ List-mult (λ ys → x ∷ ys) (distlawLcL κ (map (distlawLcL κ) ((y ∷ xs) ∷ xss))) ⟩
mapL κ (λ yss → x ∷ (List-mult yss)) (distlawLcL κ (map (distlawLcL κ) ((y ∷ xs) ∷ xss)))
≡⟨ refl ⟩
mapL κ (λ yss → x ∷ List-mult yss) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))
≡⟨ refl ⟩
mapL κ (λ yss → List-mult (([ x ]) ∷ yss)) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))
≡⟨ sym (lemma7b κ ((distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))) x) ⟩
mapL κ (λ yss → List-mult ((x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))
≡⟨ sym (mapmapL κ ((λ yss → ((x ∷ safe-head [] yss) ∷ tail yss))) List-mult
((distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss)))) ⟩
mapL κ List-mult (mapL κ (λ yss → ((x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss)))
≡⟨ cong (mapL κ List-mult) (lemma8 κ x ((distlawLcL κ (y ∷ xs))) ((map (distlawLcL κ) xss))) ⟩
mapL κ List-mult (distlawLcL κ (mapL κ (λ ys → x ∷ ys) (distlawLcL κ (y ∷ xs)) ∷ (map (distlawLcL κ) xss))) ∎
multlawLcL1 κ ((stepL x ∷ xs) ∷ xss) = (\ i → stepL (\ α → multlawLcL1 κ ((x α ∷ xs) ∷ xss) i ))
lemma9a : {A : Set} (κ : Cl) → ∀(x : ▹ κ (myLift A κ)) → ∀(y : ▹ κ (myLift (List (myLift A κ)) κ)) →
MultL κ (stepL (λ α → stepL (λ β → mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β)))) ≡
MultL κ (stepL (λ β → stepL (λ α → mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β))))
lemma9a κ x y = cong (MultL κ) (cong stepL (later-ext λ α → cong stepL (later-ext λ β →
cong₂ (mapL κ) (funExt (λ ys → cong (distlawLcL _) (cong₂ _∷_ (tick-irr x α β) refl)))
(sym (tick-irr y α β)))))
lemma9 : {A : Set} (κ : Cl) → ∀(x : ▹ κ (myLift A κ)) → ∀(y : myLift (List (myLift A κ)) κ) →
MultL κ (stepL (λ α → (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) y))) ≡ MultL κ (mapL κ (λ ys → stepL (λ α → distlawLcL κ (x α ∷ ys))) y)
lemma9 κ x (nowL y) = refl
lemma9 κ x (stepL y) = stepL (λ α → stepL (λ β → MultL κ (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β))))
≡⟨ lemma9a κ x y ⟩
stepL (λ β → stepL (λ α → MultL κ (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β))))
≡⟨ ( (\ i → stepL (\ β → lemma9 κ x (y β) i ))) ⟩
stepL (λ β → MultL κ (mapL κ (λ ys → stepL (λ α → distlawLcL κ (x α ∷ ys))) (y β))) ∎
multlawLcL2 : {A : Set} (κ : Cl) → ∀(xs : List (myLift (myLift A κ) κ)) → distlawLcL κ (map (MultL κ) xs) ≡
MultL κ (mapL κ (distlawLcL κ) (distlawLcL κ xs))
multlawLcL2 κ [] = refl
multlawLcL2 κ (nowL (nowL x) ∷ xs) = distlawLcL κ ((nowL x) ∷ map (MultL κ) xs)
≡⟨ refl ⟩
mapL κ (λ ys → x ∷ ys) (distlawLcL κ (map (MultL κ) xs))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (multlawLcL2 κ xs) ⟩
mapL κ (λ ys → x ∷ ys) (MultL κ (mapL κ (distlawLcL κ) (distlawLcL κ xs)))
≡⟨ MultMap κ (mapL κ (distlawLcL κ) (distlawLcL κ xs)) (λ ys → x ∷ ys) ⟩
MultL κ (mapL κ (mapL κ (λ ys → x ∷ ys)) (mapL κ (distlawLcL κ) (distlawLcL κ xs)) )
≡⟨ cong (MultL κ) (mapmapL κ ((distlawLcL κ)) (mapL κ (λ ys → x ∷ ys)) ((distlawLcL κ xs))) ⟩
MultL κ (mapL κ (λ ys → mapL κ (λ zs → x ∷ zs) (distlawLcL κ ys)) (distlawLcL κ xs))
≡⟨ refl ⟩
MultL κ (mapL κ (λ ys → (distlawLcL κ) ((nowL x) ∷ ys)) (distlawLcL κ xs))
≡⟨ cong (MultL κ) (sym (mapmapL κ ((λ ys → (nowL x) ∷ ys)) ((distlawLcL κ)) ((distlawLcL κ xs)))) ⟩
MultL κ (mapL κ (distlawLcL κ) (mapL κ (λ ys → (nowL x) ∷ ys) (distlawLcL κ xs))) ∎
multlawLcL2 κ (nowL (stepL x) ∷ xs) = distlawLcL κ ((stepL x) ∷ map (MultL κ) xs)
≡⟨ refl ⟩
stepL (λ α → distlawLcL κ (x α ∷ map (MultL κ) xs))
≡⟨ refl ⟩
stepL (λ α → distlawLcL κ (map (MultL κ) ((nowL (x α)) ∷ xs)))
≡⟨ (\ i → stepL (\ α → multlawLcL2 κ (((nowL (x α)) ∷ xs)) i )) ⟩
stepL (λ α → MultL κ (mapL κ (distlawLcL κ) (distlawLcL κ ((nowL (x α) ∷ xs)))) )
≡⟨ refl ⟩
MultL κ (stepL (λ α → (mapL κ (distlawLcL κ) (distlawLcL κ ((nowL (x α) ∷ xs))))))
≡⟨ refl ⟩
MultL κ (stepL (λ α → (mapL κ (distlawLcL κ) (mapL κ (λ ys → x α ∷ ys) (distlawLcL κ xs)))))
≡⟨ cong (MultL κ) ((λ i → stepL (\ α → (mapmapL κ ((λ ys → x α ∷ ys)) ((distlawLcL κ)) ((distlawLcL κ xs))) i ))) ⟩
MultL κ (stepL (λ α → (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (distlawLcL κ xs))))
≡⟨ lemma9 κ x (distlawLcL κ xs) ⟩
MultL κ (mapL κ (λ ys → stepL (λ α → distlawLcL κ (x α ∷ ys))) (distlawLcL κ xs))
≡⟨ refl ⟩
MultL κ (mapL κ (λ ys → (distlawLcL κ) ((stepL x) ∷ ys)) (distlawLcL κ xs))
≡⟨ cong (MultL κ) (sym (mapmapL κ ((λ ys → (stepL x) ∷ ys)) ((distlawLcL κ)) ((distlawLcL κ xs)))) ⟩
MultL κ (mapL κ (distlawLcL κ) (mapL κ (λ ys → (stepL x) ∷ ys) (distlawLcL κ xs))) ∎
multlawLcL2 κ (stepL x ∷ xs) = (\ i → stepL (\ α → multlawLcL2 κ ((x α ∷ xs)) i ))
-- Bonusmaterial:
-- we define a union on LcL.
_l∪l_ : {A : Set} {κ : Cl} → (LcL A κ) → (LcL A κ) → (LcL A κ)
nowL x l∪l nowL y = nowL (x ++ y)
nowL x l∪l stepL y = stepL (\ α → (nowL x l∪l (y α)))
stepL x l∪l y = stepL (\ α → ((x α) l∪l y))
--nowL [] is a unit for l∪l
left-unitl∪l : {A : Set} {κ : Cl} → ∀(x : LcL A κ) → (nowL []) l∪l x ≡ x
left-unitl∪l (nowL x) = refl
left-unitl∪l (stepL x) = stepL (λ α → nowL [] l∪l x α)
≡⟨ ((\ i → stepL (\ α → left-unitl∪l (x α) i ))) ⟩
stepL (λ α → x α)
≡⟨ refl ⟩
stepL x ∎
right-unitl∪l : {A : Set} {κ : Cl} → ∀(x : LcL A κ) → x l∪l (nowL []) ≡ x
right-unitl∪l (nowL x) = cong nowL (++-unit-r x)
right-unitl∪l (stepL x) = stepL (λ α → x α l∪l nowL [])
≡⟨ ((\ i → stepL (\ α → right-unitl∪l (x α) i ))) ⟩
stepL (λ α → x α)
≡⟨ refl ⟩
stepL x ∎
--mapL κ f distributes over l∪l if f distributes over ++
dist-mapL-l∪l : {A B : Set} (κ : Cl) → ∀(f : (List A) → (List B)) → ∀(fcom : ∀(xs : List A) → ∀(ys : List A) → f (xs ++ ys) ≡ f xs ++ f ys) →
∀(x : (LcL A κ)) → ∀(y : LcL A κ) → mapL κ f (x l∪l y) ≡ (mapL κ f x) l∪l (mapL κ f y)
dist-mapL-l∪l κ f fcom (nowL x) (nowL y) = cong nowL (fcom x y)
dist-mapL-l∪l κ f fcom (nowL x) (stepL y) = (\ i → stepL (\ α → dist-mapL-l∪l κ f fcom (nowL x) (y α) i ))
dist-mapL-l∪l κ f fcom (stepL x) y = \ i → stepL (\ α → dist-mapL-l∪l κ f fcom (x α) y i )
| 59.225225 | 179 | 0.461946 |
dc8845e48846199c7c070ff87390e0316080a65d | 475 | agda | Agda | test/interaction/Issue1523.agda | cagix/agda | cc026a6a97a3e517bb94bafa9d49233b067c7559 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/interaction/Issue1523.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/interaction/Issue1523.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | -- Andreas, 2015-07-22 Fixed bug in test for empty type of sizes
{-# OPTIONS --copatterns --sized-types #-}
open import Common.Size
record U (i : Size) : Set where
coinductive
field out : (j : Size< i) → U j
open U
fixU : {A : Size → Set} (let C = λ i → A i → U i)
→ ∀ i (f : ∀ i → (∀ (j : Size< i) → C j) → C i) → C i
out (fixU i f a) j = out (f i {!λ (j : Size< i) → fixU j f!} a) j
-- Giving should succeed (even if termination checking might not succeed yet)
| 27.941176 | 77 | 0.583158 |
20be4f0630f18af1ca5786bcecfc58203b373d8f | 545 | agda | Agda | test/Succeed/Issue2329.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2015-03-28T14:51:03.000Z | 2015-12-07T20:14:00.000Z | test/Succeed/Issue2329.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 3 | 2018-11-14T15:31:44.000Z | 2019-04-01T19:39:26.000Z | test/Succeed/Issue2329.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z | -- Andreas, 2017-01-20, issue #2329
-- Neutral sizes cannot be used by the size solver,
-- thus, should be handled by coerceSize.
-- {-# OPTIONS -v tc:10 #-}
-- {-# OPTIONS -v tc.conv.coerce:20 #-}
-- {-# OPTIONS -v tc.size:20 #-}
-- {-# OPTIONS -v tc.size.solve:50 #-}
open import Agda.Builtin.Size
record R (i : Size) : Set where
field
j : Size< i
postulate
f : ∀ i → R i
works : ∀ i → R i
R.j (works i) = R.j {i} (f i)
test : ∀ i → R i
R.j (test i) = R.j (f i)
-- Error WAS:
-- Unsolved constraint:
-- ↑ R.j (f i) =< i : Size
| 18.793103 | 51 | 0.565138 |
20c5c2889eb20637c3f055250391b58e4596de46 | 1,556 | agda | Agda | src/Dodo/Binary/Maximal.agda | sourcedennis/agda-dodo | 376f0ccee1e1aa31470890e494bcb534324f598a | [
"BSD-3-Clause"
] | null | null | null | src/Dodo/Binary/Maximal.agda | sourcedennis/agda-dodo | 376f0ccee1e1aa31470890e494bcb534324f598a | [
"BSD-3-Clause"
] | null | null | null | src/Dodo/Binary/Maximal.agda | sourcedennis/agda-dodo | 376f0ccee1e1aa31470890e494bcb534324f598a | [
"BSD-3-Clause"
] | null | null | null | {-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Maximal where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Function using (_∘_)
open import Data.Product using (_,_; ∃-syntax)
open import Data.Empty using (⊥-elim)
open import Relation.Nullary using (¬_)
open import Relation.Unary using (Pred)
open import Relation.Binary using (Rel)
open import Relation.Binary using (Trichotomous; tri<; tri≈; tri>)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Unary.Unique
open import Dodo.Binary.Equality
-- # Definitions #
maximal : ∀ {a ℓ : Level} {A : Set a}
→ Rel A ℓ
--------------
→ Pred A (a ⊔ ℓ)
maximal r = λ x → ¬ (∃[ y ] r x y)
-- # Properties #
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {≈ : Rel A ℓ₁} {< : Rel A ℓ₂} where
max-unique-tri : Trichotomous ≈ < → Unique₁ ≈ (maximal <)
max-unique-tri tri {x} {y} ¬∃z[x<z] ¬∃z[y<z] with tri x y
... | tri< x<y _ _ = ⊥-elim (¬∃z[x<z] (y , x<y))
... | tri≈ _ x≈y _ = x≈y
... | tri> _ _ y<x = ⊥-elim (¬∃z[y<z] (x , y<x))
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where
max-flips-⊆ : P ⊆₂ Q → maximal Q ⊆₁ maximal P
max-flips-⊆ P⊆Q = ⊆: lemma
where
lemma : maximal Q ⊆₁' maximal P
lemma x ¬∃zQxz (z , Pxz) = ¬∃zQxz (z , ⊆₂-apply P⊆Q Pxz)
module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {P : Rel A ℓ₁} {Q : Rel A ℓ₂} where
max-preserves-⇔ : P ⇔₂ Q → maximal P ⇔₁ maximal Q
max-preserves-⇔ = ⇔₁-sym ∘ ⇔₁-compose-⇔₂ max-flips-⊆ max-flips-⊆
| 29.358491 | 75 | 0.568123 |
18a60b11fa16fcabeb708d228c01e7a98ed194a1 | 643 | agda | Agda | test/succeed/ListsWithIrrelevantProofs.agda | masondesu/agda | 70c8a575c46f6a568c7518150a1a64fcd03aa437 | [
"MIT"
] | 1 | 2018-10-10T17:08:44.000Z | 2018-10-10T17:08:44.000Z | test/succeed/ListsWithIrrelevantProofs.agda | masondesu/agda | 70c8a575c46f6a568c7518150a1a64fcd03aa437 | [
"MIT"
] | null | null | null | test/succeed/ListsWithIrrelevantProofs.agda | masondesu/agda | 70c8a575c46f6a568c7518150a1a64fcd03aa437 | [
"MIT"
] | null | null | null | module ListsWithIrrelevantProofs where
data _≡_ {A : Set}(a : A) : A → Set where
refl : a ≡ a
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
postulate
_≤_ : ℕ → ℕ → Set
p1 : 0 ≤ 1
p2 : 0 ≤ 1
-- descending lists indexed by upper bound for largest element
data SList (bound : ℕ) : Set where
[] : SList bound
scons : (head : ℕ) →
.(head ≤ bound) → -- irrelevant proof, dotted non-dependent domain
(tail : SList head) →
SList bound
l1 : SList 1
l1 = scons 0 p1 []
l2 : SList 1
l2 = scons 0 p2 []
-- proofs in list are irrelevant
l1≡l2 : l1 ≡ l2
l1≡l2 = refl
| 16.921053 | 78 | 0.570762 |
0e905285b1628b873b394f7585c4df4e70aaaff8 | 6,349 | agda | Agda | Languages/Stream.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | Languages/Stream.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | Languages/Stream.agda | hbasold/Sandbox | 8fc7a6cd878f37f9595124ee8dea62258da28aa4 | [
"MIT"
] | null | null | null | {-# OPTIONS --copatterns --sized-types #-}
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
open import Data.List using (List; module List; []; _∷_; _++_; length)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product renaming (map to pmap)
open import Relations
-- Sized streams via head/tail.
record Stream {i : Size} (A : Set) : Set where
coinductive
constructor _∷_
field
hd : A
tl : ∀ {j : Size< i} → Stream {j} A
open Stream public
-- Shorthand
Str = Stream
tl' : ∀ {A} → Str A → Str A
tl' s = tl s {∞}
-- Constructor
scons : ∀{A} → A → Str A → Str A
hd (scons a s) = a
tl (scons a s) = s
-- | Corecursion
corec : ∀ {X A : Set} → (X → A) → (X → X) → (X → Str A)
hd (corec h s x) = h x
tl (corec h s x) = corec h s (s x)
-- Functoriality.
map : ∀ {i A B} (f : A → B) (s : Stream {i} A) → Stream {i} B
hd (map f s) = f (hd s)
tl (map {i} f s) {j} = map {j} f (tl s {j})
-- Derivative
δ : ∀{A} → ℕ → Stream A → Stream A
δ 0 s = s
δ (suc n) s = δ n (tl s)
-- Indexing
_at_ : ∀{A} → Stream A → ℕ → A
s at n = hd (δ n s)
fromStr = _at_
-- | Inverse for at
toStr : ∀ {A} → (ℕ → A) → Str A
hd (toStr f) = f 0
tl (toStr f) = toStr (λ n → f (suc n))
module Bisim (S : Setoid Level.zero Level.zero) where
infix 2 _∼_
open Setoid S renaming (Carrier to A; isEquivalence to S-equiv)
module SE = IsEquivalence S-equiv
-- Stream equality is bisimilarity
record _∼_ {i : Size} (s t : Stream A) : Set where
coinductive
field
hd≈ : hd s ≈ hd t
tl∼ : ∀ {j : Size< i} → _∼_ {j} (tl s) (tl t)
open _∼_ public
_∼[_]_ : Stream A → Size → Stream A → Set
s ∼[ i ] t = _∼_ {i} s t
s-bisim-refl : ∀ {i} {s : Stream A} → s ∼[ i ] s
hd≈ s-bisim-refl = SE.refl
tl∼ (s-bisim-refl {_} {s}) {j} = s-bisim-refl {j} {tl s}
s-bisim-sym : ∀ {i} {s t : Stream A} → s ∼[ i ] t → t ∼[ i ] s
hd≈ (s-bisim-sym p) = SE.sym (hd≈ p)
tl∼ (s-bisim-sym {_} {s} {t} p) {j} =
s-bisim-sym {j} {tl s} {tl t} (tl∼ p)
s-bisim-trans : ∀ {i} {r s t : Stream A} →
r ∼[ i ] s → s ∼[ i ] t → r ∼[ i ] t
hd≈ (s-bisim-trans p q) = SE.trans (hd≈ p) (hd≈ q)
tl∼ (s-bisim-trans {_} {r} {s} {t} p q) {j} =
s-bisim-trans {j} {tl r} {tl s} {tl t} (tl∼ p) (tl∼ q)
stream-setoid : Setoid _ _
stream-setoid = record
{ Carrier = Stream A
; _≈_ = _∼_
; isEquivalence = record
{ refl = s-bisim-refl
; sym = s-bisim-sym
; trans = s-bisim-trans
}
}
import Relation.Binary.EqReasoning as EqR
module ∼-Reasoning where
module _ where
open EqR (stream-setoid) public
hiding (_≡⟨_⟩_) renaming (_≈⟨_⟩_ to _∼⟨_⟩_; begin_ to begin_; _∎ to _∎)
-- | As usual, bisimilarity implies equality at every index.
bisim→ext-≡ : ∀ {s t : Stream A} → s ∼ t → ∀ {n} → s at n ≈ t at n
bisim→ext-≡ p {zero} = hd≈ p
bisim→ext-≡ p {suc n} = bisim→ext-≡ (tl∼ p) {n}
-- | Definition of bisimulation
isBisim : Rel (Str A) Level.zero → Set
isBisim R =
(s t : Str A) → R s t → (hd s ≈ hd t) × R (tl s) (tl t)
-- | Bisimulation proof principle
∃-bisim→∼ : ∀ {R} → isBisim R → (s t : Str A) → R s t → s ∼ t
hd≈ (∃-bisim→∼ R-isBisim s t q) = proj₁ (R-isBisim s t q)
tl∼ (∃-bisim→∼ R-isBisim s t q) =
∃-bisim→∼ R-isBisim (tl s) (tl t) (proj₂ (R-isBisim s t q))
StrRel : Set₁
StrRel = Rel (Str A) Level.zero
-- | Relation transformer that characterises bisimulations
Φ : Rel (Str A) Level.zero → Rel (Str A) Level.zero
Φ R s t = (hd s ≈ hd t) × R (tl s) (tl t)
isBisim' : Rel (Str A) Level.zero → Set
isBisim' R = R ⇒ Φ R
isBisim'→isBisim : ∀ {R} → isBisim' R → isBisim R
isBisim'→isBisim p s t q = p q
Φ-compat : RelTrans (Str A) → Set₁
Φ-compat F = Monotone F × (∀ {R} → F (Φ R) ⇒ Φ (F R))
isBisim-upto : RelTrans (Str A) → Rel (Str A) Level.zero → Set
isBisim-upto F R = R ⇒ Φ (F R)
Φ-compat-pres-upto : {F : RelTrans (Str A)} (P : Φ-compat F) {R : StrRel} →
isBisim-upto F R → isBisim-upto F (F R)
Φ-compat-pres-upto (M , P) p = P ∘ (M p)
iterTrans : RelTrans (Str A) → ℕ → StrRel → StrRel
iterTrans F zero R = R
iterTrans F (suc n) R = iterTrans F n (F R)
-- Closure of up-to technique, which will be the the bisimulation we generate from it
bisimCls : RelTrans (Str A) → StrRel → StrRel
bisimCls F R s t = ∃ λ n → iterTrans F n R s t
clsIsBisim : {F : RelTrans (Str A)} (P : Φ-compat F) {R : StrRel} →
isBisim-upto F R → isBisim' (bisimCls F R)
clsIsBisim P p {s} {t} (zero , sRt) =
(proj₁ (p sRt) , 1 , proj₂ (p sRt))
clsIsBisim {F} (M , P) {R} p {s} {t} (suc n , inFIter) =
let
foo = clsIsBisim (M , P) {F R} (Φ-compat-pres-upto (M , P) p) (n , inFIter)
in (proj₁ foo , (pmap suc id) (proj₂ foo))
-- Compatible up-to techniques are sound
compat-sound : {F : RelTrans (Str A)} (P : Φ-compat F) {R : StrRel} →
isBisim-upto F R → (s t : Str A) → R s t → s ∼ t
compat-sound {F} P {R} p s t sRt =
∃-bisim→∼ (isBisim'→isBisim {bisimCls F R} (clsIsBisim P p))
s t (0 , sRt)
-- | Useful general up-to technique: the equivalence closure is Φ-compatible.
equivCls-compat : Φ-compat EquivCls
equivCls-compat = equivCls-monotone , compat
where
compat : {R : StrRel} → EquivCls (Φ R) ⇒ Φ (EquivCls R)
compat (cls-incl (h≈ , tR)) = (h≈ , cls-incl tR)
compat cls-refl = (SE.refl , cls-refl)
compat {R} (cls-sym p) =
let (h≈ , tR) = compat {R} p
in (SE.sym h≈ , cls-sym tR)
compat {R} (cls-trans p q) =
let (hx≈hy , txRty) = compat {R} p
(hy≈hz , tyRtz) = compat {R} q
in (SE.trans hx≈hy hy≈hz , cls-trans txRty tyRtz)
-- | Element repetition
repeat : ∀{A} → A → Stream A
hd (repeat a) = a
tl (repeat a) = repeat a
-- Streams and lists.
-- Prepending a list to a stream.
_++ˢ_ : ∀ {A} → List A → Stream A → Stream A
[] ++ˢ s = s
(a ∷ as) ++ˢ s = a ∷ (as ++ˢ s)
-- Taking an initial segment of a stream.
takeˢ : ∀ {A} (n : ℕ) (s : Stream A) → List A
takeˢ 0 s = []
takeˢ (suc n) s = hd s ∷ takeˢ n (tl s)
_↓_ : ∀ {A} (s : Stream A) (n : ℕ) → List A
s ↓ n = takeˢ n s
| 29.668224 | 87 | 0.54607 |
df43bde3501cf4582ae0edb2d98581adf0873da0 | 131 | agda | Agda | test/Fail/Issue216.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Fail/Issue216.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Fail/Issue216.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
-- Should fail with S i != i
module Issue216 where
open import Common.Level
Foo : {i : Level} → Set i
Foo {i} = (R : Set i) → R
| 14.555556 | 28 | 0.610687 |
39115d30831d7d1ea9dba4096d9dd27b3937a031 | 5,296 | agda | Agda | Chapter3/Formalization.agda | CodaFi/HoTT-Exercises | 3411b253b0a49a5f9c3301df175ae8ecdc563b12 | [
"MIT"
] | null | null | null | Chapter3/Formalization.agda | CodaFi/HoTT-Exercises | 3411b253b0a49a5f9c3301df175ae8ecdc563b12 | [
"MIT"
] | null | null | null | Chapter3/Formalization.agda | CodaFi/HoTT-Exercises | 3411b253b0a49a5f9c3301df175ae8ecdc563b12 | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K #-}
module Chapter3.Formalization where
-- Sets and n-types
-- ----------------
open import Data.Unit
open import Data.Empty
open import Data.Nat
open import Data.Sum
open import Relation.Nullary using (¬_)
open import Data.Bool
open import Data.Product
open import Basics
open import Relation.Equivalence.Univalence
open import Relation.Equality
open import Relation.Equality.Extensionality
open import Relation.Path.Operation
isSet : ∀ {a} → Set a → Set a
isSet A = (x y : A) (p q : x ≡ y) → p ≡ q
-- The only possible inhabitants of ⊤ is tt which means everything
-- is reflexivity.
is-1-set : isSet ⊤
is-1-set tt tt refl refl = refl
-- Ex falso quodlibet strikes again
is-0-set : isSet ⊥
is-0-set ()
hasDecEq : ∀ {i} → Set i → Set i
hasDecEq A = (x y : A) → (x ≡ y) ⊎ ¬ (x ≡ y)
decEqIsSet : ∀ {i}{A : Set i} → hasDecEq A → isSet A
decEqIsSet {A} d x y = {! !} -- TBD: Hedberg's Theorem
-- Natural numbers are also a set because every equality type is decidable.
-- Boy, it's a pain in the ass proving that, though.
is-ℕ-set : isSet ℕ
is-ℕ-set = decEqIsSet hasDecEq-ℕ where
hasDecEq-ℕ : hasDecEq ℕ
hasDecEq-ℕ zero zero = inj₁ refl
hasDecEq-ℕ zero (suc y) = inj₂ (λ ())
hasDecEq-ℕ (suc x) zero = inj₂ (λ ())
hasDecEq-ℕ (suc x) (suc y) with hasDecEq-ℕ x y
hasDecEq-ℕ (suc x) (suc y) | inj₁ x₁ = inj₁ (ap {f = suc} x₁)
hasDecEq-ℕ (suc x) (suc y) | inj₂ pnot = inj₂ (λ p → pnot (ap {f = remark} p)) where
remark : ℕ → ℕ
remark zero = 42
remark (suc n) = n
is-×-set : ∀ {a b}{A : Set a}{B : Set b} → isSet A → isSet B → isSet (A × B)
is-×-set SA SB x y p q = {! !}
is-1-type : ∀ {a} → Set a → Set a
is-1-type A = (x y : A) → (p q : x ≡ y) → (r s : p ≡ q) → r ≡ s
3-1-8 : ∀ {a}{A : Set a} → isSet A → is-1-type A
3-1-8 f x y p q r s = {! apd r !}
where
g : (q : x ≡ y) → (p ≡ q)
g q = f x y p q
3-1-9 : ¬ (isSet Set)
3-1-9 x = {! !} where
f : Bool → Bool
f false = true
f true = false
contra : ¬ (false ≡ true)
contra ()
lem : IsEquiv f
lem = record
{ from = f
; iso₁ = λ x → mlem {x}
; iso₂ = λ x → mlem {x}
} where
mlem : ∀ {x : Bool} → f (f x) ≡ x
mlem {false} = refl
mlem {true} = refl
not-double-neg : ∀ {A : Set} → (¬ (¬ A) → A) → ⊥
not-double-neg f = {! !} where
e : Bool ≃ Bool
e = e-equiv , record { from = e-equiv ; iso₁ = λ x → helper {x} ; iso₂ = λ x → helper {x} } where
e-equiv : Bool → Bool
e-equiv true = false
e-equiv false = true
helper : ∀ {x : Bool} → e-equiv (e-equiv x) ≡ x
helper {true} = refl
helper {false} = refl
-- 3-2-4 : (x : Bool) → ¬ (e x ≡ x)
-- 3-2-4 = ?
p : Bool ≡ Bool
p = {! ua e !}
not-lem : ∀ {A : Set} → ¬ (A ⊎ (¬ A))
not-lem {A} (inj₁ x) = not-double-neg (λ _ → x)
not-lem {A} (inj₂ w) = not-double-neg (λ x → ⊥-elim (x w))
-- This defines "mere propositions"
-- If all elements of P are connected by a path, then p contains no
-- higher homotopy.
--
-- "The adjective “mere” emphasizes that although any type may be regarded as a
-- proposition (which we prove by giving an inhabitant of it), a type that is a
-- mere proposition cannot usefully be regarded as any more than a proposition:
-- there is no additional information contained in a witness of its truth."
isProp : ∀ {a} → Set a → Set a
isProp P = (x y : P) → (x ≡ y)
top-is-prop : isProp ⊤
top-is-prop tt tt = refl
3-3-3 : ∀ {a b}{P : Set a}{Q : Set b} → (p : isProp P)(q : isProp Q) → (f : P → Q) → (g : Q → P) → P ≃ Q
3-3-3 p q f g = f , record
{ from = g
; iso₁ = λ x → p (g (f x)) x
; iso₂ = λ y → q (f (g y)) y
}
3-3-2 : ∀ {a}{P : Set a} → (p : isProp P) → (x₀ : P) → P ≃ ⊤
3-3-2 {_}{P} p x₀ = 3-3-3 p (top-is-prop) f g where
f : P → ⊤
f x = tt
g : ⊤ → P
g u = x₀
isProp-isSet : ∀ {a}{A : Set a} → isProp A → isSet A
isProp-isSet {_}{A} f x y p q = lem p ∙ lem q ⁻¹ where
g : (y : A) → x ≡ y
g y = f x y
-- Read bottom-to-top
lem : (p : x ≡ y) → p ≡ (g x ⁻¹ ∙ g y)
lem p = (ap {f = (λ z → z ∙ p)} (back-and-there-again {p = (g x)}) ⁻¹) -- we have p = g(x)−1 g(y) = q.
∙ (assoc (g x ⁻¹) (g x) p ⁻¹) -- and after a little convincing
∙ ap {f = (λ z → (g x ⁻¹) ∙ z)} -- which is to say that p = g(y)⁻¹ ∙ g(z)
( (2-11-2 x p (g x) ⁻¹) -- Hence by Lemma 2.11.2, we have g(y) ∙ p = g(z)
∙ (apd {f = g} p) -- we have apd(p) : p(g(y)) = g(z).
) -- Then for any y,z : A and p : y = z
isProp-is-prop : ∀ {a}{A : Set a} → isProp (isProp A)
isProp-is-prop f g = funext λ x →
funext λ y → isProp-isSet f _ _ (f x y) (g x y)
isSet-is-prop : ∀ {a}{A : Set a} → isProp (isSet A)
isSet-is-prop f g = funext λ x →
funext λ y →
funext λ p →
funext λ q → isProp-isSet (f x y) _ _ (f x y p q) (g x y p q)
3-5-1 : ∀ {a}{A : Set a} → (P : A → Set) → ({x : A} → isProp (P x)) → (u v : Σ[ x ∈ A ] P x) → (proj₁ u ≡ proj₁ v) → u ≡ v
3-5-1 P x u v p = {! !}
3-6-1 : ∀ {a b}{A : Set a}{B : Set b} → (isProp A) → (isProp B) → isProp (A × B)
3-6-1 PA PB px py = {! !}
3-6-2 : ∀ {a b}{A : Set a}{B : A → Set b}{x : A} → (isProp (B x)) → isProp ((x : A) → B x)
3-6-2 PPI f g = funext λ x → {! f x ≡ g x !}
| 31.337278 | 122 | 0.51926 |
c573dbad1d832f5089982df95bc455a8cea47bf9 | 9,110 | agda | Agda | Sets/IterativeSet/Oper/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | 6 | 2020-04-07T17:58:13.000Z | 2022-02-05T06:53:22.000Z | Sets/IterativeSet/Oper/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | Sets/IterativeSet/Oper/Proofs.agda | Lolirofle/stuff-in-agda | 70f4fba849f2fd779c5aaa5af122ccb6a5b271ba | [
"MIT"
] | null | null | null | module Sets.IterativeSet.Oper.Proofs where
import Lvl
open import Data
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.Either as Either using (_‖_)
open import Data.Tuple as Tuple using ()
open import Functional
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Relator.Equals using () renaming (_≡_ to Id ; [≡]-intro to intro)
open import Sets.IterativeSet.Oper
open import Sets.IterativeSet.Relator
open import Sets.IterativeSet.Relator.Proofs
open import Sets.IterativeSet
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Relator.Properties
open import Structure.Relator
open import Syntax.Function
open import Syntax.Transitivity
open import Type.Dependent
open import Type.Properties.Decidable
open import Type.Properties.Decidable.Proofs
module _ where
private variable {ℓ ℓ₁ ℓ₂} : Lvl.Level
open Iset
-- If there is an element in the empty set, then there exists an instance of the empty type by definition, and that is false by definition.
∅-membership : ∀{x : Iset{ℓ₁}} → (x ∉ ∅ {ℓ₂})
∅-membership ()
-- There is a bijection between (A ‖ B) and ∃{Lvl.Up Bool}(\{(Lvl.up 𝐹) → A ; (Lvl.up 𝑇) → B}).
pair-membership : ∀{a b x : Iset{ℓ}} → (x ∈ pair a b) ↔ (x ≡ a)∨(x ≡ b)
Tuple.left (pair-membership {a = a} {x}) ([∨]-introₗ p) = [∃]-intro (Lvl.up 𝐹) ⦃ p ⦄
Tuple.left (pair-membership {a = a} {x}) ([∨]-introᵣ p) = [∃]-intro (Lvl.up 𝑇) ⦃ p ⦄
Tuple.right (pair-membership {a = a} {x}) ([∃]-intro (Lvl.up 𝐹) ⦃ eq ⦄) = [∨]-introₗ eq
Tuple.right (pair-membership {a = a} {x}) ([∃]-intro (Lvl.up 𝑇) ⦃ eq ⦄) = [∨]-introᵣ eq
-- There is a bijection between (A) and ∃{Unit}(\{<> → A}).
singleton-membership : ∀{a x : Iset{ℓ}} → (x ∈ singleton(a)) ↔ (x ≡ a)
Tuple.left (singleton-membership {a = a} {x}) xin = [∃]-intro <> ⦃ xin ⦄
Tuple.right (singleton-membership {a = a} {x}) ([∃]-intro i ⦃ eq ⦄ ) = eq
[∪]-membership : ∀{A B x : Iset{ℓ}} → (x ∈ (A ∪ B)) ↔ (x ∈ A)∨(x ∈ B)
Tuple.left ([∪]-membership {A = A} {B} {x}) ([∨]-introₗ ([∃]-intro ia)) = [∃]-intro (Either.Left ia)
Tuple.left ([∪]-membership {A = A} {B} {x}) ([∨]-introᵣ ([∃]-intro ib)) = [∃]-intro (Either.Right ib)
Tuple.right ([∪]-membership {A = A} {B} {x}) ([∃]-intro ([∨]-introₗ ia)) = [∨]-introₗ ([∃]-intro ia)
Tuple.right ([∪]-membership {A = A} {B} {x}) ([∃]-intro ([∨]-introᵣ ib)) = [∨]-introᵣ ([∃]-intro ib)
[⋃]-membership : ∀{A x : Iset{ℓ}} → (x ∈ (⋃ A)) ↔ ∃(a ↦ (a ∈ A) ∧ (x ∈ a))
Σ.left (∃.witness (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA) _ ⦄))) = iA
Σ.right (∃.witness (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA ⦃ aA ⦄) ([∃]-intro ia) ⦄))) = _⊆_.map (Tuple.right aA) ia
∃.proof (Tuple.left ([⋃]-membership {A = A} {x}) ([∃]-intro a ⦃ [∧]-intro ([∃]-intro iA ⦃ aA ⦄) ([∃]-intro ia ⦃ xa ⦄) ⦄)) = [≡]-transitivity-raw xa ([⊆]-with-elem (sub₂(_≡_)(_⊆_) aA) {ia})
∃.witness (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)) = elem(A)(iA)
Tuple.left (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄))) = [∈]-of-elem {A = A}
∃.witness (Tuple.right (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)))) = ia
∃.proof (Tuple.right (∃.proof (Tuple.right ([⋃]-membership {A = A} {x}) ([∃]-intro (intro iA ia) ⦃ proof ⦄)))) = proof
module _ {A : Iset{ℓ}} where
open import Relator.Equals.Proofs.Equivalence using ([≡]-equiv)
instance _ = [≡]-equiv {T = Index(A)}
module _ {P : Index(A) → Stmt{ℓ}} where
indexFilter-elem-membershipₗ : ∀{i : Index(A)} → (elem(A)(i) ∈ indexFilter A P) ← P(i)
Σ.left (∃.witness ((indexFilter-elem-membershipₗ {i = i}) pi)) = i
Σ.right(∃.witness ((indexFilter-elem-membershipₗ {i = i}) pi)) = pi
Tuple.left (∃.proof (indexFilter-elem-membershipₗ pi)) = intro id [≡]-reflexivity-raw
Tuple.right (∃.proof (indexFilter-elem-membershipₗ pi)) = intro id [≡]-reflexivity-raw
module _
⦃ _ : Injective(elem A) ⦄ -- TODO: Is this satisfiable?
{P : Index(A) → Stmt{ℓ}}
⦃ unaryRelator-P : UnaryRelator(P) ⦄
where
indexFilter-elem-membership : ∀{i : Index(A)} → (elem(A)(i) ∈ indexFilter A P) ↔ P(i)
Tuple.left indexFilter-elem-membership = indexFilter-elem-membershipₗ
Tuple.right (indexFilter-elem-membership {i = i}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄) = substitute₁(P) (injective(elem A) (symmetry(_≡_) pp)) PiA
filter-elem-membership : ∀{A : Iset{ℓ}}{P} ⦃ _ : UnaryRelator(P) ⦄ {i : Index(A)} → (elem(A)(i) ∈ filter A P) ↔ P(elem(A)(i))
Tuple.left (filter-elem-membership {A = A}{P = P}) = indexFilter-elem-membershipₗ {A = A}{P = P ∘ elem(A)}
Tuple.right (filter-elem-membership {P = P}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄) = substitute₁(P) (symmetry(_≡_) pp) PiA
filter-membership : ∀{A : Iset{ℓ}}{P} ⦃ _ : UnaryRelator(P) ⦄ {x : Iset{ℓ}} → (x ∈ filter A P) ↔ ((x ∈ A) ∧ P(x))
∃.witness (Tuple.left(filter-membership {P = P}) ([∧]-intro ([∃]-intro i ⦃ p ⦄) pb)) = intro i (substitute₁(P) p pb)
∃.proof (Tuple.left(filter-membership) ([∧]-intro ([∃]-intro i ⦃ p ⦄) pb)) = p
∃.witness (Tuple.left (Tuple.right(filter-membership) ([∃]-intro (intro iA PiA) ⦃ pp ⦄))) = iA
∃.proof (Tuple.left (Tuple.right(filter-membership) ([∃]-intro (intro iA PiA) ⦃ pp ⦄))) = pp
Tuple.right (Tuple.right(filter-membership {P = P}) ([∃]-intro (intro iA PiA) ⦃ pp ⦄)) = substitute₁(P) (symmetry(_≡_) pp) PiA
mapSet-membership : ∀{A : Iset{ℓ}}{f} ⦃ _ : Function(f) ⦄ {y : Iset{ℓ}} → (y ∈ mapSet f(A)) ↔ ∃(x ↦ (x ∈ A) ∧ (y ≡ f(x)))
∃.witness (Tuple.left (mapSet-membership) ([∃]-intro x ⦃ [∧]-intro xA fxy ⦄)) = [∃]-witness xA
∃.proof (Tuple.left (mapSet-membership {A = A} {f = f} {y = y}) ([∃]-intro x ⦃ [∧]-intro xA fxy ⦄)) =
y 🝖[ _≡_ ]-[ fxy ]
f(x) 🝖[ _≡_ ]-[ congruence₁(f) ([∃]-proof xA) ]
f(elem(A) ([∃]-witness xA)) 🝖[ _≡_ ]-[]
elem (mapSet f(A)) ([∃]-witness xA) 🝖[ _≡_ ]-end
∃.witness (Tuple.right (mapSet-membership {A = A}) ([∃]-intro iA)) = elem(A) iA
Tuple.left (∃.proof (Tuple.right (mapSet-membership {A = A}) ([∃]-intro iA ⦃ p ⦄))) = [∈]-of-elem {A = A} {ia = iA}
Tuple.right (∃.proof (Tuple.right mapSet-membership ([∃]-intro iA ⦃ p ⦄))) = p
open import Logic.Classical
module _ ⦃ classical : ∀{ℓ}{P} → Classical{ℓ}(P) ⦄ where
instance _ = classical-to-decidable
instance _ = classical-to-decider
indexFilterBool-subset : ∀{A : Iset{ℓ}}{P} → (indexFilterBool A P ⊆ A)
_⊇_.map indexFilterBool-subset (intro iA _) = iA
_⊇_.proof (indexFilterBool-subset {ℓ = ℓ}{A = A}{P = P}) {intro iA (Lvl.up PiA)} =
elem (indexFilterBool A P) (intro iA (Lvl.up PiA)) 🝖[ _≡_ ]-[]
elem (indexFilter A (Lvl.Up ∘ IsTrue ∘ P)) (intro iA (Lvl.up PiA)) 🝖[ _≡_ ]-[]
elem A (Σ.left {B = Lvl.Up{ℓ} ∘ IsTrue ∘ P} (intro iA (Lvl.up PiA))) 🝖[ _≡_ ]-[]
elem A iA 🝖[ _≡_ ]-end
℘-membershipₗ : ∀{A : Iset{ℓ}}{B : Iset{ℓ}} → (B ∈ ℘(A)) ← (B ⊆ A)
∃.witness (℘-membershipₗ {A = A}{B = B} BA) iA = decide(0)(∃(iB ↦ Id(_⊆_.map BA iB) iA))
_⊇_.map (Tuple.left (∃.proof (℘-membershipₗ {A = A} {B = B} _))) (intro iA (Lvl.up mapiBiA)) = [∃]-witness([↔]-to-[←] decider-true mapiBiA)
_⊇_.proof (Tuple.left (∃.proof (℘-membershipₗ {ℓ = ℓ} {A = A} {B = B} BA))) {intro iA (Lvl.up mapiBiA)} =
elem (elem (℘ A) f) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]
elem (indexFilterBool A f) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]
elem (indexFilter A (Lvl.Up ∘ IsTrue ∘ f)) (intro iA (Lvl.up mapiBiA)) 🝖[ _≡_ ]-[]
elem A (Σ.left {B = Lvl.Up{ℓ} ∘ IsTrue ∘ f} (intro iA (Lvl.up mapiBiA))) 🝖[ _≡_ ]-[]
elem A iA 🝖[ _≡_ ]-[ [≡]-to-equivalence(congruence₁(elem A) ([∃]-proof emapiBiA)) ]-sym
elem A (_⊆_.map BA ([∃]-witness emapiBiA)) 🝖[ _≡_ ]-[ _⊆_.proof BA {[∃]-witness emapiBiA} ]-sym
elem B ([∃]-witness emapiBiA) 🝖[ _≡_ ]-end
where
f = \iA → decide(0)(∃(iB ↦ Id(_⊆_.map BA iB) iA))
emapiBiA = [↔]-to-[←] decider-true mapiBiA
open import Relator.Equals.Proofs.Equiv using ([≡]-to-equivalence)
_⊇_.map (Tuple.right (∃.proof (℘-membershipₗ {A = A} {B = B} BA))) iB = intro (_⊆_.map BA iB) (Lvl.up ([↔]-to-[→] decider-true ([∃]-intro iB ⦃ intro ⦄)))
_⊇_.proof (Tuple.right (∃.proof (℘-membershipₗ {A = A} {B = B} BA))) = _⊆_.proof BA
℘-membershipᵣ : ∀{A : Iset{ℓ}}{B : Iset{ℓ}} → (B ∈ ℘(A)) → (B ⊆ A)
℘-membershipᵣ ([∃]-intro witness ⦃ b≡indexFilterBool ⦄) = substitute₂ₗ(_⊆_) (symmetry(_≡_) b≡indexFilterBool) indexFilterBool-subset
℘-membership : ∀{A : Iset{ℓ}}{x : Iset{ℓ}} → (x ∈ ℘(A)) ↔ (x ⊆ A)
℘-membership = [↔]-intro ℘-membershipₗ ℘-membershipᵣ
| 64.15493 | 190 | 0.554007 |
399682558c63730eef0bf55acf28a4d523daeb5e | 253 | agda | Agda | test/Succeed/Issue5683.agda | MxmUrw/agda | 6ede01fa854c5472e54f7d1799ca2c08ed316129 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue5683.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue5683.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z |
open import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
postulate X : Set
variable x : X
data C : Σ X (λ x → x ≡ x) → Set where
mkC :
let
eq : x ≡ x -- don't generalize over x at eq
eq = refl {x = x}
in
C (x , eq)
| 16.866667 | 50 | 0.56917 |
dcfacdeee67a710d81c1876827ffeac891055452 | 2,582 | agda | Agda | Categories/Support/EqReasoning.agda | p-pavel/categories | e41aef56324a9f1f8cf3cd30b2db2f73e01066f2 | [
"BSD-3-Clause"
] | 1 | 2018-12-29T21:51:57.000Z | 2018-12-29T21:51:57.000Z | Categories/Support/EqReasoning.agda | p-pavel/categories | e41aef56324a9f1f8cf3cd30b2db2f73e01066f2 | [
"BSD-3-Clause"
] | null | null | null | Categories/Support/EqReasoning.agda | p-pavel/categories | e41aef56324a9f1f8cf3cd30b2db2f73e01066f2 | [
"BSD-3-Clause"
] | null | null | null | {-# OPTIONS --universe-polymorphism #-}
module Categories.Support.EqReasoning where
open import Categories.Support.Equivalence using (Setoid; module Setoid)
open import Relation.Binary.PropositionalEquality using () renaming (_≡_ to _≣_; trans to ≣-trans; sym to ≣-sym; refl to ≣-refl)
module SetoidReasoning {s₁ s₂} (S : Setoid s₁ s₂) where
open Setoid S
infix 4 _IsRelatedTo_
infix 1 begin_
infixr 2 _≈⟨_⟩_ _↓⟨_⟩_ _↑⟨_⟩_ _↓≣⟨_⟩_ _↑≣⟨_⟩_ _↕_
infix 3 _∎
-- This seemingly unnecessary type is used to make it possible to
-- infer arguments even if the underlying equality evaluates.
data _IsRelatedTo_ (x y : Carrier) : Set s₂ where
relTo : (x∼y : x ≈ y) → x IsRelatedTo y
.begin_ : ∀ {x y} → x IsRelatedTo y → x ≈ y
begin relTo x∼y = x∼y
._↓⟨_⟩_ : ∀ x {y z} → x ≈ y → y IsRelatedTo z → x IsRelatedTo z
_ ↓⟨ x∼y ⟩ relTo y∼z = relTo (trans x∼y y∼z)
-- where open IsEquivalence isEquivalence
._↑⟨_⟩_ : ∀ x {y z} → y ≈ x → y IsRelatedTo z → x IsRelatedTo z
_ ↑⟨ y∼x ⟩ relTo y∼z = relTo (trans (sym y∼x) y∼z)
-- where open IsEquivalence isEquivalence
-- the syntax of the ancients, for compatibility
._≈⟨_⟩_ : ∀ x {y z} → x ≈ y → y IsRelatedTo z → x IsRelatedTo z
_≈⟨_⟩_ = _↓⟨_⟩_
._↓≣⟨_⟩_ : ∀ x {y z} → x ≣ y → y IsRelatedTo z → x IsRelatedTo z
_ ↓≣⟨ ≣-refl ⟩ y∼z = y∼z
._↑≣⟨_⟩_ : ∀ x {y z} → y ≣ x → y IsRelatedTo z → x IsRelatedTo z
_ ↑≣⟨ ≣-refl ⟩ y∼z = y∼z
._↕_ : ∀ x {z} → x IsRelatedTo z → x IsRelatedTo z
_ ↕ x∼z = x∼z
._∎ : ∀ x → x IsRelatedTo x
_∎ _ = relTo refl
-- where open IsEquivalence isEquivalence
module ≣-reasoning {ℓ} (S : Set ℓ) where
infix 4 _IsRelatedTo_
infix 2 _∎
infixr 2 _≈⟨_⟩_
infixr 2 _↓⟨_⟩_
infixr 2 _↑⟨_⟩_
infixr 2 _↕_
infix 1 begin_
-- This seemingly unnecessary type is used to make it possible to
-- infer arguments even if the underlying equality evaluates.
data _IsRelatedTo_ (x y : S) : Set ℓ where
relTo : (x∼y : x ≣ y) → x IsRelatedTo y
begin_ : ∀ {x y} → x IsRelatedTo y → x ≣ y
begin relTo x∼y = x∼y
-- the syntax of the ancients, for compatibility
_≈⟨_⟩_ : ∀ x {y z} → x ≣ y → y IsRelatedTo z → x IsRelatedTo z
_ ≈⟨ x∼y ⟩ relTo y∼z = relTo (≣-trans x∼y y∼z)
_↓⟨_⟩_ : ∀ x {y z} → x ≣ y → y IsRelatedTo z → x IsRelatedTo z
_ ↓⟨ x∼y ⟩ relTo y∼z = relTo (≣-trans x∼y y∼z)
_↑⟨_⟩_ : ∀ x {y z} → y ≣ x → y IsRelatedTo z → x IsRelatedTo z
_ ↑⟨ y∼x ⟩ relTo y∼z = relTo (≣-trans (≣-sym y∼x) y∼z)
_↕_ : ∀ x {z} → x IsRelatedTo z → x IsRelatedTo z
_ ↕ x∼z = x∼z
_∎ : ∀ x → x IsRelatedTo x
_∎ _ = relTo ≣-refl
| 30.738095 | 128 | 0.60031 |
4a213ae0825e64637c78b95b88109a1bfb08ea1f | 269 | agda | Agda | archive/agda-1/PredicateName.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null | archive/agda-1/PredicateName.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | 1 | 2019-04-29T00:35:04.000Z | 2019-05-11T23:33:04.000Z | archive/agda-1/PredicateName.agda | m0davis/oscar | 52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb | [
"RSA-MD"
] | null | null | null |
module PredicateName where
open import OscarPrelude
record PredicateName : Set
where
constructor ⟨_⟩
field
name : Nat
open PredicateName public
instance EqPredicateName : Eq PredicateName
Eq._==_ EqPredicateName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
| 16.8125 | 66 | 0.747212 |
185e892390ce8b46d5a343286bffdfc5cc843fdf | 1,445 | agda | Agda | agda-stdlib-0.9/src/Data/Conat.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/Conat.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | null | null | null | agda-stdlib-0.9/src/Data/Conat.agda | qwe2/try-agda | 9d4c43b1609d3f085636376fdca73093481ab882 | [
"Apache-2.0"
] | null | null | null | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Coinductive "natural" numbers
------------------------------------------------------------------------
module Data.Conat where
open import Coinduction
open import Data.Nat using (ℕ; zero; suc)
open import Relation.Binary
------------------------------------------------------------------------
-- The type
data Coℕ : Set where
zero : Coℕ
suc : (n : ∞ Coℕ) → Coℕ
------------------------------------------------------------------------
-- Some operations
fromℕ : ℕ → Coℕ
fromℕ zero = zero
fromℕ (suc n) = suc (♯ fromℕ n)
∞ℕ : Coℕ
∞ℕ = suc (♯ ∞ℕ)
infixl 6 _+_
_+_ : Coℕ → Coℕ → Coℕ
zero + n = n
suc m + n = suc (♯ (♭ m + n))
------------------------------------------------------------------------
-- Equality
data _≈_ : Coℕ → Coℕ → Set where
zero : zero ≈ zero
suc : ∀ {m n} (m≈n : ∞ (♭ m ≈ ♭ n)) → suc m ≈ suc n
setoid : Setoid _ _
setoid = record
{ Carrier = Coℕ
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {zero} = zero
refl {suc n} = suc (♯ refl)
sym : Symmetric _≈_
sym zero = zero
sym (suc m≈n) = suc (♯ sym (♭ m≈n))
trans : Transitive _≈_
trans zero zero = zero
trans (suc m≈n) (suc n≈k) = suc (♯ trans (♭ m≈n) (♭ n≈k))
| 22.230769 | 72 | 0.393772 |
d054d023aa191431255484b87b08432dfbccd32f | 5,818 | agda | Agda | Cubical/Reflection/RecordEquiv.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Reflection/RecordEquiv.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | Cubical/Reflection/RecordEquiv.agda | L-TChen/cubical | 60226aacd7b386aef95d43a0c29c4eec996348a8 | [
"MIT"
] | null | null | null | {-
Reflection-based tools for converting between iterated record types, particularly between
record types and iterated Σ-types. Currently requires eta equality.
See end of file for examples.
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Reflection.RecordEquiv where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.List as List
open import Cubical.Data.Nat
open import Cubical.Data.Maybe
open import Cubical.Data.Sigma
import Agda.Builtin.Reflection as R
open import Cubical.Reflection.Base
Projections = List R.Name
-- Describes a correspondence between two iterated record types
Assoc = List (Projections × Projections)
-- Describes a correspondence between a record type and an iterated Σ-types;
-- more convenient than Assoc for this special case
data ΣFormat : Type where
leaf : R.Name → ΣFormat
_,_ : ΣFormat → ΣFormat → ΣFormat
infixr 4 _,_
module Internal where
flipAssoc : Assoc → Assoc
flipAssoc = List.map λ {p .fst → p .snd; p .snd → p .fst}
list→ΣFormat : List R.Name → Maybe ΣFormat
list→ΣFormat [] = nothing
list→ΣFormat (x ∷ []) = just (leaf x)
list→ΣFormat (x ∷ y ∷ xs) = map-Maybe (leaf x ,_) (list→ΣFormat (y ∷ xs))
recordName→ΣFormat : R.Name → R.TC (Maybe ΣFormat)
recordName→ΣFormat name = R.getDefinition name >>= go
where
go : R.Definition → R.TC (Maybe ΣFormat)
go (R.record-type c fs) = R.returnTC (list→ΣFormat (List.map (λ {(R.arg _ n) → n}) fs))
go _ = R.typeError (R.strErr "Not a record type name:" ∷ R.nameErr name ∷ [])
ΣFormat→Assoc : ΣFormat → Assoc
ΣFormat→Assoc = go []
where
go : List R.Name → ΣFormat → Assoc
go prefix (leaf fieldName) = [ prefix , [ fieldName ] ]
go prefix (sig₁ , sig₂) =
go (quote fst ∷ prefix) sig₁ ++ go (quote snd ∷ prefix) sig₂
MaybeΣFormat→Assoc : Maybe ΣFormat → Assoc
MaybeΣFormat→Assoc nothing = [ [] , [] ]
MaybeΣFormat→Assoc (just sig) = ΣFormat→Assoc sig
convertTerm : Assoc → R.Term → R.Term
convertTerm al term = R.pat-lam (List.map makeClause al) []
where
makeClause : Projections × Projections → R.Clause
makeClause (projl , projr) =
R.clause [] (goPat [] projr) (goTm projl)
where
goPat : List (R.Arg R.Pattern) → List R.Name → List (R.Arg R.Pattern)
goPat acc [] = acc
goPat acc (π ∷ projs) = goPat (varg (R.proj π) ∷ acc) projs
goTm : List R.Name → R.Term
goTm [] = term
goTm (π ∷ projs) = R.def π [ varg (goTm projs) ]
convertFun : Assoc → R.Term
convertFun al = vlam "ρ" (convertTerm al (v 0))
convertMacro : Assoc → R.Term → R.TC Unit
convertMacro al hole = R.unify hole (convertFun al)
equivMacro : Assoc → R.Term → R.TC Unit
equivMacro al hole =
newMeta R.unknown >>= λ hole₁ →
newMeta R.unknown >>= λ hole₂ →
let
iso : R.Term
iso =
R.pat-lam
( R.clause [] [ varg (R.proj (quote Iso.fun)) ] hole₁
∷ R.clause [] [ varg (R.proj (quote Iso.inv)) ] hole₂
∷ R.clause [] [ varg (R.proj (quote Iso.rightInv)) ] (vlam "_" (R.def (quote refl) []))
∷ R.clause [] [ varg (R.proj (quote Iso.leftInv)) ] (vlam "_" (R.def (quote refl) []))
∷ []
)
[]
in
R.unify hole (R.def (quote isoToEquiv) [ varg iso ]) >>
convertMacro al hole₁ >>
convertMacro (flipAssoc al) hole₂
open Internal
macro
-- ΣFormat → <Σ-Type> ≃ <RecordType>
Σ≃Record : ΣFormat → R.Term → R.TC Unit
Σ≃Record sig = equivMacro (ΣFormat→Assoc sig)
-- ΣFormat → <RecordType> ≃ <Σ-Type>
Record≃Σ : ΣFormat → R.Term → R.TC Unit
Record≃Σ sig = equivMacro (flipAssoc (ΣFormat→Assoc sig))
-- <RecordTypeName> → <Σ-Type> ≃ <RecordType>
FlatΣ≃Record : R.Name → R.Term → R.TC Unit
FlatΣ≃Record name hole =
recordName→ΣFormat name >>= λ sig →
equivMacro (MaybeΣFormat→Assoc sig) hole
-- <RecordTypeName> → <RecordType> ≃ <Σ-Type>
Record≃FlatΣ : R.Name → R.Term → R.TC Unit
Record≃FlatΣ name hole =
recordName→ΣFormat name >>= λ sig →
equivMacro (flipAssoc (MaybeΣFormat→Assoc sig)) hole
-- ΣFormat → <RecordType₁> ≃ <RecordType₂>
Record≃Record : Assoc → R.Term → R.TC Unit
Record≃Record = equivMacro
module Example where
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ'
record Example {A : Type ℓ} (B : A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
cool : A
fun : A
wow : B cool
open Example
{-
Example: Equivalence between a Σ-type and record type using FlatΣ≃Record
-}
Example0 : (Σ[ a ∈ A ] Σ[ a' ∈ A ] B a) ≃ Example B
Example0 = FlatΣ≃Record Example
Example0' : Example B ≃ (Σ[ a ∈ A ] Σ[ a' ∈ A ] B a)
Example0' = Record≃FlatΣ Example
Example0'' : Unit ≃ Unit -- any record with no fields is equivalent to unit
Example0'' = FlatΣ≃Record Unit
{-
Example: Equivalence between an arbitrarily arrange Σ-type and record type using Σ≃Record
-}
Example1 : (Σ[ p ∈ A × A ] B (p .snd)) ≃ Example B
Example1 =
Σ≃Record ((leaf (quote fun) , leaf (quote cool)) , leaf (quote wow))
{-
Example: Equivalence between arbitrary iterated record types (less convenient) using
Record≃Record
-}
record Inner {A : Type ℓ} (B : A → Type ℓ') (a : A) : Type (ℓ-max ℓ ℓ') where
field
fun' : A
wow' : B a
record Outer {A : Type ℓ} (B : A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
field
cool' : A
inner : B cool'
open Inner
open Outer
Example2 : Example B ≃ Outer (Inner B)
Example2 =
Record≃Record
( ([ quote cool ] , [ quote cool' ])
∷ ([ quote fun ] , (quote fun' ∷ quote inner ∷ []))
∷ ([ quote wow ] , (quote wow' ∷ quote inner ∷ []))
∷ []
)
| 29.532995 | 97 | 0.623926 |
231a43654a6cd07684fac0cbc45573f79f9f058d | 1,717 | agda | Agda | src/Algebra.agda | asr/alga | 01f5f9f53ea81f692215300744aa77e26d8bf332 | [
"MIT"
] | null | null | null | src/Algebra.agda | asr/alga | 01f5f9f53ea81f692215300744aa77e26d8bf332 | [
"MIT"
] | null | null | null | src/Algebra.agda | asr/alga | 01f5f9f53ea81f692215300744aa77e26d8bf332 | [
"MIT"
] | null | null | null | module Algebra where
-- Core graph construction primitives
data Graph (A : Set) : Set where
ε : Graph A -- Empty graph
v : A -> Graph A -- Graph comprising a single vertex
_+_ : Graph A -> Graph A -> Graph A -- Overlay two graphs
_*_ : Graph A -> Graph A -> Graph A -- Connect two graphs
infixl 4 _≡_
infixl 8 _+_
infixl 9 _*_
infix 10 _⊆_
-- Equational theory of graphs
data _≡_ {A} : (x y : Graph A) -> Set where
-- Equivalence relation
reflexivity : ∀ {x : Graph A} -> x ≡ x
symmetry : ∀ {x y : Graph A} -> x ≡ y -> y ≡ x
transitivity : ∀ {x y z : Graph A} -> x ≡ y -> y ≡ z -> x ≡ z
-- Congruence
+left-congruence : ∀ {x y z : Graph A} -> x ≡ y -> x + z ≡ y + z
+right-congruence : ∀ {x y z : Graph A} -> x ≡ y -> z + x ≡ z + y
*left-congruence : ∀ {x y z : Graph A} -> x ≡ y -> x * z ≡ y * z
*right-congruence : ∀ {x y z : Graph A} -> x ≡ y -> z * x ≡ z * y
-- Axioms of +
+commutativity : ∀ {x y : Graph A} -> x + y ≡ y + x
+associativity : ∀ {x y z : Graph A} -> x + (y + z) ≡ (x + y) + z
-- Axioms of *
*left-identity : ∀ {x : Graph A} -> ε * x ≡ x
*right-identity : ∀ {x : Graph A} -> x * ε ≡ x
*associativity : ∀ {x y z : Graph A} -> x * (y * z) ≡ (x * y) * z
-- Other axioms
left-distributivity : ∀ {x y z : Graph A} -> x * (y + z) ≡ x * y + x * z
right-distributivity : ∀ {x y z : Graph A} -> (x + y) * z ≡ x * z + y * z
decomposition : ∀ {x y z : Graph A} -> x * y * z ≡ x * y + x * z + y * z
-- Subgraph relation
_⊆_ : ∀ {A} -> Graph A -> Graph A -> Set
x ⊆ y = x + y ≡ y
| 38.155556 | 85 | 0.45661 |
df2673785dc63ce8d945613da1ed98346a036562 | 1,833 | agda | Agda | src/Tactic/Nat/Coprime.agda | jespercockx/agda-prelude | 1984cf0341835b2f7bfe678098bd57cfe16ea11f | [
"MIT"
] | null | null | null | src/Tactic/Nat/Coprime.agda | jespercockx/agda-prelude | 1984cf0341835b2f7bfe678098bd57cfe16ea11f | [
"MIT"
] | null | null | null | src/Tactic/Nat/Coprime.agda | jespercockx/agda-prelude | 1984cf0341835b2f7bfe678098bd57cfe16ea11f | [
"MIT"
] | null | null | null | -- Tactic for proving coprimality.
-- Finds Coprime hypotheses in the context.
module Tactic.Nat.Coprime where
import Agda.Builtin.Nat as Builtin
open import Prelude
open import Control.Monad.Zero
open import Control.Monad.State
open import Container.List
open import Container.Traversable
open import Numeric.Nat
open import Tactic.Reflection
open import Tactic.Reflection.Parse
open import Tactic.Reflection.Quote
open import Tactic.Nat.Coprime.Problem
open import Tactic.Nat.Coprime.Decide
open import Tactic.Nat.Coprime.Reflect
private
Proof : Problem → Env → Set
Proof Q ρ with canProve Q
... | true = ⟦ Q ⟧p ρ
... | false = ⊤
erasePrf : ∀ Q {ρ} → ⟦ Q ⟧p ρ → ⟦ Q ⟧p ρ
erasePrf ([] ⊨ a ⋈ b) Ξ = eraseEquality Ξ
erasePrf (ψ ∷ Γ ⊨ φ) Ξ = λ H → erasePrf (Γ ⊨ φ) (Ξ H)
proof : ∀ Q ρ → Proof Q ρ
proof Q ρ with canProve Q | sound Q
... | true | prf = erasePrf Q (prf refl ρ)
... | false | _ = _
-- For the error message
unquoteE : List Term → Exp → Term
unquoteE ρ (atom x) = fromMaybe (lit (nat 0)) (index ρ x)
unquoteE ρ (e ⊗ e₁) = def₂ (quote _*_) (unquoteE ρ e) (unquoteE ρ e₁)
unquoteF : List Term → Formula → Term
unquoteF ρ (a ⋈ b) = def₂ (quote Coprime) (unquoteE ρ a) (unquoteE ρ b)
macro
auto-coprime : Tactic
auto-coprime ?hole = withNormalisation true $ do
goal ← inferType ?hole
ensureNoMetas goal
cxt ← reverse <$> getContext
(_ , Hyps , Q) , ρ ← runParse (parseProblem (map unArg cxt) goal)
unify ?hole (def (quote proof) $ map vArg (` Q ∷ quotedEnv ρ ∷ Hyps))
<|> do
case Q of λ where
(Γ ⊨ φ) → typeError (strErr "Cannot prove" ∷
termErr (unquoteF ρ φ) ∷
strErr "from" ∷
punctuate (strErr "and") (map (termErr ∘ unquoteF ρ) Γ))
| 31.067797 | 87 | 0.624659 |
cb79f55a2d3744378695aa7f2e1e215003fb792a | 8,899 | agda | Agda | LibraBFT/Base/PKCS.agda | lisandrasilva/bft-consensus-agda-1 | b7dd98dd90d98fbb934ef8cb4f3314940986790d | [
"UPL-1.0"
] | null | null | null | LibraBFT/Base/PKCS.agda | lisandrasilva/bft-consensus-agda-1 | b7dd98dd90d98fbb934ef8cb4f3314940986790d | [
"UPL-1.0"
] | null | null | null | LibraBFT/Base/PKCS.agda | lisandrasilva/bft-consensus-agda-1 | b7dd98dd90d98fbb934ef8cb4f3314940986790d | [
"UPL-1.0"
] | null | null | null | {- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Lemmas
open import LibraBFT.Prelude
open import LibraBFT.Base.Encode
open import LibraBFT.Base.ByteString
-- This module contains a model of cryptographic signatures on
-- certain data structures, and creation and verification
-- thereof. These data structures, defined by the WithVerSig
-- type, can be optionally signed, and if they are signed, the
-- signature covers a ByteString derived from the data structure,
-- enabling support for signature that cover only (functions of)
-- specific parts of the data structure. The module also
-- contains some properties we have found useful in other
-- contexts, though they are not yet used in this repo.
module LibraBFT.Base.PKCS where
postulate -- valid assumption
signature-size : ℕ
Signature : Set
Signature = Σ ByteString (λ s → length s ≡ signature-size)
postulate -- valid assumptions
PK : Set
SK : Set
IsKeyPair : PK → SK → Set
_≟PK_ : (pk1 pk2 : PK) → Dec (pk1 ≡ pk2)
instance
enc-PK : Encoder PK
enc-SigMB : Encoder (Maybe Signature)
sign-raw : ByteString → SK → Signature
verify : ByteString → Signature → PK → Bool
-- We assume no "signature collisions", as represented by verify-pk-inj
verify-pk-inj : ∀{bs sig pk pk'}
→ verify bs sig pk ≡ true
→ verify bs sig pk' ≡ true
→ pk ≡ pk'
verify-bs-inj : ∀{bs bs' sig pk}
→ verify bs sig pk ≡ true
→ verify bs' sig pk ≡ true
→ bs ≡ bs'
verify-pi : ∀{bs sig pk}
→ (v1 : verify bs sig pk ≡ true)
→ (v2 : verify bs sig pk ≡ true)
→ v1 ≡ v2
verify-sign : ∀{bs pk sk}
→ IsKeyPair pk sk
→ verify bs (sign-raw bs sk) pk ≡ true
verify-fail : ∀{bs pk sk}
→ ¬ IsKeyPair pk sk
→ verify bs (sign-raw bs sk) pk ≡ false
-- We consider a PK to be (permanently) either honest or not,
-- respresented by the following postulate. This is relevant
-- in reasoning about possible behaviours of a modeled system.
-- Specifically, the secret key corresponding to an honest PK
-- is assumed not to be leaked, ensuring that cheaters cannot
-- forge new signatures for honest PKs. Furthermore, if a peer
-- is assigned we use possession
-- of an honest PK in a given epoch to modelWe will postulate that, among
-- the PKs chosen for a particular epoch, the number of them
-- that are dishonest is at most the number of faults to be
-- tolerated for that epoch. This definition is /meta/: the
-- information about which PKs are (dis)honest should never be
-- used by the implementation -- it is only for modeling and
-- proofs.
Meta-Dishonest-PK : PK → Set
Meta-Honest-PK : PK → Set
Meta-Honest-PK = ¬_ ∘ Meta-Dishonest-PK
-- A datatype C might that might carry values with
-- signatures should be an instance of 'WithSig' below.
record WithSig (C : Set) : Set₁ where
field
-- A decidable predicate indicates whether values have
-- been signed
Signed : C → Set
Signed-pi : ∀ (c : C)
→ (is1 : Signed c)
→ (is2 : Signed c)
→ is1 ≡ is2
isSigned? : (c : C) → Dec (Signed c)
-- Signed values must have a signature
signature : (c : C)(hasSig : Signed c) → Signature
-- All values must be /encoded/ into a ByteString that
-- is supposed to be verified against a signature.
signableFields : C → ByteString
open WithSig {{...}} public
sign : {C : Set} ⦃ ws : WithSig C ⦄ → C → SK → Signature
sign c = sign-raw (signableFields c)
Signature≡ : {C : Set} ⦃ ws : WithSig C ⦄ → C → Signature → Set
Signature≡ c sig = Σ (Signed c) (λ s → signature c s ≡ sig)
-- A value of a datatype C can have its signature
-- verified; A value of type WithVerSig c is a proof of that.
-- Hence; the set (Σ C WithVerSig) is the set of values of
-- type C with verified signatures.
record WithVerSig {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) : Set where
constructor mkWithVerSig
field
isSigned : Signed c
verified : verify (signableFields c) (signature c isSigned) pk
≡ true
open WithVerSig public
ver-signature : ∀{C pk}⦃ ws : WithSig C ⦄{c : C} → WithVerSig pk c → Signature
ver-signature {c = c} wvs = signature c (isSigned wvs)
verCast : {C : Set} ⦃ ws : WithSig C ⦄ {c : C} {is1 is2 : Signed c} {pk1 pk2 : PK}
→ verify (signableFields c) (signature c is1) pk1 ≡ true
→ pk1 ≡ pk2
→ is1 ≡ is2
→ verify (signableFields c) (signature c is2) pk2 ≡ true
verCast prf refl refl = prf
wvsCast : {C : Set} ⦃ ws : WithSig C ⦄ {c : C} {pk1 pk2 : PK}
→ WithVerSig pk1 c
→ pk2 ≡ pk1
→ WithVerSig pk2 c
wvsCast {c = c} wvs refl = wvs
withVerSig-≡ : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ {wvs1 : WithVerSig pk c}
→ {wvs2 : WithVerSig pk c}
→ isSigned wvs1 ≡ isSigned wvs2
→ wvs1 ≡ wvs2
withVerSig-≡ {wvs1 = wvs1} {wvs2 = wvs2} refl
with verified wvs2 | inspect verified wvs2 | verCast (verified wvs1) refl refl
...| vwvs2 | [ R ] | vwvs1 rewrite verify-pi vwvs1 vwvs2 | sym R = refl
withVerSig-pi : {C : Set} {pk : PK} {c : C} ⦃ ws : WithSig C ⦄
→ (wvs1 : WithVerSig pk c)
→ (wvs2 : WithVerSig pk c)
→ wvs2 ≡ wvs1
withVerSig-pi {C} {pk} {c} ⦃ ws ⦄ wvs2 wvs1
with isSigned? c
...| no ¬Signed = ⊥-elim (¬Signed (isSigned wvs1))
...| yes sc = withVerSig-≡ {wvs1 = wvs1} {wvs2 = wvs2} (Signed-pi c (isSigned wvs1) (isSigned wvs2))
data SigCheckResult {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) : Set where
notSigned : ¬ Signed c → SigCheckResult pk c
checkFailed : (sc : Signed c) → verify (signableFields c) (signature c sc) pk ≡ false → SigCheckResult pk c
sigVerified : WithVerSig pk c → SigCheckResult pk c
checkFailed≢sigVerified : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
{wvs : WithVerSig ⦃ ws ⦄ pk c}
{sc : Signed c} {v : verify (signableFields c) (signature c sc) pk ≡ false}
→ checkFailed sc v ≡ sigVerified wvs → ⊥
checkFailed≢sigVerified ()
data SigCheckOutcome : Set where
notSigned : SigCheckOutcome
checkFailed : SigCheckOutcome
sigVerified : SigCheckOutcome
data SigCheckFailed : Set where
notSigned : SigCheckFailed
checkFailed : SigCheckFailed
check-signature : {C : Set} ⦃ ws : WithSig C ⦄ → (pk : PK) → (c : C) → SigCheckResult pk c
check-signature pk c with isSigned? c
...| no ns = notSigned ns
...| yes sc with verify (signableFields c) (signature c sc) pk
| inspect (verify (signableFields c) (signature c sc)) pk
...| false | [ nv ] = checkFailed sc nv
...| true | [ v ] = sigVerified (record { isSigned = sc
; verified = v })
sigCheckOutcomeFor : {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) → SigCheckOutcome
sigCheckOutcomeFor pk c with check-signature pk c
...| notSigned _ = notSigned
...| checkFailed _ _ = checkFailed
...| sigVerified _ = sigVerified
sigVerifiedVerSigCS : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ sigCheckOutcomeFor pk c ≡ sigVerified
→ ∃[ wvs ] (check-signature ⦃ ws ⦄ pk c ≡ sigVerified wvs)
sigVerifiedVerSigCS {pk = pk} {c = c} prf
with check-signature pk c | inspect
(check-signature pk) c
...| sigVerified verSig | [ R ] rewrite R = verSig , refl
sigVerifiedVerSig : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ sigCheckOutcomeFor pk c ≡ sigVerified
→ WithVerSig pk c
sigVerifiedVerSig = proj₁ ∘ sigVerifiedVerSigCS
sigVerifiedSCO : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ (wvs : WithVerSig pk c)
→ sigCheckOutcomeFor pk c ≡ sigVerified
sigVerifiedSCO {pk = pk} {c = c} wvs
with check-signature pk c
...| notSigned ns = ⊥-elim (ns (isSigned wvs))
...| checkFailed xx xxs rewrite Signed-pi c xx (isSigned wvs) = ⊥-elim (false≢true (trans (sym xxs) (verified wvs)))
...| sigVerified wvs' = refl
failedSigCheckOutcome : {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C)
→ sigCheckOutcomeFor pk c ≢ sigVerified
→ SigCheckFailed
failedSigCheckOutcome pk c prf with sigCheckOutcomeFor pk c
...| notSigned = notSigned
...| checkFailed = checkFailed
...| sigVerified = ⊥-elim (prf refl)
| 40.085586 | 117 | 0.605461 |
20bea768640f454fa95cdebb541ab888f150597e | 4,342 | agda | Agda | Cubical/Algebra/CommAlgebra/Instances/Initial.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | 1 | 2021-10-31T17:32:49.000Z | 2021-10-31T17:32:49.000Z | Cubical/Algebra/CommAlgebra/Instances/Initial.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | Cubical/Algebra/CommAlgebra/Instances/Initial.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.Instances.Initial where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Unit
open import Cubical.Data.Sigma.Properties using (Σ≡Prop)
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Algebra.Base using (IsAlgebraHom)
open import Cubical.Algebra.Algebra.Properties
open import Cubical.Algebra.CommAlgebra
import Cubical.Algebra.Algebra.Properties
open AlgebraHoms
private
variable
ℓ : Level
module _ (R : CommRing ℓ) where
initialCAlg : CommAlgebra R ℓ
initialCAlg =
let open CommRingStr (snd R)
in (fst R , commalgebrastr _ _ _ _ _ (λ r x → r · x)
(makeIsCommAlgebra (isSetRing (CommRing→Ring R))
+Assoc +Rid +Rinv +Comm
·Assoc ·Lid
·Ldist+ ·Comm
(λ x y z → sym (·Assoc x y z)) ·Ldist+ ·Rdist+ ·Lid
λ x y z → sym (·Assoc x y z)))
module _ (A : CommAlgebra R ℓ) where
open CommAlgebraStr ⦃... ⦄
private
instance
_ : CommAlgebraStr R (fst A)
_ = snd A
_ : CommAlgebraStr R (fst R)
_ = snd initialCAlg
_*_ : fst R → (fst A) → (fst A)
r * a = CommAlgebraStr._⋆_ (snd A) r a
initialMap : CommAlgebraHom initialCAlg A
initialMap =
makeCommAlgebraHom {M = initialCAlg} {N = A}
(λ r → r * 1a)
(⋆-lid _)
(λ x y → ⋆-ldist x y 1a)
(λ x y → (x · y) * 1a ≡⟨ ⋆-assoc _ _ _ ⟩
x * (y * 1a) ≡[ i ]⟨ x * (·Lid (y * 1a) (~ i)) ⟩
x * (1a · (y * 1a)) ≡⟨ sym (⋆-lassoc _ _ _) ⟩
(x * 1a) · (y * 1a) ∎)
(λ r x → (r · x) * 1a ≡⟨ ⋆-assoc _ _ _ ⟩
(r * (x * 1a)) ∎)
initialMapEq : (f : CommAlgebraHom initialCAlg A)
→ f ≡ initialMap
initialMapEq f =
let open IsAlgebraHom (snd f)
in Σ≡Prop
(isPropIsCommAlgebraHom {M = initialCAlg} {N = A})
λ i x →
((fst f) x ≡⟨ cong (fst f) (sym (·Rid _)) ⟩
fst f (x · 1a) ≡⟨ pres⋆ x 1a ⟩
CommAlgebraStr._⋆_ (snd A) x (fst f 1a) ≡⟨ cong
(λ u → (snd A CommAlgebraStr.⋆ x) u)
pres1 ⟩
(CommAlgebraStr._⋆_ (snd A) x 1a) ∎) i
initialMapProp : (f g : CommAlgebraHom initialCAlg A)
→ f ≡ g
initialMapProp f g = initialMapEq f ∙ sym (initialMapEq g)
initialityIso : Iso (CommAlgebraHom initialCAlg A) (Unit* {ℓ = ℓ})
initialityIso = iso (λ _ → tt*)
(λ _ → initialMap)
(λ {tt*x → refl})
λ f → sym (initialMapEq f)
initialityPath : CommAlgebraHom initialCAlg A ≡ Unit*
initialityPath = isoToPath initialityIso
initialityContr : isContr (CommAlgebraHom initialCAlg A)
initialityContr = initialMap , λ ϕ → sym (initialMapEq ϕ)
{-
Show that any R-Algebra with the same universal property
as the initial R-Algebra, is isomorphic to the initial
R-Algebra.
-}
module _ (A : CommAlgebra R ℓ) where
equivByInitiality :
(isInitial : (B : CommAlgebra R ℓ) → isContr (CommAlgebraHom A B))
→ CommAlgebraEquiv A (initialCAlg)
equivByInitiality isInitial = isoToEquiv asIso , snd to
where
open CommAlgebraHoms
to : CommAlgebraHom A initialCAlg
to = fst (isInitial initialCAlg)
from : CommAlgebraHom initialCAlg A
from = initialMap A
asIso : Iso (fst A) (fst initialCAlg)
Iso.fun asIso = fst to
Iso.inv asIso = fst from
Iso.rightInv asIso =
λ x i → cong
fst
(isContr→isProp (initialityContr initialCAlg) (to ∘a from) (idCAlgHom initialCAlg))
i x
Iso.leftInv asIso =
λ x i → cong
fst
(isContr→isProp (isInitial A) (from ∘a to) (idCAlgHom A))
i x
| 35.300813 | 103 | 0.523722 |
c5c44d871f2af5567964f8225d192ff69831c6c1 | 11,413 | agda | Agda | src/data/lib/prim/Agda/Builtin/Reflection.agda | m-yac/agda | 2ad3956cf0fa043eaf87f6b1f34633995e658a1a | [
"BSD-3-Clause"
] | 1 | 2016-05-20T13:58:52.000Z | 2016-05-20T13:58:52.000Z | src/data/lib/prim/Agda/Builtin/Reflection.agda | m-yac/agda | 2ad3956cf0fa043eaf87f6b1f34633995e658a1a | [
"BSD-3-Clause"
] | 1 | 2015-09-15T15:49:15.000Z | 2015-09-15T15:49:15.000Z | src/data/lib/prim/Agda/Builtin/Reflection.agda | m-yac/agda | 2ad3956cf0fa043eaf87f6b1f34633995e658a1a | [
"BSD-3-Clause"
] | 1 | 2015-09-15T14:36:15.000Z | 2015-09-15T14:36:15.000Z | {-# OPTIONS --without-K --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Reflection where
open import Agda.Builtin.Unit
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat
open import Agda.Builtin.Word
open import Agda.Builtin.List
open import Agda.Builtin.String
open import Agda.Builtin.Char
open import Agda.Builtin.Float
open import Agda.Builtin.Int
open import Agda.Builtin.Sigma
-- Names --
postulate Name : Set
{-# BUILTIN QNAME Name #-}
primitive
primQNameEquality : Name → Name → Bool
primQNameLess : Name → Name → Bool
primShowQName : Name → String
-- Fixity --
data Associativity : Set where
left-assoc : Associativity
right-assoc : Associativity
non-assoc : Associativity
data Precedence : Set where
related : Float → Precedence
unrelated : Precedence
data Fixity : Set where
fixity : Associativity → Precedence → Fixity
{-# BUILTIN ASSOC Associativity #-}
{-# BUILTIN ASSOCLEFT left-assoc #-}
{-# BUILTIN ASSOCRIGHT right-assoc #-}
{-# BUILTIN ASSOCNON non-assoc #-}
{-# BUILTIN PRECEDENCE Precedence #-}
{-# BUILTIN PRECRELATED related #-}
{-# BUILTIN PRECUNRELATED unrelated #-}
{-# BUILTIN FIXITY Fixity #-}
{-# BUILTIN FIXITYFIXITY fixity #-}
{-# COMPILE GHC Associativity = data MAlonzo.RTE.Assoc (MAlonzo.RTE.LeftAssoc | MAlonzo.RTE.RightAssoc | MAlonzo.RTE.NonAssoc) #-}
{-# COMPILE GHC Precedence = data MAlonzo.RTE.Precedence (MAlonzo.RTE.Related | MAlonzo.RTE.Unrelated) #-}
{-# COMPILE GHC Fixity = data MAlonzo.RTE.Fixity (MAlonzo.RTE.Fixity) #-}
{-# COMPILE JS Associativity = function (x,v) { return v[x](); } #-}
{-# COMPILE JS left-assoc = "left-assoc" #-}
{-# COMPILE JS right-assoc = "right-assoc" #-}
{-# COMPILE JS non-assoc = "non-assoc" #-}
{-# COMPILE JS Precedence =
function (x,v) {
if (x === "unrelated") { return v[x](); } else { return v["related"](x); }} #-}
{-# COMPILE JS related = function(x) { return x; } #-}
{-# COMPILE JS unrelated = "unrelated" #-}
{-# COMPILE JS Fixity = function (x,v) { return v["fixity"](x["assoc"], x["prec"]); } #-}
{-# COMPILE JS fixity = function (x) { return function (y) { return { "assoc": x, "prec": y}; }; } #-}
primitive
primQNameFixity : Name → Fixity
primQNameToWord64s : Name → Σ Word64 (λ _ → Word64)
-- Metavariables --
postulate Meta : Set
{-# BUILTIN AGDAMETA Meta #-}
primitive
primMetaEquality : Meta → Meta → Bool
primMetaLess : Meta → Meta → Bool
primShowMeta : Meta → String
primMetaToNat : Meta → Nat
-- Arguments --
-- Arguments can be (visible), {hidden}, or {{instance}}.
data Visibility : Set where
visible hidden instance′ : Visibility
{-# BUILTIN HIDING Visibility #-}
{-# BUILTIN VISIBLE visible #-}
{-# BUILTIN HIDDEN hidden #-}
{-# BUILTIN INSTANCE instance′ #-}
-- Arguments can be relevant or irrelevant.
data Relevance : Set where
relevant irrelevant : Relevance
{-# BUILTIN RELEVANCE Relevance #-}
{-# BUILTIN RELEVANT relevant #-}
{-# BUILTIN IRRELEVANT irrelevant #-}
data ArgInfo : Set where
arg-info : (v : Visibility) (r : Relevance) → ArgInfo
data Arg {a} (A : Set a) : Set a where
arg : (i : ArgInfo) (x : A) → Arg A
{-# BUILTIN ARGINFO ArgInfo #-}
{-# BUILTIN ARGARGINFO arg-info #-}
{-# BUILTIN ARG Arg #-}
{-# BUILTIN ARGARG arg #-}
-- Name abstraction --
data Abs {a} (A : Set a) : Set a where
abs : (s : String) (x : A) → Abs A
{-# BUILTIN ABS Abs #-}
{-# BUILTIN ABSABS abs #-}
-- Literals --
data Literal : Set where
nat : (n : Nat) → Literal
word64 : (n : Word64) → Literal
float : (x : Float) → Literal
char : (c : Char) → Literal
string : (s : String) → Literal
name : (x : Name) → Literal
meta : (x : Meta) → Literal
{-# BUILTIN AGDALITERAL Literal #-}
{-# BUILTIN AGDALITNAT nat #-}
{-# BUILTIN AGDALITWORD64 word64 #-}
{-# BUILTIN AGDALITFLOAT float #-}
{-# BUILTIN AGDALITCHAR char #-}
{-# BUILTIN AGDALITSTRING string #-}
{-# BUILTIN AGDALITQNAME name #-}
{-# BUILTIN AGDALITMETA meta #-}
-- Patterns --
data Pattern : Set where
con : (c : Name) (ps : List (Arg Pattern)) → Pattern
dot : Pattern
var : (s : String) → Pattern
lit : (l : Literal) → Pattern
proj : (f : Name) → Pattern
absurd : Pattern
{-# BUILTIN AGDAPATTERN Pattern #-}
{-# BUILTIN AGDAPATCON con #-}
{-# BUILTIN AGDAPATDOT dot #-}
{-# BUILTIN AGDAPATVAR var #-}
{-# BUILTIN AGDAPATLIT lit #-}
{-# BUILTIN AGDAPATPROJ proj #-}
{-# BUILTIN AGDAPATABSURD absurd #-}
-- Terms --
data Sort : Set
data Clause : Set
data Term : Set
Type = Term
data Term where
var : (x : Nat) (args : List (Arg Term)) → Term
con : (c : Name) (args : List (Arg Term)) → Term
def : (f : Name) (args : List (Arg Term)) → Term
lam : (v : Visibility) (t : Abs Term) → Term
pat-lam : (cs : List Clause) (args : List (Arg Term)) → Term
pi : (a : Arg Type) (b : Abs Type) → Term
agda-sort : (s : Sort) → Term
lit : (l : Literal) → Term
meta : (x : Meta) → List (Arg Term) → Term
unknown : Term
data Sort where
set : (t : Term) → Sort
lit : (n : Nat) → Sort
unknown : Sort
data Clause where
clause : (ps : List (Arg Pattern)) (t : Term) → Clause
absurd-clause : (ps : List (Arg Pattern)) → Clause
{-# BUILTIN AGDASORT Sort #-}
{-# BUILTIN AGDATERM Term #-}
{-# BUILTIN AGDACLAUSE Clause #-}
{-# BUILTIN AGDATERMVAR var #-}
{-# BUILTIN AGDATERMCON con #-}
{-# BUILTIN AGDATERMDEF def #-}
{-# BUILTIN AGDATERMMETA meta #-}
{-# BUILTIN AGDATERMLAM lam #-}
{-# BUILTIN AGDATERMEXTLAM pat-lam #-}
{-# BUILTIN AGDATERMPI pi #-}
{-# BUILTIN AGDATERMSORT agda-sort #-}
{-# BUILTIN AGDATERMLIT lit #-}
{-# BUILTIN AGDATERMUNSUPPORTED unknown #-}
{-# BUILTIN AGDASORTSET set #-}
{-# BUILTIN AGDASORTLIT lit #-}
{-# BUILTIN AGDASORTUNSUPPORTED unknown #-}
{-# BUILTIN AGDACLAUSECLAUSE clause #-}
{-# BUILTIN AGDACLAUSEABSURD absurd-clause #-}
-- Definitions --
data Definition : Set where
function : (cs : List Clause) → Definition
data-type : (pars : Nat) (cs : List Name) → Definition
record-type : (c : Name) (fs : List (Arg Name)) → Definition
data-cons : (d : Name) → Definition
axiom : Definition
prim-fun : Definition
{-# BUILTIN AGDADEFINITION Definition #-}
{-# BUILTIN AGDADEFINITIONFUNDEF function #-}
{-# BUILTIN AGDADEFINITIONDATADEF data-type #-}
{-# BUILTIN AGDADEFINITIONRECORDDEF record-type #-}
{-# BUILTIN AGDADEFINITIONDATACONSTRUCTOR data-cons #-}
{-# BUILTIN AGDADEFINITIONPOSTULATE axiom #-}
{-# BUILTIN AGDADEFINITIONPRIMITIVE prim-fun #-}
-- Errors --
data ErrorPart : Set where
strErr : String → ErrorPart
termErr : Term → ErrorPart
nameErr : Name → ErrorPart
{-# BUILTIN AGDAERRORPART ErrorPart #-}
{-# BUILTIN AGDAERRORPARTSTRING strErr #-}
{-# BUILTIN AGDAERRORPARTTERM termErr #-}
{-# BUILTIN AGDAERRORPARTNAME nameErr #-}
-- TC monad --
postulate
TC : ∀ {a} → Set a → Set a
returnTC : ∀ {a} {A : Set a} → A → TC A
bindTC : ∀ {a b} {A : Set a} {B : Set b} → TC A → (A → TC B) → TC B
unify : Term → Term → TC ⊤
typeError : ∀ {a} {A : Set a} → List ErrorPart → TC A
inferType : Term → TC Type
checkType : Term → Type → TC Term
normalise : Term → TC Term
reduce : Term → TC Term
catchTC : ∀ {a} {A : Set a} → TC A → TC A → TC A
quoteTC : ∀ {a} {A : Set a} → A → TC Term
unquoteTC : ∀ {a} {A : Set a} → Term → TC A
getContext : TC (List (Arg Type))
extendContext : ∀ {a} {A : Set a} → Arg Type → TC A → TC A
inContext : ∀ {a} {A : Set a} → List (Arg Type) → TC A → TC A
freshName : String → TC Name
declareDef : Arg Name → Type → TC ⊤
declarePostulate : Arg Name → Type → TC ⊤
defineFun : Name → List Clause → TC ⊤
getType : Name → TC Type
getDefinition : Name → TC Definition
blockOnMeta : ∀ {a} {A : Set a} → Meta → TC A
commitTC : TC ⊤
isMacro : Name → TC Bool
-- If the argument is 'true' makes the following primitives also normalise
-- their results: inferType, checkType, quoteTC, getType, and getContext
withNormalisation : ∀ {a} {A : Set a} → Bool → TC A → TC A
-- Prints the third argument if the corresponding verbosity level is turned
-- on (with the -v flag to Agda).
debugPrint : String → Nat → List ErrorPart → TC ⊤
-- Fail if the given computation gives rise to new, unsolved
-- "blocking" constraints.
noConstraints : ∀ {a} {A : Set a} → TC A → TC A
-- Run the given TC action and return the first component. Resets to
-- the old TC state if the second component is 'false', or keep the
-- new TC state if it is 'true'.
runSpeculative : ∀ {a} {A : Set a} → TC (Σ A λ _ → Bool) → TC A
{-# BUILTIN AGDATCM TC #-}
{-# BUILTIN AGDATCMRETURN returnTC #-}
{-# BUILTIN AGDATCMBIND bindTC #-}
{-# BUILTIN AGDATCMUNIFY unify #-}
{-# BUILTIN AGDATCMTYPEERROR typeError #-}
{-# BUILTIN AGDATCMINFERTYPE inferType #-}
{-# BUILTIN AGDATCMCHECKTYPE checkType #-}
{-# BUILTIN AGDATCMNORMALISE normalise #-}
{-# BUILTIN AGDATCMREDUCE reduce #-}
{-# BUILTIN AGDATCMCATCHERROR catchTC #-}
{-# BUILTIN AGDATCMQUOTETERM quoteTC #-}
{-# BUILTIN AGDATCMUNQUOTETERM unquoteTC #-}
{-# BUILTIN AGDATCMGETCONTEXT getContext #-}
{-# BUILTIN AGDATCMEXTENDCONTEXT extendContext #-}
{-# BUILTIN AGDATCMINCONTEXT inContext #-}
{-# BUILTIN AGDATCMFRESHNAME freshName #-}
{-# BUILTIN AGDATCMDECLAREDEF declareDef #-}
{-# BUILTIN AGDATCMDECLAREPOSTULATE declarePostulate #-}
{-# BUILTIN AGDATCMDEFINEFUN defineFun #-}
{-# BUILTIN AGDATCMGETTYPE getType #-}
{-# BUILTIN AGDATCMGETDEFINITION getDefinition #-}
{-# BUILTIN AGDATCMBLOCKONMETA blockOnMeta #-}
{-# BUILTIN AGDATCMCOMMIT commitTC #-}
{-# BUILTIN AGDATCMISMACRO isMacro #-}
{-# BUILTIN AGDATCMWITHNORMALISATION withNormalisation #-}
{-# BUILTIN AGDATCMDEBUGPRINT debugPrint #-}
{-# BUILTIN AGDATCMNOCONSTRAINTS noConstraints #-}
{-# BUILTIN AGDATCMRUNSPECULATIVE runSpeculative #-}
| 36.231746 | 130 | 0.560852 |
d08280c309cac23987fa05fca0620c10d1b07452 | 139 | agda | Agda | Cubical/HITs/S2.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | 1 | 2021-10-31T17:32:49.000Z | 2021-10-31T17:32:49.000Z | Cubical/HITs/S2.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | Cubical/HITs/S2.agda | guilhermehas/cubical | ce3120d3f8d692847b2744162bcd7a01f0b687eb | [
"MIT"
] | null | null | null | {-# OPTIONS --safe #-}
module Cubical.HITs.S2 where
open import Cubical.HITs.S2.Base public
open import Cubical.HITs.S2.Properties public
| 23.166667 | 45 | 0.769784 |
23bf21b22da4fe31e4c13a7107fd068f89cd8b69 | 496 | agda | Agda | agda-stdlib/src/Relation/Unary/Consequences.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | agda-stdlib/src/Relation/Unary/Consequences.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | agda-stdlib/src/Relation/Unary/Consequences.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Some properties imply others
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Unary.Consequences where
open import Relation.Unary
open import Relation.Nullary using (recompute)
dec⟶recomputable : {a ℓ : _} {A : Set a} {P : Pred A ℓ} → Decidable P → Recomputable P
dec⟶recomputable P-dec = recompute (P-dec _)
| 31 | 86 | 0.504032 |
df20ced28adf78f2f5e4d9e4cf1bc6599b729ed5 | 120 | agda | Agda | examples/AIM6/RegExp/talk/Everything.agda | mdimjasevic/agda | 8fb548356b275c7a1e79b768b64511ae937c738b | [
"BSD-3-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | examples/AIM6/RegExp/talk/Everything.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | examples/AIM6/RegExp/talk/Everything.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module Everything where
import BoolMatcher
import Eq
import Prelude
import RegExps
import Setoids
import SimpleMatcher
| 13.333333 | 23 | 0.866667 |
d088c9bb77a3126ac1f372d3fe26182d0fbb0f04 | 1,970 | agda | Agda | Cubical/DStructures/Structures/Constant.agda | Schippmunk/cubical | c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a | [
"MIT"
] | null | null | null | Cubical/DStructures/Structures/Constant.agda | Schippmunk/cubical | c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a | [
"MIT"
] | null | null | null | Cubical/DStructures/Structures/Constant.agda | Schippmunk/cubical | c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a | [
"MIT"
] | null | null | null | {-
This module contains:
- constant displayed structures of URG structures
- products of URG structures
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.Constant where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.Relation.Binary
private
variable
ℓA ℓ≅A ℓB ℓ≅B ℓC ℓ≅C ℓ≅A×B : Level
-- The constant displayed structure of a URG structure 𝒮-B over 𝒮-A
𝒮ᴰ-const : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A)
{B : Type ℓB} (𝒮-B : URGStr B ℓ≅B)
→ URGStrᴰ 𝒮-A (λ _ → B) ℓ≅B
𝒮ᴰ-const {A = A} 𝒮-A {B} 𝒮-B
= urgstrᴰ (λ b _ b' → b ≅ b') ρ uni
where
open URGStr 𝒮-B
-- the total structure of the constant structure gives
-- nondependent product of URG structures
_×𝒮_ : {A : Type ℓA} (StrA : URGStr A ℓ≅A)
{B : Type ℓB} (StrB : URGStr B ℓ≅B)
→ URGStr (A × B) (ℓ-max ℓ≅A ℓ≅B)
_×𝒮_ StrA {B} StrB = ∫⟨ StrA ⟩ (𝒮ᴰ-const StrA StrB)
-- any displayed structure defined over a
-- structure on a product can also be defined
-- over the swapped product
×𝒮-swap : {A : Type ℓA} {B : Type ℓB} {C : A × B → Type ℓC}
{ℓ≅A×B ℓ≅ᴰ : Level}
{StrA×B : URGStr (A × B) ℓ≅A×B}
(StrCᴰ : URGStrᴰ StrA×B C ℓ≅ᴰ)
→ URGStrᴰ (𝒮-transport Σ-swap-≃ StrA×B)
(λ (b , a) → C (a , b))
ℓ≅ᴰ
×𝒮-swap {C = C} {ℓ≅ᴰ = ℓ≅ᴰ} {StrA×B = StrA×B} StrCᴰ =
make-𝒮ᴰ (λ c p c' → c ≅ᴰ⟨ p ⟩ c')
ρᴰ
λ (b , a) c → isUnivalent→contrRelSingl (λ c c' → c ≅ᴰ⟨ URGStr.ρ StrA×B (a , b) ⟩ c')
ρᴰ
uniᴰ
c
where
open URGStrᴰ StrCᴰ
| 31.269841 | 99 | 0.543655 |
1c8639b49402fe61ef4ce3b723d180ac2a043c7d | 1,927 | agda | Agda | src/Data/FingerTree/Split/Point.agda | oisdk/agda-indexed-fingertree | 39c3d96937384b052b782ffddf4fdec68c5d139f | [
"MIT"
] | 1 | 2019-02-26T07:04:54.000Z | 2019-02-26T07:04:54.000Z | src/Data/FingerTree/Split/Point.agda | oisdk/agda-indexed-fingertree | 39c3d96937384b052b782ffddf4fdec68c5d139f | [
"MIT"
] | null | null | null | src/Data/FingerTree/Split/Point.agda | oisdk/agda-indexed-fingertree | 39c3d96937384b052b782ffddf4fdec68c5d139f | [
"MIT"
] | null | null | null | {-# OPTIONS --without-K --safe #-}
open import Algebra
open import Relation.Unary
open import Relation.Binary hiding (Decidable)
module Data.FingerTree.Split.Point
{r m}
(ℳ : Monoid r m)
{s}
{ℙ : Pred (Monoid.Carrier ℳ) s}
(ℙ-resp : ℙ Respects (Monoid._≈_ ℳ))
(ℙ? : Decidable ℙ)
where
open import Relation.Nullary using (¬_; yes; no; Dec)
open import Level using (_⊔_)
open import Data.Product
open import Function
open import Data.List as List using (List; _∷_; [])
open import Data.FingerTree.Measures ℳ
open import Data.FingerTree.Reasoning ℳ
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Nullary.Decidable using (True; toWitness; False; toWitnessFalse)
open σ ⦃ ... ⦄
open Monoid ℳ renaming (Carrier to 𝓡)
open import Data.FingerTree.Relation.Binary.Reasoning.FasterInference.Setoid setoid
infixr 5 _∣_
record _∣_ (left focus : 𝓡) : Set s where
constructor ¬[_]ℙ[_]
field
¬ℙ : ¬ ℙ left
!ℙ : ℙ (left ∙ focus)
open _∣_ public
_∣?_ : ∀ x y → Dec (x ∣ y)
x ∣? y with ℙ? x
... | yes p = no λ c → ¬ℙ c p
... | no ¬p with ℙ? (x ∙ y)
... | no ¬c = no (¬c ∘ !ℙ)
... | yes p = yes ¬[ ¬p ]ℙ[ p ]
infixl 2 _≈◄⟅_⟆ _≈▻⟅_⟆ _≈⟅_∣_⟆ _◄_ _▻_
_◄_ : ∀ {l f₁ f₂} → l ∣ f₁ ∙ f₂ → ¬ ℙ (l ∙ f₁) → (l ∙ f₁) ∣ f₂
!ℙ (p ◄ ¬ℙf) = ℙ-resp (sym (assoc _ _ _)) (!ℙ p)
¬ℙ (p ◄ ¬ℙf) = ¬ℙf
_▻_ : ∀ {l f₁ f₂} → l ∣ f₁ ∙ f₂ → ℙ (l ∙ f₁) → l ∣ f₁
!ℙ (p ▻ ℙf) = ℙf
¬ℙ (p ▻ ℙf) = ¬ℙ p
_≈◄⟅_⟆ : ∀ {x y z} → x ∣ y → x ≈ z → z ∣ y
¬ℙ (x⟅y⟆ ≈◄⟅ x≈z ⟆) = ¬ℙ x⟅y⟆ ∘ ℙ-resp (sym x≈z)
!ℙ (x⟅y⟆ ≈◄⟅ x≈z ⟆) = ℙ-resp (≪∙ x≈z) (!ℙ x⟅y⟆)
_≈▻⟅_⟆ : ∀ {x y z} → x ∣ y → y ≈ z → x ∣ z
¬ℙ (x⟅y⟆ ≈▻⟅ y≈z ⟆) = ¬ℙ x⟅y⟆
!ℙ (x⟅y⟆ ≈▻⟅ y≈z ⟆) = ℙ-resp (∙≫ y≈z) (!ℙ x⟅y⟆)
_≈⟅_∣_⟆ : ∀ {x₁ y₁ x₂ y₂} → x₁ ∣ y₁ → x₁ ≈ x₂ → y₁ ≈ y₂ → x₂ ∣ y₂
¬ℙ (x⟅y⟆ ≈⟅ x≈ ∣ y≈ ⟆) = ¬ℙ x⟅y⟆ ∘ ℙ-resp (sym x≈)
!ℙ (x⟅y⟆ ≈⟅ x≈ ∣ y≈ ⟆) = ℙ-resp (∙-cong x≈ y≈) (!ℙ x⟅y⟆)
¬∄ℙ : ∀ {i} → ¬ (i ∣ ε)
¬∄ℙ i⟅ε⟆ = ¬ℙ i⟅ε⟆ (ℙ-resp (identityʳ _) (!ℙ i⟅ε⟆))
| 26.763889 | 85 | 0.531396 |
39b0adc3dba7c771fae863df29f34bb95e7011dd | 7,578 | agda | Agda | agda-stdlib/src/Codata/Musical/Colist/Infinite-merge.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 5 | 2020-10-07T12:07:53.000Z | 2020-10-10T21:41:32.000Z | agda-stdlib/src/Codata/Musical/Colist/Infinite-merge.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | null | null | null | agda-stdlib/src/Codata/Musical/Colist/Infinite-merge.agda | DreamLinuxer/popl21-artifact | fb380f2e67dcb4a94f353dbaec91624fcb5b8933 | [
"MIT"
] | 1 | 2021-11-04T06:54:45.000Z | 2021-11-04T06:54:45.000Z | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Infinite merge operation for coinductive lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --guardedness #-}
module Codata.Musical.Colist.Infinite-merge where
open import Codata.Musical.Notation
open import Codata.Musical.Colist as Colist hiding (_⋎_)
open import Data.Nat.Base
open import Data.Nat.Induction using (<′-wellFounded)
open import Data.Nat.Properties
open import Data.Product as Prod
open import Data.Sum.Base
open import Data.Sum.Properties
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; Inverse; inverse)
import Function.Related as Related
open import Function.Related.TypeIsomorphisms
import Induction.WellFounded as WF
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Some code that is used to work around Agda's syntactic guardedness
-- checker.
private
infixr 5 _∷_ _⋎_
data ColistP {a} (A : Set a) : Set a where
[] : ColistP A
_∷_ : A → ∞ (ColistP A) → ColistP A
_⋎_ : ColistP A → ColistP A → ColistP A
data ColistW {a} (A : Set a) : Set a where
[] : ColistW A
_∷_ : A → ColistP A → ColistW A
program : ∀ {a} {A : Set a} → Colist A → ColistP A
program [] = []
program (x ∷ xs) = x ∷ ♯ program (♭ xs)
mutual
_⋎W_ : ∀ {a} {A : Set a} → ColistW A → ColistP A → ColistW A
[] ⋎W ys = whnf ys
(x ∷ xs) ⋎W ys = x ∷ (ys ⋎ xs)
whnf : ∀ {a} {A : Set a} → ColistP A → ColistW A
whnf [] = []
whnf (x ∷ xs) = x ∷ ♭ xs
whnf (xs ⋎ ys) = whnf xs ⋎W ys
mutual
⟦_⟧P : ∀ {a} {A : Set a} → ColistP A → Colist A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
⟦_⟧W : ∀ {a} {A : Set a} → ColistW A → Colist A
⟦ [] ⟧W = []
⟦ x ∷ xs ⟧W = x ∷ ♯ ⟦ xs ⟧P
mutual
⋎-homP : ∀ {a} {A : Set a} (xs : ColistP A) {ys} →
⟦ xs ⋎ ys ⟧P ≈ ⟦ xs ⟧P Colist.⋎ ⟦ ys ⟧P
⋎-homP xs = ⋎-homW (whnf xs) _
⋎-homW : ∀ {a} {A : Set a} (xs : ColistW A) ys →
⟦ xs ⋎W ys ⟧W ≈ ⟦ xs ⟧W Colist.⋎ ⟦ ys ⟧P
⋎-homW (x ∷ xs) ys = x ∷ ♯ ⋎-homP ys
⋎-homW [] ys = begin ⟦ ys ⟧P ∎
where open ≈-Reasoning
⟦program⟧P : ∀ {a} {A : Set a} (xs : Colist A) →
⟦ program xs ⟧P ≈ xs
⟦program⟧P [] = []
⟦program⟧P (x ∷ xs) = x ∷ ♯ ⟦program⟧P (♭ xs)
Any-⋎P : ∀ {a p} {A : Set a} {P : A → Set p} xs {ys} →
Any P ⟦ program xs ⋎ ys ⟧P ↔ (Any P xs ⊎ Any P ⟦ ys ⟧P)
Any-⋎P {P = P} xs {ys} =
Any P ⟦ program xs ⋎ ys ⟧P ↔⟨ Any-cong Inv.id (⋎-homP (program xs)) ⟩
Any P (⟦ program xs ⟧P Colist.⋎ ⟦ ys ⟧P) ↔⟨ Any-⋎ _ ⟩
(Any P ⟦ program xs ⟧P ⊎ Any P ⟦ ys ⟧P) ↔⟨ Any-cong Inv.id (⟦program⟧P _) ⊎-cong (_ ∎) ⟩
(Any P xs ⊎ Any P ⟦ ys ⟧P) ∎
where open Related.EquationalReasoning
index-Any-⋎P :
∀ {a p} {A : Set a} {P : A → Set p} xs {ys}
(p : Any P ⟦ program xs ⋎ ys ⟧P) →
index p ≥′ [ index , index ]′ (Inverse.to (Any-⋎P xs) ⟨$⟩ p)
index-Any-⋎P xs p
with Any-resp id (⋎-homW (whnf (program xs)) _) p
| index-Any-resp {f = id} (⋎-homW (whnf (program xs)) _) p
index-Any-⋎P xs p | q | q≡p
with Inverse.to (Any-⋎ ⟦ program xs ⟧P) ⟨$⟩ q
| index-Any-⋎ ⟦ program xs ⟧P q
index-Any-⋎P xs p | q | q≡p | inj₂ r | r≤q rewrite q≡p = r≤q
index-Any-⋎P xs p | q | q≡p | inj₁ r | r≤q
with Any-resp id (⟦program⟧P xs) r
| index-Any-resp {f = id} (⟦program⟧P xs) r
index-Any-⋎P xs p | q | q≡p | inj₁ r | r≤q | s | s≡r
rewrite s≡r | q≡p = r≤q
------------------------------------------------------------------------
-- Infinite variant of _⋎_.
private
merge′ : ∀ {a} {A : Set a} → Colist (A × Colist A) → ColistP A
merge′ [] = []
merge′ ((x , xs) ∷ xss) = x ∷ ♯ (program xs ⋎ merge′ (♭ xss))
merge : ∀ {a} {A : Set a} → Colist (A × Colist A) → Colist A
merge xss = ⟦ merge′ xss ⟧P
------------------------------------------------------------------------
-- Any lemma for merge.
module _ {a p} {A : Set a} {P : A → Set p} where
Any-merge : ∀ xss → Any P (merge xss) ↔ Any (λ { (x , xs) → P x ⊎ Any P xs }) xss
Any-merge xss = inverse (proj₁ ∘ to xss) from (proj₂ ∘ to xss) to∘from
where
open P.≡-Reasoning
-- The from function.
Q = λ { (x , xs) → P x ⊎ Any P xs }
from : ∀ {xss} → Any Q xss → Any P (merge xss)
from (here (inj₁ p)) = here p
from (here (inj₂ p)) = there (Inverse.from (Any-⋎P _) ⟨$⟩ inj₁ p)
from (there {x = _ , xs} p) = there (Inverse.from (Any-⋎P xs) ⟨$⟩ inj₂ (from p))
-- The from function is injective.
from-injective : ∀ {xss} (p₁ p₂ : Any Q xss) →
from p₁ ≡ from p₂ → p₁ ≡ p₂
from-injective (here (inj₁ p)) (here (inj₁ .p)) P.refl = P.refl
from-injective (here (inj₂ p₁)) (here (inj₂ p₂)) eq =
P.cong (here ∘ inj₂) $
inj₁-injective $
Inverse.injective (Inv.sym (Any-⋎P _)) {x = inj₁ p₁} {y = inj₁ p₂} $
there-injective eq
from-injective (here (inj₂ p₁)) (there p₂) eq
with Inverse.injective (Inv.sym (Any-⋎P _))
{x = inj₁ p₁} {y = inj₂ (from p₂)}
(there-injective eq)
... | ()
from-injective (there p₁) (here (inj₂ p₂)) eq
with Inverse.injective (Inv.sym (Any-⋎P _))
{x = inj₂ (from p₁)} {y = inj₁ p₂}
(there-injective eq)
... | ()
from-injective (there {x = _ , xs} p₁) (there p₂) eq =
P.cong there $
from-injective p₁ p₂ $
inj₂-injective $
Inverse.injective (Inv.sym (Any-⋎P xs))
{x = inj₂ (from p₁)} {y = inj₂ (from p₂)} $
there-injective eq
-- The to function (defined as a right inverse of from).
Input = ∃ λ xss → Any P (merge xss)
Pred : Input → Set _
Pred (xss , p) = ∃ λ (q : Any Q xss) → from q ≡ p
to : ∀ xss p → Pred (xss , p)
to = λ xss p →
WF.All.wfRec (WF.InverseImage.wellFounded size <′-wellFounded) _
Pred step (xss , p)
where
size : Input → ℕ
size (_ , p) = index p
step : ∀ p → WF.WfRec (_<′_ on size) Pred p → Pred p
step ([] , ()) rec
step ((x , xs) ∷ xss , here p) rec = here (inj₁ p) , P.refl
step ((x , xs) ∷ xss , there p) rec
with Inverse.to (Any-⋎P xs) ⟨$⟩ p
| Inverse.left-inverse-of (Any-⋎P xs) p
| index-Any-⋎P xs p
... | inj₁ q | P.refl | _ = here (inj₂ q) , P.refl
... | inj₂ q | P.refl | q≤p =
Prod.map there
(P.cong (there ∘ _⟨$⟩_ (Inverse.from (Any-⋎P xs)) ∘ inj₂))
(rec (♭ xss , q) (s≤′s q≤p))
to∘from = λ p → from-injective _ _ (proj₂ (to xss (from p)))
-- Every member of xss is a member of merge xss, and vice versa (with
-- equal multiplicities).
∈-merge : ∀ {a} {A : Set a} {y : A} xss →
y ∈ merge xss ↔ ∃₂ λ x xs → (x , xs) ∈ xss × (y ≡ x ⊎ y ∈ xs)
∈-merge {y = y} xss =
y ∈ merge xss ↔⟨ Any-merge _ ⟩
Any (λ { (x , xs) → y ≡ x ⊎ y ∈ xs }) xss ↔⟨ Any-∈ ⟩
(∃ λ { (x , xs) → (x , xs) ∈ xss × (y ≡ x ⊎ y ∈ xs) }) ↔⟨ Σ-assoc ⟩
(∃₂ λ x xs → (x , xs) ∈ xss × (y ≡ x ⊎ y ∈ xs)) ∎
where open Related.EquationalReasoning
| 35.745283 | 94 | 0.482581 |
206c430b6911eb16f4e0be508f40a188ad1c48a5 | 9,140 | agda | Agda | src/Util/PKCS.agda | LaudateCorpus1/bft-consensus-agda | a4674fc473f2457fd3fe5123af48253cfb2404ef | [
"UPL-1.0"
] | null | null | null | src/Util/PKCS.agda | LaudateCorpus1/bft-consensus-agda | a4674fc473f2457fd3fe5123af48253cfb2404ef | [
"UPL-1.0"
] | null | null | null | src/Util/PKCS.agda | LaudateCorpus1/bft-consensus-agda | a4674fc473f2457fd3fe5123af48253cfb2404ef | [
"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
-}
open import Util.ByteString
open import Util.Encode
open import Util.Lemmas
open import Util.Prelude
-- This module contains a model of cryptographic signatures on
-- certain data structures, and creation and verification
-- thereof. These data structures, defined by the WithVerSig
-- type, can be optionally signed, and if they are signed, the
-- signature covers a ByteString derived from the data structure,
-- enabling support for signature that cover only (functions of)
-- specific parts of the data structure. The module also
-- contains some properties we have found useful in other
-- contexts, though they are not yet used in this repo.
module Util.PKCS where
postulate -- valid assumption
signature-size : ℕ
Signature : Set
Signature = Σ ByteString (λ s → length s ≡ signature-size)
postulate -- valid assumptions
PK : Set
SK : Set
IsKeyPair : PK → SK → Set
_≟PK_ : (pk1 pk2 : PK) → Dec (pk1 ≡ pk2)
instance
enc-PK : Encoder PK
enc-SigMB : Encoder (Maybe Signature)
sign-raw : ByteString → SK → Signature
verify : ByteString → Signature → PK → Bool
-- We assume no "signature collisions", as represented by verify-pk-inj
verify-pk-inj : ∀{bs sig pk pk'}
→ verify bs sig pk ≡ true
→ verify bs sig pk' ≡ true
→ pk ≡ pk'
verify-bs-inj : ∀{bs bs' sig pk}
→ verify bs sig pk ≡ true
→ verify bs' sig pk ≡ true
→ bs ≡ bs'
verify-sign : ∀{bs pk sk}
→ IsKeyPair pk sk
→ verify bs (sign-raw bs sk) pk ≡ true
verify-fail : ∀{bs pk sk}
→ ¬ IsKeyPair pk sk
→ verify bs (sign-raw bs sk) pk ≡ false
-- We consider a PK to be (permanently) either honest or not,
-- respresented by the following postulate. This is relevant
-- in reasoning about possible behaviours of a modeled system.
-- Specifically, the secret key corresponding to an honest PK
-- is assumed not to be leaked, ensuring that cheaters cannot
-- forge new signatures for honest PKs. Furthermore, if a peer
-- is assigned we use possession
-- of an honest PK in a given epoch to modelWe will postulate that, among
-- the PKs chosen for a particular epoch, the number of them
-- that are dishonest is at most the number of faults to be
-- tolerated for that epoch. This definition is /meta/: the
-- information about which PKs are (dis)honest should never be
-- used by the implementation -- it is only for modeling and
-- proofs.
Meta-Dishonest-PK : PK → Set
Meta-DishonestPK? : (pk : PK) → Dec (Meta-Dishonest-PK pk)
verify-pi : ∀{bs sig pk}
→ (v1 : verify bs sig pk ≡ true)
→ (v2 : verify bs sig pk ≡ true)
→ v1 ≡ v2
verify-pi {bs} {sig} {pk} _ _
with verify bs sig pk
verify-pi {bs} {sig} {pk} refl refl | .true = refl
Meta-Honest-PK : PK → Set
Meta-Honest-PK = ¬_ ∘ Meta-Dishonest-PK
sign-encodable : ∀ {c C} → ⦃ Encoder {c} C ⦄ → C → SK → Signature
sign-encodable = sign-raw ∘ encode
-- A datatype C might that might carry values with
-- signatures should be an instance of 'WithSig' below.
record WithSig (C : Set) : Set₁ where
field
-- A decidable predicate indicates whether values have
-- been signed
Signed : C → Set
Signed-pi : ∀ (c : C)
→ (is1 : Signed c)
→ (is2 : Signed c)
→ is1 ≡ is2
isSigned? : (c : C) → Dec (Signed c)
-- Signed values must have a signature
signature : (c : C)(hasSig : Signed c) → Signature
-- All values must be /encoded/ into a ByteString that
-- is supposed to be verified against a signature.
signableFields : C → ByteString
open WithSig {{...}} public
sign : {C : Set} ⦃ ws : WithSig C ⦄ → C → SK → Signature
sign c = sign-raw (signableFields c)
Signature≡ : {C : Set} ⦃ ws : WithSig C ⦄ → C → Signature → Set
Signature≡ c sig = Σ (Signed c) (λ s → signature c s ≡ sig)
-- A value of a datatype C can have its signature
-- verified; A value of type WithVerSig c is a proof of that.
-- Hence; the set (Σ C WithVerSig) is the set of values of
-- type C with verified signatures.
record WithVerSig {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) : Set where
constructor mkWithVerSig
field
isSigned : Signed c
verified : verify (signableFields c) (signature c isSigned) pk
≡ true
open WithVerSig public
ver-signature : ∀{C pk}⦃ ws : WithSig C ⦄{c : C} → WithVerSig pk c → Signature
ver-signature {c = c} wvs = signature c (isSigned wvs)
verCast : {C : Set} ⦃ ws : WithSig C ⦄ {c : C} {is1 is2 : Signed c} {pk1 pk2 : PK}
→ verify (signableFields c) (signature c is1) pk1 ≡ true
→ pk1 ≡ pk2
→ is1 ≡ is2
→ verify (signableFields c) (signature c is2) pk2 ≡ true
verCast prf refl refl = prf
wvsCast : {C : Set} ⦃ ws : WithSig C ⦄ {c : C} {pk1 pk2 : PK}
→ WithVerSig pk1 c
→ pk2 ≡ pk1
→ WithVerSig pk2 c
wvsCast {c = c} wvs refl = wvs
withVerSig-≡ : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ {wvs1 : WithVerSig pk c}
→ {wvs2 : WithVerSig pk c}
→ isSigned wvs1 ≡ isSigned wvs2
→ wvs1 ≡ wvs2
withVerSig-≡ {wvs1 = wvs1} {wvs2 = wvs2} refl
with verified wvs2 | inspect verified wvs2 | verCast (verified wvs1) refl refl
...| vwvs2 | [ R ] | vwvs1 rewrite verify-pi vwvs1 vwvs2 | sym R = refl
withVerSig-pi : {C : Set} {pk : PK} {c : C} ⦃ ws : WithSig C ⦄
→ (wvs1 : WithVerSig pk c)
→ (wvs2 : WithVerSig pk c)
→ wvs2 ≡ wvs1
withVerSig-pi {C} {pk} {c} ⦃ ws ⦄ wvs2 wvs1
with isSigned? c
...| no ¬Signed = ⊥-elim (¬Signed (isSigned wvs1))
...| yes sc = withVerSig-≡ {wvs1 = wvs1} {wvs2 = wvs2} (Signed-pi c (isSigned wvs1) (isSigned wvs2))
data SigCheckResult {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) : Set where
notSigned : ¬ Signed c → SigCheckResult pk c
checkFailed : (sc : Signed c) → verify (signableFields c) (signature c sc) pk ≡ false → SigCheckResult pk c
sigVerified : WithVerSig pk c → SigCheckResult pk c
checkFailed≢sigVerified : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
{wvs : WithVerSig ⦃ ws ⦄ pk c}
{sc : Signed c} {v : verify (signableFields c) (signature c sc) pk ≡ false}
→ checkFailed sc v ≡ sigVerified wvs → ⊥
checkFailed≢sigVerified ()
data SigCheckOutcome : Set where
notSigned : SigCheckOutcome
checkFailed : SigCheckOutcome
sigVerified : SigCheckOutcome
data SigCheckFailed : Set where
notSigned : SigCheckFailed
checkFailed : SigCheckFailed
check-signature : {C : Set} ⦃ ws : WithSig C ⦄ → (pk : PK) → (c : C) → SigCheckResult pk c
check-signature pk c with isSigned? c
...| no ns = notSigned ns
...| yes sc with verify (signableFields c) (signature c sc) pk
| inspect (verify (signableFields c) (signature c sc)) pk
...| false | [ nv ] = checkFailed sc nv
...| true | [ v ] = sigVerified (record { isSigned = sc
; verified = v })
sigCheckOutcomeFor : {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) → SigCheckOutcome
sigCheckOutcomeFor pk c with check-signature pk c
...| notSigned _ = notSigned
...| checkFailed _ _ = checkFailed
...| sigVerified _ = sigVerified
sigVerifiedVerSigCS : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ sigCheckOutcomeFor pk c ≡ sigVerified
→ ∃[ wvs ] (check-signature ⦃ ws ⦄ pk c ≡ sigVerified wvs)
sigVerifiedVerSigCS {pk = pk} {c = c} prf
with check-signature pk c | inspect
(check-signature pk) c
...| sigVerified verSig | [ R ] rewrite R = verSig , refl
sigVerifiedVerSig : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ sigCheckOutcomeFor pk c ≡ sigVerified
→ WithVerSig pk c
sigVerifiedVerSig = proj₁ ∘ sigVerifiedVerSigCS
sigVerifiedSCO : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C}
→ (wvs : WithVerSig pk c)
→ sigCheckOutcomeFor pk c ≡ sigVerified
sigVerifiedSCO {pk = pk} {c = c} wvs
with check-signature pk c
...| notSigned ns = ⊥-elim (ns (isSigned wvs))
...| checkFailed xx xxs rewrite Signed-pi c xx (isSigned wvs) = ⊥-elim (false≢true (trans (sym xxs) (verified wvs)))
...| sigVerified wvs' = refl
failedSigCheckOutcome : {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C)
→ sigCheckOutcomeFor pk c ≢ sigVerified
→ SigCheckFailed
failedSigCheckOutcome pk c prf with sigCheckOutcomeFor pk c
...| notSigned = notSigned
...| checkFailed = checkFailed
...| sigVerified = ⊥-elim (prf refl)
| 39.5671 | 117 | 0.604595 |
c5df4aff60027b9e7aa30689c51999df7b610375 | 18,333 | agda | Agda | Cubical/Foundations/GroupoidLaws.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/Foundations/GroupoidLaws.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | null | null | null | Cubical/Foundations/GroupoidLaws.agda | kiana-S/univalent-foundations | 8bdb0766260489f9c89a14f4c0f2ad26e5190dec | [
"MIT"
] | 1 | 2021-11-22T02:02:01.000Z | 2021-11-22T02:02:01.000Z | {-
This file proves the higher groupoid structure of types
for homogeneous and heterogeneous paths
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.GroupoidLaws where
open import Cubical.Foundations.Prelude
private
variable
ℓ : Level
A : Type ℓ
x y z w v : A
_⁻¹ : (x ≡ y) → (y ≡ x)
x≡y ⁻¹ = sym x≡y
infix 40 _⁻¹
-- homogeneous groupoid laws
symInvo : (p : x ≡ y) → p ≡ p ⁻¹ ⁻¹
symInvo p = refl
rUnit : (p : x ≡ y) → p ≡ p ∙ refl
rUnit p j i = compPath-filler p refl j i
-- The filler of left unit: lUnit-filler p =
-- PathP (λ i → PathP (λ j → PathP (λ k → A) x (p (~ j ∨ i)))
-- (refl i) (λ j → compPath-filler refl p i j)) (λ k i → (p (~ k ∧ i ))) (lUnit p)
lUnit-filler : {x y : A} (p : x ≡ y) → I → I → I → A
lUnit-filler {x = x} p j k i =
hfill (λ j → λ { (i = i0) → x
; (i = i1) → p (~ k ∨ j )
; (k = i0) → p i
-- ; (k = i1) → compPath-filler refl p j i
}) (inS (p (~ k ∧ i ))) j
lUnit : (p : x ≡ y) → p ≡ refl ∙ p
lUnit p j i = lUnit-filler p i1 j i
symRefl : refl {x = x} ≡ refl ⁻¹
symRefl i = refl
compPathRefl : refl {x = x} ≡ refl ∙ refl
compPathRefl = rUnit refl
-- The filler of right cancellation: rCancel-filler p =
-- PathP (λ i → PathP (λ j → PathP (λ k → A) x (p (~ j ∧ ~ i)))
-- (λ j → compPath-filler p (p ⁻¹) i j) (refl i)) (λ j i → (p (i ∧ ~ j))) (rCancel p)
rCancel-filler : ∀ {x y : A} (p : x ≡ y) → (k j i : I) → A
rCancel-filler {x = x} p k j i =
hfill (λ k → λ { (i = i0) → x
; (i = i1) → p (~ k ∧ ~ j)
-- ; (j = i0) → compPath-filler p (p ⁻¹) k i
; (j = i1) → x
}) (inS (p (i ∧ ~ j))) k
rCancel : (p : x ≡ y) → p ∙ p ⁻¹ ≡ refl
rCancel {x = x} p j i = rCancel-filler p i1 j i
rCancel-filler' : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) → (i j k : I) → A
rCancel-filler' {x = x} {y} p i j k =
hfill
(λ i → λ
{ (j = i1) → p (~ i ∧ k)
; (k = i0) → x
; (k = i1) → p (~ i)
})
(inS (p k))
(~ i)
rCancel' : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) → p ∙ p ⁻¹ ≡ refl
rCancel' p j k = rCancel-filler' p i0 j k
lCancel : (p : x ≡ y) → p ⁻¹ ∙ p ≡ refl
lCancel p = rCancel (p ⁻¹)
assoc : (p : x ≡ y) (q : y ≡ z) (r : z ≡ w) →
p ∙ q ∙ r ≡ (p ∙ q) ∙ r
assoc p q r k = (compPath-filler p q k) ∙ compPath-filler' q r (~ k)
-- heterogeneous groupoid laws
symInvoP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → (p : PathP A x y) →
PathP (λ j → PathP (λ i → symInvo (λ i → A i) j i) x y) p (symP (symP p))
symInvoP p = refl
rUnitP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → (p : PathP A x y) →
PathP (λ j → PathP (λ i → rUnit (λ i → A i) j i) x y) p (compPathP p refl)
rUnitP p j i = compPathP-filler p refl j i
lUnitP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → (p : PathP A x y) →
PathP (λ j → PathP (λ i → lUnit (λ i → A i) j i) x y) p (compPathP refl p)
lUnitP {A = A} {x = x} p k i =
comp (λ j → lUnit-filler (λ i → A i) j k i)
(λ j → λ { (i = i0) → x
; (i = i1) → p (~ k ∨ j )
; (k = i0) → p i
}) (p (~ k ∧ i ))
rCancelP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → (p : PathP A x y) →
PathP (λ j → PathP (λ i → rCancel (λ i → A i) j i) x x) (compPathP p (symP p)) refl
rCancelP {A = A} {x = x} p j i =
comp (λ k → rCancel-filler (λ i → A i) k j i)
(λ k → λ { (i = i0) → x
; (i = i1) → p (~ k ∧ ~ j)
; (j = i1) → x
}) (p (i ∧ ~ j))
lCancelP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} → (p : PathP A x y) →
PathP (λ j → PathP (λ i → lCancel (λ i → A i) j i) y y) (compPathP (symP p) p) refl
lCancelP p = rCancelP (symP p)
assocP : {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} {z : B i1}
{C_i1 : Type ℓ} {C : (B i1) ≡ C_i1} {w : C i1} (p : PathP A x y) (q : PathP (λ i → B i) y z) (r : PathP (λ i → C i) z w) →
PathP (λ j → PathP (λ i → assoc (λ i → A i) B C j i) x w) (compPathP p (compPathP q r)) (compPathP (compPathP p q) r)
assocP {A = A} {B = B} {C = C} p q r k i =
comp (hfill (λ j → λ {
(i = i0) → A i0
; (i = i1) → compPath-filler' (λ i₁ → B i₁) (λ i₁ → C i₁) (~ k) j })
(inS (compPath-filler (λ i₁ → A i₁) (λ i₁ → B i₁) k i)) )
(λ j → λ
{ (i = i0) → p i0
; (i = i1) →
comp (hfill ((λ l → λ
{ (j = i0) → B k
; (j = i1) → C l
; (k = i1) → C (j ∧ l)
})) (inS (B ( j ∨ k)) ) )
(λ l → λ
{ (j = i0) → q k
; (j = i1) → r l
; (k = i1) → r (j ∧ l)
})
(q (j ∨ k))
})
(compPathP-filler p q k i)
-- Loic's code below
-- some exchange law for doubleCompPath and refl
invSides-filler : {x y z : A} (p : x ≡ y) (q : x ≡ z) → Square p (sym q) q (sym p)
invSides-filler {x = x} p q i j =
hcomp (λ k → λ { (i = i0) → p (k ∧ j)
; (i = i1) → q (~ j ∧ k)
; (j = i0) → q (i ∧ k)
; (j = i1) → p (~ i ∧ k)})
x
leftright : {ℓ : Level} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : y ≡ z) →
(refl ∙∙ p ∙∙ q) ≡ (p ∙∙ q ∙∙ refl)
leftright p q i j =
hcomp (λ t → λ { (j = i0) → p (i ∧ (~ t))
; (j = i1) → q (t ∨ i) })
(invSides-filler q (sym p) (~ i) j)
-- equating doubleCompPath and a succession of two compPath
split-leftright : {ℓ : Level} {A : Type ℓ} {w x y z : A} (p : w ≡ x) (q : x ≡ y) (r : y ≡ z) →
(p ∙∙ q ∙∙ r) ≡ (refl ∙∙ (p ∙∙ q ∙∙ refl) ∙∙ r)
split-leftright p q r j i =
hcomp (λ t → λ { (i = i0) → p (~ j ∧ ~ t)
; (i = i1) → r t })
(doubleCompPath-filler p q refl j i)
split-leftright' : {ℓ : Level} {A : Type ℓ} {w x y z : A} (p : w ≡ x) (q : x ≡ y) (r : y ≡ z) →
(p ∙∙ q ∙∙ r) ≡ (p ∙∙ (refl ∙∙ q ∙∙ r) ∙∙ refl)
split-leftright' p q r j i =
hcomp (λ t → λ { (i = i0) → p (~ t)
; (i = i1) → r (j ∨ t) })
(doubleCompPath-filler refl q r j i)
doubleCompPath-elim : {ℓ : Level} {A : Type ℓ} {w x y z : A} (p : w ≡ x) (q : x ≡ y)
(r : y ≡ z) → (p ∙∙ q ∙∙ r) ≡ (p ∙ q) ∙ r
doubleCompPath-elim p q r = (split-leftright p q r) ∙ (λ i → (leftright p q (~ i)) ∙ r)
doubleCompPath-elim' : {ℓ : Level} {A : Type ℓ} {w x y z : A} (p : w ≡ x) (q : x ≡ y)
(r : y ≡ z) → (p ∙∙ q ∙∙ r) ≡ p ∙ (q ∙ r)
doubleCompPath-elim' p q r = (split-leftright' p q r) ∙ (sym (leftright p (q ∙ r)))
cong-∙ : ∀ {B : Type ℓ} (f : A → B) (p : x ≡ y) (q : y ≡ z)
→ cong f (p ∙ q) ≡ (cong f p) ∙ (cong f q)
cong-∙ f p q j i = hcomp (λ k → λ { (j = i0) → f (compPath-filler p q k i)
; (i = i0) → f (p i0)
; (i = i1) → f (q k) })
(f (p i))
cong-∙∙ : ∀ {B : Type ℓ} (f : A → B) (p : w ≡ x) (q : x ≡ y) (r : y ≡ z)
→ cong f (p ∙∙ q ∙∙ r) ≡ (cong f p) ∙∙ (cong f q) ∙∙ (cong f r)
cong-∙∙ f p q r j i = hcomp (λ k → λ { (j = i0) → f (doubleCompPath-filler p q r k i)
; (i = i0) → f (p (~ k))
; (i = i1) → f (r k) })
(f (q i))
hcomp-unique : ∀ {ℓ} {A : Type ℓ} {φ} → (u : I → Partial φ A) → (u0 : A [ φ ↦ u i0 ]) →
(h2 : ∀ i → A [ (φ ∨ ~ i) ↦ (\ { (φ = i1) → u i 1=1; (i = i0) → outS u0}) ])
→ (hcomp u (outS u0) ≡ outS (h2 i1)) [ φ ↦ (\ { (φ = i1) → (\ i → u i1 1=1)}) ]
hcomp-unique {φ = φ} u u0 h2 = inS (\ i → hcomp (\ k → \ { (φ = i1) → u k 1=1
; (i = i1) → outS (h2 k) })
(outS u0))
lid-unique : ∀ {ℓ} {A : Type ℓ} {φ} → (u : I → Partial φ A) → (u0 : A [ φ ↦ u i0 ]) →
(h1 h2 : ∀ i → A [ (φ ∨ ~ i) ↦ (\ { (φ = i1) → u i 1=1; (i = i0) → outS u0}) ])
→ (outS (h1 i1) ≡ outS (h2 i1)) [ φ ↦ (\ { (φ = i1) → (\ i → u i1 1=1)}) ]
lid-unique {φ = φ} u u0 h1 h2 = inS (\ i → hcomp (\ k → \ { (φ = i1) → u k 1=1
; (i = i0) → outS (h1 k)
; (i = i1) → outS (h2 k) })
(outS u0))
transp-hcomp : ∀ {ℓ} (φ : I) {A' : Type ℓ}
(A : (i : I) → Type ℓ [ φ ↦ (λ _ → A') ]) (let B = \ (i : I) → outS (A i))
→ ∀ {ψ} (u : I → Partial ψ (B i0)) → (u0 : B i0 [ ψ ↦ u i0 ]) →
(transp B φ (hcomp u (outS u0)) ≡ hcomp (\ i o → transp B φ (u i o)) (transp B φ (outS u0)))
[ ψ ↦ (\ { (ψ = i1) → (\ i → transp B φ (u i1 1=1))}) ]
transp-hcomp φ A u u0 = inS (sym (outS (hcomp-unique
((\ i o → transp B φ (u i o))) (inS (transp B φ (outS u0)))
\ i → inS (transp B φ (hfill u u0 i)))))
where
B = \ (i : I) → outS (A i)
hcomp-cong : ∀ {ℓ} {A : Type ℓ} {φ} → (u : I → Partial φ A) → (u0 : A [ φ ↦ u i0 ]) →
(u' : I → Partial φ A) → (u0' : A [ φ ↦ u' i0 ]) →
(ueq : ∀ i → PartialP φ (\ o → u i o ≡ u' i o)) → (outS u0 ≡ outS u0') [ φ ↦ (\ { (φ = i1) → ueq i0 1=1}) ]
→ (hcomp u (outS u0) ≡ hcomp u' (outS u0')) [ φ ↦ (\ { (φ = i1) → ueq i1 1=1 }) ]
hcomp-cong u u0 u' u0' ueq 0eq = inS (\ j → hcomp (\ i o → ueq i o j) (outS 0eq j))
congFunct-filler : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {x y z : A} (f : A → B) (p : x ≡ y) (q : y ≡ z)
→ I → I → I → B
congFunct-filler {x = x} f p q i j z =
hfill (λ k → λ { (i = i0) → f x
; (i = i1) → f (q k)
; (j = i0) → f (compPath-filler p q k i)})
(inS (f (p i)))
z
congFunct : ∀ {ℓ} {B : Type ℓ} (f : A → B) (p : x ≡ y) (q : y ≡ z) → cong f (p ∙ q) ≡ cong f p ∙ cong f q
congFunct f p q j i = congFunct-filler f p q i j i1
-- congFunct for dependent types
congFunct-dep : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} {x y z : A} (f : (a : A) → B a) (p : x ≡ y) (q : y ≡ z)
→ PathP (λ i → PathP (λ j → B (compPath-filler p q i j)) (f x) (f (q i))) (cong f p) (cong f (p ∙ q))
congFunct-dep {B = B} {x = x} f p q i j = f (compPath-filler p q i j)
cong₂Funct : (f : A → A → A) →
(p : x ≡ y) →
{u v : A} (q : u ≡ v) →
cong₂ f p q ≡ cong (λ x → f x u) p ∙ cong (f y) q
cong₂Funct {x = x} {y = y} f p {u = u} {v = v} q j i =
hcomp (λ k → λ { (i = i0) → f x u
; (i = i1) → f y (q k)
; (j = i0) → f (p i) (q (i ∧ k))})
(f (p i) u)
symDistr-filler : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : y ≡ z) → I → I → I → A
symDistr-filler {A = A} {z = z} p q i j k =
hfill (λ k → λ { (i = i0) → q (k ∨ j)
; (i = i1) → p (~ k ∧ j) })
(inS (invSides-filler q (sym p) i j))
k
symDistr : ∀ {ℓ} {A : Type ℓ} {x y z : A} (p : x ≡ y) (q : y ≡ z) → sym (p ∙ q) ≡ sym q ∙ sym p
symDistr p q i j = symDistr-filler p q j i i1
-- we can not write hcomp-isEquiv : {ϕ : I} → (p : I → Partial ϕ A) → isEquiv (λ (a : A [ ϕ ↦ p i0 ]) → hcomp p a)
-- due to size issues. But what we can write (compare to hfill) is:
hcomp-equivFillerSub : {ϕ : I} → (p : I → Partial ϕ A) → (a : A [ ϕ ↦ p i0 ])
→ (i : I)
→ A [ ϕ ∨ i ∨ ~ i ↦ (λ { (i = i0) → outS a
; (i = i1) → hcomp (λ i → p (~ i)) (hcomp p (outS a))
; (ϕ = i1) → p i0 1=1 }) ]
hcomp-equivFillerSub {ϕ = ϕ} p a i =
inS (hcomp (λ k → λ { (i = i1) → hfill (λ j → p (~ j)) (inS (hcomp p (outS a))) k
; (i = i0) → outS a
; (ϕ = i1) → p (~ k ∧ i) 1=1 })
(hfill p a i))
hcomp-equivFiller : {ϕ : I} → (p : I → Partial ϕ A) → (a : A [ ϕ ↦ p i0 ])
→ (i : I) → A
hcomp-equivFiller p a i = outS (hcomp-equivFillerSub p a i)
pentagonIdentity : (p : x ≡ y) → (q : y ≡ z) → (r : z ≡ w) → (s : w ≡ v)
→
(assoc p q (r ∙ s) ∙ assoc (p ∙ q) r s)
≡
cong (p ∙_) (assoc q r s) ∙∙ assoc p (q ∙ r) s ∙∙ cong (_∙ s) (assoc p q r)
pentagonIdentity {x = x} {y} p q r s =
(λ i →
(λ j → cong (p ∙_) (assoc q r s) (i ∧ j))
∙∙ (λ j → lemma₀₀ i j ∙ lemma₀₁ i j)
∙∙ (λ j → lemma₁₀ i j ∙ lemma₁₁ i j)
)
where
lemma₀₀ : ( i j : I) → _ ≡ _
lemma₀₀ i j i₁ =
hcomp
(λ k → λ { (j = i0) → p i₁
; (i₁ = i0) → x
; (i₁ = i1) → hcomp
(λ k₁ → λ { (i = i0) → (q (j ∧ k))
; (k = i0) → y
; (j = i0) → y
; (j = i1)(k = i1) → r (k₁ ∧ i)})
(q (j ∧ k))
}) (p i₁)
lemma₀₁ : ( i j : I) → hcomp
(λ k → λ {(i = i0) → q j
; (j = i0) → y
; (j = i1) → r (k ∧ i)
})
(q j) ≡ _
lemma₀₁ i j i₁ = (hcomp
(λ k → λ { (j = i1) → hcomp
(λ k₁ → λ { (i₁ = i0) → r i
; (k = i0) → r i
; (i = i1) → s (k₁ ∧ k ∧ i₁)
; (i₁ = i1)(k = i1) → s k₁ })
(r ((i₁ ∧ k) ∨ i))
; (i₁ = i0) → compPath-filler q r i j
; (i₁ = i1) → hcomp
(λ k₁ → λ { (k = i0) → r i
; (k = i1) → s k₁
; (i = i1) → s (k ∧ k₁)})
(r (i ∨ k))})
(hfill
(λ k → λ { (j = i1) → r k
; (i₁ = i1) → r k
; (i₁ = i0)(j = i0) → y })
(inS (q (i₁ ∨ j))) i))
lemma₁₁ : ( i j : I) → (r (i ∨ j)) ≡ _
lemma₁₁ i j i₁ =
hcomp
(λ k → λ { (i = i1) → s (i₁ ∧ k)
; (j = i1) → s (i₁ ∧ k)
; (i₁ = i0) → r (i ∨ j)
; (i₁ = i1) → s k
}) (r (i ∨ j ∨ i₁))
lemma₁₀-back : I → I → I → _
lemma₁₀-back i j i₁ =
hcomp
(λ k → λ {
(i₁ = i0) → x
; (i₁ = i1) → hcomp
(λ k₁ → λ { (k = i0) → q (j ∨ ~ i)
; (k = i1) → r (k₁ ∧ j)
; (j = i0) → q (k ∨ ~ i)
; (j = i1) → r (k₁ ∧ k)
; (i = i0) → r (k ∧ j ∧ k₁)
})
(q (k ∨ j ∨ ~ i))
; (i = i0)(j = i0) → (p ∙ q) i₁
})
(hcomp
(λ k → λ { (i₁ = i0) → x
; (i₁ = i1) → q ((j ∨ ~ i ) ∧ k)
; (j = i0)(i = i1) → p i₁
})
(p i₁))
lemma₁₀-front : I → I → I → _
lemma₁₀-front i j i₁ =
(((λ _ → x) ∙∙ compPath-filler p q j ∙∙
(λ i₁ →
hcomp
(λ k → λ { (i₁ = i0) → q j
; (i₁ = i1) → r (k ∧ (j ∨ i))
; (j = i0)(i = i0) → q i₁
; (j = i1) → r (i₁ ∧ k)
})
(q (j ∨ i₁))
)) i₁)
compPath-filler-in-filler :
(p : _ ≡ y) → (q : _ ≡ _ )
→ _≡_ {A = Square (p ∙ q) (p ∙ q) (λ _ → x) (λ _ → z)}
(λ i j → hcomp
(λ i₂ →
λ { (j = i0) → x
; (j = i1) → q (i₂ ∨ ~ i)
; (i = i0) → (p ∙ q) j
})
(compPath-filler p q (~ i) j))
(λ _ → p ∙ q)
compPath-filler-in-filler p q z i j =
hcomp
(λ k → λ {
(j = i0) → p i0
; (j = i1) → q (k ∨ ~ i ∧ ~ z)
; (i = i0) → hcomp
(λ i₂ → λ {
(j = i0) → p i0
;(j = i1) → q ((k ∨ ~ z) ∧ i₂)
;(z = i1) (k = i0) → p j
})
(p j)
; (i = i1) → compPath-filler p (λ i₁ → q (k ∧ i₁)) k j
; (z = i0) → hfill
((λ i₂ → λ { (j = i0) → p i0
; (j = i1) → q (i₂ ∨ ~ i)
; (i = i0) → (p ∙ q) j
}))
(inS ((compPath-filler p q (~ i) j))) k
; (z = i1) → compPath-filler p q k j
})
(compPath-filler p q (~ i ∧ ~ z) j)
cube-comp₋₀₋ :
(c : I → I → I → A)
→ {a' : Square _ _ _ _}
→ (λ i i₁ → c i i0 i₁) ≡ a'
→ (I → I → I → A)
cube-comp₋₀₋ c p i j k =
hcomp
(λ l → λ {
(i = i0) → c i0 j k
;(i = i1) → c i1 j k
;(j = i0) → p l i k
;(j = i1) → c i i1 k
;(k = i0) → c i j i0
;(k = i1) → c i j i1
})
(c i j k)
cube-comp₀₋₋ :
(c : I → I → I → A)
→ {a' : Square _ _ _ _}
→ (λ i i₁ → c i0 i i₁) ≡ a'
→ (I → I → I → A)
cube-comp₀₋₋ c p i j k =
hcomp
(λ l → λ {
(i = i0) → p l j k
;(i = i1) → c i1 j k
;(j = i0) → c i i0 k
;(j = i1) → c i i1 k
;(k = i0) → c i j i0
;(k = i1) → c i j i1
})
(c i j k)
lemma₁₀-back' : _
lemma₁₀-back' k j i₁ =
(cube-comp₋₀₋ (lemma₁₀-back)
(compPath-filler-in-filler p q)) k j i₁
lemma₁₀ : ( i j : I) → _ ≡ _
lemma₁₀ i j i₁ =
(cube-comp₀₋₋ lemma₁₀-front (sym lemma₁₀-back')) i j i₁
| 38.273486 | 124 | 0.333279 |
23376d6e7c532228ca57275fb3115ab43a1f3508 | 435 | agda | Agda | test/Succeed/Issue2858-Fresh.agda | cagix/agda | cc026a6a97a3e517bb94bafa9d49233b067c7559 | [
"BSD-2-Clause"
] | 1,989 | 2015-01-09T23:51:16.000Z | 2022-03-30T18:20:48.000Z | test/Succeed/Issue2858-Fresh.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 4,066 | 2015-01-10T11:24:51.000Z | 2022-03-31T21:14:49.000Z | test/Succeed/Issue2858-Fresh.agda | Seanpm2001-languages/agda | 9911f73061e21a87fad76c662463257afe02c861 | [
"BSD-2-Clause"
] | 371 | 2015-01-03T14:04:08.000Z | 2022-03-30T19:00:30.000Z | module Issue2858-Fresh {A : Set} (_#_ : A → A → Set) where
interleaved mutual
data Fresh : Set
data IsFresh (a : A) : Fresh → Set
-- nil is a fresh list
data _ where
[] : Fresh
#[] : IsFresh a []
-- cons is fresh as long as the new value is fresh
data _ where
cons : (x : A) (xs : Fresh) → IsFresh x xs → Fresh
#cons : ∀ {x xs p} → a # x → IsFresh a xs → IsFresh a (cons x xs p)
| 25.588235 | 73 | 0.54023 |
20d7acbde7557038e8bb6ea8dc641ce98c193eae | 6,809 | agda | Agda | ConfluenceTakahashi.agda | iwilare/church-rosser | 2fa17f7738cc7da967375be928137adc4be38696 | [
"MIT"
] | 5 | 2020-06-02T07:27:54.000Z | 2021-11-22T01:43:09.000Z | ConfluenceTakahashi.agda | iwilare/church-rosser | 2fa17f7738cc7da967375be928137adc4be38696 | [
"MIT"
] | null | null | null | ConfluenceTakahashi.agda | iwilare/church-rosser | 2fa17f7738cc7da967375be928137adc4be38696 | [
"MIT"
] | null | null | null | open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; cong₂)
open import Data.Nat using (ℕ; zero; suc; _≤_; z≤n; s≤s)
open import Data.Nat.Properties using (≤-total)
open import Data.Fin using (Fin; zero; suc)
open import Data.Product using (∃; ∃-syntax; _×_; _,_)
open import Data.Sum using ([_,_])
open import DeBruijn
open import Substitution using (rename-subst-commute; subst-commute; extensionality)
open import Beta
open import BetaSubstitutivity using (sub-betas)
open import Takahashi
infix 8 _*⁽_⁾
_*⁽_⁾ : ∀ {n} → Term n → ℕ → Term n
M *⁽ zero ⁾ = M
M *⁽ suc k ⁾ = (M *) *⁽ k ⁾
data _—↠⁽_⁾_ : ∀ {n} → Term n → ℕ → Term n → Set where
_∎ : ∀ {n} (M : Term n)
--------------
→ M —↠⁽ zero ⁾ M
_—→⁽⁾⟨_⟩_ : ∀ {n} {N L : Term n} {k : ℕ} (M : Term n)
→ M —→ L
→ L —↠⁽ k ⁾ N
---------------
→ M —↠⁽ suc k ⁾ N
lemma3-2 : ∀ {n} {M : Term n}
→ M —↠ M *
lemma3-2 {M = # x} = # x ∎
lemma3-2 {M = ƛ _} = —↠-cong-ƛ lemma3-2
lemma3-2 {M = # _ · _} = —↠-congᵣ lemma3-2
lemma3-2 {M = _ · _ · _} = —↠-cong lemma3-2 lemma3-2
lemma3-2 {M = (ƛ M) · N} = (ƛ M) · N —→⟨ —→-β ⟩ sub-betas {M = M} lemma3-2 lemma3-2
lemma3-3 : ∀ {n} {M N : Term n}
→ M —→ N
--------
→ N —↠ M *
lemma3-3 {M = # _} ()
lemma3-3 {M = ƛ M} (—→-ƛ M—→M′) = —↠-cong-ƛ (lemma3-3 M—→M′)
lemma3-3 {M = # _ · N} (—→-ξᵣ N—→N′) = —↠-congᵣ (lemma3-3 N—→N′)
lemma3-3 {M = _ · _ · N} (—→-ξᵣ N—→N′) = —↠-cong lemma3-2 (lemma3-3 N—→N′)
lemma3-3 {M = M₁ · M₂ · _} (—→-ξₗ M—↠M′) = —↠-cong (lemma3-3 M—↠M′) lemma3-2
lemma3-3 {M = (ƛ M) · N} —→-β = sub-betas {M = M} lemma3-2 lemma3-2
lemma3-3 {M = (ƛ M) · N} (—→-ξᵣ {N′ = N′} N—→N′) = (ƛ M ) · N′ —→⟨ —→-β ⟩ sub-betas {M = M} lemma3-2 (lemma3-3 N—→N′)
lemma3-3 {M = (ƛ M) · N} (—→-ξₗ (—→-ƛ {M′ = M′} M—→M′)) = (ƛ M′) · N —→⟨ —→-β ⟩ sub-betas {N = N} (lemma3-3 M—→M′) lemma3-2
_*ˢ : ∀ {n m} → Subst n m → Subst n m
σ *ˢ = λ x → (σ x) *
rename-* : ∀ {n m} (ρ : Rename n m) (M : Term n)
→ rename ρ (M *) ≡ (rename ρ M) *
rename-* ρ (# _) = refl
rename-* ρ (ƛ M) = cong ƛ_ (rename-* (ext ρ) M)
rename-* ρ (# _ · N) = cong₂ _·_ refl (rename-* ρ N)
rename-* ρ (M₁ · M₂ · N) = cong₂ _·_ (rename-* ρ (M₁ · M₂)) (rename-* ρ N)
rename-* ρ ((ƛ M) · N) rewrite sym (rename-subst-commute {N = M *}{M = N *}{ρ = ρ})
| rename-* (ext ρ) M
| rename-* ρ N
= refl
exts-ts-commute : ∀ {n m} (σ : Subst n m)
→ exts (σ *ˢ) ≡ (exts σ) *ˢ
exts-ts-commute {n} σ = extensionality exts-ts-commute′
where
exts-ts-commute′ : (x : Fin (suc n))
→ (exts (σ *ˢ)) x ≡ ((exts σ) *ˢ) x
exts-ts-commute′ zero = refl
exts-ts-commute′ (suc x) = rename-* suc (σ x)
app-*-join : ∀ {n} (M N : Term n)
→ M * · N * —↠ (M · N) *
app-*-join (# x) N = # x · N * ∎
app-*-join (ƛ M) N = (ƛ M *) · N * —→⟨ —→-β ⟩ subst (subst-zero (N *)) (M *) ∎
app-*-join (M₁ · M₂) N = (M₁ · M₂) * · N * ∎
subst-ts : ∀ {n m} (σ : Subst n m) (M : Term n)
→ subst (σ *ˢ) (M *) —↠ (subst σ M) *
subst-ts σ (# x) = σ x * ∎
subst-ts σ (ƛ M) rewrite exts-ts-commute σ = —↠-cong-ƛ (subst-ts (exts σ) M)
subst-ts σ (# x · N) = —↠-trans (—↠-congᵣ (subst-ts σ N))
(app-*-join (σ x) (subst σ N))
subst-ts σ (M₁ · M₂ · N) = —↠-cong (subst-ts σ (M₁ · M₂)) (subst-ts σ N)
subst-ts σ ((ƛ M) · N) rewrite sym (subst-commute {N = M *}{M = N *}{σ = σ *ˢ})
| exts-ts-commute σ
= sub-betas (subst-ts (exts σ) M) (subst-ts σ N)
subst-zero-ts : ∀ {n} {N : Term n}
→ subst-zero (N *) ≡ (subst-zero N) *ˢ
subst-zero-ts = extensionality (λ { zero → refl ; (suc x) → refl })
lemma3-4 : ∀ {n} (M : Term (suc n)) (N : Term n)
→ M * [ N * ] —↠ (M [ N ]) *
lemma3-4 M N rewrite subst-zero-ts {N = N} = subst-ts (subst-zero N) M
lemma3-5 : ∀ {n} {M N : Term n}
→ M —→ N
----------
→ M * —↠ N *
lemma3-5 {M = # x} ()
lemma3-5 {M = ƛ M} (—→-ƛ M—→M′) = —↠-cong-ƛ (lemma3-5 M—→M′)
lemma3-5 {M = # _ · N} (—→-ξᵣ M₂—→M′) = —↠-congᵣ (lemma3-5 M₂—→M′)
lemma3-5 {M = (ƛ M) · N} —→-β = lemma3-4 M N
lemma3-5 {M = (ƛ M) · N} (—→-ξₗ (—→-ƛ M—→M′)) = sub-betas (lemma3-5 M—→M′) (N * ∎)
lemma3-5 {M = (ƛ M) · N} (—→-ξᵣ N—→N′) = sub-betas (M * ∎) (lemma3-5 N—→N′)
lemma3-5 {M = M₁ · M₂ · _} (—→-ξᵣ N—→N′) = —↠-congᵣ (lemma3-5 N—→N′)
lemma3-5 {M = M₁ · M₂ · _} (—→-ξₗ {M′ = # x} M₁M₂—→#x) = —↠-congₗ (lemma3-5 M₁M₂—→#x)
lemma3-5 {M = M₁ · M₂ · _} (—→-ξₗ {M′ = M′₁ · M′₂} M₁M₂—→M′₁M′₂) = —↠-congₗ (lemma3-5 M₁M₂—→M′₁M′₂)
lemma3-5 {M = M₁ · M₂ · N} (—→-ξₗ {M′ = ƛ M′} M₁M₂—→ƛM′) =
—↠-trans (—↠-congₗ (lemma3-5 M₁M₂—→ƛM′))
((ƛ M′ *) · N * —→⟨ —→-β ⟩ subst (subst-zero (N *)) (M′ *) ∎)
corollary3-6 : ∀ {n} {M N : Term n}
→ M —↠ N
----------
→ M * —↠ N *
corollary3-6 (M ∎) = M * ∎
corollary3-6 (M —→⟨ M—→L ⟩ L—↠N) = —↠-trans (lemma3-5 M—→L) (corollary3-6 L—↠N)
corollary3-7 : ∀ {n} {M N : Term n} (m : ℕ)
→ M —↠ N
--------------------
→ M *⁽ m ⁾ —↠ N *⁽ m ⁾
corollary3-7 zero M—↠N = M—↠N
corollary3-7 (suc m) M—↠N = corollary3-7 m (corollary3-6 M—↠N)
theorem3-8 : ∀ {n} {M N : Term n} {m : ℕ}
→ M —↠⁽ m ⁾ N
-------------
→ N —↠ M *⁽ m ⁾
theorem3-8 {m = zero} (M ∎) = M ∎
theorem3-8 {m = suc m} (M —→⁽⁾⟨ M—→L ⟩ L—↠ᵐN) =
—↠-trans (theorem3-8 L—↠ᵐN) (corollary3-7 m (lemma3-3 M—→L))
unnamed-named : ∀ {n} {M N : Term n}
→ M —↠ N
--------------------
→ ∃[ m ] (M —↠⁽ m ⁾ N)
unnamed-named (M ∎) = zero , (M ∎)
unnamed-named (M —→⟨ M—→L ⟩ L—↠N) with unnamed-named L—↠N
... | m′ , L—↠ᵐ′N = suc m′ , (M —→⁽⁾⟨ M—→L ⟩ L—↠ᵐ′N)
lift-* : ∀ {n} (M : Term n) (m : ℕ)
→ M —↠ M *⁽ m ⁾
lift-* M zero = M ∎
lift-* M (suc m) = —↠-trans lemma3-2 (lift-* (M *) m)
complete-* : ∀ {k} (M : Term k) {n m : ℕ}
→ n ≤ m
--------------------
→ M *⁽ n ⁾ —↠ M *⁽ m ⁾
complete-* M {m = m} z≤n = lift-* M m
complete-* M (s≤s k) = complete-* (M *) k
theorem3-9 : ∀ {n} {M A B : Term n}
→ M —↠ A → M —↠ B
------------------------
→ ∃[ N ] (A —↠ N × B —↠ N)
theorem3-9 {M = M} M—↠A M—↠B =
let n , M—↠ⁿA = unnamed-named M—↠A
m , M—↠ᵐB = unnamed-named M—↠B
A—↠M*ⁿ = theorem3-8 M—↠ⁿA
B—↠M*ᵐ = theorem3-8 M—↠ᵐB
in [ (λ n≤m →
let M*ⁿ—↠M*ᵐ : M *⁽ n ⁾ —↠ M *⁽ m ⁾
M*ⁿ—↠M*ᵐ = complete-* M n≤m
in M *⁽ m ⁾ , —↠-trans A—↠M*ⁿ M*ⁿ—↠M*ᵐ , B—↠M*ᵐ)
, (λ m≤n →
let M*ᵐ—↠M*ⁿ : M *⁽ m ⁾ —↠ M *⁽ n ⁾
M*ᵐ—↠M*ⁿ = complete-* M m≤n
in M *⁽ n ⁾ , A—↠M*ⁿ , —↠-trans B—↠M*ᵐ M*ᵐ—↠M*ⁿ)
] (≤-total n m)
| 34.563452 | 126 | 0.422088 |
Subsets and Splits