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
listlengths 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
listlengths 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
listlengths 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
412f6bb857fed6454424514aa49d7f1daa1dcb5f
| 5,412
|
agda
|
Agda
|
src/TwoPassMerge/CombinedProofs.agda
|
jstolarek/dep-typed-wbl-heaps
|
57db566cb840dc70331c29eb7bf3a0c849f8b27e
|
[
"BSD-3-Clause"
] | 1
|
2018-05-02T21:48:43.000Z
|
2018-05-02T21:48:43.000Z
|
src/TwoPassMerge/CombinedProofs.agda
|
jstolarek/dep-typed-wbl-heaps
|
57db566cb840dc70331c29eb7bf3a0c849f8b27e
|
[
"BSD-3-Clause"
] | null | null | null |
src/TwoPassMerge/CombinedProofs.agda
|
jstolarek/dep-typed-wbl-heaps
|
57db566cb840dc70331c29eb7bf3a0c849f8b27e
|
[
"BSD-3-Clause"
] | null | null | null |
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Weight biased leftist tree that proves both priority and rank --
-- invariants. Uses a two-pass merging algorithm. --
----------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module TwoPassMerge.CombinedProofs where
open import Basics
open import Sized
open import TwoPassMerge.RankProof using ( makeT-lemma; proof-1; proof-2 )
-- Now that we have separate proofs of priority and rank invariants we
-- can combine them into one proof. We index Heap with two indices:
-- one for Priority and one for Rank.
data Heap : {i : Size} → Priority → Rank → Set where
empty : {i : Size} {b : Priority} → Heap {↑ i} b zero
node : {i : Size} {b : Priority} → (p : Priority) → p ≥ b → {l r : Rank} →
l ≥ r → Heap {i} p l → Heap {i} p r → Heap {↑ i} b (suc (l + r))
-- Now we will combine functions that prove priority invariant and
-- functions that prove rank invariant into functions that prove both
-- invariants.
-- Let's begin with singleton. Note the type of created Heap. We set
-- first index to zero, because it proves the priority invariant and
-- second index to one because it proves rank invariant. The node now
-- needs two ge0 evidence.
singleton : Priority → Heap zero one
singleton p = node p ge0 ge0 empty empty
-- makeT function requires that we supply evidence that priority
-- invariant holds (value of type p ≥ b), guarantees that resulting
-- heap has correct size and maintains rank invariant by using Order
-- type to supply evidence of rank correctness to node constructor.
makeT : {b : Priority} {l r : Rank} → (p : Priority) → p ≥ b →
Heap p l → Heap p r → Heap b (suc (l + r))
makeT {b} {l-rank} {r-rank} p p≥n l r with order l-rank r-rank
makeT {b} {l-rank} {r-rank} p p≥n l r | ge l≥r
= node p p≥n l≥r l r
makeT {b} {l-rank} {r-rank} p p≥n l r | le r≥l
= subst (Heap b) (makeT-lemma r-rank l-rank) (node p p≥n r≥l r l)
-- merge combines previous proofs:
--
-- 1) it enforces priority invariant by comparing priorities using
-- order function. Recall that this function returns value of
-- Order datatype that not only gives a result of comparison but
-- also supplies evidence that result is true. That evidence is
-- given to makeT which uses it to construct a new node.
--
-- 2) it proves size invariant of merge by reusing proofs from
-- TwoPassMerge.RankProof
--
-- 3) it delegates the proof of rank invariant to makeT
merge : {i j : Size} {b : Priority} {l r : Rank} → Heap {i} b l → Heap {j} b r
→ Heap b (l + r)
merge empty h2 = h2 -- See [merge, proof 0a]
merge {_} .{_} {b} {suc l} {zero} h1 empty
= subst (Heap b)
(sym (+0 (suc l))) -- See [merge, proof 0b]
h1
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
with order p1 p2
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| le p1≤p2
= subst (Heap b)
(proof-1 l1-rank r1-rank l2-rank r2-rank) -- See [merge, proof 1]
(makeT p1 p1≥b l1 (merge {i} {↑ j} r1 (node p2 p1≤p2 l2≥r2 l2 r2)))
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| ge p1≥p2
= subst (Heap b)
(proof-2 l1-rank r1-rank l2-rank r2-rank) -- See [merge, proof 2]
(makeT p2 p2≥b l2 (merge {j} {↑ i} r2 (node p1 p1≥p2 l1≥r1 l1 r1)))
-- Implementations of insert and findMin are the same as
-- previously. We only need to update the type signature accordingly.
insert : {b : Priority} {r : Rank} → Priority → Heap zero r → Heap zero (suc r)
insert p h = merge (singleton p) h
findMin : {b : Priority} {r : Rank} → Heap b (suc r) → Priority
findMin (node p _ _ _ _) = p
-- To define deleteMin we will need to update definition of
-- liftBound. We need to redefine ≥trans because Agda won't let us
-- import it from a module that has unfinished implementation (recall
-- that we left definitions of findMin and deleteMin incomplete in
-- TwoPassMerge.PriorityProof).
≥trans : {a b c : Nat} → a ≥ b → b ≥ c → a ≥ c
≥trans a≥b ge0 = ge0
≥trans (geS a≥b) (geS b≥c) = geS (≥trans a≥b b≥c)
liftBound : {p b : Priority} → b ≥ p → {r : Rank} → Heap b r → Heap p r
liftBound b≥n empty = empty
liftBound b≥n (node p p≥b l≥r l r) = node p (≥trans p≥b b≥n) l≥r l r
-- With the new definition of liftBound we can now define deleteMin.
-- Implementation is identical to the one in TwoPassMerge.RankProof -
-- we only had to update type signature.
deleteMin : {b : Priority} {r : Rank} → Heap b (suc r) → Heap b r
deleteMin (node _ p≥b _ l r) = merge (liftBound p≥b l) (liftBound p≥b r)
| 47.893805
| 79
| 0.602919
|
38e807ef5ee7efe5c50d5ac22f64db55cb997813
| 14,865
|
agda
|
Agda
|
SeparationLogic.agda
|
iwilare/imp-semantics
|
cb98e3b3b93362654b79152bfdf2c21eb4951fcc
|
[
"MIT"
] | 6
|
2020-09-08T11:54:07.000Z
|
2022-02-24T22:29:44.000Z
|
SeparationLogic.agda
|
iwilare/imp-semantics
|
cb98e3b3b93362654b79152bfdf2c21eb4951fcc
|
[
"MIT"
] | null | null | null |
SeparationLogic.agda
|
iwilare/imp-semantics
|
cb98e3b3b93362654b79152bfdf2c21eb4951fcc
|
[
"MIT"
] | null | null | null |
open import Data.Nat using (ℕ; _+_) renaming (_≤?_ to _≤?ₙ_)
open import Data.Bool using (Bool; true; false; not; _∧_)
open import Data.String using (String)
open import Data.Sum using (_⊎_; [_,_]; inj₁; inj₂)
open import Relation.Binary using (Decidable)
open import Relation.Nullary using (yes; no; ¬_)
open import Relation.Nullary.Negation using (contradiction)
open import Data.List using (List; []; _∷_)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Data.Empty using (⊥-elim)
open import Data.Product using (_×_; -,_; _-,-_; ∃; ∃-syntax) renaming (_,_ to _,,_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
open import Level using (Level; suc; _⊔_)
open import Agda.Builtin.Sigma hiding (_,_) -- renaming (_,_ to _,,_)
open import Data.Maybe using (Maybe; just; nothing; Is-just)
import Relation.Binary.PropositionalEquality as Eq
open import IMP hiding (com; state) ---using (aexp; aval; bexp; bval)
postulate
_≟_ : Decidable {A = ℕ} _≡_
addr = ℕ
heap = addr → Maybe val
store = vname → val
state = store × heap
assn : ∀{l} → Set (suc l)
assn {a} = store → heap → Set a
emp : assn
emp _ h = ∀ a → h a ≡ nothing
_⊢>_ : IMP.aexp → IMP.aexp → assn
_⊢>_ a a′ s h = h (aval a s) ≡ just (aval a′ s)
× ∀ (a″) → ¬(a″ ≡ aval a s) → h a″ ≡ nothing
_⊆_ : heap → heap → Set
h₀ ⊆ h = ∀ a → (h a ≡ nothing → h₀ a ≡ nothing)
× (∀{o} → h₀ a ≡ just o → h₀ a ≡ h a)
heap-union : heap → heap → heap → addr → Set
heap-union h h₁ h₂ a with h a
... | just o = (h₁ a ≡ just o × h₂ a ≡ nothing)
⊎ (h₁ a ≡ nothing × h₂ a ≡ just o)
... | nothing = h₁ a ≡ nothing × h₂ a ≡ nothing
_∼_⊥_ : heap → heap → heap → Set
h ∼ h₁ ⊥ h₂ = ∀ a → heap-union h h₁ h₂ a
union-subset : ∀ h {h₁ h₂}
→ h ∼ h₁ ⊥ h₂
→ h₁ ⊆ h
union-subset h x a with h a | x a
union-subset h x a | just x₁ | inj₁ (fst₁ ,, snd₁) = (λ ()) ,, (λ {x} x₁ → fst₁)
union-subset h x a | just x₁ | inj₂ (fst₁ ,, snd₁) rewrite fst₁ = (λ _ → refl) ,, (λ {x} ())
union-subset h x a | nothing | fst₁ ,, snd₁ = (λ x → fst₁) ,, (λ {x} x₁ → fst₁)
_*_ : ∀{l} → assn {l} → assn {l} → assn {l}
_*_ P Q s h = ∃[ h₁ ] ∃[ h₂ ] ((h ∼ h₁ ⊥ h₂)
× P s h₁
× Q s h₂)
_dom_ : addr → heap → Set
a dom h = ∃[ v ] (h a ≡ just v)
_¬dom_ : addr → heap → Set
a ¬dom h = h a ≡ nothing
_[_::=ₕ_] : heap → addr → val → heap
(h [ X ::=ₕ n ]) Y with Y ≟ X
... | yes _ = just n
... | no _ = h Y
_/[_] : heap → addr → heap
(h /[ X ]) Y with Y ≟ X
... | yes _ = nothing
... | no _ = h Y
data com : Set where
SKIP : com
_::=_ : String → aexp → com
_::_ : com → com → com
IF_THEN_ELSE_ : bexp → com → com → com
WHILE_DO_ : bexp → com → com
_::=cons_ : String → addr → com
_::=[_] : String → aexp → com
[_]::=_ : aexp → aexp → com
dispose_ : aexp → com
data ⊢[_]_[_] {l} : assn {l} → com → assn {l} → Set (suc l) where
Skip : ∀{P}
→ ⊢[ P ] SKIP [ P ]
Loc : ∀{Q a x}
→ ⊢[ (λ s → Q (s [ x ::= aval a s ])) ] (x ::= a) [ Q ]
Comp : ∀{P Q R c₁ c₂}
→ ⊢[ P ] c₁ [ Q ]
→ ⊢[ Q ] c₂ [ R ]
→ ⊢[ P ] c₁ :: c₂ [ R ]
If : ∀{P b c₁ Q c₂}
→ ⊢[ (λ s h → P s h × bval b s ≡ true) ] c₁ [ Q ]
→ ⊢[ (λ s h → P s h × bval b s ≡ false) ] c₂ [ Q ]
→ ⊢[ P ] (IF b THEN c₁ ELSE c₂) [ Q ]
While : ∀{P b c}
→ ⊢[ (λ s h → P s h × bval b s ≡ true) ] c [ P ]
→ ⊢[ P ] (WHILE b DO c) [ (λ s h → P s h × bval b s ≡ false) ]
Conseq : ∀{P Q P′ Q′ : assn} {c}
→ (∀ s h → P′ s h → P s h)
→ ⊢[ P ] c [ Q ]
→ (∀ s h → Q s h → Q′ s h)
→ ⊢[ P′ ] c [ Q′ ]
Frame : ∀{A B R c}
→ ⊢[ A ] c [ B ]
→ ⊢[ A * R ] c [ B * R ]
data config : Set where
⦅_,_,_⦆ : com → store → heap → config
abort : config
data _⇒_ : config → config → Set where
Loc : ∀{x a s h}
→ ⦅ x ::= a , s , h ⦆ ⇒ ⦅ SKIP , (s [ x ::= aval a s ]) , h ⦆
Comp₁ : ∀{c s h}
→ ⦅ SKIP :: c , s , h ⦆ ⇒ ⦅ c , s , h ⦆
Comp₂ : ∀{c₁ c₁′ c₂ s s′ h h′}
→ ⦅ c₁ , s , h ⦆ ⇒ ⦅ c₁′ , s′ , h′ ⦆
→ ⦅ c₁ :: c₂ , s , h ⦆ ⇒ ⦅ c₁′ :: c₂ , s′ , h′ ⦆
CompFail : ∀{c₁ c₂ s h}
→ ⦅ c₁ , s , h ⦆ ⇒ abort
→ ⦅ c₁ :: c₂ , s , h ⦆ ⇒ abort
IfTrue : ∀{b s c₁ c₂ h}
→ bval b s ≡ true
→ ⦅ IF b THEN c₁ ELSE c₂ , s , h ⦆ ⇒ ⦅ c₁ , s , h ⦆
IfFalse : ∀{b s c₁ c₂ h}
→ bval b s ≡ false
→ ⦅ IF b THEN c₁ ELSE c₂ , s , h ⦆ ⇒ ⦅ c₂ , s , h ⦆
While : ∀{b s c h}
→ ⦅ WHILE b DO c , s , h ⦆ ⇒ ⦅ IF b THEN (c :: (WHILE b DO c)) ELSE SKIP , s , h ⦆
Cons : ∀{l h s x h′ s′}
→ l ¬dom h
→ h′ ≡ h [ l ::=ₕ 0 ]
→ s′ ≡ s [ x ::= l ]
→ ⦅ x ::=cons l , s , h ⦆ ⇒ ⦅ SKIP , s′ , h′ ⦆
Lookup : ∀{a s x h v s′}
→ (aval a s) dom h
→ s′ ≡ s [ x ::= v ]
→ ⦅ x ::=[ a ] , s , h ⦆ ⇒ ⦅ SKIP , s′ , h ⦆
LookupFail : ∀{a s x h}
→ (aval a s) ¬dom h
→ ⦅ x ::=[ a ] , s , h ⦆ ⇒ abort
Write : ∀{a s a′ h}
→ (aval a s) dom h
→ ⦅ [ a ]::= a′ , s , h ⦆ ⇒ ⦅ SKIP , s , h [ aval a s ::=ₕ aval a′ s ] ⦆
WriteFail : ∀{a s a′ x h}
→ (aval a s) ¬dom h
→ ⦅ [ x ]::= a′ , s , h ⦆ ⇒ abort
Dispose : ∀{a s h}
→ (aval a s) dom h
→ ⦅ dispose a , s , h ⦆ ⇒ ⦅ SKIP , s , h /[ aval a s ] ⦆
DisposeFail : ∀{a s h}
→ (aval a s) ¬dom h
→ ⦅ dispose a , s , h ⦆ ⇒ abort
data _⇒*_ : config → config → Set where
_∎ : ∀ c → c ⇒* c
_→⟨_⟩_ : ∀ c {c′ c″}
→ c ⇒ c′
→ c′ ⇒* c″
→ c ⇒* c″
Safe : config → Set
Safe c = ¬ (c ⇒* abort)
lemma1 : ∀{c s h₀ h}
→ h₀ ⊆ h
→ ⦅ c , s , h ⦆ ⇒ abort
→ ⦅ c , s , h₀ ⦆ ⇒ abort
lemma1 sub (CompFail r) = CompFail (lemma1 sub r)
lemma1 sub (LookupFail {a}{s} r) = LookupFail (fst (sub (aval a s)) r)
lemma1 sub (WriteFail {a}{s} r) = WriteFail {a} (fst (sub (aval a s)) r)
lemma1 sub (DisposeFail {a}{s} r) = DisposeFail (fst (sub (aval a s)) r)
subset-update : ∀ l {h h₀ v}
→ h₀ ⊆ h
→ (h₀ [ l ::=ₕ v ]) ⊆ (h [ l ::=ₕ v ])
subset-update l b Y with Y ≟ l
... | yes p = (λ x → x) ,, λ {o} _ → refl
... | no ¬p = b Y
subset-delete : ∀ v {h h₀}
→ h₀ ⊆ h
→ (h₀ /[ v ]) ⊆ (h /[ v ])
subset-delete l b Y with Y ≟ l
... | yes p = (λ x → refl) ,, (λ {x} x₁ → refl)
... | no ¬p = b Y
lemma2 : ∀ h₀ {h c c′ s s′ h′}
→ h₀ ⊆ h
→ ⦅ c , s , h ⦆ ⇒ ⦅ c′ , s′ , h′ ⦆
→ ⦅ c , s , h₀ ⦆ ⇒ abort
⊎ (∃[ h′₀ ] (h′₀ ⊆ h′
× ⦅ c , s , h₀ ⦆ ⇒ ⦅ c′ , s′ , h′₀ ⦆))
lemma2 h₀ x Loc = inj₂ (h₀ ,, x ,, Loc)
lemma2 h₀ x Comp₁ = inj₂ (h₀ ,, x ,, Comp₁)
lemma2 h₀ x (Comp₂ x₁) with lemma2 h₀ x x₁
lemma2 h₀ x (Comp₂ x₁) | inj₁ x₂ = inj₁ (CompFail x₂)
lemma2 h₀ x (Comp₂ x₁) | inj₂ (h′₀ ,, sub ,, red) = inj₂ (h′₀ ,, sub ,, Comp₂ red)
lemma2 h₀ x (IfTrue x₁) = inj₂ (h₀ ,, x ,, IfTrue x₁)
lemma2 h₀ x (IfFalse x₁) = inj₂ (h₀ ,, x ,, IfFalse x₁)
lemma2 h₀ x While = inj₂ (h₀ ,, x ,, While)
lemma2 h₀ x (Cons {l} x₁ A B) rewrite A | B = inj₂ ( (h₀ [ l ::=ₕ 0 ])
,, subset-update l x
,, Cons (fst (x l) x₁) refl refl)
lemma2 h₀ x (Lookup {a}{s} (_ ,, p) A) rewrite A with h₀ (aval a s) | Eq.inspect h₀ (aval a s)
... | nothing | Eq.[ eq ] = inj₁ (LookupFail eq)
... | just o | Eq.[ eq ] = inj₂ ( h₀
,, x
,, Lookup (-, Eq.trans (snd (x (aval a s)) eq) p) refl)
lemma2 h₀ x (Write {a}{s}{a′} (_ ,, x₁)) with h₀ (aval a s) | Eq.inspect h₀ (aval a s)
... | nothing | Eq.[ eq ] = inj₁ (WriteFail {a} eq)
... | just o | Eq.[ eq ] = inj₂ ( (h₀ [ aval a s ::=ₕ aval a′ s ])
,, subset-update (aval a s) x
,, Write (-, (Eq.trans (snd (x (aval a s)) eq) x₁)))
lemma2 h₀ x (Dispose {a}{s} (_ ,, x₁)) with h₀ (aval a s) | Eq.inspect h₀ (aval a s)
... | nothing | Eq.[ eq ] = inj₁ (DisposeFail eq)
... | just o | Eq.[ eq ] = inj₂ ( (h₀ /[ aval a s ])
,, subset-delete (aval a s) x
,, Dispose (-, (Eq.trans (snd (x (aval a s)) eq) x₁)))
frame1sub : ∀{c s h H}
→ h ⊆ H
→ Safe ⦅ c , s , h ⦆
→ Safe ⦅ c , s , H ⦆
frame1sub {c}{s}{h}{H} x x₁ (_→⟨_⟩_ .(⦅ c , s , H ⦆) {⦅ x₄ , x₅ , x₆ ⦆} x₂ x₃) with lemma2 h x x₂
... | inj₁ x₇ = x₁ (⦅ c , s , h ⦆ →⟨ x₇ ⟩ (abort ∎))
... | inj₂ (_ ,, fst₂ ,, snd₁) = frame1sub fst₂ (λ z → x₁ (_ →⟨ snd₁ ⟩ z)) x₃
frame1sub {c}{s}{h}{H} x x₁ (_→⟨_⟩_ .(⦅ c , s , H ⦆) {abort} x₂ x₃) = x₁ (_ →⟨ lemma1 x x₂ ⟩ (abort ∎))
frame1 : ∀{c s h H z}
→ H ∼ h ⊥ z
→ Safe ⦅ c , s , h ⦆
→ Safe ⦅ c , s , H ⦆
frame1 {H = H} x x₁ x₂ = frame1sub (union-subset H x) x₁ x₂
heap-union-update : ∀{l h h₀ h₁ v}
→ l ¬dom h₁
→ h ∼ h₀ ⊥ h₁
→ (h [ l ::=ₕ v ]) ∼ (h₀ [ l ::=ₕ v ]) ⊥ h₁
heap-union-update {l}{h}{v = v} d x a with (h [ l ::=ₕ v ]) a | Eq.inspect (h [ l ::=ₕ v ]) a
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] with a ≟ l | h a | Eq.inspect h a | x a
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | yes p | just x₂ | Eq.[ eq2 ] | inj₁ x₃ = inj₁ (eq ,, snd x₃)
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | yes p | just x₂ | Eq.[ eq2 ] | inj₂ y rewrite p = inj₁ (eq ,, d)
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | yes p | nothing | Eq.[ eq2 ] | C = inj₁ (eq ,, snd C)
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₁ x₃ rewrite (Eq.trans (sym eq) eq2) = inj₁ x₃
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₂ y rewrite (Eq.trans (sym eq) eq2) = inj₂ y
heap-union-update {l}{h} d x a | just x₁ | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | C rewrite (Eq.trans (sym eq) eq2) = inj₁ C
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] with a ≟ l | h a | Eq.inspect h a | x a
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₁ x₂ = Eq.trans (Eq.trans (fst x₂) (sym eq2)) eq ,, snd x₂
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₂ y = fst y ,, Eq.trans (snd y) (Eq.trans (sym eq2) eq)
heap-union-update {l}{h} d x a | nothing | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | E = E
heap-union-delete : ∀{h h₀ h₁ v}
→ v ¬dom h₁
→ h ∼ h₀ ⊥ h₁
→ (h /[ v ]) ∼ (h₀ /[ v ]) ⊥ h₁
heap-union-delete {h}{h₀}{h₁}{v} d x a with (h /[ v ]) a | Eq.inspect (h /[ v ]) a
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] with a ≟ v | h a | Eq.inspect h a | x a
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ () ] | yes p | just x₂ | Eq.[ eq2 ] | R
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₁ x₃ rewrite (Eq.trans (sym eq) eq2) = inj₁ x₃
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] | no ¬p | just x₂ | Eq.[ eq2 ] | inj₂ y rewrite (Eq.trans (sym eq) eq2) = inj₂ y
heap-union-delete {h} {h₀} {h₁} {v} d x a | just x₁ | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | fst₁ ,, snd₁ = inj₂ (fst₁ ,, Eq.trans snd₁ (Eq.trans (sym eq2) eq))
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] with a ≟ v | h a | Eq.inspect h a | x a
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | yes p | just x₁ | Eq.[ eq2 ] | inj₁ x₂ = refl ,, snd x₂
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | yes p | just x₁ | Eq.[ eq2 ] | inj₂ y rewrite p = refl ,, d
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | yes p | nothing | Eq.[ eq2 ] | E = refl ,, snd E
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₁ x₂ = Eq.trans (fst x₂) (Eq.trans (sym eq2) eq) ,, snd x₂
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | no ¬p | just x₁ | Eq.[ eq2 ] | inj₂ y = fst y ,, Eq.trans (snd y) (Eq.trans (sym eq2) eq)
heap-union-delete {h} {h₀} {h₁} {v} d x a | nothing | Eq.[ eq ] | no ¬p | nothing | Eq.[ eq2 ] | E = E
union-exclusionᵣ : ∀{l h h₀ h₁}
→ h ∼ h₀ ⊥ h₁
→ l ¬dom h
→ l ¬dom h₁
union-exclusionᵣ {l}{h} A B with h l | A l
... | nothing | fst₁ ,, snd₁ = snd₁
union-presenceᵣ : ∀{l h h₀ h₁}
→ h ∼ h₀ ⊥ h₁
→ l dom h
→ l dom h₀
→ l ¬dom h₁
union-presenceᵣ {l}{h} A B C with h l | A l
union-presenceᵣ {l} {h} A B C | just x | inj₁ (fst₁ ,, snd₁) = snd₁
union-presenceᵣ {l} {h} A B (fst₁ ,, snd₁) | just x | inj₂ (fst₂ ,, snd₂) with Eq.trans (sym fst₂) snd₁
... | ()
union-reduction : ∀{a b c s h′ h h₀ h′₀ h₁}
→ ⦅ c , s , h₀ ⦆ ⇒ ⦅ a , b , h′₀ ⦆
→ ⦅ c , s , h ⦆ ⇒ ⦅ a , b , h′ ⦆
→ h ∼ h₀ ⊥ h₁
→ h′ ∼ h′₀ ⊥ h₁
union-reduction Loc Loc C = C
union-reduction Comp₁ Comp₁ C = C
union-reduction (Comp₂ A) (Comp₂ B) C = union-reduction A B C
union-reduction (IfTrue x) (IfTrue x₁) C = C
union-reduction (IfTrue x) (IfFalse x₁) C = C
union-reduction (IfFalse x) (IfTrue x₁) C = C
union-reduction (IfFalse x) (IfFalse x₁) C = C
union-reduction While While C = C
union-reduction (Cons d A B) (Cons d2 A′ B′) C a rewrite A | B | A′ | B′ = heap-union-update (union-exclusionᵣ C d2) C a
union-reduction (Lookup e A) (Lookup e2 A′) C rewrite A | A′ = C
union-reduction (Write x) (Write x₁) C a = heap-union-update (union-presenceᵣ C x₁ x) C a
union-reduction (Dispose x) (Dispose x₁) C a = heap-union-delete (union-presenceᵣ C x₁ x) C a
frame2 : ∀{c s h h₀ h₁ h′ s′}
→ Safe ⦅ c , s , h₀ ⦆
→ h ∼ h₀ ⊥ h₁
→ ⦅ c , s , h ⦆ ⇒* ⦅ SKIP , s′ , h′ ⦆
→ ∃[ h′₀ ] ( ⦅ c , s , h₀ ⦆ ⇒* ⦅ SKIP , s′ , h′₀ ⦆
× h′ ∼ h′₀ ⊥ h₁ )
frame2 s t (.(⦅ SKIP , _ , _ ⦆) ∎) = _ ,, (_ ∎) ,, t
frame2 {h₀ = h₀} s t (_→⟨_⟩_ .(⦅ _ , _ , _ ⦆) {⦅ _ , _ , _ ⦆} x r) with lemma2 h₀ (union-subset _ t) x
... | inj₁ x₄ = ⊥-elim (s (_ →⟨ x₄ ⟩ (abort ∎)))
... | inj₂ (fst₁ ,, fst₂ ,, snd₁) with frame2 (λ z → s (_ →⟨ snd₁ ⟩ z)) (union-reduction snd₁ x t) r
... | fst₃ ,, fst₄ ,, snd₂ = fst₃ ,, (_ →⟨ snd₁ ⟩ fst₄) ,, snd₂
frame2 s t (_→⟨_⟩_ .(⦅ _ , _ , _ ⦆) {abort} x (.abort →⟨ () ⟩ r))
⊨[_]_[_] : assn → com → assn → Set
⊨[ A ] c [ B ] = ∀{s h}
→ A s h
→ Safe ⦅ c , s , h ⦆
× (∀{s′ h′} → ⦅ c , s , h ⦆ ⇒* ⦅ SKIP , s′ , h′ ⦆ → B s′ h′)
NotInfluenced : assn → com → Set
NotInfluenced R c = ∀{s s′ z h₀ h′₀ hᵣ}
→ z ∼ h′₀ ⊥ hᵣ
→ ⦅ c , s , h₀ ⦆ ⇒* ⦅ SKIP , s′ , h′₀ ⦆
→ R s hᵣ → R s′ hᵣ
frame-soundness : ∀{A B R : assn} {c}
→ NotInfluenced R c
→ ⊨[ A ] c [ B ]
→ ⊨[ A * R ] c [ B * R ]
frame-soundness {A}{B}{R}{c} Inf H {s}{h} (h₀ ,, h₁ ,, ⊥ ,, A₀ ,, R₁) with H A₀
... | safe ,, conv = frame1 ⊥ safe ,, frame2-ex
where frame2-ex : ∀{s′ h′}
→ ⦅ c , s , h ⦆ ⇒* ⦅ SKIP , s′ , h′ ⦆
→ ∃[ h₁ ] ∃[ h₂ ] ( (h′ ∼ h₁ ⊥ h₂)
× B s′ h₁
× R s′ h₂)
frame2-ex rs with frame2 safe ⊥ rs
... | h′₀ ,, r ,, ⊥′ = h′₀ ,, h₁ ,, ⊥′ ,, conv r ,, Inf ⊥′ r R₁
| 41.406685
| 164
| 0.469963
|
1ebfe84395caa8654bc1a75838e841d391c2a3f2
| 6,595
|
agda
|
Agda
|
TotalParserCombinators/Semantics.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | 1
|
2020-07-03T08:56:13.000Z
|
2020-07-03T08:56:13.000Z
|
TotalParserCombinators/Semantics.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
TotalParserCombinators/Semantics.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Semantics of the parsers
------------------------------------------------------------------------
module TotalParserCombinators.Semantics where
open import Codata.Musical.Notation
open import Data.List hiding (drop)
open import Data.List.Relation.Binary.BagAndSetEquality
using (bag) renaming (_∼[_]_ to _List-∼[_]_)
open import Data.Maybe using (Maybe); open Data.Maybe.Maybe
open import Data.Product
open import Data.Unit using (⊤; tt)
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence as Eq using (_⇔_; module Equivalence)
open import Function.Inverse using (_↔_; module Inverse)
open import Function.Related as Related using (Related)
open import Level
import Relation.Binary.HeterogeneousEquality as H
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import TotalParserCombinators.Parser
------------------------------------------------------------------------
-- Semantics
-- The semantics of the parsers. x ∈ p · s means that x can be the
-- result of applying the parser p to the string s. Note that the
-- semantics is defined inductively.
infix 60 <$>_
infixl 50 _⊛_ [_-_]_⊛_
infixl 10 _>>=_ [_-_]_>>=_
infix 4 _∈_·_
data _∈_·_ {Tok} :
∀ {R xs} → R → Parser Tok R xs → List Tok → Set₁ where
return : ∀ {R} {x : R} → x ∈ return x · []
token : ∀ {x} → x ∈ token · [ x ]
∣-left : ∀ {R x xs₁ xs₂ s}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂}
(x∈p₁ : x ∈ p₁ · s) → x ∈ p₁ ∣ p₂ · s
∣-right : ∀ {R x xs₂ s} xs₁
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂}
(x∈p₂ : x ∈ p₂ · s) → x ∈ p₁ ∣ p₂ · s
<$>_ : ∀ {R₁ R₂ x s xs} {p : Parser Tok R₁ xs} {f : R₁ → R₂}
(x∈p : x ∈ p · s) → f x ∈ f <$> p · s
_⊛_ : ∀ {R₁ R₂ f x s₁ s₂ fs xs}
{p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs)}
{p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)} →
(f∈p₁ : f ∈ ♭? p₁ · s₁)
(x∈p₂ : x ∈ ♭? p₂ · s₂) →
f x ∈ p₁ ⊛ p₂ · s₁ ++ s₂
_>>=_ : ∀ {R₁ R₂ x y s₁ s₂ xs} {f : Maybe (R₁ → List R₂)}
{p₁ : ∞⟨ f ⟩Parser Tok R₁ (flatten xs)}
{p₂ : (x : R₁) → ∞⟨ xs ⟩Parser Tok R₂ (apply f x)}
(x∈p₁ : x ∈ ♭? p₁ · s₁)
(y∈p₂x : y ∈ ♭? (p₂ x) · s₂) →
y ∈ p₁ >>= p₂ · s₁ ++ s₂
nonempty : ∀ {R xs x y s} {p : Parser Tok R xs}
(x∈p : y ∈ p · x ∷ s) → y ∈ nonempty p · x ∷ s
cast : ∀ {R xs₁ xs₂ x s}
{xs₁≈xs₂ : xs₁ List-∼[ bag ] xs₂} {p : Parser Tok R xs₁}
(x∈p : x ∈ p · s) → x ∈ cast xs₁≈xs₂ p · s
-- Some variants with fewer implicit arguments. (The arguments xs and
-- fs can usually not be inferred, but I do not want to mention them
-- in the paper, so I have made them implicit in the definition
-- above.)
[_-_]_⊛_ : ∀ {Tok R₁ R₂ f x s₁ s₂} xs fs
{p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs)}
{p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)} →
f ∈ ♭? p₁ · s₁ → x ∈ ♭? p₂ · s₂ → f x ∈ p₁ ⊛ p₂ · s₁ ++ s₂
[ xs - fs ] f∈p₁ ⊛ x∈p₂ = _⊛_ {fs = fs} {xs = xs} f∈p₁ x∈p₂
[_-_]_>>=_ : ∀ {Tok R₁ R₂ x y s₁ s₂} (f : Maybe (R₁ → List R₂)) xs
{p₁ : ∞⟨ f ⟩Parser Tok R₁ (flatten xs)}
{p₂ : (x : R₁) → ∞⟨ xs ⟩Parser Tok R₂ (apply f x)} →
x ∈ ♭? p₁ · s₁ → y ∈ ♭? (p₂ x) · s₂ →
y ∈ p₁ >>= p₂ · s₁ ++ s₂
[ f - xs ] x∈p₁ >>= y∈p₂x = _>>=_ {xs = xs} {f = f} x∈p₁ y∈p₂x
------------------------------------------------------------------------
-- Parser and language equivalence
infix 4 _∼[_]_ _≈_ _≅_ _≲_
-- There are two kinds of equivalences. Parser equivalences are
-- stronger, and correspond to bag equality. Language equivalences are
-- weaker, and correspond to set equality.
open Data.List.Relation.Binary.BagAndSetEquality public
using (Kind)
renaming ( bag to parser
; set to language
; subbag to subparser
; subset to sublanguage
; superbag to superparser
; superset to superlanguage
)
-- General definition of equivalence between parsers. (Note that this
-- definition also gives access to some ordering relations.)
_∼[_]_ : ∀ {Tok R xs₁ xs₂} →
Parser Tok R xs₁ → Kind → Parser Tok R xs₂ → Set₁
p₁ ∼[ k ] p₂ = ∀ {x s} → Related k (x ∈ p₁ · s) (x ∈ p₂ · s)
-- Language equivalence. (Corresponds to set equality.)
_≈_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁
p₁ ≈ p₂ = p₁ ∼[ language ] p₂
-- Parser equivalence. (Corresponds to bag equality.)
_≅_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁
p₁ ≅ p₂ = p₁ ∼[ parser ] p₂
-- p₁ ≲ p₂ means that the language defined by p₂ contains all the
-- string/result pairs contained in the language defined by p₁.
_≲_ : ∀ {Tok R xs₁ xs₂} → Parser Tok R xs₁ → Parser Tok R xs₂ → Set₁
p₁ ≲ p₂ = p₁ ∼[ sublanguage ] p₂
-- p₁ ≈ p₂ iff both p₁ ≲ p₂ and p₂ ≲ p₁.
≈⇔≲≳ : ∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≈ p₂ ⇔ (p₁ ≲ p₂ × p₂ ≲ p₁)
≈⇔≲≳ = Eq.equivalence
(λ p₁≈p₂ →
((λ {x s} → _⟨$⟩_ (Equivalence.to (p₁≈p₂ {x = x} {s = s})))
, λ {x s} → _⟨$⟩_ (Equivalence.from (p₁≈p₂ {x = x} {s = s}))))
(λ p₁≲≳p₂ → λ {x s} → Eq.equivalence (proj₁ p₁≲≳p₂ {s = s})
(proj₂ p₁≲≳p₂ {s = s}))
-- Parser equivalence implies language equivalence.
≅⇒≈ : ∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≅ p₂ → p₁ ≈ p₂
≅⇒≈ p₁≅p₂ = Related.↔⇒ p₁≅p₂
-- Language equivalence does not (in general) imply parser
-- equivalence.
¬≈⇒≅ : ¬ (∀ {Tok R xs₁ xs₂}
{p₁ : Parser Tok R xs₁} {p₂ : Parser Tok R xs₂} →
p₁ ≈ p₂ → p₁ ≅ p₂)
¬≈⇒≅ hyp with Inverse.injective p₁≅p₂
{∣-left return} {∣-right [ tt ] return} (lemma _ _)
where
p₁ : Parser ⊤ ⊤ _
p₁ = return tt ∣ return tt
p₂ : Parser ⊤ ⊤ _
p₂ = return tt
p₁≲p₂ : p₁ ≲ p₂
p₁≲p₂ (∣-left return) = return
p₁≲p₂ (∣-right ._ return) = return
p₁≅p₂ : p₁ ≅ p₂
p₁≅p₂ = hyp $ Eq.equivalence p₁≲p₂ ∣-left
lemma : ∀ {x s} (x∈₁ x∈₂ : x ∈ p₂ · s) → x∈₁ ≡ x∈₂
lemma return return = P.refl
... | ()
------------------------------------------------------------------------
-- A simple cast lemma
cast∈ : ∀ {Tok R xs} {p p′ : Parser Tok R xs} {x x′ s s′} →
x ≡ x′ → p ≡ p′ → s ≡ s′ → x ∈ p · s → x′ ∈ p′ · s′
cast∈ P.refl P.refl P.refl x∈ = x∈
| 36.638889
| 72
| 0.511751
|
04cc77c5404f0bae332b1067b8648b17130e4029
| 4,632
|
agda
|
Agda
|
theorems/stash/homotopy/JoinAssoc.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
theorems/stash/homotopy/JoinAssoc.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
theorems/stash/homotopy/JoinAssoc.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
-- Associativity of the join (work in progress)
module experimental.JoinAssoc {i j k} (A : Type i) (B : Type j) (C : Type k) where
{- First map -}
to : (A * B) * C → A * (B * C)
to = To.f module _ where
to-left-glue : (ab : A × B) → left (fst ab) == right (left (snd ab)) :> A * (B * C)
to-left-glue (a , b) = glue (a , left b)
module ToLeft = PushoutRec left (right ∘ left) to-left-glue
to-left : A * B → A * (B * C)
to-left = ToLeft.f
to-glue-left : (c : C) (a : A) → to-left (left a) == right (right c)
to-glue-left c a = glue (a , right c)
to-glue-right : (c : C) (b : B) → to-left (right b) == right (right c)
to-glue-right c b = ap right (glue (b , c))
to-glue-glue : (c : C) (ab : A × B) → to-glue-left c (fst ab) == to-glue-right c (snd ab) [ (λ x → to-left x == right (right c)) ↓ glue ab ]
to-glue-glue c (a , b) = ↓-swap to-left right _ idp
(ToLeft.glue-β (a , b) ◃ apd (λ x → glue (a , x)) (glue (b , c)))
module ToGlue (c : C) = PushoutElim (to-glue-left c) (to-glue-right c) (to-glue-glue c)
to-glue : (ab-c : (A * B) × C) → to-left (fst ab-c) == right (right (snd ab-c))
to-glue (ab , c) = M.f ab where module M = ToGlue c
module To = PushoutRec {d = *-span (A * B) C} to-left (right ∘ right) to-glue
{- Second map -}
from : A * (B * C) → (A * B) * C
from = From.f module MM where
from-right-glue : (bc : B × C) → left (right (fst bc)) == right (snd bc)
from-right-glue (b , c) = glue (right b , c)
module FromRight = PushoutRec (left ∘ right) right from-right-glue
from-right : B * C → (A * B) * C
from-right = FromRight.f
from-glue-left : (a : A) (b : B) → left (left a) == from-right (left b)
from-glue-left a b = ap left (glue (a , b))
from-glue-right : (a : A) (c : C) → left (left a) == from-right (right c)
from-glue-right a c = glue (left a , c)
from-glue-glue : (a : A) (bc : B × C) → from-glue-left a (fst bc) == from-glue-right a (snd bc) [ (λ x → left (left a) == from-right x) ↓ glue bc ]
from-glue-glue a (b , c) = ↓-swap! left from-right _ idp
(apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c)))
module FromGlue (a : A) = PushoutElim (from-glue-left a) (from-glue-right a) (from-glue-glue a)
from-glue : (a-bc : A × (B * C)) → left (left (fst a-bc)) == from-right (snd a-bc)
from-glue (a , bc) = M.f bc where module M = FromGlue a
module From = PushoutRec {d = *-span A (B * C)} (left ∘ left) from-right from-glue
open MM public
{- First composite -}
to-from-right-glue' : (b : B) (c : C) → ap (to ∘ from-right) (glue (b , c)) =-= ap right (glue (b , c))
to-from-right-glue' b c =
ap (λ z → to (from-right z)) (glue (b , c)) =⟪ ap-∘ to from-right (glue (b , c)) ⟫
ap to (ap from-right (glue (b , c))) =⟪ FromRight.glue-β (b , c) |in-ctx ap to ⟫
ap to (glue ((right b , c) :> ((A * B) × C))) =⟪ To.glue-β (right b , c)⟫
ap right (glue (b , c)) ∎∎
to-from-right-glue : (bc : B × C) → idp == idp [ (λ x → to (from (right x)) == right x) ↓ glue bc ]
to-from-right-glue (b , c) = ↓-='-in' (! (↯ to-from-right-glue' b c))
module ToFromRight = PushoutElim (λ _ → idp) (λ _ → idp) to-from-right-glue
to-from-right : (bc : B * C) → to (from (right bc)) == right bc
to-from-right = ToFromRight.f
to-from-glue-left' : (a : A) (b : B) → ap to (ap from (glue (a , left b))) =-= glue (a , left b)
to-from-glue-left' a b =
ap to (ap from (glue (a , left b))) =⟪ From.glue-β (a , left b) |in-ctx ap to ⟫
ap to (ap left (glue (a , b))) =⟪ ∘-ap to left (glue (a , b)) ⟫
ap to-left (glue (a , b)) =⟪ ToLeft.glue-β (a , b) ⟫
glue (a , left b) ∎∎
to-from-glue-left : (a : A) (b : B) → idp == to-from-right (left b) [ (λ x → to (from x) == x) ↓ glue (a , left b) ]
to-from-glue-left a b = ↓-∘=idf-in' to from (↯ to-from-glue-left' a b)
to-from-glue-right' : (a : A) (c : C) → ap to (ap from (glue (a , right c))) =-= glue (a , right c)
to-from-glue-right' a c =
ap to (ap from (glue (a , right c))) =⟪ From.glue-β (a , right c) |in-ctx ap to ⟫
ap to (glue (left a , c)) =⟪ To.glue-β (left a , c) ⟫
glue (a , right c) ∎∎
to-from-glue-right : (a : A) (c : C) → idp == to-from-right (right c) [ (λ x → to (from x) == x) ↓ glue (a , right c) ]
to-from-glue-right a c = ↓-∘=idf-in' to from (↯ to-from-glue-right' a c)
postulate -- Not proved yet. Some of it is being worked on at JoinAssoc2
*-assoc : ((A * B) * C) ≃ (A * (B * C))
| 42.109091
| 151
| 0.523964
|
ad16acde6034b7e80652154c6d74d87d631b9d7c
| 1,233
|
agda
|
Agda
|
YonedaLemma.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 21
|
2015-07-30T01:25:12.000Z
|
2021-02-13T18:02:18.000Z
|
YonedaLemma.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 3
|
2019-01-13T13:12:33.000Z
|
2019-05-29T09:50:26.000Z
|
YonedaLemma.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 1
|
2019-11-04T21:33:13.000Z
|
2019-11-04T21:33:13.000Z
|
module YonedaLemma where
open import Library
open import Categories
open import Categories.Sets
open import Functors
open import Naturals
open import FunctorCat
HomF[-,_] : ∀{l m}{C : Cat {l}{m}}(X : Cat.Obj C) -> Fun (C Op) (Sets {m})
HomF[-,_] {C = C} B = functor
(\ X -> Hom X B)
(\ f g -> comp g f)
(ext \ _ -> idr)
(ext \ _ -> sym ass)
where open Cat C
HomN[-,_] : ∀{l m}{C : Cat {l}{m}}{X Y : Cat.Obj C}(f : Cat.Hom C X Y) ->
NatT (HomF[-,_] {C = C} X) HomF[-, Y ]
HomN[-,_] {C = C} f = natural
(comp f)
(ext \ _ -> ass)
where open Cat C
y : ∀{l m}(C : Cat {l}{m}) -> Fun C (FunctorCat (C Op) (Sets {m}))
y C = functor
HomF[-,_]
HomN[-,_]
(NatTEq (iext \ _ -> ext \ _ -> idl))
(NatTEq (iext \ _ -> ext \ _ -> ass))
where open Cat C
yleminv : ∀{l m}(C : Cat {l}{m})(F : Fun (C Op) (Sets {m}))(X : Cat.Obj C) ->
NatT (Fun.OMap (y C) X) F -> Fun.OMap F X
yleminv C F X α = NatT.cmp α {X} (Cat.iden C)
ylem : ∀{l m}(C : Cat {l}{m})(F : Fun (C Op) (Sets {m}))(X : Cat.Obj C) ->
Fun.OMap F X -> NatT (Fun.OMap (y C) X) F
ylem C F X FX = natural
(\ {X'} f -> HMap f FX)
(\{X'}{Y}{f} -> ext \ g -> sym (fcong FX (fcomp {f = f}{g = g})) )
where open Cat C; open Fun F
| 28.674419
| 77
| 0.513382
|
383b78a173fe79a4700f98e40bba49728b3c1373
| 2,763
|
agda
|
Agda
|
src/Algebra/Module/Limit.agda
|
cspollard/reals
|
a193aeebf1326f960975b19d3e31b46fddbbfaa2
|
[
"CC0-1.0"
] | null | null | null |
src/Algebra/Module/Limit.agda
|
cspollard/reals
|
a193aeebf1326f960975b19d3e31b46fddbbfaa2
|
[
"CC0-1.0"
] | null | null | null |
src/Algebra/Module/Limit.agda
|
cspollard/reals
|
a193aeebf1326f960975b19d3e31b46fddbbfaa2
|
[
"CC0-1.0"
] | null | null | null |
open import Relation.Binary using (Rel)
open import Algebra.Bundles using (CommutativeRing)
open import Algebra.Module.Morphism.Structures
open import Algebra.Module.Normed using (NormedModule)
module Algebra.Module.Limit
{r ℓr} {CR : CommutativeRing r ℓr}
(open CommutativeRing CR using () renaming (Carrier to X))
{rel} {_≤_ : Rel X rel}
{ma ℓma} (MA : NormedModule CR _≤_ ma ℓma)
{mb ℓmb} (MB : NormedModule CR _≤_ mb ℓmb)
where
open import Data.Product using (Σ-syntax; ∃-syntax; _×_; proj₁)
open CommutativeRing CR
open import Algebra.Module.Morphism.Module using (⊸-normed)
private
module MA = NormedModule MA
module MB = NormedModule MB
module MA⊸MB = NormedModule (⊸-normed MA MB)
open NormedModule MA using () renaming
( Carrierᴹ to Carrierᴬ
; _+ᴹ_ to _+ᴬ_
; _-ᴹ_ to _-ᴬ_
; ∥_∥ to ∥_∥ᴬ
; ⟨_,_⟩ to ⟨_,_⟩ᴬ
)
open NormedModule MB using () renaming
( Carrierᴹ to Carrierᴮ
; _+ᴹ_ to _+ᴮ_
; _-ᴹ_ to _-ᴮ_
; ∥_∥ to ∥_∥ᴮ
; ⟨_,_⟩ to ⟨_,_⟩ᴮ
)
open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_ using (_<_)
Limit-syntax : (L : Carrierᴮ) (f : Carrierᴬ → Carrierᴮ) (c : Carrierᴬ) → Set _
Limit-syntax L f c =
∀ ε → 0# < ε → ∃[ δ ]
∀ x →
let d = ⟨ c , x ⟩ᴬ
in (0# < d) × (d < δ) → ⟨ f x , L ⟩ᴮ < ε
syntax Limit-syntax L (λ x → f) c = f ⟶ L As x ⟶ c
Limit-syntax-0 : (L : Carrierᴮ) (f : Carrierᴬ → Carrierᴮ) → Set _
Limit-syntax-0 L f =
∀ ε → 0# < ε → ∃[ δ ]
∀ x →
let d = ∥ x ∥ᴬ
in (0# < d) × (d < δ) → ⟨ f x , L ⟩ᴮ < ε
syntax Limit-syntax-0 L (λ x → f) = f ⟶ L As x ⟶0
Limit-syntax-0-0 : (f : Carrierᴬ → Carrierᴮ) → Set _
Limit-syntax-0-0 f =
∀ ε → 0# < ε → ∃[ δ ]
∀ x →
let d = ∥ x ∥ᴬ
in (0# < d) × (d < δ) → ∥ f x ∥ᴮ < ε
syntax Limit-syntax-0-0 (λ x → f) = f ⟶0 As x ⟶0
_Approximates_At_
: (δf : MA⊸MB.Carrierᴹ)
→ (f : Carrierᴬ → Carrierᴮ)
→ (x : Carrierᴬ)
→ Set _
δf Approximates f At x = (f (x +ᴬ dx) -ᴮ (f x +ᴮ proj₁ δf dx)) ⟶0 As dx ⟶0
_Differentiates_
: (δf : Carrierᴬ → MA⊸MB.Carrierᴹ)
→ (f : Carrierᴬ → Carrierᴮ)
→ Set _
δf Differentiates f = ∀ x → (f (x +ᴬ dx) -ᴮ (f x +ᴮ proj₁ (δf x) dx)) ⟶0 As dx ⟶0
D[_,_]_~_ : (f : Carrierᴬ → Carrierᴮ) (df : Carrierᴬ → MA⊸MB.Carrierᴹ) → Set _
D[_,_]_~_ f df = df Differentiates f
_DifferentiableAt_ : (f : Carrierᴬ → Carrierᴮ) (x : Carrierᴬ) → Set _
f DifferentiableAt x = ∃[ δf ] δf Approximates f At x
Differentiable : (f : Carrierᴬ → Carrierᴮ) → Set _
Differentiable f = ∀ x → f DifferentiableAt x
D[_,_][_,_] : (f : Carrierᴬ → Carrierᴮ) (x : Carrierᴬ) → Set _
D[_,_][_,_] f x = f DifferentiableAt x
-- [_,_]~[_~_]_
-- : (δf : Carrierᴬ → Carrierᴮ)
-- → (f : Carrierᴬ → Carrierᴮ)
-- → (x : Carrierᴬ)
-- → Set _
-- [_,_][_~_]_ df f x = {! df Approximates f At x !}
| 27.356436
| 81
| 0.5903
|
2e33ffa2495e784e33b88509b6ad7afce01e1822
| 1,177
|
agda
|
Agda
|
agda-stdlib/src/Relation/Binary/Properties/Preorder.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Relation/Binary/Properties/Preorder.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Relation/Binary/Properties/Preorder.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by preorders
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Properties.Preorder
{p₁ p₂ p₃} (P : Preorder p₁ p₂ p₃) where
open import Function
open import Data.Product as Prod
open Preorder P
------------------------------------------------------------------------
-- The inverse relation is also a preorder.
invIsPreorder : IsPreorder _≈_ (flip _∼_)
invIsPreorder = record
{ isEquivalence = isEquivalence
; reflexive = reflexive ∘ Eq.sym
; trans = flip trans
}
invPreorder : Preorder p₁ p₂ p₃
invPreorder = record
{ isPreorder = invIsPreorder
}
------------------------------------------------------------------------
-- For every preorder there is an induced equivalence
InducedEquivalence : Setoid _ _
InducedEquivalence = record
{ _≈_ = λ x y → x ∼ y × y ∼ x
; isEquivalence = record
{ refl = (refl , refl)
; sym = swap
; trans = Prod.zip trans (flip trans)
}
}
| 25.586957
| 72
| 0.504673
|
22c6e4b2c5551cbc62fd28a0815972ab50c77fdb
| 140
|
agda
|
Agda
|
test/interaction/Issue2166.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue2166.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue2166.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.cover.split.con:100 #-}
{-# OPTIONS --show-implicit #-}
data D : Set where
d : {x : D} → D
f : D → Set
f y = {!!}
| 14
| 44
| 0.492857
|
9a1e191f9b82c43f522ef1ae3074d12e70adbc89
| 9,541
|
agda
|
Agda
|
vendor/stdlib/src/Data/List/Countdown.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Data/List/Countdown.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Data/List/Countdown.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- A data structure which keeps track of an upper bound on the number
-- of elements /not/ in a given list
------------------------------------------------------------------------
open import Relation.Binary
module Data.List.Countdown (D : DecSetoid) where
open import Data.Empty
open import Data.Fin using (Fin; zero; suc)
open import Data.Function
open import Data.List
open import Data.List.Any as Any using (here; there)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product
open import Data.Sum
open import Relation.Nullary
open import Relation.Binary.FunctionSetoid
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong)
open PropEq.≡-Reasoning
private
open module D = DecSetoid D
hiding (refl) renaming (carrier to Elem)
open Any.Membership D.setoid
------------------------------------------------------------------------
-- Helper functions
private
drop-suc : ∀ {n} {i j : Fin n} →
_≡_ {Fin (suc n)} (suc i) (suc j) → i ≡ j
drop-suc refl = refl
drop-inj₂ : ∀ {A B x y} → inj₂ {A} {B} x ≡ inj₂ y → x ≡ y
drop-inj₂ refl = refl
-- The /first/ occurrence of x in xs.
first-occurrence : ∀ {xs} x → x ∈ xs → x ∈ xs
first-occurrence x (here x≈y) = here x≈y
first-occurrence x (there {x = y} x∈xs) with x ≟ y
... | yes x≈y = here x≈y
... | no _ = there $ first-occurrence x x∈xs
-- The index of the first occurrence of x in xs.
first-index : ∀ {xs} x → x ∈ xs → Fin (length xs)
first-index x x∈xs = Any.index $ first-occurrence x x∈xs
-- first-index preserves equality of its first argument.
first-index-pres : ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
x₁ ≈ x₂ → first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs
first-index-pres {x₁} {x₂} x₁∈xs x₂∈xs x₁≈x₂ = helper x₁∈xs x₂∈xs
where
helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs
helper (here x₁≈x) (here x₂≈x) = refl
helper (here x₁≈x) (there {x = x} x₂∈xs) with x₂ ≟ x
... | yes x₂≈x = refl
... | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x))
helper (there {x = x} x₁∈xs) (here x₂≈x) with x₁ ≟ x
... | yes x₁≈x = refl
... | no x₁≉x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x))
helper (there {x = x} x₁∈xs) (there x₂∈xs) with x₁ ≟ x | x₂ ≟ x
... | yes x₁≈x | yes x₂≈x = refl
... | yes x₁≈x | no x₂≉x = ⊥-elim (x₂≉x (trans (sym x₁≈x₂) x₁≈x))
... | no x₁≉x | yes x₂≈x = ⊥-elim (x₁≉x (trans x₁≈x₂ x₂≈x))
... | no x₁≉x | no x₂≉x = cong suc $ helper x₁∈xs x₂∈xs
-- first-index is injective in its first argument.
first-index-injective
: ∀ {x₁ x₂ xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂
first-index-injective {x₁} {x₂} = helper
where
helper : ∀ {xs} (x₁∈xs : x₁ ∈ xs) (x₂∈xs : x₂ ∈ xs) →
first-index x₁ x₁∈xs ≡ first-index x₂ x₂∈xs → x₁ ≈ x₂
helper (here x₁≈x) (here x₂≈x) _ = trans x₁≈x (sym x₂≈x)
helper (here x₁≈x) (there {x = x} x₂∈xs) _ with x₂ ≟ x
helper (here x₁≈x) (there {x = x} x₂∈xs) _ | yes x₂≈x = trans x₁≈x (sym x₂≈x)
helper (here x₁≈x) (there {x = x} x₂∈xs) () | no x₂≉x
helper (there {x = x} x₁∈xs) (here x₂≈x) _ with x₁ ≟ x
helper (there {x = x} x₁∈xs) (here x₂≈x) _ | yes x₁≈x = trans x₁≈x (sym x₂≈x)
helper (there {x = x} x₁∈xs) (here x₂≈x) () | no x₁≉x
helper (there {x = x} x₁∈xs) (there x₂∈xs) _ with x₁ ≟ x | x₂ ≟ x
helper (there {x = x} x₁∈xs) (there x₂∈xs) _ | yes x₁≈x | yes x₂≈x = trans x₁≈x (sym x₂≈x)
helper (there {x = x} x₁∈xs) (there x₂∈xs) () | yes x₁≈x | no x₂≉x
helper (there {x = x} x₁∈xs) (there x₂∈xs) () | no x₁≉x | yes x₂≈x
helper (there {x = x} x₁∈xs) (there x₂∈xs) eq | no x₁≉x | no x₂≉x =
helper x₁∈xs x₂∈xs (drop-suc eq)
-- If there are at least two elements in Fin (suc n), then Fin n is
-- inhabited. This is a variant of the thick function from Conor
-- McBride's "First-order unification by structural recursion".
thick : ∀ {n} (i j : Fin (suc n)) → i ≢ j → Fin n
thick zero zero i≢j = ⊥-elim (i≢j refl)
thick zero (suc j) _ = j
thick {zero} (suc ()) _ _
thick {suc n} (suc i) zero _ = zero
thick {suc n} (suc i) (suc j) i≢j =
suc (thick i j (i≢j ∘ cong suc))
-- thick i is injective in one of its arguments.
thick-injective : ∀ {n} (i j k : Fin (suc n))
{i≢j : i ≢ j} {i≢k : i ≢ k} →
thick i j i≢j ≡ thick i k i≢k → j ≡ k
thick-injective zero zero _ {i≢j = i≢j} _ = ⊥-elim (i≢j refl)
thick-injective zero _ zero {i≢k = i≢k} _ = ⊥-elim (i≢k refl)
thick-injective zero (suc j) (suc k) j≡k = cong suc j≡k
thick-injective {zero} (suc ()) _ _ _
thick-injective {suc n} (suc i) zero zero _ = refl
thick-injective {suc n} (suc i) zero (suc k) ()
thick-injective {suc n} (suc i) (suc j) zero ()
thick-injective {suc n} (suc i) (suc j) (suc k) eq =
cong suc $ thick-injective i j k (drop-suc eq)
------------------------------------------------------------------------
-- The countdown data structure
-- If counted ⊕_n is inhabited then there are at most n values of type
-- Elem which are not members of counted (up to _≈_). You can read the
-- symbol _⊕_ as partitioning Elem into two parts: counted and
-- uncounted.
infix 4 _⊕_
record _⊕_ (counted : List Elem) (n : ℕ) : Set where
field
-- An element can be of two kinds:
-- ⑴ It is provably in counted.
-- ⑵ It is one of at most n elements which may or may not be in
-- counted. The "at most n" part is guaranteed by the field
-- "injective".
kind : ∀ x → x ∈ counted ⊎ Fin n
injective : ∀ {x y i} → kind x ≡ inj₂ i → kind y ≡ inj₂ i → x ≈ y
-- A countdown can be initialised by proving that Elem is finite.
empty : ∀ {n} → Injection D.setoid (PropEq.setoid (Fin n)) → [] ⊕ n
empty inj =
record { kind = inj₂ ∘ _⟨$⟩_ to
; injective = λ {x} {y} {i} eq₁ eq₂ → injective (begin
to ⟨$⟩ x ≡⟨ drop-inj₂ eq₁ ⟩
i ≡⟨ PropEq.sym $ drop-inj₂ eq₂ ⟩
to ⟨$⟩ y ∎)
}
where open Injection inj
-- A countdown can also be initialised by proving that Elem is finite.
emptyFromList : (counted : List Elem) → (∀ x → x ∈ counted) →
[] ⊕ length counted
emptyFromList counted complete = empty record
{ to = record
{ _⟨$⟩_ = λ x → first-index x (complete x)
; pres = first-index-pres (complete _) (complete _)
}
; injective = first-index-injective (complete _) (complete _)
}
-- Finds out if an element has been counted yet.
lookup : ∀ {counted n} → counted ⊕ n → ∀ x → Dec (x ∈ counted)
lookup {counted} _ x = Any.any (_≟_ x) counted
-- When no element remains to be counted all elements have been
-- counted.
lookup! : ∀ {counted} → counted ⊕ zero → ∀ x → x ∈ counted
lookup! counted⊕0 x with _⊕_.kind counted⊕0 x
... | inj₁ x∈counted = x∈counted
... | inj₂ ()
private
-- A variant of lookup!.
lookup‼ : ∀ {m counted} →
counted ⊕ m → ∀ x → x ∉ counted → ∃ λ n → m ≡ suc n
lookup‼ {suc m} counted⊕n x x∉counted = (m , refl)
lookup‼ {zero} counted⊕n x x∉counted =
⊥-elim (x∉counted $ lookup! counted⊕n x)
-- Counts a previously uncounted element.
insert : ∀ {counted n} →
counted ⊕ suc n → ∀ x → x ∉ counted → x ∷ counted ⊕ n
insert {counted} {n} counted⊕1+n x x∉counted =
record { kind = kind′; injective = inj }
where
open _⊕_ counted⊕1+n
helper : ∀ x y i {j} →
kind x ≡ inj₂ i → kind y ≡ inj₂ j → i ≡ j → x ≈ y
helper _ _ _ eq₁ eq₂ refl = injective eq₁ eq₂
kind′ : ∀ y → y ∈ x ∷ counted ⊎ Fin n
kind′ y with y ≟ x | kind x | kind y | helper x y
kind′ y | yes y≈x | _ | _ | _ = inj₁ (here y≈x)
kind′ y | _ | inj₁ x∈counted | _ | _ = ⊥-elim (x∉counted x∈counted)
kind′ y | _ | _ | inj₁ y∈counted | _ = inj₁ (there y∈counted)
kind′ y | no y≉x | inj₂ i | inj₂ j | hlp =
inj₂ (thick i j (y≉x ∘ sym ∘ hlp _ refl refl))
inj : ∀ {y z i} → kind′ y ≡ inj₂ i → kind′ z ≡ inj₂ i → y ≈ z
inj {y} {z} eq₁ eq₂ with y ≟ x | z ≟ x | kind x | kind y | kind z
| helper x y | helper x z | helper y z
inj () _ | yes _ | _ | _ | _ | _ | _ | _ | _
inj _ () | _ | yes _ | _ | _ | _ | _ | _ | _
inj _ _ | no _ | no _ | inj₁ x∈counted | _ | _ | _ | _ | _ = ⊥-elim (x∉counted x∈counted)
inj () _ | no _ | no _ | inj₂ _ | inj₁ _ | _ | _ | _ | _
inj _ () | no _ | no _ | inj₂ _ | _ | inj₁ _ | _ | _ | _
inj eq₁ eq₂ | no _ | no _ | inj₂ _ | inj₂ _ | inj₂ _ | _ | _ | hlp =
hlp _ refl refl $
thick-injective _ _ _ $
PropEq.trans (drop-inj₂ eq₁) (PropEq.sym (drop-inj₂ eq₂))
-- Counts an element if it has not already been counted.
lookupOrInsert : ∀ {counted m} →
counted ⊕ m →
∀ x → x ∈ counted ⊎
∃ λ n → m ≡ suc n × x ∷ counted ⊕ n
lookupOrInsert counted⊕n x with lookup counted⊕n x
... | yes x∈counted = inj₁ x∈counted
... | no x∉counted with lookup‼ counted⊕n x x∉counted
... | (n , refl) = inj₂ (n , refl , insert counted⊕n x x∉counted)
| 40.257384
| 107
| 0.531705
|
3d4e5fd9e8570c4dc79a5b0c96b7a4142052c5b7
| 973
|
agda
|
Agda
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst-test.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 36
|
2015-01-29T14:37:15.000Z
|
2021-07-30T06:55:03.000Z
|
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst-test.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | null | null | null |
agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-bst-test.agda
|
haroldcarr/learn-haskell-coq-ml-etc
|
3dc7abca7ad868316bb08f31c77fbba0d3910225
|
[
"Unlicense"
] | 8
|
2015-04-13T21:40:15.000Z
|
2021-09-21T15:58:10.000Z
|
open import eq
open import bool
open import bool-relations using (transitive; total)
open import maybe
open import nat
open import nat-thms using (≤-trans; ≤-total)
open import product
module z05-01-bst-test where
open import bool-relations _≤_ hiding (transitive; total)
import z05-01-bst as BST
open BST nat _≤_ (λ {x} {y} {z} → ≤-trans {x} {y} {z})
(λ {x} {y} → ≤-total {x} {y})
empty : bst 0 0
empty = bst-leaf refl
_ : bst-search 0 empty ≡ nothing
_ = refl
_ : bst-insert 5 empty ≡ bst-node 5 (bst-leaf refl) (bst-leaf refl) refl refl
_ = refl
bst-5 : bst 0 5
bst-5 = bst-insert 5 empty
_ : maybe (Σ ℕ (λ z → (5 < z || 5 =ℕ z) && (z < 5 || z =ℕ 5) ≡ tt))
_ = bst-search 5 bst-5
_ : bst-insert 9 bst-5 ≡ bst-node 5 (bst-leaf refl)
(bst-node 9 (bst-leaf refl) (bst-leaf refl) refl refl) refl refl
_ = refl
_ : bst 0 9
_ = bst-insert 9 bst-5
_ : bst 0 5
_ = bst-dec-lb {0} {0} {5} (bst-leaf refl) refl
| 23.731707
| 91
| 0.601233
|
fb0b907750865875e404b8e12fe16d0f24cf3d70
| 509
|
agda
|
Agda
|
agda/SOList/Lower/Properties.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/SOList/Lower/Properties.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/SOList/Lower/Properties.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --sized-types #-}
module SOList.Lower.Properties {A : Set}(_≤_ : A → A → Set) where
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Size
open import List.Sorted _≤_
open import SOList.Lower _≤_
lemma-solist-sorted : {ι : Size}{b : Bound} → (xs : SOList {ι} b) → Sorted (forget xs)
lemma-solist-sorted onil = nils
lemma-solist-sorted (:< {x = x} _ onil) = singls x
lemma-solist-sorted (:< b≤x (:< (lexy x≤y) ys)) = conss x≤y (lemma-solist-sorted (:< (lexy x≤y) ys))
| 29.941176
| 101
| 0.656189
|
c7c5ec08fd2f0126c22189082b069731c493cc8d
| 166
|
agda
|
Agda
|
test/Fail/Issue4786a.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue4786a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue4786a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
record R (A : Set) : Set where
constructor c₂
field
f : A → A
g : A → A
g x = f (f x)
open R public
_ : (@0 A : Set) → R A → A → A
_ = λ A → g {A = A}
| 12.769231
| 30
| 0.451807
|
1e7c1be664eaf0b53cc3021bfdb52d6a0d9fca69
| 25,667
|
agda
|
Agda
|
core/lib/types/Truncation.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/types/Truncation.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/types/Truncation.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.FunctionSeq
open import lib.types.TLevel
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.NType2
module lib.types.Truncation where
module _ {i} where
postulate -- HIT
Trunc : (n : ℕ₋₂) (A : Type i) → Type i
[_] : {n : ℕ₋₂} {A : Type i} → A → Trunc n A
instance Trunc-level : {n : ℕ₋₂} {A : Type i} → has-level n (Trunc n A)
module TruncElim {n : ℕ₋₂} {A : Type i} {j} {P : Trunc n A → Type j}
{{p : (x : Trunc n A) → has-level n (P x)}} (d : (a : A) → P [ a ]) where
postulate -- HIT
f : Π (Trunc n A) P
[_]-β : ∀ a → f [ a ] ↦ d a
{-# REWRITE [_]-β #-}
open TruncElim public renaming (f to Trunc-elim)
module TruncRec {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {{p : has-level n B}}
(d : A → B) where
private
module M = TruncElim {{λ x → p}} d
f : Trunc n A → B
f = M.f
open TruncRec public renaming (f to Trunc-rec)
module TruncRecType {i j} {n : ℕ₋₂} {A : Type i} (d : A → n -Type j) where
open TruncRec {{n -Type-level j}} d public
flattening-Trunc : Σ (Trunc (S n) A) (fst ∘ f) ≃ Trunc (S n) (Σ A (fst ∘ d))
flattening-Trunc = equiv to from to-from from-to where
to-aux : (x : Trunc (S n) A) → (fst (f x) → Trunc (S n) (Σ A (fst ∘ d)))
to-aux = Trunc-elim (λ a b → [ (a , b) ])
to : Σ (Trunc (S n) A) (fst ∘ f) → Trunc (S n) (Σ A (fst ∘ d))
to (x , y) = to-aux x y
from-aux : Σ A (fst ∘ d) → Σ (Trunc (S n) A) (fst ∘ f)
from-aux (a , b) = ([ a ] , b)
from : Trunc (S n) (Σ A (fst ∘ d)) → Σ (Trunc (S n) A) (fst ∘ f)
from = Trunc-rec {{Σ-level ⟨⟩ (λ x → raise-level _ (snd (f x)))}}
from-aux where
to-from : (x : Trunc (S n) (Σ A (fst ∘ d))) → to (from x) == x
to-from = Trunc-elim (λ _ → idp)
from-to-aux : (a : Trunc (S n) A) (b : fst (f a)) → from (to-aux a b) == (a , b)
from-to-aux = Trunc-elim {{λ _ → Π-level (λ _ → =-preserves-level (Σ-level ⟨⟩ (λ x → raise-level _ (snd (f x)))))}}
(λ a b → idp)
from-to : (x : Σ (Trunc (S n) A) (fst ∘ f)) → from (to x) == x
from-to (a , b) = from-to-aux a b
⊙Trunc : ∀ {i} → ℕ₋₂ → Ptd i → Ptd i
⊙Trunc n ⊙[ A , a ] = ⊙[ Trunc n A , [ a ] ]
⊙Trunc-rec : ∀ {i j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} {{Y-level : has-level n (de⊙ Y)}}
→ X ⊙→ Y
→ ⊙Trunc n X ⊙→ Y
⊙Trunc-rec {{Y-level}} f = Trunc-rec {{Y-level}} (fst f) , snd f
⊙Trunc-rec-post-⊙∘ : ∀ {i j k} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
{{Y-level : has-level n (de⊙ Y)}} {{Z-level : has-level n (de⊙ Z)}}
(g : Y ⊙→ Z) (f : X ⊙→ Y)
→ ⊙Trunc-rec {n = n} {{Z-level}} (g ⊙∘ f) == g ⊙∘ ⊙Trunc-rec {{Y-level}} f
⊙Trunc-rec-post-⊙∘ {{Y-level}} {{Z-level}} g f =
⊙λ=' (Trunc-elim {{λ x → =-preserves-level Z-level}} (λ x → idp)) idp
module _ {i} {A : Type i} where
[_]₀ : A → Trunc 0 A
[_]₀ = [_] {n = 0}
[_]₁ : A → Trunc 1 A
[_]₁ = [_] {n = 1}
[_]₂ : A → Trunc 2 A
[_]₂ = [_] {n = 2}
module _ {i} {n : ℕ₋₂} {A : Type i} where
private
Trunc= : (a b : Trunc (S n) A) → n -Type i
Trunc= = Trunc-elim (λ a → Trunc-elim ((λ b → (Trunc n (a == b) , Trunc-level))))
{- t is for truncated -}
_=ₜ_ : (a b : Trunc (S n) A) → Type i
_=ₜ_ a b = fst (Trunc= a b)
=ₜ-level : (a b : Trunc (S n) A) → has-level n (a =ₜ b)
=ₜ-level a b = snd (Trunc= a b)
=ₜ-refl : (a : Trunc (S n) A) → a =ₜ a
=ₜ-refl = Trunc-elim {{λ x → raise-level _ (=ₜ-level x x)}}
(λ a → [ idp ])
=ₜ-equiv : (a b : Trunc (S n) A) → (a == b) ≃ (a =ₜ b)
=ₜ-equiv a b = to a b , to-is-equiv a b where
to : (a b : Trunc (S n) A) → (a == b → a =ₜ b)
to a b p = transport (λ c → a =ₜ c) p (=ₜ-refl a)
from-aux : (a b : A) → a == b → [ a ] == [ b ] :> Trunc (S n) A
from-aux _ _ = ap [_]
from : (a b : Trunc (S n) A) → a =ₜ b → a == b
from = Trunc-elim (λ a → Trunc-elim (λ b → Trunc-rec (from-aux a b)))
to-from-aux : (a b : A) → (p : a == b) → to _ _ (from-aux a b p) == [ p ]
to-from-aux a .a idp = idp
to-from : (a b : Trunc (S n) A) (x : a =ₜ b) → to a b (from a b x) == x
to-from = Trunc-elim {{λ x → Π-level (λ y → Π-level (λ _ → =-preserves-level (raise-level _ (=ₜ-level x y))))}}
(λ a → Trunc-elim {{λ x → Π-level (λ _ → =-preserves-level (raise-level _ (=ₜ-level [ a ] x)))}}
(λ b → Trunc-elim
(to-from-aux a b)))
from-to-aux : (a : Trunc (S n) A) → from a a (=ₜ-refl a) == idp
from-to-aux = Trunc-elim (λ _ → idp)
from-to : (a b : Trunc (S n) A) (p : a == b) → from a b (to a b p) == p
from-to a .a idp = from-to-aux a
adj : (ta tb : Trunc (S n) A) (p : ta == tb)
→ ap (to ta tb) (from-to ta tb p) == to-from ta tb (to ta tb p)
adj ta .ta idp =
Trunc-elim {P = λ ta → ap (to ta ta) (from-to ta ta idp) == to-from ta ta (to ta ta idp)}
{{λ x → =-preserves-level $ =-preserves-level $ raise-level _ $ =ₜ-level x x}}
(λ _ → idp)
ta
to-is-equiv : ∀ a b → is-equiv (to a b)
to-is-equiv a b =
record
{ g = from a b
; f-g = to-from a b
; g-f = from-to a b
; adj = adj a b
}
=ₜ-path : (a b : Trunc (S n) A) → (a == b) == (a =ₜ b)
=ₜ-path a b = ua (=ₜ-equiv a b)
{- Universal property -}
abstract
Trunc-rec-is-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)
{{p : has-level n B}} → is-equiv (Trunc-rec {{p}} :> ((A → B) → (Trunc n A → B)))
Trunc-rec-is-equiv n A B {{p}} = is-eq _ (λ f → f ∘ [_])
(λ f → λ= (Trunc-elim (λ a → idp))) (λ f → idp)
Trunc-preserves-level : ∀ {i} {A : Type i} {n : ℕ₋₂} (m : ℕ₋₂)
→ has-level n A → has-level n (Trunc m A)
Trunc-preserves-level {n = ⟨-2⟩} _ p = has-level-in
([ contr-center p ] , Trunc-elim (λ a → ap [_] (contr-path p a)))
Trunc-preserves-level ⟨-2⟩ _ = contr-has-level Trunc-level
Trunc-preserves-level {n = (S n)} (S m) c = has-level-in (λ t₁ t₂ →
Trunc-elim
{{λ s₁ → prop-has-level-S {A = has-level n (s₁ == t₂)} has-level-is-prop}}
(λ a₁ → Trunc-elim
{{λ s₂ → prop-has-level-S {A = has-level n ([ a₁ ] == s₂)} has-level-is-prop}}
(λ a₂ → equiv-preserves-level
((=ₜ-equiv [ a₁ ] [ a₂ ])⁻¹)
{{Trunc-preserves-level {n = n} m (has-level-apply c a₁ a₂)}})
t₂)
t₁)
{- an n-type is equivalent to its n-truncation -}
unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (A : Type i)
{{_ : has-level n A}} → Trunc n A ≃ A
unTrunc-equiv A = equiv f [_] (λ _ → idp) g-f where
f = Trunc-rec (idf _)
g-f = Trunc-elim (λ _ → idp)
⊙unTrunc-equiv : ∀ {i} {n : ℕ₋₂} (X : Ptd i)
{{_ : has-level n (de⊙ X)}} → ⊙Trunc n X ⊙≃ X
⊙unTrunc-equiv {n = n} X = ≃-to-⊙≃ (unTrunc-equiv (de⊙ X)) idp
-- Equivalence associated to the universal property
Trunc-extend-equiv : ∀ {i j} (n : ℕ₋₂) (A : Type i) (B : Type j)
{{p : has-level n B}} → (A → B) ≃ (Trunc n A → B)
Trunc-extend-equiv n A B = (Trunc-rec , Trunc-rec-is-equiv n A B)
Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → ((A → B) → (Trunc n A → Trunc n B))
Trunc-fmap f = Trunc-rec ([_] ∘ f)
⊙Trunc-fmap : ∀ {i j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} → ((X ⊙→ Y) → (⊙Trunc n X ⊙→ ⊙Trunc n Y))
⊙Trunc-fmap F = Trunc-fmap (fst F) , ap [_] (snd F)
–>-unTrunc-equiv-natural : ∀ {i} {j} {n : ℕ₋₂}
{A : Type i} {B : Type j} (f : A → B)
{{_ : has-level n A}} {{_ : has-level n B}}
→ –> (unTrunc-equiv {n = n} B) ∘ Trunc-fmap f ∼
f ∘ –> (unTrunc-equiv {n = n} A)
–>-unTrunc-equiv-natural f = Trunc-elim (λ a → idp)
⊙–>-⊙unTrunc-equiv-natural : ∀ {i} {j} {n : ℕ₋₂}
{X : Ptd i} {Y : Ptd j} (f : X ⊙→ Y)
{{_ : has-level n (de⊙ X)}} {{_ : has-level n (de⊙ Y)}}
→ ⊙–> (⊙unTrunc-equiv {n = n} Y) ⊙∘ ⊙Trunc-fmap f ==
f ⊙∘ ⊙–> (⊙unTrunc-equiv {n = n} X)
⊙–>-⊙unTrunc-equiv-natural (f' , idp) =
⊙λ=' (–>-unTrunc-equiv-natural f') idp
⊙–>-⊙unTrunc-equiv-natural-=⊙∘ : ∀ {i} {n : ℕ₋₂}
{X Y : Ptd i} (f : X ⊙→ Y)
{{_ : has-level n (de⊙ X)}} {{_ : has-level n (de⊙ Y)}}
→ ⊙–> (⊙unTrunc-equiv {n = n} Y) ◃⊙∘
⊙Trunc-fmap f ◃⊙idf
=⊙∘
f ◃⊙∘
⊙–> (⊙unTrunc-equiv {n = n} X) ◃⊙idf
⊙–>-⊙unTrunc-equiv-natural-=⊙∘ f =
=⊙∘-in (⊙–>-⊙unTrunc-equiv-natural f)
Trunc-fmap2 : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}
→ ((A → B → C) → (Trunc n A → Trunc n B → Trunc n C))
Trunc-fmap2 f = Trunc-rec (λ a → Trunc-fmap (f a))
⊙Trunc-rec-⊙Trunc-fmap : ∀ {i j k} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
{{Z-level : has-level n (de⊙ Z)}}
(g : Y ⊙→ Z) (f : X ⊙→ Y)
→ ⊙Trunc-rec {n = n} {{Z-level}} g ⊙∘ ⊙Trunc-fmap f ==
⊙Trunc-rec {n = n} {{Z-level}} (g ⊙∘ f)
⊙Trunc-rec-⊙Trunc-fmap {{Z-level}} g f =
⊙λ=' (Trunc-elim {{λ tx → =-preserves-level Z-level}} (λ x → idp)) $
ap (_∙ snd g) (∘-ap (Trunc-elim (fst g)) [_] (snd f))
-- XXX What is the naming convention?
Trunc-fpmap : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} {f g : A → B}
→ f ∼ g → Trunc-fmap {n = n} f ∼ Trunc-fmap g
Trunc-fpmap h = Trunc-elim (ap [_] ∘ h)
Trunc-fmap-idf : ∀ {i} {n : ℕ₋₂} {A : Type i}
→ ∀ x → Trunc-fmap {n = n} (idf A) x == x
Trunc-fmap-idf = Trunc-elim (λ _ → idp)
⊙Trunc-fmap-⊙idf : ∀ {i} {n : ℕ₋₂} {X : Ptd i}
→ ⊙Trunc-fmap (⊙idf X) ⊙∼ ⊙idf (⊙Trunc n X)
⊙Trunc-fmap-⊙idf = Trunc-fmap-idf , idp
transport-Trunc : ∀ {i} {n : ℕ₋₂} {A B : Type i}
(p : A == B)
→ transport (Trunc n) p == Trunc-fmap (coe p)
transport-Trunc p@idp = ! (λ= Trunc-fmap-idf)
⊙transport-⊙Trunc : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i}
(p : X == Y)
→ ⊙transport (⊙Trunc n) p == ⊙Trunc-fmap (⊙coe p)
⊙transport-⊙Trunc p@idp = ! (⊙λ= ⊙Trunc-fmap-⊙idf)
Trunc-fmap-cst : ∀ {i} {j} {n : ℕ₋₂} {A : Type i} {B : Type j}
→ ∀ (b : B) → Trunc-fmap {n = n} {A = A} (cst b) ∼ cst [ b ]
Trunc-fmap-cst b = Trunc-elim (λ a → idp)
⊙Trunc-fmap-cst : ∀ {i} {j} {n : ℕ₋₂} {X : Ptd i} {Y : Ptd j}
→ ⊙Trunc-fmap {n = n} (⊙cst {X = X} {Y = Y}) ⊙∼ ⊙cst
⊙Trunc-fmap-cst {Y = Y} = Trunc-fmap-cst (pt Y) , idp
Trunc-fmap-∘ : ∀ {i j k} {n : ℕ₋₂} {A : Type i} {B : Type j} {C : Type k}
(g : B → C) (f : A → B)
→ ∀ x → Trunc-fmap {n = n} g (Trunc-fmap f x) == Trunc-fmap (g ∘ f) x
Trunc-fmap-∘ g f = Trunc-elim (λ _ → idp)
⊙Trunc-fmap-⊙∘ : ∀ {i j k} {n : ℕ₋₂} {A : Ptd i} {B : Ptd j} {C : Ptd k}
(g : B ⊙→ C) (f : A ⊙→ B)
→ ⊙Trunc-fmap {n = n} g ⊙∘ ⊙Trunc-fmap f ⊙∼ ⊙Trunc-fmap (g ⊙∘ f)
⊙Trunc-fmap-⊙∘ {n = n} g f =
Trunc-fmap-∘ (fst g) (fst f) , pres-pt-path
where
pres-pt-path : snd (⊙Trunc-fmap {n = n} g ⊙∘ ⊙Trunc-fmap f) == snd (⊙Trunc-fmap (g ⊙∘ f))
pres-pt-path =
ap (Trunc-fmap (fst g)) (ap [_] (snd f)) ∙ ap [_] (snd g)
=⟨ ap (_∙ ap [_] (snd g))
(∘-ap (Trunc-fmap (fst g)) [_] (snd f) ∙
ap-∘ [_] (fst g) (snd f)) ⟩
ap [_] (ap (fst g) (snd f)) ∙ ap [_] (snd g)
=⟨ ∙-ap [_] (ap (fst g) (snd f)) (snd g) ⟩
ap [_] (ap (fst g) (snd f) ∙ snd g) =∎
⊙Trunc-fmap-seq : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i}
→ X ⊙–→ Y
→ ⊙Trunc n X ⊙–→ ⊙Trunc n Y
⊙Trunc-fmap-seq ⊙idf-seq = ⊙idf-seq
⊙Trunc-fmap-seq (f ◃⊙∘ fs) = ⊙Trunc-fmap f ◃⊙∘ ⊙Trunc-fmap-seq fs
⊙Trunc-fmap-seq-⊙∘ : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i} (fs : X ⊙–→ Y)
→ ⊙Trunc-fmap {n = n} (⊙compose fs) ◃⊙idf =⊙∘ ⊙Trunc-fmap-seq fs
⊙Trunc-fmap-seq-⊙∘ ⊙idf-seq = =⊙∘-in (⊙λ= (⊙Trunc-fmap-⊙idf))
⊙Trunc-fmap-seq-⊙∘ (f ◃⊙∘ fs) = =⊙∘-in $
⊙Trunc-fmap (f ⊙∘ ⊙compose fs)
=⟨ ! $ ⊙λ= $ ⊙Trunc-fmap-⊙∘ f (⊙compose fs) ⟩
⊙Trunc-fmap f ⊙∘ ⊙Trunc-fmap (⊙compose fs)
=⟨ ap (⊙Trunc-fmap f ⊙∘_) (=⊙∘-out (⊙Trunc-fmap-seq-⊙∘ fs)) ⟩
⊙Trunc-fmap f ⊙∘ ⊙compose (⊙Trunc-fmap-seq fs) =∎
⊙Trunc-fmap-seq-=⊙∘ : ∀ {i} {n : ℕ₋₂} {X Y : Ptd i} {fs gs : X ⊙–→ Y}
→ fs =⊙∘ gs
→ ⊙Trunc-fmap-seq {n = n} fs =⊙∘ ⊙Trunc-fmap-seq {n = n} gs
⊙Trunc-fmap-seq-=⊙∘ {fs = fs} {gs = gs} p =
⊙Trunc-fmap-seq fs
=⊙∘⟨ !⊙∘ (⊙Trunc-fmap-seq-⊙∘ fs) ⟩
⊙Trunc-fmap (⊙compose fs) ◃⊙idf
=⊙∘₁⟨ ap ⊙Trunc-fmap (=⊙∘-out p) ⟩
⊙Trunc-fmap (⊙compose gs) ◃⊙idf
=⊙∘⟨ ⊙Trunc-fmap-seq-⊙∘ gs ⟩
⊙Trunc-fmap-seq gs ∎⊙∘
Trunc-csmap : ∀ {i₀ i₁ j₀ j₁} {n : ℕ₋₂}
{A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
{f : A₀ → B₀} {g : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁}
→ CommSquare f g hA hB
→ CommSquare (Trunc-fmap {n = n} f) (Trunc-fmap g) (Trunc-fmap hA) (Trunc-fmap hB)
Trunc-csmap (comm-sqr cs) = comm-sqr $ Trunc-elim (ap [_] ∘ cs)
{- Pushing concatenatation through _=ₜ_ -}
module _ {i} {n : ℕ₋₂} {A : Type i} where
{- concatenation in _=ₜ_ -}
_∙ₜ_ : {ta tb tc : Trunc (S n) A}
→ ta =ₜ tb → tb =ₜ tc → ta =ₜ tc
_∙ₜ_ {ta = ta} {tb = tb} {tc = tc} =
Trunc-elim {P = λ ta → C ta tb tc}
{{λ ta → level ta tb tc}}
(λ a → Trunc-elim {P = λ tb → C [ a ] tb tc}
{{λ tb → level [ a ] tb tc}}
(λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc}
{{λ tc → level [ a ] [ b ] tc}}
(λ c → Trunc-fmap2 _∙_)
tc)
tb)
ta
where
C : (ta tb tc : Trunc (S n) A) → Type i
C ta tb tc = ta =ₜ tb → tb =ₜ tc → ta =ₜ tc
level : (ta tb tc : Trunc (S n) A) → has-level (S n) (C ta tb tc)
level ta tb tc =
raise-level _ $
Π-level $ λ _ →
Π-level $ λ _ →
=ₜ-level ta tc
{- inversion in _=ₜ_ -}
!ₜ : {ta tb : Trunc (S n) A}
→ ta =ₜ tb
→ tb =ₜ ta
!ₜ {ta = ta} {tb = tb} =
Trunc-elim {P = λ ta → C ta tb}
{{λ ta → level ta tb}}
(λ a → Trunc-elim {P = λ tb → C [ a ] tb}
{{λ tb → level [ a ] tb}}
(λ b → Trunc-fmap !)
tb)
ta
where
C : (ta tb : Trunc (S n) A) → Type i
C ta tb = ta =ₜ tb → tb =ₜ ta
level : (ta tb : Trunc (S n) A) → has-level (S n) (C ta tb)
level ta tb = raise-level _ $ Π-level $ λ _ → =ₜ-level tb ta
∙ₜ-assoc : {ta tb tc td : Trunc (S n) A}
(tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td)
→ _∙ₜ_ {ta} (_∙ₜ_ {ta} tp tq) tr
== _∙ₜ_ {ta} tp (_∙ₜ_ {tb} tq tr)
∙ₜ-assoc {ta = ta} {tb = tb} {tc = tc} {td = td} =
Trunc-elim {P = λ ta → C ta tb tc td}
{{λ ta → C-level ta tb tc td}}
(λ a → Trunc-elim {P = λ tb → C [ a ] tb tc td}
{{λ tb → C-level [ a ] tb tc td}}
(λ b → Trunc-elim {P = λ tc → C [ a ] [ b ] tc td}
{{λ tc → C-level [ a ] [ b ] tc td}}
(λ c → Trunc-elim {P = λ td → C [ a ] [ b ] [ c ] td}
{{λ td → C-level [ a ] [ b ] [ c ] td}}
(λ d tp tq tr → Trunc-elim
{P = λ tp → D [ a ] [ b ] [ c ] [ d ] tp tq tr}
{{λ tp → D-level [ a ] [ b ] [ c ] [ d ] tp tq tr}}
(λ p → Trunc-elim
{P = λ tq → D [ a ] [ b ] [ c ] [ d ] [ p ] tq tr}
{{λ tq → D-level [ a ] [ b ] [ c ] [ d ] [ p ] tq tr}}
(λ q → Trunc-elim
{P = λ tr → D [ a ] [ b ] [ c ] [ d ] [ p ] [ q ] tr}
{{λ tr → D-level [ a ] [ b ] [ c ] [ d ] [ p ] [ q ] tr}}
(λ r → ap [_] (∙-assoc p q r))
tr)
tq)
tp)
td)
tc)
tb)
ta
where
D : (ta tb tc td : Trunc (S n) A)
→ ta =ₜ tb → tb =ₜ tc → tc =ₜ td
→ Type i
D ta tb tc td tp tq tr =
_∙ₜ_ {ta} (_∙ₜ_ {ta} tp tq) tr
== _∙ₜ_ {ta} tp (_∙ₜ_ {tb} tq tr)
C : (ta tb tc td : Trunc (S n) A) → Type i
C ta tb tc td = ∀ tp tq tr → D ta tb tc td tp tq tr
D-level : (ta tb tc td : Trunc (S n) A)
(tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td)
→ has-level n (D ta tb tc td tp tq tr)
D-level ta tb tc td tp tq tr = =-preserves-level (=ₜ-level ta td)
C-level : (ta tb tc td : Trunc (S n) A) → has-level (S n) (C ta tb tc td)
C-level ta tb tc td =
raise-level _ $
Π-level $ λ tp →
Π-level $ λ tq →
Π-level $ λ tr →
D-level ta tb tc td tp tq tr
abstract
∙ₜ-assoc-pentagon : {ta tb tc td te : Trunc (S n) A}
(tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td) (ts : td =ₜ te)
→ ∙ₜ-assoc {ta} (_∙ₜ_ {ta} tp tq) tr ts ◃∙
∙ₜ-assoc {ta} tp tq (_∙ₜ_ {tc} tr ts) ◃∎
=ₛ
ap (λ u → _∙ₜ_ {ta} u ts) (∙ₜ-assoc {ta} tp tq tr) ◃∙
∙ₜ-assoc {ta} tp (_∙ₜ_ {tb} tq tr) ts ◃∙
ap (_∙ₜ_ {ta} tp) (∙ₜ-assoc {tb} tq tr ts) ◃∎
∙ₜ-assoc-pentagon {ta} {tb} {tc} {td} {te} = core ta tb tc td te
where
P : (ta tb tc td te : Trunc (S n) A)
(tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td) (ts : td =ₜ te)
→ Type i
P ta tb tc td te tp tq tr ts =
∙ₜ-assoc {ta} (_∙ₜ_ {ta} tp tq) tr ts ◃∙
∙ₜ-assoc {ta} tp tq (_∙ₜ_ {tc} tr ts) ◃∎
=ₛ
ap (λ u → _∙ₜ_ {ta} u ts) (∙ₜ-assoc {ta} tp tq tr) ◃∙
∙ₜ-assoc {ta} tp (_∙ₜ_ {tb} tq tr) ts ◃∙
ap (_∙ₜ_ {ta} tp) (∙ₜ-assoc {tb} tq tr ts) ◃∎
P-level : ∀ ta tb tc td te →
(tp : ta =ₜ tb) (tq : tb =ₜ tc) (tr : tc =ₜ td) (ts : td =ₜ te)
→ has-level n (P ta tb tc td te tp tq tr ts)
P-level ta tb tc td te tp tq tr ts =
=ₛ-level $ raise-level _ $ raise-level _ $ =ₜ-level ta te
Q : (ta tb tc td te : Trunc (S n) A) → Type i
Q ta tb tc td te = ∀ tp tq tr ts → P ta tb tc td te tp tq tr ts
Q-level : ∀ ta tb tc td te → has-level (S n) (Q ta tb tc td te)
Q-level ta tb tc td te =
raise-level n $
Π-level $ λ tp →
Π-level $ λ tq →
Π-level $ λ tr →
Π-level $ λ ts →
P-level ta tb tc td te tp tq tr ts
core' : ∀ {a} {b} {c} {d} {e} p q r s → P [ a ] [ b ] [ c ] [ d ] [ e ] [ p ] [ q ] [ r ] [ s ]
core' idp idp r s = =ₛ-in idp
core : ∀ ta tb tc td te → Q ta tb tc td te
core ta tb tc td te =
Trunc-elim {P = λ ta → Q ta tb tc td te} {{λ ta → Q-level ta tb tc td te}} (λ a →
Trunc-elim {P = λ tb → Q [ a ] tb tc td te} {{λ tb → Q-level [ a ] tb tc td te}} (λ b →
Trunc-elim {P = λ tc → Q [ a ] [ b ] tc td te} {{λ tc → Q-level [ a ] [ b ] tc td te}} (λ c →
Trunc-elim {P = λ td → Q [ a ] [ b ] [ c ] td te} {{λ td → Q-level [ a ] [ b ] [ c ] td te}} (λ d →
Trunc-elim {P = λ te → Q [ a ] [ b ] [ c ] [ d ] te} {{λ te → Q-level [ a ] [ b ] [ c ] [ d ] te}} (λ e →
let R = P [ a ] [ b ] [ c ] [ d ] [ e ]
R-level = P-level [ a ] [ b ] [ c ] [ d ] [ e ]
in λ tp tq tr ts →
Trunc-elim {P = λ tp → R tp tq tr ts} {{λ tp → R-level tp tq tr ts }} (λ p →
Trunc-elim {P = λ tq → R [ p ] tq tr ts} {{λ tq → R-level [ p ] tq tr ts}} (λ q →
Trunc-elim {P = λ tr → R [ p ] [ q ] tr ts} {{λ tr → R-level [ p ] [ q ] tr ts}} (λ r →
Trunc-elim {P = λ ts → R [ p ] [ q ] [ r ] ts} {{λ ts → R-level [ p ] [ q ] [ r ] ts}} (λ s →
core' p q r s
) ts
) tr
) tq
) tp
) te
) td
) tc
) tb
) ta
–>-=ₜ-equiv-pres-∙ : {ta tb tc : Trunc (S n) A}
(p : ta == tb) (q : tb == tc)
→ –> (=ₜ-equiv ta tc) (p ∙ q)
==
_∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta tb) p) (–> (=ₜ-equiv tb tc) q)
–>-=ₜ-equiv-pres-∙ {ta = ta} idp idp =
Trunc-elim
{P = λ ta → –> (=ₜ-equiv ta ta) idp
== _∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta ta) idp)
(–> (=ₜ-equiv ta ta) idp)}
{{λ ta → raise-level _ $ =-preserves-level $ =ₜ-level ta ta}}
(λ a → idp)
ta
!ₜ-=ₜ-refl : ∀ (ta : Trunc (S n) A)
→ !ₜ {ta = ta} (=ₜ-refl ta) == =ₜ-refl ta
!ₜ-=ₜ-refl =
Trunc-elim
{P = λ ta → !ₜ {ta = ta} (=ₜ-refl ta) == =ₜ-refl ta}
{{λ ta → raise-level _ $ =-preserves-level $ =ₜ-level ta ta}}
(λ a → idp)
–>-=ₜ-equiv-pres-! : {ta tb : Trunc (S n) A}
(p : ta == tb)
→ –> (=ₜ-equiv tb ta) (! p) == !ₜ {ta = ta} (–> (=ₜ-equiv ta tb) p)
–>-=ₜ-equiv-pres-! {ta = ta} p@idp = ! (!ₜ-=ₜ-refl ta)
abstract
–>-=ₜ-equiv-pres-∙-coh : {ta tb tc td : Trunc (S n) A}
(p : ta == tb) (q : tb == tc) (r : tc == td)
→ –>-=ₜ-equiv-pres-∙ (p ∙ q) r ◃∙
ap (λ u → _∙ₜ_ {ta = ta} u (–> (=ₜ-equiv tc td) r)) (–>-=ₜ-equiv-pres-∙ p q) ◃∙
∙ₜ-assoc {ta = ta} (–> (=ₜ-equiv ta tb) p) (–> (=ₜ-equiv tb tc) q) (–> (=ₜ-equiv tc td) r) ◃∎
=ₛ
ap (–> (=ₜ-equiv ta td)) (∙-assoc p q r) ◃∙
–>-=ₜ-equiv-pres-∙ p (q ∙ r) ◃∙
ap (_∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta tb) p)) (–>-=ₜ-equiv-pres-∙ q r) ◃∎
–>-=ₜ-equiv-pres-∙-coh {ta = ta} idp idp idp =
Trunc-elim
{P = λ ta → P ta ta ta ta idp idp idp}
{{λ ta → =ₛ-level $ raise-level (S (S n)) $ raise-level (S n) $ raise-level n $ =ₜ-level ta ta}}
(λ a → =ₛ-in idp)
ta
where
P : (ta tb tc td : Trunc (S n) A) (p : ta == tb) (q : tb == tc) (r : tc == td) → Type i
P ta tb tc td p q r =
–>-=ₜ-equiv-pres-∙ (p ∙ q) r ◃∙
ap (λ u → _∙ₜ_ {ta = ta} u (–> (=ₜ-equiv tc td) r)) (–>-=ₜ-equiv-pres-∙ p q) ◃∙
∙ₜ-assoc {ta = ta} (–> (=ₜ-equiv ta tb) p) (–> (=ₜ-equiv tb tc) q) (–> (=ₜ-equiv tc td) r) ◃∎
=ₛ
ap (–> (=ₜ-equiv ta td)) (∙-assoc p q r) ◃∙
–>-=ₜ-equiv-pres-∙ p (q ∙ r) ◃∙
ap (_∙ₜ_ {ta = ta} (–> (=ₜ-equiv ta tb) p)) (–>-=ₜ-equiv-pres-∙ q r) ◃∎
{- naturality of =ₜ-equiv -}
module _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (f : A → B) where
=ₜ-fmap : ∀ (a₀ a₁ : Trunc (S n) A)
→ a₀ =ₜ a₁ → Trunc-fmap f a₀ =ₜ Trunc-fmap f a₁
=ₜ-fmap = Trunc-elim
{P = λ a₀ → ∀ a₁ → a₀ =ₜ a₁ → Trunc-fmap f a₀ =ₜ Trunc-fmap f a₁}
{{λ a₀ → Π-level λ a₁ → Π-level λ _ → raise-level _ $ =ₜ-level (Trunc-fmap f a₀) (Trunc-fmap f a₁)}}
(λ a₀ → Trunc-elim
{P = λ a₁ → [ a₀ ] =ₜ a₁ → [ f a₀ ] =ₜ Trunc-fmap f a₁}
{{λ a₁ → Π-level λ _ → raise-level _ $ =ₜ-level [ f a₀ ] (Trunc-fmap f a₁)}}
(λ a₁ → Trunc-fmap (ap f)))
module _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} (f : A → B) where
=ₜ-equiv-nat : ∀ (a₀ a₁ : Trunc (S n) A) (p : a₀ == a₁)
→ –> (=ₜ-equiv (Trunc-fmap f a₀) (Trunc-fmap f a₁)) (ap (Trunc-fmap f) p)
== =ₜ-fmap f a₀ a₁ (–> (=ₜ-equiv a₀ a₁) p)
=ₜ-equiv-nat a₀ .a₀ idp =
Trunc-elim
{P = λ a
→ –> (=ₜ-equiv (Trunc-fmap f a) (Trunc-fmap f a)) idp
== =ₜ-fmap f a a (–> (=ₜ-equiv a a) idp)}
{{λ a → raise-level _ $ =-preserves-level $ =ₜ-level (Trunc-fmap f a) (Trunc-fmap f a)}}
(λ _ → idp)
a₀
{- Truncation preserves equivalences - more convenient than univalence+ap
- when we need to know the forward or backward function explicitly -}
module _ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} where
Trunc-isemap : {f : A → B} → is-equiv f → is-equiv (Trunc-fmap {n = n} f)
Trunc-isemap {f-orig} ie = is-eq f g f-g g-f where
f = Trunc-fmap f-orig
g = Trunc-fmap (is-equiv.g ie)
f-g : ∀ tb → f (g tb) == tb
f-g = Trunc-elim (ap [_] ∘ is-equiv.f-g ie)
g-f : ∀ ta → g (f ta) == ta
g-f = Trunc-elim (ap [_] ∘ is-equiv.g-f ie)
Trunc-emap : A ≃ B → Trunc n A ≃ Trunc n B
Trunc-emap (f , f-ie) = Trunc-fmap f , Trunc-isemap f-ie
Trunc-csemap : ∀ {i₀ i₁ j₀ j₁} {n : ℕ₋₂}
{A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
{f : A₀ → B₀} {g : A₁ → B₁} {hA : A₀ → A₁} {hB : B₀ → B₁}
→ CommSquareEquiv f g hA hB
→ CommSquareEquiv (Trunc-fmap {n = n} f) (Trunc-fmap g) (Trunc-fmap hA) (Trunc-fmap hB)
Trunc-csemap (cs , hA-ise , hB-ise) = Trunc-csmap cs , Trunc-isemap hA-ise , Trunc-isemap hB-ise
transport-Trunc' : ∀ {i j} {A : Type i} {n : ℕ₋₂} (P : A → Type j)
{x y : A} (p : x == y) (b : P x)
→ transport (Trunc n ∘ P) p [ b ] == [ transport P p b ]
transport-Trunc' _ idp _ = idp
Trunc-fuse : ∀ {i} (A : Type i) (m n : ℕ₋₂)
→ Trunc m (Trunc n A) ≃ Trunc (minT m n) A
Trunc-fuse A m n = equiv
(Trunc-rec {{raise-level-≤T (minT≤l m n) Trunc-level}}
(Trunc-rec {{raise-level-≤T (minT≤r m n) Trunc-level}}
[_]))
(Trunc-rec ([_] ∘ [_]))
(Trunc-elim (λ _ → idp))
(Trunc-elim (Trunc-elim
{{λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level)}}
(λ _ → idp)))
where
instance
l : has-level (minT m n) (Trunc m (Trunc n A))
l with (minT-out m n)
l | inl p = transport (λ k → has-level k (Trunc m (Trunc n A)))
(! p) Trunc-level
l | inr q = Trunc-preserves-level _
(transport (λ k → has-level k (Trunc n A))
(! q) Trunc-level)
Trunc-fuse-≤ : ∀ {i} (A : Type i) {m n : ℕ₋₂} (m≤n : m ≤T n)
→ Trunc m (Trunc n A) ≃ Trunc m A
Trunc-fuse-≤ A m≤n = equiv
(Trunc-rec (Trunc-rec {{raise-level-≤T m≤n Trunc-level}}
[_]))
(Trunc-rec ([_] ∘ [_]))
(Trunc-elim (λ _ → idp))
(Trunc-elim (Trunc-elim
{{λ _ → =-preserves-level (Trunc-preserves-level _ Trunc-level)}}
(λ _ → idp)))
{- Truncating a binary product is equivalent to truncating its components -}
Trunc-×-econv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)
→ Trunc n (A × B) ≃ Trunc n A × Trunc n B
Trunc-×-econv n A B = equiv f g f-g g-f
where
f : Trunc n (A × B) → Trunc n A × Trunc n B
f = Trunc-rec (λ {(a , b) → [ a ] , [ b ]})
g : Trunc n A × Trunc n B → Trunc n (A × B)
g (ta , tb) = Trunc-rec (λ a → Trunc-rec (λ b → [ a , b ]) tb) ta
f-g : ∀ p → f (g p) == p
f-g (ta , tb) = Trunc-elim
{P = λ ta → f (g (ta , tb)) == (ta , tb)}
(λ a → Trunc-elim
{P = λ tb → f (g ([ a ] , tb)) == ([ a ] , tb)}
(λ b → idp)
tb)
ta
g-f : ∀ tab → g (f tab) == tab
g-f = Trunc-elim
{P = λ tab → g (f tab) == tab}
(λ ab → idp)
Trunc-×-conv : ∀ {i} {j} (n : ℕ₋₂) (A : Type i) (B : Type j)
→ Trunc n (A × B) == Trunc n A × Trunc n B
Trunc-×-conv n A B = ua (Trunc-×-econv n A B)
| 38.65512
| 121
| 0.460669
|
ad292d398135db1f26eb02da70e96e8f63241544
| 134
|
agda
|
Agda
|
formalization/all.agda
|
ishantheperson/Obsidian
|
b5fc75b137cf86251c03709c58f940286d730e86
|
[
"BSD-3-Clause"
] | 79
|
2017-08-19T16:24:10.000Z
|
2022-03-27T10:34:28.000Z
|
formalization/all.agda
|
ishantheperson/Obsidian
|
b5fc75b137cf86251c03709c58f940286d730e86
|
[
"BSD-3-Clause"
] | 259
|
2017-08-18T19:50:41.000Z
|
2022-03-29T18:20:05.000Z
|
formalization/all.agda
|
ishantheperson/Obsidian
|
b5fc75b137cf86251c03709c58f940286d730e86
|
[
"BSD-3-Clause"
] | 11
|
2018-05-24T08:20:52.000Z
|
2021-06-09T18:40:19.000Z
|
-- This file serves to aggregate all the top-level dependencies in the Silica project.
open import preservation
open import progress
| 26.8
| 86
| 0.813433
|
04faed55407fc6c62aad51b1ad94ff81409828bd
| 851
|
agda
|
Agda
|
test/Succeed/Issue383.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue383.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue383.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2011-05-09
-- {-# OPTIONS -v tc.meta:15 -v tc.inj:40 #-}
module Issue383 where
data D (A : Set) : A → Set where
data Unit : Set where
unit : Unit
D′ : (A : Set) → A → Unit → Set
D′ A x unit = D A x
postulate
Q : (A : Set) → A → Set
q : (u : Unit) (A : Set) (x : A) → D′ A x u → Q A x
A : Set
x : A
d : D A x
P : (A : Set) → A → Set
p : P (Q _ _) (q _ _ _ d)
-- SOLVED, WORKS NOW.
-- OLD BEHAVIOR:
-- Agda does not infer the values of the underscores on the last line.
-- Shouldn't constructor-headedness come to the rescue here? Agda does
-- identify D′ as being constructor-headed, and does invert D′ /six
-- times/, but still fails to infer that the third underscore should
-- be unit.
{-
blocked _41 := d
by [(D A x) =< (D′ _39 _40 _38) : Set]
blocked _42 := q _38 _36 _40 _41
by [_40 == _37 : _36]
-}
| 22.394737
| 70
| 0.582844
|
2927964ba90083eccb66568e5d5b0d2ac62cf402
| 29,728
|
agda
|
Agda
|
Agda/06-universes.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/06-universes.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/06-universes.agda
|
tmoux/HoTT-Intro
|
22023fd35023cb6804424ce12cd10d252b80fd29
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split --safe #-}
module 06-universes where
import 05-identity-types
open 05-identity-types public
--------------------------------------------------------------------------------
-- Section 6.3 Observational equality on the natural numbers
-- Definition 6.3.1
Eq-ℕ : ℕ → ℕ → UU lzero
Eq-ℕ zero-ℕ zero-ℕ = 𝟙
Eq-ℕ zero-ℕ (succ-ℕ n) = 𝟘
Eq-ℕ (succ-ℕ m) zero-ℕ = 𝟘
Eq-ℕ (succ-ℕ m) (succ-ℕ n) = Eq-ℕ m n
-- Lemma 6.3.2
refl-Eq-ℕ : (n : ℕ) → Eq-ℕ n n
refl-Eq-ℕ zero-ℕ = star
refl-Eq-ℕ (succ-ℕ n) = refl-Eq-ℕ n
-- Proposition 6.3.3
Eq-ℕ-eq : {x y : ℕ} → Id x y → Eq-ℕ x y
Eq-ℕ-eq {x} {.x} refl = refl-Eq-ℕ x
eq-Eq-ℕ : (x y : ℕ) → Eq-ℕ x y → Id x y
eq-Eq-ℕ zero-ℕ zero-ℕ e = refl
eq-Eq-ℕ (succ-ℕ x) (succ-ℕ y) e = ap succ-ℕ (eq-Eq-ℕ x y e)
--------------------------------------------------------------------------------
-- Section 6.4 Peano's seventh and eighth axioms
-- Theorem 6.4.1
is-injective-succ-ℕ : (x y : ℕ) → Id (succ-ℕ x) (succ-ℕ y) → Id x y
is-injective-succ-ℕ x y e = eq-Eq-ℕ x y (Eq-ℕ-eq e)
Peano-7 :
(x y : ℕ) →
((Id x y) → (Id (succ-ℕ x) (succ-ℕ y))) ×
((Id (succ-ℕ x) (succ-ℕ y)) → (Id x y))
Peano-7 x y = pair (ap succ-ℕ) (is-injective-succ-ℕ x y)
-- Theorem 6.4.2
Peano-8 :
(x : ℕ) → ¬ (Id zero-ℕ (succ-ℕ x))
Peano-8 x p = Eq-ℕ-eq p
--------------------------------------------------------------------------------
-- Exercises
-- Exercise 6.1
-- Exercise 6.1 (a)
is-injective-add-ℕ :
(k m n : ℕ) → Id (add-ℕ m k) (add-ℕ n k) → Id m n
is-injective-add-ℕ zero-ℕ m n = id
is-injective-add-ℕ (succ-ℕ k) m n p =
is-injective-add-ℕ k m n (is-injective-succ-ℕ (add-ℕ m k) (add-ℕ n k) p)
-- Exercise 6.1 (b)
is-injective-mul-ℕ :
(k m n : ℕ) → Id (mul-ℕ m (succ-ℕ k)) (mul-ℕ n (succ-ℕ k)) → Id m n
is-injective-mul-ℕ k zero-ℕ zero-ℕ p = refl
is-injective-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
ap succ-ℕ
( is-injective-mul-ℕ k m n
( is-injective-add-ℕ
( succ-ℕ k)
( mul-ℕ m (succ-ℕ k))
( mul-ℕ n (succ-ℕ k))
( ( inv (left-successor-law-mul-ℕ m (succ-ℕ k))) ∙
( ( p) ∙
( left-successor-law-mul-ℕ n (succ-ℕ k))))))
-- Exercise 6.1 (c)
neq-add-ℕ :
(m n : ℕ) → ¬ (Id m (add-ℕ m (succ-ℕ n)))
neq-add-ℕ (succ-ℕ m) n p =
neq-add-ℕ m n
( ( is-injective-succ-ℕ m (add-ℕ (succ-ℕ m) n) p) ∙
( left-successor-law-add-ℕ m n))
-- Exercise 6.1 (d)
neq-mul-ℕ :
(m n : ℕ) → ¬ (Id (succ-ℕ m) (mul-ℕ (succ-ℕ m) (succ-ℕ (succ-ℕ n))))
neq-mul-ℕ m n p =
neq-add-ℕ
( succ-ℕ m)
( add-ℕ (mul-ℕ m (succ-ℕ n)) n)
( ( p) ∙
( ( right-successor-law-mul-ℕ (succ-ℕ m) (succ-ℕ n)) ∙
( ap (add-ℕ (succ-ℕ m)) (left-successor-law-mul-ℕ m (succ-ℕ n)))))
-- Exercise 6.2
-- Exercise 6.2 (a)
Eq-𝟚 : bool → bool → UU lzero
Eq-𝟚 true true = unit
Eq-𝟚 true false = empty
Eq-𝟚 false true = empty
Eq-𝟚 false false = unit
-- Exercise 6.2 (b)
reflexive-Eq-𝟚 : (x : bool) → Eq-𝟚 x x
reflexive-Eq-𝟚 true = star
reflexive-Eq-𝟚 false = star
Eq-eq-𝟚 :
{x y : bool} → Id x y → Eq-𝟚 x y
Eq-eq-𝟚 {x = x} refl = reflexive-Eq-𝟚 x
eq-Eq-𝟚 :
{x y : bool} → Eq-𝟚 x y → Id x y
eq-Eq-𝟚 {true} {true} star = refl
eq-Eq-𝟚 {false} {false} star = refl
-- Exercise 6.2 (c)
neq-neg-𝟚 : (b : bool) → ¬ (Id b (neg-𝟚 b))
neq-neg-𝟚 true = Eq-eq-𝟚
neq-neg-𝟚 false = Eq-eq-𝟚
neq-false-true-𝟚 :
¬ (Id false true)
neq-false-true-𝟚 = Eq-eq-𝟚
-- Exercise 6.3
-- Exercise 6.3 (a)
leq-ℕ : ℕ → ℕ → UU lzero
leq-ℕ zero-ℕ m = unit
leq-ℕ (succ-ℕ n) zero-ℕ = empty
leq-ℕ (succ-ℕ n) (succ-ℕ m) = leq-ℕ n m
_≤_ = leq-ℕ
-- Some trivialities that will be useful later
leq-zero-ℕ :
(n : ℕ) → leq-ℕ zero-ℕ n
leq-zero-ℕ n = star
eq-leq-zero-ℕ :
(x : ℕ) → leq-ℕ x zero-ℕ → Id zero-ℕ x
eq-leq-zero-ℕ zero-ℕ star = refl
succ-leq-ℕ : (n : ℕ) → leq-ℕ n (succ-ℕ n)
succ-leq-ℕ zero-ℕ = star
succ-leq-ℕ (succ-ℕ n) = succ-leq-ℕ n
concatenate-eq-leq-eq-ℕ :
{x1 x2 x3 x4 : ℕ} → Id x1 x2 → leq-ℕ x2 x3 → Id x3 x4 → leq-ℕ x1 x4
concatenate-eq-leq-eq-ℕ refl H refl = H
concatenate-leq-eq-ℕ :
(m : ℕ) {n n' : ℕ} → leq-ℕ m n → Id n n' → leq-ℕ m n'
concatenate-leq-eq-ℕ m H refl = H
concatenate-eq-leq-ℕ :
{m m' : ℕ} (n : ℕ) → Id m' m → leq-ℕ m n → leq-ℕ m' n
concatenate-eq-leq-ℕ n refl H = H
-- Exercise 6.3 (b)
reflexive-leq-ℕ : (n : ℕ) → leq-ℕ n n
reflexive-leq-ℕ zero-ℕ = star
reflexive-leq-ℕ (succ-ℕ n) = reflexive-leq-ℕ n
leq-eq-ℕ : (m n : ℕ) → Id m n → leq-ℕ m n
leq-eq-ℕ m .m refl = reflexive-leq-ℕ m
transitive-leq-ℕ :
(n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l)
transitive-leq-ℕ zero-ℕ m l p q = star
transitive-leq-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-leq-ℕ n m l p q
preserves-leq-succ-ℕ :
(m n : ℕ) → leq-ℕ m n → leq-ℕ m (succ-ℕ n)
preserves-leq-succ-ℕ m n p = transitive-leq-ℕ m n (succ-ℕ n) p (succ-leq-ℕ n)
anti-symmetric-leq-ℕ : (m n : ℕ) → leq-ℕ m n → leq-ℕ n m → Id m n
anti-symmetric-leq-ℕ zero-ℕ zero-ℕ p q = refl
anti-symmetric-leq-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-leq-ℕ m n p q)
-- Exercise 6.3 (c)
decide-leq-ℕ :
(m n : ℕ) → coprod (leq-ℕ m n) (leq-ℕ n m)
decide-leq-ℕ zero-ℕ zero-ℕ = inl star
decide-leq-ℕ zero-ℕ (succ-ℕ n) = inl star
decide-leq-ℕ (succ-ℕ m) zero-ℕ = inr star
decide-leq-ℕ (succ-ℕ m) (succ-ℕ n) = decide-leq-ℕ m n
-- Exercise 6.3 (d)
preserves-order-add-ℕ :
(k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k)
preserves-order-add-ℕ zero-ℕ m n = id
preserves-order-add-ℕ (succ-ℕ k) m n = preserves-order-add-ℕ k m n
reflects-order-add-ℕ :
(k m n : ℕ) → leq-ℕ (add-ℕ m k) (add-ℕ n k) → leq-ℕ m n
reflects-order-add-ℕ zero-ℕ m n = id
reflects-order-add-ℕ (succ-ℕ k) m n = reflects-order-add-ℕ k m n
-- Exercise 6.3 (e)
preserves-order-mul-ℕ :
(k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k)
preserves-order-mul-ℕ k zero-ℕ n p = star
preserves-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
preserves-order-add-ℕ k
( mul-ℕ m k)
( mul-ℕ n k)
( preserves-order-mul-ℕ k m n p)
reflects-order-mul-ℕ :
(k m n : ℕ) → leq-ℕ (mul-ℕ m (succ-ℕ k)) (mul-ℕ n (succ-ℕ k)) → leq-ℕ m n
reflects-order-mul-ℕ k zero-ℕ n p = star
reflects-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p =
reflects-order-mul-ℕ k m n
( reflects-order-add-ℕ
( succ-ℕ k)
( mul-ℕ m (succ-ℕ k))
( mul-ℕ n (succ-ℕ k))
( p))
-- Exercise 6.3 (f)
leq-min-ℕ :
(k m n : ℕ) → leq-ℕ k m → leq-ℕ k n → leq-ℕ k (min-ℕ m n)
leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star
leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H K = star
leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H K = star
leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H K = star
leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-min-ℕ k m n H K
leq-left-leq-min-ℕ :
(k m n : ℕ) → leq-ℕ k (min-ℕ m n) → leq-ℕ k m
leq-left-leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H = star
leq-left-leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H = star
leq-left-leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H = star
leq-left-leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H = star
leq-left-leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-left-leq-min-ℕ k m n H
leq-right-leq-min-ℕ :
(k m n : ℕ) → leq-ℕ k (min-ℕ m n) → leq-ℕ k n
leq-right-leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H = star
leq-right-leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H = star
leq-right-leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H = star
leq-right-leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H = star
leq-right-leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-right-leq-min-ℕ k m n H
leq-max-ℕ :
(k m n : ℕ) → leq-ℕ m k → leq-ℕ n k → leq-ℕ (max-ℕ m n) k
leq-max-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star
leq-max-ℕ (succ-ℕ k) zero-ℕ zero-ℕ H K = star
leq-max-ℕ (succ-ℕ k) zero-ℕ (succ-ℕ n) H K = K
leq-max-ℕ (succ-ℕ k) (succ-ℕ m) zero-ℕ H K = H
leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-max-ℕ k m n H K
leq-left-leq-max-ℕ :
(k m n : ℕ) → leq-ℕ (max-ℕ m n) k → leq-ℕ m k
leq-left-leq-max-ℕ k zero-ℕ zero-ℕ H = star
leq-left-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = star
leq-left-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = H
leq-left-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-left-leq-max-ℕ k m n H
leq-right-leq-max-ℕ :
(k m n : ℕ) → leq-ℕ (max-ℕ m n) k → leq-ℕ n k
leq-right-leq-max-ℕ k zero-ℕ zero-ℕ H = star
leq-right-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = H
leq-right-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = star
leq-right-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H =
leq-right-leq-max-ℕ k m n H
-- Exercise 6.4
-- Exercise 6.4 (a)
-- We define a distance function on ℕ --
dist-ℕ : ℕ → ℕ → ℕ
dist-ℕ zero-ℕ n = n
dist-ℕ (succ-ℕ m) zero-ℕ = succ-ℕ m
dist-ℕ (succ-ℕ m) (succ-ℕ n) = dist-ℕ m n
dist-ℕ' : ℕ → ℕ → ℕ
dist-ℕ' m n = dist-ℕ n m
ap-dist-ℕ :
{m n m' n' : ℕ} → Id m m' → Id n n' → Id (dist-ℕ m n) (dist-ℕ m' n')
ap-dist-ℕ refl refl = refl
{- We show that two natural numbers are equal if and only if their distance is
zero. -}
eq-dist-ℕ :
(m n : ℕ) → Id zero-ℕ (dist-ℕ m n) → Id m n
eq-dist-ℕ zero-ℕ zero-ℕ p = refl
eq-dist-ℕ (succ-ℕ m) (succ-ℕ n) p = ap succ-ℕ (eq-dist-ℕ m n p)
dist-eq-ℕ' :
(n : ℕ) → Id zero-ℕ (dist-ℕ n n)
dist-eq-ℕ' zero-ℕ = refl
dist-eq-ℕ' (succ-ℕ n) = dist-eq-ℕ' n
dist-eq-ℕ :
(m n : ℕ) → Id m n → Id zero-ℕ (dist-ℕ m n)
dist-eq-ℕ m .m refl = dist-eq-ℕ' m
-- The distance function is symmetric --
symmetric-dist-ℕ :
(m n : ℕ) → Id (dist-ℕ m n) (dist-ℕ n m)
symmetric-dist-ℕ zero-ℕ zero-ℕ = refl
symmetric-dist-ℕ zero-ℕ (succ-ℕ n) = refl
symmetric-dist-ℕ (succ-ℕ m) zero-ℕ = refl
symmetric-dist-ℕ (succ-ℕ m) (succ-ℕ n) = symmetric-dist-ℕ m n
-- We compute the distance from zero --
left-zero-law-dist-ℕ :
(n : ℕ) → Id (dist-ℕ zero-ℕ n) n
left-zero-law-dist-ℕ zero-ℕ = refl
left-zero-law-dist-ℕ (succ-ℕ n) = refl
right-zero-law-dist-ℕ :
(n : ℕ) → Id (dist-ℕ n zero-ℕ) n
right-zero-law-dist-ℕ zero-ℕ = refl
right-zero-law-dist-ℕ (succ-ℕ n) = refl
-- We prove the triangle inequality --
ap-add-ℕ :
{m n m' n' : ℕ} → Id m m' → Id n n' → Id (add-ℕ m n) (add-ℕ m' n')
ap-add-ℕ refl refl = refl
triangle-inequality-dist-ℕ :
(m n k : ℕ) → leq-ℕ (dist-ℕ m n) (add-ℕ (dist-ℕ m k) (dist-ℕ k n))
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = star
triangle-inequality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = star
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ =
tr ( leq-ℕ (succ-ℕ n))
( inv (left-unit-law-add-ℕ (succ-ℕ n)))
( reflexive-leq-ℕ (succ-ℕ n))
triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (left-zero-law-dist-ℕ n)))
( triangle-inequality-dist-ℕ zero-ℕ n k)
( ( ap (succ-ℕ ∘ (add-ℕ' (dist-ℕ k n))) (left-zero-law-dist-ℕ k)) ∙
( inv (left-successor-law-add-ℕ k (dist-ℕ k n))))
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = reflexive-leq-ℕ (succ-ℕ m)
triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
concatenate-eq-leq-eq-ℕ
( inv (ap succ-ℕ (right-zero-law-dist-ℕ m)))
( triangle-inequality-dist-ℕ m zero-ℕ k)
( ap (succ-ℕ ∘ (add-ℕ (dist-ℕ m k))) (right-zero-law-dist-ℕ k))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ =
concatenate-leq-eq-ℕ
( dist-ℕ m n)
( transitive-leq-ℕ
( dist-ℕ m n)
( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))
( succ-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))
( transitive-leq-ℕ
( dist-ℕ m n)
( add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))
( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))
( triangle-inequality-dist-ℕ m n zero-ℕ)
( succ-leq-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))
( succ-leq-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))))
( ( ap (succ-ℕ ∘ succ-ℕ)
( ap-add-ℕ (right-zero-law-dist-ℕ m) (left-zero-law-dist-ℕ n))) ∙
( inv (left-successor-law-add-ℕ m (succ-ℕ n))))
triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
triangle-inequality-dist-ℕ m n k
-- Exercise 6.5 (c)
-- We show that dist-ℕ x y is a solution to a simple equation.
leq-dist-ℕ :
(x y : ℕ) → leq-ℕ x y → Id (add-ℕ x (dist-ℕ x y)) y
leq-dist-ℕ zero-ℕ zero-ℕ H = refl
leq-dist-ℕ zero-ℕ (succ-ℕ y) star = left-unit-law-add-ℕ (succ-ℕ y)
leq-dist-ℕ (succ-ℕ x) (succ-ℕ y) H =
( left-successor-law-add-ℕ x (dist-ℕ x y)) ∙
( ap succ-ℕ (leq-dist-ℕ x y H))
-- If three elements are ordered linearly, then their distances add up.
triangle-equality-dist-ℕ :
(x y z : ℕ) → (leq-ℕ x y) → (leq-ℕ y z) →
Id (add-ℕ (dist-ℕ x y) (dist-ℕ y z)) (dist-ℕ x z)
triangle-equality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ H1 H2 = refl
triangle-equality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ z) star star =
ap succ-ℕ (left-unit-law-add-ℕ z)
triangle-equality-dist-ℕ zero-ℕ (succ-ℕ y) (succ-ℕ z) star H2 =
left-successor-law-add-ℕ y (dist-ℕ y z) ∙
ap succ-ℕ (leq-dist-ℕ y z H2)
triangle-equality-dist-ℕ (succ-ℕ x) (succ-ℕ y) (succ-ℕ z) H1 H2 =
triangle-equality-dist-ℕ x y z H1 H2
rewrite-left-add-dist-ℕ :
(x y z : ℕ) → Id (add-ℕ x y) z → Id x (dist-ℕ y z)
rewrite-left-add-dist-ℕ zero-ℕ zero-ℕ .zero-ℕ refl = refl
rewrite-left-add-dist-ℕ zero-ℕ (succ-ℕ y) .(succ-ℕ (add-ℕ zero-ℕ y)) refl =
( dist-eq-ℕ' y) ∙
( inv (ap (dist-ℕ (succ-ℕ y)) (left-unit-law-add-ℕ (succ-ℕ y))))
rewrite-left-add-dist-ℕ (succ-ℕ x) zero-ℕ .(succ-ℕ x) refl = refl
rewrite-left-add-dist-ℕ
(succ-ℕ x) (succ-ℕ y) .(succ-ℕ (add-ℕ (succ-ℕ x) y)) refl =
rewrite-left-add-dist-ℕ (succ-ℕ x) y (add-ℕ (succ-ℕ x) y) refl
rewrite-left-dist-add-ℕ :
(x y z : ℕ) → leq-ℕ y z → Id x (dist-ℕ y z) → Id (add-ℕ x y) z
rewrite-left-dist-add-ℕ .(dist-ℕ y z) y z H refl =
( commutative-add-ℕ (dist-ℕ y z) y) ∙
( leq-dist-ℕ y z H)
rewrite-right-add-dist-ℕ :
(x y z : ℕ) → Id (add-ℕ x y) z → Id y (dist-ℕ x z)
rewrite-right-add-dist-ℕ x y z p =
rewrite-left-add-dist-ℕ y x z (commutative-add-ℕ y x ∙ p)
rewrite-right-dist-add-ℕ :
(x y z : ℕ) → leq-ℕ x z → Id y (dist-ℕ x z) → Id (add-ℕ x y) z
rewrite-right-dist-add-ℕ x .(dist-ℕ x z) z H refl =
leq-dist-ℕ x z H
-- We show that dist-ℕ is translation invariant
translation-invariant-dist-ℕ :
(k m n : ℕ) → Id (dist-ℕ (add-ℕ k m) (add-ℕ k n)) (dist-ℕ m n)
translation-invariant-dist-ℕ zero-ℕ m n =
ap-dist-ℕ (left-unit-law-add-ℕ m) (left-unit-law-add-ℕ n)
translation-invariant-dist-ℕ (succ-ℕ k) m n =
( ap-dist-ℕ (left-successor-law-add-ℕ k m) (left-successor-law-add-ℕ k n)) ∙
( translation-invariant-dist-ℕ k m n)
-- We show that dist-ℕ is linear with respect to scalar multiplication
linear-dist-ℕ :
(m n k : ℕ) → Id (dist-ℕ (mul-ℕ k m) (mul-ℕ k n)) (mul-ℕ k (dist-ℕ m n))
linear-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = refl
linear-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = linear-dist-ℕ zero-ℕ zero-ℕ k
linear-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ = refl
linear-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) =
ap (dist-ℕ' (mul-ℕ (succ-ℕ k) (succ-ℕ n))) (right-zero-law-mul-ℕ (succ-ℕ k))
linear-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = refl
linear-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) =
ap (dist-ℕ (mul-ℕ (succ-ℕ k) (succ-ℕ m))) (right-zero-law-mul-ℕ (succ-ℕ k))
linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ = refl
linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) =
( ap-dist-ℕ
( right-successor-law-mul-ℕ (succ-ℕ k) m)
( right-successor-law-mul-ℕ (succ-ℕ k) n)) ∙
( ( translation-invariant-dist-ℕ
( succ-ℕ k)
( mul-ℕ (succ-ℕ k) m)
( mul-ℕ (succ-ℕ k) n)) ∙
( linear-dist-ℕ m n (succ-ℕ k)))
-- We give an upper bound for the distantce between two numbers.
upper-bound-dist-ℕ :
(b x y : ℕ) → leq-ℕ x b → leq-ℕ y b → leq-ℕ (dist-ℕ x y) b
upper-bound-dist-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star
upper-bound-dist-ℕ (succ-ℕ b) zero-ℕ zero-ℕ H K = star
upper-bound-dist-ℕ (succ-ℕ b) zero-ℕ (succ-ℕ y) H K = K
upper-bound-dist-ℕ (succ-ℕ b) (succ-ℕ x) zero-ℕ H K = H
upper-bound-dist-ℕ (succ-ℕ b) (succ-ℕ x) (succ-ℕ y) H K =
preserves-leq-succ-ℕ (dist-ℕ x y) b (upper-bound-dist-ℕ b x y H K)
--------------------------------------------------------------------------------
-- Exercise 6.5
-- We introduce the absolute value of an integer. --
abs-ℤ : ℤ → ℕ
abs-ℤ (inl x) = succ-ℕ x
abs-ℤ (inr (inl star)) = zero-ℕ
abs-ℤ (inr (inr x)) = succ-ℕ x
int-abs-ℤ : ℤ → ℤ
int-abs-ℤ = int-ℕ ∘ abs-ℤ
eq-abs-ℤ : (x : ℤ) → Id zero-ℕ (abs-ℤ x) → Id zero-ℤ x
eq-abs-ℤ (inl x) p = ex-falso (Peano-8 x p)
eq-abs-ℤ (inr (inl star)) p = refl
eq-abs-ℤ (inr (inr x)) p = ex-falso (Peano-8 x p)
abs-eq-ℤ : (x : ℤ) → Id zero-ℤ x → Id zero-ℕ (abs-ℤ x)
abs-eq-ℤ .zero-ℤ refl = refl
predecessor-law-abs-ℤ :
(x : ℤ) → leq-ℕ (abs-ℤ (pred-ℤ x)) (succ-ℕ (abs-ℤ x))
predecessor-law-abs-ℤ (inl x) =
reflexive-leq-ℕ (succ-ℕ x)
predecessor-law-abs-ℤ (inr (inl star)) =
reflexive-leq-ℕ zero-ℕ
predecessor-law-abs-ℤ (inr (inr zero-ℕ)) =
star
predecessor-law-abs-ℤ (inr (inr (succ-ℕ x))) =
preserves-leq-succ-ℕ x (succ-ℕ x) (succ-leq-ℕ x)
successor-law-abs-ℤ :
(x : ℤ) → leq-ℕ (abs-ℤ (succ-ℤ x)) (succ-ℕ (abs-ℤ x))
successor-law-abs-ℤ (inl zero-ℕ) =
star
successor-law-abs-ℤ (inl (succ-ℕ x)) =
preserves-leq-succ-ℕ x (succ-ℕ x) (succ-leq-ℕ x)
successor-law-abs-ℤ (inr (inl star)) =
reflexive-leq-ℕ zero-ℕ
successor-law-abs-ℤ (inr (inr x)) =
reflexive-leq-ℕ (succ-ℕ x)
subadditive-abs-ℤ :
(x y : ℤ) → leq-ℕ (abs-ℤ (add-ℤ x y)) (add-ℕ (abs-ℤ x) (abs-ℤ y))
subadditive-abs-ℤ x (inl zero-ℕ) =
concatenate-eq-leq-eq-ℕ
( ap abs-ℤ (add-neg-one-right-ℤ x))
( predecessor-law-abs-ℤ x)
( refl)
subadditive-abs-ℤ x (inl (succ-ℕ y)) =
concatenate-eq-leq-eq-ℕ
( ap abs-ℤ (right-predecessor-law-add-ℤ x (inl y)))
( transitive-leq-ℕ
( abs-ℤ (pred-ℤ (add-ℤ x (inl y))))
( succ-ℕ (abs-ℤ (add-ℤ x (inl y))))
( add-ℕ (abs-ℤ x) (succ-ℕ (succ-ℕ y)))
( predecessor-law-abs-ℤ (add-ℤ x (inl y)))
( subadditive-abs-ℤ x (inl y)))
( refl)
subadditive-abs-ℤ x (inr (inl star)) =
concatenate-eq-leq-eq-ℕ
( ap abs-ℤ (right-unit-law-add-ℤ x))
( reflexive-leq-ℕ (abs-ℤ x))
( refl)
subadditive-abs-ℤ x (inr (inr zero-ℕ)) =
concatenate-eq-leq-eq-ℕ
( ap abs-ℤ (add-one-right-ℤ x))
( successor-law-abs-ℤ x)
( refl)
subadditive-abs-ℤ x (inr (inr (succ-ℕ y))) =
concatenate-eq-leq-eq-ℕ
( ap abs-ℤ (right-successor-law-add-ℤ x (inr (inr y))))
( transitive-leq-ℕ
( abs-ℤ (succ-ℤ (add-ℤ x (inr (inr y)))))
( succ-ℕ (abs-ℤ (add-ℤ x (inr (inr y)))))
( succ-ℕ (add-ℕ (abs-ℤ x) (succ-ℕ y)))
( successor-law-abs-ℤ (add-ℤ x (inr (inr y))))
( subadditive-abs-ℤ x (inr (inr y))))
( refl)
negative-law-abs-ℤ :
(x : ℤ) → Id (abs-ℤ (neg-ℤ x)) (abs-ℤ x)
negative-law-abs-ℤ (inl x) = refl
negative-law-abs-ℤ (inr (inl star)) = refl
negative-law-abs-ℤ (inr (inr x)) = refl
--------------------------------------------------------------------------------
-- Exercise 6.6
{- In this exercise we were asked to define the relations ≤ and < on the
integers. As a criterion of correctness, we were then also asked to show
that the type of all integers l satisfying k ≤ l satisfy the induction
principle of the natural numbers. -}
diff-ℤ : ℤ → ℤ → ℤ
diff-ℤ k l = add-ℤ (neg-ℤ k) l
is-non-negative-ℤ : ℤ → UU lzero
is-non-negative-ℤ (inl x) = empty
is-non-negative-ℤ (inr k) = unit
leq-ℤ : ℤ → ℤ → UU lzero
leq-ℤ k l = is-non-negative-ℤ (diff-ℤ k l)
reflexive-leq-ℤ : (k : ℤ) → leq-ℤ k k
reflexive-leq-ℤ k =
tr is-non-negative-ℤ (inv (left-inverse-law-add-ℤ k)) star
is-non-negative-succ-ℤ :
(k : ℤ) → is-non-negative-ℤ k → is-non-negative-ℤ (succ-ℤ k)
is-non-negative-succ-ℤ (inr (inl star)) p = star
is-non-negative-succ-ℤ (inr (inr x)) p = star
is-non-negative-add-ℤ :
(k l : ℤ) →
is-non-negative-ℤ k → is-non-negative-ℤ l → is-non-negative-ℤ (add-ℤ k l)
is-non-negative-add-ℤ (inr (inl star)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inl star)) (inr (inr n)) p q = star
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inl star)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inl star)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inl star)) star star)
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inr m)) star star = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inr m)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inr m)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inr m)) star star)
triangle-diff-ℤ :
(k l m : ℤ) → Id (add-ℤ (diff-ℤ k l) (diff-ℤ l m)) (diff-ℤ k m)
triangle-diff-ℤ k l m =
( associative-add-ℤ (neg-ℤ k) l (diff-ℤ l m)) ∙
( ap
( add-ℤ (neg-ℤ k))
( ( inv (associative-add-ℤ l (neg-ℤ l) m)) ∙
( ( ap (λ x → add-ℤ x m) (right-inverse-law-add-ℤ l)) ∙
( left-unit-law-add-ℤ m))))
transitive-leq-ℤ : (k l m : ℤ) → leq-ℤ k l → leq-ℤ l m → leq-ℤ k m
transitive-leq-ℤ k l m p q =
tr is-non-negative-ℤ
( triangle-diff-ℤ k l m)
( is-non-negative-add-ℤ
( add-ℤ (neg-ℤ k) l)
( add-ℤ (neg-ℤ l) m)
( p)
( q))
succ-leq-ℤ : (k : ℤ) → leq-ℤ k (succ-ℤ k)
succ-leq-ℤ k =
tr is-non-negative-ℤ
( inv
( ( right-successor-law-add-ℤ (neg-ℤ k) k) ∙
( ap succ-ℤ (left-inverse-law-add-ℤ k))))
( star)
leq-ℤ-succ-leq-ℤ : (k l : ℤ) → leq-ℤ k l → leq-ℤ k (succ-ℤ l)
leq-ℤ-succ-leq-ℤ k l p = transitive-leq-ℤ k l (succ-ℤ l) p (succ-leq-ℤ l)
is-positive-ℤ : ℤ → UU lzero
is-positive-ℤ k = is-non-negative-ℤ (pred-ℤ k)
le-ℤ : ℤ → ℤ → UU lzero
le-ℤ (inl zero-ℕ) (inl x) = empty
le-ℤ (inl zero-ℕ) (inr y) = unit
le-ℤ (inl (succ-ℕ x)) (inl zero-ℕ) = unit
le-ℤ (inl (succ-ℕ x)) (inl (succ-ℕ y)) = le-ℤ (inl x) (inl y)
le-ℤ (inl (succ-ℕ x)) (inr y) = unit
le-ℤ (inr x) (inl y) = empty
le-ℤ (inr (inl star)) (inr (inl star)) = empty
le-ℤ (inr (inl star)) (inr (inr x)) = unit
le-ℤ (inr (inr x)) (inr (inl star)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr (succ-ℕ y))) = unit
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr (succ-ℕ y))) =
le-ℤ (inr (inr x)) (inr (inr y))
-- Extra material
-- We show that ℕ is an ordered semi-ring
left-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k)
left-law-leq-add-ℕ zero-ℕ m n = id
left-law-leq-add-ℕ (succ-ℕ k) m n H = left-law-leq-add-ℕ k m n H
right-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ k m) (add-ℕ k n)
right-law-leq-add-ℕ k m n H =
concatenate-eq-leq-eq-ℕ
( commutative-add-ℕ k m)
( left-law-leq-add-ℕ k m n H)
( commutative-add-ℕ n k)
preserves-leq-add-ℕ :
{m m' n n' : ℕ} → leq-ℕ m m' → leq-ℕ n n' → leq-ℕ (add-ℕ m n) (add-ℕ m' n')
preserves-leq-add-ℕ {m} {m'} {n} {n'} H K =
transitive-leq-ℕ
( add-ℕ m n)
( add-ℕ m' n)
( add-ℕ m' n')
( left-law-leq-add-ℕ n m m' H)
( right-law-leq-add-ℕ m' n n' K)
{-
right-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ k m) (mul-ℕ k n)
right-law-leq-mul-ℕ zero-ℕ m n H = star
right-law-leq-mul-ℕ (succ-ℕ k) m n H = {!!}
-}
{-
preserves-leq-add-ℕ
{ m = mul-ℕ k m}
{ m' = mul-ℕ k n}
( right-law-leq-mul-ℕ k m n H) H
left-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k)
left-law-leq-mul-ℕ k m n H =
concatenate-eq-leq-eq-ℕ
( commutative-mul-ℕ k m)
( commutative-mul-ℕ k n)
( right-law-leq-mul-ℕ k m n H)
-}
-- We show that ℤ is an ordered ring
{-
leq-add-ℤ : (m k l : ℤ) → leq-ℤ k l → leq-ℤ (add-ℤ m k) (add-ℤ m l)
leq-add-ℤ (inl zero-ℕ) k l H = {!!}
leq-add-ℤ (inl (succ-ℕ x)) k l H = {!!}
leq-add-ℤ (inr m) k l H = {!!}
-}
-- Section 5.5 Identity systems
succ-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) →
(m n : ℕ) → Eq-ℕ m n → UU i
succ-fam-Eq-ℕ R m n e = R (succ-ℕ m) (succ-ℕ n) e
succ-refl-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
(ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
(n : ℕ) → (succ-fam-Eq-ℕ R n n (refl-Eq-ℕ n))
succ-refl-fam-Eq-ℕ R ρ n = ρ (succ-ℕ n)
path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( m n : ℕ) (e : Eq-ℕ m n) → R m n e
path-ind-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
path-ind-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
path-ind-Eq-ℕ
( λ m n e → R (succ-ℕ m) (succ-ℕ n) e)
( λ n → ρ (succ-ℕ n)) m n e
comp-path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( n : ℕ) → Id (path-ind-Eq-ℕ R ρ n n (refl-Eq-ℕ n)) (ρ n)
comp-path-ind-Eq-ℕ R ρ zero-ℕ = refl
comp-path-ind-Eq-ℕ R ρ (succ-ℕ n) =
comp-path-ind-Eq-ℕ
( λ m n e → R (succ-ℕ m) (succ-ℕ n) e)
( λ n → ρ (succ-ℕ n)) n
{-
-- Graphs
Gph : (i : Level) → UU (lsuc i)
Gph i = Σ (UU i) (λ X → (X → X → (UU i)))
-- Reflexive graphs
rGph : (i : Level) → UU (lsuc i)
rGph i = Σ (UU i) (λ X → Σ (X → X → (UU i)) (λ R → (x : X) → R x x))
-}
-- Exercise 3.7
{- With the construction of the divisibility relation we open the door to basic
number theory. -}
divides : (d n : ℕ) → UU lzero
divides d n = Σ ℕ (λ m → Eq-ℕ (mul-ℕ d m) n)
-- We prove some lemmas about inequalities --
leq-add-ℕ :
(m n : ℕ) → leq-ℕ m (add-ℕ m n)
leq-add-ℕ m zero-ℕ = reflexive-leq-ℕ m
leq-add-ℕ m (succ-ℕ n) =
transitive-leq-ℕ m (add-ℕ m n) (succ-ℕ (add-ℕ m n))
( leq-add-ℕ m n)
( succ-leq-ℕ (add-ℕ m n))
leq-add-ℕ' :
(m n : ℕ) → leq-ℕ m (add-ℕ n m)
leq-add-ℕ' m n =
concatenate-leq-eq-ℕ m (leq-add-ℕ m n) (commutative-add-ℕ m n)
leq-leq-add-ℕ :
(m n x : ℕ) → leq-ℕ (add-ℕ m x) (add-ℕ n x) → leq-ℕ m n
leq-leq-add-ℕ m n zero-ℕ H = H
leq-leq-add-ℕ m n (succ-ℕ x) H = leq-leq-add-ℕ m n x H
leq-leq-add-ℕ' :
(m n x : ℕ) → leq-ℕ (add-ℕ x m) (add-ℕ x n) → leq-ℕ m n
leq-leq-add-ℕ' m n x H =
leq-leq-add-ℕ m n x
( concatenate-eq-leq-eq-ℕ
( commutative-add-ℕ m x)
( H)
( commutative-add-ℕ x n))
leq-leq-mul-ℕ :
(m n x : ℕ) → leq-ℕ (mul-ℕ (succ-ℕ x) m) (mul-ℕ (succ-ℕ x) n) → leq-ℕ m n
leq-leq-mul-ℕ zero-ℕ zero-ℕ x H = star
leq-leq-mul-ℕ zero-ℕ (succ-ℕ n) x H = star
leq-leq-mul-ℕ (succ-ℕ m) zero-ℕ x H =
ex-falso
( concatenate-leq-eq-ℕ
( mul-ℕ (succ-ℕ x) (succ-ℕ m))
( H)
( right-zero-law-mul-ℕ (succ-ℕ x)))
leq-leq-mul-ℕ (succ-ℕ m) (succ-ℕ n) x H =
leq-leq-mul-ℕ m n x
( leq-leq-add-ℕ' (mul-ℕ (succ-ℕ x) m) (mul-ℕ (succ-ℕ x) n) (succ-ℕ x)
( concatenate-eq-leq-eq-ℕ
( inv (right-successor-law-mul-ℕ (succ-ℕ x) m))
( H)
( right-successor-law-mul-ℕ (succ-ℕ x) n)))
leq-leq-mul-ℕ' :
(m n x : ℕ) → leq-ℕ (mul-ℕ m (succ-ℕ x)) (mul-ℕ n (succ-ℕ x)) → leq-ℕ m n
leq-leq-mul-ℕ' m n x H =
leq-leq-mul-ℕ m n x
( concatenate-eq-leq-eq-ℕ
( commutative-mul-ℕ (succ-ℕ x) m)
( H)
( commutative-mul-ℕ n (succ-ℕ x)))
{-
succ-relation-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) → ℕ → ℕ → UU i
succ-relation-ℕ R m n = R (succ-ℕ m) (succ-ℕ n)
succ-reflexivity-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(n : ℕ) → succ-relation-ℕ R n n
succ-reflexivity-ℕ R ρ n = ρ (succ-ℕ n)
{- In the book we suggest that first the order of the variables should be
swapped, in order to make the inductive hypothesis stronger. Agda's pattern
matching mechanism allows us to bypass this step and give a more direct
construction. -}
least-reflexive-Eq-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(m n : ℕ) → Eq-ℕ m n → R m n
least-reflexive-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
least-reflexive-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
least-reflexive-Eq-ℕ (succ-relation-ℕ R) (succ-reflexivity-ℕ R ρ) m n e
-}
-- The definition of <
le-ℕ : ℕ → ℕ → UU lzero
le-ℕ m zero-ℕ = empty
le-ℕ zero-ℕ (succ-ℕ m) = unit
le-ℕ (succ-ℕ n) (succ-ℕ m) = le-ℕ n m
_<_ = le-ℕ
anti-reflexive-le-ℕ : (n : ℕ) → ¬ (n < n)
anti-reflexive-le-ℕ zero-ℕ = ind-empty
anti-reflexive-le-ℕ (succ-ℕ n) = anti-reflexive-le-ℕ n
transitive-le-ℕ : (n m l : ℕ) → (le-ℕ n m) → (le-ℕ m l) → (le-ℕ n l)
transitive-le-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ l) p q = star
transitive-le-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-le-ℕ n m l p q
succ-le-ℕ : (n : ℕ) → le-ℕ n (succ-ℕ n)
succ-le-ℕ zero-ℕ = star
succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n
anti-symmetric-le-ℕ : (m n : ℕ) → le-ℕ m n → le-ℕ n m → Id m n
anti-symmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-le-ℕ m n p q)
{-
--------------------------------------------------------------------------------
data Fin-Tree : UU lzero where
constr : (n : ℕ) → (Fin n → Fin-Tree) → Fin-Tree
root-Fin-Tree : Fin-Tree
root-Fin-Tree = constr zero-ℕ ex-falso
succ-Fin-Tree : Fin-Tree → Fin-Tree
succ-Fin-Tree t = constr one-ℕ (λ i → t)
map-assoc-coprod :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {C : UU l3} →
coprod (coprod A B) C → coprod A (coprod B C)
map-assoc-coprod (inl (inl x)) = inl x
map-assoc-coprod (inl (inr x)) = inr (inl x)
map-assoc-coprod (inr x) = inr (inr x)
map-coprod-Fin :
(m n : ℕ) → Fin (add-ℕ m n) → coprod (Fin m) (Fin n)
map-coprod-Fin m zero-ℕ = inl
map-coprod-Fin m (succ-ℕ n) =
map-assoc-coprod ∘ (functor-coprod (map-coprod-Fin m n) (id {A = unit}))
add-Fin-Tree : Fin-Tree → Fin-Tree → Fin-Tree
add-Fin-Tree (constr n x) (constr m y) =
constr (add-ℕ n m) ((ind-coprod (λ i → Fin-Tree) x y) ∘ (map-coprod-Fin n m))
--------------------------------------------------------------------------------
data labeled-Bin-Tree {l1 : Level} (A : UU l1) : UU l1 where
leaf : A → labeled-Bin-Tree A
constr : (bool → labeled-Bin-Tree A) → labeled-Bin-Tree A
mul-leaves-labeled-Bin-Tree :
{l1 : Level} {A : UU l1} (μ : A → (A → A)) →
labeled-Bin-Tree A → A
mul-leaves-labeled-Bin-Tree μ (leaf x) = x
mul-leaves-labeled-Bin-Tree μ (constr f) =
μ ( mul-leaves-labeled-Bin-Tree μ (f false))
( mul-leaves-labeled-Bin-Tree μ (f true))
pick-list : {l1 : Level} {A : UU l1} → ℕ → list A → coprod A unit
pick-list zero-ℕ nil = inr star
pick-list zero-ℕ (cons a x) = inl a
pick-list (succ-ℕ n) nil = inr star
pick-list (succ-ℕ n) (cons a x) = pick-list n x
-}
| 31.491525
| 80
| 0.569631
|
ad9ff9a638bda48dcb778a996a4a57700a886cb5
| 8,632
|
agda
|
Agda
|
constructability.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
constructability.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
constructability.agda
|
hazelgrove/hazelnut-agda
|
a3640d7b0f76cdac193afd382694197729ed6d57
|
[
"MIT"
] | null | null | null |
open import Nat
open import Prelude
open import List
open import judgemental-erase
open import statics-checks
open import statics-core
module constructability where
-- we construct expressions and types by induction on their
-- structure. for each sub term, we call the relevant theorem, then
-- assemble the results with carefully chosen lists of actions that allow
-- us to call the appropriate zipper lemmas and maintain well-typedness
-- at every stage of the contruction.
--
-- the proof term at each stage except subsumption is, morally, just the
-- mapping of the fragment of the action semantics used by the constructs
-- in the list in the current formation context into the list monoid.
-- if the name of the given hole is irrelevant
irr-hole : Nat
irr-hole = 0
-- construction of types
construct-type : (t : htyp) → Σ[ L ∈ List action ] runtype (▹ ⦇-⦈ ◃) L (▹ t ◃)
construct-type num = [ construct num ] , DoType TMConNum DoRefl
construct-type ⦇-⦈ = [ del irr-hole ] , DoType TMDel DoRefl
construct-type (t1 ==> t2) with construct-type t1 | construct-type t2
... | (l1 , ih1) | (l2 , ih2) = l1 ++ construct arrow :: l2 ++ [ move parent ] ,
runtype++ ih1
(DoType TMConArrow
(runtype++ (ziplem-tmarr2 ih2)
(DoType TMArrParent2 DoRefl)))
construct-type (t1 ⊕ t2) with construct-type t1 | construct-type t2
... | (l1 , ih1) | (l2 , ih2) = l1 ++ construct sum :: l2 ++ [ move parent ] ,
runtype++ ih1
(DoType TMConPlus
(runtype++ (ziplem-tmplus2 ih2)
(DoType TMPlusParent2 DoRefl)))
construct-type (t1 ⊠ t2) with construct-type t1 | construct-type t2
... | (l1 , ih1) | (l2 , ih2) = l1 ++ construct prod :: l2 ++ [ move parent ] ,
runtype++ ih1
(DoType TMConProd
(runtype++ (ziplem-tmprod2 ih2)
(DoType TMProdParent2 DoRefl)))
mutual
-- construction of expressions in synthetic positions
construct-synth : {Γ : tctx} {u : Nat} {t : htyp} {e : hexp} →
(Γ ⊢ e => t) →
Σ[ L ∈ List action ]
runsynth Γ ▹ ⦇-⦈[ u ] ◃ ⦇-⦈ L ▹ e ◃ t
-- the three base cases
construct-synth (SVar x) = [ construct (var _ irr-hole) ] , DoSynth (SAConVar x) DoRefl
construct-synth SNum = [ construct (numlit _ irr-hole) ] , DoSynth SAConNumlit DoRefl
construct-synth SEHole = [ del _ ] , DoSynth SADel DoRefl
-- the inductive cases
construct-synth (SPlus e1 e2 ) with construct-ana e1 | construct-ana e2
... | (l1 , ih1) | (l2 , ih2) =
construct (plus irr-hole irr-hole) :: (l2 ++ move parent ::
move (child 1) :: (l1 ++ [ move parent ])) ,
DoSynth (SAConPlus1 TCHole2)
(runsynth++ (ziplem-plus2 ih2)
(DoSynth (SAMove EMPlusParent2)
(DoSynth (SAMove EMPlusChild1)
(runsynth++ (ziplem-plus1 ih1)
(DoSynth (SAMove EMPlusParent1) DoRefl)))))
construct-synth {t = t} (SAsc x) with construct-type t | construct-ana x
... | (l1 , ih1) | (l2 , ih2) =
construct asc :: (l1 ++ move parent :: move (child 1) :: (l2 ++ [ move parent ])) ,
DoSynth SAConAsc
(runsynth++ (ziplem-asc2 ETTop ETTop ih1)
(DoSynth (SAMove EMAscParent2)
(DoSynth (SAMove EMAscChild1)
(runsynth++ (ziplem-asc1 ih2)
(DoSynth (SAMove EMAscParent1) DoRefl)))))
construct-synth {t = t1 ==> t2} (SLam x wt) with construct-type t1 | construct-synth wt
... | l1 , ih1 | l2 , ih2 =
construct (lam _ irr-hole irr-hole) ::
(l1 ++ (move parent :: move (child 2) :: (l2 ++ [ move parent ]))) ,
DoSynth (SAConLam x)
(runsynth++ (ziplem-halflam1 x ETTop (rel◆t _) ih1)
(DoSynth (SAMove EMHalfLamParent1)
(DoSynth (SAMove EMHalfLamChild2)
(runsynth++ (ziplem-halflam2 x EETop SEHole ih2)
(DoSynth (SAMove EMHalfLamParent2) DoRefl)))))
construct-synth (SAp e1 m e2) with construct-synth e1 | construct-ana e2
... | l1 , ih1 | l2 , ih2 =
l1 ++ construct (ap irr-hole irr-hole) :: (l2 ++ [ move parent ]) ,
runsynth++ ih1
(DoSynth (SAConApArr m)
(runsynth++ (ziplem-ap2 e1 m ih2)
(DoSynth (SAMove EMApParent2) DoRefl)))
construct-synth (SNEHole {u = u} wt) with construct-synth wt
... | l , ih = l ++ construct (nehole u) :: move parent :: [] ,
runsynth++ ih
(DoSynth SAConNEHole
(DoSynth (SAMove EMNEHoleParent) DoRefl))
construct-synth (SPair e1 e2) with construct-synth e1 | construct-synth e2
... | l1 , ih1 | l2 , ih2 =
construct (pair irr-hole irr-hole) :: (l1 ++ move parent :: move (child 2)
:: l2 ++ [ move parent ]) ,
DoSynth SAConPair
(runsynth++ (ziplem-pair1 EETop SEHole ih1 SEHole)
(DoSynth (SAMove EMPairParent1)
(DoSynth (SAMove EMPairChild2)
(runsynth++ (ziplem-pair2 e1 EETop SEHole ih2)
(DoSynth (SAMove EMPairParent2) DoRefl)))))
construct-synth (SFst e pr) with construct-synth e
... | l , ih = l ++ [ construct (fst irr-hole) ] ,
runsynth++ ih (DoSynth (SAConFst1 pr) DoRefl)
construct-synth (SSnd e pr) with construct-synth e
... | l , ih = l ++ [ construct (snd irr-hole) ] ,
runsynth++ ih (DoSynth (SAConSnd1 pr) DoRefl)
-- construction of expressions in analytic positions
construct-ana : {Γ : tctx} {u : Nat} {t : htyp} {e : hexp} →
(Γ ⊢ e <= t) →
Σ[ L ∈ List action ]
runana Γ ▹ ⦇-⦈[ u ] ◃ L ▹ e ◃ t
construct-ana (ASubsume x c) with construct-synth x
... | l , ih = construct (nehole irr-hole) :: l ++ (move parent :: finish :: []) ,
DoAna (AASubsume EETop SEHole SAConNEHole TCHole1)
(runana++ (ziplem-nehole-b SEHole c ih)
(DoAna (AAMove EMNEHoleParent)
(DoAna (AAFinish (ASubsume x c)) DoRefl)))
construct-ana (ALam a m e) with construct-ana e
... | l , ih = construct (lam _ irr-hole irr-hole) :: (l ++ [ move parent ]) ,
DoAna (AAConLam1 a m)
(runana++ (ziplem-lam a m ih)
(DoAna (AAMove EMLamParent) DoRefl))
construct-ana (AInl m wt) with construct-ana wt
... | l , ih = construct (inl irr-hole irr-hole) :: l ++ [ move parent ] ,
DoAna (AAConInl1 m)
(runana++ (ziplem-inl m ih)
(DoAna (AAMove EMInlParent) DoRefl))
construct-ana (AInr m wt) with construct-ana wt
... | l , ih = construct (inr irr-hole irr-hole) :: l ++ [ move parent ] ,
DoAna (AAConInr1 m)
(runana++ (ziplem-inr m ih)
(DoAna (AAMove EMInrParent) DoRefl))
construct-ana (ACase {x = x} {y = y} x# y# m wt0 wt1 wt2)
with construct-synth wt0
| construct-ana wt1
| construct-ana wt2
... | l0 , ih0 | l1 , ih1 | l2 , ih2 =
construct (case x y irr-hole irr-hole irr-hole) :: construct (nehole irr-hole) ::
l0 ++ (move parent :: finish :: move parent :: move (child 2) ::
l1 ++ (move parent :: move (child 3) ::
l2 ++ [ move parent ])) ,
DoAna (AAConCase x# y#)
(DoAna (AAZipCase1 x# y# EETop SEHole SAConNEHole MSHole
(ASubsume SEHole TCHole1) (ASubsume SEHole TCHole1))
(runana++ (ziplem-case1b x# y# EETop SEHole ih0)
(DoAna (AAZipCase1 x# y# (EENEHole EETop)
(SNEHole wt0) (SAMove EMNEHoleParent) MSHole (ASubsume SEHole TCHole1)
(ASubsume SEHole TCHole1))
(DoAna (AAZipCase1 x# y# EETop (SNEHole wt0) (SAFinish wt0) m
(ASubsume SEHole TCHole1) (ASubsume SEHole TCHole1))
(DoAna (AAMove EMCaseParent1)
(DoAna (AAMove EMCaseChild2)
(runana++ (ziplem-case2 x# y# wt0 (ASubsume SEHole TCHole1) m ih1)
(DoAna (AAMove EMCaseParent2)
(DoAna (AAMove EMCaseChild3)
(runana++ (ziplem-case3 x# y# wt0 wt1 m ih2)
(DoAna (AAMove EMCaseParent3) DoRefl)))))))))))
| 48.768362
| 91
| 0.544486
|
add0cd1454a4836512a0567aa888b34a307d5f33
| 2,474
|
agda
|
Agda
|
lib/Haskell/Prim/Bounded.agda
|
flupe/agda2hs
|
4cb28f1b5032948b19b977b390fa260be292abf6
|
[
"MIT"
] | null | null | null |
lib/Haskell/Prim/Bounded.agda
|
flupe/agda2hs
|
4cb28f1b5032948b19b977b390fa260be292abf6
|
[
"MIT"
] | null | null | null |
lib/Haskell/Prim/Bounded.agda
|
flupe/agda2hs
|
4cb28f1b5032948b19b977b390fa260be292abf6
|
[
"MIT"
] | null | null | null |
module Haskell.Prim.Bounded where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
open import Agda.Builtin.Char
open import Agda.Builtin.Equality
open import Agda.Builtin.List
open import Haskell.Prim
open import Haskell.Prim.Eq
open import Haskell.Prim.Int
open import Haskell.Prim.Maybe
open import Haskell.Prim.Ord
open import Haskell.Prim.Tuple
open import Haskell.Prim.Word
--------------------------------------------------
-- Bounded
record BoundedBelow (a : Set) : Set where
field
minBound : a
record BoundedAbove (a : Set) : Set where
field
maxBound : a
record Bounded (a : Set) : Set where
field
overlap ⦃ below ⦄ : BoundedBelow a
overlap ⦃ above ⦄ : BoundedAbove a
open BoundedBelow ⦃ ... ⦄ public
open BoundedAbove ⦃ ... ⦄ public
instance
iBounded : ⦃ BoundedBelow a ⦄ → ⦃ BoundedAbove a ⦄ → Bounded a
iBounded .Bounded.below = it
iBounded .Bounded.above = it
instance
iBoundedBelowNatural : BoundedBelow Nat
iBoundedBelowNatural .minBound = 0
iBoundedBelowWord : BoundedBelow Word
iBoundedBelowWord .minBound = 0
iBoundedAboveWord : BoundedAbove Word
iBoundedAboveWord .maxBound = 18446744073709551615
iBoundedBelowInt : BoundedBelow Int
iBoundedBelowInt .minBound = -9223372036854775808
iBoundedAboveInt : BoundedAbove Int
iBoundedAboveInt .maxBound = 9223372036854775807
iBoundedBelowBool : BoundedBelow Bool
iBoundedBelowBool .minBound = false
iBoundedAboveBool : BoundedAbove Bool
iBoundedAboveBool .maxBound = true
iBoundedBelowChar : BoundedBelow Char
iBoundedBelowChar .minBound = '\0'
iBoundedAboveChar : BoundedAbove Char
iBoundedAboveChar .maxBound = '\1114111'
iBoundedBelowTuple₀ : BoundedBelow (Tuple [])
iBoundedBelowTuple₀ .minBound = []
iBoundedAboveTuple₀ : BoundedAbove (Tuple [])
iBoundedAboveTuple₀ .maxBound = []
iBoundedBelowTuple : ∀ {as} → ⦃ BoundedBelow a ⦄ → ⦃ BoundedBelow (Tuple as) ⦄ → BoundedBelow (Tuple (a ∷ as))
iBoundedBelowTuple .minBound = minBound ∷ minBound
iBoundedAboveTuple : ∀ {as} → ⦃ BoundedAbove a ⦄ → ⦃ BoundedAbove (Tuple as) ⦄ → BoundedAbove (Tuple (a ∷ as))
iBoundedAboveTuple .maxBound = maxBound ∷ maxBound
iBoundedBelowOrdering : BoundedBelow Ordering
iBoundedBelowOrdering .minBound = LT
iBoundedAboveOrdering : BoundedAbove Ordering
iBoundedAboveOrdering .maxBound = GT
-- Sanity checks
private
_ : addWord maxBound 1 ≡ minBound
_ = refl
_ : addInt maxBound 1 ≡ minBound
_ = refl
| 27.797753
| 112
| 0.736055
|
9a4aa66b2dc23e0fb01c9f3714a5dee2a7323b3c
| 1,667
|
agda
|
Agda
|
src/StateSizedIO/Object.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 23
|
2016-06-19T12:57:55.000Z
|
2020-10-12T23:15:25.000Z
|
src/StateSizedIO/Object.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | null | null | null |
src/StateSizedIO/Object.agda
|
agda/ooAgda
|
7cc45e0148a4a508d20ed67e791544c30fecd795
|
[
"MIT"
] | 2
|
2018-09-01T15:02:37.000Z
|
2022-03-12T11:41:00.000Z
|
module StateSizedIO.Object where
open import Data.Product
open import Level renaming (zero to lzero; suc to lsuc)
open import StateSizedIO.GUI.BaseStateDependent
-- open import StateSizedIO.Base public
{-
-- This definition was probably moved to StateSizedIO.Base
-- and by accident left here. Delete this.
record Interfaceˢ : Set₁ where
field
Stateˢ : Set
Methodˢ : Stateˢ → Set
Resultˢ : (s : Stateˢ) → (m : Methodˢ s) → Set
nextˢ : (s : Stateˢ) → (m : Methodˢ s) → Resultˢ s m → Stateˢ
open Interfaceˢ public
-}
module _ (I : Interfaceˢ {lzero} {lzero} {lzero})(let S = Stateˢ I) (let M = Methodˢ I)
(let R = Resultˢ I) (let next = nextˢ I) where
-- A simple object just returns for a method the response
-- and the object itself
record Objectˢ (s : S) : Set where
coinductive
field
objectMethod : (m : M s) → Σ[ r ∈ R s m ] Objectˢ (next s m r)
open Objectˢ public
_▹_ : {A : Set } → { B : Set } → A → (A → B) → B
a ▹ f = f a
-- Bisimilation for Objectˢ
module Bisim (I : Interfaceˢ)
(let S = Stateˢ I)
(let M = Methodˢ I)
(let R = Resultˢ I)
(let next = nextˢ I)
(let O = Objectˢ I)
where
mutual
record _≅_ {s : S} (o o' : O s) : Set where
coinductive
field bisimMethod : (m : M s) → objectMethod o m ≡×≅ objectMethod o' m
data _≡×≅_ {s m} : (p p' : Σ[ r ∈ R s m ] O (next s m r)) → Set where
bisim : ∀{r} (let s' = next s m r) {o o' : O s'} (p : o ≅ o')
→ (r , o) ≡×≅ (r , o')
open _≅_ public
refl≅ : ∀{s} (o : O s) → o ≅ o
bisimMethod (refl≅ o) m = bisim (refl≅ (proj₂ (objectMethod o m)))
| 27.783333
| 87
| 0.577085
|
8baa6a469ff8676ceeeadf0525ebca60e405d793
| 379
|
agda
|
Agda
|
Operator/Equals.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Operator/Equals.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Operator/Equals.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Operator.Equals {ℓ ℓₑ} where
open import Data.Boolean
open import Logic
open import Structure.Setoid
open import Type.Properties.Decidable
open import Type
DecidableEquiv : (T : Type{ℓ}) ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Stmt
DecidableEquiv(T) = Decidable(2)(_≡_)
_==_ : ∀{T : Type{ℓ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ ⦃ _ : DecidableEquiv(T) ⦄ → (T → T → Bool)
_==_ = decide(2)(_≡_)
| 27.071429
| 89
| 0.670185
|
032b0674aab4bd51a629655b6c817fa029099c5a
| 1,279
|
agda
|
Agda
|
test/Succeed/Issue1607.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1607.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1607.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-07-10, issue reported by asr
-- {-# OPTIONS -v scope:20 #-}
-- {-# OPTIONS -v scope.createModule:10 #-}
module _ where
module A where
module Y where
module B where
-- FAILS:
module X = A
open X public
-- open A public --WORKS
module C = B
-- On maint and master:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/Syntax/Scope/Monad.hs:107
{-
createModule Issue1607.C
module macro
ScopeInfo
current = Issue1607
context = TopCtx
modules
scope
scope Issue1607
public
modules
A --> [Issue1607.A]
B --> [Issue1607.B]
scope Issue1607.A
public
modules
Y --> [Issue1607.A.Y]
scope Issue1607.A.Y
scope Issue1607.B
public
modules
X --> [Issue1607.B.X]
Y --> [Issue1607.B.X.Y]
scope Issue1607.B.X
public
modules
Y --> [Issue1607.B.X.Y]
scope Issue1607.B.X.Y
scope Issue1607.C
Copying scope Issue1607.B to Issue1607.C
createModule Issue1607.C.X
Copying scope Issue1607.B.X to Issue1607.C.X
createModule Issue1607.C.X.Y
Copying scope Issue1607.B.X.Y to Issue1607.C.X.Y
createModule Issue1607.C.X.Y
Copying scope Issue1607.B.X.Y to Issue1607.C.X.Y
-}
| 21.677966
| 65
| 0.63878
|
4b25a6e04182709a2fedacfcb5ad3922f8b62cc5
| 7,752
|
agda
|
Agda
|
Cubical/Categories/NaturalTransformation/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/NaturalTransformation/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Categories/NaturalTransformation/Base.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.NaturalTransformation.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism renaming (iso to iIso)
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.Commutativity
open import Cubical.Categories.Morphism renaming (isIso to isIsoC)
private
variable
ℓC ℓC' ℓD ℓD' : Level
module _ {C : Precategory ℓC ℓC'} {D : Precategory ℓD ℓD'} where
-- syntax for sequencing in category D
infixl 15 _⋆ᴰ_
private
_⋆ᴰ_ : ∀ {x y z} (f : D [ x , y ]) (g : D [ y , z ]) → D [ x , z ]
f ⋆ᴰ g = f ⋆⟨ D ⟩ g
open Precategory
open Functor
-- type aliases because it gets tedious typing it out all the time
N-ob-Type : (F G : Functor C D) → Type _
N-ob-Type F G = (x : C .ob) → D [(F .F-ob x) , (G .F-ob x)]
N-hom-Type : (F G : Functor C D) → N-ob-Type F G → Type _
N-hom-Type F G ϕ = {x y : C .ob} (f : C [ x , y ]) → (F .F-hom f) ⋆ᴰ (ϕ y) ≡ (ϕ x) ⋆ᴰ (G .F-hom f)
record NatTrans (F G : Functor C D) : Type (ℓ-max (ℓ-max ℓC ℓC') ℓD') where
constructor natTrans
field
-- components of the natural transformation
N-ob : N-ob-Type F G
-- naturality condition
N-hom : N-hom-Type F G N-ob
record NatIso (F G : Functor C D): Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where
field
trans : NatTrans F G
open NatTrans trans
field
nIso : ∀ (x : C .ob) → isIsoC {C = D} (N-ob x)
open isIsoC
-- the three other commuting squares
sqRL : ∀ {x y : C .ob} {f : C [ x , y ]}
→ F ⟪ f ⟫ ≡ (N-ob x) ⋆ᴰ G ⟪ f ⟫ ⋆ᴰ (nIso y) .inv
sqRL {x} {y} {f} = invMoveR (isIso→areInv (nIso y)) (N-hom f)
sqLL : ∀ {x y : C .ob} {f : C [ x , y ]}
→ G ⟪ f ⟫ ⋆ᴰ (nIso y) .inv ≡ (nIso x) .inv ⋆ᴰ F ⟪ f ⟫
sqLL {x} {y} {f} = invMoveL (isIso→areInv (nIso x)) (sym sqRL')
where
sqRL' : F ⟪ f ⟫ ≡ (N-ob x) ⋆ᴰ ( G ⟪ f ⟫ ⋆ᴰ (nIso y) .inv )
sqRL' = sqRL ∙ (D .⋆Assoc _ _ _)
sqLR : ∀ {x y : C .ob} {f : C [ x , y ]}
→ G ⟪ f ⟫ ≡ (nIso x) .inv ⋆ᴰ F ⟪ f ⟫ ⋆ᴰ (N-ob y)
sqLR {x} {y} {f} = invMoveR (symAreInv (isIso→areInv (nIso y))) sqLL
open NatTrans
open NatIso
infix 10 NatTrans
syntax NatTrans F G = F ⇒ G
infix 9 NatIso
syntax NatIso F G = F ≅ᶜ G -- c superscript to indicate that this is in the context of categories
-- component of a natural transformation
infix 30 _⟦_⟧
_⟦_⟧ : ∀ {F G : Functor C D} → (F ⇒ G) → (x : C .ob) → D [(F .F-ob x) , (G .F-ob x)]
_⟦_⟧ = N-ob
idTrans : (F : Functor C D) → NatTrans F F
idTrans F .N-ob x = D .id (F .F-ob x)
idTrans F .N-hom f =
(F .F-hom f) ⋆ᴰ (idTrans F .N-ob _)
≡⟨ D .⋆IdR _ ⟩
F .F-hom f
≡⟨ sym (D .⋆IdL _) ⟩
(D .id (F .F-ob _)) ⋆ᴰ (F .F-hom f)
∎
syntax idTrans F = 1[ F ]
-- vertical sequencing
seqTrans : {F G H : Functor C D} (α : NatTrans F G) (β : NatTrans G H) → NatTrans F H
seqTrans α β .N-ob x = (α .N-ob x) ⋆ᴰ (β .N-ob x)
seqTrans {F} {G} {H} α β .N-hom f =
(F .F-hom f) ⋆ᴰ ((α .N-ob _) ⋆ᴰ (β .N-ob _))
≡⟨ sym (D .⋆Assoc _ _ _) ⟩
((F .F-hom f) ⋆ᴰ (α .N-ob _)) ⋆ᴰ (β .N-ob _)
≡[ i ]⟨ (α .N-hom f i) ⋆ᴰ (β .N-ob _) ⟩
((α .N-ob _) ⋆ᴰ (G .F-hom f)) ⋆ᴰ (β .N-ob _)
≡⟨ D .⋆Assoc _ _ _ ⟩
(α .N-ob _) ⋆ᴰ ((G .F-hom f) ⋆ᴰ (β .N-ob _))
≡[ i ]⟨ (α .N-ob _) ⋆ᴰ (β .N-hom f i) ⟩
(α .N-ob _) ⋆ᴰ ((β .N-ob _) ⋆ᴰ (H .F-hom f))
≡⟨ sym (D .⋆Assoc _ _ _) ⟩
((α .N-ob _) ⋆ᴰ (β .N-ob _)) ⋆ᴰ (H .F-hom f)
∎
compTrans : {F G H : Functor C D} (β : NatTrans G H) (α : NatTrans F G) → NatTrans F H
compTrans β α = seqTrans α β
infixl 8 seqTrans
syntax seqTrans α β = α ●ᵛ β
-- vertically sequence natural transformations whose
-- common functor is not definitional equal
seqTransP : {F G G' H : Functor C D} (p : G ≡ G')
→ (α : NatTrans F G) (β : NatTrans G' H)
→ NatTrans F H
seqTransP {F} {G} {G'} {H} p α β .N-ob x
-- sequence morphisms with non-judgementally equal (co)domain
= seqP {C = D} {p = Gx≡G'x} (α ⟦ x ⟧) (β ⟦ x ⟧)
where
Gx≡G'x : ∀ {x} → G ⟅ x ⟆ ≡ G' ⟅ x ⟆
Gx≡G'x {x} i = F-ob (p i) x
seqTransP {F} {G} {G'} {H} p α β .N-hom {x = x} {y} f
-- compose the two commuting squares
-- 1. α's commuting square
-- 2. β's commuting square, but extended to G since β is only G' ≡> H
= compSq {C = D} (α .N-hom f) βSq
where
-- functor equality implies equality of actions on objects and morphisms
Gx≡G'x : G ⟅ x ⟆ ≡ G' ⟅ x ⟆
Gx≡G'x i = F-ob (p i) x
Gy≡G'y : G ⟅ y ⟆ ≡ G' ⟅ y ⟆
Gy≡G'y i = F-ob (p i) y
Gf≡G'f : PathP (λ i → D [ Gx≡G'x i , Gy≡G'y i ]) (G ⟪ f ⟫) (G' ⟪ f ⟫)
Gf≡G'f i = p i ⟪ f ⟫
-- components of β extended out to Gx and Gy respectively
βx' = subst (λ a → D [ a , H ⟅ x ⟆ ]) (sym Gx≡G'x) (β ⟦ x ⟧)
βy' = subst (λ a → D [ a , H ⟅ y ⟆ ]) (sym Gy≡G'y) (β ⟦ y ⟧)
-- extensions are equal to originals
βy'≡βy : PathP (λ i → D [ Gy≡G'y i , H ⟅ y ⟆ ]) βy' (β ⟦ y ⟧)
βy'≡βy = symP (toPathP {A = λ i → D [ Gy≡G'y (~ i) , H ⟅ y ⟆ ]} refl)
βx≡βx' : PathP (λ i → D [ Gx≡G'x (~ i) , H ⟅ x ⟆ ]) (β ⟦ x ⟧) βx'
βx≡βx' = toPathP refl
-- left wall of square
left : PathP (λ i → D [ Gx≡G'x i , H ⟅ y ⟆ ]) (G ⟪ f ⟫ ⋆⟨ D ⟩ βy') (G' ⟪ f ⟫ ⋆⟨ D ⟩ β ⟦ y ⟧)
left i = Gf≡G'f i ⋆⟨ D ⟩ βy'≡βy i
-- right wall of square
right : PathP (λ i → D [ Gx≡G'x (~ i) , H ⟅ y ⟆ ]) (β ⟦ x ⟧ ⋆⟨ D ⟩ H ⟪ f ⟫) (βx' ⋆⟨ D ⟩ H ⟪ f ⟫)
right i = βx≡βx' i ⋆⟨ D ⟩ refl {x = H ⟪ f ⟫} i
-- putting it all together
βSq : G ⟪ f ⟫ ⋆⟨ D ⟩ βy' ≡ βx' ⋆⟨ D ⟩ H ⟪ f ⟫
βSq i = comp (λ k → D [ Gx≡G'x (~ k) , H ⟅ y ⟆ ])
(λ j → λ { (i = i0) → left (~ j)
; (i = i1) → right j })
(β .N-hom f i)
module _ ⦃ isCatD : isCategory D ⦄ {F G : Functor C D} {α β : NatTrans F G} where
open Precategory
open Functor
open NatTrans
makeNatTransPath : α .N-ob ≡ β .N-ob → α ≡ β
makeNatTransPath p i .N-ob = p i
makeNatTransPath p i .N-hom f = rem i
where
rem : PathP (λ i → (F .F-hom f) ⋆ᴰ (p i _) ≡ (p i _) ⋆ᴰ (G .F-hom f)) (α .N-hom f) (β .N-hom f)
rem = toPathP (isCatD .isSetHom _ _ _ _)
module _ ⦃ isCatD : isCategory D ⦄ {F F' G G' : Functor C D}
{α : NatTrans F G}
{β : NatTrans F' G'} where
open Precategory
open Functor
open NatTrans
makeNatTransPathP : ∀ (p : F ≡ F') (q : G ≡ G')
→ PathP (λ i → (x : C .ob) → D [ (p i) .F-ob x , (q i) .F-ob x ]) (α .N-ob) (β .N-ob)
→ PathP (λ i → NatTrans (p i) (q i)) α β
makeNatTransPathP p q P i .N-ob = P i
makeNatTransPathP p q P i .N-hom f = rem i
where
rem : PathP (λ i → ((p i) .F-hom f) ⋆ᴰ (P i _) ≡ (P i _) ⋆ᴰ ((q i) .F-hom f)) (α .N-hom f) (β .N-hom f)
rem = toPathP (isCatD .isSetHom _ _ _ _)
private
variable
ℓA ℓA' ℓB ℓB' : Level
module _ {B : Precategory ℓB ℓB'} {C : Precategory ℓC ℓC'} {D : Precategory ℓD ℓD'} where
open NatTrans
-- whiskering
-- αF
_∘ˡ_ : ∀ {G H : Functor C D} (α : NatTrans G H) → (F : Functor B C)
→ NatTrans (G ∘F F) (H ∘F F)
(_∘ˡ_ {G} {H} α F) .N-ob x = α ⟦ F ⟅ x ⟆ ⟧
(_∘ˡ_ {G} {H} α F) .N-hom f = (α .N-hom) _
-- Kβ
_∘ʳ_ : ∀ (K : Functor C D) → {G H : Functor B C} (β : NatTrans G H)
→ NatTrans (K ∘F G) (K ∘F H)
(_∘ʳ_ K {G} {H} β) .N-ob x = K ⟪ β ⟦ x ⟧ ⟫
(_∘ʳ_ K {G} {H} β) .N-hom f = preserveCommF {C = C} {D = D} {K} (β .N-hom f)
| 34.918919
| 111
| 0.498194
|
adfac348750e3222e81b4d79b732328414474565
| 210
|
agda
|
Agda
|
Light/Variable/Other.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | 1
|
2019-12-20T21:33:05.000Z
|
2019-12-20T21:33:05.000Z
|
Light/Variable/Other.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
Light/Variable/Other.agda
|
zamfofex/lightlib
|
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
|
[
"0BSD"
] | null | null | null |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Variable.Other {ℓ} (𝕒 : Set ℓ) where
variable a b c d e f g h i j k l m : 𝕒
variable n o p q r s t u v w x y z : 𝕒
| 30
| 79
| 0.647619
|
29271b76de97b633496b0fcb675f73bf18f721a8
| 741
|
agda
|
Agda
|
Cubical/Algebra/AbGroup/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Algebra/AbGroup/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/AbGroup/Properties.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.AbGroup.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.AbGroup.Base
private variable
ℓ : Level
module AbGroupTheory (A'@(A , Ar) : AbGroup ℓ) where
open AbGroupStr Ar
comm-4 : (a b c d : A) → ((a + b) + (c + d) ≡ (a + c) + (b + d))
comm-4 a b c d = ((a + b) + (c + d) ≡⟨ assoc (a + b) c d ⟩
(((a + b) + c) + d) ≡⟨ cong (λ X → X + d) (sym (assoc a b c)) ⟩
((a + (b + c)) + d) ≡⟨ cong (λ X → (a + X) + d) (comm b c) ⟩
((a + (c + b)) + d) ≡⟨ cong (λ X → X + d) (assoc a c b) ⟩
(((a + c) + b) + d) ≡⟨ sym (assoc (a + c) b d) ⟩
((a + c) + (b + d)) ∎)
| 32.217391
| 82
| 0.42915
|
583c32639b0dcfbf0a42b44c534e4876b4be595b
| 8,428
|
agda
|
Agda
|
src/LibraBFT/Impl/Consensus/BlockStorage/BlockTree.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Consensus/BlockStorage/BlockTree.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Consensus/BlockStorage/BlockTree.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
import LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock as ExecutedBlock
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.Impl.OBM.Prelude
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.ByteString
open import Util.Hash
import Util.KVMap as Map
open import Util.PKCS
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
module LibraBFT.Impl.Consensus.BlockStorage.BlockTree where
postulate -- TODO-2: implement linkableBlockNew
linkableBlockNew : ExecutedBlock → LinkableBlock
module addChild (lb : LinkableBlock) (hv : HashValue) where
VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL
VariantFor EL = EL ErrLog LinkableBlock
postulate -- TODO-2: implement addChild
step₀ : VariantFor EitherD
-- addChild : LinkableBlock → HashValue → Either ErrLog LinkableBlock
-- addChild lb hv =
-- if Set.member hv (lb ^∙ lbChildren)
-- then Left fakeErr
-- else Right (lb & lbChildren %~ Set.insert hv)
E : VariantFor Either
E = toEither step₀
D : VariantFor EitherD
D = fromEither E
addChild = addChild.D
new : ExecutedBlock → QuorumCert → QuorumCert → Usize → Maybe TimeoutCertificate
→ Either ErrLog BlockTree
new root0 rootQuorumCert rootLedgerInfo maxPruned mHighestTimeoutCert = do
lcheck ((root0 ^∙ ebId) == (rootLedgerInfo ^∙ qcCommitInfo ∙ biId))
("BlockTree" ∷ "newBlockTree" ∷ "inconsistent root and ledger info" ∷ [])
let idToBlock = Map.insert (root0 ^∙ ebId) (linkableBlockNew root0) Map.empty
idToQuorumCert = Map.insert (rootQuorumCert ^∙ qcCertifiedBlock ∙ biId) rootQuorumCert Map.empty
prunedBlockIds = vdNew -- TODO
in pure $ mkBlockTree
idToBlock
(root0 ^∙ ebId) -- _btRootId
(root0 ^∙ ebId) -- _btHighestCertifiedBlockId
rootQuorumCert -- _btHighestQuorumCert
mHighestTimeoutCert
rootLedgerInfo -- _btHighestCommitCert
idToQuorumCert
prunedBlockIds
maxPruned
replaceTimeoutCertM : TimeoutCertificate → LBFT Unit
replaceTimeoutCertM tc = do
lBlockStore ∙ bsInner ∙ btHighestTimeoutCert ?= tc
logInfo fakeInfo -- lTO (InfoUpdateHighestTimeoutCert (Just tc))
------------------------------------------------------------------------------
module insertBlockE (block : ExecutedBlock)(bt : BlockTree) where
VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL
VariantFor EL = EL ErrLog (BlockTree × ExecutedBlock)
-- TODO: break into smaller steps to take advantage of the EitherD-weakestpre machinery to prove
-- the contract.
step₀ = do
let blockId = block ^∙ ebId
caseMD btGetBlock blockId bt of λ where
(just existingBlock) → pure (bt , existingBlock)
nothing → caseMD btGetLinkableBlock (block ^∙ ebParentId) bt of λ where
nothing → LeftD fakeErr
(just parentBlock) → (do
parentBlock' ← addChild parentBlock blockId
let bt' = bt & btIdToBlock ∙~ Map.kvm-insert-Haskell (block ^∙ ebParentId) parentBlock' (bt ^∙ btIdToBlock)
pure ( (bt' & btIdToBlock ∙~ Map.kvm-insert-Haskell blockId (LinkableBlock∙new block) (bt' ^∙ btIdToBlock))
, block))
E : VariantFor Either
E = toEither step₀
D : VariantFor EitherD
D = fromEither E
-- We make the EitherD variant the default, because the only call in code
-- modeled is in EitherD, so it's nice to keep it exactly like the Haskell
-- code being modeled. However, insertBlockESpec.Contract and the proof of
-- executeAndInsertBlockESpec.contract' (which was written before EitherD
-- support was developed) both want an Either variant, so they use
-- insertBlockE.E. This demonstrates the flexibility of the VariantOf
-- approach, providing variants for any EitherLike, and means to convert
-- between them easily.
insertBlockE = insertBlockE.D
------------------------------------------------------------------------------
module insertQuorumCertE (qc : QuorumCert) (bt0 : BlockTree) where
VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL
VariantFor EL = EL ErrLog (BlockTree × List InfoLog)
step₁ : HashValue → VariantFor EitherD
step₂ : HashValue → ExecutedBlock → VariantFor EitherD
step₃ : HashValue → ExecutedBlock → ExecutedBlock → VariantFor EitherD
continue1 : BlockTree → HashValue → ExecutedBlock → List InfoLog → (BlockTree × List InfoLog)
continue2 : BlockTree → List InfoLog → (BlockTree × List InfoLog)
here' : List String → List String
here' t = "BlockTree" ∷ "insertQuorumCert" ∷ t
blockId = qc ^∙ qcCertifiedBlock ∙ biId
safetyInvariant = forM_ (Map.elems (bt0 ^∙ btIdToQuorumCert)) $ \x →
lcheck ( (x ^∙ qcLedgerInfo ∙ liwsLedgerInfo ∙ liConsensusDataHash
== qc ^∙ qcLedgerInfo ∙ liwsLedgerInfo ∙ liConsensusDataHash)
∨ (x ^∙ qcCertifiedBlock ∙ biRound
/= qc ^∙ qcCertifiedBlock ∙ biRound))
(here' ("failed check" ∷ "existing qc == qc || existing qc.round /= qc.round" ∷ []))
step₀ =
case safetyInvariant of λ where
(Left e) → LeftD e
(Right unit) → step₁ blockId
step₁ blockId =
maybeSD (btGetBlock blockId bt0) (LeftD fakeErr) $ step₂ blockId
step₂ blockId block =
maybeSD (bt0 ^∙ btHighestCertifiedBlock) (LeftD fakeErr) $ step₃ blockId block
step₃ blockId block hcb =
ifD ((block ^∙ ebRound) >? (hcb ^∙ ebRound))
then
(let bt = bt0 & btHighestCertifiedBlockId ∙~ block ^∙ ebId
& btHighestQuorumCert ∙~ qc
info = (fakeInfo ∷ [])
in pure (continue1 bt blockId block info))
else pure (continue1 bt0 blockId block [])
continue1 bt blockId block info =
continue2 ( bt & btIdToQuorumCert ∙~ lookupOrInsert blockId qc (bt ^∙ btIdToQuorumCert))
( (fakeInfo ∷ info) ++ (if ExecutedBlock.isNilBlock block then fakeInfo ∷ [] else [] ))
continue2 bt info =
if-dec (bt ^∙ btHighestCommitCert ∙ qcCommitInfo ∙ biRound) <? (qc ^∙ qcCommitInfo ∙ biRound)
then ((bt & btHighestCommitCert ∙~ qc) , info)
else (bt , info)
E : VariantFor Either
E = toEither step₀
D : VariantFor EitherD
D = fromEither E
insertQuorumCertE = insertQuorumCertE.E
insertQuorumCertM : QuorumCert → LBFT Unit
insertQuorumCertM qc = do
bt ← use lBlockTree
case insertQuorumCertE qc bt of λ where
(Left e) → logErr e
(Right (bt' , info)) → do
forM_ info logInfo
lBlockTree ∙= bt'
------------------------------------------------------------------------------
module pathFromRoot (blockId : HashValue) (blockTree : BlockTree) where
-- TODO-1 PROVE IT TERMINATES
{-# TERMINATING #-}
loop : ExecutedBlock → HashValue → List ExecutedBlock → Maybe (HashValue × List ExecutedBlock)
loop btr curBlockId res = case btGetBlock curBlockId blockTree of λ where
(just block) → if-dec (block ^∙ ebRound) ≤?ℕ (btr ^∙ ebRound)
then just (curBlockId , res)
else loop btr (block ^∙ ebParentId) (block ∷ res)
nothing → nothing
pathFromRoot : HashValue → BlockTree → Either ErrLog (List ExecutedBlock)
pathFromRoot blockId blockTree =
maybeS (blockTree ^∙ btRoot) (Left fakeErr) $ λ btr →
maybeS (loop btr blockId []) (pure []) (pure ∘ continue)
where
open pathFromRoot blockId blockTree
continue : (HashValue × List ExecutedBlock) → List ExecutedBlock
continue (curBlockId , res) =
if not (curBlockId /= (blockTree ^∙ btRootId))
then []
else res
------------------------------------------------------------------------------
getAllBlockIdM : LBFT (List HashValue)
getAllBlockIdM = Map.kvm-keys <$> use (lBlockTree ∙ btIdToBlock)
| 39.568075
| 118
| 0.652468
|
38761c5a652736a061293ce3374bc6debd26df2a
| 5,409
|
agda
|
Agda
|
core/lib/types/Circle.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Circle.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | null | null | null |
core/lib/types/Circle.agda
|
mikeshulman/HoTT-Agda
|
e7d663b63d89f380ab772ecb8d51c38c26952dbb
|
[
"MIT"
] | 1
|
2018-12-26T21:31:57.000Z
|
2018-12-26T21:31:57.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NConnected
open import lib.NType2
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Truncation
open import lib.types.Unit
open import lib.types.Bool
open import lib.types.Suspension
open import lib.types.IteratedSuspension
module lib.types.Circle where
{-
Idea :
data S¹ : Type₀ where
base : S¹
loop : base == base
I’m using Dan Licata’s trick to have a higher inductive type with definitional
reduction rule for [base]
-}
{-
favonia (2016/05): Now [Circle] is defined as [Sphere 1].
-}
module _ where
-- (already defined in IteratedSuspension.agda)
-- S¹ : Type₀
-- S¹ = Sphere 1
base : S¹
base = north
loop : base == base
loop = merid true ∙' ! (merid false)
module S¹Elim {i} {P : S¹ → Type i} (base* : P base)
(loop* : base* == base* [ P ↓ loop ]) where
private
north* = base*
south* = transport P (merid false) base*
merid*-general :
∀ {x : S¹} (p q : base == x) (loop* : base* == base* [ P ↓ p ∙' ! q ]) (b : Bool)
→ base* == transport P q base* [ P ↓ if b then p else q ]
merid*-general p idp loop* true = loop*
merid*-general p idp loop* false = idp
merid* : ∀ (b : Bool) → north* == south* [ P ↓ merid b ]
merid* true = merid*-general (merid true) (merid false) loop* true
merid* false = merid*-general (merid true) (merid false) loop* false
module SE = SuspElim north* south* merid*
f : Π S¹ P
f = SE.f
private
merid*-general-lemma :
∀ {x : S¹} (p q : base == x) (loop* : base* == base* [ P ↓ p ∙' ! q ])
→ merid*-general p q loop* true ▹ !ᵈ (merid*-general p q loop* false) == loop*
merid*-general-lemma p idp loop* = ▹idp _
loop-β : apd f loop == loop*
loop-β =
apd f loop
=⟨ apd-∙' f (merid true) (! (merid false)) ⟩
apd f (merid true) ▹ apd f (! (merid false))
=⟨ apd-! f (merid false) |in-ctx apd f (merid true) ▹_ ⟩
apd f (merid true) ▹ !ᵈ (apd f (merid false))
=⟨ SE.merid-β true |in-ctx _▹ !ᵈ (apd f (merid false)) ⟩
merid* true ▹ !ᵈ (apd f (merid false))
=⟨ SE.merid-β false |in-ctx (λ p → merid* true ▹ !ᵈ p) ⟩
merid* true ▹ !ᵈ (merid* false)
=⟨ merid*-general-lemma (merid true) (merid false) loop* ⟩
loop*
=∎
open S¹Elim public using () renaming (f to S¹-elim)
module S¹Rec {i} {A : Type i} (base* : A) (loop* : base* == base*) where
private
module M = S¹Elim base* (↓-cst-in loop*)
f : S¹ → A
f = M.f
loop-β : ap f loop == loop*
loop-β = apd=cst-in {f = f} M.loop-β
open S¹Rec public using () renaming (f to S¹-rec)
S¹-rec-η : ∀ {i} {A : Type i} (f : S¹ → A)
→ ∀ x → S¹-rec (f base) (ap f loop) x == f x
S¹-rec-η f = S¹-elim idp (↓-='-in' $ ! $ S¹Rec.loop-β (f base) (ap f loop))
module S¹RecType {i} (A : Type i) (e : A ≃ A) where
open S¹Rec A (ua e) public
coe-loop-β : (a : A) → coe (ap f loop) a == –> e a
coe-loop-β a =
coe (ap f loop) a =⟨ loop-β |in-ctx (λ u → coe u a) ⟩
coe (ua e) a =⟨ coe-β e a ⟩
–> e a =∎
coe!-loop-β : (a : A) → coe! (ap f loop) a == <– e a
coe!-loop-β a =
coe! (ap f loop) a =⟨ loop-β |in-ctx (λ u → coe! u a) ⟩
coe! (ua e) a =⟨ coe!-β e a ⟩
<– e a =∎
↓-loop-out : {a a' : A} → a == a' [ f ↓ loop ] → –> e a == a'
↓-loop-out {a} {a'} p =
–> e a =⟨ ! (coe-loop-β a) ⟩
coe (ap f loop) a =⟨ to-transp p ⟩
a' =∎
import lib.types.Generic1HIT as Generic1HIT
module S¹G = Generic1HIT Unit Unit (idf _) (idf _)
module P = S¹G.RecType (cst A) (cst e)
private
generic-S¹ : Σ S¹ f == Σ S¹G.T P.f
generic-S¹ = eqv-tot where
module To = S¹Rec (S¹G.cc tt) (S¹G.pp tt)
to = To.f
module From = S¹G.Rec (cst base) (cst loop)
from : S¹G.T → S¹
from = From.f
abstract
to-from : (x : S¹G.T) → to (from x) == x
to-from = S¹G.elim (λ _ → idp) (λ _ → ↓-∘=idf-in' to from
(ap to (ap from (S¹G.pp tt)) =⟨ From.pp-β tt |in-ctx ap to ⟩
ap to loop =⟨ To.loop-β ⟩
S¹G.pp tt =∎))
from-to : (x : S¹) → from (to x) == x
from-to = S¹-elim idp (↓-∘=idf-in' from to
(ap from (ap to loop) =⟨ To.loop-β |in-ctx ap from ⟩
ap from (S¹G.pp tt) =⟨ From.pp-β tt ⟩
loop =∎))
eqv : S¹ ≃ S¹G.T
eqv = equiv to from to-from from-to
eqv-fib : f == P.f [ (λ X → (X → Type _)) ↓ ua eqv ]
eqv-fib =
↓-app→cst-in (λ {t} p → S¹-elim {P = λ t → f t == P.f (–> eqv t)} idp
(↓-='-in'
(ap (P.f ∘ (–> eqv)) loop =⟨ ap-∘ P.f to loop ⟩
ap P.f (ap to loop) =⟨ To.loop-β |in-ctx ap P.f ⟩
ap P.f (S¹G.pp tt) =⟨ P.pp-β tt ⟩
ua e =⟨ ! loop-β ⟩
ap f loop =∎))
t ∙ ap P.f (↓-idf-ua-out eqv p))
eqv-tot : Σ S¹ f == Σ S¹G.T P.f
eqv-tot = ap (uncurry Σ) (pair= (ua eqv) eqv-fib)
import lib.types.Flattening as Flattening
module FlatteningS¹ = Flattening
Unit Unit (idf _) (idf _) (cst A) (cst e)
open FlatteningS¹ public hiding (flattening-equiv; module P)
flattening-S¹ : Σ S¹ f == Wt
flattening-S¹ = generic-S¹ ∙ ua FlatteningS¹.flattening-equiv
S¹-conn : is-connected 0 S¹
S¹-conn = Sphere-conn 1
| 30.05
| 90
| 0.524866
|
2273b1cd8b9638cc22ea2ad88de02a6b3353e4b5
| 373
|
agda
|
Agda
|
test/agda-ocaml/Golden/Index.agda
|
agda/agda-ocaml
|
e38b699870ba638221828b07b12948d70a1bdaec
|
[
"BSD-3-Clause"
] | 48
|
2017-03-29T14:19:31.000Z
|
2021-08-15T09:08:14.000Z
|
test/agda-ocaml/Golden/Index.agda
|
agda/agda-ocaml
|
e38b699870ba638221828b07b12948d70a1bdaec
|
[
"BSD-3-Clause"
] | 8
|
2017-03-29T13:37:52.000Z
|
2018-11-05T21:28:57.000Z
|
test/agda-ocaml/Golden/Index.agda
|
agda/agda-ocaml
|
e38b699870ba638221828b07b12948d70a1bdaec
|
[
"BSD-3-Clause"
] | 7
|
2018-05-24T10:45:59.000Z
|
2022-03-12T11:39:48.000Z
|
module Golden.Index where
open import Agda.Builtin.Nat
open import Agda.Builtin.List
open import Agda.Builtin.Bool
lst : List Nat
lst = 1 ∷ 2 ∷ []
atDef : ∀ {a : Set} → a → List a -> Nat -> a
atDef def (x ∷ l) zero = x
atDef def (x ∷ l) (suc ix) = atDef def l ix
atDef def _ _ = def
l0 : Nat
l0 = atDef 0 lst 0
l1 : Nat
l1 = atDef 0 lst 1
l2 : Nat
l2 = atDef 0 lst 2
| 16.217391
| 44
| 0.630027
|
9a0346ae9e46bcfa9bfd845f22666d6e8932eada
| 124
|
agda
|
Agda
|
test/Compiler/with-stdlib/HelloWorld.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Compiler/with-stdlib/HelloWorld.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Compiler/with-stdlib/HelloWorld.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
module HelloWorld where
open import IO
open import Data.String
open import Data.Unit
main = run (putStrLn "Hello World!")
| 15.5
| 36
| 0.774194
|
c7b79062b5d7e1738eafaff0eb91002663bf2cac
| 3,975
|
agda
|
Agda
|
test/succeed/SizedCoinductiveRecords.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/SizedCoinductiveRecords.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/succeed/SizedCoinductiveRecords.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
{-# OPTIONS --copatterns --sized-types --experimental-irrelevance #-}
-- {-# OPTIONS --show-implicit --show-irrelevant #-}
-- {-# OPTIONS -v tc.polarity:10 -v tc.pos:15 -v tc.size.solve:100 #-}
module SizedCoinductiveRecords where
open import Common.Size
postulate
Size< : ..(_ : Size) → Set
{-# BUILTIN SIZELT Size< #-}
{- THIS WOULD BE A BETTER TYPING FOR sizeSuc, but it requires builtin Size<
sizeSuc : (i : Size) → Size< (↑ (↑ i))
sizeSuc i = ↑ i
-}
-- Subtyping for Size<
emb< : {i : Size} → Size< i → Size
emb< {i} j = j
-- Use Size< hypotheses
data Empty : {i : Size} → Set where
empty : {i : Size} → Empty {i} → Empty {↑ i}
subEmpty : {i : Size}{j : Size< i} → Empty {j} → Empty {i}
subEmpty x = x
-- SHOULD FAIL:
-- fail : {i : Size}{j : Size< i} → Empty {i} → Empty {j}
-- fail x = x
-- Covariance for Size<
co : {i : Size}{j : Size< i} → Size< j → Size< i
co k = k
-- Contravariance for bounded quantification
Bounded : Size → Set
Bounded i = (j : Size< i) → Empty {j}
contra : {i : Size}{j : Size< i} → Bounded i → Bounded j
contra k = k
-- sized naturals
data Nat {i : Size} : Set where
zero : Nat
suc : {j : Size< i} → Nat {j} → Nat
-- polarity of successor
data Bool : Set where
true false : Bool
-- a natural number
one : Nat
one = suc {i = ∞} zero
mySuc : {i : Size} → Nat {i} → Nat {↑ i}
mySuc x = suc x
pred : {i : Size} → Nat {↑ i} → Nat {i}
pred zero = zero
pred (suc n) = n
shift : {i : Size} → (Nat → Nat {↑ i}) → Nat → Nat {i}
shift f n = pred (f (suc n))
{- Does not type check
loop : {i : Size} → Nat {i} → (Nat → Nat {i}) → Set
loop (suc n) f = loop n (shift f)
loop zero = Nat
-}
data ⊥ : Set where
record ⊤ : Set where
mono : {i : Size}{j : Size< i} → Nat {j} → Nat {i}
mono n = n
id : {i : Size} → Nat {i} → Nat {i}
id (zero) = zero
id (suc n) = suc (id n)
monus : {i : Size} → Nat {i} → Nat → Nat {i}
monus x zero = x
monus zero y = zero
monus (suc x) (suc y) = monus x y
div : {i : Size} → Nat {i} → Nat → Nat {i}
div zero y = zero
div (suc x) y = suc (div (monus x y) y)
postulate _∪_ : {i : Size} → Size< i → Size< i → Size< i
{-
max : {i : Size} → Nat {i} → Nat {i} → Nat {i}
max zero n = n
max m zero = m
max {i} (suc {j = j} m) (suc {j = k} n) = suc {j = j ∪ k} (max {j ∪ k} m n)
-}
-- omega inst
{- DOES NOT MAKE SENSE:
omegaBad' : (F : Size → Set) (i : Size) (j : Size< i)
(f : (k : Size< (↑ j)) → F k) → F j
omegaBad' F i j f = f j
-}
-- fix
A : Size → Set
A i = Nat {i} → Nat
{-# NO_TERMINATION_CHECK #-}
fix : (f : (i : Size) → ((j : Size< i) → A j) → A i) → (i : Size) → A i
fix f i zero = zero
fix f i (suc {j} n) = f i (fix f) (suc n)
-- forever : {i : Size} → ({j : Size< i} → Nat {i} → Nat {j}) → Nat {i} → ⊥
-- forever {i} f n = forever f (f {{!!}} n)
-- sized streams
module STREAM where
record Stream (A : Set) {i : Size} : Set where
coinductive
constructor _∷_
field
head : A
tail : {j : Size< i} → Stream A {j}
open Stream
map : {A B : Set}(f : A → B){i : Size} → Stream A {i} → Stream B {i}
head (map f s) = f (head s)
tail (map f s) = map f (tail s)
-- stream antitone
anti : {A : Set}{i : Size}{j : Size< i} → Stream A {i} → Stream A {j}
anti s = s
anti' : {A : Set}{i : Size}{j : Size< i} → (Stream A {j} → A) → (Stream A {i} → A)
anti' f = f
-- Spanning tree
data List (A : Set) {i : Size} : Set where
[] : List A
_∷_ : {j : Size< i}(x : A)(xs : List A {j}) → List A
map : {A B : Set}(f : A → B){i : Size} → List A {i} → List B {i}
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
module Graph (I : Set)(adj : I → List I) where
record Span {i : Size} : Set where
coinductive
constructor span
field
root : I
nodes : {j : Size< i} → List (Span {j})
open Span
{-# NO_TERMINATION_CHECK #-}
tree : {i : Size} → I → Span {i}
root (tree root) = root
nodes (tree root) = map (tree) (adj root)
-- nodes (tree root) = λ {j} → map (tree {j}) (adj root)
| 22.331461
| 84
| 0.530314
|
9ac3c9398dfb681577e7512e2f533586aaeae05c
| 522
|
agda
|
Agda
|
test/Succeed/RewritingBlocked.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/RewritingBlocked.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/RewritingBlocked.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
{-# OPTIONS --rewriting --confluence-check #-}
-- {-# OPTIONS -v rewriting:100 -v tc.conv.atom:30 -v tc.inj.use:30 #-}
open import Common.Equality
{-# BUILTIN REWRITE _≡_ #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
_+_ : Nat → Nat → Nat
zero + n = n
(suc m) + n = suc (m + n)
postulate
plus-zero : ∀ x → (x + zero) ≡ x
{-# REWRITE plus-zero #-}
mutual
secret-number : Nat
secret-number = _
test : ∀ x → (x + secret-number) ≡ x
test x = refl
reveal : secret-number ≡ zero
reveal = refl
| 16.83871
| 71
| 0.586207
|
130caa516b59267666f27e043625c5499b650efe
| 1,063
|
agda
|
Agda
|
Cubical/Relation/Binary/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
Cubical/Relation/Binary/Base.agda
|
kiana-S/univalent-foundations
|
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function using (_on_)
open import Cubical.Foundations.HLevels
open import Cubical.Classes using (Cast; [_]) public
private
variable
a b ℓ : Level
A : Type a
B : Type b
RawREL : Type a → Type b → (ℓ : Level) → Type _
RawREL A B ℓ = A → B → Type ℓ
RawRel : Type a → (ℓ : Level) → Type _
RawRel A ℓ = RawREL A A ℓ
REL : Type a → Type b → (ℓ : Level) → Type _
REL A B ℓ = A → B → hProp ℓ
Rel : Type a → (ℓ : Level) → Type _
Rel A ℓ = REL A A ℓ
isPropValued : RawREL A B ℓ → Type _
isPropValued R = ∀ a b → isProp (R a b)
instance
RelCast : Cast (REL A B ℓ) (RawREL A B ℓ)
RelCast = record { cast = λ R a b → R a b .fst }
isProp[_] : (R : REL A B ℓ) → isPropValued [ R ]
isProp[ R ] a b = R a b .snd
fromRaw : (R : RawREL A B ℓ) → isPropValued R → REL A B ℓ
fromRaw R isPropR a b .fst = R a b
fromRaw R isPropR a b .snd = isPropR a b
| 23.108696
| 57
| 0.638758
|
39ba9767b51f470e9fa6ca1011c57e205c0d0621
| 1,869
|
agda
|
Agda
|
src/Partiality-monad/Inductive/Monotone.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | 2
|
2020-05-21T22:59:18.000Z
|
2020-07-03T08:56:08.000Z
|
src/Partiality-monad/Inductive/Monotone.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
src/Partiality-monad/Inductive/Monotone.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Monotone functions
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Partiality-monad.Inductive.Monotone where
open import Equality.Propositional
open import Prelude
open import Bijection equality-with-J using (_↔_)
import Partiality-algebra.Monotone as M
open import Partiality-monad.Inductive
-- Definition of monotone functions.
[_⊥→_⊥]⊑ : ∀ {a b} → Type a → Type b → Type (a ⊔ b)
[ A ⊥→ B ⊥]⊑ = M.[ partiality-algebra A ⟶ partiality-algebra B ]⊑
module [_⊥→_⊥]⊑ {a b} {A : Type a} {B : Type b} (f : [ A ⊥→ B ⊥]⊑) =
M.[_⟶_]⊑ f
open [_⊥→_⊥]⊑
-- Identity.
id⊑ : ∀ {a} {A : Type a} → [ A ⊥→ A ⊥]⊑
id⊑ = M.id⊑
-- Composition.
infixr 40 _∘⊑_
_∘⊑_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
[ B ⊥→ C ⊥]⊑ → [ A ⊥→ B ⊥]⊑ → [ A ⊥→ C ⊥]⊑
_∘⊑_ = M._∘⊑_
-- Equality characterisation lemma for monotone functions.
equality-characterisation-monotone :
∀ {a b} {A : Type a} {B : Type b} {f g : [ A ⊥→ B ⊥]⊑} →
(∀ x → function f x ≡ function g x) ↔ f ≡ g
equality-characterisation-monotone =
M.equality-characterisation-monotone
-- Composition is associative.
∘⊑-assoc :
∀ {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d}
(f : [ C ⊥→ D ⊥]⊑) (g : [ B ⊥→ C ⊥]⊑) {h : [ A ⊥→ B ⊥]⊑} →
f ∘⊑ (g ∘⊑ h) ≡ (f ∘⊑ g) ∘⊑ h
∘⊑-assoc = M.∘⊑-assoc
module _ {a b} {A : Type a} {B : Type b} where
-- If a monotone function is applied to an increasing sequence,
-- then the result is another increasing sequence.
[_$_]-inc :
[ A ⊥→ B ⊥]⊑ → Increasing-sequence A → Increasing-sequence B
[_$_]-inc = M.[_$_]-inc
-- A lemma relating monotone functions and least upper bounds.
⨆$⊑$⨆ : (f : [ A ⊥→ B ⊥]⊑) →
∀ s → ⨆ [ f $ s ]-inc ⊑ function f (⨆ s)
⨆$⊑$⨆ = M.⨆$⊑$⨆
| 26.7
| 72
| 0.509898
|
1eff43bbca0eee3788012cd069780f446157379a
| 891
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Closure/Transitive/WithK.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Closure/Transitive/WithK.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Closure/Transitive/WithK.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some code related to transitive closures that relies on the K rule
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Relation.Binary.Construct.Closure.Transitive.WithK where
open import Function
open import Relation.Binary
open import Relation.Binary.Construct.Closure.Transitive
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
module _ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} where
∼⁺⟨⟩-injectiveˡ : ∀ {x y z} {p r : x [ _∼_ ]⁺ y} {q s} →
(x [ _∼_ ]⁺ z ∋ x ∼⁺⟨ p ⟩ q) ≡ (x ∼⁺⟨ r ⟩ s) → p ≡ r
∼⁺⟨⟩-injectiveˡ refl = refl
∼⁺⟨⟩-injectiveʳ : ∀ {x y z} {p r : x [ _∼_ ]⁺ y} {q s} →
(x [ _∼_ ]⁺ z ∋ x ∼⁺⟨ p ⟩ q) ≡ (x ∼⁺⟨ r ⟩ s) → q ≡ s
∼⁺⟨⟩-injectiveʳ refl = refl
| 35.64
| 72
| 0.476992
|
4bb75b4d076fe4863b3a86e85da3d6a465d6643e
| 51,941
|
agda
|
Agda
|
src/Free-variables.agda
|
nad/chi
|
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
|
[
"MIT"
] | 2
|
2020-05-21T22:58:07.000Z
|
2020-10-20T16:27:00.000Z
|
src/Free-variables.agda
|
nad/chi
|
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
|
[
"MIT"
] | 1
|
2020-05-21T23:29:54.000Z
|
2020-06-08T11:08:25.000Z
|
src/Free-variables.agda
|
nad/chi
|
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Definitions of "free in" and "closed", along with some properties
------------------------------------------------------------------------
open import Atom
module Free-variables (atoms : χ-atoms) where
open import Dec
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (const; swap)
open import Bag-equivalence equality-with-J as B using (_∈_)
open import Bijection equality-with-J as Bijection using (_↔_)
import Erased.Cubical equality-with-paths as E
open import Equivalence equality-with-J as Eq using (_≃_)
open import Finite-subset.Listed equality-with-paths as S
using (Finite-subset-of)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths as T
using (∥_∥)
open import List equality-with-J using (_++_; foldr)
open import Chi atoms
open import Propositional atoms
open import Substitution atoms
open import Values atoms
open χ-atoms atoms
private
variable
A : Type
bs : List Br
c c′ : Const
e e₁ e₂ e′ e″ : Exp
es : List Exp
x y : Var
xs xs′ : A
private
-- Two variants of V._≟_.
_≟V₁_ : (x y : Var) → Dec T.∥ x ≡ y ∥
_≟V₁_ = T.decidable→decidable-∥∥ V._≟_
_≟V₂_ : (x y : Var) → E.Dec-Erased T.∥ x ≡ y ∥
x ≟V₂ y = E.Dec→Dec-Erased (x ≟V₁ y)
------------------------------------------------------------------------
-- Definitions
-- Free variables.
infix 4 _∈FV_
data _∈FV_ (x : Var) : Exp → Type where
apply-left : ∀ {e₁ e₂} → x ∈FV e₁ → x ∈FV apply e₁ e₂
apply-right : ∀ {e₁ e₂} → x ∈FV e₂ → x ∈FV apply e₁ e₂
lambda : ∀ {y e} → x ≢ y → x ∈FV e → x ∈FV lambda y e
case-head : ∀ {e bs} → x ∈FV e → x ∈FV case e bs
case-body : ∀ {e bs c xs e′} →
x ∈FV e′ → branch c xs e′ ∈ bs → ¬ x ∈ xs →
x ∈FV case e bs
rec : ∀ {y e} → x ≢ y → x ∈FV e → x ∈FV rec y e
var : ∀ {y} → x ≡ y → x ∈FV var y
const : ∀ {c es e} → x ∈FV e → e ∈ es → x ∈FV const c es
-- Closed, except that the given variables may occur.
Closed′ : List Var → Exp → Type
Closed′ xs e = ∀ x → ¬ x ∈ xs → ¬ x ∈FV e
-- The property of being closed.
Closed : Exp → Type
Closed = Closed′ []
-- Closed expressions.
Closed-exp : Type
Closed-exp = ∃ Closed
------------------------------------------------------------------------
-- Inversion lemmas for _∈_
∈apply : (x ∈FV apply e₁ e₂) ≃ (x ∈FV e₁ ⊎ x ∈FV e₂)
∈apply = Eq.↔→≃
(λ { (apply-left x∈) → inj₁ x∈
; (apply-right x∈) → inj₂ x∈
})
[ apply-left , apply-right ]
[ (λ _ → refl) , (λ _ → refl) ]
(λ { (apply-left _) → refl
; (apply-right _) → refl
})
∈lambda : (x ∈FV lambda y e) ≃ (x ≢ y × x ∈FV e)
∈lambda = Eq.↔→≃
(λ { (lambda x≢y x∈e) → x≢y , x∈e })
(uncurry lambda)
(λ _ → refl)
(λ { (lambda _ _) → refl })
∈case :
(x ∈FV case e bs) ≃
(x ∈FV e ⊎
∃ λ c → ∃ λ xs → ∃ λ e′ → x ∈FV e′ × branch c xs e′ ∈ bs × ¬ x ∈ xs)
∈case = Eq.↔→≃
(λ { (case-head x∈) → inj₁ x∈
; (case-body x∈ b∈ x∉) → inj₂ (_ , _ , _ , x∈ , b∈ , x∉)
})
[ case-head , (λ (_ , _ , _ , x∈ , b∈ , x∉) → case-body x∈ b∈ x∉) ]
[ (λ _ → refl) , (λ _ → refl) ]
(λ { (case-head _) → refl
; (case-body _ _ _) → refl
})
∈rec : (x ∈FV rec y e) ≃ (x ≢ y × x ∈FV e)
∈rec = Eq.↔→≃
(λ { (rec x≢y x∈e) → x≢y , x∈e })
(uncurry rec)
(λ _ → refl)
(λ { (rec _ _) → refl })
∈var : (x ∈FV var y) ≃ (x ≡ y)
∈var = Eq.↔→≃
(λ { (var x≡y) → x≡y })
var
(λ _ → refl)
(λ { (var _) → refl })
∈const : (x ∈FV const c es) ≃ (∃ λ e → x ∈FV e × e ∈ es)
∈const = Eq.↔→≃
(λ { (const ∈e ∈es) → _ , ∈e , ∈es })
(λ (_ , ∈e , ∈es) → const ∈e ∈es)
(λ _ → refl)
(λ { (const _ _) → refl })
------------------------------------------------------------------------
-- Characterisation lemmas for Closed′
Closed′-apply≃ :
Closed′ xs (apply e₁ e₂) ≃ (Closed′ xs e₁ × Closed′ xs e₂)
Closed′-apply≃ {xs = xs} {e₁ = e₁} {e₂ = e₂} =
Closed′ xs (apply e₁ e₂) ↔⟨⟩
(∀ x → ¬ x ∈ xs → ¬ x ∈FV apply e₁ e₂) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈apply) ⟩
(∀ x → ¬ x ∈ xs → ¬ (x ∈FV e₁ ⊎ x ∈FV e₂)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬⊎↔¬×¬ ext) ⟩
(∀ x → ¬ x ∈ xs → (¬ x ∈FV e₁ × ¬ x ∈FV e₂)) ↔⟨ (∀-cong ext λ _ → ΠΣ-comm) ⟩
(∀ x → (¬ x ∈ xs → ¬ x ∈FV e₁) × (¬ x ∈ xs → ¬ x ∈FV e₂)) ↔⟨ ΠΣ-comm ⟩
(∀ x → ¬ x ∈ xs → ¬ x ∈FV e₁) × (∀ x → ¬ x ∈ xs → ¬ x ∈FV e₂) ↔⟨⟩
Closed′ xs e₁ × Closed′ xs e₂ □
Closed′-lambda≃ :
Closed′ xs (lambda x e) ≃ Closed′ (x ∷ xs) e
Closed′-lambda≃ {xs = xs} {x = x} {e = e} =
Closed′ xs (lambda x e) ↔⟨⟩
(∀ y → ¬ y ∈ xs → ¬ y ∈FV lambda x e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈lambda) ⟩
(∀ y → ¬ y ∈ xs → ¬ (y ≢ x × y ∈FV e)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → currying) ⟩
(∀ y → ¬ y ∈ xs → y ≢ x → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → Π-comm) ⟩
(∀ y → y ≢ x → ¬ y ∈ xs → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → inverse currying) ⟩
(∀ y → y ≢ x × ¬ y ∈ xs → ¬ y ∈FV e) ↝⟨ (∀-cong ext λ _ → →-cong₁ {k₁ = equivalence} ext $ inverse $ ¬⊎↔¬×¬ ext) ⟩
(∀ y → ¬ (y ≡ x ⊎ y ∈ xs) → ¬ y ∈FV e) ↔⟨⟩
Closed′ (x ∷ xs) e □
Closed′-rec≃ :
Closed′ xs (rec x e) ≃ Closed′ (x ∷ xs) e
Closed′-rec≃ {xs = xs} {x = x} {e = e} =
Closed′ xs (rec x e) ↔⟨⟩
(∀ y → ¬ y ∈ xs → ¬ y ∈FV rec x e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈rec) ⟩
(∀ y → ¬ y ∈ xs → ¬ (y ≢ x × y ∈FV e)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → currying) ⟩
(∀ y → ¬ y ∈ xs → y ≢ x → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → Π-comm) ⟩
(∀ y → y ≢ x → ¬ y ∈ xs → ¬ y ∈FV e) ↔⟨ (∀-cong ext λ _ → inverse currying) ⟩
(∀ y → y ≢ x × ¬ y ∈ xs → ¬ y ∈FV e) ↝⟨ (∀-cong ext λ _ → →-cong₁ {k₁ = equivalence} ext $ inverse $ ¬⊎↔¬×¬ ext) ⟩
(∀ y → ¬ (y ≡ x ⊎ y ∈ xs) → ¬ y ∈FV e) ↔⟨⟩
Closed′ (x ∷ xs) e □
Closed′-case≃ :
Closed′ xs (case e bs) ≃
(Closed′ xs e ×
∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e)
Closed′-case≃ {xs = xs} {e = e} {bs = bs} =
Closed′ xs (case e bs) ↔⟨⟩
(∀ x → ¬ x ∈ xs → ¬ x ∈FV case e bs) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈case) ⟩
(∀ x → ¬ x ∈ xs →
¬ (x ∈FV e ⊎
∃ λ c → ∃ λ ys → ∃ λ e′ →
x ∈FV e′ × branch c ys e′ ∈ bs × ¬ x ∈ ys)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬⊎↔¬×¬ ext) ⟩
(∀ x → ¬ x ∈ xs →
¬ x ∈FV e ×
¬ ∃ λ c → ∃ λ ys → ∃ λ e′ →
x ∈FV e′ × branch c ys e′ ∈ bs × ¬ x ∈ ys) ↔⟨ ΠΣ-comm F.∘
(∀-cong ext λ _ → ΠΣ-comm) ⟩
(∀ x → ¬ x ∈ xs → ¬ x ∈FV e) ×
(∀ x → ¬ x ∈ xs →
¬ ∃ λ c → ∃ λ ys → ∃ λ e′ →
x ∈FV e′ × branch c ys e′ ∈ bs × ¬ x ∈ ys) ↝⟨ ∃-cong lemma ⟩
(∀ x → ¬ x ∈ xs → ¬ x ∈FV e) ×
(∀ {c ys e} → branch c ys e ∈ bs → ∀ x → ¬ x ∈ ys ++ xs → ¬ x ∈FV e) ↔⟨⟩
Closed′ xs e ×
(∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e) □
where
lemma = λ hyp →
(∀ x → ¬ x ∈ xs →
¬ ∃ λ c → ∃ λ ys → ∃ λ e →
x ∈FV e × branch c ys e ∈ bs × ¬ x ∈ ys) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
currying F.∘
Π-comm F.∘
currying) F.∘
currying) F.∘
currying) F.∘
currying) ⟩
(∀ x → ¬ x ∈ xs → ∀ c ys e →
branch c ys e ∈ bs → ¬ x ∈ ys → ¬ x ∈FV e) ↔⟨ (∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
(∀-cong ext λ _ →
inverse currying) F.∘
currying) F.∘
Π-comm) F.∘
Π-comm) F.∘
Π-comm) F.∘
Π-comm F.∘
inverse currying ⟩
(∀ c ys e → branch c ys e ∈ bs →
∀ x → ¬ x ∈ xs × ¬ x ∈ ys → ¬ x ∈FV e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ inverse $
¬⊎↔¬×¬ {k = equivalence} ext) ⟩
(∀ c ys e → branch c ys e ∈ bs →
∀ x → ¬ (x ∈ xs ⊎ x ∈ ys) → ¬ x ∈FV e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ ¬-cong ext
⊎-comm) ⟩
(∀ c ys e → branch c ys e ∈ bs →
∀ x → ¬ (x ∈ ys ⊎ x ∈ xs) → ¬ x ∈FV e) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
∀-cong ext λ _ → ∀-cong ext λ _ → →-cong₁ ext $ ¬-cong ext $ inverse $
B.Any-++ _ _ _) ⟩
(∀ c ys e → branch c ys e ∈ bs →
∀ x → ¬ x ∈ ys ++ xs → ¬ x ∈FV e) ↔⟨ inverse $
(∀-cong ext λ _ →
(∀-cong ext λ _ → Bijection.implicit-Π↔Π) F.∘
Bijection.implicit-Π↔Π) F.∘
Bijection.implicit-Π↔Π ⟩□
(∀ {c ys e} → branch c ys e ∈ bs →
∀ x → ¬ x ∈ ys ++ xs → ¬ x ∈FV e) □
Closed′-const≃ :
Closed′ xs (const c es) ≃ (∀ e → e ∈ es → Closed′ xs e)
Closed′-const≃ {xs = xs} {c = c} {es = es} =
Closed′ xs (const c es) ↔⟨⟩
(∀ x → ¬ x ∈ xs → ¬ x ∈FV const c es) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈const) ⟩
(∀ x → ¬ x ∈ xs → ¬ ∃ λ e → x ∈FV e × e ∈ es) ↔⟨ currying F.∘
(∀-cong ext λ _ →
currying) F.∘
Π-comm F.∘
(∀-cong ext λ _ →
inverse currying F.∘
(∀-cong ext λ _ →
Π-comm F.∘
currying) F.∘
currying) F.∘
inverse currying ⟩
(∀ e → e ∈ es → ∀ x → ¬ x ∈ xs → ¬ x ∈FV e) ↔⟨⟩
(∀ e → e ∈ es → Closed′ xs e) □
Closed′-var≃ : Closed′ xs (var x) ≃ ∥ x ∈ xs ∥
Closed′-var≃ {xs = xs} {x = x} =
Closed′ xs (var x) ↔⟨⟩
(∀ y → ¬ y ∈ xs → ¬ y ∈FV var x) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ¬-cong ext ∈var) ⟩
(∀ y → ¬ y ∈ xs → ¬ y ≡ x) ↝⟨ (∀-cong ext λ _ → →-cong₁ ext $ inverse T.¬∥∥↔¬) ⟩
(∀ y → ¬ ∥ y ∈ xs ∥ → ¬ y ≡ x) ↝⟨ (∀-cong ext λ _ → inverse $
→≃¬→¬
(λ _ _ → T.truncation-is-proposition)
(λ _ → Dec-map
(from-equivalence $ inverse S.∥∈∥≃∈-from-List)
(S.member? _≟V₁_ _ _))
ext) ⟩
(∀ y → y ≡ x → ∥ y ∈ xs ∥) ↝⟨ (∀-cong ext λ _ → →-cong₁ ext ≡-comm) ⟩
(∀ y → x ≡ y → ∥ y ∈ xs ∥) ↝⟨ inverse $ ∀-intro _ ext ⟩□
∥ x ∈ xs ∥ □
------------------------------------------------------------------------
-- Some properties
-- Closed is propositional.
Closed-propositional : ∀ {e} → Is-proposition (Closed e)
Closed-propositional =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
¬-propositional ext
-- Closed-exp is a set.
Closed-exp-set : Is-set Closed-exp
Closed-exp-set =
Σ-closure 2 Exp-set (λ _ → mono₁ 1 Closed-propositional)
-- Two closed expressions are equal if the underlying expressions are
-- equal.
closed-equal-if-expressions-equal :
{e₁ e₂ : Closed-exp} → proj₁ e₁ ≡ proj₁ e₂ → e₁ ≡ e₂
closed-equal-if-expressions-equal eq =
Σ-≡,≡→≡ eq (Closed-propositional _ _)
-- Constructor applications are closed.
mutual
const→closed : ∀ {e} → Constructor-application e → Closed e
const→closed (const c cs) x x∉[] (const x∈e e∈es) =
consts→closed cs e∈es x x∉[] x∈e
consts→closed : ∀ {e es} →
Constructor-applications es → e ∈ es → Closed e
consts→closed [] ()
consts→closed (c ∷ cs) (inj₁ refl) = const→closed c
consts→closed (c ∷ cs) (inj₂ e∈es) = consts→closed cs e∈es
-- Closed e implies Closed′ xs e, for any xs.
Closed→Closed′ : ∀ {xs e} → Closed e → Closed′ xs e
Closed→Closed′ cl x _ = cl x (λ ())
-- If a variable is free in e [ x ← e′ ], then it is either free in e,
-- or it is distinct from x and free in e′.
mutual
subst-∈FV : ∀ x e {x′ e′} →
x′ ∈FV e [ x ← e′ ] → x′ ∈FV e × x′ ≢ x ⊎ x′ ∈FV e′
subst-∈FV x (apply e₁ e₂) (apply-left p) = ⊎-map (Σ-map apply-left id) id (subst-∈FV x e₁ p)
subst-∈FV x (apply e₁ e₂) (apply-right p) = ⊎-map (Σ-map apply-right id) id (subst-∈FV x e₂ p)
subst-∈FV x (lambda y e) (lambda x′≢y p) with x V.≟ y
subst-∈FV x (lambda y e) (lambda x′≢y p) | yes x≡y = inj₁ (lambda x′≢y p , x′≢y ∘ flip trans x≡y)
subst-∈FV x (lambda y e) (lambda x′≢y p) | no _ = ⊎-map (Σ-map (lambda x′≢y) id) id (subst-∈FV x e p)
subst-∈FV x (case e bs) (case-head p) = ⊎-map (Σ-map case-head id) id (subst-∈FV x e p)
subst-∈FV x (case e bs) (case-body p ps x′∉xs) = ⊎-map (Σ-map (λ (p : ∃ λ _ → ∃ λ _ → ∃ λ _ → _ × _ × _) →
let _ , _ , _ , ps , p , ∉ = p in
case-body p ps ∉)
id)
id
(subst-∈FV-B⋆ bs p ps x′∉xs)
subst-∈FV x (rec y e) p with x V.≟ y
subst-∈FV x (rec y e) (rec x′≢y p) | yes x≡y = inj₁ (rec x′≢y p , x′≢y ∘ flip trans x≡y)
subst-∈FV x (rec y e) (rec x′≢y p) | no x≢y = ⊎-map (Σ-map (rec x′≢y) id) id (subst-∈FV x e p)
subst-∈FV x (var y) p with x V.≟ y
subst-∈FV x (var y) p | yes x≡y = inj₂ p
subst-∈FV x (var y) (var x′≡y) | no x≢y = inj₁ (var x′≡y , x≢y ∘ flip trans x′≡y ∘ sym)
subst-∈FV x (const c es) (const p ps) = ⊎-map (Σ-map (λ { (_ , ps , p) → const p ps }) id) id
(subst-∈FV-⋆ es p ps)
subst-∈FV-⋆ : ∀ {x x′ e e′} es →
x′ ∈FV e → e ∈ es [ x ← e′ ]⋆ →
(∃ λ e → e ∈ es × x′ ∈FV e) × x′ ≢ x ⊎ x′ ∈FV e′
subst-∈FV-⋆ [] p ()
subst-∈FV-⋆ (e ∷ es) p (inj₁ refl) = ⊎-map (Σ-map (λ p → _ , inj₁ refl , p) id) id (subst-∈FV _ e p)
subst-∈FV-⋆ (e ∷ es) p (inj₂ q) = ⊎-map (Σ-map (Σ-map id (Σ-map inj₂ id)) id) id (subst-∈FV-⋆ es p q)
subst-∈FV-B⋆ : ∀ {x x′ e e′ c xs} bs →
x′ ∈FV e → branch c xs e ∈ bs [ x ← e′ ]B⋆ → ¬ x′ ∈ xs →
(∃ λ c → ∃ λ xs → ∃ λ e →
branch c xs e ∈ bs × x′ ∈FV e × ¬ x′ ∈ xs) × x′ ≢ x
⊎
x′ ∈FV e′
subst-∈FV-B⋆ [] p ()
subst-∈FV-B⋆ {x} (branch c xs e ∷ bs) p (inj₁ eq) q with V.member x xs
subst-∈FV-B⋆ {x} (branch c xs e ∷ bs) p (inj₁ refl) q | yes x∈xs = inj₁ ((c , xs , e , inj₁ refl , p , q) , λ x′≡x →
q (subst (_∈ _) (sym x′≡x) x∈xs))
subst-∈FV-B⋆ {x} (branch c xs e ∷ bs) p (inj₁ refl) q | no x∉xs = ⊎-map (Σ-map (λ p → _ , _ , _ , inj₁ refl , p , q) id)
id
(subst-∈FV _ e p)
subst-∈FV-B⋆ (b ∷ bs) p (inj₂ ps) q =
⊎-map (Σ-map (Σ-map _ (Σ-map _ (Σ-map _ (Σ-map inj₂ id)))) id) id
(subst-∈FV-B⋆ bs p ps q)
------------------------------------------------------------------------
-- Various closure properties (or similar properties) for Closed′
Closed′-closed-under-apply :
∀ {xs e₁ e₂} →
Closed′ xs e₁ → Closed′ xs e₂ → Closed′ xs (apply e₁ e₂)
Closed′-closed-under-apply = curry $ _≃_.from Closed′-apply≃
Closed′-closed-under-lambda :
∀ {x xs e} →
Closed′ (x ∷ xs) e → Closed′ xs (lambda x e)
Closed′-closed-under-lambda = _≃_.from Closed′-lambda≃
Closed′-closed-under-rec :
∀ {x xs e} →
Closed′ (x ∷ xs) e → Closed′ xs (rec x e)
Closed′-closed-under-rec = _≃_.from Closed′-rec≃
Closed′-closed-under-case :
∀ {xs e bs} →
Closed′ xs e →
(∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e) →
Closed′ xs (case e bs)
Closed′-closed-under-case = curry $ _≃_.from Closed′-case≃
Closed′-closed-under-const :
∀ {xs c es} →
(∀ e → e ∈ es → Closed′ xs e) →
Closed′ xs (const c es)
Closed′-closed-under-const = _≃_.from Closed′-const≃
Closed′-closed-under-var : ∀ {x xs} → x ∈ xs → Closed′ xs (var x)
Closed′-closed-under-var = _≃_.from Closed′-var≃ ∘ T.∣_∣
Closed′-closed-under-subst :
∀ {x xs e e′} →
Closed′ (x ∷ xs) e →
Closed′ xs e′ →
Closed′ xs (e [ x ← e′ ])
Closed′-closed-under-subst cl-e cl-e′ y y∉xs =
[ uncurry (λ y∈e y≢x → cl-e y [ y≢x , y∉xs ] y∈e)
, cl-e′ y y∉xs
] ∘ subst-∈FV _ _
------------------------------------------------------------------------
-- Computing free or fresh variables
-- One can construct a finite set containing exactly the free
-- variables in a term.
mutual
free :
(e : Exp) →
∃ λ (fs : Finite-subset-of Var) → ∀ x → (x S.∈ fs) ⇔ (x ∈FV e)
free (apply e₁ e₂) =
Σ-zip S._∪_
(λ {fs₁ fs₂} hyp₁ hyp₂ x →
x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩
x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _)
(S.member? _≟V₁_ _ _)) ⟩
x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩
x ∈FV e₁ ⊎ x ∈FV e₂ ↔⟨ inverse ∈apply ⟩□
x ∈FV apply e₁ e₂ □)
(free e₁) (free e₂)
free (lambda x e) =
Σ-map (S.delete _≟V₂_ x)
(λ {fs} hyp y →
y S.∈ S.delete _≟V₂_ x fs ↔⟨ S.∈delete≃ _≟V₂_ ⟩
y ≢ x × y S.∈ fs ↝⟨ (∃-cong λ _ → hyp y) ⟩
y ≢ x × y ∈FV e ↔⟨ inverse ∈lambda ⟩□
y ∈FV lambda x e □)
(free e)
free (case e bs) =
Σ-zip S._∪_
(λ {fs₁ fs₂} hyp₁ hyp₂ x →
x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩
x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _)
(S.member? _≟V₁_ _ _)) ⟩
x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩
(x ∈FV e ⊎
∃ λ c → ∃ λ xs → ∃ λ e′ →
x ∈FV e′ × branch c xs e′ ∈ bs × ¬ x ∈ xs) ↔⟨ inverse ∈case ⟩□
x ∈FV case e bs □)
(free e) (free-B⋆ bs)
free (rec x e) =
Σ-map (S.delete _≟V₂_ x)
(λ {fs} hyp y →
y S.∈ S.delete _≟V₂_ x fs ↔⟨ S.∈delete≃ _≟V₂_ ⟩
y ≢ x × y S.∈ fs ↝⟨ (∃-cong λ _ → hyp y) ⟩
y ≢ x × y ∈FV e ↔⟨ inverse ∈rec ⟩□
y ∈FV rec x e □)
(free e)
free (var x) =
S.singleton x
, λ y →
y S.∈ S.singleton x ↔⟨ S.∈singleton≃ ⟩
T.∥ y ≡ x ∥ ↔⟨ T.∥∥↔ V.Name-set ⟩
y ≡ x ↔⟨ inverse ∈var ⟩□
y ∈FV var x □
free (const c es) =
Σ-map id
(λ {fs} hyp x →
x S.∈ fs ↝⟨ hyp x ⟩
(∃ λ e → x ∈FV e × e ∈ es) ↔⟨ inverse ∈const ⟩□
x ∈FV const c es □)
(free-⋆ es)
free-⋆ :
(es : List Exp) →
∃ λ (fs : Finite-subset-of Var) →
∀ x → (x S.∈ fs) ⇔ (∃ λ e → x ∈FV e × e ∈ es)
free-⋆ [] =
S.[]
, λ x →
x S.∈ S.[] ↔⟨ S.∈[]≃ ⟩
⊥ ↔⟨ inverse ×-right-zero ⟩
Exp × ⊥₀ ↔⟨ (∃-cong λ _ → inverse ×-right-zero) ⟩
(∃ λ e → x ∈FV e × ⊥) ↔⟨⟩
(∃ λ e → x ∈FV e × e ∈ []) □
free-⋆ (e ∷ es) =
Σ-zip S._∪_
(λ {fs₁ fs₂} hyp₁ hyp₂ x →
x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩
x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _)
(S.member? _≟V₁_ _ _)) ⟩
x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩
x ∈FV e ⊎ (∃ λ e′ → x ∈FV e′ × e′ ∈ es) ↔⟨ inverse $
(drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $
singleton-contractible _)
⊎-cong
F.id ⟩
x ∈FV e × (∃ λ e′ → e′ ≡ e) ⊎ (∃ λ e′ → x ∈FV e′ × e′ ∈ es) ↔⟨ ∃-comm ⊎-cong F.id ⟩
(∃ λ e′ → x ∈FV e × e′ ≡ e) ⊎ (∃ λ e′ → x ∈FV e′ × e′ ∈ es) ↔⟨ inverse ∃-⊎-distrib-left ⟩
(∃ λ e′ → (x ∈FV e × e′ ≡ e) ⊎ (x ∈FV e′ × e′ ∈ es)) ↔⟨ (∃-cong λ _ →
(×-cong₁ λ e′≡e → ≡⇒↝ equivalence $ cong (_ ∈FV_) $ sym
e′≡e)
⊎-cong
F.id) ⟩
(∃ λ e′ → (x ∈FV e′ × e′ ≡ e) ⊎ (x ∈FV e′ × e′ ∈ es)) ↔⟨ (∃-cong λ _ → inverse ×-⊎-distrib-left) ⟩
(∃ λ e′ → x ∈FV e′ × (e′ ≡ e ⊎ e′ ∈ es)) ↔⟨⟩
(∃ λ e′ → x ∈FV e′ × e′ ∈ e ∷ es) □)
(free e) (free-⋆ es)
free-B :
(b : Br) →
∃ λ (fs : Finite-subset-of Var) →
∀ x →
(x S.∈ fs) ⇔
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e × branch c xs e ≡ b × ¬ x ∈ xs)
free-B (branch c xs e) =
Σ-map (λ fs → S.minus _≟V₂_ fs (S.from-List xs))
(λ {fs} hyp x →
x S.∈ S.minus _≟V₂_ fs (S.from-List xs) ↔⟨ S.∈minus≃ ⟩
x S.∈ fs × x S.∉ S.from-List xs ↔⟨ (∃-cong λ _ → ¬-cong ext $ inverse
S.∥∈∥≃∈-from-List) ⟩
x S.∈ fs × ¬ T.∥ x ∈ xs ∥ ↔⟨ (∃-cong λ _ → T.¬∥∥↔¬) ⟩
x S.∈ fs × ¬ x ∈ xs ↝⟨ hyp x ×-cong F.id ⟩
x ∈FV e × ¬ x ∈ xs ↔⟨ (inverse $ drop-⊤-right λ _ →
×-left-identity F.∘ ×-left-identity) ⟩
(x ∈FV e × ¬ x ∈ xs) × ⊤ × ⊤ × ⊤ ↔⟨ (∃-cong λ _ → inverse $
(_⇔_.to contractible⇔↔⊤ $ singleton-contractible _)
×-cong
(_⇔_.to contractible⇔↔⊤ $ singleton-contractible _)
×-cong
(_⇔_.to contractible⇔↔⊤ $ singleton-contractible _)) ⟩
(x ∈FV e × ¬ x ∈ xs) ×
(∃ λ c′ → c′ ≡ c) × (∃ λ xs′ → xs′ ≡ xs) × (∃ λ e′ → e′ ≡ e) ↔⟨ (∃-cong λ _ →
(∃-cong λ _ →
(∃-cong λ _ →
∃-comm F.∘
(∃-cong λ _ → ∃-comm)) F.∘
∃-comm F.∘
(∃-cong λ _ → inverse Σ-assoc)) F.∘
inverse Σ-assoc) ⟩
(x ∈FV e × ¬ x ∈ xs) ×
(∃ λ c′ → ∃ λ xs′ → ∃ λ e′ → c′ ≡ c × xs′ ≡ xs × e′ ≡ e) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) F.∘
(∃-cong λ _ → ∃-comm) F.∘
∃-comm ⟩
(∃ λ c′ → ∃ λ xs′ → ∃ λ e′ →
(x ∈FV e × ¬ x ∈ xs) × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →
(∃-cong λ _ → ×-comm) F.∘
inverse Σ-assoc) ⟩
(∃ λ c′ → ∃ λ xs′ → ∃ λ e′ →
x ∈FV e × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e) × ¬ x ∈ xs) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →
∃-cong λ (_ , xs′≡xs , _) → ≡⇒↝ _ $ cong (¬_ ∘ (_ ∈_)) $ sym
xs′≡xs) ⟩
(∃ λ c′ → ∃ λ xs′ → ∃ λ e′ →
x ∈FV e × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e) × ¬ x ∈ xs′) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →
×-cong₁ λ ((_ , _ , e′≡e) , _) → ≡⇒↝ _ $ cong (_ ∈FV_) $ sym
e′≡e) ⟩
(∃ λ c′ → ∃ λ xs′ → ∃ λ e′ →
x ∈FV e′ × (c′ ≡ c × xs′ ≡ xs × e′ ≡ e) × ¬ x ∈ xs′) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-cong₁ λ _ →
lemma) ⟩□
(∃ λ c′ → ∃ λ xs′ → ∃ λ e′ →
x ∈FV e′ × branch c′ xs′ e′ ≡ branch c xs e × ¬ x ∈ xs′) □)
(free e)
where
lemma :
c′ ≡ c × xs′ ≡ xs × e′ ≡ e ⇔ branch c′ xs′ e′ ≡ branch c xs e
lemma ._⇔_.to (c′≡c , xs′≡xs , e′≡e) =
cong₂ (uncurry branch) (cong₂ _,_ c′≡c xs′≡xs) e′≡e
lemma ._⇔_.from eq =
cong (λ { (branch c _ _) → c }) eq
, cong (λ { (branch _ xs _) → xs }) eq
, cong (λ { (branch _ _ e) → e }) eq
free-B⋆ :
(bs : List Br) →
∃ λ (fs : Finite-subset-of Var) →
∀ x →
(x S.∈ fs) ⇔
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e × branch c xs e ∈ bs × ¬ x ∈ xs)
free-B⋆ [] =
S.[]
, λ x →
x S.∈ S.[] ↔⟨ S.∈[]≃ ⟩
⊥ ↔⟨ (inverse $
×-right-zero {ℓ₁ = lzero} F.∘
∃-cong λ _ →
×-right-zero {ℓ₁ = lzero} F.∘
∃-cong λ _ →
×-right-zero {ℓ₁ = lzero} F.∘
∃-cong λ _ →
×-right-zero {ℓ₁ = lzero} F.∘
∃-cong λ _ →
×-left-zero) ⟩
Const × (∃ λ xs → ∃ λ e → x ∈FV e × ⊥ × ¬ x ∈ xs) ↔⟨⟩
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e × branch c xs e ∈ [] × ¬ x ∈ xs) □
free-B⋆ (b ∷ bs) =
Σ-zip S._∪_
(λ {fs₁ fs₂} hyp₁ hyp₂ x →
x S.∈ fs₁ S.∪ fs₂ ↔⟨ S.∈∪≃ ⟩
x S.∈ fs₁ T.∥⊎∥ x S.∈ fs₂ ↝⟨ T.Dec→∥∥⇔ (Dec-⊎ (S.member? _≟V₁_ _ _)
(S.member? _≟V₁_ _ _)) ⟩
x S.∈ fs₁ ⊎ x S.∈ fs₂ ↝⟨ hyp₁ x ⊎-cong hyp₂ x ⟩
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e × branch c xs e ≡ b × ¬ x ∈ xs) ⊎
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e × branch c xs e ∈ bs × ¬ x ∈ xs) ↔⟨ (inverse $
∃-⊎-distrib-left F.∘
∃-cong λ _ →
∃-⊎-distrib-left F.∘
∃-cong λ _ →
∃-⊎-distrib-left F.∘
∃-cong λ _ →
∃-⊎-distrib-left F.∘
∃-cong λ _ →
∃-⊎-distrib-right) ⟩
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e ×
(branch c xs e ≡ b ⊎ branch c xs e ∈ bs) ×
¬ x ∈ xs) ↔⟨⟩
(∃ λ c → ∃ λ xs → ∃ λ e →
x ∈FV e × branch c xs e ∈ b ∷ bs × ¬ x ∈ xs) □)
(free-B b) (free-B⋆ bs)
-- It is possible to find a variable that is neither free in a given
-- expression, nor a member of a given finite set.
fresh′ :
(xs : Finite-subset-of Var) (e : Exp) →
∃ λ (x : Var) → ¬ x ∈FV e × x S.∉ xs
fresh′ xs e =
Σ-map id
(λ {x} →
x S.∉ proj₁ (free e) S.∪ xs ↔⟨ ¬-cong ext S.∈∪≃ ⟩
¬ (x S.∈ proj₁ (free e) T.∥⊎∥ x S.∈ xs) ↔⟨ T.¬∥∥↔¬ ⟩
¬ (x S.∈ proj₁ (free e) ⊎ x S.∈ xs) ↝⟨ ¬⊎↔¬×¬ _ ⟩
x S.∉ proj₁ (free e) × x S.∉ xs ↔⟨ ¬-cong-⇔ ext (proj₂ (free e) x) ×-cong F.id ⟩□
¬ x ∈FV e × x S.∉ xs □)
(V.fresh (proj₁ (free e) S.∪ xs))
-- It is possible to find a variable that is not free in a given
-- expression.
fresh : (e : Exp) → ∃ λ (x : Var) → ¬ x ∈FV e
fresh e = Σ-map id proj₁ (fresh′ S.[] e)
-- If two expressions have the same free variables (ignoring any
-- variables in xs), then fresh′ xs returns the same fresh variable
-- for both expressions.
fresh′-unique :
(∀ x → x S.∉ xs → x ∈FV e₁ ⇔ x ∈FV e₂) →
proj₁ (fresh′ xs e₁) ≡ proj₁ (fresh′ xs e₂)
fresh′-unique {xs = xs} {e₁ = e₁} {e₂ = e₂} same =
proj₁ (V.fresh (proj₁ (free e₁) S.∪ xs)) ≡⟨ (cong (proj₁ ∘ V.fresh) $
_≃_.from S.extensionality λ x →
x S.∈ proj₁ (free e₁) S.∪ xs ↝⟨ lemma x e₁ ⟩
x S.∉ xs × x ∈FV e₁ T.∥⊎∥ x S.∈ xs ↝⟨ ∃-cong (same x) T.∥⊎∥-cong F.id ⟩
x S.∉ xs × x ∈FV e₂ T.∥⊎∥ x S.∈ xs ↝⟨ inverse $ lemma x e₂ ⟩□
x S.∈ proj₁ (free e₂) S.∪ xs □) ⟩∎
proj₁ (V.fresh (proj₁ (free e₂) S.∪ xs)) ∎
where
lemma : ∀ _ _ → _ ⇔ _
lemma x e =
x S.∈ proj₁ (free e) S.∪ xs ↔⟨ S.∈∪≃ ⟩
x S.∈ proj₁ (free e) T.∥⊎∥ x S.∈ xs ↝⟨ proj₂ (free e) x T.∥⊎∥-cong F.id ⟩
x ∈FV e T.∥⊎∥ x S.∈ xs ↔⟨ T.∥⊎∥≃¬×∥⊎∥ $ T.Dec→Dec-∥∥ $ S.member? _≟V₁_ x xs ⟩□
x S.∉ xs × x ∈FV e T.∥⊎∥ x S.∈ xs □
-- If two expressions have the same free variables, then fresh returns
-- the same fresh variable for both expressions.
fresh-unique :
(∀ x → x ∈FV e₁ ⇔ x ∈FV e₂) →
proj₁ (fresh e₁) ≡ proj₁ (fresh e₂)
fresh-unique same = fresh′-unique (λ x _ → same x)
------------------------------------------------------------------------
-- Decision procedures
-- These decision procedures could presumably be implemented using
-- free.
-- The free variable relation, _∈FV_, is decidable.
mutual
_∈?_ : ∀ x e → Dec (x ∈FV e)
x ∈? apply e₁ e₂ with x ∈? e₁
x ∈? apply e₁ e₂ | yes x∈e₁ = yes (apply-left x∈e₁)
x ∈? apply e₁ e₂ | no x∉e₁ = ⊎-map apply-right
(λ x∉e₂ → λ { (apply-left x∈e₁) → x∉e₁ x∈e₁
; (apply-right x∈e₂) → x∉e₂ x∈e₂
})
(x ∈? e₂)
x ∈? lambda y e with x V.≟ y
x ∈? lambda y e | yes x≡y = no (λ { (lambda x≢y _) → x≢y x≡y })
x ∈? lambda y e | no x≢y = ⊎-map (lambda x≢y)
(λ x∉e → λ { (lambda _ x∈e) → x∉e x∈e })
(x ∈? e)
x ∈? rec y e with x V.≟ y
x ∈? rec y e | yes x≡y = no (λ { (rec x≢y _) → x≢y x≡y })
x ∈? rec y e | no x≢y = ⊎-map (rec x≢y)
(λ x∉e → λ { (rec _ x∈e) → x∉e x∈e })
(x ∈? e)
x ∈? var y with x V.≟ y
x ∈? var y | yes x≡y = yes (var x≡y)
x ∈? var y | no x≢y = no (λ { (var x≡y) → x≢y x≡y })
x ∈? const c es = ⊎-map (λ { (_ , e∈es , x∈e) → const x∈e e∈es })
(λ x∉es → λ { (const x∈e e∈es) →
x∉es (_ , e∈es , x∈e) })
(x ∈?-⋆ es)
x ∈? case e bs with x ∈? e
x ∈? case e bs | yes x∈e = yes (case-head x∈e)
x ∈? case e bs | no x∉e = ⊎-map (λ { (_ , _ , _ , xs→e∈bs , x∈e , x∉xs) →
case-body x∈e xs→e∈bs x∉xs })
(λ x∉bs → λ { (case-head x∈e) → x∉e x∈e
; (case-body x∈e xs→e∈bs x∉xs) →
x∉bs (_ , _ , _ , xs→e∈bs , x∈e , x∉xs)
})
(x ∈?-B⋆ bs)
_∈?-⋆_ : ∀ x es → Dec (∃ λ e → e ∈ es × x ∈FV e)
x ∈?-⋆ [] = no (λ { (_ , () , _) })
x ∈?-⋆ (e ∷ es) with x ∈? e
x ∈?-⋆ (e ∷ es) | yes x∈e = yes (_ , inj₁ refl , x∈e)
x ∈?-⋆ (e ∷ es) | no x∉e =
⊎-map (Σ-map id (Σ-map inj₂ id))
(λ x∉es → λ { (_ , inj₁ refl , x∈e) → x∉e x∈e
; (_ , inj₂ e∈es , x∈e) → x∉es (_ , e∈es , x∈e)
})
(x ∈?-⋆ es)
_∈?-B⋆_ :
∀ x bs →
Dec (∃ λ c → ∃ λ xs → ∃ λ e →
branch c xs e ∈ bs × x ∈FV e × ¬ x ∈ xs)
x ∈?-B⋆ [] = no λ { (_ , _ , _ , () , _) }
x ∈?-B⋆ (branch c xs e ∷ bs) with x ∈?-B⋆ bs
x ∈?-B⋆ (branch c xs e ∷ bs) | yes x∈bs =
yes (Σ-map id (Σ-map id (Σ-map id (Σ-map inj₂ id))) x∈bs)
x ∈?-B⋆ (branch c xs e ∷ bs) | no x∉bs with V.member x xs
x ∈?-B⋆ (branch c xs e ∷ bs) | no x∉bs | yes x∈xs =
no (λ { (_ , _ , _ , inj₁ refl , _ , x∉xs) → x∉xs x∈xs
; (_ , _ , _ , inj₂ e∈es , x∈e , x∉xs) →
x∉bs (_ , _ , _ , e∈es , x∈e , x∉xs)
})
x ∈?-B⋆ (branch c xs e ∷ bs) | no x∉bs | no x∉xs =
⊎-map (λ x∈e → _ , _ , _ , inj₁ refl , x∈e , x∉xs)
(λ x∉e → λ { (_ , _ , _ , inj₁ refl , x∈e , _) → x∉e x∈e
; (_ , _ , _ , inj₂ e∈es , x∈e , x∉xs) →
x∉bs (_ , _ , _ , e∈es , x∈e , x∉xs)
})
(x ∈? e)
-- The Closed′ relation is decidable.
mutual
closed′? : ∀ e xs → Dec (Closed′ xs e)
closed′? (apply e₁ e₂) xs with closed′? e₁ xs
closed′? (apply e₁ e₂) xs | no ¬cl₁ = no (¬cl₁ ∘ (λ cl₁ x x∉xs → cl₁ x x∉xs ∘ apply-left))
closed′? (apply e₁ e₂) xs | yes cl₁ = ⊎-map (Closed′-closed-under-apply cl₁)
(_∘ (λ cl₂ x x∉xs → cl₂ x x∉xs ∘ apply-right))
(closed′? e₂ xs)
closed′? (lambda x e) xs = ⊎-map Closed′-closed-under-lambda
(λ ¬cl cl → ¬cl (λ y y∉x∷xs y∈e → cl y (y∉x∷xs ∘ inj₂)
(lambda (y∉x∷xs ∘ inj₁) y∈e)))
(closed′? e (x ∷ xs))
closed′? (rec x e) xs = ⊎-map Closed′-closed-under-rec
(λ ¬cl cl → ¬cl (λ y y∉x∷xs y∈e → cl y (y∉x∷xs ∘ inj₂)
(rec (y∉x∷xs ∘ inj₁) y∈e)))
(closed′? e (x ∷ xs))
closed′? (var x) xs = ⊎-map Closed′-closed-under-var
(λ x∉xs cl → cl x x∉xs (var refl))
(V.member x xs)
closed′? (const c es) xs = ⊎-map Closed′-closed-under-const
(λ ¬cl cl → ¬cl (λ _ e∈es x x∉xs x∈e →
cl x x∉xs (const x∈e e∈es)))
(closed′?-⋆ es xs)
closed′? (case e bs) xs with closed′? e xs
closed′? (case e bs) xs | no ¬cl-e = no (λ cl → ¬cl-e (λ x x∉xs →
cl x x∉xs ∘ case-head))
closed′? (case e bs) xs | yes cl-e =
⊎-map (Closed′-closed-under-case cl-e)
(λ ¬cl-bs cl → ¬cl-bs (λ b∈bs x x∉ys++xs x∈e →
let ¬[x∈ys⊎x∈xs] = x∉ys++xs ∘ _↔_.from (B.Any-++ _ _ _) in
cl x (¬[x∈ys⊎x∈xs] ∘ inj₂)
(case-body x∈e b∈bs (¬[x∈ys⊎x∈xs] ∘ inj₁))))
(closed′?-B⋆ bs xs)
closed′?-⋆ : ∀ es xs → Dec (∀ e → e ∈ es → Closed′ xs e)
closed′?-⋆ [] xs = yes (λ _ ())
closed′?-⋆ (e ∷ es) xs with closed′? e xs
closed′?-⋆ (e ∷ es) xs | no ¬cl-e = no (λ cl →
¬cl-e (cl _ (inj₁ refl)))
closed′?-⋆ (e ∷ es) xs | yes cl-e =
⊎-map (λ cl-es e → [ (λ e′≡e x x∉xs → subst (λ e → ¬ x ∈FV e)
(sym e′≡e)
(cl-e x x∉xs))
, cl-es e
])
(λ ¬cl-es cl → ¬cl-es (λ e → cl e ∘ inj₂))
(closed′?-⋆ es xs)
closed′?-B⋆ :
∀ bs xs →
Dec (∀ {c ys e} → branch c ys e ∈ bs → Closed′ (ys ++ xs) e)
closed′?-B⋆ [] xs = yes (λ ())
closed′?-B⋆ (branch c ys e ∷ bs) xs with closed′?-B⋆ bs xs
closed′?-B⋆ (branch c ys e ∷ bs) xs | no ¬cl-bs =
no (λ cl → ¬cl-bs (cl ∘ inj₂))
closed′?-B⋆ (branch c ys e ∷ bs) xs | yes cl-bs =
⊎-map (λ cl-e {c′} {ys′} {e′} →
[ (λ b′≡b x x∉ys++xs′ x∈e′ →
cl-e x (subst (λ ys → ¬ x ∈ ys ++ xs) (ys-lemma b′≡b)
x∉ys++xs′)
(subst (x ∈FV_) (e-lemma b′≡b) x∈e′))
, cl-bs
])
(λ ¬cl-e cl → ¬cl-e (cl (inj₁ refl)))
(closed′? e (ys ++ xs))
where
e-lemma :
∀ {c ys e c′ ys′ e′} →
branch c ys e ≡ branch c′ ys′ e′ → e ≡ e′
e-lemma refl = refl
ys-lemma :
∀ {c ys e c′ ys′ e′} →
branch c ys e ≡ branch c′ ys′ e′ → ys ≡ ys′
ys-lemma refl = refl
-- The Closed relation is decidable.
closed? : ∀ e → Dec (Closed e)
closed? e = closed′? e []
------------------------------------------------------------------------
-- Substituting something for a variable that is not free
-- If x is not free in e, then nothing happens when a term is
-- substituted for x in e.
mutual
subst-∉ : ∀ x e {e′} → ¬ x ∈FV e → e [ x ← e′ ] ≡ e
subst-∉ x (apply e₁ e₂) x∉ = cong₂ apply (subst-∉ x e₁ (x∉ ∘ apply-left))
(subst-∉ x e₂ (x∉ ∘ apply-right))
subst-∉ x (lambda y e) x∉ with x V.≟ y
subst-∉ x (lambda y e) x∉ | yes _ = refl
subst-∉ x (lambda y e) x∉ | no x≢y = cong (lambda y) (subst-∉ x e (x∉ ∘ lambda x≢y))
subst-∉ x (case e bs) x∉ = cong₂ case (subst-∉ x e (x∉ ∘ case-head))
(subst-∉-B⋆ x bs _ (λ { (_ , _ , _ , ∈bs , x∈ , x∉xs) →
x∉ (case-body x∈ ∈bs x∉xs) }))
subst-∉ x (rec y e) x∉ with x V.≟ y
subst-∉ x (rec y e) x∉ | yes _ = refl
subst-∉ x (rec y e) x∉ | no x≢y = cong (rec y) (subst-∉ x e (x∉ ∘ rec x≢y))
subst-∉ x (var y) x∉ with x V.≟ y
subst-∉ x (var y) x∉ | yes x≡y = ⊥-elim (x∉ (var x≡y))
subst-∉ x (var y) x∉ | no _ = refl
subst-∉ x (const c es) x∉ = cong (const c) (subst-∉-⋆ x es
(x∉ ∘ (λ { (_ , ps , p) → const p ps })))
subst-∉-⋆ :
∀ x es {e′} →
¬ (∃ λ e → e ∈ es × x ∈FV e) →
es [ x ← e′ ]⋆ ≡ es
subst-∉-⋆ x [] x∉ = refl
subst-∉-⋆ x (e ∷ es) x∉ = cong₂ _∷_ (subst-∉ x e (λ x∈ → x∉ (_ , inj₁ refl , x∈)))
(subst-∉-⋆ x es (x∉ ∘ Σ-map id (Σ-map inj₂ id)))
subst-∉-B⋆ :
∀ x bs e′ →
¬ (∃ λ c → ∃ λ xs → ∃ λ e →
branch c xs e ∈ bs × x ∈FV e × ¬ x ∈ xs) →
bs [ x ← e′ ]B⋆ ≡ bs
subst-∉-B⋆ x [] _ x∉ = refl
subst-∉-B⋆ x (branch c xs e ∷ bs) _ x∉
with V.member x xs
| subst-∉-B⋆ x bs _
(x∉ ∘ Σ-map id (Σ-map id (Σ-map id (Σ-map inj₂ id))))
... | yes x∈xs | eq = cong₂ _∷_ refl eq
... | no x∉xs | eq = cong₂ (λ e bs → branch c xs e ∷ bs)
(subst-∉ x e λ x∈e →
x∉ (_ , _ , _ , inj₁ refl , x∈e , x∉xs))
eq
-- If e is closed, then nothing happens when a term is substituted for
-- x in e.
subst-closed : ∀ x e′ {e} → Closed e → e [ x ← e′ ] ≡ e
subst-closed _ _ c = subst-∉ _ _ (c _ (λ ()))
-- An n-ary variant of the previous lemma.
substs-closed :
∀ e → Closed e → ∀ ps →
foldr (λ ye → _[ proj₁ ye ← proj₂ ye ]) e ps ≡ e
substs-closed e cl [] = refl
substs-closed e cl ((y , e′) ∷ ps) =
foldr (λ { (y , e) → _[ y ← e ] }) e ps [ y ← e′ ] ≡⟨ cong _[ y ← e′ ] (substs-closed e cl ps) ⟩
e [ y ← e′ ] ≡⟨ subst-closed _ _ cl ⟩∎
e ∎
------------------------------------------------------------------------
-- Evaluation and free variables
-- If a value contains a free variable, then every term that evaluates
-- to this value also contains the given free variable.
mutual
⇓-does-not-introduce-variables :
∀ {x v e} → e ⇓ v → x ∈FV v → x ∈FV e
⇓-does-not-introduce-variables lambda q = q
⇓-does-not-introduce-variables (const ps) (const x∈v v∈vs)
with ⇓⋆-does-not-introduce-variables ps (_ , v∈vs , x∈v)
... | _ , e∈es , x∈e = const x∈e e∈es
⇓-does-not-introduce-variables (apply {e = e} p₁ p₂ p₃) q
with subst-∈FV _ e (⇓-does-not-introduce-variables p₃ q)
... | inj₂ x∈v₂ = apply-right
(⇓-does-not-introduce-variables p₂ x∈v₂)
... | inj₁ (x∈e , x≢x′) = apply-left
(⇓-does-not-introduce-variables p₁
(lambda x≢x′ x∈e))
⇓-does-not-introduce-variables (rec {e = e} p) q
with subst-∈FV _ e (⇓-does-not-introduce-variables p q)
... | inj₂ x∈rec = x∈rec
... | inj₁ (x∈e , x≢x′) = rec x≢x′ x∈e
⇓-does-not-introduce-variables {x} {w}
(case {e = e} {bs = bs} {c = c} {es = es} {xs = xs} {e′ = e′} {e″ = e″} p₁ p₂ p₃ p₄) =
x ∈FV w ↝⟨ ⇓-does-not-introduce-variables p₄ ⟩
x ∈FV e″ ↝⟨ lemma₁ p₃ ⟩
(x ∈FV e′ × ¬ x ∈ xs) ⊎ ∃ (λ e″₁ → e″₁ ∈ es × x ∈FV e″₁) ↝⟨ ⊎-map id (λ { (_ , ps , p) → const p ps }) ⟩
(x ∈FV e′ × ¬ x ∈ xs) ⊎ x ∈FV const c es ↝⟨ ⊎-map (λ p → lemma₂ p₂ , p) (⇓-does-not-introduce-variables p₁) ⟩
(branch c xs e′ ∈ bs × x ∈FV e′ × ¬ x ∈ xs) ⊎ x ∈FV e ↝⟨ [ (λ { (ps , p , q) → case-body p ps q }) , case-head ] ⟩
x ∈FV case e bs □
where
lemma₁ : ∀ {e e′ x xs es} →
e [ xs ← es ]↦ e′ → x ∈FV e′ →
(x ∈FV e × ¬ x ∈ xs) ⊎ ∃ λ e″ → e″ ∈ es × x ∈FV e″
lemma₁ {e′ = e′} {x} [] =
x ∈FV e′ ↝⟨ (λ p → inj₁ (p , (λ ()))) ⟩□
x ∈FV e′ × ¬ x ∈ [] ⊎ _ □
lemma₁ {e} {x = x}
(∷_ {x = y} {xs = ys} {e′ = e′} {es′ = es′} {e″ = e″} p) =
x ∈FV e″ [ y ← e′ ] ↝⟨ subst-∈FV _ _ ⟩
x ∈FV e″ × x ≢ y ⊎ x ∈FV e′ ↝⟨ ⊎-map (Σ-map (lemma₁ p) id) id ⟩
(x ∈FV e × ¬ x ∈ ys ⊎ ∃ λ e‴ → e‴ ∈ es′ × x ∈FV e‴) × x ≢ y
⊎
x ∈FV e′ ↝⟨ [ uncurry (λ p x≢y → ⊎-map (Σ-map id (λ x∉ys → [ x≢y , x∉ys ]))
(Σ-map id (Σ-map inj₂ id))
p)
, (λ p → inj₂ (_ , inj₁ refl , p))
] ⟩□
x ∈FV e × ¬ x ∈ y ∷ ys ⊎ (∃ λ e″ → e″ ∈ e′ ∷ es′ × x ∈FV e″) □
lemma₂ : ∀ {c bs xs e} → Lookup c bs xs e → branch c xs e ∈ bs
lemma₂ here = inj₁ refl
lemma₂ (there _ p) = inj₂ (lemma₂ p)
⇓⋆-does-not-introduce-variables :
∀ {x es vs} →
es ⇓⋆ vs →
(∃ λ v → v ∈ vs × x ∈FV v) →
(∃ λ e → e ∈ es × x ∈FV e)
⇓⋆-does-not-introduce-variables [] = id
⇓⋆-does-not-introduce-variables (p ∷ ps) (v , inj₁ refl , q) =
_ , inj₁ refl , ⇓-does-not-introduce-variables p q
⇓⋆-does-not-introduce-variables (p ∷ ps) (v , inj₂ v∈ , q) =
Σ-map id (Σ-map inj₂ id)
(⇓⋆-does-not-introduce-variables ps (v , v∈ , q))
-- A closed term's value is closed.
closed⇓closed : ∀ {e v xs} → e ⇓ v → Closed′ xs e → Closed′ xs v
closed⇓closed {e} {v} {xs} p q x x∉xs =
x ∈FV v ↝⟨ ⇓-does-not-introduce-variables p ⟩
x ∈FV e ↝⟨ q x x∉xs ⟩□
⊥ □
------------------------------------------------------------------------
-- More properties
-- A constructor for closed expressions.
apply-cl : Closed-exp → Closed-exp → Closed-exp
apply-cl (e₁ , cl-e₁) (e₂ , cl-e₂) =
apply e₁ e₂
, (Closed′-closed-under-apply
(Closed→Closed′ cl-e₁)
(Closed→Closed′ cl-e₂))
-- A certain "swapping" lemma does not hold.
no-swapping :
¬ (∀ x y e e′ e″ →
x ≢ y →
Closed e′ →
Closed (e″ [ x ← e′ ]) →
e [ x ← e′ ] [ y ← e″ [ x ← e′ ] ] ≡ e [ y ← e″ ] [ x ← e′ ])
no-swapping hyp = distinct (hyp x′ y′ e₁′ e₂′ e₃′ x≢y cl₁ cl₂)
where
x′ = V.name 0
y′ = V.name 1
e₁′ : Exp
e₁′ = lambda x′ (var y′)
e₂′ : Exp
e₂′ = const (C.name 0) []
e₃′ : Exp
e₃′ = var x′
x≢y : x′ ≢ y′
x≢y = V.distinct-codes→distinct-names (λ ())
cl₁ : Closed e₂′
cl₁ = from-⊎ (closed? e₂′)
cl₂ : Closed (e₃′ [ x′ ← e₂′ ])
cl₂ with x′ V.≟ x′
... | no x≢x = ⊥-elim (x≢x refl)
... | yes _ = cl₁
lhs : e₁′ [ x′ ← e₂′ ] [ y′ ← e₃′ [ x′ ← e₂′ ] ] ≡ lambda x′ e₂′
lhs with x′ V.≟ x′
... | no x≢x = ⊥-elim (x≢x refl)
... | yes _ with y′ V.≟ x′
... | yes y≡x = ⊥-elim (x≢y (sym y≡x))
... | no _ with y′ V.≟ y′
... | no y≢y = ⊥-elim (y≢y refl)
... | yes _ = refl
rhs : e₁′ [ y′ ← e₃′ ] [ x′ ← e₂′ ] ≡ lambda x′ (var x′)
rhs with y′ V.≟ x′
... | yes y≡x = ⊥-elim (x≢y (sym y≡x))
... | no _ with y′ V.≟ y′
... | no y≢y = ⊥-elim (y≢y refl)
... | yes _ with x′ V.≟ x′
... | no x≢x = ⊥-elim (x≢x refl)
... | yes _ = refl
distinct : e₁′ [ x′ ← e₂′ ] [ y′ ← e₃′ [ x′ ← e₂′ ] ] ≢
e₁′ [ y′ ← e₃′ ] [ x′ ← e₂′ ]
distinct rewrite lhs | rhs = λ ()
-- Another swapping lemma does hold.
module _
(x≢y : x ≢ y)
(x∉e″ : ¬ x ∈FV e″)
(y∉e′ : ¬ y ∈FV e′)
where
mutual
swap : ∀ e → e [ x ← e′ ] [ y ← e″ ] ≡ e [ y ← e″ ] [ x ← e′ ]
swap (apply e₁ e₂) = cong₂ apply (swap e₁) (swap e₂)
swap (lambda z e) with x V.≟ z | y V.≟ z
… | yes _ | yes _ = refl
… | yes _ | no _ = refl
… | no _ | yes _ = refl
… | no _ | no _ = cong (lambda z) (swap e)
swap (case e bs) = cong₂ case (swap e) (swap-B⋆ bs)
swap (rec z e) with x V.≟ z | y V.≟ z
… | yes _ | yes _ = refl
… | yes _ | no _ = refl
… | no _ | yes _ = refl
… | no _ | no _ = cong (rec z) (swap e)
swap (var z) with x V.≟ z | y V.≟ z
… | yes x≡z | yes y≡z =
⊥-elim $ x≢y (trans x≡z (sym y≡z))
… | yes x≡z | no _ =
e′ [ y ← e″ ] ≡⟨ subst-∉ _ _ y∉e′ ⟩
e′ ≡⟨ sym $ var-step-≡ x≡z ⟩∎
var z [ x ← e′ ] ∎
… | no _ | yes y≡z =
var z [ y ← e″ ] ≡⟨ var-step-≡ y≡z ⟩
e″ ≡⟨ sym $ subst-∉ _ _ x∉e″ ⟩∎
e″ [ x ← e′ ] ∎
… | no x≢z | no y≢z =
var z [ y ← e″ ] ≡⟨ var-step-≢ y≢z ⟩
var z ≡⟨ sym $ var-step-≢ x≢z ⟩∎
var z [ x ← e′ ] ∎
swap (const c es) = cong (const c) (swap-⋆ es)
swap-B :
∀ b → b [ x ← e′ ]B [ y ← e″ ]B ≡ b [ y ← e″ ]B [ x ← e′ ]B
swap-B (branch c zs e) with V.member x zs | V.member y zs
… | yes x∈zs | yes y∈zs =
branch c zs e [ y ← e″ ]B ≡⟨ branch-step-∈ y∈zs ⟩
branch c zs e ≡⟨ sym $ branch-step-∈ x∈zs ⟩∎
branch c zs e [ x ← e′ ]B ∎
… | yes x∈zs | no y∉zs =
branch c zs e [ y ← e″ ]B ≡⟨ branch-step-∉ y∉zs ⟩
branch c zs (e [ y ← e″ ]) ≡⟨ sym $ branch-step-∈ x∈zs ⟩∎
branch c zs (e [ y ← e″ ]) [ x ← e′ ]B ∎
… | no x∉zs | yes y∈zs =
branch c zs (e [ x ← e′ ]) [ y ← e″ ]B ≡⟨ branch-step-∈ y∈zs ⟩
branch c zs (e [ x ← e′ ]) ≡⟨ sym $ branch-step-∉ x∉zs ⟩∎
branch c zs e [ x ← e′ ]B ∎
… | no x∉zs | no y∉zs =
branch c zs (e [ x ← e′ ]) [ y ← e″ ]B ≡⟨ branch-step-∉ y∉zs ⟩
branch c zs (e [ x ← e′ ] [ y ← e″ ]) ≡⟨ cong (branch c zs) (swap e) ⟩
branch c zs (e [ y ← e″ ] [ x ← e′ ]) ≡⟨ sym $ branch-step-∉ x∉zs ⟩∎
branch c zs (e [ y ← e″ ]) [ x ← e′ ]B ∎
swap-⋆ :
∀ es → es [ x ← e′ ]⋆ [ y ← e″ ]⋆ ≡ es [ y ← e″ ]⋆ [ x ← e′ ]⋆
swap-⋆ [] = refl
swap-⋆ (e ∷ es) = cong₂ _∷_ (swap e) (swap-⋆ es)
swap-B⋆ :
∀ bs → bs [ x ← e′ ]B⋆ [ y ← e″ ]B⋆ ≡ bs [ y ← e″ ]B⋆ [ x ← e′ ]B⋆
swap-B⋆ [] = refl
swap-B⋆ (b ∷ bs) = cong₂ _∷_ (swap-B b) (swap-B⋆ bs)
| 43.943316
| 140
| 0.347009
|
506948505ddaf8057e5aec22499bca16da888694
| 380
|
agda
|
Agda
|
test/interaction/Issue3002.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Issue3002.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Issue3002.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.Nat
data ⊥ : Set where
data Zero : Set where
zero : Zero
data One : Set where
suc : Zero → One
one : One
one = suc zero
data _≤_ : One → Zero → Set where
leq : ∀ m n → Nat → Nat → m ≤ n → ⊥
leq (suc m) zero = λ i j ()
test : Nat → one ≤ zero → ⊥
test = leq one zero 5
-- Normalise: test
-- Expected: λ j ()
| 14.615385
| 35
| 0.605263
|
2e410cba92fe0e81fe4361fa3cd51d506e6af768
| 3,992
|
agda
|
Agda
|
src/Categories/Category/Monoidal/Braided/Properties.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
src/Categories/Category/Monoidal/Braided/Properties.agda
|
andrejbauer/agda-categories
|
d07746023503cc8f49670e309a6170dc4b404b95
|
[
"MIT"
] | null | null | null |
src/Categories/Category/Monoidal/Braided/Properties.agda
|
andrejbauer/agda-categories
|
d07746023503cc8f49670e309a6170dc4b404b95
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category; module Commutation)
open import Categories.Category.Monoidal
open import Categories.Category.Monoidal.Braided using (Braided)
module Categories.Category.Monoidal.Braided.Properties
{o ℓ e} {C : Category o ℓ e} {M : Monoidal C} (BM : Braided M) where
open import Data.Product using (_,_)
open import Categories.Category.Monoidal.Properties M
open import Categories.Category.Monoidal.Reasoning M
open import Categories.Category.Monoidal.Utilities M
open import Categories.Functor using (Functor)
open import Categories.Morphism.Reasoning C hiding (push-eq)
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
using (push-eq)
open Category C
open Braided BM
open Commutation C
private
variable
X Y Z : Obj
-- A shorthand for the braiding
B : ∀ {X Y} → X ⊗₀ Y ⇒ Y ⊗₀ X
B {X} {Y} = braiding.⇒.η (X , Y)
-- It's easier to prove the following lemma, which is the desired
-- coherence theorem moduolo application of the |-⊗ unit| functor.
-- Because |-⊗ unit| is equivalent to the identity functor, the
-- lemma and the theorem are equivalent.
-- The following diagram illustrates the hexagon that we are
-- operating on. The main outer hexagon is hexagon₁, the braiding
-- coherence, instantiated with X, 1 and 1 (Here we denote the unit
-- by 1 for brevity).
-- In the middle are X1 and 1X along with morphisms towards them.
-- The lower hexagon (given by the double lines) commutes and is
-- an intermediary in the final proof. It is there to effectively
-- get rid of the top half of the main hexagon.
-- The rest of the proof is isolating the bottom left triangle
-- which represents our desired identity. It is doing that by
-- proving that the pentagon to the right of it commutes.
-- The pentagon commuting is, in turn, proved by gluing the
-- rightmost "square" onto the middle triangle.
--
--
-- ┌─────> X(11) ─────────> (11)X ──────┐
-- ┌┘ α │ B │ α └┐
-- ┌┘ │id⊗λ │λ⊗id └┐
-- ┌┘ V V V
-- (X1)1 ═══════> X1 ════════════> 1X <══════ 1(1X)
-- ╚╗ ρ⊗id Λ <───┐ B λ Λ
-- ╚╗ │λ⊗id └────────┐ ╔╝
-- ╚╗ │ λ └┐ ╔╝
-- ╚═════> (1X)1 ═════════> 1(X1) ═════╝
-- B⊗id α id⊗B
braiding-coherence⊗unit : [ (X ⊗₀ unit) ⊗₀ unit ⇒ X ⊗₀ unit ]⟨
B ⊗₁ id ⇒⟨ (unit ⊗₀ X) ⊗₀ unit ⟩
unitorˡ.from ⊗₁ id
≈ unitorʳ.from ⊗₁ id
⟩
braiding-coherence⊗unit = cancel-fromˡ braiding.FX≅GX (
begin
B ∘ unitorˡ.from ⊗₁ id ∘ B ⊗₁ id ≈⟨ pullˡ (⟺ (glue◽◃ unitorˡ-commute-from coherence₁)) ⟩
(unitorˡ.from ∘ id ⊗₁ B ∘ associator.from) ∘ B ⊗₁ id ≈⟨ assoc²' ⟩
unitorˡ.from ∘ id ⊗₁ B ∘ associator.from ∘ B ⊗₁ id ≈⟨ refl⟩∘⟨ hexagon₁ ⟩
unitorˡ.from ∘ associator.from ∘ B ∘ associator.from ≈⟨ pullˡ coherence₁ ⟩
unitorˡ.from ⊗₁ id ∘ B ∘ associator.from ≈˘⟨ pushˡ (braiding.⇒.commute _) ⟩
(B ∘ id ⊗₁ unitorˡ.from) ∘ associator.from ≈⟨ pullʳ triangle ⟩
B ∘ unitorʳ.from ⊗₁ id
∎)
-- The desired theorem follows from |braiding-coherence⊗unit| by
-- translating it along the right unitor (which is a natural iso).
braiding-coherence : [ X ⊗₀ unit ⇒ X ]⟨
B ⇒⟨ unit ⊗₀ X ⟩
unitorˡ.from
≈ unitorʳ.from
⟩
braiding-coherence = push-eq unitorʳ-naturalIsomorphism (begin
(unitorˡ.from ∘ B) ⊗₁ id ≈⟨ homomorphism ⟩
(unitorˡ.from ⊗₁ id) ∘ (B ⊗₁ id) ≈⟨ braiding-coherence⊗unit ⟩
unitorʳ.from ⊗₁ id ∎)
where open Functor (-⊗ unit)
| 42.924731
| 124
| 0.561122
|
38060e1a5286aa00bd517c0e7fae04d54716211a
| 224
|
agda
|
Agda
|
test/Compiler/simple/Issue2914.agda
|
xekoukou/agda-ocaml
|
026a8f8473ab91f99c3f6545728e71fa847d2720
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Compiler/simple/Issue2914.agda
|
xekoukou/agda-ocaml
|
026a8f8473ab91f99c3f6545728e71fa847d2720
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Compiler/simple/Issue2914.agda
|
xekoukou/agda-ocaml
|
026a8f8473ab91f99c3f6545728e71fa847d2720
|
[
"BSD-3-Clause"
] | null | null | null |
open import Common.IO
open import Common.Nat
open import Common.String
open import Common.Unit
private
n : Nat
n = 7
{-# COMPILE OCaml n as val n : Z.t #-}
main : IO Unit
main = do
putStrLn (natToString n)
| 14
| 38
| 0.665179
|
ad86933e7da743e29a130aad9329bfbbc22b439d
| 3,715
|
agda
|
Agda
|
BasicIPC/Semantics/TarskiGluedClosedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIPC/Semantics/TarskiGluedClosedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIPC/Semantics/TarskiGluedClosedHilbert.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Basic intuitionistic propositional calculus, without ∨ or ⊥.
-- Tarski-style semantics with glueing for α and ▻, after Coquand-Dybjer.
-- Hilbert-style closed syntax.
module BasicIPC.Semantics.TarskiGluedClosedHilbert where
open import BasicIPC.Syntax.Common public
open import Common.Semantics public
-- Tarski models with explicit syntax.
record Model : Set₁ where
infix 3 ⊩ᵅ_ [⊢]_
field
-- Forcing for atomic propositions.
⊩ᵅ_ : Atom → Set
-- Hilbert-style closed syntax representation.
[⊢]_ : Ty → Set
[app] : ∀ {A B} → [⊢] A ▻ B → [⊢] A → [⊢] B
[ci] : ∀ {A} → [⊢] A ▻ A
[ck] : ∀ {A B} → [⊢] A ▻ B ▻ A
[cs] : ∀ {A B C} → [⊢] (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
[cpair] : ∀ {A B} → [⊢] A ▻ B ▻ A ∧ B
[cfst] : ∀ {A B} → [⊢] A ∧ B ▻ A
[csnd] : ∀ {A B} → [⊢] A ∧ B ▻ B
[unit] : [⊢] ⊤
infix 3 [⊢]⋆_
[⊢]⋆_ : Cx Ty → Set
[⊢]⋆ ∅ = 𝟙
[⊢]⋆ Ξ , A = [⊢]⋆ Ξ × [⊢] A
open Model {{…}} public
-- Forcing in a particular model.
module _ {{_ : Model}} where
infix 3 ⊩_
⊩_ : Ty → Set
⊩ α P = Glue ([⊢] α P) (⊩ᵅ P)
⊩ A ▻ B = Glue ([⊢] A ▻ B) (⊩ A → ⊩ B)
⊩ A ∧ B = ⊩ A × ⊩ B
⊩ ⊤ = 𝟙
infix 3 ⊩⋆_
⊩⋆_ : Cx Ty → Set
⊩⋆ ∅ = 𝟙
⊩⋆ Ξ , A = ⊩⋆ Ξ × ⊩ A
-- Entailment, or forcing in all models.
infix 3 ⊨_
⊨_ : Ty → Set₁
⊨ A = ∀ {{_ : Model}} → ⊩ A
-- Extraction of syntax representation in a particular model.
module _ {{_ : Model}} where
reifyʳ : ∀ {A} → ⊩ A → [⊢] A
reifyʳ {α P} s = syn s
reifyʳ {A ▻ B} s = syn s
reifyʳ {A ∧ B} s = [app] ([app] [cpair] (reifyʳ (π₁ s))) (reifyʳ (π₂ s))
reifyʳ {⊤} s = [unit]
reifyʳ⋆ : ∀ {Ξ} → ⊩⋆ Ξ → [⊢]⋆ Ξ
reifyʳ⋆ {∅} ∙ = ∙
reifyʳ⋆ {Ξ , A} (ts , t) = reifyʳ⋆ ts , reifyʳ t
-- Useful theorems in functional form.
module _ {{_ : Model}} where
[multicut] : ∀ {Ξ A} → [⊢]⋆ Ξ → [⊢] Ξ ▻⋯▻ A → [⊢] A
[multicut] {∅} ∙ u = u
[multicut] {Ξ , B} (ts , t) u = [app] ([multicut] ts u) t
-- Additional useful equipment.
module _ {{_ : Model}} where
_⟪$⟫_ : ∀ {A B} → ⊩ A ▻ B → ⊩ A → ⊩ B
s ⟪$⟫ a = sem s a
⟪K⟫ : ∀ {A B} → ⊩ A → ⊩ B ▻ A
⟪K⟫ a = [app] [ck] (reifyʳ a) ⅋ K a
⟪S⟫ : ∀ {A B C} → ⊩ A ▻ B ▻ C → ⊩ A ▻ B → ⊩ A → ⊩ C
⟪S⟫ s₁ s₂ a = (s₁ ⟪$⟫ a) ⟪$⟫ (s₂ ⟪$⟫ a)
⟪S⟫′ : ∀ {A B C} → ⊩ A ▻ B ▻ C → ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ s₁ = [app] [cs] (reifyʳ s₁) ⅋ λ s₂ →
[app] ([app] [cs] (reifyʳ s₁)) (reifyʳ s₂) ⅋ ⟪S⟫ s₁ s₂
_⟪,⟫′_ : ∀ {A B} → ⊩ A → ⊩ B ▻ A ∧ B
_⟪,⟫′_ a = [app] [cpair] (reifyʳ a) ⅋ _,_ a
-- Forcing in a particular model, for sequents.
module _ {{_ : Model}} where
infix 3 ⊩_⇒_
⊩_⇒_ : Cx Ty → Ty → Set
⊩ Γ ⇒ A = ⊩⋆ Γ → ⊩ A
infix 3 ⊩_⇒⋆_
⊩_⇒⋆_ : Cx Ty → Cx Ty → Set
⊩ Γ ⇒⋆ Ξ = ⊩⋆ Γ → ⊩⋆ Ξ
-- Entailment, or forcing in all models, for sequents.
infix 3 _⊨_
_⊨_ : Cx Ty → Ty → Set₁
Γ ⊨ A = ∀ {{_ : Model}} → ⊩ Γ ⇒ A
infix 3 _⊨⋆_
_⊨⋆_ : Cx Ty → Cx Ty → Set₁
Γ ⊨⋆ Ξ = ∀ {{_ : Model}} → ⊩ Γ ⇒⋆ Ξ
-- Additional useful equipment, for sequents.
module _ {{_ : Model}} where
lookup : ∀ {A Γ} → A ∈ Γ → ⊩ Γ ⇒ A
lookup top (γ , a) = a
lookup (pop i) (γ , b) = lookup i γ
⟦λ⟧ : ∀ {A B Γ} → [⊢] A ▻ B → ⊩ Γ , A ⇒ B → ⊩ Γ ⇒ A ▻ B
⟦λ⟧ t s γ = t ⅋ λ a → s (γ , a)
_⟦$⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ A ▻ B → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B
(s₁ ⟦$⟧ s₂) γ = s₁ γ ⟪$⟫ s₂ γ
⟦K⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B ▻ A
⟦K⟧ {A} {B} a γ = ⟪K⟫ {A} {B} (a γ)
⟦S⟧ : ∀ {A B C Γ} → ⊩ Γ ⇒ A ▻ B ▻ C → ⊩ Γ ⇒ A ▻ B → ⊩ Γ ⇒ A → ⊩ Γ ⇒ C
⟦S⟧ s₁ s₂ a γ = ⟪S⟫ (s₁ γ) (s₂ γ) (a γ)
_⟦,⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ A → ⊩ Γ ⇒ B → ⊩ Γ ⇒ A ∧ B
(a ⟦,⟧ b) γ = a γ , b γ
⟦π₁⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A ∧ B → ⊩ Γ ⇒ A
⟦π₁⟧ s γ = π₁ (s γ)
⟦π₂⟧ : ∀ {A B Γ} → ⊩ Γ ⇒ A ∧ B → ⊩ Γ ⇒ B
⟦π₂⟧ s γ = π₂ (s γ)
| 24.281046
| 74
| 0.426918
|
9a24aee6ee405e2e043fc6c03b32bf0ad6fb3975
| 535
|
agda
|
Agda
|
out/Unit/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/Unit/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/Unit/Signature.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order signature was created from the following second-order syntax description:
syntax Unit | U
type
𝟙 : 0-ary
term
unit : 𝟙
theory
(𝟙η) u : 𝟙 |> u = unit
-}
module Unit.Signature where
open import SOAS.Context
-- Type declaration
data UT : Set where
𝟙 : UT
open import SOAS.Syntax.Signature UT public
open import SOAS.Syntax.Build UT public
-- Operator symbols
data Uₒ : Set where
unitₒ : Uₒ
-- Term signature
U:Sig : Signature Uₒ
U:Sig = sig λ
{ unitₒ → ⟼₀ 𝟙
}
open Signature U:Sig public
| 13.375
| 91
| 0.693458
|
597123c617c07a6ce9e2a88bb08d8537cec05fd3
| 11,300
|
agda
|
Agda
|
RW/Language/RTermUtils.agda
|
VictorCMiraldo/agda-rw
|
2856afd12b7dbbcc908482975638d99220f38bf2
|
[
"MIT"
] | 16
|
2015-02-09T15:43:38.000Z
|
2019-10-24T17:38:20.000Z
|
RW/Language/RTermUtils.agda
|
VictorCMiraldo/agda-rw
|
2856afd12b7dbbcc908482975638d99220f38bf2
|
[
"MIT"
] | 4
|
2015-02-06T15:03:33.000Z
|
2015-05-28T14:48:03.000Z
|
RW/Language/RTermUtils.agda
|
VictorCMiraldo/agda-rw
|
2856afd12b7dbbcc908482975638d99220f38bf2
|
[
"MIT"
] | null | null | null |
open import Prelude
open import Data.Nat using (_≤?_)
open import Data.Maybe using (Maybe; just; nothing; is-just)
open import Reflection using (_≟-Lit_; _≟-Name_)
open import RW.Language.RTerm
open import RW.Utils.Monads
module RW.Language.RTermUtils where
open Monad {{...}}
-- The complexity annotations might require
-- a slight notational introduction.
--
-- If a variable name overlaps one in the corresponding type signature,
-- this is intentional.
--
-- Sₜ is defined by (S t).
-- #Fvₜ is defined by length (Fv t).
-- Both measures are defined below.
--
--------------
-- Measures --
--------------
-- The TERMINATING pragmas are required since Agda does not
-- recognize a call to map as terminating.
{-# TERMINATING #-}
height : {A : Set} → RTerm A → ℕ
height (ovar _) = 0
height (ivar _) = 0
height (rlit _) = 0
height (rlam t) = 1 + height t
height (rapp _ ts) = 1 + max* (map height ts)
where
max : ℕ → ℕ → ℕ
max a b with a ≤? b
...| yes _ = b
...| no _ = a
max* : List ℕ → ℕ
max* [] = 0
max* (h ∷ t) = max h (max* t)
{-# TERMINATING #-}
S : {A : Set} → RTerm A → ℕ
S (ovar _) = 1
S (ivar _) = 1
S (rlit _) = 1
S (rlam t) = 1 + S t
S (rapp n ts) = 1 + sum (map S ts)
where open import Data.List using (sum)
{-# TERMINATING #-}
Fv : {A : Set} → RTerm A → List A
Fv (ovar a) = a ∷ []
Fv (ivar _) = []
Fv (rlit _) = []
Fv (rlam t) = Fv t
Fv (rapp _ ts) = concatMap Fv ts
where open import Data.List using (concatMap)
-------------------------------------------------------
-- Terms with Context
--
-- Holes will be represented by a nothing;
pattern hole = ovar nothing
isHole : ∀{a}{A : Set a} → RTerm (Maybe A) → Bool
isHole (ovar nothing) = true
isHole _ = false
-- Term Intersection
--
-- Complexity analisys follows below.
{-# TERMINATING #-}
_∩_ : ∀{A} ⦃ eqA : Eq A ⦄
→ RTerm A → RTerm A → RTerm (Maybe A)
_∩_ (rapp x ax) (rapp y ay) with x ≟-RTermName y
...| no _ = ovar nothing
...| yes _ = rapp x (map (uncurry _∩_) (zip ax ay))
_∩_ (ivar x) (ivar y) with x ≟-ℕ y
...| no _ = ovar nothing
...| yes _ = ivar x
_∩_ ⦃ eq _≟_ ⦄ (ovar x) (ovar y) with x ≟ y
...| no _ = ovar nothing
...| yes _ = ovar (just x)
_∩_ (rlit x) (rlit y) with x ≟-Lit y
...| no _ = ovar nothing
...| yes _ = rlit x
_∩_ (rlam x) (rlam y) = rlam (x ∩ y)
_∩_ _ _ = ovar nothing
-- The wors case for a intersection is, of course, both terms being
-- equal. But in that case, (t ∩ t) is just a (fmap just), as we
-- can see below.
--
-- Therefore, t ∩ t ∈ O(Sₜ)
--
-- In case we have two different terms, the smaller of
-- them will make _∩_ halt. Therefore,
--
-- t ∩ u ∈ O(min(Sₜ , Sᵤ))
--
private
mutual
t∩t≡t : {A : Set}⦃ eqA : Eq A ⦄{t : RTerm A}
→ t ∩ t ≡ replace-A (ovar ∘ just) t
t∩t≡t ⦃ eq _≟_ ⦄ {t = ovar x} with x ≟ x
...| yes x≡x = refl
...| no x≢x = ⊥-elim (x≢x refl)
t∩t≡t {t = ivar n} with n ≟-ℕ n
...| yes n≡n = refl
...| no n≢n = ⊥-elim (n≢n refl)
t∩t≡t {t = rlit l} with l ≟-Lit l
...| yes l≡l = refl
...| no l≢l = ⊥-elim (l≢l refl)
t∩t≡t {A} {t = rlam t}
= trans (cong rlam (t∩t≡t {t = t}))
(sym (lemma-replace-rlam {A = A} {f = ovar ∘ just} {t = t}))
t∩t≡t {t = rapp n ts} with n ≟-RTermName n
...| no n≢n = ⊥-elim (n≢n refl)
...| yes n≡n = cong (rapp n) t∩t≡t*
t∩t≡t* : {A : Set}⦃ eqA : Eq A ⦄{ts : List (RTerm A)}
→ map (uncurry _∩_) (zip ts ts)
≡ map (replace-A (ovar ∘ just)) ts
t∩t≡t* {ts = []} = refl
t∩t≡t* {ts = t ∷ ts}
rewrite sym (t∩t≡t {t = t}) = cong (_∷_ (t ∩ t)) (t∩t≡t* {ts = ts})
-- Lifting holes.
--
-- Will translate every definition with only holes as arguments
-- into a single hole.
--
-- The worst case for lifting holes is to find a term t
-- with no holes. Therefore _↑ ∈ O(Sₜ).
{-# TERMINATING #-}
_↑ : ∀{a}{A : Set a} → RTerm (Maybe A) → RTerm (Maybe A)
_↑ (rapp x []) = rapp x []
_↑ (rapp x ax) with all isHole ax
...| true = ovar nothing
...| false = rapp x (map _↑ ax)
_↑ (rlam x) = rlam (x ↑)
_↑ t = t
-- It is commom to need only "linear" intersections;
--
-- _∩↑_ ∈ O(Sₜ + Sₜ) ≈ O(Sₜ)
--
_∩↑_ : ∀{A} ⦃ eqA : Eq A ⦄
→ RTerm A → RTerm A → RTerm (Maybe A)
v ∩↑ u = (v ∩ u) ↑
-- Casting
⊥2UnitCast : RTerm (Maybe ⊥) → RTerm Unit
⊥2UnitCast = replace-A (maybe ⊥-elim (ovar unit))
-- Converting Holes to Abstractions
--
-- Will replace holes for "var 0",
-- and increment every other non-captured variable.
--
{-# TERMINATING #-}
holeElim : ℕ → RTerm Unit → RTerm ⊥
holeElim d (ovar unit) = ivar zero
holeElim d (ivar n) with suc n ≤? d
...| yes _ = ivar n
...| no _ = ivar (suc n)
holeElim d (rlit l) = rlit l
holeElim d (rlam rt) = rlam (holeElim (suc d) rt)
holeElim d (rapp n ts) = rapp n (map (holeElim d) ts)
-- Specialized version for handling indexes.
hole2Abs : RTerm Unit → RTerm ⊥
hole2Abs = rlam ∘ holeElim 0
hole2Absℕ : RTerm Unit → RTerm ℕ
hole2Absℕ = replace-A ⊥-elim ∘ hole2Abs
open import Data.String hiding (_++_)
postulate
err : ∀{a}{A : Set a} → String → A
private
joinInner : {A : Set} → List (Maybe (List A)) → Maybe (List A)
joinInner [] = just []
joinInner (nothing ∷ _) = nothing -- err "2"
joinInner (just x ∷ xs) = maybe (λ l → just (x ++ l)) nothing (joinInner xs)
lemma-joinInner : {A : Set}{x : List A}{l : List (Maybe (List A))}
→ joinInner (just x ∷ l)
≡ maybe (λ l → just (x ++ l)) nothing (joinInner l)
lemma-joinInner = refl
-- Term Subtraction
--
-- Compelxity analisys follows below.
--
{-# TERMINATING #-}
_-_ : ∀{A} ⦃ eqA : Eq A ⦄ → RTerm (Maybe A) → RTerm A → Maybe (List (RTerm A))
hole - t = return (t ∷ [])
(rapp x ax) - (rapp y ay) with x ≟-RTermName y
...| no _ = nothing -- err "1"
...| yes _ = joinInner (map (uncurry _-_) (zip ax ay))
(rlam x) - (rlam y) = x - y
x - y with x ≟-RTerm (replace-A (ovar ∘ just) y)
...| yes _ = just []
...| no _ = nothing -- err "3"
-- Similarly to _∩_, we will prove the worst case complexity
-- based on lemma t-t≡Fvt.
-- That is, looking at term subtraction, the wors possible case
-- is that our roadmap (RTerm (Maybe A)) perfectly matches the
-- term we are looking for, and has all occurences of ovars as holes.
-- (a simple drawing might help to see this).
--
-- Well, when this is the case, our lemma tells us that
-- subtraction is the same as getting the free variables
-- and mapping ovar over them.
--
-- It is clear that we have some additional complexity on
-- the function joinInner, but we will ignore this for
-- the sake of simplicity, for now.
-- If we consider that most of the lemmas do not have more than 10
-- free variables, joinInner is of negligible run-time
-- (TODO: dangerous afirmation!!)
--
-- We'll then say that _-_ ∈ O(#Fvₜ).
--
private
fmap-nothing : {A : Set} → RTerm A → RTerm (Maybe A)
fmap-nothing = replace-A (const $ ovar nothing)
mutual
t-t≡Fvt : {A : Set}⦃ eqA : Eq A ⦄(t : RTerm A)
→ (fmap-nothing t) - t
≡ just (map ovar (Fv t))
t-t≡Fvt (ovar x) = refl
t-t≡Fvt (ivar n) with n ≟-ℕ n
...| yes n≡n = refl
...| no n≢n = ⊥-elim (n≢n refl)
t-t≡Fvt (rlit l) with l ≟-Lit l
...| yes l≡l = refl
...| no l≢l = ⊥-elim (l≢l refl)
t-t≡Fvt (rlam t) = t-t≡Fvt t
t-t≡Fvt (rapp n ts) with n ≟-RTermName n
...| yes n≡n = t-t≡Fvt* ts
...| no n≢n = ⊥-elim (n≢n refl)
t-t≡Fvt* : {A : Set}⦃ eqA : Eq A ⦄(ts : List (RTerm A))
→ joinInner (map (uncurry _-_) (zip (map fmap-nothing ts) ts))
≡ just (map ovar (concat (map Fv ts)))
t-t≡Fvt* [] = refl
t-t≡Fvt* (t ∷ ts)
rewrite t-t≡Fvt t
with joinInner (map (uncurry _-_) (zip (map fmap-nothing ts) ts))
| t-t≡Fvt* ts
t-t≡Fvt* (t ∷ ts) | nothing | ()
t-t≡Fvt* (t ∷ ts) | just .(map ovar (foldr _++_ [] (map Fv ts)))
| refl
= cong just (sym (map-++-commute ovar (Fv t) (concat (map Fv ts))))
where open import Data.List.Properties using (map-++-commute)
-- Term Subtraction, single result.
--
-- Disconsidering lazyness, (_-↓_ t) = fmap head ∘ (_-_ t)
-- Therefore, _-↓_ ∈ O(#Fvₜ).
--
_-↓_ : ∀{A} ⦃ eqA : Eq A ⦄ → RTerm (Maybe A) → RTerm A → Maybe (RTerm A)
t -↓ u with t - u
...| just [] = nothing
...| just (x ∷ _) = just x
...| nothing = nothing
-- Structural Manipulation
{-# TERMINATING #-}
map-ivar : {A : Set} → ℕ → (ℕ → RTerm A) → RTerm ⊥ → RTerm A
map-ivar _ f (ovar ())
map-ivar d f (ivar n) with d ≤? n
...| yes _ = f n
...| no _ = ivar n
map-ivar _ f (rlit l) = rlit l
map-ivar d f (rlam t) = rlam (map-ivar (suc d) f t)
map-ivar d f (rapp n ts) = rapp n (map (map-ivar d f) ts)
-- Lift ivar's to ovar's
lift-ivar : RTerm ⊥ → RTerm ℕ
lift-ivar = map-ivar 0 ovar
private
last : {A : Set} → List A → Maybe A
last [] = nothing
last (x ∷ []) = just x
last (_ ∷ xs) = last xs
strip-last : {A : Set} → List A → List A
strip-last [] = []
strip-last (x ∷ []) = []
strip-last (x ∷ xs) = x ∷ (strip-last xs)
-- last argument
larg : {B : Set} → RTerm B → Maybe (RTerm B)
larg (rapp n []) = nothing
larg (rapp n ts) = last ts
larg _ = nothing
dec : ℕ → ℕ
dec zero = zero
dec (suc x) = x
strip-larg : {B : Set} → RTerm B → RTerm B
strip-larg (rapp n ts) = rapp n (strip-last ts)
strip-larg t = t
{-# TERMINATING #-}
n-is-in : {B : Set} → ℕ → RTerm B → Bool
n-is-in n (ivar k) = dec-elim (const true) (const false) (n ≟-ℕ k)
n-is-in n (rapp _ ts) = foldr (λ h r → n-is-in n h or r) false ts
n-is-in n (rlam t) = n-is-in (suc n) t
n-is-in _ _ = false
{-# TERMINATING #-}
η : RTerm ⊥ → RTerm ⊥
η (ovar x) = ovar x
η (ivar n) = ivar n
η (rlit l) = rlit l
η (rlam t) with η t
...| t' with larg t'
...| just (ivar 0)
= if n-is-in 0 (strip-larg t')
then rlam t'
else map-ivar 0 (ivar ∘ dec) (strip-larg t')
...| _ = rlam t'
η (rapp n ts) = rapp n (map η ts)
-- Models a binary application
RBinApp : ∀{a} → Set a → Set _
RBinApp A = RTermName × RTerm A × RTerm A
-- Opens a term representing a binary application.
forceBinary : ∀{a}{A : Set a}
→ RTerm A → Maybe (RBinApp A)
forceBinary (rapp n (a₁ ∷ a₂ ∷ [])) = just (n , a₁ , a₂)
forceBinary _ = nothing
-- Given a 'impl' chain, return it's result.
typeResult : ∀{a}{A : Set a}
→ RTerm A → RTerm A
typeResult (rapp impl (t1 ∷ t2 ∷ [])) = typeResult t2
typeResult t = t
-- Gives the length of a 'impl' chain.
typeArity : ∀{a}{A : Set a} → RTerm A → ℕ
typeArity (rapp impl (t1 ∷ t2 ∷ [])) = suc (typeArity t2)
typeArity _ = 0
| 30.958904
| 80
| 0.524867
|
8bf138abe01d5f69397d5868f9c433bee8d4ca15
| 2,791
|
agda
|
Agda
|
Cubical/Experiments/ZCohomologyOld/Groups/WedgeOfSpheres.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/ZCohomologyOld/Groups/WedgeOfSpheres.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/ZCohomologyOld/Groups/WedgeOfSpheres.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Experiments.ZCohomologyOld.Groups.WedgeOfSpheres where
open import Cubical.Experiments.ZCohomologyOld.Base
open import Cubical.Experiments.ZCohomologyOld.Properties
open import Cubical.Experiments.ZCohomologyOld.Groups.Unit
open import Cubical.Experiments.ZCohomologyOld.Groups.Sn
open import Cubical.Experiments.ZCohomologyOld.Groups.Wedge
open import Cubical.Experiments.ZCohomologyOld.Groups.Connected
open import Cubical.HITs.Sn
open import Cubical.HITs.S1
open import Cubical.Foundations.Prelude
open import Cubical.HITs.Susp
open import Cubical.HITs.Wedge
open import Cubical.HITs.Pushout
open import Cubical.HITs.Truncation renaming (elim to trElim)
open import Cubical.Algebra.Group
S¹⋁S¹ : Type₀
S¹⋁S¹ = S₊∙ 1 ⋁ S₊∙ 1
S²⋁S¹⋁S¹ : Type₀
S²⋁S¹⋁S¹ = S₊∙ 2 ⋁ (S¹⋁S¹ , inl base)
------------- H⁰(S¹⋁S¹) ------------
H⁰-S¹⋁S¹ : GroupIso (coHomGr 0 S¹⋁S¹) intGroup
H⁰-S¹⋁S¹ = H⁰-connected (inl base) (wedgeConnected _ _ (Sn-connected 0) (Sn-connected 0))
------------- H¹(S¹⋁S¹) ------------
H¹-S¹⋁S¹ : GroupIso (coHomGr 1 S¹⋁S¹) (dirProd intGroup intGroup)
H¹-S¹⋁S¹ = (Hⁿ-⋁ _ _ 0) □ dirProdGroupIso coHom1S1≃ℤ coHom1S1≃ℤ
------------- H⁰(S²⋁S¹⋁S¹) ---------
H⁰-S²⋁S¹⋁S¹ : GroupIso (coHomGr 0 S²⋁S¹⋁S¹) intGroup
H⁰-S²⋁S¹⋁S¹ = H⁰-connected (inl north)
(wedgeConnected _ _
(Sn-connected 1)
(wedgeConnected _ _
(Sn-connected 0)
(Sn-connected 0)))
------------- H¹(S²⋁S¹⋁S¹) ---------
H¹-S²⋁S¹⋁S¹ : GroupIso (coHomGr 1 S²⋁S¹⋁S¹) (dirProd intGroup intGroup)
H¹-S²⋁S¹⋁S¹ =
Hⁿ-⋁ (S₊∙ 2) (S¹⋁S¹ , inl base) 0
□ dirProdGroupIso (H¹-Sⁿ≅0 0) H¹-S¹⋁S¹
□ lUnitGroupIso
------------- H²(S²⋁S¹⋁S¹) ---------
H²-S²⋁S¹⋁S¹ : GroupIso (coHomGr 2 S²⋁S¹⋁S¹) intGroup
H²-S²⋁S¹⋁S¹ =
compGroupIso
(Hⁿ-⋁ _ _ 1)
(dirProdGroupIso {B = trivialGroup}
(invGroupIso (Hⁿ-Sⁿ≅ℤ 1))
((Hⁿ-⋁ _ _ 1) □ dirProdGroupIso (Hⁿ-S¹≅0 0) (Hⁿ-S¹≅0 0) □ rUnitGroupIso)
□ rUnitGroupIso)
private
open import Cubical.Data.Int
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
to₂ : coHom 2 S²⋁S¹⋁S¹ → Int
to₂ = GroupHom.fun (GroupIso.map H²-S²⋁S¹⋁S¹)
from₂ : Int → coHom 2 S²⋁S¹⋁S¹
from₂ = GroupIso.inv H²-S²⋁S¹⋁S¹
to₁ : coHom 1 S²⋁S¹⋁S¹ → Int × Int
to₁ = GroupHom.fun (GroupIso.map H¹-S²⋁S¹⋁S¹)
from₁ : Int × Int → coHom 1 S²⋁S¹⋁S¹
from₁ = GroupIso.inv H¹-S²⋁S¹⋁S¹
to₀ : coHom 0 S²⋁S¹⋁S¹ → Int
to₀ = GroupHom.fun (GroupIso.map H⁰-S²⋁S¹⋁S¹)
from₀ : Int → coHom 0 S²⋁S¹⋁S¹
from₀ = GroupIso.inv H⁰-S²⋁S¹⋁S¹
{-
-- Computes (a lot slower than for the torus)
test : to₁ (from₁ (1 , 0) +ₕ from₁ (0 , 1)) ≡ (1 , 1)
test = refl
-- Does not compute:
test2 : to₂ (from₂ 0) ≡ 0
test2 = refl
-}
| 31.359551
| 89
| 0.651379
|
a0e026bb9c1aa1872d184687aa1606ea78dafe39
| 1,762
|
agda
|
Agda
|
Cubical/Data/Strict2Group/Explicit/Notation.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/Data/Strict2Group/Explicit/Notation.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
Cubical/Data/Strict2Group/Explicit/Notation.agda
|
Schippmunk/cubical
|
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Strict2Group.Explicit.Notation where
open import Cubical.Foundations.Prelude hiding (comp)
open import Cubical.Data.Group.Base
module S2GBaseNotation {ℓ : Level} (C₀ C₁ : Group ℓ) (s t : morph C₁ C₀) (i : morph C₀ C₁) (∘ : (g f : Group.type C₁) → (s .fst) g ≡ (t .fst f) → Group.type C₁) where
-- group operations of the object group
TC₀ = Group.type C₀
1₀ = isGroup.id (Group.groupStruc C₀)
_∙₀_ = isGroup.comp (Group.groupStruc C₀)
C₀⁻¹ = isGroup.inv (Group.groupStruc C₀)
rUnit₀ = isGroup.rUnit (Group.groupStruc C₀)
lUnit₀ = isGroup.lUnit (Group.groupStruc C₀)
assoc₀ = isGroup.assoc (Group.groupStruc C₀)
lCancel₀ = isGroup.lCancel (Group.groupStruc C₀)
rCancel₀ = isGroup.lCancel (Group.groupStruc C₀)
-- group operation of the morphism group
TC₁ = Group.type C₁
1₁ = isGroup.id (Group.groupStruc C₁)
C₁⁻¹ = isGroup.inv (Group.groupStruc C₁)
_∙₁_ = isGroup.comp (Group.groupStruc C₁)
rUnit₁ = isGroup.rUnit (Group.groupStruc C₁)
lUnit₁ = isGroup.lUnit (Group.groupStruc C₁)
assoc₁ = isGroup.assoc (Group.groupStruc C₁)
lCancel₁ = isGroup.lCancel (Group.groupStruc C₁)
rCancel₁ = isGroup.lCancel (Group.groupStruc C₁)
-- interface for source, target and identity map
src = fst s
src∙₁ = snd s
tar = fst t
tar∙₁ = snd t
id = fst i
id∙₀ = snd i
∙c : {g f g' f' : Group.type C₁} → (coh1 : s .fst g ≡ t .fst f) → (coh2 : s .fst g' ≡ t .fst f') → s .fst (g ∙₁ g') ≡ t .fst (f ∙₁ f')
∙c {g} {f} {g'} {f'} coh1 coh2 = (s .snd g g') ∙ ((cong (_∙₀ (s .fst g')) coh1) ∙ (cong ((t .fst f) ∙₀_) coh2) ∙ (sym (t .snd f f')))
-- for two morphisms the condition for them to be composable
CohCond : (g f : TC₁) → Type ℓ
CohCond g f = src g ≡ tar f
| 38.304348
| 166
| 0.654938
|
8bcdf4d14f7c174e0f1416a7c5e8855a3750a2bd
| 88
|
agda
|
Agda
|
test/Succeed/Issue5363.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue5363.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue5363.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
open import Agda.Primitive
variable
A : Set _
levelOf : A → Level
levelOf {a} _ = a
| 11
| 26
| 0.670455
|
1ee3b7c85d5ad571157aa99355376c0f43e357bf
| 3,435
|
agda
|
Agda
|
Cubical/Data/List/Dependent.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Data/List/Dependent.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Data/List/Dependent.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
open import Cubical.Foundations.Everything renaming (Iso to _≅_)
open import Cubical.Data.List
open import Cubical.Data.Unit
open import Cubical.Data.Prod hiding (map)
open import Cubical.Data.Nat
module Cubical.Data.List.Dependent where
open _≅_
data ListP {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) : (as : List A) → Type (ℓ-max ℓA ℓB) where
[] : ListP B []
_∷_ : {x : A} (y : B x) {xs : List A} (ys : ListP B xs) → ListP B (x ∷ xs)
-- Represent ListP via known operations in order to derive properties more easily.
RepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → Type (ℓ-max ℓA ℓB)
RepListP B [] = Lift Unit
RepListP B (a ∷ as) = B a × RepListP B as
isoRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≅ RepListP B as
fun (isoRepListP B []) bs = lift tt
inv (isoRepListP B []) u = []
rightInv (isoRepListP B []) u = refl
leftInv (isoRepListP B []) [] = refl
fun (isoRepListP B (a ∷ as)) (b ∷ bs) = b , fun (isoRepListP B as) bs
inv (isoRepListP B (a ∷ as)) (b , br) = b ∷ inv (isoRepListP B as) br
rightInv (isoRepListP B (a ∷ as)) (b , br) i = b , rightInv (isoRepListP B as) br i
leftInv (isoRepListP B (a ∷ as)) (b ∷ bs) i = b ∷ leftInv (isoRepListP B as) bs i
equivRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≃ RepListP B as
equivRepListP B as = isoToEquiv (isoRepListP B as)
pathRepListP : ∀ {ℓA ℓB} {A : Type ℓA} (B : A → Type ℓB) (as : List A) → ListP B as ≡ RepListP B as
pathRepListP B as = ua (equivRepListP B as)
private
isOfHLevelSucSuc-RepListP : ∀ {ℓA ℓB} (n : HLevel)
→ {A : Type ℓA}
→ {B : A → Type ℓB} → ((a : A) → isOfHLevel (suc (suc n)) (B a))
→ (as : List A)
→ isOfHLevel (suc (suc n)) (RepListP B as)
isOfHLevelSucSuc-RepListP n isHB [] = isOfHLevelLift (suc (suc n)) (isOfHLevelUnit (suc (suc n)))
isOfHLevelSucSuc-RepListP n isHB (a ∷ as) = isOfHLevelProd (suc (suc n)) (isHB a) (isOfHLevelSucSuc-RepListP n isHB as)
isOfHLevelSucSuc-ListP : ∀ {ℓA ℓB} (n : HLevel)
→ {A : Type ℓA}
→ {B : A → Type ℓB} → ((a : A) → isOfHLevel (suc (suc n)) (B a))
→ {as : List A}
→ isOfHLevel (suc (suc n)) (ListP B as)
isOfHLevelSucSuc-ListP n {A} {B} isHB {as} =
subst⁻ (isOfHLevel (suc (suc n))) (pathRepListP B as) (isOfHLevelSucSuc-RepListP n isHB as)
--------------------------
mapP : ∀ {ℓA ℓA' ℓB ℓB'} {A : Type ℓA} {A' : Type ℓA'} {B : A → Type ℓB} {B' : A' → Type ℓB'}
(f : A → A') (g : (a : A) → B a → B' (f a)) → ∀ as → ListP B as → ListP B' (map f as)
mapP f g [] [] = []
mapP f g (a ∷ as) (b ∷ bs) = g _ b ∷ mapP f g as bs
mapOverIdfun : ∀ {ℓA ℓB ℓB'} {A : Type ℓA} {B : A → Type ℓB} {B' : A → Type ℓB'}
(g : (a : A) → B a → B' a) → ∀ as → ListP B as → ListP B' as
mapOverIdfun g [] [] = []
mapOverIdfun g (a ∷ as) (b ∷ bs) = g a b ∷ mapOverIdfun g as bs
mapOverIdfun-idfun : ∀ {ℓA ℓB} {A : Type ℓA} {B : A → Type ℓB} as → mapOverIdfun (λ a → idfun _) as ≡ (idfun (ListP B as))
mapOverIdfun-idfun [] i [] = []
mapOverIdfun-idfun (a ∷ as) i (b ∷ bs) = b ∷ mapOverIdfun-idfun as i bs
mapOverIdfun-∘ : ∀ {ℓA ℓB ℓB' ℓB''} {A : Type ℓA} {B : A → Type ℓB} {B' : A → Type ℓB'} {B'' : A → Type ℓB''}
(h : (a : A) → B' a → B'' a) (g : (a : A) → B a → B' a) → ∀ as
→ mapOverIdfun (λ a → h a ∘ g a) as ≡ mapOverIdfun h as ∘ mapOverIdfun g as
mapOverIdfun-∘ h g [] i [] = []
mapOverIdfun-∘ h g (a ∷ as) i (b ∷ bs) = h a (g a b) ∷ mapOverIdfun-∘ h g as i bs
| 44.61039
| 122
| 0.578166
|
593062074f05cf20e7700abc546bea7167cd6e05
| 9,400
|
agda
|
Agda
|
src/Dodo/Binary/SplittableOrder.agda
|
sourcedennis/agda-dodo
|
376f0ccee1e1aa31470890e494bcb534324f598a
|
[
"BSD-3-Clause"
] | null | null | null |
src/Dodo/Binary/SplittableOrder.agda
|
sourcedennis/agda-dodo
|
376f0ccee1e1aa31470890e494bcb534324f598a
|
[
"BSD-3-Clause"
] | null | null | null |
src/Dodo/Binary/SplittableOrder.agda
|
sourcedennis/agda-dodo
|
376f0ccee1e1aa31470890e494bcb534324f598a
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.SplittableOrder where
-- Stdlib imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open import Level using (Level; _⊔_)
open import Function using (_∘_)
open import Data.Empty using (⊥-elim)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂; ∃-syntax)
open import Relation.Nullary using (¬_)
open import Relation.Unary using (Pred)
open import Relation.Binary using (Rel; REL; Transitive; Trichotomous; Tri; tri<; tri≈; tri>)
open import Relation.Binary.Construct.Closure.Transitive using (TransClosure; [_]; _∷_; _++_)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Binary.Equality
open import Dodo.Binary.Immediate
open import Dodo.Binary.Trichotomous
open import Dodo.Binary.Transitive
open import Dodo.Binary.Domain
open import Dodo.Binary.Filter
open import Function using (flip)
-- # Definitions #
-- For any `R x y` there exists a /path/ from `x` to `y`.
SplittableOrder : {a ℓ : Level} {A : Set a} (R : Rel A ℓ) → Set (a ⊔ ℓ)
SplittableOrder R = R ⇔₂ TransClosure (immediate R)
-- # Properties #
module _ {a ℓ : Level} {A : Set a} {R : Rel A ℓ} where
splittable-trans : SplittableOrder R → Transitive R
splittable-trans splitR Rij Rjk =
⇔₂-apply-⊇₂ splitR (⇔₂-apply-⊆₂ splitR Rij ++ ⇔₂-apply-⊆₂ splitR Rjk)
splittable-flip : SplittableOrder R → SplittableOrder (flip R)
splittable-flip splitR = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : flip R ⊆₂' TransClosure (immediate (flip R))
⊆-proof _ _ = ⁺-map _ imm-flip ∘ ⁺-flip ∘ ⇔₂-apply-⊆₂ splitR
⊇-proof : TransClosure (immediate (flip R)) ⊆₂' flip R
⊇-proof _ _ = ⇔₂-apply-⊇₂ splitR ∘ ⁺-flip ∘ ⁺-map _ imm-flip
-- # Operations #
-- Split the left-most element from the ordered relation chain
splitˡ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ {x y : A}
→ R x y
--------------------------------------------------
→ immediate R x y ⊎ ∃[ z ] (immediate R x z × R z y)
splitˡ splitR Rxy with ⇔₂-apply-⊆₂ splitR Rxy
... | [ immRxy ] = inj₁ immRxy
... | _∷_ {x} {z} {y} immRxz immR⁺zy = inj₂ (z , immRxz , ⇔₂-apply-⊇₂ splitR immR⁺zy)
-- Split the right-most element from the ordered relation chain
splitʳ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ {x y : A}
→ R x y
--------------------------------------------------
→ immediate R x y ⊎ ∃[ z ] (R x z × immediate R z y)
splitʳ {A = A} {R = R} splitR Rxy = lemma (⇔₂-apply-⊆₂ splitR Rxy)
where
lemma : ∀ {x y : A} → TransClosure (immediate R) x y → immediate R x y ⊎ ∃[ z ] (R x z × immediate R z y)
lemma [ immRxy ] = inj₁ immRxy
lemma ( _∷_ {x} {z} {y} immRxz immR⁺zy ) with lemma immR⁺zy
... | inj₁ immRzy = inj₂ (z , proj₁ immRxz , immRzy)
... | inj₂ (w , Rzw , immRwy) = inj₂ (w , splittable-trans splitR (proj₁ immRxz) Rzw , immRwy)
-- Splits the given left-most element from the chain.
unsplitˡ : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a} {_≈_ : Rel A ℓ₁} {R : Rel A ℓ₂}
→ Trichotomous _≈_ R
→ SplittableOrder R
→ {x y z : A}
→ R x z
→ immediate R x y
→ y ≈ z ⊎ R y z
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy with splitˡ splitR Rxz
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₁ immRxz = inj₁ (tri-immʳ triR immRxy immRxz)
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) with triR y z
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) | tri< Ryz y≢z ¬Rzy = inj₂ Ryz
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) | tri≈ ¬Ryz y≡z ¬Rzy = inj₁ y≡z
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) | tri> ¬Ryz y≢z Rzy = ⊥-elim (proj₂ immRxy (z , Rxz , [ Rzy ]))
-- Splits the given right-most element from the chain.
unsplitʳ : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a} {_≈_ : Rel A ℓ₁} {R : Rel A ℓ₂}
→ Trichotomous _≈_ R
→ SplittableOrder R
→ {x y z : A}
→ R x z
→ immediate R y z
→ x ≈ y ⊎ R x y
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz with splitʳ splitR Rxz
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₁ iRxz = inj₁ (tri-immˡ triR iRxz iRyz)
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) with triR x y
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) | tri< Rxy x≢y ¬Ryx = inj₂ Rxy
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) | tri≈ ¬Rxy x≡y ¬Ryx = inj₁ x≡y
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) | tri> ¬Rxy x≢y Ryx = ⊥-elim (proj₂ iRyz (x , Ryx , [ Rxz ]))
splittable-imm-udr : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ udr R ⇔₁ udr (immediate R)
splittable-imm-udr {R = R} splitR = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : udr R ⊆₁' udr (immediate R)
⊆-proof x (inj₁ (y , Rxy)) = inj₁ (⁺-dom (⇔₂-apply-⊆₂ splitR Rxy))
⊆-proof y (inj₂ (x , Rxy)) = inj₂ (⁺-codom (⇔₂-apply-⊆₂ splitR Rxy))
⊇-proof : udr (immediate R) ⊆₁' udr R
⊇-proof x (inj₁ (y , Rxy)) = inj₁ (y , proj₁ Rxy)
⊇-proof y (inj₂ (x , Rxy)) = inj₂ (x , proj₁ Rxy)
-- | If any value in the chain of R satisfies P, it remains splittable after lifting.
--
-- The chain is traversed /to the left/.
filter-splittableˡ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ (P : Pred A ℓ)
→ (∀ {x y : A} → P y → R x y → P x)
---------------------------------
→ SplittableOrder (filter-rel P R)
filter-splittableˡ {A = A} {R = R} splitR P f = ⇔: ⊆-proof ⊇-proof
where
lemma⊆-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate R x y → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
lemma⊆-imm {x} {y} Px Py (Rxy , ¬∃z) = Rxy , ¬∃z'
where
¬∃z' : ¬ (∃[ z ] filter-rel P R (with-pred x Px) z × TransClosure (filter-rel P R) z (with-pred y Py))
¬∃z' (with-pred z Pz , Rxz , R⁺zy) = ¬∃z (z , Rxz , ⁺-strip-filter R⁺zy)
lemma⊆ : ∀ {x y : A} → (Px : P x) → (Py : P y) → TransClosure (immediate R) x y
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
lemma⊆ Px Py [ iRxy ] = [ lemma⊆-imm Px Py iRxy ]
lemma⊆ Px Py ( iRxz ∷ iR⁺zy ) =
let Pz = ⁺-predˡ (λ Pz → f Pz ∘ proj₁) iR⁺zy Py
in lemma⊆-imm Px Pz iRxz ∷ lemma⊆ Pz Py iR⁺zy
⊆-proof : filter-rel P R ⊆₂' TransClosure (immediate (filter-rel P R))
⊆-proof (with-pred x Px) (with-pred y Py) Rxy = lemma⊆ Px Py (⇔₂-apply-⊆₂ splitR Rxy)
lemma⊇-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
→ immediate R x y
lemma⊇-imm {x} {y} Px Py (Rxy , ¬∃z) = (Rxy , ¬∃z')
where
¬∃z' : ¬ (∃[ z ] R x z × TransClosure R z y)
¬∃z' (z , Rxz , R⁺zy) =
let Pz = ⁺-predˡ f R⁺zy Py
in ¬∃z (with-pred z Pz , Rxz , ⁺-filter-relˡ f Pz Py R⁺zy)
lemma⊇ : ∀ {x y : A} → (Px : P x) → (Py : P y)
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
→ TransClosure (immediate R) x y
lemma⊇ Px Py [ iRxy ] = [ lemma⊇-imm Px Py iRxy ]
lemma⊇ Px Py ( _∷_ {_} {with-pred z Pz} iRxz iR⁺zy ) = lemma⊇-imm Px Pz iRxz ∷ lemma⊇ Pz Py iR⁺zy
⊇-proof : TransClosure (immediate (filter-rel P R)) ⊆₂' filter-rel P R
⊇-proof (with-pred x Px) (with-pred y Py) Rxy = ⇔₂-apply-⊇₂ splitR (lemma⊇ Px Py Rxy)
-- | If any value in the chain of R satisfies P, it remains splittable after lifting.
--
-- The chain is traversed /to the right/.
filter-splittableʳ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ (P : Pred A ℓ)
→ (∀ {x y : A} → P x → R x y → P y)
---------------------------------
→ SplittableOrder (filter-rel P R)
filter-splittableʳ {A = A} {R = R} splitR P f = ⇔: ⊆-proof ⊇-proof
where
lemma⊆-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate R x y → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
lemma⊆-imm {x} {y} Px Py (Rxy , ¬∃z) = Rxy , ¬∃z'
where
¬∃z' : ¬ (∃[ z ] filter-rel P R (with-pred x Px) z × TransClosure (filter-rel P R) z (with-pred y Py))
¬∃z' (with-pred z Pz , Rxz , R⁺zy) = ¬∃z (z , Rxz , ⁺-strip-filter R⁺zy)
lemma⊆ : ∀ {x y : A} → (Px : P x) → (Py : P y) → TransClosure (immediate R) x y
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
lemma⊆ Px Py [ iRxy ] = [ lemma⊆-imm Px Py iRxy ]
lemma⊆ Px Py ( iRxz ∷ iR⁺zy ) =
let Pz = f Px (proj₁ iRxz)
in lemma⊆-imm Px Pz iRxz ∷ lemma⊆ Pz Py iR⁺zy
⊆-proof : filter-rel P R ⊆₂' TransClosure (immediate (filter-rel P R))
⊆-proof (with-pred x Px) (with-pred y Py) Rxy = lemma⊆ Px Py (⇔₂-apply-⊆₂ splitR Rxy)
lemma⊇-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
→ immediate R x y
lemma⊇-imm {x} {y} Px Py (Rxy , ¬∃z) = Rxy , ¬∃z'
where
¬∃z' : ¬ (∃[ z ] R x z × TransClosure R z y)
¬∃z' (z , Rxz , R⁺zy) =
let Pz = f Px Rxz
in ¬∃z (with-pred z Pz , Rxz , ⁺-filter-relʳ f Pz Py R⁺zy)
lemma⊇ : ∀ {x y : A} → (Px : P x) → (Py : P y)
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
→ TransClosure (immediate R) x y
lemma⊇ Px Py [ iRxy ] = [ lemma⊇-imm Px Py iRxy ]
lemma⊇ Px Py ( _∷_ {_} {with-pred z Pz} iRxz iR⁺zy ) = lemma⊇-imm Px Pz iRxz ∷ lemma⊇ Pz Py iR⁺zy
⊇-proof : TransClosure (immediate (filter-rel P R)) ⊆₂' filter-rel P R
⊇-proof (with-pred x Px) (with-pred y Py) Rxy = ⇔₂-apply-⊇₂ splitR (lemma⊇ Px Py Rxy)
| 42.533937
| 134
| 0.583617
|
2e51af9035330a1af8ab4e4881007ca9eb9b0c38
| 2,472
|
agda
|
Agda
|
src/Categories/Category/Restriction/Instance/PartialFunctions.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Category/Restriction/Instance/PartialFunctions.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Category/Restriction/Instance/PartialFunctions.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Restriction.Instance.PartialFunctions where
-- The Category of partial functions is a restriction category
-- The proof is straightforward in the sense that it's all unwinding definitions,
-- but also no-trivial in that they need to be unwound with care (a lot of
-- case analyses with 'with' and inspect is used a lot).
open import Data.Maybe using (Maybe; map; just; nothing; _>>=_)
open import Data.Maybe.Properties
open import Function using (const)
open import Level using (Level)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; inspect; [_])
open import Categories.Category.Core using (Category)
open import Categories.Category.Instance.PartialFunctions using (PartialFunctions)
open import Categories.Category.Restriction using (Restriction)
private
variable
o : Level
A B C : Set o
Restriction-PF : ∀ {o} → Restriction (PartialFunctions o)
Restriction-PF {o} = record
{ _↓ = λ f x → map (const x) (f x)
; pidʳ = pidʳ
; ↓-comm = λ {_} {_} {_} {g} {f} → ↓-comm {g = g} {f}
; ↓-denestʳ = λ {_} {_} {_} {f} {g} → ↓-denestʳ {f = f} {g}
; ↓-skew-comm = λ {_} {_} {_} {g} {f} → ↓-skew-comm {g = g} {f}
; ↓-cong = ↓-cong
}
where
open Category (PartialFunctions o)
_↓ : (A → Maybe B) → (A → Maybe A)
_↓ = λ f x → map (const x) (f x)
pidʳ : {f : A → Maybe B} → f ∘ f ↓ ≈ f
pidʳ {f = f} x with f x | inspect f x
... | just z | [ eq ] = eq
... | nothing | _ = refl
↓-comm : {g : A → Maybe C} {f : A → Maybe B} → g ↓ ∘ f ↓ ≈ f ↓ ∘ g ↓
↓-comm {g = g} {f} x with f x | g x | inspect f x | inspect g x
... | just b | just b′ | [ fx=jb ] | [ gx=jb′ ] rewrite fx=jb | gx=jb′ = refl
... | just b | nothing | _ | [ eq ] rewrite eq = refl
... | nothing | just b′ | [ eq ] | _ rewrite eq = refl
... | nothing | nothing | _ | _ = refl
↓-denestʳ : {A B C : Obj} {f : A ⇒ B} {g : A ⇒ C} → (g ∘ f ↓) ↓ ≈ g ↓ ∘ f ↓
↓-denestʳ {f = f} a with f a
... | just b = refl
... | nothing = refl
↓-skew-comm : {A B C : Obj} {g : A ⇒ B} {f : C ⇒ A} → g ↓ ∘ f ≈ f ∘ (g ∘ f) ↓
↓-skew-comm {g = g} {f = f} a with f a | inspect f a
... | just b | [ eq ] with g b
... | just c = sym eq
... | nothing = refl
↓-skew-comm _ | nothing | _ = refl
↓-cong : {A B : Obj} {f g : A ⇒ B} → f ≈ g → f ↓ ≈ g ↓
↓-cong eq a rewrite eq a = refl
| 38.030769
| 86
| 0.544094
|
9a5c09d751baaa7d2597f60773898aba9bbd6428
| 419
|
agda
|
Agda
|
test/Fail/Issue1615.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue1615.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue1615.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
-- {-# OPTIONS -v tc.term:20 -v tc.meta.assign:10 -v tc.conv.coerce:10 #-}
{-# OPTIONS --sized-types #-}
open import Common.Size
data Nat (i : Size) : Set where
suc : (j : Size< i) → Nat j → Nat i
min : ∀ i → Nat i → Nat i → Nat i
min i (suc j n) (suc k m) = suc i' (min i' n m)
where i' = _
-- Size consistency check should not be circumvented
-- by putting the meta in a definition.
| 23.277778
| 74
| 0.606205
|
2953a1619ec45b7b5f0a190e8b66d5cfc7ab0dc4
| 30,989
|
agda
|
Agda
|
Cubical/Algebra/Matrix/RowTransformation.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Matrix/RowTransformation.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Matrix/RowTransformation.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-
Technical results about row transformation applied to matrices
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Matrix.RowTransformation where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Data.Nat hiding (_+_ ; _·_)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Data.FinData renaming (znots to znotsFin ; snotz to snotzFin)
open import Cubical.Relation.Nullary
open import Cubical.Algebra.Matrix
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.Algebra.Matrix.CommRingCoefficient
private
variable
ℓ : Level
A : Type ℓ
m n k l : ℕ
takeRows : FinMatrix A (suc (suc m)) n → FinMatrix A 2 n
takeRows M zero = M zero
takeRows M one = M one
takeRowsᶜ : FinMatrix A (suc (suc m)) n → FinMatrix A (suc m) n
takeRowsᶜ M zero = M zero
takeRowsᶜ M (suc i) = M (suc (suc i))
combRows : FinMatrix A (suc (suc m)) n → FinMatrix A 2 n → FinMatrix A (suc m) n
combRows M M₀ zero = M₀ zero
combRows M M₀ (suc i) = M (suc (suc i))
shufRows : FinMatrix A 2 n → FinMatrix A (suc m) n → FinMatrix A (suc (suc m)) n
shufRows M₀ M₁ zero = M₁ zero
shufRows M₀ M₁ one = M₀ one
shufRows M₀ M₁ (suc (suc i)) = M₁ (suc i)
module _
(T₀ : FinMatrix A 2 n → FinMatrix A 2 n)
(M : FinMatrix A (suc (suc m)) n) where
private
M₀ = T₀ (takeRows M)
takeTrans : FinMatrix A (suc (suc m)) n
takeTrans zero = M₀ zero
takeTrans one = M₀ one
takeTrans (suc (suc i)) = M (suc (suc i))
module _
(T₁ : FinMatrix A (suc m) n → FinMatrix A (suc m) n)
(M : FinMatrix A (suc (suc m)) n) where
private
M₁ = T₁ (takeRowsᶜ M)
combTrans : FinMatrix A (suc (suc m)) n
combTrans zero = M₁ zero
combTrans one = M one
combTrans (suc (suc i)) = M₁ (suc i)
module _
(T₀ : FinMatrix A 2 n → FinMatrix A 2 n)
(T₁ : FinMatrix A (suc m) n → FinMatrix A (suc m) n)
(M : FinMatrix A (suc (suc m)) n) where
private
M₀ = T₀ (takeRows M)
M₁ = T₁ (combRows M M₀)
helper : takeRowsᶜ (takeTrans T₀ M) ≡ combRows M M₀
helper t zero = M₀ zero
helper t (suc i) = M (suc (suc i))
takeCombShufRows : FinMatrix A (suc (suc m)) n
takeCombShufRows = shufRows M₀ M₁
takeCombShufEquiv : combTrans T₁ (takeTrans T₀ M) ≡ takeCombShufRows
takeCombShufEquiv t zero = T₁ (helper t) zero
takeCombShufEquiv t one = M₀ one
takeCombShufEquiv t (suc (suc i)) = T₁ (helper t) (suc i)
-- The iterated row transformation
module _
(T : FinMatrix A 2 n → FinMatrix A 2 n) where
transRows : FinMatrix A (suc m) n → FinMatrix A (suc m) n
transRows {m = 0} M = M
transRows {m = suc m} = takeCombShufRows T transRows
-- Several induction principle to prove properties after transformation
module _
(invRow : (M : FinMatrix A 2 n) → M zero ≡ T M zero) where
invRow₀ : (M : FinMatrix A (suc m) n) → M zero ≡ transRows M zero
invRow₀ {m = 0} _ = refl
invRow₀ {m = suc m} M = invRow _ ∙ invRow₀ (combRows M _)
module _
(P : FinVec A n → Type ℓ)
(indP : (M : FinMatrix A 2 n) → P (M zero) → P (T M zero)) where
transRowsIndP : (M : FinMatrix A (suc m) n) → P (M zero) → P (transRows M zero)
transRowsIndP {m = 0} _ h = h
transRowsIndP {m = suc m} M h = transRowsIndP (combRows M _) (indP _ h)
module _
(P : FinVec A n → Type ℓ)
(indP : (M : FinMatrix A 2 n) → P (T M one)) where
transRowsIndP' : (M : FinMatrix A (suc m) n) → (i : Fin m) → P (transRows M (suc i))
transRowsIndP' {m = suc m} M zero = indP _
transRowsIndP' {m = suc m} M (suc i) = transRowsIndP' _ i
module _
(Q : FinVec A n → Type ℓ)
(P : FinVec A n → Type ℓ)
(indQ : (M : FinMatrix A 2 n) → Q (M zero) → Q (T M zero))
(indP : (M : FinMatrix A 2 n) → Q (M zero) → P (T M one )) where
transRowsIndPQ : (M : FinMatrix A (suc m) n) → Q (M zero) → (i : Fin m) → P (transRows M (suc i))
transRowsIndPQ {m = suc m} M p zero = indP _ p
transRowsIndPQ {m = suc m} M p (suc i) = transRowsIndPQ _ (indQ _ p) i
module _
(Q : FinVec A n → Type ℓ)
(P : FinVec A n → Type ℓ)
(indQ : (M : FinMatrix A 2 n) → Q (M zero) → Q (T M zero))
(indP : (M : FinMatrix A 2 n) → P (M one ) → Q (T M zero)) where
transRowsIndPQ' : (M : FinMatrix A (suc m) n) → (i : Fin m) → P (M (suc i)) → Q (transRows M zero)
transRowsIndPQ' {m = suc m} M zero p = transRowsIndP Q indQ (combRows M _) (indP _ p)
transRowsIndPQ' {m = suc m} M (suc i) p = transRowsIndPQ' (combRows M _) _ p
module _
(Rel : FinVec A n → FinVec A n → Type ℓ)
(indRel : (M : FinMatrix A 2 n) → Rel (M one) (T M one)) where
transRowsIndRel : (M : FinMatrix A (suc m) n) → (i : Fin m) → Rel (M (suc i)) (transRows M (suc i))
transRowsIndRel {m = suc m} M zero = indRel _
transRowsIndRel {m = suc m} M (suc i) = transRowsIndRel _ i
module _
(Rel3 : FinVec A n → FinVec A n → FinVec A n → Type ℓ)
(invRow : (M : FinMatrix A 2 n) → M zero ≡ T M zero)
(indRel3 : (M : FinMatrix A 2 n) → Rel3 (M zero) (M one) (T M one)) where
transRowsIndRel3 : (M : FinMatrix A (suc m) n) → (i : Fin m) → Rel3 (M zero) (M (suc i)) (transRows M (suc i))
transRowsIndRel3 {m = suc m} M zero = indRel3 _
transRowsIndRel3 {m = suc m} M (suc i) =
subst (λ V → Rel3 V (M (suc (suc i)))
(transRows M (suc (suc i)))) (sym (invRow _)) (transRowsIndRel3 _ i)
module _
(Rel : FinVec A n → FinVec A n → Type ℓ)
(indRel : (M : FinMatrix A 2 n) → Rel (M zero) (M one) → M zero ≡ T M zero) where
transRowsIndRelInv :
(M : FinMatrix A (suc m) n)
→ ((i : Fin m) → Rel (M zero) (M (suc i)))
→ M zero ≡ transRows M zero
transRowsIndRelInv {m = 0} _ _ = refl
transRowsIndRelInv {m = suc m} M rel =
let invRow = indRel _ (rel zero)
rel₁ = (λ i → subst (λ V → Rel V (M (suc (suc i)))) invRow (rel (suc i)))
in invRow ∙ transRowsIndRelInv _ rel₁
module _
(P : FinVec A n → Type ℓ)
(Rel : FinVec A n → FinVec A n → Type ℓ)
(indPRel : (M : FinMatrix A 2 n) → P (M zero) → Rel (M zero) (M one) → M zero ≡ T M zero) where
transRowsIndPRelInv :
(M : FinMatrix A (suc m) n)
→ P (M zero)
→ ((i : Fin m) → Rel (M zero) (M (suc i)))
→ M zero ≡ transRows M zero
transRowsIndPRelInv {m = 0} _ _ _ = refl
transRowsIndPRelInv {m = suc m} M p rel =
let invRow = indPRel _ p (rel zero)
p₁ = subst P invRow p
rel₁ = (λ i → subst (λ V → Rel V (M (suc (suc i)))) invRow (rel (suc i)))
in invRow ∙ transRowsIndPRelInv _ p₁ rel₁
module _
(P : FinVec A n → Type ℓ)
(indP₀ : (M : FinMatrix A 2 n) → P (M zero) → P (M one) → P (T M zero))
(indP₁ : (M : FinMatrix A 2 n) → P (M zero) → P (M one) → P (T M one )) where
transRowsIndP₀ :
(M : FinMatrix A (suc m) n)
→ P (M zero)
→ ((i : Fin m) → P (M (suc i)))
→ P (transRows M zero)
transRowsIndP₀ {m = 0} _ p _ = p
transRowsIndP₀ {m = suc m} _ p q = transRowsIndP₀ _ (indP₀ _ p (q zero)) (q ∘ suc)
transRowsIndP₁ :
(M : FinMatrix A (suc m) n)
→ P (M zero)
→ ((i : Fin m) → P (M (suc i)))
→ (i : Fin m) → P (transRows M (suc i))
transRowsIndP₁ {m = 0} _ _ q = q
transRowsIndP₁ {m = suc m} _ p q zero = indP₁ _ p (q zero)
transRowsIndP₁ {m = suc m} M p q (suc i) = transRowsIndP₁ _ (indP₀ _ p (q zero)) (q ∘ suc) i
-- Row transformation of linear coefficient matrices
module LinearTransformation (𝓡 : CommRing ℓ) where
private
R = 𝓡 .fst
𝑹 = CommRing→Ring 𝓡
AbR = Ring→AbGroup 𝑹
open CommRingStr (𝓡 .snd) renaming ( is-set to isSetR )
open CommRingTheory 𝓡
open RingTheory 𝑹
open KroneckerDelta 𝑹
open Sum 𝑹
open Coefficient 𝓡
-- Definition of linear transformation
record isLinear2×2 (T : Mat 2 n → Mat 2 n) : Type ℓ where
field
transMat : (M : Mat 2 n) → Mat 2 2
transEq : (M : Mat 2 n) → T M ≡ transMat M ⋆ M
record isLinear (T : Mat m n → Mat k n) : Type ℓ where
field
transMat : (M : Mat m n) → Mat k m
transEq : (M : Mat m n) → T M ≡ transMat M ⋆ M
open isLinear2×2
open isLinear
isLinearId : isLinear {m = m} {n = n} (idfun _)
isLinearId .transMat _ = 𝟙
isLinearId .transEq _ = sym (⋆lUnit _)
isInvId : (M : Mat (suc m) (suc n)) → isInv (isLinearId .transMat M)
isInvId _ = isInv𝟙
module _
{T₁ : Mat (suc m) (suc n) → Mat (suc k) (suc n)}
{T₂ : Mat (suc k) (suc n) → Mat (suc l) (suc n)}
(isLinearT₁ : isLinear T₁)
(isLinearT₂ : isLinear T₂) where
isLinearComp : isLinear (T₂ ∘ T₁)
isLinearComp .transMat M =
let T₁M = isLinearT₁ .transMat M in
isLinearT₂ .transMat (T₁ M) ⋆ T₁M
isLinearComp .transEq M =
isLinearT₂ .transEq _
∙ (λ t → isLinearT₂ .transMat (T₁ M) ⋆ (isLinearT₁ .transEq M t))
∙ ⋆Assoc (isLinearT₂ .transMat _) (isLinearT₁ .transMat M) M
module _
{T₁ : Mat (suc m) (suc n) → Mat (suc m) (suc n)}
{T₂ : Mat (suc m) (suc n) → Mat (suc m) (suc n)}
(isLinearT₁ : isLinear T₁)
(isLinearT₂ : isLinear T₂) where
module _
(isInvT₁ : (M : Mat (suc m) (suc n)) → isInv (isLinearT₁ .transMat M))
(isInvT₂ : (M : Mat (suc m) (suc n)) → isInv (isLinearT₂ .transMat M)) where
isInvComp : (M : Mat (suc m) (suc n)) → isInv (isLinearComp isLinearT₁ isLinearT₂ .transMat M)
isInvComp M =
let T₁M = isLinearT₁ .transMat M in
isInv⋆ {M = isLinearT₂ .transMat (T₁ M)} {M' = T₁M} (isInvT₂ (T₁ M)) (isInvT₁ M)
module _
(P : FinVec R (suc n) → Type ℓ)
(indP : (M : Mat (suc m) (suc n)) → P (M zero) → P (T₁ M zero))
(isInvT₁ : (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearT₁ .transMat M))
(isInvT₂ : (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearT₂ .transMat M)) where
isInvCompInd : (M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearComp isLinearT₁ isLinearT₂ .transMat M)
isInvCompInd M p =
let T₁M = isLinearT₁ .transMat M in
isInv⋆ {M = isLinearT₂ .transMat (T₁ M)} {M' = T₁M} (isInvT₂ (T₁ M) (indP _ p)) (isInvT₁ M p)
-- Linearity of row transformation
takeTransMat : Mat 2 2 → Mat (suc (suc m)) (suc (suc m))
takeTransMat P zero zero = P zero zero
takeTransMat P one zero = P one zero
takeTransMat P zero one = P zero one
takeTransMat P one one = P one one
takeTransMat _ zero (suc (suc j)) = 0r
takeTransMat _ one (suc (suc j)) = 0r
takeTransMat _ (suc (suc i)) zero = 0r
takeTransMat _ (suc (suc i)) one = 0r
takeTransMat _ (suc (suc i)) (suc (suc j)) = 𝟙 i j
takeTransMat𝟙 : takeTransMat {m = m} 𝟙 ≡ 𝟙
takeTransMat𝟙 t zero zero = 1r
takeTransMat𝟙 t one zero = 0r
takeTransMat𝟙 t zero one = 0r
takeTransMat𝟙 t one one = 1r
takeTransMat𝟙 t zero (suc (suc j)) = 0r
takeTransMat𝟙 t one (suc (suc j)) = 0r
takeTransMat𝟙 t (suc (suc i)) zero = 0r
takeTransMat𝟙 t (suc (suc i)) one = 0r
takeTransMat𝟙 t (suc (suc i)) (suc (suc j)) = δ i j
module _
(M N : Mat 2 2) where
⋆TakeTransMat : takeTransMat M ⋆ takeTransMat N ≡ takeTransMat {m = m} (M ⋆ N)
⋆TakeTransMat {m = m} t zero zero =
M zero zero · N zero zero + (M zero one · N one zero + ∑Mul0r {n = m} (λ i → 0r) t)
⋆TakeTransMat {m = m} t one zero =
M one zero · N zero zero + (M one one · N one zero + ∑Mul0r {n = m} (λ i → 0r) t)
⋆TakeTransMat {m = m} t zero one =
M zero zero · N zero one + (M zero one · N one one + ∑Mul0r {n = m} (λ i → 0r) t)
⋆TakeTransMat {m = m} t one one =
M one zero · N zero one + (M one one · N one one + ∑Mul0r {n = m} (λ i → 0r) t)
⋆TakeTransMat t zero (suc (suc j)) =
(helper (M zero zero) (M zero one ) _ ∙ ∑Mul0r (λ i → 𝟙 i j)) t
where helper : (a b c : R) → a · 0r + (b · 0r + c) ≡ c
helper = solve 𝓡
⋆TakeTransMat t one (suc (suc j)) =
(helper (M one zero) (M one one ) _ ∙ ∑Mul0r (λ i → 𝟙 i j)) t
where helper : (a b c : R) → a · 0r + (b · 0r + c) ≡ c
helper = solve 𝓡
⋆TakeTransMat t (suc (suc i)) zero =
(helper (N zero zero) (N one zero) _ ∙ ∑Mulr0 (λ j → 𝟙 i j)) t
where helper : (a b c : R) → 0r · a + (0r · b + c) ≡ c
helper = solve 𝓡
⋆TakeTransMat t (suc (suc i)) one =
(helper (N zero one ) (N one one ) _ ∙ ∑Mulr0 (λ j → 𝟙 i j)) t
where helper : (a b c : R) → 0r · a + (0r · b + c) ≡ c
helper = solve 𝓡
⋆TakeTransMat t (suc (suc i)) (suc (suc j)) =
(helper _
∙ (λ t → ⋆lUnit 𝟙 t i j)) t
where helper : (c : R) → 0r · 0r + (0r · 0r + c) ≡ c
helper = solve 𝓡
module _
(T₀ : Mat 2 (suc n) → Mat 2 (suc n))
(isLinear2×2T₀ : isLinear2×2 T₀) where
module _
(M : Mat (suc (suc m)) (suc n)) where
private
P = isLinear2×2T₀ .transMat (takeRows M)
takeTransEquiv : takeTrans T₀ M ≡ takeTransMat P ⋆ M
takeTransEquiv t zero j =
((λ t → isLinear2×2T₀ .transEq (takeRows M) t zero j)
∙ mul2 P (takeRows M) _ _
∙ helper _ _
∙ (λ t → P zero zero · M zero j + (P zero one · M one j
+ ∑Mul0r (λ i → M (suc (suc i)) j) (~ t)))) t
where helper : (a b : R) → a + b ≡ a + (b + 0r)
helper = solve 𝓡
takeTransEquiv t one j =
((λ t → isLinear2×2T₀ .transEq (takeRows M) t one j)
∙ mul2 P (takeRows M) _ _
∙ helper _ _
∙ (λ t → P one zero · M zero j + (P one one · M one j
+ ∑Mul0r (λ i → M (suc (suc i)) j) (~ t)))) t
where helper : (a b : R) → a + b ≡ a + (b + 0r)
helper = solve 𝓡
takeTransEquiv t (suc (suc i)) j =
((λ t → ⋆lUnit (λ i j → M (suc (suc i)) j) (~ t) i j)
∙ helper (M zero j) (M one j) _) t
where helper : (a b c : R) → c ≡ 0r · a + (0r · b + c)
helper = solve 𝓡
isLinearTakeRowsTrans : isLinear (takeTrans {m = m} T₀)
isLinearTakeRowsTrans .transMat M = takeTransMat _
isLinearTakeRowsTrans .transEq = takeTransEquiv
isInvTakeTransMat : (M : Mat 2 2)(isInvM : isInv M) → isInv (takeTransMat {m = m} M)
isInvTakeTransMat M isInvM .fst = takeTransMat (isInvM .fst)
isInvTakeTransMat M isInvM .snd .fst =
⋆TakeTransMat _ _ ∙ (λ t → takeTransMat (isInvM .snd .fst t)) ∙ takeTransMat𝟙
isInvTakeTransMat M isInvM .snd .snd =
⋆TakeTransMat _ _ ∙ (λ t → takeTransMat (isInvM .snd .snd t)) ∙ takeTransMat𝟙
combTransMat : Mat (suc m) (suc m) → Mat (suc (suc m)) (suc (suc m))
combTransMat P zero zero = P zero zero
combTransMat _ zero one = 0r
combTransMat _ one zero = 0r
combTransMat _ one one = 1r
combTransMat P zero (suc (suc j)) = P zero (suc j)
combTransMat _ one (suc (suc j)) = 0r
combTransMat P (suc (suc i)) zero = P (suc i) zero
combTransMat _ (suc (suc i)) one = 0r
combTransMat P (suc (suc i)) (suc (suc j)) = P (suc i) (suc j)
combTransMat𝟙 : combTransMat {m = m} 𝟙 ≡ 𝟙
combTransMat𝟙 t zero zero = 1r
combTransMat𝟙 t zero one = 0r
combTransMat𝟙 t one zero = 0r
combTransMat𝟙 t one one = 1r
combTransMat𝟙 t zero (suc (suc j)) = 0r
combTransMat𝟙 t one (suc (suc j)) = 0r
combTransMat𝟙 t (suc (suc i)) zero = 0r
combTransMat𝟙 t (suc (suc i)) one = 0r
combTransMat𝟙 t (suc (suc i)) (suc (suc j)) = δ i j
module _
(M N : Mat (suc m) (suc m)) where
⋆CombTransMat : combTransMat M ⋆ combTransMat N ≡ combTransMat (M ⋆ N)
⋆CombTransMat t zero zero =
helper (M zero zero · N zero zero) (∑ (λ l → M zero (suc l) · N (suc l) zero)) t
where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c
helper = solve 𝓡
⋆CombTransMat t zero one =
(helper (M zero zero) _ ∙ ∑Mulr0 (λ j → M zero (suc j))) t
where helper : (a c : R) → a · 0r + (0r · 1r + c) ≡ c
helper = solve 𝓡
⋆CombTransMat t one zero =
(helper (N zero zero) _ ∙ ∑Mul0r (λ i → N (suc i) zero)) t
where helper : (a c : R) → 0r · a + (1r · 0r + c) ≡ c
helper = solve 𝓡
⋆CombTransMat t one one =
((λ t → 0r · 0r + (1r · 1r + ∑Mul0r {n = m} (λ i → 0r) t))
∙ helper) t
where helper : 0r · 0r + (1r · 1r + 0r) ≡ 1r
helper = solve 𝓡
⋆CombTransMat t zero (suc (suc j)) =
helper (M zero zero · N zero (suc j)) (∑ (λ l → M zero (suc l) · N (suc l) (suc j))) t
where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c
helper = solve 𝓡
⋆CombTransMat t one (suc (suc j)) =
(helper (N zero (suc j)) _ ∙ ∑Mul0r (λ i → N (suc i) (suc j))) t
where helper : (a c : R) → 0r · a + (1r · 0r + c) ≡ c
helper = solve 𝓡
⋆CombTransMat t (suc (suc i)) zero =
helper (M (suc i) zero · N zero zero) (∑ (λ l → M (suc i) (suc l) · N (suc l) zero)) t
where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c
helper = solve 𝓡
⋆CombTransMat t (suc (suc i)) one =
(helper (M (suc i) zero) _ ∙ ∑Mulr0 (λ j → M (suc i) (suc j))) t
where helper : (a c : R) → a · 0r + (0r · 1r + c) ≡ c
helper = solve 𝓡
⋆CombTransMat t (suc (suc i)) (suc (suc j)) =
helper (M (suc i) zero · N zero (suc j)) (∑ (λ l → M (suc i) (suc l) · N (suc l) (suc j))) t
where helper : (a c : R) → a + (0r · 0r + c) ≡ a + c
helper = solve 𝓡
module _
(T₁ : Mat (suc m) (suc n) → Mat (suc m) (suc n))
(isLinearT₁ : isLinear T₁) where
module _
(M : Mat (suc (suc m)) (suc n)) where
private
P = isLinearT₁ .transMat (takeRowsᶜ M)
combTransEquiv : combTrans T₁ M ≡ combTransMat P ⋆ M
combTransEquiv t zero j =
((λ t → isLinearT₁ .transEq (takeRowsᶜ M) t zero j)
∙ helper _ (M one j) _) t
where helper : (a b c : R) → a + c ≡ a + (0r · b + c)
helper = solve 𝓡
combTransEquiv t one j =
(helper _ _
∙ (λ t → 0r · M zero j + (1r · M one j
+ ∑Mul0r (λ i → M (suc (suc i)) j) (~ t)))) t
where helper : (a b : R) → b ≡ 0r · a + (1r · b + 0r)
helper = solve 𝓡
combTransEquiv t (suc (suc i)) j =
((λ t → isLinearT₁ .transEq (takeRowsᶜ M) t (suc i) j)
∙ helper _ (M one j) _) t
where helper : (a b c : R) → a + c ≡ a + (0r · b + c)
helper = solve 𝓡
isLinearCombRowsTrans : isLinear (combTrans T₁)
isLinearCombRowsTrans .transMat M = combTransMat _
isLinearCombRowsTrans .transEq = combTransEquiv
isInvCombTransMat : (M : Mat (suc m) (suc m))(isInvM : isInv M) → isInv (combTransMat M)
isInvCombTransMat M isInvM .fst = combTransMat (isInvM .fst)
isInvCombTransMat M isInvM .snd .fst =
⋆CombTransMat _ _ ∙ (λ t → combTransMat (isInvM .snd .fst t)) ∙ combTransMat𝟙
isInvCombTransMat M isInvM .snd .snd =
⋆CombTransMat _ _ ∙ (λ t → combTransMat (isInvM .snd .snd t)) ∙ combTransMat𝟙
module _
{T₁ : Mat 2 (suc n) → Mat 2 (suc n)}
{T₂ : Mat (suc m) (suc n) → Mat (suc m) (suc n)}
(isLinearT₁ : isLinear2×2 T₁)
(isLinearT₂ : isLinear T₂) where
private
compL = isLinearComp (isLinearTakeRowsTrans _ isLinearT₁) (isLinearCombRowsTrans _ isLinearT₂)
isLinearTakeCombShufRows : isLinear (takeCombShufRows {m = m} T₁ T₂)
isLinearTakeCombShufRows .transMat = compL .transMat
isLinearTakeCombShufRows .transEq M = sym (takeCombShufEquiv _ _ _) ∙ compL .transEq _
module _
(T : Mat 2 (suc n) → Mat 2 (suc n))
(isLinear2×2T : isLinear2×2 T) where
isLinearTransRows : (m : ℕ) → isLinear (transRows T {m = m})
isLinearTransRows 0 = isLinearId
isLinearTransRows (suc m) = isLinearTakeCombShufRows isLinear2×2T (isLinearTransRows m)
module _
(isInvT : (M : Mat 2 (suc n)) → isInv (isLinear2×2T .transMat M)) where
isInvTransRows : (M : Mat (suc m) (suc n)) → isInv (isLinearTransRows _ .transMat M)
isInvTransRows {m = 0} _ = isInv𝟙
isInvTransRows {m = suc m} M =
isInv⋆ {M = combTransMat _} {M' = takeTransMat _}
(isInvCombTransMat _ (isInvTransRows _))
(isInvTakeTransMat _ (isInvT _))
module _
(P : FinVec R (suc n) → Type ℓ)
(indP : (M : Mat 2 (suc n)) → P (M zero) → P (T M zero))
(isInvT : (M : Mat 2 (suc n)) → P (M zero) → isInv (isLinear2×2T .transMat M)) where
isInvTransRowsInd :
(M : Mat (suc m) (suc n)) → P (M zero) → isInv (isLinearTransRows _ .transMat M)
isInvTransRowsInd {m = 0} M _ = isInvId M
isInvTransRowsInd {m = suc m} M p =
isInv⋆ {M = combTransMat _} {M' = takeTransMat _}
(isInvCombTransMat _ (isInvTransRowsInd _ (indP _ p)))
(isInvTakeTransMat _ (isInvT _ p))
-- Some useful properties of 2-rows transformation
symδ : (i j : Fin m) → δ i j ≡ δ j i
symδ zero zero = refl
symδ zero (suc _) = refl
symδ (suc _) zero = refl
symδ (suc i) (suc j) = symδ i j
diagδ : (i j : Fin m)(p : i ≡ j) → δ i j ≡ 1r
diagδ zero zero _ = refl
diagδ (suc _) zero p = Empty.rec (snotzFin p)
diagδ zero (suc _) p = Empty.rec (znotsFin p)
diagδ (suc i) (suc j) p = diagδ _ _ (injSucFin p)
skewδ : (i j : Fin m)(p : ¬ i ≡ j) → δ i j ≡ 0r
skewδ zero zero p = Empty.rec (p refl)
skewδ (suc _) zero _ = refl
skewδ zero (suc _) _ = refl
skewδ (suc i) (suc j) p = skewδ _ _ (λ r → p (cong suc r))
diagSet : (i₀ : Fin m)(a : R) → Mat m m
diagSet {m = suc m} zero a zero zero = a
diagSet {m = suc m} zero _ (suc i) zero = 0r
diagSet {m = suc m} zero _ zero (suc j) = 0r
diagSet {m = suc m} zero _ (suc i) (suc j) = δ i j
diagSet {m = suc m} (suc i₀) _ zero zero = 1r
diagSet {m = suc m} (suc i₀) _ (suc i) zero = 0r
diagSet {m = suc m} (suc i₀) _ zero (suc j) = 0r
diagSet {m = suc m} (suc i₀) a (suc i) (suc j) = diagSet i₀ a i j
diagSet≡diagSetᵗ : (i₀ : Fin m)(a : R) → diagSet i₀ a ≡ (diagSet i₀ a)ᵗ
diagSet≡diagSetᵗ {m = suc m} zero a t zero zero = a
diagSet≡diagSetᵗ {m = suc m} zero _ t (suc i) zero = 0r
diagSet≡diagSetᵗ {m = suc m} zero _ t zero (suc j) = 0r
diagSet≡diagSetᵗ {m = suc m} zero _ t (suc i) (suc j) = symδ i j t
diagSet≡diagSetᵗ {m = suc m} (suc i₀) _ t zero zero = 1r
diagSet≡diagSetᵗ {m = suc m} (suc i₀) _ t (suc i) zero = 0r
diagSet≡diagSetᵗ {m = suc m} (suc i₀) _ t zero (suc j) = 0r
diagSet≡diagSetᵗ {m = suc m} (suc i₀) a t (suc i) (suc j) = diagSet≡diagSetᵗ i₀ a t i j
diagSet1≡𝟙 : (i₀ : Fin m) → diagSet i₀ 1r ≡ 𝟙
diagSet1≡𝟙 {m = suc m} zero t zero zero = 1r
diagSet1≡𝟙 {m = suc m} zero t (suc i) zero = 0r
diagSet1≡𝟙 {m = suc m} zero t zero (suc j) = 0r
diagSet1≡𝟙 {m = suc m} zero t (suc i) (suc j) = δ i j
diagSet1≡𝟙 {m = suc m} (suc i₀) t zero zero = 1r
diagSet1≡𝟙 {m = suc m} (suc i₀) t (suc i) zero = 0r
diagSet1≡𝟙 {m = suc m} (suc i₀) t zero (suc j) = 0r
diagSet1≡𝟙 {m = suc m} (suc i₀) t (suc i) (suc j) = diagSet1≡𝟙 i₀ t i j
module _
(a b c : R) where
·DiagSetˡ : (i₀ : Fin m)(i : Fin m) → a · δ i₀ i + diagSet i₀ b i i₀ · c ≡ (a + (b · c + 0r)) · δ i₀ i
·DiagSetˡ {m = suc m} zero zero = helper _ _ _
where helper : (a b c : R) → a · 1r + b · c ≡ (a + (b · c + 0r)) · 1r
helper = solve 𝓡
·DiagSetˡ {m = suc m} (suc i₀) zero = helper _ _ _
where helper : (a b c : R) → a · 0r + 0r · c ≡ (a + (b · c + 0r)) · 0r
helper = solve 𝓡
·DiagSetˡ {m = suc m} zero (suc j) = helper _ _ _
where helper : (a b c : R) → a · 0r + 0r · c ≡ (a + (b · c + 0r)) · 0r
helper = solve 𝓡
·DiagSetˡ {m = suc m} (suc i₀) (suc j) = ·DiagSetˡ i₀ j
·DiagSetʳ : (i₀ : Fin m)(i : Fin m) → a · δ i₀ i + b · diagSet i₀ c i₀ i ≡ (a + (b · c + 0r)) · δ i₀ i
·DiagSetʳ {m = suc m} zero zero = helper _ _ _
where helper : (a b c : R) → a · 1r + b · c ≡ (a + (b · c + 0r)) · 1r
helper = solve 𝓡
·DiagSetʳ {m = suc m} (suc i₀) zero = helper _ _ _
where helper : (a b c : R) → a · 0r + b · 0r ≡ (a + (b · c + 0r)) · 0r
helper = solve 𝓡
·DiagSetʳ {m = suc m} zero (suc j) = helper _ _ _
where helper : (a b c : R) → a · 0r + b · 0r ≡ (a + (b · c + 0r)) · 0r
helper = solve 𝓡
·DiagSetʳ {m = suc m} (suc i₀) (suc j) = ·DiagSetʳ i₀ j
module _
(a b : R) where
⋆DiagSet : (i₀ : Fin m) → diagSet i₀ a ⋆ diagSet i₀ b ≡ diagSet i₀ (a · b)
⋆DiagSet {m = suc m} zero t zero zero =
((λ t → a · b + ∑Mul0r {n = m} (λ i → 0r) t) ∙ helper _) t
where helper : (a : R) → a + 0r ≡ a
helper = solve 𝓡
⋆DiagSet {m = suc m} zero t (suc i) zero =
((λ t → 0r · b + ∑Mulr0 (λ j → diagSet zero a (suc i) (suc j)) t) ∙ helper _) t
where helper : (b : R) → 0r · b + 0r ≡ 0r
helper = solve 𝓡
⋆DiagSet {m = suc m} zero t zero (suc j) =
((λ t → a · 0r + ∑Mul0r (λ i → diagSet zero b (suc i) (suc j)) t) ∙ helper _) t
where helper : (a : R) → a · 0r + 0r ≡ 0r
helper = solve 𝓡
⋆DiagSet {m = suc m} zero t (suc i) (suc j) =
((λ t → 0r · 0r + ∑Mulr1 _ (λ l → δ i l) j t) ∙ helper _) t
where helper : (d : R) → 0r · 0r + d ≡ d
helper = solve 𝓡
⋆DiagSet {m = suc m} (suc i₀) t zero zero =
((λ t → 1r · 1r + ∑Mul0r {n = m} (λ i → 0r) t) ∙ helper) t
where helper : 1r · 1r + 0r ≡ 1r
helper = solve 𝓡
⋆DiagSet {m = suc m} (suc i₀) t (suc i) zero =
((λ t → 0r · 1r + ∑Mulr0 (λ j → diagSet (suc i₀) a (suc i) (suc j)) t) ∙ helper) t
where helper : 0r · 1r + 0r ≡ 0r
helper = solve 𝓡
⋆DiagSet {m = suc m} (suc i₀) t zero (suc j) =
((λ t → 1r · 0r + ∑Mul0r (λ i → diagSet (suc i₀) b (suc i) (suc j)) t) ∙ helper) t
where helper : 1r · 0r + 0r ≡ 0r
helper = solve 𝓡
⋆DiagSet {m = suc m} (suc i₀) t (suc i) (suc j) =
((λ t → 0r · 0r + ⋆DiagSet i₀ t i j) ∙ helper _) t
where helper : (a : R) → 0r · 0r + a ≡ a
helper = solve 𝓡
module _
(a b c : R) where
+DiagSet :
(i₀ i j : Fin m)
→ (a · δ i₀ i) · (b · δ i₀ j) + diagSet i₀ c i j ≡ diagSet i₀ (a · b + (c + 0r)) i j
+DiagSet {m = suc m} zero zero zero = helper _ _ _
where helper : (a b c : R) → (a · 1r) · (b · 1r) + c ≡ a · b + (c + 0r)
helper = solve 𝓡
+DiagSet {m = suc m} zero (suc i) zero = helper _ _
where helper : (a b : R) → (a · 0r) · (b · 1r) + 0r ≡ 0r
helper = solve 𝓡
+DiagSet {m = suc m} zero zero (suc j) = helper _ _
where helper : (a b : R) → (a · 1r) · (b · 0r) + 0r ≡ 0r
helper = solve 𝓡
+DiagSet {m = suc m} zero (suc i) (suc j) = helper _ _ _
where helper : (a b d : R) → (a · 0r) · (b · 0r) + d ≡ d
helper = solve 𝓡
+DiagSet {m = suc m} (suc i₀) zero zero = helper _ _
where helper : (a b : R) → (a · 0r) · (b · 0r) + 1r ≡ 1r
helper = solve 𝓡
+DiagSet {m = suc m} (suc i₀) (suc i) zero = helper _ _
where helper : (a b : R) → a · (b · 0r) + 0r ≡ 0r
helper = solve 𝓡
+DiagSet {m = suc m} (suc i₀) zero (suc j) = helper _ _
where helper : (a b : R) → (a · 0r) · b + 0r ≡ 0r
helper = solve 𝓡
+DiagSet {m = suc m} (suc i₀) (suc i) (suc j) = +DiagSet i₀ i j
module _
(M : Mat 2 2)(i₀ : Fin m) where
trans2RowsMat : Mat (suc m) (suc m)
trans2RowsMat zero zero = M zero zero
trans2RowsMat (suc i) zero = M one zero · δ i₀ i
trans2RowsMat zero (suc j) = M zero one · δ i₀ j
trans2RowsMat (suc i) (suc j) = diagSet i₀ (M one one) i j
module _
(i₀ : Fin m) where
trans2RowsMat𝟙 : trans2RowsMat 𝟙 i₀ ≡ 𝟙
trans2RowsMat𝟙 t zero zero = 1r
trans2RowsMat𝟙 t (suc i) zero = 0LeftAnnihilates (δ i₀ i) t
trans2RowsMat𝟙 t zero (suc j) = 0LeftAnnihilates (δ i₀ j) t
trans2RowsMat𝟙 t (suc i) (suc j) = diagSet1≡𝟙 i₀ t i j
module _
(M N : Mat 2 2)(i₀ : Fin m) where
private
∑helper00 : (x a b : R) → x + ∑(λ l → (a · δ i₀ l) · (b · δ i₀ l)) ≡ x + a · b
∑helper00 x a b =
(λ t → x + ∑(λ l → helper a b (δ i₀ l) (δ i₀ l) t))
∙ (λ t → x + ∑Mul1r _ (λ l → (δ i₀ l · (a · b))) i₀ t)
∙ (λ t → x + diagδ i₀ i₀ refl t · (a · b))
∙ (λ t → x + ·IdL (a · b) t)
where helper : (a b x y : R) → (a · x) · (b · y) ≡ x · (y · (a · b))
helper = solve 𝓡
∑helper10 :
(a b c : R)(K : Mat m m)(i : Fin m)
→ (a · δ i₀ i) · b + ∑ (λ l → K i l · (c · δ i₀ l)) ≡ (a · b) · δ i₀ i + K i i₀ · c
∑helper10 a b c K i =
(λ t → helper1 a b (δ i₀ i) t + ∑ (λ l → helper2 (K i l) c (δ i₀ l) t))
∙ (λ t → (a · b) · δ i₀ i + ∑Mul1r _ (λ l → K i l · c) i₀ t)
where helper1 : (a b c : R) → (a · c) · b ≡ (a · b) · c
helper1 = solve 𝓡
helper2 : (a b c : R) → a · (b · c) ≡ c · (a · b)
helper2 = solve 𝓡
∑helper01 :
(a b c : R)(K : Mat m m)(i : Fin m)
→ a · (b · δ i₀ i) + ∑ (λ l → (c · δ i₀ l) · K l i) ≡ (a · b) · δ i₀ i + c · K i₀ i
∑helper01 a b c K i =
(λ t → helper1 a b (δ i₀ i) t + ∑ (λ l → helper2 c (K l i) (δ i₀ l) t))
∙ (λ t → (a · b) · δ i₀ i + ∑Mul1r _ (λ l → c · K l i) i₀ t)
where helper1 : (a b c : R) → a · (b · c) ≡ (a · b) · c
helper1 = solve 𝓡
helper2 : (a b c : R) → (a · c) · b ≡ c · (a · b)
helper2 = solve 𝓡
⋆Trans2RowsMat : trans2RowsMat M i₀ ⋆ trans2RowsMat N i₀ ≡ trans2RowsMat (M ⋆ N) i₀
⋆Trans2RowsMat t zero zero =
(∑helper00 _ _ _ ∙ sym (mul2 M N zero zero)) t
⋆Trans2RowsMat t (suc i) zero =
(∑helper10 (M one zero) (N zero zero)
(N one zero) (diagSet i₀ (M one one)) i
∙ ·DiagSetˡ _ _ _ i₀ i) t
⋆Trans2RowsMat t zero (suc j) =
(∑helper01 (M zero zero) (N zero one)
(M zero one ) (diagSet i₀ (N one one)) j
∙ ·DiagSetʳ _ _ _ i₀ j) t
⋆Trans2RowsMat t (suc i) (suc j) =
((λ t → (M one zero · δ i₀ i) · (N zero one · δ i₀ j)
+ ⋆DiagSet (M one one) (N one one) i₀ t i j)
∙ +DiagSet _ _ _ i₀ i j) t
isInvTrans2RowsMat : (M : Mat 2 2)(i₀ : Fin m)(isInvM : isInv M) → isInv (trans2RowsMat M i₀)
isInvTrans2RowsMat M i₀ isInvM .fst = trans2RowsMat (isInvM .fst) i₀
isInvTrans2RowsMat M i₀ isInvM .snd .fst =
⋆Trans2RowsMat _ _ _ ∙ (λ t → trans2RowsMat (isInvM .snd .fst t) i₀) ∙ trans2RowsMat𝟙 _
isInvTrans2RowsMat M i₀ isInvM .snd .snd =
⋆Trans2RowsMat _ _ _ ∙ (λ t → trans2RowsMat (isInvM .snd .snd t) i₀) ∙ trans2RowsMat𝟙 _
| 40.141192
| 116
| 0.54187
|
c7b993a3d87351aa69afd5b8945dbcf48f71d06d
| 7,607
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Algebra/Properties/BooleanAlgebra/Expression.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Algebra/Properties/BooleanAlgebra/Expression.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Algebra/Properties/BooleanAlgebra/Expression.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Boolean algebra expressions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.BooleanAlgebra.Expression
{b} (B : BooleanAlgebra b b)
where
open BooleanAlgebra B
open import Category.Applicative
import Category.Applicative.Indexed as Applicative
open import Category.Monad
open import Data.Fin using (Fin)
open import Data.Nat
open import Data.Product using (_,_; proj₁; proj₂)
open import Data.Vec as Vec using (Vec)
import Data.Vec.Categorical as VecCat
import Function.Identity.Categorical as IdCat
open import Data.Vec.Properties using (lookup-map)
open import Data.Vec.Relation.Binary.Pointwise.Extensional as PW
using (Pointwise; ext)
open import Function
open import Relation.Binary.PropositionalEquality as P using (_≗_)
import Relation.Binary.Reflection as Reflection
-- Expressions made up of variables and the operations of a boolean
-- algebra.
infixr 7 _and_
infixr 6 _or_
data Expr n : Set b where
var : (x : Fin n) → Expr n
_or_ _and_ : (e₁ e₂ : Expr n) → Expr n
not : (e : Expr n) → Expr n
top bot : Expr n
-- The semantics of an expression, parametrised by an applicative
-- functor.
module Semantics
{F : Set b → Set b}
(A : RawApplicative F)
where
open RawApplicative A
⟦_⟧ : ∀ {n} → Expr n → Vec (F Carrier) n → F Carrier
⟦ var x ⟧ ρ = Vec.lookup ρ x
⟦ e₁ or e₂ ⟧ ρ = pure _∨_ ⊛ ⟦ e₁ ⟧ ρ ⊛ ⟦ e₂ ⟧ ρ
⟦ e₁ and e₂ ⟧ ρ = pure _∧_ ⊛ ⟦ e₁ ⟧ ρ ⊛ ⟦ e₂ ⟧ ρ
⟦ not e ⟧ ρ = pure ¬_ ⊛ ⟦ e ⟧ ρ
⟦ top ⟧ ρ = pure ⊤
⟦ bot ⟧ ρ = pure ⊥
-- flip Semantics.⟦_⟧ e is natural.
module Naturality
{F₁ F₂ : Set b → Set b}
{A₁ : RawApplicative F₁}
{A₂ : RawApplicative F₂}
(f : Applicative.Morphism A₁ A₂)
where
open P.≡-Reasoning
open Applicative.Morphism f
open Semantics A₁ renaming (⟦_⟧ to ⟦_⟧₁)
open Semantics A₂ renaming (⟦_⟧ to ⟦_⟧₂)
open RawApplicative A₁ renaming (pure to pure₁; _⊛_ to _⊛₁_)
open RawApplicative A₂ renaming (pure to pure₂; _⊛_ to _⊛₂_)
natural : ∀ {n} (e : Expr n) → op ∘ ⟦ e ⟧₁ ≗ ⟦ e ⟧₂ ∘ Vec.map op
natural (var x) ρ = begin
op (Vec.lookup ρ x) ≡⟨ P.sym $ lookup-map x op ρ ⟩
Vec.lookup (Vec.map op ρ) x ∎
natural (e₁ or e₂) ρ = begin
op (pure₁ _∨_ ⊛₁ ⟦ e₁ ⟧₁ ρ ⊛₁ ⟦ e₂ ⟧₁ ρ) ≡⟨ op-⊛ _ _ ⟩
op (pure₁ _∨_ ⊛₁ ⟦ e₁ ⟧₁ ρ) ⊛₂ op (⟦ e₂ ⟧₁ ρ) ≡⟨ P.cong₂ _⊛₂_ (op-⊛ _ _) P.refl ⟩
op (pure₁ _∨_) ⊛₂ op (⟦ e₁ ⟧₁ ρ) ⊛₂ op (⟦ e₂ ⟧₁ ρ) ≡⟨ P.cong₂ _⊛₂_ (P.cong₂ _⊛₂_ (op-pure _) (natural e₁ ρ))
(natural e₂ ρ) ⟩
pure₂ _∨_ ⊛₂ ⟦ e₁ ⟧₂ (Vec.map op ρ) ⊛₂ ⟦ e₂ ⟧₂ (Vec.map op ρ) ∎
natural (e₁ and e₂) ρ = begin
op (pure₁ _∧_ ⊛₁ ⟦ e₁ ⟧₁ ρ ⊛₁ ⟦ e₂ ⟧₁ ρ) ≡⟨ op-⊛ _ _ ⟩
op (pure₁ _∧_ ⊛₁ ⟦ e₁ ⟧₁ ρ) ⊛₂ op (⟦ e₂ ⟧₁ ρ) ≡⟨ P.cong₂ _⊛₂_ (op-⊛ _ _) P.refl ⟩
op (pure₁ _∧_) ⊛₂ op (⟦ e₁ ⟧₁ ρ) ⊛₂ op (⟦ e₂ ⟧₁ ρ) ≡⟨ P.cong₂ _⊛₂_ (P.cong₂ _⊛₂_ (op-pure _) (natural e₁ ρ))
(natural e₂ ρ) ⟩
pure₂ _∧_ ⊛₂ ⟦ e₁ ⟧₂ (Vec.map op ρ) ⊛₂ ⟦ e₂ ⟧₂ (Vec.map op ρ) ∎
natural (not e) ρ = begin
op (pure₁ ¬_ ⊛₁ ⟦ e ⟧₁ ρ) ≡⟨ op-⊛ _ _ ⟩
op (pure₁ ¬_) ⊛₂ op (⟦ e ⟧₁ ρ) ≡⟨ P.cong₂ _⊛₂_ (op-pure _) (natural e ρ) ⟩
pure₂ ¬_ ⊛₂ ⟦ e ⟧₂ (Vec.map op ρ) ∎
natural top ρ = begin
op (pure₁ ⊤) ≡⟨ op-pure _ ⟩
pure₂ ⊤ ∎
natural bot ρ = begin
op (pure₁ ⊥) ≡⟨ op-pure _ ⟩
pure₂ ⊥ ∎
-- An example of how naturality can be used: Any boolean algebra can
-- be lifted, in a pointwise manner, to vectors of carrier elements.
lift : ℕ → BooleanAlgebra b b
lift n = record
{ Carrier = Vec Carrier n
; _≈_ = Pointwise _≈_
; _∨_ = zipWith _∨_
; _∧_ = zipWith _∧_
; ¬_ = map ¬_
; ⊤ = pure ⊤
; ⊥ = pure ⊥
; isBooleanAlgebra = record
{ isDistributiveLattice = record
{ isLattice = record
{ isEquivalence = PW.isEquivalence isEquivalence
; ∨-comm = λ _ _ → ext λ i →
solve i 2 (λ x y → x or y , y or x)
(∨-comm _ _) _ _
; ∨-assoc = λ _ _ _ → ext λ i →
solve i 3
(λ x y z → (x or y) or z , x or (y or z))
(∨-assoc _ _ _) _ _ _
; ∨-cong = λ xs≈us ys≈vs → ext λ i →
solve₁ i 4 (λ x y u v → x or y , u or v)
_ _ _ _
(∨-cong (Pointwise.app xs≈us i)
(Pointwise.app ys≈vs i))
; ∧-comm = λ _ _ → ext λ i →
solve i 2 (λ x y → x and y , y and x)
(∧-comm _ _) _ _
; ∧-assoc = λ _ _ _ → ext λ i →
solve i 3
(λ x y z → (x and y) and z ,
x and (y and z))
(∧-assoc _ _ _) _ _ _
; ∧-cong = λ xs≈ys us≈vs → ext λ i →
solve₁ i 4 (λ x y u v → x and y , u and v)
_ _ _ _
(∧-cong (Pointwise.app xs≈ys i)
(Pointwise.app us≈vs i))
; absorptive =
(λ _ _ → ext λ i →
solve i 2 (λ x y → x or (x and y) , x) (∨-absorbs-∧ _ _) _ _) ,
(λ _ _ → ext λ i →
solve i 2 (λ x y → x and (x or y) , x) (∧-absorbs-∨ _ _) _ _)
}
; ∨-∧-distribʳ = λ _ _ _ → ext λ i →
solve i 3
(λ x y z → (y and z) or x ,
(y or x) and (z or x))
(∨-∧-distribʳ _ _ _) _ _ _
}
; ∨-complementʳ = λ _ → ext λ i →
solve i 1 (λ x → x or (not x) , top)
(∨-complementʳ _) _
; ∧-complementʳ = λ _ → ext λ i →
solve i 1 (λ x → x and (not x) , bot)
(∧-complementʳ _) _
; ¬-cong = λ xs≈ys → ext λ i →
solve₁ i 2 (λ x y → not x , not y) _ _
(¬-cong (Pointwise.app xs≈ys i))
}
}
where
open RawApplicative VecCat.applicative
using (pure; zipWith) renaming (_<$>_ to map)
⟦_⟧Id : ∀ {n} → Expr n → Vec Carrier n → Carrier
⟦_⟧Id = Semantics.⟦_⟧ IdCat.applicative
⟦_⟧Vec : ∀ {m n} → Expr n → Vec (Vec Carrier m) n → Vec Carrier m
⟦_⟧Vec = Semantics.⟦_⟧ VecCat.applicative
open module R {n} (i : Fin n) =
Reflection setoid var
(λ e ρ → Vec.lookup (⟦ e ⟧Vec ρ) i)
(λ e ρ → ⟦ e ⟧Id (Vec.map (flip Vec.lookup i) ρ))
(λ e ρ → sym $ reflexive $
Naturality.natural (VecCat.lookup-morphism i) e ρ)
| 40.897849
| 124
| 0.432102
|
313d811603a47169720b2321066c26a3009a96be
| 1,330
|
agda
|
Agda
|
Cubical/HITs/ListedFiniteSet/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/ListedFiniteSet/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/ListedFiniteSet/Properties.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.ListedFiniteSet.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Logic
open import Cubical.Foundations.Everything
open import Cubical.HITs.ListedFiniteSet.Base
private
variable
A : Type₀
_++_ : ∀ (xs ys : LFSet A) → LFSet A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
---------------------------------------------
dup x xs i ++ ys = proof i
where
proof :
-- Need: (x ∷ x ∷ xs) ++ ys ≡ (x ∷ xs) ++ ys
-- which reduces to:
x ∷ x ∷ (xs ++ ys) ≡ x ∷ (xs ++ ys)
proof = dup 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
assoc-++ : ∀ (xs : LFSet A) ys zs → xs ++ (ys ++ zs) ≡ (xs ++ ys) ++ zs
assoc-++ [] ys zs = refl
assoc-++ (x ∷ xs) ys zs
= cong (x ∷_) (assoc-++ xs ys zs)
------------------------------------
assoc-++ (dup x xs i) ys zs j
= dup x (assoc-++ xs ys zs j) i
assoc-++ (comm x y xs i) ys zs j
= comm x y (assoc-++ xs ys zs j) i
assoc-++ (trunc xs xs' p q i k) ys zs j
= trunc (assoc-++ xs ys zs j) (assoc-++ xs' ys zs j)
(cong (\ xs -> assoc-++ xs ys zs j) p) (cong (\ xs -> assoc-++ xs ys zs j) q) i k
| 31.666667
| 91
| 0.481955
|
316a4a2fcebff50d380e70126b55aa760e97667e
| 1,523
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Setoid/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Setoid/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Setoid/Properties.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of interleaving using setoid equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Setoid)
module Data.List.Relation.Ternary.Interleaving.Setoid.Properties
{c ℓ} (S : Setoid c ℓ) where
open import Data.List.Base using (List; []; _∷_; filter; _++_)
open import Relation.Unary using (Decidable)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (¬?)
open import Function
open import Data.List.Relation.Binary.Equality.Setoid S using (≋-refl)
open import Data.List.Relation.Ternary.Interleaving.Setoid S
open Setoid S renaming (Carrier to A)
------------------------------------------------------------------------
-- Re-exporting existing properties
open import Data.List.Relation.Ternary.Interleaving.Properties public
------------------------------------------------------------------------
-- _++_
++-linear : (xs ys : List A) → Interleaving xs ys (xs ++ ys)
++-linear xs ys = ++-disjoint (left ≋-refl) (right ≋-refl)
------------------------------------------------------------------------
-- filter
module _ {p} {P : A → Set p} (P? : Decidable P) where
filter⁺ : ∀ xs → Interleaving (filter P? xs) (filter (¬? ∘ P?) xs) xs
filter⁺ [] = []
filter⁺ (x ∷ xs) with P? x
... | yes px = refl ∷ˡ filter⁺ xs
... | no ¬px = refl ∷ʳ filter⁺ xs
| 33.844444
| 72
| 0.520026
|
13b1be5f7538824e95dc1f80fe7e7571a68723d8
| 1,599
|
agda
|
Agda
|
test/LibSucceed/Issue421.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/LibSucceed/Issue421.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/LibSucceed/Issue421.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- In Agda 2.5.3 the error was:
-- μ₂ is not strictly positive, because it occurs
-- in the third argument to ⟦_⟧
-- in the type of the constructor fix
-- in the definition of μ₂.
open import Data.Nat using (ℕ;zero;suc)
open import Data.Fin using (Fin;zero;suc)
open import Data.Vec
open import Data.Empty
open import Data.Product hiding (_<*>_)
open import Data.Sum
open import Data.Unit
Σ# : {n : ℕ} -> (Fin n -> Set) -> Set
Σ# {zero} f = ⊥
Σ# {suc zero} f = f zero
Σ# {suc n} f = f zero ⊎ Σ# {n} λ i -> f (suc i)
module Matrices {Ix : Set} {Σ : (Ix -> Set) -> Set} where
Matrix : Set1
Matrix = (i j : Ix) -> Set
_<+>_ : Matrix -> Matrix -> Matrix
m <+> n = λ i j -> m i j ⊎ n i j
{-# INLINE _<+>_ #-}
_<*>_ : Matrix -> Matrix -> Matrix
m <*> n = λ i j -> Σ λ k -> m i k × n k j
{-# INLINE _<*>_ #-}
data Poly {Coeffs : Set1} : Set1 where
0p 1p : Poly
X : Poly
_+_ _*_ : (D1 D2 : Poly {Coeffs}) -> Poly {Coeffs}
K : Coeffs -> Poly
module Dim {n : ℕ} where
open Matrices {Fin n} {Σ#}
⟦_⟧ : Poly {Vec (Vec Set n) n} -> Matrix -> Matrix
⟦ 0p ⟧ x i j = ⊥
⟦ 1p ⟧ x i j = ⊤
⟦ X ⟧ x i j = x i j
⟦ D1 + D2 ⟧ x i j = (⟦ D1 ⟧ x <+> ⟦ D2 ⟧ x) i j
⟦ D1 * D2 ⟧ x i j = (⟦ D1 ⟧ x <*> ⟦ D2 ⟧ x) i j
⟦ K S ⟧ x i j = lookup (lookup S i) j
⟪_⟫ : Poly {Set} -> Set → Set
⟪ 0p ⟫ x = ⊥
⟪ 1p ⟫ x = ⊤
⟪ X ⟫ x = x
⟪ D1 + D2 ⟫ x = (⟪ D1 ⟫ x ⊎ ⟪ D2 ⟫ x)
⟪ D1 * D2 ⟫ x = (⟪ D1 ⟫ x × ⟪ D2 ⟫ x)
⟪ K S ⟫ x = S
data μ₁ (p : Poly) : Set where
fix : ⟪ p ⟫ (μ₁ p) -> μ₁ p
data μ₂ (p : Poly) (i j : Fin n) : Set where
fix : ⟦ p ⟧ (μ₂ p) i j -> μ₂ p i j
| 24.984375
| 57
| 0.501563
|
03336f5c7ae2a4497838751f1e92acea892a6d8a
| 8,800
|
agda
|
Agda
|
Cubical/HITs/CumulativeHierarchy/Constructions.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/HITs/CumulativeHierarchy/Constructions.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/HITs/CumulativeHierarchy/Constructions.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
{-
Constructions of "sets" in the cumulative hierarchy. Including:
- the empty set
- unions
- ω
- replacement
- separation
-}
module Cubical.HITs.CumulativeHierarchy.Constructions where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Structure
open import Cubical.Functions.Embedding
open import Cubical.Functions.Logic as L
open import Cubical.Data.Sum hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sum as ⊎ using (_⊎_)
open import Cubical.Data.Bool
open import Cubical.Data.Unit
open import Cubical.Data.Empty as E hiding (elim)
open import Cubical.HITs.PropositionalTruncation as P hiding (elim; elim2)
open import Cubical.HITs.CumulativeHierarchy.Base
open import Cubical.HITs.CumulativeHierarchy.Properties
import Cubical.HITs.PropositionalTruncation.Monad as PropMonad
private
variable
ℓ ℓ' : Level
------------
-- Structures for building specific sets by giving encodings and decodings for their membership
-----------
record SetStructure ℓ : Type (ℓ-suc ℓ) where
field
X : Type ℓ
ix : X → V ℓ
resSet : V ℓ
resSet = sett X ix
record SetPackage ℓ ℓ' : Type (ℓ-max (ℓ-suc ℓ) (ℓ-suc ℓ')) where
field
structure : SetStructure ℓ
open SetStructure structure hiding (resSet)
open SetStructure structure using (resSet) public
field
∈-rep : V ℓ → hProp ℓ'
unpack : (x : X) → ⟨ ∈-rep (ix x) ⟩
repack : {y : V ℓ} → ⟨ ∈-rep y ⟩ → ∥ fiber ix y ∥₁
open PropMonad
classification : ⟨ ∀[ y ] (y ∈ₛ resSet ⇔ ∈-rep y) ⟩
classification y = intoClassifier , fromClassifier where
intoClassifier : ⟨ y ∈ₛ resSet ⟩ → ⟨ ∈-rep y ⟩
intoClassifier (yi , yr) = proof (∈-rep y) by do
(x , ix) ← ∈∈ₛ {b = resSet} .snd (yi , yr)
return (subst (fst ∘ ∈-rep) ix (unpack x))
fromClassifier : ⟨ ∈-rep y ⟩ → ⟨ y ∈ₛ resSet ⟩
fromClassifier yr = ∈∈ₛ {b = resSet} .fst (repack {y = y} yr)
------------
-- Specific constructions
-----------
open SetPackage using (structure; ∈-rep; unpack; repack)
module EmptySet where
EmptyStructure : SetStructure ℓ
SetStructure.X EmptyStructure = Lift E.⊥
SetStructure.ix EmptyStructure ()
EmptyPackage : SetPackage ℓ ℓ-zero
structure EmptyPackage = EmptyStructure
∈-rep EmptyPackage _ = L.⊥
unpack EmptyPackage ()
repack EmptyPackage ()
∅ : V ℓ
∅ = SetStructure.resSet EmptyStructure
∅-empty : ⟨ ∀[ b ∶ V ℓ ] ¬ (b ∈ₛ ∅) ⟩
∅-empty b = SetPackage.classification EmptyPackage b .fst
open EmptySet using (∅; ∅-empty) public
module UnionSet (S : V ℓ) where
UnionStructure : SetStructure ℓ
SetStructure.X UnionStructure = Σ[ r ∈ ⟪ S ⟫ ] ⟪ ⟪ S ⟫↪ r ⟫
SetStructure.ix UnionStructure (r , i) = ⟪ ⟪ S ⟫↪ r ⟫↪ i
UNION : V ℓ
UNION = SetStructure.resSet UnionStructure
UnionPackage : SetPackage _ (ℓ-suc ℓ)
structure UnionPackage = UnionStructure
∈-rep UnionPackage y = ∃[ v ] (v ∈ₛ S) ⊓ (y ∈ₛ v)
unpack UnionPackage (vi , yi) = ∣ ⟪ S ⟫↪ vi , ∈ₛ⟪ S ⟫↪ vi , ∈ₛ⟪ ⟪ S ⟫↪ vi ⟫↪ yi ∣₁
repack UnionPackage {y = y} = P.rec squash₁ go where
go : Σ[ v ∈ V _ ] ⟨ v ∈ₛ S ⟩ ⊓′ ⟨ y ∈ₛ v ⟩ → ∥ fiber _ y ∥₁
go (v , (vi , vS) , xv) = ∣ repFiber≃fiber _ _ .fst ((vi , key .fst) , key .snd) ∣₁ where
path : v ≡ ⟪ S ⟫↪ vi
path = sym (equivFun identityPrinciple vS)
key : Σ[ i ∈ ⟪ ⟪ S ⟫↪ vi ⟫ ] ⟪ ⟪ S ⟫↪ vi ⟫↪ i ≊ y
key = subst (λ v → Σ[ ix ∈ ⟪ v ⟫ ] ⟪ v ⟫↪ ix ≊ y) path xv
union-ax : ⟨ ∀[ u ] (u ∈ₛ UNION ⇔ (∃[ v ] (v ∈ₛ S) ⊓ (u ∈ₛ v))) ⟩
union-ax = classification where
open SetPackage UnionPackage using (classification)
open UnionSet renaming (UNION to infixr 9 ⋃_) using (union-ax) public
module PairingSet (a b : V ℓ) where
PairingStructure : SetStructure ℓ
SetStructure.X PairingStructure = Lift Bool
SetStructure.ix PairingStructure (lift false) = a
SetStructure.ix PairingStructure (lift true) = b
open PropMonad
PairingPackage : SetPackage _ (ℓ-suc ℓ)
structure PairingPackage = PairingStructure
∈-rep PairingPackage d = (d ≡ₕ a) ⊔ (d ≡ₕ b)
unpack PairingPackage (lift false) = L.inl refl
unpack PairingPackage (lift true) = L.inr refl
repack PairingPackage {y = y} = _>>= λ where
(_⊎_.inl ya) → ∣ lift false , sym ya ∣₁
(_⊎_.inr yb) → ∣ lift true , sym yb ∣₁
PAIR : V ℓ
PAIR = SetStructure.resSet PairingStructure
pairing-ax : ⟨ ∀[ d ] (d ∈ₛ PAIR ⇔ (d ≡ₕ a) ⊔ (d ≡ₕ b)) ⟩
pairing-ax = classification where
open SetPackage PairingPackage using (classification)
-- pairing TODO: notation?
open PairingSet renaming (PAIR to infix 12 ⁅_,_⁆) using (pairing-ax) public
module SingletonSet (a : V ℓ) where
SingletonStructure : SetStructure ℓ
SetStructure.X SingletonStructure = Lift Unit
SetStructure.ix SingletonStructure (lift tt) = a
SingletonPackage : SetPackage _ (ℓ-suc ℓ)
structure SingletonPackage = SingletonStructure
∈-rep SingletonPackage d = d ≡ₕ a
unpack SingletonPackage _ = refl
repack SingletonPackage ya = ∣ lift tt , sym ya ∣₁
SINGL : V ℓ
SINGL = SetStructure.resSet SingletonStructure
open SingletonSet renaming (SINGL to infix 10 ⁅_⁆s) public
-- small unions
_∪_ : (a b : V ℓ) → V ℓ
a ∪ b = ⋃ ⁅ a , b ⁆
module InfinitySet {ℓ} where
sucV : V ℓ → V ℓ
sucV N = N ∪ ⁅ N ⁆s
#_ : ℕ → V ℓ
# zero = ∅
# suc n = sucV (# n)
ωStructure : SetStructure ℓ
SetStructure.X ωStructure = Lift ℕ
SetStructure.ix ωStructure = #_ ∘ lower
ω : V ℓ
ω = SetStructure.resSet ωStructure
open PropMonad
ωPackage : SetPackage _ (ℓ-suc ℓ)
structure ωPackage = ωStructure
∈-rep ωPackage d = (d ≡ₕ ∅) ⊔ (∃[ v ] (d ≡ₕ sucV v) ⊓ (v ∈ₛ ω))
unpack ωPackage (lift zero) = L.inl refl
unpack ωPackage (lift (suc n)) = L.inr ∣ # n , refl , ∈∈ₛ {b = ω} .fst ∣ lift n , refl ∣₁ ∣₁
repack ωPackage {y = y} = ⊔-elim (y ≡ₕ ∅) ∥ _ ∥ₚ (λ _ → ∥ fiber _ y ∥ₚ)
(λ e → ∣ lift zero , sym e ∣₁)
(λ m → do (v , yv , vr) ← m
(lift n , eq) ← ∈∈ₛ {b = ω} .snd vr
∣ lift (suc n) , sym (subst (λ v → y ≡ (v ∪ ⁅ v ⁆s)) (sym eq) yv) ∣₁
)
infinity-ax : ⟨ ∀[ y ] (y ∈ₛ ω ⇔ (y ≡ₕ ∅) ⊔ (∃[ v ] (y ≡ₕ sucV v) ⊓ (v ∈ₛ ω))) ⟩
infinity-ax = classification where
open SetPackage ωPackage using (classification)
ω-empty : ⟨ ∅ ∈ₛ ω ⟩
ω-empty = infinity-ax ∅ .snd (L.inl refl)
ω-next : ⟨ ∀[ x ∶ V ℓ ] x ∈ₛ ω ⇒ sucV x ∈ₛ ω ⟩
ω-next x x∈ω = infinity-ax (sucV x) .snd (L.inr ∣ x , refl , x∈ω ∣₁)
#-in-ω : ∀ n → ⟨ # n ∈ₛ ω ⟩
#-in-ω zero = ω-empty
#-in-ω (suc n) = ω-next (# n) (#-in-ω n)
open InfinitySet using (ω; ω-empty; ω-next; infinity-ax) public
module ReplacementSet (r : V ℓ → V ℓ) (a : V ℓ) where
ReplacementStructure : SetStructure ℓ
SetStructure.X ReplacementStructure = ⟪ a ⟫
SetStructure.ix ReplacementStructure = r ∘ ⟪ a ⟫↪
REPLACED : V ℓ
REPLACED = SetStructure.resSet ReplacementStructure
open PropMonad
ReplacementPackage : SetPackage _ (ℓ-suc ℓ)
structure ReplacementPackage = ReplacementStructure
∈-rep ReplacementPackage y = ∃[ z ] (z ∈ₛ a) ⊓ (y ≡ₕ r z)
unpack ReplacementPackage ⟪a⟫ = ∣ ⟪ a ⟫↪ ⟪a⟫ , (∈ₛ⟪ a ⟫↪ ⟪a⟫) , refl ∣₁
repack ReplacementPackage {y = y} m = do
(z , (a , za) , yr) ← m
∣ a , cong r (equivFun identityPrinciple za) ∙ sym yr ∣₁
replacement-ax : ⟨ ∀[ y ] (y ∈ₛ REPLACED ⇔ (∃[ z ] (z ∈ₛ a) ⊓ (y ≡ₕ r z))) ⟩
replacement-ax y = classification y where
open SetPackage ReplacementPackage using (classification)
open ReplacementSet renaming (REPLACED to infix 12 ⁅_∣_⁆) using (replacement-ax) public
module SeparationSet (a : V ℓ) (ϕ : V ℓ → hProp ℓ) where
SeparationStructure : SetStructure ℓ
SetStructure.X SeparationStructure = Σ[ x ∈ ⟪ a ⟫ ] ⟨ ϕ (⟪ a ⟫↪ x) ⟩
SetStructure.ix SeparationStructure = ⟪ a ⟫↪ ∘ fst
SeparationPackage : SetPackage _ ℓ
structure SeparationPackage = SeparationStructure
∈-rep SeparationPackage y = (y ∈ₛ a) ⊓ ϕ y
unpack SeparationPackage (⟪a⟫ , phi) = (∈ₛ⟪ a ⟫↪ ⟪a⟫) , phi
repack SeparationPackage ((⟪a⟫ , ya) , phi) =
∣ (⟪a⟫ , subst (fst ∘ ϕ) (sym (equivFun identityPrinciple ya)) phi)
, equivFun identityPrinciple ya ∣₁
SEPAREE : V ℓ
SEPAREE = SetStructure.resSet SeparationStructure
separation-ax : ⟨ ∀[ y ] (y ∈ₛ SEPAREE ⇔ (y ∈ₛ a) ⊓ ϕ y) ⟩
separation-ax y = classification y .fst , classification y .snd where
open SetPackage SeparationPackage using (classification)
open SeparationSet renaming (SEPAREE to infix 12 ⁅_∶_⁆) using (separation-ax) public
module Examples where
open InfinitySet
the1 : V ℓ-zero
the1 = # 1
1-ok? : ∥ Bool ∥₁
1-ok? = do
prf ← infinity-ax the1 .fst (#-in-ω 1)
case prf of λ { (⊎.inl _) → ∣ false ∣₁ ; (⊎.inr _) → ∣ true ∣₁ }
where
open PropMonad
test : 1-ok? ≡ ∣ true ∣₁
test = refl
| 33.716475
| 95
| 0.63875
|
38e0561fe4b1da7f7378813be7655839e9b06773
| 2,575
|
agda
|
Agda
|
Cubical/Categories/Limits/Pullback.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Categories/Limits/Pullback.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Categories/Limits/Pullback.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Limits.Pullback where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Limits.Base
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Data.Sigma
open import Cubical.Categories.Instances.Cospan public
private
variable
ℓ ℓ' : Level
module _ {C : Precategory ℓ ℓ'} where
open Precategory C
open Functor
record Cospan : Type (ℓ-max ℓ ℓ') where
constructor cospan
field
l m r : ob
s₁ : C [ l , m ]
s₂ : C [ r , m ]
record PullbackLegs (cspn : Cospan) (c : ob) : Type (ℓ-max ℓ ℓ') where
constructor pblegs
open Cospan cspn
field
p₁ : C [ c , l ]
p₂ : C [ c , r ]
record PullbackCone (cspn : Cospan) (c : ob) : Type (ℓ-max ℓ ℓ') where
constructor cone
open Cospan cspn
field
pl : PullbackLegs cspn c
open PullbackLegs pl public
field
sq : p₁ ⋆⟨ C ⟩ s₁ ≡ p₂ ⋆⟨ C ⟩ s₂
record isPullback (cspn : _) {c} (pb : PullbackLegs cspn c) : Type (ℓ-max ℓ ℓ') where
open Cospan cspn
open PullbackLegs
field
sq : pb .p₁ ⋆⟨ C ⟩ s₁ ≡ pb .p₂ ⋆⟨ C ⟩ s₂
open PullbackCone
field
up : ∀ {d}
→ (pb' : PullbackCone cspn d)
→ isContr (Σ[ f ∈ (C [ d , c ]) ] ((pb' .p₁ ≡ f ⋆⟨ C ⟩ pb .p₁)
× (pb' .p₂ ≡ f ⋆⟨ C ⟩ pb .p₂)))
Cospan→Func : Cospan → Functor CospanCat C
Cospan→Func (cospan l m r f g) .F-ob ⓪ = l
Cospan→Func (cospan l m r f g) .F-ob ① = m
Cospan→Func (cospan l m r f g) .F-ob ② = r
Cospan→Func (cospan l m r f g) .F-hom {⓪} {①} k = f
Cospan→Func (cospan l m r f g) .F-hom {②} {①} k = g
Cospan→Func (cospan l m r f g) .F-hom {⓪} {⓪} k = id l
Cospan→Func (cospan l m r f g) .F-hom {①} {①} k = id m
Cospan→Func (cospan l m r f g) .F-hom {②} {②} k = id r
Cospan→Func (cospan l m r f g) .F-id {⓪} = refl
Cospan→Func (cospan l m r f g) .F-id {①} = refl
Cospan→Func (cospan l m r f g) .F-id {②} = refl
Cospan→Func (cospan l m r f g) .F-seq {⓪} {⓪} {⓪} φ ψ = sym (⋆IdL _)
Cospan→Func (cospan l m r f g) .F-seq {⓪} {⓪} {①} φ ψ = sym (⋆IdL _)
Cospan→Func (cospan l m r f g) .F-seq {⓪} {①} {①} φ ψ = sym (⋆IdR _)
Cospan→Func (cospan l m r f g) .F-seq {①} {①} {①} φ ψ = sym (⋆IdL _)
Cospan→Func (cospan l m r f g) .F-seq {②} {②} {②} φ ψ = sym (⋆IdL _)
Cospan→Func (cospan l m r f g) .F-seq {②} {②} {①} φ ψ = sym (⋆IdL _)
Cospan→Func (cospan l m r f g) .F-seq {②} {①} {①} φ ψ = sym (⋆IdR _)
-- TODO: show that this definition of Pullback is equivalent to the Cospan limit
| 31.790123
| 87
| 0.579806
|
4ba9f92c39884b365614daec3b8f4fe8a463b020
| 1,510
|
agda
|
Agda
|
Cubical/Structures/TypeEqvTo.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | 1
|
2021-10-31T17:32:49.000Z
|
2021-10-31T17:32:49.000Z
|
Cubical/Structures/TypeEqvTo.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
Cubical/Structures/TypeEqvTo.agda
|
guilhermehas/cubical
|
ce3120d3f8d692847b2744162bcd7a01f0b687eb
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Structures.TypeEqvTo where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Sigma
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Pointed
open import Cubical.Structures.Axioms
open import Cubical.Structures.Pointed
private
variable
ℓ ℓ' ℓ'' : Level
TypeEqvTo : (ℓ : Level) (X : Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ')
TypeEqvTo ℓ X = TypeWithStr ℓ (λ Y → ∥ Y ≃ X ∥₁)
PointedEqvTo : (ℓ : Level) (X : Type ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ')
PointedEqvTo ℓ X = TypeWithStr ℓ (λ Y → Y × ∥ Y ≃ X ∥₁)
module _ (X : Type ℓ') where
PointedEqvToStructure : Type ℓ → Type (ℓ-max ℓ ℓ')
PointedEqvToStructure = AxiomsStructure PointedStructure (λ Y _ → ∥ Y ≃ X ∥₁)
PointedEqvToEquivStr : StrEquiv PointedEqvToStructure ℓ''
PointedEqvToEquivStr = AxiomsEquivStr PointedEquivStr (λ Y _ → ∥ Y ≃ X ∥₁)
pointedEqvToUnivalentStr : UnivalentStr {ℓ} PointedEqvToStructure PointedEqvToEquivStr
pointedEqvToUnivalentStr = axiomsUnivalentStr PointedEquivStr {axioms = λ Y _ → ∥ Y ≃ X ∥₁}
(λ _ _ → squash₁) pointedUnivalentStr
PointedEqvToSIP : (A B : PointedEqvTo ℓ X) → A ≃[ PointedEqvToEquivStr ] B ≃ (A ≡ B)
PointedEqvToSIP = SIP pointedEqvToUnivalentStr
PointedEqvTo-sip : (A B : PointedEqvTo ℓ X) → A ≃[ PointedEqvToEquivStr ] B → (A ≡ B)
PointedEqvTo-sip A B = equivFun (PointedEqvToSIP A B)
| 35.952381
| 93
| 0.703311
|
387b1dc0fb1b06dadc7513b586a42b401c9c00e4
| 582
|
agda
|
Agda
|
old/Type/Functions/Inverse.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
old/Type/Functions/Inverse.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
old/Type/Functions/Inverse.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
import Lvl
open import Type
module Type.Functions.Inverse {ℓₗ : Lvl.Level}{ℓₒ₁}{ℓₒ₂} {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} where
open import Function.Domains
open import Type.Functions {ℓₗ}{ℓₒ₁}{ℓₒ₂} {X}{Y}
open import Type.Properties.Empty
open import Type.Properties.Singleton {ℓₒ₁}{ℓₒ₂}
inv : (f : X → Y) → ⦃ _ : Bijective(f) ⦄ → (Y → X)
inv f ⦃ Bijective.intro(proof) ⦄ (y) with proof{y}
... | IsUnit.intro (Unapply.intro x) _ = x
invᵣ : (f : X → Y) → ⦃ _ : Surjective(f) ⦄ → (Y → X)
invᵣ f ⦃ Surjective.intro(proof) ⦄ (y) with proof{y}
... | ◊.intro ⦃ Unapply.intro x ⦄ = x
| 32.333333
| 94
| 0.630584
|
3139dcc649a695157fe08d8f537f19892b8f642b
| 389
|
agda
|
Agda
|
Cubical/Categories/Instances/Lattice.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Categories/Instances/Lattice.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/Lattice.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Lattice where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Lattice
open import Cubical.Categories.Category
open import Cubical.Categories.Instances.Semilattice
open Category
LatticeCategory : ∀ {ℓ} (L : Lattice ℓ) → Category ℓ ℓ
LatticeCategory L = JoinSemilatticeCategory (Lattice→JoinSemilattice L)
| 24.3125
| 71
| 0.802057
|
59a7c84652ec1f12e8dadca33a0e6d097551b067
| 4,797
|
agda
|
Agda
|
vendor/stdlib/src/Data/Covec.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Data/Covec.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Data/Covec.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Coinductive vectors
------------------------------------------------------------------------
module Data.Covec where
open import Coinduction
open import Data.Nat using (ℕ; zero; suc)
open import Data.Conat
open import Data.Cofin using (Cofin; zero; suc)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Colist as Colist using (Colist; []; _∷_)
open import Data.Product using (_,_)
open import Relation.Binary
------------------------------------------------------------------------
-- The type
infixr 5 _∷_
data Covec (A : Set) : Coℕ → Set where
[] : Covec A zero
_∷_ : ∀ {n} (x : A) (xs : ∞ (Covec A (♭ n))) → Covec A (suc n)
------------------------------------------------------------------------
-- Some operations
map : ∀ {A B n} → (A → B) → Covec A n → Covec B n
map f [] = []
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
fromVec : ∀ {A n} → Vec A n → Covec A (fromℕ n)
fromVec [] = []
fromVec (x ∷ xs) = x ∷ ♯ fromVec xs
fromColist : ∀ {A} (xs : Colist A) → Covec A (Colist.length xs)
fromColist [] = []
fromColist (x ∷ xs) = x ∷ ♯ fromColist (♭ xs)
take : ∀ {A} m {n} → Covec A (m + n) → Covec A m
take zero xs = []
take (suc n) (x ∷ xs) = x ∷ ♯ take (♭ n) (♭ xs)
drop : ∀ {A} m {n} → Covec A (fromℕ m + n) → Covec A n
drop zero xs = xs
drop (suc n) (x ∷ xs) = drop n (♭ xs)
replicate : ∀ {A} n → A → Covec A n
replicate zero x = []
replicate (suc n) x = x ∷ ♯ replicate (♭ n) x
lookup : ∀ {A n} → Cofin n → Covec A n → A
lookup zero (x ∷ xs) = x
lookup (suc n) (x ∷ xs) = lookup n (♭ xs)
infixr 5 _++_
_++_ : ∀ {A m n} → Covec A m → Covec A n → Covec A (m + n)
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ ♯ (♭ xs ++ ys)
[_] : ∀ {A} → A → Covec A (suc (♯ zero))
[ x ] = x ∷ ♯ []
------------------------------------------------------------------------
-- Equality and other relations
-- xs ≈ ys means that xs and ys are equal.
infix 4 _≈_
data _≈_ {A} : ∀ {n} (xs ys : Covec A n) → Set where
[] : [] ≈ []
_∷_ : ∀ {n} x {xs ys}
(xs≈ : ∞ (♭ xs ≈ ♭ ys)) → _≈_ {n = suc n} (x ∷ xs) (x ∷ ys)
-- x ∈ xs means that x is a member of xs.
infix 4 _∈_
data _∈_ {A} : ∀ {n} → A → Covec A n → Set where
here : ∀ {n x } {xs} → _∈_ {n = suc n} x (x ∷ xs)
there : ∀ {n x y} {xs} (x∈xs : x ∈ ♭ xs) → _∈_ {n = suc n} x (y ∷ xs)
-- xs ⊑ ys means that xs is a prefix of ys.
infix 4 _⊑_
data _⊑_ {A} : ∀ {m n} → Covec A m → Covec A n → Set where
[] : ∀ {n} {ys : Covec A n} → [] ⊑ ys
_∷_ : ∀ {m n} x {xs ys} (p : ∞ (♭ xs ⊑ ♭ ys)) →
_⊑_ {m = suc m} {suc n} (x ∷ xs) (x ∷ ys)
------------------------------------------------------------------------
-- Some proofs
setoid : Set → Coℕ → Setoid
setoid A n = record
{ carrier = Covec A n
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : ∀ {A n} → Reflexive (_≈_ {A} {n})
refl {x = []} = []
refl {x = x ∷ xs} = x ∷ ♯ refl
sym : ∀ {A n} → Symmetric (_≈_ {A} {n})
sym [] = []
sym (x ∷ xs≈) = x ∷ ♯ sym (♭ xs≈)
trans : ∀ {A n} → Transitive (_≈_ {A} {n})
trans [] [] = []
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
poset : Set → Coℕ → Poset
poset A n = record
{ carrier = Covec A n
; _≈_ = _≈_
; _≤_ = _⊑_
; isPartialOrder = record
{ isPreorder = record
{ isEquivalence = Setoid.isEquivalence (setoid A n)
; reflexive = reflexive
; trans = trans
; ∼-resp-≈ = ((λ {_} → ⊑-resp-≈ˡ) , λ {_} → ⊑-resp-≈ʳ)
}
; antisym = antisym
}
}
where
reflexive : ∀ {A n} → _≈_ {A} {n} ⇒ _⊑_
reflexive [] = []
reflexive (x ∷ xs≈) = x ∷ ♯ reflexive (♭ xs≈)
trans : ∀ {A n} → Transitive (_⊑_ {A} {n})
trans [] _ = []
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
⊑-resp-≈ˡ : ∀ {A n} {xs : Covec A n} →
(λ ys → xs ⊑ ys) Respects _≈_ {A} {n}
⊑-resp-≈ˡ _ [] = []
⊑-resp-≈ˡ (x ∷ xs≈) (.x ∷ p) = x ∷ ♯ ⊑-resp-≈ˡ (♭ xs≈) (♭ p)
⊑-resp-≈ʳ : ∀ {A n} {ys : Covec A n} →
(λ xs → xs ⊑ ys) Respects _≈_ {A} {n}
⊑-resp-≈ʳ [] _ = []
⊑-resp-≈ʳ (x ∷ xs≈) (.x ∷ p) = x ∷ ♯ ⊑-resp-≈ʳ (♭ xs≈) (♭ p)
antisym : ∀ {A n} → Antisymmetric (_≈_ {A} {n}) _⊑_
antisym [] [] = []
antisym (x ∷ p₁) (.x ∷ p₂) = x ∷ ♯ antisym (♭ p₁) (♭ p₂)
map-cong : ∀ {A B n} (f : A → B) → _≈_ {n = n} =[ map f ]⇒ _≈_
map-cong f [] = []
map-cong f (x ∷ xs≈) = f x ∷ ♯ map-cong f (♭ xs≈)
take-⊑ : ∀ {A} m {n} (xs : Covec A (m + n)) → take m xs ⊑ xs
take-⊑ zero xs = []
take-⊑ (suc n) (x ∷ xs) = x ∷ ♯ take-⊑ (♭ n) (♭ xs)
| 29.072727
| 72
| 0.406087
|
c7f1303506479efbb94e923f4be5e523955fb47d
| 7,983
|
agda
|
Agda
|
Cubical/Experiments/Brunerie.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Experiments/Brunerie.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Experiments/Brunerie.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Experiments.Brunerie where
open import Cubical.Foundations.Everything
open import Cubical.Data.Bool
open import Cubical.Data.Nat
open import Cubical.Data.Int
open import Cubical.Data.HomotopyGroup
open import Cubical.HITs.S1
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.HITs.Join
open import Cubical.HITs.SetTruncation as SetTrunc
open import Cubical.HITs.GroupoidTruncation as GroupoidTrunc
open import Cubical.HITs.2GroupoidTruncation as 2GroupoidTrunc
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Hopf
open S¹Hopf
-- This code is adapted from examples/brunerie3.ctt on the pi4s3_nobug branch of cubicaltt
Bool∙ S¹∙ S³∙ : Pointed₀
Bool∙ = (Bool , true)
S¹∙ = (S¹ , base)
S³∙ = (S³ , base)
∥_∥₃∙ ∥_∥₄∙ : Pointed₀ → Pointed₀
∥ A , a ∥₃∙ = ∥ A ∥₃ , ∣ a ∣₃
∥ A , a ∥₄∙ = ∥ A ∥₄ , ∣ a ∣₄
join∙ : Pointed₀ → Type₀ → Pointed₀
join∙ (A , a) B = join A B , inl a
Ω² Ω³ : Pointed₀ → Pointed₀
Ω² = Ω^ 2
Ω³ = Ω^ 3
mapΩrefl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω A .fst → Ω (B , f (pt A)) .fst
mapΩrefl f p i = f (p i)
mapΩ²refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω² A .fst → Ω² (B , f (pt A)) .fst
mapΩ²refl f p i j = f (p i j)
mapΩ³refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω³ A .fst → Ω³ (B , f (pt A)) .fst
mapΩ³refl f p i j k = f (p i j k)
meridS² : S¹ → Path S² base base
meridS² base _ = base
meridS² (loop i) j = surf i j
alpha : join S¹ S¹ → S²
alpha (inl x) = base
alpha (inr y) = base
alpha (push x y i) = (meridS² y ∙ meridS² x) i
connectionBoth : {A : Type₀} {a : A} (p : Path A a a) → PathP (λ i → Path A (p i) (p i)) p p
connectionBoth {a = a} p i j =
hcomp
(λ k → λ
{ (i = i0) → p (j ∨ ~ k)
; (i = i1) → p (j ∧ k)
; (j = i0) → p (i ∨ ~ k)
; (j = i1) → p (i ∧ k)
})
a
data PostTotalHopf : Type₀ where
base : S¹ → PostTotalHopf
loop : (x : S¹) → PathP (λ i → Path PostTotalHopf (base x) (base (rotLoop x (~ i)))) refl refl
tee12 : (x : S²) → HopfS² x → PostTotalHopf
tee12 base y = base y
tee12 (surf i j) y =
hcomp
(λ k → λ
{ (i = i0) → base y
; (i = i1) → base y
; (j = i0) → base y
; (j = i1) → base (rotLoopInv y (~ i) k)
})
(loop (unglue (i ∨ ~ i ∨ j ∨ ~ j) y) i j)
tee34 : PostTotalHopf → join S¹ S¹
tee34 (base x) = inl x
tee34 (loop x i j) =
hcomp
(λ k → λ
{ (i = i0) → push x x (j ∧ ~ k)
; (i = i1) → push x x (j ∧ ~ k)
; (j = i0) → inl x
; (j = i1) → push (rotLoop x (~ i)) x (~ k)
})
(push x x j)
tee : (x : S²) → HopfS² x → join S¹ S¹
tee x y = tee34 (tee12 x y)
fibΩ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω B .fst → Type₀
fibΩ P f p = PathP (λ i → P (p i)) f f
fibΩ² : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω² B .fst → Type₀
fibΩ² P f = fibΩ (fibΩ P f) refl
fibΩ³ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω³ B .fst → Type₀
fibΩ³ P f = fibΩ² (fibΩ P f) refl
Ω³Hopf : Ω³ S²∙ .fst → Type₀
Ω³Hopf = fibΩ³ HopfS² base
fibContrΩ³Hopf : ∀ p → Ω³Hopf p
fibContrΩ³Hopf p i j k =
hcomp
(λ m → λ
{ (i = i0) → base
; (i = i1) → base
; (j = i0) → base
; (j = i1) → base
; (k = i0) → base
; (k = i1) →
isSetΩS¹ refl refl
(λ i j → transp (λ n → HopfS² (p i j n)) (i ∨ ~ i ∨ j ∨ ~ j) base)
(λ _ _ → base)
m i j
})
(transp (λ n → HopfS² (p i j (k ∧ n))) (i ∨ ~ i ∨ j ∨ ~ j ∨ ~ k) base)
h : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
h p i j k = tee (p i j k) (fibContrΩ³Hopf p i j k)
multTwoAux : (x : S²) → Path (Path ∥ S² ∥₄ ∣ x ∣₄ ∣ x ∣₄) refl refl
multTwoAux base i j = ∣ surf i j ∣₄
multTwoAux (surf k l) i j =
hcomp
(λ m → λ
{ (i = i0) → ∣ surf k l ∣₄
; (i = i1) → ∣ surf k l ∣₄
; (j = i0) → ∣ surf k l ∣₄
; (j = i1) → ∣ surf k l ∣₄
; (k = i0) → ∣ surf i j ∣₄
; (k = i1) → ∣ surf i j ∣₄
; (l = i0) → ∣ surf i j ∣₄
; (l = i1) → squash₄ _ _ _ _ _ _ (λ k i j → step₁ k i j) refl m k i j
})
(step₁ k i j)
where
step₁ : I → I → I → ∥ S² ∥₄
step₁ k i j =
hcomp {A = ∥ S² ∥₄}
(λ m → λ
{ (i = i0) → ∣ surf k (l ∧ m) ∣₄
; (i = i1) → ∣ surf k (l ∧ m) ∣₄
; (j = i0) → ∣ surf k (l ∧ m) ∣₄
; (j = i1) → ∣ surf k (l ∧ m) ∣₄
; (k = i0) → ∣ surf i j ∣₄
; (k = i1) → ∣ surf i j ∣₄
; (l = i0) → ∣ surf i j ∣₄
})
∣ surf i j ∣₄
multTwoTildeAux : (t : ∥ S² ∥₄) → Path (Path ∥ S² ∥₄ t t) refl refl
multTwoTildeAux ∣ x ∣₄ = multTwoAux x
multTwoTildeAux (squash₄ _ _ _ _ _ _ t u k l m n) i j =
squash₄ _ _ _ _ _ _
(λ k l m → multTwoTildeAux (t k l m) i j)
(λ k l m → multTwoTildeAux (u k l m) i j)
k l m n
multTwoEquivAux : Path (Path (∥ S² ∥₄ ≃ ∥ S² ∥₄) (idEquiv _) (idEquiv _)) refl refl
multTwoEquivAux i j =
( f i j
, hcomp
(λ l → λ
{ (i = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (i = i1) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (j = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (j = i1) →
isPropIsEquiv _
(transp (λ k → isEquiv (f i k)) (i ∨ ~ i) (idIsEquiv _))
(idIsEquiv _)
l
})
(transp (λ k → isEquiv (f i (j ∧ k))) (i ∨ ~ i ∨ ~ j) (idIsEquiv _))
)
where
f : I → I → ∥ S² ∥₄ → ∥ S² ∥₄
f i j t = multTwoTildeAux t i j
tHopf³ : S³ → Type₀
tHopf³ base = ∥ S² ∥₄
tHopf³ (surf i j k) =
Glue ∥ S² ∥₄
(λ { (i = i0) → (∥ S² ∥₄ , idEquiv _)
; (i = i1) → (∥ S² ∥₄ , idEquiv _)
; (j = i0) → (∥ S² ∥₄ , idEquiv _)
; (j = i1) → (∥ S² ∥₄ , idEquiv _)
; (k = i0) → (∥ S² ∥₄ , multTwoEquivAux i j)
; (k = i1) → (∥ S² ∥₄ , idEquiv _)
})
π₃S³ : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst
π₃S³ p i j = transp (λ k → tHopf³ (p j k i)) i0 ∣ base ∣₄
codeS² : S² → hGroupoid _
codeS² s = ∥ HopfS² s ∥₃ , squash₃
codeTruncS² : ∥ S² ∥₄ → hGroupoid _
codeTruncS² = 2GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 3) codeS²
encodeTruncS² : Ω ∥ S²∙ ∥₄∙ .fst → ∥ S¹ ∥₃
encodeTruncS² p = transp (λ i → codeTruncS² (p i) .fst) i0 ∣ base ∣₃
codeS¹ : S¹ → hSet _
codeS¹ s = ∥ helix s ∥₂ , squash₂
codeTruncS¹ : ∥ S¹ ∥₃ → hSet _
codeTruncS¹ = GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 2) codeS¹
encodeTruncS¹ : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂
encodeTruncS¹ p = transp (λ i → codeTruncS¹ (p i) .fst) i0 ∣ pos zero ∣₂
-- THE BIG GAME
f3 : Ω³ S³∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
f3 = mapΩ³refl S³→joinS¹S¹
f4 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S²∙ .fst
f4 = mapΩ³refl alpha
f5 : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
f5 = h
f6 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S³∙ .fst
f6 = mapΩ³refl joinS¹S¹→S³
f7 : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst
f7 = π₃S³
g8 : Ω² ∥ S²∙ ∥₄∙ .fst → Ω ∥ S¹∙ ∥₃∙ .fst
g8 = mapΩrefl encodeTruncS²
g9 : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂
g9 = encodeTruncS¹
g10 : ∥ ℤ ∥₂ → ℤ
g10 = SetTrunc.rec isSetℤ (idfun ℤ)
-- don't run me
brunerie : ℤ
brunerie = g10 (g9 (g8 (f7 (f6 (f5 (f4 (f3 (λ i j k → surf i j k))))))))
-- simpler tests
test63 : ℕ → ℤ
test63 n = g10 (g9 (g8 (f7 (63n n))))
where
63n : ℕ → Ω³ S³∙ .fst
63n zero i j k = surf i j k
63n (suc n) = f6 (f3 (63n n))
foo : Ω³ S²∙ .fst
foo i j k =
hcomp
(λ l → λ
{ (i = i0) → surf l l
; (i = i1) → surf l l
; (j = i0) → surf l l
; (j = i1) → surf l l
; (k = i0) → surf l l
; (k = i1) → surf l l
})
base
sorghum : Ω³ S²∙ .fst
sorghum i j k =
hcomp
(λ l → λ
{ (i = i0) → surf j l
; (i = i1) → surf k (~ l)
; (j = i0) → surf k (i ∧ ~ l)
; (j = i1) → surf k (i ∧ ~ l)
; (k = i0) → surf j (i ∨ l)
; (k = i1) → surf j (i ∨ l)
})
(hcomp
(λ l → λ
{ (i = i0) → base
; (i = i1) → surf j l
; (j = i0) → surf k i
; (j = i1) → surf k i
; (k = i0) → surf j (i ∧ l)
; (k = i1) → surf j (i ∧ l)
})
(surf k i))
goo : Ω³ S²∙ .fst → ℤ
goo x = g10 (g9 (g8 (f7 (f6 (f5 x)))))
| 26.698997
| 96
| 0.503821
|
c7829e5a72c1bd87ffb5c54981aea4f28d5f5868
| 5,408
|
agda
|
Agda
|
Cubical/HITs/Ints/QuoInt/Base.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/QuoInt/Base.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Ints/QuoInt/Base.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
-- Define the integers as a HIT by identifying +0 and -0
{-# OPTIONS --safe #-}
module Cubical.HITs.Ints.QuoInt.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Relation.Nullary
open import Cubical.Data.Int as Int using (Int; sucInt; predInt; discreteInt; isSetInt)
open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc)
open import Cubical.Data.Bool as Bool using (Bool; not; notnot)
variable
l : Level
Sign : Type₀
Sign = Bool
pattern spos = Bool.false
pattern sneg = Bool.true
_·S_ : Sign → Sign → Sign
_·S_ = Bool._⊕_
data ℤ : Type₀ where
signed : (s : Sign) (n : ℕ) → ℤ
posneg : signed spos 0 ≡ signed sneg 0
pattern pos n = signed spos n
pattern neg n = signed sneg n
sign : ℤ → Sign
sign (signed _ zero) = spos
sign (signed s (suc _)) = s
sign (posneg i) = spos
sign-pos : ∀ n → sign (pos n) ≡ spos
sign-pos zero = refl
sign-pos (suc n) = refl
abs : ℤ → ℕ
abs (signed _ n) = n
abs (posneg i) = zero
signed-inv : ∀ n → signed (sign n) (abs n) ≡ n
signed-inv (pos zero) = refl
signed-inv (neg zero) = posneg
signed-inv (signed s (suc n)) = refl
signed-inv (posneg i) j = posneg (i ∧ j)
signed-zero : ∀ s₁ s₂ → signed s₁ zero ≡ signed s₂ zero
signed-zero spos spos = refl
signed-zero sneg sneg = refl
signed-zero spos sneg = posneg
signed-zero sneg spos = sym posneg
rec : ∀ {A : Type l} → (pos' neg' : ℕ → A) → pos' 0 ≡ neg' 0 → ℤ → A
rec pos' neg' eq (pos m) = pos' m
rec pos' neg' eq (neg m) = neg' m
rec pos' neg' eq (posneg i) = eq i
elim : ∀ (P : ℤ → Type l)
→ (pos' : ∀ n → P (pos n))
→ (neg' : ∀ n → P (neg n))
→ (λ i → P (posneg i)) [ pos' 0 ≡ neg' 0 ]
→ ∀ z → P z
elim P pos' neg' eq (pos n) = pos' n
elim P pos' neg' eq (neg n) = neg' n
elim P pos' neg' eq (posneg i) = eq i
Int→ℤ : Int → ℤ
Int→ℤ (Int.pos n) = pos n
Int→ℤ (Int.negsuc n) = neg (suc n)
ℤ→Int : ℤ → Int
ℤ→Int (pos n) = Int.pos n
ℤ→Int (neg zero) = Int.pos 0
ℤ→Int (neg (suc n)) = Int.negsuc n
ℤ→Int (posneg _) = Int.pos 0
ℤ→Int→ℤ : ∀ (n : ℤ) → Int→ℤ (ℤ→Int n) ≡ n
ℤ→Int→ℤ (pos n) _ = pos n
ℤ→Int→ℤ (neg zero) i = posneg i
ℤ→Int→ℤ (neg (suc n)) _ = neg (suc n)
ℤ→Int→ℤ (posneg j) i = posneg (j ∧ i)
Int→ℤ→Int : ∀ (n : Int) → ℤ→Int (Int→ℤ n) ≡ n
Int→ℤ→Int (Int.pos n) _ = Int.pos n
Int→ℤ→Int (Int.negsuc n) _ = Int.negsuc n
Int≡ℤ : Int ≡ ℤ
Int≡ℤ = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)
discreteℤ : Discrete ℤ
discreteℤ = subst Discrete Int≡ℤ discreteInt
isSetℤ : isSet ℤ
isSetℤ = subst isSet Int≡ℤ isSetInt
-_ : ℤ → ℤ
- signed s n = signed (not s) n
- posneg i = posneg (~ i)
negate-invol : ∀ n → - - n ≡ n
negate-invol (signed s n) i = signed (notnot s i) n
negate-invol (posneg i) _ = posneg i
negateEquiv : ℤ ≃ ℤ
negateEquiv = isoToEquiv (iso -_ -_ negate-invol negate-invol)
negateEq : ℤ ≡ ℤ
negateEq = ua negateEquiv
infixl 6 _+_
infixl 7 _·_
sucℤ : ℤ → ℤ
sucℤ (pos n) = pos (suc n)
sucℤ (neg zero) = pos 1
sucℤ (neg (suc n)) = neg n
sucℤ (posneg _) = pos 1
predℤ : ℤ → ℤ
predℤ = subst (λ Z → (Z → Z)) negateEq sucℤ
-- definitionally equal to λ n → - (sucℤ (- n))
-- strictly more useful than the direct pattern matching version,
-- see negateSuc and negatePred
sucPredℤ : ∀ n → sucℤ (predℤ n) ≡ n
sucPredℤ (pos zero) = sym posneg
sucPredℤ (pos (suc _)) = refl
sucPredℤ (neg _) = refl
sucPredℤ (posneg i) j = posneg (i ∨ ~ j)
predSucℤ : ∀ n → predℤ (sucℤ n) ≡ n
predSucℤ (pos _) = refl
predSucℤ (neg zero) = posneg
predSucℤ (neg (suc _)) = refl
predSucℤ (posneg i) j = posneg (i ∧ j)
_+_ : ℤ → ℤ → ℤ
(signed _ zero) + n = n
(posneg _) + n = n
(pos (suc m)) + n = sucℤ (pos m + n)
(neg (suc m)) + n = predℤ (neg m + n)
sucPathℤ : ℤ ≡ ℤ
sucPathℤ = isoToPath (iso sucℤ predℤ sucPredℤ predSucℤ)
-- We do the same trick as in Cubical.Data.Int to prove that addition
-- is an equivalence
addEqℤ : ℕ → ℤ ≡ ℤ
addEqℤ zero = refl
addEqℤ (suc n) = addEqℤ n ∙ sucPathℤ
predPathℤ : ℤ ≡ ℤ
predPathℤ = isoToPath (iso predℤ sucℤ predSucℤ sucPredℤ)
subEqℤ : ℕ → ℤ ≡ ℤ
subEqℤ zero = refl
subEqℤ (suc n) = subEqℤ n ∙ predPathℤ
addℤ : ℤ → ℤ → ℤ
addℤ (pos m) n = transport (addEqℤ m) n
addℤ (neg m) n = transport (subEqℤ m) n
addℤ (posneg _) n = n
isEquivAddℤ : (m : ℤ) → isEquiv (addℤ m)
isEquivAddℤ (pos n) = isEquivTransport (addEqℤ n)
isEquivAddℤ (neg n) = isEquivTransport (subEqℤ n)
isEquivAddℤ (posneg _) = isEquivTransport refl
addℤ≡+ℤ : addℤ ≡ _+_
addℤ≡+ℤ i (pos (suc m)) n = sucℤ (addℤ≡+ℤ i (pos m) n)
addℤ≡+ℤ i (neg (suc m)) n = predℤ (addℤ≡+ℤ i (neg m) n)
addℤ≡+ℤ i (pos zero) n = n
addℤ≡+ℤ i (neg zero) n = n
addℤ≡+ℤ _ (posneg _) n = n
isEquiv+ℤ : (m : ℤ) → isEquiv (m +_)
isEquiv+ℤ = subst (λ _+_ → (m : ℤ) → isEquiv (m +_)) addℤ≡+ℤ isEquivAddℤ
_·_ : ℤ → ℤ → ℤ
m · n = signed (sign m ·S sign n) (abs m ℕ.· abs n)
private
·-abs : ∀ m n → abs (m · n) ≡ abs m ℕ.· abs n
·-abs m n = refl
-- Natural number and negative integer literals for ℤ
open import Cubical.Data.Nat.Literals public
instance
fromNatℤ : HasFromNat ℤ
fromNatℤ = record { Constraint = λ _ → Unit ; fromNat = λ n → pos n }
instance
fromNegℤ : HasFromNeg ℤ
fromNegℤ = record { Constraint = λ _ → Unit ; fromNeg = λ n → neg n }
| 25.037037
| 87
| 0.619083
|
04fac9552d42599d28b21558390cccad1403351d
| 3,510
|
agda
|
Agda
|
agda/Utils.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | 3
|
2020-07-31T18:15:26.000Z
|
2022-02-19T12:15:21.000Z
|
agda/Utils.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
agda/Utils.agda
|
mchristianl/synthetic-reals
|
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts #-}
module Utils where -- thing that currently do not belong anywhere and do not have many dependencies
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
⊎-swap : ∀{x : Type ℓ} {y : Type ℓ'} → x ⊎ y → y ⊎ x
⊎-swap (inl x) = inr x
⊎-swap (inr x) = inl x
swap : ∀{x : Type ℓ} {y : Type ℓ'} → x × y → y × x
swap (x , y) = (y , x)
curry : ∀{ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} {C : (a : A) → (b : B a) → Type ℓ''}
→ ((p : Σ A B) → C (fst p) (snd p))
→ ((x : A) → (y : B x) → C x y)
curry f x y = f (x , y)
-- NOTE: this is non-hProp logic
-- contraposition : {P : Type ℓ} {Q : Type ℓ'} → (P → Q) → ¬ Q → ¬ P
-- contraposition f ¬q p = ⊥-elim (¬q (f p))
deMorgan₂' : {P : Type ℓ} {Q : Type ℓ'} → ¬(P ⊎ Q) → (¬ P) × (¬ Q)
deMorgan₂' {P = P} {Q = Q} ¬[p⊎q] = (λ p → ⊥-elim (¬[p⊎q] (inl p))) , λ q → ⊥-elim (¬[p⊎q] (inr q))
deMorgan₂-back' : {P : Type ℓ} {Q : Type ℓ'} → (¬ P) × (¬ Q) → ¬(P ⊎ Q)
deMorgan₂-back' (¬p , ¬q) (inl p) = ¬p p
deMorgan₂-back' (¬p , ¬q) (inr q) = ¬q q
-- hPropRel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ'))
-- hPropRel A B ℓ' = A → B → hProp ℓ'
{- NOTE: there is also `Relation.Binary.PropositionalEquality` where they write:
-- Inspect can be used when you want to pattern match on the result r
-- of some expression e, and you also need to "remember" that r ≡ e.
-- See README.Inspect for an explanation of how/why to use this.
record Reveal_·_is_ {A : Set a} {B : A → Set b}
(f : (x : A) → B x) (x : A) (y : B x) :
Set (a ⊔ b) where
constructor [_]
field eq : f x ≡ y
inspect : ∀ {A : Set a} {B : A → Set b}
(f : (x : A) → B x) (x : A) → Reveal f · x is f x
inspect f x = [ refl ]
-}
{- NOTE: an example is
plus-eq-with : ∀ m n → Plus-eq m n (m + n)
plus-eq-with m n with m + n | inspect (m +_) n
... | zero | [ m+n≡0 ] = m+n≡0⇒m≡0 m m+n≡0 , m+n≡0⇒n≡0 m m+n≡0
... | suc p | [ m+n≡1+p ] = m+n≡1+p
-} -- so this looks like a mechanism for "@-pattern-disribution over `with` cases"
record !_ {ℓ} (X : Type ℓ) : Type ℓ where
inductive
constructor !!_ -- map "into" `!!_ : X → ! X`
field !!!_ : X -- map "out of" `!!!_ : ! X → X`
infix 1 !!!_
open !_ public -- brings !!!_ into scope
infix 1 !!_
infix 1 !_
!-iso : ∀{ℓ} {X : Type ℓ} → Iso (! X) X
Iso.fun !-iso = !!!_
Iso.inv !-iso = !!_
Iso.rightInv !-iso = λ x → refl
Iso.leftInv !-iso = λ{ (!! x) → refl }
!-≡ : ∀{ℓ} {X : Type ℓ} → (! X) ≡ X
!-≡ {X = X} = isoToPath !-iso
!-equiv : ∀{ℓ} {X : Type ℓ} → (! X) ≃ X
!-equiv = !!!_ , λ where .equiv-proof x → ((!! x) , refl) , λ{ ((!! y) , p) → λ i → (!! p (~ i)) , (λ j → p (~ i ∨ j)) }
-- `A unfold refl to B` checks `A` and `B` to be definitionally equal (with `refl`) and then uses `B`
-- this allows for a nicer Goal/Have at the very beginning of implementing and when using something
unfold' : ∀{ℓ A} → (x y : A) → _≡_ {ℓ} x y → _
unfold' x y p = y
infix -8 unfold'
syntax unfold' x y p = x unfold p to y
{-# DISPLAY unfold' x y p = p #-}
| 34.411765
| 120
| 0.535328
|
8be867f0aeda6f13f29504777990684139a9f7ad
| 23,881
|
agda
|
Agda
|
Grammar/Non-terminal.agda
|
nad/pretty
|
b956803ba90b6c5f57bbbaab01bb18485d948492
|
[
"MIT"
] | null | null | null |
Grammar/Non-terminal.agda
|
nad/pretty
|
b956803ba90b6c5f57bbbaab01bb18485d948492
|
[
"MIT"
] | null | null | null |
Grammar/Non-terminal.agda
|
nad/pretty
|
b956803ba90b6c5f57bbbaab01bb18485d948492
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Grammars defined as functions from non-terminals to productions
------------------------------------------------------------------------
{-# OPTIONS --safe #-}
module Grammar.Non-terminal where
open import Algebra
open import Category.Monad
open import Data.Bool
open import Data.Bool.Properties
open import Data.Char
open import Data.Empty
open import Data.List hiding (unfold)
open import Data.List.Properties
open import Data.Maybe hiding (_>>=_)
open import Data.Maybe.Categorical as MaybeC
open import Data.Nat
open import Data.Product as Product
open import Data.Unit
open import Function
open import Level using (Lift; lift)
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
open import Relation.Nullary
open import Tactic.MonoidSolver
private
module LM {A : Set} = Monoid (++-monoid A)
open module MM {f} = RawMonadPlus (MaybeC.monadPlus {f = f})
using ()
renaming (_<$>_ to _<$>M_; _⊛_ to _⊛M_;
_>>=_ to _>>=M_; _∣_ to _∣M_)
open import Utilities
------------------------------------------------------------------------
-- Grammars
-- Productions. (Note that productions can contain choices.)
infix 30 _⋆
infixl 20 _⊛_ _<⊛_
infixl 15 _>>=_
infixl 10 _∣_
data Prod (NT : Set → Set₁) : Set → Set₁ where
! : ∀ {A} → NT A → Prod NT A
fail : ∀ {A} → Prod NT A
return : ∀ {A} → A → Prod NT A
token : Prod NT Char
tok : Char → Prod NT Char
_⊛_ : ∀ {A B} → Prod NT (A → B) → Prod NT A → Prod NT B
_<⊛_ : ∀ {A B} → Prod NT A → Prod NT B → Prod NT A
_>>=_ : ∀ {A B} → Prod NT A → (A → Prod NT B) → Prod NT B
_∣_ : ∀ {A} → Prod NT A → Prod NT A → Prod NT A
_⋆ : ∀ {A} → Prod NT A → Prod NT (List A)
-- Grammars.
Grammar : (Set → Set₁) → Set₁
Grammar NT = ∀ A → NT A → Prod NT A
-- An empty non-terminal type.
Empty-NT : Set → Set₁
Empty-NT _ = Lift _ ⊥
-- A corresponding grammar.
empty-grammar : Grammar Empty-NT
empty-grammar _ (lift ())
------------------------------------------------------------------------
-- Production combinators
-- Map.
infixl 20 _<$>_ _<$_
_<$>_ : ∀ {NT A B} → (A → B) → Prod NT A → Prod NT B
f <$> p = return f ⊛ p
_<$_ : ∀ {NT A B} → A → Prod NT B → Prod NT A
x <$ p = return x <⊛ p
-- Various sequencing operators.
infixl 20 _⊛>_
infixl 15 _>>_
_>>_ : ∀ {NT A B} → Prod NT A → Prod NT B → Prod NT B
p₁ >> p₂ = (λ _ x → x) <$> p₁ ⊛ p₂
_⊛>_ : ∀ {NT A B} → Prod NT A → Prod NT B → Prod NT B
_⊛>_ = _>>_
-- Kleene plus.
infix 30 _+
_+ : ∀ {NT A} → Prod NT A → Prod NT (List A)
p + = _∷_ <$> p ⊛ p ⋆
-- Elements separated by something.
infixl 18 _sep-by_
_sep-by_ : ∀ {NT A B} → Prod NT A → Prod NT B → Prod NT (List A)
g sep-by sep = _∷_ <$> g ⊛ (sep >> g) ⋆
-- A production for tokens satisfying a given predicate.
if-true : ∀ {NT} (b : Bool) → Prod NT (T b)
if-true true = return tt
if-true false = fail
sat : ∀ {NT} (p : Char → Bool) → Prod NT (∃ λ t → T (p t))
sat p = token >>= λ t → _,_ t <$> if-true (p t)
-- A production for whitespace.
whitespace : ∀ {NT} → Prod NT Char
whitespace = tok ' ' ∣ tok '\n'
-- A production for a given string.
string : ∀ {NT} → List Char → Prod NT (List Char)
string [] = return []
string (t ∷ s) = _∷_ <$> tok t ⊛ string s
-- A production for the given string, possibly followed by some
-- whitespace.
symbol : ∀ {NT} → List Char → Prod NT (List Char)
symbol s = string s <⊛ whitespace ⋆
------------------------------------------------------------------------
-- Semantics
infix 4 [_]_∈_·_
data [_]_∈_·_ {NT : Set → Set₁} (g : Grammar NT) :
∀ {A} → A → Prod NT A → List Char → Set₁ where
!-sem : ∀ {A} {nt : NT A} {x s} →
[ g ] x ∈ g A nt · s → [ g ] x ∈ ! nt · s
return-sem : ∀ {A} {x : A} → [ g ] x ∈ return x · []
token-sem : ∀ {t} → [ g ] t ∈ token · [ t ]
tok-sem : ∀ {t} → [ g ] t ∈ tok t · [ t ]
⊛-sem : ∀ {A B} {p₁ : Prod NT (A → B)} {p₂ : Prod NT A}
{f x s₁ s₂} →
[ g ] f ∈ p₁ · s₁ → [ g ] x ∈ p₂ · s₂ →
[ g ] f x ∈ p₁ ⊛ p₂ · s₁ ++ s₂
<⊛-sem : ∀ {A B} {p₁ : Prod NT A} {p₂ : Prod NT B} {x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ · s₂ →
[ g ] x ∈ p₁ <⊛ p₂ · s₁ ++ s₂
>>=-sem : ∀ {A B} {p₁ : Prod NT A} {p₂ : A → Prod NT B}
{x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ x · s₂ →
[ g ] y ∈ p₁ >>= p₂ · s₁ ++ s₂
left-sem : ∀ {A} {p₁ p₂ : Prod NT A} {x s} →
[ g ] x ∈ p₁ · s → [ g ] x ∈ p₁ ∣ p₂ · s
right-sem : ∀ {A} {p₁ p₂ : Prod NT A} {x s} →
[ g ] x ∈ p₂ · s → [ g ] x ∈ p₁ ∣ p₂ · s
⋆-[]-sem : ∀ {A} {p : Prod NT A} →
[ g ] [] ∈ p ⋆ · []
⋆-+-sem : ∀ {A} {p : Prod NT A} {xs s} →
[ g ] xs ∈ p + · s → [ g ] xs ∈ p ⋆ · s
-- Cast lemma.
cast : ∀ {NT g A} {p : Prod NT A} {x s₁ s₂} →
s₁ ≡ s₂ → [ g ] x ∈ p · s₁ → [ g ] x ∈ p · s₂
cast P.refl = id
------------------------------------------------------------------------
-- Semantics combinators
<$>-sem : ∀ {NT} {g : Grammar NT} {A B} {f : A → B} {x p s} →
[ g ] x ∈ p · s → [ g ] f x ∈ f <$> p · s
<$>-sem x∈ = ⊛-sem return-sem x∈
<$-sem : ∀ {NT g A B} {p : Prod NT B} {x : A} {y s} →
[ g ] y ∈ p · s → [ g ] x ∈ x <$ p · s
<$-sem y∈ = <⊛-sem return-sem y∈
>>-sem : ∀ {NT g A B} {p₁ : Prod NT A} {p₂ : Prod NT B} {x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ · s₂ →
[ g ] y ∈ p₁ >> p₂ · s₁ ++ s₂
>>-sem x∈ y∈ = ⊛-sem (⊛-sem return-sem x∈) y∈
⊛>-sem : ∀ {NT g A B} {p₁ : Prod NT A} {p₂ : Prod NT B} {x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ · s₂ →
[ g ] y ∈ p₁ ⊛> p₂ · s₁ ++ s₂
⊛>-sem = >>-sem
+-sem : ∀ {NT g A} {p : Prod NT A} {x xs s₁ s₂} →
[ g ] x ∈ p · s₁ → [ g ] xs ∈ p ⋆ · s₂ →
[ g ] x ∷ xs ∈ p + · s₁ ++ s₂
+-sem x∈ xs∈ = ⊛-sem (⊛-sem return-sem x∈) xs∈
⋆-∷-sem : ∀ {NT g A} {p : Prod NT A} {x xs s₁ s₂} →
[ g ] x ∈ p · s₁ → [ g ] xs ∈ p ⋆ · s₂ →
[ g ] x ∷ xs ∈ p ⋆ · s₁ ++ s₂
⋆-∷-sem x∈ xs∈ = ⋆-+-sem (+-sem x∈ xs∈)
⋆-⋆-sem : ∀ {NT g A} {p : Prod NT A} {xs₁ xs₂ s₁ s₂} →
[ g ] xs₁ ∈ p ⋆ · s₁ → [ g ] xs₂ ∈ p ⋆ · s₂ →
[ g ] xs₁ ++ xs₂ ∈ p ⋆ · s₁ ++ s₂
⋆-⋆-sem ⋆-[]-sem xs₂∈ = xs₂∈
⋆-⋆-sem (⋆-+-sem (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) xs₁∈)) xs₂∈ =
cast (P.sym $ LM.assoc s₁ _ _)
(⋆-∷-sem x∈ (⋆-⋆-sem xs₁∈ xs₂∈))
+-∷-sem : ∀ {NT g A} {p : Prod NT A} {x xs s₁ s₂} →
[ g ] x ∈ p · s₁ → [ g ] xs ∈ p + · s₂ →
[ g ] x ∷ xs ∈ p + · s₁ ++ s₂
+-∷-sem x∈ xs∈ = +-sem x∈ (⋆-+-sem xs∈)
+-⋆-sem : ∀ {NT g A} {p : Prod NT A} {xs₁ xs₂ s₁ s₂} →
[ g ] xs₁ ∈ p + · s₁ → [ g ] xs₂ ∈ p ⋆ · s₂ →
[ g ] xs₁ ++ xs₂ ∈ p + · s₁ ++ s₂
+-⋆-sem (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) xs₁∈) xs₂∈ =
cast (P.sym $ LM.assoc s₁ _ _)
(+-sem x∈ (⋆-⋆-sem xs₁∈ xs₂∈))
sep-by-sem-singleton :
∀ {NT g A B} {p : Prod NT A} {sep : Prod NT B} {x s} →
[ g ] x ∈ p · s → [ g ] [ x ] ∈ p sep-by sep · s
sep-by-sem-singleton x∈ =
cast (proj₂ LM.identity _) (⊛-sem (<$>-sem x∈) ⋆-[]-sem)
sep-by-sem-∷ :
∀ {NT g A B} {p : Prod NT A} {sep : Prod NT B} {x y xs s₁ s₂ s₃} →
[ g ] x ∈ p · s₁ → [ g ] y ∈ sep · s₂ → [ g ] xs ∈ p sep-by sep · s₃ →
[ g ] x ∷ xs ∈ p sep-by sep · s₁ ++ s₂ ++ s₃
sep-by-sem-∷ {s₂ = s₂} x∈ y∈ (⊛-sem (⊛-sem return-sem x′∈) xs∈) =
⊛-sem (<$>-sem x∈)
(cast (LM.assoc s₂ _ _) (⋆-∷-sem (>>-sem y∈ x′∈) xs∈))
if-true-sem : ∀ {NT} {g : Grammar NT} {b}
(t : T b) → [ g ] t ∈ if-true b · []
if-true-sem {b = true} _ = return-sem
if-true-sem {b = false} ()
sat-sem : ∀ {NT} {g : Grammar NT} {p t}
(pt : T (p t)) → [ g ] (t , pt) ∈ sat p · [ t ]
sat-sem pt = >>=-sem token-sem (<$>-sem (if-true-sem pt))
whitespace-sem-space : ∀ {NT} {g : Grammar NT} →
[ g ] ' ' ∈ whitespace · [ ' ' ]
whitespace-sem-space = left-sem tok-sem
whitespace-sem-newline : ∀ {NT} {g : Grammar NT} →
[ g ] '\n' ∈ whitespace · [ '\n' ]
whitespace-sem-newline = right-sem tok-sem
string-sem : ∀ {NT} {g : Grammar NT} {s} →
[ g ] s ∈ string s · s
string-sem {s = []} = return-sem
string-sem {s = t ∷ s} = ⊛-sem (<$>-sem tok-sem) string-sem
symbol-sem : ∀ {NT} {g : Grammar NT} {s s′ s″} →
[ g ] s″ ∈ whitespace ⋆ · s′ → [ g ] s ∈ symbol s · s ++ s′
symbol-sem s″∈ = <⊛-sem string-sem s″∈
------------------------------------------------------------------------
-- Some production transformers
-- Replaces all non-terminals with non-terminal-free productions.
replace : ∀ {NT A} → (∀ {A} → NT A → Prod Empty-NT A) →
Prod NT A → Prod Empty-NT A
replace f (! nt) = f nt
replace f fail = fail
replace f (return x) = return x
replace f token = token
replace f (tok x) = tok x
replace f (p₁ ⊛ p₂) = replace f p₁ ⊛ replace f p₂
replace f (p₁ <⊛ p₂) = replace f p₁ <⊛ replace f p₂
replace f (p₁ >>= p₂) = replace f p₁ >>= λ x → replace f (p₂ x)
replace f (p₁ ∣ p₂) = replace f p₁ ∣ replace f p₂
replace f (p ⋆) = replace f p ⋆
-- A lemma relating the resulting production with the original one in
-- case every non-terminal is replaced by fail.
replace-fail :
∀ {NT A g} (p : Prod NT A) {x s} →
[ empty-grammar ] x ∈ replace (λ _ → fail) p · s →
[ g ] x ∈ p · s
replace-fail (! nt) ()
replace-fail fail ()
replace-fail (return x) return-sem = return-sem
replace-fail token token-sem = token-sem
replace-fail (tok t) tok-sem = tok-sem
replace-fail (p₁ ⊛ p₂) (⊛-sem f∈ x∈) = ⊛-sem (replace-fail p₁ f∈) (replace-fail p₂ x∈)
replace-fail (p₁ <⊛ p₂) (<⊛-sem x∈ y∈) = <⊛-sem (replace-fail p₁ x∈) (replace-fail p₂ y∈)
replace-fail (p₁ >>= p₂) (>>=-sem x∈ y∈) = >>=-sem (replace-fail p₁ x∈) (replace-fail (p₂ _) y∈)
replace-fail (p₁ ∣ p₂) (left-sem x∈) = left-sem (replace-fail p₁ x∈)
replace-fail (p₁ ∣ p₂) (right-sem x∈) = right-sem (replace-fail p₂ x∈)
replace-fail (p ⋆) ⋆-[]-sem = ⋆-[]-sem
replace-fail (p ⋆) (⋆-+-sem xs∈) = ⋆-+-sem (replace-fail (p +) xs∈)
-- Unfolds every non-terminal. At most n /nested/ unfoldings are
-- performed.
unfold : ∀ {NT A} → (n : ℕ) → Grammar NT → Prod NT A → Prod NT A
unfold zero g p = p
unfold (suc n) g (! nt) = unfold n g (g _ nt)
unfold n g fail = fail
unfold n g (return x) = return x
unfold n g token = token
unfold n g (tok x) = tok x
unfold n g (p₁ ⊛ p₂) = unfold n g p₁ ⊛ unfold n g p₂
unfold n g (p₁ <⊛ p₂) = unfold n g p₁ <⊛ unfold n g p₂
unfold n g (p₁ >>= p₂) = unfold n g p₁ >>= λ x → unfold n g (p₂ x)
unfold n g (p₁ ∣ p₂) = unfold n g p₁ ∣ unfold n g p₂
unfold n g (p ⋆) = unfold n g p ⋆
-- Unfold is semantics-preserving.
unfold-to : ∀ {NT A} {g : Grammar NT} {x s} n (p : Prod NT A) →
[ g ] x ∈ p · s → [ g ] x ∈ unfold n g p · s
unfold-to zero p x∈ = x∈
unfold-to (suc n) (! nt) (!-sem x∈) = unfold-to n _ x∈
unfold-to (suc n) fail x∈ = x∈
unfold-to (suc n) (return x) x∈ = x∈
unfold-to (suc n) token x∈ = x∈
unfold-to (suc n) (tok x) x∈ = x∈
unfold-to (suc n) (p₁ ⊛ p₂) (⊛-sem f∈ x∈) = ⊛-sem (unfold-to (suc n) p₁ f∈)
(unfold-to (suc n) p₂ x∈)
unfold-to (suc n) (p₁ <⊛ p₂) (<⊛-sem x∈ y∈) = <⊛-sem (unfold-to (suc n) p₁ x∈)
(unfold-to (suc n) p₂ y∈)
unfold-to (suc n) (p₁ >>= p₂) (>>=-sem x∈ y∈) = >>=-sem (unfold-to (suc n) p₁ x∈)
(unfold-to (suc n) (p₂ _) y∈)
unfold-to (suc n) (p₁ ∣ p₂) (left-sem x∈) = left-sem (unfold-to (suc n) p₁ x∈)
unfold-to (suc n) (p₁ ∣ p₂) (right-sem x∈) = right-sem (unfold-to (suc n) p₂ x∈)
unfold-to (suc n) (p ⋆) ⋆-[]-sem = ⋆-[]-sem
unfold-to (suc n) (p ⋆) (⋆-+-sem xs∈) = ⋆-+-sem (unfold-to (suc n) (p +) xs∈)
unfold-from : ∀ {NT A} {g : Grammar NT} {x s} n (p : Prod NT A) →
[ g ] x ∈ unfold n g p · s → [ g ] x ∈ p · s
unfold-from zero p x∈ = x∈
unfold-from (suc n) (! nt) x∈ = !-sem (unfold-from n _ x∈)
unfold-from (suc n) fail x∈ = x∈
unfold-from (suc n) (return x) x∈ = x∈
unfold-from (suc n) token x∈ = x∈
unfold-from (suc n) (tok x) x∈ = x∈
unfold-from (suc n) (p₁ ⊛ p₂) (⊛-sem f∈ x∈) = ⊛-sem (unfold-from (suc n) p₁ f∈)
(unfold-from (suc n) p₂ x∈)
unfold-from (suc n) (p₁ <⊛ p₂) (<⊛-sem x∈ y∈) = <⊛-sem (unfold-from (suc n) p₁ x∈)
(unfold-from (suc n) p₂ y∈)
unfold-from (suc n) (p₁ >>= p₂) (>>=-sem x∈ y∈) = >>=-sem (unfold-from (suc n) p₁ x∈)
(unfold-from (suc n) (p₂ _) y∈)
unfold-from (suc n) (p₁ ∣ p₂) (left-sem x∈) = left-sem (unfold-from (suc n) p₁ x∈)
unfold-from (suc n) (p₁ ∣ p₂) (right-sem x∈) = right-sem (unfold-from (suc n) p₂ x∈)
unfold-from (suc n) (p ⋆) ⋆-[]-sem = ⋆-[]-sem
unfold-from (suc n) (p ⋆) (⋆-+-sem xs∈) = ⋆-+-sem (unfold-from (suc n) (p +) xs∈)
------------------------------------------------------------------------
-- Nullability
-- A production is nullable (with respect to a given grammar) if the
-- empty string is a member of the language defined by the production.
Nullable : ∀ {NT A} → Grammar NT → Prod NT A → Set₁
Nullable g p = ∃ λ x → [ g ] x ∈ p · []
-- Nullability is not decidable, not even for productions without
-- non-terminals. If nullability were decidable, then we could decide
-- if a given function of type ℕ → Bool always returns false.
nullability-not-decidable :
(∀ {A} (p : Prod Empty-NT A) → Dec (Nullable empty-grammar p)) →
(f : ℕ → Bool) → Dec (∀ n → f n ≡ false)
nullability-not-decidable dec f = goal
where
p : Prod Empty-NT ℕ
p = return tt ⋆ >>= λ tts →
let n = length tts in
if f n then return n else fail
true-lemma : ∀ {n s} → [ empty-grammar ] n ∈ p · s → f n ≡ true
true-lemma (>>=-sem {x = tts} _ _)
with f (length tts) | P.inspect f (length tts)
true-lemma (>>=-sem _ return-sem) | true | P.[ fn≡true ] = fn≡true
true-lemma (>>=-sem _ ()) | false | _
no-lemma : ∀ {n} → f n ≡ true → ¬ (∀ n → f n ≡ false)
no-lemma {n} ≡true ≡false with begin
true ≡⟨ P.sym ≡true ⟩
f n ≡⟨ ≡false n ⟩
false ∎
where open P.≡-Reasoning
... | ()
to-tts : ℕ → List ⊤
to-tts n = replicate n tt
n∈₁ : ∀ n → [ empty-grammar ] to-tts n ∈ return tt ⋆ · []
n∈₁ zero = ⋆-[]-sem
n∈₁ (suc n) = ⋆-∷-sem return-sem (n∈₁ n)
n∈₂ : ∀ n → f n ≡ true →
let n′ = length (replicate n tt) in
[ empty-grammar ] n ∈ if f n′ then return n′ else fail · []
n∈₂ n fn≡true rewrite length-replicate n {x = tt} | fn≡true =
return-sem
yes-lemma : ∀ n → ¬ ([ empty-grammar ] n ∈ p · []) → f n ≢ true
yes-lemma n n∉ fn≡true = n∉ (>>=-sem (n∈₁ n) (n∈₂ n fn≡true))
goal : Dec (∀ n → f n ≡ false)
goal with dec p
... | yes (_ , n∈) = no (no-lemma (true-lemma n∈))
... | no ¬[]∈ = yes λ n → ¬-not (yes-lemma n (¬[]∈ ∘ -,_))
-- However, we can implement a procedure that either proves that a
-- production is nullable, or returns "don't know" as the answer.
--
-- Note that, in the case of bind, the second argument is only applied
-- to one input—the first argument could give rise to infinitely many
-- results (as in the example above).
--
-- Note also that no attempt is made to memoise non-terminals—the
-- grammar could consist of an infinite number of non-terminals.
-- Instead the grammar is unfolded a certain number of times (n).
-- Memoisation still seems like a useful heuristic, but requires that
-- equality of non-terminals is decidable.
nullable? : ∀ {NT A} (n : ℕ) (g : Grammar NT) (p : Prod NT A) →
Maybe (Nullable g p)
nullable? {NT} n g p =
Product.map id (unfold-from n _) <$>M null? (unfold n g p)
where
null? : ∀ {A} (p : Prod NT A) → Maybe (Nullable g p)
null? (! nt) = nothing
null? fail = nothing
null? token = nothing
null? (tok t) = nothing
null? (return x) = just (x , return-sem)
null? (p ⋆) = just ([] , ⋆-[]-sem)
null? (p₁ ⊛ p₂) = Product.zip _$_ ⊛-sem <$>M null? p₁ ⊛M null? p₂
null? (p₁ <⊛ p₂) = Product.zip const <⊛-sem <$>M null? p₁ ⊛M null? p₂
null? (p₁ >>= p₂) = null? p₁ >>=M λ { (x , x∈) →
null? (p₂ x) >>=M λ { (y , y∈) →
just (y , >>=-sem x∈ y∈) }}
null? (p₁ ∣ p₂) = (Product.map id left-sem <$>M null? p₁)
∣M
(Product.map id right-sem <$>M null? p₂)
------------------------------------------------------------------------
-- Detecting the whitespace combinator
-- A predicate for the whitespace combinator.
data Is-whitespace {NT} : ∀ {A} → Prod NT A → Set₁ where
is-whitespace : Is-whitespace whitespace
-- Detects the whitespace combinator.
is-whitespace? : ∀ {NT A} (p : Prod NT A) → Maybe (Is-whitespace p)
is-whitespace? {NT} (tok ' ' ∣ p) = helper p P.refl
where
helper : ∀ {A} (p : Prod NT A) (eq : A ≡ Char) →
Maybe (Is-whitespace (tok ' ' ∣ P.subst (Prod NT) eq p))
helper (tok '\n') P.refl = just is-whitespace
helper _ _ = nothing
is-whitespace? _ = nothing
------------------------------------------------------------------------
-- Trailing whitespace
-- A predicate for productions that can "swallow" extra trailing
-- whitespace.
Trailing-whitespace : ∀ {NT A} → Grammar NT → Prod NT A → Set₁
Trailing-whitespace g p =
∀ {x s} → [ g ] x ∈ p <⊛ whitespace ⋆ · s → [ g ] x ∈ p · s
-- A heuristic procedure that either proves that a production can
-- swallow trailing whitespace, or returns "don't know" as the answer.
trailing-whitespace :
∀ {NT A} (n : ℕ) (g : Grammar NT) (p : Prod NT A) →
Maybe (Trailing-whitespace g p)
trailing-whitespace {NT} n g p =
convert ∘ unfold-lemma <$>M trailing? (unfold n g p)
where
-- An alternative formulation of Trailing-whitespace.
Trailing-whitespace′ : ∀ {NT A} → Grammar NT → Prod NT A → Set₁
Trailing-whitespace′ g p =
∀ {x s₁ s₂ s} →
[ g ] x ∈ p · s₁ → [ g ] s ∈ whitespace ⋆ · s₂ →
[ g ] x ∈ p · s₁ ++ s₂
convert : ∀ {NT A} {g : Grammar NT} {p : Prod NT A} →
Trailing-whitespace′ g p → Trailing-whitespace g p
convert t (<⊛-sem x∈ w) = t x∈ w
++-lemma : ∀ s₁ {s₂} → (s₁ ++ s₂) ++ [] ≡ (s₁ ++ []) ++ s₂
++-lemma _ = solve (++-monoid Char)
unfold-lemma : Trailing-whitespace′ g (unfold n g p) →
Trailing-whitespace′ g p
unfold-lemma t x∈ white = unfold-from n _ (t (unfold-to n _ x∈) white)
⊛-return-lemma :
∀ {A B} {p : Prod NT (A → B)} {x} →
Trailing-whitespace′ g p →
Trailing-whitespace′ g (p ⊛ return x)
⊛-return-lemma t (⊛-sem {s₁ = s₁} f∈ return-sem) white =
cast (++-lemma s₁) (⊛-sem (t f∈ white) return-sem)
+-lemma :
∀ {A} {p : Prod NT A} →
Trailing-whitespace′ g p →
Trailing-whitespace′ g (p +)
+-lemma t (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) ⋆-[]-sem) white =
cast (++-lemma s₁) (+-sem (t x∈ white) ⋆-[]-sem)
+-lemma t (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) (⋆-+-sem xs∈))
white =
cast (P.sym $ LM.assoc s₁ _ _)
(+-∷-sem x∈ (+-lemma t xs∈ white))
⊛-⋆-lemma :
∀ {A B} {p₁ : Prod NT (List A → B)} {p₂ : Prod NT A} →
Trailing-whitespace′ g p₁ →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ ⊛ p₂ ⋆)
⊛-⋆-lemma t₁ t₂ (⊛-sem {s₁ = s₁} f∈ ⋆-[]-sem) white =
cast (++-lemma s₁) (⊛-sem (t₁ f∈ white) ⋆-[]-sem)
⊛-⋆-lemma t₁ t₂ (⊛-sem {s₁ = s₁} f∈ (⋆-+-sem xs∈)) white =
cast (P.sym $ LM.assoc s₁ _ _)
(⊛-sem f∈ (⋆-+-sem (+-lemma t₂ xs∈ white)))
⊛-∣-lemma : ∀ {A B} {p₁ : Prod NT (A → B)} {p₂ p₃ : Prod NT A} →
Trailing-whitespace′ g (p₁ ⊛ p₂) →
Trailing-whitespace′ g (p₁ ⊛ p₃) →
Trailing-whitespace′ g (p₁ ⊛ (p₂ ∣ p₃))
⊛-∣-lemma t₁₂ t₁₃ {s₂ = s₃}
(⊛-sem {f = f} {x = x} {s₁ = s₁} {s₂ = s₂} f∈ (left-sem x∈))
white
with f x | (s₁ ++ s₂) ++ s₃ | t₁₂ (⊛-sem f∈ x∈) white
... | ._ | ._ | ⊛-sem f∈′ x∈′ = ⊛-sem f∈′ (left-sem x∈′)
⊛-∣-lemma t₁₂ t₁₃ {s₂ = s₃}
(⊛-sem {f = f} {x = x} {s₁ = s₁} {s₂ = s₂} f∈ (right-sem x∈))
white
with f x | (s₁ ++ s₂) ++ s₃ | t₁₃ (⊛-sem f∈ x∈) white
... | ._ | ._ | ⊛-sem f∈′ x∈′ = ⊛-sem f∈′ (right-sem x∈′)
⊛-lemma : ∀ {A B} {p₁ : Prod NT (A → B)} {p₂ : Prod NT A} →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ ⊛ p₂)
⊛-lemma t₂ (⊛-sem {s₁ = s₁} f∈ x∈) white =
cast (P.sym $ LM.assoc s₁ _ _)
(⊛-sem f∈ (t₂ x∈ white))
<⊛-return-lemma :
∀ {A B} {p : Prod NT A} {x : B} →
Trailing-whitespace′ g p →
Trailing-whitespace′ g (p <⊛ return x)
<⊛-return-lemma t (<⊛-sem {s₁ = s₁} f∈ return-sem) white =
cast (++-lemma s₁) (<⊛-sem (t f∈ white) return-sem)
<⊛-⋆-lemma :
∀ {A B} {p₁ : Prod NT A} {p₂ : Prod NT B} →
Is-whitespace p₂ →
Trailing-whitespace′ g (p₁ <⊛ p₂ ⋆)
<⊛-⋆-lemma is-whitespace (<⊛-sem {s₁ = s₁} x∈ white₁) white₂ =
cast (P.sym $ LM.assoc s₁ _ _)
(<⊛-sem x∈ (⋆-⋆-sem white₁ white₂))
<⊛-lemma : ∀ {A B} {p₁ : Prod NT A} {p₂ : Prod NT B} →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ <⊛ p₂)
<⊛-lemma t₂ (<⊛-sem {s₁ = s₁} f∈ x∈) white =
cast (P.sym $ LM.assoc s₁ _ _)
(<⊛-sem f∈ (t₂ x∈ white))
fail->>=-lemma : ∀ {A B} {p : A → Prod NT B} →
Trailing-whitespace′ g (fail >>= p)
fail->>=-lemma (>>=-sem () _)
return->>=-lemma : ∀ {A B} {p : A → Prod NT B} {x} →
Trailing-whitespace′ g (p x) →
Trailing-whitespace′ g (return x >>= p)
return->>=-lemma t (>>=-sem return-sem y∈) white =
>>=-sem return-sem (t y∈ white)
tok->>=-lemma : ∀ {A} {p : Char → Prod NT A} {t} →
Trailing-whitespace′ g (p t) →
Trailing-whitespace′ g (tok t >>= p)
tok->>=-lemma t (>>=-sem tok-sem y∈) white =
>>=-sem tok-sem (t y∈ white)
∣-lemma : ∀ {A} {p₁ p₂ : Prod NT A} →
Trailing-whitespace′ g p₁ →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ ∣ p₂)
∣-lemma t₁ t₂ (left-sem x∈) white = left-sem (t₁ x∈ white)
∣-lemma t₁ t₂ (right-sem x∈) white = right-sem (t₂ x∈ white)
trailing? : ∀ {A} (p : Prod NT A) →
Maybe (Trailing-whitespace′ g p)
trailing? fail = just (λ ())
trailing? (p ⊛ return x) = ⊛-return-lemma <$>M trailing? p
trailing? (p₁ ⊛ p₂ ⋆) = ⊛-⋆-lemma <$>M trailing? p₁ ⊛M trailing? p₂
trailing? (p₁ ⊛ (p₂ ∣ p₃)) = ⊛-∣-lemma <$>M trailing? (p₁ ⊛ p₂)
⊛M trailing? (p₁ ⊛ p₃)
trailing? (p₁ ⊛ p₂) = ⊛-lemma <$>M trailing? p₂
trailing? (p <⊛ return x) = <⊛-return-lemma <$>M trailing? p
trailing? (p₁ <⊛ p₂ ⋆) = <⊛-⋆-lemma <$>M is-whitespace? p₂
trailing? (p₁ <⊛ p₂) = <⊛-lemma <$>M trailing? p₂
trailing? (fail >>= p) = just fail->>=-lemma
trailing? (return x >>= p) = return->>=-lemma <$>M trailing? (p x)
trailing? (tok t >>= p) = tok->>=-lemma <$>M trailing? (p t)
trailing? (p₁ ∣ p₂) = ∣-lemma <$>M trailing? p₁ ⊛M trailing? p₂
trailing? _ = nothing
private
-- A unit test.
test : T (is-just (trailing-whitespace
0 empty-grammar (tt <$ whitespace ⋆)))
test = _
| 37.846276
| 96
| 0.479503
|
4b0dd628c7d294c4bd9bf78d3929b7b9e5028188
| 10,200
|
agda
|
Agda
|
examples/GUIgeneric/GUIFeaturesPart2.agda
|
stephanadls/state-dependent-gui
|
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
|
[
"MIT"
] | 2
|
2020-07-31T15:37:39.000Z
|
2020-07-31T17:20:59.000Z
|
examples/GUIgeneric/GUIFeaturesPart2.agda
|
stephanadls/state-dependent-gui
|
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
|
[
"MIT"
] | null | null | null |
examples/GUIgeneric/GUIFeaturesPart2.agda
|
stephanadls/state-dependent-gui
|
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
|
[
"MIT"
] | null | null | null |
module GUIgeneric.GUIFeaturesPart2 where
open import GUIgeneric.Prelude renaming (addButton to addButton')
open import GUIgeneric.GUIDefinitions renaming (add to add'; add' to add)
open import GUIgeneric.GUI
open import GUIgeneric.GUIExampleLib
open import StateSizedIO.GUI.WxGraphicsLibLevel3 renaming (addButton to addButton')
open import GUIgeneric.GUIFeatures
open import GUIgeneric.GUIExample using (propOneBtn; propTwoBtn ; black ; oneColumnLayout)
open import Data.Product
open import Data.Fin
data ReturnTypeₛ (S : Set) : Set where
noChange : ReturnTypeₛ S
changedState : (snew : S) → ReturnTypeₛ S
-- handler GUI interface with separte state (i.e. state is a separte set instead of GUI)
-- We might later separte State into a gui state and property state i.e. have
-- GuiState : Set
-- AttrState : GuiState → Set
-- s2GUI : GuiState → GUI
-- s2prop : (g : GuiState)(prop : AttrState g) → properties (s2GUI g)
handlerGUIInterfₛ : (S : Set) (s2GUI : (s : S) → Frame)
→ Interfaceˢ
handlerGUIInterfₛ S s2GUI .Stateˢ = S
handlerGUIInterfₛ S s2GUI .Methodˢ s = methodsG (s2GUI s)
handlerGUIInterfₛ S s2GUI .Resultˢ s m = ReturnTypeₛ S
handlerGUIInterfₛ S s2GUI .nextˢ s m noChange = s
handlerGUIInterfₛ S s2GUI .nextˢ s m (changedState snew) = snew
handlerGUIObjectₛ : (i : Size)(S : Set) (s2GUI : (s : S) → Frame)(s : S) → Set
handlerGUIObjectₛ i S s2GUI s = IOObjectˢ- GuiLev1Interface (handlerGUIInterfₛ S s2GUI) i s
mutual
hGuiObjₛ2ord : (i : Size)(S : Set)
(s2GUI : (s : S) → Frame)
(s2prop : (s : S) → properties (s2GUI s))
(obj : (s : S) → handlerGUIObjectₛ i S s2GUI s)
(s : S)
→ HandlerObject i (s2GUI s)
method (hGuiObjₛ2ord i S s2GUI s2prop obj s) {j} m =
hGuiObjₛ2ordaux ∞ j S s2GUI s s2prop obj m (method (obj s) m )
hGuiObjₛ2ordaux' : (j : Size)(j' : Size)(S : Set)
(s2GUI : (s : S) → Frame)(s : S)
(s2prop : (s : S) → properties (s2GUI s))
(obj : (s : S) → handlerGUIObjectₛ j' S s2GUI s)
(m : methodsG (s2GUI s))
(prog : IO' GuiLev1Interface j
(ReturnTypeₛ S))
→ IO' GuiLev1Interface j
( Σ[ r ∈ returnType (s2GUI s) ]
(IOObjectˢ GuiLev1Interface handlerInterface j'
(nextˢ handlerInterface (s2GUI s) m r)))
hGuiObjₛ2ordaux' j j' S s2GUI s s2prop obj m (do' c f) = do' c (λ r → hGuiObjₛ2ordaux j j' S s2GUI s s2prop obj m (f r) )
hGuiObjₛ2ordaux' j j' S s2GUI s s2prop obj m (return' noChange ) = return' (noChange , hGuiObjₛ2ord j' S s2GUI s2prop obj s {-obj'-})
hGuiObjₛ2ordaux' j j' S s2GUI s s2prop obj m (return' (changedState snew)) = return' (changedGUI (s2GUI snew) (s2prop snew) , hGuiObjₛ2ord j' S s2GUI s2prop obj snew {- obj'-})
hGuiObjₛ2ordaux : (j : Size)(j' : Size)(S : Set)
(s2GUI : (s : S) → Frame)(s : S)
(s2prop : (s : S) → properties (s2GUI s))
(obj : (s : S) → handlerGUIObjectₛ j' S s2GUI s)
(m : methodsG (s2GUI s))
(prog : IO GuiLev1Interface j
(ReturnTypeₛ S))
→ IO GuiLev1Interface j
( Σ[ r ∈ returnType (s2GUI s) ]
(IOObjectˢ GuiLev1Interface handlerInterface j'
(nextˢ handlerInterface (s2GUI s) m r)))
force (hGuiObjₛ2ordaux j j' S s2GUI s s2prop obj m pr) {j''} = hGuiObjₛ2ordaux' j'' j' S s2GUI s s2prop obj m (force pr)
{- *** STATE MACHINES **** -}
sMachineHdl : (S : Set)(s : S) (f : Frame) → Set
sMachineHdl S s f = (m : methodsG f)
→ IO GuiLev1Interface ∞ (ReturnTypeₛ S)
record SMachineState (S : Set)(s : S) : Set where
field
fSM : Frame
propSM : properties fSM
handlSM : sMachineHdl S s fSM
SMachine : Set → Set
SMachine S = (s : S) → SMachineState S s
open SMachineState public
SMachine2HandlerGuiObjectₛ : (S : Set)
(sm : SMachine S)
(s : S)
→ handlerGUIObjectₛ ∞ S (λ s → sm s .fSM) s
method (SMachine2HandlerGuiObjectₛ S sm s) = sm s .handlSM
stateMachine2Obj : (S : Set)
(sm : SMachine S)
(s : S)
→ HandlerObject ∞ (sm s .fSM)
stateMachine2Obj S sm = hGuiObjₛ2ord ∞ S
(λ s → sm s .fSM)
(λ s → sm s .propSM)
(λ s → SMachine2HandlerGuiObjectₛ S sm s)
stateMachine2GUI : (S : Set) (sm : SMachine S) (s : S) → GUI
stateMachine2GUI S sm s .defFrame = sm s .fSM
stateMachine2GUI S sm s .property = sm s .propSM
stateMachine2GUI S sm s .obj = stateMachine2Obj S sm s
compileSMachine : {S : Set} (sm : SMachine S) (s : S)
→ NativeIO Unit
compileSMachine {S} sm s =
compileGUI (stateMachine2GUI S sm s)
{- **************** FEATURE MACHINE **** -}
-- an example of a feature machine wihout additional states:
record FeatureVMVers1 : Set₁ where
field
Features : Set
State : Set
GUIF : (f : Features) → SMachine State
record FMachine (BaseSt : Set) : Set₁ where
field
Features : Set
AddStateF : Set
GUIF : (f : Features) → SMachine (BaseSt ⊎ AddStateF)
State : Set
State = BaseSt ⊎ AddStateF
open FMachine public
featureVMFull2GUI : (BaseSt : Set)
(vm : FMachine BaseSt)
(f : vm .Features)
(s : State vm)
→ GUI
featureVMFull2GUI BaseSt vm f s =
stateMachine2GUI
(BaseSt ⊎ vm .AddStateF)
(vm .GUIF f) s
featureVMFull2IOˢprog : {BaseSt : Set}
(vm : FMachine BaseSt)
(f : vm .Features)
(s : State vm) → IOˢ GuiLev3Interface ∞ (λ _ → Unit) []
featureVMFull2IOˢprog {BaseSt} vm f s = guiFull2IOˢprog (featureVMFull2GUI BaseSt vm f s)
compileFeatureVM : {BaseSt : Set}
(vm : FMachine BaseSt)
(f : vm .Features)
(s : State vm)
→ NativeIO Unit
compileFeatureVM {BaseSt} vm f s = compileGUI (featureVMFull2GUI BaseSt vm f s)
{- methodsREduce creates from a method for the frame (addButon s g)
a method for g -}
mutual
methodsReduce : (g : Frame)(str : String)(m : MethodsStruct)
(u : methodsStruct2Method (addButton str g notOptimzed) m)
→ methodsStruct2Method g m
methodsReduce g str (fficom) (ffibtn , gcomp) = gcomp
methodsReduce g str (⊥^) ()
methodsReduce g str (m ⊎^unoptimized m₁) (inj₁ x) = inj₁ (methodsReduce g str m x)
methodsReduce g str (m ⊎^unoptimized m₁) (inj₂ y) = inj₂ (methodsReduce g str m₁ y)
methodsReduce g str (m ⊎^ m₁) x = methodsReduceaux g str m m₁
(methodsUnivIsEmpty m)
(methodsUnivIsEmpty m₁) x
methodsReduceaux : (g : Frame)(str : String)(m : MethodsStruct)
(m₁ : MethodsStruct)
(s : SemiDec (λ g' → methodsStruct2Method g' m))
(s₁ : SemiDec (λ g' → methodsStruct2Method g' m₁))
(u : methodsStruct2Methodaux
(addButton str g notOptimzed) m m₁ s s₁)
→ methodsStruct2Methodaux g m m₁ s s₁
methodsReduceaux g str m m₁ s (isEmpty s₁) u = methodsReduce g str m u
methodsReduceaux g str m m₁ (isEmpty x) posNonEmpty u = methodsReduce g str m₁ u
methodsReduceaux g str m m₁ posNonEmpty posNonEmpty (inj₁ x) = inj₁ (methodsReduce g str m x)
methodsReduceaux g str m m₁ posNonEmpty posNonEmpty (inj₂ y) = inj₂ (methodsReduce g str m₁ y)
subMethodToFullMethod : (btnStr : String)
(fr : Frame)
(m : methodsStruct2Method (addButton btnStr fr notOptimzed)
(methodStruct fr ))
→ methodsG fr
subMethodToFullMethod btnStr fr m = methodsReduce fr btnStr (methodStruct fr ) m
simpleAttr1Btn : (btnStr : String) → properties (addButton btnStr create-frame notOptimzed)
simpleAttr1Btn btnStr = black , oneColumnLayout
simpleSMState : {S : Set}
(btnStr : String)
{start : S}
(end : S)
→ SMachineState S start
simpleSMState btnStr end .fSM = addButton btnStr create-frame notOptimzed
simpleSMState btnStr end .propSM = simpleAttr1Btn btnStr
simpleSMState btnStr end .handlSM m .force = return' (changedState end)
baseF : FMachine StateV
baseF .Features = ⊤
baseF .AddStateF = ⊥
baseF .GUIF f (inj₁ s0) = simpleSMState "1Euro" (inj₁ s1)
baseF .GUIF f (inj₁ s1) = simpleSMState "Get Change" (inj₁ s2)
baseF .GUIF f (inj₁ s2) = simpleSMState "Soda" (inj₁ s0)
baseF .GUIF f (inj₂ ())
addBtn2StateMachine : {S : Set}{s : S}(sm : SMachineState S s)
(btnStr : String)(end : S)
→ SMachineState S s
addBtn2StateMachine sm btnStr end .fSM = addButton btnStr (sm .fSM) notOptimzed
addBtn2StateMachine sm btnStr end .propSM = black , sm .propSM
addBtn2StateMachine sm btnStr end .handlSM (inj₁ x) .force = return' (changedState end)
addBtn2StateMachine sm btnStr end .handlSM (inj₂ m) =
sm .handlSM (subMethodToFullMethod btnStr (sm .fSM) m)
simpleCancel : FMachine StateV → FMachine StateV
simpleCancel vm .Features = vm .Features × FeatureCancel
simpleCancel vm .AddStateF = vm .AddStateF
simpleCancel vm .GUIF (f , yesCancel) (inj₁ s1) =
addBtn2StateMachine (vm .GUIF f (inj₁ s1)) "Cancel" (inj₁ s0)
simpleCancel vm .GUIF (f , _) s = vm .GUIF f s
simpleCancelBase : FMachine StateV
simpleCancelBase = simpleCancel baseF
main1 : NativeIO Unit
main1 = compileFeatureVM baseF _ (inj₁ s0) --
main : NativeIO Unit
main = compileFeatureVM simpleCancelBase (_ , yesCancel) (inj₁ s0) --
| 38.202247
| 178
| 0.586176
|
0b8d97bd7f99575ce628e48dcff6d47fc4d0b984
| 3,186
|
agda
|
Agda
|
test/Succeed/Generalize.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/Generalize.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Generalize.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2020-05-16T20:10:05.000Z
|
2020-05-16T20:10:05.000Z
|
{-# OPTIONS --without-K --rewriting #-}
module Generalize where
data _≡_ {ℓ}{A : Set ℓ} (x : A) : A → Set ℓ where
refl : x ≡ x
infix 4 _≡_
{-# BUILTIN REWRITE _≡_ #-}
------------------------------------------------------------------
postulate Con : Set
postulate Ty : (Γ : Con) → Set
postulate Tms : (Γ Δ : Con) → Set
postulate Tm : (Γ : Con)(A : Ty Γ) → Set
------------------------------------------------------------------
variable {Γ Δ Θ} : Con
postulate • : Con -- • is \bub
postulate _▹_ : ∀ Γ → Ty Γ → Con -- ▹ is \tw2
infixl 5 _▹_
variable {A B C} : Ty _
postulate _∘ᵀ_ : Ty Δ → Tms Γ Δ → Ty Γ
infixl 6 _∘ᵀ_
variable {σ δ ν} : Tms _ _
postulate _∘_ : Tms Θ Δ → Tms Γ Θ → Tms Γ Δ
infixr 7 _∘_
postulate id : Tms Γ Γ
postulate ε : Tms Γ •
postulate _,_ : (σ : Tms Γ Δ) → Tm Γ (A ∘ᵀ σ) → Tms Γ (Δ ▹ A)
infixl 5 _,_
postulate π₁ : Tms Γ (Δ ▹ A) → Tms Γ Δ
variable {t u v} : Tm _ _
postulate π₂ : (σ : Tms Γ (Δ ▹ A)) → Tm Γ (A ∘ᵀ π₁ σ)
postulate _∘ᵗ_ : Tm Δ A → (σ : Tms Γ Δ) → Tm Γ (A ∘ᵀ σ)
infixl 6 _∘ᵗ_
postulate ass : (σ ∘ δ) ∘ ν ≡ σ ∘ δ ∘ ν
{-# REWRITE ass #-}
postulate idl : id ∘ δ ≡ δ
{-# REWRITE idl #-}
postulate idr : δ ∘ id ≡ δ
{-# REWRITE idr #-}
postulate εη : δ ≡ ε -- can't rewrite, so we specialize this in the next two cases
postulate εηid : id ≡ ε
{-# REWRITE εηid #-}
postulate εη∘ : ε ∘ δ ≡ ε
{-# REWRITE εη∘ #-}
postulate ,β₁ : π₁ (δ , t) ≡ δ
{-# REWRITE ,β₁ #-}
postulate ,β₂ : π₂ (δ , t) ≡ t
{-# REWRITE ,β₂ #-}
postulate ,η : (π₁ δ , π₂ δ) ≡ δ
{-# REWRITE ,η #-}
postulate [id]ᵀ : A ∘ᵀ id ≡ A
{-# REWRITE [id]ᵀ #-}
postulate [∘]ᵀ : A ∘ᵀ δ ∘ᵀ σ ≡ A ∘ᵀ δ ∘ σ
{-# REWRITE [∘]ᵀ #-}
postulate ,∘ : (δ , t) ∘ σ ≡ δ ∘ σ , t ∘ᵗ σ
{-# REWRITE ,∘ #-}
postulate [∘]ᵗ : t ∘ᵗ σ ∘ᵗ δ ≡ t ∘ᵗ σ ∘ δ
{-# REWRITE [∘]ᵗ #-}
postulate π₁∘ : π₁ δ ∘ σ ≡ π₁ (δ ∘ σ)
{-# REWRITE π₁∘ #-}
postulate π₂∘ : π₂ δ ∘ᵗ σ ≡ π₂ (δ ∘ σ)
{-# REWRITE π₂∘ #-}
postulate ∘id : t ∘ᵗ id ≡ t
{-# REWRITE ∘id #-}
_↑_ : ∀ σ A → Tms (Γ ▹ A ∘ᵀ σ) (Δ ▹ A)
σ ↑ A = σ ∘ π₁ id , π₂ id
⟨_⟩ : Tm Γ A → Tms Γ (Γ ▹ A)
⟨ t ⟩ = id , t
------------------------------------------------------------------
postulate U : Ty Γ
variable {a b c} : Tm _ U
postulate El : Tm Γ U → Ty Γ
postulate U[] : U ∘ᵀ σ ≡ U
{-# REWRITE U[] #-}
postulate El[] : El a ∘ᵀ σ ≡ El (a ∘ᵗ σ)
{-# REWRITE El[] #-}
------------------------------------------------------------------
postulate Π : (a : Tm Γ U) → Ty (Γ ▹ El a) → Ty Γ
postulate Π[] : Π a B ∘ᵀ σ ≡ Π (a ∘ᵗ σ) (B ∘ᵀ σ ↑ El a)
{-# REWRITE Π[] #-}
postulate app : Tm Γ (Π a B) → Tm (Γ ▹ El a) B
postulate app[] : app t ∘ᵗ (σ ↑ El a) ≡ app (t ∘ᵗ σ)
{-# REWRITE app[] #-}
| 31.544554
| 102
| 0.3801
|
0395961e6f765e0df4216a8eab2593bc096ebfc4
| 143
|
agda
|
Agda
|
test/Fail/CompiledMustBePostulate.agda
|
pthariensflame/agda
|
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
|
[
"BSD-3-Clause"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/fail/CompiledMustBePostulate.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/fail/CompiledMustBePostulate.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- Compiled things must be a postulate
module CompiledMustBePostulate where
postulate
A : Set
foo : Set
foo = A
{-# COMPILED foo bar #-}
| 11.916667
| 38
| 0.706294
|
182364c922291ffbc1dd6dea09c10dd0bb3e4932
| 579
|
agda
|
Agda
|
test/Fail/Issue2451.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2451.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2451.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
-- {-# OPTIONS -v rewriting:30 #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality renaming (_≡_ to _≡≡_)
record Eq (t : Set) : Set₁ where
field
_≡_ : t → t → Set
open Eq {{...}}
{-# BUILTIN REWRITE _≡_ #-}
instance
eqN : Eq Nat
eqN = record { _≡_ = _≡≡_ }
postulate
plus0p : ∀{x} → (x + zero) ≡ x
{-# REWRITE plus0p #-}
-- Error:
-- plus0p does not target rewrite relation
-- when checking the pragma REWRITE plus0p
-- The type of the postulate ends in _≡≡_ (after reduction)
-- but the rewrite relation is _≡_
| 18.677419
| 59
| 0.625216
|
04ebe307bcea6d3d1a57a36fe626da651d02213b
| 7,272
|
agda
|
Agda
|
part1/connectives/Connectives.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | 1
|
2020-07-07T09:42:22.000Z
|
2020-07-07T09:42:22.000Z
|
part1/connectives/Connectives.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
part1/connectives/Connectives.agda
|
akiomik/plfa-solutions
|
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
|
[
"Apache-2.0"
] | null | null | null |
module Connectives where
-- Imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning
open import Data.Nat using (ℕ)
open import Function using (_∘_)
-- open import plfa.part1.Isomorphism using (_≃_; _≲_; extensionality)
-- open plfa.part1.Isomorphism.≃-Reasoning
postulate
-- 外延性の公理
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- 同型
infix 0 _≃_
record _≃_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
≃-refl : ∀ {A : Set}
-----
→ A ≃ A
≃-refl =
record
{ to = λ{x → x}
; from = λ{y → y}
; from∘to = λ{x → refl}
; to∘from = λ{y → refl}
}
≃-trans : ∀ {A B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
≃-trans A≃B B≃C =
record
{ to = to B≃C ∘ to A≃B
; from = from A≃B ∘ from B≃C
; from∘to = λ{x →
begin
(from A≃B ∘ from B≃C) ((to B≃C ∘ to A≃B) x)
≡⟨⟩
from A≃B (from B≃C (to B≃C (to A≃B x)))
≡⟨ cong (from A≃B) (from∘to B≃C (to A≃B x)) ⟩
from A≃B (to A≃B x)
≡⟨ from∘to A≃B x ⟩
x
∎}
; to∘from = λ{y →
begin
(to B≃C ∘ to A≃B) ((from A≃B ∘ from B≃C) y)
≡⟨⟩
to B≃C (to A≃B (from A≃B (from B≃C y)))
≡⟨ cong (to B≃C) (to∘from A≃B (from B≃C y)) ⟩
to B≃C (from B≃C y)
≡⟨ to∘from B≃C y ⟩
y
∎}
}
module ≃-Reasoning where
infix 1 ≃-begin_
infixr 2 _≃⟨_⟩_
infix 3 _≃-∎
≃-begin_ : ∀ {A B : Set}
→ A ≃ B
-----
→ A ≃ B
≃-begin A≃B = A≃B
_≃⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
A ≃⟨ A≃B ⟩ B≃C = ≃-trans A≃B B≃C
_≃-∎ : ∀ (A : Set)
-----
→ A ≃ A
A ≃-∎ = ≃-refl
open ≃-Reasoning
-- 埋め込み
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
-- Conjunction is product
-- 直積
data _×_ (A B : Set) : Set where
⟨_,_⟩ :
A
→ B
-----
→ A × B
proj₁ : ∀ {A B : Set}
→ A × B
-----
→ A
proj₁ ⟨ x , y ⟩ = x
proj₂ : ∀ {A B : Set}
→ A × B
-----
→ B
proj₂ ⟨ x , y ⟩ = y
record _×′_ (A B : Set) : Set where
field
proj₁′ : A
proj₂′ : B
open _×′_
η-× : ∀ {A B : Set} (w : A × B) → ⟨ proj₁ w , proj₂ w ⟩ ≡ w
η-× ⟨ x , y ⟩ = refl
infixr 2 _×_
data Bool : Set where
true : Bool
false : Bool
data Tri : Set where
aa : Tri
bb : Tri
cc : Tri
×-count : Bool × Tri → ℕ
×-count ⟨ true , aa ⟩ = 1
×-count ⟨ true , bb ⟩ = 2
×-count ⟨ true , cc ⟩ = 3
×-count ⟨ false , aa ⟩ = 4
×-count ⟨ false , bb ⟩ = 5
×-count ⟨ false , cc ⟩ = 6
×-comm : ∀ {A B : Set} → A × B ≃ B × A
×-comm =
record
{ to = λ{ ⟨ x , y ⟩ → ⟨ y , x ⟩ }
; from = λ{ ⟨ y , x ⟩ → ⟨ x , y ⟩ }
; from∘to = λ{ ⟨ x , y ⟩ → refl }
; to∘from = λ{ ⟨ y , x ⟩ → refl }
}
×-assoc : ∀ {A B C : Set} → (A × B) × C ≃ A × (B × C)
×-assoc =
record
{ to = λ{ ⟨ ⟨ x , y ⟩ , z ⟩ → ⟨ x , ⟨ y , z ⟩ ⟩ }
; from = λ{ ⟨ x , ⟨ y , z ⟩ ⟩ → ⟨ ⟨ x , y ⟩ , z ⟩ }
; from∘to = λ{ ⟨ ⟨ x , y ⟩ , z ⟩ → refl }
; to∘from = λ{ ⟨ x , ⟨ y , z ⟩ ⟩ → refl }
}
-- Truth is unit
data ⊤ : Set where
tt :
--
⊤
η-⊤ : ∀ (w : ⊤) → tt ≡ w
η-⊤ tt = refl
⊤-count : ⊤ → ℕ
⊤-count tt = 1
⊤-identityˡ : ∀ {A : Set} → ⊤ × A ≃ A
⊤-identityˡ =
record
{ to = λ{ ⟨ tt , x ⟩ → x }
; from = λ{ x → ⟨ tt , x ⟩ }
; from∘to = λ{ ⟨ tt , x ⟩ → refl }
; to∘from = λ{ x → refl }
}
⊤-identityʳ : ∀ {A : Set} → (A × ⊤) ≃ A
⊤-identityʳ {A} =
≃-begin
(A × ⊤)
≃⟨ ×-comm ⟩
(⊤ × A)
≃⟨ ⊤-identityˡ ⟩
A
≃-∎
-- Disjunction is sum
-- 直和
data _⊎_ (A B : Set) : Set where
inj₁ :
A
-----
→ A ⊎ B
inj₂ :
B
-----
→ A ⊎ B
case-⊎ : ∀ {A B C : Set}
→ (A → C)
→ (B → C)
→ A ⊎ B
-----------
→ C
case-⊎ f g (inj₁ x) = f x
case-⊎ f g (inj₂ y) = g y
η-⊎ : ∀ {A B : Set} (w : A ⊎ B) → case-⊎ inj₁ inj₂ w ≡ w
η-⊎ (inj₁ x) = refl
η-⊎ (inj₂ y) = refl
uniq-⊎ : ∀ {A B C : Set} (h : A ⊎ B → C) (w : A ⊎ B) →
case-⊎ (h ∘ inj₁) (h ∘ inj₂) w ≡ h w
uniq-⊎ h (inj₁ x) = refl
uniq-⊎ h (inj₂ y) = refl
infixr 1 _⊎_
⊎-count : Bool ⊎ Tri → ℕ
⊎-count (inj₁ true) = 1
⊎-count (inj₁ false) = 2
⊎-count (inj₂ aa) = 3
⊎-count (inj₂ bb) = 4
⊎-count (inj₂ cc) = 5
-- False is empty
data ⊥ : Set where
-- no clauses!
⊥-elim : ∀ {A : Set}
→ ⊥
--
→ A
⊥-elim ()
uniq-⊥ : ∀ {C : Set} (h : ⊥ → C) (w : ⊥) → ⊥-elim w ≡ h w
uniq-⊥ h ()
⊥-count : ⊥ → ℕ
⊥-count ()
-- Implication is function
→-elim : ∀ {A B : Set}
→ (A → B)
→ A
-------
→ B
→-elim L M = L M
η-→ : ∀ {A B : Set} (f : A → B) → (λ (x : A) → f x) ≡ f
η-→ f = refl
→-count : (Bool → Tri) → ℕ
→-count f with f true | f false
... | aa | aa = 1
... | aa | bb = 2
... | aa | cc = 3
... | bb | aa = 4
... | bb | bb = 5
... | bb | cc = 6
... | cc | aa = 7
... | cc | bb = 8
... | cc | cc = 9
currying : ∀ {A B C : Set} → (A → B → C) ≃ (A × B → C)
currying =
record
{ to = λ{ f → λ{ ⟨ x , y ⟩ → f x y }}
; from = λ{ g → λ{ x → λ{ y → g ⟨ x , y ⟩ }}}
; from∘to = λ{ f → refl }
; to∘from = λ{ g → extensionality λ{ ⟨ x , y ⟩ → refl }}
}
→-distrib-⊎ : ∀ {A B C : Set} → (A ⊎ B → C) ≃ ((A → C) × (B → C))
→-distrib-⊎ =
record
{ to = λ{ f → ⟨ f ∘ inj₁ , f ∘ inj₂ ⟩ }
; from = λ{ ⟨ g , h ⟩ → λ{ (inj₁ x) → g x ; (inj₂ y) → h y } }
; from∘to = λ{ f → extensionality λ{ (inj₁ x) → refl ; (inj₂ y) → refl } }
; to∘from = λ{ ⟨ g , h ⟩ → refl }
}
→-distrib-× : ∀ {A B C : Set} → (A → B × C) ≃ (A → B) × (A → C)
→-distrib-× =
record
{ to = λ{ f → ⟨ proj₁ ∘ f , proj₂ ∘ f ⟩ }
; from = λ{ ⟨ g , h ⟩ → λ x → ⟨ g x , h x ⟩ }
; from∘to = λ{ f → extensionality λ{ x → η-× (f x) } }
; to∘from = λ{ ⟨ g , h ⟩ → refl }
}
-- Distribution
×-distrib-⊎ : ∀ {A B C : Set} → (A ⊎ B) × C ≃ (A × C) ⊎ (B × C)
×-distrib-⊎ =
record
{ to = λ{ ⟨ inj₁ x , z ⟩ → (inj₁ ⟨ x , z ⟩)
; ⟨ inj₂ y , z ⟩ → (inj₂ ⟨ y , z ⟩)
}
; from = λ{ (inj₁ ⟨ x , z ⟩) → ⟨ inj₁ x , z ⟩
; (inj₂ ⟨ y , z ⟩) → ⟨ inj₂ y , z ⟩
}
; from∘to = λ{ ⟨ inj₁ x , z ⟩ → refl
; ⟨ inj₂ y , z ⟩ → refl
}
; to∘from = λ{ (inj₁ ⟨ x , z ⟩) → refl
; (inj₂ ⟨ y , z ⟩) → refl
}
}
⊎-distrib-× : ∀ {A B C : Set} → (A × B) ⊎ C ≲ (A ⊎ C) × (B ⊎ C)
⊎-distrib-× =
record
{ to = λ{ (inj₁ ⟨ x , y ⟩) → ⟨ inj₁ x , inj₁ y ⟩
; (inj₂ z) → ⟨ inj₂ z , inj₂ z ⟩
}
; from = λ{ ⟨ inj₁ x , inj₁ y ⟩ → (inj₁ ⟨ x , y ⟩)
; ⟨ inj₁ x , inj₂ z ⟩ → (inj₂ z)
; ⟨ inj₂ z , _ ⟩ → (inj₂ z)
}
; from∘to = λ{ (inj₁ ⟨ x , y ⟩) → refl
; (inj₂ z) → refl
}
}
| 20.600567
| 78
| 0.363586
|
c5278de3bfbf1eb20ab2560c6814bfcafc3b73e5
| 2,282
|
agda
|
Agda
|
agda/Cardinality/Finite/Structure.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 4
|
2021-01-05T14:07:44.000Z
|
2021-01-05T15:32:14.000Z
|
agda/Cardinality/Finite/Structure.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | null | null | null |
agda/Cardinality/Finite/Structure.agda
|
oisdk/combinatorics-paper
|
3c176d4690566d81611080e9378f5a178b39b851
|
[
"MIT"
] | 1
|
2021-01-05T14:05:30.000Z
|
2021-01-05T14:05:30.000Z
|
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Cardinality.Finite.Structure where
open import Prelude
open import Data.Fin
open import Data.Nat
open import Data.Nat.Properties
private
variable
n m : ℕ
liftˡ : ∀ n m → Fin m → Fin (n + m)
liftˡ zero m x = x
liftˡ (suc n) m x = fs (liftˡ n m x)
liftʳ : ∀ n m → Fin n → Fin (n + m)
liftʳ (suc n) m f0 = f0
liftʳ (suc n) m (fs x) = fs (liftʳ n m x)
mapl : (A → B) → A ⊎ C → B ⊎ C
mapl f (inl x) = inl (f x)
mapl f (inr x) = inr x
fin-sum-to : ∀ n m → Fin n ⊎ Fin m → Fin (n + m)
fin-sum-to n m = either (liftʳ n m) (liftˡ n m)
fin-sum-from : ∀ n m → Fin (n + m) → Fin n ⊎ Fin m
fin-sum-from zero m x = inr x
fin-sum-from (suc n) m f0 = inl f0
fin-sum-from (suc n) m (fs x) = mapl fs (fin-sum-from n m x)
mapl-distrib : ∀ {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d} (xs : A ⊎ B) (h : A → C) (f : C → D) (g : B → D) → either′ f g (mapl h xs) ≡ either′ (f ∘′ h) g xs
mapl-distrib (inl x) h f g = refl
mapl-distrib (inr x) h f g = refl
either-distrib : ∀ {d} {D : Type d} (f : A → C) (g : B → C) (h : C → D) (xs : A ⊎ B) → either′ (h ∘ f) (h ∘ g) xs ≡ h (either′ f g xs)
either-distrib f g h (inl x) = refl
either-distrib f g h (inr x) = refl
open import Path.Reasoning
fin-sum-to-from : ∀ n m x → fin-sum-to n m (fin-sum-from n m x) ≡ x
fin-sum-to-from zero m x = refl
fin-sum-to-from (suc n) m f0 = refl
fin-sum-to-from (suc n) m (fs x) =
fin-sum-to (suc n) m (mapl fs (fin-sum-from n m x)) ≡⟨ mapl-distrib (fin-sum-from n m x) fs (liftʳ (suc n) m) (liftˡ (suc n) m) ⟩
either (liftʳ (suc n) m ∘ fs) (liftˡ (suc n) m) (fin-sum-from n m x) ≡⟨⟩
either (fs ∘ liftʳ n m) (fs ∘ liftˡ n m) (fin-sum-from n m x) ≡⟨ either-distrib (liftʳ n m) (liftˡ n m) fs (fin-sum-from n m x) ⟩
fs (either (liftʳ n m) (liftˡ n m) (fin-sum-from n m x)) ≡⟨ cong fs (fin-sum-to-from n m x) ⟩
fs x ∎
-- fin-sum-from-to : ∀ n m x → fin-sum-from n m (fin-sum-to n m x) ≡ x
-- fin-sum-from-to n m (inl x) = {!!}
-- fin-sum-from-to n m (inr x) = {!!}
-- fin-sum : ∀ n m → Fin n ⊎ Fin m ⇔ Fin (n + m)
-- fin-sum n m .fun = fin-sum-to n m
-- fin-sum n m .inv = fin-sum-from n m
-- fin-sum n m .rightInv = fin-sum-to-from n m
-- fin-sum n m .leftInv = fin-sum-from-to n m
| 33.558824
| 177
| 0.558282
|
9aa562023843180170654e41f7f145edde040cd3
| 9,899
|
agda
|
Agda
|
src/Queue/Quotiented.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/Queue/Quotiented.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/Queue/Quotiented.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Quotiented queues: any two queues representing the same sequence
-- are equal
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Queue.Quotiented
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level.Closure equality-with-J
open import List equality-with-J as L hiding (map)
import Queue equality-with-J as Q
open import Quotient eq as Quotient
open import Sum equality-with-J
private
variable
a b : Level
A B : Type a
s s′ s₁ s₂ : Is-set A
q q₁ q₂ x x₁ x₂ : A
f g : A → B
xs : List A
------------------------------------------------------------------------
-- Queues
-- The queue type family is parametrised.
module _
-- The underlying queue type family.
(Q : ∀ {ℓ} → Type ℓ → Type ℓ)
-- Note that the predicate is required to be trivial. Perhaps the
-- code could be made more general, but I have not found a use for
-- such generality.
⦃ is-queue : ∀ {ℓ} → Q.Is-queue Q (λ _ → ↑ _ ⊤) ℓ ⦄
where
abstract
private
-- The quotienting relation: Two queues are seen as equal if
-- they represent the same list.
_∼_ : {A : Type a} (_ _ : Q A) → Type a
q₁ ∼ q₂ = Q.to-List _ q₁ ≡ Q.to-List _ q₂
-- Queues.
--
-- The type is abstract to ensure that a change to a different
-- underlying queue type family does not break code that uses this
-- module.
--
-- Ulf Norell suggested to me that I could use parametrisation
-- instead of abstract. (Because if the underlying queue type
-- family is a parameter, then the underlying queues do not
-- compute.) I decided to use both. (Because I want to have the
-- flexibility that comes with parametrisation, but I do not want
-- to force users to work in a parametrised setting.)
Queue : Type a → Type a
Queue A = Q A / _∼_
-- The remainder of the code uses an implicit underlying queue type
-- family parameter, and an extra instance argument.
module _
{Q : ∀ {ℓ} → Type ℓ → Type ℓ}
⦃ is-queue : ∀ {ℓ} → Q.Is-queue Q (λ _ → ↑ _ ⊤) ℓ ⦄
⦃ is-queue-with-map : ∀ {ℓ₁ ℓ₂} → Q.Is-queue-with-map Q ℓ₁ ℓ₂ ⦄
where
abstract
-- Queue A is a set.
Queue-is-set : Is-set (Queue Q A)
Queue-is-set = /-is-set
------------------------------------------------------------------------
-- Conversion functions
abstract
-- Converts queues to lists. (The carrier type is required to be a
-- set.)
to-List : Is-set A → Queue Q A → List A
to-List s = Quotient.rec λ where
.[]ʳ → Q.to-List _
.[]-respects-relationʳ → id
.is-setʳ → H-level-List 0 s
-- Converts lists to queues.
from-List : List A → Queue Q A
from-List = [_] ∘ Q.from-List
-- The function from-List is a right inverse of to-List s.
to-List-from-List : to-List s (from-List q) ≡ q
to-List-from-List = Q.to-List-from-List
-- The function from-List is a left inverse of to-List s.
from-List-to-List :
(q : Queue Q A) → _≡_ {A = Queue Q A} (from-List (to-List s q)) q
from-List-to-List = Quotient.elim-prop λ where
.[]ʳ q → []-respects-relation (
Q.to-List ⦃ is-queue = is-queue ⦄ _
(Q.from-List (Q.to-List _ q)) ≡⟨ Q.to-List-from-List ⟩∎
Q.to-List _ q ∎)
.is-propositionʳ _ → Queue-is-set
-- If A is a set, then there is a bijection between Queue Q A and
-- List A.
Queue↔List : Is-set A → Queue Q A ↔ List A
Queue↔List s = record
{ surjection = record
{ logical-equivalence = record
{ to = to-List s
; from = from-List
}
; right-inverse-of = λ _ → to-List-from-List
}
; left-inverse-of = from-List-to-List
}
------------------------------------------------------------------------
-- Queue operations
abstract
private
-- Helper functions that can be used to define unary functions
-- on queues.
unary :
{A : Type a} {B : Type b}
(f : List A → List B)
(g : Q A → Q B) →
(∀ {q} → Q.to-List _ (g q) ≡ f (Q.to-List _ q)) →
Queue Q A → Queue Q B
unary f g h =
g /-map λ q₁ q₂ q₁∼q₂ →
Q.to-List _ (g q₁) ≡⟨ h ⟩
f (Q.to-List _ q₁) ≡⟨ cong f q₁∼q₂ ⟩
f (Q.to-List _ q₂) ≡⟨ sym h ⟩∎
Q.to-List _ (g q₂) ∎
to-List-unary :
∀ {h : ∀ {q} → _} q →
to-List s₁ (unary f g (λ {q} → h {q = q}) q) ≡ f (to-List s₂ q)
to-List-unary {s₁ = s₁} {f = f} {g = g} {s₂ = s₂} {h = h} =
Quotient.elim-prop λ where
.[]ʳ q →
to-List s₁ (unary f g h [ q ]) ≡⟨⟩
Q.to-List _ (g q) ≡⟨ h ⟩
f (Q.to-List _ q) ≡⟨⟩
f (to-List s₂ [ q ]) ∎
.is-propositionʳ _ → H-level-List 0 s₁
-- Generalisations of the functions above.
unary′ :
{A : Type a} {F : Type a → Type b} →
(∀ {A} → Is-set A → Is-set (F A)) →
(map : ∀ {A B} → (A → B) → F A → F B) →
(∀ {A} {x : F A} → map id x ≡ x) →
(∀ {A B C} {f : B → C} {g : A → B} x →
map (f ∘ g) x ≡ map f (map g x)) →
(f : List A → F (List B))
(g : Q A → F (Q B)) →
(∀ {q} → map (Q.to-List _) (g q) ≡ f (Q.to-List _ q)) →
Is-set B →
Queue Q A → F (Queue Q B)
unary′ F-set map map-id map-∘ f g h s = Quotient.rec λ where
.[]ʳ → map [_] ∘ g
.[]-respects-relationʳ {x = q₁} {y = q₂} q₁∼q₂ → lemma₂ (
map (to-List s) (map [_] (g q₁)) ≡⟨ sym $ map-∘ _ ⟩
map (Q.to-List _) (g q₁) ≡⟨ h ⟩
f (Q.to-List _ q₁) ≡⟨ cong f q₁∼q₂ ⟩
f (Q.to-List _ q₂) ≡⟨ sym h ⟩
map (Q.to-List _) (g q₂) ≡⟨ map-∘ _ ⟩∎
map (to-List s) (map [_] (g q₂)) ∎)
.is-setʳ → F-set Queue-is-set
where
lemma₁ : map from-List (map (to-List s) x) ≡ x
lemma₁ {x = x} =
map from-List (map (to-List s) x) ≡⟨ sym $ map-∘ _ ⟩
map (from-List ∘ to-List s) x ≡⟨ cong (flip map x) $ ⟨ext⟩ $ _↔_.left-inverse-of (Queue↔List s) ⟩
map id x ≡⟨ map-id ⟩∎
x ∎
lemma₂ :
map (to-List s) x₁ ≡ map (to-List s) x₂ →
x₁ ≡ x₂
lemma₂ {x₁ = x₁} {x₂ = x₂} eq =
x₁ ≡⟨ sym lemma₁ ⟩
map from-List (map (to-List s) x₁) ≡⟨ cong (map from-List) eq ⟩
map from-List (map (to-List s) x₂) ≡⟨ lemma₁ ⟩∎
x₂ ∎
to-List-unary′ :
{F : Type a → Type b}
(F-set : ∀ {A} → Is-set A → Is-set (F A))
(map : ∀ {A B} → (A → B) → F A → F B)
(map-id : ∀ {A} {x : F A} → map id x ≡ x)
(map-∘ : ∀ {A B C} {f : B → C} {g : A → B} x →
map (f ∘ g) x ≡ map f (map g x))
(f : List A → F (List B))
(g : Q A → F (Q B))
(h : ∀ {q} → map (Q.to-List _) (g q) ≡ f (Q.to-List _ q))
(s : Is-set B) →
∀ q →
map (to-List s) (unary′ F-set map map-id map-∘ f g h s q) ≡
f (to-List s′ q)
to-List-unary′ {s′ = s′} F-set map map-id map-∘ f g h s =
Quotient.elim-prop λ where
.[]ʳ q →
map (to-List s)
(unary′ F-set map map-id map-∘ f g h s [ q ]) ≡⟨⟩
map (to-List s) (map [_] (g q)) ≡⟨ sym $ map-∘ _ ⟩
map (Q.to-List _) (g q) ≡⟨ h ⟩
f (Q.to-List _ q) ≡⟨⟩
f (to-List s′ [ q ]) ∎
.is-propositionʳ _ → F-set (H-level-List 0 s)
-- Enqueues an element.
enqueue : A → Queue Q A → Queue Q A
enqueue x = unary (_++ x ∷ []) (Q.enqueue x) Q.to-List-enqueue
to-List-enqueue : to-List s (enqueue x q) ≡ to-List s q ++ x ∷ []
to-List-enqueue {q = q} = to-List-unary q
-- Dequeues an element, if possible. (The carrier type is required
-- to be a set.)
dequeue : Is-set A → Queue Q A → Maybe (A × Queue Q A)
dequeue s = unary′
(Maybe-closure 0 ∘ ×-closure 2 s)
(λ f → ⊎-map id (Σ-map id f))
⊎-map-id
⊎-map-∘
(_↔_.to List↔Maybe[×List])
(Q.dequeue _)
Q.to-List-dequeue
s
to-List-dequeue :
⊎-map id (Σ-map id (to-List s)) (dequeue s q) ≡
_↔_.to List↔Maybe[×List] (to-List s q)
to-List-dequeue {q = q} = to-List-unary′
(Maybe-closure 0 ∘ ×-closure 2 _)
(λ f → ⊎-map id (Σ-map id f))
⊎-map-id
⊎-map-∘
_
(Q.dequeue _)
_
_
q
-- The "inverse" of the dequeue operation.
dequeue⁻¹ : Maybe (A × Queue Q A) → Queue Q A
dequeue⁻¹ nothing = [ Q.empty ]
dequeue⁻¹ (just (x , q)) = unary (x ∷_) (Q.cons x) Q.to-List-cons q
to-List-dequeue⁻¹ :
to-List s (dequeue⁻¹ x) ≡
_↔_.from List↔Maybe[×List] (⊎-map id (Σ-map id (to-List s)) x)
to-List-dequeue⁻¹ {x = nothing} = Q.to-List-empty
to-List-dequeue⁻¹ {x = just (_ , q)} = to-List-unary q
-- A map function.
map : (A → B) → Queue Q A → Queue Q B
map f = unary (L.map f) (Q.map f) Q.to-List-map
to-List-map : to-List s₁ (map f q) ≡ L.map f (to-List s₂ q)
to-List-map {q = q} = to-List-unary q
| 32.349673
| 112
| 0.472068
|
1eb4ad627a40f5e15aacbe1dac761ae6ad9e581e
| 4,043
|
agda
|
Agda
|
src/Web/Semantic/DL/Integrity.agda
|
agda/agda-web-semantic
|
8ddbe83965a616bff6fc7a237191fa261fa78bab
|
[
"MIT"
] | 9
|
2015-09-13T17:46:41.000Z
|
2020-03-14T14:21:08.000Z
|
src/Web/Semantic/DL/Integrity.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | 4
|
2018-11-14T02:32:28.000Z
|
2021-01-04T20:57:19.000Z
|
src/Web/Semantic/DL/Integrity.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.Unary using ( _∈_ )
open import Web.Semantic.DL.ABox using ( ABox )
open import Web.Semantic.DL.ABox.Interp using ( Interp ; _*_ )
open import Web.Semantic.DL.ABox.Interp.Morphism using
( _≲_ ; ≲-trans ; _**_ ; _≋_ )
open import Web.Semantic.DL.KB using ( KB ; _,_ ; tbox )
open import Web.Semantic.DL.KB.Model using ( _⊨_ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( _,_ )
open import Web.Semantic.Util using ( _⊕_⊕_ ; inode ; enode )
module Web.Semantic.DL.Integrity {Σ : Signature} {X V Y : Set} where
-- A variant of the notion of OWL integrity in:
-- Boris Motik, Ian Horrocks, and Ulrike Sattler. Bridging the gap between OWL and
-- relational databases. In Proc. Conf. World Wide Web (WWW2007), pp 807–816, 2007.
-- They propose defining that an integrity constraint S (given as a T-Box) is valid
-- for a knowlege base K whenever S is valid in every minimal Herbrand model.
-- We strengthen this requirement to say that there is a minimal model of K,
-- which validtes S.
infixr 4 _>>_ _,_
infix 2 _⊕_⊨_
-- J ∈ Initial I K whenever J is the initial extension of I
-- satisfying K, that is there is I≲J s.t. I ⊨ K
-- and for any other such I≲K, there is a unique
-- J≲K which commutes with I≲J and I≲K.
_>>_ : ∀ {I : Interp Σ X} {J K : Interp Σ (X ⊕ V ⊕ Y)} →
(I ≲ inode * J) → (J ≲ K) → (I ≲ inode * K)
I≲J >> J≲K = ≲-trans I≲J (inode ** J≲K)
Unique : ∀ (I : Interp Σ X) → (J K : Interp Σ (X ⊕ V ⊕ Y)) →
(I ≲ inode * J) → (I ≲ inode * K) → Set
Unique I J K I≲J I≲K = ∀ (J≲₁K J≲₂K : J ≲ K) →
(I≲K ≋ I≲J >> J≲₁K) → (I≲K ≋ I≲J >> J≲₂K) → (J≲₁K ≋ J≲₂K)
data Mediated (I : Interp Σ X) (J K : Interp Σ (X ⊕ V ⊕ Y))
(I≲J : I ≲ inode * J) (I≲K : I ≲ inode * K) : Set where
_,_ : (J≲K : J ≲ K) → (I≲K ≋ I≲J >> J≲K) × (Unique I J K I≲J I≲K)
→ Mediated I J K I≲J I≲K
med-≲ : ∀ {I} {J K : Interp Σ (X ⊕ V ⊕ Y)} {I≲J I≲K} →
(Mediated I J K I≲J I≲K) → (J ≲ K)
med-≲ (J≲K , I≲K≋I≲J≲K , J≲K-uniq) = J≲K
med-≋ : ∀ {I} {J K : Interp Σ (X ⊕ V ⊕ Y)} {I≲J I≲K} →
(m : Mediated I J K I≲J I≲K) → (I≲K ≋ I≲J >> med-≲ m)
med-≋ (J≲K , I≲K≋I≲J≲K , J≲K-uniq) = I≲K≋I≲J≲K
med-uniq : ∀ {I} {J K : Interp Σ (X ⊕ V ⊕ Y)} {I≲J I≲K} →
(Mediated I J K I≲J I≲K) → Unique I J K I≲J I≲K
med-uniq (J≲K , I≲K≋I≲J≲K , J≲K-uniq) = J≲K-uniq
Mediator : ∀ (I : Interp Σ X) → (J : Interp Σ (X ⊕ V ⊕ Y)) →
(I ≲ inode * J) → (KB Σ (X ⊕ V ⊕ Y)) → Set₁
Mediator I J I≲J KB =
∀ K (I≲K : I ≲ inode * K) → (K ⊨ KB) → Mediated I J K I≲J I≲K
data Initial I KB (J : Interp Σ (X ⊕ V ⊕ Y)) : Set₁ where
_,_ : ∀ (I≲J : I ≲ inode * J) → (J ⊨ KB) × (Mediator I J I≲J KB) →
(J ∈ Initial I KB)
init-≲ : ∀ {I KB} {J : Interp Σ (X ⊕ V ⊕ Y)} →
(J ∈ Initial I KB) → (I ≲ inode * J)
init-≲ (I≲J , J⊨KB , J-med) = I≲J
init-⊨ : ∀ {I KB} {J : Interp Σ (X ⊕ V ⊕ Y)} →
(J ∈ Initial I KB) → (J ⊨ KB)
init-⊨ (I≲J , J⊨KB , J-med) = J⊨KB
init-med : ∀ {I KB} {J : Interp Σ (X ⊕ V ⊕ Y)} →
(J-init : J ∈ Initial I KB) → Mediator I J (init-≲ J-init) KB
init-med (I≲J , J⊨KB , J-med) = J-med
-- I ⊕ KB₁ ⊨ KB₂ whenever the initial extension of I satisfying
-- KB₁ exists, and has exports satisfying KB₂.
data _⊕_⊨_ I (KB₁ : KB Σ (X ⊕ V ⊕ Y)) KB₂ : Set₁ where
_,_ : ∀ J → ((J ∈ Initial I KB₁) × (enode * J ⊨ KB₂)) → (I ⊕ KB₁ ⊨ KB₂)
extension : ∀ {I KB₁ KB₂} → (I ⊕ KB₁ ⊨ KB₂) → (Interp Σ (X ⊕ V ⊕ Y))
extension (J , J-init , J⊨KB₂) = J
ext-init : ∀ {I} {KB₁ : KB Σ (X ⊕ V ⊕ Y)} {KB₂} →
(I⊕KB₁⊨KB₂ : I ⊕ KB₁ ⊨ KB₂) → (extension I⊕KB₁⊨KB₂ ∈ Initial I KB₁)
ext-init (J , J-init , J⊨KB₂) = J-init
ext-⊨ : ∀ {I} {KB₁ : KB Σ (X ⊕ V ⊕ Y)} {KB₂} →
(I⊕KB₁⊨KB₂ : I ⊕ KB₁ ⊨ KB₂) → (enode * (extension I⊕KB₁⊨KB₂) ⊨ KB₂)
ext-⊨ (J , J-init , J⊨KB₂) = J⊨KB₂
ext✓ : ∀ {I S T} {F : ABox Σ (X ⊕ V ⊕ Y)} {B} →
(I⊕SF⊨TB : I ⊕ S , F ⊨ T , B) →
(enode * (extension I⊕SF⊨TB) ⊨ (S , T) , B)
ext✓ I⊕SF⊨TB =
( ( proj₁ (init-⊨ (ext-init I⊕SF⊨TB))
, proj₁ (ext-⊨ I⊕SF⊨TB) )
, proj₂ (ext-⊨ I⊕SF⊨TB) )
| 38.875
| 85
| 0.542419
|
58139761632cc12e0a44ba2fc45c5242c78f4849
| 1,892
|
agda
|
Agda
|
test/Compiler/simple/Forcing4.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 7
|
2018-11-05T22:13:36.000Z
|
2018-11-06T16:38:43.000Z
|
test/Compiler/simple/Forcing4.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 16
|
2018-10-08T00:32:04.000Z
|
2019-09-08T13:47:04.000Z
|
test/Compiler/simple/Forcing4.agda
|
xekoukou/agda-ocaml
|
026a8f8473ab91f99c3f6545728e71fa847d2720
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
module Forcing4 where
open import Common.Nat renaming (zero to Z; suc to S)
open import Lib.Fin
open import Common.Equality
open import Common.String
open import Common.IO
open import Common.Unit
{-
toNat : {n : Nat} → Fin n → Nat
toNat (zero _) = 0
toNat (suc _ i) = suc (toNat i)
-}
Rel : (X : Set) -> Set1
Rel X = X -> X -> Set
data _<=_ : Rel Nat where
z<=n : ∀ n → Z <= n
s<=s : ∀ m n (m<=n : m <= n) → S m <= S n
_ℕ<_ : Rel Nat
m ℕ< n = S m <= n
fromℕ≤ : ∀ {m n} → m ℕ< n → Fin n
fromℕ≤ (s<=s .0 n (z<=n .n)) = fz {n}
fromℕ≤ (s<=s .(S m) .(S n) (s<=s m n m<=n)) = fs {S n} (fromℕ≤ (s<=s m n m<=n))
fromℕ≤-toℕ : ∀ m (i : Fin m) (i<m : forget i ℕ< m) → fromℕ≤ i<m ≡ i
fromℕ≤-toℕ .(S n) (fz {n}) (s<=s .0 .n (z<=n .n)) = refl
fromℕ≤-toℕ .(S (S n)) (fs .{S n} y) (s<=s .(S (forget y)) .(S n) (s<=s .(forget y) n m≤n)) = cong (\ n -> fs n) (fromℕ≤-toℕ (S n) y (s<=s (forget y) n m≤n))
[_/2] : Nat -> Nat
[ 0 /2] = 0
[ 1 /2] = 0
[ S (S n) /2] = S [ n /2]
[1/2]-mono : (m n : Nat) -> m <= n -> [ m /2] <= [ n /2]
[1/2]-mono .0 .n (z<=n n) = z<=n [ n /2]
[1/2]-mono .1 .(S n) (s<=s .0 .n (z<=n n)) = z<=n [ S n /2]
[1/2]-mono .(S (S m)) .(S (S n)) (s<=s .(S m) .(S n) (s<=s m n m<=n)) = s<=s [ m /2] [ n /2] ([1/2]-mono m n m<=n)
showEq : {X : Set}{A : X} -> A ≡ A -> String
showEq refl = "refl"
show<= : {m n : Nat} -> m <= n -> String
show<= (z<=n n) = "0 <= " +S+ natToString n
show<= (s<=s m n m<=n) = natToString (S m) +S+ " <= " +S+ natToString (S n)
data Bot : Set where
-- Only to check that it compiles..
foo : (n : Nat) -> S n <= n -> Bot
foo .(S n) (s<=s .(S n) n le) = foo n le
main : IO Unit
main = putStrLn (showEq (fromℕ≤-toℕ 3 (inc (inject 1)) le)) ,,
putStrLn (show<= ([1/2]-mono 4 6 le'))
where
le : 2 <= 3
le = s<=s _ _ (s<=s _ _ (z<=n _))
le' : 4 <= 6
le' = s<=s _ _ (s<=s _ _ (s<=s _ _ (s<=s _ _ (z<=n _))))
| 28.666667
| 156
| 0.463002
|
8b3c6467bf4d83949c0e620a4951f02b1437a1db
| 976
|
agda
|
Agda
|
src/MJ/Examples/While.agda
|
metaborg/mj.agda
|
0c096fea1716d714db0ff204ef2a9450b7a816df
|
[
"Apache-2.0"
] | 10
|
2017-11-17T17:10:36.000Z
|
2021-09-24T08:02:33.000Z
|
src/MJ/Examples/While.agda
|
metaborg/mj.agda
|
0c096fea1716d714db0ff204ef2a9450b7a816df
|
[
"Apache-2.0"
] | 1
|
2019-01-13T13:03:47.000Z
|
2020-10-14T13:41:58.000Z
|
src/MJ/Examples/While.agda
|
metaborg/mj.agda
|
0c096fea1716d714db0ff204ef2a9450b7a816df
|
[
"Apache-2.0"
] | 1
|
2021-12-28T17:38:05.000Z
|
2021-12-28T17:38:05.000Z
|
module MJ.Examples.While where
open import MJ.Examples.Integer
open import Prelude
open import MJ.Types
open import MJ.Classtable.Code Σ
open import MJ.Syntax Σ
open import MJ.Syntax.Program Σ
open import MJ.Semantics Σ Lib
open import MJ.Semantics.Values Σ
open import Data.List.Any
open import Data.List.Membership.Propositional
open import Data.Star
open import Data.Bool as Bools hiding (_≤?_)
open import Relation.Nullary.Decidable
-- a simple program that computes 10 using a while loop
p₁ : Prog int
p₁ = Lib ,
let
x = (here refl)
in body
(
loc int
◅ asgn x (num 1)
◅ while iop (λ x y → Bools.if ⌊ suc x ≤? y ⌋ then 0 else 1) (var x) (num 10) run (
asgn x (iop (λ x y → x + y) (var x) (num 1))
)
-- test simplest if-then-else and early return from statement
◅ if (num 0) then (ret (var x)) else (ret (num 0))
◅ ε
)
(num 0)
test1 : p₁ ⇓⟨ 100 ⟩ (λ {W} (v : Val W int) → v ≡ num 10)
test1 = refl
| 25.684211
| 88
| 0.647541
|
035660b58194fa527c1e47eb69e5734950344316
| 778
|
agda
|
Agda
|
Common.agda
|
fangyi-zhou/mpst-in-agda
|
3d12eed9d340207d242d70f43c6b34e01d3620de
|
[
"MIT"
] | 1
|
2021-08-14T17:36:53.000Z
|
2021-08-14T17:36:53.000Z
|
Common.agda
|
fangyi-zhou/mpst-in-agda
|
3d12eed9d340207d242d70f43c6b34e01d3620de
|
[
"MIT"
] | 1
|
2021-08-31T10:15:38.000Z
|
2021-11-24T11:30:17.000Z
|
Common.agda
|
fangyi-zhou/mpst-in-agda
|
3d12eed9d340207d242d70f43c6b34e01d3620de
|
[
"MIT"
] | null | null | null |
module Common where
open import Level using (Level)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; sym; refl)
open import Relation.Nullary.Decidable using (False; toWitnessFalse)
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin; _≟_)
private
variable
n : ℕ
l : Level
A : Set l
x x′ y : A
Label : Set
Label = ℕ
data Action (n : ℕ) : Set where
action : (p q : Fin n) -> p ≢ q -> Label -> Action n
action′ : (p q : Fin n) -> {False (p ≟ q)} -> Label -> Action n
action′ p q {p≢q} l = action p q (toWitnessFalse p≢q) l
¬≡-flip : x ≢ y -> y ≢ x
¬≡-flip x≢y = λ y≡x → x≢y (sym y≡x)
≢-subst-left : x ≢ y -> x ≡ x′ -> x′ ≢ y
≢-subst-left x≢y refl = x≢y
≢-subst-right : y ≢ x -> x ≡ x′ -> y ≢ x′
≢-subst-right y≢x refl = y≢x
| 23.575758
| 77
| 0.59126
|
20f96b3bc3593229e09f75cce6df5153eea6e5fb
| 1,059
|
agda
|
Agda
|
Thesis/Lang.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 10
|
2015-03-04T06:09:20.000Z
|
2019-07-19T07:06:59.000Z
|
Thesis/Lang.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 6
|
2015-07-01T18:09:31.000Z
|
2017-05-04T13:53:59.000Z
|
Thesis/Lang.agda
|
inc-lc/ilc-agda
|
39bb081c6f192bdb87bd58b4a89291686d2d7d03
|
[
"MIT"
] | 1
|
2016-02-18T12:26:44.000Z
|
2016-02-18T12:26:44.000Z
|
module Thesis.Lang where
open import Thesis.Syntax public
open import Thesis.Environments public
⟦_⟧Const : ∀ {τ} → Const τ → ⟦ τ ⟧Type
⟦ unit ⟧Const = tt
⟦ lit n ⟧Const = n
⟦ plus ⟧Const = _+_
⟦ minus ⟧Const = _-_
⟦ cons ⟧Const v1 v2 = v1 , v2
⟦ fst ⟧Const (v1 , v2) = v1
⟦ snd ⟧Const (v1 , v2) = v2
⟦ linj ⟧Const v1 = inj₁ v1
⟦ rinj ⟧Const v2 = inj₂ v2
⟦ match ⟧Const (inj₁ x) f g = f x
⟦ match ⟧Const (inj₂ y) f g = g y
⟦_⟧Term : ∀ {Γ τ} → Term Γ τ → ⟦ Γ ⟧Context → ⟦ τ ⟧Type
⟦ const c ⟧Term ρ = ⟦ c ⟧Const
⟦ var x ⟧Term ρ = ⟦ x ⟧Var ρ
⟦ app s t ⟧Term ρ = ⟦ s ⟧Term ρ (⟦ t ⟧Term ρ)
⟦ abs t ⟧Term ρ = λ v → ⟦ t ⟧Term (v • ρ)
open import Theorem.CongApp
open import Postulate.Extensionality
weaken-sound : ∀ {Γ₁ Γ₂ τ} {Γ₁≼Γ₂ : Γ₁ ≼ Γ₂}
(t : Term Γ₁ τ) (ρ : ⟦ Γ₂ ⟧Context) → ⟦ weaken Γ₁≼Γ₂ t ⟧Term ρ ≡ ⟦ t ⟧Term (⟦ Γ₁≼Γ₂ ⟧≼ ρ)
weaken-sound {Γ₁≼Γ₂ = Γ₁≼Γ₂} (var x) ρ = weaken-var-sound Γ₁≼Γ₂ x ρ
weaken-sound (app s t) ρ = weaken-sound s ρ ⟨$⟩ weaken-sound t ρ
weaken-sound (abs t) ρ = ext (λ v → weaken-sound t (v • ρ))
weaken-sound (const c) ρ = refl
| 31.147059
| 91
| 0.593012
|
03a10492932a1594f61de8f3ed029dae8fdcd9ea
| 1,429
|
agda
|
Agda
|
src/Leftovers/TraverseTerm.agda
|
JoeyEremondi/AgdaLeftovers
|
01b60b405009feaada181af175f019ceb89e42b2
|
[
"BSD-3-Clause"
] | null | null | null |
src/Leftovers/TraverseTerm.agda
|
JoeyEremondi/AgdaLeftovers
|
01b60b405009feaada181af175f019ceb89e42b2
|
[
"BSD-3-Clause"
] | null | null | null |
src/Leftovers/TraverseTerm.agda
|
JoeyEremondi/AgdaLeftovers
|
01b60b405009feaada181af175f019ceb89e42b2
|
[
"BSD-3-Clause"
] | null | null | null |
{-# OPTIONS --without-K #-}
module Leftovers.TraverseTerm where
open import Data.List
-- We only need the writer monad, but as far as I can tell
-- it's not in the Agda stdlib
open import Category.Monad.State
open import Reflection using (Term ; Meta ; Name ; Arg)
import Leftovers.Everywhere
open import Relation.Binary.PropositionalEquality
open import Data.Product
open import Data.Nat
open import Data.Maybe
open import Data.String
LCxt : Set
LCxt = List (String × Arg Term)
record LeafInfoMaker (A : Set) : Set where
field
onVar : LCxt → ℕ → Maybe A
onMeta : LCxt → Meta → Maybe A
onCon : LCxt → Name → Maybe A
onDef : LCxt → Name → Maybe A
collectFromSubterms : ∀ {A : Set} → LeafInfoMaker A → Term → List A
collectFromSubterms {A} f t = proj₂ (stateResult [])
where
open RawMonadState (StateMonadState (List A))
open import Leftovers.Everywhere (StateMonad (List A))
toAction : ∀ {X : Set} → (LCxt → X → Maybe A) → Action X
toAction f cxt x with f (Cxt.context cxt) x
... | nothing = return x
... | just fx =
do
modify (fx ∷_)
return x
stateResult : State (List A) Term
stateResult =
everywhere (record
{ onVar = toAction (LeafInfoMaker.onVar f)
; onMeta = toAction (LeafInfoMaker.onMeta f)
; onCon = toAction (LeafInfoMaker.onCon f)
; onDef = toAction (LeafInfoMaker.onDef f) }) (λ Γ x → return x) t
| 27.480769
| 76
| 0.660602
|
ad5ca444363bc1898406147cb08e6fcd278f3081
| 24,762
|
agda
|
Agda
|
src/to-string.agda
|
CarlOlson/cedille
|
f5ce42258b7d9bc66f75cd679c785d6133b82b58
|
[
"MIT"
] | null | null | null |
src/to-string.agda
|
CarlOlson/cedille
|
f5ce42258b7d9bc66f75cd679c785d6133b82b58
|
[
"MIT"
] | null | null | null |
src/to-string.agda
|
CarlOlson/cedille
|
f5ce42258b7d9bc66f75cd679c785d6133b82b58
|
[
"MIT"
] | null | null | null |
import cedille-options
module to-string (options : cedille-options.options) where
open import lib
open import cedille-types
open import constants
open import syntax-util
open import ctxt
open import rename
open import general-util
open import datatype-functions
open import erase
data expr-side : Set where
left : expr-side
right : expr-side
neither : expr-side
not-left : expr-side → 𝔹
not-left left = ff
not-left _ = tt
not-right : expr-side → 𝔹
not-right right = ff
not-right _ = tt
exprd-eq : exprd → exprd → 𝔹
exprd-eq TERM TERM = tt
exprd-eq TYPE TYPE = tt
exprd-eq KIND KIND = tt
exprd-eq TK TK = tt
exprd-eq LIFTINGTYPE LIFTINGTYPE = tt
exprd-eq QUALIF QUALIF = tt
exprd-eq ARG ARG = tt
exprd-eq _ _ = ff
no-parens : {ed : exprd} → {ed' : exprd} → ⟦ ed ⟧ → ⟦ ed' ⟧ → expr-side → 𝔹
no-parens {_} {TERM} _ (IotaPair pi t t' og pi') lr = tt
no-parens {_} {TYPE} _ (TpEq _ t t' _) lr = tt
no-parens {_} {TERM} _ (Beta pi ot ot') lr = tt
no-parens {_} {TERM} _ (Phi pi eq t t' pi') right = tt
no-parens {_} {TERM} _ (Phi pi eq t t' pi') neither = tt
no-parens {_} {TERM} _ (Rho _ _ _ _ _ _) right = tt
no-parens {_} {TERM} _ (Chi _ _ _) right = tt
no-parens {_} {TERM} _ (Delta _ _ _) right = tt
no-parens {_} {TERM} _ (Let _ _ _ _) lr = tt
no-parens {_} {TERM} _ (Lam _ _ _ _ _ _) lr = tt
no-parens {_} {TERM} _ (Mu _ _ _ _ _ _ _ _) right = tt
no-parens {_} {TERM} _ (Mu' _ _ _ _ _ _ _) right = tt
no-parens {_} {TYPE} _ (TpLambda _ _ _ _ _) lr = tt
no-parens {_} {TYPE} _ (Abs _ _ _ _ _ _) lr = tt
--no-parens {_} {KIND} _ (KndPi _ _ _ _ _) lr = tt
no-parens {_} {TYPE} _ (Iota _ _ _ _ _) lr = tt
no-parens {_} {LIFTINGTYPE} _ (LiftPi _ _ _ _) lr = tt
no-parens {TERM} {_} (App t me t') p lr = is-term-level-app p && not-right lr
no-parens {TERM} {_} (AppTp t T) p lr = is-term-level-app p && not-right lr
no-parens {TERM} {_} (Beta pi ot ot') p lr = tt
no-parens {TERM} {_} (Chi pi mT t) p lr = ff
no-parens {TERM} {_} (Delta pi mT t) p lr = ff
no-parens {TERM} {_} (Epsilon pi lr' m t) p lr = is-eq-op p
no-parens {TERM} {_} (Hole pi) p lr = tt
no-parens {TERM} {_} (IotaPair pi t t' og pi') p lr = tt
no-parens {TERM} {_} (IotaProj t n pi) p lr = tt
no-parens {TERM} {_} (Lam pi l' pi' x oc t) p lr = ff
no-parens {TERM} {_} (Let pi _ dtT t) p lr = ff
no-parens {TERM} {_} (Open _ _ _ _ _) p lr = ff
no-parens {TERM} {_} (Parens pi t pi') p lr = tt
no-parens {TERM} {_} (Phi pi eq t t' pi') p lr = ff
no-parens {TERM} {_} (Rho pi op on eq og t) p lr = ff
no-parens {TERM} {_} (Sigma pi t) p lr = is-eq-op p
no-parens {TERM} {_} (Theta pi theta t lts) p lr = ff
no-parens {TERM} {_} (Var pi x) p lr = tt
no-parens {TERM} {_} (Mu _ _ _ _ _ _ _ _) p lr = ff
no-parens {TERM} {_} (Mu' _ _ _ _ _ _ _) p lr = ff
no-parens {TYPE} {e} (Abs pi b pi' x Tk T) p lr = exprd-eq e TYPE && is-arrow p && not-left lr
no-parens {TYPE} {_} (Iota pi pi' x oT T) p lr = ff
no-parens {TYPE} {_} (Lft pi pi' x t lT) p lr = ff
no-parens {TYPE} {_} (NoSpans T pi) p lr = tt
no-parens {TYPE} {_} (TpApp T T') p lr = is-arrow p || (is-type-level-app p && not-right lr)
no-parens {TYPE} {_} (TpAppt T t) p lr = is-arrow p || (is-type-level-app p && not-right lr)
no-parens {TYPE} {e} (TpArrow T a T') p lr = exprd-eq e TYPE && is-arrow p && not-left lr
no-parens {TYPE} {_} (TpEq _ t t' _) p lr = tt
no-parens {TYPE} {_} (TpHole pi) p lr = tt
no-parens {TYPE} {_} (TpLambda pi pi' x Tk T) p lr = ff
no-parens {TYPE} {_} (TpParens pi T pi') p lr = tt
no-parens {TYPE} {_} (TpVar pi x) p lr = tt
no-parens {TYPE} {_} (TpLet _ _ _) _ _ = ff
no-parens {KIND} {_} (KndArrow k k') p lr = is-arrow p && not-left lr
no-parens {KIND} {_} (KndParens pi k pi') p lr = tt
no-parens {KIND} {_} (KndPi pi pi' x Tk k) p lr = is-arrow p && not-left lr
no-parens {KIND} {_} (KndTpArrow T k) p lr = is-arrow p && not-left lr
no-parens {KIND} {_} (KndVar pi x as) p lr = tt
no-parens {KIND} {_} (Star pi) p lr = tt
no-parens {LIFTINGTYPE} (LiftArrow lT lT') p lr = is-arrow p && not-left lr
no-parens {LIFTINGTYPE} (LiftParens pi lT pi') p lr = tt
no-parens {LIFTINGTYPE} (LiftPi pi x T lT) p lr = is-arrow p && not-left lr
no-parens {LIFTINGTYPE} (LiftStar pi) p lr = tt
no-parens {LIFTINGTYPE} (LiftTpArrow T lT) p lr = is-arrow p && not-left lr
no-parens {TK} _ _ _ = tt
no-parens {QUALIF} _ _ _ = tt
no-parens {ARG} _ _ _ = tt
pattern ced-ops-drop-spine = cedille-options.options.mk-options _ _ _ _ ff _ _ ff
pattern ced-ops-conv-arr = cedille-options.options.mk-options _ _ _ _ _ _ _ ff
pattern ced-ops-conv-abs = cedille-options.options.mk-options _ _ _ _ _ _ _ tt
drop-spine : cedille-options.options → {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
drop-spine ops @ ced-ops-drop-spine = h
where
drop-mod-args : ctxt → maybeErased → spineApp → spineApp
drop-mod-args Γ me (v , as) =
let qv = unqual-all (ctxt-get-qualif Γ) v in qv ,
maybe-else' (maybe-if (~ v =string qv) ≫maybe ctxt-qualif-args-length Γ me qv)
as (λ n → reverse (drop n (reverse as)))
h : {ed : exprd} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
h {TERM} Γ t = maybe-else' (term-to-spapp t) t (spapp-term ∘ drop-mod-args Γ (cedille-options.options.erase-types ops))
h {TYPE} Γ T = maybe-else' (type-to-spapp T) T (spapp-type ∘ drop-mod-args Γ NotErased)
h Γ x = x
drop-spine ops Γ x = x
to-string-rewrite : {ed : exprd} → ctxt → cedille-options.options → ⟦ ed ⟧ → Σi exprd ⟦_⟧
to-string-rewrite{TERM} Γ ops (Parens _ t _) = to-string-rewrite Γ ops t
to-string-rewrite{TYPE} Γ ops (TpParens _ T _) = to-string-rewrite Γ ops T
to-string-rewrite{KIND} Γ ops (KndParens _ k _) = to-string-rewrite Γ ops k
to-string-rewrite{LIFTINGTYPE} Γ ops (LiftParens _ lT _) = to-string-rewrite Γ ops lT
to-string-rewrite{TK} Γ ops (Tkt T) = to-string-rewrite Γ ops T
to-string-rewrite{TK} Γ ops (Tkk k) = to-string-rewrite Γ ops k
to-string-rewrite{TYPE} Γ ced-ops-conv-arr (Abs _ me _ ignored-var (Tkt T) T') = , TpArrow T me T'
to-string-rewrite{KIND} Γ ced-ops-conv-arr (KndPi _ _ ignored-var (Tkt T) k) = , KndTpArrow T k
to-string-rewrite{KIND} Γ ced-ops-conv-arr (KndPi _ _ ignored-var (Tkk k) k') = , KndArrow k k'
to-string-rewrite{LIFTINGTYPE} Γ ced-ops-conv-arr (LiftPi _ ignored-var T lT) = , LiftTpArrow T lT
to-string-rewrite{TYPE} Γ ced-ops-conv-abs (TpArrow T me T') = , Abs posinfo-gen me posinfo-gen ignored-var (Tkt T) T'
to-string-rewrite{KIND} Γ ced-ops-conv-abs (KndTpArrow T k) = , KndPi posinfo-gen posinfo-gen ignored-var (Tkt T) k
to-string-rewrite{KIND} Γ ced-ops-conv-abs (KndArrow k k') = , KndPi posinfo-gen posinfo-gen ignored-var (Tkk k) k'
to-string-rewrite{LIFTINGTYPE} Γ ced-ops-conv-abs (LiftTpArrow T lT) = , LiftPi posinfo-gen ignored-var T lT
to-string-rewrite{TERM} Γ ops @ ced-ops-conv-abs (Open _ _ _ _ t) = to-string-rewrite Γ ops t
to-string-rewrite{TERM} Γ ops (Sigma pi t) with to-string-rewrite Γ ops t
...| ,_ {TERM} (Sigma pi' t') = , t'
...| ,_ {TERM} t' = , Sigma posinfo-gen t'
...| t? = , Sigma posinfo-gen t
to-string-rewrite Γ ops x = , drop-spine ops Γ x
-------------------------------
strM : Set
strM = ∀ {ed} → rope → ℕ → 𝕃 tag → ctxt → maybe ⟦ ed ⟧ → expr-side → rope × ℕ × 𝕃 tag
to-stringh : {ed : exprd} → ⟦ ed ⟧ → strM
strM-Γ : (ctxt → strM) → strM
strM-Γ f s n ts Γ = f Γ s n ts Γ
infixr 4 _≫str_
_≫str_ : strM → strM → strM
(m ≫str m') s n ts Γ pe lr with m s n ts Γ pe lr
(m ≫str m') s n ts Γ pe lr | s' , n' , ts' = m' s' n' ts' Γ pe lr
strAdd : string → strM
strAdd s s' n ts Γ pe lr = s' ⊹⊹ [[ s ]] , n + string-length s , ts
strΓ' : defScope → var → strM → strM
strΓ' ds v m s n ts Γ@(mk-ctxt (fn , mn , ps , q) syms i symb-occs Δ) pe =
let gl = ds iff globalScope
v' = if gl then (mn # v) else v in
m s n ts (mk-ctxt
(fn , mn , ps , qualif-insert-params q v' (unqual-local v) (if gl then ps else []))
syms (trie-insert i v' (var-decl , ("missing" , "missing"))) symb-occs Δ) pe
strΓ : var → strM → strM
strΓ x m s n ts Γ = m s n ts (ctxt-var-decl x Γ)
ctxt-get-file-id : ctxt → (filename : string) → ℕ
ctxt-get-file-id (mk-ctxt mod (syms , mn-fn , mn-ps , ids , id) is os Δ) =
trie-lookup-else 0 ids
make-loc-tag : ctxt → (filename start-to end-to : string) → (start-from end-from : ℕ) → tag
make-loc-tag Γ fn s e = make-tag "loc"
(("fn" , [[ ℕ-to-string (ctxt-get-file-id Γ fn) ]]) ::
("s" , [[ s ]]) :: ("e" , [[ e ]]) :: [])
var-loc-tag : ctxt → location → var → 𝕃 (string × 𝕃 tag)
var-loc-tag Γ ("missing" , "missing") x = []
var-loc-tag Γ ("" , _) x = []
var-loc-tag Γ (_ , "") x = []
var-loc-tag Γ (fn , pi) x =
let fn-tag = "fn" , [[ ℕ-to-string (ctxt-get-file-id Γ fn) ]]
s-tag = "s" , [[ pi ]]
e-tag = "e" , [[ posinfo-plus-str pi x ]] in
[ "loc" , fn-tag :: s-tag :: e-tag :: [] ]
var-tags : ctxt → qvar → var → 𝕃 (string × 𝕃 tag)
var-tags Γ qv uqv =
(if qv =string qualif-var Γ uqv then id else ("shadowed" , []) ::_)
(var-loc-tag Γ (ctxt-var-location Γ qv) uqv)
strAddTags : string → 𝕃 (string × 𝕃 tag) → strM
strAddTags sₙ tsₙ sₒ n tsₒ Γ pe lr =
let n' = n + string-length sₙ in
sₒ ⊹⊹ [[ sₙ ]] , n' , map (uncurry λ k vs → make-tag k vs n n') tsₙ ++ tsₒ
strVar : var → strM
strVar v = strM-Γ λ Γ →
let uqv = unqual-local v -- $ unqual-all (ctxt-get-qualif Γ) v
uqv' = if cedille-options.options.show-qualified-vars options then v else uqv in
strAddTags uqv' (var-tags Γ (qualif-var Γ v) uqv)
strKvar : var → strM
strKvar v = strM-Γ λ Γ → strVar (unqual-all (ctxt-get-qualif Γ) v)
-- Only necessary to unqual-local because of module parameters
strBvar : var → (class body : strM) → strM
strBvar v cm bm = strAdd (unqual-local v) ≫str cm ≫str strΓ' localScope v bm
strMetaVar : var → span-location → strM
strMetaVar x (fn , pi , pi') s n ts Γ pe lr =
let n' = n + string-length x in
s ⊹⊹ [[ x ]] , n' , make-loc-tag Γ fn pi pi' n n' :: ts
strEmpty : strM
strEmpty s n ts Γ pe lr = s , n , ts
{-# TERMINATING #-}
term-to-stringh : term → strM
type-to-stringh : type → strM
kind-to-stringh : kind → strM
liftingType-to-stringh : liftingType → strM
tk-to-stringh : tk → strM
ctr-to-string : ctr → strM
ctrs-to-string : ctrs → strM
case-to-string : case → strM
cases-to-string : cases → strM
caseArgs-to-string : caseArgs → strM → strM
params-to-string : params → strM
params-to-string' : strM → params → strM
file-to-string : start → strM
cmds-to-string : cmds → strM → strM
cmd-to-string : cmd → strM → strM
optTerm-to-string : optTerm → string → string → strM
optClass-to-string : optClass → strM
optGuide-to-string : optGuide → strM
optNums-to-string : optNums → strM
optType-to-string : string → optType → strM
maybeCheckType-to-string : optType → strM
lterms-to-string : lterms → strM
arg-to-string : arg → strM
args-to-string : args → strM
binder-to-string : maybeErased → string
opacity-to-string : opacity → string
maybeErased-to-string : maybeErased → string
lam-to-string : maybeErased → string
leftRight-to-string : leftRight → string
vars-to-string : vars → strM
nums-to-string : nums → strM
theta-to-string : theta → strM
arrowtype-to-string : maybeErased → string
maybeMinus-to-string : maybeMinus → string
optPlus-to-string : rhoHnf → string
optPublic-to-string : optPublic → string
optAs-to-string : optAs → strM
to-string-ed : {ed : exprd} → ⟦ ed ⟧ → strM
to-string-ed{TERM} = term-to-stringh
to-string-ed{TYPE} = type-to-stringh
to-string-ed{KIND} = kind-to-stringh
to-string-ed{LIFTINGTYPE} = liftingType-to-stringh
to-string-ed{TK} = tk-to-stringh
to-string-ed{ARG} = arg-to-string
to-string-ed{QUALIF} q = strEmpty
to-stringh' : {ed : exprd} → expr-side → ⟦ ed ⟧ → strM
to-stringh' {ed} lr t {ed'} s n ts Γ mp lr' =
elim-Σi (to-string-rewrite Γ options t) λ t' →
parens-unless (~ isJust (mp ≫=maybe λ pe → maybe-if (~ no-parens t' pe lr)))
(to-string-ed t') s n ts Γ (just t') lr
where
parens-unless : 𝔹 → strM → strM
parens-unless p s = if p then s else (strAdd "(" ≫str s ≫str strAdd ")")
to-stringl : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringr : {ed : exprd} → ⟦ ed ⟧ → strM
to-stringl = to-stringh' left
to-stringr = to-stringh' right
to-stringh = to-stringh' neither
ctr-to-string (Ctr _ x T) = strAdd x ≫str strAdd " : " ≫str to-stringh T
ctrs-to-string [] = strEmpty
ctrs-to-string (c :: []) = ctr-to-string c
ctrs-to-string (c :: cs) =
ctr-to-string c ≫str
strAdd " | " ≫str
ctrs-to-string cs
{-
caseArgs-drop-params : params → caseArgs → caseArgs
caseArgs-drop-params (Decl _ _ NotErased x (Tkt T) _ :: ps) (CaseTermArg _ NotErased ignored-var :: as) =
caseArgs-drop-params ps as
caseArgs-drop-params (Decl _ _ Erased x (Tkt T) _ :: ps) (CaseTermArg _ Erased ignored-var :: as) =
caseArgs-drop-params ps as
caseArgs-drop-params (Decl _ _ _ x (Tkk k) _ :: ps) (CaseTypeArg _ ignored-var :: as) =
caseArgs-drop-params ps as
caseArgs-drop-params (_ :: ps) as = caseArgs-drop-params ps as
caseArgs-drop-params [] as = as
-}
case-to-string (Case _ x as t) =
strM-Γ λ Γ →
let as-f = λ x as → strVar x ≫str caseArgs-to-string as (strAdd " ➔ " ≫str to-stringr t) in
case (env-lookup Γ x , options) of uncurry λ where
(just (ctr-def mps T _ _ _ , _ , _)) ced-ops-drop-spine →
as-f (unqual-all (ctxt-get-qualif Γ) x) as
-- $ maybe-else' mps as $ flip caseArgs-drop-params as
_ _ → as-f x as
cases-to-string [] = strEmpty
cases-to-string (m :: []) = case-to-string m
cases-to-string (m :: ms) = case-to-string m ≫str strAdd " | " ≫str cases-to-string ms
caseArgs-to-string [] m = m
caseArgs-to-string (CaseTermArg pi me x :: as) m = strAdd (" " ^ maybeErased-to-string me) ≫str strBvar x strEmpty (caseArgs-to-string as m)
caseArgs-to-string (CaseTypeArg pi x :: as) m = strAdd " · " ≫str strBvar x strEmpty (caseArgs-to-string as m)
tk-to-stringh (Tkt T) = to-stringh T
tk-to-stringh (Tkk k) = to-stringh k
private
let-lbrack-to-string : forceErased → string
let-lbrack-to-string tt = "{ "
let-lbrack-to-string ff = "[ "
let-rbrack-to-string : forceErased → string
let-rbrack-to-string tt = " } - "
let-rbrack-to-string ff = " ] - "
term-to-stringh (App t me t') = to-stringl t ≫str strAdd (" " ^ maybeErased-to-string me) ≫str to-stringr t'
term-to-stringh (AppTp t T) = to-stringl t ≫str strAdd " · " ≫str to-stringr T
term-to-stringh (Beta pi ot ot') = strAdd "β" ≫str optTerm-to-string ot " < " " >" ≫str optTerm-to-string ot' " { " " }"
term-to-stringh (Chi pi mT t) = strAdd "χ" ≫str optType-to-string " " mT ≫str strAdd " - " ≫str to-stringr t
term-to-stringh (Delta pi mT t) = strAdd "δ" ≫str optType-to-string " " mT ≫str strAdd " - " ≫str to-stringr t
term-to-stringh (Epsilon pi lr m t) = strAdd "ε" ≫str strAdd (leftRight-to-string lr) ≫str strAdd (maybeMinus-to-string m) ≫str to-stringh t
term-to-stringh (Hole pi) = strM-Γ λ Γ → strAddTags "●" (var-loc-tag Γ (split-var pi) "●")
term-to-stringh (IotaPair pi t t' og pi') = strAdd "[ " ≫str to-stringh t ≫str strAdd " , " ≫str to-stringh t' ≫str optGuide-to-string og ≫str strAdd " ]"
term-to-stringh (IotaProj t n pi) = to-stringh t ≫str strAdd ("." ^ n)
term-to-stringh (Lam pi l pi' x oc t) = strAdd (lam-to-string l) ≫str strAdd " " ≫str strBvar x (optClass-to-string oc) (strAdd " . " ≫str to-stringr t)
term-to-stringh (Let pi fe dtT t) with dtT
...| DefTerm pi' x m t' = strAdd (let-lbrack-to-string fe) ≫str strBvar x (maybeCheckType-to-string m
≫str strAdd " = " ≫str to-stringh t' ≫str strAdd (let-rbrack-to-string fe)) (to-stringh t)
...| DefType pi' x k t' = strAdd "[ " ≫str strBvar x (strAdd " : " ≫str to-stringh k ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t)
--term-to-stringh (Open elab-hide-key o pi' x t) = term-to-stringh t
term-to-stringh (Open pi o pi' x t) = strAdd (if o iff OpacTrans then "open " else "close ") ≫str strVar x ≫str strAdd " - " ≫str to-stringh t
term-to-stringh (Parens pi t pi') = to-stringh t
term-to-stringh (Phi pi eq t t' pi') = strAdd "φ " ≫str to-stringl eq ≫str strAdd " - " ≫str to-stringh t ≫str strAdd " { " ≫str to-stringr t' ≫str strAdd " }"
term-to-stringh (Rho pi op on eq og t) = strAdd "ρ" ≫str strAdd (optPlus-to-string op) ≫str optNums-to-string on ≫str strAdd " " ≫str to-stringl eq ≫str optGuide-to-string og ≫str strAdd " - " ≫str to-stringr t
term-to-stringh (Sigma pi t) = strAdd "ς " ≫str to-stringh t
term-to-stringh (Theta pi theta t lts) = theta-to-string theta ≫str to-stringh t ≫str lterms-to-string lts
term-to-stringh (Var pi x) = strVar x
term-to-stringh (Mu pi pi' x t ot pi'' cs pi''') = strAdd "μ " ≫str strBvar x (strAdd " . " ≫str to-stringl t ≫str optType-to-string " @ " ot) (strAdd " { " ≫str cases-to-string cs ≫str strAdd " }")
term-to-stringh (Mu' pi ot t oT pi' cs pi'') = strAdd "μ' " ≫str optTerm-to-string ot " < " " > " ≫str to-stringl t ≫str optType-to-string " @ " oT ≫str strAdd " { " ≫str cases-to-string cs ≫str strAdd " }"
type-to-stringh (Abs pi b pi' x Tk T) = strAdd (binder-to-string b ^ " ") ≫str strBvar x (strAdd " : " ≫str to-stringl Tk ≫str strAdd " . ") (to-stringh T)
type-to-stringh (Iota pi pi' x T T') = strAdd "ι " ≫str strBvar x (strAdd " : " ≫str to-stringh T ≫str strAdd " . ") (to-stringh T')
type-to-stringh (Lft pi pi' x t lT) = strAdd "↑ " ≫str strBvar x (strAdd " . ") (to-stringh t) ≫str strAdd " : " ≫str to-stringh lT
type-to-stringh (NoSpans T pi) = to-string-ed T
type-to-stringh (TpApp T T') = to-stringl T ≫str strAdd " · " ≫str to-stringr T'
type-to-stringh (TpAppt T t) = to-stringl T ≫str strAdd " " ≫str to-stringr t
type-to-stringh (TpArrow T a T') = to-stringl T ≫str strAdd (arrowtype-to-string a) ≫str to-stringr T'
type-to-stringh (TpEq _ t t' _) = strAdd "{ " ≫str to-stringh (erase-term t) ≫str strAdd " ≃ " ≫str to-stringh (erase-term t') ≫str strAdd " }"
type-to-stringh (TpHole pi) = strM-Γ λ Γ → strAddTags "●" (var-loc-tag Γ (split-var pi) "●")
type-to-stringh (TpLambda pi pi' x Tk T) = strAdd "λ " ≫str strBvar x (strAdd " : " ≫str tk-to-stringh Tk ≫str strAdd " . ") (to-stringr T)
type-to-stringh (TpParens pi T pi') = to-stringh T
type-to-stringh (TpVar pi x) = strVar x
type-to-stringh (TpLet pi dtT t) with dtT
...| DefTerm pi' x m t' = strAdd "[ " ≫str strBvar x (maybeCheckType-to-string m ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t)
...| DefType pi' x k t' = strAdd "[ " ≫str strBvar x (strAdd " : " ≫str to-stringh k ≫str strAdd " = " ≫str to-stringh t' ≫str strAdd " ] - ") (to-stringh t)
kind-to-stringh (KndArrow k k') = to-stringl k ≫str strAdd " ➔ " ≫str to-stringr k'
kind-to-stringh (KndParens pi k pi') = to-stringh k
kind-to-stringh (KndPi pi pi' x Tk k) = strAdd "Π " ≫str strBvar x (strAdd " : " ≫str to-stringl Tk ≫str strAdd " . ") (to-stringh k)
kind-to-stringh (KndTpArrow T k) = to-stringl T ≫str strAdd " ➔ " ≫str to-stringr k
kind-to-stringh (KndVar pi x as) = strKvar x ≫str args-to-string as
kind-to-stringh (Star pi) = strAdd "★"
liftingType-to-stringh (LiftArrow lT lT') = to-stringl lT ≫str strAdd " ➔↑ " ≫str to-stringr lT'
liftingType-to-stringh (LiftParens pi lT pi') = strAdd "(" ≫str to-string-ed lT ≫str strAdd ")"
liftingType-to-stringh (LiftPi pi x T lT) = strAdd "Π↑ " ≫str strBvar x (strAdd " : " ≫str to-stringh T ≫str strAdd " . ") (to-stringh lT)
liftingType-to-stringh (LiftStar pi) = strAdd "☆"
liftingType-to-stringh (LiftTpArrow T lT) = to-stringl T ≫str strAdd " ➔↑ " ≫str to-stringr lT
optTerm-to-string NoTerm c1 c2 = strEmpty
optTerm-to-string (SomeTerm t _) c1 c2 = strAdd c1 ≫str to-stringh (erase-term t) ≫str strAdd c2
optClass-to-string NoClass = strEmpty
optClass-to-string (SomeClass Tk) = strAdd " : " ≫str tk-to-stringh Tk
optGuide-to-string NoGuide = strEmpty
optGuide-to-string (Guide pi v T) = strAdd " @ " ≫str strBvar v (strAdd " . ") (to-stringh T)
optType-to-string pfx NoType = strEmpty
optType-to-string pfx (SomeType T) = strAdd pfx ≫str to-stringh T
maybeCheckType-to-string NoType = strEmpty
maybeCheckType-to-string (SomeType T) = strAdd " : " ≫str to-stringh T
lterms-to-string (Lterm m t :: ts) = strAdd (" " ^ maybeErased-to-string m) ≫str to-stringh t ≫str lterms-to-string ts
lterms-to-string [] = strEmpty
arg-to-string (TermArg me t) = strAdd (maybeErased-to-string me) ≫str to-stringh t
arg-to-string (TypeArg T) = strAdd "· " ≫str to-stringh T
args-to-string = foldr' strEmpty λ t x → strAdd " " ≫str arg-to-string t ≫str x
binder-to-string All = "∀"
binder-to-string Pi = "Π"
opacity-to-string OpacOpaque = "opaque "
opacity-to-string OpacTrans = ""
maybeErased-to-string Erased = "-"
maybeErased-to-string NotErased = ""
lam-to-string Erased = "Λ"
lam-to-string NotErased = "λ"
leftRight-to-string Left = "l"
leftRight-to-string Right = "r"
leftRight-to-string Both = ""
vars-to-string (VarsStart v) = strVar v
vars-to-string (VarsNext v vs) = strVar v ≫str strAdd " " ≫str vars-to-string vs
theta-to-string Abstract = strAdd "θ "
theta-to-string AbstractEq = strAdd "θ+ "
theta-to-string (AbstractVars vs) = strAdd "θ<" ≫str vars-to-string vs ≫str strAdd "> "
nums-to-string (NumsStart n) = strAdd n
nums-to-string (NumsNext n ns) = strAdd n ≫str strAdd " " ≫str nums-to-string ns
optNums-to-string NoNums = strEmpty
optNums-to-string (SomeNums ns) = strAdd "<" ≫str nums-to-string ns ≫str strAdd ">"
arrowtype-to-string NotErased = " ➔ "
arrowtype-to-string Erased = " ➾ "
maybeMinus-to-string EpsHnf = ""
maybeMinus-to-string EpsHanf = "-"
optPlus-to-string RhoPlain = ""
optPlus-to-string RhoPlus = "+"
optPublic-to-string NotPublic = ""
optPublic-to-string IsPublic = "public "
optAs-to-string NoOptAs = strEmpty
optAs-to-string (SomeOptAs _ x) = strAdd " as " ≫str strAdd x
braceL : maybeErased → string
braceL me = if me then "{" else "("
braceR : maybeErased → string
braceR me = if me then "}" else ")"
param-to-string : decl → strM → strM
param-to-string (Decl _ pi me v atk _) f =
strAdd (braceL me) ≫str
strAdd (unqual-local v) ≫str
strAdd " : " ≫str
tk-to-stringh atk ≫str
strAdd (braceR me) ≫str
strΓ' localScope v f
params-to-string' f [] = f
params-to-string' f (p :: []) = param-to-string p f
params-to-string' f (p :: ps) = param-to-string p (strAdd " " ≫str params-to-string' f ps)
params-to-string = params-to-string' strEmpty
file-to-string (File is _ _ mn ps cs _) =
cmds-to-string (imps-to-cmds is)
(strAdd "module " ≫str
strAdd mn ≫str
strAdd " " ≫str
params-to-string'
(strAdd "." ≫str strAdd "\n" ≫str
cmds-to-string cs strEmpty) ps)
cmds-to-string [] f = f
cmds-to-string (c :: cs) f =
strAdd "\n" ≫str
cmd-to-string c
(strAdd "\n" ≫str
cmds-to-string cs f)
cmd-to-string (DefTermOrType op (DefTerm pi x mcT t) _) f =
strM-Γ λ Γ →
let ps = ctxt-get-current-params Γ
ps' = if pi =string elab-hide-key then params-set-erased Erased ps else ps in
strAdd (opacity-to-string op) ≫str
strAdd x ≫str
maybeCheckType-to-string (case mcT of λ where
NoType → NoType
(SomeType T) → SomeType (abs-expand-type ps' T)) ≫str
strAdd " = " ≫str
to-stringh (lam-expand-term ps' t) ≫str
strAdd " ." ≫str
strΓ' globalScope x f
cmd-to-string (DefTermOrType op (DefType pi x k T) _) f =
strM-Γ λ Γ →
let ps = ctxt-get-current-params Γ
ps' = if pi =string elab-hide-key then params-set-erased Erased ps else ps in
strAdd (opacity-to-string op) ≫str
strAdd x ≫str
strAdd " : " ≫str
to-stringh (abs-expand-kind ps' k) ≫str
strAdd " = " ≫str
to-stringh (lam-expand-type ps' T) ≫str
strAdd " ." ≫str
strΓ' globalScope x f
cmd-to-string (DefKind pi x ps k _) f =
strM-Γ λ Γ →
let ps' = ctxt-get-current-params Γ in
strAdd x ≫str
params-to-string (ps' ++ ps) ≫str
strAdd " = " ≫str
to-stringh k ≫str
strAdd " ." ≫str
strΓ' globalScope x f
cmd-to-string (ImportCmd (Import _ op _ fn oa as _)) f =
strAdd "import " ≫str
strAdd (optPublic-to-string op) ≫str
strAdd fn ≫str
optAs-to-string oa ≫str
args-to-string as ≫str
strAdd " ." ≫str
f
cmd-to-string (DefDatatype (Datatype pi pi' x ps k cs ) pi'') f =
strAdd "data " ≫str
strAdd x ≫str
strAdd " " ≫str
params-to-string ps ≫str
strAdd " : " ≫str
kind-to-stringh k ≫str
strAdd " = " ≫str
ctrs-to-string cs ≫str
strΓ' globalScope x f
strRun : ctxt → strM → rope
strRun Γ m = fst (m {TERM} [[]] 0 [] Γ nothing neither)
strRunTag : (name : string) → ctxt → strM → tagged-val
strRunTag name Γ m with m {TERM} [[]] 0 [] Γ nothing neither
...| s , n , ts = name , s , ts
to-string-tag : {ed : exprd} → string → ctxt → ⟦ ed ⟧ → tagged-val
to-string-tag name Γ t = strRunTag name Γ
(to-stringh
(if cedille-options.options.erase-types options
then erase t
else t))
to-string : {ed : exprd} → ctxt → ⟦ ed ⟧ → rope
to-string Γ t = strRun Γ (to-stringh t)
tk-to-string : ctxt → tk → rope
tk-to-string Γ atk = strRun Γ (tk-to-stringh atk)
params-to-string-tag : string → ctxt → params → tagged-val
params-to-string-tag name Γ ps = strRunTag name Γ (params-to-string ps)
| 45.186131
| 210
| 0.644213
|
1ead735f83d208f20c09b678446c9024da75943c
| 986
|
agda
|
Agda
|
test/Succeed/Issue4048.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4048.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4048.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting #-}
module Issue4048 where
data _==_ {i} {A : Set i} : (x y : A) → Set i where
refl : {a : A} → a == a
{-# BUILTIN REWRITE _==_ #-}
postulate
Π : (A : Set) (B : A → Set) → Set
lam : {A : Set} {B : A → Set} (b : (a : A) → B a) → Π A B
app : {A : Set} {B : A → Set} (f : Π A B) (a : A) → B a
Π-β : {A : Set} {B : A → Set} (b : (a : A) → B a) (a : A) → app (lam b) a == b a
{-# REWRITE Π-β #-}
postulate
⊤ : Set
tt : ⊤
⊤-elim : ∀ {i} (A : ⊤ → Set i) (d : A tt) (x : ⊤) → A x
⊤-β : ∀ {i} (A : ⊤ → Set i) (d : A tt) → ⊤-elim A d tt == d
{-# REWRITE ⊤-β #-}
tt' : ⊤
tt' = tt
module _
(C : (p : ⊤) → Set)
(z : C tt)
where
F : (n p x : ⊤) → C p
F n p = app (⊤-elim (λ n → (p : ⊤) → Π ⊤ (λ _ → C p))
(⊤-elim _ (lam (⊤-elim _ z)))
n p)
F-red : F tt tt tt == z
F-red = refl
-- Bug?
F-red' : F tt tt' tt == z
F-red' = refl -- Not accepted, even though tt' is tt by definition.
| 24.04878
| 82
| 0.396552
|
22d8f0128e902a2c82808909dce32a3a2073e772
| 490
|
agda
|
Agda
|
agda-stdlib/src/Data/Char.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Char.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Char.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Characters
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Char where
------------------------------------------------------------------------
-- Re-export base definitions and decidability of equality
open import Data.Char.Base public
open import Data.Char.Properties using (_≈?_; _≟_; _<?_; _==_) public
| 30.625
| 72
| 0.393878
|
ad4cb53c8315cedde13f1f7bd51defd878ffa113
| 592
|
agda
|
Agda
|
test/Common/Nat.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/Common/Nat.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/Common/Nat.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
module Common.Nat where
open import Agda.Builtin.Nat public
using ( Nat; zero; suc; _+_; _*_ )
renaming ( _-_ to _∸_ )
{-# COMPILED_JS Nat function (x,v) { return (x < 1? v.zero(): v.suc(x-1)); } #-}
{-# COMPILED_JS zero 0 #-}
{-# COMPILED_JS suc function (x) { return x+1; } #-}
{-# COMPILED_JS _+_ function (x) { return function (y) { return x+y; }; } #-}
{-# COMPILED_JS _*_ function (x) { return function (y) { return x*y; }; } #-}
{-# COMPILED_JS _∸_ function (x) { return function (y) { return Math.max(0,x-y); }; } #-}
pred : Nat → Nat
pred zero = zero
pred (suc n) = n
| 31.157895
| 89
| 0.586149
|
4a2e4094ca5cf653a394d630c38c3a4ed2ffed8c
| 5,453
|
agda
|
Agda
|
src/fot/FOTC/Program/SortList/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/SortList/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/SortList/PropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Properties stated in the Burstall's paper
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool.PropertiesATP
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesATP
open import FOTC.Program.SortList.Properties.Totality.BoolATP
open import FOTC.Program.SortList.Properties.Totality.ListN-ATP
open import FOTC.Program.SortList.Properties.Totality.OrdList.FlattenATP
open import FOTC.Program.SortList.Properties.Totality.OrdListATP
open import FOTC.Program.SortList.Properties.Totality.OrdTreeATP
open import FOTC.Program.SortList.Properties.Totality.TreeATP
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
-- Burstall's lemma: If t is ordered then totree(i, t) is ordered.
toTree-OrdTree : ∀ {item t} → N item → Tree t → OrdTree t →
OrdTree (toTree · item · t)
toTree-OrdTree {item} Nitem tnil OTt = prf
where postulate prf : OrdTree (toTree · item · nil)
{-# ATP prove prf #-}
toTree-OrdTree {item} Nitem (ttip {i} Ni) OTt =
case prf₁ prf₂ (x>y∨x≤y Ni Nitem)
where
postulate prf₁ : i > item → OrdTree (toTree · item · tip i)
{-# ATP prove prf₁ x≤x x<y→x≤y x>y→x≰y #-}
postulate prf₂ : i ≤ item → OrdTree (toTree · item · tip i)
{-# ATP prove prf₂ x≤x #-}
toTree-OrdTree {item} Nitem (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTtnode =
case (prf₁ (toTree-OrdTree Nitem Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(prf₂ (toTree-OrdTree Nitem Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(x>y∨x≤y Ni Nitem)
where
postulate prf₁ : ordTree (toTree · item · t₁) ≡ true →
OrdTree t₂ →
i > item →
OrdTree (toTree · item · node t₁ i t₂)
{-# ATP prove prf₁ &&-list₄-t x>y→x≰y le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool toTree-OrdTree-helper₁ #-}
postulate prf₂ : ordTree (toTree · item · t₂) ≡ true →
OrdTree t₁ →
i ≤ item →
OrdTree (toTree · item · node t₁ i t₂)
{-# ATP prove prf₂ &&-list₄-t le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool toTree-OrdTree-helper₂ #-}
------------------------------------------------------------------------------
-- Burstall's lemma: ord(maketree(is)).
-- makeTree-TreeOrd : ∀ {is} → ListN is → OrdTree (makeTree is)
-- makeTree-TreeOrd LNis =
-- ind-lit OrdTree toTree nil LNis ordTree-nil
-- (λ Nx y TOy → toTree-OrdTree Nx {!!} TOy)
makeTree-OrdTree : ∀ {is} → ListN is → OrdTree (makeTree is)
makeTree-OrdTree lnnil = prf
where postulate prf : OrdTree (makeTree [])
{-# ATP prove prf #-}
makeTree-OrdTree (lncons {i} {is} Ni Lis) = prf (makeTree-OrdTree Lis)
where postulate prf : OrdTree (makeTree is) → OrdTree (makeTree (i ∷ is))
{-# ATP prove prf makeTree-Tree toTree-OrdTree #-}
------------------------------------------------------------------------------
-- Burstall's lemma: If ord(is1) and ord(is2) and is1 ≤ is2 then
-- ord(concat(is1, is2)).
++-OrdList : ∀ {is js} → ListN is → ListN js → OrdList is → OrdList js →
≤-Lists is js → OrdList (is ++ js)
++-OrdList {js = js} lnnil LNjs LOis LOjs is≤js =
subst OrdList (sym (++-leftIdentity js)) LOjs
++-OrdList {js = js} (lncons {i} {is} Ni LNis) LNjs OLi∷is OLjs i∷is≤js =
subst OrdList
(sym (++-∷ i is js))
(lemma (++-OrdList LNis LNjs
(subList-OrdList Ni LNis OLi∷is)
OLjs
(&&-list₂-t₂ (le-ItemList-Bool Ni LNjs)
(le-Lists-Bool LNis LNjs)
(trans (sym (le-Lists-∷ i is js)) i∷is≤js))))
where postulate lemma : OrdList (is ++ js) → OrdList (i ∷ is ++ js)
{-# ATP prove lemma &&-list₂-t ++-OrdList-helper le-ItemList-Bool le-Lists-Bool ordList-Bool #-}
------------------------------------------------------------------------------
-- Burstall's lemma: If t is ordered then (flatten t) is ordered.
flatten-OrdList : ∀ {t} → Tree t → OrdTree t → OrdList (flatten t)
flatten-OrdList tnil OTt =
subst OrdList (sym flatten-nil) ordList-[]
flatten-OrdList (ttip {i} Ni) OTt = prf
where postulate prf : OrdList (flatten (tip i))
{-# ATP prove prf #-}
flatten-OrdList (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTt
= prf (++-OrdList (flatten-ListN Tt₁)
(flatten-ListN Tt₂)
(flatten-OrdList Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTt))
(flatten-OrdList Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTt))
(flatten-OrdList-helper Tt₁ Ni Tt₂ OTt))
where postulate prf : OrdList (flatten t₁ ++ flatten t₂) → -- Indirect IH.
OrdList (flatten (node t₁ i t₂))
{-# ATP prove prf #-}
| 44.696721
| 113
| 0.567027
|
2058e722fdc8e34f529787309d8d6b1e90c4fbfb
| 3,163
|
agda
|
Agda
|
out/Monad/Syntax.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/Monad/Syntax.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/Monad/Syntax.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order term syntax was created from the following second-order syntax description:
syntax Monad | M
type
T : 1-ary
term
ret : α -> T α
bind : T α α.(T β) -> T β | _>>=_ r10
theory
(LU) a : α b : α.(T β) |> bind (ret(a), x. b[x]) = b[a]
(RU) t : T α |> bind (t, x. ret(x)) = t
(AS) t : T α b : α.(T β) c : β.(T γ) |> bind (bind (t, x.b[x]), y.c[y]) = bind (t, x. bind (b[x], y.c[y]))
-}
module Monad.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import Monad.Signature
private
variable
Γ Δ Π : Ctx
α β : MT
𝔛 : Familyₛ
-- Inductive term declaration
module M:Terms (𝔛 : Familyₛ) where
data M : Familyₛ where
var : ℐ ⇾̣ M
mvar : 𝔛 α Π → Sub M Π Γ → M α Γ
ret : M α Γ → M (T α) Γ
_>>=_ : M (T α) Γ → M (T β) (α ∙ Γ) → M (T β) Γ
infixr 10 _>>=_
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
Mᵃ : MetaAlg M
Mᵃ = record
{ 𝑎𝑙𝑔 = λ where
(retₒ ⋮ a) → ret a
(bindₒ ⋮ a , b) → _>>=_ a b
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module Mᵃ = MetaAlg Mᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : M ⇾̣ 𝒜
𝕊 : Sub M Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (ret a) = 𝑎𝑙𝑔 (retₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (_>>=_ a b) = 𝑎𝑙𝑔 (bindₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Mᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ M α Γ) → 𝕤𝕖𝕞 (Mᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (retₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (bindₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ M ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : M ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Mᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : M α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub M Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (ret a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (_>>=_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
M:Syn : Syntax
M:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = M:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open M:Terms 𝔛 in record
{ ⊥ = M ⋉ Mᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax M:Syn public
open M:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands Mᵃ public
open import SOAS.Metatheory M:Syn public
| 25.508065
| 110
| 0.527031
|
293715f0f73b952beb23af5cb3fb49e97094a1bc
| 12,967
|
agda
|
Agda
|
src/H-level/Truncation/Propositional/One-step/Erased.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | 3
|
2020-05-21T22:58:50.000Z
|
2021-09-02T17:18:15.000Z
|
src/H-level/Truncation/Propositional/One-step/Erased.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
src/H-level/Truncation/Propositional/One-step/Erased.agda
|
nad/equality
|
402b20615cfe9ca944662380d7b2d69b0f175200
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The one-step truncation HIT with an erased higher constructor
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining the one-step truncation operator
-- uses path equality, but the supplied notion of equality is used for
-- many other things.
import Equality.Path as P
module H-level.Truncation.Propositional.One-step.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Decidable-UIP equality-with-J using (Constant)
import Equality.Decidable-UIP P.equality-with-J as PD
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Equivalence.Erased.Cubical eq as EEq using (_≃ᴱ_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level.Closure equality-with-J
open import Surjection equality-with-J using (_↠_)
private
variable
a b p : Level
A B : Type a
P : A → Type p
e r x y : A
n : ℕ
------------------------------------------------------------------------
-- The type
-- One-step truncation.
--
-- This definition is based on that in van Doorn's "Constructing the
-- Propositional Truncation using Non-recursive HITs", but has an
-- erased higher constructor.
data ∥_∥¹ᴱ (A : Type a) : Type a where
∣_∣ : A → ∥ A ∥¹ᴱ
@0 ∣∣-constantᴾ : PD.Constant (∣_∣ {A = A})
-- The function ∣_∣ is constant (in erased contexts).
@0 ∣∣-constant : Constant (∣_∣ {A = A})
∣∣-constant x y = _↔_.from ≡↔≡ (∣∣-constantᴾ x y)
------------------------------------------------------------------------
-- Eliminators
-- A dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : ∥ A ∥¹ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
@0 ∣∣-constantʳ :
(x y : A) →
P.[ (λ i → P (∣∣-constantᴾ x y i)) ] ∣∣ʳ x ≡ ∣∣ʳ y
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : ∥ A ∥¹ᴱ) → P x
elimᴾ {A = A} {P = P} e = helper
where
module E = Elimᴾ e
helper : (x : ∥ A ∥¹ᴱ) → P x
helper ∣ x ∣ = E.∣∣ʳ x
helper (∣∣-constantᴾ x y i) = E.∣∣-constantʳ x y i
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
@0 ∣∣-constantʳ : PD.Constant ∣∣ʳ
open Recᴾ public
recᴾ : Recᴾ A B → ∥ A ∥¹ᴱ → B
recᴾ r = elimᴾ λ where
.∣∣ʳ → R.∣∣ʳ
.∣∣-constantʳ → R.∣∣-constantʳ
where
module R = Recᴾ r
-- A dependent eliminator.
record Elim {A : Type a} (P : ∥ A ∥¹ᴱ → Type p) : Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
@0 ∣∣-constantʳ :
(x y : A) → subst P (∣∣-constant x y) (∣∣ʳ x) ≡ ∣∣ʳ y
open Elim public
elim : Elim P → (x : ∥ A ∥¹ᴱ) → P x
elim e = elimᴾ λ where
.∣∣ʳ → E.∣∣ʳ
.∣∣-constantʳ x y → subst≡→[]≡ (E.∣∣-constantʳ x y)
where
module E = Elim e
-- A "computation" rule.
@0 elim-∣∣-constant :
dcong (elim e) (∣∣-constant x y) ≡ Elim.∣∣-constantʳ e x y
elim-∣∣-constant = dcong-subst≡→[]≡ (refl _)
-- A non-dependent eliminator.
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
@0 ∣∣-constantʳ : Constant ∣∣ʳ
open Rec public
rec : Rec A B → ∥ A ∥¹ᴱ → B
rec r = recᴾ λ where
.∣∣ʳ → R.∣∣ʳ
.∣∣-constantʳ x y → _↔_.to ≡↔≡ (R.∣∣-constantʳ x y)
where
module R = Rec r
-- A "computation" rule.
@0 rec-∣∣-constant :
cong (rec r) (∣∣-constant x y) ≡ Rec.∣∣-constantʳ r x y
rec-∣∣-constant = cong-≡↔≡ (refl _)
-- A variant of rec.
rec′ : (f : A → B) → @0 Constant f → ∥ A ∥¹ᴱ → B
rec′ f c = rec λ where
.Rec.∣∣ʳ → f
.Rec.∣∣-constantʳ → c
------------------------------------------------------------------------
-- Some preservation lemmas
-- A map function for ∥_∥¹ᴱ.
∥∥¹ᴱ-map : (A → B) → ∥ A ∥¹ᴱ → ∥ B ∥¹ᴱ
∥∥¹ᴱ-map f = rec λ where
.∣∣ʳ x → ∣ f x ∣
.∣∣-constantʳ x y → ∣∣-constant (f x) (f y)
-- The truncation operator preserves logical equivalences.
∥∥¹ᴱ-cong-⇔ : A ⇔ B → ∥ A ∥¹ᴱ ⇔ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-⇔ A⇔B = record
{ to = ∥∥¹ᴱ-map (_⇔_.to A⇔B)
; from = ∥∥¹ᴱ-map (_⇔_.from A⇔B)
}
private
-- A lemma used below.
@0 ∥∥¹ᴱ-cong-lemma :
(f : A → B) (g : B → A) (eq : ∀ x → f (g x) ≡ x) →
subst (λ z → ∥∥¹ᴱ-map f (∥∥¹ᴱ-map g z) ≡ z)
(∣∣-constant x y) (cong ∣_∣ (eq x)) ≡
cong ∣_∣ (eq y)
∥∥¹ᴱ-cong-lemma {x = x} {y = y} f g eq =
subst
(λ z → ∥∥¹ᴱ-map f (∥∥¹ᴱ-map g z) ≡ z)
(∣∣-constant x y) (cong ∣_∣ (eq x)) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (∥∥¹ᴱ-map f ∘ ∥∥¹ᴱ-map g) (∣∣-constant x y)))
(trans (cong ∣_∣ (eq x)) (cong id (∣∣-constant x y))) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (cong ∣_∣ (eq x)) q))
(trans (sym $ cong-∘ _ _ _) $
trans (cong (cong (∥∥¹ᴱ-map f)) rec-∣∣-constant) $
rec-∣∣-constant)
(sym $ cong-id _) ⟩
trans (sym (∣∣-constant (f (g x)) (f (g y))))
(trans (cong ∣_∣ (eq x)) (∣∣-constant x y)) ≡⟨ cong (λ f → trans _ (trans (cong ∣_∣ (f _)) _)) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) eq ⟩
trans (sym (∣∣-constant (f (g x)) (f (g y))))
(trans (cong ∣_∣ (ext⁻¹ (⟨ext⟩ eq) x)) (∣∣-constant x y)) ≡⟨ elim₁
(λ {f} eq → trans (sym (∣∣-constant (f x) (f y)))
(trans (cong ∣_∣ (ext⁻¹ eq x)) (∣∣-constant x y)) ≡
cong ∣_∣ (ext⁻¹ eq y))
(
trans (sym (∣∣-constant x y))
(trans (cong ∣_∣ (ext⁻¹ (refl id) x)) (∣∣-constant x y)) ≡⟨ cong (trans _) $
trans (cong (flip trans _) $
trans (cong (cong _) $ cong-refl _) $
cong-refl _) $
trans-reflˡ _ ⟩
trans (sym (∣∣-constant x y)) (∣∣-constant x y) ≡⟨ trans-symˡ _ ⟩
refl _ ≡⟨ trans (sym $ cong-refl _) $
cong (cong _) $ sym $ cong-refl _ ⟩∎
cong ∣_∣ (ext⁻¹ (refl _) y) ∎)
_ ⟩
cong ∣_∣ (ext⁻¹ (⟨ext⟩ eq) y) ≡⟨ cong (λ f → cong ∣_∣ (f _)) $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) eq ⟩∎
cong ∣_∣ (eq y) ∎
-- The truncation operator preserves split surjections.
∥∥¹ᴱ-cong-↠ : A ↠ B → ∥ A ∥¹ᴱ ↠ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-↠ A↠B = record
{ logical-equivalence = ∥∥¹ᴱ-cong-⇔ (_↠_.logical-equivalence A↠B)
; right-inverse-of = elim λ where
.∣∣ʳ x → cong ∣_∣ (_↠_.right-inverse-of A↠B x)
.∣∣-constantʳ x y →
∥∥¹ᴱ-cong-lemma (_↠_.to A↠B) (_↠_.from A↠B)
(_↠_.right-inverse-of A↠B)
}
-- The truncation operator preserves bijections.
∥∥¹ᴱ-cong-↔ : A ↔ B → ∥ A ∥¹ᴱ ↔ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-↔ A↔B = record
{ surjection = ∥∥¹ᴱ-cong-↠ (_↔_.surjection A↔B)
; left-inverse-of = elim λ where
.∣∣ʳ x → cong ∣_∣ (_↔_.left-inverse-of A↔B x)
.∣∣-constantʳ x y →
∥∥¹ᴱ-cong-lemma (_↔_.from A↔B) (_↔_.to A↔B)
(_↔_.left-inverse-of A↔B)
}
-- The truncation operator preserves equivalences.
∥∥¹ᴱ-cong-≃ : A ≃ B → ∥ A ∥¹ᴱ ≃ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-≃ = from-isomorphism ∘ ∥∥¹ᴱ-cong-↔ ∘ from-isomorphism
-- The truncation operator preserves equivalences with erased proofs.
∥∥¹ᴱ-cong-≃ᴱ : A ≃ᴱ B → ∥ A ∥¹ᴱ ≃ᴱ ∥ B ∥¹ᴱ
∥∥¹ᴱ-cong-≃ᴱ A≃B =
EEq.[≃]→≃ᴱ (EEq.[proofs] (∥∥¹ᴱ-cong-≃ (EEq.≃ᴱ→≃ A≃B)))
------------------------------------------------------------------------
-- Iterated applications of the one-step truncation operator
-- Applies the one-step truncation the given number of times, from the
-- "outside".
--
-- This definition and the next one are taken from van Doorn's
-- "Constructing the Propositional Truncation using Non-recursive
-- HITs".
∥_∥¹ᴱ-out-^ : Type a → ℕ → Type a
∥ A ∥¹ᴱ-out-^ zero = A
∥ A ∥¹ᴱ-out-^ (suc n) = ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ
-- A "constructor" for ∥_∥¹ᴱ-out-^.
∣_∣-out-^ : A → ∀ n → ∥ A ∥¹ᴱ-out-^ n
∣ x ∣-out-^ zero = x
∣ x ∣-out-^ (suc n) = ∣ ∣ x ∣-out-^ n ∣
-- A rearrangement lemma.
∥∥¹ᴱ-out-^+≃ :
∀ m → ∥ A ∥¹ᴱ-out-^ (m + n) ≃ ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ-out-^ m
∥∥¹ᴱ-out-^+≃ zero = F.id
∥∥¹ᴱ-out-^+≃ {A = A} {n = n} (suc m) =
∥ ∥ A ∥¹ᴱ-out-^ (m + n) ∥¹ᴱ ↝⟨ ∥∥¹ᴱ-cong-≃ (∥∥¹ᴱ-out-^+≃ m) ⟩□
∥ ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ-out-^ m ∥¹ᴱ □
-- ∥_∥¹ᴱ commutes with ∥_∥¹ᴱ-out-^ n.
∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute :
∀ n → ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ↔ ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-out-^ n
∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute zero = F.id
∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute {A = A} (suc n) =
∥ ∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ∥¹ᴱ ↝⟨ ∥∥¹ᴱ-cong-↔ (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) ⟩□
∥ ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-out-^ n ∥¹ᴱ □
private
-- The lemma above is defined using _↔_ rather than _≃_ because the
-- following equalities hold by definition when _↔_ is used, but (at
-- the time of writing) the second one does not hold when _≃_ is
-- used.
_ :
{x : A} →
_↔_.left-inverse-of (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute 0) ∣ x ∣ ≡ refl ∣ x ∣
_ = refl _
_ :
{A : Type a} {x : ∥ A ∥¹ᴱ-out-^ (suc n)} →
_↔_.left-inverse-of (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n)) ∣ x ∣ ≡
cong ∣_∣ (_↔_.left-inverse-of (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) x)
_ = refl _
-- A variant of ∥_∥¹ᴱ-out-^ which applies the one-step truncation the
-- given number of times from the "inside".
∥_∥¹ᴱ-in-^ : Type a → ℕ → Type a
∥ A ∥¹ᴱ-in-^ zero = A
∥ A ∥¹ᴱ-in-^ (suc n) = ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n
-- The two variants of ∥_∥¹ᴱ^ are pointwise equivalent.
∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ : ∀ n → ∥ A ∥¹ᴱ-out-^ n ≃ ∥ A ∥¹ᴱ-in-^ n
∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ zero = F.id
∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ {A = A} (suc n) =
∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ↔⟨ ∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n ⟩
∥ ∥ A ∥¹ᴱ ∥¹ᴱ-out-^ n ↝⟨ ∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n ⟩□
∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n □
-- ∥_∥¹ᴱ commutes with ∥_∥¹ᴱ-in-^ n.
∥∥¹ᴱ-∥∥¹ᴱ-in-^-commute : ∀ n → ∥ ∥ A ∥¹ᴱ-in-^ n ∥¹ᴱ ≃ ∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n
∥∥¹ᴱ-∥∥¹ᴱ-in-^-commute {A = A} n =
∥ ∥ A ∥¹ᴱ-in-^ n ∥¹ᴱ ↝⟨ ∥∥¹ᴱ-cong-≃ (inverse $ ∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) ⟩
∥ ∥ A ∥¹ᴱ-out-^ n ∥¹ᴱ ↔⟨⟩
∥ A ∥¹ᴱ-out-^ (suc n) ↝⟨ ∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (suc n) ⟩
∥ A ∥¹ᴱ-in-^ (suc n) ↔⟨⟩
∥ ∥ A ∥¹ᴱ ∥¹ᴱ-in-^ n □
-- A "constructor" for ∥_∥¹ᴱ-in-^.
∣_,_∣-in-^ : ∀ n → ∥ A ∥¹ᴱ-in-^ n → ∥ A ∥¹ᴱ-in-^ (suc n)
∣ zero , x ∣-in-^ = ∣ x ∣
∣ suc n , x ∣-in-^ = ∣ n , x ∣-in-^
-- ∣_,_∣-in-^ is related to ∣_∣.
∣∣≡∣,∣-in-^ :
∀ n {x : ∥ A ∥¹ᴱ-out-^ n} →
_≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (suc n)) ∣ x ∣ ≡
∣ n , _≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) x ∣-in-^
∣∣≡∣,∣-in-^ zero {x = x} = ∣ x ∣ ∎
∣∣≡∣,∣-in-^ (suc n) {x = x} =
_≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (2 + n)) ∣ x ∣ ≡⟨⟩
_≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (1 + n))
∣ _↔_.to (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) x ∣ ≡⟨ ∣∣≡∣,∣-in-^ n ⟩∎
∣ n , _≃_.to (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n)
(_↔_.to (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute n) x) ∣-in-^ ∎
-- A variant of ∣∣≡∣,∣-in-^.
∣,∣-in-^≡∣∣ :
∀ n {x : ∥ A ∥¹ᴱ-in-^ n} →
_≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (suc n)) ∣ n , x ∣-in-^ ≡
∣ _≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) x ∣
∣,∣-in-^≡∣∣ zero {x = x} = ∣ x ∣ ∎
∣,∣-in-^≡∣∣ (suc n) {x = x} =
_≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (2 + n)) ∣ 1 + n , x ∣-in-^ ≡⟨⟩
_↔_.from (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n))
(_≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ (1 + n)) ∣ n , x ∣-in-^) ≡⟨ cong (_↔_.from (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n))) $ ∣,∣-in-^≡∣∣ n ⟩∎
_↔_.from (∥∥¹ᴱ-∥∥¹ᴱ-out-^-commute (1 + n))
∣ _≃_.from (∥∥¹ᴱ-out-^≃∥∥¹ᴱ-in-^ n) x ∣ ∎
| 34.857527
| 138
| 0.440194
|
57364c2817300e3ffc670dc063969ec9a9822ea9
| 10,515
|
agda
|
Agda
|
LibraBFT/Concrete/Properties/VotesOnce.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/Properties/VotesOnce.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Concrete/Properties/VotesOnce.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"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 Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Consensus.Types hiding (EpochConfigFor)
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Handle sha256 sha256-cr
open import LibraBFT.Concrete.System.Parameters
open EpochConfig
open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK
-- In this module, we define two "implementation obligations"
-- (ImplObligationᵢ for i ∈ {1 , 2}), which are predicates over
-- reachable states of a system defined by
-- 'LibraBFT.Concrete.System.Parameters'. These two properties relate
-- votes sent by the same sender, ensuring that if they are for the
-- same epoch and round, then they vote for the same blockID; the
-- first relates a vote output by the handler to a vote sent
-- previously, and the second relates two votes both sent by the
-- handler.
--
-- We then prove that, if an implementation satisfies these two
-- semantic obligations, along with a structural one about messages
-- sent by honest peers in the implementation, then the implemenation
-- satisfies the LibraBFT.Abstract.Properties.VotesOnce invariant.
module LibraBFT.Concrete.Properties.VotesOnce where
-- TODO-3: This may not be the best way to state the implementation obligation. Why not reduce
-- this as much as possible before giving the obligation to the implementation? For example, this
-- will still require the implementation to deal with hash collisons (v and v' could be different,
-- but yield the same bytestring and therefore same signature). Also, avoid the need for the
-- implementation to reason about messages sent by step-cheat, or give it something to make this
-- case easy to eliminate.
ImplObligation₁ : Set₁
ImplObligation₁ =
∀{e pid pid' inits' s' outs pk}{pre : SystemState e}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ StepPeerState pid (availEpochs pre) (msgPool pre) (initialised pre) (peerStates pre pid) inits' (s' , outs)
→ ∀{v m v' m'} → Meta-Honest-PK pk
-- For signed every vote v of every outputted message
→ v ⊂Msg m → m ∈ outs → (sig : WithVerSig pk v)
-- If v is really new and valid
-- Note that this does not directly exclude possibility of previous message with
-- same signature, but sent by someone else. We could prove it implies it though.
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → ValidSenderForPK (availEpochs pre) v pid pk
-- And if there exists another v' that has been sent before
→ v' ⊂Msg m' → (pid' , m') ∈ (msgPool pre) → WithVerSig pk v'
-- If v and v' share the same epoch and round
→ (v ^∙ vEpoch) ≡ (v' ^∙ vEpoch)
→ (v ^∙ vProposed ∙ biRound) ≡ (v' ^∙ vProposed ∙ biRound)
----------------------------------------------------------
-- Then an honest implemenation promises v and v' vote for the same blockId.
→ (v ^∙ vProposed ∙ biId) ≡ (v' ^∙ vProposed ∙ biId)
ImplObligation₂ : Set₁
ImplObligation₂ =
∀{e pid inits' s' outs pk}{pre : SystemState e}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ StepPeerState pid (availEpochs pre) (msgPool pre) (initialised pre) (peerStates pre pid) inits' (s' , outs)
→ ∀{v m v' m'} → Meta-Honest-PK pk
-- For every vote v represented in a message output by the call
→ v ⊂Msg m → m ∈ outs → (sig : WithVerSig pk v)
-- If v is really new and valid
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre)) → ValidSenderForPK (availEpochs pre) v pid pk
-- And if there exists another v' that is also new and valid
→ v' ⊂Msg m' → m' ∈ outs → (sig' : WithVerSig pk v')
→ ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre)) → ValidSenderForPK (availEpochs pre) v' pid pk
-- If v and v' share the same epoch and round
→ (v ^∙ vEpoch) ≡ (v' ^∙ vEpoch)
→ (v ^∙ vProposed ∙ biRound) ≡ (v' ^∙ vProposed ∙ biRound)
----------------------------------------------------------
-- Then, an honest implemenation promises v and v' vote for the same blockId.
→ (v ^∙ vProposed ∙ biId) ≡ (v' ^∙ vProposed ∙ biId)
-- Next, we prove that, given the necessary obligations,
module Proof
(sps-corr : StepPeerState-AllValidParts)
(Impl-VO1 : ImplObligation₁)
(Impl-VO2 : ImplObligation₂)
where
-- Any reachable state satisfies the VO rule for any epoch in the system.
module _ {e}(st : SystemState e)(r : ReachableSystemState st)(eid : Fin e) where
open Structural sps-corr
-- Bring in IntSystemState
open import LibraBFT.Concrete.System sps-corr
open PerState st r
open PerEpoch eid
open import LibraBFT.Concrete.Obligations.VotesOnce 𝓔 (ConcreteVoteEvidence 𝓔) as VO
-- The VO proof is done by induction on the execution trace leading to 'st'. In
-- Agda, this is 'r : RechableSystemState st' above.
private
-- From this point onwards, it might be easier to read this proof starting at 'voo'
-- at the end of the file. Next, we provide an overview the proof.
--
-- We wish to prove that, for any two votes v and v' cast by an honest α in the message
-- pool of a state st, if v and v' have equal rounds and epochs, then they vote for the
-- same block.
--
-- The base case and the case for a new epoch in the system are trivial. For the base case
-- we get to a contradiction because it's not possible to have any message in the msgpool.
--
-- Regarding the PeerStep case. The induction hypothesis tells us that the property holds
-- in the pre-state. Next, we reason about the post-state. We start by analyzing whether
-- v and v' have been sent as outputs of the PeerStep under scrutiny or were already in
-- the pool before.
--
-- There are four possibilities:
--
-- i) v and v' were aleady present in the msgPool before: use induction hypothesis.
-- ii) v and v' are both in the output produced by the PeerStep under scrutiny.
-- iii) v was present before, but v' is new.
-- iv) v' was present before, but v is new.
--
-- In order to obtain this four possiblities we invoke newMsg⊎msgSent4 lemma, which
-- receives proof that some vote is in a message that is in the msgPool of the post state
-- and returns evidence that either the vote is new or that some message with the same
-- signature was sent before.
--
-- Case (i) is trivial; cases (iii) and (iv) are symmetric and reduce to an implementation
-- obligation (Impl-VO1) and case (ii) reduces to a different implementation obligation
-- (Impl-VO2).
VotesOnceProof :
∀ {v v' e pk} {st : SystemState e}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (vv : WithVerSig pk v) → MsgWithSig∈ pk (ver-signature vv) (msgPool st)
→ (vv' : WithVerSig pk v') → MsgWithSig∈ pk (ver-signature vv') (msgPool st)
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound ≡ v' ^∙ vRound
→ v ^∙ vProposedId ≡ v' ^∙ vProposedId
VotesOnceProof step-0 _ _ msv _ _ _ _ = ⊥-elim (¬Any[] (msg∈pool msv))
VotesOnceProof (step-s r (step-epoch _)) pkH vv msv vv' msv' ep≡ r≡
= VotesOnceProof r pkH vv msv vv' msv' ep≡ r≡
VotesOnceProof (step-s r (step-peer cheat@(step-cheat f c))) pkH vv msv vv' msv' ep≡ r≡
with ¬cheatForgeNew cheat refl unit pkH msv | ¬cheatForgeNew cheat refl unit pkH msv'
...| msb4 | m'sb4
with msgSameSig msb4 | msgSameSig m'sb4
...| refl | refl = VotesOnceProof r pkH vv msb4 vv' m'sb4 ep≡ r≡
VotesOnceProof (step-s r (step-peer stHon@(step-honest stPeer))) pkH vv msv vv' msv' ep≡ r≡
with msgSameSig msv | msgSameSig msv'
...| refl | refl
with sameHonestSig⇒sameVoteData pkH (msgSigned msv) vv (msgSameSig msv)
| sameHonestSig⇒sameVoteData pkH (msgSigned msv') vv' (msgSameSig msv')
...| inj₁ hb | _ = ⊥-elim (meta-sha256-cr hb)
...| inj₂ refl | inj₁ hb = ⊥-elim (meta-sha256-cr hb)
...| inj₂ refl | inj₂ refl
with newMsg⊎msgSentB4 r stHon pkH (msgSigned msv) (msg⊆ msv) (msg∈pool msv)
| newMsg⊎msgSentB4 r stHon pkH (msgSigned msv') (msg⊆ msv') (msg∈pool msv')
...| inj₂ msb4 | inj₂ m'sb4
= VotesOnceProof r pkH vv msb4 vv' m'sb4 ep≡ r≡
...| inj₁ (m∈outs , vspk , newV) | inj₁ (m'∈outs , v'spk , newV')
= Impl-VO2 r stPeer pkH (msg⊆ msv) m∈outs (msgSigned msv) newV vspk
(msg⊆ msv') m'∈outs (msgSigned msv') newV' v'spk ep≡ r≡
...| inj₁ (m∈outs , vspk , newV) | inj₂ m'sb4
with sameHonestSig⇒sameVoteData pkH (msgSigned m'sb4) vv' (msgSameSig m'sb4)
...| inj₁ hb = ⊥-elim (meta-sha256-cr hb)
...| inj₂ refl
= Impl-VO1 r stPeer pkH (msg⊆ msv) m∈outs (msgSigned msv) newV vspk
(msg⊆ m'sb4) (msg∈pool m'sb4) (msgSigned m'sb4) ep≡ r≡
VotesOnceProof (step-s r (step-peer (step-honest stPeer))) pkH vv msv vv' msv' ep≡ r≡
| refl | refl
| inj₂ refl | inj₂ refl
| inj₂ msb4 | inj₁ (m'∈outs , v'spk , newV')
with sameHonestSig⇒sameVoteData pkH (msgSigned msb4) vv (msgSameSig msb4)
...| inj₁ hb = ⊥-elim (meta-sha256-cr hb)
...| inj₂ refl
= sym (Impl-VO1 r stPeer pkH (msg⊆ msv') m'∈outs (msgSigned msv') newV' v'spk
(msg⊆ msb4) (msg∈pool msb4) (msgSigned msb4) (sym ep≡) (sym r≡))
voo : VO.Type IntSystemState
voo hpk refl sv refl sv' round≡
with vmsg≈v (vmFor sv) | vmsg≈v (vmFor sv')
...| refl | refl
= let ver = vmsgSigned (vmFor sv)
mswsv = mkMsgWithSig∈ (nm (vmFor sv)) (cv (vmFor sv)) (cv∈nm (vmFor sv))
_ (nmSentByAuth sv) (vmsgSigned (vmFor sv)) refl
ver' = vmsgSigned (vmFor sv')
mswsv' = mkMsgWithSig∈ (nm (vmFor sv')) (cv (vmFor sv')) (cv∈nm (vmFor sv'))
_ (nmSentByAuth sv') (vmsgSigned (vmFor sv')) refl
epoch≡ = trans (vmsgEpoch (vmFor sv)) (sym (vmsgEpoch (vmFor sv')))
in VotesOnceProof r hpk ver mswsv ver' mswsv' epoch≡ round≡
| 51.292683
| 112
| 0.649643
|
389b5a6477932b1b0ce1262a2b5ae1683debd6de
| 955
|
agda
|
Agda
|
test/interaction/Multisplit.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/interaction/Multisplit.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/interaction/Multisplit.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.lhs.unify.flexflex:100 -v tc.lhs.unify.assign:100 -v tc.lhs:100 #-}
module Multisplit where
data Bool : Set where
true false : Bool
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
data Fin : ℕ → Set where
zero : ∀ {n} → Fin (suc n)
suc : ∀ {n} → Fin n → Fin (suc n)
data Vec {a} (A : Set a) : ℕ → Set a where
[] : Vec A zero
_∷_ : ∀ {n} (x : A) → Vec A n → Vec A (suc n)
data Fin∘suc : ℕ → Set where
zero : ∀ {n} → Fin∘suc n
suc : ∀ {n} → Fin∘suc n → Fin∘suc (suc n)
_==_ : Bool → Bool → Bool
b₁ == b₂ = {!b₁ b₂!}
lookup : ∀ {a n} {A : Set a} → Vec A n → Fin n → A
lookup xs i = {!xs i!}
32-cases : Bool → Bool → Bool → Bool → Bool → Bool
32-cases a b c d e = {!a b c d e!}
No-splits-after-absurd-pattern-encountered :
(n : ℕ) → Fin n → Fin n → Set
No-splits-after-absurd-pattern-encountered n i j = {!n i j!}
Dotted-patterns-are-not-split : ∀ n → Fin∘suc n → Set
Dotted-patterns-are-not-split n i = {!i n!}
| 25.131579
| 88
| 0.563351
|
dfb56e6feb00feb0467bbae1fe9a9bc5ce11596e
| 4,303
|
agda
|
Agda
|
binders-disjoint-checks.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 16
|
2018-03-12T14:32:03.000Z
|
2021-12-19T02:50:23.000Z
|
binders-disjoint-checks.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 54
|
2017-06-29T20:53:34.000Z
|
2018-11-29T16:32:40.000Z
|
binders-disjoint-checks.agda
|
hazelgrove/hazelnut-dynamics-agda
|
229dfb06ea51ebe91cb3b1c973c2f2792e66797c
|
[
"MIT"
] | 1
|
2019-09-13T18:20:02.000Z
|
2019-09-13T18:20:02.000Z
|
open import Prelude
open import Nat
open import core
module binders-disjoint-checks where
-- these are fairly mechanical lemmas that show that the
-- judgementally-defined binders-disjoint is really a type-directed
-- function
mutual
lem-bdσ-lam : ∀{σ x τ d} → binders-disjoint-σ σ (·λ_[_]_ x τ d) → binders-disjoint-σ σ d
lem-bdσ-lam BDσId = BDσId
lem-bdσ-lam (BDσSubst x₁ bd) = BDσSubst (lem-bd-lam x₁) (lem-bdσ-lam bd)
lem-bd-lam : ∀{ d1 x τ1 d} → binders-disjoint d1 (·λ_[_]_ x τ1 d) → binders-disjoint d1 d
lem-bd-lam BDConst = BDConst
lem-bd-lam BDVar = BDVar
lem-bd-lam (BDLam bd (UBLam2 x₂ x₃)) = BDLam (lem-bd-lam bd) x₃
lem-bd-lam (BDHole x₁) = BDHole (lem-bdσ-lam x₁)
lem-bd-lam (BDNEHole x₁ bd) = BDNEHole (lem-bdσ-lam x₁) (lem-bd-lam bd)
lem-bd-lam (BDAp bd bd₁) = BDAp (lem-bd-lam bd) (lem-bd-lam bd₁)
lem-bd-lam (BDCast bd) = BDCast (lem-bd-lam bd)
lem-bd-lam (BDFailedCast bd) = BDFailedCast (lem-bd-lam bd)
mutual
lem-bdσ-hole : ∀{d u σ σ'} → binders-disjoint-σ σ ⦇⌜ d ⌟⦈⟨ u , σ' ⟩ → binders-disjoint-σ σ d
lem-bdσ-hole BDσId = BDσId
lem-bdσ-hole (BDσSubst x bd) = BDσSubst (lem-bd-hole x) (lem-bdσ-hole bd)
lem-bd-hole : ∀{d1 d u σ} → binders-disjoint d1 ⦇⌜ d ⌟⦈⟨ u , σ ⟩ → binders-disjoint d1 d
lem-bd-hole BDConst = BDConst
lem-bd-hole BDVar = BDVar
lem-bd-hole (BDLam bd (UBNEHole x₁ x₂)) = BDLam (lem-bd-hole bd) x₂
lem-bd-hole (BDHole x) = BDHole (lem-bdσ-hole x)
lem-bd-hole (BDNEHole x bd) = BDNEHole (lem-bdσ-hole x) (lem-bd-hole bd)
lem-bd-hole (BDAp bd bd₁) = BDAp (lem-bd-hole bd) (lem-bd-hole bd₁)
lem-bd-hole (BDCast bd) = BDCast (lem-bd-hole bd)
lem-bd-hole (BDFailedCast bd) = BDFailedCast (lem-bd-hole bd)
mutual
lem-bdσ-cast : ∀{σ d τ1 τ2} → binders-disjoint-σ σ (d ⟨ τ1 ⇒ τ2 ⟩) → binders-disjoint-σ σ d
lem-bdσ-cast BDσId = BDσId
lem-bdσ-cast (BDσSubst x bd) = BDσSubst (lem-bd-cast x) (lem-bdσ-cast bd)
lem-bd-cast : ∀{d1 d τ1 τ2} → binders-disjoint d1 (d ⟨ τ1 ⇒ τ2 ⟩) → binders-disjoint d1 d
lem-bd-cast BDConst = BDConst
lem-bd-cast BDVar = BDVar
lem-bd-cast (BDLam bd (UBCast x₁)) = BDLam (lem-bd-cast bd) x₁
lem-bd-cast (BDHole x) = BDHole (lem-bdσ-cast x)
lem-bd-cast (BDNEHole x bd) = BDNEHole (lem-bdσ-cast x) (lem-bd-cast bd)
lem-bd-cast (BDAp bd bd₁) = BDAp (lem-bd-cast bd) (lem-bd-cast bd₁)
lem-bd-cast (BDCast bd) = BDCast (lem-bd-cast bd)
lem-bd-cast (BDFailedCast bd) = BDFailedCast (lem-bd-cast bd)
mutual
lem-bdσ-failedcast : ∀{σ d τ1 τ2} → binders-disjoint-σ σ (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) → binders-disjoint-σ σ d
lem-bdσ-failedcast BDσId = BDσId
lem-bdσ-failedcast (BDσSubst x bd) = BDσSubst (lem-bd-failedcast x) (lem-bdσ-failedcast bd)
lem-bd-failedcast : ∀{d1 d τ1 τ2} → binders-disjoint d1 (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) → binders-disjoint d1 d
lem-bd-failedcast BDConst = BDConst
lem-bd-failedcast BDVar = BDVar
lem-bd-failedcast (BDLam bd (UBFailedCast x₁)) = BDLam (lem-bd-failedcast bd) x₁
lem-bd-failedcast (BDHole x) = BDHole (lem-bdσ-failedcast x)
lem-bd-failedcast (BDNEHole x bd) = BDNEHole (lem-bdσ-failedcast x) (lem-bd-failedcast bd)
lem-bd-failedcast (BDAp bd bd₁) = BDAp (lem-bd-failedcast bd) (lem-bd-failedcast bd₁)
lem-bd-failedcast (BDCast bd) = BDCast (lem-bd-failedcast bd)
lem-bd-failedcast (BDFailedCast bd) = BDFailedCast (lem-bd-failedcast bd)
mutual
lem-bdσ-into-cast : ∀{σ d τ1 τ2} → binders-disjoint-σ σ d → binders-disjoint-σ σ (d ⟨ τ1 ⇒ τ2 ⟩)
lem-bdσ-into-cast BDσId = BDσId
lem-bdσ-into-cast (BDσSubst x bd) = BDσSubst (lem-bd-into-cast x) (lem-bdσ-into-cast bd)
lem-bd-into-cast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint d1 (d2 ⟨ τ1 ⇒ τ2 ⟩)
lem-bd-into-cast BDConst = BDConst
lem-bd-into-cast BDVar = BDVar
lem-bd-into-cast (BDLam bd x₁) = BDLam (lem-bd-into-cast bd) (UBCast x₁)
lem-bd-into-cast (BDHole x) = BDHole (lem-bdσ-into-cast x)
lem-bd-into-cast (BDNEHole x bd) = BDNEHole (lem-bdσ-into-cast x) (lem-bd-into-cast bd)
lem-bd-into-cast (BDAp bd bd₁) = BDAp (lem-bd-into-cast bd) (lem-bd-into-cast bd₁)
lem-bd-into-cast (BDCast bd) = BDCast (lem-bd-into-cast bd)
lem-bd-into-cast (BDFailedCast bd) = BDFailedCast (lem-bd-into-cast bd)
| 51.22619
| 106
| 0.651406
|
10879694451a6db2c196e0f88d4e068fe2826b14
| 939
|
agda
|
Agda
|
BasicIS4/Metatheory/DyadicGentzen-BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
BasicIS4/Metatheory/DyadicGentzen-BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
BasicIS4/Metatheory/DyadicGentzen-BasicKripkeOno.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
module BasicIS4.Metatheory.DyadicGentzen-BasicKripkeOno where
open import BasicIS4.Syntax.DyadicGentzen public
open import BasicIS4.Semantics.BasicKripkeOno public hiding (_⊨_) -- TODO
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊨ A
eval (var i) γ δ = lookup i γ
eval (lam t) γ δ = λ ξ a → eval t (mono⊩⋆ ξ γ , a) (λ ζ →
δ (transR (≤→R ξ) ζ))
eval (app {A} {B} t u) γ δ = _⟪$⟫_ {A} {B} (eval t γ δ) (eval u γ δ)
eval (mvar i) γ δ = lookup i (δ reflR)
eval (box t) γ δ = λ ζ → eval t ∙ (λ ζ′ → δ (transR ζ ζ′))
eval (unbox t u) γ δ = eval u γ (λ ζ → δ ζ , (eval t γ δ) ζ)
eval (pair t u) γ δ = eval t γ δ , eval u γ δ
eval (fst t) γ δ = π₁ (eval t γ δ)
eval (snd t) γ δ = π₂ (eval t γ δ)
eval unit γ δ = ∙
-- TODO: Correctness of evaluation with respect to conversion.
| 39.125
| 73
| 0.539936
|
a0ba97aa6fb59304f4ef6ca45b36b8d28542ff47
| 7,833
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/RawAlgebra.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/RawAlgebra.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/RingSolver/RawAlgebra.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.RawAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Int renaming (_+_ to _+ℤ_ ; _·_ to _·ℤ_ ; -_ to -ℤ_ ; _-_ to _-ℤ_ ; +Assoc to +ℤAssoc ; +Comm to +ℤComm ; -DistL· to -ℤDistL·ℤ)
open import Cubical.Algebra.RingSolver.RawRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
open import Cubical.Algebra.RingSolver.IntAsRawRing
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Ring
private
variable
ℓ ℓ′ : Level
record RawAlgebra (R : RawRing ℓ) (ℓ′ : Level) : Type (ℓ-suc (ℓ-max ℓ ℓ′)) where
constructor rawalgebra
field
Carrier : Type ℓ′
scalar : ⟨ R ⟩ᵣ → Carrier
0r : Carrier
1r : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
infixl 8 _·_
infixl 7 -_
infixl 6 _+_
⟨_⟩ : {R : RawRing ℓ} → RawAlgebra R ℓ′ → Type ℓ′
⟨_⟩ = RawAlgebra.Carrier
{-
Mapping to integer scalars and its (homorphism) properties.
-}
module _ (R : CommRing ℓ) where
open CommRingStr (snd R)
open Cubical.Algebra.Ring.RingTheory (CommRing→Ring R)
scalarℕ : ℕ → (fst R)
scalarℕ ℕ.zero = 0r
scalarℕ (ℕ.suc ℕ.zero) = 1r
scalarℕ (ℕ.suc (ℕ.suc n)) = 1r + scalarℕ (ℕ.suc n)
scalar : ℤ → (fst R)
scalar (pos k) = scalarℕ k
scalar (negsuc k) = - scalarℕ (ℕ.suc k)
-DistScalar : (k : ℤ)
→ scalar (-ℤ k) ≡ - (scalar k)
-DistScalar (pos ℕ.zero) = sym 0Selfinverse
-DistScalar (pos (ℕ.suc n)) = refl
-DistScalar (negsuc n) = sym (-Idempotent _)
lemmaSuc : (k : ℤ)
→ scalar (sucℤ k) ≡ 1r + scalar k
lemmaSuc (pos ℕ.zero) = sym (+Rid _)
lemmaSuc (pos (ℕ.suc ℕ.zero)) = refl
lemmaSuc (pos (ℕ.suc (ℕ.suc n))) = refl
lemmaSuc (negsuc ℕ.zero) = sym (+Rinv _)
lemmaSuc (negsuc (ℕ.suc n)) =
scalar (negsuc n) ≡⟨ sym (+Lid (scalar (negsuc n))) ⟩
0r + scalar (negsuc n) ≡[ i ]⟨ +Rinv 1r (~ i) + scalar (negsuc n) ⟩
(1r - 1r) + scalar (negsuc n) ≡⟨ sym (+Assoc _ _ _) ⟩
1r + (- 1r + - scalar (pos (ℕ.suc n))) ≡[ i ]⟨ 1r + -Dist 1r (scalar (pos (ℕ.suc n))) i ⟩
1r + -(1r + scalar (pos (ℕ.suc n))) ≡⟨ refl ⟩
1r + -(scalar (pos (ℕ.suc (ℕ.suc n)))) ≡⟨ refl ⟩
1r + scalar (negsuc (ℕ.suc n)) ∎
lemmaPred : (k : ℤ)
→ scalar (predℤ k) ≡ - 1r + scalar k
lemmaPred k = sym(
- 1r + scalar k ≡[ i ]⟨ - 1r + scalar (sucPred k (~ i)) ⟩
- 1r + scalar (sucℤ (predℤ k)) ≡[ i ]⟨ - 1r + lemmaSuc (predℤ k) i ⟩
- 1r + (1r + scalar (predℤ k)) ≡⟨ +Assoc _ _ _ ⟩
(- 1r + 1r) + scalar (predℤ k) ≡[ i ]⟨ +Linv 1r i + scalar (predℤ k) ⟩
0r + scalar (predℤ k) ≡⟨ +Lid _ ⟩
scalar (predℤ k) ∎)
+HomScalar : (k l : ℤ)
→ scalar (k +ℤ l) ≡ (scalar k) + (scalar l)
+HomScalar (pos ℕ.zero) l =
scalar (0 +ℤ l) ≡[ i ]⟨ scalar (sym (pos0+ l) i) ⟩
scalar l ≡⟨ sym (+Lid _) ⟩
0r + scalar l ≡⟨ refl ⟩
scalar 0 + scalar l ∎
+HomScalar (pos (ℕ.suc ℕ.zero)) l =
scalar (1 +ℤ l) ≡[ i ]⟨ scalar (+ℤComm 1 l i) ⟩
scalar (l +ℤ 1) ≡⟨ refl ⟩
scalar (sucℤ l) ≡⟨ lemmaSuc l ⟩
1r + scalar l ≡⟨ refl ⟩
scalar (pos (ℕ.suc ℕ.zero)) + scalar l ∎
+HomScalar (pos (ℕ.suc (ℕ.suc n))) l =
scalar (pos (ℕ.suc (ℕ.suc n)) +ℤ l) ≡⟨ refl ⟩
scalar ((pos (ℕ.suc n) +ℤ 1) +ℤ l) ≡[ i ]⟨ scalar ((+ℤComm (pos (ℕ.suc n)) 1 i) +ℤ l) ⟩
scalar ((1 +ℤ (pos (ℕ.suc n))) +ℤ l) ≡[ i ]⟨ scalar (+ℤAssoc 1 (pos (ℕ.suc n)) l (~ i)) ⟩
scalar (1 +ℤ (pos (ℕ.suc n) +ℤ l)) ≡⟨ +HomScalar (pos (ℕ.suc ℕ.zero)) (pos (ℕ.suc n) +ℤ l) ⟩
scalar 1 + scalar (pos (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩
1r + (scalar (pos (ℕ.suc n) +ℤ l)) ≡[ i ]⟨ 1r + +HomScalar (pos (ℕ.suc n)) l i ⟩
1r + (scalar (pos (ℕ.suc n)) + scalar l) ≡⟨ +Assoc _ _ _ ⟩
(1r + scalar (pos (ℕ.suc n))) + scalar l ≡⟨ refl ⟩
scalar (pos (ℕ.suc (ℕ.suc n))) + scalar l ∎
+HomScalar (negsuc ℕ.zero) l =
scalar (-1 +ℤ l) ≡[ i ]⟨ scalar (+ℤComm -1 l i) ⟩
scalar (l +ℤ -1) ≡⟨ refl ⟩
scalar (predℤ l) ≡⟨ lemmaPred l ⟩
- 1r + scalar l ≡⟨ refl ⟩
scalar -1 + scalar l ∎
+HomScalar (negsuc (ℕ.suc n)) l =
scalar (negsuc (ℕ.suc n) +ℤ l) ≡⟨ refl ⟩
scalar ((negsuc n +ℤ -1) +ℤ l) ≡[ i ]⟨ scalar (+ℤComm (negsuc n) -1 i +ℤ l) ⟩
scalar ((-1 +ℤ negsuc n) +ℤ l) ≡[ i ]⟨ scalar (+ℤAssoc -1 (negsuc n) l (~ i)) ⟩
scalar (-1 +ℤ (negsuc n +ℤ l)) ≡⟨ +HomScalar -1 (negsuc n +ℤ l) ⟩
- 1r + scalar (negsuc n +ℤ l) ≡[ i ]⟨ - 1r + +HomScalar (negsuc n) l i ⟩
- 1r + (scalar (negsuc n) + scalar l) ≡⟨ +Assoc (- 1r) _ _ ⟩
(- 1r + (scalar (negsuc n))) + scalar l ≡⟨ refl ⟩
(- 1r + - scalar (pos (ℕ.suc n))) + scalar l ≡[ i ]⟨ -Dist 1r (scalar (pos (ℕ.suc n))) i + scalar l ⟩
(- (1r + scalar (pos (ℕ.suc n)))) + scalar l ≡⟨ refl ⟩
scalar (negsuc (ℕ.suc n)) + scalar l ∎
lemma1 : (n : ℕ)
→ 1r + scalar (pos n) ≡ scalar (pos (ℕ.suc n))
lemma1 ℕ.zero = +Rid _
lemma1 (ℕ.suc k) = refl
lemma-1 : (n : ℕ)
→ - 1r + scalar (negsuc n) ≡ scalar (negsuc (ℕ.suc n))
lemma-1 ℕ.zero = -Dist _ _
lemma-1 (ℕ.suc k) =
- 1r + scalar (negsuc (ℕ.suc k)) ≡⟨ refl ⟩
- 1r + - scalar (pos (ℕ.suc (ℕ.suc k))) ≡⟨ -Dist _ _ ⟩
- (1r + scalar (pos (ℕ.suc (ℕ.suc k)))) ≡⟨ refl ⟩
scalar (negsuc (ℕ.suc (ℕ.suc k))) ∎
·HomScalar : (k l : ℤ)
→ scalar (k ·ℤ l) ≡ scalar k · scalar l
·HomScalar (pos ℕ.zero) l = 0r ≡⟨ sym (0LeftAnnihilates (scalar l)) ⟩ 0r · scalar l ∎
·HomScalar (pos (ℕ.suc n)) l =
scalar (l +ℤ (pos n ·ℤ l)) ≡⟨ +HomScalar l (pos n ·ℤ l) ⟩
scalar l + scalar (pos n ·ℤ l) ≡[ i ]⟨ scalar l + ·HomScalar (pos n) l i ⟩
scalar l + (scalar (pos n) · scalar l) ≡[ i ]⟨ ·Lid (scalar l) (~ i) + (scalar (pos n) · scalar l) ⟩
1r · scalar l + (scalar (pos n) · scalar l) ≡⟨ sym (·Ldist+ 1r _ _) ⟩
(1r + scalar (pos n)) · scalar l ≡[ i ]⟨ lemma1 n i · scalar l ⟩
scalar (pos (ℕ.suc n)) · scalar l ∎
·HomScalar (negsuc ℕ.zero) l =
scalar (-ℤ l) ≡⟨ -DistScalar l ⟩
- scalar l ≡[ i ]⟨ - (·Lid (scalar l) (~ i)) ⟩
- (1r · scalar l) ≡⟨ sym (-DistL· _ _) ⟩
- 1r · scalar l ≡⟨ refl ⟩
scalar (negsuc ℕ.zero) · scalar l ∎
·HomScalar (negsuc (ℕ.suc n)) l =
scalar ((-ℤ l) +ℤ (negsuc n ·ℤ l)) ≡⟨ +HomScalar (-ℤ l) (negsuc n ·ℤ l) ⟩
scalar (-ℤ l) + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ -DistScalar l i + scalar (negsuc n ·ℤ l) ⟩
- scalar l + scalar (negsuc n ·ℤ l) ≡[ i ]⟨ - scalar l + ·HomScalar (negsuc n) l i ⟩
- scalar l + scalar (negsuc n) · scalar l ≡[ i ]⟨ (- ·Lid (scalar l) (~ i))
+ scalar (negsuc n) · scalar l ⟩
- (1r · scalar l) + scalar (negsuc n) · scalar l ≡[ i ]⟨ -DistL· 1r (scalar l) (~ i)
+ scalar (negsuc n) · scalar l ⟩
- 1r · scalar l + scalar (negsuc n) · scalar l ≡⟨ sym (·Ldist+ _ _ _) ⟩
(- 1r + scalar (negsuc n)) · scalar l ≡[ i ]⟨ lemma-1 n i · scalar l ⟩
scalar (negsuc (ℕ.suc n)) · scalar l ∎
CommRing→RawℤAlgebra : CommRing ℓ → RawAlgebra ℤAsRawRing ℓ
CommRing→RawℤAlgebra (R , commringstr 0r 1r _+_ _·_ -_ isCommRing) =
rawalgebra R (scalar ((R , commringstr 0r 1r _+_ _·_ -_ isCommRing))) 0r 1r _+_ _·_ -_
| 44.254237
| 152
| 0.486914
|
8bb81ec3ecebf8f700ef721dcfd188c669016e35
| 15,455
|
agda
|
Agda
|
Cubical/Categories/Instances/CommAlgebras.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/CommAlgebras.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/CommAlgebras.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Categories.Instances.CommAlgebras where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.HLevels
open import Cubical.Data.Unit
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.Instances.Unit
open import Cubical.Categories.Category
open import Cubical.Categories.Functor.Base
open import Cubical.Categories.Limits.Terminal
open import Cubical.Categories.Limits.Pullback
open import Cubical.Categories.Instances.CommRings
open import Cubical.HITs.PropositionalTruncation
open Category hiding (_∘_) renaming (_⋆_ to _⋆c_)
open CommAlgebraHoms
open Cospan
open Pullback
private
variable
ℓ ℓ' ℓ'' : Level
module _ (R : CommRing ℓ) where
CommAlgebrasCategory : Category (ℓ-suc (ℓ-max ℓ ℓ')) (ℓ-max ℓ ℓ')
ob CommAlgebrasCategory = CommAlgebra R _
Hom[_,_] CommAlgebrasCategory = CommAlgebraHom
id CommAlgebrasCategory {A} = idCommAlgebraHom A
_⋆c_ CommAlgebrasCategory {A} {B} {C} = compCommAlgebraHom A B C
⋆IdL CommAlgebrasCategory {A} {B} = compIdCommAlgebraHom {A = A} {B}
⋆IdR CommAlgebrasCategory {A} {B} = idCompCommAlgebraHom {A = A} {B}
⋆Assoc CommAlgebrasCategory {A} {B} {C} {D} = compAssocCommAlgebraHom {A = A} {B} {C} {D}
isSetHom CommAlgebrasCategory = isSetAlgebraHom _ _
TerminalCommAlgebra : Terminal (CommAlgebrasCategory {ℓ' = ℓ'})
fst TerminalCommAlgebra = UnitCommAlgebra R
fst (fst (snd TerminalCommAlgebra A)) = λ _ → tt*
snd (fst (snd TerminalCommAlgebra A)) = makeIsAlgebraHom
refl (λ _ _ → refl) (λ _ _ → refl) (λ _ _ → refl)
snd (snd TerminalCommAlgebra A) f = AlgebraHom≡ (funExt (λ _ → refl))
module PullbackFromCommRing (R : CommRing ℓ)
(commRingCospan : Cospan (CommRingsCategory {ℓ = ℓ}))
(commRingPB : Pullback _ commRingCospan)
(f₁ : CommRingHom R (commRingPB .pbOb))
(f₂ : CommRingHom R (commRingCospan .r))
(f₃ : CommRingHom R (commRingCospan .l))
(f₄ : CommRingHom R (commRingCospan .m))
where
open AlgebraHoms
open CommAlgChar R
open CommAlgebraStr ⦃...⦄
private
CommAlgCat = CommAlgebrasCategory {ℓ = ℓ} R {ℓ' = ℓ}
A = commRingPB .pbOb
B = commRingCospan .r
C = commRingCospan .l
D = commRingCospan .m
g₁ = commRingPB .pbPr₂
g₂ = commRingPB .pbPr₁
g₃ = commRingCospan .s₂
g₄ = commRingCospan .s₁
{-
g₁
A → B
⌟
g₂ ↓ ↓ g₃
C → D
g₄
-}
open RingHoms
univPropCommRingWithHomHom : (isRHom₁ : isCommRingWithHomHom (A , f₁) (B , f₂) g₁)
(isRHom₂ : isCommRingWithHomHom (A , f₁) (C , f₃) g₂)
(isRHom₃ : isCommRingWithHomHom (B , f₂) (D , f₄) g₃)
(isRHom₄ : isCommRingWithHomHom (C , f₃) (D , f₄) g₄)
(E,f₅ : CommRingWithHom)
(h₂ : CommRingWithHomHom E,f₅ (C , f₃))
(h₁ : CommRingWithHomHom E,f₅ (B , f₂))
→ g₄ ∘r fst h₂ ≡ g₃ ∘r fst h₁
→ ∃![ h₃ ∈ CommRingWithHomHom E,f₅ (A , f₁) ]
(fst h₂ ≡ g₂ ∘r fst h₃) × (fst h₁ ≡ g₁ ∘r fst h₃)
univPropCommRingWithHomHom isRHom₁ isRHom₂ isRHom₃ isRHom₄
(E , f₅) (h₂ , comm₂) (h₁ , comm₁) squareComm =
((h₃ , h₃∘f₅≡f₁) , h₂≡g₂∘h₃ , h₁≡g₁∘h₃)
, λ h₃' → Σ≡Prop (λ _ → isProp× (isSetRingHom _ _ _ _) (isSetRingHom _ _ _ _))
(Σ≡Prop (λ _ → isSetRingHom _ _ _ _)
(cong fst (commRingPB .univProp h₂ h₁ squareComm .snd
(h₃' .fst .fst , h₃' .snd .fst , h₃' .snd .snd))))
where
h₃ : CommRingHom E A
h₃ = commRingPB .univProp h₂ h₁ squareComm .fst .fst
h₂≡g₂∘h₃ : h₂ ≡ g₂ ∘r h₃
h₂≡g₂∘h₃ = commRingPB .univProp h₂ h₁ squareComm .fst .snd .fst
h₁≡g₁∘h₃ : h₁ ≡ g₁ ∘r h₃
h₁≡g₁∘h₃ = commRingPB .univProp h₂ h₁ squareComm .fst .snd .snd
-- the crucial obervation:
-- we can apply the universal property to maps R → A
fgSquare : g₄ ∘r f₃ ≡ g₃ ∘r f₂
fgSquare = isRHom₄ ∙ sym isRHom₃
h₃∘f₅≡f₁ : h₃ ∘r f₅ ≡ f₁
h₃∘f₅≡f₁ = cong fst (isContr→isProp (commRingPB .univProp f₃ f₂ fgSquare)
(h₃ ∘r f₅ , triangle1 , triangle2) (f₁ , (sym isRHom₂) , sym isRHom₁))
where
triangle1 : f₃ ≡ g₂ ∘r (h₃ ∘r f₅)
triangle1 = sym comm₂ ∙∙ cong (compRingHom f₅) h₂≡g₂∘h₃ ∙∙ sym (compAssocRingHom f₅ h₃ g₂)
triangle2 : f₂ ≡ g₁ ∘r (h₃ ∘r f₅)
triangle2 = sym comm₁ ∙∙ cong (compRingHom f₅) h₁≡g₁∘h₃ ∙∙ sym (compAssocRingHom f₅ h₃ g₁)
algCospan : (isRHom₁ : isCommRingWithHomHom (A , f₁) (B , f₂) g₁)
(isRHom₂ : isCommRingWithHomHom (A , f₁) (C , f₃) g₂)
(isRHom₃ : isCommRingWithHomHom (B , f₂) (D , f₄) g₃)
(isRHom₄ : isCommRingWithHomHom (C , f₃) (D , f₄) g₄)
→ Cospan CommAlgCat
l (algCospan isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlg (C , f₃)
m (algCospan isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlg (D , f₄)
r (algCospan isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlg (B , f₂)
s₁ (algCospan isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlgebraHom _ _ g₄ isRHom₄
s₂ (algCospan isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlgebraHom _ _ g₃ isRHom₃
algPullback : (isRHom₁ : isCommRingWithHomHom (A , f₁) (B , f₂) g₁)
(isRHom₂ : isCommRingWithHomHom (A , f₁) (C , f₃) g₂)
(isRHom₃ : isCommRingWithHomHom (B , f₂) (D , f₄) g₃)
(isRHom₄ : isCommRingWithHomHom (C , f₃) (D , f₄) g₄)
→ Pullback CommAlgCat (algCospan isRHom₁ isRHom₂ isRHom₃ isRHom₄)
pbOb (algPullback isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlg (A , f₁)
pbPr₁ (algPullback isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlgebraHom _ _ g₂ isRHom₂
pbPr₂ (algPullback isRHom₁ isRHom₂ isRHom₃ isRHom₄) = toCommAlgebraHom _ _ g₁ isRHom₁
pbCommutes (algPullback isRHom₁ isRHom₂ isRHom₃ isRHom₄) =
AlgebraHom≡ (cong fst (pbCommutes commRingPB))
univProp (algPullback isRHom₁ isRHom₂ isRHom₃ isRHom₄) {d = F} h₂' h₁' g₄∘h₂'≡g₃∘h₁' =
(k , kComm₂ , kComm₁) , uniqueness
where
E = fromCommAlg F .fst
f₅ = fromCommAlg F .snd
h₁ : CommRingHom E B
fst h₁ = fst h₁'
IsRingHom.pres0 (snd h₁) = IsAlgebraHom.pres0 (snd h₁')
IsRingHom.pres1 (snd h₁) = IsAlgebraHom.pres1 (snd h₁')
IsRingHom.pres+ (snd h₁) = IsAlgebraHom.pres+ (snd h₁')
IsRingHom.pres· (snd h₁) = IsAlgebraHom.pres· (snd h₁')
IsRingHom.pres- (snd h₁) = IsAlgebraHom.pres- (snd h₁')
h₁comm : h₁ ∘r f₅ ≡ f₂
h₁comm = RingHom≡ (funExt (λ x → IsAlgebraHom.pres⋆ (snd h₁') x 1a
∙∙ cong (fst f₂ x ·_) (IsAlgebraHom.pres1 (snd h₁'))
∙∙ ·Rid _))
where
instance
_ = snd F
_ = snd (toCommAlg (B , f₂))
h₂ : CommRingHom E C
fst h₂ = fst h₂'
IsRingHom.pres0 (snd h₂) = IsAlgebraHom.pres0 (snd h₂')
IsRingHom.pres1 (snd h₂) = IsAlgebraHom.pres1 (snd h₂')
IsRingHom.pres+ (snd h₂) = IsAlgebraHom.pres+ (snd h₂')
IsRingHom.pres· (snd h₂) = IsAlgebraHom.pres· (snd h₂')
IsRingHom.pres- (snd h₂) = IsAlgebraHom.pres- (snd h₂')
h₂comm : h₂ ∘r f₅ ≡ f₃
h₂comm = RingHom≡ (funExt (λ x → IsAlgebraHom.pres⋆ (snd h₂') x 1a
∙∙ cong (fst f₃ x ·_) (IsAlgebraHom.pres1 (snd h₂'))
∙∙ ·Rid _))
where
instance
_ = snd F
_ = snd (toCommAlg (C , f₃))
commRingSquare : g₄ ∘r h₂ ≡ g₃ ∘r h₁
commRingSquare = RingHom≡ (funExt (λ x → funExt⁻ (cong fst g₄∘h₂'≡g₃∘h₁') x))
uniqueH₃ : ∃![ h₃ ∈ CommRingWithHomHom (E , f₅) (A , f₁) ] (h₂ ≡ g₂ ∘r fst h₃) × (h₁ ≡ g₁ ∘r fst h₃)
uniqueH₃ = univPropCommRingWithHomHom isRHom₁ isRHom₂ isRHom₃ isRHom₄
(E , f₅) (h₂ , h₂comm) (h₁ , h₁comm) commRingSquare
h₃ : CommRingHom E A
h₃ = uniqueH₃ .fst .fst .fst
h₃comm = uniqueH₃ .fst .fst .snd
k : CommAlgebraHom F (toCommAlg (A , f₁))
fst k = fst h₃
IsAlgebraHom.pres0 (snd k) = IsRingHom.pres0 (snd h₃)
IsAlgebraHom.pres1 (snd k) = IsRingHom.pres1 (snd h₃)
IsAlgebraHom.pres+ (snd k) = IsRingHom.pres+ (snd h₃)
IsAlgebraHom.pres· (snd k) = IsRingHom.pres· (snd h₃)
IsAlgebraHom.pres- (snd k) = IsRingHom.pres- (snd h₃)
IsAlgebraHom.pres⋆ (snd k) =
λ r y → sym (fst f₁ r · fst h₃ y ≡⟨ cong (_· fst h₃ y) (sym (funExt⁻ (cong fst h₃comm) r)) ⟩
fst h₃ (fst f₅ r) · fst h₃ y ≡⟨ sym (IsRingHom.pres· (snd h₃) _ _) ⟩
fst h₃ (fst f₅ r · y) ≡⟨ refl ⟩
fst h₃ ((r ⋆ 1a) · y) ≡⟨ cong (fst h₃) (⋆-lassoc _ _ _) ⟩
fst h₃ (r ⋆ (1a · y)) ≡⟨ cong (λ x → fst h₃ (r ⋆ x)) (·Lid y) ⟩
fst h₃ (r ⋆ y) ∎)
where
instance
_ = snd F
_ = (toCommAlg (A , f₁) .snd)
kComm₂ : h₂' ≡ toCommAlgebraHom _ _ g₂ isRHom₂ ∘a k
kComm₂ = AlgebraHom≡ (cong fst (uniqueH₃ .fst .snd .fst))
kComm₁ : h₁' ≡ toCommAlgebraHom _ _ g₁ isRHom₁ ∘a k
kComm₁ = AlgebraHom≡ (cong fst (uniqueH₃ .fst .snd .snd))
uniqueness : (y : Σ[ k' ∈ CommAlgebraHom F (toCommAlg (A , f₁)) ]
(h₂' ≡ toCommAlgebraHom _ _ g₂ isRHom₂ ∘a k')
× (h₁' ≡ toCommAlgebraHom _ _ g₁ isRHom₁ ∘a k'))
→ (k , kComm₂ , kComm₁) ≡ y
uniqueness (k' , k'Comm₂ , k'Comm₁) = Σ≡Prop (λ _ → isProp× (isSetAlgebraHom _ _ _ _)
(isSetAlgebraHom _ _ _ _))
(AlgebraHom≡ (cong (fst ∘ fst ∘ fst) uniqHelper))
where
h₃' : CommRingHom E A
fst h₃' = fst k'
IsRingHom.pres0 (snd h₃') = IsAlgebraHom.pres0 (snd k')
IsRingHom.pres1 (snd h₃') = IsAlgebraHom.pres1 (snd k')
IsRingHom.pres+ (snd h₃') = IsAlgebraHom.pres+ (snd k')
IsRingHom.pres· (snd h₃') = IsAlgebraHom.pres· (snd k')
IsRingHom.pres- (snd h₃') = IsAlgebraHom.pres- (snd k')
h₃'IsRHom : h₃' ∘r f₅ ≡ f₁
h₃'IsRHom = RingHom≡ (funExt (λ x → IsAlgebraHom.pres⋆ (snd k') x 1a
∙ cong (fst f₁ x ·_) (IsAlgebraHom.pres1 (snd k'))
∙ ·Rid (fst f₁ x)))
where
instance
_ = snd F
_ = (toCommAlg (A , f₁) .snd)
h₃'Comm₂ : h₂ ≡ g₂ ∘r h₃'
h₃'Comm₂ = RingHom≡ (cong fst k'Comm₂)
h₃'Comm₁ : h₁ ≡ g₁ ∘r h₃'
h₃'Comm₁ = RingHom≡ (cong fst k'Comm₁)
-- basically saying that h₃≡h₃' but we have to give all the commuting triangles
uniqHelper : uniqueH₃ .fst ≡ ((h₃' , h₃'IsRHom) , h₃'Comm₂ , h₃'Comm₁)
uniqHelper = uniqueH₃ .snd ((h₃' , h₃'IsRHom) , h₃'Comm₂ , h₃'Comm₁)
module PreSheafFromUniversalProp (C : Category ℓ ℓ') (P : ob C → Type ℓ)
{R : CommRing ℓ''} (𝓕 : Σ (ob C) P → CommAlgebra R ℓ'')
(uniqueHom : ∀ x y → C [ fst x , fst y ] → isContr (CommAlgebraHom (𝓕 y) (𝓕 x)))
where
private
∥P∥ : ℙ (ob C)
∥P∥ x = ∥ P x ∥ , isPropPropTrunc
ΣC∥P∥Cat = ΣPropCat C ∥P∥
CommAlgCat = CommAlgebrasCategory {ℓ = ℓ''} R {ℓ' = ℓ''}
𝓕UniqueEquiv : (x : ob C) (p q : P x) → isContr (CommAlgebraEquiv (𝓕 (x , p)) (𝓕 (x , q)))
𝓕UniqueEquiv x = contrCommAlgebraHom→contrCommAlgebraEquiv (curry 𝓕 x) λ p q → uniqueHom _ _ (id C)
theMap : (x : ob C) → ∥ P x ∥ → CommAlgebra R ℓ''
theMap x = recPT→CommAlgebra (curry 𝓕 x) (λ p q → 𝓕UniqueEquiv x p q .fst)
λ p q r → 𝓕UniqueEquiv x p r .snd _
theAction : (x y : ob C) → C [ x , y ]
→ (p : ∥ P x ∥) (q : ∥ P y ∥) → isContr (CommAlgebraHom (theMap y q) (theMap x p))
theAction _ _ f = elim2 (λ _ _ → isPropIsContr) λ _ _ → uniqueHom _ _ f
open Functor
universalPShf : Functor (ΣC∥P∥Cat ^op) CommAlgCat
F-ob universalPShf = uncurry theMap
F-hom universalPShf {x = x} {y = y} f = theAction _ _ f (y .snd) (x. snd) .fst
F-id universalPShf {x = x} = theAction (x .fst) (x .fst) (id C) (x .snd) (x .snd) .snd _
F-seq universalPShf {x = x} {z = z} f g = theAction _ _ (g ⋆⟨ C ⟩ f) (z .snd) (x .snd) .snd _
-- a big transport to help verifying the sheaf property
module toSheaf (x y u v : ob ΣC∥P∥Cat)
{f : C [ v .fst , y . fst ]} {g : C [ v .fst , u .fst ]}
{h : C [ u .fst , x . fst ]} {k : C [ y .fst , x .fst ]}
(Csquare : g ⋆⟨ C ⟩ h ≡ f ⋆⟨ C ⟩ k)
{-
v → y
↓ ↓
u → x
-}
(AlgCospan : Cospan CommAlgCat)
(AlgPB : Pullback _ AlgCospan)
(p₁ : AlgPB .pbOb ≡ F-ob universalPShf x) (p₂ : AlgCospan .l ≡ F-ob universalPShf u)
(p₃ : AlgCospan .r ≡ F-ob universalPShf y) (p₄ : AlgCospan .m ≡ F-ob universalPShf v)
where
private
-- just: 𝓕 k ⋆ 𝓕 f ≡ 𝓕 h ⋆ 𝓕 g
inducedSquare : seq' CommAlgCat {x = F-ob universalPShf x}
{y = F-ob universalPShf u}
{z = F-ob universalPShf v}
(F-hom universalPShf h) (F-hom universalPShf g)
≡ seq' CommAlgCat {x = F-ob universalPShf x}
{y = F-ob universalPShf y}
{z = F-ob universalPShf v}
(F-hom universalPShf k) (F-hom universalPShf f)
inducedSquare = F-square universalPShf Csquare
f' = F-hom universalPShf {x = y} {y = v} f
g' = F-hom universalPShf {x = u} {y = v} g
h' = F-hom universalPShf {x = x} {y = u} h
k' = F-hom universalPShf {x = x} {y = y} k
gPathP : PathP (λ i → CommAlgCat [ p₂ i , p₄ i ]) (AlgCospan .s₁) g'
gPathP = toPathP (sym (theAction _ _ g (v .snd) (u .snd) .snd _))
fPathP : PathP (λ i → CommAlgCat [ p₃ i , p₄ i ]) (AlgCospan .s₂) f'
fPathP = toPathP (sym (theAction _ _ f (v .snd) (y .snd) .snd _))
kPathP : PathP (λ i → CommAlgCat [ p₁ i , p₃ i ]) (AlgPB .pbPr₂) k'
kPathP = toPathP (sym (theAction _ _ k (y .snd) (x .snd) .snd _))
hPathP : PathP (λ i → CommAlgCat [ p₁ i , p₂ i ]) (AlgPB .pbPr₁) h'
hPathP = toPathP (sym (theAction _ _ h (u .snd) (x .snd) .snd _))
fgCospan : Cospan CommAlgCat
l fgCospan = F-ob universalPShf u
m fgCospan = F-ob universalPShf v
r fgCospan = F-ob universalPShf y
s₁ fgCospan = g'
s₂ fgCospan = f'
cospanPath : AlgCospan ≡ fgCospan
l (cospanPath i) = p₂ i
m (cospanPath i) = p₄ i
r (cospanPath i) = p₃ i
s₁ (cospanPath i) = gPathP i
s₂ (cospanPath i) = fPathP i
squarePathP : PathP (λ i → hPathP i ⋆⟨ CommAlgCat ⟩ gPathP i ≡ kPathP i ⋆⟨ CommAlgCat ⟩ fPathP i)
(AlgPB .pbCommutes) inducedSquare
squarePathP = toPathP (CommAlgCat .isSetHom _ _ _ _)
abstract
lemma : isPullback CommAlgCat fgCospan {c = F-ob universalPShf x} h' k' inducedSquare
lemma = transport (λ i → isPullback CommAlgCat (cospanPath i) {c = p₁ i}
(hPathP i) (kPathP i) (squarePathP i))
(AlgPB .univProp)
| 42.226776
| 102
| 0.569589
|
13c0375a880985435b1287735b6a3f6bbad1cb14
| 6,687
|
agda
|
Agda
|
src/Web/Semantic/DL/Category.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.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.agda
|
bblfish/agda-web-semantic
|
38fbc3af7062ba5c3d7d289b2b4bcfb995d99057
|
[
"MIT"
] | 3
|
2017-12-03T14:52:09.000Z
|
2022-03-12T11:40:03.000Z
|
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
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.Tensor
import Web.Semantic.DL.Category.Unit
import Web.Semantic.DL.Category.Wiring
module Web.Semantic.DL.Category {Σ : Signature} where
infix 2 _≣_ _⇒_
infixr 5 _∙_ _⊗_ _⟨⊗⟩_
-- Categorial structure
Object : TBox Σ → TBox Σ → Set₁
Object = Web.Semantic.DL.Category.Object.Object
_⇒_ : ∀ {S T} → (Object S T) → (Object S T) → Set₁
_⇒_ = Web.Semantic.DL.Category.Morphism._⇒_
identity : ∀ {S T} (A : Object S T) → (A ⇒ A)
identity = Web.Semantic.DL.Category.Wiring.identity
_∙_ : ∀ {S T} {A B C : Object S T} → (A ⇒ B) → (B ⇒ C) → (A ⇒ C)
_∙_ = Web.Semantic.DL.Category.Composition._∙_
-- Symmetric monoidal structure
I : ∀ {S T} → Object S T
I = Web.Semantic.DL.Category.Unit.I
_⊗_ : ∀ {S T} → Object S T → Object S T → Object S T
_⊗_ = Web.Semantic.DL.Category.Tensor._⊗_
_⟨⊗⟩_ : ∀ {S T : TBox Σ} {A₁ A₂ B₁ B₂ : Object S T} →
(A₁ ⇒ B₁) → (A₂ ⇒ B₂) → ((A₁ ⊗ A₂) ⇒ (B₁ ⊗ B₂))
_⟨⊗⟩_ = Web.Semantic.DL.Category.Tensor._⟨⊗⟩_
symm : ∀ {S T : TBox Σ} → (A B : Object S T) → ((A ⊗ B) ⇒ (B ⊗ A))
symm = Web.Semantic.DL.Category.Wiring.symm
assoc : ∀ {S T : TBox Σ} → (A B C : Object S T) →
(((A ⊗ B) ⊗ C) ⇒ (A ⊗ (B ⊗ C)))
assoc = Web.Semantic.DL.Category.Wiring.assoc
assoc⁻¹ : ∀ {S T : TBox Σ} → (A B C : Object S T) →
((A ⊗ (B ⊗ C)) ⇒ ((A ⊗ B) ⊗ C))
assoc⁻¹ = Web.Semantic.DL.Category.Wiring.assoc⁻¹
unit₁ : ∀ {S T : TBox Σ} (A : Object S T) → ((I ⊗ A) ⇒ A)
unit₁ = Web.Semantic.DL.Category.Wiring.unit₁
unit₁⁻¹ : ∀ {S T : TBox Σ} (A : Object S T) → (A ⇒ (I ⊗ A))
unit₁⁻¹ = Web.Semantic.DL.Category.Wiring.unit₁⁻¹
unit₂ : ∀ {S T : TBox Σ} (A : Object S T) → ((A ⊗ I) ⇒ A)
unit₂ = Web.Semantic.DL.Category.Wiring.unit₂
unit₂⁻¹ : ∀ {S T : TBox Σ} (A : Object S T) → (A ⇒ (A ⊗ I))
unit₂⁻¹ = Web.Semantic.DL.Category.Wiring.unit₂⁻¹
-- Equivalence of morphisms
_≣_ : ∀ {S T} {A B : Object S T} → (A ⇒ B) → (A ⇒ B) → Set₁
_≣_ = Web.Semantic.DL.Category.Morphism._≣_
≣-refl : ∀ {S T} {A B : Object S T} (F : A ⇒ B) →
(F ≣ F)
≣-refl = Web.Semantic.DL.Category.Properties.≣-refl
≣-sym : ∀ {S T} {A B : Object S T} {F G : A ⇒ B} →
(F ≣ G) → (G ≣ F)
≣-sym = Web.Semantic.DL.Category.Properties.≣-sym
≣-trans : ∀ {S T} {A B : Object S T} {F G H : A ⇒ B} →
(F ≣ G) → (G ≣ H) → (F ≣ H)
≣-trans = Web.Semantic.DL.Category.Properties.≣-trans
-- Equations of a category
compose-resp-≣ : ∀ {S T} {A B C : Object S T} {F₁ F₂ : A ⇒ B} {G₁ G₂ : B ⇒ C} →
(F₁ ≣ F₂) → (G₁ ≣ G₂) → (F₁ ∙ G₁ ≣ F₂ ∙ G₂)
compose-resp-≣ = Web.Semantic.DL.Category.Properties.compose-resp-≣
compose-unit₁ : ∀ {S T} {A B C : Object S T} (F : A ⇒ B) →
(identity A ∙ F ≣ F)
compose-unit₁ = Web.Semantic.DL.Category.Properties.compose-unit₁
compose-unit₂ : ∀ {S T} {A B C : Object S T} (F : A ⇒ B) →
(F ∙ identity B ≣ F)
compose-unit₂ = Web.Semantic.DL.Category.Properties.compose-unit₂
compose-assoc : ∀ {S T} {A B C D : Object S T}
(F : A ⇒ B) (G : B ⇒ C) (H : C ⇒ D) →
((F ∙ G) ∙ H ≣ F ∙ (G ∙ H))
compose-assoc = Web.Semantic.DL.Category.Properties.compose-assoc
-- Tensor is a bifunctor
tensor-resp-≣ : ∀ {S T} {A₁ A₂ B₁ B₂ : Object S T}
{F₁ G₁ : A₁ ⇒ B₁} {F₂ G₂ : A₂ ⇒ B₂} →
(F₁ ≣ G₁) → (F₂ ≣ G₂) → (F₁ ⟨⊗⟩ F₂ ≣ G₁ ⟨⊗⟩ G₂)
tensor-resp-≣ = Web.Semantic.DL.Category.Properties.tensor-resp-≣
tensor-resp-compose : ∀ {S T} {A₁ A₂ B₁ B₂ C₁ C₂ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (G₁ : B₁ ⇒ C₁) (G₂ : B₂ ⇒ C₂) →
(((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)) ≣ ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)))
tensor-resp-compose = Web.Semantic.DL.Category.Properties.tensor-resp-compose
tensor-resp-id : ∀ {S T} (A₁ A₂ : Object S T) →
((identity A₁ ⟨⊗⟩ identity A₂) ≣ identity (A₁ ⊗ A₂))
tensor-resp-id = Web.Semantic.DL.Category.Properties.tensor-resp-id
-- Isomorphisms of a symmetric monoidal category
symm-iso : ∀ {S T} (A₁ A₂ : Object S T) →
(symm A₁ A₂ ∙ symm A₂ A₁ ≣ identity (A₁ ⊗ A₂))
symm-iso = Web.Semantic.DL.Category.Properties.symm-iso
assoc-iso : ∀ {S T} (A₁ A₂ A₃ : Object S T) →
(assoc A₁ A₂ A₃ ∙ assoc⁻¹ A₁ A₂ A₃ ≣ identity ((A₁ ⊗ A₂) ⊗ A₃))
assoc-iso = Web.Semantic.DL.Category.Properties.assoc-iso
assoc⁻¹-iso : ∀ {S T} (A₁ A₂ A₃ : Object S T) →
(assoc⁻¹ A₁ A₂ A₃ ∙ assoc A₁ A₂ A₃ ≣ identity (A₁ ⊗ (A₂ ⊗ A₃)))
assoc⁻¹-iso = Web.Semantic.DL.Category.Properties.assoc⁻¹-iso
unit₁-iso : ∀ {S T} (A : Object S T) →
(unit₁ A ∙ unit₁⁻¹ A ≣ identity (I ⊗ A))
unit₁-iso = Web.Semantic.DL.Category.Properties.unit₁-iso
unit₁⁻¹-iso : ∀ {S T} (A : Object S T) →
(unit₁⁻¹ A ∙ unit₁ A ≣ identity A)
unit₁⁻¹-iso = Web.Semantic.DL.Category.Properties.unit₁⁻¹-iso
unit₂-iso : ∀ {S T} (A : Object S T) →
(unit₂ A ∙ unit₂⁻¹ A ≣ identity (A ⊗ I))
unit₂-iso = Web.Semantic.DL.Category.Properties.unit₂-iso
unit₂⁻¹-iso : ∀ {S T} (A : Object S T) →
(unit₂⁻¹ A ∙ unit₂ A ≣ identity A)
unit₂⁻¹-iso = Web.Semantic.DL.Category.Properties.unit₂⁻¹-iso
-- Coherence conditions of a symmetric monoidal category
assoc-unit : ∀ {S T} (A₁ A₂ : Object S T) →
(assoc A₁ I A₂ ∙ (identity A₁ ⟨⊗⟩ unit₁ A₂) ≣ unit₂ A₁ ⟨⊗⟩ identity A₂)
assoc-unit = Web.Semantic.DL.Category.Properties.assoc-unit
assoc-assoc : ∀ {S T} (A₁ A₂ A₃ A₄ : Object S T) →
(assoc (A₁ ⊗ A₂) A₃ A₄ ∙ assoc A₁ A₂ (A₃ ⊗ A₄) ≣
(assoc A₁ A₂ A₃ ⟨⊗⟩ identity A₄) ∙ assoc A₁ (A₂ ⊗ A₃) A₄ ∙ (identity A₁ ⟨⊗⟩ assoc A₂ A₃ A₄))
assoc-assoc = Web.Semantic.DL.Category.Properties.assoc-assoc
assoc-symm : ∀ {S T} (A₁ A₂ A₃ : Object S T) →
(symm (A₁ ⊗ A₂) A₃ ∙ assoc⁻¹ A₃ A₁ A₂ ≣
assoc A₁ A₂ A₃ ∙ (identity A₁ ⟨⊗⟩ symm A₂ A₃) ∙ assoc⁻¹ A₁ A₃ A₂ ∙ (symm A₁ A₃ ⟨⊗⟩ identity A₂))
assoc-symm = Web.Semantic.DL.Category.Properties.assoc-symm
-- Naturality conditions of a symmetric monoidal category
unit₁-natural : ∀ {S T} {A B : Object S T} (F : A ⇒ B) →
((identity I ⟨⊗⟩ F) ∙ unit₁ B ≣ unit₁ A ∙ F)
unit₁-natural = Web.Semantic.DL.Category.Properties.unit₁-natural
unit₂-natural : ∀ {S T} {A B : Object S T} (F : A ⇒ B) →
((F ⟨⊗⟩ identity I) ∙ unit₂ B ≣ unit₂ A ∙ F)
unit₂-natural = Web.Semantic.DL.Category.Properties.unit₂-natural
symm-natural : ∀ {S T} {A₁ A₂ B₁ B₂ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) →
((F₁ ⟨⊗⟩ F₂) ∙ symm B₁ B₂ ≣ symm A₁ A₂ ∙ (F₂ ⟨⊗⟩ F₁))
symm-natural = Web.Semantic.DL.Category.Properties.symm-natural
assoc-natural : ∀ {S T} {A₁ A₂ A₃ B₁ B₂ B₃ : Object S T}
(F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (F₃ : A₃ ⇒ B₃) →
(((F₁ ⟨⊗⟩ F₂) ⟨⊗⟩ F₃) ∙ assoc B₁ B₂ B₃ ≣
assoc A₁ A₂ A₃ ∙ (F₁ ⟨⊗⟩ (F₂ ⟨⊗⟩ F₃)))
assoc-natural = Web.Semantic.DL.Category.Properties.assoc-natural
| 36.342391
| 100
| 0.605952
|
191892d4282c8aae8d09a6408f5ef124e1e0f4d8
| 2,921
|
agda
|
Agda
|
src/Lambda/Interpreter/Steps.agda
|
nad/definitional-interpreters
|
dec8cd2d2851340840de25acb0feb78f7b5ffe96
|
[
"MIT"
] | null | null | null |
src/Lambda/Interpreter/Steps.agda
|
nad/definitional-interpreters
|
dec8cd2d2851340840de25acb0feb78f7b5ffe96
|
[
"MIT"
] | null | null | null |
src/Lambda/Interpreter/Steps.agda
|
nad/definitional-interpreters
|
dec8cd2d2851340840de25acb0feb78f7b5ffe96
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A definitional interpreter that is instrumented with information
-- about the number of steps required to run the compiled program
------------------------------------------------------------------------
open import Prelude
import Lambda.Syntax
module Lambda.Interpreter.Steps
{Name : Type}
(open Lambda.Syntax Name)
(def : Name → Tm 1)
where
import Equality.Propositional as E
open import Monad E.equality-with-J
open import Vec.Data E.equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Lambda.Delay-crash
import Lambda.Interpreter def as I
open Closure Tm
------------------------------------------------------------------------
-- The interpreter
-- A step annotation.
infix 1 ✓_
✓_ : ∀ {A i} → Delay-crash A i → Delay-crash A i
✓ x = later λ { .force → x }
-- The instrumented interpreter.
infix 10 _∙_
mutual
⟦_⟧ : ∀ {i n} → Tm n → Env n → Delay-crash Value i
⟦ var x ⟧ ρ = ✓ return (index ρ x)
⟦ lam t ⟧ ρ = ✓ return (lam t ρ)
⟦ t₁ · t₂ ⟧ ρ = do v₁ ← ⟦ t₁ ⟧ ρ
v₂ ← ⟦ t₂ ⟧ ρ
v₁ ∙ v₂
⟦ call f t ⟧ ρ = do v ← ⟦ t ⟧ ρ
lam (def f) [] ∙ v
⟦ con b ⟧ ρ = ✓ return (con b)
⟦ if t₁ t₂ t₃ ⟧ ρ = do v₁ ← ⟦ t₁ ⟧ ρ
⟦if⟧ v₁ t₂ t₃ ρ
_∙_ : ∀ {i} → Value → Value → Delay-crash Value i
lam t₁ ρ ∙ v₂ = later λ { .force → ⟦ t₁ ⟧ (v₂ ∷ ρ) }
con _ ∙ _ = crash
⟦if⟧ : ∀ {i n} →
Value → Tm n → Tm n → Env n → Delay-crash Value i
⟦if⟧ (lam _ _) _ _ _ = crash
⟦if⟧ (con true) t₂ t₃ ρ = ✓ ⟦ t₂ ⟧ ρ
⟦if⟧ (con false) t₂ t₃ ρ = ✓ ⟦ t₃ ⟧ ρ
------------------------------------------------------------------------
-- The semantics given above gives the same (uninstrumented) result as
-- the one in Lambda.Interpreter
mutual
-- The result of the instrumented interpreter is an expansion of
-- that of the uninstrumented interpreter.
⟦⟧≳⟦⟧ :
∀ {i n} (t : Tm n) {ρ : Env n} →
[ i ] ⟦ t ⟧ ρ ≳ I.⟦ t ⟧ ρ
⟦⟧≳⟦⟧ (var x) = laterˡ (reflexive _)
⟦⟧≳⟦⟧ (lam t) = laterˡ (reflexive _)
⟦⟧≳⟦⟧ (t₁ · t₂) = ⟦⟧≳⟦⟧ t₁ >>=-cong λ _ →
⟦⟧≳⟦⟧ t₂ >>=-cong λ _ →
∙≳∙ _
⟦⟧≳⟦⟧ (call f t) = ⟦⟧≳⟦⟧ t >>=-cong λ _ →
∙≳∙ _
⟦⟧≳⟦⟧ (con b) = laterˡ (reflexive _)
⟦⟧≳⟦⟧ (if t₁ t₂ t₃) = ⟦⟧≳⟦⟧ t₁ >>=-cong λ _ →
⟦if⟧≳⟦if⟧ _ t₂ t₃
∙≳∙ :
∀ {i} (v₁ {v₂} : Value) →
[ i ] v₁ ∙ v₂ ≳ v₁ I.∙ v₂
∙≳∙ (lam t₁ ρ) = later λ { .force → ⟦⟧≳⟦⟧ t₁ }
∙≳∙ (con _) = reflexive _
⟦if⟧≳⟦if⟧ :
∀ {i n} v₁ (t₂ t₃ : Tm n) {ρ} →
[ i ] ⟦if⟧ v₁ t₂ t₃ ρ ≳ I.⟦if⟧ v₁ t₂ t₃ ρ
⟦if⟧≳⟦if⟧ (lam _ _) _ _ = reflexive _
⟦if⟧≳⟦if⟧ (con true) t₂ t₃ = laterˡ (⟦⟧≳⟦⟧ t₂)
⟦if⟧≳⟦if⟧ (con false) t₂ t₃ = laterˡ (⟦⟧≳⟦⟧ t₃)
| 28.637255
| 72
| 0.444368
|
03df42b576e5a12764b571158f0852ce1e883993
| 2,352
|
agda
|
Agda
|
proglangs-learning/Agda/sv20/assign1/Second.agda
|
helq/old_code
|
a432faf1b340cb379190a2f2b11b997b02d1cd8d
|
[
"CC0-1.0"
] | null | null | null |
proglangs-learning/Agda/sv20/assign1/Second.agda
|
helq/old_code
|
a432faf1b340cb379190a2f2b11b997b02d1cd8d
|
[
"CC0-1.0"
] | 4
|
2020-03-10T19:20:21.000Z
|
2021-06-07T15:39:48.000Z
|
proglangs-learning/Agda/sv20/assign1/Second.agda
|
helq/old_code
|
a432faf1b340cb379190a2f2b11b997b02d1cd8d
|
[
"CC0-1.0"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module sv20.assign1.Second where
{- Code partially taken from the book "Programming Language Foundations in
- Agda" by Philip Wadler, Wen Kokke, Jeremy Siek and many others. The book
- can be found at https://plfa.github.io/
-
- Based on chapters 6 and 7 - Connectives and Negation
- https://plfa.github.io/Connectives/
- https://plfa.github.io/Negation/
-}
open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_])
open import Relation.Nullary using (¬_)
-- Logic can be formalised as types [1], so the current homework solution uses
-- types and type operations to proof logic operations.
--
-- [1] “Propositions as Types”, Philip Wadler, Communications of the ACM, December 2015.
------------------------------------------------------------------------------------------
-- HOMEWORK SOLUTION --
------------------------------------------------------------------------------------------
-- Conjuction is formalised in type systems as product
-- Prove that: A ⇒ B ⇒ C from A ∧ B ⇒ C
proof₁ : ∀ {A B C : Set}
→ (A × B → C)
-------------
→ (A → B → C)
proof₁ f a b = f ⟨ a , b ⟩
-- Prove that: (A ⇒ ¬ E ⇒ ¬ C) from ((A ∨ B) ⇒ (C ∨ D) ⇒ E)
-- Preliminary proofs
modus-tollens : ∀ {A B : Set}
→ (A → B)
-------------
→ (¬ B → ¬ A)
modus-tollens a→b = λ{¬b → λ{a → ¬b (a→b a)}}
-- Disjunction is formalised as Union
lemma₁ : ∀ {A B E : Set}
→ (A ⊎ B → E)
-------------
→ (A → E)
lemma₁ a⊎b→e a = a⊎b→e (inj₁ a)
lemma₂ : ∀ {C D : Set}
→ ¬ (C ⊎ D)
-------------
→ ¬ C
lemma₂ c⊎d = λ{c → c⊎d (inj₁ c)}
---- And finally the proof
proof₂ : ∀ {A B C D E : Set}
→ (A ⊎ B → C ⊎ D → E)
---------------------
→ (A → ¬ E → ¬ C)
proof₂ a⊎b→c⊎d→e a ¬e =
let
-- (A ⊎ B → C ⊎ D → E)
-- → A
-- ---------------------
-- → (C ⊎ D → E)
c⊎d→e = lemma₁ a⊎b→c⊎d→e a
-- (C ⊎ D → E)
-- → ¬E
-- -------------
-- → ¬ (C ⊎ D)
¬c⊎d = modus-tollens c⊎d→e ¬e
in
-- ¬ (C ⊎ D)
-- -------------
-- → ¬ C
lemma₂ ¬c⊎d
-------- Other stuff
stuff₁ : ∀ {C D : Set}
→ ¬ (C ⊎ D)
-------------
→ (¬ C) × (¬ D)
stuff₁ c⊎d = ⟨ (λ c → c⊎d (inj₁ c)) , (λ d → c⊎d (inj₂ d)) ⟩
| 25.846154
| 90
| 0.4375
|
a0781e180265bdc46ce8c52f29e4c42375bef743
| 6,574
|
agda
|
Agda
|
old/Main.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
old/Main.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
old/Main.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Main where
import Automaton.DeterministicFinite
import Automaton.NonDeterministicFinite
import Automaton.Pushdown
import Automaton.TuringMachine
import Cardinal
import Cardinal.Finite.Count
import Cardinal.Proofs
import Data
import Data.Any
import Data.Boolean
import Data.Boolean.Stmt
import Data.Boolean.Operators
import Data.Boolean.Proofs
import Data.Either
import Data.List
import Data.List.Computability
import Data.List.Proofs
import Data.List.Relation.Membership.Proofs
import Data.List.Relation.Sublist.Proofs
import Data.List.Relation
import Data.List.Relation.Membership
import Data.List.Relation.Sublist
import Data.ListNonEmpty
import Data.Option
import Data.Proofs
import Data.Tuple
import Data.Tuple.Function
import Data.Tuple.List
import Data.Tuple.Proofs
import Data.Tuple.Raise
import Data.Tuple.Raiseᵣ
import Data.Tuple.Raiseₗ
import FFI.IO as FFI
import FormalLanguage
import FormalLanguage.ContextFreeGrammar
import FormalLanguage.Proofs
import FormalLanguage.RegularExpression
import Functional
import Function.DomainRaise
import Function.Domains
import Function.Domains.Proofs
import Function.Equals
import Function.Names
import Function.PrimitiveRecursion
import Function.Proofs
import Function.Iteration
import Function.Iteration.Proofs
-- import Geometry.Test
-- import Geometry.Test2
import Geometry.Test3
import Graph
import Lang.Instance
import Lang.Irrelevance
import Logic.Classical
import Logic.Classical.DoubleNegated
import Logic.Classical.Mere
import Logic.Computability
import Logic.Computability.Binary
import Logic.Convenience
import Logic.DiagonalProof
import Logic.LambdaCalculus
import Logic.Predicate
import Logic.Predicate.Theorems
import Logic.Propositional
import Logic.Propositional.Names
import Logic.Propositional.Theorems
import Lvl
import Metalogic.Classical.Propositional.ProofSystem
import Metalogic.Classical.Propositional.Syntax
import Metalogic.Classical.Propositional.TruthSemanticsModel
import Metalogic.Constructive.NaturalDeduction.TreeModel
-- import Metalogic.Constructive.Provability
import Metalogic.Linear.SequentCalculus
import Metalogic.Linear.Syntax
import Numeral.CoordinateVector
import Numeral.FiniteInclusive
import Numeral.Finite
import Numeral.Finite.Bound
import Numeral.Finite.Functions
import Numeral.Finite.Oper
import Numeral.Finite.Oper.Comparisons
import Numeral.Finite.Proofs
import Numeral.Integer
import Numeral.Integer.Function
import Numeral.Integer.Oper
import Numeral.Integer.Proofs
import Numeral.Integer.Relation
import Numeral.Integer.Sign
import Numeral.Matrix
import Numeral.Natural
import Numeral.Natural.Coprime
import Numeral.Natural.Function
import Numeral.Natural.Function.Proofs
-- import Numeral.Natural.GreatestCommonDivisor
import Numeral.Natural.Induction
import Numeral.Natural.Inductions
import Numeral.Natural.Oper
import Numeral.Natural.Oper.Comparisons
import Numeral.Natural.Oper.Comparisons.Proofs
import Numeral.Natural.Oper.Divisibility
import Numeral.Natural.Oper.Modulo
import Numeral.Natural.Oper.Modulo.Proofs
import Numeral.Natural.Oper.Proofs
import Numeral.Natural.Order
import Numeral.Natural.Prime
import Numeral.Natural.Relation
import Numeral.Natural.Relation.Computability
import Numeral.Natural.Relation.Countable
import Numeral.Natural.Relation.Divisibility
import Numeral.Natural.Relation.Order
import Numeral.Natural.Relation.Order.Computability
import Numeral.Natural.Relation.Order.Existence
import Numeral.Natural.Relation.Order.Existence.Proofs
import Numeral.Natural.Relation.Order.Proofs
import Numeral.Natural.Relation.Properties
import Numeral.Natural.TotalOper
import Numeral.Natural.UnclosedOper
import Numeral.PositiveInteger
import Numeral.PositiveInteger.Oper
import Numeral.Rational.AlterAdd
-- import Numeral.Rational.SternBrocot
import Numeral.Real
import Numeral.Real.Properties
import Numeral.Sign
import Numeral.Sign.Oper
import Numeral.Sign.Oper0
import Operator.Equals
import Relator.Bijection
import Relator.Congruence
import Relator.Congruence.Proofs
import Relator.Countable
import Relator.Equals
import Relator.Equals.Proofs
import Relator.Equals.Proofs.Uniqueness
import Structure.Setoid.Uniqueness
import Relator.Finite
import Sets.BoolSet
import Sets.BoolSet.Proofs
import Sets.ETCS
import Sets.IZF
import Sets.PredicateSet
import Sets.PredicateSet.Filter
import Sets.PredicateSet.Finite
import Sets.PredicateSet.Proofs
import Sets.PredicateSet.Relations
import Structure.Setoid
import Structure.Setoid.Proofs
import Stream
import String
import Structure.Arithmetic
-- import Structure.Category
import Structure.Function.Domain
import Structure.Function.Linear
import Structure.Function.Ordering
import Structure.LinearAlgebra
import Structure.Logic.Classical.PredicateBoundedQuantification
import Structure.Logic.Classical.NaturalDeduction
import Structure.Logic.Classical.NaturalDeduction.Proofs
import Structure.Logic.Classical.SetTheory
import Structure.Logic.Classical.SetTheory.SetBoundedQuantification
import Structure.Logic.Classical.SetTheory.Function
import Structure.Logic.Classical.SetTheory.Relation
import Structure.Logic.Classical.SetTheory.ZFC
import Structure.Logic.Classical.SetTheory.ZFC.BinaryRelatorSet
-- import Structure.Logic.Classical.SetTheory.ZFC.Finite
import Structure.Logic.Classical.SetTheory.ZFC.FunctionSet
import Structure.Logic.Classical.SetTheory.ZFC.Proofs
import Structure.Logic.Constructive.Functions.Properties
import Structure.Logic.Constructive.NaturalDeduction
import Structure.Operator.Field
import Structure.Operator.Functions
import Structure.Operator.Group
import Structure.Operator.Group.Proofs
import Structure.Operator.Monoid
import Structure.Operator.Proofs
import Structure.Operator.Properties
import Structure.Operator.SetAlgebra
import Structure.Operator.Vector
import Structure.Real
import Structure.Relator.Equivalence as Eq
import Structure.Relator.Function
import Structure.Relator.Ordering
import Structure.Relator.Ordering.Subsets
import Structure.Relator.Properties
import Structure.Relator.Properties.Proofs
import Syntax.Function
import Syntax.Method
import Syntax.Number
import Type
import Type.Cardinality
import Type.Cardinality.Proofs
import Type.Dependent
import Type.Properties.Empty
import Type.Properties.Empty.Proofs
import Type.Functions
import Type.Functions.Inverse
import Type.Functions.Inverse.Proofs
import Type.Functions.Proofs
import Type.Singleton
import Type.Singleton.Proofs
import Type.Properties.Singleton
import Type.Properties.Singleton.Proofs
import Type.Univalence
main : FFI.IO Data.Unit
main = FFI.printStrLn("Okay")
| 31.454545
| 67
| 0.871768
|
1ee86657fff7bba429250db4c24179db1dd6379e
| 4,473
|
agda
|
Agda
|
Cubical/Experiments/Problem.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Experiments/Problem.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Experiments/Problem.agda
|
hyleIndex/cubical
|
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
-- An example of something where normalization is surprisingly slow
{-# OPTIONS --safe #-}
module Cubical.Experiments.Problem where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Int
open import Cubical.HITs.S1
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.HITs.Join
open import Cubical.HITs.Hopf
ptType : Type _
ptType = Σ Type₀ \ A → A
pt : (A : ptType) → A .fst
pt A = A .snd
S¹pt : ptType
S¹pt = (S¹ , base)
S²pt : ptType
S²pt = (S² , base)
S³pt : ptType
S³pt = (S³ , base)
joinpt : ptType
joinpt = (join S¹ S¹ , inl base)
Ω : (A : ptType) → ptType
Ω A = Path _ (pt A) (pt A) , refl
Ω² : (A : ptType) → ptType
Ω² A = Ω (Ω A)
Ω³ : (A : ptType) → ptType
Ω³ A = Ω² (Ω A)
α : join S¹ S¹ → S²
α (inl _) = base
α (inr _) = base
α (push x y i) = (merid y ∙ merid x) i
where
merid : S¹ → Path S² base base
merid base = refl
merid (loop i) = λ j → surf i j
-- The tests
test0To2 : Ω³ S³pt .fst
test0To2 i j k = surf i j k
f3 : Ω³ S³pt .fst → Ω³ joinpt .fst
f3 p i j k = S³→joinS¹S¹ (p i j k)
test0To3 : Ω³ joinpt .fst
test0To3 = f3 test0To2
f4 : Ω³ joinpt .fst → Ω³ S²pt .fst
f4 p i j k = α (p i j k)
test0To4 : Ω³ S²pt .fst
test0To4 = f4 test0To3
innerpath : ∀ i j → HopfS² (test0To4 i j i1)
innerpath i j = transp (λ k → HopfS² (test0To4 i j k)) i0 base
-- C-c C-n problem uses a lot of memory
problem : pos 0 ≡ pos 0
problem i = transp (λ j → helix (innerpath i j)) i0 (pos 0)
-- Lots of tests: (thanks Evan!)
winding2 : Path (Path S² base base) refl refl → ℤ
winding2 p = winding (λ j → transp (λ i → HopfS² (p i j)) i0 base)
test0 : ℤ
test0 = winding2 (λ i j → surf i j)
test1 : ℤ
test1 = winding2 (λ i j → surf j i)
test2 : ℤ
test2 = winding2 (λ i j → hcomp (λ _ → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) (surf i j))
test3 : ℤ
test3 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → surf j k ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) base)
test4 : ℤ
test4 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → surf j k ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) base)
test5 : ℤ
test5 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → surf k i ; (j = i1) → base}) base)
test6 : ℤ
test6 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → base ; (j = i1) → surf k i}) base)
test7 : ℤ
test7 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → surf j k ; (j = i0) → base ; (j = i1) → base}) (surf i j))
test8 : ℤ
test8 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → surf k i ; (j = i1) → base}) (surf i j))
test9 : ℤ
test9 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → base ; (j = i1) → surf k i}) (surf i j))
test10 : ℤ
test10 = winding2 (λ i j → hcomp (λ k → λ { (i = i0) → surf j k ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) (surf i j))
-- Tests using HopfS²'
winding2' : Path (Path S² base base) refl refl → ℤ
winding2' p = winding (λ j → transp (λ i → HopfS²' (p i j)) i0 base)
test0' : ℤ
test0' = winding2' (λ i j → surf i j)
test1' : ℤ
test1' = winding2' (λ i j → surf j i)
test2' : ℤ
test2' = winding2' (λ i j → hcomp (λ _ → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) (surf i j))
test3' : ℤ
test3' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → surf j k ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) base)
test4' : ℤ
test4' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → surf j k ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) base)
test5' : ℤ
test5' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → surf k i ; (j = i1) → base}) base)
test6' : ℤ
test6' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → base ; (j = i1) → surf k i}) base)
test7' : ℤ
test7' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → surf j k ; (j = i0) → base ; (j = i1) → base}) (surf i j))
test8' : ℤ
test8' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → surf k i ; (j = i1) → base}) (surf i j))
test9' : ℤ
test9' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → base ; (i = i1) → base ; (j = i0) → base ; (j = i1) → surf k i}) (surf i j))
test10' : ℤ
test10' = winding2' (λ i j → hcomp (λ k → λ { (i = i0) → surf j k ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base}) (surf i j))
| 30.020134
| 133
| 0.539683
|
58bb4e8b44c7f803718a50a1fe42faa44e1e017f
| 464
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Cubical/Path.agda
|
vlopezj/agda
|
ff4d89e75970cf27599fb9f572bd43c9455cbb56
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
src/data/lib/prim/Agda/Builtin/Cubical/Path.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
src/data/lib/prim/Agda/Builtin/Cubical/Path.agda
|
vikfret/agda
|
49ad0b3f0d39c01bc35123478b857e702b29fb9d
|
[
"BSD-3-Clause"
] | 1
|
2021-04-01T18:30:09.000Z
|
2021-04-01T18:30:09.000Z
|
{-# OPTIONS --cubical --safe --no-sized-types --no-guardedness #-}
module Agda.Builtin.Cubical.Path where
open import Agda.Primitive.Cubical
postulate
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
infix 4 _≡_
-- We have a variable name in `(λ i → A)` as a hint for case
-- splitting.
_≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
_≡_ {A = A} = PathP (λ i → A)
{-# BUILTIN PATH _≡_ #-}
| 24.421053
| 66
| 0.534483
|
1e5c9ea6b680509b76dbbc5f1ff37d06ff4f76c8
| 96
|
agda
|
Agda
|
Experiment/Categories/Category/Monoidal/Strict.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | 3
|
2020-04-07T17:49:42.000Z
|
2020-04-21T00:03:43.000Z
|
Experiment/Categories/Category/Monoidal/Strict.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
Experiment/Categories/Category/Monoidal/Strict.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Experiment.Categories.Category.Monoidal.Strict where
| 24
| 59
| 0.75
|
1a6d53301320b78e3203345dd2023dbe79e75180
| 1,649
|
agda
|
Agda
|
vendor/stdlib/src/Data/Product/Record.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 56
|
2015-01-20T02:11:42.000Z
|
2021-12-21T17:02:19.000Z
|
vendor/stdlib/src/Data/Product/Record.agda
|
larrytheliquid/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 1
|
2022-03-12T12:17:51.000Z
|
2022-03-12T12:17:51.000Z
|
vendor/stdlib/src/Data/Product/Record.agda
|
isabella232/Lemmachine
|
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
|
[
"MIT"
] | 3
|
2015-07-21T16:37:58.000Z
|
2022-03-12T11:54:10.000Z
|
------------------------------------------------------------------------
-- Products implemented using records
------------------------------------------------------------------------
-- It it ever becomes convenient to pattern match on records I might
-- make this the default implementation of products.
module Data.Product.Record where
open import Data.Function
infixr 4 _,_
infixr 2 _×_ _-×-_ _-,-_
------------------------------------------------------------------------
-- Definition
record Σ (a : Set) (b : a → Set) : Set where
field
proj₁ : a
proj₂ : b proj₁
open Σ public
_×_ : (a b : Set) → Set
a × b = Σ a (λ _ → b)
------------------------------------------------------------------------
-- Functions
_,_ : ∀ {a b} → (x : a) → b x → Σ a b
(x , y) = record {proj₁ = x; proj₂ = y}
<_,_> : ∀ {A} {B : A → Set} {C : ∀ {x} → B x → Set}
(f : (x : A) → B x) → ((x : A) → C (f x)) →
((x : A) → Σ (B x) C)
< f , g > x = (f x , g x)
map : ∀ {A B P Q} →
(f : A → B) → (∀ {x} → P x → Q (f x)) →
Σ A P → Σ B Q
map f g = < f ∘ proj₁ , g ∘ proj₂ >
swap : ∀ {a b} → a × b → b × a
swap = < proj₂ , proj₁ >
_-×-_ : ∀ {a b} → (a → b → Set) → (a → b → Set) → (a → b → Set)
f -×- g = f -[ _×_ ]₁- g
_-,-_ : ∀ {a b c d} → (a → b → c) → (a → b → d) → (a → b → c × d)
f -,- g = f -[ _,_ ]- g
curry : {a : Set} {b : a → Set} {c : Σ a b → Set} →
((p : Σ a b) → c p) →
((x : a) → (y : b x) → c (x , y))
curry f x y = f (x , y)
uncurry : {a : Set} {b : a → Set} {c : Σ a b → Set} →
((x : a) → (y : b x) → c (x , y)) →
((p : Σ a b) → c p)
uncurry f p = f (proj₁ p) (proj₂ p)
| 26.596774
| 72
| 0.349909
|
3d1909ffd83ded3eb9dffb63cb5e609ca23c58be
| 7,866
|
agda
|
Agda
|
agda-stdlib-0.9/src/Data/Container.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/Container.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
agda-stdlib-0.9/src/Data/Container.agda
|
qwe2/try-agda
|
9d4c43b1609d3f085636376fdca73093481ab882
|
[
"Apache-2.0"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Containers, based on the work of Abbott and others
------------------------------------------------------------------------
module Data.Container where
open import Data.M
open import Data.Product as Prod hiding (map)
open import Data.W
open import Function renaming (id to ⟨id⟩; _∘_ to _⟨∘⟩_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse using (_↔_; module Inverse)
import Function.Related as Related
open import Level
open import Relation.Binary
using (Setoid; module Setoid; Preorder; module Preorder)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≗_; refl)
open import Relation.Unary using (_⊆_)
------------------------------------------------------------------------
-- Containers
-- A container is a set of shapes, and for every shape a set of
-- positions.
infix 5 _▷_
record Container (ℓ : Level) : Set (suc ℓ) where
constructor _▷_
field
Shape : Set ℓ
Position : Shape → Set ℓ
open Container public
-- The semantics ("extension") of a container.
⟦_⟧ : ∀ {ℓ} → Container ℓ → Set ℓ → Set ℓ
⟦ C ⟧ X = Σ[ s ∈ Shape C ] (Position C s → X)
-- The least and greatest fixpoints of a container.
μ : ∀ {ℓ} → Container ℓ → Set ℓ
μ C = W (Shape C) (Position C)
ν : ∀ {ℓ} → Container ℓ → Set ℓ
ν C = M (Shape C) (Position C)
-- Equality, parametrised on an underlying relation.
Eq : ∀ {c ℓ} {C : Container c} {X Y : Set c} →
(X → Y → Set ℓ) → ⟦ C ⟧ X → ⟦ C ⟧ Y → Set (c ⊔ ℓ)
Eq {C = C} _≈_ (s , f) (s′ , f′) =
Σ[ eq ∈ s ≡ s′ ] (∀ p → f p ≈ f′ (P.subst (Position C) eq p))
private
-- Note that, if propositional equality were extensional, then
-- Eq _≡_ and _≡_ would coincide.
Eq⇒≡ : ∀ {c} {C : Container c} {X : Set c} {xs ys : ⟦ C ⟧ X} →
P.Extensionality c c → Eq _≡_ xs ys → xs ≡ ys
Eq⇒≡ {xs = s , f} {ys = .s , f′} ext (refl , f≈f′) =
P.cong (_,_ s) (ext f≈f′)
setoid : ∀ {ℓ} → Container ℓ → Setoid ℓ ℓ → Setoid ℓ ℓ
setoid C X = record
{ Carrier = ⟦ C ⟧ X.Carrier
; _≈_ = _≈_
; isEquivalence = record
{ refl = (refl , λ _ → X.refl)
; sym = sym
; trans = λ {_ _ zs} → trans zs
}
}
where
module X = Setoid X
_≈_ = Eq X._≈_
sym : {xs ys : ⟦ C ⟧ X.Carrier} → xs ≈ ys → ys ≈ xs
sym {_ , _} {._ , _} (refl , f) = (refl , X.sym ⟨∘⟩ f)
trans : ∀ {xs ys : ⟦ C ⟧ X.Carrier} zs → xs ≈ ys → ys ≈ zs → xs ≈ zs
trans {_ , _} {._ , _} (._ , _) (refl , f₁) (refl , f₂) =
(refl , λ p → X.trans (f₁ p) (f₂ p))
------------------------------------------------------------------------
-- Functoriality
-- Containers are functors.
map : ∀ {c} {C : Container c} {X Y} → (X → Y) → ⟦ C ⟧ X → ⟦ C ⟧ Y
map f = Prod.map ⟨id⟩ (λ g → f ⟨∘⟩ g)
module Map where
identity : ∀ {c} {C : Container c} X →
let module X = Setoid X in
(xs : ⟦ C ⟧ X.Carrier) → Eq X._≈_ (map ⟨id⟩ xs) xs
identity {C = C} X xs = Setoid.refl (setoid C X)
composition : ∀ {c} {C : Container c} {X Y : Set c} Z →
let module Z = Setoid Z in
(f : Y → Z.Carrier) (g : X → Y) (xs : ⟦ C ⟧ X) →
Eq Z._≈_ (map f (map g xs)) (map (f ⟨∘⟩ g) xs)
composition {C = C} Z f g xs = Setoid.refl (setoid C Z)
------------------------------------------------------------------------
-- Container morphisms
-- Representation of container morphisms.
record _⇒_ {c} (C₁ C₂ : Container c) : Set c where
field
shape : Shape C₁ → Shape C₂
position : ∀ {s} → Position C₂ (shape s) → Position C₁ s
open _⇒_ public
-- Interpretation of _⇒_.
⟪_⟫ : ∀ {c} {C₁ C₂ : Container c} →
C₁ ⇒ C₂ → ∀ {X} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X
⟪ m ⟫ xs = (shape m (proj₁ xs) , proj₂ xs ⟨∘⟩ position m)
module Morphism where
-- Naturality.
Natural : ∀ {c} {C₁ C₂ : Container c} →
(∀ {X} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X) → Set (suc c)
Natural {c} {C₁} m =
∀ {X} (Y : Setoid c c) → let module Y = Setoid Y in
(f : X → Y.Carrier) (xs : ⟦ C₁ ⟧ X) →
Eq Y._≈_ (m $ map f xs) (map f $ m xs)
-- Natural transformations.
NT : ∀ {c} (C₁ C₂ : Container c) → Set (suc c)
NT C₁ C₂ = ∃ λ (m : ∀ {X} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X) → Natural m
-- Container morphisms are natural.
natural : ∀ {c} {C₁ C₂ : Container c}
(m : C₁ ⇒ C₂) → Natural ⟪ m ⟫
natural {C₂ = C₂} m Y f xs = Setoid.refl (setoid C₂ Y)
-- In fact, all natural functions of the right type are container
-- morphisms.
complete : ∀ {c} {C₁ C₂ : Container c} →
(nt : NT C₁ C₂) →
∃ λ m → (X : Setoid c c) →
let module X = Setoid X in
(xs : ⟦ C₁ ⟧ X.Carrier) →
Eq X._≈_ (proj₁ nt xs) (⟪ m ⟫ xs)
complete (nt , nat) =
(m , λ X xs → nat X (proj₂ xs) (proj₁ xs , ⟨id⟩))
where
m = record { shape = λ s → proj₁ (nt (s , ⟨id⟩))
; position = λ {s} → proj₂ (nt (s , ⟨id⟩))
}
-- Identity.
id : ∀ {c} (C : Container c) → C ⇒ C
id _ = record {shape = ⟨id⟩; position = ⟨id⟩}
-- Composition.
infixr 9 _∘_
_∘_ : ∀ {c} {C₁ C₂ C₃ : Container c} → C₂ ⇒ C₃ → C₁ ⇒ C₂ → C₁ ⇒ C₃
f ∘ g = record
{ shape = shape f ⟨∘⟩ shape g
; position = position g ⟨∘⟩ position f
}
-- Identity and composition commute with ⟪_⟫.
id-correct : ∀ {c} {C : Container c} {X : Set c} →
⟪ id C ⟫ {X} ≗ ⟨id⟩
id-correct xs = refl
∘-correct : ∀ {c} {C₁ C₂ C₃ : Container c}
(f : C₂ ⇒ C₃) (g : C₁ ⇒ C₂) {X : Set c} →
⟪ f ∘ g ⟫ {X} ≗ (⟪ f ⟫ ⟨∘⟩ ⟪ g ⟫)
∘-correct f g xs = refl
------------------------------------------------------------------------
-- Linear container morphisms
record _⊸_ {c} (C₁ C₂ : Container c) : Set c where
field
shape⊸ : Shape C₁ → Shape C₂
position⊸ : ∀ {s} → Position C₂ (shape⊸ s) ↔ Position C₁ s
morphism : C₁ ⇒ C₂
morphism = record
{ shape = shape⊸
; position = _⟨$⟩_ (Inverse.to position⊸)
}
⟪_⟫⊸ : ∀ {X} → ⟦ C₁ ⟧ X → ⟦ C₂ ⟧ X
⟪_⟫⊸ = ⟪ morphism ⟫
open _⊸_ public using (shape⊸; position⊸; ⟪_⟫⊸)
------------------------------------------------------------------------
-- All and any
-- All.
□ : ∀ {c} {C : Container c} {X : Set c} →
(X → Set c) → (⟦ C ⟧ X → Set c)
□ P (s , f) = ∀ p → P (f p)
□-map : ∀ {c} {C : Container c} {X : Set c} {P Q : X → Set c} →
P ⊆ Q → □ {C = C} P ⊆ □ Q
□-map P⊆Q = _⟨∘⟩_ P⊆Q
-- Any.
◇ : ∀ {c} {C : Container c} {X : Set c} →
(X → Set c) → (⟦ C ⟧ X → Set c)
◇ P (s , f) = ∃ λ p → P (f p)
◇-map : ∀ {c} {C : Container c} {X : Set c} {P Q : X → Set c} →
P ⊆ Q → ◇ {C = C} P ⊆ ◇ Q
◇-map P⊆Q = Prod.map ⟨id⟩ P⊆Q
-- Membership.
infix 4 _∈_
_∈_ : ∀ {c} {C : Container c} {X : Set c} →
X → ⟦ C ⟧ X → Set c
x ∈ xs = ◇ (_≡_ x) xs
-- Bag and set equality and related preorders. Two containers xs and
-- ys are equal when viewed as sets if, whenever x ∈ xs, we also have
-- x ∈ ys, and vice versa. They are equal when viewed as bags if,
-- additionally, the sets x ∈ xs and x ∈ ys have the same size.
open Related public
using (Kind; Symmetric-kind)
renaming ( implication to subset
; reverse-implication to superset
; equivalence to set
; injection to subbag
; reverse-injection to superbag
; bijection to bag
)
[_]-Order : ∀ {ℓ} → Kind → Container ℓ → Set ℓ → Preorder ℓ ℓ ℓ
[ k ]-Order C X = Related.InducedPreorder₂ k (_∈_ {C = C} {X = X})
[_]-Equality : ∀ {ℓ} → Symmetric-kind → Container ℓ → Set ℓ → Setoid ℓ ℓ
[ k ]-Equality C X = Related.InducedEquivalence₂ k (_∈_ {C = C} {X = X})
infix 4 _∼[_]_
_∼[_]_ : ∀ {c} {C : Container c} {X : Set c} →
⟦ C ⟧ X → Kind → ⟦ C ⟧ X → Set c
_∼[_]_ {C = C} {X} xs k ys = Preorder._∼_ ([ k ]-Order C X) xs ys
| 29.133333
| 72
| 0.483092
|
2ec5319c219b37239858cb674a90d7ba70c190fc
| 4,262
|
agda
|
Agda
|
UniDB/Examples/Lc.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Examples/Lc.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
UniDB/Examples/Lc.agda
|
skeuchel/unidb-agda
|
7ae52205db44ad4f463882ba7e5082120fb76349
|
[
"MIT"
] | null | null | null |
module UniDB.Examples.Lc where
open import UniDB
data Tm (γ : Dom) : Set where
var : (i : Ix γ) → Tm γ
abs : (t : Tm (suc γ)) → Tm γ
app : (t₁ t₂ : Tm γ) → Tm γ
instance
iVrTm : Vr Tm
vr {{iVrTm}} = var
vr-inj {{iVrTm}} refl = refl
iApTm : Ap Tm Tm
ap {{iApTm}} ξ (var i) = lk ξ i
ap {{iApTm}} ξ (abs t) = abs (ap {Tm} (ξ ↑₁) t )
ap {{iApTm}} ξ (app t t₁) = app (ap {Tm} ξ t) (ap {Tm} ξ t₁)
iApVrTm : ApVr Tm
ap-vr {{iApVrTm}} ξ i = refl
iApIdmTm : ApIdm Tm Tm
ap-idm {{iApIdmTm}} {Ξ} (var i) = lk-idm {Tm} {Ξ} i
ap-idm {{iApIdmTm}} {Ξ} (abs t) = cong abs (begin
ap {Tm} (idm {Ξ} _ ↑₁) t ≡⟨ cong₂ (ap {Tm}) (idm-↑₁ {Ξ}) (refl {x = t}) ⟩
ap {Tm} (idm {Ξ} _) t ≡⟨ ap-idm {Tm} t ⟩
t ∎)
ap-idm {{iApIdmTm}} {Ξ} (app t t₁) =
cong₂ app (ap-idm {Tm} t) (ap-idm {Tm} t₁)
iApPairTm : ApPair Tm Tm
ap-pair {{iApPairTm}} ξ ζ (var i) = refl
ap-pair {{iApPairTm}} ξ ζ (abs x) = cong abs (ap-pair {Tm} (ξ ↑₁) (ζ ↑₁) x)
ap-pair {{iApPairTm}} ξ ζ (app x₁ x₂) = cong₂ app (ap-pair {Tm} ξ ζ x₁) (ap-pair {Tm} ξ ζ x₂)
iApRelTm : ApRel Tm Tm
ap-rel≅ {{iApRelTm}} hyp (var i) = lk≃ (≅-to-≃ hyp) i
ap-rel≅ {{iApRelTm}} hyp (abs t) = cong abs (ap-rel≅ {Tm} {Tm} (≅-↑₁ hyp) t)
ap-rel≅ {{iApRelTm}} hyp (app t₁ t₂) = cong₂ app (ap-rel≅ {Tm} {Tm} hyp t₁) (ap-rel≅ {Tm} {Tm} hyp t₂)
postulate
Ρ : MOR
instance
iIdmΡ : Idm Ρ
iWkmΡ : Wkm Ρ
iUpΡ : Up Ρ
iUpIdmΡ : UpIdm Ρ
iCompΡ : Comp Ρ
iWkmHomΡ : WkmHom Ρ
iLkΡ : {T : STX} {{vrT : Vr T}} → Lk T Ρ
iLkIdmΡ : {T : STX} {{vrT : Vr T}} → LkIdm T Ρ
iLkWkmΡ : {T : STX} {{vrT : Vr T}} → LkWkm T Ρ
iLkCompAp : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} → LkCompAp T Ρ
iLkUpΡ : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} → LkUp T Ρ
iLkRenΡ : {T : STX} {{vrT : Vr T}} → LkRen T Ρ
instance
iWkTm : Wk Tm
wk₁ {{iWkTm}} = ap {Tm} (wkm {Ρ} 1)
wk {{iWkTm}} δ t = ap {Tm} (wkm {Ρ} δ) t
wk-zero {{iWkTm}} t = begin
ap {Tm} (wkm {Ρ} 0) t ≡⟨ ap-rel≅ {Tm} (Ix≅-to-≅ {Tm} (≃-to-≅` (≃-↑ {Ix} (record { lk≃ = λ i → begin
lk (wkm {Ρ} 0) i ≡⟨ lk-wkm {Ix} {Ρ} 0 i ⟩
i ≡⟨ sym (lk-idm {Ix} {Ρ} i) ⟩
lk (idm {Ρ} _) i ∎
})))) t ⟩
ap {Tm} (idm {Ρ} _) t ≡⟨ ap-idm {Tm} {Tm} {Ρ} t ⟩
t ∎
wk-suc {{iWkTm}} δ t = begin
ap {Tm} (wkm {Ρ} (suc δ)) t ≡⟨ cong (λ ζ → ap {Tm} {Tm} {Ρ} ζ t) (wkm-suc {Ρ} δ) ⟩
ap {Tm} (wkm {Ρ} δ ⊙ wkm {Ρ} 1) t ≡⟨ ap-rel≅ {Tm} (Ix≅-to-≅ {Tm} {Ρ} {Pair Ρ Ρ} (≃-to-≅`
(≃-↑ {Ix} {Ρ} {Pair Ρ Ρ} {ξ = wkm {Ρ} δ ⊙ wkm {Ρ} 1} {wkm {Ρ} δ ⊗ wkm {Ρ} 1} (record { lk≃ =
lk-⊙-ap {Ix} {Ρ} (wkm {Ρ} δ) (wkm {Ρ} 1) })))) t ⟩
ap {Tm} (wkm {Ρ} δ ⊗ wkm {Ρ} 1) t ≡⟨ ap-pair {Tm} (wkm {Ρ} δ) (wkm {Ρ} 1) t ⟩
ap {Tm} (wkm {Ρ} 1) (ap {Tm} (wkm {Ρ} δ) t) ∎
instance
iWkVrTm : WkVr Tm
wk₁-vr {{iWkVrTm}} i = lk-wkm {Tm} {Ρ} 1 i
wk-vr {{iWkVrTm}} δ i = lk-wkm {Tm} {Ρ} δ i
iApWkmWkTm : ApWkmWk Tm Tm
ap-wkm-wk₁ {{iApWkmWkTm}} {Ξ} = ap-wkm-rel Tm Tm Ξ Ρ 1
ap-wkm-wk {{iApWkmWkTm}} {Ξ} = ap-wkm-rel Tm Tm Ξ Ρ
-- iApCompTm : ApComp Tm Tm
-- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (var i) = lk-⊙-ap {Tm} {Ξ} ξ₁ ξ₂ i
-- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (abs t) rewrite ⊙-↑₁ {Ξ} ξ₁ ξ₂ =
-- cong abs (ap-⊙ {Tm} (ξ₁ ↑₁) (ξ₂ ↑₁) t)
-- ap-⊙ {{iApCompTm}} {Ξ} ξ₁ ξ₂ (app t₁ t₂) =
-- cong₂ app (ap-⊙ {Tm} {Tm} {Ξ} ξ₁ ξ₂ t₁) (ap-⊙ {Tm} {Tm} {Ξ} ξ₁ ξ₂ t₂)
iApCompTm : ApComp Tm Tm
iApCompTm = iApComp Tm Tm
iApWkTm : ApWk Tm Tm
iApWkTm = iApWk Tm Tm
{-}
--------------------------------------------------------------------------------
subTm : {X : STX} {{apTmX : Ap Tm X}} {γ : Dom} (s : Tm γ) (x : X (suc γ)) → X γ
subTm {X} s x = ap Tm X (Sub Tm) (beta Tm (Sub Tm) s) x
data Eval {γ : Dom} : Tm γ → Tm γ → Set where
e-app₁ : {t₁ t₁' t₂ : Tm γ} → Eval t₁ t₁' → Eval (app t₁ t₂) (app t₁' t₂)
e-app₂ : {t₁ t₂ t₂' : Tm γ} → Eval t₂ t₂' → Eval (app t₁ t₂) (app t₁ t₂')
e-abs : {t t' : Tm (suc γ)} → Eval t t' → Eval (abs t) (abs t')
e-beta : {s : Tm γ} {t : Tm (suc γ)} → Eval (app (abs t) s) (subTm s t)
--------------------------------------------------------------------------------
-}
| 36.118644
| 104
| 0.456828
|
2e2d428338d6b115e2fb3c98ec4c61e5703647ee
| 3,327
|
agda
|
Agda
|
out/Combinatory/Syntax.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 39
|
2021-11-09T20:39:55.000Z
|
2022-03-19T17:33:12.000Z
|
out/Combinatory/Syntax.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 1
|
2021-11-21T12:19:32.000Z
|
2021-11-21T12:19:32.000Z
|
out/Combinatory/Syntax.agda
|
JoeyEremondi/agda-soas
|
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
|
[
"MIT"
] | 4
|
2021-11-09T20:39:59.000Z
|
2022-01-24T12:49:17.000Z
|
{-
This second-order term syntax was created from the following second-order syntax description:
syntax Combinatory | CL
type
* : 0-ary
term
app : * * -> * | _$_ l20
i : *
k : *
s : *
theory
(IA) x |> app (i, x) = x
(KA) x y |> app (app(k, x), y) = x
(SA) x y z |> app (app (app (s, x), y), z) = app (app(x, z), app(y, z))
-}
module Combinatory.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import Combinatory.Signature
private
variable
Γ Δ Π : Ctx
α : *T
𝔛 : Familyₛ
-- Inductive term declaration
module CL:Terms (𝔛 : Familyₛ) where
data CL : Familyₛ where
var : ℐ ⇾̣ CL
mvar : 𝔛 α Π → Sub CL Π Γ → CL α Γ
_$_ : CL * Γ → CL * Γ → CL * Γ
I : CL * Γ
K : CL * Γ
S : CL * Γ
infixl 20 _$_
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
CLᵃ : MetaAlg CL
CLᵃ = record
{ 𝑎𝑙𝑔 = λ where
(appₒ ⋮ a , b) → _$_ a b
(iₒ ⋮ _) → I
(kₒ ⋮ _) → K
(sₒ ⋮ _) → S
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module CLᵃ = MetaAlg CLᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : CL ⇾̣ 𝒜
𝕊 : Sub CL Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 I = 𝑎𝑙𝑔 (iₒ ⋮ tt)
𝕤𝕖𝕞 K = 𝑎𝑙𝑔 (kₒ ⋮ tt)
𝕤𝕖𝕞 S = 𝑎𝑙𝑔 (sₒ ⋮ tt)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ CLᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ CL α Γ) → 𝕤𝕖𝕞 (CLᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (iₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (kₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (sₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ CL ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : CL ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ CLᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : CL α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub CL Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! I = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! K = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! S = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
CL:Syn : Syntax
CL:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = CL:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open CL:Terms 𝔛 in record
{ ⊥ = CL ⋉ CLᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax CL:Syn public
open CL:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands CLᵃ public
open import SOAS.Metatheory CL:Syn public
| 24.463235
| 93
| 0.514878
|
4b7dc773e29b02dcc1d1738a7d123474c51097e7
| 2,151
|
agda
|
Agda
|
RMonads/Modules.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 21
|
2015-07-30T01:25:12.000Z
|
2021-02-13T18:02:18.000Z
|
RMonads/Modules.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 3
|
2019-01-13T13:12:33.000Z
|
2019-05-29T09:50:26.000Z
|
RMonads/Modules.agda
|
jmchapman/Relative-Monads
|
74707d3538bf494f4bd30263d2f5515a84733865
|
[
"MIT"
] | 1
|
2019-11-04T21:33:13.000Z
|
2019-11-04T21:33:13.000Z
|
module RMonads.Modules where
open import Library
open import Categories
open import Functors
open import RMonads
record Mod {a}{b}{c}{d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}
(RM : RMonad J) : Set (a ⊔ c ⊔ d) where
constructor mod
open Cat
open Fun
open RMonad RM
field M : Obj C → Obj D
mbind : ∀ {X Y} → Hom D (OMap J X) (T Y) → Hom D (M X) (M Y)
laweta : ∀{X} → mbind (η {X}) ≅ iden D {M X}
lawbind : ∀{X Y Z}
{f : Hom D (OMap J X) (T Y)}{g : Hom D (OMap J Y) (T Z)} →
mbind (comp D (bind g) f) ≅ comp D (mbind g) (mbind f)
-- any rel. monad is trivially a module over its J.
ModJ : forall {a}{b}{c}{d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D} (RM : RMonad J) -> Mod (trivRM J)
ModJ {D = D}{J = J} RM =
mod T
(\ f -> bind (comp η f))
(trans (cong bind idr) law1)
(trans (cong bind (trans (trans (sym ass)
(cong (\ g -> comp g _) (sym law2)))
ass))
law3)
where open Fun J; open RMonad RM; open Cat D
open import Functors.FullyFaithful
open import Isomorphism
-- if J is fully faithful then any suitably typed functor is a module for trivial rel monad given by J
ModF : forall {a}{b}{c}{d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D} → Full J → Faithful J → (F : Fun C D) -> Mod (trivRM J)
ModF {C = C}{D = D}{J = J} P Q F = mod
(OMap F)
(λ f → HMap F (fst (P f)))
(trans (cong (HMap F) (Q (trans (snd (P (Cat.iden D))) (sym $ fid J)))) (fid F))
(trans (cong (HMap F)
(Q (trans (snd (P _))
(trans (cong₂ (Cat.comp D)
(sym $ snd (P _))
(sym $ snd (P _)))
(sym $ fcomp J)))))
(fcomp F)) where open Fun
-- any rel. monad is trivially a module over itself, 'tautalogical module'
ModRM : forall {a}{b}{c}{d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D} (RM : RMonad J) -> Mod RM
ModRM RM = mod T bind law1 law3 where open RMonad RM
| 36.457627
| 102
| 0.483031
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.