Search is not available for this dataset
text
string | meta
dict |
---|---|
module sn-calculus-compatconf where
open import sn-calculus
open import utility renaming (_U̬_ to _∪_)
open import context-properties
using (get-view ; ->E-view ; ->pot-view)
open import sn-calculus-compatconf.eview
using (1-steplρ-E-view)
open import sn-calculus-compatconf.pot
using (1-steplρ-pot)
open import sn-calculus-confluence
using (R-confluent)
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.Properties
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ;
Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning)
open import Data.Bool
using (Bool ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _∷_ ; [] ; _++_)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function using (_∘_ ; id ; _∋_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ->E-view
open ->pot-view
open EvaluationContext1
open _≐_⟦_⟧e
open Context1
open _≐_⟦_⟧c
open ListSet Data.Nat._≟_
1-step-sn⟶₁ : ∀{p q r BV FV} →
CorrectBinding p BV FV →
p sn⟶₁ q →
p sn⟶₁ r →
Σ[ p' ∈ Term ] (q sn⟶* p' × r sn⟶* p')
1-step-sn⟶₁ cb psn⟶₁q psn⟶₁r with R-confluent cb psn⟶₁q psn⟶₁r
... | inj₁ refl = _ , rrefl ,′ rrefl
... | inj₂ (inj₁ (_ , qsn⟶₁s , rsn⟶₁s)) =
_ , sn⟶*-inclusion (sn⟶-inclusion qsn⟶₁s) ,′ sn⟶*-inclusion (sn⟶-inclusion rsn⟶₁s)
... | inj₂ (inj₂ (inj₁ qsn⟶₁r)) =
_ , sn⟶*-inclusion (sn⟶-inclusion qsn⟶₁r) ,′ rrefl
... | inj₂ (inj₂ (inj₂ rsn⟶₁q)) =
_ , rrefl ,′ sn⟶*-inclusion (sn⟶-inclusion rsn⟶₁q)
1-steplρ : ∀{p q r θ θq BV FV A Aq} →
CorrectBinding (ρ⟨ θ , A ⟩· p) BV FV →
ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θq , Aq ⟩· q →
p sn⟶ r →
Σ[ p' ∈ Term ] ((ρ⟨ θq , Aq ⟩· q) sn⟶* p' × (ρ⟨ θ , A ⟩· r) sn⟶* p')
1-steplρ {p} {q} {r} cb
ρθ·psn⟶₁ρθq·q psn⟶r@(rcontext {.p} {rin} {ro} C p≐C⟦rin⟧ rinsn⟶₁ro)
with get-view ρθ·psn⟶₁ρθq·q
... | inj₂ (refl , refl , pot) =
_ , 1-steplρ-pot cb pot psn⟶r
... | inj₁ (E , qin , qo , p≐E⟦qin⟧ , q≐E⟦qo⟧ , e-view) =
_ , proj₂ (1-steplρ-E-view cb p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐C⟦rin⟧ rinsn⟶₁ro)
1-stepl : ∀{p q r BV FV} →
CorrectBinding p BV FV →
p sn⟶₁ q →
p sn⟶ r →
Σ[ p' ∈ Term ] (q sn⟶* p' × r sn⟶* p')
1-stepl cb psn⟶₁q
(rcontext [] dchole psn⟶₁r) =
1-step-sn⟶₁ cb psn⟶₁q psn⟶₁r
1-stepl cb (rpar-done-right p' q')
(rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) =
⊥-elim (halted-¬sn⟶ p' (rcontext _ dcr psn⟶₁r))
1-stepl cb (rpar-done-left (dhalted p') q')
(rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) =
⊥-elim (halted-¬sn⟶ p' (rcontext _ dcr psn⟶₁r))
1-stepl cb (rpar-done-left (dpaused p') hnothin)
(rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ dcr psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ dchole
(rpar-done-left
(dpaused (paused-sn⟶ p' (rcontext _ dcr psn⟶₁r)))
hnothin))
1-stepl cb (rpar-done-left (dpaused p') (hexit n))
(rcontext (ceval (epar₁ _) ∷ crs) (dcpar₁ dcr) psn⟶₁r) =
_ ,
rrefl ,′
sn⟶*-inclusion (rcontext _ dchole
(rpar-done-left
(dpaused (paused-sn⟶ p' (rcontext _ dcr psn⟶₁r)))
(hexit n)))
1-stepl cb (rpar-done-right p' (dhalted q'))
(rcontext (ceval (epar₂ p₁) ∷ crs) (dcpar₂ dcr) psn⟶₁r) =
⊥-elim (halted-¬sn⟶ q' (rcontext _ dcr psn⟶₁r))
1-stepl cb (rpar-done-right hnothin (dpaused q'))
(rcontext (ceval (epar₂ .nothin) ∷ crs) (dcpar₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ dcr psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ dchole
(rpar-done-right
hnothin
(dpaused (paused-sn⟶ q' (rcontext _ dcr psn⟶₁r)))))
1-stepl cb (rpar-done-right (hexit n) (dpaused q'))
(rcontext (ceval (epar₂ .(exit n)) ∷ crs) (dcpar₂ dcr) psn⟶₁r) =
_ ,
rrefl ,′
sn⟶*-inclusion (rcontext _ dchole
(rpar-done-right
(hexit n)
(dpaused (paused-sn⟶ q' (rcontext _ dcr psn⟶₁r)))))
1-stepl cb (rpar-done-left p' q')
(rcontext (ceval (epar₂ p₁) ∷ crs) (dcpar₂ dcr) psn⟶₁r) =
⊥-elim (halted-¬sn⟶ q' (rcontext _ dcr psn⟶₁r))
1-stepl cb rseq-done
(rcontext _ (dcseq₁ dchole) psn⟶₁r) =
⊥-elim (halted-¬sn⟶₁ hnothin psn⟶₁r)
1-stepl cb rseq-exit
(rcontext _ (dcseq₁ dchole) psn⟶₁r) =
⊥-elim (halted-¬sn⟶₁ (hexit _) psn⟶₁r)
1-stepl cb rloopˢ-exit
(rcontext _ (dcloopˢ₁ dchole) psn⟶₁r) =
⊥-elim (halted-¬sn⟶₁ (hexit _) psn⟶₁r)
1-stepl cb (rsuspend-done p')
(rcontext (ceval (esuspend S) ∷ crs) (dcsuspend dcr) psn⟶₁r) =
⊥-elim (halted-¬sn⟶₁ (halted-⟦⟧c p' dcr) psn⟶₁r)
1-stepl cb (rtrap-done p')
(rcontext (ceval etrap ∷ crs) (dctrap dcr) psn⟶₁r) =
⊥-elim (halted-¬sn⟶₁ (halted-⟦⟧c p' dcr) psn⟶₁r)
1-stepl cb rraise-signal (rcontext (csignl S ∷ crs) (dcsignl dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcenv dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ dchole rraise-signal)
1-stepl cb rloop-unroll
(rcontext (cloop ∷ crs) (dcloop dcr) psn⟶₁r) =
_ ,
rstep (rcontext _ (dcloopˢ₁ dcr) psn⟶₁r)
(rstep (rcontext _ (dcloopˢ₂ dcr) psn⟶₁r) rrefl) ,′
sn⟶*-inclusion (rcontext [] dchole rloop-unroll)
1-stepl cb rseq-done
(rcontext (cseq₂ .nothin ∷ crs) (dcseq₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ dcr psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ dchole rseq-done)
1-stepl cb rseq-exit
(rcontext (cseq₂ .(exit _) ∷ crs) (dcseq₂ dcr) psn⟶₁r) =
_ ,
rrefl ,′
sn⟶*-inclusion (rcontext _ dchole rseq-exit)
1-stepl cb rloopˢ-exit
(rcontext (cloopˢ₂ .(exit _) ∷ crs) (dcloopˢ₂ dcr) psn⟶₁r) =
_ ,
rrefl ,′
sn⟶*-inclusion (rcontext _ dchole rloopˢ-exit)
1-stepl {ρ⟨ .θ , .A ⟩· p} cb
ρθpsn⟶₁q
ρθpsn⟶r@(rcontext {p = p₂} {p' = r} (cenv θ A ∷ crs) (dcenv p≐crs⟦p₂⟧) p₂sn⟶₁r)
with ρ-stays-ρ-sn⟶₁ ρθpsn⟶₁q
... | θ' , A' , qin , refl =
1-steplρ cb ρθpsn⟶₁q (rcontext crs p≐crs⟦p₂⟧ p₂sn⟶₁r)
1-step : ∀{p q r BV FV} →
CorrectBinding p BV FV →
p sn⟶ q →
p sn⟶ r →
Σ[ p' ∈ Term ] (q sn⟶* p' × r sn⟶* p')
1-step cb (rcontext [] dchole psn⟶₁q) psn⟶r = 1-stepl cb psn⟶₁q psn⟶r
1-step cb
psn⟶q@(rcontext (_ ∷ _) _ _) (rcontext [] dchole psn⟶₁r) with 1-stepl cb psn⟶₁r psn⟶q
... | _ , rsn⟶*p' , qsn⟶*p' = _ , qsn⟶*p' ,′ rsn⟶*p'
1-step cb@(CBpar cbp cbq _ _ _ _)
(rcontext (cq ∷ cqs) (dcpar₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpar₁ dcr) psn⟶₁r)
with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBpar cbp cbq _ _ _ _)
(rcontext (cq ∷ cqs) (dcpar₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpar₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcpar₂ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcpar₁ dcq) psn⟶₁q)
1-step cb@(CBpar cbp cbq _ _ _ _)
(rcontext (cq ∷ cqs) (dcpar₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpar₁ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcpar₁ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcpar₂ dcq) psn⟶₁q)
1-step cb@(CBpar cbp cbq _ _ _ _)
(rcontext (cq ∷ cqs) (dcpar₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpar₂ dcr) psn⟶₁r)
with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBseq cbp cbq _)
(rcontext (cq ∷ cqs) (dcseq₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcseq₁ dcr) psn⟶₁r)
with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb
(rcontext (cq ∷ cqs) (dcseq₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcseq₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcseq₂ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcseq₁ dcq) psn⟶₁q)
1-step cb
(rcontext (cq ∷ cqs) (dcseq₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcseq₁ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcseq₁ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcseq₂ dcq) psn⟶₁q)
1-step cb@(CBseq cbp cbq _)
(rcontext (cq ∷ cqs) (dcseq₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcseq₂ dcr) psn⟶₁r)
with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBloopˢ cbp cbq _ _)
(rcontext (cq ∷ cqs) (dcloopˢ₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcloopˢ₁ dcr) psn⟶₁r)
with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb
(rcontext (cq ∷ cqs) (dcloopˢ₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcloopˢ₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcloopˢ₂ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcloopˢ₁ dcq) psn⟶₁q)
1-step cb
(rcontext (cq ∷ cqs) (dcloopˢ₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcloopˢ₁ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcloopˢ₁ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcloopˢ₂ dcq) psn⟶₁q)
1-step cb@(CBloopˢ cbp cbq _ _)
(rcontext (cq ∷ cqs) (dcloopˢ₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcloopˢ₂ dcr) psn⟶₁r)
with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBsusp cb' _)
(rcontext (cq ∷ cqs) (dcsuspend dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcsuspend dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBtrap cb')
(rcontext (cq ∷ cqs) (dctrap dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dctrap dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBsig cb')
(rcontext (cq ∷ cqs) (dcsignl dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcsignl dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBpresent cbp cbq)
(rcontext (cq ∷ cqs) (dcpresent₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpresent₁ dcr) psn⟶₁r)
with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb
(rcontext (cq ∷ cqs) (dcpresent₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpresent₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcpresent₂ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcpresent₁ dcq) psn⟶₁q)
1-step cb
(rcontext (cq ∷ cqs) (dcpresent₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpresent₁ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcpresent₁ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcpresent₂ dcq) psn⟶₁q)
1-step cb@(CBpresent cbp cbq)
(rcontext (cq ∷ cqs) (dcpresent₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcpresent₂ dcr) psn⟶₁r)
with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBloop cb' _)
(rcontext (cq ∷ cqs) (dcloop dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcloop dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBshared cb')
(rcontext (cq ∷ cqs) (dcshared dcq) psn⟶₁q) (rcontext (cr ∷ crs) (dcshared dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBvar cb')
(rcontext (cq ∷ cqs) (dcvar dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcvar dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBif cbp cbq)
(rcontext (cq ∷ cqs) (dcif₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcif₁ dcr) psn⟶₁r)
with 1-step cbp (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb
(rcontext (cq ∷ cqs) (dcif₁ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcif₂ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcif₂ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcif₁ dcq) psn⟶₁q)
1-step cb
(rcontext (cq ∷ cqs) (dcif₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcif₁ dcr) psn⟶₁r) =
_ ,
sn⟶*-inclusion (rcontext _ (dcif₁ dcr) psn⟶₁r) ,′
sn⟶*-inclusion (rcontext _ (dcif₂ dcq) psn⟶₁q)
1-step cb@(CBif cbp cbq)
(rcontext (cq ∷ cqs) (dcif₂ dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcif₂ dcr) psn⟶₁r)
with 1-step cbq (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
1-step cb@(CBρ cb')
(rcontext (cq ∷ cqs) (dcenv dcq) psn⟶₁q)
(rcontext (cr ∷ crs) (dcenv dcr) psn⟶₁r)
with 1-step cb' (rcontext cqs dcq psn⟶₁q) (rcontext crs dcr psn⟶₁r)
... | p'' , q'sn⟶*p'' , r'sn⟶*p'' = _ , Context1-sn⟶* cq q'sn⟶*p'' ,′ Context1-sn⟶* cr r'sn⟶*p''
| {
"alphanum_fraction": 0.5917344173,
"avg_line_length": 41.6949152542,
"ext": "agda",
"hexsha": "57aba13abe277a62d2890838e77d1e4287efd81d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-compatconf.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-compatconf.agda",
"max_line_length": 97,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-compatconf.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 7100,
"size": 14760
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An example of how Data.Fin.Substitution can be used: a definition
-- of substitution for the untyped λ-calculus, along with some lemmas
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Substitution.Example where
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Nat
open import Data.Fin using (Fin)
open import Data.Vec
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl; sym; cong; cong₂)
open PropEq.≡-Reasoning
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
using (Star; ε; _◅_)
-- A representation of the untyped λ-calculus. Uses de Bruijn indices.
infixl 9 _·_
data Tm (n : ℕ) : Set where
var : (x : Fin n) → Tm n
ƛ : (t : Tm (suc n)) → Tm n
_·_ : (t₁ t₂ : Tm n) → Tm n
-- Code for applying substitutions.
module TmApp {ℓ} {T : ℕ → Set ℓ} (l : Lift T Tm) where
open Lift l hiding (var)
-- Applies a substitution to a term.
infix 8 _/_
_/_ : ∀ {m n} → Tm m → Sub T m n → Tm n
var x / ρ = lift (lookup ρ x)
ƛ t / ρ = ƛ (t / ρ ↑)
t₁ · t₂ / ρ = (t₁ / ρ) · (t₂ / ρ)
open Application (record { _/_ = _/_ }) using (_/✶_)
-- Some lemmas about _/_.
ƛ-/✶-↑✶ : ∀ k {m n t} (ρs : Subs T m n) →
ƛ t /✶ ρs ↑✶ k ≡ ƛ (t /✶ ρs ↑✶ suc k)
ƛ-/✶-↑✶ k ε = refl
ƛ-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (ƛ-/✶-↑✶ k ρs) refl
·-/✶-↑✶ : ∀ k {m n t₁ t₂} (ρs : Subs T m n) →
t₁ · t₂ /✶ ρs ↑✶ k ≡ (t₁ /✶ ρs ↑✶ k) · (t₂ /✶ ρs ↑✶ k)
·-/✶-↑✶ k ε = refl
·-/✶-↑✶ k (ρ ◅ ρs) = cong₂ _/_ (·-/✶-↑✶ k ρs) refl
tmSubst : TermSubst Tm
tmSubst = record { var = var; app = TmApp._/_ }
open TermSubst tmSubst hiding (var)
-- Substitution lemmas.
tmLemmas : TermLemmas Tm
tmLemmas = record
{ termSubst = tmSubst
; app-var = refl
; /✶-↑✶ = Lemma./✶-↑✶
}
where
module Lemma {T₁ T₂} {lift₁ : Lift T₁ Tm} {lift₂ : Lift T₂ Tm} where
open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)
open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)
/✶-↑✶ : ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) →
∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k
/✶-↑✶ ρs₁ ρs₂ hyp k (var x) = hyp k x
/✶-↑✶ ρs₁ ρs₂ hyp k (ƛ t) = begin
ƛ t /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.ƛ-/✶-↑✶ _ k ρs₁ ⟩
ƛ (t /✶₁ ρs₁ ↑✶₁ suc k) ≡⟨ cong ƛ (/✶-↑✶ ρs₁ ρs₂ hyp (suc k) t) ⟩
ƛ (t /✶₂ ρs₂ ↑✶₂ suc k) ≡⟨ sym (TmApp.ƛ-/✶-↑✶ _ k ρs₂) ⟩
ƛ t /✶₂ ρs₂ ↑✶₂ k ∎
/✶-↑✶ ρs₁ ρs₂ hyp k (t₁ · t₂) = begin
t₁ · t₂ /✶₁ ρs₁ ↑✶₁ k ≡⟨ TmApp.·-/✶-↑✶ _ k ρs₁ ⟩
(t₁ /✶₁ ρs₁ ↑✶₁ k) · (t₂ /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _·_ (/✶-↑✶ ρs₁ ρs₂ hyp k t₁)
(/✶-↑✶ ρs₁ ρs₂ hyp k t₂) ⟩
(t₁ /✶₂ ρs₂ ↑✶₂ k) · (t₂ /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (TmApp.·-/✶-↑✶ _ k ρs₂) ⟩
t₁ · t₂ /✶₂ ρs₂ ↑✶₂ k ∎
open TermLemmas tmLemmas public hiding (var)
| {
"alphanum_fraction": 0.486631016,
"avg_line_length": 33.1145833333,
"ext": "agda",
"hexsha": "edb7c3a874e290d0a3bdfe6732ef5cbb59def3a8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Example.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Example.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1503,
"size": 3179
} |
open import Agda.Builtin.Nat
interleaved mutual
plus : Nat → Nat → Nat
mult : Nat → Nat → Nat
-- base case
mult 0 n = 0
plus 0 n = n
-- inductive case. The fun clauses with an ellipsis belong to mult
mult (suc m) n with mult m n
... | p with plus p n
... | q = q
plus (suc m) n = suc (plus m n)
open import Agda.Builtin.Equality
proof : ∀ m n → mult (suc m) n ≡ plus (mult m n) n
proof m n with mult m n
... | p with plus p n
... | q = refl
| {
"alphanum_fraction": 0.5995717345,
"avg_line_length": 19.4583333333,
"ext": "agda",
"hexsha": "50cc4fb1407599a4a1d7aff5802a222c66bc8207",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2858-with.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2858-with.agda",
"max_line_length": 68,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2858-with.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 169,
"size": 467
} |
------------------------------------------------------------------------------
-- Testing some inductive predicates for inequalities
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Data.Nat.Inequalities.InductivePredicates where
open import FOTC.Base
open import FOTC.Data.Nat.Type
open import FOTC.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
module m₁ where
data _≤_ : D → D → Set where
z≤n : ∀ n → zero ≤ n
s≤s : ∀ {m n} → m ≤ n → succ₁ m ≤ succ₁ n
_<_ : D → D → Set
m < n = succ₁ m ≤ n
_≥_ : D → D → Set
m ≥ n = n ≤ m
_>_ : D → D → Set
m > n = n < m
x≤y→x≤Sy : ∀ {m n} → m ≤ n → m ≤ succ₁ n
x≤y→x≤Sy {.zero} {n} (z≤n .n) = z≤n (succ₁ n)
x≤y→x≤Sy (s≤s m≤n) = s≤s (x≤y→x≤Sy m≤n)
module m₂ where
data _≤_ : D → D → Set where
z≤n : ∀ {n} → N n → zero ≤ n
s≤s : ∀ {m n} → N m → N n → m ≤ n → succ₁ m ≤ succ₁ n
_<_ : D → D → Set
m < n = succ₁ m ≤ n
_≥_ : D → D → Set
m ≥ n = n ≤ m
_>_ : D → D → Set
m > n = n < m
x≤y→x≤Sy : ∀ {m n} → m ≤ n → m ≤ succ₁ n
x≤y→x≤Sy (z≤n Nn) = z≤n (nsucc Nn)
x≤y→x≤Sy (s≤s Nm Nn m≤n) = s≤s Nm (nsucc Nn) (x≤y→x≤Sy m≤n)
postulate
lt : D → D → D
lt-00 : lt zero zero ≡ false
lt-0S : ∀ n → lt zero (succ₁ n) ≡ true
lt-S0 : ∀ n → lt (succ₁ n) zero ≡ false
lt-SS : ∀ m n → lt (succ₁ m) (succ₁ n) ≡ lt m n
le : D → D → D
le m n = lt m (succ₁ n)
≤→le : ∀ {m n} → m ≤ n → le m n ≡ true
≤→le {n = n} (z≤n Nn) = lt-0S n
≤→le (s≤s nzero nzero h) = trans (lt-SS zero 1') (≤→le h)
≤→le (s≤s nzero (nsucc {n} Nn) h) = trans (lt-SS zero (succ₁ (succ₁ n))) (≤→le h)
≤→le (s≤s (nsucc {m} Nm) nzero h) = trans (lt-SS (succ₁ m) 1') (≤→le h)
≤→le (s≤s (nsucc {m} Nm) (nsucc {n} Nn) h) =
trans (lt-SS (succ₁ m) (succ₁ (succ₁ n))) (≤→le h)
le→≤ : ∀ {m n} → N m → N n → le m n ≡ true → m ≤ n
le→≤ nzero Nn h = z≤n Nn
le→≤ (nsucc nzero) nzero h =
⊥-elim (t≢f (trans (sym h) (trans (lt-SS zero zero) lt-00)))
le→≤ (nsucc (nsucc {m} Nm)) nzero h =
⊥-elim (t≢f (trans (sym h) (trans (lt-SS (succ₁ m) zero) (lt-S0 m))))
{-# CATCHALL #-}
le→≤ (nsucc {m} Nm) (nsucc {n} Nn) h =
s≤s Nm Nn (le→≤ Nm Nn (trans (sym (lt-SS m (succ₁ n))) h))
module m₃ where
data _≤_ : ∀ {m n} → N m → N n → Set where
z≤n : ∀ {n} → (Nn : N n) → nzero ≤ Nn
s≤s : ∀ {m n} → (Nm : N m) → (Nn : N n) → Nm ≤ Nn → nsucc Nm ≤ nsucc Nn
_<_ : ∀ {m n} → N m → N n → Set
Nm < Nn = nsucc Nm ≤ Nn
_≥_ : ∀ {m n} → N m → N n → Set
Nm ≥ Nn = Nn ≤ Nm
_>_ : ∀ {m n} → N m → N n → Set
Nm > Nn = Nn < Nm
x≤y→x≤Sy : ∀ {m n} → (Nm : N m) → (Nn : N n) → Nm ≤ Nn → Nm ≤ nsucc Nn
x≤y→x≤Sy .nzero Nn (z≤n .Nn) = z≤n (nsucc Nn)
x≤y→x≤Sy .(nsucc Nm) .(nsucc Nn) (s≤s Nm Nn Nm≤Nn) =
s≤s Nm (nsucc Nn) (x≤y→x≤Sy Nm Nn Nm≤Nn)
| {
"alphanum_fraction": 0.42496,
"avg_line_length": 31.25,
"ext": "agda",
"hexsha": "b86068ac59016de3250a0912f49da560af7b1e6b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Data/Nat/Inequalities/InductivePredicates.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Data/Nat/Inequalities/InductivePredicates.agda",
"max_line_length": 83,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Data/Nat/Inequalities/InductivePredicates.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1454,
"size": 3125
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Reasoning.Equality where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
private
variable
ℓ : Level
A : Type ℓ
infixr 1 _≡⟨⟩_ _≡⟨_⟩_ _≡˘⟨_⟩_
infix 2 _∎
-- Step with a non-trivial propositional equality
_≡⟨_⟩_ : ∀ x {y z : A} → x ≡ y → y ≡ z → x ≡ z
_≡⟨_⟩_ x = _∙_
-- Step with a flipped non-trivial propositional equality
_≡˘⟨_⟩_ : ∀ x {y z : A} → y ≡ x → y ≡ z → x ≡ z
x ≡˘⟨ y≡x ⟩ y≡z = x ≡⟨ sym y≡x ⟩ y≡z
-- Step with a trivial propositional equality
_≡⟨⟩_ : ∀ x {y : A} → x ≡ y → x ≡ y
_ ≡⟨⟩ x≡y = x≡y
-- Syntax for path definition
≡⟨⟩-syntax : ∀ x {y z : A} → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 1 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
≡˘⟨⟩-syntax : ∀ x {y z : A} → y ≡ x → y ≡ z → x ≡ z
≡˘⟨⟩-syntax = _≡˘⟨_⟩_
infixr 1 ≡˘⟨⟩-syntax
syntax ≡˘⟨⟩-syntax x (λ i → B) y = x ≡˘[ i ]⟨ B ⟩ y
-- Termination step
_∎ : ∀ (x : A) → x ≡ x
x ∎ = refl
| {
"alphanum_fraction": 0.5380811078,
"avg_line_length": 21.9782608696,
"ext": "agda",
"hexsha": "20d9d5020a7a0746d95c4cd010733b58f0f77283",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Reasoning/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Reasoning/Equality.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Reasoning/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 520,
"size": 1011
} |
module Numeral.Natural.Relation where
open import Data.Boolean.Stmt
open import Numeral.Natural
open import Numeral.Natural.Oper.Comparisons
open import Logic.Propositional
open import Logic
import Lvl
open import Relator.Equals
open import Type
Positive : ℕ → Stmt
Positive(n) = IsTrue(positive? n)
zero-not-positive : ¬ Positive(𝟎)
zero-not-positive ()
positive-not-zero : ∀{n} → ⦃ _ : Positive(n) ⦄ → (n ≢ 𝟎)
positive-not-zero {𝟎} ⦃ pos ⦄ _ = pos
non-zero-positive : ∀{n} → (n ≢ 𝟎) → Positive(n)
non-zero-positive {𝟎} p = p [≡]-intro
non-zero-positive {𝐒 n} p = [⊤]-intro
| {
"alphanum_fraction": 0.6984667802,
"avg_line_length": 24.4583333333,
"ext": "agda",
"hexsha": "921027508c716cd596f94e5d4bc869e53889cbe5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Relation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Relation.agda",
"max_line_length": 56,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Relation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 200,
"size": 587
} |
{-# OPTIONS --without-K --safe #-}
module Algebra.Linear.Structures.Bundles where
open import Algebra
open import Level using (Level; suc; _⊔_)
open import Relation.Binary using (Rel; IsEquivalence)
open import Algebra.FunctionProperties
open import Algebra.Structures.Field
open import Algebra.Structures.Bundles.Field
open import Algebra.Linear.Structures.VectorSpace
record RawVectorSpace {k ℓᵏ} (K : Field k ℓᵏ) (c ℓ : Level) : Set (suc (c ⊔ k ⊔ ℓ)) where
infix 20 _≈_
infixl 25 _+_
infixr 30 _∙_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Carrier -> Carrier -> Carrier
_∙_ : Field.Carrier K -> Carrier -> Carrier
-_ : Carrier -> Carrier
0# : Carrier
rawGroup : RawGroup c ℓ
rawGroup = record { _≈_ = _≈_; _∙_ = _+_; ε = 0#; _⁻¹ = -_ }
open RawGroup rawGroup public
using (rawMagma; rawMonoid)
record VectorSpace {k ℓᵏ} (K : Field k ℓᵏ) (c ℓ : Level) : Set (suc (c ⊔ k ⊔ ℓ ⊔ ℓᵏ)) where
infix 20 _≈_
infixl 25 _+_
infixr 30 _∙_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Carrier -> Carrier -> Carrier
_∙_ : Field.Carrier K -> Carrier -> Carrier
-_ : Carrier -> Carrier
0# : Carrier
isVectorSpace : IsVectorSpace K _≈_ _+_ _∙_ -_ 0#
open IsVectorSpace isVectorSpace public
rawVectorSpace : RawVectorSpace K c ℓ
rawVectorSpace = record
{ _≈_ = _≈_; _+_ = _+_; _∙_ = _∙_; -_ = -_; 0# = 0# }
abelianGroup : AbelianGroup c ℓ
abelianGroup = record { isAbelianGroup = isAbelianGroup }
open AbelianGroup abelianGroup public
using (rawMagma; magma; rawMonoid; monoid; rawGroup; group)
| {
"alphanum_fraction": 0.6146682189,
"avg_line_length": 29.6206896552,
"ext": "agda",
"hexsha": "cd552e34c0b1a00772c73950f69b73b8542bb216",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Structures/Bundles.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Structures/Bundles.agda",
"max_line_length": 91,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Structures/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 581,
"size": 1718
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Numbers.ClassicalReals.RealField
open import LogicalFormulae
open import Setoids.Subset
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Sets.EquivalenceRelations
open import Rings.Orders.Partial.Definition
open import Rings.Definition
open import Fields.Fields
open import Groups.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Functions.Definition
module Numbers.Intervals.Definition {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {_<_ : Rel {_} {c} A} {R : Ring S _+_ _*_} {pOrder : SetoidPartialOrder S _<_} (pRing : PartiallyOrderedRing R pOrder) where
record OpenInterval : Set a where
field
minBound : A
maxBound : A
isInInterval : A → OpenInterval → Set c
isInInterval a record { minBound = min ; maxBound = max } = (min < a) && (a < max)
| {
"alphanum_fraction": 0.738990333,
"avg_line_length": 35.8076923077,
"ext": "agda",
"hexsha": "d659c28dfb6925dce7f08a5177c34f5ad81d574c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Intervals/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Intervals/Definition.agda",
"max_line_length": 229,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Intervals/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 263,
"size": 931
} |
open import Prelude
module Implicits.Resolution.Finite.Algorithm where
open import Induction.WellFounded
open import Induction.Nat
open import Data.Fin.Substitution
open import Data.Nat.Base using (_<′_)
open import Data.List.Any
open Membership-≡
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification
open import Implicits.Syntax.Type.Unification.Lemmas
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Implicits.Resolution.Finite.Resolution
open import Implicits.Resolution.Termination
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Function.Equality hiding (cong; flip; const)
open import Data.List.Any.Properties using (Any↔)
open import Data.Nat hiding (_<_)
open import Data.Nat.Properties
open import Relation.Binary using (module DecTotalOrder)
open DecTotalOrder decTotalOrder using () renaming
(refl to ≤-refl; trans to ≤-trans)
open Lexicographic using (left; right)
module M = MetaTypeMetaSubst
module Lemmas where
postulate lem₄ : ∀ {m ν} (a : MetaType m (suc ν)) u us → from-meta ((M.open-meta a) M./ (us M.↑) M./ (M.sub u)) ≡ (from-meta (a M./ (us M.↑tp))) tp[/tp from-meta u ]
m<-Acc : ∀ {m ν} → MetaType m ν → Set
m<-Acc {m} {ν} r = Acc _m<_ (m , ν , r)
ρ<-Acc : ∀ {ν} → Type ν → Set
ρ<-Acc {ν} r = Acc _ρ<_ (ν , r)
module Arg<-well-founded where
open Lexicographic (_N<_) (const _ρ<_)
open import Induction.Nat
open import Data.Nat.Properties
module image = Subrelation {A = ℕ} {_N<_} {_<′_} ≤⇒≤′
arg<-well-founded : Well-founded _<_
arg<-well-founded = well-founded (image.well-founded <-well-founded) ρ<-well-founded
_arg<_ = _<_
-- Accessibility of the 'goal' type during resolution.
-- Either the *head* of the goal shrinks (Oliveira's termination condition)
-- Or the head size remains equal and the goal shrinks in an absolute sense.
Arg<-Acc : ∀ {ν} → Type ν → Set
Arg<-Acc a = Acc _arg<_ (h|| a || , (, a))
open Arg<-well-founded using (Arg<-Acc; arg<-well-founded) public
lem₆ : ∀ {ν μ} (a : Type ν) (b : Type (suc μ)) c → (, a) hρ< (, b) → (, a) hρ< (, b tp[/tp c ])
lem₆ a b c p = ≤-trans p (h||a/s|| b (TypeSubst.sub c))
where open SubstSizeLemmas
lem₅ : ∀ {ν μ} {Δ : ICtx ν} {b τ} (a : Type μ) → Δ ⊢ b ↓ τ → (, a) hρ< (, b) → (, a) hρ< (, simpl τ)
lem₅ {τ = τ} a (i-simp .τ) q = q
lem₅ a (i-iabs _ _ p) q = lem₅ a p q
lem₅ a (i-tabs {ρ = b} c p) q = lem₅ a p (lem₆ a b c q)
open Lemmas
mutual
match' : ∀ {m ν ρ} (Δ : ICtx ν) (r∈Δ : ρ List.∈ Δ) τ → (r : MetaType m ν) →
Arg<-Acc (simpl τ) →
m<-Acc r →
Maybe (∃ λ u → Δ ⊢ from-meta (r M./ u) ↓ τ)
match' Δ r∈Δ τ (simpl x) f g with mgu (simpl x) τ | sound (simpl x) τ
match' Δ r∈Δ τ (simpl x) f g | just u | just u-unifies =
just (u , subst (λ a → Δ ⊢ a ↓ τ) (sym u-unifies) (i-simp τ))
match' Δ r∈Δ τ (simpl x) f g | nothing | _ = nothing
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) with match' Δ r∈Δ τ b (acc f) (g _ (b-m<-a⇒b a b))
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) | nothing = nothing
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) | just (u , b/u↓τ)
with (from-meta (a M./ u)) hρ<? (from-meta (b M./ u))
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) | just (u , b/u↓τ) | yes ρ₁<
with resolve' Δ (from-meta (a M./ u)) (f _ (left (lem₅ (from-meta (a M./ u)) b/u↓τ ρ₁<)))
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) | just (u , b/u↓τ) | yes ρ₁< | just ⊢ᵣa =
just (u , i-iabs ρ₁< ⊢ᵣa b/u↓τ)
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) | just (u , b/u↓τ) | yes _ | nothing = nothing
match' Δ r∈Δ τ (a ⇒ b) (acc f) (acc g) | just (u , b/u↓τ) | no p = nothing
match' Δ r∈Δ τ (∀' a) f (acc g) with match' Δ r∈Δ τ (open-meta a) f (g _ (open-meta-a-m<-∀'a a))
match' Δ r∈Δ τ (∀' a) f (acc g) | just p = just $ lem p
where
lem : (∃ λ u → Δ ⊢ (from-meta ((open-meta a) M./ u)) ↓ τ) →
∃ λ u' → Δ ⊢ (from-meta (∀' a M./ u')) ↓ τ
lem (u ∷ us , p) = us , (i-tabs (from-meta u) (subst (λ v → Δ ⊢ v ↓ τ) (begin
from-meta (M._/_ (open-meta a) (u ∷ us))
≡⟨ cong (λ v → from-meta (M._/_ (open-meta a) v)) (sym $ us↑-⊙-sub-u≡u∷us u us) ⟩
from-meta ((open-meta a) M./ (us M.↑ M.⊙ (M.sub u)))
≡⟨ cong from-meta (/-⊙ (open-meta a)) ⟩
from-meta ((open-meta a) M./ us M.↑ M./ (M.sub u))
≡⟨ lem₄ a u us ⟩
from-meta (M._/_ a (us M.↑tp)) tp[/tp from-meta u ] ∎) p))
where open MetaTypeMetaLemmas hiding (subst)
match' Δ r∈Δ τ (∀' r) f (acc g) | nothing = nothing
-- match defers to match', which concerns itself with MetaTypes.
-- If match' finds a match, we can use the fact that we have zero unification variables open here
-- to show that we found the right thing.
match : ∀ {ν ρ} (Δ : ICtx ν) (r∈Δ : ρ List.∈ Δ) r τ → Arg<-Acc (simpl τ) → Maybe (Δ ⊢ r ↓ τ)
match Δ r∈Δ a τ f with match' Δ r∈Δ τ (to-meta {zero} a) f (m<-well-founded _)
match Δ r∈Δ a τ f | just x = just (lem x)
where
eq : ∀ {ν} {a : Type ν} {s} → from-meta (to-meta {zero} a M./ s) ≡ a
eq {a = a} {s = []} = begin
from-meta (M._/_ (to-meta {zero} a) [])
≡⟨ cong (λ q → from-meta q) (MetaTypeMetaLemmas.id-vanishes (to-meta {zero} a)) ⟩
from-meta (to-meta {zero} a)
≡⟨ to-meta-zero-vanishes ⟩
a ∎
lem : ∃ (λ u → Δ ⊢ from-meta (to-meta {zero} a M./ u) ↓ τ) →
Δ ⊢ a ↓ τ
lem ([] , proj₂) = subst (λ u → Δ ⊢ u ↓ τ) eq proj₂
match Δ r∈Δ a τ f | nothing = nothing
match1st : ∀ {ν} (Δ : ICtx ν) τ → Arg<-Acc (simpl τ) →
Maybe (∃₂ λ r (r∈Δ : r List.∈ Δ) → Δ ⊢ r ↓ τ)
match1st {ν = ν} Δ τ f = match1st' Δ Prelude.id
where
match1st' : ∀ (ρs : ICtx ν) → ρs ⊆ Δ → Maybe (∃₂ λ r (r∈Δ : r List.∈ Δ) → Δ ⊢ r ↓ τ)
match1st' List.[] sub = nothing
match1st' (x List.∷ xs) sub with match Δ (sub (here refl)) x τ f
match1st' (x List.∷ xs) sub | just px = just (x , ((sub (here refl)) , px))
match1st' (x List.∷ xs) sub | nothing with match1st' xs (λ r∈xs → sub (there r∈xs))
match1st' (x List.∷ xs) sub | nothing | just p = just p
match1st' (x List.∷ xs) sub | nothing | nothing = nothing
resolve' : ∀ {ν} (Δ : ICtx ν) r → Arg<-Acc r → (Maybe (Δ ⊢ᵣ r))
resolve' Δ (simpl x) f with match1st Δ x f
resolve' Δ (simpl x) f | just (_ , r∈Δ , r↓x) = just (r-simp r∈Δ r↓x)
resolve' Δ (simpl x) f | nothing = nothing
resolve' Δ (a ⇒ b) (acc f) with resolve' (a List.∷ Δ) b (f _ (right (b-ρ<-a⇒b a b)))
resolve' Δ (a ⇒ b) (acc f) | just p = just (r-iabs p)
resolve' Δ (a ⇒ b) (acc f) | nothing = nothing
resolve' Δ (∀' r) (acc f) with resolve' (ictx-weaken Δ) r (f _ (right (a-ρ<-∀a r)))
resolve' Δ (∀' r) (acc f) | just p = just (r-tabs p)
resolve' Δ (∀' r) (acc f) | nothing = nothing
resolve : ∀ {ν} (Δ : ICtx ν) r → (Maybe (Δ ⊢ᵣ r))
resolve Δ r = resolve' Δ r (arg<-well-founded _)
| {
"alphanum_fraction": 0.5604948928,
"avg_line_length": 45.7302631579,
"ext": "agda",
"hexsha": "eb2ebe54e1a4889688d5baebd562534f42116c15",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Finite/Algorithm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Finite/Algorithm.agda",
"max_line_length": 167,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Finite/Algorithm.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 2774,
"size": 6951
} |
-- Check that unquoted functions are termination checked.
module _ where
open import Common.Prelude hiding (_>>=_)
open import Common.Reflection
`⊥ : Type
`⊥ = def (quote ⊥) []
data Box : Set where
box : ⊥ → Box
unbox : Box → ⊥
unbox (box x) = x
`Box : Type
`Box = def (quote Box) []
{-
Generate
aux : Box
aux = box (unbox aux)
-}
makeLoop : TC ⊤
makeLoop =
freshName "aux" >>= λ aux →
declareDef (iArg aux) `Box >>= λ _ →
defineFun aux (clause [] (con (quote box) (vArg (def (quote unbox) (vArg (def aux []) ∷ [])) ∷ [])) ∷ [])
unquoteDecl = makeLoop
it : ∀ {a} {A : Set a} {{_ : A}} → A
it {{x}} = x
loop : ⊥
loop = unbox it
| {
"alphanum_fraction": 0.5817901235,
"avg_line_length": 17.5135135135,
"ext": "agda",
"hexsha": "93950aae2367ffd2a6e7644d629febb73e7e9c77",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/TerminationCheckUnquoteDeclUnnamed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/TerminationCheckUnquoteDeclUnnamed.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/TerminationCheckUnquoteDeclUnnamed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 235,
"size": 648
} |
{-# OPTIONS --cubical --safe #-}
module Issue3577 where
open import Agda.Primitive.Cubical renaming (primTransp to transp; primHComp to hcomp)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Sigma
open import Agda.Builtin.Cubical.Sub renaming (primSubOut to ouc; Sub to _[_↦_])
refl : ∀ {l} {A : Set l} {x : A} → x ≡ x
refl {x = x} = \ _ → x
ptType : Set₁
ptType = Σ Set (λ A → A)
data Susp' (A : ptType) : Set where
susp* : Susp' A
-- Non-computation of transp on non-HIT's hcomp
testTr : {A' : ptType} (ψ : I) (A : I → ptType [ ψ ↦ (\ _ → A') ])
{φ : I}
(u : ∀ i → Partial φ (Susp' (ouc (A i0))))
(u0 : Susp' (ouc (A i0)) [ φ ↦ u i0 ])
→ transp (\ i -> Susp' (ouc (A i))) ψ (hcomp u (ouc u0))
≡ hcomp (λ j .o → transp (λ i → Susp' (ouc (A i))) ψ (u j o)) (transp (λ i → Susp' (ouc (A i))) ψ (ouc u0))
testTr ψ A u u0 = refl
| {
"alphanum_fraction": 0.5608938547,
"avg_line_length": 33.1481481481,
"ext": "agda",
"hexsha": "cb8b43a1f4cda6c5779b06097abeea695bd04f7b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue3577.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue3577.agda",
"max_line_length": 116,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue3577.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 358,
"size": 895
} |
postulate
D : Set
∃ : (A : D → Set) → Set
vx : D
Q₂ : D → D → Set
postulate
foo : (∃ λ x → Q₂ vx x) → (∃ λ x → Q₂ vx x)
{-# ATP prove foo #-}
-- $ apia Bug.agda
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/Apia/Utils/AgdaAPI/DeBruijn.hs:68
| {
"alphanum_fraction": 0.5789473684,
"avg_line_length": 20.2666666667,
"ext": "agda",
"hexsha": "0db770dad7b449278dcf4b3e09dc135756884698",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/Issue28.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/Issue28.agda",
"max_line_length": 63,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/Issue28.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 119,
"size": 304
} |
-- Internal hom in families
module SOAS.Abstract.Hom {T : Set} where
open import SOAS.Common
open import SOAS.Construction.Structure
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core {T}
open import SOAS.Families.Isomorphism
open import SOAS.Families.BCCC
open import SOAS.Construction.Skew.SkewClosed
open import Categories.Functor.Bifunctor
open import Categories.NaturalTransformation.Dinatural using (dtHelper)
-- Heterogeneous action of a sorted family on a family
⟨_,_⟩ : Familyₛ → Family → Family
⟨ 𝒳 , Y ⟩ Γ = (Γ ~[ 𝒳 ]↝_) ⇾ Y
⟨-,-⟩F : Bifunctor 𝔽amₛ.op 𝔽amilies 𝔽amilies
⟨-,-⟩F = record
{ F₀ = λ{ (𝒳 , Y) → ⟨ 𝒳 , Y ⟩ }
; F₁ = λ{ (f , g) o {Δ} σ → g (o (f ∘ σ)) }
; identity = refl
; homomorphism = refl
; F-resp-≈ = λ{ {f = f , g} (p , p′) {Γ} {o} → dext′ (trans (cong (g ∘ o) (dext′ p)) p′) }
}
-- Arrow mapping
⟨_,_⟩₁ : {𝒳 𝒳′ : Familyₛ} {Y Y′ : Family} → 𝒳′ ⇾̣ 𝒳 → Y ⇾ Y′ → (⟨ 𝒳 , Y ⟩ ⇾ ⟨ 𝒳′ , Y′ ⟩)
⟨ f , g ⟩₁ = Functor.₁ ⟨-,-⟩F (f , g)
-- Internal hom of sorted families
〖_,_〗 : Familyₛ → Familyₛ → Familyₛ
〖 X , Y 〗 τ = ⟨ X , Y τ ⟩
〖-,-〗F : Bifunctor 𝔽amₛ.op 𝔽amiliesₛ 𝔽amiliesₛ
〖-,-〗F = record
{ F₀ = λ{ (X , Y) → 〖 X , Y 〗 }
; F₁ = λ{ (f , g) o {Δ} σ → g (o (f ∘ σ)) }
; identity = refl
; homomorphism = refl
; F-resp-≈ = λ{ {f = f , g} (p , p′) {x = h} → dext′ (trans (cong (g ∘ h) (dext′ p)) p′) }
}
-- Arrow mapping
〖_,_〗₁ : {𝒳 𝒳′ 𝒴 𝒴′ : Familyₛ} → 𝒳′ ⇾̣ 𝒳 → 𝒴 ⇾̣ 𝒴′ → (〖 𝒳 , 𝒴 〗 ⇾̣ 〖 𝒳′ , 𝒴′ 〗)
〖 f , g 〗₁ h σ = g (h (f ∘ σ))
〖_,_〗ₗ : {𝒳 𝒳′ : Familyₛ} → 𝒳′ ⇾̣ 𝒳 → (𝒴 : Familyₛ) → (〖 𝒳 , 𝒴 〗 ⇾̣ 〖 𝒳′ , 𝒴 〗)
〖 f , Z 〗ₗ h σ = h (f ∘ σ)
〖_,_〗ᵣ : {𝒴 𝒴′ : Familyₛ} → (𝒳 : Familyₛ) → 𝒴 ⇾̣ 𝒴′ → (〖 𝒳 , 𝒴 〗 ⇾̣ 〖 𝒳 , 𝒴′ 〗)
〖 X , g 〗ᵣ h σ = g (h σ)
-- | Structure morphisms
i : (𝒳 : Familyₛ) → 〖 ℐ , 𝒳 〗 ⇾̣ 𝒳
i 𝒳 o = o id
i′ : (X : Family) → ⟨ ℐ , X ⟩ ⇾ X
i′ X o = o id
j : (𝒳 : Familyₛ) → ℐ ⇾̣ 〖 𝒳 , 𝒳 〗
j 𝒳 v σ = σ v
L : (𝒳 𝒴 𝒵 : Familyₛ) → 〖 𝒴 , 𝒵 〗 ⇾̣ 〖 〖 𝒳 , 𝒴 〗 , 〖 𝒳 , 𝒵 〗 〗
L 𝒳 Y Z o ς σ = o (λ v → ς v σ)
L′ : (𝒳 𝒴 : Familyₛ)(Z : Family) → ⟨ 𝒴 , Z ⟩ ⇾ ⟨ 〖 𝒳 , 𝒴 〗 , ⟨ 𝒳 , Z ⟩ ⟩
L′ 𝒳 𝒴 Z o ς σ = o (λ v → ς v σ)
-- Category of sorted families is skew-closed under the internal hom
𝔽amₛ:SkewClosed : SkewClosed 𝔽amiliesₛ
𝔽amₛ:SkewClosed = record
{ [-,-] = 〖-,-〗F
; unit = ℐ
; identity = ntHelper record { η = i ; commute = λ f → refl }
; diagonal = dtHelper record { α = j ; commute = λ f → refl }
; L = L
; L-commute = refl
; Lj≈j = refl
; ijL≈id = refl
; iL≈i = refl
; ij≈id = refl
; pentagon = refl
}
private
variable
𝒳 𝒴 𝒵 : Familyₛ
Y Z : Family
-- ⟨X,-⟩ distributes over and factors out of products
⟨𝒳,Y×Z⟩≅⟨𝒳,Y⟩×⟨𝒳,Z⟩ : ⟨ 𝒳 , (Y ×ₘ Z) ⟩ ≅ₘ ⟨ 𝒳 , Y ⟩ ×ₘ ⟨ 𝒳 , Z ⟩
⟨𝒳,Y×Z⟩≅⟨𝒳,Y⟩×⟨𝒳,Z⟩ = record
{ from = λ h → (λ ρ → proj₁ (h ρ)) , λ ϱ → proj₂ (h ϱ)
; to = λ{ (bx , by) ρ → bx ρ , by ρ}
; iso = record { isoˡ = refl ; isoʳ = refl }
}
-- ⟨X,-⟩ factors out of coproducts
⟨𝒳,Y⟩+⟨𝒳,Z⟩⇾⟨𝒳,Y+Z⟩ : ⟨ 𝒳 , Y ⟩ +ₘ ⟨ 𝒳 , Z ⟩ ⇾ ⟨ 𝒳 , (Y +ₘ Z) ⟩
⟨𝒳,Y⟩+⟨𝒳,Z⟩⇾⟨𝒳,Y+Z⟩ (inj₁ ox) σ = inj₁ (ox σ)
⟨𝒳,Y⟩+⟨𝒳,Z⟩⇾⟨𝒳,Y+Z⟩ (inj₂ oy) ς = inj₂ (oy ς)
-- Same properties for the hom
〖𝒳,𝒴×̣𝒵〗≅̣〖𝒳,𝒴〗×̣〖𝒳,𝒵〗 : 〖 𝒳 , 𝒴 ×̣ₘ 𝒵 〗 ≅̣ₘ 〖 𝒳 , 𝒴 〗 ×̣ₘ 〖 𝒳 , 𝒵 〗
〖𝒳,𝒴×̣𝒵〗≅̣〖𝒳,𝒴〗×̣〖𝒳,𝒵〗 = ≅ₘ→≅̣ₘ ⟨𝒳,Y×Z⟩≅⟨𝒳,Y⟩×⟨𝒳,Z⟩
〖𝒳,𝒴〗+̣〖𝒳,𝒵〗⇾̣〖𝒳,𝒴+̣𝒵〗 : 〖 𝒳 , 𝒴 〗 +̣ₘ 〖 𝒳 , 𝒵 〗 ⇾̣ 〖 𝒳 , (𝒴 +̣ₘ 𝒵) 〗
〖𝒳,𝒴〗+̣〖𝒳,𝒵〗⇾̣〖𝒳,𝒴+̣𝒵〗 = ⟨𝒳,Y⟩+⟨𝒳,Z⟩⇾⟨𝒳,Y+Z⟩
| {
"alphanum_fraction": 0.4851929405,
"avg_line_length": 27.8583333333,
"ext": "agda",
"hexsha": "2bc9f2675dc71821adc483355ac4a31744b78017",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "SOAS/Abstract/Hom.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "SOAS/Abstract/Hom.agda",
"max_line_length": 92,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "SOAS/Abstract/Hom.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 2147,
"size": 3343
} |
module Data.Num where
open import Data.Num.Core renaming
( carry to carry'
; carry-lower-bound to carry-lower-bound'
; carry-upper-bound to carry-upper-bound'
)
open import Data.Num.Maximum
open import Data.Num.Bounded
open import Data.Num.Next
open import Data.Num.Increment
open import Data.Num.Continuous
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Properties.Simple
open import Data.Nat.Properties.Extra
open import Data.Nat.DM
open import Data.Fin as Fin
using (Fin; fromℕ≤; inject≤)
renaming (zero to z; suc to s)
open import Data.Fin.Properties using (toℕ-fromℕ≤; bounded)
open import Data.Product
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Function
open import Relation.Nullary.Decidable
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_)
open DecTotalOrder decTotalOrder using (reflexive) renaming (refl to ≤-refl)
infix 4 _≋_
_≋_ : ∀ {b d o}
→ (xs ys : Numeral b d o)
→ Set
xs ≋ ys = ⟦ xs ⟧ ≡ ⟦ ys ⟧
fromℕ : ∀ {b d o}
→ {cont : True (Continuous? b (suc d) o)}
→ (n : ℕ)
→ n ≥ o
→ Numeral b (suc d) o
fromℕ {o = o} n p with o ≟ n
fromℕ n n≥o | yes eq = z ∙
fromℕ {o = o} zero n≥o | no ¬eq = contradiction (≤0⇒≡0 o n≥o) ¬eq
fromℕ {cont = cont} (suc n) n≥o | no ¬eq = 1+ {cont = cont} (fromℕ {cont = cont} n (≤-pred $ ≤∧≢⇒< n≥o ¬eq))
fromℕ-toℕ : ∀ {b d o}
→ (cont : True (Continuous? b (suc d) o))
→ (n : ℕ)
→ (n≥o : n ≥ o)
→ ⟦ fromℕ {cont = cont} n n≥o ⟧ ≡ n
fromℕ-toℕ {o = o} cont n n≥o with o ≟ n
fromℕ-toℕ cont n n≥o | yes eq = eq
fromℕ-toℕ {o = o} cont zero n≥o | no ¬eq = contradiction (≤0⇒≡0 o n≥o) ¬eq
fromℕ-toℕ cont (suc n) n≥o | no ¬eq =
let
n≥o' = ≤-pred (≤∧≢⇒< n≥o ¬eq)
in
begin
⟦ 1+ {cont = cont} (fromℕ {cont = cont} n n≥o') ⟧
≡⟨ 1+-toℕ {cont = cont} (fromℕ {cont = cont} n n≥o') ⟩
suc ⟦ fromℕ {cont = cont} n n≥o' ⟧
≡⟨ cong suc (fromℕ-toℕ cont n n≥o') ⟩
suc n
∎
-- toℕ-fromℕ : ∀ {b d o}
-- → (cont : True (Continuous? b (suc d) o))
-- → (xs : Numeral b (suc d) o)
-- → fromℕ {cont = cont} ⟦ xs ⟧ (Num-lower-bound xs) ≋ xs
-- toℕ-fromℕ cont xs = fromℕ-toℕ cont ⟦ xs ⟧ (Num-lower-bound xs)
sum : ∀ {d}
→ (o : ℕ)
→ (x y : Digit (suc d))
→ ℕ
sum o x y = Digit-toℕ x o + Digit-toℕ y o
sum≥o : ∀ {d} o
→ (x y : Digit (suc d))
→ sum o x y ≥ o
sum≥o o x y = start
o
≤⟨ n≤m+n (Fin.toℕ x) o ⟩
Digit-toℕ x o
≤⟨ m≤m+n (Digit-toℕ x o) (Digit-toℕ y o) ⟩
sum o x y
□
sum-upper-bound : ∀ {d} o
→ (x y : Digit (suc d))
→ sum o x y ≤ (d + o) + (d + o)
sum-upper-bound {d} o x y =
start
Digit-toℕ x o + Digit-toℕ y o
≤⟨ ≤-pred (Digit-upper-bound o x) +-mono ≤-pred (Digit-upper-bound o y) ⟩
d + o + (d + o)
□
-- 0 o d+o d+o+(1⊔o)×b
----|---|-----------------|----------------|
-- o d (1⊔o)×b
-- [----------------] "buffer capacity"
data Sum : (b d o : ℕ) (x y : Digit (suc d)) → Set where
NoCarry : ∀ {b d o x y}
→ (leftover : Digit (suc d))
→ (property : Digit-toℕ leftover o ≡ sum o x y)
→ Sum b d o x y
Fixed : ∀ {b d o x y}
→ (leftover carry : Digit (suc d))
→ (property : Digit-toℕ leftover o + (Digit-toℕ carry o) * suc b ≡ sum o x y)
→ Sum b d o x y
Floating : ∀ {b d o x y}
→ (leftover carry : Digit (suc d))
→ (property : Digit-toℕ leftover o + (Digit-toℕ carry o) * suc b ≡ sum o x y)
→ Sum b d o x y
sumView : ∀ b d o
→ (¬gapped : ¬ (Gapped#0 b d o))
→ (proper : 2 ≤ suc d + o)
→ (x y : Digit (suc d))
→ Sum b d o x y
sumView b d o ¬gapped proper x y with (sum o x y) ≤? d + o
sumView b d o ¬gapped proper x y | yes below
= NoCarry
(Digit-fromℕ leftover o leftover-upper-bound)
property
where
leftover : ℕ
leftover = sum o x y
leftover-upper-bound : leftover ≤ d + o
leftover-upper-bound = below
property :
Digit-toℕ (Digit-fromℕ leftover o leftover-upper-bound) o
≡ sum o x y
property =
begin
Digit-toℕ (Digit-fromℕ (sum o x y) o below) o
≡⟨ Digit-fromℕ-toℕ (sum o x y) (sum≥o o x y) below ⟩
sum o x y
∎
sumView b d o ¬gapped proper x y | no ¬below with (sum o x y) ≤? d + o + (1 ⊔ o) * (suc b)
sumView b d o ¬gapped proper x y | no ¬below | yes within
= Fixed
(Digit-fromℕ leftover o leftover-upper-bound)
(Digit-fromℕ carry o carry-upper-bound)
property
where
base : ℕ
base = suc b
carry : ℕ
carry = carry' o
sum≥carry*base : sum o x y ≥ carry * base
sum≥carry*base =
start
carry * base
≤⟨ m≤m+n (carry * base) o ⟩
carry * base + o
≤⟨ +n-mono o (≤-pred (≰⇒> ¬gapped)) ⟩
suc (d + o)
≤⟨ ≰⇒> ¬below ⟩
sum o x y
□
leftover : ℕ
leftover = sum o x y ∸ carry * base
leftover-lower-bound : leftover ≥ o
leftover-lower-bound =
start
o
≈⟨ sym (m+n∸n≡m o (carry * base)) ⟩
o + carry * base ∸ carry * base
≈⟨ cong (λ w → w ∸ carry * base) (+-comm o (carry * base)) ⟩
carry * base + o ∸ carry * base
≤⟨ ∸n-mono (carry * base) (+n-mono o (≤-pred (≰⇒> ¬gapped))) ⟩
suc d + o ∸ carry * base
≤⟨ ∸n-mono (carry * base) (≰⇒> ¬below) ⟩
leftover
□
leftover-upper-bound : leftover ≤ d + o
leftover-upper-bound = +n-mono-inverse (carry * base) $
start
leftover + carry * base
≈⟨ refl ⟩
sum o x y ∸ carry * base + carry * base
≈⟨ m∸n+n≡m sum≥carry*base ⟩
sum o x y
≤⟨ within ⟩
d + o + carry * base
□
carry-lower-bound : carry ≥ o
carry-lower-bound = carry-lower-bound'
carry-upper-bound : carry ≤ d + o
carry-upper-bound = carry-upper-bound' {d} {o} proper
property :
Digit-toℕ (Digit-fromℕ leftover o leftover-upper-bound) o
+ Digit-toℕ (Digit-fromℕ carry o carry-upper-bound) o * base
≡ sum o x y
property =
begin
Digit-toℕ (Digit-fromℕ leftover o leftover-upper-bound) o
+ Digit-toℕ (Digit-fromℕ carry o carry-upper-bound) o * base
≡⟨ cong₂
(λ l c → l + c * base)
(Digit-fromℕ-toℕ leftover leftover-lower-bound leftover-upper-bound)
(Digit-fromℕ-toℕ carry carry-lower-bound carry-upper-bound)
⟩
leftover + carry * base
≡⟨ refl ⟩
sum o x y ∸ carry * base + carry * base
≡⟨ m∸n+n≡m sum≥carry*base ⟩
sum o x y
∎
sumView b d o ¬gapped proper x y | no ¬below | no ¬within with (sum o x y ∸ ((d + o) + (1 ⊔ o) * (suc b))) divMod (suc b)
sumView b d o ¬gapped proper x y | no ¬below | no ¬within | result quotient remainder divModProp _ _
= Floating
(Digit-fromℕ leftover o leftover-upper-bound)
(Digit-fromℕ carry o carry-upper-bound)
property
where
base : ℕ
base = suc b
carry : ℕ
carry = (1 ⊓ Fin.toℕ remainder) + quotient + (1 ⊔ o)
divModProp' : sum o x y ≡ Fin.toℕ remainder + quotient * base + (d + o + (1 ⊔ o) * base)
divModProp' =
begin
sum o x y
≡⟨ sym (m∸n+n≡m (<⇒≤ (≰⇒> ¬within))) ⟩
sum o x y ∸ (d + o + (1 ⊔ o) * base) + (d + o + (1 ⊔ o) * base)
≡⟨ cong (λ w → w + ((d + o) + (1 ⊔ o) * base)) divModProp ⟩
Fin.toℕ remainder + quotient * base + ((d + o) + (1 ⊔ o) * base)
∎
leftover : ℕ
leftover = sum o x y ∸ carry * base
leftover-lower-bound-lemma :
(remainder : Fin base)
→ (prop : sum o x y ∸ (d + o + (1 ⊔ o) * base) ≡ Fin.toℕ remainder + quotient * base)
→ sum o x y ≥ o + ((1 ⊓ Fin.toℕ remainder) + quotient + (1 ⊔ o)) * base
leftover-lower-bound-lemma z prop =
start
o + (quotient + (1 ⊔ o)) * base
≤⟨ +n-mono ((quotient + (1 ⊔ o)) * base) (n≤m+n d o) ⟩
d + o + (quotient + (1 ⊔ o)) * base
≈⟨ cong (λ w → d + o + w) (distribʳ-*-+ base quotient (1 ⊔ o)) ⟩
d + o + (quotient * base + (1 ⊔ o) * base)
≈⟨ a+[b+c]≡b+[a+c] (d + o) (quotient * base) ((1 ⊔ o) * base) ⟩
quotient * base + ((d + o) + (1 ⊔ o) * base)
≈⟨ cong (λ w → w + ((d + o) + (1 ⊔ o) * base)) (sym prop) ⟩
(sum o x y ∸ ((d + o) + (1 ⊔ o) * base)) + ((d + o) + (1 ⊔ o) * base)
≈⟨ m∸n+n≡m (<⇒≤ (≰⇒> ¬within)) ⟩
sum o x y
□
leftover-lower-bound-lemma (s r) prop =
start
o + ((1 ⊓ (Fin.toℕ (s r))) + quotient + (1 ⊔ o)) * base
≈⟨ refl ⟩
o + (1 + (quotient + (1 ⊔ o))) * base
≈⟨ cong (λ w → o + w) (distribʳ-*-+ base 1 (quotient + (1 ⊔ o))) ⟩
o + (1 * base + (quotient + (1 ⊔ o)) * base)
≈⟨ cong (λ w → o + (1 * base + w)) (distribʳ-*-+ base quotient (1 ⊔ o)) ⟩
o + (1 * base + (quotient * base + (1 ⊔ o) * base))
≤⟨ n+-mono o
(n+-mono (1 * base)
(+n-mono ((1 ⊔ o) * base)
(n≤m+n (Fin.toℕ r) (quotient * base)))) ⟩
o + (1 * base + (Fin.toℕ r + quotient * base + (1 ⊔ o) * base))
≈⟨ a+[b+c]≡b+[a+c] o (1 * base) (Fin.toℕ r + quotient * base + (1 ⊔ o) * base) ⟩
1 * base + (o + (Fin.toℕ r + quotient * base + (1 ⊔ o) * base))
≤⟨ +n-mono (o + (Fin.toℕ r + quotient * base + (1 ⊔ o) * base)) (*n-mono base (m≤m⊔n 1 o)) ⟩
(1 ⊔ o) * base + (o + (Fin.toℕ r + quotient * base + (1 ⊔ o) * base))
≤⟨ +n-mono (o + ((Fin.toℕ r) + quotient * base + (1 ⊔ o) * base)) (≤-pred (≰⇒> ¬gapped)) ⟩
suc d + (o + ((Fin.toℕ r) + quotient * base + (1 ⊔ o) * base))
≈⟨ cong suc (sym (+-assoc d o ((Fin.toℕ r) + quotient * base + (1 ⊔ o) * base))) ⟩
suc (d + o + ((Fin.toℕ r) + quotient * base + (1 ⊔ o) * base))
≈⟨ sym (+-suc (d + o) ((Fin.toℕ r) + quotient * base + (1 ⊔ o) * base)) ⟩
d + o + suc ((Fin.toℕ r) + quotient * base + (1 ⊔ o) * base)
≈⟨ a+[b+c]≡b+[a+c] (d + o) (suc (Fin.toℕ r) + quotient * base) ((1 ⊔ o) * base) ⟩
suc (Fin.toℕ r) + quotient * base + ((d + o) + (1 ⊔ o) * base)
≈⟨ cong (λ w → w + ((d + o) + (1 ⊔ o) * base)) (sym prop) ⟩
(sum o x y ∸ ((d + o) + (1 ⊔ o) * base)) + ((d + o) + (1 ⊔ o) * base)
≈⟨ m∸n+n≡m (<⇒≤ (≰⇒> ¬within)) ⟩
sum o x y
□
leftover-lower-bound : leftover ≥ o
leftover-lower-bound =
start
o
≈⟨ sym (m+n∸n≡m o (carry * base)) ⟩
o + carry * base ∸ carry * base
≤⟨ ∸n-mono (carry * base) (leftover-lower-bound-lemma remainder divModProp) ⟩
sum o x y ∸ carry * base
≈⟨ refl ⟩
leftover
□
leftover-upper-bound-lemma :
(remainder : Fin base)
→ (prop : sum o x y ∸ (d + o + (1 ⊔ o) * base) ≡ Fin.toℕ remainder + quotient * base)
→ sum o x y ≤ d + o + ((1 ⊓ Fin.toℕ remainder) + quotient + (1 ⊔ o)) * base
leftover-upper-bound-lemma z prop =
start
sum o x y
≈⟨ sym (m∸n+n≡m (<⇒≤ (≰⇒> ¬within))) ⟩
(sum o x y ∸ ((d + o) + (1 ⊔ o) * base)) + ((d + o) + (1 ⊔ o) * base)
≈⟨ cong (λ w → w + ((d + o) + (1 ⊔ o) * base)) prop ⟩
quotient * base + ((d + o) + (1 ⊔ o) * base)
≈⟨ a+[b+c]≡b+[a+c] (quotient * base) (d + o) ((1 ⊔ o) * base) ⟩
d + o + (quotient * base + (1 ⊔ o) * base)
≈⟨ cong (λ w → d + o + w) (sym (distribʳ-*-+ base quotient (1 ⊔ o))) ⟩
d + o + (quotient + (1 ⊔ o)) * base
□
leftover-upper-bound-lemma (s r) prop =
start
sum o x y
≈⟨ sym (m∸n+n≡m (<⇒≤ (≰⇒> ¬within))) ⟩
(sum o x y ∸ ((d + o) + (1 ⊔ o) * base)) + ((d + o) + (1 ⊔ o) * base)
≈⟨ cong (λ w → w + ((d + o) + (1 ⊔ o) * base)) prop ⟩
suc (Fin.toℕ r) + quotient * base + ((d + o) + (1 ⊔ o) * base)
≈⟨ a+[b+c]≡b+[a+c] (suc (Fin.toℕ r) + quotient * base) (d + o) ((1 ⊔ o) * base) ⟩
d + o + (suc (Fin.toℕ r) + quotient * base + (1 ⊔ o) * base)
≤⟨ n+-mono (d + o)
(+n-mono ((1 ⊔ o) * base)
(+n-mono (quotient * base)
(≤-step (bounded r)))) ⟩
d + o + (suc quotient * base + (1 ⊔ o) * base)
≈⟨ cong (λ w → d + o + w) (sym (distribʳ-*-+ base (suc quotient) (1 ⊔ o))) ⟩
d + o + (1 + (quotient + (1 ⊔ o))) * base
≈⟨ refl ⟩
d + o + ((1 ⊓ (Fin.toℕ (s r))) + quotient + (1 ⊔ o)) * base
□
leftover-upper-bound : leftover ≤ d + o
leftover-upper-bound =
start
leftover
≈⟨ refl ⟩
sum o x y ∸ carry * base
≤⟨ ∸n-mono (carry * base) (leftover-upper-bound-lemma remainder divModProp) ⟩
d + o + carry * base ∸ carry * base
≈⟨ m+n∸n≡m (d + o) (carry * base) ⟩
d + o
□
carry-lower-bound : carry ≥ o
carry-lower-bound =
start
o
≤⟨ m≤n⊔m o 1 ⟩
1 ⊔ o
≤⟨ n≤m+n (1 ⊓ Fin.toℕ remainder + quotient) (1 ⊔ o) ⟩
1 ⊓ Fin.toℕ remainder + quotient + (1 ⊔ o)
□
carry-upper-bound : carry ≤ d + o
carry-upper-bound = +n-mono-inverse (d + o) $
start
1 ⊓ Fin.toℕ remainder + quotient + (1 ⊔ o) + (d + o)
≤⟨ +n-mono (d + o)
(+n-mono (1 ⊔ o)
(+n-mono quotient
(m⊓n≤n 1 (Fin.toℕ remainder))))
⟩
Fin.toℕ remainder + quotient + (1 ⊔ o) + (d + o)
≈⟨ +-assoc (Fin.toℕ remainder + quotient) (1 ⊔ o) (d + o) ⟩
Fin.toℕ remainder + quotient + (1 ⊔ o + (d + o))
≈⟨ cong (λ w → Fin.toℕ remainder + quotient + w) (+-comm (1 ⊔ o) (d + o)) ⟩
Fin.toℕ remainder + quotient + (d + o + (1 ⊔ o))
≤⟨ +n-mono (d + o + (1 ⊔ o))
(n+-mono (Fin.toℕ remainder) (m≤m*1+n quotient b))
⟩
Fin.toℕ remainder + quotient * base + (d + o + (1 ⊔ o))
≤⟨ n+-mono (Fin.toℕ remainder + quotient * base)
(n+-mono (d + o)
(m≤m*1+n (1 ⊔ o) b))
⟩
Fin.toℕ remainder + quotient * base + (d + o + (1 ⊔ o) * base)
≈⟨ cong (λ w → w + (d + o + (1 ⊔ o) * base)) (sym divModProp) ⟩
sum o x y ∸ (d + o + (1 ⊔ o) * base) + (d + o + (1 ⊔ o) * base)
≈⟨ m∸n+n≡m (<⇒≤ (≰⇒> ¬within)) ⟩
sum o x y
≤⟨ sum-upper-bound o x y ⟩
d + o + (d + o)
□
property :
Digit-toℕ (Digit-fromℕ leftover o leftover-upper-bound) o
+ Digit-toℕ (Digit-fromℕ carry o carry-upper-bound) o * base
≡ sum o x y
property =
begin
Digit-toℕ (Digit-fromℕ leftover o leftover-upper-bound) o
+ Digit-toℕ (Digit-fromℕ carry o carry-upper-bound) o * base
≡⟨ cong₂
(λ l c → l + c * base)
(Digit-fromℕ-toℕ leftover leftover-lower-bound leftover-upper-bound)
(Digit-fromℕ-toℕ carry carry-lower-bound carry-upper-bound)
⟩
leftover + carry * base
≡⟨ refl ⟩
sum o x y ∸ carry * base + carry * base
≡⟨ m∸n+n≡m $
start
carry * base
≤⟨ n≤m+n o (carry * base) ⟩
o + carry * base
≤⟨ leftover-lower-bound-lemma remainder divModProp ⟩
sum o x y
□
⟩
sum o x y
∎
n+-Proper : ∀ {b d o}
→ (¬gapped : ¬ (Gapped#0 b d o))
→ (proper : suc d + o ≥ 2)
→ (x : Digit (suc d))
→ (xs : Numeral (suc b) (suc d) o)
→ Numeral (suc b) (suc d) o
n+-Proper {b} {d} {o} ¬gapped proper x xs with sumView b d o ¬gapped proper x (lsd xs)
n+-Proper ¬gapped proper x (_ ∙) | NoCarry leftover property = leftover ∙
n+-Proper ¬gapped proper x (_ ∷ xs) | NoCarry leftover property = leftover ∷ xs
n+-Proper ¬gapped proper x (_ ∙) | Fixed leftover carry property = leftover ∷ carry ∙
n+-Proper ¬gapped proper x (_ ∷ xs) | Fixed leftover carry property = leftover ∷ n+-Proper ¬gapped proper carry xs
n+-Proper ¬gapped proper x (_ ∙) | Floating leftover carry property = leftover ∷ carry ∙
n+-Proper ¬gapped proper x (_ ∷ xs) | Floating leftover carry property = leftover ∷ n+-Proper ¬gapped proper carry xs
n+-Proper-toℕ : ∀ {b d o}
→ (¬gapped : ¬ (Gapped#0 b d o))
→ (proper : suc d + o ≥ 2)
→ (x : Digit (suc d))
→ (xs : Numeral (suc b) (suc d) o)
→ ⟦ n+-Proper ¬gapped proper x xs ⟧ ≡ Digit-toℕ x o + ⟦ xs ⟧
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x xs with sumView b d o ¬gapped proper x (lsd xs)
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x (_ ∙) | NoCarry leftover property = property
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x (x' ∷ xs) | NoCarry leftover property =
begin
⟦ leftover ∷ xs ⟧
≡⟨ refl ⟩
Digit-toℕ leftover o + ⟦ xs ⟧ * suc b
≡⟨ cong (λ w → w + ⟦ xs ⟧ * suc b) property ⟩
Digit-toℕ x o + Digit-toℕ x' o + ⟦ xs ⟧ * suc b
≡⟨ +-assoc (Digit-toℕ x o) (Digit-toℕ x' o) (⟦ xs ⟧ * suc b) ⟩
Digit-toℕ x o + ⟦ x' ∷ xs ⟧
∎
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x (_ ∙) | Fixed leftover carry property = property
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x (x' ∷ xs) | Fixed leftover carry property =
begin
⟦ leftover ∷ n+-Proper ¬gapped proper carry xs ⟧
≡⟨ refl ⟩
Digit-toℕ leftover o + ⟦ n+-Proper ¬gapped proper carry xs ⟧ * suc b
≡⟨ cong (λ w → Digit-toℕ leftover o + w * suc b) (n+-Proper-toℕ ¬gapped proper carry xs) ⟩
Digit-toℕ leftover o + (Digit-toℕ carry o + ⟦ xs ⟧) * suc b
≡⟨ cong (λ w → Digit-toℕ leftover o + w) (distribʳ-*-+ (suc b) (Digit-toℕ carry o) ⟦ xs ⟧) ⟩
Digit-toℕ leftover o + ((Digit-toℕ carry o) * suc b + ⟦ xs ⟧ * suc b)
≡⟨ sym (+-assoc (Digit-toℕ leftover o) ((Digit-toℕ carry o) * suc b) (⟦ xs ⟧ * suc b)) ⟩
Digit-toℕ leftover o + (Digit-toℕ carry o) * suc b + ⟦ xs ⟧ * suc b
≡⟨ cong (λ w → w + ⟦ xs ⟧ * suc b) property ⟩
Digit-toℕ x o + Digit-toℕ x' o + ⟦ xs ⟧ * suc b
≡⟨ +-assoc (Digit-toℕ x o) (Digit-toℕ x' o) (⟦ xs ⟧ * suc b) ⟩
Digit-toℕ x o + (Digit-toℕ x' o + ⟦ xs ⟧ * suc b)
∎
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x (_ ∙) | Floating leftover carry property = property
n+-Proper-toℕ {b} {d} {o} ¬gapped proper x (x' ∷ xs) | Floating leftover carry property =
begin
⟦ leftover ∷ n+-Proper ¬gapped proper carry xs ⟧
≡⟨ refl ⟩
Digit-toℕ leftover o + ⟦ n+-Proper ¬gapped proper carry xs ⟧ * suc b
≡⟨ cong (λ w → Digit-toℕ leftover o + w * suc b) (n+-Proper-toℕ ¬gapped proper carry xs) ⟩
Digit-toℕ leftover o + (Digit-toℕ carry o + ⟦ xs ⟧) * suc b
≡⟨ cong (λ w → Digit-toℕ leftover o + w) (distribʳ-*-+ (suc b) (Digit-toℕ carry o) ⟦ xs ⟧) ⟩
Digit-toℕ leftover o + ((Digit-toℕ carry o) * suc b + ⟦ xs ⟧ * suc b)
≡⟨ sym (+-assoc (Digit-toℕ leftover o) ((Digit-toℕ carry o) * suc b) (⟦ xs ⟧ * suc b)) ⟩
Digit-toℕ leftover o + (Digit-toℕ carry o) * suc b + ⟦ xs ⟧ * suc b
≡⟨ cong (λ w → w + ⟦ xs ⟧ * suc b) property ⟩
Digit-toℕ x o + Digit-toℕ x' o + ⟦ xs ⟧ * suc b
≡⟨ +-assoc (Digit-toℕ x o) (Digit-toℕ x' o) (⟦ xs ⟧ * suc b) ⟩
Digit-toℕ x o + (Digit-toℕ x' o + ⟦ xs ⟧ * suc b)
∎
-- -- data N+Closed : (b d o : ℕ) → Set where
-- -- IsContinuous : ∀ {b d o} → (cont : True (Continuous? b d o)) → N+Closed b d o
-- -- ℤₙ : ∀ {o} → N+Closed 1 1 o
-- --
-- -- n+-ℤₙ : ∀ {o}
-- -- → (n : Digit 1)
-- -- → (xs : Numeral 1 1 (o))
-- -- → Numeral 1 1 o
-- -- n+-ℤₙ n xs = n ∷ xs
-- --
-- -- n+-ℤₙ-toℕ : ∀ {o}
-- -- → (n : Digit 1)
-- -- → (xs : Numeral 1 1 o)
-- -- → ⟦ n+-ℤₙ n xs ⟧ ≡ Digit-toℕ n o + ⟦ xs ⟧
-- -- n+-ℤₙ-toℕ {o} n xs =
-- -- begin
-- -- Fin.toℕ n + o + ⟦ xs ⟧ * suc zero
-- -- ≡⟨ cong (λ w → Fin.toℕ n + o + w) (*-right-identity ⟦ xs ⟧) ⟩
-- -- Fin.toℕ n + o + ⟦ xs ⟧
-- -- ∎
--
n+ : ∀ {b d o}
→ {cont : True (Continuous? b d o)}
→ (n : Digit d)
→ (xs : Numeral b d o)
→ Numeral b d o
n+ {b} {d} {o} n xs with numView b d o
n+ {_} {_} {_} {()} n xs | NullBase d o
n+ {_} {_} {_} n xs | NoDigits b o = NoDigits-explode xs
n+ {_} {_} {_} {()} n xs | AllZeros b
n+ {_} {_} {_} n xs | Proper b d o proper with Gapped#0? b d o
n+ {_} {_} {_} {()} n xs | Proper b d o proper | yes gapped#0
n+ {_} {_} {_} n xs | Proper b d o proper | no ¬gapped#0 = n+-Proper ¬gapped#0 proper n xs
n+-toℕ : ∀ {b d o}
→ {cont : True (Continuous? b d o)}
→ (n : Digit d)
→ (xs : Numeral b d o)
→ ⟦ n+ {cont = cont} n xs ⟧ ≡ Digit-toℕ n o + ⟦ xs ⟧
n+-toℕ {b} {d} {o} n xs with numView b d o
n+-toℕ {_} {_} {_} {()} n xs | NullBase d o
n+-toℕ {_} {_} {_} n xs | NoDigits b o = NoDigits-explode xs
n+-toℕ {_} {_} {_} {()} n xs | AllZeros b
n+-toℕ {_} {_} {_} n xs | Proper b d o proper with Gapped#0? b d o
n+-toℕ {_} {_} {_} {()} n xs | Proper b d o proper | yes gapped#0
n+-toℕ {_} {_} {_} n xs | Proper b d o proper | no ¬gapped#0 = n+-Proper-toℕ ¬gapped#0 proper n xs
⊹-Proper : ∀ {b d o}
→ (¬gapped : ¬ (Gapped#0 b d o))
→ (proper : suc d + o ≥ 2)
→ (xs ys : Numeral (suc b) (suc d) o)
→ Numeral (suc b) (suc d) o
⊹-Proper ¬gapped proper (x ∙) ys = n+-Proper ¬gapped proper x ys
⊹-Proper ¬gapped proper (x ∷ xs) (y ∙) = n+-Proper ¬gapped proper y (x ∷ xs)
⊹-Proper {b} {d} {o} ¬gapped proper (x ∷ xs) (y ∷ ys) with sumView b d o ¬gapped proper x y
⊹-Proper ¬gapped proper (x ∷ xs) (y ∷ ys) | NoCarry leftover property = leftover ∷ ⊹-Proper ¬gapped proper xs ys
⊹-Proper ¬gapped proper (x ∷ xs) (y ∷ ys) | Fixed leftover carry property = leftover ∷ n+-Proper ¬gapped proper carry (⊹-Proper ¬gapped proper xs ys)
⊹-Proper ¬gapped proper (x ∷ xs) (y ∷ ys) | Floating leftover carry property = leftover ∷ n+-Proper ¬gapped proper carry (⊹-Proper ¬gapped proper xs ys)
_⊹_ : ∀ {b d o}
→ {cont : True (Continuous? b d o)}
→ (xs ys : Numeral b d o)
→ Numeral b d o
_⊹_ {b} {d} {o} xs ys with numView b d o
_⊹_ {cont = ()} xs ys | NullBase d o
_⊹_ {cont = cont} xs ys | NoDigits b o = NoDigits-explode xs
_⊹_ {cont = ()} xs ys | AllZeros b
_⊹_ {cont = cont} xs ys | Proper b d o proper with Gapped#0? b d o
_⊹_ {cont = ()} xs ys | Proper b d o proper | yes ¬gapped#0
_⊹_ {cont = cont} xs ys | Proper b d o proper | no ¬gapped#0 = ⊹-Proper ¬gapped#0 proper xs ys
| {
"alphanum_fraction": 0.4624154347,
"avg_line_length": 40.9333333333,
"ext": "agda",
"hexsha": "0c4fb2edd5f9d5acb4e211d42adcc68d7e277c3b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "Data/Num.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "Data/Num.agda",
"max_line_length": 152,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "Data/Num.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 8991,
"size": 23946
} |
module Prelude.List where
open import Prelude.Nat
open import Prelude.Bool
open import Prelude.Maybe
open import Prelude.Product
open import Prelude.Empty
open import Prelude.Function
open import Prelude.Functor
open import Prelude.Applicative
open import Prelude.Monad
open import Prelude.Decidable
open import Prelude.Equality
open import Prelude.Ord
open import Prelude.Semiring
open import Prelude.Strict
open import Agda.Builtin.List public
infixr 5 _++_
pattern [_] x = x ∷ []
singleton : ∀ {a} {A : Set a} → A → List A
singleton x = x ∷ []
map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
_++_ : ∀ {a} {A : Set a} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ xs ++ ys
length : ∀ {a} {A : Set a} → List A → Nat
length [] = 0
length (x ∷ xs) = 1 + length xs
foldr : ∀ {a b} {A : Set a} {B : Set b} → (A → B → B) → B → List A → B
foldr f z [] = z
foldr f z (x ∷ xs) = f x (foldr f z xs)
foldl : ∀ {a b} {A : Set a} {B : Set b} → (B → A → B) → B → List A → B
foldl f z [] = z
foldl f z (x ∷ xs) = foldl f (f z x) xs
foldl! : ∀ {a b} {A : Set a} {B : Set b} → (B → A → B) → B → List A → B
foldl! f z [] = z
foldl! f z (x ∷ xs) = force (f z x) λ z′ → foldl! f z′ xs
reverse : ∀ {a} {A : Set a} → List A → List A
reverse xs = foldl (flip _∷_) [] xs
concat : ∀ {a} {A : Set a} → List (List A) → List A
concat = foldr _++_ []
concatMap : ∀ {a b} {A : Set a} {B : Set b} → (A → List B) → List A → List B
concatMap f = concat ∘ map f
filter : ∀ {a} {A : Set a} → (A → Bool) → List A → List A
filter p [] = []
filter p (x ∷ xs) = if p x then x ∷ filter p xs
else filter p xs
catMaybes : ∀ {a} {A : Set a} → List (Maybe A) → List A
catMaybes [] = []
catMaybes (x ∷ xs) = maybe (catMaybes xs) (_∷ catMaybes xs) x
all? : ∀ {a} {A : Set a} → (A → Bool) → List A → Bool
all? p [] = true
all? p (x ∷ xs) = p x && all? p xs
any? : ∀ {a} {A : Set a} → (A → Bool) → List A → Bool
any? p [] = false
any? p (x ∷ xs) = p x || any? p xs
take : ∀ {a} {A : Set a} → Nat → List A → List A
take zero _ = []
take (suc n) [] = []
take (suc n) (x ∷ xs) = x ∷ take n xs
drop : ∀ {a} {A : Set a} → Nat → List A → List A
drop zero xs = xs
drop (suc n) [] = []
drop (suc n) (x ∷ xs) = drop n xs
splitAt : ∀ {a} {A : Set a} → Nat → List A → List A × List A
splitAt zero xs = [] , xs
splitAt (suc n) [] = [] , []
splitAt (suc n) (x ∷ xs) = first (x ∷_) (splitAt n xs)
null : ∀ {a} {A : Set a} → List A → Bool
null [] = true
null (_ ∷ _) = false
elem : ∀ {a} {A : Set a} {{EqA : Eq A}} → A → List A → Bool
elem x xs = not (null (filter (isYes ∘ _==_ x) xs))
lookup : ∀ {a b} {A : Set a} {B : Set b} {{EqA : Eq A}} → List (A × B) → A → Maybe B
lookup [] _ = nothing
lookup ((x₁ , v) ∷ xs) x = ifYes (x == x₁) then just v else lookup xs x
index : ∀ {a} {A : Set a} → List A → Nat → Maybe A
index [] _ = nothing
index (x ∷ xs) 0 = just x
index (x ∷ xs) (suc i) = index xs i
replicate : ∀ {a} {A : Set a} → Nat → A → List A
replicate zero x = []
replicate (suc n) x = x ∷ replicate n x
zipWith : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A → B → C) → List A → List B → List C
zipWith f [] _ = []
zipWith f _ [] = []
zipWith f (x ∷ xs) (y ∷ ys) = f x y ∷ zipWith f xs ys
zip : ∀ {a b} {A : Set a} {B : Set b} → List A → List B → List (A × B)
zip = zipWith _,_
punctuate : ∀ {a} {A : Set a} → A → List A → List A
punctuate z [] = []
punctuate z [ x ] = [ x ]
punctuate z (x ∷ xs) = x ∷ z ∷ punctuate z xs
module _ {a b} {F : Set a → Set b} {{_ : Applicative F}} {A : Set a} where
replicateA : Nat → F A → F (List A)
replicateA zero _ = pure []
replicateA (suc n) x = pure _∷_ <*> x <*> replicateA n x
module _ {a} {A : Set a} {{_ : Semiring A}} where
sum : List A → A
sum = foldl! _+_ zro
product : List A → A
product = foldl! _*_ one
sumR : List A → A
sumR = foldr _+_ zro
productR : List A → A
productR = foldr _*_ one
module _ {a} {A : Set a} {{_ : Ord A}} where
insert : A → List A → List A
insert x [] = x ∷ []
insert x (y ∷ xs) = if x <? y then x ∷ y ∷ xs else y ∷ insert x xs
sort : List A → List A
sort [] = []
sort (x ∷ xs) = insert x (sort xs)
infix 10 from_for_ from_to_ from_for_step_ from-to-step
from_for_ : Nat → Nat → List Nat
from 0 for 0 = [] -- make strict
from a for 0 = []
from a for suc d = a ∷ from suc a for d
from_for_step_ : Nat → Nat → Nat → List Nat
from 0 for 0 step _ = [] -- make strict
from a for 0 step _ = []
from a for suc c step d = a ∷ from a + d for c step d
from_to_ : Nat → Nat → List Nat
from a to b = from a for (suc b - a)
syntax from-to-step d a b = from a to b step d
from-to-step : (d : Nat) {{_ : NonZero d}} → Nat → Nat → List Nat
from-to-step d a b = from a for 1 + (b - a) div d step d
--- Equality ---
cons-inj-tail : ∀ {a} {A : Set a} {x : A} {xs : List A} {y : A}
{ys : List A} →
x ∷ xs ≡ y ∷ ys → xs ≡ ys
cons-inj-tail refl = refl
cons-inj-head : ∀ {a} {A : Set a} {x : A} {xs : List A} {y : A}
{ys : List A} →
x ∷ xs ≡ y ∷ ys → x ≡ y
cons-inj-head refl = refl
private
dec-∷ : ∀ {a} {A : Set a} {x : A} {xs : List A} {y : A}
{ys : List A} → Dec (x ≡ y) → Dec (xs ≡ ys) → Dec (x ∷ xs ≡ y ∷ ys)
dec-∷ (yes refl) (yes refl) = yes refl
dec-∷ _ (no neq) = no λ eq → neq (cons-inj-tail eq)
dec-∷ (no neq) _ = no λ eq → neq (cons-inj-head eq)
eqList : ∀ {a} {A : Set a} {{EqA : Eq A}} (xs ys : List A) → Dec (xs ≡ ys)
eqList [] [] = yes refl
eqList [] (_ ∷ _) = no (λ ())
eqList (_ ∷ _) [] = no (λ ())
eqList (x ∷ xs) (y ∷ ys) = dec-∷ (x == y) (eqList xs ys)
instance
EqList : ∀ {a} {A : Set a} {{EqA : Eq A}} → Eq (List A)
_==_ {{EqList}} = eqList
--- Ord ---
data LessList {a} {A : Set a} (_<_ : A → A → Set a) : List A → List A → Set a where
nil<cons : ∀ {x xs} → LessList _<_ [] (x ∷ xs)
head< : ∀ {x y xs ys} → x < y → LessList _<_ (x ∷ xs) (y ∷ ys)
tail< : ∀ {x xs ys} → LessList _<_ xs ys → LessList _<_ (x ∷ xs) (x ∷ ys)
compareCons : ∀ {a} {A : Set a} {_<_ : A → A → Set a}
{x : A} {xs : List A} {y : A} {ys : List A} →
Comparison _<_ x y →
Comparison (LessList _<_) xs ys →
Comparison (LessList _<_) (x ∷ xs) (y ∷ ys)
compareCons (less lt) _ = less (head< lt)
compareCons (greater gt) _ = greater (head< gt)
compareCons (equal refl) (less lt) = less (tail< lt)
compareCons (equal refl) (greater gt) = greater (tail< gt)
compareCons (equal refl) (equal refl) = equal refl
compareList : ∀ {a} {A : Set a} {_<_ : A → A → Set a} (cmp : ∀ x y → Comparison _<_ x y) (xs ys : List A) →
Comparison (LessList _<_) xs ys
compareList cmp [] [] = equal refl
compareList cmp [] (x ∷ ys) = less nil<cons
compareList cmp (x ∷ xs) [] = greater nil<cons
compareList cmp (x ∷ xs) (y ∷ ys) = compareCons (cmp x y) (compareList cmp xs ys)
instance
OrdList : ∀ {a} {A : Set a} {{OrdA : Ord A}} → Ord (List A)
OrdList = defaultOrd (compareList compare)
OrdListLaws : ∀ {a} {A : Set a} {{OrdA : Ord/Laws A}} → Ord/Laws (List A)
Ord/Laws.super OrdListLaws = it
less-antirefl {{OrdListLaws {A = A}}} (head< hd) = less-antirefl {A = A} hd
less-antirefl {{OrdListLaws {A = A}}} (tail< tl) = less-antirefl {A = List A} tl
less-trans {{OrdListLaws}} nil<cons (head< hd) = nil<cons
less-trans {{OrdListLaws}} nil<cons (tail< tl) = nil<cons
less-trans {{OrdListLaws {A = A}}} (head< hd) (head< hd₁) = head< (less-trans {A = A} hd hd₁)
less-trans {{OrdListLaws {A = A}}} (head< hd) (tail< tl) = head< hd
less-trans {{OrdListLaws {A = A}}} (tail< tl) (head< hd) = head< hd
less-trans {{OrdListLaws {A = A}}} (tail< tl) (tail< tl₁) = tail< (less-trans {A = List A} tl tl₁)
--- Functor ---
instance
FunctorList : ∀ {a} → Functor (List {a})
fmap {{FunctorList}} = map
FunctorList′ : ∀ {a b} → Functor′ {a} {b} List
fmap′ {{FunctorList′}} = map
ApplicativeList : ∀ {a} → Applicative (List {a})
pure {{ApplicativeList}} x = x ∷ []
_<*>_ {{ApplicativeList}} = monadAp (flip concatMap)
ApplicativeList′ : ∀ {a b} → Applicative′ {a} {b} List
_<*>′_ {{ApplicativeList′}} = monadAp′ (flip concatMap)
MonadList : ∀ {a} → Monad (List {a})
_>>=_ {{MonadList}} xs f = concatMap f xs
MonadList′ : ∀ {a b} → Monad′ {a} {b} List
_>>=′_ {{MonadList′}} xs f = concatMap f xs
| {
"alphanum_fraction": 0.5268616711,
"avg_line_length": 32.5037878788,
"ext": "agda",
"hexsha": "c6946124d68fbb40a35c65d37212a541f0320047",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Prelude/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lclem/agda-prelude",
"max_issues_repo_path": "src/Prelude/List.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Prelude/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3338,
"size": 8581
} |
module Dave.Embedding where
open import Dave.Functions
open import Dave.Equality
open import Dave.Isomorphism
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
≲-refl : ∀ {A : Set} → A ≲ A
≲-refl = record
{
to = λ a → a ;
from = λ b → b ;
from∘to = λ a → refl
}
≲-trans : ∀ {A B C : Set} → A ≲ B → B ≲ C → A ≲ C
≲-trans A≲B B≲C = record
{
to = λ a → to B≲C (to A≲B a) ;
from = λ c → from A≲B (from B≲C c) ;
from∘to = λ a → begin
(from A≲B ∘ from B≲C) ((to B≲C ∘ to A≲B) a) ≡⟨⟩
from A≲B (from B≲C (to B≲C (to A≲B a))) ≡⟨ cong (from A≲B) (from∘to B≲C (to A≲B a)) ⟩
from A≲B (to A≲B a) ≡⟨ from∘to A≲B a ⟩
a ∎
}
≲-antisym : ∀ {A B : Set}
→ (A≲B : A ≲ B)
→ (B≲A : B ≲ A)
→ (to A≲B ≡ from B≲A)
→ (from A≲B ≡ to B≲A)
→ A ≃ B
≲-antisym A≲B B≲A to≡from from≡to = record
{
to = λ a → to A≲B a ;
from = λ b → from A≲B b ;
from∘to = from∘to A≲B;
to∘from = λ b → begin
to A≲B (from A≲B b) ≡⟨ cong (λ x → (to A≲B (x b))) from≡to ⟩
to A≲B (to B≲A b) ≡⟨ cong-app to≡from (to B≲A b) ⟩
from B≲A (to B≲A b) ≡⟨ from∘to B≲A b ⟩
b ∎
}
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
≃-implies-≲ : ∀ {A B : Set} → A ≃ B → A ≲ B
≃-implies-≲ A≃B = record
{
to = _≃_.to A≃B;
from = _≃_.from A≃B;
from∘to = _≃_.from∘to A≃B
}
| {
"alphanum_fraction": 0.3385231317,
"avg_line_length": 25.5454545455,
"ext": "agda",
"hexsha": "da3c65affb7f8d48f9574fc36080385b59947108",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Embedding.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Embedding.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Embedding.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 967,
"size": 2248
} |
{-# OPTIONS --prop --without-K --rewriting #-}
-- The phase distinction for extension.
module Calf.PhaseDistinction where
open import Calf.Prelude
open import Calf.Metalanguage
open import Relation.Binary.PropositionalEquality as P
-- Extensional phase.
postulate
ext : Ω
-- Open/extensional modality.
◯ : □ → □
◯ A = ext → A
infix 10 ◯⁺_
infix 10 ◯⁻_
postulate
ext/val : (ext → tp pos) → tp pos
ext/val/decode : ∀ {A} → val (ext/val A) ≡ ∀ (u : ext) → (val (A u))
{-# REWRITE ext/val/decode #-}
ext/cmp : (ext → tp neg) → tp neg
ext/cmp/decode : ∀ {A} → val (U (ext/cmp A)) ≡ ∀ (u : ext) → (cmp (A u))
{-# REWRITE ext/cmp/decode #-}
◯⁺_ : tp pos → tp pos
◯⁺ A = ext/val (λ _ → A)
◯⁻_ : tp neg → tp neg
◯⁻ A = ext/cmp (λ _ → A)
-- Closed/intensional modality.
postulate
● : tp pos → tp pos
η : ∀ {A} → val A → val (● A)
∗ : ∀ {A} → ext → val (● A)
η≡∗ : ∀ {A} (a : val A) u → η {A} a ≡ ∗ u
●/ind : ∀ {A} (a : val (● A)) (X : val (● A) → tp neg)
(x0 : (a : val A) → cmp (X (η a))) →
(x1 : (u : ext) → cmp (X (∗ u))) →
((a : val A) → (u : ext) → P.subst (λ a → cmp (X a)) (η≡∗ a u) (x0 a) ≡ x1 u ) →
cmp (X a)
●/ind/β₁ : ∀ {A} (a : val A) (X : val (● A) → tp neg)
(x0 : (a : val A) → cmp (X (η a))) →
(x1 : (u : ext) → cmp (X (∗ u))) →
(h : (a : val A) → (u : ext) → P.subst (λ a → cmp (X a)) (η≡∗ a u) (x0 a) ≡ x1 u ) →
●/ind (η a) X x0 x1 h ≡ x0 a
{-# REWRITE ●/ind/β₁ #-}
●/ind/β₂ : ∀ {A} (u : ext) (X : val (● A) → tp neg)
(x0 : (a : val A) → cmp (X (η a))) →
(x1 : (u : ext) → cmp (X (∗ u))) →
(h : (a : val A) → (u : ext) → P.subst (λ a → cmp (X a)) (η≡∗ a u) (x0 a) ≡ x1 u ) →
●/ind (∗ u) X x0 x1 h ≡ x1 u
{-# REWRITE ●/ind/β₂ #-}
| {
"alphanum_fraction": 0.4659353349,
"avg_line_length": 26.6461538462,
"ext": "agda",
"hexsha": "625030380e5084b16012b16ebdc984797ce31ff8",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/PhaseDistinction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/PhaseDistinction.agda",
"max_line_length": 88,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/PhaseDistinction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 805,
"size": 1732
} |
module Data.List.At where
open import Data.Nat
open import Data.List
open import Data.List.Relation.Unary.All hiding (map; lookup; _[_]=_)
open import Data.List.Relation.Unary.Any hiding (map; lookup)
open import Data.List.Membership.Propositional
open import Data.List.Relation.Binary.Pointwise hiding (refl; map)
open import Data.Fin hiding (_<_)
open import Data.Maybe hiding (map)
open import Data.Product hiding (map)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
maybe-lookup : ∀ {a}{A : Set a} → ℕ → List A → Maybe A
maybe-lookup n [] = nothing
maybe-lookup zero (x ∷ μ) = just x
maybe-lookup (suc n) (x ∷ μ) = maybe-lookup n μ
maybe-write : ∀ {a}{A : Set a} → ℕ → A → List A → Maybe (List A)
maybe-write n _ [] = nothing
maybe-write zero v (x ∷ z) = just (v ∷ z)
maybe-write (suc n) v (x ∷ z) = maybe-write n v z
_[_]=_ : ∀ {a}{A : Set a} → List A → ℕ → A → Set _
l [ i ]= x = maybe-lookup i l ≡ just x
[]=-map : ∀ {a b}{A : Set a}{B : Set b}{x} i → (l : List A) →
l [ i ]= x → ∀ (f : A → B) → (map f l) [ i ]= (f x)
[]=-map _ [] ()
[]=-map zero (x ∷ l) refl = λ f → refl
[]=-map (suc i) (x ∷ l) p = []=-map i l p
at-lookup : ∀ {a}{A : Set a} → (l : List A) → (i : Fin (length l)) → l [ toℕ i ]= (lookup l i)
at-lookup [] ()
at-lookup (x ∷ l) zero = refl
at-lookup (x ∷ l) (suc i) = at-lookup l i
lookup-in : ∀ {a}{A : Set a} → (l : List A) → (i : Fin (length l)) → (lookup l i) ∈ l
lookup-in [] ()
lookup-in (x ∷ l) zero = here refl
lookup-in (x ∷ l) (suc i) = there (lookup-in l i)
dec-lookup : ∀ {a} {A : Set a} → (i : ℕ) → (l : List A) → Dec (∃ λ x → l [ i ]= x)
dec-lookup _ [] = no (λ{ (_ , ())})
dec-lookup zero (x ∷ l) = yes (x , refl)
dec-lookup (suc i) (_ ∷ l) = dec-lookup i l
all-lookup : ∀ {a} {A : Set a} {l : List A} {i x p P} → l [ i ]= x → All {p = p} P l → P x
all-lookup {l = []} () q
all-lookup {l = x ∷ l} {zero} refl (px ∷ q) = px
all-lookup {l = x ∷ l} {suc i} p (px ∷ q) = all-lookup p q
[]=-length : ∀ {a} {A : Set a} (L : List A) {i x} → L [ i ]= x → i < length L
[]=-length [] ()
[]=-length (x ∷ L) {zero} refl = s≤s z≤n
[]=-length (x ∷ L) {suc i} p = s≤s ([]=-length L p)
∷ʳ[length] : ∀ {a} {A : Set a} (l : List A) x → (l ∷ʳ x) [ length l ]= x
∷ʳ[length] [] y = refl
∷ʳ[length] (x ∷ Σ) y = ∷ʳ[length] Σ y
pointwise-lookup : ∀ {a b ℓ A B P l m i x} → Pointwise {a} {b} {ℓ} {A} {B} P l m →
l [ i ]= x → ∃ λ y → m [ i ]= y × P x y
pointwise-lookup [] ()
pointwise-lookup {i = zero} (x∼y ∷ q) refl = _ , refl , x∼y
pointwise-lookup {i = suc i} (x∼y ∷ q) p = pointwise-lookup q p
pointwise-lookup′ : ∀ {a b ℓ A B P l m i x y} → Pointwise {a} {b} {ℓ} {A} {B} P l m →
l [ i ]= x → m [ i ]= y → P x y
pointwise-lookup′ [] () q
pointwise-lookup′ {i = zero} (x∼y ∷ z) refl refl = x∼y
pointwise-lookup′ {i = suc i} (x∼y ∷ z) p q = pointwise-lookup′ z p q
| {
"alphanum_fraction": 0.5358503637,
"avg_line_length": 39.0135135135,
"ext": "agda",
"hexsha": "dbf284f207b36955eaaffa22a88580fd756d790a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/Data/List/At.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/Data/List/At.agda",
"max_line_length": 94,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/Data/List/At.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 1192,
"size": 2887
} |
{-# OPTIONS --safe #-}
module Cubical.Relation.Binary.Poset where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Reflection.RecordEquiv
open import Cubical.Reflection.StrictEquiv
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Relation.Binary.Base
open Iso
open BinaryRelation
private
variable
ℓ ℓ' ℓ'' ℓ₀ ℓ₀' ℓ₁ ℓ₁' : Level
record IsPoset {A : Type ℓ} (_≤_ : A → A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
no-eta-equality
constructor isposet
field
is-set : isSet A
is-prop-valued : isPropValued _≤_
is-refl : isRefl _≤_
is-trans : isTrans _≤_
is-antisym : isAntisym _≤_
unquoteDecl IsPosetIsoΣ = declareRecordIsoΣ IsPosetIsoΣ (quote IsPoset)
record PosetStr (ℓ' : Level) (A : Type ℓ) : Type (ℓ-max ℓ (ℓ-suc ℓ')) where
constructor posetstr
field
_≤_ : A → A → Type ℓ'
isPoset : IsPoset _≤_
infixl 7 _≤_
open IsPoset isPoset public
Poset : ∀ ℓ ℓ' → Type (ℓ-max (ℓ-suc ℓ) (ℓ-suc ℓ'))
Poset ℓ ℓ' = TypeWithStr ℓ (PosetStr ℓ')
poset : (A : Type ℓ) (_≤_ : A → A → Type ℓ') (h : IsPoset _≤_) → Poset ℓ ℓ'
poset A _≤_ h = A , posetstr _≤_ h
record IsPosetEquiv {A : Type ℓ₀} {B : Type ℓ₁}
(M : PosetStr ℓ₀' A) (e : A ≃ B) (N : PosetStr ℓ₁' B)
: Type (ℓ-max (ℓ-max ℓ₀ ℓ₀') ℓ₁')
where
constructor
isposetequiv
-- Shorter qualified names
private
module M = PosetStr M
module N = PosetStr N
field
pres≤ : (x y : A) → x M.≤ y ≃ equivFun e x N.≤ equivFun e y
PosetEquiv : (M : Poset ℓ₀ ℓ₀') (M : Poset ℓ₁ ℓ₁') → Type (ℓ-max (ℓ-max ℓ₀ ℓ₀') (ℓ-max ℓ₁ ℓ₁'))
PosetEquiv M N = Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] IsPosetEquiv (M .snd) e (N .snd)
isPropIsPoset : {A : Type ℓ} (_≤_ : A → A → Type ℓ') → isProp (IsPoset _≤_)
isPropIsPoset _≤_ = isOfHLevelRetractFromIso 1 IsPosetIsoΣ
(isPropΣ isPropIsSet
λ isSetA → isPropΣ (isPropΠ2 (λ _ _ → isPropIsProp))
λ isPropValued≤ → isProp×2
(isPropΠ (λ _ → isPropValued≤ _ _))
(isPropΠ5 λ _ _ _ _ _ → isPropValued≤ _ _)
(isPropΠ4 λ _ _ _ _ → isSetA _ _))
𝒮ᴰ-Poset : DUARel (𝒮-Univ ℓ) (PosetStr ℓ') (ℓ-max ℓ ℓ')
𝒮ᴰ-Poset =
𝒮ᴰ-Record (𝒮-Univ _) IsPosetEquiv
(fields:
data[ _≤_ ∣ autoDUARel _ _ ∣ pres≤ ]
prop[ isPoset ∣ (λ _ _ → isPropIsPoset _) ])
where
open PosetStr
open IsPoset
open IsPosetEquiv
PosetPath : (M N : Poset ℓ ℓ') → PosetEquiv M N ≃ (M ≡ N)
PosetPath = ∫ 𝒮ᴰ-Poset .UARel.ua
-- an easier way of establishing an equivalence of posets
module _ {P : Poset ℓ₀ ℓ₀'} {S : Poset ℓ₁ ℓ₁'} (e : ⟨ P ⟩ ≃ ⟨ S ⟩) where
private
module P = PosetStr (P .snd)
module S = PosetStr (S .snd)
module _ (isMon : ∀ x y → x P.≤ y → equivFun e x S.≤ equivFun e y)
(isMonInv : ∀ x y → x S.≤ y → invEq e x P.≤ invEq e y) where
open IsPosetEquiv
open IsPoset
makeIsPosetEquiv : IsPosetEquiv (P .snd) e (S .snd)
pres≤ makeIsPosetEquiv x y = propBiimpl→Equiv (P.isPoset .is-prop-valued _ _)
(S.isPoset .is-prop-valued _ _)
(isMon _ _) (isMonInv' _ _)
where
isMonInv' : ∀ x y → equivFun e x S.≤ equivFun e y → x P.≤ y
isMonInv' x y ex≤ey = transport (λ i → retEq e x i P.≤ retEq e y i) (isMonInv _ _ ex≤ey)
module PosetReasoning (P' : Poset ℓ ℓ') where
private P = fst P'
open PosetStr (snd P')
open IsPoset
_≤⟨_⟩_ : (x : P) {y z : P} → x ≤ y → y ≤ z → x ≤ z
x ≤⟨ p ⟩ q = isPoset .is-trans x _ _ p q
_◾ : (x : P) → x ≤ x
x ◾ = isPoset .is-refl x
infixr 0 _≤⟨_⟩_
infix 1 _◾
| {
"alphanum_fraction": 0.6157476403,
"avg_line_length": 28.964028777,
"ext": "agda",
"hexsha": "57d7560484954e54589645ab285bd9fef9e68aa6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Relation/Binary/Poset.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Relation/Binary/Poset.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Relation/Binary/Poset.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 1617,
"size": 4026
} |
module Common where
data PSet (A : Set) : Set where
⦃⦄ : PSet A
_::_ : A -> PSet A -> PSet A
data Pair (A : Set) : Set where
<_,_> : A -> A -> Pair A
data Bool : Set where
true : Bool
false : Bool
neg : Bool -> Bool
neg true = false
neg false = true
_&&_ : Bool -> Bool -> Bool
true && true = true
_ && _ = false
_||_ : Bool -> Bool -> Bool
false || false = false
_ || _ = true
-- data _≡_ {a} {A : Set a} (x : A) : A → Set a where
-- instance refl : x ≡ x
-- data _≡_ {a} {A : Set a} : A → A → Set where
-- refl : (a : A) → a ≡ a
-- sym : ∀ x y → x ≡ y → y ≡ x
-- sym .a .a (refl a) = refl a
-- isEq : ∀ x y -> x ≡ y -> Bool
-- isEq .a .a (refl a) = true
record Eq {a} (A : Set a) : Set a where
field
_==_ : A → A → Bool
open Eq {{...}} public
instance
eqPair : {A : Set} {{_ : Eq A}} → Eq (Pair A)
_==_ {{eqPair}} < x₁ , x₂ > < y₁ , y₂ > = (x₁ == y₁) && (x₂ == y₂)
| {
"alphanum_fraction": 0.4872646733,
"avg_line_length": 20.0666666667,
"ext": "agda",
"hexsha": "5b13d291b44bc37ba05e498a078b0b2a435fd74c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9f8bbff7248dbeb54919e03957daf9b35ec1ac23",
"max_forks_repo_licenses": [
"Artistic-2.0"
],
"max_forks_repo_name": "daherb/Agda-Montague",
"max_forks_repo_path": "Common.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f8bbff7248dbeb54919e03957daf9b35ec1ac23",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Artistic-2.0"
],
"max_issues_repo_name": "daherb/Agda-Montague",
"max_issues_repo_path": "Common.agda",
"max_line_length": 68,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9f8bbff7248dbeb54919e03957daf9b35ec1ac23",
"max_stars_repo_licenses": [
"Artistic-2.0"
],
"max_stars_repo_name": "daherb/Agda-Montague",
"max_stars_repo_path": "Common.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-18T11:56:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-18T11:56:24.000Z",
"num_tokens": 377,
"size": 903
} |
module Issue373 where
data Nat : Set where
zero : Nat
suc : (n : Nat) → Nat
{-# BUILTIN NATURAL Nat #-}
{-# FOREIGN GHC data Nat = Zero | Suc Nat #-}
{-# COMPILE GHC Nat = data Nat (Zero | Suc) #-} -- should fail when compiling
| {
"alphanum_fraction": 0.6144067797,
"avg_line_length": 21.4545454545,
"ext": "agda",
"hexsha": "5055488a510cda76c23416681e539a520e766b96",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue373.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue373.agda",
"max_line_length": 77,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue373.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 67,
"size": 236
} |
{-# OPTIONS --safe #-}
module Cubical.Data.Fin.Recursive where
open import Cubical.Data.Fin.Recursive.Base public
open import Cubical.Data.Fin.Recursive.Properties public
| {
"alphanum_fraction": 0.7919075145,
"avg_line_length": 24.7142857143,
"ext": "agda",
"hexsha": "bbba831b29e491ee6a59f2c6f96313a2c112fa59",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Data/Fin/Recursive.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Data/Fin/Recursive.agda",
"max_line_length": 56,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Data/Fin/Recursive.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 39,
"size": 173
} |
module Issue591 where
import Issue591.M
| {
"alphanum_fraction": 0.8292682927,
"avg_line_length": 10.25,
"ext": "agda",
"hexsha": "6d3d64f91563751ff72a33a644cb24eb19778ee4",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue591.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue591.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue591.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 10,
"size": 41
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A categorical view of List
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Categorical where
open import Category.Functor
open import Category.Applicative
open import Category.Monad
open import Data.Bool.Base using (false; true)
open import Data.List
open import Data.List.Properties
open import Function
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; _≗_; refl)
open P.≡-Reasoning
------------------------------------------------------------------------
-- List applicative functor
functor : ∀ {ℓ} → RawFunctor {ℓ} List
functor = record { _<$>_ = map }
applicative : ∀ {ℓ} → RawApplicative {ℓ} List
applicative = record
{ pure = [_]
; _⊛_ = λ fs as → concatMap (λ f → map f as) fs
}
applicativeZero : ∀ {ℓ} → RawApplicativeZero {ℓ} List
applicativeZero = record
{ applicative = applicative
; ∅ = []
}
alternative : ∀ {ℓ} → RawAlternative {ℓ} List
alternative = record
{ applicativeZero = applicativeZero
; _∣_ = _++_
}
------------------------------------------------------------------------
-- List monad
monad : ∀ {ℓ} → RawMonad {ℓ} List
monad = record
{ return = [_]
; _>>=_ = flip concatMap
}
monadZero : ∀ {ℓ} → RawMonadZero {ℓ} List
monadZero = record
{ monad = monad
; applicativeZero = applicativeZero
}
monadPlus : ∀ {ℓ} → RawMonadPlus {ℓ} List
monadPlus = record
{ monad = monad
; alternative = alternative
}
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {f F} (App : RawApplicative {f} F) where
open RawApplicative App
sequenceA : ∀ {A} → List (F A) → F (List A)
sequenceA [] = pure []
sequenceA (x ∷ xs) = _∷_ <$> x ⊛ sequenceA xs
mapA : ∀ {a} {A : Set a} {B} → (A → F B) → List A → F (List B)
mapA f = sequenceA ∘ map f
forA : ∀ {a} {A : Set a} {B} → List A → (A → F B) → F (List B)
forA = flip mapA
module _ {m M} (Mon : RawMonad {m} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM = sequenceA App
mapM = mapA App
forM = forA App
------------------------------------------------------------------------
-- List monad transformer
monadT : ∀ {ℓ} → RawMonadT {ℓ} (_∘′ List)
monadT M = record
{ return = pure ∘′ [_]
; _>>=_ = λ mas f → mas >>= λ as → concat <$> mapM M f as
} where open RawMonad M
------------------------------------------------------------------------
-- The list monad.
private
open module LMP {ℓ} = RawMonadPlus (monadPlus {ℓ = ℓ})
module MonadProperties where
left-identity : ∀ {ℓ} {A B : Set ℓ} (x : A) (f : A → List B) →
(return x >>= f) ≡ f x
left-identity x f = ++-identityʳ (f x)
right-identity : ∀ {ℓ} {A : Set ℓ} (xs : List A) →
(xs >>= return) ≡ xs
right-identity [] = refl
right-identity (x ∷ xs) = P.cong (x ∷_) (right-identity xs)
left-zero : ∀ {ℓ} {A B : Set ℓ} (f : A → List B) → (∅ >>= f) ≡ ∅
left-zero f = refl
right-zero : ∀ {ℓ} {A B : Set ℓ} (xs : List A) →
(xs >>= const ∅) ≡ ∅ {A = B}
right-zero [] = refl
right-zero (x ∷ xs) = right-zero xs
private
not-left-distributive :
let xs = true ∷ false ∷ []; f = return; g = return in
(xs >>= λ x → f x ∣ g x) ≢ ((xs >>= f) ∣ (xs >>= g))
not-left-distributive ()
right-distributive : ∀ {ℓ} {A B : Set ℓ}
(xs ys : List A) (f : A → List B) →
(xs ∣ ys >>= f) ≡ ((xs >>= f) ∣ (ys >>= f))
right-distributive [] ys f = refl
right-distributive (x ∷ xs) ys f = begin
f x ∣ (xs ∣ ys >>= f) ≡⟨ P.cong (f x ∣_) $ right-distributive xs ys f ⟩
f x ∣ ((xs >>= f) ∣ (ys >>= f)) ≡⟨ P.sym $ ++-assoc (f x) _ _ ⟩
((f x ∣ (xs >>= f)) ∣ (ys >>= f)) ∎
associative : ∀ {ℓ} {A B C : Set ℓ}
(xs : List A) (f : A → List B) (g : B → List C) →
(xs >>= λ x → f x >>= g) ≡ (xs >>= f >>= g)
associative [] f g = refl
associative (x ∷ xs) f g = begin
(f x >>= g) ∣ (xs >>= λ x → f x >>= g) ≡⟨ P.cong ((f x >>= g) ∣_) $ associative xs f g ⟩
(f x >>= g) ∣ (xs >>= f >>= g) ≡⟨ P.sym $ right-distributive (f x) (xs >>= f) g ⟩
(f x ∣ (xs >>= f) >>= g) ∎
cong : ∀ {ℓ} {A B : Set ℓ} {xs₁ xs₂} {f₁ f₂ : A → List B} →
xs₁ ≡ xs₂ → f₁ ≗ f₂ → (xs₁ >>= f₁) ≡ (xs₂ >>= f₂)
cong {xs₁ = xs} refl f₁≗f₂ = P.cong concat (map-cong f₁≗f₂ xs)
------------------------------------------------------------------------
-- The applicative functor derived from the list monad.
-- Note that these proofs (almost) show that RawIMonad.rawIApplicative
-- is correctly defined. The proofs can be reused if proof components
-- are ever added to RawIMonad and RawIApplicative.
module Applicative where
private
module MP = MonadProperties
-- A variant of flip map.
pam : ∀ {ℓ} {A B : Set ℓ} → List A → (A → B) → List B
pam xs f = xs >>= return ∘ f
-- ∅ is a left zero for _⊛_.
left-zero : ∀ {ℓ} {A B : Set ℓ} (xs : List A) → (∅ ⊛ xs) ≡ ∅ {A = B}
left-zero xs = begin
∅ ⊛ xs ≡⟨⟩
(∅ >>= pam xs) ≡⟨ MonadProperties.left-zero (pam xs) ⟩
∅ ∎
-- ∅ is a right zero for _⊛_.
right-zero : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) → (fs ⊛ ∅) ≡ ∅
right-zero {ℓ} fs = begin
fs ⊛ ∅ ≡⟨⟩
(fs >>= pam ∅) ≡⟨ (MP.cong (refl {x = fs}) λ f →
MP.left-zero (return ∘ f)) ⟩
(fs >>= λ _ → ∅) ≡⟨ MP.right-zero fs ⟩
∅ ∎
-- _⊛_ distributes over _∣_ from the right.
right-distributive : ∀ {ℓ} {A B : Set ℓ} (fs₁ fs₂ : List (A → B)) xs →
((fs₁ ∣ fs₂) ⊛ xs) ≡ (fs₁ ⊛ xs ∣ fs₂ ⊛ xs)
right-distributive fs₁ fs₂ xs = begin
(fs₁ ∣ fs₂) ⊛ xs ≡⟨⟩
(fs₁ ∣ fs₂ >>= pam xs) ≡⟨ MonadProperties.right-distributive fs₁ fs₂ (pam xs) ⟩
(fs₁ >>= pam xs) ∣ (fs₂ >>= pam xs) ≡⟨⟩
(fs₁ ⊛ xs ∣ fs₂ ⊛ xs) ∎
-- _⊛_ does not distribute over _∣_ from the left.
private
not-left-distributive :
let fs = id ∷ id ∷ []; xs₁ = true ∷ []; xs₂ = true ∷ false ∷ [] in
(fs ⊛ (xs₁ ∣ xs₂)) ≢ (fs ⊛ xs₁ ∣ fs ⊛ xs₂)
not-left-distributive ()
-- Applicative functor laws.
identity : ∀ {a} {A : Set a} (xs : List A) → (return id ⊛ xs) ≡ xs
identity xs = begin
return id ⊛ xs ≡⟨⟩
(return id >>= pam xs) ≡⟨ MonadProperties.left-identity id (pam xs) ⟩
(xs >>= return) ≡⟨ MonadProperties.right-identity xs ⟩
xs ∎
private
pam-lemma : ∀ {ℓ} {A B C : Set ℓ}
(xs : List A) (f : A → B) (fs : B → List C) →
(pam xs f >>= fs) ≡ (xs >>= λ x → fs (f x))
pam-lemma xs f fs = begin
(pam xs f >>= fs) ≡⟨ P.sym $ MP.associative xs (return ∘ f) fs ⟩
(xs >>= λ x → return (f x) >>= fs) ≡⟨ MP.cong (refl {x = xs}) (λ x → MP.left-identity (f x) fs) ⟩
(xs >>= λ x → fs (f x)) ∎
composition : ∀ {ℓ} {A B C : Set ℓ}
(fs : List (B → C)) (gs : List (A → B)) xs →
(return _∘′_ ⊛ fs ⊛ gs ⊛ xs) ≡ (fs ⊛ (gs ⊛ xs))
composition {ℓ} fs gs xs = begin
return _∘′_ ⊛ fs ⊛ gs ⊛ xs ≡⟨⟩
(return _∘′_ >>= pam fs >>= pam gs >>= pam xs) ≡⟨ MP.cong (MP.cong (MP.left-identity _∘′_ (pam fs))
(λ f → refl {x = pam gs f}))
(λ fg → refl {x = pam xs fg}) ⟩
(pam fs _∘′_ >>= pam gs >>= pam xs) ≡⟨ MP.cong (pam-lemma fs _∘′_ (pam gs)) (λ _ → refl) ⟩
((fs >>= λ f → pam gs (f ∘′_)) >>= pam xs) ≡⟨ P.sym $ MP.associative fs (λ f → pam gs (_∘′_ f)) (pam xs) ⟩
(fs >>= λ f → pam gs (f ∘′_) >>= pam xs) ≡⟨ (MP.cong (refl {x = fs}) λ f →
pam-lemma gs (f ∘′_) (pam xs)) ⟩
(fs >>= λ f → gs >>= λ g → pam xs (f ∘′ g)) ≡⟨ (MP.cong (refl {x = fs}) λ f →
MP.cong (refl {x = gs}) λ g →
P.sym $ pam-lemma xs g (return ∘ f)) ⟩
(fs >>= λ f → gs >>= λ g → pam (pam xs g) f) ≡⟨ (MP.cong (refl {x = fs}) λ f →
MP.associative gs (pam xs) (return ∘ f)) ⟩
(fs >>= pam (gs >>= pam xs)) ≡⟨⟩
fs ⊛ (gs ⊛ xs) ∎
homomorphism : ∀ {ℓ} {A B : Set ℓ} (f : A → B) x →
(return f ⊛ return x) ≡ return (f x)
homomorphism f x = begin
return f ⊛ return x ≡⟨⟩
(return f >>= pam (return x)) ≡⟨ MP.left-identity f (pam (return x)) ⟩
pam (return x) f ≡⟨ MP.left-identity x (return ∘ f) ⟩
return (f x) ∎
interchange : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) {x} →
(fs ⊛ return x) ≡ (return (λ f → f x) ⊛ fs)
interchange fs {x} = begin
fs ⊛ return x ≡⟨⟩
(fs >>= pam (return x)) ≡⟨ (MP.cong (refl {x = fs}) λ f →
MP.left-identity x (return ∘ f)) ⟩
(fs >>= λ f → return (f x)) ≡⟨⟩
(pam fs (λ f → f x)) ≡⟨ P.sym $ MP.left-identity (λ f → f x) (pam fs) ⟩
(return (λ f → f x) >>= pam fs) ≡⟨⟩
return (λ f → f x) ⊛ fs ∎
| {
"alphanum_fraction": 0.4337738009,
"avg_line_length": 35.9962546816,
"ext": "agda",
"hexsha": "725c052ef871fe817781cce083ec0c5b4d167ced",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Categorical.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Categorical.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Categorical.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3356,
"size": 9611
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Functors where
-- the "Functor Category", often denoted [ C , D ]
open import Level
open import Data.Product using (_,_; proj₁; uncurry′)
open import Categories.Category using (Category; _[_∘_])
open import Categories.Category.Equivalence using (StrongEquivalence)
open import Categories.Category.Product using (_※ⁿ_) renaming (Product to _×_)
open import Categories.Functor using (Functor; _∘F_)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Construction.Constant using (constNat)
open import Categories.NaturalTransformation
using (NaturalTransformation; _∘ᵥ_; _∘ˡ_; _∘ₕ_) renaming (id to idN)
open import Categories.NaturalTransformation.Equivalence using (_≃_; ≃-isEquivalence)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (NaturalIsomorphism)
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e o′ ℓ′ e′ : Level
C D C₁ C₂ : Category o ℓ e
-- The reason the proofs below are so easy is that _∘ᵥ_ 'computes' all the way down into
-- expressions in D, from which the properties follow.
Functors : Category o ℓ e → Category o′ ℓ′ e′ → Category (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) (o ⊔ e′)
Functors C D = record
{ Obj = Functor C D
; _⇒_ = NaturalTransformation
; _≈_ = _≃_
; id = idN
; _∘_ = _∘ᵥ_
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = ≃-isEquivalence
; ∘-resp-≈ = λ eq eq′ → ∘-resp-≈ eq eq′
}
where module C = Category C
module D = Category D
open D
-- Part of the proof that Cats is a CCC:
eval : Bifunctor (Functors C D) C D
eval {C = C} {D = D} = record
{ F₀ = uncurry′ Functor.F₀
; F₁ = λ where
{F , _} {_ , B} (α , f) →
let open NaturalTransformation α
open Functor F
in η B ∘ F₁ f
; identity = λ where
{F , _} → elimʳ (Functor.identity F)
; homomorphism = λ where
{F , _} {G , B} {_ , C} {α , f} {β , g} →
let open NaturalTransformation
open Functor
in begin
(η β C ∘ η α C) ∘ F₁ F (g C.∘ f) ≈⟨ refl ⟩∘⟨ homomorphism F ⟩
(η β C ∘ η α C) ∘ F₁ F g ∘ F₁ F f ≈⟨ assoc ⟩
η β C ∘ η α C ∘ F₁ F g ∘ F₁ F f ≈⟨ refl ⟩∘⟨ pullˡ (commute α g) ⟩
η β C ∘ (F₁ G g ∘ η α B) ∘ F₁ F f ≈⟨ refl ⟩∘⟨ assoc ⟩
η β C ∘ F₁ G g ∘ η α B ∘ F₁ F f ≈˘⟨ assoc ⟩
(η β C ∘ F₁ G g) ∘ η α B ∘ F₁ F f ∎
; F-resp-≈ = λ where
{F , _} (comm , eq) → ∘-resp-≈ comm (Functor.F-resp-≈ F eq)
}
where module C = Category C
module D = Category D
open D
open MR D
open HomReasoning
-- Currying induces a functor between functor categories -- another
-- part of the proof that Cats is a catesian closed (bi)category.
curry : Functor (Functors (C₁ × C₂) D) (Functors C₁ (Functors C₂ D))
curry {C₁ = C₁} {C₂ = C₂} {D = D} = record
{ F₀ = curry₀
; F₁ = curry₁
; identity = Equiv.refl D
; homomorphism = Equiv.refl D
; F-resp-≈ = λ F≈G {x₁} {x₂} → F≈G {x₁ , x₂}
}
where
open Category
curry₀ : Bifunctor C₁ C₂ D → Functor C₁ (Functors C₂ D)
curry₀ F = record
{ F₀ = λ c → appˡ F c
; F₁ = λ f → F ∘ˡ (constNat f ※ⁿ idN)
; identity = identity
; homomorphism = λ {_} {_} {_} {f} {g} → begin
F₁ (C₁ [ g ∘ f ] , id C₂)
≈˘⟨ F-resp-≈ (Equiv.refl C₁ , identityˡ C₂) ⟩
F₁ (C₁ [ g ∘ f ] , C₂ [ id C₂ ∘ id C₂ ])
≈⟨ homomorphism ⟩
D [ F₁ (g , id C₂) ∘ F₁ (f , id C₂) ]
∎
; F-resp-≈ = λ f≈g → F-resp-≈ (f≈g , Equiv.refl C₂)
}
where
open Functor F
open HomReasoning D
curry₁ : {F G : Bifunctor C₁ C₂ D} →
NaturalTransformation F G →
NaturalTransformation (curry₀ F) (curry₀ G)
curry₁ α = record
{ η = λ c → record
{ η = λ a → η α (c , a)
; commute = λ f → commute α (id C₁ , f)
; sym-commute = λ f → sym-commute α (id C₁ , f)
}
; commute = λ f → commute α (f , id C₂)
; sym-commute = λ f → sym-commute α (f , id C₂)
}
where open NaturalTransformation
module curry {o₁ e₁ ℓ₁} {C₁ : Category o₁ e₁ ℓ₁}
{o₂ e₂ ℓ₂} {C₂ : Category o₂ e₂ ℓ₂}
{o′ e′ ℓ′} {D : Category o′ e′ ℓ′}
where
open Functor (curry {C₁ = C₁} {C₂ = C₂} {D = D}) public
open Category
open NaturalIsomorphism
-- Currying preserves natural isos.
-- This makes |curry.F₀| a map between the hom-setoids of Cats.
resp-NI : {F G : Bifunctor C₁ C₂ D} →
NaturalIsomorphism F G → NaturalIsomorphism (F₀ F) (F₀ G)
resp-NI α = record
{ F⇒G = F₁ (F⇒G α)
; F⇐G = F₁ (F⇐G α)
; iso = λ x → record
{ isoˡ = iso.isoˡ α (x , _)
; isoʳ = iso.isoʳ α (x , _)
}
}
-- Godement product ?
product : {A B C : Category o ℓ e} → Bifunctor (Functors B C) (Functors A B) (Functors A C)
product {A = A} {B = B} {C = C} = record
{ F₀ = uncurry′ _∘F_
; F₁ = uncurry′ _∘ₕ_
; identity = λ {f} → identityʳ ○ identity {D = C} (proj₁ f)
; homomorphism = λ { {_ , F₂} {G₁ , G₂} {H₁ , _} {f₁ , f₂} {g₁ , g₂} {x} → begin
F₁ H₁ (η g₂ x B.∘ η f₂ x) ∘ η g₁ (F₀ F₂ x) ∘ η f₁ (F₀ F₂ x)
≈⟨ ∘-resp-≈ˡ (homomorphism H₁) ○ assoc ○ ∘-resp-≈ʳ (⟺ assoc) ⟩
F₁ H₁ (η g₂ x) ∘ (F₁ H₁ (η f₂ x) ∘ η g₁ (F₀ F₂ x)) ∘ η f₁ (F₀ F₂ x)
≈⟨ ⟺ ( refl⟩∘⟨ ( commute g₁ (η f₂ x) ⟩∘⟨refl) ) ⟩
F₁ H₁ (η g₂ x) ∘ (η g₁ (F₀ G₂ x) ∘ F₁ G₁ (η f₂ x)) ∘ η f₁ (F₀ F₂ x)
≈⟨ ∘-resp-≈ʳ assoc ○ ⟺ assoc ⟩
(F₁ H₁ (η g₂ x) ∘ η g₁ (F₀ G₂ x)) ∘ F₁ G₁ (η f₂ x) ∘ η f₁ (F₀ F₂ x) ∎ }
; F-resp-≈ = λ { {_} {g₁ , _} (≈₁ , ≈₂) → ∘-resp-≈ (F-resp-≈ g₁ ≈₂) ≈₁ }
}
where
open Category C
open HomReasoning
open Functor
module B = Category B
open NaturalTransformation
-- op induces a Functor on the Functors category.
-- This is an instance where the proof-irrelevant version is simpler because (op op C) is
-- just C. Here we rather need to be more explicit.
opF⇒ : {A : Category o ℓ e} {B : Category o′ ℓ′ e′} →
Functor (Category.op (Functors (Category.op A) (Category.op B))) (Functors A B)
opF⇒ {A = A} {B} = record
{ F₀ = Functor.op
; F₁ = NaturalTransformation.op
; identity = Equiv.refl
; homomorphism = Equiv.refl
; F-resp-≈ = λ eq → eq
}
where open Category B
opF⇐ : {A : Category o ℓ e} {B : Category o′ ℓ′ e′} →
Functor (Functors A B) (Category.op (Functors (Category.op A) (Category.op B)))
opF⇐ {A = A} {B} = record
{ F₀ = Functor.op
; F₁ = NaturalTransformation.op
; identity = Equiv.refl
; homomorphism = Equiv.refl
; F-resp-≈ = λ eq → eq
}
where open Category B
Functorsᵒᵖ-equiv : {A : Category o ℓ e} {B : Category o′ ℓ′ e′} →
StrongEquivalence (Category.op (Functors (Category.op A) (Category.op B))) (Functors A B)
Functorsᵒᵖ-equiv {B = B} = record
{ F = opF⇒
; G = opF⇐
; weak-inverse = record
{ F∘G≈id = record
{ F⇒G = record
{ η = λ _ → idN
; commute = λ _ → id-comm-sym
; sym-commute = λ _ → id-comm
}
; F⇐G = record
{ η = λ _ → idN
; commute = λ _ → id-comm-sym
; sym-commute = λ _ → id-comm
}
; iso = λ _ → record
{ isoˡ = identityˡ
; isoʳ = identityˡ
}
}
; G∘F≈id = record
{ F⇒G = record
{ η = λ _ → idN
; commute = λ _ → id-comm-sym
; sym-commute = λ _ → id-comm
}
; F⇐G = record
{ η = λ _ → idN
; commute = λ _ → id-comm-sym
; sym-commute = λ _ → id-comm
}
; iso = λ _ → record
{ isoˡ = identityˡ
; isoʳ = identityˡ
}
}
}
}
where open Category B
open HomReasoning
open MR B
| {
"alphanum_fraction": 0.5355674598,
"avg_line_length": 33.7268907563,
"ext": "agda",
"hexsha": "d0a1950b8a839432ab7b8c50695684f14ab1e2b8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Category/Construction/Functors.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Category/Construction/Functors.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Category/Construction/Functors.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3138,
"size": 8027
} |
{-# OPTIONS --without-K #-}
data D : Set → Set₁ where
c : (@0 A : Set) → D A
| {
"alphanum_fraction": 0.5,
"avg_line_length": 16,
"ext": "agda",
"hexsha": "bc8d305e820cc4b7bebaa912d959f7613d1f642e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Fail/Issue5434-1.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Fail/Issue5434-1.agda",
"max_line_length": 27,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Fail/Issue5434-1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 80
} |
-- Laws for weakenings and substitutions.
{-# OPTIONS --without-K --safe #-}
module Definition.Untyped.Properties where
open import Definition.Untyped
open import Tools.Nat
open import Tools.List
open import Tools.PropositionalEquality hiding (subst)
-- Weakening properties
-- Two weakenings ρ and ρ′ are extensionally equal if they agree on
-- all arguments when interpreted as functions mapping variables to
-- variables. Formally, they are considered equal iff
--
-- (∀ x → wkVar ρ x ≡ wkVar ρ′ x)
--
-- Intensional (propositional) equality would be too fine. For
-- instance,
--
-- lift id : Γ∙A ≤ Γ∙A
--
-- is extensionally equal to
--
-- id : Γ∙A ≤ Γ∙A
--
-- but syntactically different.
-- "lift" preserves equality of weakenings. Or:
-- If two weakenings are equal under wkVar, then they are equal when lifted.
wkVar-lift : ∀ {ρ ρ′}
→ (∀ x → wkVar ρ x ≡ wkVar ρ′ x)
→ (∀ x → wkVar (lift ρ) x ≡ wkVar (lift ρ′) x)
wkVar-lift eq 0 = refl
wkVar-lift eq (1+ x) = cong 1+ (eq x)
wkVar-lifts : ∀ {ρ ρ′}
→ (∀ x → wkVar ρ x ≡ wkVar ρ′ x)
→ (∀ n x → wkVar (repeat lift ρ n) x ≡ wkVar (repeat lift ρ′ n) x)
wkVar-lifts eq 0 x = eq x
wkVar-lifts eq (1+ n) x = wkVar-lift (wkVar-lifts eq n) x
-- Extensionally equal weakenings, if applied to a term,
-- yield the same weakened term. Or:
-- If two weakenings are equal under wkVar, then they are equal under wk.
mutual
wkVar-to-wk : ∀ {ρ ρ′}
→ (∀ x → wkVar ρ x ≡ wkVar ρ′ x)
→ ∀ t → wk ρ t ≡ wk ρ′ t
wkVar-to-wk eq (var x) = cong var (eq x)
wkVar-to-wk eq (gen x c) = cong (gen x) (wkVar-to-wkGen eq c)
wkVar-to-wkGen : ∀ {ρ ρ′}
→ (∀ x → wkVar ρ x ≡ wkVar ρ′ x)
→ ∀ t → wkGen ρ t ≡ wkGen ρ′ t
wkVar-to-wkGen eq [] = refl
wkVar-to-wkGen eq (⟦ l , t ⟧ ∷ g) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (wkVar-to-wk (wkVar-lifts eq l) t))
(wkVar-to-wkGen eq g)
-- lift id is extensionally equal to id.
wkVar-lift-id : (x : Nat) → wkVar (lift id) x ≡ wkVar id x
wkVar-lift-id 0 = refl
wkVar-lift-id (1+ x) = refl
wkVar-lifts-id : (n x : Nat) → wkVar (repeat lift id n) x ≡ wkVar id x
wkVar-lifts-id 0 x = refl
wkVar-lifts-id (1+ n) 0 = refl
wkVar-lifts-id (1+ n) (1+ x) = cong 1+ (wkVar-lifts-id n x)
-- id is the identity renaming.
wkVar-id : (x : Nat) → wkVar id x ≡ x
wkVar-id x = refl
mutual
wk-id : (t : Term) → wk id t ≡ t
wk-id (var x) = refl
wk-id (gen x c) = cong (gen x) (wkGen-id c)
wkGen-id : ∀ x → wkGen id x ≡ x
wkGen-id [] = refl
wkGen-id (⟦ l , t ⟧ ∷ g) =
cong₂ _∷_ (cong (⟦_,_⟧ l)
(trans (wkVar-to-wk (wkVar-lifts-id l) t) (wk-id t))) (wkGen-id g)
-- lift id is also the identity renaming.
wk-lift-id : (t : Term) → wk (lift id) t ≡ t
wk-lift-id t = trans (wkVar-to-wk wkVar-lift-id t) (wk-id t)
-- The composition of weakenings is correct...
--
-- ...as action on variables.
wkVar-comp : ∀ ρ ρ′ x → wkVar ρ (wkVar ρ′ x) ≡ wkVar (ρ • ρ′) x
wkVar-comp id ρ′ x = refl
wkVar-comp (step ρ) ρ′ x = cong 1+ (wkVar-comp ρ ρ′ x)
wkVar-comp (lift ρ) id x = refl
wkVar-comp (lift ρ) (step ρ′) x = cong 1+ (wkVar-comp ρ ρ′ x)
wkVar-comp (lift ρ) (lift ρ′) 0 = refl
wkVar-comp (lift ρ) (lift ρ′) (1+ x) = cong 1+ (wkVar-comp ρ ρ′ x)
wkVar-comps : ∀ n ρ ρ′ x
→ wkVar (repeat lift ρ n • repeat lift ρ′ n) x
≡ wkVar (repeat lift (ρ • ρ′) n) x
wkVar-comps 0 ρ ρ′ x = refl
wkVar-comps (1+ n) ρ ρ′ 0 = refl
wkVar-comps (1+ n) ρ ρ′ (1+ x) = cong 1+ (wkVar-comps n ρ ρ′ x)
-- ... as action on terms.
mutual
wk-comp : ∀ ρ ρ′ t → wk ρ (wk ρ′ t) ≡ wk (ρ • ρ′) t
wk-comp ρ ρ′ (var x) = cong var (wkVar-comp ρ ρ′ x)
wk-comp ρ ρ′ (gen x c) = cong (gen x) (wkGen-comp ρ ρ′ c)
wkGen-comp : ∀ ρ ρ′ g → wkGen ρ (wkGen ρ′ g) ≡ wkGen (ρ • ρ′) g
wkGen-comp ρ ρ′ [] = refl
wkGen-comp ρ ρ′ (⟦ l , t ⟧ ∷ g) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wk-comp (repeat lift ρ l) (repeat lift ρ′ l) t)
(wkVar-to-wk (wkVar-comps l ρ ρ′) t)))
(wkGen-comp ρ ρ′ g)
-- The following lemmata are variations on the equality
--
-- wk1 ∘ ρ = lift ρ ∘ wk1.
--
-- Typing: Γ∙A ≤ Γ ≤ Δ <==> Γ∙A ≤ Δ∙A ≤ Δ.
lift-step-comp : (ρ : Wk) → step id • ρ ≡ lift ρ • step id
lift-step-comp id = refl
lift-step-comp (step ρ) = cong step (lift-step-comp ρ)
lift-step-comp (lift ρ) = refl
wk1-wk : ∀ ρ t → wk1 (wk ρ t) ≡ wk (step ρ) t
wk1-wk ρ t = wk-comp (step id) ρ t
lift-wk1 : ∀ ρ t → wk (lift ρ) (wk1 t) ≡ wk (step ρ) t
lift-wk1 pr A = trans (wk-comp (lift pr) (step id) A)
(sym (cong (λ x → wk x A) (lift-step-comp pr)))
wk1-wk≡lift-wk1 : ∀ ρ t → wk1 (wk ρ t) ≡ wk (lift ρ) (wk1 t)
wk1-wk≡lift-wk1 ρ t = trans (wk1-wk ρ t) (sym (lift-wk1 ρ t))
-- Substitution properties.
-- Two substitutions σ and σ′ are equal if they are pointwise equal,
-- i.e., agree on all variables.
--
-- ∀ x → σ x ≡ σ′ x
-- If σ = σ′ then lift σ = lift σ′.
substVar-lift : ∀ {σ σ′}
→ (∀ x → σ x ≡ σ′ x)
→ ∀ x → liftSubst σ x ≡ liftSubst σ′ x
substVar-lift eq 0 = refl
substVar-lift eq (1+ x) = cong wk1 (eq x)
substVar-lifts : ∀ {σ σ′}
→ (∀ x → σ x ≡ σ′ x)
→ ∀ n x → repeat liftSubst σ n x ≡ repeat liftSubst σ′ n x
substVar-lifts eq 0 x = eq x
substVar-lifts eq (1+ n) 0 = refl
substVar-lifts eq (1+ n) (1+ x) = cong wk1 (substVar-lifts eq n x)
-- If σ = σ′ then subst σ t = subst σ′ t.
mutual
substVar-to-subst : ∀ {σ σ′}
→ ((x : Nat) → σ x ≡ σ′ x)
→ (t : Term) → subst σ t ≡ subst σ′ t
substVar-to-subst eq (var x) = eq x
substVar-to-subst eq (gen x c) = cong (gen x) (substVar-to-substGen eq c)
substVar-to-substGen : ∀ {σ σ′}
→ ((x : Nat) → σ x ≡ σ′ x)
→ ∀ g → substGen σ g ≡ substGen σ′ g
substVar-to-substGen eq [] = refl
substVar-to-substGen eq (⟦ l , t ⟧ ∷ g) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (substVar-to-subst (substVar-lifts eq l) t))
(substVar-to-substGen eq g)
-- lift id = id (as substitutions)
subst-lift-id : (x : Nat) → (liftSubst idSubst) x ≡ idSubst x
subst-lift-id 0 = refl
subst-lift-id (1+ x) = refl
subst-lifts-id : (n x : Nat) → (repeat liftSubst idSubst n) x ≡ idSubst x
subst-lifts-id 0 x = refl
subst-lifts-id (1+ n) 0 = refl
subst-lifts-id (1+ n) (1+ x) = cong wk1 (subst-lifts-id n x)
-- Identity substitution.
mutual
subst-id : (t : Term) → subst idSubst t ≡ t
subst-id (var x) = refl
subst-id (gen x c) = cong (gen x) (substGen-id c)
substGen-id : ∀ g → substGen idSubst g ≡ g
substGen-id [] = refl
substGen-id (⟦ l , t ⟧ ∷ g) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (substVar-to-subst (subst-lifts-id l) t)
(subst-id t)))
(substGen-id g)
-- Correctness of composition of weakening and substitution.
-- Composition of liftings is lifting of the composition.
-- lift ρ •ₛ lift σ = lift (ρ •ₛ σ)
subst-lift-•ₛ : ∀ {ρ σ} t
→ subst (lift ρ •ₛ liftSubst σ) t
≡ subst (liftSubst (ρ •ₛ σ)) t
subst-lift-•ₛ =
substVar-to-subst (λ { 0 → refl ; (1+ x) → sym (wk1-wk≡lift-wk1 _ _)})
helper1 : ∀ {ρ σ} (n x : Nat) →
(lift (repeat lift ρ n) •ₛ liftSubst (repeat liftSubst σ n)) x ≡
liftSubst (repeat liftSubst (ρ •ₛ σ) n) x
helper1 0 0 = refl
helper1 0 (1+ x) = sym (wk1-wk≡lift-wk1 _ _)
helper1 (1+ n) 0 = refl
helper1 (1+ n) (1+ x) = trans (sym (wk1-wk≡lift-wk1 _ _)) (cong wk1 (helper1 n x))
subst-lifts-•ₛ : ∀ {ρ σ} n t
→ subst (repeat lift ρ n •ₛ repeat liftSubst σ n) t
≡ subst (repeat liftSubst (ρ •ₛ σ) n) t
subst-lifts-•ₛ 0 t = refl
subst-lifts-•ₛ (1+ n) t = substVar-to-subst (helper1 n) t
-- lift σ ₛ• lift ρ = lift (σ ₛ• ρ)
subst-lift-ₛ• : ∀ {ρ σ} t
→ subst (liftSubst σ ₛ• lift ρ) t
≡ subst (liftSubst (σ ₛ• ρ)) t
subst-lift-ₛ• = substVar-to-subst (λ { 0 → refl ; (1+ x) → refl})
helper2 : ∀ {ρ σ} (n x : Nat) →
liftSubst (repeat liftSubst σ n) (wkVar (lift (repeat lift ρ n)) x) ≡
liftSubst (repeat liftSubst (λ x₁ → σ (wkVar ρ x₁)) n) x
helper2 0 0 = refl
helper2 0 (1+ x) = refl
helper2 (1+ n) 0 = refl
helper2 (1+ n) (1+ x) = cong wk1 (helper2 n x)
subst-lifts-ₛ• : ∀ {ρ σ} n t
→ subst (repeat liftSubst σ n ₛ• repeat lift ρ n) t
≡ subst (repeat liftSubst (σ ₛ• ρ) n) t
subst-lifts-ₛ• 0 t = refl
subst-lifts-ₛ• (1+ n) t = substVar-to-subst (helper2 n) t
-- wk ρ ∘ subst σ = subst (ρ •ₛ σ)
mutual
wk-subst : ∀ {ρ σ} t → wk ρ (subst σ t) ≡ subst (ρ •ₛ σ) t
wk-subst (var x) = refl
wk-subst (gen x c) = cong (gen x) (wkGen-substGen c)
wkGen-substGen : ∀ {ρ σ} t → wkGen ρ (substGen σ t) ≡ substGen (ρ •ₛ σ) t
wkGen-substGen [] = refl
wkGen-substGen (⟦ l , t ⟧ ∷ c) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (wk-subst t) (subst-lifts-•ₛ l t)))
(wkGen-substGen c)
-- subst σ ∘ wk ρ = subst (σ •ₛ ρ)
mutual
subst-wk : ∀ {ρ σ} t → subst σ (wk ρ t) ≡ subst (σ ₛ• ρ) t
subst-wk (var x) = refl
subst-wk (gen x c) = cong (gen x) (substGen-wkGen c)
substGen-wkGen : ∀ {ρ σ} t → substGen σ (wkGen ρ t) ≡ substGen (σ ₛ• ρ) t
substGen-wkGen [] = refl
substGen-wkGen (⟦ l , t ⟧ ∷ c) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (subst-wk t) (subst-lifts-ₛ• l t)))
(substGen-wkGen c)
-- Composition of liftings is lifting of the composition.
wk-subst-lift : ∀ {ρ σ} G
→ wk (lift ρ) (subst (liftSubst σ) G)
≡ subst (liftSubst (ρ •ₛ σ)) G
wk-subst-lift G = trans (wk-subst G) (subst-lift-•ₛ G)
-- Renaming with ρ is the same as substituting with ρ turned into a substitution.
wk≡subst : ∀ ρ t → wk ρ t ≡ subst (toSubst ρ) t
wk≡subst ρ t = trans (cong (wk ρ) (sym (subst-id t))) (wk-subst t)
-- Composition of substitutions.
-- Composition of liftings is lifting of the composition.
substCompLift : ∀ {σ σ′} x
→ (liftSubst σ ₛ•ₛ liftSubst σ′) x
≡ (liftSubst (σ ₛ•ₛ σ′)) x
substCompLift 0 = refl
substCompLift {σ} {σ′} (1+ x) = trans (subst-wk (σ′ x)) (sym (wk-subst (σ′ x)))
substCompLifts : ∀ {σ σ′} n x
→ (repeat liftSubst σ n ₛ•ₛ repeat liftSubst σ′ n) x
≡ (repeat liftSubst (σ ₛ•ₛ σ′) n) x
substCompLifts 0 x = refl
substCompLifts (1+ n) 0 = refl
substCompLifts {σ} {σ′} (1+ n) (1+ x) =
trans (substCompLift {repeat liftSubst σ n} {repeat liftSubst σ′ n} (1+ x))
(cong wk1 (substCompLifts n x))
-- Soundness of the composition of substitutions.
mutual
substCompEq : ∀ {σ σ′} (t : Term)
→ subst σ (subst σ′ t) ≡ subst (σ ₛ•ₛ σ′) t
substCompEq (var x) = refl
substCompEq (gen x c) = cong (gen x) (substGenCompEq c)
substGenCompEq : ∀ {σ σ′} t
→ substGen σ (substGen σ′ t) ≡ substGen (σ ₛ•ₛ σ′) t
substGenCompEq [] = refl
substGenCompEq (⟦ l , t ⟧ ∷ c) =
cong₂ _∷_ (cong (⟦_,_⟧ l) (trans (substCompEq t)
(substVar-to-subst (substCompLifts l) t)))
(substGenCompEq c)
-- Weakening single substitutions.
-- Pulling apart a weakening composition in specific context _[a].
wk-comp-subst : ∀ {a} ρ ρ′ G
→ wk (lift (ρ • ρ′)) G [ a ] ≡ wk (lift ρ) (wk (lift ρ′) G) [ a ]
wk-comp-subst {a} ρ ρ′ G =
cong (λ x → x [ a ]) (sym (wk-comp (lift ρ) (lift ρ′) G))
-- Pushing a weakening into a single substitution.
-- ρ (t[a]) = ((lift ρ) t)[ρ a]
wk-β : ∀ {ρ a} t → wk ρ (t [ a ]) ≡ wk (lift ρ) t [ wk ρ a ]
wk-β t = trans (wk-subst t) (sym (trans (subst-wk t)
(substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t)))
-- Pushing a weakening into a single shifting substitution.
-- If ρ′ = lift ρ then ρ′(t[a]↑) = ρ′(t) [ρ′(a)]↑
wk-β↑ : ∀ {ρ a} t → wk (lift ρ) (t [ a ]↑) ≡ wk (lift ρ) t [ wk (lift ρ) a ]↑
wk-β↑ t = trans (wk-subst t) (sym (trans (subst-wk t)
(substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t)))
-- A specific equation on weakenings used for the reduction of natrec.
wk-β-natrec : ∀ ρ G
→ Π ℕ ▹ (Π wk (lift ρ) G ▹ wk (lift (lift ρ)) (wk1 (G [ suc (var 0) ]↑)))
≡ Π ℕ ▹ (wk (lift ρ) G ▹▹ wk (lift ρ) G [ suc (var 0) ]↑)
wk-β-natrec ρ G =
cong₂ Π_▹_ refl (cong₂ Π_▹_ refl
(trans (wk-comp (lift (lift ρ)) (step id)
(subst (consSubst (wk1Subst var) (suc (var 0))) G))
(trans (wk-subst G) (sym (trans (wk-subst (wk (lift ρ) G))
(trans (subst-wk G)
(substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)))))))
-- Composing a singleton substitution and a lifted substitution.
-- sg u ∘ lift σ = cons id u ∘ lift σ = cons σ u
substVarSingletonComp : ∀ {u σ} (x : Nat)
→ (sgSubst u ₛ•ₛ liftSubst σ) x ≡ (consSubst σ u) x
substVarSingletonComp 0 = refl
substVarSingletonComp {σ = σ} (1+ x) = trans (subst-wk (σ x)) (subst-id (σ x))
-- The same again, as action on a term t.
substSingletonComp : ∀ {a σ} t
→ subst (sgSubst a ₛ•ₛ liftSubst σ) t ≡ subst (consSubst σ a) t
substSingletonComp = substVar-to-subst substVarSingletonComp
-- A single substitution after a lifted substitution.
-- ((lift σ) G)[t] = (cons σ t)(G)
singleSubstComp : ∀ t σ G
→ (subst (liftSubst σ) G) [ t ]
≡ subst (consSubst σ t) G
singleSubstComp t σ G = trans (substCompEq G) (substSingletonComp G)
-- A single substitution after a lifted substitution (with weakening).
-- ((lift (ρ ∘ σ)) G)[t] = (cons (ρ ∘ σ) t)(G)
singleSubstWkComp : ∀ {ρ} t σ G
→ wk (lift ρ) (subst (liftSubst σ) G) [ t ]
≡ subst (consSubst (ρ •ₛ σ) t) G
singleSubstWkComp t σ G =
trans (cong (subst (consSubst var t))
(trans (wk-subst G) (subst-lift-•ₛ G)))
(trans (substCompEq G) (substSingletonComp G))
-- Pushing a substitution into a single substitution.
singleSubstLift : ∀ {σ} G t
→ subst σ (G [ t ])
≡ subst (liftSubst σ) G [ subst σ t ]
singleSubstLift G t =
trans (substCompEq G)
(trans (trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)
(sym (substSingletonComp G)))
(sym (substCompEq G)))
-- More specific laws.
idWkLiftSubstLemma : ∀ σ G
→ wk (lift (step id)) (subst (liftSubst σ) G) [ var 0 ]
≡ subst (liftSubst σ) G
idWkLiftSubstLemma σ G =
trans (singleSubstWkComp (var 0) σ G)
(substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G)
substVarComp↑ : ∀ {t} σ x
→ (consSubst (wk1Subst idSubst) (subst (liftSubst σ) t) ₛ•ₛ liftSubst σ) x
≡ (liftSubst σ ₛ•ₛ consSubst (wk1Subst idSubst) t) x
substVarComp↑ σ 0 = refl
substVarComp↑ σ (1+ x) = trans (subst-wk (σ x)) (sym (wk≡subst (step id) (σ x)))
singleSubstLift↑ : ∀ σ G t
→ subst (liftSubst σ) (G [ t ]↑)
≡ subst (liftSubst σ) G [ subst (liftSubst σ) t ]↑
singleSubstLift↑ σ G t =
trans (substCompEq G)
(sym (trans (substCompEq G) (substVar-to-subst (substVarComp↑ σ) G)))
substConsComp : ∀ {σ t G}
→ subst (consSubst (λ x → σ (1+ x)) (subst (tail σ) t)) G
≡ subst σ (subst (consSubst (λ x → var (1+ x)) (wk1 t)) G)
substConsComp {t = t} {G = G} =
trans (substVar-to-subst (λ { 0 → sym (subst-wk t) ; (1+ x) → refl }) G)
(sym (substCompEq G))
wkSingleSubstId : ∀ F → (wk (lift (step id)) F) [ var 0 ] ≡ F
wkSingleSubstId F =
trans (subst-wk F)
(trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) F)
(subst-id F))
cons-wk-subst : ∀ ρ σ a t
→ subst (sgSubst a ₛ• lift ρ ₛ•ₛ liftSubst σ) t
≡ subst (consSubst (ρ •ₛ σ) a) t
cons-wk-subst ρ σ a = substVar-to-subst
(λ { 0 → refl
; (1+ x) → trans (subst-wk (σ x)) (sym (wk≡subst ρ (σ x))) })
natrecSucCaseLemma : ∀ {σ} (x : Nat)
→ (step id •ₛ consSubst (wk1Subst idSubst) (suc (var 0)) ₛ•ₛ liftSubst σ) x
≡ (liftSubst (liftSubst σ) ₛ• step id ₛ•ₛ consSubst (wk1Subst idSubst) (suc (var 0))) x
natrecSucCaseLemma 0 = refl
natrecSucCaseLemma {σ} (1+ x) =
trans (subst-wk (σ x))
(sym (trans (wk1-wk (step id) _)
(wk≡subst (step (step id)) (σ x))))
natrecSucCase : ∀ σ F
→ Π ℕ ▹ (Π subst (liftSubst σ) F
▹ subst (liftSubst (liftSubst σ)) (wk1 (F [ suc (var 0) ]↑)))
≡ Π ℕ ▹ (subst (liftSubst σ) F ▹▹ subst (liftSubst σ) F [ suc (var 0) ]↑)
natrecSucCase σ F =
cong₂ Π_▹_ refl
(cong₂ Π_▹_ refl
(trans (trans (subst-wk (F [ suc (var 0) ]↑))
(substCompEq F))
(sym (trans (wk-subst (subst (liftSubst σ) F))
(trans (substCompEq F)
(substVar-to-subst natrecSucCaseLemma F))))))
natrecIrrelevantSubstLemma : ∀ F z s m σ (x : Nat)
→ (sgSubst (natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m)
ₛ•ₛ liftSubst (sgSubst m)
ₛ•ₛ liftSubst (liftSubst σ)
ₛ• step id
ₛ•ₛ consSubst (tail idSubst) (suc (var 0))) x
≡ (consSubst σ (suc m)) x
natrecIrrelevantSubstLemma F z s m σ 0 =
cong suc (trans (subst-wk m) (subst-id m))
natrecIrrelevantSubstLemma F z s m σ (1+ x) =
trans (subst-wk (wk (step id) (σ x)))
(trans (subst-wk (σ x))
(subst-id (σ x)))
natrecIrrelevantSubst : ∀ F z s m σ
→ subst (consSubst σ (suc m)) F
≡ subst (liftSubst (sgSubst m))
(subst (liftSubst (liftSubst σ))
(wk1 (F [ suc (var 0) ]↑)))
[ natrec (subst (liftSubst σ) F) (subst σ z) (subst σ s) m ]
natrecIrrelevantSubst F z s m σ =
sym (trans (substCompEq (subst (liftSubst (liftSubst σ))
(wk (step id)
(subst (consSubst (tail idSubst) (suc (var 0))) F))))
(trans (substCompEq (wk (step id)
(subst (consSubst (tail idSubst) (suc (var 0))) F)))
(trans
(subst-wk (subst (consSubst (tail idSubst) (suc (var 0))) F))
(trans (substCompEq F)
(substVar-to-subst (natrecIrrelevantSubstLemma F z s m σ) F)))))
natrecIrrelevantSubstLemma′ : ∀ F z s n (x : Nat)
→ (sgSubst (natrec F z s n)
ₛ•ₛ liftSubst (sgSubst n)
ₛ• step id
ₛ•ₛ consSubst (tail idSubst) (suc (var 0))) x
≡ (consSubst var (suc n)) x
natrecIrrelevantSubstLemma′ F z s n 0 =
cong suc (trans (subst-wk n) (subst-id n))
natrecIrrelevantSubstLemma′ F z s n (1+ x) = refl
natrecIrrelevantSubst′ : ∀ F z s n
→ subst (liftSubst (sgSubst n))
(wk1 (F [ suc (var 0) ]↑))
[ natrec F z s n ]
≡ F [ suc n ]
natrecIrrelevantSubst′ F z s n =
trans (substCompEq (wk (step id)
(subst (consSubst (tail idSubst) (suc (var 0))) F)))
(trans (subst-wk (subst (consSubst (tail idSubst) (suc (var 0))) F))
(trans (substCompEq F)
(substVar-to-subst (natrecIrrelevantSubstLemma′ F z s n) F)))
cons0wkLift1-id : ∀ σ G
→ subst (sgSubst (var 0))
(wk (lift (step id)) (subst (liftSubst σ) G))
≡ subst (liftSubst σ) G
cons0wkLift1-id σ G =
trans (subst-wk (subst (liftSubst σ) G))
(trans (substVar-to-subst (λ { 0 → refl ; (1+ x) → refl })
(subst (liftSubst σ) G))
(subst-id (subst (liftSubst σ) G)))
substConsId : ∀ {σ t} G
→ subst (consSubst σ (subst σ t)) G
≡ subst σ (subst (sgSubst t) G)
substConsId G =
sym (trans (substCompEq G)
(substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) G))
substConsTailId : ∀ {G t σ}
→ subst (consSubst (tail σ) (subst σ t)) G
≡ subst σ (subst (consSubst (tail idSubst) t) G)
substConsTailId {G} {t} {σ} =
trans (substVar-to-subst (λ { 0 → refl
; (1+ x) → refl }) G)
(sym (substCompEq G))
substConcatSingleton′ : ∀ {a σ} t
→ subst (σ ₛ•ₛ sgSubst a) t
≡ subst (consSubst σ (subst σ a)) t
substConcatSingleton′ t = substVar-to-subst (λ { 0 → refl ; (1+ x) → refl}) t
wk1-tailId : ∀ t → wk1 t ≡ subst (tail idSubst) t
wk1-tailId t = trans (sym (subst-id (wk1 t))) (subst-wk t)
| {
"alphanum_fraction": 0.5594704787,
"avg_line_length": 34.7933450088,
"ext": "agda",
"hexsha": "c7268b46e91fa4db313656f69ddbb7e1352f6d15",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Untyped/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Untyped/Properties.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Untyped/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7861,
"size": 19867
} |
module index where
-- For a brief presentation of every single module, head over to
import Everything
-- Otherwise, here is an exhaustive, stern list of all the available modules.
| {
"alphanum_fraction": 0.7802197802,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "bfbc733c2fe4589c1ad3c83e82bb512bb4995c68",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "travis/index.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "travis/index.agda",
"max_line_length": 77,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "travis/index.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 37,
"size": 182
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- The empty binary relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Construct.Never where
open import Relation.Binary
open import Relation.Binary.Construct.Constant
open import Data.Empty using (⊥)
open import Level using (Lift; lift)
------------------------------------------------------------------------
-- Definition
Never : ∀ {a ℓ} {A : Set a} → Rel A ℓ
Never = Const (Lift _ ⊥)
| {
"alphanum_fraction": 0.4446337308,
"avg_line_length": 27.9523809524,
"ext": "agda",
"hexsha": "17a8689bc5176260648e3cb6ec5044269a62449d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Never.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Never.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Never.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 102,
"size": 587
} |
module Section6 where
open import Section5 public
-- 6. Application to terms
-- =======================
--
-- In practice we may not want to work with proof trees but rather well-typed terms. As an
-- application of the results above we show how to give semantics to a formulation of Martin-
-- Löf’s substitution calculus [13, 20] in the simply typed setting. In this calculus we have a
-- set of untyped terms, `𝕋`, and we define when a term in `𝕋` is well-typed and when two terms
-- of a given type are convertible with each other.
--
-- In order to give semantics to untyped terms, we first define an erasure function that
-- translates a proof tree `M` to an untyped term, denoted `M ⁻`. The main theorem is then to prove
-- that if two proof trees `M, N` erase to the same term, `M ⁻ ≡ N ⁻`, then `M ≅ N`; it follows that
-- `M` and `N` have the same semantics. For this we first prove that `nf M ⁻ ≡ nf N ⁻` implies
-- `M ≅ N`. We also define a reduction on the untyped terms `Γ ⊢ t₁ ⇓ t₂ ∷ A` that is deterministic
-- (i.e., if `Γ ⊢ t ⇓ t₁ ∷ A` and `Γ ⊢ t ⇓ t₂ ∷ A`, then `t₁ ≡ t₂`) such that `Γ ⊢ M ⁻ ⇓ nf M ⁻ ∷ A`.
-- We then prove that if a proof tree `M` erases to a well-typed term `t`, then `t ⇓ nf M ⁻`. Now,
-- if two proof trees `M` and `N` erase to the same well-typed term `t`, then `t ⇓ nf M ⁻` and
-- `t ⇓ nf N ⁻`. Since the reduction is deterministic we have that `nf M ⁻` and `nf N ⁻` are the
-- same, and hence `M ≅ N`. The idea of this proof comes from Streicher [19] (chapter IV).
-- 6.1. Definition of terms
-- ------------------------
--
-- We mutually define the set of terms, `𝕋 : Set`, and substitutions, `𝕊 : Set`. (…)
mutual
data 𝕋 : Set where
ν : Name → 𝕋
ƛ : Name → 𝕋 → 𝕋
_∙_ : 𝕋 → 𝕋 → 𝕋
_▶_ : 𝕋 → 𝕊 → 𝕋
data 𝕊 : Set where
[] : 𝕊
[_,_≔_] : 𝕊 → Name → 𝕋 → 𝕊
_●_ : 𝕊 → 𝕊 → 𝕊
-- 6.2. Typing rules
-- -----------------
--
-- We give the typing rules for terms and substitutions mutually inductively. (…)
mutual
infix 3 _⊢_∷_
data _⊢_∷_ : 𝒞 → 𝕋 → 𝒯 → Set where
↑⟨_⟩⊢∷ : ∀ {Γ Δ A t} →
Γ ⊇ Δ → Δ ⊢ t ∷ A →
Γ ⊢ t ∷ A
ν : ∀ {Γ A} →
(x : Name) → Γ ∋ x ∷ A →
Γ ⊢ ν x ∷ A
ƛ : ∀ {Γ A B t} →
(x : Name) {{_ : T (fresh x Γ)}} → [ Γ , x ∷ A ] ⊢ t ∷ B →
Γ ⊢ ƛ x t ∷ A ⊃ B
_∙_ : ∀ {Γ A B t₁ t₂} →
Γ ⊢ t₁ ∷ A ⊃ B → Γ ⊢ t₂ ∷ A →
Γ ⊢ t₁ ∙ t₂ ∷ B
_▶_ : ∀ {Γ Δ A s t} →
Δ ⊢ t ∷ A → Γ ⋙ s ∷ Δ →
Γ ⊢ t ▶ s ∷ A
infix 3 _⋙_∷_
data _⋙_∷_ : 𝒞 → 𝕊 → 𝒞 → Set where
↑⟨_⟩⋙∷ : ∀ {Γ Δ Θ s} →
Θ ⊇ Γ → Γ ⋙ s ∷ Δ →
Θ ⋙ s ∷ Δ
↓⟨_⟩⋙∷ : ∀ {Γ Δ Θ s} →
Δ ⊇ Θ → Γ ⋙ s ∷ Δ →
Γ ⋙ s ∷ Θ
refl⋙∷ : ∀ {Γ} →
Γ ⋙ [] ∷ Γ
[_,_≔_] : ∀ {Γ Δ A s t} →
Γ ⋙ s ∷ Δ → (x : Name) {{_ : T (fresh x Δ)}} → Γ ⊢ t ∷ A →
Γ ⋙ [ s , x ≔ t ] ∷ [ Δ , x ∷ A ]
_●_ : ∀ {Γ Δ Θ s₁ s₂} →
Δ ⋙ s₂ ∷ Θ → Γ ⋙ s₁ ∷ Δ →
Γ ⋙ s₂ ● s₁ ∷ Θ
module _ where
instance
raise⊢∷ : ∀ {A t} → Raiseable (_⊢ t ∷ A)
raise⊢∷ = record { ↑⟨_⟩ = ↑⟨_⟩⊢∷ }
raise⋙∷ : ∀ {Γ s} → Raiseable (_⋙ s ∷ Γ)
raise⋙∷ = record { ↑⟨_⟩ = ↑⟨_⟩⋙∷ }
lower⋙∷ : ∀ {Δ s} → Lowerable (Δ ⋙ s ∷_)
lower⋙∷ = record { ↓⟨_⟩ = ↓⟨_⟩⋙∷ }
-- 6.3. Convertibility of terms
-- ----------------------------
--
-- We mutually inductively define when two terms are convertible with each other together
-- with the definition of convertibility between substitutions. (…)
mutual
infix 3 _⊢_≊_∷_
data _⊢_≊_∷_ : 𝒞 → 𝕋 → 𝕋 → 𝒯 → Set where
refl≊ : ∀ {Γ A t} →
Γ ⊢ t ≊ t ∷ A
sym≊ : ∀ {Γ A t t′} →
Γ ⊢ t ≊ t′ ∷ A →
Γ ⊢ t′ ≊ t ∷ A
trans≊ : ∀ {Γ A t t′ t″} →
Γ ⊢ t ≊ t′ ∷ A → Γ ⊢ t′ ≊ t″ ∷ A →
Γ ⊢ t ≊ t″ ∷ A
congƛ≊ : ∀ {Γ A B t t′ x} {{_ : T (fresh x Γ)}} →
[ Γ , x ∷ A ] ⊢ t ≊ t′ ∷ B →
Γ ⊢ ƛ x t ≊ ƛ x t′ ∷ A ⊃ B
cong∙≊ : ∀ {Γ A B t t′ u u′} →
Γ ⊢ t ≊ t′ ∷ A ⊃ B → Γ ⊢ u ≊ u′ ∷ A →
Γ ⊢ t ∙ u ≊ t′ ∙ u′ ∷ B
cong▶≊ : ∀ {Γ Δ A t t′ s s′} →
Γ ⊢ t ≊ t′ ∷ A → Δ ⋙ s ≊ₛ s′ ∷ Γ →
Γ ⊢ t ▶ s ≊ t′ ▶ s′ ∷ A
conv₁≊ : ∀ {Γ A t} →
Γ ⊢ t ∷ A →
Γ ⊢ t ≊ t ∷ A
conv₂≊ : ∀ {Γ Δ A B s t₁ t₂ x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ Δ → [ Δ , x ∷ A ] ⊢ t₁ ∷ B → Γ ⊢ t₂ ∷ A →
Γ ⊢ (ƛ x t₁ ▶ s) ∙ t₂ ≊ t₁ ▶ [ s , x ≔ t₂ ] ∷ B
conv₃≊ : ∀ {Γ A B t x} {{_ : T (fresh x Γ)}} →
Γ ⊢ t ∷ A ⊃ B →
Γ ⊢ t ≊ ƛ x (t ∙ ν x) ∷ A ⊃ B
conv₄≊ : ∀ {Γ Δ A t₁ t₂} →
Γ ⊇ Δ → Δ ⊢ t₁ ≊ t₂ ∷ A →
Γ ⊢ t₁ ≊ t₂ ∷ A
conv₅≊ : ∀ {Γ Δ A s t x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ Δ → Γ ⊢ t ∷ A →
Γ ⊢ ν x ▶ [ s , x ≔ t ] ≊ t ∷ A
conv₆≊ : ∀ {Γ A t} →
Γ ⊢ t ∷ A →
Γ ⊢ t ▶ [] ≊ t ∷ A
conv₇≊ : ∀ {Γ Δ A B s t₁ t₂} →
Δ ⊢ t₁ ∷ A ⊃ B → Δ ⊢ t₂ ∷ A → Γ ⋙ s ∷ Δ →
Γ ⊢ (t₁ ∙ t₂) ▶ s ≊ (t₁ ▶ s) ∙ (t₂ ▶ s) ∷ B
conv₈≊ : ∀ {Γ₁ Γ₂ Γ₃ A s₁ s₂ t} →
Γ₂ ⋙ s₁ ∷ Γ₃ → Γ₁ ⋙ s₂ ∷ Γ₂ → Γ₃ ⊢ t ∷ A →
Γ₁ ⊢ (t ▶ s₁) ▶ s₂ ≊ t ▶ (s₁ ● s₂) ∷ A
data _⋙_≊ₛ_∷_ : 𝒞 → 𝕊 → 𝕊 → 𝒞 → Set where
refl≊ₛ : ∀ {Γ Δ s} →
Δ ⋙ s ≊ₛ s ∷ Γ
sym≊ₛ : ∀ {Γ Δ s s′} →
Δ ⋙ s ≊ₛ s′ ∷ Γ →
Δ ⋙ s′ ≊ₛ s ∷ Γ
trans≊ₛ : ∀ {Γ Δ s s′ s″} →
Δ ⋙ s ≊ₛ s′ ∷ Γ → Δ ⋙ s′ ≊ₛ s″ ∷ Γ →
Δ ⋙ s ≊ₛ s″ ∷ Γ
cong≔≊ₛ : ∀ {Γ Δ A s s′ t t′ x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ≊ₛ s′ ∷ Δ → Γ ⊢ t ≊ t′ ∷ A →
Γ ⋙ [ s , x ≔ t ] ≊ₛ [ s′ , x ≔ t′ ] ∷ [ Δ , x ∷ A ]
cong●≊ₛ : ∀ {Γ Δ Θ s₁ s₁′ s₂ s₂′} →
Δ ⋙ s₂ ≊ₛ s₂′ ∷ Θ → Γ ⋙ s₁ ≊ₛ s₁′ ∷ Δ →
Γ ⋙ s₂ ● s₁ ≊ₛ s₂′ ● s₁′ ∷ Θ
conv₁≊ₛ : ∀ {Γ₁ Γ₂ Δ s₁ s₂} →
Γ₁ ⊇ Γ₂ → Γ₂ ⋙ s₁ ≊ₛ s₂ ∷ Δ →
Γ₁ ⋙ s₁ ≊ₛ s₂ ∷ Δ
conv₂≊ₛ : ∀ {Γ Δ₁ Δ₂ s₁ s₂} →
Δ₁ ⊇ Δ₂ → Γ ⋙ s₁ ≊ₛ s₂ ∷ Δ₁ →
Γ ⋙ s₁ ≊ₛ s₂ ∷ Δ₂
conv₃≊ₛ : ∀ {Γ Δ s} →
Γ ⋙ s ∷ Δ →
Γ ⋙ s ● [] ≊ₛ s ∷ Δ
conv₄≊ₛ : ∀ {Γ₁ Γ₂ Γ₃ Δ s₁ s₂ s₃} →
Γ₁ ⋙ s₃ ∷ Γ₂ → Γ₂ ⋙ s₂ ∷ Γ₃ → Γ₃ ⋙ s₁ ∷ Δ →
Γ₃ ⋙ (s₁ ● s₂) ● s₃ ≊ₛ s₁ ● (s₂ ● s₃) ∷ Δ
conv₅≊ₛ : ∀ {Γ₁ Γ₂ Δ A s₁ s₂ t x} {{_ : T (fresh x Δ)}} →
Γ₁ ⋙ s₂ ∷ Γ₂ → Γ₂ ⋙ s₁ ∷ Δ → Γ₂ ⊢ t ∷ A →
Γ₁ ⋙ [ s₁ , x ≔ t ] ● s₂ ≊ₛ [ s₁ ● s₂ , x ≔ t ▶ s₂ ] ∷ [ Δ , x ∷ A ]
conv₆≊ₛ : ∀ {Γ s} →
Γ ⋙ s ∷ [] →
Γ ⋙ s ≊ₛ [] ∷ []
conv₇≊ₛ : ∀ {Γ Δ A s x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ [ Δ , x ∷ A ] →
Γ ⋙ s ≊ₛ [ s , x ≔ ν x ▶ s ] ∷ [ Δ , x ∷ A ]
conv₈≊ₛ : ∀ {Γ Δ A s t x} {{_ : T (fresh x Δ)}} →
Γ ⋙ s ∷ Δ → Δ ⊢ t ∷ A →
Γ ⋙ [ s , x ≔ t ] ≊ₛ s ∷ Δ
conv₉≊ₛ : ∀ {Γ Δ s} →
Γ ⋙ s ∷ Δ →
Γ ⋙ [] ● s ≊ₛ s ∷ Δ
-- It is straightforward to prove that if two terms (substitutions) are convertible with each
-- other, then they are also well-typed.
-- TODO: What to do about the above paragraph?
| {
"alphanum_fraction": 0.375289155,
"avg_line_length": 36.745,
"ext": "agda",
"hexsha": "2fb28ffbdb36790a362f71cf3256beef70af1922",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/coquand",
"max_forks_repo_path": "src/Section6.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/coquand",
"max_issues_repo_path": "src/Section6.agda",
"max_line_length": 101,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/coquand",
"max_stars_repo_path": "src/Section6.agda",
"max_stars_repo_stars_event_max_datetime": "2017-09-07T12:44:40.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-27T01:29:58.000Z",
"num_tokens": 3520,
"size": 7349
} |
{-# OPTIONS --cubical #-}
module _ where
module _ where
import Agda.Primitive
open import Agda.Primitive.Cubical public
open import Agda.Builtin.Cubical.Path public
refl : ∀ {a} {A : Set a} {x : A} → x ≡ x
refl {x = x} = \ _ → x
testPath : ∀ {A : Set} {b a : A} (let H : b ≡ b; H = _) → ∀ i → H i ≡ b
testPath i = refl
| {
"alphanum_fraction": 0.5795795796,
"avg_line_length": 22.2,
"ext": "agda",
"hexsha": "56a38e16217f0fd27e51b605c07a87d28b087edf",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2650.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2650.agda",
"max_line_length": 71,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2650.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 127,
"size": 333
} |
{-# OPTIONS --cubical #-}
module Type.Cubical where
import Lvl
open import Type
open import Agda.Primitive public
using (SSet)
open import Agda.Primitive.Cubical public
using ()
renaming (I to Interval) -- _ : SSet(Lvl.𝟎). Inhabitants can be seen as points on a closed unit interval.
module Interval where
open Agda.Primitive.Cubical public
using (
Partial ; -- _ : ∀{ℓ} → Interval → Type{ℓ} → SSet(ℓ)
PartialP -- _ : ∀{ℓ} → (i : Interval) → (.(Is-𝟏 i) → Type{ℓ}) → SSet(ℓ)
)
renaming (
i0 to 𝟎 ; -- _ : Interval. 0 (the initial point) in the interval.
i1 to 𝟏 ; -- _ : Interval. 1 (the terminal point) in the interval.
primIMin to min ; -- _ : Interval → Interval → Interval. Chooses the point nearest 𝟎. Also called: _∧_ (from lattice structure).
primIMax to max ; -- _ : Interval → Interval → Interval. Chooses the point nearest 𝟏. Also called: _∨_ (from lattice structure).
primINeg to flip ; -- _ : Interval → Interval. Flips a point in the interval around the point of symmetry (the middle). Essentially (p ↦ 𝟏 − p).
IsOne to Is-𝟏 ; -- _ : Interval → SSet(Lvl.𝟎). The predicate stating that a point is 𝟏.
itIsOne to 𝟏-is-𝟏 ; -- _ : Is-𝟏(𝟏). Proof of 𝟏 being 𝟏.
primComp to comp ; -- _ : ∀{ℓ : Interval → Lvl.Level} → (P : (i : Interval) → Type{ℓ(i)}) → ∀{i : Interval} → ((j : Interval) → .(Is-𝟏 i) → P(j)) → (P(𝟎) → P(𝟏))
primHComp to hComp ; -- _ : ∀{ℓ}{A : Type{ℓ}}{i : Interval} → (Interval → .(Is-𝟏 i) → A) → (A → A)
primTransp to transp -- _ : ∀{ℓ : Interval → Lvl.Level}(A : (i : Interval) → Type{ℓ(i)}) → Interval → A(𝟎)→ A(𝟏).
)
-- The distance to the nearest boundary.
nearBound : Interval → Interval
nearBound x = min x (flip x)
-- The distance to the furthest boundary.
farBound : Interval → Interval
farBound x = max x (flip x)
-- Proof of maximum of 𝟏 being 𝟏.
maxₗ-is-𝟏 : ∀{x y} → Is-𝟏(x) → Is-𝟏(max x y)
maxₗ-is-𝟏 {x}{y} = Agda.Primitive.Cubical.IsOne1 x y
-- Proof of maximum of 𝟏 being 𝟏.
maxᵣ-is-𝟏 : ∀{x y} → Is-𝟏(y) → Is-𝟏(max x y)
maxᵣ-is-𝟏 {x}{y} = Agda.Primitive.Cubical.IsOne2 x y
-- The predicate stating that a point is 𝟎.
Is-𝟎 : Interval → SSet(Lvl.𝟎)
Is-𝟎 i = Is-𝟏(flip i)
-- Proof of 𝟎 being 𝟎.
𝟎-is-𝟎 : Is-𝟎(𝟎)
𝟎-is-𝟎 = 𝟏-is-𝟏
-- Proof of minimum of 𝟎 being 𝟎.
minₗ-is-𝟎 : ∀{x y} → Is-𝟎(x) → Is-𝟎(min x y)
minₗ-is-𝟎 {x}{y} = maxₗ-is-𝟏 {flip x} {flip y}
-- Proof of minimum of 𝟎 being 𝟎.
minᵣ-is-𝟎 : ∀{x y} → Is-𝟎(y) → Is-𝟎(min x y)
minᵣ-is-𝟎 {x}{y} = maxᵣ-is-𝟏 {flip x} {flip y}
| {
"alphanum_fraction": 0.5956538611,
"avg_line_length": 39.6461538462,
"ext": "agda",
"hexsha": "73343828fd85fd51d3d988887800e0fb074fa060",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Type/Cubical.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Type/Cubical.agda",
"max_line_length": 167,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Type/Cubical.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1079,
"size": 2577
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Incrementalization as term-to-term transformation (Fig. 4g).
------------------------------------------------------------------------
import Parametric.Syntax.Type as Type
import Parametric.Syntax.Term as Term
import Parametric.Change.Type as ChangeType
module Parametric.Change.Derive
{Base : Type.Structure}
(Const : Term.Structure Base)
(ΔBase : ChangeType.Structure Base)
where
open Type.Structure Base
open Term.Structure Base Const
open ChangeType.Structure Base ΔBase
-- Extension point: Incrementalization of primitives.
Structure : Set
Structure = ∀ {τ} →
Const τ →
Term ∅ (ΔType τ)
module Structure (derive-const : Structure) where
fit : ∀ {τ Γ} → Term Γ τ → Term (ΔContext Γ) τ
fit = weaken Γ≼ΔΓ
-- In the paper, we transform "x" to "dx". Here, we work with
-- de Bruijn indices, so we have to manipulate the indices to
-- account for a bigger context after transformation.
deriveVar : ∀ {τ Γ} → Var Γ τ → Var (ΔContext Γ) (ΔType τ)
deriveVar this = this
deriveVar (that x) = that (that (deriveVar x))
-- We provide: Incrementalization of arbitrary terms.
derive : ∀ {τ Γ} → Term Γ τ → Term (ΔContext Γ) (ΔType τ)
derive (var x) = var (deriveVar x)
derive (app s t) = app (app (derive s) (fit t)) (derive t)
derive (abs t) = abs (abs (derive t))
derive {Γ = Γ} (const c) = weaken (∅≼Γ {ΔContext Γ}) (derive-const c)
| {
"alphanum_fraction": 0.6202020202,
"avg_line_length": 33.75,
"ext": "agda",
"hexsha": "734759d2f968b4a5979b2afdf98a9a67c83b3c33",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Parametric/Change/Derive.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Parametric/Change/Derive.agda",
"max_line_length": 72,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Parametric/Change/Derive.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 419,
"size": 1485
} |
{- 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.Impl.OBM.Rust.RustTypes
open import Util.ByteString
module LibraBFT.Impl.OBM.ConfigHardCoded where
------------------------------------------------------------------------------
postulate -- TODO-1 ePOCHCHANGE
ePOCHCHANGE : ByteString
--ePOCHCHANGE = "EPOCHCHANGE"
------------------------------------------------------------------------------
maxPrunedBlocksInMem : Usize
maxPrunedBlocksInMem = 10
roundInitialTimeoutMS : U64
roundInitialTimeoutMS = 3000
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5594059406,
"avg_line_length": 29.9259259259,
"ext": "agda",
"hexsha": "78ea5ae0fb6f9353ae623965821fa56d9265fb02",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/OBM/ConfigHardCoded.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/OBM/ConfigHardCoded.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/OBM/ConfigHardCoded.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 168,
"size": 808
} |
{- Auxiliary functions for temporal operators. -}
module TemporalOps.Common where
open import TemporalOps.Common.Rewriting public
open import TemporalOps.Common.Compare public
open import TemporalOps.Common.Other public
| {
"alphanum_fraction": 0.8378378378,
"avg_line_length": 27.75,
"ext": "agda",
"hexsha": "9e0c8007bc055d6c83a64e074f1db453bcb7c911",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/TemporalOps/Common.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/TemporalOps/Common.agda",
"max_line_length": 49,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/TemporalOps/Common.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 46,
"size": 222
} |
open import Level
open import Relation.Binary.PropositionalEquality
open import Relation.Binary using (Setoid)
import Function.Equality
import Relation.Binary.Reasoning.Setoid as SetoidR
import Categories.Category
import Categories.Functor
import Categories.NaturalTransformation
import Categories.Category.Instance.Setoids
import Categories.Category.Cocartesian
import SecondOrder.Arity
import SecondOrder.Signature
import SecondOrder.Metavariable
import SecondOrder.Term
import SecondOrder.VRenaming
module SecondOrder.MRenaming
{ℓ}
{𝔸 : SecondOrder.Arity.Arity}
(Σ : SecondOrder.Signature.Signature ℓ 𝔸)
where
open SecondOrder.Signature.Signature Σ
open SecondOrder.Metavariable Σ
open SecondOrder.Term Σ
open SecondOrder.VRenaming Σ
-- a metarenaming maps metavariables between contexts in an arity-preserving way
_⇒ᵐ_ : ∀ (Θ ψ : MContext) → Set ℓ
Θ ⇒ᵐ ψ = ∀ {Δ A} → [ Δ , A ]∈ Θ → [ Δ , A ]∈ ψ
infix 4 _⇒ᵐ_
-- equality of metarenamings
_≡ᵐ_ : ∀ {Θ ψ} (ι μ : Θ ⇒ᵐ ψ) → Set ℓ
_≡ᵐ_ {Θ} ι μ = ∀ {Δ A} (M : [ Δ , A ]∈ Θ) → ι M ≡ μ M
infixl 3 _≡ᵐ_
≡ᵐ-refl : ∀ {Θ ψ} {ι : Θ ⇒ᵐ ψ} → ι ≡ᵐ ι
≡ᵐ-refl = λ M → refl
≡ᵐ-sym : ∀ {Θ ψ} {ι μ : Θ ⇒ᵐ ψ}
→ ι ≡ᵐ μ
→ μ ≡ᵐ ι
≡ᵐ-sym eq M = sym (eq M)
≡ᵐ-trans : ∀ {Θ ψ} {ι μ δ : Θ ⇒ᵐ ψ}
→ ι ≡ᵐ μ
→ μ ≡ᵐ δ
→ ι ≡ᵐ δ
≡ᵐ-trans eq1 eq2 M = trans (eq1 M) (eq2 M)
-- meta-variable renamings form a setoid
Mrenaming-setoid : ∀ (Θ ψ : MContext) → Setoid ℓ ℓ
Mrenaming-setoid Θ ψ =
record
{ Carrier = Θ ⇒ᵐ ψ
; _≈_ = λ ι μ → ι ≡ᵐ μ
; isEquivalence =
record
{ refl = λ {ι} M → ≡ᵐ-refl {Θ} {ψ} {ι} M
; sym = ≡ᵐ-sym
; trans = ≡ᵐ-trans
}
}
-- the identity renaming
idᵐ : ∀ {Θ : MContext} → Θ ⇒ᵐ Θ
idᵐ M = M
-- equal metavariable renaming act the same on metavariables
-- composition of renamings
_∘ᵐ_ : ∀ {Θ ψ Ω} → ψ ⇒ᵐ Ω → Θ ⇒ᵐ ψ → Θ ⇒ᵐ Ω
(ι ∘ᵐ μ) M = ι (μ M)
infix 7 _∘ᵐ_
-- composition respects equality
∘ᵐ-resp-≡ᵐ : ∀ {Γ Δ Ξ} {τ₁ τ₂ : Δ ⇒ᵐ Ξ} {σ₁ σ₂ : Γ ⇒ᵐ Δ} →
τ₁ ≡ᵐ τ₂ → σ₁ ≡ᵐ σ₂ → τ₁ ∘ᵐ σ₁ ≡ᵐ τ₂ ∘ᵐ σ₂
∘ᵐ-resp-≡ᵐ {τ₁ = τ₁} {σ₂ = σ₂} ζ ξ x = trans (cong τ₁ (ξ x)) (ζ (σ₂ x))
-- the identity is the unit
identity-leftᵐ : ∀ {Γ Δ} {ρ : Γ ⇒ᵐ Δ} → idᵐ ∘ᵐ ρ ≡ᵐ ρ
identity-leftᵐ ρ = refl
identity-rightᵐ : ∀ {Γ Δ} {ρ : Γ ⇒ᵐ Δ} → ρ ∘ᵐ idᵐ ≡ᵐ ρ
identity-rightᵐ ρ = refl
-- composition is associative
assocᵐ : ∀ {Γ Δ Ξ Ψ} {τ : Γ ⇒ᵐ Δ} {ρ : Δ ⇒ᵐ Ξ} {σ : Ξ ⇒ᵐ Ψ} →
(σ ∘ᵐ ρ) ∘ᵐ τ ≡ᵐ σ ∘ᵐ (ρ ∘ᵐ τ)
assocᵐ x = refl
sym-assocᵐ : ∀ {Γ Δ Ξ Ψ} {τ : Γ ⇒ᵐ Δ} {ρ : Δ ⇒ᵐ Ξ} {σ : Ξ ⇒ᵐ Ψ} →
σ ∘ᵐ (ρ ∘ᵐ τ) ≡ᵐ (σ ∘ᵐ ρ) ∘ᵐ τ
sym-assocᵐ x = refl
-- contexts and renamings form a category
module _ where
open Categories.Category
MContexts : Category ℓ ℓ ℓ
MContexts =
record
{ Obj = MContext
; _⇒_ = _⇒ᵐ_
; _≈_ = _≡ᵐ_
; id = idᵐ
; _∘_ = _∘ᵐ_
; assoc = λ {_} {_} {_} {_} {f} {g} {h} {_} → assocᵐ {τ = f} {ρ = g} {σ = h}
; sym-assoc = λ {_} {_} {_} {_} {f} {g} {h} {_} → sym-assocᵐ {τ = f} {ρ = g} {σ = h}
; identityˡ = λ x → refl
; identityʳ = λ x → refl
; identity² = λ x → refl
; equiv = record { refl = λ {ι} {_} → ≡ᵐ-refl {ι = ι} ; sym = ≡ᵐ-sym ; trans = ≡ᵐ-trans }
; ∘-resp-≈ = ∘ᵐ-resp-≡ᵐ
}
-- the coproduct structure of the category
module _ where
infixl 7 [_,_]ᵐ
[_,_]ᵐ : ∀ {Γ Δ Ξ} → Γ ⇒ᵐ Ξ → Δ ⇒ᵐ Ξ → Γ ,, Δ ⇒ᵐ Ξ
[ σ , τ ]ᵐ (var-inl x) = σ x
[ σ , τ ]ᵐ (var-inr y) = τ y
inlᵐ : ∀ {Γ Δ} → Γ ⇒ᵐ Γ ,, Δ
inlᵐ = var-inl
inrᵐ : ∀ {Γ Δ} → Δ ⇒ᵐ Γ ,, Δ
inrᵐ = var-inr
uniqueᵐ : ∀ {Γ Δ Ξ} {τ : Γ ,, Δ ⇒ᵐ Ξ} {ρ : Γ ⇒ᵐ Ξ} {σ : Δ ⇒ᵐ Ξ}
→ τ ∘ᵐ inlᵐ ≡ᵐ ρ
→ τ ∘ᵐ inrᵐ ≡ᵐ σ
→ [ ρ , σ ]ᵐ ≡ᵐ τ
uniqueᵐ ξ ζ (var-inl x) = sym (ξ x)
uniqueᵐ ξ ζ (var-inr y) = sym (ζ y)
MContext-+ : Categories.Category.Cocartesian.BinaryCoproducts MContexts
MContext-+ =
record {
coproduct =
λ {Γ Δ} →
record
{ A+B = Γ ,, Δ
; i₁ = inlᵐ
; i₂ = inrᵐ
; [_,_] = [_,_]ᵐ
; inject₁ = λ x → refl
; inject₂ = λ x → refl
; unique = uniqueᵐ
}
}
open Categories.Category.Cocartesian.BinaryCoproducts MContext-+
-- the renaming from the empty context
inᵐ : ∀ {Γ} → ctx-empty ⇒ᵐ Γ
inᵐ ()
-- extension of a renaming is summing with identity
⇑ᵐ : ∀ {Θ Ψ Ω} → Θ ⇒ᵐ Ψ → Θ ,, Ω ⇒ᵐ Ψ ,, Ω
⇑ᵐ ρ = ρ +₁ idᵐ
-- a renaming can also be extended on the right
ᵐ⇑ᵐ : ∀ {Θ Ψ} → Θ ⇒ᵐ Ψ → ∀ {Ω} → Ω ,, Θ ⇒ᵐ Ω ,, Ψ
ᵐ⇑ᵐ ρ = idᵐ +₁ ρ
-- the action of a metavariable renaming on terms
infix 6 [_]ᵐ_
[_]ᵐ_ : ∀ {Θ Ψ Γ A} → Θ ⇒ᵐ Ψ → Term Θ Γ A → Term Ψ Γ A
[ ι ]ᵐ (tm-var x) = tm-var x
[ ι ]ᵐ (tm-meta M ts) = tm-meta (ι M) (λ i → [ ι ]ᵐ ts i)
[ ι ]ᵐ (tm-oper f es) = tm-oper f (λ i → [ ι ]ᵐ es i)
-- The sum of identities is an identity
idᵐ+idᵐ : ∀ {Θ Ψ} → idᵐ {Θ = Θ} +₁ idᵐ {Θ = Ψ} ≡ᵐ idᵐ {Θ = Θ ,, Ψ}
idᵐ+idᵐ (var-inl x) = refl
idᵐ+idᵐ (var-inr y) = refl
-- The action of a renaming respects equality of terms
[]ᵐ-resp-≈ : ∀ {Θ Ψ Γ A} {s t : Term Θ Γ A} {ι : Θ ⇒ᵐ Ψ} → s ≈ t → [ ι ]ᵐ s ≈ [ ι ]ᵐ t
[]ᵐ-resp-≈ (≈-≡ refl) = ≈-≡ refl
[]ᵐ-resp-≈ (≈-meta ξ) = ≈-meta (λ i → []ᵐ-resp-≈ (ξ i))
[]ᵐ-resp-≈ (≈-oper ξ) = ≈-oper (λ i → []ᵐ-resp-≈ (ξ i))
-- The action of a renaming respects equality of renamings
[]ᵐ-resp-≡ᵐ : ∀ {Θ Ψ Γ A} {ι μ : Θ ⇒ᵐ Ψ} {t : Term Θ Γ A} → ι ≡ᵐ μ → [ ι ]ᵐ t ≈ [ μ ]ᵐ t
[]ᵐ-resp-≡ᵐ {t = tm-var x} ξ = ≈-≡ refl
[]ᵐ-resp-≡ᵐ {Θ} {Ψ} {Γ} {A} {ι = ι} {μ = μ} {t = tm-meta M ts} ξ =
let open SetoidR (Term-setoid Ψ Γ A) in
begin
tm-meta (ι M) (λ i → [ ι ]ᵐ ts i) ≈⟨ ≈-meta (λ i → []ᵐ-resp-≡ᵐ ξ) ⟩
tm-meta (ι M) (λ i → [ μ ]ᵐ ts i) ≈⟨ ≈-≡ ((cong λ N → tm-meta N (λ i → [ μ ]ᵐ ts i)) (ξ M)) ⟩
tm-meta (μ M) (λ i → [ μ ]ᵐ ts i) ≈⟨ ≈-≡ refl ⟩
tm-meta (μ M) (λ i → [ μ ]ᵐ ts i)
∎
[]ᵐ-resp-≡ᵐ {t = tm-oper f es} ξ = ≈-oper λ i → []ᵐ-resp-≡ᵐ ξ
-- The action of the identity is trival
[idᵐ] : ∀ {Θ Γ A} {t : Term Θ Γ A} → [ idᵐ ]ᵐ t ≈ t
[idᵐ] {t = tm-var x} = ≈-refl
[idᵐ] {t = tm-meta M ts} = ≈-meta λ i → [idᵐ]
[idᵐ] {t = tm-oper f es} = ≈-oper λ i → [idᵐ]
-- Extension respects composition
⇑ᵐ-resp-∘ᵐ : ∀ {Γ Δ Ξ Ψ} {ρ : Γ ⇒ᵐ Δ} {τ : Δ ⇒ᵐ Ξ} → ⇑ᵐ {Ω = Ψ} (τ ∘ᵐ ρ) ≡ᵐ (⇑ᵐ τ) ∘ᵐ (⇑ᵐ ρ)
⇑ᵐ-resp-∘ᵐ (var-inl x) = refl
⇑ᵐ-resp-∘ᵐ (var-inr y) = refl
ᵐ⇑ᵐ-resp-∘ᵐ : ∀ {Θ Ψ Ω Ξ} {ρ : Θ ⇒ᵐ Ψ} {τ : Ψ ⇒ᵐ Ω}
→ ᵐ⇑ᵐ {Θ} {Ω} (τ ∘ᵐ ρ) {Ξ} ≡ᵐ (ᵐ⇑ᵐ τ) ∘ᵐ (ᵐ⇑ᵐ ρ)
ᵐ⇑ᵐ-resp-∘ᵐ (var-inl M) = refl
ᵐ⇑ᵐ-resp-∘ᵐ (var-inr N) = refl
-- Extension of the identity renaming is the identity
⇑ᵐ-resp-idᵐ : ∀ {Θ Ψ} → (⇑ᵐ {Θ} {Θ} {Ψ}) (idᵐ {Θ}) ≡ᵐ idᵐ
⇑ᵐ-resp-idᵐ (var-inl M) = refl
⇑ᵐ-resp-idᵐ (var-inr N) = refl
ᵐ⇑ᵐ-resp-idᵐ : ∀ {Θ Ψ} → (ᵐ⇑ᵐ {Θ} {Θ}) (idᵐ {Θ}) {Ψ} ≡ᵐ idᵐ
ᵐ⇑ᵐ-resp-idᵐ (var-inl M) = refl
ᵐ⇑ᵐ-resp-idᵐ (var-inr N) = refl
-- Extension preserves equality of metavariable renamings
ᵐ⇑ᵐ-resp-≡ᵐ : ∀ {Θ Ψ Ω} {ι μ : Θ ⇒ᵐ Ψ} → ι ≡ᵐ μ → ᵐ⇑ᵐ ι {Ω} ≡ᵐ ᵐ⇑ᵐ μ
ᵐ⇑ᵐ-resp-≡ᵐ ι≡μ (var-inl M) = refl
ᵐ⇑ᵐ-resp-≡ᵐ {ι = ι} ι≡μ (var-inr N) = cong (inrᵐ) (ι≡μ N)
⇑ᵐ-resp-≡ᵐ : ∀ {Θ Ψ Ω} {ι μ : Θ ⇒ᵐ Ψ} → ι ≡ᵐ μ → ⇑ᵐ {Ω = Ω} ι ≡ᵐ ⇑ᵐ μ
⇑ᵐ-resp-≡ᵐ ι≡μ (var-inl M) = cong var-inl (ι≡μ M)
⇑ᵐ-resp-≡ᵐ {ι = ι} ι≡μ (var-inr N) = refl
-- The action of a renaming is functorial
[∘ᵐ] : ∀ {Θ Ψ Ω Γ} {ι : Θ ⇒ᵐ Ψ} {μ : Ψ ⇒ᵐ Ω} {A} {t : Term Θ Γ A}
→ [ μ ∘ᵐ ι ]ᵐ t ≈ [ μ ]ᵐ ([ ι ]ᵐ t)
[∘ᵐ] {t = tm-var x} = ≈-refl
[∘ᵐ] {t = tm-meta M ts} = ≈-meta (λ i → [∘ᵐ])
[∘ᵐ] {t = tm-oper f es} = ≈-oper (λ i → [∘ᵐ])
ᵐ∘ᵛ≈ᵛ∘ᵐ : ∀ {Θ Ψ Γ Δ A} {ρ : Γ ⇒ᵛ Δ} {ι : Θ ⇒ᵐ Ψ} {t : Term Θ Γ A}
→ [ ι ]ᵐ ([ ρ ]ᵛ t) ≈ [ ρ ]ᵛ ([ ι ]ᵐ t)
ᵐ∘ᵛ≈ᵛ∘ᵐ {t = tm-var x} = ≈-refl
ᵐ∘ᵛ≈ᵛ∘ᵐ {t = tm-meta M ts} = ≈-meta (λ i → ᵐ∘ᵛ≈ᵛ∘ᵐ {t = ts i})
ᵐ∘ᵛ≈ᵛ∘ᵐ {t = tm-oper f es} = ≈-oper (λ i → ᵐ∘ᵛ≈ᵛ∘ᵐ {t = es i})
split-sum : ∀ {Θ Ψ Ξ Ω} {ι : Θ ⇒ᵐ Ψ} {μ : Ξ ⇒ᵐ Ω}
→ (μ +₁ ι) ≡ᵐ (⇑ᵐ μ) ∘ᵐ (ᵐ⇑ᵐ ι)
split-sum (var-inl M) = refl
split-sum (var-inr N) = refl
split-sum2 : ∀ {Θ Ψ Ξ Ω} {ι : Θ ⇒ᵐ Ψ} {μ : Ξ ⇒ᵐ Ω}
→ (μ +₁ ι) ≡ᵐ (ᵐ⇑ᵐ ι) ∘ᵐ (⇑ᵐ μ)
split-sum2 (var-inl M) = refl
split-sum2 (var-inr N) = refl
⇑-resp-+ : ∀ {Θ Ψ Ξ Ω Γ A} {ι : Θ ⇒ᵐ Ψ} {μ : Ξ ⇒ᵐ Ω} {t : Term (Ξ + Θ) Γ A}
→ [ (⇑ᵐ μ) ]ᵐ ([ (ᵐ⇑ᵐ ι) ]ᵐ t) ≈ [ (ᵐ⇑ᵐ ι) ]ᵐ ([ (⇑ᵐ μ) ]ᵐ t)
⇑-resp-+ {Θ} {Ψ} {Ξ} {Ω} {Γ} {A} {ι} {μ} {t = t} =
let open SetoidR (Term-setoid (Ω ,, Ψ) Γ A) in
begin
[ ⇑ᵐ μ ]ᵐ ([ ᵐ⇑ᵐ ι ]ᵐ t) ≈⟨ ≈-sym [∘ᵐ] ⟩
[ (⇑ᵐ μ) ∘ᵐ (ᵐ⇑ᵐ ι) ]ᵐ t ≈⟨ ≈-sym ([]ᵐ-resp-≡ᵐ split-sum) ⟩
[ (μ +₁ ι) ]ᵐ t ≈⟨ []ᵐ-resp-≡ᵐ split-sum2 ⟩
[(ᵐ⇑ᵐ ι) ∘ᵐ (⇑ᵐ μ) ]ᵐ t ≈⟨ [∘ᵐ] ⟩
[ ᵐ⇑ᵐ ι ]ᵐ ([ ⇑ᵐ μ ]ᵐ t)
∎
∘ᵐ-resp-⇑ : ∀ {Θ Ψ Ξ Ω} {ι : Θ ⇒ᵐ Ψ} {μ : Ψ ⇒ᵐ Ω}
→ ⇑ᵐ {Ω = Ξ} (μ ∘ᵐ ι) ≡ᵐ ⇑ᵐ μ ∘ᵐ ⇑ᵐ ι
∘ᵐ-resp-⇑ (var-inl M) = refl
∘ᵐ-resp-⇑ (var-inr N) = refl
∘ᵐ-resp-⇑-term : ∀ {Θ Ψ Ξ Ω Γ A} {ι : Θ ⇒ᵐ Ψ} {μ : Ψ ⇒ᵐ Ω} {t : Term (Θ ,, Ξ) Γ A}
→ [ ⇑ᵐ {Ω = Ξ} (μ ∘ᵐ ι) ]ᵐ t ≈ [ ⇑ᵐ μ ]ᵐ ([ ⇑ᵐ ι ]ᵐ t)
∘ᵐ-resp-⇑-term {Θ} {Ψ} {Ξ} {Ω} {Γ} {A} {ι} {μ} {t = t} =
let open SetoidR (Term-setoid (Ω ,, Ξ) Γ A) in
begin
[ ⇑ᵐ {Ω = Ξ} (μ ∘ᵐ ι) ]ᵐ t ≈⟨ []ᵐ-resp-≡ᵐ ∘ᵐ-resp-⇑ ⟩
[ ⇑ᵐ μ ∘ᵐ ⇑ᵐ ι ]ᵐ t ≈⟨ [∘ᵐ] ⟩
[ ⇑ᵐ μ ]ᵐ ([ ⇑ᵐ ι ]ᵐ t)
∎
∘ᵐ-resp-ᵐ⇑ : ∀ {Θ Ψ Ξ Ω} {ι : Θ ⇒ᵐ Ψ} {μ : Ψ ⇒ᵐ Ω}
→ ᵐ⇑ᵐ (μ ∘ᵐ ι) {Ω = Ξ} ≡ᵐ ᵐ⇑ᵐ μ ∘ᵐ ᵐ⇑ᵐ ι
∘ᵐ-resp-ᵐ⇑ (var-inl M) = refl
∘ᵐ-resp-ᵐ⇑ (var-inr N) = refl
∘ᵐ-resp-ᵐ⇑-term : ∀ {Θ Ψ Ξ Ω Γ A} {ι : Θ ⇒ᵐ Ψ} {μ : Ψ ⇒ᵐ Ω} {t : Term (Ξ ,, Θ) Γ A}
→ [ ᵐ⇑ᵐ (μ ∘ᵐ ι) {Ω = Ξ} ]ᵐ t ≈ [ ᵐ⇑ᵐ μ ]ᵐ ([ ᵐ⇑ᵐ ι ]ᵐ t)
∘ᵐ-resp-ᵐ⇑-term {Θ} {Ψ} {Ξ} {Ω} {Γ} {A} {ι} {μ} {t = t} =
let open SetoidR (Term-setoid (Ξ ,, Ω) Γ A) in
begin
[ ᵐ⇑ᵐ (μ ∘ᵐ ι) {Ω = Ξ} ]ᵐ t ≈⟨ []ᵐ-resp-≡ᵐ ∘ᵐ-resp-ᵐ⇑ ⟩
[ ᵐ⇑ᵐ μ ∘ᵐ ᵐ⇑ᵐ ι ]ᵐ t ≈⟨ [∘ᵐ] ⟩
[ ᵐ⇑ᵐ μ ]ᵐ ([ ᵐ⇑ᵐ ι ]ᵐ t)
∎
vr-comm-mr : ∀ {Θ Ψ Γ Δ A} {ρ : Γ ⇒ᵛ Δ} {ι : Θ ⇒ᵐ Ψ} {t : Term Θ Γ A}
→ [ ι ]ᵐ ([ ρ ]ᵛ t) ≈ [ ρ ]ᵛ ([ ι ]ᵐ t)
vr-comm-mr {t = tm-var x} = ≈-refl
vr-comm-mr {t = tm-meta M ts} = ≈-meta (λ i → vr-comm-mr)
vr-comm-mr {t = tm-oper f es} = ≈-oper (λ i → vr-comm-mr)
mr-comm-vr : ∀ {Θ Ψ Γ Δ A} {ρ : Γ ⇒ᵛ Δ} {ι : Θ ⇒ᵐ Ψ} {t : Term Θ Γ A}
→ [ ρ ]ᵛ ([ ι ]ᵐ t) ≈ [ ι ]ᵐ ([ ρ ]ᵛ t)
mr-comm-vr {t = tm-var x} = ≈-refl
mr-comm-vr {t = tm-meta M ts} = ≈-meta (λ i → mr-comm-vr)
mr-comm-vr {t = tm-oper f es} = ≈-oper (λ i → mr-comm-vr)
module _ {Θ Ψ : MContext} {A : sort} where
open Categories.Category
open Categories.Category.Instance.Setoids
open Categories.Functor
open Categories.NaturalTransformation
MRenaming-NT : ∀ (ι : Θ ⇒ᵐ Ψ) → NaturalTransformation (Term-Functor {Θ} {A}) (Term-Functor {Ψ} {A})
MRenaming-NT ι =
record
{ η = λ Γ → record { _⟨$⟩_ = [ ι ]ᵐ_ ; cong = []ᵐ-resp-≈ }
; commute = λ ρ t≈s → ≈-trans ([]ᵐ-resp-≈ ([]ᵛ-resp-≈ t≈s)) (ᵐ∘ᵛ≈ᵛ∘ᵐ)
; sym-commute = λ ρ t≈s → ≈-trans (≈-sym ᵐ∘ᵛ≈ᵛ∘ᵐ) ([]ᵐ-resp-≈ ([]ᵛ-resp-≈ t≈s))
}
| {
"alphanum_fraction": 0.4670201294,
"avg_line_length": 32.3488372093,
"ext": "agda",
"hexsha": "409a3b9a2473e396481529aaf0915edea8a3e7c8",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/SecondOrder/MRenaming.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/SecondOrder/MRenaming.agda",
"max_line_length": 103,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/SecondOrder/MRenaming.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 6801,
"size": 11128
} |
module UntypingPairs where
open import Relation.Binary.PropositionalEquality
open import Function using (id)
open import Data.Empty
open import Data.Unit
open import Relation.Nullary
open import Data.Nat
open import Data.Fin
open import Data.Vec
open import Data.Sum
open import Data.Product
open import Data.List
open import Data.Maybe
-- Rather tedious --- stuff grows quadratically. Get this to go
-- through and then see if we can generalize to codes for constructors
-- or something like that.
------------------------------------------------------------
-- Types
------------------------------------------------------------
-- A universe of types for STLC + natural numbers + pairs.
data Type : Set where
Nat : Type
_⇒_ : Type → Type → Type
_⊗_ : Type → Type → Type
infixr 80 _⇒_
infixr 90 _⊗_
-- The function type constructor is injective.
⇒-inj : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂ ≡ τ₃ ⇒ τ₄) → (τ₁ ≡ τ₃) × (τ₂ ≡ τ₄)
⇒-inj refl = refl , refl
⊗-inj : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⊗ τ₂ ≡ τ₃ ⊗ τ₄) → (τ₁ ≡ τ₃) × (τ₂ ≡ τ₄)
⊗-inj refl = refl , refl
-- Equality of types is decidable.
_≡?_ : (τ₁ τ₂ : Type) → (τ₁ ≡ τ₂) ⊎ (τ₁ ≢ τ₂)
Nat ≡? Nat = inj₁ refl
Nat ≡? (_ ⇒ _) = inj₂ (λ ())
Nat ≡? (_ ⊗ _) = inj₂ (λ ())
(_ ⇒ _) ≡? Nat = inj₂ (λ ())
(_ ⇒ _) ≡? (_ ⊗ _) = inj₂ (λ ())
(_ ⊗ _) ≡? Nat = inj₂ (λ ())
(_ ⊗ _) ≡? (_ ⇒ _) = inj₂ (λ ())
(τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
(τ₁ ⇒ τ₂) ≡? (.τ₁ ⇒ .τ₂) | inj₁ refl | inj₁ refl = inj₁ refl
(τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) | inj₂ τ₁≢τ₃ | _ = inj₂ (λ eq → τ₁≢τ₃ (proj₁ (⇒-inj eq)))
(τ₁ ⇒ τ₂) ≡? (τ₃ ⇒ τ₄) | _ | inj₂ τ₂≢τ₄ = inj₂ (λ eq → τ₂≢τ₄ (proj₂ (⇒-inj eq)))
(τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
(τ₁ ⊗ τ₂) ≡? (.τ₁ ⊗ .τ₂) | inj₁ refl | inj₁ refl = inj₁ refl
(τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) | inj₂ τ₁≢τ₃ | _ = inj₂ (λ x → τ₁≢τ₃ (proj₁ (⊗-inj x)))
(τ₁ ⊗ τ₂) ≡? (τ₃ ⊗ τ₄) | _ | inj₂ τ₂≢τ₄ = inj₂ (λ eq → τ₂≢τ₄ (proj₂ (⊗-inj eq)))
≢-cong-⇒ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂ ≢ τ₃ ⇒ τ₄) → (τ₁ ≢ τ₃) ⊎ (τ₂ ≢ τ₄)
≢-cong-⇒ {τ₁} {τ₂} {τ₃} {τ₄} neq with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
≢-cong-⇒ neq | inj₂ τ₁≢τ₃ | _ = inj₁ τ₁≢τ₃
≢-cong-⇒ neq | _ | inj₂ τ₂≢τ₄ = inj₂ τ₂≢τ₄
≢-cong-⇒ neq | inj₁ refl | inj₁ refl = ⊥-elim (neq refl)
≢-cong-⊗ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⊗ τ₂ ≢ τ₃ ⊗ τ₄) → (τ₁ ≢ τ₃) ⊎ (τ₂ ≢ τ₄)
≢-cong-⊗ {τ₁} {τ₂} {τ₃} {τ₄} neq with τ₁ ≡? τ₃ | τ₂ ≡? τ₄
≢-cong-⊗ neq | inj₂ τ₁≢τ₃ | _ = inj₁ τ₁≢τ₃
≢-cong-⊗ neq | _ | inj₂ τ₂≢τ₄ = inj₂ τ₂≢τ₄
≢-cong-⊗ neq | inj₁ refl | inj₁ refl = ⊥-elim (neq refl)
-- A type of explicit evidence explaining *why* two types are unequal.
data _≁_ : Type → Type → Set where
Nat≁⇒ : ∀ {τ₁ τ₂} → Nat ≁ (τ₁ ⇒ τ₂)
Nat≁⊗ : ∀ {τ₁ τ₂} → Nat ≁ (τ₁ ⊗ τ₂)
⇒≁⊗ : ∀ {τ₁ τ₂ τ₃ τ₄} → (τ₁ ⇒ τ₂) ≁ (τ₃ ⊗ τ₄)
⇒ˡ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₁ ≁ τ₂ → (τ₁ ⇒ τ₃) ≁ (τ₂ ⇒ τ₄)
⇒ʳ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₃ ≁ τ₄ → (τ₁ ⇒ τ₃) ≁ (τ₂ ⇒ τ₄)
⊗ˡ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₁ ≁ τ₂ → (τ₁ ⊗ τ₃) ≁ (τ₂ ⊗ τ₄)
⊗ʳ-≁ : ∀ {τ₁ τ₂ τ₃ τ₄} → τ₃ ≁ τ₄ → (τ₁ ⊗ τ₃) ≁ (τ₂ ⊗ τ₄)
≁-sym : ∀ {τ₁ τ₂} → τ₁ ≁ τ₂ → τ₂ ≁ τ₁
-- Given such a proof we can show the types are unequal.
≁-≢ : ∀ {τ₁ τ₂} → (τ₁ ≁ τ₂) → (τ₁ ≢ τ₂)
≁-≢ Nat≁⇒ = λ ()
≁-≢ Nat≁⊗ = λ ()
≁-≢ ⇒≁⊗ = λ ()
≁-≢ (⇒ˡ-≁ τ₁≁τ₂) refl = ≁-≢ τ₁≁τ₂ refl
≁-≢ (⇒ʳ-≁ τ₃≁τ₄) refl = ≁-≢ τ₃≁τ₄ refl
≁-≢ (⊗ˡ-≁ τ₁≁τ₂) refl = ≁-≢ τ₁≁τ₂ refl
≁-≢ (⊗ʳ-≁ τ₃≁τ₄) refl = ≁-≢ τ₃≁τ₄ refl
≁-≢ (≁-sym τ₂≁τ₁) refl = ≁-≢ τ₂≁τ₁ refl
-- Since our universe of types is closed, we can actually go the other
-- way too. That is, ≢ is equivalent to ≁ ; the point is that the
-- latter is more immediately informative (by pattern-matching etc.)
-- which can be used to produce error messages and so on.
--
-- Note, however, that there might be *multiple* terms of type τ₁ ≁
-- τ₂: each corresponds to a different explanation of why the types
-- are not equal. We might actually care which one we have.
-- Round-tripping through (τ₁ ≢ τ₂) is not the identity.
≢-≁ : ∀ {τ₁ τ₂} → (τ₁ ≢ τ₂) → (τ₁ ≁ τ₂)
≢-≁ {Nat} {Nat} τ₁≢τ₂ with τ₁≢τ₂ refl
... | ()
≢-≁ {Nat} {τ₂ ⇒ τ₃} _ = Nat≁⇒
≢-≁ {Nat} {τ₂ ⊗ τ₃} _ = Nat≁⊗
≢-≁ {τ₁ ⇒ τ₂} {Nat} _ = ≁-sym Nat≁⇒
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⊗ τ₄} _ = ⇒≁⊗
≢-≁ {τ₁ ⊗ τ₂} {Nat} _ = ≁-sym Nat≁⊗
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⇒ τ₄} _ = ≁-sym ⇒≁⊗
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ with ≢-cong-⇒ τ₁⇒τ₂≢τ₃⇒τ₄
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ | inj₁ τ₁≢τ₃ = ⇒ˡ-≁ (≢-≁ τ₁≢τ₃)
≢-≁ {τ₁ ⇒ τ₂} {τ₃ ⇒ τ₄} τ₁⇒τ₂≢τ₃⇒τ₄ | inj₂ τ₂≢τ₄ = ⇒ʳ-≁ (≢-≁ τ₂≢τ₄)
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ with ≢-cong-⊗ τ₁⊗τ₂≢τ₃⊗τ₄
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ | inj₁ τ₁≢τ₃ = ⊗ˡ-≁ (≢-≁ τ₁≢τ₃)
≢-≁ {τ₁ ⊗ τ₂} {τ₃ ⊗ τ₄} τ₁⊗τ₂≢τ₃⊗τ₄ | inj₂ τ₂≢τ₄ = ⊗ʳ-≁ (≢-≁ τ₂≢τ₄)
-- Sometimes it's convenient to decide equality of types using ≁ in place of ≢.
_∼?_ : (τ₁ τ₂ : Type) → (τ₁ ≡ τ₂) ⊎ (τ₁ ≁ τ₂)
τ₁ ∼? τ₂ = Data.Sum.map id ≢-≁ (τ₁ ≡? τ₂)
-- Evidence that a type is not an arrow type.
data not⇒_ : Type → Set where
not⇒Nat : not⇒ Nat
not⇒⊗ : ∀ {τ₁ τ₂} → not⇒ (τ₁ ⊗ τ₂)
data not⊗_ : Type → Set where
not⊗Nat : not⊗ Nat
not⊗⇒ : ∀ {τ₁ τ₂} → not⊗ (τ₁ ⇒ τ₂)
⇒? : (τ : Type) → (Σ[ τ₁ ∈ Type ] Σ[ τ₂ ∈ Type ] τ ≡ τ₁ ⇒ τ₂) ⊎ (not⇒ τ)
⇒? Nat = inj₂ not⇒Nat
⇒? (_ ⊗ _) = inj₂ not⇒⊗
⇒? (τ₁ ⇒ τ₂) = inj₁ (τ₁ , τ₂ , refl)
------------------------------------------------------------
-- Expressions
------------------------------------------------------------
-- (Untyped) expressions of STLC + arithmetic + pairs.
data Expr (n : ℕ) : Set where
lit : ℕ → Expr n
_⊕_ : Expr n → Expr n → Expr n
⟨_,_⟩ : Expr n → Expr n → Expr n
π₁ : Expr n
π₂ : Expr n
var : Fin n → Expr n
ƛ : Type → Expr (suc n) → Expr n
_·_ : Expr n → Expr n → Expr n
Ctx : ℕ → Set
Ctx n = Vec Type n
------------------------------------------------------------
-- Typing
------------------------------------------------------------
-- Typing derivations.
data _⊢_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where
lit : ∀ {n} {Γ : Ctx n} {m}
→ Γ ⊢ lit m ∶ Nat
_⊕_ : ∀ {n} {Γ : Ctx n} {t₁ t₂}
→ Γ ⊢ t₁ ∶ Nat
→ Γ ⊢ t₂ ∶ Nat
→ Γ ⊢ (t₁ ⊕ t₂) ∶ Nat
⟨_,_⟩ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊢ t₁ ∶ τ₁
→ Γ ⊢ t₂ ∶ τ₂
→ Γ ⊢ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂
π₁ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ Γ ⊢ π₁ ∶ (τ₁ ⊗ τ₂) ⇒ τ₁
π₂ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ Γ ⊢ π₂ ∶ (τ₁ ⊗ τ₂) ⇒ τ₂
var : ∀ {n} {Γ : Ctx n} {i}
→ Γ ⊢ var i ∶ lookup i Γ
ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂}
→ (τ₁ ∷ Γ) ⊢ t ∶ τ₂
→ Γ ⊢ ƛ τ₁ t ∶ (τ₁ ⇒ τ₂)
_·_ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊢ t₁ ∶ τ₁ ⇒ τ₂
→ Γ ⊢ t₂ ∶ τ₁
→ Γ ⊢ t₁ · t₂ ∶ τ₂
-- Explicit, constructive evidence for the *untypability* of a term.
data _⊬_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where
-- Explicitly build in uniqueness of typing as an axiom. t is not
-- typeable at type τ₂ if t is typeable at some different type.
mismatch : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂}
→ Γ ⊢ t ∶ τ₁
→ τ₁ ≁ τ₂
→ Γ ⊬ t ∶ τ₂
-- There are three ways for a + term to fail to have a given type τ:
-- either the left or right sides do not have type Nat, or the type
-- τ itself is not Nat.
⊕ˡ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ Γ ⊬ t₁ ∶ Nat
→ Γ ⊬ (t₁ ⊕ t₂) ∶ τ
⊕ʳ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ Γ ⊬ t₂ ∶ Nat
→ Γ ⊬ (t₁ ⊕ t₂) ∶ τ
⊕≁Nat : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ τ ≁ Nat → Γ ⊬ (t₁ ⊕ t₂) ∶ τ
⟨⟩-ty : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ}
→ not⊗ τ → Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ
⟨⟩ˡ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊬ t₁ ∶ τ₁
→ Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂
⟨⟩ʳ : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊬ t₂ ∶ τ₂
→ Γ ⊬ ⟨ t₁ , t₂ ⟩ ∶ τ₁ ⊗ τ₂
π₁-⇒ : ∀ {n} {Γ : Ctx n} {τ}
→ not⇒ τ
→ Γ ⊬ π₁ ∶ τ
π₁-⊗ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ not⊗ τ₁
→ Γ ⊬ π₁ ∶ τ₁ ⇒ τ₂
π₁-∼ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂ τ₃}
→ τ₁ ≁ τ₃
→ Γ ⊬ π₁ ∶ (τ₁ ⊗ τ₂) ⇒ τ₃
π₂-⇒ : ∀ {n} {Γ : Ctx n} {τ}
→ not⇒ τ
→ Γ ⊬ π₂ ∶ τ
π₂-⊗ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂}
→ not⊗ τ₁
→ Γ ⊬ π₂ ∶ τ₁ ⇒ τ₂
π₂-∼ : ∀ {n} {Γ : Ctx n} {τ₁ τ₂ τ₃}
→ τ₂ ≁ τ₃
→ Γ ⊬ π₂ ∶ (τ₁ ⊗ τ₂) ⇒ τ₃
-- ƛ-funty holds if τ is not a function type at all, or if it is a
-- function type whose input type is not τ₁.
ƛ-funty : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ}
→ (∀ {τ₂} → τ ≁ τ₁ ⇒ τ₂)
→ Γ ⊬ ƛ τ₁ t ∶ τ
-- Otherwise, τ is of the form (τ₁ ⇒ τ₂) but the body t does not
-- have type τ₂. Note this could be either because t is not typable
-- at all, or because it has some type other than τ₂.
ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂}
→ (τ₁ ∷ Γ) ⊬ t ∶ τ₂
→ Γ ⊬ ƛ τ₁ t ∶ (τ₁ ⇒ τ₂)
-- Had this ƛ-resty constructor, but it turns out we don't need it:
-- it is not used in inference or checking, and isn't needed to
-- prove equivalence of ⊬ and ¬ ⊢ . It handles *only* the case
-- where t is typable but has a type different than the output type
-- of the whole expression; but the ƛ constructor handles this case
-- as well as the case where t is not typeable at all.
-- ƛ-resty : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂ τ₃}
-- → (τ₁ ∷ Γ) ⊢ t ∶ τ₂
-- → τ₂ ≁ τ₃
-- → Γ ⊬ ƛ τ₁ t ∶ τ₁ ⇒ τ₃
-- Finally, there are two cases when an application is not typeable.
-- Either the function does not have an appropriate function type,
-- or the argument does not have a type that matches the function's
-- input type.
·-fun : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₂}
→ (∀ {τ₁} → Γ ⊬ t₁ ∶ τ₁ ⇒ τ₂)
→ Γ ⊬ t₁ · t₂ ∶ τ₂
·-arg : ∀ {n} {Γ : Ctx n} {t₁ t₂} {τ₁ τ₂}
→ Γ ⊢ t₁ ∶ τ₁ ⇒ τ₂
→ Γ ⊬ t₂ ∶ τ₁
→ Γ ⊬ t₁ · t₂ ∶ τ₂
-- ------------------------------------------------------------
-- -- Type inference and checking
-- ------------------------------------------------------------
-- -- Type inference for a term in a given context returns either a type
-- -- and a valid typing derivation, or a constructive proof that the
-- -- term has no type. Note that in this system, ALL terms can be
-- -- inferred. In a bidirectional system we would have to restrict this
-- -- to only take inferrable terms as inputs.
-- infer : ∀ {n} → (Γ : Ctx n) → (t : Expr n) → (∃ λ τ → Γ ⊢ t ∶ τ) ⊎ (∀ τ → Γ ⊬ t ∶ τ)
-- infer Γ (lit n) = inj₁ (Nat , lit)
-- infer Γ (t₁ ⊕ t₂) with infer Γ t₁ | infer Γ t₂
-- infer Γ (t₁ ⊕ t₂) | inj₁ (Nat , Γ⊢t₁∶Nat) | inj₁ (Nat , Γ⊢t₂∶Nat) = inj₁ (Nat , (Γ⊢t₁∶Nat ⊕ Γ⊢t₂∶Nat))
-- infer Γ (t₁ ⊕ t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ _ = inj₂ (λ _ → ⊕ˡ (mismatch Γ⊢t₁∶τ₁⇒τ₂ (≁-sym Nat≁⇒)))
-- infer Γ (t₁ ⊕ t₂) | inj₁ _ | inj₁ (τ₃ ⇒ τ₄ , Γ⊢t₂∶τ₃⇒τ₄) = inj₂ (λ _ → ⊕ʳ (mismatch Γ⊢t₂∶τ₃⇒τ₄ (≁-sym Nat≁⇒)))
-- infer Γ (t₁ ⊕ t₂) | inj₂ Γ⊬t₁∶ | _ = inj₂ (λ _ → ⊕ˡ (Γ⊬t₁∶ Nat))
-- infer Γ (t₁ ⊕ t₂) | _ | inj₂ Γ⊬t₂∶ = inj₂ (λ _ → ⊕ʳ (Γ⊬t₂∶ Nat))
-- infer Γ (var i) = inj₁ (lookup i Γ , var)
-- infer Γ (ƛ τ₁ t) with infer (τ₁ ∷ Γ) t
-- infer Γ (ƛ τ₁ t) | inj₁ (τ₂ , τ₁∷Γ⊢t∶τ₂) = inj₁ (τ₁ ⇒ τ₂ , ƛ τ₁∷Γ⊢t∶τ₂)
-- infer Γ (ƛ τ₁ t) | inj₂ τ₁∷Γ⊬t∶ = inj₂ lemma
-- where
-- lemma : (τ : Type) → Γ ⊬ ƛ τ₁ t ∶ τ
-- lemma Nat = ƛ-funty Nat≁⇒
-- lemma (τ₁′ ⇒ τ₂) with τ₁′ ∼? τ₁
-- lemma (.τ₁ ⇒ τ₂) | inj₁ refl = ƛ (τ₁∷Γ⊬t∶ τ₂)
-- lemma (τ₁′ ⇒ τ₂) | inj₂ τ₁′≁τ₁ = ƛ-funty (λ {τ₃} → ⇒ˡ-≁ τ₁′≁τ₁)
-- infer Γ (t₁ · t₂) with infer Γ t₁ | infer Γ t₂
-- infer Γ (t₁ · t₂) | inj₁ (Nat , Γ⊢t₁∶Nat) | _ = inj₂ (λ _ → ·-fun (mismatch Γ⊢t₁∶Nat Nat≁⇒))
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (τ₁′ , Γ⊢t₂∶τ₁′) with τ₁ ∼? τ₁′
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (.τ₁ , Γ⊢t₂∶τ₁ ) | inj₁ refl = inj₁ (τ₂ , (Γ⊢t₁∶τ₁⇒τ₂ · Γ⊢t₂∶τ₁))
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₁ (τ₁′ , Γ⊢t₂∶τ₁′) | inj₂ τ₁≁τ₁′ = inj₂ lemma2
-- where
-- lemma2 : ∀ τ → Γ ⊬ t₁ · t₂ ∶ τ
-- lemma2 τ with τ ∼? τ₂
-- lemma2 τ | inj₁ τ≡τ₂ rewrite τ≡τ₂ = ·-arg Γ⊢t₁∶τ₁⇒τ₂ (mismatch Γ⊢t₂∶τ₁′ (≁-sym τ₁≁τ₁′))
-- lemma2 τ | inj₂ τ≁τ₂ = ·-fun (mismatch Γ⊢t₁∶τ₁⇒τ₂ (⇒ʳ-≁ (≁-sym τ≁τ₂)))
-- infer Γ (t₁ · t₂) | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁⇒τ₂) | inj₂ Γ⊬t₂ = inj₂ lemma3
-- where
-- lemma3 : ∀ τ → Γ ⊬ t₁ · t₂ ∶ τ
-- lemma3 τ with τ ∼? τ₂
-- lemma3 τ | inj₁ τ≡τ₂ rewrite τ≡τ₂ = ·-arg Γ⊢t₁∶τ₁⇒τ₂ (Γ⊬t₂ τ₁)
-- lemma3 τ | inj₂ τ≁τ₂ = ·-fun (mismatch Γ⊢t₁∶τ₁⇒τ₂ (⇒ʳ-≁ (≁-sym τ≁τ₂)))
-- infer Γ (t₁ · t₂) | inj₂ Γ⊬t₁∶ | _ = inj₂ (λ τ₂ → ·-fun (λ {τ₁} → Γ⊬t₁∶ (τ₁ ⇒ τ₂)))
-- -- Check whether a given term has a *given* type.
-- check : ∀ {n} → (Γ : Ctx n) → (t : Expr n) → (τ : Type) → (Γ ⊢ t ∶ τ) ⊎ (Γ ⊬ t ∶ τ)
-- check Γ (lit _) (τ ⇒ τ₁) = inj₂ (mismatch lit Nat≁⇒)
-- check Γ (lit _) Nat = inj₁ lit
-- check Γ (_ ⊕ _ ) (τ ⇒ τ₁) = inj₂ (⊕≁Nat (≁-sym Nat≁⇒))
-- check Γ (t₁ ⊕ t₂) Nat with check Γ t₁ Nat | check Γ t₂ Nat
-- check Γ (t₁ ⊕ t₂) Nat | inj₁ Γ⊢t₁∶Nat | inj₁ Γ⊢t₂∶Nat = inj₁ (Γ⊢t₁∶Nat ⊕ Γ⊢t₂∶Nat)
-- check Γ (t₁ ⊕ t₂) Nat | inj₂ Γ⊬t₁∶Nat | _ = inj₂ (⊕ˡ Γ⊬t₁∶Nat)
-- check Γ (t₁ ⊕ t₂) Nat | _ | inj₂ Γ⊬t₂∶Nat = inj₂ (⊕ʳ Γ⊬t₂∶Nat)
-- check Γ (var i) τ with τ ∼? lookup i Γ
-- check Γ (var i) τ | inj₁ τ≡iΓ rewrite τ≡iΓ = inj₁ var
-- check Γ (var i) τ | inj₂ τ≁iΓ = inj₂ (mismatch var (≁-sym τ≁iΓ))
-- check Γ (ƛ τ₁ t) Nat = inj₂ (ƛ-funty Nat≁⇒)
-- check Γ (ƛ τ₁ t) (τ ⇒ τ₂) with τ ∼? τ₁ | check (τ₁ ∷ Γ) t τ₂
-- check Γ (ƛ τ₁ t) (τ ⇒ τ₂) | inj₂ τ≁τ₁ | _ = inj₂ (ƛ-funty (⇒ˡ-≁ τ≁τ₁))
-- check Γ (ƛ τ₁ t) (.τ₁ ⇒ τ₂) | inj₁ refl | inj₂ τ₁∷Γ⊬t∶τ₂ = inj₂ (ƛ τ₁∷Γ⊬t∶τ₂)
-- check Γ (ƛ τ₁ t) (.τ₁ ⇒ τ₂) | inj₁ refl | inj₁ τ₁∷Γ⊢t∶τ₂ = inj₁ (ƛ τ₁∷Γ⊢t∶τ₂)
-- --- Note that in order to check an application we have to use type inference on t₁.
-- check Γ (t₁ · t₂) τ with infer Γ t₁
-- check Γ (t₁ · t₂) τ | inj₂ Γ⊬t₁∶ = inj₂ (·-fun (λ {τ₁} → Γ⊬t₁∶ (τ₁ ⇒ τ)))
-- check Γ (t₁ · t₂) τ | inj₁ (Nat , Γ⊢t₁∶τ₁) = inj₂ (·-fun (mismatch Γ⊢t₁∶τ₁ Nat≁⇒))
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) with τ ∼? τ₂
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₂ τ≁τ₂ = inj₂ (·-fun (mismatch Γ⊢t₁∶τ₁ (⇒ʳ-≁ (≁-sym τ≁τ₂))))
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ rewrite τ≡τ₂ with check Γ t₂ τ₁
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ | inj₂ Γ⊬t₂∶τ₁ = inj₂ (·-arg Γ⊢t₁∶τ₁ Γ⊬t₂∶τ₁)
-- check Γ (t₁ · t₂) τ | inj₁ (τ₁ ⇒ τ₂ , Γ⊢t₁∶τ₁) | inj₁ τ≡τ₂ | inj₁ Γ⊢t₂∶τ₁ = inj₁ (Γ⊢t₁∶τ₁ · Γ⊢t₂∶τ₁)
-- ------------------------------------------------------------
-- -- Correctness
-- ------------------------------------------------------------
-- -- The whole idea is that ⊬ is a more explicit/constructive, yet
-- -- equivalent, way to represent the negation of ⊢ . We can actually
-- -- prove the equivalence.
-- -- First, straightforward induction on typing derivations shows that
-- -- we really do have unique types, as assumed by the 'mismatch'
-- -- constructor.
-- ⊢-unique : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ₁ τ₂ : Type} → (Γ ⊢ t ∶ τ₁) → (Γ ⊢ t ∶ τ₂) → (τ₁ ≡ τ₂)
-- ⊢-unique lit lit = refl
-- ⊢-unique (_ ⊕ _) (_ ⊕ _) = refl
-- ⊢-unique var var = refl
-- ⊢-unique (ƛ Γ⊢t∶τ₁) (ƛ Γ⊢t∶τ₂) rewrite ⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ₂ = refl
-- ⊢-unique (Γ⊢t∶τ₁ · _) (Γ⊢t∶τ₂ · _) = proj₂ (⇒-inj (⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ₂))
-- -- Now we can do one direction of the equivalence. This direction is
-- -- just induction over derivations, making use of uniqueness of
-- -- typing.
-- ⊬-¬⊢ : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ : Type} → (Γ ⊬ t ∶ τ) → (¬ (Γ ⊢ t ∶ τ))
-- ⊬-¬⊢ (mismatch Γ⊢t∶τ₁ τ₁≁τ) Γ⊢t∶τ = ≁-≢ τ₁≁τ (⊢-unique Γ⊢t∶τ₁ Γ⊢t∶τ)
-- ⊬-¬⊢ (⊕ˡ Γ⊬t₁∶N) (Γ⊢t₁∶N ⊕ _ ) = ⊬-¬⊢ Γ⊬t₁∶N Γ⊢t₁∶N
-- ⊬-¬⊢ (⊕ʳ Γ⊬t₂∶N) (_ ⊕ Γ⊢t₂∶N) = ⊬-¬⊢ Γ⊬t₂∶N Γ⊢t₂∶N
-- ⊬-¬⊢ (⊕≁Nat τ≁N) (_ ⊕ _ ) = ≁-≢ τ≁N refl
-- ⊬-¬⊢ (ƛ-funty τ≁τ₁⇒) (ƛ _) = ≁-≢ τ≁τ₁⇒ refl
-- ⊬-¬⊢ (ƛ Γ⊬t∶τ₂) (ƛ Γ⊢t∶τ₂) = ⊬-¬⊢ Γ⊬t∶τ₂ Γ⊢t∶τ₂
-- ⊬-¬⊢ (·-fun Γ⊬t₁) (Γ⊢t₁ · _) = ⊬-¬⊢ Γ⊬t₁ Γ⊢t₁
-- ⊬-¬⊢ (·-arg Γ⊢t₁∶τ₁⇒τ Γ⊬t₂∶τ) (Γ⊢t₁∶τ₂⇒τ · Γ⊢t₂)
-- rewrite proj₁ (⇒-inj (⊢-unique Γ⊢t₁∶τ₁⇒τ Γ⊢t₁∶τ₂⇒τ)) = ⊬-¬⊢ Γ⊬t₂∶τ Γ⊢t₂
-- -- The other direction follows straightforwardly from type checking.
-- ¬⊢-⊬ : ∀ {n} {Γ : Ctx n} {t : Expr n} {τ : Type} → (¬ (Γ ⊢ t ∶ τ)) → (Γ ⊬ t ∶ τ)
-- ¬⊢-⊬ {_} {Γ} {t} {τ} ¬Γ⊢t∶τ with check Γ t τ
-- ¬⊢-⊬ ¬Γ⊢t∶τ | inj₁ Γ⊢t∶τ = ⊥-elim (¬Γ⊢t∶τ Γ⊢t∶τ)
-- ¬⊢-⊬ ¬Γ⊢t∶τ | inj₂ Γ⊬t∶τ = Γ⊬t∶τ
-- ------------------------------------------------------------
-- -- Take 2
-- ------------------------------------------------------------
-- -- XXX these need to be dependent somehow? e.g. consider the ƛ case
-- -- below. If τ is not an arrow type the whole thing fails; but if it
-- -- does, we need to know what τ₁ and τ₂ are in order to refer to them
-- -- in the rest of the conditions.
-- data many : List (Set × Set) → Set where
-- empty : many []
-- here : ∀ {Tₗ Tᵣ Ts} → Tₗ → many Ts → many ((Tₗ , Tᵣ) ∷ Ts)
-- there : ∀ {Tₗ Tᵣ Ts} → Tᵣ → many Ts → many ((Tₗ , Tᵣ) ∷ Ts)
-- data some : List (Set × Set) → Set where
-- here : ∀ {Tₗ Tᵣ Ts} → Tₗ → many Ts → some ((Tₗ , Tᵣ) ∷ Ts)
-- there : ∀ {Tₗ Tᵣ Ts} → Tᵣ → some Ts → some ((Tₗ , Tᵣ) ∷ Ts)
-- -- Unique untypability; gives *every* possible reason that something
-- -- is not typeable. There is no 'mismatch' constructor.
-- {-# NO_POSITIVITY_CHECK #-}
-- data _⊬₂_∶_ : ∀ {n} → Ctx n → Expr n → Type → Set where
-- lit : ∀ {n} {Γ : Ctx n} {m} {τ} → τ ≁ Nat → Γ ⊬₂ lit m ∶ τ
-- -- For t₁ ⊕ t₂ to be untypeable, at least one of three things must be wrong:
-- ⊕ : ∀ {n} {Γ : Ctx n} {t₁ t₂ τ}
-- → some
-- ( (Γ ⊬₂ t₁ ∶ Nat , Γ ⊢ t₁ ∶ Nat) -- Either t₁ is well-typed or not
-- ∷ (Γ ⊬₂ t₂ ∶ Nat , Γ ⊢ t₂ ∶ Nat) -- Either t₂ is well-typed or not
-- ∷ ((τ ≁ Nat) , (τ ≡ Nat)) -- τ is Nat or not
-- ∷ []
-- )
-- → Γ ⊬₂ t₁ ⊕ t₂ ∶ τ
-- var : ∀ {n} {Γ : Ctx n} {i τ}
-- → τ ≁ lookup i Γ
-- → Γ ⊬₂ var i ∶ τ
-- -- ƛ τ₁ t does not have type τ if
-- -- - τ is not an arrow type
-- -- ƛ : ∀ {n} {Γ : Ctx n} {t} {τ₁ τ₂ τ}
-- -- → some
-- -- ( (τ ≁
| {
"alphanum_fraction": 0.4710358234,
"avg_line_length": 41.1073059361,
"ext": "agda",
"hexsha": "df8d448e16aa68f9d8460e7ae34349b3d2b6712f",
"lang": "Agda",
"max_forks_count": 20,
"max_forks_repo_forks_event_max_datetime": "2021-07-30T05:37:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-02-18T20:36:05.000Z",
"max_forks_repo_head_hexsha": "6c7561bcc9877c6df9107f12f7e843f4e880189a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "enlambdment/disco",
"max_forks_repo_path": "explore/typecheck/UntypingPairs.agda",
"max_issues_count": 282,
"max_issues_repo_head_hexsha": "6c7561bcc9877c6df9107f12f7e843f4e880189a",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T21:43:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-11-19T18:05:42.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "enlambdment/disco",
"max_issues_repo_path": "explore/typecheck/UntypingPairs.agda",
"max_line_length": 123,
"max_stars_count": 138,
"max_stars_repo_head_hexsha": "6c7561bcc9877c6df9107f12f7e843f4e880189a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "enlambdment/disco",
"max_stars_repo_path": "explore/typecheck/UntypingPairs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-22T22:56:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-10T08:10:03.000Z",
"num_tokens": 9478,
"size": 18005
} |
module UniDB.Morph.Reg where
open import UniDB.Spec
open import UniDB.Morph.WeakenPrime
open import UniDB.Morph.ShiftsPrime
--------------------------------------------------------------------------------
data Reg (T : STX) : MOR where
baseR : {γ₁ γ₂ : Dom} (ξ : Weaken` γ₁ γ₂) → Reg T γ₁ γ₂
snocR : {γ₁ γ₂ : Dom} (ξ : Reg T γ₁ γ₂) (t : T γ₂) → Reg T (suc γ₁) γ₂
module _ {T : STX} where
instance
iIdmReg : Idm (Reg T)
idm {{iIdmReg}} γ = baseR baseW
iWkmReg : Wkm (Reg T)
wkm {{iWkmReg}} δ = baseR (wkm {Weaken`} δ)
iBetaReg : Beta T (Reg T)
beta {{iBetaReg}} t = snocR (idm {_} _) t
module _ {{vrT : Vr T}} {{wkT : Wk T}} where
instance
iWkReg : {γ₁ : Dom} → Wk (Reg T γ₁)
wk₁ {{iWkReg}} (baseR ξ) = baseR (wk₁ ξ)
wk₁ {{iWkReg}} (snocR ξ t) = snocR (wk₁ ξ) (wk₁ t)
wk {{iWkReg}} zero ξ = ξ
wk {{iWkReg}} (suc δ) ξ = wk₁ (wk δ ξ)
wk-zero {{iWkReg}} x = refl
wk-suc {{iWkReg}} δ x = refl
iUpReg : Up (Reg T)
_↑₁ {{iUpReg}} ξ = snocR (wk₁ ξ) (vr {T} zero)
_↑_ {{iUpReg}} ξ 0 = ξ
_↑_ {{iUpReg}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpReg}} ξ = refl
↑-suc {{iUpReg}} ξ δ⁺ = refl
-- iUpIdmReg : {{wkT : Wk T}} → UpIdm (Reg T)
-- idm-↑₁ {{iUpIdmReg}} = ?refl
instance
iHCompWeakenReg : HComp Weaken` (Reg T) (Reg T)
_⊡_ {{iHCompWeakenReg}} ξ (baseR ζ) = baseR (ξ ⊙ ζ)
_⊡_ {{iHCompWeakenReg}} baseW ζ = ζ
_⊡_ {{iHCompWeakenReg}} (stepW ξ) (snocR ζ t) = ξ ⊡ ζ
iHCompIdmLeftWeakenReg : HCompIdmLeft Weaken` (Reg T)
idm-⊡ {{iHCompIdmLeftWeakenReg}} (baseR ξ)
rewrite idm-⊙ {Weaken`} ξ = refl
idm-⊡ {{iHCompIdmLeftWeakenReg}} (snocR ξ₂ t) = refl
⊡-⊡-assoc : {γ₁ γ₂ γ₃ γ₄ : Dom}
(ξ₁ : Weaken` γ₁ γ₂)
(ξ₂ : Weaken` γ₂ γ₃)
(ξ₃ : Reg T γ₃ γ₄) →
_⊡_ {Weaken`} {Reg T} {Reg T} ξ₁ (ξ₂ ⊡ ξ₃) ≡ (ξ₁ ⊙ ξ₂) ⊡ ξ₃
⊡-⊡-assoc ξ₁ ξ₂ (baseR ξ₃) = cong baseR (⊙-assoc {Weaken`} ξ₁ ξ₂ ξ₃)
⊡-⊡-assoc ξ₁ baseW ξ₃ rewrite idm-⊡ {Weaken`} {Reg T} ξ₃ = refl
⊡-⊡-assoc ξ₁ (stepW ξ₂) (snocR ξ₃ t) = ⊡-⊡-assoc ξ₁ ξ₂ ξ₃
module _ {T : STX} {{vrT : Vr T}} where
instance
iLkReg : Lk T (Reg T)
lk {{iLkReg}} (baseR ξ) i = lk {T} {Weaken`} ξ i
lk {{iLkReg}} (snocR ξ t) zero = t
lk {{iLkReg}} (snocR ξ t) (suc i) = lk {T} {Reg T} ξ i
iLkIdmReg : LkIdm T (Reg T)
lk-idm {{iLkIdmReg}} i = refl
iLkWkmReg : {{wkT : Wk T}} → LkWkm T (Reg T)
lk-wkm {{iLkWkmReg}} = lk-wkm {T} {Weaken`}
iLkUpReg : {{wkT : Wk T}} {{wkVrT : WkVr T}} → LkUp T (Reg T)
lk-↑₁-zero {{iLkUpReg}} ξ = refl
lk-↑₁-suc {{iLkUpReg}} (baseR ξ) i = sym (wk₁-vr {T} (lk {Ix} {Weaken`} ξ i))
lk-↑₁-suc {{iLkUpReg}} (snocR ξ t) zero = refl
lk-↑₁-suc {{iLkUpReg}} (snocR ξ t) (suc i) = lk-↑₁-suc {T} {Reg T} ξ i
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.499316473,
"avg_line_length": 33.25,
"ext": "agda",
"hexsha": "6f47f1b620ff51ee90036d43f1c9899959abc35d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Morph/Reg.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Morph/Reg.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Morph/Reg.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1408,
"size": 2926
} |
------------------------------------------------------------------------
-- Not
------------------------------------------------------------------------
module TotalParserCombinators.Not where
open import Axiom.Extensionality.Propositional
open import Data.Bool
open import Data.Empty
open import Data.List
open import Data.List.Membership.Propositional using (_∈_)
open import Data.List.Relation.Binary.BagAndSetEquality
using () renaming (_∼[_]_ to _List-∼[_]_)
open import Data.List.Relation.Unary.Any using (here; there)
open import Data.Product
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Unit
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (module Equivalence)
open import Function.Inverse as Inv using (_↔_)
open import Function.Related
import Function.Related.TypeIsomorphisms as Iso
open import Level
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import TotalParserCombinators.Congruence as C using (_∼[_]P_; _≅P_)
open import TotalParserCombinators.Derivative using (D)
open import TotalParserCombinators.Parser
import TotalParserCombinators.Pointwise as Pointwise
open import TotalParserCombinators.Semantics using (_∈_·_; parser)
------------------------------------------------------------------------
-- An initial bag operator
-- not-index xs is non-empty iff xs is empty.
not-index : {R : Set} → List R → List ⊤
not-index xs = if null xs then [ tt ] else []
-- not-index preserves equality.
not-index-cong : ∀ {k R} {xs xs′ : List R} →
xs List-∼[ ⌊ k ⌋⇔ ] xs′ →
not-index xs List-∼[ ⌊ k ⌋⇔ ] not-index xs′
not-index-cong {xs = [] } {xs′ = [] } eq = ↔⇒ Inv.id
not-index-cong {xs = _ ∷ _} {xs′ = _ ∷ _} eq = ↔⇒ Inv.id
not-index-cong {xs = [] } {xs′ = _ ∷ _} eq
with Equivalence.from (⇒⇔ eq) ⟨$⟩ here P.refl
... | ()
not-index-cong {xs = _ ∷ _} {xs′ = [] } eq
with Equivalence.to (⇒⇔ eq) ⟨$⟩ here P.refl
... | ()
-- not-index is correct, assuming that propositional equality is
-- extensional.
not-index-correct :
Extensionality zero zero →
∀ {R} (xs : List R) → tt ∈ not-index xs ↔ ∄ λ x → x ∈ xs
not-index-correct ext [] = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = from∘to
; right-inverse-of = to∘from
}
}
where
to : tt ∈ [ tt ] → ∄ λ x → x ∈ []
to _ (_ , ())
from : (∄ λ x → x ∈ []) → tt ∈ [ tt ]
from _ = here P.refl
to∘from : (p : ∄ λ x → x ∈ []) → to (from p) ≡ p
to∘from p = ext helper
where
helper : (∈[] : ∃ λ x → x ∈ []) → to (from p) ∈[] ≡ p ∈[]
helper (_ , ())
from∘to : (p : tt ∈ [ tt ]) → from (to p) ≡ p
from∘to (here P.refl) = P.refl
from∘to (there ())
not-index-correct ext (x ∷ xs) = record
{ to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = λ ()
; right-inverse-of = to∘from
}
}
where
ys = x ∷ xs
to : tt ∈ [] → ∄ λ y → y ∈ ys
to ()
from : (∄ λ y → y ∈ ys) → tt ∈ []
from y∉∷ with y∉∷ (-, here P.refl)
... | ()
to∘from : (p : ∄ λ y → y ∈ ys) → to (from p) ≡ p
to∘from y∉∷ with y∉∷ (-, here P.refl)
... | ()
------------------------------------------------------------------------
-- Not
-- ¬_ is defined as a pointwise lifting of not-index. Note that ¬_
-- preserves parser and language equality, but not the
-- sub-/superparser and sub-/superlanguage relations.
private
module Not {R : Set} =
Pointwise ⊥ R ⌊_⌋⇔ (const not-index) (const not-index-cong)
infix 60 ¬_ ¬-cong_
-- ¬ p returns a result if p doesn't.
¬_ : ∀ {Tok R xs} → Parser Tok R xs → Parser Tok ⊤ (not-index xs)
¬_ = Not.lift fail
-- D distributes over ¬_.
D-¬ : ∀ {Tok R xs t} (p : Parser Tok R xs) → D t (¬ p) ≅P ¬ D t p
D-¬ = Not.D-lift fail
-- ¬_ preserves equality.
¬-cong_ : ∀ {k Tok R xs xs′}
{p : Parser Tok R xs} {p′ : Parser Tok R xs′} →
p ∼[ ⌊ k ⌋⇔ ]P p′ → ¬ p ∼[ ⌊ k ⌋⇔ ]P ¬ p′
¬-cong_ = Not.lift-cong C.fail
-- ¬_ is correct (assuming that propositional equality is
-- extensional).
correct : (∀ {ℓ} → Extensionality ℓ zero) →
∀ {Tok R xs s} (p : Parser Tok R xs) →
tt ∈ ¬ p · s ↔ ∄ λ x → x ∈ p · s
correct ext =
Not.lift-property
(λ _ G H → H tt ↔ ∄ G)
(λ _ G↔G′ H↔H′ →
Iso.Related-cong
(H↔H′ tt)
(Iso.→-cong ext ext (Σ.cong Inv.id λ {x} → G↔G′ x) Inv.id))
(not-index-correct ext _)
fail
| {
"alphanum_fraction": 0.5490326885,
"avg_line_length": 29.3921568627,
"ext": "agda",
"hexsha": "a88e26b465942420f758e22fd15f7bc6fd082232",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Not.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Not.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Not.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 1517,
"size": 4497
} |
module Issue1039 where
open import Common.Level
Test : ∀ {a b} → Set a → Set (a ⊔ b) → Set a
Test X Y = X
test : Set (lsuc lzero)
test = Test Set (Set (lsuc lzero))
test₂ : ∀ {l} → Set (lsuc l)
test₂ {l} = Test (Set l) (Set (lsuc l))
| {
"alphanum_fraction": 0.5966386555,
"avg_line_length": 18.3076923077,
"ext": "agda",
"hexsha": "49642ba2b1386c611da65ddda94fd639e690bcd1",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1039.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1039.agda",
"max_line_length": 44,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1039.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 92,
"size": 238
} |
module Numeral.Natural.Function.Coprimalize where
open import Data.Tuple
open import Numeral.Natural
open import Numeral.Natural.Function.GreatestCommonDivisor
open import Numeral.Natural.Oper.FlooredDivision
coprimalize : (ℕ ⨯ ℕ) → (ℕ ⨯ ℕ)
coprimalize(x , y) = ((x ⌊/⌋₀ gcd(x)(y)) , (y ⌊/⌋₀ gcd(x)(y)))
{- TODO: Maybe prove something like (b ∣ a) → ((d ∣ (a / b)) ↔ ((d ∣ a) ∧ (d ∤ b))) if it holds?
open import Numeral.Natural.Coprime
open import Relator.Equals
Coprime-coprimalize : ∀{xy} → uncurry Coprime(coprimalize xy)
Coprime.proof Coprime-coprimalize nx ny = {!!} where
n ∣ (x ⌊/⌋₀ gcd(x)(y))
(n ∣ x) ∧ (n ∤ gcd(x)(y))
-}
| {
"alphanum_fraction": 0.6698113208,
"avg_line_length": 30.2857142857,
"ext": "agda",
"hexsha": "e19a4f30507d65b8cb0e19a6bb4c61c694e2b86a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Function/Coprimalize.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Function/Coprimalize.agda",
"max_line_length": 96,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Function/Coprimalize.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 249,
"size": 636
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of n-ary products
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Recursive.Properties where
open import Level using (Level)
open import Data.Nat.Base hiding (_^_)
open import Data.Product
open import Data.Vec.Recursive
open import Data.Vec.Base using (Vec; _∷_)
open import Function.Inverse using (_↔_; inverse)
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
private
variable
a : Level
A : Set a
------------------------------------------------------------------------
-- Basic proofs
cons-head-tail-identity : ∀ n (as : A ^ suc n) → cons n (head n as) (tail n as) ≡ as
cons-head-tail-identity 0 as = P.refl
cons-head-tail-identity (suc n) as = P.refl
head-cons-identity : ∀ n a (as : A ^ n) → head n (cons n a as) ≡ a
head-cons-identity 0 a as = P.refl
head-cons-identity (suc n) a as = P.refl
tail-cons-identity : ∀ n a (as : A ^ n) → tail n (cons n a as) ≡ as
tail-cons-identity 0 a as = P.refl
tail-cons-identity (suc n) a as = P.refl
append-cons-commute : ∀ m n a (xs : A ^ m) ys →
append (suc m) n (cons m a xs) ys ≡ cons (m + n) a (append m n xs ys)
append-cons-commute 0 n a xs ys = P.refl
append-cons-commute (suc m) n a xs ys = P.refl
append-splitAt-identity : ∀ m n (as : A ^ (m + n)) → uncurry (append m n) (splitAt m n as) ≡ as
append-splitAt-identity 0 n as = P.refl
append-splitAt-identity (suc m) n as = begin
let x = head (m + n) as in
let (xs , ys) = splitAt m n (tail (m + n) as) in
append (suc m) n (cons m (head (m + n) as) xs) ys
≡⟨ append-cons-commute m n x xs ys ⟩
cons (m + n) x (append m n xs ys)
≡⟨ P.cong (cons (m + n) x) (append-splitAt-identity m n (tail (m + n) as)) ⟩
cons (m + n) x (tail (m + n) as)
≡⟨ cons-head-tail-identity (m + n) as ⟩
as
∎
------------------------------------------------------------------------
-- Conversion to and from Vec
fromVec∘toVec : ∀ n (xs : A ^ n) → fromVec (toVec n xs) ≡ xs
fromVec∘toVec 0 _ = P.refl
fromVec∘toVec (suc n) xs = begin
cons n (head n xs) (fromVec (toVec n (tail n xs)))
≡⟨ P.cong (cons n (head n xs)) (fromVec∘toVec n (tail n xs)) ⟩
cons n (head n xs) (tail n xs)
≡⟨ cons-head-tail-identity n xs ⟩
xs ∎
toVec∘fromVec : ∀ {n} (xs : Vec A n) → toVec n (fromVec xs) ≡ xs
toVec∘fromVec Vec.[] = P.refl
toVec∘fromVec {n = suc n} (x Vec.∷ xs) = begin
head n (cons n x (fromVec xs)) Vec.∷ toVec n (tail n (cons n x (fromVec xs)))
≡⟨ P.cong₂ (λ x xs → x Vec.∷ toVec n xs) hd-prf tl-prf ⟩
x Vec.∷ toVec n (fromVec xs)
≡⟨ P.cong (x Vec.∷_) (toVec∘fromVec xs) ⟩
x Vec.∷ xs
∎ where
hd-prf = head-cons-identity _ x (fromVec xs)
tl-prf = tail-cons-identity _ x (fromVec xs)
↔Vec : ∀ n → A ^ n ↔ Vec A n
↔Vec n = inverse (toVec n) fromVec (fromVec∘toVec n) toVec∘fromVec
| {
"alphanum_fraction": 0.5487723955,
"avg_line_length": 35.0465116279,
"ext": "agda",
"hexsha": "f97c91ef43d6affb25e2a0e6d16cb6daa2a3b5e9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Vec/Recursive/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Vec/Recursive/Properties.agda",
"max_line_length": 95,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Vec/Recursive/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1061,
"size": 3014
} |
-- This is mostly based on the ``Dependently-typed Functional Programming''
-- lecture from Pierre-Evariste Dagand (17--18, MPRI).
-- ref: https://gitlab.inria.fr/fpottier/mpri-2.4-public/
module lambda.stlc where
open import Relation.Binary.PropositionalEquality
open import Function hiding (id)
open import Data.Product
open import Agda.Builtin.Unit
open import lambda.stack
infixr 50 _⇒_
data type : Set where
unit : type
_⇒_ : type → type → type
context : Set
context = stack type
data _⊢_ (Γ : context) : type → Set where
lam : ∀ {A B} → Γ ▸ A ⊢ B → Γ ⊢ A ⇒ B
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
app : ∀ {A B} → Γ ⊢ A ⇒ B → Γ ⊢ A → Γ ⊢ B
tt : Γ ⊢ unit
module norm where
infix 30 _⊢ⁿ_
infix 30 _⊢ᵉ_
infix 40 _⟶_
infix 45 _⟦⇒⟧_
infix 50 _⟦×⟧_
data _⊢ᵉ_ (Γ : context) : type → Set
data _⊢ⁿ_ (Γ : context) : type → Set
data _⊢ⁿ_ (Γ : context) where
lam : ∀ {A B} → Γ ▸ A ⊢ⁿ B → Γ ⊢ⁿ A ⇒ B
tt : Γ ⊢ⁿ unit
ground : Γ ⊢ᵉ unit → Γ ⊢ⁿ unit
data _⊢ᵉ_ (Γ : context) where
var : ∀ {A} → A ∈ Γ → Γ ⊢ᵉ A
app : ∀ {A B} → Γ ⊢ᵉ A ⇒ B → Γ ⊢ⁿ A → Γ ⊢ᵉ B
⌊_⌋ⁿ : ∀ {Γ A} → Γ ⊢ⁿ A → Γ ⊢ A
⌊_⌋ᵉ : ∀ {Γ A} → Γ ⊢ᵉ A → Γ ⊢ A
⌊ lam x ⌋ⁿ = lam ⌊ x ⌋ⁿ
⌊ tt ⌋ⁿ = tt
⌊ ground x ⌋ⁿ = ⌊ x ⌋ᵉ
⌊ var x ⌋ᵉ = var x
⌊ app x y ⌋ᵉ = app ⌊ x ⌋ᵉ ⌊ y ⌋ⁿ
record sem : Set₁ where
field
_⊢ : context → Set
ren : ∀ {Γ Δ} → Γ ⊇ Δ → Δ ⊢ → Γ ⊢
_⟶_ : (A B : sem) → Set
A ⟶ B = ∀ {Γ} → Γ ⊢A → Γ ⊢B
where open sem A renaming (_⊢ to _⊢A)
open sem B renaming (_⊢ to _⊢B)
renameⁿ : ∀ {Γ Δ T} → Γ ⊇ Δ → Δ ⊢ⁿ T → Γ ⊢ⁿ T
renameᵉ : ∀ {Γ Δ T} → Γ ⊇ Δ → Δ ⊢ᵉ T → Γ ⊢ᵉ T
renameⁿ wk (lam b) = lam (renameⁿ (keep wk) b)
renameⁿ wk (ground grnd) = ground (renameᵉ wk grnd)
renameⁿ wk tt = tt
renameᵉ wk (var v) = var (shift wk v)
renameᵉ wk (app f s) = app (renameᵉ wk f) (renameⁿ wk s)
renameⁿ-id : ∀ {Γ T} → (x : Γ ⊢ⁿ T) → renameⁿ id x ≡ x
renameᵉ-id : ∀ {Γ T} → (x : Γ ⊢ᵉ T) → renameᵉ id x ≡ x
renameⁿ-id (lam x) = cong lam (renameⁿ-id x)
renameⁿ-id tt = refl
renameⁿ-id (ground x) = cong ground (renameᵉ-id x)
renameᵉ-id (var x) = cong var (shift-id x)
renameᵉ-id (app x y) = cong₂ app (renameᵉ-id x) (renameⁿ-id y)
semⁿ : type → sem
semⁿ T = record {
_⊢ = λ Γ → Γ ⊢ⁿ T ;
ren = renameⁿ }
semᵉ : type → sem
semᵉ T = record {
_⊢ = λ Γ → Γ ⊢ᵉ T ;
ren = renameᵉ }
⟦unit⟧ : sem
⟦unit⟧ = semⁿ unit
⟦tt⟧ : ∀ {P} → P ⟶ ⟦unit⟧
⟦tt⟧ ρ = tt
_⟦⇒⟧_ : sem → sem → sem
P ⟦⇒⟧ Q = record {
_⊢ = λ Γ → ∀ {Δ} → Δ ⊇ Γ → Δ ⊢P → Δ ⊢Q ;
ren = λ wk₁ k wk₂ → k (wk₂ ∘⊇ wk₁) }
where open sem P renaming (_⊢ to _⊢P)
open sem Q renaming (_⊢ to _⊢Q)
_⟦×⟧_ : sem → sem → sem
P ⟦×⟧ Q = record { _⊢ = λ Γ → (Γ ⊢P) × (Γ ⊢Q)
; ren = λ { wk (x , y) → ( ren-P wk x , ren-Q wk y ) } }
where open sem P renaming (_⊢ to _⊢P ; ren to ren-P)
open sem Q renaming (_⊢ to _⊢Q ; ren to ren-Q)
⟦lam⟧ : ∀ {P Q R} → P ⟦×⟧ Q ⟶ R → P ⟶ Q ⟦⇒⟧ R
⟦lam⟧ {P} η p = λ wk q → η (ren-P wk p , q)
where open sem P renaming (ren to ren-P)
⟦app⟧ : ∀ {P Q R} → P ⟶ Q ⟦⇒⟧ R → P ⟶ Q → P ⟶ R
⟦app⟧ η μ = λ px → η px id (μ px)
⟦_⟧ : type → sem
⟦ unit ⟧ = ⟦unit⟧
⟦ S ⇒ T ⟧ = ⟦ S ⟧ ⟦⇒⟧ ⟦ T ⟧
⊤̂ : sem
⊤̂ = record { _⊢ = λ _ → ⊤
; ren = λ _ _ → tt }
⟦_⟧c : (Γ : context) → sem
⟦ ε ⟧c = ⊤̂
⟦ Γ ▸ T ⟧c = ⟦ Γ ⟧c ⟦×⟧ ⟦ T ⟧
_⟦⊢⟧_ : context → type → Set
Γ ⟦⊢⟧ T = ⟦ Γ ⟧c ⟶ ⟦ T ⟧
lookup : ∀ {Γ T} → T ∈ Γ → Γ ⟦⊢⟧ T
lookup here (_ , v) = v
lookup (there x) (γ , _) = lookup x γ
eval : ∀ {Γ T} → Γ ⊢ T → Γ ⟦⊢⟧ T
eval {Γ} {A ⇒ B} (lam x) = ⟦lam⟧ {⟦ Γ ⟧c} {⟦ A ⟧} {⟦ B ⟧} (eval x)
eval (var x) = lookup x
eval {Γ} {B} (app {A} x y) = ⟦app⟧ {⟦ Γ ⟧c} {⟦ A ⟧} {⟦ B ⟧} (eval x) (eval y)
eval {Γ} tt = ⟦tt⟧ {⟦ Γ ⟧c}
[_]⊢_ : context → type → Set
[ Γ ]⊢ T = Γ ⊢⟦T⟧
where open sem ⟦ T ⟧ renaming (_⊢ to _⊢⟦T⟧)
[_]⊢c_ : context → context → Set
[ Γ ]⊢c Δ = Γ ⊢⟦Δ⟧c
where open sem ⟦ Δ ⟧c renaming (_⊢ to _⊢⟦Δ⟧c)
reify : ∀ {T Γ} → [ Γ ]⊢ T → Γ ⊢ⁿ T
reflect : ∀ {Γ} → (T : type) → Γ ⊢ᵉ T → [ Γ ]⊢ T
reify {unit} v = v
reify {A ⇒ B} x = lam (reify (x (skip id) (reflect A (var here))))
reflect unit x = ground x
reflect (A ⇒ B) x = λ w s → reflect B (app (ren w x) (reify s))
where open sem (semᵉ (A ⇒ B))
reify-id : ∀ {Γ T} → Γ ⟦⊢⟧ T → Γ ⊢ⁿ T
reify-id {Γ} x = reify (x (id-c Γ))
where
open sem
id-c : ∀ Γ → [ Γ ]⊢c Γ
id-c ε = tt
id-c (Γ ▸ T) = ren ⟦ Γ ⟧c (skip id) (id-c Γ) , reflect T (var here)
norm : ∀ {Γ T} → Γ ⊢ T → Γ ⊢ⁿ T
norm = reify-id ∘ eval
| {
"alphanum_fraction": 0.4724919094,
"avg_line_length": 25.0540540541,
"ext": "agda",
"hexsha": "b04210264d5275597a4b2ab07e4001c304e3d7d1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Lapin0t/lambda",
"max_forks_repo_path": "lambda/stlc.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "Lapin0t/lambda",
"max_issues_repo_path": "lambda/stlc.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09a231d9b3057d57b864070188ed9fe14a07eda2",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "Lapin0t/lambda",
"max_stars_repo_path": "lambda/stlc.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2404,
"size": 4635
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Bicategory.Bigroupoid where
open import Level
open import Function using (_$_)
open import Data.Product using (Σ; _,_)
open import Categories.Category
open import Categories.Category.Equivalence using (WeakInverse)
open import Categories.Category.Product
open import Categories.Category.Groupoid using (IsGroupoid)
open import Categories.Bicategory
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Properties
open import Categories.Functor.Bifunctor.Properties
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_; NaturalIsomorphism)
import Categories.Morphism as Mor
import Categories.Morphism.Properties as MP
import Categories.Morphism.Reasoning as MR
-- https://link.springer.com/article/10.1023/A:1011270417127
record IsBigroupoid {o ℓ e t} (C : Bicategory o ℓ e t) : Set (o ⊔ ℓ ⊔ e ⊔ t) where
open Bicategory C public
field
hom-isGroupoid : ∀ A B → IsGroupoid (hom A B)
hom[_,_]⁻¹ : ∀ A B → Functor (hom A B) (hom B A)
cancel : ∀ A B → ⊚ ∘F (hom[ A , B ]⁻¹ ※ idF) ≃ const id₁
cancel′ : ∀ A B → ⊚ ∘F (idF ※ hom[ A , B ]⁻¹) ≃ const id₁
module hom⁻¹ {A B} = Functor (hom[ A , B ]⁻¹)
module cancel {A B} = NaturalIsomorphism (cancel A B)
module cancel′ {A B} = NaturalIsomorphism (cancel′ A B)
infix 13 _⁻¹ _⁻¹′
_⁻¹ : ∀ {A B} → A ⇒₁ B → B ⇒₁ A
_⁻¹ = hom⁻¹.F₀
_⁻¹′ : ∀ {A B} {f g : A ⇒₁ B} → f ⇒₂ g → f ⁻¹ ⇒₂ g ⁻¹
_⁻¹′ = hom⁻¹.F₁
open hom.Commutation
field
pentagon₁ : ∀ {A B} {f : A ⇒₁ B} →
[ (f ∘ₕ f ⁻¹) ∘ₕ f ⇒ f ]⟨
associator.from ⇒⟨ f ∘ₕ f ⁻¹ ∘ₕ f ⟩
f ▷ cancel.⇒.η f ⇒⟨ f ∘ₕ id₁ ⟩
unitorʳ.from
≈ cancel′.⇒.η f ◁ f ⇒⟨ id₁ ∘ₕ f ⟩
unitorˡ.from
⟩
pentagon₂ : ∀ {A B} {f : A ⇒₁ B} →
[ (f ⁻¹ ∘ₕ f) ∘ₕ f ⁻¹ ⇒ f ⁻¹ ]⟨
associator.from ⇒⟨ f ⁻¹ ∘ₕ f ∘ₕ f ⁻¹ ⟩
f ⁻¹ ▷ cancel′.⇒.η f ⇒⟨ f ⁻¹ ∘ₕ id₁ ⟩
unitorʳ.from
≈ cancel.⇒.η f ◁ f ⁻¹ ⇒⟨ id₁ ∘ₕ f ⁻¹ ⟩
unitorˡ.from
⟩
private
variable
A B : Obj
f g : A ⇒₁ B
α β : f ⇒₂ g
open hom.HomReasoning
module MR′ {A B} where
open MR (hom A B) public
open Mor (hom A B) public
open MP (hom A B) public
open MR′
module ℱ = Functor
cancel-comm : ∀ {α : f ⇒₂ g} → cancel.⇒.η g ∘ᵥ (α ⁻¹′ ⊚₁ α) ≈ cancel.⇒.η f
cancel-comm {α = α} = cancel.⇒.commute α ○ identity₂ˡ
cancel⁻¹-comm : ∀ {α : f ⇒₂ g} → (α ⁻¹′ ⊚₁ α) ∘ᵥ cancel.⇐.η f ≈ cancel.⇐.η g
cancel⁻¹-comm {α = α} = ⟺ (cancel.⇐.commute α) ○ identity₂ʳ
cancel′-comm : ∀ {α : f ⇒₂ g} → cancel′.⇒.η g ∘ᵥ (α ⊚₁ α ⁻¹′) ≈ cancel′.⇒.η f
cancel′-comm {α = α} = cancel′.⇒.commute α ○ identity₂ˡ
cancel′⁻¹-comm : ∀ {α : f ⇒₂ g} → (α ⊚₁ α ⁻¹′) ∘ᵥ cancel′.⇐.η f ≈ cancel′.⇐.η g
cancel′⁻¹-comm {α = α} = ⟺ (cancel′.⇐.commute α) ○ identity₂ʳ
hom⁻¹⁻¹≃id : ∀ {A B} → hom[ B , A ]⁻¹ ∘F hom[ A , B ]⁻¹ ≃ idF
hom⁻¹⁻¹≃id {A} {B} = record
{ F⇒G = ntHelper record
{ η = λ f → (((unitorˡ.from ∘ᵥ cancel.⇒.η (f ⁻¹) ◁ f) ∘ᵥ associator.to) ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
; commute = λ {f g} α → begin
((((unitorˡ.from ∘ᵥ cancel.⇒.η (g ⁻¹) ◁ g) ∘ᵥ associator.to) ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇐.η g) ∘ᵥ unitorʳ.to) ∘ᵥ α ⁻¹′ ⁻¹′
≈˘⟨ pushʳ ◁-∘ᵥ-λ⁻¹ ⟩
(((unitorˡ.from ∘ᵥ cancel.⇒.η (g ⁻¹) ◁ g) ∘ᵥ associator.to) ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇐.η g) ∘ᵥ ((α ⁻¹′ ⁻¹′ ◁ id₁) ∘ᵥ unitorʳ.to)
≈⟨ center ◁-▷-exchg ⟩
((unitorˡ.from ∘ᵥ cancel.⇒.η (g ⁻¹) ◁ g) ∘ᵥ associator.to) ∘ᵥ (α ⁻¹′ ⁻¹′ ◁ (g ⁻¹ ∘ₕ g) ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η g) ∘ᵥ unitorʳ.to
≈⟨ center (⟺ assoc₂ ○ hom.∘-resp-≈ assoc⁻¹-◁-∘ₕ (ℱ.F-resp-≈ ((f ⁻¹ ⁻¹) ⊚-) (⟺ cancel⁻¹-comm))) ⟩
(unitorˡ.from ∘ᵥ cancel.⇒.η (g ⁻¹) ◁ g) ∘ᵥ ((α ⁻¹′ ⁻¹′ ◁ g ⁻¹ ◁ g ∘ᵥ associator.to) ∘ᵥ f ⁻¹ ⁻¹ ▷ ((α ⁻¹′ ⊚₁ α) ∘ᵥ cancel.⇐.η f)) ∘ᵥ unitorʳ.to
≈⟨ refl ⟩∘⟨ (hom.∘-resp-≈ʳ (ℱ.homomorphism ((f ⁻¹ ⁻¹) ⊚-)) ○ center (⊚-assoc.⇐.commute _) ○ center⁻¹ ([ ⊚ ]-merge (⟺ [ ⊚ ]-decompose₁) identity₂ˡ) refl) ⟩∘⟨ refl ⟩
(unitorˡ.from ∘ᵥ cancel.⇒.η (g ⁻¹) ◁ g) ∘ᵥ (((α ⁻¹′ ⁻¹′ ⊚₁ α ⁻¹′) ⊚₁ α) ∘ᵥ associator.to ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
≈˘⟨ assoc₂ ⟩
((unitorˡ.from ∘ᵥ cancel.⇒.η (g ⁻¹) ◁ g) ∘ᵥ (((α ⁻¹′ ⁻¹′ ⊚₁ α ⁻¹′) ⊚₁ α) ∘ᵥ associator.to ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f)) ∘ᵥ unitorʳ.to
≈⟨ center ([ ⊚ ]-merge cancel-comm identity₂ˡ) ⟩∘⟨refl ⟩
(unitorˡ.from ∘ᵥ cancel.⇒.η (f ⁻¹) ⊚₁ α ∘ᵥ associator.to ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
≈˘⟨ (assoc₂ ○ assoc₂) ⟩∘⟨refl ⟩
(((unitorˡ.from ∘ᵥ cancel.⇒.η (f ⁻¹) ⊚₁ α) ∘ᵥ associator.to) ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
≈⟨ (hom.∘-resp-≈ʳ [ ⊚ ]-decompose₂) ⟩∘⟨refl ⟩∘⟨refl ⟩∘⟨refl ⟩
(((unitorˡ.from ∘ᵥ id₁ ▷ α ∘ᵥ cancel.⇒.η (f ⁻¹) ◁ f) ∘ᵥ associator.to) ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
≈⟨ pullˡ ρ-∘ᵥ-▷ ⟩∘⟨refl ⟩∘⟨refl ⟩∘⟨refl ⟩
((((α ∘ᵥ unitorˡ.from) ∘ᵥ cancel.⇒.η (f ⁻¹) ◁ f) ∘ᵥ associator.to) ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
≈⟨ (assoc₂ ○ assoc₂ ○ assoc₂ ○ assoc₂) ⟩
α ∘ᵥ unitorˡ.from ∘ᵥ cancel.⇒.η (f ⁻¹) ◁ f ∘ᵥ associator.to ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f ∘ᵥ unitorʳ.to
≈˘⟨ refl⟩∘⟨ (assoc₂ ○ assoc₂ ○ assoc₂) ⟩
α ∘ᵥ (((unitorˡ.from ∘ᵥ cancel.⇒.η (f ⁻¹) ◁ f) ∘ᵥ associator.to) ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇐.η f) ∘ᵥ unitorʳ.to
∎
}
; F⇐G = ntHelper record
{ η = λ f → unitorʳ.from ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇒.η f ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (f ⁻¹) ◁ f ∘ᵥ unitorˡ.to
; commute = λ {f g} α → begin
(unitorʳ.from ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇒.η g ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (g ⁻¹) ◁ g ∘ᵥ unitorˡ.to) ∘ᵥ α
≈⟨ assoc₂ ○ hom.∘-resp-≈ʳ (assoc₂ ○ hom.∘-resp-≈ʳ (assoc₂ ○ hom.∘-resp-≈ʳ assoc₂)) ⟩
unitorʳ.from ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇒.η g ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (g ⁻¹) ◁ g ∘ᵥ unitorˡ.to ∘ᵥ α
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ ⟺ ▷-∘ᵥ-ρ⁻¹ ⟩
unitorʳ.from ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇒.η g ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (g ⁻¹) ◁ g ∘ᵥ id₁ ▷ α ∘ᵥ unitorˡ.to
≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ pullˡ (⟺ [ ⊚ ]-decompose₁ ○ ⊚.F-resp-≈ (⟺ cancel⁻¹-comm , refl)) ⟩
unitorʳ.from ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇒.η g ∘ᵥ associator.from ∘ᵥ (α ⁻¹′ ⁻¹′ ⊚₁ α ⁻¹′ ∘ᵥ cancel.⇐.η (f ⁻¹)) ⊚₁ α ∘ᵥ unitorˡ.to
≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ hom.∘-resp-≈ˡ ([ ⊚ ]-merge refl identity₂ʳ) ⟩
unitorʳ.from ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇒.η g ∘ᵥ associator.from ∘ᵥ ((α ⁻¹′ ⁻¹′ ⊚₁ α ⁻¹′) ⊚₁ α ∘ᵥ cancel.⇐.η (f ⁻¹) ◁ f) ∘ᵥ unitorˡ.to
≈⟨ refl⟩∘⟨ refl⟩∘⟨ center⁻¹ (⊚-assoc.⇒.commute _) refl ⟩
unitorʳ.from ∘ᵥ g ⁻¹ ⁻¹ ▷ cancel.⇒.η g ∘ᵥ (α ⁻¹′ ⁻¹′ ⊚₁ α ⁻¹′ ⊚₁ α ∘ᵥ associator.from) ∘ᵥ cancel.⇐.η (f ⁻¹) ◁ f ∘ᵥ unitorˡ.to
≈⟨ refl⟩∘⟨ (hom.∘-resp-≈ʳ assoc₂ ○ pullˡ ([ ⊚ ]-merge identity₂ˡ cancel-comm)) ⟩
unitorʳ.from ∘ᵥ (α ⁻¹′ ⁻¹′) ⊚₁ (cancel.⇒.η f) ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (f ⁻¹) ◁ f ∘ᵥ unitorˡ.to
≈⟨ refl⟩∘⟨ (hom.∘-resp-≈ˡ [ ⊚ ]-decompose₁ ○ assoc₂) ⟩
unitorʳ.from ∘ᵥ (α ⁻¹′ ⁻¹′) ◁ id₁ ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇒.η f ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (f ⁻¹) ◁ f ∘ᵥ unitorˡ.to
≈⟨ (pullˡ λ-∘ᵥ-◁) ○ assoc₂ ⟩
α ⁻¹′ ⁻¹′ ∘ᵥ unitorʳ.from ∘ᵥ f ⁻¹ ⁻¹ ▷ cancel.⇒.η f ∘ᵥ associator.from ∘ᵥ cancel.⇐.η (f ⁻¹) ◁ f ∘ᵥ unitorˡ.to
∎
}
; iso = λ f → Iso-∘ (Iso-swap (unitʳ.iso _)) $
Iso-∘ ([ (f ⁻¹ ⁻¹) ⊚- ]-resp-Iso (Iso-swap (cancel.iso f))) $
Iso-∘ (Iso-swap associator.iso) $
Iso-∘ ([ -⊚ f ]-resp-Iso (cancel.iso _))
(unitˡ.iso _)
}
hom⁻¹-weakInverse : ∀ {A B} → WeakInverse hom[ A , B ]⁻¹ hom[ B , A ]⁻¹
hom⁻¹-weakInverse = record { F∘G≈id = hom⁻¹⁻¹≃id ; G∘F≈id = hom⁻¹⁻¹≃id }
module hom⁻¹-weakInverse {A B} = WeakInverse (hom⁻¹-weakInverse {A} {B})
open hom⁻¹-weakInverse using () renaming (F⊣G to hom⁻¹-⊣Equivalence) public
-- A bigroupoid is a bicategory that has a bigroupoid structure
record Bigroupoid (o ℓ e t : Level) : Set (suc (o ⊔ ℓ ⊔ e ⊔ t)) where
field
bicategory : Bicategory o ℓ e t
isBigroupoid : IsBigroupoid bicategory
open IsBigroupoid isBigroupoid public
| {
"alphanum_fraction": 0.51940545,
"avg_line_length": 50.7604790419,
"ext": "agda",
"hexsha": "680ac4c0eabc30f07bc9c6bb250017a9be5b02d0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Bicategory/Bigroupoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Bicategory/Bigroupoid.agda",
"max_line_length": 173,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Bicategory/Bigroupoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4490,
"size": 8477
} |
{-# OPTIONS --guardedness #-}
module Cubical.Codata.Stream where
open import Cubical.Codata.Stream.Base public
open import Cubical.Codata.Stream.Properties public
| {
"alphanum_fraction": 0.7951807229,
"avg_line_length": 20.75,
"ext": "agda",
"hexsha": "45011fd3125f5b8bec593dfc80b88b312060888f",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Codata/Stream.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Codata/Stream.agda",
"max_line_length": 51,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Codata/Stream.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 34,
"size": 166
} |
module Issue217 where
record A : Set where
⊥ : Set
⊥ = ⊥
| {
"alphanum_fraction": 0.5873015873,
"avg_line_length": 9,
"ext": "agda",
"hexsha": "98cc557ff0c42ef26b6efd903365b6271238cef0",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue217.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue217.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue217.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 25,
"size": 63
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Instance.01-Truncation where
-- The adjunction between (0,1)-truncation and the inclusion functor
-- from Posets to Categories.
open import Data.Product using (_,_)
import Function
open import Relation.Binary using (Poset)
open import Relation.Binary.OrderMorphism using (_⇒-Poset_)
open import Categories.Adjoint using (_⊣_)
open import Categories.Category.Construction.Thin using (Thin)
open import Categories.Category using (Category)
open import Categories.Category.Instance.Cats using (Cats)
open import Categories.Category.Instance.Posets using (Posets)
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Instance.01-Truncation using (Trunc)
open import Categories.NaturalTransformation
using (NaturalTransformation; ntHelper)
open import Categories.NaturalTransformation.NaturalIsomorphism using (refl)
open _⇒-Poset_
-- The inclusion functor from Posets to Categories
Inclusion : ∀ {c ℓ₁ ℓ₂} e → Functor (Posets c ℓ₁ ℓ₂) (Cats c ℓ₂ e)
Inclusion {c} {ℓ₁} e = record
{ F₀ = Thin e
; F₁ = λ f → record { F₀ = fun f ; F₁ = monotone f }
; identity = refl
; homomorphism = refl
; F-resp-≈ = λ {A B f g} f≗g →
let open Poset B
in record
{ F⇒G = record { η = λ _ → reflexive f≗g }
; F⇐G = record { η = λ _ → reflexive (Eq.sym f≗g) }
}
}
-- Trunc is left-adjoint to the inclusion functor from Setoids to Groupoids
TruncAdj : ∀ {o ℓ e} → Trunc ⊣ Inclusion {o} {ℓ} e
TruncAdj {o} {ℓ} {e} = record
{ unit = unit
; counit = counit
; zig = λ {C} → id C , id C
; zag = refl
}
where
open Category
unit : NaturalTransformation idF (Inclusion e ∘F Trunc)
unit = record
{ η = λ _ → record { F₀ = Function.id ; F₁ = Function.id }
; commute = λ _ → refl
; sym-commute = λ _ → refl
}
counit : NaturalTransformation (Trunc ∘F Inclusion e) idF
counit = ntHelper record
{ η = λ _ → record { fun = Function.id ; monotone = Function.id }
; commute = λ {_ D} _ → Poset.Eq.refl D
}
| {
"alphanum_fraction": 0.6557530402,
"avg_line_length": 32.3939393939,
"ext": "agda",
"hexsha": "b0b1bf1f6ef849ac42e48537a8163a2872c19b12",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Instance/01-Truncation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Instance/01-Truncation.agda",
"max_line_length": 77,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Instance/01-Truncation.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 651,
"size": 2138
} |
module SystemF.BigStep.Extrinsic.Welltyped where
open import Prelude
open import SystemF.BigStep.Types
open import SystemF.BigStep.Extrinsic.Terms
open import Data.List
open import Extensions.List
-- welltyped terms
data _⊢_∶_ {n}(Γ : Ctx n) : Term → Type n → Set where
unit : -------------------
Γ ⊢ unit ∶ Unit
ƛ : ∀ {b t} a →
(a ∷ Γ) ⊢ t ∶ b →
-------------------
Γ ⊢ ƛ t ∶ (a ⇒ b)
var : ∀ {a i} →
Γ [ i ]= a →
-------------
Γ ⊢ var i ∶ a
_·_ : ∀ {f e a b} →
Γ ⊢ f ∶ (a ⇒ b) →
Γ ⊢ e ∶ a →
---------------
Γ ⊢ f · e ∶ b
Λ : ∀ {a t} →
(Γ ctx/ wk) ⊢ t ∶ a →
---------------------
Γ ⊢ Λ t ∶ ∀' a
_[_] : ∀ {f a} →
Γ ⊢ f ∶ (∀' a) →
(b : Type n) →
---------------------------
Γ ⊢ f [-] ∶ (a / (sub b))
| {
"alphanum_fraction": 0.3679131484,
"avg_line_length": 20.2195121951,
"ext": "agda",
"hexsha": "75963b43999e77142e6d0d363f7914e91ccdf264",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/SystemF/BigStep/Extrinsic/Welltyped.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/SystemF/BigStep/Extrinsic/Welltyped.agda",
"max_line_length": 53,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/SystemF/BigStep/Extrinsic/Welltyped.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 320,
"size": 829
} |
module AocVec where
open import Data.Vec as Vec
open import Data.Nat
addToBack : {A : Set} → {N : ℕ} → A → Vec A N → Vec A (suc N)
addToBack v [] = v ∷ []
addToBack v (x ∷ vs) = x ∷ addToBack v vs
dupFrontToBack : {A : Set} → {N : ℕ} → Vec A (suc N) → Vec A (suc (suc N))
dupFrontToBack (x ∷ vs) = addToBack x (x ∷ vs)
dupFirstNToBack : {A : Set} → {M : ℕ} → (N : ℕ) → Vec A (suc M) → Vec A (N + (suc M))
dupFirstNToBack zero vs = vs
dupFirstNToBack (suc N) (x ∷ vs) = x ∷ dupFirstNToBack N (addToBack x vs) | {
"alphanum_fraction": 0.5980392157,
"avg_line_length": 36.4285714286,
"ext": "agda",
"hexsha": "c274b720a47c75b50b51ab6a1a36deff54a147ef",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/adventofcode2017",
"max_forks_repo_path": "lib/AocVec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/adventofcode2017",
"max_issues_repo_path": "lib/AocVec.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/adventofcode2017",
"max_stars_repo_path": "lib/AocVec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 214,
"size": 510
} |
module _ where
open import Agda.Primitive
open import Agda.Builtin.Equality
data Wrap {a} (A : Set a) : Set a where
wrap : A → Wrap A
data Unit (A : Set) : Set where
unit : Unit A
record Functor {a b} (F : Set a → Set b) : Set (lsuc (a ⊔ b)) where
field
fmap : ∀ {A B} → (A → B) → F A → F B
open Functor ⦃ ... ⦄
instance
FunWrap : ∀ {a} → Functor {a} Wrap
FunWrap .fmap f (wrap x) = wrap (f x)
FunUnit : Functor Unit
FunUnit .fmap f unit = unit
_=$=_ : ∀ {a b} {A B : Set a} {F : Set a → Set b} {{_ : Functor F}} {x y : F A}
(f : A → B) → x ≡ y → fmap f x ≡ fmap f y
f =$= refl = refl
postulate A : Set
wrap-refl : (x : A) → wrap x ≡ wrap x
wrap-refl x = refl
prf : (x : Wrap A) → wrap x ≡ wrap x
prf (wrap x) = wrap =$= wrap-refl x
-- Incomplete pattern matching when applying FunUnit
-- (Internal error at Reduce.Fast:1347)
| {
"alphanum_fraction": 0.5750577367,
"avg_line_length": 22.2051282051,
"ext": "agda",
"hexsha": "5d91c2dff8990e3c50d97eafe129443eb204e36a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3870.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3870.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3870.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 327,
"size": 866
} |
module _ {A : Set} where
postulate B : Set
postulate
H : {A : Set} → Set
test-H : Set
test-H = H {A = B}
record R {A : Set} : Set where
constructor rc
field f : A
test-R : Set
test-R = R {A = B}
test-f : ∀ B → R {A = B} → B
test-f B = R.f {A = B}
module N {A : Set} where
module test-N = N {A = B}
| {
"alphanum_fraction": 0.5335463259,
"avg_line_length": 12.52,
"ext": "agda",
"hexsha": "eb13af962a345c3fb3410f985904c27da5d8403a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue2018b.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2018b.agda",
"max_line_length": 30,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2018b.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 124,
"size": 313
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to Any
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.Any.Properties where
open import Category.Monad
open import Data.Bool.Base using (Bool; false; true; T)
open import Data.Bool.Properties
open import Data.Empty using (⊥)
open import Data.Fin using (Fin) renaming (zero to fzero; suc to fsuc)
open import Data.List as List
open import Data.List.Categorical using (monad)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties.Core
using (Any↔; find∘map; map∘find; lose∘find)
open import Data.List.Relation.Binary.Pointwise
using (Pointwise; []; _∷_)
open import Data.Nat using (zero; suc; _<_; z≤n; s≤s)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Maybe.Relation.Unary.Any as MAny using (just)
open import Data.Product as Prod
using (_×_; _,_; ∃; ∃₂; proj₁; proj₂; uncurry′)
open import Data.Product.Properties
open import Data.Product.Function.NonDependent.Propositional
using (_×-cong_)
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Sum as Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; equivalence; Equivalence)
open import Function.Inverse as Inv using (_↔_; inverse; Inverse)
open import Function.Related as Related using (Related; SK-sym)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; inspect)
open import Relation.Unary
using (Pred; _⟨×⟩_; _⟨→⟩_) renaming (_⊆_ to _⋐_)
open import Relation.Nullary using (¬_)
open Related.EquationalReasoning
private
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
------------------------------------------------------------------------
-- Equality properties
module _ {a p ℓ} {A : Set a} {P : A → Set p} {_≈_ : Rel A ℓ} where
lift-resp : P Respects _≈_ → (Any P) Respects (Pointwise _≈_)
lift-resp resp [] ()
lift-resp resp (x≈y ∷ xs≈ys) (here px) = here (resp x≈y px)
lift-resp resp (x≈y ∷ xs≈ys) (there pxs) =
there (lift-resp resp xs≈ys pxs)
module _ {a p} {A : Set a} {P : A → Set p} where
here-injective : ∀ {x xs} {p q : P x} →
here {P = P} {xs = xs} p ≡ here q → p ≡ q
here-injective refl = refl
there-injective : ∀ {x xs} {p q : Any P xs} →
there {x = x} p ≡ there q → p ≡ q
there-injective refl = refl
------------------------------------------------------------------------
-- Misc
module _ {a p} {A : Set a} {P : A → Set p} where
¬Any[] : ¬ Any P []
¬Any[] ()
------------------------------------------------------------------------
-- Any is a congruence
module _ {a k p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
Any-cong : ∀ {xs ys : List A} →
(∀ x → Related k (P x) (Q x)) →
Preorder._∼_ (Related.InducedPreorder₂ k {A = A} _∈_) xs ys →
Related k (Any P xs) (Any Q ys)
Any-cong {xs} {ys} P↔Q xs≈ys =
Any P xs ↔⟨ SK-sym Any↔ ⟩
(∃ λ x → x ∈ xs × P x) ∼⟨ Σ.cong Inv.id (xs≈ys ×-cong P↔Q _) ⟩
(∃ λ x → x ∈ ys × Q x) ↔⟨ Any↔ ⟩
Any Q ys ∎
------------------------------------------------------------------------
-- map
map-id : ∀ {a p} {A : Set a} {P : A → Set p} (f : P ⋐ P) {xs} →
(∀ {x} (p : P x) → f p ≡ p) →
(p : Any P xs) → Any.map f p ≡ p
map-id f hyp (here p) = P.cong here (hyp p)
map-id f hyp (there p) = P.cong there $ map-id f hyp p
map-∘ : ∀ {a p q r}
{A : Set a} {P : A → Set p} {Q : A → Set q} {R : A → Set r}
(f : Q ⋐ R) (g : P ⋐ Q)
{xs} (p : Any P xs) →
Any.map (f ∘ g) p ≡ Any.map f (Any.map g p)
map-∘ f g (here p) = refl
map-∘ f g (there p) = P.cong there $ map-∘ f g p
------------------------------------------------------------------------
-- Swapping
-- Nested occurrences of Any can sometimes be swapped. See also ×↔.
swap : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : A → B → Set ℓ} {xs ys} →
Any (λ x → Any (P x) ys) xs → Any (λ y → Any (flip P y) xs) ys
swap (here pys) = Any.map here pys
swap (there pxys) = Any.map there (swap pxys)
swap-there : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : A → B → Set ℓ}
{x xs ys} → (any : Any (λ x → Any (P x) ys) xs) →
swap (Any.map (there {x = x}) any) ≡ there (swap any)
swap-there (here pys) = refl
swap-there (there pxys) = P.cong (Any.map there) (swap-there pxys)
swap-invol : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : A → B → Set ℓ}
{xs ys} → (any : Any (λ x → Any (P x) ys) xs) →
swap (swap any) ≡ any
swap-invol (here (here px)) = refl
swap-invol (here (there pys)) =
P.cong (Any.map there) (swap-invol (here pys))
swap-invol (there pxys) =
P.trans (swap-there (swap pxys)) (P.cong there (swap-invol pxys))
swap↔ : ∀ {ℓ} {A B : Set ℓ} {P : A → B → Set ℓ} {xs ys} →
Any (λ x → Any (P x) ys) xs ↔ Any (λ y → Any (flip P y) xs) ys
swap↔ {P = P} = inverse swap swap swap-invol swap-invol
------------------------------------------------------------------------
-- Lemmas relating Any to ⊥
⊥↔Any⊥ : ∀ {a} {A : Set a} {xs : List A} → ⊥ ↔ Any (const ⊥) xs
⊥↔Any⊥ {A = A} = inverse (λ()) (λ p → from p) (λ()) (λ p → from p)
where
from : {xs : List A} → Any (const ⊥) xs → ∀ {b} {B : Set b} → B
from (here ())
from (there p) = from p
⊥↔Any[] : ∀ {a p} {A : Set a} {P : A → Set p} → ⊥ ↔ Any P []
⊥↔Any[] = inverse (λ()) (λ()) (λ()) (λ())
------------------------------------------------------------------------
-- Lemmas relating Any to ⊤
-- These introduction and elimination rules are not inverses, though.
module _ {a} {A : Set a} where
any⁺ : ∀ (p : A → Bool) {xs} → Any (T ∘ p) xs → T (any p xs)
any⁺ p (here px) = Equivalence.from T-∨ ⟨$⟩ inj₁ px
any⁺ p (there {x = x} pxs) with p x
... | true = _
... | false = any⁺ p pxs
any⁻ : ∀ (p : A → Bool) xs → T (any p xs) → Any (T ∘ p) xs
any⁻ p [] ()
any⁻ p (x ∷ xs) px∷xs with p x | inspect p x
any⁻ p (x ∷ xs) px∷xs | true | P.[ eq ] = here (Equivalence.from T-≡ ⟨$⟩ eq)
any⁻ p (x ∷ xs) px∷xs | false | _ = there (any⁻ p xs px∷xs)
any⇔ : ∀ {p : A → Bool} {xs} → Any (T ∘ p) xs ⇔ T (any p xs)
any⇔ = equivalence (any⁺ _) (any⁻ _ _)
------------------------------------------------------------------------
-- Sums commute with Any
module _ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} where
Any-⊎⁺ : ∀ {xs} → Any P xs ⊎ Any Q xs → Any (λ x → P x ⊎ Q x) xs
Any-⊎⁺ = [ Any.map inj₁ , Any.map inj₂ ]′
Any-⊎⁻ : ∀ {xs} → Any (λ x → P x ⊎ Q x) xs → Any P xs ⊎ Any Q xs
Any-⊎⁻ (here (inj₁ p)) = inj₁ (here p)
Any-⊎⁻ (here (inj₂ q)) = inj₂ (here q)
Any-⊎⁻ (there p) = Sum.map there there (Any-⊎⁻ p)
⊎↔ : ∀ {xs} → (Any P xs ⊎ Any Q xs) ↔ Any (λ x → P x ⊎ Q x) xs
⊎↔ = inverse Any-⊎⁺ Any-⊎⁻ from∘to to∘from
where
from∘to : ∀ {xs} (p : Any P xs ⊎ Any Q xs) → Any-⊎⁻ (Any-⊎⁺ p) ≡ p
from∘to (inj₁ (here p)) = refl
from∘to (inj₁ (there p)) rewrite from∘to (inj₁ p) = refl
from∘to (inj₂ (here q)) = refl
from∘to (inj₂ (there q)) rewrite from∘to (inj₂ q) = refl
to∘from : ∀ {xs} (p : Any (λ x → P x ⊎ Q x) xs) →
Any-⊎⁺ (Any-⊎⁻ p) ≡ p
to∘from (here (inj₁ p)) = refl
to∘from (here (inj₂ q)) = refl
to∘from (there p) with Any-⊎⁻ p | to∘from p
to∘from (there .(Any.map inj₁ p)) | inj₁ p | refl = refl
to∘from (there .(Any.map inj₂ q)) | inj₂ q | refl = refl
------------------------------------------------------------------------
-- Products "commute" with Any.
module _ {a b p q} {A : Set a} {B : Set b}
{P : Pred A p} {Q : Pred B q} where
Any-×⁺ : ∀ {xs ys} → Any P xs × Any Q ys →
Any (λ x → Any (λ y → P x × Q y) ys) xs
Any-×⁺ (p , q) = Any.map (λ p → Any.map (λ q → (p , q)) q) p
Any-×⁻ : ∀ {xs ys} → Any (λ x → Any (λ y → P x × Q y) ys) xs →
Any P xs × Any Q ys
Any-×⁻ pq with Prod.map id (Prod.map id find) (find pq)
... | (x , x∈xs , y , y∈ys , p , q) = (lose x∈xs p , lose y∈ys q)
×↔ : ∀ {xs ys} →
(Any P xs × Any Q ys) ↔ Any (λ x → Any (λ y → P x × Q y) ys) xs
×↔ {xs} {ys} = inverse Any-×⁺ Any-×⁻ from∘to to∘from
where
from∘to : ∀ pq → Any-×⁻ (Any-×⁺ pq) ≡ pq
from∘to (p , q) rewrite
find∘map p (λ p → Any.map (λ q → (p , q)) q)
| find∘map q (λ q → proj₂ (proj₂ (find p)) , q)
| lose∘find p
| lose∘find q
= refl
to∘from : ∀ pq → Any-×⁺ (Any-×⁻ pq) ≡ pq
to∘from pq
with find pq
| (λ (f : (proj₁ (find pq) ≡_) ⋐ _) → map∘find pq {f})
... | (x , x∈xs , pq′) | lem₁
with find pq′
| (λ (f : (proj₁ (find pq′) ≡_) ⋐ _) → map∘find pq′ {f})
... | (y , y∈ys , p , q) | lem₂
rewrite P.sym $ map-∘ {R = λ x → Any (λ y → P x × Q y) ys}
(λ p → Any.map (λ q → p , q) (lose y∈ys q))
(λ y → P.subst P y p)
x∈xs
= lem₁ _ helper
where
helper : Any.map (λ q → p , q) (lose y∈ys q) ≡ pq′
helper rewrite P.sym $ map-∘ (λ q → p , q)
(λ y → P.subst Q y q)
y∈ys
= lem₂ _ refl
------------------------------------------------------------------------
-- Invertible introduction (⁺) and elimination (⁻) rules for various
-- list functions
------------------------------------------------------------------------
-- map
module _ {a p} {A : Set a} {P : Pred A p} where
singleton⁺ : ∀ {x} → P x → Any P [ x ]
singleton⁺ Px = here Px
singleton⁻ : ∀ {x} → Any P [ x ] → P x
singleton⁻ (here Px) = Px
singleton⁻ (there ())
------------------------------------------------------------------------
-- map
module _ {a b} {A : Set a} {B : Set b} {f : A → B} where
map⁺ : ∀ {p} {P : B → Set p} {xs} →
Any (P ∘ f) xs → Any P (List.map f xs)
map⁺ (here p) = here p
map⁺ (there p) = there $ map⁺ p
map⁻ : ∀ {p} {P : B → Set p} {xs} →
Any P (List.map f xs) → Any (P ∘ f) xs
map⁻ {xs = []} ()
map⁻ {xs = x ∷ xs} (here p) = here p
map⁻ {xs = x ∷ xs} (there p) = there $ map⁻ p
map⁺∘map⁻ : ∀ {p} {P : B → Set p} {xs} →
(p : Any P (List.map f xs)) → map⁺ (map⁻ p) ≡ p
map⁺∘map⁻ {xs = []} ()
map⁺∘map⁻ {xs = x ∷ xs} (here p) = refl
map⁺∘map⁻ {xs = x ∷ xs} (there p) = P.cong there (map⁺∘map⁻ p)
map⁻∘map⁺ : ∀ {p} (P : B → Set p) {xs} →
(p : Any (P ∘ f) xs) → map⁻ {P = P} (map⁺ p) ≡ p
map⁻∘map⁺ P (here p) = refl
map⁻∘map⁺ P (there p) = P.cong there (map⁻∘map⁺ P p)
map↔ : ∀ {p} {P : B → Set p} {xs} →
Any (P ∘ f) xs ↔ Any P (List.map f xs)
map↔ = inverse map⁺ map⁻ (map⁻∘map⁺ _) map⁺∘map⁻
------------------------------------------------------------------------
-- mapMaybe
module _ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
(f : A → Maybe B) where
mapMaybe⁺ : ∀ xs → Any (MAny.Any P) (map f xs) →
Any P (mapMaybe f xs)
mapMaybe⁺ [] ()
mapMaybe⁺ (x ∷ xs) ps with f x | ps
... | nothing | here ()
... | nothing | there pxs = mapMaybe⁺ xs pxs
... | just _ | here (just py) = here py
... | just _ | there pxs = there (mapMaybe⁺ xs pxs)
------------------------------------------------------------------------
-- _++_
module _ {a p} {A : Set a} {P : A → Set p} where
++⁺ˡ : ∀ {xs ys} → Any P xs → Any P (xs ++ ys)
++⁺ˡ (here p) = here p
++⁺ˡ (there p) = there (++⁺ˡ p)
++⁺ʳ : ∀ xs {ys} → Any P ys → Any P (xs ++ ys)
++⁺ʳ [] p = p
++⁺ʳ (x ∷ xs) p = there (++⁺ʳ xs p)
++⁻ : ∀ xs {ys} → Any P (xs ++ ys) → Any P xs ⊎ Any P ys
++⁻ [] p = inj₂ p
++⁻ (x ∷ xs) (here p) = inj₁ (here p)
++⁻ (x ∷ xs) (there p) = Sum.map there id (++⁻ xs p)
++⁺∘++⁻ : ∀ xs {ys} (p : Any P (xs ++ ys)) →
[ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs p) ≡ p
++⁺∘++⁻ [] p = refl
++⁺∘++⁻ (x ∷ xs) (here p) = refl
++⁺∘++⁻ (x ∷ xs) (there p) with ++⁻ xs p | ++⁺∘++⁻ xs p
++⁺∘++⁻ (x ∷ xs) (there p) | inj₁ p′ | ih = P.cong there ih
++⁺∘++⁻ (x ∷ xs) (there p) | inj₂ p′ | ih = P.cong there ih
++⁻∘++⁺ : ∀ xs {ys} (p : Any P xs ⊎ Any P ys) →
++⁻ xs ([ ++⁺ˡ , ++⁺ʳ xs ]′ p) ≡ p
++⁻∘++⁺ [] (inj₁ ())
++⁻∘++⁺ [] (inj₂ p) = refl
++⁻∘++⁺ (x ∷ xs) (inj₁ (here p)) = refl
++⁻∘++⁺ (x ∷ xs) {ys} (inj₁ (there p)) rewrite ++⁻∘++⁺ xs {ys} (inj₁ p) = refl
++⁻∘++⁺ (x ∷ xs) (inj₂ p) rewrite ++⁻∘++⁺ xs (inj₂ p) = refl
++↔ : ∀ {xs ys} → (Any P xs ⊎ Any P ys) ↔ Any P (xs ++ ys)
++↔ {xs = xs} = inverse [ ++⁺ˡ , ++⁺ʳ xs ]′ (++⁻ xs) (++⁻∘++⁺ xs) (++⁺∘++⁻ xs)
++-comm : ∀ xs ys → Any P (xs ++ ys) → Any P (ys ++ xs)
++-comm xs ys = [ ++⁺ʳ ys , ++⁺ˡ ]′ ∘ ++⁻ xs
++-comm∘++-comm : ∀ xs {ys} (p : Any P (xs ++ ys)) →
++-comm ys xs (++-comm xs ys p) ≡ p
++-comm∘++-comm [] {ys} p
rewrite ++⁻∘++⁺ ys {ys = []} (inj₁ p) = refl
++-comm∘++-comm (x ∷ xs) {ys} (here p)
rewrite ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₂ (here p)) = refl
++-comm∘++-comm (x ∷ xs) (there p) with ++⁻ xs p | ++-comm∘++-comm xs p
++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ʳ ys p))))
| inj₁ p | refl
rewrite ++⁻∘++⁺ ys (inj₂ p)
| ++⁻∘++⁺ ys (inj₂ $ there {x = x} p) = refl
++-comm∘++-comm (x ∷ xs) {ys} (there .([ ++⁺ʳ xs , ++⁺ˡ ]′ (++⁻ ys (++⁺ˡ p))))
| inj₂ p | refl
rewrite ++⁻∘++⁺ ys {ys = xs} (inj₁ p)
| ++⁻∘++⁺ ys {ys = x ∷ xs} (inj₁ p) = refl
++↔++ : ∀ xs ys → Any P (xs ++ ys) ↔ Any P (ys ++ xs)
++↔++ xs ys = inverse (++-comm xs ys) (++-comm ys xs)
(++-comm∘++-comm xs) (++-comm∘++-comm ys)
++-insert : ∀ xs {ys x} → P x → Any P (xs ++ [ x ] ++ ys)
++-insert xs Px = ++⁺ʳ xs (++⁺ˡ (singleton⁺ Px))
------------------------------------------------------------------------
-- concat
module _ {a p} {A : Set a} {P : A → Set p} where
concat⁺ : ∀ {xss} → Any (Any P) xss → Any P (concat xss)
concat⁺ (here p) = ++⁺ˡ p
concat⁺ (there {x = xs} p) = ++⁺ʳ xs (concat⁺ p)
concat⁻ : ∀ xss → Any P (concat xss) → Any (Any P) xss
concat⁻ [] ()
concat⁻ ([] ∷ xss) p = there $ concat⁻ xss p
concat⁻ ((x ∷ xs) ∷ xss) (here p) = here (here p)
concat⁻ ((x ∷ xs) ∷ xss) (there p) with concat⁻ (xs ∷ xss) p
... | here p′ = here (there p′)
... | there p′ = there p′
concat⁻∘++⁺ˡ : ∀ {xs} xss (p : Any P xs) →
concat⁻ (xs ∷ xss) (++⁺ˡ p) ≡ here p
concat⁻∘++⁺ˡ xss (here p) = refl
concat⁻∘++⁺ˡ xss (there p) rewrite concat⁻∘++⁺ˡ xss p = refl
concat⁻∘++⁺ʳ : ∀ xs xss (p : Any P (concat xss)) →
concat⁻ (xs ∷ xss) (++⁺ʳ xs p) ≡ there (concat⁻ xss p)
concat⁻∘++⁺ʳ [] xss p = refl
concat⁻∘++⁺ʳ (x ∷ xs) xss p rewrite concat⁻∘++⁺ʳ xs xss p = refl
concat⁺∘concat⁻ : ∀ xss (p : Any P (concat xss)) →
concat⁺ (concat⁻ xss p) ≡ p
concat⁺∘concat⁻ [] ()
concat⁺∘concat⁻ ([] ∷ xss) p = concat⁺∘concat⁻ xss p
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (here p) = refl
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there p)
with concat⁻ (xs ∷ xss) p | concat⁺∘concat⁻ (xs ∷ xss) p
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ˡ p′)) | here p′ | refl = refl
concat⁺∘concat⁻ ((x ∷ xs) ∷ xss) (there .(++⁺ʳ xs (concat⁺ p′))) | there p′ | refl = refl
concat⁻∘concat⁺ : ∀ {xss} (p : Any (Any P) xss) → concat⁻ xss (concat⁺ p) ≡ p
concat⁻∘concat⁺ (here p) = concat⁻∘++⁺ˡ _ p
concat⁻∘concat⁺ (there {x = xs} {xs = xss} p)
rewrite concat⁻∘++⁺ʳ xs xss (concat⁺ p) =
P.cong there $ concat⁻∘concat⁺ p
concat↔ : ∀ {xss} → Any (Any P) xss ↔ Any P (concat xss)
concat↔ {xss} = inverse concat⁺ (concat⁻ xss) concat⁻∘concat⁺ (concat⁺∘concat⁻ xss)
------------------------------------------------------------------------
-- applyUpTo
module _ {a p} {A : Set a} {P : A → Set p} where
applyUpTo⁺ : ∀ f {i n} → P (f i) → i < n → Any P (applyUpTo f n)
applyUpTo⁺ _ p (s≤s z≤n) = here p
applyUpTo⁺ f p (s≤s (s≤s i<n)) =
there (applyUpTo⁺ (f ∘ suc) p (s≤s i<n))
applyUpTo⁻ : ∀ f {n} → Any P (applyUpTo f n) →
∃ λ i → i < n × P (f i)
applyUpTo⁻ f {zero} ()
applyUpTo⁻ f {suc n} (here p) = zero , s≤s z≤n , p
applyUpTo⁻ f {suc n} (there p) with applyUpTo⁻ (f ∘ suc) p
... | i , i<n , q = suc i , s≤s i<n , q
------------------------------------------------------------------------
-- tabulate
module _ {a p} {A : Set a} {P : A → Set p} where
tabulate⁺ : ∀ {n} {f : Fin n → A} i → P (f i) → Any P (tabulate f)
tabulate⁺ fzero p = here p
tabulate⁺ (fsuc i) p = there (tabulate⁺ i p)
tabulate⁻ : ∀ {n} {f : Fin n → A} →
Any P (tabulate f) → ∃ λ i → P (f i)
tabulate⁻ {zero} ()
tabulate⁻ {suc n} (here p) = fzero , p
tabulate⁻ {suc n} (there p) = Prod.map fsuc id (tabulate⁻ p)
------------------------------------------------------------------------
-- map-with-∈.
module _ {a b p} {A : Set a} {B : Set b} {P : B → Set p} where
map-with-∈⁺ : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B) →
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
Any P (map-with-∈ xs f)
map-with-∈⁺ f (_ , here refl , p) = here p
map-with-∈⁺ f (_ , there x∈xs , p) =
there $ map-with-∈⁺ (f ∘ there) (_ , x∈xs , p)
map-with-∈⁻ : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B) →
Any P (map-with-∈ xs f) →
∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)
map-with-∈⁻ [] f ()
map-with-∈⁻ (y ∷ xs) f (here p) = (y , here refl , p)
map-with-∈⁻ (y ∷ xs) f (there p) =
Prod.map id (Prod.map there id) $ map-with-∈⁻ xs (f ∘ there) p
map-with-∈↔ : ∀ {xs : List A} {f : ∀ {x} → x ∈ xs → B} →
(∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) ↔ Any P (map-with-∈ xs f)
map-with-∈↔ = inverse (map-with-∈⁺ _) (map-with-∈⁻ _ _) (from∘to _) (to∘from _ _)
where
from∘to : ∀ {xs : List A} (f : ∀ {x} → x ∈ xs → B)
(p : ∃₂ λ x (x∈xs : x ∈ xs) → P (f x∈xs)) →
map-with-∈⁻ xs f (map-with-∈⁺ f p) ≡ p
from∘to f (_ , here refl , p) = refl
from∘to f (_ , there x∈xs , p)
rewrite from∘to (f ∘ there) (_ , x∈xs , p) = refl
to∘from : ∀ (xs : List A) (f : ∀ {x} → x ∈ xs → B)
(p : Any P (map-with-∈ xs f)) →
map-with-∈⁺ f (map-with-∈⁻ xs f p) ≡ p
to∘from [] f ()
to∘from (y ∷ xs) f (here p) = refl
to∘from (y ∷ xs) f (there p) =
P.cong there $ to∘from xs (f ∘ there) p
------------------------------------------------------------------------
-- return
module _ {a p} {A : Set a} {P : A → Set p} where
return⁺ : ∀ {x} → P x → Any P (return x)
return⁺ = here
return⁻ : ∀ {x} → Any P (return x) → P x
return⁻ (here p) = p
return⁻ (there ())
return⁺∘return⁻ : ∀ {x} (p : Any P (return x)) →
return⁺ (return⁻ p) ≡ p
return⁺∘return⁻ (here p) = refl
return⁺∘return⁻ (there ())
return⁻∘return⁺ : ∀ {x} (p : P x) → return⁻ (return⁺ p) ≡ p
return⁻∘return⁺ p = refl
return↔ : ∀ {x} → P x ↔ Any P (return x)
return↔ = inverse return⁺ return⁻ return⁻∘return⁺ return⁺∘return⁻
------------------------------------------------------------------------
-- _∷_
module _ {a p} {A : Set a} where
∷↔ : ∀ (P : Pred A p) {x xs} → (P x ⊎ Any P xs) ↔ Any P (x ∷ xs)
∷↔ P {x} {xs} =
(P x ⊎ Any P xs) ↔⟨ return↔ {P = P} ⊎-cong (Any P xs ∎) ⟩
(Any P [ x ] ⊎ Any P xs) ↔⟨ ++↔ {P = P} {xs = [ x ]} ⟩
Any P (x ∷ xs) ∎
------------------------------------------------------------------------
-- _>>=_
module _ {ℓ p} {A B : Set ℓ} {P : B → Set p} {f : A → List B} where
>>=↔ : ∀ {xs} → Any (Any P ∘ f) xs ↔ Any P (xs >>= f)
>>=↔ {xs} =
Any (Any P ∘ f) xs ↔⟨ map↔ ⟩
Any (Any P) (List.map f xs) ↔⟨ concat↔ ⟩
Any P (xs >>= f) ∎
------------------------------------------------------------------------
-- _⊛_
module _ {ℓ} {A B : Set ℓ} where
⊛↔ : ∀ {P : B → Set ℓ} {fs : List (A → B)} {xs : List A} →
Any (λ f → Any (P ∘ f) xs) fs ↔ Any P (fs ⊛ xs)
⊛↔ {P = P} {fs} {xs} =
Any (λ f → Any (P ∘ f) xs) fs ↔⟨ Any-cong (λ _ → Any-cong (λ _ → return↔) (_ ∎)) (_ ∎) ⟩
Any (λ f → Any (Any P ∘ return ∘ f) xs) fs ↔⟨ Any-cong (λ _ → >>=↔ ) (_ ∎) ⟩
Any (λ f → Any P (xs >>= return ∘ f)) fs ↔⟨ >>=↔ ⟩
Any P (fs ⊛ xs) ∎
-- An alternative introduction rule for _⊛_
⊛⁺′ : ∀ {P : A → Set ℓ} {Q : B → Set ℓ} {fs : List (A → B)} {xs} →
Any (P ⟨→⟩ Q) fs → Any P xs → Any Q (fs ⊛ xs)
⊛⁺′ pq p =
Inverse.to ⊛↔ ⟨$⟩
Any.map (λ pq → Any.map (λ {x} → pq {x}) p) pq
------------------------------------------------------------------------
-- _⊗_
module _ {ℓ} {A B : Set ℓ} where
⊗↔ : {P : A × B → Set ℓ} {xs : List A} {ys : List B} →
Any (λ x → Any (λ y → P (x , y)) ys) xs ↔ Any P (xs ⊗ ys)
⊗↔ {P} {xs} {ys} =
Any (λ x → Any (λ y → P (x , y)) ys) xs ↔⟨ return↔ ⟩
Any (λ _,_ → Any (λ x → Any (λ y → P (x , y)) ys) xs) (return _,_) ↔⟨ ⊛↔ ⟩
Any (λ x, → Any (P ∘ x,) ys) (_,_ <$> xs) ↔⟨ ⊛↔ ⟩
Any P (xs ⊗ ys) ∎
⊗↔′ : {P : A → Set ℓ} {Q : B → Set ℓ} {xs : List A} {ys : List B} →
(Any P xs × Any Q ys) ↔ Any (P ⟨×⟩ Q) (xs ⊗ ys)
⊗↔′ {P} {Q} {xs} {ys} =
(Any P xs × Any Q ys) ↔⟨ ×↔ ⟩
Any (λ x → Any (λ y → P x × Q y) ys) xs ↔⟨ ⊗↔ ⟩
Any (P ⟨×⟩ Q) (xs ⊗ ys) ∎
| {
"alphanum_fraction": 0.4266175936,
"avg_line_length": 37.8795180723,
"ext": "agda",
"hexsha": "192cd7b539b072c279aefb626b126b3676c9ef26",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any/Properties.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Unary/Any/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8942,
"size": 22008
} |
{-# OPTIONS --cumulativity --postfix-projections #-}
open import Agda.Primitive
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
variable
ℓ ℓ₁ ℓ₂ ℓ₃ : Level
A B C : Set ℓ
x y z : A
k l m n : Nat
record Σ {ℓ} (A : Set ℓ) (B : A → Set ℓ) : Set ℓ where
constructor _,_
field
fst : A
snd : B fst
open Σ public
record Category ℓ : Set (lsuc ℓ) where
field
Carrier : Set ℓ
_~>_ : Carrier → Carrier → Set ℓ
id : ∀ {X} → X ~> X
_∘_ : ∀ {X Y Z} → X ~> Y → Y ~> Z → X ~> Z
open Category public
SetCat : ∀ ℓ → Category (lsuc ℓ)
SetCat ℓ .Carrier = Set ℓ
SetCat ℓ ._~>_ A B = A → B
SetCat ℓ .id = λ x → x
SetCat ℓ ._∘_ f g = λ x → g (f x)
record Functor (c : Category ℓ₁) (c′ : Category ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
private
module c = Category c
module c′ = Category c′
field
F : c.Carrier → c′.Carrier
fmap : {A B : c.Carrier} → A c.~> B → F A c′.~> F B
open Functor public
idFunctor : {c : Category ℓ} → Functor c c
idFunctor .F X = X
idFunctor .fmap f = f
compFunctor : {c₁ : Category ℓ₁} {c₂ : Category ℓ₂} {c₃ : Category ℓ₃}
→ Functor c₁ c₂ → Functor c₂ c₃ → Functor c₁ c₃
compFunctor F₁ F₂ .F X = F₂ .F (F₁ .F X)
compFunctor F₁ F₂ .fmap f = F₂ .fmap (F₁ .fmap f)
Cat : ∀ ℓ → Category (lsuc ℓ)
Cat ℓ .Carrier = Category ℓ
Cat ℓ ._~>_ c₁ c₂ = Functor c₁ c₂
Cat ℓ .id = idFunctor
Cat ℓ ._∘_ = compFunctor
NatTrans : {c₁ : Category ℓ₁} {c₂ : Category ℓ₂} → (F G : Functor c₁ c₂) → Set (ℓ₁ ⊔ ℓ₂)
NatTrans {c₁ = c₁} {c₂ = c₂} F G =
let module c₁ = Category c₁
module c₂ = Category c₂
module F = Functor F
module G = Functor G
in ∀ X → F.F X c₂.~> G.F X
FunctorCat : (c₁ : Category ℓ₁) (c₂ : Category ℓ₂) → Category (ℓ₁ ⊔ ℓ₂)
FunctorCat c₁ c₂ .Carrier = Functor c₁ c₂
FunctorCat c₁ c₂ ._~>_ = NatTrans
FunctorCat c₁ c₂ .id X = c₂ .id
FunctorCat c₁ c₂ ._∘_ α β X =
let module c₁ = Category c₁
module c₂ = Category c₂
in α X c₂.∘ β X
record Setoid ℓ : Set (lsuc ℓ) where
field
Carrier : Set ℓ
_~_ : Carrier → Carrier → Set ℓ
rfl : ∀ {x} → x ~ x
sym : ∀ {x y} → x ~ y → y ~ x
trans : ∀ {x y z} → x ~ y → y ~ z → x ~ z
open Setoid public
DiscreteSetoid : Set ℓ → Setoid ℓ
DiscreteSetoid A .Carrier = A
DiscreteSetoid A ._~_ = _≡_
DiscreteSetoid A .rfl = refl
DiscreteSetoid A .sym refl = refl
DiscreteSetoid A .trans refl refl = refl
SetoidCat : ∀ ℓ → Category (lsuc ℓ)
SetoidCat ℓ .Carrier = Setoid ℓ
SetoidCat ℓ ._~>_ A B =
let module A = Setoid A
module B = Setoid B
in Σ {ℓ} (A.Carrier → B.Carrier)
λ f → ∀ {x y} → x A.~ y → f x B.~ f y
SetoidCat ℓ .id = (λ x → x) , λ x= → x=
SetoidCat ℓ ._∘_ (f , f=) (g , g=) = (λ x → g (f x)) , λ x= → g= (f= x=)
DiscreteSetoidFunctor : ∀ {ℓ} → Functor (SetCat ℓ) (SetoidCat ℓ)
DiscreteSetoidFunctor .F = DiscreteSetoid
DiscreteSetoidFunctor .fmap f .fst = f
DiscreteSetoidFunctor .fmap f .snd refl = refl
Op : Category ℓ → Category ℓ
Op c .Carrier = c .Carrier
Op c ._~>_ A B = c ._~>_ B A
Op c .id = c .id
Op c ._∘_ = let module c = Category c in λ f g → g c.∘ f
Yoneda : {c : Category ℓ} (X : c .Carrier) → Functor c (Op (SetCat ℓ))
Yoneda {c = c} X .F Y =
let module c = Category c
in Y c.~> X
Yoneda {c = c} X .fmap = c ._∘_
test : Functor (SetCat (lsuc lzero)) (Op (SetCat (lsuc (lsuc lzero))))
test = Yoneda {c = SetCat (lsuc lzero)} Set
| {
"alphanum_fraction": 0.5856093979,
"avg_line_length": 28.1404958678,
"ext": "agda",
"hexsha": "943240622c7bde0ce261a1af718663b1e753d1e3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/CumulCat.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/CumulCat.agda",
"max_line_length": 88,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/CumulCat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 1428,
"size": 3405
} |
module Issue4435-2 where
record ⊤ : Set where
data Foo (a : Set) : Set where
Bar : {a : Set} → Foo a → Set
-- Here, the error message does NOT include
-- "Perhaps you meant to write 'data Foo a where'"
-- because Foo is defined above (rather than declared - note the "where"
-- compared to Issue4435-1.agda).
data Foo a : Set where
c1 : Foo a
c2 : (x : Foo a) (y : Bar x → Foo a) → Foo a
Bar c1 = ⊤
Bar (c2 a b) = (x : Bar a) → Bar (b x)
| {
"alphanum_fraction": 0.6233183857,
"avg_line_length": 24.7777777778,
"ext": "agda",
"hexsha": "d4d4b225244261fe37ce11b49f99acaa5e7b5955",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/Issue4435-2.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue4435-2.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue4435-2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 153,
"size": 446
} |
module PushArgument where
open import Agda.Builtin.Nat
data List (A : Set) : Nat -> Set where
nil : List A 0
cons : {n : Nat} -> A -> List A n -> List A (suc n)
newFunc : {A : Set} -> {B : Set} -> (f : A -> B) -> (x : A) -> B
newFunc f x = f x
map : {n : Nat} -> {A : Set} -> {B : Set} -> (A -> B) -> List A n -> List B n
map f nil = nil
map f (cons x xs) = cons (newFunc f x) (map f xs)
| {
"alphanum_fraction": 0.5062034739,
"avg_line_length": 22.3888888889,
"ext": "agda",
"hexsha": "c1183276522a468b082ce4896b59882330c3b9a9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/PushArgument.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/PushArgument.agda",
"max_line_length": 77,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/PushArgument.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 156,
"size": 403
} |
-- Andreas, 2016-07-28, issue #779
record R : Set1 where
data Bla : Set where
field F : Set
-- WAS:
-- Not a valid let-definition
-- Expected:
-- Success, or error outlawing pattern matching definition before last field.
| {
"alphanum_fraction": 0.6973684211,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "c31198a3d2db8a068e4d355de240ead081b8c6bc",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue779data.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue779data.agda",
"max_line_length": 77,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue779data.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 63,
"size": 228
} |
------------------------------------------------------------------------
-- Examples related to Univalence-axiom.Isomorphism-is-equality.More
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- Note that this module uses ordinary propositional equality, with a
-- computing J rule.
-- This module has been developed in collaboration with Thierry
-- Coquand.
module Univalence-axiom.Isomorphism-is-equality.More.Examples where
open import Equality.Propositional renaming (equality-with-J to eq)
open import Equivalence eq hiding (id)
open import Function-universe eq hiding (id)
open import H-level.Closure eq
open import Prelude hiding (id)
open import Univalence-axiom.Isomorphism-is-equality.More
------------------------------------------------------------------------
-- Magmas
magma : Code
magma = ε ▻ A-type ▻ N-ary [0] 2
Magma : Type₁
Magma = ⟦ magma ⟧
private
-- An unfolding of Magma.
Magma-unfolded :
Magma ≡ Σ (Σ (↑ _ ⊤) λ _ →
Type ) λ { (_ , A) →
↑ _ A → ↑ _ A → ↑ _ A }
Magma-unfolded = refl
-- An unfolding of Isomorphic magma.
Isomorphic-magma-unfolded :
∀ {ass A₁ f₁ A₂ f₂} →
Isomorphic ass magma ((_ , A₁) , f₁) ((_ , A₂) , f₂) ≡
Σ (Σ (↑ _ ⊤) λ _ →
↑ _ (A₁ ≃ A₂) ) λ { (_ , lift A₁≃A₂) →
let open _≃_ (↑-cong A₁≃A₂) in
∀ x y → to (f₁ x y) ≡ f₂ (to x) (to y) }
Isomorphic-magma-unfolded = refl
------------------------------------------------------------------------
-- Semigroups
-- Note that one axiom states that the underlying type is a set. This
-- assumption is used to prove that the other axiom is propositional.
semigroup : Code
semigroup =
ε
▻ A-type
▻ Is-a-set [0]
▻ N-ary (1+ [0]) 2
▻ Proposition
(λ { (_ , _∙_) →
∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) })
assoc-prop
where
assoc-prop = λ { ass ((_ , A-set) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
A-set }
Semigroup : Type₁
Semigroup = ⟦ semigroup ⟧
private
-- An unfolding of Semigroup.
Semigroup-unfolded :
Semigroup ≡ Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →
Type ) λ { (_ , A) →
Is-set (↑ _ A) }) λ { ((_ , A) , _) →
↑ _ A → ↑ _ A → ↑ _ A }) λ { (_ , _∙_) →
∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }
Semigroup-unfolded = refl
-- An unfolding of Isomorphic semigroup.
Isomorphic-semigroup-unfolded :
∀ {ass A₁} {is₁ : Is-set (↑ _ A₁)} {_∙₁_ assoc₁}
{A₂} {is₂ : Is-set (↑ _ A₂)} {_∙₂_ assoc₂} →
Isomorphic ass semigroup ((((_ , A₁) , is₁) , _∙₁_) , assoc₁)
((((_ , A₂) , is₂) , _∙₂_) , assoc₂) ≡
Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →
↑ _ (A₁ ≃ A₂) ) λ { _ →
↑ _ ⊤ }) λ { ((_ , lift A₁≃A₂) , _) →
let open _≃_ (↑-cong A₁≃A₂) in
∀ x y → to (x ∙₁ y) ≡ (to x ∙₂ to y) }) λ { _ →
↑ _ ⊤ }
Isomorphic-semigroup-unfolded = refl
------------------------------------------------------------------------
-- Sets with fixed-point operators
set-with-fixed-point-operator : Code
set-with-fixed-point-operator =
ε
▻ A-type
▻ Is-a-set [0]
▻ Simple ((base (1+ [0]) ⟶ base (1+ [0])) ⟶ base (1+ [0]))
▻ Proposition
(λ { (_ , fix) →
∀ f → fix f ≡ f (fix f) })
fix-point-prop
where
fix-point-prop = λ { ass ((_ , A-set) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
A-set }
Set-with-fixed-point-operator : Type₁
Set-with-fixed-point-operator = ⟦ set-with-fixed-point-operator ⟧
private
-- An unfolding of Set-with-fixed-point-operator.
Set-with-fixed-point-operator-unfolded :
Set-with-fixed-point-operator ≡ Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →
Type ) λ { (_ , A) →
Is-set (↑ _ A) }) λ { ((_ , A) , _) →
(↑ _ A → ↑ _ A) → ↑ _ A }) λ { (_ , fix) →
∀ f → fix f ≡ f (fix f) }
Set-with-fixed-point-operator-unfolded = refl
-- An unfolding of Isomorphic set-with-fixed-point-operator.
Isomorphic-set-with-fixed-point-operator-unfolded :
∀ {ass A₁} {is₁ : Is-set (↑ _ A₁)} {fix₁ fixed-point₁}
{A₂} {is₂ : Is-set (↑ _ A₂)} {fix₂ fixed-point₂} →
Isomorphic ass set-with-fixed-point-operator
((((_ , A₁) , is₁) , fix₁) , fixed-point₁)
((((_ , A₂) , is₂) , fix₂) , fixed-point₂) ≡
Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →
↑ _ (A₁ ≃ A₂) ) λ { _ →
↑ _ ⊤ }) λ { ((_ , lift A₁≃A₂) , _) →
let open _≃_ (↑-cong A₁≃A₂) in
∀ f g →
(∀ x y → to x ≡ y → to (f x) ≡ g y) →
to (fix₁ f) ≡ fix₂ g }) λ { _ →
↑ _ ⊤ }
Isomorphic-set-with-fixed-point-operator-unfolded = refl
------------------------------------------------------------------------
-- Abelian groups
abelian-group : Code
abelian-group =
ε
-- The underlying type.
▻ A-type
-- The underlying type is a set.
▻ Is-a-set [0]
-- The binary group operation.
▻ N-ary (1+ [0]) 2
-- Commutativity.
▻ Comm
-- Associativity.
▻ Assoc
-- Identity.
▻ N-ary (1+ 1+ 1+ 1+ [0]) 0
-- Left identity.
▻ Left-identity
-- Right identity.
▻ Right-identity
-- Inverse.
▻ N-ary (1+ 1+ 1+ 1+ 1+ 1+ 1+ [0]) 1
-- Left inverse.
▻ Left-inverse
-- Right inverse.
▻ Right-inverse
where
Comm = Proposition
(λ { (_ , _∙_) →
∀ x y → (x ∙ y) ≡ (y ∙ x) })
(λ { ass ((_ , A-set) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
A-set
})
Assoc = Proposition
(λ { ((_ , _∙_) , _) →
∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) })
(λ { ass (((_ , A-set) , _) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
A-set
})
Left-identity = Proposition
(λ { ((((_ , _∙_) , _) , _) , e) →
∀ x → (e ∙ x) ≡ x })
(λ { ass (((((_ , A-set) , _) , _) , _) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
A-set
})
Right-identity = Proposition
(λ { (((((_ , _∙_) , _) , _) , e) , _) →
∀ x → (x ∙ e) ≡ x })
(λ { ass ((((((_ , A-set) , _) , _) , _) , _) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
A-set
})
Left-inverse = Proposition
(λ { (((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) →
∀ x → ((x ⁻¹) ∙ x) ≡ e })
(λ { ass ((((((((_ , A-set) , _) , _) , _) , _) , _) , _) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
A-set
})
Right-inverse = Proposition
(λ { ((((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) , _) →
∀ x → (x ∙ (x ⁻¹)) ≡ e })
(λ { ass (((((((((_ , A-set) , _) , _) , _) , _) , _) , _) , _) , _) →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
A-set
})
Abelian-group : Type₁
Abelian-group = ⟦ abelian-group ⟧
private
-- An unfolding of Abelian-group. Note that the inner structure is
-- left-nested.
Abelian-group-unfolded :
Abelian-group ≡ Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →
Type ) λ { (_ , A) →
Is-set (↑ _ A) }) λ { ((_ , A) , _) →
↑ _ A → ↑ _ A → ↑ _ A }) λ { (_ , _∙_) →
∀ x y → (x ∙ y) ≡ (y ∙ x) }) λ { ((_ , _∙_) , _) →
∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }) λ { (((((_ , A) , _) , _ ) , _) , _) →
↑ _ A }) λ { ((((_ , _∙_) , _) , _) , e) →
∀ x → (e ∙ x) ≡ x }) λ { (((((_ , _∙_) , _) , _) , e) , _) →
∀ x → (x ∙ e) ≡ x }) λ { ((((((((_ , A) , _) , _ ) , _) , _) , _) , _) , _) →
↑ _ A → ↑ _ A }) λ { (((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) →
∀ x → ((x ⁻¹) ∙ x) ≡ e }) λ { ((((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) , _) →
∀ x → (x ∙ (x ⁻¹)) ≡ e }
Abelian-group-unfolded = refl
-- An unfolding of Isomorphic abelian-group.
Isomorphic-abelian-group-unfolded :
∀ {ass A₁} {is₁ : Is-set (↑ _ A₁)}
{_∙₁_ comm₁ assoc₁ e₁ lid₁ rid₁ _⁻¹₁ linv₁ rinv₁}
{A₂} {is₂ : Is-set (↑ _ A₂)}
{_∙₂_ comm₂ assoc₂ e₂ lid₂ rid₂ _⁻¹₂ linv₂ rinv₂} →
Isomorphic ass abelian-group
(((((((((((_ , A₁) , is₁) , _∙₁_) , comm₁) ,
assoc₁) , e₁) , lid₁) , rid₁) , _⁻¹₁) , linv₁) , rinv₁)
(((((((((((_ , A₂) , is₂) , _∙₂_) , comm₂) ,
assoc₂) , e₂) , lid₂) , rid₂) , _⁻¹₂) , linv₂) , rinv₂) ≡
Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ →
↑ _ (A₁ ≃ A₂) ) λ { _ →
↑ _ ⊤ }) λ { ((_ , lift A₁≃A₂) , _) →
let open _≃_ (↑-cong A₁≃A₂) in
∀ x y → to (x ∙₁ y) ≡ (to x ∙₂ to y) }) λ { _ →
↑ _ ⊤ }) λ { _ →
↑ _ ⊤ }) λ { (((((_ , lift A₁≃A₂) , _) , _) , _) , _) →
let open _≃_ (↑-cong A₁≃A₂) in
to e₁ ≡ e₂ }) λ { _ →
↑ _ ⊤ }) λ { _ →
↑ _ ⊤ }) λ { ((((((((_ , lift A₁≃A₂) , _) , _) , _) , _) , _) , _) , _) →
let open _≃_ (↑-cong A₁≃A₂) in
∀ x → to (x ⁻¹₁) ≡ (to x ⁻¹₂) }) λ { _ →
↑ _ ⊤ }) λ { _ →
↑ _ ⊤ }
Isomorphic-abelian-group-unfolded = refl
------------------------------------------------------------------------
-- Church-encoded natural numbers for which we can do induction
-- Church-encoded natural numbers.
Nat : Type₁
Nat = (A : Type) → ↑ (# 1) A → (↑ (# 1) A → ↑ (# 1) A) → ↑ (# 1) A
-- Zero and successor.
Zero : Nat
Zero = λ A z s → z
Suc : Nat → Nat
Suc = λ n A z s → s (n A z s)
-- The code.
inductive-natural-numbers : Code
inductive-natural-numbers =
ε
▻ Dep (Π set (Π (base ⟨0⟩)
(Π (Π (base (1+ ⟨0⟩)) (base (1+ 1+ ⟨0⟩)))
(base (1+ 1+ ⟨0⟩)))))
▻ Proposition
(λ { (_ , n) →
(P : Nat → Type) →
Is-proposition (P n) →
P Zero →
(∀ m → P m → P (Suc m)) →
P n })
(λ ass _ →
let open Assumptions ass in
Π-closure ext₁ 1 λ _ →
Π-closure (lower-extensionality (# 1) (# 0) ext₁) 1 λ Pn-prop →
Π-closure (lower-extensionality (# 1) (# 0) ext₁) 1 λ _ →
Π-closure (lower-extensionality (# 0) (# 1) ext₁) 1 λ _ →
Pn-prop)
where open Dependent
private
-- The usual unfolding lemmas.
⟦inductive-natural-numbers⟧ :
⟦ inductive-natural-numbers ⟧
≡
Σ (Σ (↑ _ ⊤) λ _ →
Nat ) λ { (_ , n) →
(P : Nat → Type) →
Is-proposition (P n) →
P Zero →
(∀ m → P m → P (Suc m)) →
P n }
⟦inductive-natural-numbers⟧ = refl
Isomorphic-inductive-natural-numbers :
∀ {ass : Assumptions}
{n₁ n₂ : Nat}
{prop₁ : (P : Nat → Type) → Is-proposition (P n₁) →
P Zero → (∀ m → P m → P (Suc m)) → P n₁}
{prop₂ : (P : Nat → Type) → Is-proposition (P n₂) →
P Zero → (∀ m → P m → P (Suc m)) → P n₂} →
Isomorphic ass inductive-natural-numbers
((_ , n₁) , prop₁) ((_ , n₂) , prop₂)
≡
Σ (Σ (↑ (# 1) ⊤) λ _ →
((A₁ A₂ : Type) → (A₁≃A₂ : ↑ (# 1) (A₁ ≃ A₂)) →
let cast = _≃_.from (↑-cong (lower A₁≃A₂)) in
(z₁ : ↑ (# 1) A₁) (z₂ : ↑ (# 1) A₂) →
z₁ ≡ cast z₂ →
(s₁ : ↑ (# 1) A₁ → ↑ (# 1) A₁) (s₂ : ↑ (# 1) A₂ → ↑ (# 1) A₂) →
(∀ n₁ n₂ → n₁ ≡ cast n₂ → s₁ n₁ ≡ cast (s₂ n₂)) →
n₁ A₁ z₁ s₁ ≡ cast (n₂ A₂ z₂ s₂))) λ _ →
↑ (# 1) ⊤
Isomorphic-inductive-natural-numbers = refl
| {
"alphanum_fraction": 0.4068999266,
"avg_line_length": 30.1253071253,
"ext": "agda",
"hexsha": "35ecf410ca0f2bd1fa64816ceb2394828e56fdad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Univalence-axiom/Isomorphism-is-equality/More/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Univalence-axiom/Isomorphism-is-equality/More/Examples.agda",
"max_line_length": 118,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Univalence-axiom/Isomorphism-is-equality/More/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 4381,
"size": 12261
} |
{-# OPTIONS --rewriting --prop #-}
open import common
open import syntx
open import derivability
{- Helper functions to compute the arity of a rule given the arity of the symbol. -}
SStoJS : SyntaxSort → JudgmentSort
SStoJS Ty = Ty
SStoJS Tm = Tm
TArityArgs : SyntaxArityArgs → JudgmentArityArgs
TArityArgs [] = []
TArityArgs (ar , (n , k)) = TArityArgs ar , (n , SStoJS k)
TArity : SyntaxArity → JudgmentArity
TArity ar = (TArityArgs (args ar) , SStoJS (sort ar))
SStoJS= : SyntaxSort → JudgmentSort
SStoJS= Ty = Ty=
SStoJS= Tm = Tm=
CArityArgs : SyntaxArityArgs → JudgmentArityArgs
CArityArgs [] = []
CArityArgs (ar , (n , k)) = CArityArgs ar , (n , SStoJS= k)
CArity : SyntaxArity → JudgmentArity
CArity ar = (CArityArgs (args ar) , SStoJS= (sort ar))
{-
[↑DerivationRule r] extends the derivation rule [r] to an extended signature.
This is easy because derivation rules were designed to be extendable.
-}
↑DerivationRule : {Σ : Signature} {sar : SyntaxArity} {jar : JudgmentArity}
→ DerivationRule Σ jar → DerivationRule (ExtSig Σ sar) jar
rule (↑DerivationRule r) ↑ Γ = rule r (Ext→ ↑) Γ
{- Record combining the typing and congruence rules for a new symbol. -}
record DerivationRules {Σ : Signature} (E : DerivabilityStructure Σ) (ar : SyntaxArity) : Set₁ where
field
typingdrule : DerivationRule (ExtSig Σ ar) (TArity ar)
congruencedrule : DerivationRule (ExtSig Σ ar) (CArity ar)
open DerivationRules public
{-
[extend E tc] extends the derivability structure [E] to an extended signature, where [tc] is the
typing/congruence rules of a new symbol. We also use a custom data type in order to add the two new
rules, in order to get something readable.
-}
data ExtT (A : JudgmentArity → Set) (sar : SyntaxArity) : JudgmentArity → Set where
typingrule : ExtT A sar (TArity sar)
prev : {jar : JudgmentArity} → A jar → ExtT A sar jar
data ExtC (A : JudgmentArity → Set) (sar : SyntaxArity) : JudgmentArity → Set where
congruencerule : ExtC A sar (CArity sar)
prev : {jar : JudgmentArity} → A jar → ExtC A sar jar
extend : {Σ : Signature} (E : DerivabilityStructure Σ)
{ar : SyntaxArity}
(tc : DerivationRules E ar)
→ DerivabilityStructure (ExtSig Σ ar)
Rules (extend E {ar} tc) S = Rules E S
Rules (extend E {ar} tc) T = ExtT (Rules E T) ar
Rules (extend E {ar} tc) C = ExtC (Rules E C) ar
Rules (extend E {ar} tc) Eq = Rules E Eq
derivationRule (extend E tc) {t = S} r = ↑DerivationRule (derivationRule E r)
derivationRule (extend E tc) {t = T} (prev r) = ↑DerivationRule (derivationRule E r)
derivationRule (extend E tc) {t = T} typingrule = typingdrule tc
derivationRule (extend E tc) {t = C} (prev r) = ↑DerivationRule (derivationRule E r)
derivationRule (extend E tc) {t = C} congruencerule = congruencedrule tc
derivationRule (extend E tc) {t = Eq} r = ↑DerivationRule (derivationRule E r)
-- data Ext (A : Tag → JudgmentArity → Set) (sar : SyntaxArity) : Tag → JudgmentArity → Set where
-- typingrule : Ext A sar T (TArity sar)
-- congruencerule : Ext A sar C (CArity sar)
-- prev : {t : Tag} {jar : JudgmentArity} → A t jar → Ext A sar t jar
-- extend : {Σ : Signature} (E : DerivabilityStructure Σ)
-- {ar : SyntaxArity}
-- (tc : DerivationRules E ar 0)
-- → DerivabilityStructure (ExtSig Σ ar)
-- Rules (extend E {ar} tc) = Ext (Rules E) ar
-- derivationRule (extend E tc) typingrule = typingdrule tc
-- derivationRule (extend E tc) congruencerule = congruencedrule tc
-- derivationRule (extend E tc) (prev r) = ↑DerivationRule (derivationRule E r)
{- Typing rules for basic metavariables (simply a derivable type in the empty context) -}
record BMTypingRule {Σ : Signature} (E : DerivabilityStructure Σ) : Set where
constructor _/_
field
type : TyExpr Σ 0
der : Derivable E {Γ = ◇} (◇ ⊢ type)
open BMTypingRule public
{- The derivation rules corresponding to a basic metavariable (on the extended signature). -}
BMRules : {Σ : Signature} {E : DerivabilityStructure Σ}
(t : BMTypingRule E)
→ DerivationRules E ([] , Tm)
rule (typingdrule (BMRules t)) ↑ Γ [] = return (◇ ⊢ (↑ $ new) []
:> ↑Expr (Ext→ ↑) (weaken0 (type t)))
rule (congruencedrule (BMRules t)) ↑ Γ [] = return (◇ ⊢ (↑ $ new) [] == (↑ $ new) []
:> ↑Expr (Ext→ ↑) (weaken0 (type t)))
-- -------------- -----------------
-- Γ ⊢ s : A Γ ⊢ s = s : A
{-
The premises of a typing rule for a metavariables form essentially a list of typing rules for basic
metavariables in increasingly extended signatures. There are two different ways to order the premises:
- either we have the first premise, and then the rest in an extended signature,
- or we have all but the last premises, and then the last one in a signature extended by all the
previous ones.
The first option looks simpler, but we use the second option because we will need to talk about
multiple substitution later anyway, and also it allows us to keep typing rules in the empty context.
The type [MTypingRulePremises E n] represents a list of length [n] of such premises. It is defined
simultaneously with multiple substitution: [extend^BM E ts] represents the derivability structure
[E] extended by all the basic metavariables of [ts].
-}
data MTypingRulePremises : {Σ : Signature} (E : DerivabilityStructure Σ) (n : ℕ) → Set
extend^BM : {Σ : Signature} (E : DerivabilityStructure Σ) {n : ℕ} (ts : MTypingRulePremises E n)
→ DerivabilityStructure (ExtSig^ Σ (MArityArgs n))
data MTypingRulePremises where
[] : ∀ {Σ} {E : DerivabilityStructure Σ} → MTypingRulePremises E 0
_,_ : ∀ {Σ} {E : DerivabilityStructure Σ} {n : ℕ}
→ (ts : MTypingRulePremises E n)
→ (t : BMTypingRule (extend^BM E ts))
→ MTypingRulePremises E (suc n)
extend^BM E [] = E
extend^BM E (ts , t) = extend (extend^BM E ts) (BMRules t)
{-
[MTypingRule E n k] represents typing rules in derivability structure [E] for a metavariable of
arity (n , k).
There are two cases depending on [k]:
- if [k] is [Ty], then we simply need a list of premises,
- if [k] is [Tm], then we need a list of premises and a type for the conclusion, in the correctly
extended derivability structure.
-}
data MTypingRule {Σ : Signature} (E : DerivabilityStructure Σ) (n : ℕ) : (k : SyntaxSort) → Set where
Ty : MTypingRulePremises E n → MTypingRule E n Ty
Tm : (ts : MTypingRulePremises E n) → BMTypingRule (extend^BM E ts) → MTypingRule E n Tm
{-
Γ, n : ℕ, y : P n ⊢ dS : P (n + 1)
◇ ⊢ _n : ℕ
◇ ⊢ _y : P _n
----------------------------
◇ ⊢ dS(_n , _y) : P (_n + 1)
Γ ⊢ n = m : ℕ
Γ ⊢ u = v : P n
-----------
Γ ⊢ dS(n , u) = dS(m , v) : P (n + 1)
Γ ⊢ 3 : ℕ
Γ ⊢ u : P 3
~~~>
Γ ⊢ dS(3 , u) : P (3 + 1)
(n : ℕ, y : P n)
-}
{-
The derivation rules associated to a typing rule for a metavariable.
-}
MTypingRule-TArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {n m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m}
(ts : MTypingRulePremises E n) (js : DerivationRulePremises Σ' Γ (TArityArgs (MArityArgs n)))
→ Partial (Args Σ' m (MArityArgs n))
MTypingRule-TArgs E ↑ [] [] = return []
MTypingRule-TArgs E ↑ (ts , t) (js , ◇ ⊢ a :> A) = do
as ← MTypingRule-TArgs E ↑ ts js
assume (A ≡ ↑Expr (SubstM ↑ as) (weaken0 (type t)))
return (as , a)
MTypingRule-TRule : {Σ : Signature} (E : DerivabilityStructure Σ) {n : ℕ} {k : SyntaxSort}
(t : MTypingRule E n k)
→ DerivationRule (ExtSig Σ (MArity n k)) (TArity (MArity n k))
rule (MTypingRule-TRule E (Ty ts)) ↑ Γ js = do
as ← MTypingRule-TArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as)
rule (MTypingRule-TRule E (Tm ts t)) ↑ Γ js = do
as ← MTypingRule-TArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t)))
MTypingRule-CArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {n m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m}
(ts : MTypingRulePremises E n) (js : DerivationRulePremises Σ' Γ (CArityArgs (MArityArgs n)))
→ Partial (Args Σ' m (MArityArgs n) × Args Σ' m (MArityArgs n))
MTypingRule-CArgs E ↑ [] [] = return ([] , [])
MTypingRule-CArgs E ↑ (ts , t) (js , ◇ ⊢ a == a' :> A) = do
(as , as') ← MTypingRule-CArgs E ↑ ts js
assume (A ≡ ↑Expr (SubstM ↑ as) (weaken0 (type t)))
return ((as , a) , (as' , a'))
MTypingRule-CRule : {Σ : Signature} (E : DerivabilityStructure Σ) {n : ℕ} {k : SyntaxSort}
(t : MTypingRule E n k)
→ DerivationRule (ExtSig Σ (MArity n k)) (CArity (MArity n k))
rule (MTypingRule-CRule E (Ty ts)) ↑ Γ js = do
(as , as') ← MTypingRule-CArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as == (↑ $ new) as')
rule (MTypingRule-CRule E (Tm ts t)) ↑ Γ js = do
(as , as') ← MTypingRule-CArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as == (↑ $ new) as' :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t)))
MRules : {Σ : Signature} {E : DerivabilityStructure Σ} {n : ℕ} {k : SyntaxSort}
(t : MTypingRule E n k)
→ DerivationRules E (MArity n k)
typingdrule (MRules t) = MTypingRule-TRule _ t
congruencedrule (MRules t) = MTypingRule-CRule _ t
{-
General typing rules are very similar to typing rules of metavariables, except that they are using
[MTypingRule] instead of [BMTypingRule] for the premises.
-}
data TypingRulePremises : {Σ : Signature} (E : DerivabilityStructure Σ) (args : SyntaxArityArgs) → Set
extend^M : {Σ : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} (ts : TypingRulePremises E args) → DerivabilityStructure (ExtSig^ Σ args)
data TypingRulePremises where
[] : ∀ {Σ} {E : DerivabilityStructure Σ} → TypingRulePremises E []
_,_ : ∀ {Σ} {E : DerivabilityStructure Σ} {args : SyntaxArityArgs} {m : ℕ} {k : SyntaxSort}
→ (ts : TypingRulePremises E args)
→ (t : MTypingRule (extend^M E ts) m k)
→ TypingRulePremises E (args , (m , k))
extend^M E [] = E
extend^M E (ts , t) = extend (extend^M E ts) (MRules t)
data TypingRule {Σ : Signature} (E : DerivabilityStructure Σ) (args : SyntaxArityArgs) : (k : SyntaxSort) → Set where
Ty : TypingRulePremises E args → TypingRule E args Ty
Tm : (ts : TypingRulePremises E args) → BMTypingRule (extend^M E ts) → TypingRule E args Tm
{- The derivation rules associated to a typing rule. -}
{- List of all the last [n] variables in scope [m + n] -}
Vars : {Σ : Signature} {n : ℕ} (m : ℕ) → Args Σ (m + n) (MArityArgs n)
Vars {n = zero} m = []
Vars {n = suc n} m = weakenA {{≤-+ {m + n} {1}}} last (Vars m) , var last
{-
[check-DepCtx ↑ as ts Δ] checks that the premises [ts] correspond to the dependent context [Δ],
where [as] corresponds to the interpretations of the metavariables.
-}
check-DepCtx : {Σ Σ' : Signature} {m n : ℕ} {args : SyntaxArityArgs}
{E : DerivabilityStructure (ExtSig^ Σ args)}
→ (Σ →Sig Σ') m → Args Σ' m args
→ MTypingRulePremises E n → DepCtx Σ' m n → Prop
check-DepCtx ↑ as [] ◇ = ⊤
check-DepCtx {m = m} {n = suc n} ↑ as (ts , t) (Δ , A) =
ΣP (check-DepCtx ↑ as ts Δ)
(λ _ → A ≡ ↑Expr (SubstM (liftSig ↑) (weakenAL as)) (↑Expr (SubstM idSig (Vars m)) (weaken0 (type t))))
TypingRule-TArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m}
(ts : TypingRulePremises E args) (js : DerivationRulePremises Σ' Γ (TArityArgs args))
→ Partial (Args Σ' m args)
TypingRule-TArgs E ↑ [] [] = return []
TypingRule-TArgs E ↑ (ts , Ty t's) (js , Δ ⊢ A) = do
as ← TypingRule-TArgs E ↑ ts js
assume (check-DepCtx ↑ as t's Δ)
return (as , A)
TypingRule-TArgs E {m = m} ↑ (ts , Tm t's t) (_,_ {m = m'} js (Δ ⊢ u :> A)) = do
as ← TypingRule-TArgs E ↑ ts js
assume (check-DepCtx ↑ as t's Δ)
assume (A ≡ ↑Expr (SubstM (liftSig ↑) (weakenAL as)) (↑Expr (SubstM idSig (Vars m)) (weaken0 (type t))))
return (as , u)
TypingRule-TRule : {Σ : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {k : SyntaxSort}
(t : TypingRule E args k)
→ DerivationRule (ExtSig Σ (args , k)) (TArity (args , k))
rule (TypingRule-TRule E (Ty ts)) ↑ Γ js = do
as ← TypingRule-TArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as)
rule (TypingRule-TRule E (Tm ts t)) ↑ Γ js = do
as ← TypingRule-TArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t)))
TypingRule-CArgs : {Σ Σ' : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {m : ℕ} (↑ : (Σ →Sig Σ') m) {Γ : Ctx Σ' m}
(ts : TypingRulePremises E args) (js : DerivationRulePremises Σ' Γ (CArityArgs args))
→ Partial (Args Σ' m args × Args Σ' m args)
TypingRule-CArgs E ↑ [] [] = return ([] , [])
TypingRule-CArgs E {args = args , (n , Ty)} {m} ↑ (ts , Ty t's) (js , Δ ⊢ A == A') = do
(as , as') ← TypingRule-CArgs E ↑ ts js
assume (check-DepCtx ↑ as t's Δ)
return ((as , A) , (as' , A'))
TypingRule-CArgs E {args = args , (n , Tm)} {m} ↑ (ts , Tm t's t) (js , Δ ⊢ u == u' :> A) = do
(as , as') ← TypingRule-CArgs E ↑ ts js
assume (check-DepCtx ↑ as t's Δ)
assume (A ≡ ↑Expr (SubstM (liftSig ↑) (weakenAL as)) (↑Expr (SubstM idSig (Vars m)) (weaken0 (type t))))
return ((as , u) , (as' , u'))
TypingRule-CRule : {Σ : Signature} (E : DerivabilityStructure Σ) {args : SyntaxArityArgs} {k : SyntaxSort}
(t : TypingRule E args k)
→ DerivationRule (ExtSig Σ (args , k)) (CArity (args , k))
rule (TypingRule-CRule E (Ty ts)) ↑ Γ js = do
(as , as') ← TypingRule-CArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as == (↑ $ new) as')
rule (TypingRule-CRule E (Tm ts t)) {n = n} ↑ Γ js = do
(as , as') ← TypingRule-CArgs E (Ext→ ↑) ts js
return (◇ ⊢ (↑ $ new) as == (↑ $ new) as' :> ↑Expr (SubstM (Ext→ ↑) as) (weaken0 (type t)))
TRules : {Σ : Signature} {E : DerivabilityStructure Σ} {ar : SyntaxArity}
(t : TypingRule E (args ar) (sort ar))
→ DerivationRules E ar
typingdrule (TRules t) = TypingRule-TRule _ t
congruencedrule (TRules t) = TypingRule-CRule _ t
{-
Γ ⊢ A == A'
Γ , x : A ⊢ B == B'
--------------------
Γ ⊢ Π A B == Π A' B'
-}
{- Equality rules -}
{-
[extendE E tc] extends the derivability structure with one single (equality) rule
-}
data ExtE (A : JudgmentArity → Set) (nar : JudgmentArity) : JudgmentArity → Set where
equalityrule : ExtE A nar nar
prev : {jar : JudgmentArity} → A jar → ExtE A nar jar
extendE : {Σ : Signature} (E : DerivabilityStructure Σ)
{ar : JudgmentArity}
(tc : DerivationRule Σ ar)
→ DerivabilityStructure Σ
Rules (extendE E {ar} tc) S = Rules E S
Rules (extendE E {ar} tc) T = Rules E T
Rules (extendE E {ar} tc) C = Rules E C
Rules (extendE E {ar} tc) Eq = ExtE (Rules E Eq) ar
derivationRule (extendE E tc) {S} r = derivationRule E r
derivationRule (extendE E tc) {T} r = derivationRule E r
derivationRule (extendE E tc) {C} r = derivationRule E r
derivationRule (extendE E tc) {Eq} (prev r) = derivationRule E r
derivationRule (extendE E tc) {Eq} equalityrule = tc
-- data ExtE (A : Tag → JudgmentArity → Set) (nar : JudgmentArity) : Tag → JudgmentArity → Set where
-- equalityrule : ExtE A nar Eq nar
-- prev : {t : Tag} {jar : JudgmentArity} → A t jar → ExtE A nar t jar
-- extendE : {Σ : Signature} (E : DerivabilityStructure Σ)
-- {ar : JudgmentArity}
-- (tc : {n : ℕ} → DerivationRule Σ ar n)
-- → DerivabilityStructure Σ
-- Rules (extendE E {ar} tc) = ExtE (Rules E) ar
-- derivationRule (extendE E tc) (prev r) = derivationRule E r
-- derivationRule (extendE E tc) equalityrule = tc
record TermEquality {Σ : Signature} (E : DerivabilityStructure Σ) : Set where
constructor _<:_/_//_/_
field
type : TyExpr Σ 0
term1 : TmExpr Σ 0
der1 : Derivable E {Γ = ◇} (◇ ⊢ term1 :> type)
term2 : TmExpr Σ 0
der2 : Derivable E {Γ = ◇} (◇ ⊢ term2 :> type)
open BMTypingRule public
data EqualityRule {Σ : Signature} (E : DerivabilityStructure Σ) (args : SyntaxArityArgs) : (k : SyntaxSort) → Set where
Ty= : (ts : TypingRulePremises E args) (A B : BMTypingRule (extend^M E ts)) → EqualityRule E args Ty
Tm= : (ts : TypingRulePremises E args) (A : TermEquality (extend^M E ts)) → EqualityRule E args Tm
ERule : {Σ : Signature} {E : DerivabilityStructure Σ} {args : SyntaxArityArgs} {k : SyntaxSort}
→ EqualityRule E args k
→ DerivationRule Σ (TArityArgs args , SStoJS= k)
rule (ERule {E = E} (Ty= ts A B)) ↑ Γ js = do
as ← TypingRule-TArgs E ↑ ts js
return (◇ ⊢ (↑Expr (SubstM ↑ as) (weaken0 (A .type))) == (↑Expr (SubstM ↑ as) (weaken0 (B .type))))
rule (ERule {E = E} (Tm= ts (A <: u / _ // v / _))) ↑ Γ js = do
as ← TypingRule-TArgs E ↑ ts js
return (◇ ⊢ (↑Expr (SubstM ↑ as) (weaken0 u)) == (↑Expr (SubstM ↑ as) (weaken0 v)) :> ↑Expr (SubstM ↑ as) (weaken0 A))
| {
"alphanum_fraction": 0.6176781934,
"avg_line_length": 41.881773399,
"ext": "agda",
"hexsha": "43ab704adad8868163d5f15fb2218b7ee83c1366",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guillaumebrunerie/general-type-theories",
"max_forks_repo_path": "typingrules.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guillaumebrunerie/general-type-theories",
"max_issues_repo_path": "typingrules.agda",
"max_line_length": 155,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guillaumebrunerie/general-type-theories",
"max_stars_repo_path": "typingrules.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6029,
"size": 17004
} |
compose : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
→ (B → C)
→ (A → B)
→ A → C
compose f g x = f (g x)
| {
"alphanum_fraction": 0.3333333333,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "2b57eece9fdcd3426fcaf329884fef94e9ae5705",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
"max_forks_repo_licenses": [
"Info-ZIP"
],
"max_forks_repo_name": "seanwallawalla-forks/RosettaCodeData",
"max_forks_repo_path": "Task/Function-composition/Agda/function-composition.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Info-ZIP"
],
"max_issues_repo_name": "seanwallawalla-forks/RosettaCodeData",
"max_issues_repo_path": "Task/Function-composition/Agda/function-composition.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9ad63ea473a958506c041077f1d810c0c7c8c18d",
"max_stars_repo_licenses": [
"Info-ZIP"
],
"max_stars_repo_name": "LaudateCorpus1/RosettaCodeData",
"max_stars_repo_path": "Task/Function-composition/Agda/function-composition.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T13:42:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-05T13:42:20.000Z",
"num_tokens": 56,
"size": 132
} |
module Generic.Lib.Data.String where
open import Data.String.Base using (String) renaming (toList to toListˢ; _++_ to _++ˢ_) public
open import Generic.Lib.Decidable
import Data.String as String
instance
StringEq : Eq String
StringEq = viaBase String._≟_
| {
"alphanum_fraction": 0.7709923664,
"avg_line_length": 23.8181818182,
"ext": "agda",
"hexsha": "44de3e5704bee76d1532e8359b4ca87bf2226f8e",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Data/String.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Data/String.agda",
"max_line_length": 94,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Data/String.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 69,
"size": 262
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Orders.Total.Definition
open import Orders.Partial.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Setoids.Orders.Total.Definition where
open import Setoids.Orders.Partial.Definition
record SetoidTotalOrder {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_<_ : Rel {a} {c} A} (P : SetoidPartialOrder S _<_) : Set (a ⊔ b ⊔ c) where
open Setoid S
field
totality : (a b : A) → ((a < b) || (b < a)) || (a ∼ b)
partial : SetoidPartialOrder S _<_
partial = P
min : A → A → A
min a b with totality a b
min a b | inl (inl a<b) = a
min a b | inl (inr b<a) = b
min a b | inr a=b = a
max : A → A → A
max a b with totality a b
max a b | inl (inl a<b) = b
max a b | inl (inr b<a) = a
max a b | inr a=b = b
totalOrderToSetoidTotalOrder : {a b : _} {A : Set a} (T : TotalOrder {a} A {b}) → SetoidTotalOrder (partialOrderToSetoidPartialOrder (TotalOrder.order T))
SetoidTotalOrder.totality (totalOrderToSetoidTotalOrder T) = TotalOrder.totality T
| {
"alphanum_fraction": 0.6617391304,
"avg_line_length": 33.8235294118,
"ext": "agda",
"hexsha": "c16dc700a0f7ecb108fff182e3b5236df02530c3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Setoids/Orders/Total/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Setoids/Orders/Total/Definition.agda",
"max_line_length": 154,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Setoids/Orders/Total/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 408,
"size": 1150
} |
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
postulate
A : Set
a : A
record R : Set where
constructor c
field f : A
open R
postulate
r : R
rew₁ : ∀ x → c x ≡ r
{-# REWRITE rew₁ #-}
postulate
g : A → A
rew₂ : g (f r) ≡ a
{-# REWRITE rew₂ #-}
postulate
rew₃ : f r ≡ a
{-# REWRITE rew₃ #-}
| {
"alphanum_fraction": 0.6071428571,
"avg_line_length": 12.6451612903,
"ext": "agda",
"hexsha": "eba4f24c6586ea674a4998b31f6482d5181fc9c8",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue3848.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue3848.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue3848.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 140,
"size": 392
} |
------------------------------------------------------------------------------
-- Theorems which require a non-empty domain
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOL.NonEmptyDomain.TheoremsI where
-- The theorems below are valid on intuitionistic logic.
open import FOL.Base hiding ( pem )
------------------------------------------------------------------------------
-- We postulate some formulae and propositional functions.
postulate
A : Set
A¹ : D → Set
∀→∃ : (∀ {x} → A¹ x) → ∃ A¹
∀→∃ h = D≢∅ , h
-- Let A be a formula. If x is not free in A then ⊢ (∃x)A ↔ A
-- (Mendelson 1997, proposition 2.18 (b), p. 70).
∃-erase-add₁ : (∃[ _ ] A) ↔ A
∃-erase-add₁ = l→r , r→l
where
l→r : (∃[ _ ] A) → A
l→r (_ , a) = a
r→l : A → (∃[ _ ] A)
r→l A = D≢∅ , A
-- Quantification over a variable that does not occur can be erased or
-- added.
∀-erase-add : ((x : D) → A) ↔ A
∀-erase-add = l→r , r→l
where
l→r : ((x : D) → A) → A
l→r h = h D≢∅
r→l : A → (x : D) → A
r→l a _ = a
∃-erase-add₂ : (∃[ x ] (A ∨ A¹ x)) ↔ A ∨ (∃[ x ] A¹ x)
∃-erase-add₂ = l→r , r→l
where
l→r : ∃[ x ] (A ∨ A¹ x) → A ∨ (∃[ x ] A¹ x)
l→r (x , inj₁ a) = inj₁ a
l→r (x , inj₂ A¹x) = inj₂ (x , A¹x)
r→l : A ∨ (∃[ x ] A¹ x) → ∃[ x ] (A ∨ A¹ x)
r→l (inj₁ a) = D≢∅ , inj₁ a
r→l (inj₂ (x , A¹x)) = x , inj₂ A¹x
------------------------------------------------------------------------------
-- References
--
-- Mendelson, Elliott (1997). Introduction to Mathematical Logic. 4th
-- ed. Chapman & Hall.
| {
"alphanum_fraction": 0.4195965418,
"avg_line_length": 27.9838709677,
"ext": "agda",
"hexsha": "bf63315410ceac15927d145ec223cfd02e72e503",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOL/NonEmptyDomain/TheoremsI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOL/NonEmptyDomain/TheoremsI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOL/NonEmptyDomain/TheoremsI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 620,
"size": 1735
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module Number.Prelude.Int where
open import Cubical.Data.Int public using
( Int
; fromNatInt
; fromNegInt
; sucInt
; predInt
; sucInt+
; predInt+
; _+pos_
; _+negsuc_
) renaming
( isSetInt to isSetℤ
; _-_ to infix 7 _-ᶻ_
; _+_ to infix 5 _+ᶻ_
; pos to posᶻ
; negsuc to negsucᶻ
)
open import Number.Instances.Int public using
( +negsuc-identityˡ
; negsuc+negsuc≡+ⁿ
; sneg
; spos
) renaming
( _·_ to _·ᶻ_
; -_ to -ᶻ_
; _<_ to _<ᶻ_
; min to minᶻ
; max to maxᶻ
; is-min to is-minᶻ
; is-max to is-maxᶻ
; ·-reflects-< to ·ᶻ-reflects-<ᶻ
; is-LinearlyOrderedCommRing to is-LinearlyOrderedCommRingᶻ
)
-- Int≅Builtin
-- Int≡Builtin
-- Sign
-- spos
-- sneg
-- _·ˢ_
-- sign
-- signed
-- -_
-- -involutive
-- _·_
-- _·'_
-- _·''_
-- ·''-nullifiesʳ
-- _<_
-- min
-- max
-- <-irrefl
-- <-trans
-- <-asym
-- <-cotrans
-- +-identityʳ
-- +-identityˡ
-- -1·≡-
-- negsuc≡-pos
-- negsuc-reflects-≡
-- pos-reflects-≡
-- possuc+negsuc≡0
-- sucInt[negsuc+pos]≡0
-- +-inverseʳ
-- +-inverseˡ
-- +-inverse
-- pos+pos≡+ⁿ
-- negsuc+negsuc≡+ⁿ
-- +negsuc-identityˡ
-- pos+negsuc≡⊎
-- negsuc+pos≡⊎
-- pos+negsuc≡negsuc+pos
-- predInt-
-- pos+negsuc-swap
-- negsuc+pos-swap
-- +negsuc-assoc
-- sucInt[negsuc+pos]≡pos
-- +pos-inverse
-- +pos-assoc
-- Trichotomy
-- _≟_
-- MinTrichtotomy
-- MaxTrichtotomy
-- min-trichotomy
-- max-trichotomy
-- is-min
-- is-max
-- sucInt-reflects-<
-- predInt-reflects-<
-- sucInt-preserves-<
-- predInt-preserves-<
-- +-preserves-<
-- +-reflects-<
-- +-reflects-<ˡ
-- +-<-ext
-- ·≡·'
-- ·'-nullifiesʳ
-- ·'-nullifiesˡ
-- -distrˡ
-- ·-comm
-- -distrʳ
-- ·'-assoc
-- ·'-assoc≡
-- ·-assoc
-- ·-nullifiesˡ
-- ·-nullifiesʳ
-- ·-identityˡ
-- ·-identityʳ
-- ·-preserves-<
-- ·-reflects-<
-- ·-sucInt
-- ·-sucIntˡ
-- ·-predInt
-- ·-predIntˡ
-- -distrib
-- ·-distribˡ
-- ·-distribʳ
-- ·-Semigroup .IsSemigroup.is-assoc
-- +-Monoid .IsMonoid.is-identity
-- ·-Monoid .IsMonoid.is-identity
-- is-Semiring .IsSemiring.is-dist
-- <-StrictLinearOrder .IsStrictLinearOrder.is-tricho
| {
"alphanum_fraction": 0.5896840149,
"avg_line_length": 16.8125,
"ext": "agda",
"hexsha": "c7bb4b6f07d71ba1311d519f8375b5b1b183c435",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Prelude/Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Prelude/Int.agda",
"max_line_length": 61,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Prelude/Int.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 951,
"size": 2152
} |
------------------------------------------------------------------------
-- A coinductive definition of weak similarity
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Labelled-transition-system
module Similarity.Weak {ℓ} (lts : LTS ℓ) where
open import Equality.Propositional
open import Prelude
open import Prelude.Size
open import Bisimilarity.Weak lts as WB using ([_]_≈_; [_]_≈′_)
open import Expansion lts as E using ([_]_≳_; [_]_≳′_)
open import Indexed-container hiding (⟨_⟩)
open import Relation
open import Similarity lts as S using ([_]_≤_; [_]_≤′_)
import Similarity.General
open LTS lts
private
module General = Similarity.General lts _[_]⇒̂_ ⟶→⇒̂
open General public
using (module StepC; ⟨_⟩; challenge; force;
[_]_≡_; [_]_≡′_; []≡↔; Extensionality; extensionality)
renaming ( reflexive-≤ to reflexive-≼
; reflexive-≤′ to reflexive-≼′
; ≡⇒≤ to ≡⇒≼
; ≤:_ to ≼:_
; ≤′:_ to ≼′:_
)
-- StepC is given in the following way, rather than via open public,
-- to make hyperlinks to it more informative.
StepC : Container (Proc × Proc) (Proc × Proc)
StepC = General.StepC
-- The following definitions are given explicitly, in order to make
-- the code easier to follow.
Weak-similarity : Size → Rel₂ ℓ Proc
Weak-similarity = ν StepC
Weak-similarity′ : Size → Rel₂ ℓ Proc
Weak-similarity′ = ν′ StepC
infix 4 [_]_≼_ [_]_≼′_ _≼_ _≼′_
[_]_≼_ : Size → Proc → Proc → Type ℓ
[ i ] p ≼ q = ν StepC i (p , q)
[_]_≼′_ : Size → Proc → Proc → Type ℓ
[ i ] p ≼′ q = ν′ StepC i (p , q)
_≼_ : Proc → Proc → Type ℓ
_≼_ = [ ∞ ]_≼_
_≼′_ : Proc → Proc → Type ℓ
_≼′_ = [ ∞ ]_≼′_
private
-- However, these definitions are definitionally equivalent to
-- corresponding definitions in General.
indirect-Weak-similarity : Weak-similarity ≡ General.Similarity
indirect-Weak-similarity = refl
indirect-Weak-similarity′ : Weak-similarity′ ≡ General.Similarity′
indirect-Weak-similarity′ = refl
indirect-[]≼ : [_]_≼_ ≡ General.[_]_≤_
indirect-[]≼ = refl
indirect-[]≼′ : [_]_≼′_ ≡ General.[_]_≤′_
indirect-[]≼′ = refl
indirect-≼ : _≼_ ≡ General._≤_
indirect-≼ = refl
indirect-≼′ : _≼′_ ≡ General._≤′_
indirect-≼′ = refl
mutual
-- Weak bisimilarity is contained in weak similarity.
≈⇒≼ : ∀ {i p q} → [ i ] p ≈ q → [ i ] p ≼ q
≈⇒≼ = λ p≈q →
⟨ (λ q⟶q′ →
let p′ , p⇒̂p′ , p′≈′q′ = WB.left-to-right p≈q q⟶q′
in p′ , p⇒̂p′ , ≈⇒≼′ p′≈′q′)
⟩
≈⇒≼′ : ∀ {i p q} → [ i ] p ≈′ q → [ i ] p ≼′ q
force (≈⇒≼′ p≳′q) = ≈⇒≼ (S.force p≳′q)
mutual
-- Similarity is contained in weak similarity.
≤⇒≼ : ∀ {i p q} → [ i ] p ≤ q → [ i ] p ≼ q
≤⇒≼ = λ p≤q →
⟨ (λ q⟶q′ →
let p′ , p⟶p′ , p′≤′q′ = S.challenge p≤q q⟶q′
in p′ , ⟶→⇒̂ p⟶p′ , ≤⇒≼′ p′≤′q′)
⟩
≤⇒≼′ : ∀ {i p q} → [ i ] p ≤′ q → [ i ] p ≼′ q
force (≤⇒≼′ p≳′q) = ≤⇒≼ (S.force p≳′q)
-- Weak similarity is a weak simulation (of a certain kind).
weak-is-weak⇒̂ :
∀ {p p′ q μ} →
p ≼ q → p [ μ ]⇒̂ p′ →
∃ λ q′ → q [ μ ]⇒̂ q′ × p′ ≼ q′
weak-is-weak⇒̂ = is-weak⇒̂ challenge (λ p≼′q → force p≼′q) ⇒̂→⇒ id
mutual
-- Weak similarity is transitive.
--
-- Note that the size of the second argument is not preserved.
--
-- TODO: Can one prove that the size cannot be preserved?
transitive-≼ : ∀ {i p q r} → [ i ] p ≼ q → q ≼ r → [ i ] p ≼ r
transitive-≼ p≼q q≼r =
⟨ (λ p⟶p′ →
let q′ , q⇒̂q′ , p′≼q′ = challenge p≼q p⟶p′
r′ , r⇒̂r′ , q′≼r′ = weak-is-weak⇒̂ q≼r q⇒̂q′
in r′ , r⇒̂r′ , transitive-≼′ p′≼q′ q′≼r′)
⟩
transitive-≼′ :
∀ {i p q r} → [ i ] p ≼′ q → q ≼ r → [ i ] p ≼′ r
force (transitive-≼′ p≼q q≼r) = transitive-≼ (force p≼q) q≼r
mutual
-- A fully size-preserving transitivity-like lemma.
--
-- Note that expansion could be replaced by a kind of one-sided
-- expansion.
transitive-≳≼ : ∀ {i p q r} → [ i ] p ≳ q → [ i ] q ≼ r → [ i ] p ≼ r
transitive-≳≼ p≳q q≼r =
⟨ (λ p⟶p′ → case E.left-to-right p≳q p⟶p′ of λ where
(_ , done s , p′≳q) →
_ , silent s done
, transitive-≳≼′
p′≳q (record { force = λ { {_} → q≼r } })
(q′ , step q⟶q′ , p′≳q′) →
let r′ , r⇒̂r′ , q′≼r′ = challenge q≼r q⟶q′
in r′ , r⇒̂r′ , transitive-≳≼′ p′≳q′ q′≼r′)
⟩
transitive-≳≼′ :
∀ {i p q r} → [ i ] p ≳′ q → [ i ] q ≼′ r → [ i ] p ≼′ r
force (transitive-≳≼′ p≼q q≼r) =
transitive-≳≼ (force p≼q) (force q≼r)
| {
"alphanum_fraction": 0.5061943056,
"avg_line_length": 27.224852071,
"ext": "agda",
"hexsha": "1a746bd12b5fa645db3f6bf9770d2510e65a7105",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Similarity/Weak.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Similarity/Weak.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Similarity/Weak.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1959,
"size": 4601
} |
module Implicits.Everything where
-- common agda stdlib imports
open import Prelude
--
-- Oliveira's calculi in Agda
--
-- We give a well-scoped version of Oliveira's ambiguous and deterministic
-- resolution rules
open import Implicits.Resolution.Ambiguous.Resolution
open import Implicits.Resolution.Deterministic.Resolution
-- and prove soundness of det. resolution w.r.t the ambiguous one
open import Implicits.Resolution.Deterministic.Expressiveness
-- we show that Oliveira's deterministic rules are incomplete w.r.t.
-- the ambiguous resolution
open import Implicits.Resolution.Deterministic.Incomplete
-- and prove ambiguous resolution undecidable
open import Implicits.Resolution.Ambiguous.SystemFEquiv
open import Implicits.Resolution.Ambiguous.Undecidable
--
-- Partial resolution
--
-- We maintain the syntax-directedness of the rules and strenghten the hypothesis of r-simp
-- to circumvent the weakness of Oliveira's deterministic rules.
-- In order to maintain strict-positiveness of the rules, we drop determinacy.
-- We will regain determinacy in the algorithmic description of resolution.
open import Implicits.Resolution.Infinite.Resolution
-- We first show that the rules are isomorphic to EBNF System F expressions
-- and use it to prove that infinite resolution is complete w.r.t. ambiguous resolution.
open import Implicits.Resolution.Infinite.NormalFormEquiv
open import Implicits.Resolution.Infinite.Expressiveness
-- Furthermore we give a partial algorithm for infinite resolution.
-- We have soundness and develop partial completeness for this algorithm.
open import Implicits.Resolution.Infinite.Algorithm
open import Implicits.Resolution.Infinite.Algorithm.Soundness
-- open import Implicits.Resolution.Infinite.Algorithm.Completeness
-- We'd love to show that the existence of a finite resolution Δ ⊢ᵣ r guarantees
-- termination of the partial resolution algorithm on input r;
-- but this clearly isn't a theorem: it's easy to imagine an implicit context that both has
-- a diverging 'trap' for the deterministic algorithm but also allows a finite 'shortcut'
-- derivation (hiding behind the trap).
-- In fact, the fact that infinite resolution is complete w.r.t. Ambiguous resolution,
-- indirectly proves that it's undecidable.
-- Instead we define a version of infinite resolution with a generic termination condition
open import Implicits.Resolution.GenericFinite.TerminationCondition
open import Implicits.Resolution.GenericFinite.Resolution
open import Implicits.Resolution.GenericFinite.Expressiveness
-- We give a total algorithm and prove it sound
open import Implicits.Resolution.GenericFinite.Algorithm
open import Implicits.Resolution.GenericFinite.Algorithm.Soundness
-- and develop completeness; finished modulo 2 lemmas
-- open import Implicits.Resolution.GenericFinite.Algorithm.Completeness
-- We provide two examples of termination conditions
-- A simple "maximum depth" condition like Coq's auto tactic has:
open import Implicits.Resolution.GenericFinite.Examples.MaximumDepth
-- And basically a termination condition inspired by Haskell's conditions on
-- typeclasses, developed by Oliveira et al.
-- Importantly we prove that the resulting calculus is more expressive than
-- Oliveira's deterministic resolution
open import Implicits.Resolution.GenericFinite.Examples.Haskell
-- We define a denotation semantics for the entire calculus -- into System F.
-- To this end we develop System F:
open import SystemF.Syntax
open import SystemF.WellTyped
open import SystemF.SmallStep
open import SystemF.NormalForm
-- The actual semantics is implemented aa module that depends on
-- the semantics for your favorite flavor of resolution.
-- It includes a proof that the translation preserves the typing relation.
open import Implicits.Semantics.Preservation
open import Implicits.Semantics
| {
"alphanum_fraction": 0.8179220779,
"avg_line_length": 44.2528735632,
"ext": "agda",
"hexsha": "de5686b8f21fcb8c0d4121164601cf87eaabe8b0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Everything.agda",
"max_line_length": 91,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 824,
"size": 3850
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Operations on nullary relations (like negation and decidability)
------------------------------------------------------------------------
-- Some operations on/properties of nullary relations, i.e. sets.
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary where
open import Agda.Builtin.Equality
open import Data.Bool.Base
open import Data.Empty hiding (⊥-elim)
open import Data.Empty.Irrelevant
open import Level
------------------------------------------------------------------------
-- Negation.
infix 3 ¬_
infix 2 _because_
¬_ : ∀ {ℓ} → Set ℓ → Set ℓ
¬ P = P → ⊥
------------------------------------------------------------------------
-- `Reflects` idiom.
-- The truth value of P is reflected by a boolean value.
data Reflects {p} (P : Set p) : Bool → Set p where
ofʸ : ( p : P) → Reflects P true
ofⁿ : (¬p : ¬ P) → Reflects P false
------------------------------------------------------------------------
-- Decidability.
-- Decidability proofs have two parts: the `does` term which contains
-- the boolean result and the `proof` term which contains a proof that
-- reflects the boolean result. This definition allows the boolean
-- part of the decision procedure to compute independently from the
-- proof. This leads to better computational behaviour when we only care
-- about the result and not the proof. See README.Decidability for
-- further details.
record Dec {p} (P : Set p) : Set p where
constructor _because_
field
does : Bool
proof : Reflects P does
open Dec public
pattern yes p = true because ofʸ p
pattern no ¬p = false because ofⁿ ¬p
-- Given an irrelevant proof of a decidable type, a proof can
-- be recomputed and subsequently used in relevant contexts.
recompute : ∀ {a} {A : Set a} → Dec A → .A → A
recompute (yes x) _ = x
recompute (no ¬p) x = ⊥-elim (¬p x)
------------------------------------------------------------------------
-- Irrelevant types
Irrelevant : ∀ {p} → Set p → Set p
Irrelevant P = ∀ (p₁ p₂ : P) → p₁ ≡ p₂
| {
"alphanum_fraction": 0.5492890995,
"avg_line_length": 29.7183098592,
"ext": "agda",
"hexsha": "869a0ae406b2b89b858a0ddfb1d8ae15069faf9a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Relation/Nullary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Nullary.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Nullary.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 500,
"size": 2110
} |
{-# OPTIONS --cubical --safe #-}
module DTLC.Base where
open import Cubical.Foundations.Prelude hiding (Σ; _,_)
open import Cubical.Foundations.Function
--------------------------------------------------------------------------
-- Adapted from: Type Theory in Type Theory using Quotient Inductive Types
-- by Thorsten Altenkirch and Ambrus Kaposi
-- See: http://www.cs.nott.ac.uk/~psztxa/publ/tt-in-tt.pdf
--
-- Note: We have changed a number of names relative to this paper, in the
-- interest of clarity. In particular, Tms is now _~>_, with the
-- arguments reversed. Thus, _∘_ (which we call _∘*_) also is reversed
-- with respect to [AK16]. Furthermore, we renamed π₁ to tail*, π₂
-- to head*, and app to unlam to make their functions more clear.
--------------------------------------------------------------------------
infixl 6 _,_
infixl 6 _,*_
infixr 5 _∘*_
PathPSyntax = PathP
syntax PathPSyntax A x y = x ≡[ A ]≡ y
infix 2 PathPSyntax
-----------------
-- Declarations
-----------------
-- We will mutually inductively define:
-- The type of contexts
data Ctx : Type₀
-- The type of types
data Typ : Ctx -> Type₀
-- The type of judgements x : τ ⊣ Γ ("x has type τ in context Γ")
Term : (Γ : Ctx) -> Typ Γ -> Type₀
syntax Term Γ τ = τ ⊣ Γ
-- The type of transformations / generalized subsitutions between contexts
_~>_ : Ctx -> Ctx -> Type₀
-- ...in fact, we define terms and transformations together:
data TmQV : Type₀ where
TmV : TmQV
TrV : TmQV
TmQArg : TmQV -> Ctx -> Type₀
TmQArg TmV Γ = Typ Γ
TmQArg TrV _ = Ctx
data TmQ : (a : TmQV) -> (Γ : Ctx) -> TmQArg a Γ -> Type₀
Term = TmQ TmV
_~>_ = TmQ TrV
-- Some forward declarations:
id* : ∀ {Γ} -> Γ ~> Γ
_∘*_ : ∀ {Γ Δ Σ} -> (Δ ~> Σ) -> (Γ ~> Δ) -> Γ ~> Σ
_[_]T : ∀ {Γ Δ} (τ : Typ Γ) (f : Γ ~> Δ) -> Typ Δ
_[_] : ∀ {Γ Δ τ} (x : τ ⊣ Γ) (f : Γ ~> Δ) -> (τ [ f ]T) ⊣ Δ
----------------
-- Definitions
----------------
data Ctx where
∙ : Ctx
_,_ : (Γ : Ctx) -> Typ Γ -> Ctx
-- Unlike Altenkirch-Kaposi, we have a universe of types U:
data Typ where
U : ∀ {Γ} -> Typ Γ
type : ∀ {Γ} (τ : U ⊣ Γ) -> Typ Γ
-- Subsitution on types is defined in terms of substition on terms!
U [ f ]T = U
(type τ) [ f ]T = type (τ [ f ])
-- Substitution on types is a functor -- definitions are below
[id]T : ∀ {Γ} (τ : Typ Γ) -> τ [ id* ]T ≡ τ
[][]T : ∀ {Γ Δ Σ} (g : Δ ~> Σ) (f : Γ ~> Δ) (τ : Typ Γ)
-> τ [ f ]T [ g ]T ≡ τ [ g ∘* f ]T
-- Having these is quite useful for readibility:
coeTm : ∀ {Γ} {x y : Typ Γ} -> x ≡ y -> Term Γ x -> Term Γ y
coeTm p = transport (cong (Term _) p)
coeTmTy : ∀ {Γ} {τ σ : Term Γ U} -> τ ≡ σ -> Term Γ (type τ) -> Term Γ (type σ)
coeTmTy p = transport (cong (Term _ ∘ type) p)
-- We define terms and transformations together
data TmQ where
-- Ctx and ~> form a category
-- Note: these are the definitions of id* and ∘* -- see below
id*C : ∀ {Γ} -> Γ ~> Γ
_∘*C_ : ∀ {Γ Δ Σ} -> (Δ ~> Σ) -> (Γ ~> Δ) -> Γ ~> Σ
id*-l : ∀ {Γ Δ} (f : Γ ~> Δ) -> id* ∘* f ≡ f
id*-r : ∀ {Γ Δ} (f : Γ ~> Δ) -> f ∘* id* ≡ f
assoc : ∀ {Γ Δ Σ P} (h : Σ ~> P) (g : Δ ~> Σ) (f : Γ ~> Δ)
-> (h ∘* g) ∘* f ≡ h ∘* (g ∘* f)
-- ~> has a list structure on its first argument
∙* : ∀ {Δ} -> ∙ ~> Δ
_,*_ : ∀ {Γ Δ τ} (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T)) -> (Γ , τ) ~> Δ
tail* : ∀ {Γ Δ τ} (f : (Γ , τ) ~> Δ) -> Γ ~> Δ
head* : ∀ {Γ Δ τ} (f : (Γ , τ) ~> Δ) -> (τ [ tail* f ]T) ⊣ Δ
,*-∘* : ∀ {Γ Δ Σ τ} (g : Δ ~> Σ) (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T))
-> g ∘* (f ,* x) ≡ (g ∘* f) ,* coeTm ([][]T g f τ) (x [ g ])
-- Computation rules for tail* and head*
tail*-β : ∀ {Γ Δ τ} (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T)) -> tail* (f ,* x) ≡ f
head*-β : ∀ {Γ Δ τ} (f : Γ ~> Δ) (x : Term Δ (τ [ f ]T))
-> head* (f ,* x) ≡[ (λ i → (τ [ tail*-β f x i ]T) ⊣ Δ) ]≡ x
-- Uniqueness rules for ~>
∙*-η : ∀ {Δ} (f : ∙ ~> Δ) -> f ≡ ∙*
,*-η : ∀ {Γ Δ τ} (f : (Γ , τ) ~> Δ) -> (tail* f ,* head* f) ≡ f
-- A useful combinator, defined in terms of the above
_↑_ : ∀ {Γ Δ} (f : Γ ~> Δ) (τ : Typ Γ) -> (Γ , τ) ~> (Δ , τ [ f ]T)
↑-β : ∀ {Γ Δ} (f : Γ ~> Δ) (τ : Typ Γ) -> (Γ , τ) ~> (Δ , τ [ f ]T)
-> f ↑ τ ≡ (tail* id* ∘* f) ,* coeTm ([][]T (tail* id*) f τ) (head* id*)
-- The definition of substitution on terms _[_]
_[_]C : ∀ {Γ Δ τ} (x : τ ⊣ Γ) (f : Γ ~> Δ) -> (τ [ f ]T) ⊣ Δ
-- Substitution on terms is a functor
[id] : ∀ {Γ τ} (x : τ ⊣ Γ) -> x [ id* ] ≡[ (λ i → ([id]T τ i) ⊣ Γ) ]≡ x
[][] : ∀ {Γ Δ Σ τ} (g : Δ ~> Σ) (f : Γ ~> Δ) (x : τ ⊣ Γ)
-> x [ f ] [ g ] ≡[ (λ i → ([][]T g f τ i) ⊣ Σ) ]≡ x [ g ∘* f ]
-- Pi types and their computation rule for substition
Π : ∀ {Γ} (τ : Typ Γ) (σ : Typ (Γ , τ)) -> U ⊣ Γ
Π[] : ∀ {Γ Δ} (τ : Typ Γ) (σ : Typ (Γ , τ)) (f : Γ ~> Δ)
-> (Π τ σ) [ f ] ≡ Π (τ [ f ]T) (σ [ f ↑ τ ]T)
-- lambdas and their computation rule for substitition
lam : ∀ {Γ τ σ} (y : σ ⊣ (Γ , τ)) -> type (Π τ σ) ⊣ Γ
lam[] : ∀ {Γ Δ τ σ} (y : σ ⊣ (Γ , τ)) (f : Γ ~> Δ)
-> lam y [ f ] ≡[ (λ i → type (Π[] τ σ f i) ⊣ Δ) ]≡ lam (y [ f ↑ τ ])
-- Pi type elim, whose computation rule for substition is derivable using Π-η
-- (Note: application is defined in terms of this below)
unlam : ∀ {Γ τ σ} (ℓ : type (Π τ σ) ⊣ Γ) -> σ ⊣ (Γ , τ)
-- Computation and uniqueness for Pi types
Π-β : ∀ {Γ τ σ} (y : σ ⊣ (Γ , τ)) -> unlam (lam y) ≡ y
Π-η : ∀ {Γ τ σ} (ℓ : type (Π τ σ) ⊣ Γ) -> lam (unlam ℓ) ≡ ℓ
-- The missing substitution computation rule for unlam, derivable because we have definitional η!
unlam[] : ∀ {Γ Δ τ σ} (ℓ : type (Π τ σ) ⊣ Γ) (f : Γ ~> Δ)
-> unlam ℓ [ f ↑ τ ] ≡ unlam (coeTmTy (Π[] τ σ f) (ℓ [ f ]))
unlam[] {Γ} {Δ} {τ} {σ} ℓ f =
(unlam ℓ) [ f ↑ τ ] ≡[ i ]⟨ Π-β ((unlam ℓ) [ f ↑ τ ]) (~ i) ⟩
unlam (lam ((unlam ℓ) [ f ↑ τ ])) ≡[ i ]⟨ unlam (fromPathP (lam[] (unlam ℓ) f) (~ i)) ⟩
unlam (coeTmTy (Π[] τ σ f) ((lam (unlam ℓ)) [ f ])) ≡[ i ]⟨ unlam (coeTmTy (Π[] τ σ f) ((Π-η ℓ i) [ f ])) ⟩
unlam (coeTmTy (Π[] τ σ f) (ℓ [ f ])) ∎
-- Missing definitions from above
[id]T U = refl
[id]T (type τ) = cong type ([id] τ)
[][]T g f U = refl
[][]T g f (type τ) = cong type ([][] g f τ)
id* = id*C
_∘*_ = _∘*C_
_[_] = _[_]C
--------------------
-- Derived Notions
--------------------
-- Weakening on contexts
wkn : ∀ {Γ τ} -> Γ ~> (Γ , τ)
wkn = tail* id*
-- A single substition at the top of a context
<_> : ∀ {Γ τ} (x : τ ⊣ Γ) -> (Γ , τ) ~> Γ
< x > = id* ,* coeTm (sym ([id]T _)) x
-- Using substition, we can now write the usual definition of application
_$_ : ∀ {Γ τ σ} (ℓ : (type (Π τ σ)) ⊣ Γ) (x : τ ⊣ Γ) -> (σ [ < x > ]T) ⊣ Γ
ℓ $ x = unlam ℓ [ < x > ]
infixl 4 _$_
-- Variables (as de Bruijn indices) are also derived!
var₀ : ∀ {Γ τ} -> (τ [ wkn ]T) ⊣ (Γ , τ)
var₀ = head* id*
var₊ : ∀ {Γ τ σ} -> τ ⊣ Γ -> (τ [ wkn ]T) ⊣ (Γ , σ)
var₊ x = x [ wkn ]
var₁ : ∀ {Γ τ σ} -> (τ [ wkn ]T [ wkn ]T) ⊣ ((Γ , τ) , σ)
var₁ = var₊ var₀
var₂ : ∀ {Γ τ σ ρ} -> (τ [ wkn ]T [ wkn ]T [ wkn ]T) ⊣ (((Γ , τ) , σ) , ρ)
var₂ = var₊ var₁
-- The other classical operations on contexts:
ctr : ∀ {Γ τ} -> (Γ , τ , τ [ wkn ]T) ~> (Γ , τ)
ctr {Γ} {τ} = id* ,* coeTm (sym p) var₀
where p : τ [ wkn ]T [ id* ]T ≡ τ [ tail* id* ]T
p =
τ [ wkn ]T [ id* ]T ≡⟨ [][]T id* wkn _ ⟩
τ [ id* ∘* wkn ]T ≡⟨ cong (τ [_]T) (id*-l wkn) ⟩
τ [ tail* id* ]T ∎
-- exg : ∀ {Γ τ σ} -> (Γ , τ , σ [ wkn ]T) ~> (Γ , σ , τ [ wkn ]T)
-- exg {Γ} {τ} {σ} = wkn ∘* wkn ,*
-- coeTm ([][]T wkn wkn τ) var₀ ,*
-- coeTm (sym p) (coeTm ([][]T wkn wkn σ) var₁)
-- where p : σ [ wkn ]T [ (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₀ ]T ≡ σ [ wkn ∘* wkn ]T
-- p = begin
-- σ [ wkn ]T [ (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₀ ]T ≡⟨ [][]T _ _ σ ⟩
-- σ [ ((wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₀) ∘* wkn ]T ≡⟨ cong (σ [_]T) {!!} ⟩
-- σ [ wkn ∘* wkn ]T ∎
-- -- p' : (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₁ ≡ wkn
-- -- p' = begin
-- -- (wkn ∘* wkn) ,* coeTm ([][]T wkn wkn τ) var₁ ≡⟨ sym (,*-∘* wkn wkn var₀) ⟩
-- -- wkn ∘* (wkn ,* var₀) ≡⟨ cong (wkn ∘*_) (,*-η id*) ⟩
-- -- wkn ∘* id* ≡⟨ id*-r wkn ⟩
-- -- wkn ∎
--------------------------------------
-- Experimental: Encoding more types
--------------------------------------
_⇒_ : ∀ {Γ} (τ : U ⊣ Γ) (σ : U ⊣ (Γ , type τ)) -> U ⊣ Γ
x ⇒ y = Π (type x) (type y)
infixr 4 _⇒_
-- The natural number type
N : ∀ {Γ} -> U ⊣ Γ
N = Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂))
-- N[] : ∀ {Γ Δ} (f : Γ ~> Δ) -> type N [ f ]T ≡ type N
-- N[] f = cong type p
-- where p : Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂)) [ f ] ≡ Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂))
-- p = begin
-- Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂)) [ f ] ≡⟨ Π[] _ _ f ⟩
-- Π U (type ((var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂) [ f ↑ U ])) ≡⟨ {!!} ⟩
-- Π U (type (var₀ ⇒ (var₁ ⇒ var₂) ⇒ var₂)) ∎
z : ∀ {Γ} -> type N ⊣ Γ
z = lam (lam (lam var₁))
-- s : ∀ {Γ} (n : type N ⊣ Γ) -> type N ⊣ Γ
-- s {Γ} n = lam (lam (lam {!!})) -- var₀ $ (n' $ var₀ $ var₁ $ var₂)
-- where n' : type N ⊣ (((Γ , U) , type var₀) , type (var₁ ⇒ var₂))
-- n' = coe (cong (Term _) {!!}) (var₊ (var₊ (var₊ n)))
-- The dependent pair type
-- Σ : ∀ {Γ} (τ : Typ Γ) (σ : Typ (Γ , τ)) -> U ⊣ Γ
-- Σ τ σ = Π U (type ((Π (τ [ tail* id* ]T) (type (Π (σ [ tail* id* ↑ τ ]T) (type var₂)))) ⇒ var₀))
-- pair : ∀ {Γ τ σ} (x : τ ⊣ Γ) (y : σ ⊣ (Γ , τ)) -> (type (Σ τ σ)) ⊣ Γ
-- pair x y = lam (lam {!!})
-- Σ : ∀ {Γ} (τ : Typ Γ) (σ : Typ (Γ , τ)) -> U ⊣ Γ
-- Σ[] : ∀ {Γ Δ} (τ : Typ Γ) (σ : Typ (Γ , τ)) (f : Γ ~> Δ)
-- -> (Σ τ σ) [ f ] ≡ Σ (τ [ f ]T) (σ [ f ↑ τ ]T)
-- pair : ∀ {Γ τ σ} (x : τ ⊣ Γ) (y : σ ⊣ (Γ , τ)) -> (type (Σ τ σ)) ⊣ Γ
-- pair[] : ∀ {Γ Δ τ σ} (x : τ ⊣ Γ) (y : σ ⊣ (Γ , τ)) (f : Γ ~> Δ)
-- -> (pair x y) [ f ] ≡[ (λ i → type (Σ[] τ σ f i) ⊣ Δ) ]≡ pair (x [ f ]) (y [ f ↑ τ ])
-- Σ-ind : ∀ {Γ τ σ} (ρ : Typ (Γ , type (Σ τ σ)))
-- (xy : (ρ [ {!!} ∘* ({!!} ↑ type (Σ τ σ)) ]T) ⊣ ((Γ , τ) , σ))
-- -> ρ ⊣ (Γ , type (Σ τ σ))
| {
"alphanum_fraction": 0.4290752351,
"avg_line_length": 33.8013245033,
"ext": "agda",
"hexsha": "ea772fd0dbf7a2b704f9e3284438f684b7ab22fe",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z",
"max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ajnavarro/language-dataset",
"max_forks_repo_path": "data/github.com/m-yac/tt-in-cagda/d2c1c36cb3e09d8c3c73b8a043dbe36865765bce/src/DTLC/Base.agda",
"max_issues_count": 91,
"max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ajnavarro/language-dataset",
"max_issues_repo_path": "data/github.com/m-yac/tt-in-cagda/d2c1c36cb3e09d8c3c73b8a043dbe36865765bce/src/DTLC/Base.agda",
"max_line_length": 109,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ajnavarro/language-dataset",
"max_stars_repo_path": "data/github.com/m-yac/tt-in-cagda/d2c1c36cb3e09d8c3c73b8a043dbe36865765bce/src/DTLC/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z",
"num_tokens": 4558,
"size": 10208
} |
module Metalogic.Linear.Syntax {ℓₚ} (Proposition : Set(ℓₚ)) where
import Lvl
-- https://en.wikipedia.org/wiki/Linear_logic
-- https://plato.stanford.edu/entries/logic-linear/#ProSys
data Formula : Set(ℓₚ) where
•_ : Proposition → Formula
-- Top
⊤ : Formula
-- Bottom
⊥ : Formula
-- Classical conjunction
_∧_ : Formula → Formula → Formula
-- Classical disjunction
_∨_ : Formula → Formula → Formula
-- Additive and
_&_ : Formula → Formula → Formula
-- Additive or
_⊕_ : Formula → Formula → Formula
-- Multiplicative and
_⊗_ : Formula → Formula → Formula
-- Multiplicative or
_⅋_ : Formula → Formula → Formula
-- Linear implication
_⊸_ : Formula → Formula → Formula
| {
"alphanum_fraction": 0.6574202497,
"avg_line_length": 16.0222222222,
"ext": "agda",
"hexsha": "48d496aac85d86bd0cb5a0f1ff74170dac941e44",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Metalogic/Linear/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Metalogic/Linear/Syntax.agda",
"max_line_length": 65,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Metalogic/Linear/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 222,
"size": 721
} |
{-# OPTIONS --erased-cubical --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Cubical.Id where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub renaming (primSubOut to ouc; Sub to _[_↦_])
{-# BUILTIN ID Id #-}
{-# BUILTIN REFLID reflId #-}
private
module ConId where
primitive
primConId : ∀ {ℓ} {A : Set ℓ} {x y : A} → I → x ≡ y → Id x y
open ConId public renaming (primConId to conid)
-- Id x y is treated as a pair of I and x ≡ y, using "i" for the
-- first component and "p" for the second.
{-# COMPILE JS conid =
_ => _ => _ => _ => i => p => { return { "i" : i, "p" : p } }
#-}
primitive
primDepIMin : _
primIdFace : ∀ {ℓ} {A : Set ℓ} {x y : A} → Id x y → I
primIdPath : ∀ {ℓ} {A : Set ℓ} {x y : A} → Id x y → x ≡ y
primitive
primIdJ : ∀ {ℓ ℓ'} {A : Set ℓ} {x : A} (P : ∀ y → Id x y → Set ℓ') →
P x (conid i1 (λ i → x)) → ∀ {y} (p : Id x y) → P y p
primitive
primIdElim : ∀ {a c} {A : Set a} {x : A}
(C : (y : A) → Id x y → Set c) →
((φ : I) (y : A [ φ ↦ (λ _ → x) ])
(w : (x ≡ ouc y) [ φ ↦ (λ { (φ = i1) → \ _ → x}) ]) →
C (ouc y) (conid φ (ouc w))) →
{y : A} (p : Id x y) → C y p
| {
"alphanum_fraction": 0.4617563739,
"avg_line_length": 32.8372093023,
"ext": "agda",
"hexsha": "6236b43f51f6f38ee6f9b8f608f179134bb196d4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Id.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Id.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Cubical/Id.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 534,
"size": 1412
} |
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Neutral {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties.Reflexivity
open import Definition.LogicalRelation.Properties.Escape
open import Definition.LogicalRelation.Properties.Symmetry
import Definition.LogicalRelation.Weakening as W
open import Tools.Product
import Tools.PropositionalEquality as PE
import Data.Fin as Fin
import Data.Nat as Nat
-- Neutral reflexive types are reducible.
neu : ∀ {l Γ A r ll} (neA : Neutral A)
→ Γ ⊢ A ^ [ r , ι ll ]
→ Γ ⊢ A ~ A ∷ Univ r ll ^ [ ! , next ll ]
→ Γ ⊩⟨ l ⟩ A ^ [ r , ι ll ]
neu neA A A~A = ne′ _ (idRed:*: A) neA A~A
-- Helper function for reducible neutral equality of a specific type of derivation.
neuEq′ : ∀ {l Γ A B r ll} ([A] : Γ ⊩⟨ l ⟩ne A ^[ r , ll ])
(neA : Neutral A)
(neB : Neutral B)
→ Γ ⊢ A ^ [ r , ι ll ] → Γ ⊢ B ^ [ r , ι ll ]
→ Γ ⊢ A ~ B ∷ Univ r ll ^ [ ! , next ll ]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ι ll ] / ne-intr [A]
neuEq′ (noemb (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neA neB A B A~B =
let A≡K = whnfRed* D (ne neA)
in ne₌ _ (idRed:*: B) neB (PE.subst (λ x → _ ⊢ x ~ _ ∷ _ ^ _) A≡K A~B)
neuEq′ {ι ¹} (emb emb< X) = neuEq′ X
neuEq′ {∞} (emb ∞< X) = neuEq′ X
-- Neutrally equal types are of reducible equality.
neuEq : ∀ {l Γ A B r ll} ([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ι ll ])
(neA : Neutral A)
(neB : Neutral B)
→ Γ ⊢ A ^ [ r , ι ll ] → Γ ⊢ B ^ [ r , ι ll ]
→ Γ ⊢ A ~ B ∷ Univ r ll ^ [ ! , next ll ]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ι ll ] / [A]
neuEq [A] neA neB A B A~B =
irrelevanceEq (ne-intr (ne-elim neA [A]))
[A]
(neuEq′ (ne-elim neA [A]) neA neB A B A~B)
mutual
neuTerm⁰ : ∀ {Γ A r n} ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ r) (neN : Neutral n)
→ Γ ⊢ n ∷ A ^ r
→ Γ ⊢ n ~ n ∷ A ^ r
→ Γ ⊩⟨ ι ⁰ ⟩ n ∷ A ^ r / [A]
neuTerm⁰ (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN n n~n =
let A≡ℕ = subset* D
n~n′ = ~-conv n~n A≡ℕ
n≡n = ~-to-≅ₜ n~n′
in ℕₜ _ (idRedTerm:*: (conv n A≡ℕ)) n≡n (ne (neNfₜ neN (conv n A≡ℕ) n~n′))
neuTerm⁰ {r = [ ! , ll ]} (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) neN n n~n =
let A≡K = subset* D
in neₜ _ (idRedTerm:*: (conv n A≡K)) (neNfₜ neN (conv n A≡K)
(~-conv n~n A≡K))
neuTerm⁰ {r = [ ! , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n =
let A≡ΠFG = subset* (red D)
in Πₜ _ (idRedTerm:*: (conv n A≡ΠFG)) (ne neN) (~-to-≅ₜ (~-conv n~n A≡ΠFG))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let A≡ΠFG = subset* (red D)
ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
G[a]≡G[b] = escapeEq ([G] [ρ] ⊢Δ [b])
(symEq ([G] [ρ] ⊢Δ [a]) ([G] [ρ] ⊢Δ [b])
(G-ext [ρ] ⊢Δ [a] [b] [a≡b]))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
b = escapeTerm ([F] [ρ] ⊢Δ) [b]
a≡b = escapeTermEq ([F] [ρ] ⊢Δ) [a≡b]
ρn = conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG
neN∘a = ∘ₙ (wkNeutral ρ neN)
neN∘b = ∘ₙ (wkNeutral ρ neN)
in neuEqTerm⁰ ([G] [ρ] ⊢Δ [a]) neN∘a neN∘b
(ρn ∘ⱼ a)
(conv (ρn ∘ⱼ b) (≅-eq G[a]≡G[b]))
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡b))
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ) (reflEqTerm ([F] [ρ] ⊢Δ) [a])
in neuTerm⁰ ([G] [ρ] ⊢Δ [a]) (∘ₙ (wkNeutral ρ neN))
(conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡a))
neuTerm⁰ (Emptyᵣ [[ ⊢A , ⊢B , D ]]) neN n n~n =
let A≡ℕ = subset* D
in Emptyₜ (ne (conv n A≡ℕ))
neuTerm⁰ {r = [ % , ll ]} (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) neN n n~n =
let A≡K = subset* D
in neₜ n
neuTerm⁰ {r = [ % , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n = let A≡ΠFG = subset* (red D) in conv n A≡ΠFG
neuTerm⁰ {r = [ % , ll ]} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n = let A≡ΠFG = subset* (red D) in conv n A≡ΠFG
neuEqTerm⁰ : ∀ {Γ A n n′ r} ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ r)
(neN : Neutral n) (neN′ : Neutral n′)
→ Γ ⊢ n ∷ A ^ r
→ Γ ⊢ n′ ∷ A ^ r
→ Γ ⊢ n ~ n′ ∷ A ^ r
→ Γ ⊩⟨ ι ⁰ ⟩ n ≡ n′ ∷ A ^ r / [A]
neuEqTerm⁰ (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN neN′ n n′ n~n′ =
let A≡ℕ = subset* D
n~n′₁ = ~-conv n~n′ A≡ℕ
n≡n′ = ~-to-≅ₜ n~n′₁
in ℕₜ₌ _ _ (idRedTerm:*: (conv n A≡ℕ)) (idRedTerm:*: (conv n′ A≡ℕ))
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm⁰ (Emptyᵣ [[ ⊢A , ⊢B , D ]]) neN neN′ n n′ n~n′ =
let A≡Empty = subset* D
in Emptyₜ₌ (ne (conv n A≡Empty) (conv n′ A≡Empty))
neuEqTerm⁰ {r = [ ! , ll ]} (ne (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neN neN′ n n′ n~n′ =
let A≡K = subset* D
in neₜ₌ _ _ (idRedTerm:*: (conv n A≡K)) (idRedTerm:*: (conv n′ A≡K))
(neNfₜ₌ neN neN′ (~-conv n~n′ A≡K))
neuEqTerm⁰ {r = [ % , ll ]} (ne (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neN neN′ n n′ n~n′ =
let A≡K = subset* D
in neₜ₌ n n′
neuEqTerm⁰ {r = [ ! , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let [ΠFG] = Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΠFG = subset* D
n~n′₁ = ~-conv n~n′ A≡ΠFG
n≡n′ = ~-to-≅ₜ n~n′₁
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
in Πₜ₌ _ _ (idRedTerm:*: (conv n A≡ΠFG)) (idRedTerm:*: (conv n′ A≡ΠFG))
(ne neN) (ne neN′) n≡n′
(neuTerm⁰ [ΠFG] neN n n~n) (neuTerm⁰ [ΠFG] neN′ n′ n′~n′)
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ A≡ΠFG
ρn = wkTerm [ρ] ⊢Δ n
ρn′ = wkTerm [ρ] ⊢Δ n′
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ)
(reflEqTerm ([F] [ρ] ⊢Δ) [a])
neN∙a = ∘ₙ (wkNeutral ρ neN)
neN′∙a′ = ∘ₙ (wkNeutral ρ neN′)
in neuEqTerm⁰ ([G] [ρ] ⊢Δ [a]) neN∙a neN′∙a′
(conv ρn ρA≡ρΠFG ∘ⱼ a)
(conv ρn′ ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ n~n′₁) a≡a))
neuEqTerm⁰ {r = [ % , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let A≡ΠFG = subset* D
in conv n A≡ΠFG , conv n′ A≡ΠFG
neuEqTerm⁰ {r = [ % , ll ]} (∃ᵣ′ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let A≡ΠFG = subset* D
in conv n A≡ΠFG , conv n′ A≡ΠFG
mutual
-- Neutral reflexive terms are reducible.
neuTerm : ∀ {l Γ A r n} ([A] : Γ ⊩⟨ l ⟩ A ^ r) (neN : Neutral n)
→ Γ ⊢ n ∷ A ^ r
→ Γ ⊢ n ~ n ∷ A ^ r
→ Γ ⊩⟨ l ⟩ n ∷ A ^ r / [A]
neuTerm {ι ¹} (Uᵣ′ A .(next ⁰) r ⁰ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN n n~n =
let n' = (conv n (subset* D))
n~n' = ~-conv n~n (subset* D)
[n] = neu {l = ι ¹} neN (univ n') n~n'
in Uₜ _ (idRedTerm:*: n') (ne neN) (~-to-≅ₜ n~n')
(λ {ρ} [ρ] ⊢Δ → let n'ρ = wkTerm [ρ] ⊢Δ n'
n~n'ρ = ~-wk [ρ] ⊢Δ n~n'
[nρ] = neu (wkNeutral ρ neN) (univ n'ρ) n~n'ρ
in [nρ])
neuTerm {∞} (Uᵣ′ A .(next ¹) r ¹ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN n n~n =
let n' = (conv n (subset* D))
n~n' = ~-conv n~n (subset* D)
[n] = neu {l = ∞} neN (univ n') n~n'
in Uₜ _ (idRedTerm:*: n') (ne neN) (~-to-≅ₜ n~n')
(λ {ρ} [ρ] ⊢Δ → let n'ρ = wkTerm [ρ] ⊢Δ n'
n~n'ρ = ~-wk [ρ] ⊢Δ n~n'
[nρ] = neu (wkNeutral ρ neN) (univ n'ρ) n~n'ρ
in [nρ])
neuTerm (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN n n~n =
let A≡ℕ = subset* D
n~n′ = ~-conv n~n A≡ℕ
n≡n = ~-to-≅ₜ n~n′
in ℕₜ _ (idRedTerm:*: (conv n A≡ℕ)) n≡n (ne (neNfₜ neN (conv n A≡ℕ) n~n′))
neuTerm {r = [ ! , ll ]} (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) neN n n~n =
let A≡K = subset* D
in neₜ _ (idRedTerm:*: (conv n A≡K)) (neNfₜ neN (conv n A≡K)
(~-conv n~n A≡K))
neuTerm {r = [ ! , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n =
let A≡ΠFG = subset* (red D)
in Πₜ _ (idRedTerm:*: (conv n A≡ΠFG)) (ne neN) (~-to-≅ₜ (~-conv n~n A≡ΠFG))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let A≡ΠFG = subset* (red D)
ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
G[a]≡G[b] = escapeEq ([G] [ρ] ⊢Δ [b])
(symEq ([G] [ρ] ⊢Δ [a]) ([G] [ρ] ⊢Δ [b])
(G-ext [ρ] ⊢Δ [a] [b] [a≡b]))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
b = escapeTerm ([F] [ρ] ⊢Δ) [b]
a≡b = escapeTermEq ([F] [ρ] ⊢Δ) [a≡b]
ρn = conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG
neN∘a = ∘ₙ (wkNeutral ρ neN)
neN∘b = ∘ₙ (wkNeutral ρ neN)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∘a neN∘b
(ρn ∘ⱼ a)
(conv (ρn ∘ⱼ b) (≅-eq G[a]≡G[b]))
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡b))
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ) (reflEqTerm ([F] [ρ] ⊢Δ) [a])
in neuTerm ([G] [ρ] ⊢Δ [a]) (∘ₙ (wkNeutral ρ neN))
(conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡a))
neuTerm (Emptyᵣ [[ ⊢A , ⊢B , D ]]) neN n n~n =
let A≡ℕ = subset* D
in Emptyₜ (ne (conv n A≡ℕ))
neuTerm {r = [ % , ll ]} (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) neN n n~n =
let A≡K = subset* D
in neₜ n
neuTerm {r = [ % , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n = let A≡ΠFG = subset* (red D) in conv n A≡ΠFG
neuTerm {r = [ % , ll ]} (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN n n~n = let A≡ΠFG = subset* (red D) in conv n A≡ΠFG
neuTerm {ι ¹} (emb l< X) neN n = neuTerm X neN n
neuTerm {∞} (emb l< X) neN n = neuTerm X neN n
-- Neutrally equal terms are of reducible equality.
neuEqTerm : ∀ {l Γ A n n′ r} ([A] : Γ ⊩⟨ l ⟩ A ^ r)
(neN : Neutral n) (neN′ : Neutral n′)
→ Γ ⊢ n ∷ A ^ r
→ Γ ⊢ n′ ∷ A ^ r
→ Γ ⊢ n ~ n′ ∷ A ^ r
→ Γ ⊩⟨ l ⟩ n ≡ n′ ∷ A ^ r / [A]
neuEqTerm {ι ¹} (Uᵣ′ A _ r ⁰ l< PE.refl D) neN neN′ n n′ n~n' =
let n~n = ~-trans n~n' (~-sym n~n')
n'~n' = ~-trans (~-sym n~n') n~n'
[[n]] = neuTerm (Uᵣ (Uᵣ r ⁰ l< PE.refl D)) neN n n~n
[[n']] = neuTerm (Uᵣ (Uᵣ r ⁰ l< PE.refl D)) neN′ n′ n'~n'
n' = conv n (subset* (red D))
n′' = conv n′ (subset* (red D))
n~n'U = ~-conv n~n' (subset* (red D))
[n] = neu {l = ι ¹} neN (univ n') (~-conv n~n (subset* (red D)))
[n′] = neu {l = ι ¹} neN′ (univ n′') (~-conv n'~n' (subset* (red D)))
in Uₜ₌ [[n]] [[n']] (~-to-≅ₜ n~n'U)
(λ [ρ] ⊢Δ → W.wkEq [ρ] ⊢Δ [n] ((neuEq [n] neN neN′ (univ n') (univ n′') n~n'U)))
neuEqTerm {∞} (Uᵣ′ A _ r ¹ l< PE.refl D) neN neN′ n n′ n~n' =
let n~n = ~-trans n~n' (~-sym n~n')
n'~n' = ~-trans (~-sym n~n') n~n'
[[n]] = neuTerm (Uᵣ (Uᵣ r ¹ l< PE.refl D)) neN n n~n
[[n']] = neuTerm (Uᵣ (Uᵣ r ¹ l< PE.refl D)) neN′ n′ n'~n'
n' = conv n (subset* (red D))
n′' = conv n′ (subset* (red D))
n~n'U = ~-conv n~n' (subset* (red D))
[n] = neu {l = ∞} neN (univ n') (~-conv n~n (subset* (red D)))
[n′] = neu {l = ∞} neN′ (univ n′') (~-conv n'~n' (subset* (red D)))
in Uₜ₌ [[n]] [[n']] (~-to-≅ₜ n~n'U)
(λ [ρ] ⊢Δ → W.wkEq [ρ] ⊢Δ [n] ((neuEq [n] neN neN′ (univ n') (univ n′') n~n'U)))
neuEqTerm (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN neN′ n n′ n~n′ =
let A≡ℕ = subset* D
n~n′₁ = ~-conv n~n′ A≡ℕ
n≡n′ = ~-to-≅ₜ n~n′₁
in ℕₜ₌ _ _ (idRedTerm:*: (conv n A≡ℕ)) (idRedTerm:*: (conv n′ A≡ℕ))
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm (Emptyᵣ [[ ⊢A , ⊢B , D ]]) neN neN′ n n′ n~n′ =
let A≡Empty = subset* D
in Emptyₜ₌ (ne (conv n A≡Empty) (conv n′ A≡Empty))
neuEqTerm {r = [ ! , ll ]} (ne (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neN neN′ n n′ n~n′ =
let A≡K = subset* D
in neₜ₌ _ _ (idRedTerm:*: (conv n A≡K)) (idRedTerm:*: (conv n′ A≡K))
(neNfₜ₌ neN neN′ (~-conv n~n′ A≡K))
neuEqTerm {r = [ % , ll ]} (ne (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neN neN′ n n′ n~n′ =
let A≡K = subset* D
in neₜ₌ n n′
neuEqTerm {r = [ ! , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let [ΠFG] = Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΠFG = subset* D
n~n′₁ = ~-conv n~n′ A≡ΠFG
n≡n′ = ~-to-≅ₜ n~n′₁
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
in Πₜ₌ _ _ (idRedTerm:*: (conv n A≡ΠFG)) (idRedTerm:*: (conv n′ A≡ΠFG))
(ne neN) (ne neN′) n≡n′
(neuTerm [ΠFG] neN n n~n) (neuTerm [ΠFG] neN′ n′ n′~n′)
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ A≡ΠFG
ρn = wkTerm [ρ] ⊢Δ n
ρn′ = wkTerm [ρ] ⊢Δ n′
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ)
(reflEqTerm ([F] [ρ] ⊢Δ) [a])
neN∙a = ∘ₙ (wkNeutral ρ neN)
neN′∙a′ = ∘ₙ (wkNeutral ρ neN′)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∙a neN′∙a′
(conv ρn ρA≡ρΠFG ∘ⱼ a)
(conv ρn′ ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ n~n′₁) a≡a))
neuEqTerm {r = [ % , ll ]} (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let A≡ΠFG = subset* D
in conv n A≡ΠFG , conv n′ A≡ΠFG
neuEqTerm {r = [ % , ll ]} (∃ᵣ′ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ n n′ n~n′ =
let A≡ΠFG = subset* D
in conv n A≡ΠFG , conv n′ A≡ΠFG
neuEqTerm {ι ¹} (emb l< X) neN n neN′ n:≡:n′ = neuEqTerm X neN n neN′ n:≡:n′
neuEqTerm {∞} (emb l< X) neN n neN′ n:≡:n′ = neuEqTerm X neN n neN′ n:≡:n′
-- Neutral reflexive types are reducible.
neu:⇒*: : ∀ {l Γ A K r ll} (neK : Neutral K)
→ Γ ⊢ A :⇒*: K ^ [ r , ι ll ]
→ Γ ⊢ K ~ K ∷ Univ r ll ^ [ ! , next ll ]
→ Γ ⊩⟨ l ⟩ A ^ [ r , ι ll ]
neu:⇒*: neK D K~K = ne′ _ D neK K~K
-- Helper function for reducible neutral equality of a specific type of derivation.
neuEq:⇒*:′ : ∀ {l Γ A B K L r ll} ([A] : Γ ⊩⟨ l ⟩ne A ^[ r , ll ])
(neK : Neutral K)
(neL : Neutral L)
→ Γ ⊢ A :⇒*: K ^ [ r , ι ll ]
→ Γ ⊢ B :⇒*: L ^ [ r , ι ll ]
→ Γ ⊢ K ~ L ∷ Univ r ll ^ [ ! , next ll ]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ι ll ] / ne-intr [A]
neuEq:⇒*:′ (noemb (ne A' [[ ⊢A , ⊢B , D ]] neA A≡A)) neK neL [[ ⊢A' , ⊢K , D' ]] [B] A~B =
let A≡K = whrDet* (D , ne neA) (D' , ne neK) -- (ne neA)
in ne₌ _ [B] neL (PE.subst (λ x → _ ⊢ x ~ _ ∷ _ ^ _) (PE.sym A≡K) A~B)
neuEq:⇒*:′ {ι ¹} (emb emb< X) = neuEq:⇒*:′ X
neuEq:⇒*:′ {∞} (emb ∞< X) = neuEq:⇒*:′ X
-- Neutrally equal types are of reducible equality.
neuEq:⇒*: : ∀ {l Γ A B K L r ll} ([A] : Γ ⊩⟨ l ⟩ A ^ [ r , ι ll ])
(neK : Neutral K)
(neL : Neutral L)
→ Γ ⊢ A :⇒*: K ^ [ r , ι ll ]
→ Γ ⊢ B :⇒*: L ^ [ r , ι ll ]
→ Γ ⊢ K ~ L ∷ Univ r ll ^ [ ! , next ll ]
→ Γ ⊩⟨ l ⟩ A ≡ B ^ [ r , ι ll ] / [A]
neuEq:⇒*: [A] neK neL [[ ⊢A , ⊢K , D ]] B A~B =
let ne-intrA = ne-elim′ D neK [A] PE.refl
in irrelevanceEq (ne-intr ne-intrA)
[A]
(neuEq:⇒*:′ ne-intrA neK neL [[ ⊢A , ⊢K , D ]] B A~B)
app:⇒*: : ∀ {Γ a t u A B rA lA lB l}
(⊢a : Γ ⊢ a ∷ A ^ [ rA , ι lA ])
(D : Γ ⊢ t :⇒*: u ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ ι l)
→ Γ ⊢ t ∘ a ^ l :⇒*: u ∘ a ^ l ∷ B [ a ] ^ ι lB
app:⇒*: ⊢a [[ ⊢t , ⊢u , D ]] = [[ ⊢t ∘ⱼ ⊢a , ⊢u ∘ⱼ ⊢a , appRed* ⊢a D ]]
mutual
neuTerm:⇒*:⁰ : ∀ {Γ A ll t n} ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ [ ! , ll ]) (neN : Neutral n)
→ Γ ⊢ t :⇒*: n ∷ A ^ ll
→ Γ ⊢ n ~ n ∷ A ^ [ ! , ll ]
→ Γ ⊩⟨ ι ⁰ ⟩ t ∷ A ^ [ ! , ll ] / [A]
neuTerm:⇒*:⁰ (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN [[ ⊢t , n , D' ]] n~n =
let A≡ℕ = subset* D
n~n′ = ~-conv n~n A≡ℕ
n≡n = ~-to-≅ₜ n~n′
in ℕₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ℕ) n≡n (ne (neNfₜ neN (conv n A≡ℕ) n~n′))
neuTerm:⇒*:⁰ (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) neN [[ ⊢t , n , D' ]] n~n =
let A≡K = subset* D
in neₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡K) (neNfₜ neN (conv n A≡K)
(~-conv n~n A≡K))
neuTerm:⇒*:⁰ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN [[ ⊢t , n , D' ]] n~n =
let A≡ΠFG = subset* (red D)
in Πₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ΠFG) (ne neN) (~-to-≅ₜ (~-conv n~n A≡ΠFG))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let A≡ΠFG = subset* (red D)
ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
G[a]≡G[b] = escapeEq ([G] [ρ] ⊢Δ [b])
(symEq ([G] [ρ] ⊢Δ [a]) ([G] [ρ] ⊢Δ [b])
(G-ext [ρ] ⊢Δ [a] [b] [a≡b]))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
b = escapeTerm ([F] [ρ] ⊢Δ) [b]
a≡b = escapeTermEq ([F] [ρ] ⊢Δ) [a≡b]
ρn = conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG
neN∘a = ∘ₙ (wkNeutral ρ neN)
neN∘b = ∘ₙ (wkNeutral ρ neN)
in neuEqTerm⁰ ([G] [ρ] ⊢Δ [a]) neN∘a neN∘b (ρn ∘ⱼ a) (conv (ρn ∘ⱼ b) (≅-eq G[a]≡G[b]))
((~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡b)))
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ) (reflEqTerm ([F] [ρ] ⊢Δ) [a])
in neuTerm ([G] [ρ] ⊢Δ [a]) (∘ₙ (wkNeutral ρ neN))
(conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡a))
neuEqTerm:⇒*:⁰ : ∀ {Γ A n n′ t u ll} ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ [ ! , ll ])
(neN : Neutral n) (neN′ : Neutral n′)
→ Γ ⊢ t :⇒*: n ∷ A ^ ll
→ Γ ⊢ u :⇒*: n′ ∷ A ^ ll
→ Γ ⊢ n ~ n′ ∷ A ^ [ ! , ll ]
→ Γ ⊩⟨ ι ⁰ ⟩ t ≡ u ∷ A ^ [ ! , ll ] / [A]
neuEqTerm:⇒*:⁰ (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n′ =
let A≡ℕ = subset* D
n~n′₁ = ~-conv n~n′ A≡ℕ
n≡n′ = ~-to-≅ₜ n~n′₁
in ℕₜ₌ _ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ℕ) (conv:⇒*: [[ ⊢u , n′ , D′ ]] A≡ℕ)
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm:⇒*:⁰ (ne (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n′ =
let A≡K = subset* D
in neₜ₌ _ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡K) (conv:⇒*: [[ ⊢u , n′ , D′ ]] A≡K)
(neNfₜ₌ neN neN′ (~-conv n~n′ A≡K))
neuEqTerm:⇒*:⁰ (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n′ =
let [ΠFG] = Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΠFG = subset* D
n~n′₁ = ~-conv n~n′ A≡ΠFG
n≡n′ = ~-to-≅ₜ n~n′₁
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
in Πₜ₌ _ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ΠFG) (conv:⇒*: [[ ⊢u , n′ , D′ ]] A≡ΠFG)
(ne neN) (ne neN′) n≡n′
(neuTerm:⇒*:⁰ [ΠFG] neN [[ ⊢t , n , D' ]] n~n) (neuTerm:⇒*:⁰ [ΠFG] neN′ [[ ⊢u , n′ , D′ ]] n′~n′)
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ A≡ΠFG
ρn = wkTerm [ρ] ⊢Δ n
ρn′ = wkTerm [ρ] ⊢Δ n′
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ)
(reflEqTerm ([F] [ρ] ⊢Δ) [a])
neN∙a = ∘ₙ (wkNeutral ρ neN)
neN′∙a′ = ∘ₙ (wkNeutral ρ neN′)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∙a neN′∙a′
(conv ρn ρA≡ρΠFG ∘ⱼ a)
(conv ρn′ ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ n~n′₁) a≡a) )
mutual
-- Neutral reflexive terms are reducible.
neuTerm:⇒*: : ∀ {l Γ A ll t n} ([A] : Γ ⊩⟨ l ⟩ A ^ [ ! , ll ]) (neN : Neutral n)
→ Γ ⊢ t :⇒*: n ∷ A ^ ll
→ Γ ⊢ n ~ n ∷ A ^ [ ! , ll ]
→ Γ ⊩⟨ l ⟩ t ∷ A ^ [ ! , ll ] / [A]
neuTerm:⇒*: {ι ¹} (Uᵣ′ A .(next ⁰) r ⁰ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN [[ ⊢t , n , D' ]] n~n =
let D'' = conv:⇒*: [[ ⊢t , n , D' ]] (subset* D)
n~n' = ~-conv n~n (subset* D)
in Uₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] (subset* D))
(ne neN) (~-to-≅ₜ n~n')
(λ {ρ} [ρ] ⊢Δ → let ρD' = wkRed:*:Term [ρ] ⊢Δ D''
n~n'ρ = ~-wk [ρ] ⊢Δ n~n'
in neu:⇒*: (wkNeutral ρ neN) (univ:⇒*: ρD') n~n'ρ)
neuTerm:⇒*: {∞} (Uᵣ′ A .(next ¹) r ¹ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN [[ ⊢t , n , D' ]] n~n =
let D'' = conv:⇒*: [[ ⊢t , n , D' ]] (subset* D)
n~n' = ~-conv n~n (subset* D)
in Uₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] (subset* D))
(ne neN) (~-to-≅ₜ n~n')
(λ {ρ} [ρ] ⊢Δ → let ρD' = wkRed:*:Term [ρ] ⊢Δ D''
n~n'ρ = ~-wk [ρ] ⊢Δ n~n'
in neu:⇒*: (wkNeutral ρ neN) (univ:⇒*: ρD') n~n'ρ)
neuTerm:⇒*: (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN [[ ⊢t , n , D' ]] n~n =
let A≡ℕ = subset* D
n~n′ = ~-conv n~n A≡ℕ
n≡n = ~-to-≅ₜ n~n′
in ℕₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ℕ) n≡n (ne (neNfₜ neN (conv n A≡ℕ) n~n′))
neuTerm:⇒*: (ne′ K [[ ⊢A , ⊢B , D ]] neK K≡K) neN [[ ⊢t , n , D' ]] n~n =
let A≡K = subset* D
in neₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡K) (neNfₜ neN (conv n A≡K)
(~-conv n~n A≡K))
neuTerm:⇒*: (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) neN [[ ⊢t , n , D' ]] n~n =
let A≡ΠFG = subset* (red D)
in Πₜ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ΠFG) (ne neN) (~-to-≅ₜ (~-conv n~n A≡ΠFG))
(λ {ρ} [ρ] ⊢Δ [a] [b] [a≡b] →
let A≡ΠFG = subset* (red D)
ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
G[a]≡G[b] = escapeEq ([G] [ρ] ⊢Δ [b])
(symEq ([G] [ρ] ⊢Δ [a]) ([G] [ρ] ⊢Δ [b])
(G-ext [ρ] ⊢Δ [a] [b] [a≡b]))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
b = escapeTerm ([F] [ρ] ⊢Δ) [b]
a≡b = escapeTermEq ([F] [ρ] ⊢Δ) [a≡b]
ρn = conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG
neN∘a = ∘ₙ (wkNeutral ρ neN)
neN∘b = ∘ₙ (wkNeutral ρ neN)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∘a neN∘b (ρn ∘ⱼ a) (conv (ρn ∘ⱼ b) (≅-eq G[a]≡G[b]))
((~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡b)))
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ (subset* (red D))
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ) (reflEqTerm ([F] [ρ] ⊢Δ) [a])
in neuTerm ([G] [ρ] ⊢Δ [a]) (∘ₙ (wkNeutral ρ neN))
(conv (wkTerm [ρ] ⊢Δ n) ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ (~-conv n~n A≡ΠFG)) a≡a))
neuTerm:⇒*: {ι ¹} (emb l< X) neN n n:≡:n′ = neuTerm:⇒*: X neN n n:≡:n′
neuTerm:⇒*: {∞} (emb l< X) neN n n:≡:n′ = neuTerm:⇒*: X neN n n:≡:n′
-- Neutrally equal terms are of reducible equality.
neuEqTerm:⇒*: : ∀ {l Γ A t u n n′ ll} ([A] : Γ ⊩⟨ l ⟩ A ^ [ ! , ll ])
(neN : Neutral n) (neN′ : Neutral n′)
→ Γ ⊢ t :⇒*: n ∷ A ^ ll
→ Γ ⊢ u :⇒*: n′ ∷ A ^ ll
→ Γ ⊢ n ~ n′ ∷ A ^ [ ! , ll ]
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A ^ [ ! , ll ] / [A]
neuEqTerm:⇒*: {ι ¹} (Uᵣ′ A _ r ⁰ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n' =
let n~n = ~-trans n~n' (~-sym n~n')
n'~n' = ~-trans (~-sym n~n') n~n'
n~n'U = ~-conv n~n' (subset* D)
n~nU = ~-conv n~n (subset* D)
[t] = neuTerm:⇒*: (Uᵣ′ A _ r ⁰ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN [[ ⊢t , n , D' ]] n~n
Uₜ _ _ _ _ [Δt] = [t]
D'' = conv:⇒*: [[ ⊢t , n , D' ]] (subset* D)
D′' = conv:⇒*: [[ ⊢u , n′ , D′ ]] (subset* D)
in Uₜ₌ [t]
(neuTerm:⇒*: (Uᵣ′ A _ r ⁰ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN′ [[ ⊢u , n′ , D′ ]] n'~n')
(~-to-≅ₜ n~n'U)
λ {ρ} [ρ] ⊢Δ → let ρD' = wkRed:*:Term [ρ] ⊢Δ D''
ρD′ = wkRed:*:Term [ρ] ⊢Δ D′'
n~nUρ = ~-wk [ρ] ⊢Δ n~nU
n~n'Uρ = ~-wk [ρ] ⊢Δ n~n'U
in neuEq:⇒*: {l = ι ¹} (neu:⇒*: (wkNeutral ρ neN) (univ:⇒*: ρD') n~nUρ) (wkNeutral ρ neN) (wkNeutral ρ neN′)
(univ:⇒*: ρD') (univ:⇒*: ρD′) n~n'Uρ
neuEqTerm:⇒*: {∞} (Uᵣ′ A _ r ¹ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n' =
let n~n = ~-trans n~n' (~-sym n~n')
n'~n' = ~-trans (~-sym n~n') n~n'
n~n'U = ~-conv n~n' (subset* D)
n~nU = ~-conv n~n (subset* D)
[t] = neuTerm:⇒*: (Uᵣ′ A _ r ¹ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN [[ ⊢t , n , D' ]] n~n
Uₜ _ _ _ _ [Δt] = [t]
D'' = conv:⇒*: [[ ⊢t , n , D' ]] (subset* D)
D′' = conv:⇒*: [[ ⊢u , n′ , D′ ]] (subset* D)
in Uₜ₌ [t]
(neuTerm:⇒*: (Uᵣ′ A _ r ¹ l< PE.refl [[ ⊢A , ⊢U , D ]]) neN′ [[ ⊢u , n′ , D′ ]] n'~n')
(~-to-≅ₜ n~n'U)
λ {ρ} [ρ] ⊢Δ → let ρD' = wkRed:*:Term [ρ] ⊢Δ D''
ρD′ = wkRed:*:Term [ρ] ⊢Δ D′'
n~nUρ = ~-wk [ρ] ⊢Δ n~nU
n~n'Uρ = ~-wk [ρ] ⊢Δ n~n'U
in neuEq:⇒*: {l = ∞} (neu:⇒*: (wkNeutral ρ neN) (univ:⇒*: ρD') n~nUρ) (wkNeutral ρ neN) (wkNeutral ρ neN′)
(univ:⇒*: ρD') (univ:⇒*: ρD′) n~n'Uρ
neuEqTerm:⇒*: (ℕᵣ [[ ⊢A , ⊢B , D ]]) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n′ =
let A≡ℕ = subset* D
n~n′₁ = ~-conv n~n′ A≡ℕ
n≡n′ = ~-to-≅ₜ n~n′₁
in ℕₜ₌ _ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ℕ) (conv:⇒*: [[ ⊢u , n′ , D′ ]] A≡ℕ)
n≡n′ (ne (neNfₜ₌ neN neN′ n~n′₁))
neuEqTerm:⇒*: (ne (ne K [[ ⊢A , ⊢B , D ]] neK K≡K)) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n′ =
let A≡K = subset* D
in neₜ₌ _ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡K) (conv:⇒*: [[ ⊢u , n′ , D′ ]] A≡K)
(neNfₜ₌ neN neN′ (~-conv n~n′ A≡K))
neuEqTerm:⇒*: (Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) neN neN′ [[ ⊢t , n , D' ]] [[ ⊢u , n′ , D′ ]] n~n′ =
let [ΠFG] = Πᵣ′ rF lF lG lF≤ lG≤ F G [[ ⊢A , ⊢B , D ]] ⊢F ⊢G A≡A [F] [G] G-ext
A≡ΠFG = subset* D
n~n′₁ = ~-conv n~n′ A≡ΠFG
n≡n′ = ~-to-≅ₜ n~n′₁
n~n = ~-trans n~n′ (~-sym n~n′)
n′~n′ = ~-trans (~-sym n~n′) n~n′
in Πₜ₌ _ _ (conv:⇒*: [[ ⊢t , n , D' ]] A≡ΠFG) (conv:⇒*: [[ ⊢u , n′ , D′ ]] A≡ΠFG)
(ne neN) (ne neN′) n≡n′
(neuTerm:⇒*: [ΠFG] neN [[ ⊢t , n , D' ]] n~n) (neuTerm:⇒*: [ΠFG] neN′ [[ ⊢u , n′ , D′ ]] n′~n′)
(λ {ρ} [ρ] ⊢Δ [a] →
let ρA≡ρΠFG = wkEq [ρ] ⊢Δ A≡ΠFG
ρn = wkTerm [ρ] ⊢Δ n
ρn′ = wkTerm [ρ] ⊢Δ n′
a = escapeTerm ([F] [ρ] ⊢Δ) [a]
a≡a = escapeTermEq ([F] [ρ] ⊢Δ)
(reflEqTerm ([F] [ρ] ⊢Δ) [a])
neN∙a = ∘ₙ (wkNeutral ρ neN)
neN′∙a′ = ∘ₙ (wkNeutral ρ neN′)
in neuEqTerm ([G] [ρ] ⊢Δ [a]) neN∙a neN′∙a′
(conv ρn ρA≡ρΠFG ∘ⱼ a)
(conv ρn′ ρA≡ρΠFG ∘ⱼ a)
(~-app (~-wk [ρ] ⊢Δ n~n′₁) a≡a) )
neuEqTerm:⇒*: {ι ¹} (emb l< X) neN n neN′ n:≡:n′ = neuEqTerm:⇒*: X neN n neN′ n:≡:n′
neuEqTerm:⇒*: {∞} (emb l< X) neN n neN′ n:≡:n′ = neuEqTerm:⇒*: X neN n neN′ n:≡:n′
| {
"alphanum_fraction": 0.3759528162,
"avg_line_length": 50.3350694444,
"ext": "agda",
"hexsha": "51fb7d6c669d765b585037c9297963bb25a699d1",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Properties/Neutral.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Properties/Neutral.agda",
"max_line_length": 138,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Properties/Neutral.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 14741,
"size": 28993
} |
-- Intuitionistic propositional logic, PHOAS approach, final encoding
module Pf.Ip where
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set1
Cx = Ty -> Set
isTrue : Ty -> Cx -> Set
isTrue a tc = tc a
-- Terms
TmRepr : Set1
TmRepr = Cx -> Ty -> Set
module ArrMp where
record Tm (tr : TmRepr) : Set1 where
infixl 1 _$_
field
var : forall {tc a} -> isTrue a tc -> tr tc a
lam' : forall {tc a b} -> (isTrue a tc -> tr tc b) -> tr tc (a => b)
_$_ : forall {tc a b} -> tr tc (a => b) -> tr tc a -> tr tc b
lam'' : forall {tc a b} -> (tr tc a -> tr tc b) -> tr tc (a => b)
lam'' f = lam' \x -> f (var x)
syntax lam'' (\a -> b) = lam a => b
open Tm {{...}} public
module Mp where
record Tm (tr : TmRepr) : Set1 where
field
pair' : forall {tc a b} -> tr tc a -> tr tc b -> tr tc (a && b)
fst : forall {tc a b} -> tr tc (a && b) -> tr tc a
snd : forall {tc a b} -> tr tc (a && b) -> tr tc b
left : forall {tc a b} -> tr tc a -> tr tc (a || b)
right : forall {tc a b} -> tr tc b -> tr tc (a || b)
case' : forall {tc a b c} -> tr tc (a || b) -> (isTrue a tc -> tr tc c) -> (isTrue b tc -> tr tc c) -> tr tc c
isArrMp : ArrMp.Tm tr
open ArrMp.Tm isArrMp public
case'' : forall {tc a b c} -> tr tc (a || b) -> (tr tc a -> tr tc c) -> (tr tc b -> tr tc c) -> tr tc c
case'' xy f g = case' xy (\x -> f (var x)) (\y -> g (var y))
syntax pair' x y = [ x , y ]
syntax case'' xy (\x -> z1) (\y -> z2) = case xy of x => z1 or y => z2
open Tm {{...}} public
module Ip where
record Tm (tr : TmRepr) : Set1 where
field
abort : forall {tc a} -> tr tc FALSE -> tr tc a
isMp : Mp.Tm tr
open Mp.Tm isMp public
open Tm {{...}} public
Thm : Ty -> Set1
Thm a = forall {tr tc} {{_ : Tm tr}} -> tr tc a
open Ip public
-- Example theorems
t1 : forall {a b} -> Thm (a => NOT a => b)
t1 =
lam x =>
lam f => abort (f $ x)
t2 : forall {a b} -> Thm (NOT a => a => b)
t2 =
lam f =>
lam x => abort (f $ x)
t3 : forall {a} -> Thm (a => NOT (NOT a))
t3 =
lam x =>
lam f => f $ x
t4 : forall {a} -> Thm (NOT a <=> NOT (NOT (NOT a)))
t4 =
[ lam f =>
lam g => g $ f
, lam g =>
lam x => g $ (lam f => f $ x)
]
| {
"alphanum_fraction": 0.4626255113,
"avg_line_length": 23.3826086957,
"ext": "agda",
"hexsha": "1c3cacb01ebe3bf43f85d17a1489ceae3d9a62b1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Pf/Ip.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Pf/Ip.agda",
"max_line_length": 116,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Pf/Ip.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 1010,
"size": 2689
} |
-- Issue #2814 reported by tomjack on 2017-10-18
{-# OPTIONS --cubical --rewriting #-}
-- prelude stolen from Saizan/cubical-demo
open import Agda.Primitive.Cubical public
postulate
Path' : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
infix 4 _≡_
_≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
_≡_ {A = A} = PathP (λ _ → A)
Path = _≡_
refl : ∀ {ℓ} {A : Set ℓ} {x : A} → x ≡ x
refl {x = x} = λ _ → x
postulate
Rewrite : ∀ {ℓ} {A : Set ℓ} → A → A → Set
{-# BUILTIN REWRITE Rewrite #-}
module Good where
postulate
Unit : Set
unit : Unit
module UnitElim (P : Unit → Set) (unit* : P unit) where
postulate
Unit-elim : (x : Unit) → P x
unit-β : Rewrite (Unit-elim unit) unit*
open UnitElim public
{-# REWRITE unit-β #-}
test₁ : {C : Set} {c₀ : C} → Path {A = C} (Unit-elim (λ _ → C) c₀ unit) c₀
test₁ = refl
test₂ : {C : Set} {c₀ : C} → Path {A = Path c₀ c₀} (λ j → Unit-elim (λ _ → C) c₀ unit) refl
test₂ = refl
-- same code, but with a dummy module parameter
module Bad (Dummy : Set) where
postulate
Unit : Set
unit : Unit
module UnitElim (P : Unit → Set) (unit* : P unit) where
postulate
Unit-elim : (x : Unit) → P x
unit-β : Rewrite (Unit-elim unit) unit*
open UnitElim public
{-# REWRITE unit-β #-}
test₁ : {C : Set} {c₀ : C} → Path {A = C} (Unit-elim (λ _ → C) c₀ unit) c₀
test₁ = refl
test₂ : {C : Set} {c₀ : C} → Path {A = Path c₀ c₀} (λ j → Unit-elim (λ _ → C) c₀ unit) refl
test₂ = refl
-- WAS:
-- Unit-elim (λ _ → .C) .c₀ unit != .c₀ of type .C
-- when checking that the expression refl has type
-- Path (λ j → Unit-elim (λ _ → .C) .c₀ unit) refl
-- SHOULD: succeed
| {
"alphanum_fraction": 0.5539160045,
"avg_line_length": 23.4933333333,
"ext": "agda",
"hexsha": "2dab48ecf836001a7bce9650c569059da7262f07",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue2814.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue2814.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue2814.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 697,
"size": 1762
} |
module LecIC where
open import CS410-Prelude
open import CS410-Nat
_-:>_ : {I : Set}(S T : I -> Set) -> I -> Set
(S -:> T) i = S i -> T i
infixr 3 _-:>_
-- notation for indexed sets
[_] : {I : Set}(X : I -> Set) -> Set
[ X ] = forall {i} -> X i
record MonadIx {W : Set}(F : (W -> Set) -> (W -> Set)) : Set1 where
field
retIx : forall {P} -> [ P -:> F P ]
extendIx : forall {P Q} -> [ P -:> F Q ] -> [ F P -:> F Q ]
_?>=_ : forall {P Q w} ->
F P w -> (forall {v} -> P v -> F Q v) -> F Q w
fp ?>= k = extendIx k fp
IC : (W : Set)
(C : W -> Set)
(R : (w : W) -> C w -> Set)
(n : (w : W)(c : C w)(r : R w c) -> W)
-> (W -> Set) -> (W -> Set)
IC W C R n G w = Sg (C w) \ c -> (r : R w c) -> G (n w c r)
data FreeIx (W : Set)
(C : W -> Set)
(R : (w : W) -> C w -> Set)
(n : (w : W)(c : C w)(r : R w c) -> W)
(G : W -> Set)
(w : W)
: Set
where
ret : G w -> FreeIx W C R n G w
do : IC W C R n (FreeIx W C R n G) w -> FreeIx W C R n G w
postulate
FileName : Set
Char : Set
foo : FileName
blah : Char
data WriteFileW : Set where
opened closed : WriteFileW
data WriteFileC : WriteFileW -> Set where
write : Char -> WriteFileC opened
openW : FileName -> WriteFileC closed
closeW : WriteFileC opened
WriteFileR : (w : WriteFileW)(c : WriteFileC w) -> Set
WriteFileR .opened (write x) = One
WriteFileR .closed (openW x) = WriteFileW
WriteFileR .opened closeW = One
WriteFileN : (w : WriteFileW)(c : WriteFileC w)(r : WriteFileR w c) -> WriteFileW
WriteFileN .opened (write x) <> = opened
WriteFileN .closed (openW x) r = r
WriteFileN .opened closeW <> = closed
WRITE : (WriteFileW -> Set) -> (WriteFileW -> Set)
WRITE = FreeIx WriteFileW WriteFileC WriteFileR WriteFileN
Goal : WriteFileW -> Set
Goal opened = Zero
Goal closed = One
play : WRITE Goal closed
play = do (openW foo , \
{ opened -> do (write blah , (\ _ -> do (closeW , (\ _ -> ret <>))))
; closed -> ret <>
})
FreeMonadIx : (W : Set)
(C : W -> Set)
(R : (w : W) -> C w -> Set)
(n : (w : W)(c : C w)(r : R w c) -> W)
-> MonadIx (FreeIx W C R n)
FreeMonadIx W C R n =
record { retIx = ret
; extendIx = help
} where
help : {P Q : W → Set} ->
[ P -:> FreeIx W C R n Q ] ->
[ FreeIx W C R n P -:> FreeIx W C R n Q ]
help k (ret p) = k p
help k (do (c , j)) = do (c , \ r -> help k (j r))
data HType : Set where hTwo hNat : HType
-- mapping names for types to real types.
THVal : HType -> Set
THVal hTwo = Two
THVal hNat = Nat
-- A syntax for types expressions, indexed by typed variables. Compare
-- with the untyped HExp and fill in the missing expression formers,
-- we have shown you the way with _+H_. think: what can be guaranteed?
data THExp (X : HType -> Set) : HType -> Set where
var : forall {T} -> X T -> THExp X T
val : forall {T} -> THVal T -> THExp X T
_+H_ : THExp X hNat -> THExp X hNat -> THExp X hNat
-- ??? fill in the other two constructs, typed appropriately
-- (remember that "if then else" can compute values at any type)
THExpMonadIx : MonadIx THExp
THExpMonadIx = record
{ retIx = var
; extendIx = help
} where
help : forall {P Q} -> [ P -:> THExp Q ] -> [ THExp P -:> THExp Q ]
help f (var x) = f x
help f (val v) = val v
help f (e1 +H e2) = help f e1 +H help f e2
WH : Set
WH = Nat * Nat
data Tiling (X : WH -> Set)(wh : WH) : Set where
! : X wh -> Tiling X wh
joinH : (wl wr : Nat)(wq : wl +N wr == fst wh) ->
Tiling X (wl , snd wh) -> Tiling X (wr , snd wh) -> Tiling X wh
joinV : (ht hb : Nat)(hq : ht +N hb == snd wh) ->
Tiling X (fst wh , ht) -> Tiling X (fst wh , hb) -> Tiling X wh
TilingMonadIx : MonadIx Tiling
TilingMonadIx = record
{ retIx = !
; extendIx = help
} where
help : {P Q : WH -> Set} -> [ P -:> Tiling Q ] -> [ Tiling P -:> Tiling Q ]
help f (! p) = f p
help f (joinH wl wr wq t-l t-r) = joinH wl wr wq (help f t-l) (help f t-r)
help f (joinV ht hb hq t-t t-b) = joinV ht hb hq (help f t-t) (help f t-b)
IsZero : Nat -> Set
IsZero zero = One
IsZero (suc n) = Zero
CanCons : Set -> Nat -> Set
CanCons X zero = Zero
CanCons X (suc n) = X
afterCons : {X : Set}(n : Nat) -> CanCons X n -> One -> Nat
afterCons zero () <>
afterCons (suc n) c <> = n
VEC : Set -> Nat -> Set
VEC X = FreeIx Nat (CanCons X) (\ _ _ -> One) afterCons IsZero
| {
"alphanum_fraction": 0.5427801482,
"avg_line_length": 28.0062893082,
"ext": "agda",
"hexsha": "87f9ae002871fa1f0fffdea74e3e05037711d13b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "LecIC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "clarkdm/CS410",
"max_issues_repo_path": "LecIC.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "LecIC.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1623,
"size": 4453
} |
data Bool : Set where
true : Bool
false : Bool
data Nat : Set where
suc : Nat -> Nat
zer : Nat
{-# BUILTIN NATURAL Nat #-}
data Vec (A : Set) : (n : Nat) -> Set where
_,_ : ∀ {n} -> A -> Vec A n -> Vec A (suc n)
[] : Vec A zer
data Sig (A : Set) (B : A → Set) : Set where
sig : (a : A) → B a → Sig A B
Exists : ∀ {A : Set} → (A → Set) → Set
Exists = Sig _
Pair : ∀ (A B : Set) → Set
Pair A B = Sig A (λ x → B)
-- variable
-- m n : Nat
-- b : Bool
-- Γ Δ Ξ T I O : Vec Bool n
-- A Linear term has an output and an output usage annotation
-- For each variable (i.e. index in the Vec):
-- * true: available
-- * false: already consumed
Linear : Set₁
Linear = ∀ n (Γa Γb : Vec Bool n) → Set
data Var : Linear where
z : ∀ {n Γ} → Var (suc n) (true , Γ) (false , Γ)
s : ∀ {n Γa Γb x} → Var n Γa Γb → Var (suc n) (x , Γa) (x , Γb)
data Lam : Linear where
var : ∀ {n Γa Γb} → Var n Γa Γb → Lam n Γa Γb
app : ∀ {n Γa Γb Γc} → Lam n Γa Γb → Lam n Γb Γc → Lam n Γa Γc
lam : ∀ {n Γa Γb} → Lam (suc n) (true , Γa) (false , Γb) → Lam n Γa Γb
-- Γi Γo: input and output usage of the env
-- Γt: target usage covered by the content of the env
data Env : ∀ n m → (Γi Γo : Vec Bool n) (Γt : Vec Bool m) → Set where
-- empty environment
[] : ∀ {n Γi Γo} → Env n zer Γi Γo []
-- 0th variable is available so we have a value for it
_,_ : ∀ {n m Γi Γm Γo Γt} → Lam n Γi Γm → Env n m Γm Γo Γt → Env n (suc m) Γi Γo (true , Γt)
-- -- 0th variable has already been consumed: we don't have a term for it anymore
─,_ : ∀ {n m Γi Γo Γt} → Env n m Γi Γo Γt → Env n (suc m) Γi Γo (false , Γt)
-- -- When we go under binders, we need to be able to extend the input/output
-- -- context to cope with the extended context
[v]∷_ : ∀ {n m Γi Γo Γt} → Env n m Γi Γo Γt → Env (suc n) (suc m) (true , Γi) (false , Γo) (false , Γt)
]v[∷_ : ∀ {n m Γi Γo Γt} → Env n m Γi Γo Γt → Env (suc n) (suc m) (false , Γi) (false , Γo) (false , Γt)
-- Input/output usage pairs that have the same consumption pattern
data Equiv : ∀ n → (Γ0i Γ0o Γ1i Γ1o : Vec Bool n) → Set where
-- Empty pairs have the same consumption pattern
empty : Equiv zer [] [] [] []
-- If a resource is untouched in one side, then it must be untouched on the other
skip : ∀ {n} Γ0i Γ0o Γ1i Γ1o A B → Equiv (suc n) (A , Γ0i) (A , Γ0o) (B , Γ1i) (B , Γ1o)
-- If a resource is used in one side, then it must be used on the other
consume : ∀ {n} Γ0i Γ0o Γ1i Γ1o → Equiv (suc n) (true , Γ0i) (false , Γ0o) (true , Γ1i) (false , Γ1o)
-- R: target of the substitution
-- V: output (e.g. substituting for vars yields terms)
Subst : (R : Linear) (V : Linear) → Set
Subst R V = ∀ {n m Γi Γo I O}
-- environment targetting I
→ Env n m Γi Γo I
-- R consuming resources in I, returning O leftovers
→ R m I O
-- the result is a usage annotation, a value V consuming in the input, returning M leftovers, an environment of leftovers for whatever is still true in O
→ Exists (λ M → Pair (V n Γi M) (Env n m M Γo O))
-- substVar : Subst Var Lam
-- substVar (t ∷ ρ) z = -, t , ─∷ ρ
-- substVar (x ∷ ρ) (s v) = {!!}
-- substVar (─∷ ρ) (s v) = {!!}
-- substVar ([v]∷ ρ) (s v) = {!!}
-- substVar (]v[∷ ρ) (s v) = {!!}
| {
"alphanum_fraction": 0.567419158,
"avg_line_length": 38.5647058824,
"ext": "agda",
"hexsha": "5a1027b18b01fdd5c44a5931a0a91a88fce1e507",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-03-19T23:03:08.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-31T09:27:14.000Z",
"max_forks_repo_head_hexsha": "f2517e2e04cd9956a19ec3d7d3843856eb164e20",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "moonad/Elementary-Affine-Calculus",
"max_forks_repo_path": "agda/Linear.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2517e2e04cd9956a19ec3d7d3843856eb164e20",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "moonad/Elementary-Affine-Calculus",
"max_issues_repo_path": "agda/Linear.agda",
"max_line_length": 163,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "f2517e2e04cd9956a19ec3d7d3843856eb164e20",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MaiaVictor/Elementary-Affine-Core-legacy",
"max_stars_repo_path": "agda/Linear.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-16T21:09:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-28T00:06:32.000Z",
"num_tokens": 1279,
"size": 3278
} |
open import Type
open import Structure.Relator
open import Structure.Setoid renaming (_≡_ to _≡ₑ_)
module Structure.Sets.ZFC {ℓₛ ℓₗ ℓₑ} {S : Type{ℓₛ}} ⦃ equiv : Equiv{ℓₑ}(S) ⦄ (_∈_ : S → S → Type{ℓₗ}) ⦃ [∈]-binaryRelator : BinaryRelator(_∈_) ⦄ where
open import Functional
open import Function.Equals
import Lvl
open import Logic.Predicate
open import Logic.Propositional
open import Type.Properties.Inhabited
open import Structure.Function
open import Structure.Operator
open import Structure.Relator.Proofs renaming ([≡]-binaryRelator to [≡ₑ]-binaryRelator)
open import Structure.Setoid.Uniqueness
import Structure.Sets.Names
open import Syntax.Function
open import Syntax.Implication
private variable ℓ ℓ₁ ℓ₂ ℓₑ₁ : Lvl.Level
private variable A B C D E a b c d e x y z As : S
private variable f g h : S → S
private variable P Q R : S → Type{ℓ}
private variable ⦃ func ⦄ : Function ⦃ equiv ⦄ ⦃ equiv ⦄ (f)
private variable ⦃ unaryRel ⦄ : UnaryRelator ⦃ equiv ⦄ (P)
open Structure.Sets.Names.From-[∈] (_∈_)
open Structure.Sets.Names.Relations (_∈_)
open Structure.Sets.Names.One (_∈_)
open Structure.Sets.Names.Two (_∈_)(_∈_)
open Structure.Sets.Names.TwoDifferent (_∈_)(_∈_)
open Structure.Sets.Names.TwoSame (_∈_)(_∈_)
open Structure.Sets.Names.Three (_∈_)(_∈_)(_∈_)
open Structure.Sets.Names.ThreeNestedTwoDifferent (_∈_)
open Structure.Sets.Names.ThreeTwoNested (_∈_)(_∈_)(_∈_)
open import Structure.Sets.Quantifiers(_∈_)
open import Structure.Sets.Quantifiers.Proofs(_∈_) ⦃ [∈]-binaryRelator ⦄
{-
-- The statement that the sets in ss are all pairwise disjoint
PairwiseDisjoint : S → Type
PairwiseDisjoint(ss) = ∀ₛ(ss)(s₁ ↦ ∀ₛ(ss)(s₂ ↦ ∀ₗ(x ↦ ((x ∈ s₁) → (x ∈ s₂) → (s₁ ≡ s₂)))))
-- ∀ₛ(ss)(s₁ ↦ ∀ₛ(ss)(s₂ ↦ (s₁ ≢ s₂) → Disjoint(s₁)(s₂)))
-- The statement that the relation predicate F can be interpreted as a partial function
PartialFunction : (S → S → Type{ℓ}) → S → Type
PartialFunction(F) (dom) = ∀ₛ(dom)(x ↦ Unique(y ↦ F(x)(y)))
-- The statement that the relation predicate F can be interpreted as a total function
TotalFunction : (S → S → Type{ℓ}) → S → Type
TotalFunction(F) (dom) = ∀ₛ(dom)(x ↦ ∃!(y ↦ F(x)(y)))
-- A binary relator modifier which makes the binary relator to a statement about all distinct pairs in a set.
-- Note: This is specifically for irreflexive binary relations.
DistinctivelyPairwise : (S → S → Type{ℓ}) → (S → Type)
DistinctivelyPairwise Related (S) = ∀ₛ(S)(a ↦ ∀ₛ(S)(b ↦ ((a ≢ b) → Related(a)(b))))
-}
record ZFC : Typeω where
field
-- Empty set
-- The set consisting of no elements.
∅ : S
-- Pair set.
-- The set consisting of only two elements.
pair : S → S → S
-- Subset filtering.
-- The subset of the specified set where all elements satisfy the specified formula.
filter : (P : S → Type{ℓ}) ⦃ rel-P : UnaryRelator(P) ⦄ → (S → S)
-- Union over arbitrary sets.
-- Constructs a set which consists of elements which are in any of the specified sets.
⋃ : S → S
-- Power set.
-- The set of all subsets of the specified set.
℘ : S → S
-- The map of a set.
-- The set of values when a function is applied to every element of a set.
-- Or: The image of the function on the set.
-- Or: The image of the function.
map : (f : S → S) ⦃ func-f : Function(f) ⦄ → (S → S)
-- The set of all finite ordinals.
-- A set which has the `Inductive`-property. Also infinite.
ω₀ : S
-- A choice function for non-empty sets in a family of sets.
-- Chooses an arbitrary element in a non-empty set from a family of sets.
-- Example: choose {ℕ,ℤ,ℚ,ℝ} ℝ ∈ ℝ.
choose : S → S → S
-- Singleton set.
-- A set consisting of only a single element.
singleton : S → S
singleton(s) = pair(s)(s)
-- Union operator.
-- Constructs a set which consists of both elements from LHS and RHS.
_∪_ : S → S → S
a ∪ b = ⋃(pair a b)
infixl 3000 _∪_
-- The zero constant expressed in the standard inductive set definition of ℕ in ZFC set theory.
𝟎 : S
𝟎 = ∅
-- The successor function expressed in the standard inductive set definition of ℕ in ZFC set theory.
-- This definition implies that natural numbers are sets that contain all numbers lesser than themselves.
-- Examples:
-- • 0: {}
-- • 1: 0∪{0} = {0} = {{},{{}}}
-- • 2: 1∪{1} = {0}∪{1} = {0,1} = {{},{{},{{}}}}
-- • 3: 2∪{2} = {0,1}∪{2} = {0,1,2} = {{{},{{},{{}}}},{{{},{{},{{}}}}}}
-- • 4: 3∪{3} = {0,1,2}∪{3} = {0,1,2,3} = {{{{},{{},{{}}}},{{{},{{},{{}}}}}},{{{{},{{},{{}}}},{{{},{{},{{}}}}}}}}
𝐒 : S → S
𝐒(n) = n ∪ singleton(n)
𝟏 : S
𝟏 = 𝐒(𝟎)
-- A set is ℕ-inductive when has zero and all its successors.
-- In loose terms: Inductive(I) means (I ⊆ ℕ)
Inductive : S → Type
Inductive(I) = (𝟎 ∈ I) ∧ (∀ₗ(x ↦ ((x ∈ I) → (𝐒(x) ∈ I))))
field
-- Set identity is extensionally determined. More specifically by its contents.
set-extensionality : SetEqualityMembership(_≡ₑ_)
-- `∅` is a set which is empty.
-- • Allows a construction of an empty set.
empty : EmptyMembership(∅)
-- `pair` is the construction of a set with two elements.
-- • Allows a construction of a set with two elements.
pairing : PairMembership(pair)
-- `filter` is the set which is the subset of a set where all elements satisfies a predicate.
restricted-comprehension : FilterMembership{ℓ = ℓ}(filter)
-- `⋃` is the construction of a set which contains all the elements of a collection of sets.
-- • Allows a construction of a set that is the union of some sets.
union : BigUnionMembership(⋃)
-- `℘` is the construction of a set which contains all the subsets of a set.
-- • Allows a construction of a set that is the powerset of a set.
power : PowerMembership(_⊆_)(℘)
-- `map` is the construction of the image of a function restricted to a set.
-- • The `map`-function on a function is a function from sets to sets.
replacement : MapMembership(map)
-- `inductiveSet` is ℕ-inductive.
-- • An inductive set is infinite, so this implies that an infinite set exists.
-- • Makes it possible to construct the set of natural numbers (ℕ).
infinity : Inductive(ω₀)
-- A non-empty set contain sets that are disjoint to it.
-- • Prevents sets from containing themselves.
-- • Makes every set have an ordinal rank.
regularity : ∀ₗ(s₁ ↦ (NonEmpty(s₁) → ∃(s₂ ↦ (s₂ ∈ s₁) ∧ Disjoint(s₁)(s₂))))
--choice : (∀{a} → (a ∈ A) → NonEmpty(a)) → PairwiseDisjoint(A) → ∃(b ↦ ∀{a} → (a ∈ A) → ∃!(_∈ (a ∩ b)))
--choice : ∀{A B} ⦃ AB : A ⊇ B ⦄ ⦃ ne-B ⦄ → (choose(A)(B) ⦃ AB ⦄ ⦃ ne-B ⦄ ∈ B)
-- The values of a choice function of a family of sets are all in the given sets.
-- This states that a choice function actually chooses an element from the specified set.
-- Note: A variant without the mentioning of `A` and a proof of `a ∈ A` would instead lead to the formulation of the axiom of global choice. The reason for not using global choice as an axiom is because unlike global choice, this variant makes every choice function expressable as a set. This variant should be interpreted as there being different choice functions for every family of sets. For example, when `A ≢ B`, `x ∈ A` and `x ∈ B` is satisfied, then `choose(A)(x) ≡ choose(B)(x)` should not neccesarily be satisfied while still (choose(A)(x) ∈ x) and (choose(B)(x) ∈ x).
-- Examples:
-- choose {ℕ,ℤ,ℚ,ℝ} ℝ ∈ ℝ
-- choose {ℕ,ℤ,ℚ,ℝ} ℝ ≢ choose {ℤ,ℚ,ℝ} ℝ
-- For example, it could be the case that (choose {ℕ,ℤ,ℚ,ℝ} ℝ = 0) but (choose {ℤ,ℚ,ℝ} ℝ = 1).
-- Note: Without `choose-function`, `choice` would not be an actual choice function.
choice : ∀{A a} → ⦃ ne : NonEmpty(a) ⦄ ⦃ aA : a ∈ A ⦄ → (choose A a ∈ a)
⦃ choose-function ⦄ : BinaryOperator(choose)
𝑇 = 𝟎
𝐹 = 𝟏
BoolSet = pair 𝑇 𝐹
instance
Inductive-unaryRelator : UnaryRelator(Inductive)
Inductive-unaryRelator = [∧]-unaryRelator ⦃ rel-P = binary-unaryRelatorₗ ⦄ ⦃ rel-Q = [∀]-unaryRelator ⦃ rel-P = [→]-unaryRelator ⦃ rel-P = binary-unaryRelatorₗ ⦄ ⦃ rel-Q = binary-unaryRelatorₗ ⦄ ⦄ ⦄
open import Logic.Predicate.Theorems
open import Logic.Propositional.Theorems
open import Structure.Relator.Properties
open import Structure.Relator.Proofs renaming ([≡]-binaryRelator to [≡ₑ]-binaryRelator)
instance
[≡]-binaryRelator : BinaryRelator(_≡_)
BinaryRelator.substitution [≡]-binaryRelator xy₁ xy₂ x₁x₂ = [↔]-to-[→] set-extensionality (BinaryRelator.substitution [≡ₑ]-binaryRelator xy₁ xy₂ ([↔]-to-[←] set-extensionality x₁x₂))
instance
[⊆]-binaryRelator : BinaryRelator(_⊆_)
BinaryRelator.substitution [⊆]-binaryRelator p1 p2 sub = [↔]-to-[→] ([↔]-to-[→] set-extensionality p2) ∘ sub ∘ [↔]-to-[←] ([↔]-to-[→] set-extensionality p1)
instance
pair-binaryOperator : BinaryOperator(pair)
BinaryOperator.congruence pair-binaryOperator p1 p2 = [↔]-to-[←] set-extensionality (\{x} → [↔]-transitivity pairing ([↔]-transitivity ([∨]-map-[↔] (substitute₂ₗᵣ(_≡ₑ_) ⦃ [≡ₑ]-binaryRelator ⦄ (reflexivity(_≡ₑ_) {x}) p1) (substitute₂ₗᵣ(_≡ₑ_) ⦃ [≡ₑ]-binaryRelator ⦄ (reflexivity(_≡ₑ_) {x}) p2)) ([↔]-symmetry pairing)))
instance
℘-function : Function(℘)
Function.congruence ℘-function xy = [↔]-to-[←] set-extensionality \{x} → [↔]-transitivity power ([↔]-transitivity ([↔]-intro (substitute₂ᵣ(_⊆_) ⦃ [⊆]-binaryRelator ⦄ (symmetry(_≡ₑ_) xy)) (substitute₂ᵣ(_⊆_) ⦃ [⊆]-binaryRelator ⦄ xy)) ([↔]-symmetry power))
instance
⋃-function : Function(⋃)
Function.congruence ⋃-function xy = [↔]-to-[←] set-extensionality \{x} → [↔]-transitivity union ([↔]-transitivity ([∃]-map-proof-[↔] ([∧]-map-[↔] ([↔]-to-[→] set-extensionality xy) [↔]-reflexivity)) ([↔]-symmetry union))
filter-function : ∀ ⦃ rel-P : UnaryRelator(P) ⦄ ⦃ rel-Q : UnaryRelator(Q) ⦄ → (∀{x} → P(x) ↔ Q(x)) → ∀{A B} → (A ≡ₑ B) → (filter P(A) ≡ₑ filter Q(B))
filter-function PQ AB = [↔]-to-[←] set-extensionality ([↔]-transitivity restricted-comprehension ([↔]-transitivity ([∧]-map-[↔] ([↔]-to-[→] set-extensionality AB) PQ) ([↔]-symmetry restricted-comprehension)))
map-function : ∀{f} ⦃ func-f : Function(f) ⦄ {g} ⦃ func-g : Function(g) ⦄ → (f ⊜ g) → ∀{A B} → (A ≡ₑ B) → (map f(A) ≡ₑ map g(B))
map-function {f = f}{g = g} (intro fg) {A = A}{B = B} AB = [↔]-to-[←] set-extensionality $ \{y} →
(y ∈ map f A) ⇔-[ replacement ]
∃ₛ(A)(x ↦ f(x) ≡ₑ y) ⇔-[ [∃]-map-proof-[↔] (\{x} → [∧]-map-[↔] ([↔]-to-[→] set-extensionality AB) (substitute₂ₗᵣ(_≡ₑ_) ⦃ [≡ₑ]-binaryRelator ⦄ (fg{x}) (reflexivity(_≡ₑ_)))) ]
∃ₛ(B)(x ↦ g(x) ≡ₑ y) ⇔-[ replacement ]-sym
(y ∈ map g B) ⇔-end
[∪]-inclusion : UnionMembership(_∪_)
[∪]-inclusion {A = A}{B = B}{x = x} =
(x ∈ ⋃ (pair A B)) ⇔-[ union ]
∃(y ↦ (y ∈ pair A B) ∧ (x ∈ y)) ⇔-[ [∃]-map-proof-[↔] (\{y} →
(y ∈ pair A B) ∧ (x ∈ y) ⇔-[ [∧]-map-[↔] pairing [↔]-reflexivity ]
((y ≡ₑ A) ∨ (y ≡ₑ B)) ∧ (x ∈ y) ⇔-[ [∧][∨]-distributivityᵣ ]
((y ≡ₑ A) ∧ (x ∈ y)) ∨ ((y ≡ₑ B) ∧ (x ∈ y)) ⇔-end
) ]
∃(y ↦ ((y ≡ₑ A) ∧ (x ∈ y)) ∨ ((y ≡ₑ B) ∧ (x ∈ y))) ⇔-[ [∃][∨]-distributivity ]
∃(y ↦ (y ≡ₑ A) ∧ (x ∈ y)) ∨ ∃(y ↦ (y ≡ₑ B) ∧ (x ∈ y)) ⇔-[ [∨]-map-[↔] (p ⦃ rel = binary-unaryRelatorₗ ⦄) (p ⦃ rel = binary-unaryRelatorₗ ⦄) ]
(x ∈ A) ∨ (x ∈ B) ⇔-end
where
-- TODO: Maybe move this somewhere else
p : ∀{T : Type{ℓ₁}} ⦃ equiv : Equiv{ℓₑ₁}(T) ⦄ {P : T → Type{ℓ₂}} ⦃ rel : UnaryRelator(P) ⦄ {y} → ∃(x ↦ (x ≡ₑ y) ∧ P(x)) ↔ P(y)
p {P = P} = [↔]-intro (py ↦ [∃]-intro _ ⦃ [∧]-intro (reflexivity(_≡ₑ_)) py ⦄) (\([∃]-intro x ⦃ [∧]-intro xy px ⦄) → substitute₁(P) xy px)
BoolSet-inclusion : (x ∈ BoolSet) ↔ (x ≡ₑ 𝑇) ∨ (x ≡ₑ 𝐹)
BoolSet-inclusion = pairing
pair-contains-left : a ∈ pair a b
pair-contains-left = [↔]-to-[←] pairing ([∨]-introₗ (reflexivity(_≡ₑ_)))
pair-contains-right : b ∈ pair a b
pair-contains-right = [↔]-to-[←] pairing ([∨]-introᵣ (reflexivity(_≡ₑ_)))
𝑇-in-BoolSet : 𝑇 ∈ BoolSet
𝑇-in-BoolSet = pair-contains-left
𝐹-in-BoolSet : 𝐹 ∈ BoolSet
𝐹-in-BoolSet = pair-contains-right
℘-self : (A ∈ ℘(A))
℘-self = [↔]-to-[←] power id
pair-superset : (x ∈ A) → (y ∈ A) → (pair x y ⊆ A)
pair-superset pa pb p = [∨]-elim
(eq ↦ substitute₂ₗ(_∈_) (symmetry(_≡ₑ_) eq) pa)
(eq ↦ substitute₂ₗ(_∈_) (symmetry(_≡ₑ_) eq) pb)
([↔]-to-[→] pairing p)
pair-superset-union : (a ∈ A) → (b ∈ B) → (pair a b ⊆ (A ∪ B))
pair-superset-union pa pb p = pair-superset (([↔]-to-[←] [∪]-inclusion ∘ [∨]-introₗ) pa) (([↔]-to-[←] [∪]-inclusion ∘ [∨]-introᵣ) pb) p
instance
postulate [≡][⊆]-sub : (_≡_) ⊆₂ (_⊆_)
instance
postulate [⊆]-transitivity : Transitivity(_⊆_)
open import Data.Either as Either using ()
import Data.Tuple as Tuple
open import Syntax.Transitivity
open import Syntax.Implication
[≡][≢]-semitransitivityₗ : (a ≡ₑ b) → (b ≢ c) → (a ≢ c)
[≡][≢]-semitransitivityₗ ab nbc ac = nbc(symmetry(_≡ₑ_) ab 🝖 ac)
[≡][≢]-semitransitivityᵣ : (a ≢ b) → (b ≡ₑ c) → (a ≢ c)
[≡][≢]-semitransitivityᵣ nab bc ac = nab(ac 🝖 symmetry(_≡ₑ_) bc)
nonEmpty-filter : NonEmpty(filter P ⦃ unaryRel ⦄ A) ↔ ∃ₛ(A) P
nonEmpty-filter = [∃]-map-proof-[↔] restricted-comprehension
open import Function.Proofs
instance
singleton-function : Function(singleton)
singleton-function = [$₂]-function
singleton-inclusion : SingletonMembership(singleton)
singleton-inclusion {y = y}{x = x} =
x ∈ pair y y ⇔-[ pairing ]
(x ≡ₑ y) ∨ (x ≡ₑ y) ⇔-[ [∨]-redundancy ]
x ≡ₑ y ⇔-end
singleton-contains-element : a ∈ singleton a
singleton-contains-element = [↔]-to-[←] singleton-inclusion (reflexivity(_≡ₑ_))
singleton-nonempty : NonEmpty(singleton x)
singleton-nonempty{x = x} = [∃]-intro x ⦃ singleton-contains-element ⦄
singleton-superset : (a ∈ A) → (singleton a ⊆ A)
singleton-superset pa p = substitute₂ₗ(_∈_) (symmetry(_≡ₑ_) ([↔]-to-[→] singleton-inclusion p)) pa
zero-one-ineq : (𝟎 ≢ 𝟏)
zero-one-ineq p =
p ⇒
𝟎 ≡ₑ 𝟏 ⇒-[ p ↦ [↔]-to-[→] set-extensionality p {𝟎} ]
(𝟎 ∈ 𝟎) ↔ (𝟎 ∈ 𝟏) ⇒-[ [↔]-to-[←] ]
(𝟎 ∈ 𝟎) ← (𝟎 ∈ 𝟏) ⇒-[ apply ([↔]-to-[←] [∪]-inclusion ([∨]-introᵣ ([↔]-to-[←] singleton-inclusion (reflexivity(_≡ₑ_))))) ]
(𝟎 ∈ 𝟎) ⇒-[ empty ]
⊥ ⇒-end
| {
"alphanum_fraction": 0.5930849232,
"avg_line_length": 45.9462025316,
"ext": "agda",
"hexsha": "b8bce261464b014e254b315464a40c731854c0ee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Sets/ZFC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Sets/ZFC.agda",
"max_line_length": 581,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Sets/ZFC.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 5460,
"size": 14519
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of general interleavings
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Ternary.Interleaving.Properties where
open import Data.Nat
open import Data.Nat.Properties using (+-suc)
open import Data.List.Base hiding (_∷ʳ_)
open import Data.List.Properties using (reverse-involutive)
open import Data.List.Relation.Ternary.Interleaving hiding (map)
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; cong; module ≡-Reasoning)
open ≡-Reasoning
------------------------------------------------------------------------
-- length
module _ {a b c l r} {A : Set a} {B : Set b} {C : Set c}
{L : REL A C l} {R : REL B C r} where
interleave-length : ∀ {as l r} → Interleaving L R l r as →
length as ≡ length l + length r
interleave-length [] = refl
interleave-length (l ∷ˡ sp) = cong suc (interleave-length sp)
interleave-length {as} {l} {r ∷ rs} (_ ∷ʳ sp) = begin
length as ≡⟨ cong suc (interleave-length sp) ⟩
suc (length l + length rs) ≡⟨ sym $ +-suc _ _ ⟩
length l + length (r ∷ rs) ∎
------------------------------------------------------------------------
-- _++_
++⁺ : ∀ {as₁ as₂ l₁ l₂ r₁ r₂} →
Interleaving L R as₁ l₁ r₁ → Interleaving L R as₂ l₂ r₂ →
Interleaving L R (as₁ ++ as₂) (l₁ ++ l₂) (r₁ ++ r₂)
++⁺ [] sp₂ = sp₂
++⁺ (l ∷ˡ sp₁) sp₂ = l ∷ˡ (++⁺ sp₁ sp₂)
++⁺ (r ∷ʳ sp₁) sp₂ = r ∷ʳ (++⁺ sp₁ sp₂)
++-disjoint : ∀ {as₁ as₂ l₁ r₂} →
Interleaving L R l₁ [] as₁ → Interleaving L R [] r₂ as₂ →
Interleaving L R l₁ r₂ (as₁ ++ as₂)
++-disjoint [] sp₂ = sp₂
++-disjoint (l ∷ˡ sp₁) sp₂ = l ∷ˡ ++-disjoint sp₁ sp₂
------------------------------------------------------------------------
-- map
module _ {a b c d e f l r}
{A : Set a} {B : Set b} {C : Set c}
{D : Set d} {E : Set e} {F : Set f}
{L : REL A C l} {R : REL B C r}
(f : E → A) (g : F → B) (h : D → C)
where
map⁺ : ∀ {as l r} →
Interleaving (λ x z → L (f x) (h z)) (λ y z → R (g y) (h z)) l r as →
Interleaving L R (map f l) (map g r) (map h as)
map⁺ [] = []
map⁺ (l ∷ˡ sp) = l ∷ˡ map⁺ sp
map⁺ (r ∷ʳ sp) = r ∷ʳ map⁺ sp
map⁻ : ∀ {as l r} →
Interleaving L R (map f l) (map g r) (map h as) →
Interleaving (λ x z → L (f x) (h z)) (λ y z → R (g y) (h z)) l r as
map⁻ {[]} {[]} {[]} [] = []
map⁻ {_ ∷ _} {[]} {_ ∷ _} (r ∷ʳ sp) = r ∷ʳ map⁻ sp
map⁻ {_ ∷ _} {_ ∷ _} {[]} (l ∷ˡ sp) = l ∷ˡ map⁻ sp
map⁻ {_ ∷ _} {_ ∷ _} {_ ∷ _} (l ∷ˡ sp) = l ∷ˡ map⁻ sp
map⁻ {_ ∷ _} {_ ∷ _} {_ ∷ _} (r ∷ʳ sp) = r ∷ʳ map⁻ sp
-- impossible cases needed until 2.6.0
map⁻ {[]} {_} {_ ∷ _} ()
map⁻ {[]} {_ ∷ _} {_} ()
map⁻ {_ ∷ _} {[]} {[]} ()
------------------------------------------------------------------------
-- reverse
module _ {a b c l r} {A : Set a} {B : Set b} {C : Set c}
{L : REL A C l} {R : REL B C r}
where
reverseAcc⁺ : ∀ {as₁ as₂ l₁ l₂ r₁ r₂} →
Interleaving L R l₁ r₁ as₁ →
Interleaving L R l₂ r₂ as₂ →
Interleaving L R (reverseAcc l₁ l₂) (reverseAcc r₁ r₂) (reverseAcc as₁ as₂)
reverseAcc⁺ sp₁ [] = sp₁
reverseAcc⁺ sp₁ (l ∷ˡ sp₂) = reverseAcc⁺ (l ∷ˡ sp₁) sp₂
reverseAcc⁺ sp₁ (r ∷ʳ sp₂) = reverseAcc⁺ (r ∷ʳ sp₁) sp₂
reverse⁺ : ∀ {as l r} → Interleaving L R l r as →
Interleaving L R (reverse l) (reverse r) (reverse as)
reverse⁺ = reverseAcc⁺ []
reverse⁻ : ∀ {as l r} → Interleaving L R (reverse l) (reverse r) (reverse as) →
Interleaving L R l r as
reverse⁻ {as} {l} {r} sp with reverse⁺ sp
... | sp′ rewrite reverse-involutive as
| reverse-involutive l
| reverse-involutive r = sp′
| {
"alphanum_fraction": 0.4586206897,
"avg_line_length": 37.5925925926,
"ext": "agda",
"hexsha": "ad30a61510cc057c6092345f220267d2f802d706",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Properties.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1465,
"size": 4060
} |
{-# OPTIONS --cubical --safe #-}
module Lens.Definition where
open import Prelude
record LensPart (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
constructor lens-part
eta-equality
field
get : B
set : B → A
open LensPart public
map-lens-part : LensPart A C → (A → B) → LensPart B C
get (map-lens-part xs f) = get xs
set (map-lens-part xs f) x = f (set xs x)
record LensLaws {A : Type a} {B : Type b} (into : A → LensPart A B) : Type (a ℓ⊔ b) where
no-eta-equality
field
get-set : ∀ s v → into (into s .set v) .get ≡ v
set-get : ∀ s → into s .set (into s .get) ≡ s
set-set : ∀ s v₁ v₂ → into (into s .set v₁) .set v₂ ≡ into s .set v₂
open LensLaws public
Lens : Type a → Type b → Type (a ℓ⊔ b)
Lens A B = Σ (A → LensPart A B) LensLaws
| {
"alphanum_fraction": 0.6038961039,
"avg_line_length": 26.5517241379,
"ext": "agda",
"hexsha": "289ce81dde5cc4e481e0eb94e5deddb8be1dd091",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Lens/Definition.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Lens/Definition.agda",
"max_line_length": 89,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Lens/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 295,
"size": 770
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.Posets where
-- The category of partially ordered sets and order-preserving maps.
open import Level
open import Relation.Binary using (Poset; IsEquivalence; _Preserves_⟶_)
open import Relation.Binary.Morphism using (IsOrderHomomorphism)
import Relation.Binary.Morphism.Construct.Identity as Id
import Relation.Binary.Morphism.Construct.Composition as Comp
open import Categories.Category
open Poset renaming (_≈_ to ₍_₎_≈_; _≤_ to ₍_₎_≤_)
private
variable
a₁ a₂ a₃ b₁ b₂ b₃ : Level
A B C : Poset a₁ a₂ a₃
record _⇒-Poset_ (A : Poset a₁ a₂ a₃) (B : Poset b₁ b₂ b₃) : Set (a₁ ⊔ a₂ ⊔ a₃ ⊔ b₁ ⊔ b₂ ⊔ b₃) where
field
fun : Carrier A → Carrier B
isOrderHomomorphism : IsOrderHomomorphism ₍ A ₎_≈_ ₍ B ₎_≈_ ₍ A ₎_≤_ ₍ B ₎_≤_ fun
open IsOrderHomomorphism isOrderHomomorphism public
renaming (mono to monotone)
open _⇒-Poset_
⇒-Poset-id : A ⇒-Poset A
⇒-Poset-id = record
{ isOrderHomomorphism = Id.isOrderHomomorphism _ _
}
⇒-Poset-∘ : B ⇒-Poset C → A ⇒-Poset B → A ⇒-Poset C
⇒-Poset-∘ B⇒C A⇒B = record
{ isOrderHomomorphism = Comp.isOrderHomomorphism (isOrderHomomorphism A⇒B) (isOrderHomomorphism B⇒C)
}
module _ {A : Poset a₁ a₂ a₃} {B : Poset b₁ b₂ b₃} where
infix 4 _≗_
-- Order morphisms preserve equality.
mono⇒cong : ∀ {f} → f Preserves ₍ A ₎_≤_ ⟶ ₍ B ₎_≤_ → f Preserves ₍ A ₎_≈_ ⟶ ₍ B ₎_≈_
mono⇒cong {f} monotone x≈y = antisym B
(monotone (reflexive A x≈y))
(monotone (reflexive A (Eq.sym A x≈y)))
⇒-Poset-helper : ∀ f → f Preserves ₍ A ₎_≤_ ⟶ ₍ B ₎_≤_ → A ⇒-Poset B
⇒-Poset-helper f mono = record
{ isOrderHomomorphism = record
{ cong = mono⇒cong mono
; mono = mono
}
}
-- Pointwise equality (on order preserving maps).
_≗_ : (f g : A ⇒-Poset B) → Set (a₁ ⊔ b₂)
f ≗ g = ∀ {x} → ₍ B ₎ fun f x ≈ fun g x
≗-isEquivalence : IsEquivalence _≗_
≗-isEquivalence = record
{ refl = Eq.refl B
; sym = λ f≈g → Eq.sym B f≈g
; trans = λ f≈g g≈h → Eq.trans B f≈g g≈h
}
module ≗ = IsEquivalence ≗-isEquivalence
-- The category of posets and order-preserving maps.
Posets : ∀ c ℓ₁ ℓ₂ → Category (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) (c ⊔ ℓ₁ ⊔ ℓ₂) (c ⊔ ℓ₁)
Posets c ℓ₁ ℓ₂ = record
{ Obj = Poset c ℓ₁ ℓ₂
; _⇒_ = _⇒-Poset_
; _≈_ = _≗_
; id = ⇒-Poset-id
; _∘_ = ⇒-Poset-∘
; assoc = λ {_ _ _ D} → Eq.refl D
; sym-assoc = λ {_ _ _ D} → Eq.refl D
; identityˡ = λ {_ B} → Eq.refl B
; identityʳ = λ {_ B} → Eq.refl B
; identity² = λ {A} → Eq.refl A
; equiv = ≗-isEquivalence
; ∘-resp-≈ = λ {_ _ C _ h} f≈h g≈i → Eq.trans C f≈h (cong h g≈i)
}
| {
"alphanum_fraction": 0.6029574861,
"avg_line_length": 30.0555555556,
"ext": "agda",
"hexsha": "7da18df9e43ed7c0419bfbdf0aea4c5412d42e1b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d07746023503cc8f49670e309a6170dc4b404b95",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Instance/Posets.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d07746023503cc8f49670e309a6170dc4b404b95",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Instance/Posets.agda",
"max_line_length": 102,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FintanH/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Instance/Posets.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-18T18:21:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-18T18:21:47.000Z",
"num_tokens": 1176,
"size": 2705
} |
{- --- 3. Natural numbers --- -}
{- 3.1 Definition -}
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{- 3.2 Addition -}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
{- 3.3 Multiplication -}
_*_ : ℕ → ℕ → ℕ
zero * b = zero
suc a * b = b + (a * b)
{- 3.4 Equality is a congruence for successor -}
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
infix 4 _≡_
suc-≡ : {m n : ℕ} → (m ≡ n) → (suc m ≡ suc n)
suc-≡ refl = refl
{- 3.5 Some properties -}
zeroL : (n : ℕ) → zero + n ≡ n
zeroL n = refl
zeroR : (n : ℕ) → n + zero ≡ n
zeroR zero = refl
zeroR (suc n) = suc-≡ (zeroR n)
+-assoc : (m n p : ℕ) → ((m + n) + p) ≡ (m + (n + p))
+-assoc zero n p = refl
+-assoc (suc m) n p = suc-≡ (+-assoc m n p)
one : ℕ
one = suc zero
+-assoc1 : (m n : ℕ) → ((m + n) + one) ≡ (m + (n + one))
+-assoc1 m n = +-assoc m n one
{- Falsity type, needed for the next property -}
data ⊥ : Set where
{- ¬ : Set → Set
¬ A = A → ⊥ -}
open import Relation.Nullary
suc-notzero : (n : ℕ) → ¬ (zero ≡ suc n)
suc-notzero n ()
{- 3.6 The recurrence principle -}
rec : (P : ℕ → Set) → (P zero) → ((n : ℕ) → (P n) → (P (suc n))) → ((n : ℕ) → P n)
rec p z h zero = z
rec p z h (suc n) = h n (rec p z h n)
{- 3.7 Properties of equality -}
sym : {A : Set} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
cong : {A B : Set} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
p : {m n : ℕ} → (e : m ≡ n) → suc-≡ e ≡ cong suc e
p refl = refl
subst : {A : Set} (P : A → Set) → {x y : A} → x ≡ y → P x → P y
subst P refl p = p
{- 3.8 Commutativity of addition -}
+-suc : (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n = suc-≡ (+-suc m n)
+-commut : (m n : ℕ) → m + n ≡ n + m
+-commut m zero = zeroR m
+-commut m (suc n) = trans (+-suc m n) (suc-≡ (+-commut m n))
{- 3.9 Injectivity of successor -}
suc-inj : {m n : ℕ} → suc m ≡ suc n → m ≡ n
suc-inj refl = refl
{- 3.10 Decidability of equality -}
open import Data.Sum renaming (_⊎_ to _∨_ ; inj₁ to left ; inj₂ to right)
ℕ-≡-dec : (m n : ℕ) → (m ≡ n) ∨ ¬ (m ≡ n)
ℕ-≡-dec zero zero = left refl
ℕ-≡-dec zero (suc n) = right (suc-notzero n)
ℕ-≡-dec (suc m) zero = right λ ()
ℕ-≡-dec (suc m) (suc n) with ℕ-≡-dec m n
ℕ-≡-dec (suc m) (suc n) | left e = left (suc-≡ e)
ℕ-≡-dec (suc m) (suc n) | right e' = right λ x → e' (suc-inj x)
{- 3.11 Recurrence for equality -}
J : (A : Set) → (P : (x : A) → (y : A) → (p : x ≡ y) → Set) → (r : (x : A) → P x x refl) → (x : A) → (y : A) → (p : x ≡ y) → P x y p
J A P r x .x refl = r x
| {
"alphanum_fraction": 0.4918541505,
"avg_line_length": 24.320754717,
"ext": "agda",
"hexsha": "2c99c243deac47fe056feaf393eece417915a64b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "erwinkn/program-eq-proof",
"max_forks_repo_path": "TD6/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "erwinkn/program-eq-proof",
"max_issues_repo_path": "TD6/Nat.agda",
"max_line_length": 132,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "erwinkn/program-eq-proof",
"max_stars_repo_path": "TD6/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1194,
"size": 2578
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Booleans
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Bool where
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl)
------------------------------------------------------------------------
-- The boolean type and some operations
open import Data.Bool.Base public
------------------------------------------------------------------------
-- Publicly re-export queries
open import Data.Bool.Properties public
using (_≟_; _≤?_; _<?_)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
decSetoid = Data.Bool.Properties.≡-decSetoid
{-# WARNING_ON_USAGE decSetoid
"Warning: decSetoid was deprecated in v1.1.
Please use ≡-decSetoid from Data.Bool.Properties instead."
#-}
| {
"alphanum_fraction": 0.4648370497,
"avg_line_length": 28.4390243902,
"ext": "agda",
"hexsha": "0c0c78b8bcafc13d1cdc954503d7a528c1a02b94",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Bool.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 197,
"size": 1166
} |
{-# OPTIONS --copatterns #-}
module TestsInstances where
open import Function
open import Data.Product
open import Relation.Nullary using (Dec; yes; no; ¬_)
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
open import Data.Empty renaming (⊥ to Empty)
open import Data.Unit renaming (⊤ to One) hiding (_≟_)
open import Data.Bool hiding (_≟_)
open import Data.Bool.Properties using (¬-not; T-not-≡)
open import Data.Nat hiding (_⊔_)
open import Isomorphisms
open import Tests
-- | Functions are testable if their codomain is
FunTestable : {A B : Set} → Testable B → Testable (A → B)
FunTestable {A} {B} TB =
record
{ index = A
; parts = λ _ → B
; kind = coind
; obs = λ f → record { app = f }
; partsTestable = λ _ → TB
}
FunIsoTestable : {A B : Set} → IsoTestable B → IsoTestable (A → B)
FunIsoTestable T =
record
{ testable = FunTestable (testable T)
; obsIso = (record { inv = app
; isLeftInv = λ a → refl
; isRightInv = λ b → refl })
}
-- | We get extensionality for functions under observational equivalence.
ext : {A B : Set} → (T : Testable B) →
(f : A → B) → (g : A → B) →
((a : A) → f a ≃⟨ T ⟩ g a) → f ≃⟨ FunTestable T ⟩ g
ext {A} {B} TB f g p = record { eqProof = q }
where
q : (φ : Test (FunTestable TB)) → f ⊨ φ ≡ g ⊨ φ
q ⊤ = refl
q ⊥ = refl
q (nonTriv (i , ψ)) = eqProof (p i) ψ
-- | Make unit type testable
⊤-testable : Testable One
index ⊤-testable = One
parts ⊤-testable = λ _ → One
kind ⊤-testable = coind
obs ⊤-testable = λ { tt → record { app = λ x → x } }
partsTestable ⊤-testable = λ i → ⊤-testable
⊤-IsoTestable : IsoTestable One
⊤-IsoTestable =
record
{ testable = ⊤-testable
; obsIso =
record { inv = λ f → app f tt
; isLeftInv = λ a → refl
; isRightInv = λ b → refl
}
}
-- | Obs. equiv. is a congruence on ⊤.
≃-cong-⊤ : {A : Set} → {T : Testable A} → {x y : One} →
(f : One → A) → x ≃⟨ ⊤-testable ⟩ y → f x ≃⟨ T ⟩ f y
≃-cong-⊤ f p = record { eqProof = λ φ → refl }
Parts-ℕ : Bool → Set
Parts-ℕ true = One
Parts-ℕ false = ℕ
rep-ℕ : ℕ → Σ Bool Parts-ℕ
rep-ℕ ℕ.zero = (true , tt)
rep-ℕ (ℕ.suc n) = (false , n)
unrep-ℕ : Σ Bool Parts-ℕ → ℕ
unrep-ℕ (true , tt) = ℕ.zero
unrep-ℕ (false , n) = ℕ.suc n
-- | Make naturals testable
ℕ-testable : Testable ℕ
index ℕ-testable = Bool
parts ℕ-testable = Parts-ℕ
kind ℕ-testable = ind
obs ℕ-testable = rep-ℕ
partsTestable ℕ-testable = λ
{ true → ⊤-testable
; false → ℕ-testable }
ℕ-IsoTestable : IsoTestable ℕ
ℕ-IsoTestable =
record
{ testable = ℕ-testable
; obsIso =
record { inv = unrep-ℕ
; isLeftInv = li
; isRightInv = ri
}
}
where
li : (n : ℕ) → unrep-ℕ (rep-ℕ n) ≡ n
li ℕ.zero = refl
li (ℕ.suc a) = refl
ri : (x : Σ Bool Parts-ℕ) → rep-ℕ (unrep-ℕ x) ≡ x
ri (true , tt) = refl
ri (false , n) = refl
¬zero→suc : (n : ℕ) → n ≢ zero → ∃ (λ m → n ≡ suc m)
¬zero→suc n p with n ≟ zero
¬zero→suc zero p | yes n=z = ⊥-elim (p n=z)
¬zero→suc (suc m) p | yes sm=z = ⊥-elim (p sm=z)
¬zero→suc zero p | no ¬n=z = ⊥-elim (p refl)
¬zero→suc (suc n) p | no ¬n=z = n , refl
lem-tt≢ff : (a : Bool) → a ≡ true → a ≢ false
lem-tt≢ff true _ ()
lem-tt≢ff false () _
-- | If a number is observationally equivalent to 0, then it is
-- actually 0.
lem-≃→≡-ℕ-zero : {n : ℕ} → n ≃⟨ ℕ-testable ⟩ zero → n ≡ zero
lem-≃→≡-ℕ-zero {n} p = q
where
-- Test to distinguish zero
ψs : SubTests ℕ-testable ind
ψs = record { app = λ {
true → ⊤ ;
false → ⊥ } }
φ : Test ℕ-testable
φ = nonTriv ψs
-- n fulfils test, ...
u : n ⊨ φ ≡ true
u = eqProof p φ
-- ... hence is 0.
q : n ≡ zero
q with n ≟ zero
q | yes n=z = n=z
q | no ¬n=z = ⊥-elim (lem (¬zero→suc n ¬n=z))
where
-- If n ≡ suc n, then we get a contradiction to u
lem : (∃ (λ m → n ≡ suc m)) → Empty
lem (m , q) with (n ≟ suc m)
... | yes n=sm = lem-tt≢ff (n ⊨ φ) u contradict
where
contradict : n ⊨ φ ≡ false
contradict =
begin
n ⊨ φ
≡⟨ refl ⟩
cotuple (λ i y → y ⊨ app ψs i) (rep-ℕ n)
≡⟨ cong (λ u → cotuple (λ i y → y ⊨ app ψs i) (rep-ℕ u)) n=sm ⟩
cotuple (λ i y → y ⊨ app ψs i) (false , n)
≡⟨ refl ⟩
false
∎
... | no ¬n=sm = ¬n=sm q
-- | If a number is observationally equivalent to a successor, then it is
-- actually a succesor.
lem-≃→≡-ℕ-suc : (n m : ℕ) → n ≃⟨ ℕ-testable ⟩ suc m →
∃ λ n' → (n ≡ suc n') × (n' ≃⟨ ℕ-testable ⟩ m)
lem-≃→≡-ℕ-suc = {!!}
-- | Observational equivalence for natural numbers implies equivalence.
≃→≡-ℕ : {n m : ℕ} → n ≃⟨ ℕ-testable ⟩ m → n ≡ m
≃→≡-ℕ {n} {zero} p = lem-≃→≡-ℕ-zero p
≃→≡-ℕ {n} {(suc m)} p with lem-≃→≡-ℕ-suc n m p
... | n' , q , p' =
begin
n
≡⟨ q ⟩
suc n'
≡⟨ cong suc (≃→≡-ℕ {n'} {m} p') ⟩
suc m
∎
-- | Obs. equiv. is a congruence for natural numbers.
≃-cong-ℕ : {A : Set} → {T : Testable A} → {x y : ℕ} →
(f : ℕ → A) → x ≃⟨ ℕ-testable ⟩ y → f x ≃⟨ T ⟩ f y
≃-cong-ℕ {A} {T} {x} {y} f p = record { eqProof = q }
where
q : (φ : Test T) → f x ⊨ φ ≡ f y ⊨ φ
q φ = cong (λ u → f u ⊨ φ) (≃→≡-ℕ p)
| {
"alphanum_fraction": 0.52,
"avg_line_length": 27.5773195876,
"ext": "agda",
"hexsha": "103e0eb49ecfce74bcf33771b142bdb923df86ea",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "OTTTests/TestsInstances.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "OTTTests/TestsInstances.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "OTTTests/TestsInstances.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2176,
"size": 5350
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidable vector equality over propositional equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
module Data.Vec.Relation.Binary.Equality.DecPropositional
{a} {A : Set a} (_≟_ : Decidable {A = A} _≡_) where
import Data.Vec.Relation.Binary.Equality.Propositional as PEq
import Data.Vec.Relation.Binary.Equality.DecSetoid as DSEq
------------------------------------------------------------------------
-- Publicly re-export everything from decSetoid and propositional
-- equality
open PEq public
open DSEq (decSetoid _≟_) public
using (_≋?_; ≋-isDecEquivalence; ≋-decSetoid)
| {
"alphanum_fraction": 0.5640718563,
"avg_line_length": 33.4,
"ext": "agda",
"hexsha": "77d67d040f401a165bf2ec383851cc58487ceb91",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Equality/DecPropositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Equality/DecPropositional.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Equality/DecPropositional.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 179,
"size": 835
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Integers.Definition
module Numbers.Integers.Multiplication where
infix 25 _*Z_
_*Z_ : ℤ → ℤ → ℤ
nonneg x *Z nonneg y = nonneg (x *N y)
nonneg zero *Z negSucc y = nonneg zero
nonneg (succ x) *Z negSucc y = negSucc ((succ x) *N y +N x)
negSucc x *Z nonneg zero = nonneg zero
negSucc x *Z nonneg (succ y) = negSucc ((succ y) *N x +N y)
negSucc x *Z negSucc y = nonneg ((succ x) *N (succ y))
*ZInherits : (a b : ℕ) → nonneg (a *N b) ≡ (nonneg a) *Z (nonneg b)
*ZInherits a b = refl
| {
"alphanum_fraction": 0.6768982229,
"avg_line_length": 30.95,
"ext": "agda",
"hexsha": "6f0ebd50db4b4f813d6c85eaaf8ff489a9775e3e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Integers/Multiplication.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Integers/Multiplication.agda",
"max_line_length": 67,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Integers/Multiplication.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 231,
"size": 619
} |
{-# OPTIONS --cubical --safe #-}
open import Prelude
open import Relation.Binary
module Relation.Binary.Construct.Decision
{a ℓ₁ ℓ₂} {A : Type a}
(ord : TotalOrder A ℓ₁ ℓ₂)
where
open TotalOrder ord renaming (refl to ≤-refl)
_<′_ : A → A → Type
x <′ y = T (does (x <? y))
_≤′_ : A → A → Type
x ≤′ y = T (not (does (y <? x)))
witness-< : ∀ {x y} → x <′ y → x < y
witness-< {x} {y} p with x <? y
witness-< {x} {y} p | yes q = q
witness-≤ : ∀ {x y} → x ≤′ y → x ≤ y
witness-≤ {x} {y} p with y <? x
witness-≤ {x} {y} p | no q = ≮⇒≥ q
compute-< : ∀ {x y} → x < y → x <′ y
compute-< {x} {y} p with x <? y
compute-< {x} {y} p | yes q = tt
compute-< {x} {y} p | no ¬p = ⊥-elim (¬p p)
compute-≤ : ∀ {x y} → x ≤ y → x ≤′ y
compute-≤ {x} {y} ¬p with y <? x
compute-≤ {x} {y} ¬p | yes p = ⊥-elim (<⇒≱ p ¬p)
compute-≤ {x} {y} ¬p | no _ = tt
≰⇒>′ : ∀ {x y} → ¬ (x ≤′ y) → y <′ x
≰⇒>′ {x} {y} p with y <? x
≰⇒>′ {x} {y} p | no _ = p tt
≰⇒>′ {x} {y} p | yes _ = tt
≮⇒≥′ : ∀ {x y} → ¬ (x <′ y) → y ≤′ x
≮⇒≥′ {x} {y} p with x <? y
≮⇒≥′ {x} {y} p | no _ = tt
≮⇒≥′ {x} {y} p | yes _ = p tt
dec-ord : TotalOrder A ℓzero ℓzero
StrictPreorder._<_ (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder dec-ord)) = _<′_
StrictPreorder.trans (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder dec-ord)) p q = compute-< (<-trans (witness-< p) (witness-< q))
StrictPreorder.irrefl (StrictPartialOrder.strictPreorder (TotalOrder.strictPartialOrder dec-ord)) p = irrefl (witness-< p)
StrictPartialOrder.conn (TotalOrder.strictPartialOrder dec-ord) p q = conn (p ∘ compute-<) (q ∘ compute-<)
Preorder._≤_ (PartialOrder.preorder (TotalOrder.partialOrder dec-ord)) = _≤′_
Preorder.refl (PartialOrder.preorder (TotalOrder.partialOrder dec-ord)) = compute-≤ ≤-refl
PartialOrder.antisym (TotalOrder.partialOrder dec-ord) p q = antisym (witness-≤ p) (witness-≤ q)
Preorder.trans (PartialOrder.preorder (TotalOrder.partialOrder dec-ord)) p q = compute-≤ (≤-trans (witness-≤ p) (witness-≤ q))
TotalOrder._<?_ dec-ord x y = iff-dec (compute-< iff witness-<) (x <? y)
TotalOrder.≰⇒> dec-ord = ≰⇒>′
TotalOrder.≮⇒≥ dec-ord = ≮⇒≥′
| {
"alphanum_fraction": 0.5877684407,
"avg_line_length": 35.1147540984,
"ext": "agda",
"hexsha": "c23babad83f885446f02442818983667a0bf97dc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Relation/Binary/Construct/Decision.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Relation/Binary/Construct/Decision.agda",
"max_line_length": 151,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Relation/Binary/Construct/Decision.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 942,
"size": 2142
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.Exactness
open import cohomology.FunctionOver
{- Splitting Lemma - Left Split
Assume an exact sequence:
φ ψ
G → H → K → 0
where H is abelian. If φ has a left inverse χ, then H == G × K. Over
this path φ becomes the natural injection and ψ the natural projection.
The only non-private terms are [iso], [φ-over-iso], and [ψ-over-iso].
-}
module cohomology.SplitExactLeft {i} {G H K L : Group i}
(H-abelian : is-abelian H) (φ : G →ᴳ H) (ψ : H →ᴳ K) where
private
module G = Group G
module H = Group H
module K = Group K
module φ = GroupHom φ
module ψ = GroupHom ψ
module SplitExactLeft
(ex : is-exact-seq (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ K ⟨ cst-hom ⟩→ L ⊣|))
(χ : H →ᴳ G) (χ-linv : (g : G.El) → GroupHom.f χ (φ.f g) == g)
where
private
module χ = GroupHom χ
{- H == Im φ ×G Ker χ -}
im-part : H →ᴳ Im φ
im-part = im-in-hom φ ∘ᴳ χ
im-part-imφ : (h : H.El) (s : Trunc -1 (Σ G.El (λ g → φ.f g == h)))
→ GroupHom.f im-part h == (h , s)
im-part-imφ h s = pair=
(Trunc-rec (Group.El-level H _ _)
(λ {(g , p) →
φ.f (χ.f h) =⟨ ap (φ.f ∘ χ.f) (! p) ⟩
φ.f (χ.f (φ.f g)) =⟨ ap φ.f (χ-linv g) ⟩
φ.f g =⟨ p ⟩
h ∎})
s)
(prop-has-all-paths-↓ Trunc-level)
im-part-kerχ : (h : H.El) (p : χ.f h == G.ident)
→ GroupHom.f im-part h == Group.ident (Im φ)
im-part-kerχ h p = pair=
(ap φ.f p ∙ φ.pres-ident)
(prop-has-all-paths-↓ Trunc-level)
ker-part : H →ᴳ Ker χ
ker-part = ker-hom χ
(comp-hom H-abelian (idhom H) (inv-hom H H-abelian ∘ᴳ (φ ∘ᴳ χ)))
(λ h →
χ.f (H.comp h (H.inv (φ.f (χ.f h))))
=⟨ χ.pres-comp h (H.inv (φ.f (χ.f h))) ⟩
G.comp (χ.f h) (χ.f (H.inv (φ.f (χ.f h))))
=⟨ ! (φ.pres-inv (χ.f h))
|in-ctx (λ w → G.comp (χ.f h) (χ.f w)) ⟩
G.comp (χ.f h) (χ.f (φ.f (G.inv (χ.f h))))
=⟨ χ-linv (G.inv (χ.f h)) |in-ctx (λ w → G.comp (χ.f h) w) ⟩
G.comp (χ.f h) (G.inv (χ.f h))
=⟨ G.invr (χ.f h) ⟩
G.ident ∎)
ker-part-imφ : (h : H.El) → Trunc -1 (Σ G.El (λ g → φ.f g == h))
→ GroupHom.f ker-part h == Group.ident (Ker χ)
ker-part-imφ h = Trunc-rec (Group.El-level (Ker χ) _ _) $
λ {(g , p) → pair=
(H.comp h (H.inv (φ.f (χ.f h)))
=⟨ ! p |in-ctx (λ w → H.comp w (H.inv (φ.f (χ.f w)))) ⟩
H.comp (φ.f g) (H.inv (φ.f (χ.f (φ.f g))))
=⟨ χ-linv g |in-ctx (λ w → H.comp (φ.f g) (H.inv (φ.f w))) ⟩
H.comp (φ.f g) (H.inv (φ.f g))
=⟨ H.invr (φ.f g) ⟩
H.ident ∎)
(prop-has-all-paths-↓ (Group.El-level G _ _))}
ker-part-kerχ : (h : H.El) (p : χ.f h == G.ident)
→ GroupHom.f ker-part h == (h , p)
ker-part-kerχ h p = pair=
(H.comp h (H.inv (φ.f (χ.f h)))
=⟨ p |in-ctx (λ w → H.comp h (H.inv (φ.f w))) ⟩
H.comp h (H.inv (φ.f G.ident))
=⟨ φ.pres-ident |in-ctx (λ w → H.comp h (H.inv w)) ⟩
H.comp h (H.inv H.ident)
=⟨ group-inv-ident H |in-ctx H.comp h ⟩
H.comp h H.ident
=⟨ H.unitr h ⟩
h ∎)
(prop-has-all-paths-↓ (Group.El-level G _ _))
decomp : H →ᴳ Im φ ×ᴳ Ker χ
decomp = ×ᴳ-hom-in im-part ker-part
decomp-is-equiv : is-equiv (GroupHom.f decomp)
decomp-is-equiv = is-eq _ dinv decomp-dinv dinv-decomp
where
dinv : Group.El (Im φ ×ᴳ Ker χ) → H.El
dinv ((h₁ , _) , (h₂ , _)) = H.comp h₁ h₂
decomp-dinv : ∀ s → GroupHom.f decomp (dinv s) == s
decomp-dinv ((h₁ , im) , (h₂ , kr)) = pair×=
(GroupHom.f im-part (H.comp h₁ h₂)
=⟨ GroupHom.pres-comp im-part h₁ h₂ ⟩
Group.comp (Im φ) (GroupHom.f im-part h₁) (GroupHom.f im-part h₂)
=⟨ im-part-imφ h₁ im
|in-ctx (λ w → Group.comp (Im φ) w (GroupHom.f im-part h₂)) ⟩
Group.comp (Im φ) (h₁ , im) (GroupHom.f im-part h₂)
=⟨ im-part-kerχ h₂ kr
|in-ctx (λ w → Group.comp (Im φ) (h₁ , im) w) ⟩
Group.comp (Im φ) (h₁ , im) (Group.ident (Im φ))
=⟨ Group.unitr (Im φ) (h₁ , im) ⟩
(h₁ , im) ∎)
(GroupHom.f ker-part (H.comp h₁ h₂)
=⟨ GroupHom.pres-comp ker-part h₁ h₂ ⟩
Group.comp (Ker χ) (GroupHom.f ker-part h₁) (GroupHom.f ker-part h₂)
=⟨ ker-part-imφ h₁ im
|in-ctx (λ w → Group.comp (Ker χ) w (GroupHom.f ker-part h₂)) ⟩
Group.comp (Ker χ) (Group.ident (Ker χ)) (GroupHom.f ker-part h₂)
=⟨ ker-part-kerχ h₂ kr
|in-ctx (λ w → Group.comp (Ker χ) (Group.ident (Ker χ)) w) ⟩
Group.comp (Ker χ) (Group.ident (Ker χ)) (h₂ , kr)
=⟨ Group.unitl (Ker χ) (h₂ , kr) ⟩
(h₂ , kr) ∎)
dinv-decomp : ∀ h → dinv (GroupHom.f decomp h) == h
dinv-decomp h =
H.comp (φ.f (χ.f h)) (H.comp h (H.inv (φ.f (χ.f h))))
=⟨ H-abelian (φ.f (χ.f h)) (H.comp h (H.inv (φ.f (χ.f h)))) ⟩
H.comp (H.comp h (H.inv (φ.f (χ.f h)))) (φ.f (χ.f h))
=⟨ H.assoc h (H.inv (φ.f (χ.f h))) (φ.f (χ.f h)) ⟩
H.comp h (H.comp (H.inv (φ.f (χ.f h))) (φ.f (χ.f h)))
=⟨ H.invl (φ.f (χ.f h)) |in-ctx (λ w → H.comp h w) ⟩
H.comp h H.ident
=⟨ H.unitr h ⟩
h ∎
decomp-equiv : H.El ≃ Group.El (Im φ ×ᴳ Ker χ)
decomp-equiv = (_ , decomp-is-equiv)
decomp-iso : H == Im φ ×ᴳ Ker χ
decomp-iso = group-ua (decomp , decomp-is-equiv)
{- K == Ker χ -}
ψ|kerχ-inj : (h : Group.El (Ker χ))
→ ψ.f (GroupHom.f (ker-inj χ) h) == K.ident → h == Group.ident (Ker χ)
ψ|kerχ-inj (h , p) q = pair=
(Trunc-rec (H.El-level _ _)
(λ {(g , r) →
! r ∙ ap φ.f (! (χ-linv g) ∙ ap χ.f r ∙ p) ∙ φ.pres-ident})
(ktoi (exact-get ex 0) h q))
(prop-has-all-paths-↓ (G.El-level _ _))
ψ|kerχ-surj : (k : K.El)
→ Trunc -1 (Σ (Group.El (Ker χ))
(λ h → ψ.f (GroupHom.f (ker-inj χ) h) == k))
ψ|kerχ-surj k = Trunc-fmap
(λ {(h , p) → (GroupHom.f ker-part h ,
ψ.f (H.comp h (H.inv (φ.f (χ.f h))))
=⟨ ψ.pres-comp h (H.inv (φ.f (χ.f h))) ⟩
K.comp (ψ.f h) (ψ.f (H.inv (φ.f (χ.f h))))
=⟨ ψ.pres-inv (φ.f (χ.f h))
|in-ctx (λ k → K.comp (ψ.f h) k) ⟩
K.comp (ψ.f h) (K.inv (ψ.f (φ.f (χ.f h))))
=⟨ itok (exact-get ex 0) (φ.f (χ.f h)) [ χ.f h , idp ]
|in-ctx (λ k → K.comp (ψ.f h) (K.inv k)) ⟩
K.comp (ψ.f h) (K.inv K.ident)
=⟨ group-inv-ident K |in-ctx (λ k → K.comp (ψ.f h) k) ⟩
K.comp (ψ.f h) K.ident
=⟨ K.unitr (ψ.f h) ⟩
ψ.f h
=⟨ p ⟩
k ∎)})
(ktoi (exact-get ex 1) k idp)
ψ|kerχ-is-equiv : is-equiv (GroupHom.f (ψ ∘ᴳ ker-inj χ))
ψ|kerχ-is-equiv = surj-inj-is-equiv (ψ ∘ᴳ ker-inj χ)
(zero-kernel-injective (ψ ∘ᴳ ker-inj χ) ψ|kerχ-inj)
ψ|kerχ-surj
Kerχ-iso-K : Ker χ == K
Kerχ-iso-K = group-ua (ψ ∘ᴳ ker-inj χ , ψ|kerχ-is-equiv)
{- G == Im φ -}
im-in-φ-is-equiv : is-equiv (GroupHom.f (im-in-hom φ))
im-in-φ-is-equiv = surj-inj-is-equiv (im-in-hom φ) inj (im-in-surj φ)
where
inj = zero-kernel-injective (im-in-hom φ)
(λ g p → ! (χ-linv g) ∙ ap (χ.f ∘ fst) p ∙ χ.pres-ident)
G-iso-Imφ : G == Im φ
G-iso-Imφ = group-ua (im-in-hom φ , im-in-φ-is-equiv)
{- H == G ×ᴳ K -}
iso : H == G ×ᴳ K
iso = decomp-iso ∙ ap2 _×ᴳ_ (! G-iso-Imφ) Kerχ-iso-K
private
decomp-φ = ×ᴳ-hom-in (im-in-hom φ) (cst-hom {G = G} {H = Ker χ})
φ-over-decomp : φ == decomp-φ [ (λ J → G →ᴳ J) ↓ decomp-iso ]
φ-over-decomp = codomain-over-iso $ codomain-over-equiv φ.f _ ▹ lemma
where
lemma : GroupHom.f decomp ∘ φ.f == GroupHom.f decomp-φ
lemma = λ= $ λ g → pair×=
(im-part-imφ (φ.f g) [ g , idp ])
(ker-part-imφ (φ.f g) [ g , idp ])
ψ-dinv : Im φ ×ᴳ Ker χ →ᴳ K
ψ-dinv = ψ ∘ᴳ ×ᴳ-sum-hom H-abelian (im-inj φ) (ker-inj χ)
ψ-over-decomp : ψ == ψ-dinv [ (λ J → J →ᴳ K) ↓ decomp-iso ]
ψ-over-decomp = domain-over-iso $ domain!-over-equiv ψ.f _
id-over-G-iso : idhom _ == im-in-hom φ [ (λ J → G →ᴳ J) ↓ G-iso-Imφ ]
id-over-G-iso = codomain-over-iso $ codomain-over-equiv (idf _) _
φ-over-G-iso : φ == im-inj φ [ (λ J → J →ᴳ H) ↓ G-iso-Imφ ]
φ-over-G-iso =
domain-over-iso $ domain-over-equiv (GroupHom.f (im-inj φ)) _
ψ|kerχ-over-K-iso :
ψ ∘ᴳ ker-inj χ == idhom K [ (λ J → J →ᴳ K) ↓ Kerχ-iso-K ]
ψ|kerχ-over-K-iso = domain-over-iso $ domain-over-equiv (idf _) _
φ-over-G-K-isos : decomp-φ == ×ᴳ-inl
[ (λ J → G →ᴳ J) ↓ ap2 _×ᴳ_ (! G-iso-Imφ) Kerχ-iso-K ]
φ-over-G-K-isos = ↓-ap2-in _ _×ᴳ_ $ transport
(λ q → decomp-φ == ×ᴳ-inl [ (λ {(J₁ , J₂) → G →ᴳ J₁ ×ᴳ J₂}) ↓ q ])
(! (pair×=-split-l (! G-iso-Imφ) (Kerχ-iso-K)))
(l ∙ᵈ r)
where
l : decomp-φ == ×ᴳ-hom-in (idhom G) (cst-hom {G = G} {H = Ker χ})
[ (λ {(J₁ , J₂) → G →ᴳ J₁ ×ᴳ J₂})
↓ ap (λ J → J , Ker χ) (! G-iso-Imφ) ]
l = ↓-ap-in _ (λ J → J , Ker χ)
(ap↓ (λ θ → ×ᴳ-hom-in θ (cst-hom {G = G} {H = Ker χ}))
(!ᵈ id-over-G-iso))
r : ×ᴳ-hom-in (idhom G) (cst-hom {G = G} {H = Ker χ}) == ×ᴳ-inl
[ (λ {(J₁ , J₂) → G →ᴳ J₁ ×ᴳ J₂}) ↓ ap (λ J → G , J) Kerχ-iso-K ]
r = ↓-ap-in _ (λ J → G , J)
(apd (λ J → ×ᴳ-hom-in (idhom G) (cst-hom {G = G} {H = J}))
Kerχ-iso-K)
ψ-over-G-K-isos : ψ-dinv == ×ᴳ-snd {G = G}
[ (λ J → J →ᴳ K) ↓ ap2 _×ᴳ_ (! G-iso-Imφ) Kerχ-iso-K ]
ψ-over-G-K-isos = ↓-ap2-in _ _×ᴳ_ $ transport
(λ q → ψ-dinv == ×ᴳ-snd {G = G}
[ (λ {(J₁ , J₂) → J₁ ×ᴳ J₂ →ᴳ K}) ↓ q ])
(! (pair×=-split-l (! G-iso-Imφ) (Kerχ-iso-K)))
(l ∙ᵈ (m ◃ r))
where
l : ψ-dinv == ψ ∘ᴳ ×ᴳ-sum-hom H-abelian φ (ker-inj χ)
[ (λ {(J₁ , J₂) → J₁ ×ᴳ J₂ →ᴳ K})
↓ ap (λ J → J , Ker χ) (! G-iso-Imφ) ]
l = ↓-ap-in _ (λ J → J , Ker χ)
(ap↓ (λ θ → ψ ∘ᴳ ×ᴳ-sum-hom H-abelian θ (ker-inj χ))
(!ᵈ φ-over-G-iso))
m : ψ ∘ᴳ ×ᴳ-sum-hom H-abelian φ (ker-inj χ)
== (ψ ∘ᴳ ker-inj χ) ∘ᴳ ×ᴳ-snd {G = G}
m = hom= _ _ (λ= (λ {(g , (h , _)) →
ψ.f (H.comp (φ.f g) h)
=⟨ ψ.pres-comp (φ.f g) h ⟩
K.comp (ψ.f (φ.f g)) (ψ.f h)
=⟨ itok (exact-get ex 0) (φ.f g) [ g , idp ]
|in-ctx (λ k → K.comp k (ψ.f h)) ⟩
K.comp K.ident (ψ.f h)
=⟨ K.unitl (ψ.f h) ⟩
ψ.f h ∎}))
r : (ψ ∘ᴳ ker-inj χ) ∘ᴳ ×ᴳ-snd {G = G} == ×ᴳ-snd {G = G}
[ (λ {(J₁ , J₂) → J₁ ×ᴳ J₂ →ᴳ K})
↓ (ap (λ J → G , J) Kerχ-iso-K) ]
r = ↓-ap-in _ (λ J → G , J)
(ap↓ (λ θ → θ ∘ᴳ ×ᴳ-snd {G = G}) ψ|kerχ-over-K-iso)
φ-over-iso : φ == ×ᴳ-inl [ (λ J → G →ᴳ J) ↓ iso ]
φ-over-iso = φ-over-decomp ∙ᵈ φ-over-G-K-isos
ψ-over-iso : ψ == (×ᴳ-snd {G = G}) [ (λ J → J →ᴳ K) ↓ iso ]
ψ-over-iso = ψ-over-decomp ∙ᵈ ψ-over-G-K-isos
| {
"alphanum_fraction": 0.4611826592,
"avg_line_length": 36.8762541806,
"ext": "agda",
"hexsha": "279ed8ccfbace842f919e6e06377546d6bcea7e8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/SplitExactLeft.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/SplitExactLeft.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/SplitExactLeft.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4786,
"size": 11026
} |
module Data.Real.Gauge where
import Data.Rational
open Data.Rational using (Rational)
Gauge = Rational
| {
"alphanum_fraction": 0.785046729,
"avg_line_length": 11.8888888889,
"ext": "agda",
"hexsha": "2d549f96549711416db3dfc4ab3a06596a7f0836",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Real/Gauge.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Real/Gauge.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Real/Gauge.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 27,
"size": 107
} |
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
module Quasigroup.Structures
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality relation
where
open import Algebra.Core
open import Level using (_⊔_)
open import Data.Product using (_,_; proj₁; proj₂)
open import Algebra.Definitions _≈_
open import Algebra.Structures _≈_
open import Quasigroup.Definitions _≈_
record IsPique (∙ \\ // : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isQuasigroup : IsQuasigroup ∙ \\ //
idem : Idempotent ∙
open IsQuasigroup isQuasigroup public
| {
"alphanum_fraction": 0.6902515723,
"avg_line_length": 28.9090909091,
"ext": "agda",
"hexsha": "275cd796b4c9fe20dcd769dd966a088b915c302a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Quasigroup/Structures.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Quasigroup/Structures.agda",
"max_line_length": 62,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Quasigroup/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 197,
"size": 636
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.Freudenthal
module homotopy.IterSuspensionStable where
{- π (S k) (Ptd-Susp^ (S n) X) == π k (Ptd-Susp^ n X), where k = S k'
Susp^Stable below assumes k ≠ O instead of taking k' as the argument -}
module Susp^StableSucc {i} (X : Ptd i) (cX : is-connected ⟨0⟩ (fst X))
(n : ℕ) (k' : ℕ) (kle : S k' ≤ n *2) where
{- need k,n ≥ 1 -}
k : ℕ
k = S k'
{- some numeric computations -}
private
kle' : ⟨ k ⟩ ≤T S ((n -2) +2+ S (n -2))
kle' = ≤T-trans (⟨⟩-monotone-≤ kle) (inl (lemma n))
where lemma : (n : ℕ) → ⟨ n *2 ⟩ == S ((n -2) +2+ S (n -2))
lemma O = idp
lemma (S n') = ap S (ap S (lemma n')
∙ ! (+2+-βr (S n' -2) (S n' -2)))
nlemma₁ : (n : ℕ) → (n -2) +2+ ⟨0⟩ == S (S (n -2))
nlemma₁ n = +2+-comm (n -2) ⟨0⟩
nlemma₂ : (k : ℕ) → (k -2) +2+ ⟨0⟩ == ⟨ k ⟩
nlemma₂ O = idp
nlemma₂ (S k) = ap S (nlemma₂ k)
private
module F = FreudenthalIso
(n -2) k (ℕ-S≠O _) kle' (⊙Susp^ n X)
(transport (λ t → is-connected t (fst (⊙Susp^ n X)))
(nlemma₁ n) (⊙Susp^-conn n cX))
stable : (tk : k ≠ 0) (tsk : S k ≠ 0)
→ π (S k) tsk (⊙Susp^ (S n) X) == π k tk (⊙Susp^ n X)
stable tk tsk =
π (S k) tsk (⊙Susp^ (S n) X)
=⟨ π-inner-iso k tk tsk (⊙Susp^ (S n) X) ⟩
π k tk (⊙Ω (⊙Susp^ (S n) X))
=⟨ ! (π-Trunc-shift-iso k tk (⊙Ω (⊙Susp^ (S n) X))) ⟩
Ω^-Group k tk (⊙Trunc ⟨ k ⟩ (⊙Ω (⊙Susp^ (S n) X))) Trunc-level
=⟨ ! (group-ua F.iso) ⟩
Ω^-Group k tk (⊙Trunc ⟨ k ⟩ (⊙Susp^ n X)) Trunc-level
=⟨ π-Trunc-shift-iso k tk (⊙Susp^ n X) ⟩
π k tk (⊙Susp^ n X) ∎
{- π (S k) (⊙Susp^ (S n) X) == π k (⊙Susp^ n X), where k > 0 -}
module Susp^Stable {i} (X : Ptd i) (cX : is-connected ⟨0⟩ (fst X))
(n : ℕ) (k : ℕ) (tk : k ≠ 0) (tsk : S k ≠ 0) (kle : k ≤ n *2) where
private
lemma : ∀ {i} (C : (n : ℕ) → n ≠ 0 → S n ≠ 0 → Type i)
→ ((n : ℕ) (tsn : S n ≠ 0) (tssn : S (S n) ≠ 0)
→ C (S n) tsn tssn)
→ ((n : ℕ) (tn : n ≠ 0) (tsn : S n ≠ 0)
→ C n tn tsn)
lemma C f O tn _ = ⊥-rec (tn idp)
lemma C f (S n) tsn tssn = f n tsn tssn
abstract
stable : π (S k) tsk (⊙Susp^ (S n) X) == π k tk (⊙Susp^ n X)
stable = lemma
(λ r tr tsr → (r ≤ n *2) →
π (S r) tsr (⊙Susp^ (S n) X) == π r tr (⊙Susp^ n X))
(λ r' tsr' tssr' → λ rle →
Susp^StableSucc.stable X cX n r' rle tsr' tssr')
k tk tsk kle
| {
"alphanum_fraction": 0.4512390088,
"avg_line_length": 33.8108108108,
"ext": "agda",
"hexsha": "8037cba0a161b226e3a77818260f117c71661e76",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "homotopy/IterSuspensionStable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "homotopy/IterSuspensionStable.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "homotopy/IterSuspensionStable.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1170,
"size": 2502
} |
module RecordUpdatePreservesType where
data ⊤ : Set where
tt : ⊤
record R : Set where
field
a : ⊤
record Q : Set where
field
a : ⊤
old : R
old = record { a = tt }
new : Q
new = record old { a = tt }
| {
"alphanum_fraction": 0.5825688073,
"avg_line_length": 11.4736842105,
"ext": "agda",
"hexsha": "d2d400401fc8c6d06d2200746ea950c9e97de50f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/RecordUpdatePreservesType.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/RecordUpdatePreservesType.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/RecordUpdatePreservesType.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 76,
"size": 218
} |
module Dave.Algebra.Naturals.Ordering where
open import Dave.Algebra.Naturals.Definition public
open import Dave.Algebra.Naturals.Addition public
open import Dave.Algebra.Naturals.Multiplication public
-- TO-DO: define relation
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ} → zero ≤ n
s≤s : ∀ {m n : ℕ} → m ≤ n → suc m ≤ suc n
infix 4 _≤_
inv-s≤s : ∀ {m n : ℕ} → suc m ≤ suc n → m ≤ n
inv-s≤s (s≤s m≤n) = m≤n
inv-z≤n : ∀ {m : ℕ} → m ≤ zero → m ≡ zero
inv-z≤n z≤n = refl
-- TO-DO: define relation properties in general
≤-refl : ∀ {n : ℕ} → n ≤ n
≤-refl {zero} = z≤n
≤-refl {suc n} = s≤s ≤-refl
≤-trans : ∀ {m n p : ℕ} → m ≤ n → n ≤ p → m ≤ p
≤-trans z≤n n≤p = z≤n
≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p)
≤-trans´ : ∀ (m n p : ℕ) → m ≤ n → n ≤ p → m ≤ p
≤-trans´ zero n p z≤n n≤p = z≤n
≤-trans´ (suc m) (suc n) (suc p) (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans´ m n p m≤n n≤p)
≤-antisym : ∀ {m n : ℕ} → m ≤ n → n ≤ m → m ≡ n
≤-antisym z≤n z≤n = refl
≤-antisym (s≤s m≤n) (s≤s n≤m) = cong suc (≤-antisym m≤n n≤m)
data Total (m n : ℕ) : Set where
forward : m ≤ n → Total m n
flipped : n ≤ m → Total m n
data Total´ : ℕ → ℕ → Set where
forward´ : ∀ {m n : ℕ} → m ≤ n → Total´ m n
flipped´ : ∀ {m n : ℕ} → n ≤ m → Total´ m n
≤-total : ∀ (m n : ℕ) → Total m n
≤-total zero n = forward z≤n
≤-total (suc m) zero = flipped z≤n
≤-total (suc m) (suc n) with ≤-total m n
... | forward m≤n = forward (s≤s m≤n)
... | flipped n≤m = flipped (s≤s n≤m)
≤-total´ : ∀ (m n : ℕ) → Total m n
≤-total´ zero n = forward z≤n
≤-total´ (suc m) zero = flipped z≤n
≤-total´ (suc m) (suc n) = helper (≤-total´ m n)
where
helper : Total m n → Total (suc m) (suc n)
helper (forward m≤n) = forward (s≤s m≤n)
helper (flipped n≤m) = flipped (s≤s n≤m)
+-monoᵣ-≤ : ∀ (n p q : ℕ) → p ≤ q → n + p ≤ n + q
+-monoᵣ-≤ zero p q p≤q = p≤q
+-monoᵣ-≤ (suc n) p q p≤q = s≤s (+-monoᵣ-≤ n p q p≤q)
+-monoₗ-≤ : ∀ (m n p : ℕ) → m ≤ n → m + p ≤ n + p
+-monoₗ-≤ m n p m≤n rewrite +-comm m p | +-comm n p = +-monoᵣ-≤ p m n m≤n
+-mono-≤ : ∀ (m n p q : ℕ) → m ≤ n → p ≤ q → m + p ≤ n + q
+-mono-≤ m n p q m≤n p≤q = ≤-trans (+-monoₗ-≤ m n p m≤n) (+-monoᵣ-≤ n p q p≤q)
*-monoᵣ-≤ : ∀ (n p q : ℕ) → p ≤ q → n * p ≤ n * q
*-monoᵣ-≤ zero p q p≤q = z≤n
*-monoᵣ-≤ (suc n) p q p≤q = +-mono-≤ (n * p) (n * q) p q (*-monoᵣ-≤ n p q p≤q) p≤q
*-monoₗ-≤ : ∀ (m n p : ℕ) → m ≤ n → m * p ≤ n * p
*-monoₗ-≤ m n p m≤n rewrite ℕ-*-comm m p | ℕ-*-comm n p = *-monoᵣ-≤ p m n m≤n
*-mono-≤ : ∀ (m n p q : ℕ) → m ≤ n → p ≤ q → m * p ≤ n * q
*-mono-≤ m n p q m≤n p≤q = ≤-trans (*-monoₗ-≤ m n p m≤n) (*-monoᵣ-≤ n p q p≤q)
{- Strict inequality -}
infix 4 _<_ _>_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ} → zero < suc n
s<s : ∀ {m n : ℕ} → m < n → suc m < suc n
<-trans : ∀ {m n p : ℕ} → m < n → n < p → m < p
<-trans z<s (s<s n<p) = z<s
<-trans (s<s m<n) (s<s n<p) = s<s (<-trans m<n n<p)
+-monoᵣ-< : ∀ (n p q : ℕ) → p < q → n + p < n + q
+-monoᵣ-< zero p q p<q = p<q
+-monoᵣ-< (suc n) p q p<q = s<s (+-monoᵣ-< n p q p<q)
+-monoₗ-< : ∀ (m n p : ℕ) → m < n → m + p < n + p
+-monoₗ-< m n p m<n rewrite +-comm m p | +-comm n p = +-monoᵣ-< p m n m<n
+-mono-< : ∀ (m n p q : ℕ) → m < n → p < q → m + p < n + q
+-mono-< m n p q m<n p<q = <-trans (+-monoₗ-< m n p m<n) (+-monoᵣ-< n p q p<q)
suc-≤→< : ∀ (m n : ℕ) → suc m ≤ n → m < n
suc-≤→< zero (suc n) leq = z<s
suc-≤→< (suc m) (suc n) (s≤s leq) = s<s (suc-≤→< m n leq)
<→suc-≤ : ∀ (m n : ℕ) → m < n → suc m ≤ n
<→suc-≤ zero (suc n) le = s≤s z≤n
<→suc-≤ (suc m) (suc n) (s<s le) = s≤s (<→suc-≤ m n le)
data _>_ : ℕ → ℕ → Set where
co-m>n : ∀ {m n : ℕ} → n < m → m > n
ℕ-suc-> : ∀ {m n : ℕ} → m > n → suc m > suc n
ℕ-suc-> (co-m>n x) = co-m>n (s<s x)
{- Trichotomy -}
data Trichotomy (m n : ℕ) : Set where
t-m>n : m > n → Trichotomy m n
t-m≡n : m ≡ n → Trichotomy m n
t-m<n : m < n → Trichotomy m n
ℕ-suc-Trichotomy : ∀ {m n : ℕ} → Trichotomy m n → Trichotomy (suc m) (suc n)
ℕ-suc-Trichotomy (t-m>n x) = t-m>n (ℕ-suc-> x)
ℕ-suc-Trichotomy (t-m≡n refl) = t-m≡n refl
ℕ-suc-Trichotomy (t-m<n x) = t-m<n (s<s x)
ℕ-is-Trichotomy : ∀ (m n : ℕ) → Trichotomy m n
ℕ-is-Trichotomy zero zero = t-m≡n refl
ℕ-is-Trichotomy zero (suc n) = t-m<n z<s
ℕ-is-Trichotomy (suc m) zero = t-m>n (co-m>n z<s)
ℕ-is-Trichotomy (suc m) (suc n) = ℕ-suc-Trichotomy (ℕ-is-Trichotomy m n)
| {
"alphanum_fraction": 0.4405010438,
"avg_line_length": 36.5648854962,
"ext": "agda",
"hexsha": "6750d721525820ea475d0fbf88428be7d85d22bb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Algebra/Naturals/Ordering.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Algebra/Naturals/Ordering.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Algebra/Naturals/Ordering.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2334,
"size": 4790
} |
{-# OPTIONS --type-in-type #-}
open import Agda.Primitive using (Setω)
-- No panic should be triggered
data A : Setω where
record B' : Set where
field
theA : A
data B : Set where
b : A → B
data C : Set where
c : Setω → C
data C' : Setω where
c : Setω → C'
record C'' : Setω where
field
theSet : Setω
thefield : theSet
| {
"alphanum_fraction": 0.6057142857,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "317bbc577520ce07cadcc8a87f31f3d3c60bad68",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3697.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3697.agda",
"max_line_length": 39,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3697.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 116,
"size": 350
} |
module Issue160 where
data Bool : Set where
true : Bool
false : Bool
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
inj : ∀ {A} (f : A -> A) {a b : A} →
f a ≡ f b -> a ≡ b
inj f refl = refl
absurd : true ≡ false
absurd = inj (λ _ → true) refl
| {
"alphanum_fraction": 0.5241635688,
"avg_line_length": 15.8235294118,
"ext": "agda",
"hexsha": "1266f37bd941eeab36ad9258c30015c6a73f5f15",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue160.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue160.agda",
"max_line_length": 41,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue160.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 113,
"size": 269
} |
-- Shrunk version of examples/TT.agda
-- Bug introduced by fix of issue 1560
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS --no-termination-check #-}
-- {-# OPTIONS --no-positivity-check #-}
-- {-# OPTIONS -v tc.pos:10 #-}
-- {-# OPTIONS -v tc.polarity:30 #-}
data True : Set where
tt : True
data ⊥ : Set where
infix 3 _/\_
data _/\_ (P Q : Set) : Set where
andI : P -> Q -> P /\ Q
data Nat : Set where
zero : Nat
suc : Nat -> Nat
-- Finite sets ------------------------------------------------------------
data Suc (A : Set) : Set where
fzero' : Suc A
fsuc' : A -> Suc A
mutual
data Fin (n : Nat) : Set where
finI : Fin' n -> Fin n
Fin' : Nat -> Set
Fin' zero = ⊥
Fin' (suc n) = Suc (Fin n)
fsuc : {n : Nat} -> Fin n -> Fin (suc n)
fsuc i = finI (fsuc' i)
module FinEq where
infix 5 _==_
_==_ : {n : Nat} -> Fin n -> Fin n -> Set
_==_ {suc _} (finI fzero' ) (finI fzero' ) = True
_==_ {suc _} (finI (fsuc' i)) (finI (fsuc' j)) = i == j
_==_ _ _ = ⊥
-- Needed
rewriteEq : {n : Nat}(C : Fin n -> Set){i j : Fin n} -> i == j -> C j -> C i
rewriteEq {suc _} C {finI fzero' } {finI fzero' } eq x = x
rewriteEq {suc _} C {finI (fsuc' i)} {finI (fsuc' j)} eq x = rewriteEq (\z -> C (fsuc z)) eq x
rewriteEq {suc _} C {finI (fsuc' _)} {finI fzero' } () _
rewriteEq {suc _} C {finI fzero' } {finI (fsuc' _)} () _
rewriteEq {zero} C {finI ()} {_} _ _
data Expr (n : Nat) : Set where
eVar : Fin n -> Expr n
eApp : Expr n -> Expr n -> Expr n
module ExprEq where
infix 5 _==_
_==_ : {n : Nat} -> Expr n -> Expr n -> Set
eVar i == eVar j = FinEq._==_ i j
eApp e1 e2 == eApp e3 e4 = e1 == e3 /\ e2 == e4
_ == _ = ⊥
rewriteEq : {n : Nat}(C : Expr n -> Set){r s : Expr n} -> r == s -> C s -> C r
rewriteEq C {eVar i } {eVar j } eq x = FinEq.rewriteEq (\z -> C (eVar z)) eq x
rewriteEq C {eApp e1 e2} {eApp e3 e4} (andI eq13 eq24) x =
rewriteEq (\z -> C (eApp z e2)) eq13 (
rewriteEq (\z -> C (eApp e3 z)) eq24 x
)
rewriteEq C {eVar _} {eApp _ _} () _
rewriteEq C {eApp _ _} {eVar _ } () _
-- checking args of rewriteEq
-- args of rewriteEq =
-- [Mixed, Unused, Mixed, Mixed, Unused, StrictPos]
-- Computing polarity of Polarity.ExprEq.rewriteEq
-- Polarity of Polarity.ExprEq.rewriteEq from positivity:
-- [Invariant,Nonvariant,Invariant,Invariant,Nonvariant,Covariant]
-- Refining polarity with type {n : Nat} (C : Expr n → Set)
-- {r s : Expr n} →
-- r == s → C s → C r
-- Polarity of Polarity.ExprEq.rewriteEq: [Invariant,Invariant,Invariant,Invariant,Nonvariant,Covariant]
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Polarity.hs:235
-- -}
-- -}
| {
"alphanum_fraction": 0.5310559006,
"avg_line_length": 29.5714285714,
"ext": "agda",
"hexsha": "9d7c7fbc7bb1e4db59c4c137b2d220a72470e47a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1560a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1560a.agda",
"max_line_length": 104,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1560a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 1040,
"size": 2898
} |
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Emptyrec {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
import Definition.Typed.Weakening as T
open import Definition.Typed.Properties
open import Definition.Typed.RedSteps
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Application
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
import Definition.LogicalRelation.Substitution.Irrelevance as S
open import Definition.LogicalRelation.Substitution.Reflexivity
open import Definition.LogicalRelation.Substitution.Weakening
open import Definition.LogicalRelation.Substitution.Introductions.Empty
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst
open import Tools.Product
open import Tools.Unit
open import Tools.Empty
open import Tools.Nat
import Tools.PropositionalEquality as PE
-- Reducibility of natural recursion under a valid substitution.
EmptyrecTerm : ∀ {F rF lF lEmpty n Γ Δ σ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ])
(⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σn] : Δ ⊩⟨ l ⟩ n ∷ Empty lEmpty ^ [ % , ι lEmpty ] / Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ))))
→ Δ ⊩⟨ l ⟩ Emptyrec lF lEmpty (subst σ F) n
∷ subst σ F ^ [ rF , ι lF ]
/ proj₁ ([F] ⊢Δ [σ])
EmptyrecTerm {F} {rF = !} {lF} {lEmpty} {n} {Γ} {Δ} {σ} {l} [Γ] [F] ⊢Δ [σ]
(Emptyₜ (ne d)) =
let [Empty] = Emptyᵛ {ll = lEmpty} {l = l} [Γ]
[σEmpty] = proj₁ ([Empty] ⊢Δ [σ])
[σF] = proj₁ ([F] ⊢Δ [σ])
⊢F = escape [σF]
⊢F≡F = escapeEq [σF] (reflEq [σF])
in neuTerm [σF] (Emptyrecₙ) (Emptyrecⱼ ⊢F d)
(~-Emptyrec ⊢F≡F d d)
EmptyrecTerm {F} {rF = %} {lF} {lEmpty} {n} {Γ} {Δ} {σ} {l} [Γ] [F] ⊢Δ [σ]
(Emptyₜ (ne d)) =
let [Empty] = Emptyᵛ {ll = lEmpty} {l = l} [Γ]
[σEmpty] = proj₁ ([Empty] ⊢Δ [σ])
[σF] = proj₁ ([F] ⊢Δ [σ])
⊢F = escape [σF]
⊢F≡F = escapeEq [σF] (reflEq [σF])
in logRelIrr [σF] (Emptyrecⱼ ⊢F d)
-- Reducibility of natural recursion congurence under a valid substitution equality.
Emptyrec-congTerm : ∀ {F F′ rF lF lEmpty n m Γ Δ σ σ′ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ])
([F′] : Γ ⊩ᵛ⟨ l ⟩ F′ ^ [ rF , ι lF ] / [Γ])
([F≡F′] : Γ ⊩ᵛ⟨ l ⟩ F ≡ F′ ^ [ rF , ι lF ] / [Γ] / [F])
(⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ)
([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ])
([σn] : Δ ⊩⟨ l ⟩ n ∷ Empty lEmpty ^ [ % , ι lEmpty ] / Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ))))
([σm] : Δ ⊩⟨ l ⟩ m ∷ Empty lEmpty ^ [ % , ι lEmpty ] / Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ))))
→ Δ ⊩⟨ l ⟩ Emptyrec lF lEmpty (subst σ F) n
≡ Emptyrec lF lEmpty (subst σ′ F′) m
∷ subst σ F ^ [ rF , ι lF ]
/ proj₁ ([F] ⊢Δ [σ])
Emptyrec-congTerm {F} {F′} {rF = !} {lF} {lEmpty} {n} {m} {Γ} {Δ} {σ} {σ′} {l}
[Γ] [F] [F′] [F≡F′]
⊢Δ [σ] [σ′] [σ≡σ′]
(Emptyₜ (ne ⊢n′))
(Emptyₜ (ne ⊢m′)) =
let [Empty] = Emptyᵛ {ll = lEmpty} {l = l} [Γ]
[σEmpty] = proj₁ ([Empty] ⊢Δ [σ])
[σ′Empty] = proj₁ ([Empty] ⊢Δ [σ′])
[σF] = proj₁ ([F] ⊢Δ [σ])
[σ′F] = proj₁ ([F] ⊢Δ [σ′])
[σ′F′] = proj₁ ([F′] ⊢Δ [σ′])
⊢F = escape [σF]
⊢F≡F = escapeEq [σF] (reflEq [σF])
⊢F′ = escape [σ′F′]
⊢F′≡F′ = escapeEq [σ′F′] (reflEq [σ′F′])
⊢σF≡σ′F = escapeEq [σF] (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′])
⊢σ′F≡σ′F′ = escapeEq [σ′F] ([F≡F′] ⊢Δ [σ′])
⊢F≡F′ = ≅-trans ⊢σF≡σ′F ⊢σ′F≡σ′F′
[σF≡σ′F] = proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]
[σ′F≡σ′F′] = [F≡F′] ⊢Δ [σ′]
[σF≡σ′F′] = transEq [σF] [σ′F] [σ′F′] [σF≡σ′F] [σ′F≡σ′F′]
EmptyrecN = neuTerm [σF] (Emptyrecₙ) (Emptyrecⱼ ⊢F ⊢n′)
(~-Emptyrec ⊢F≡F ⊢n′ ⊢n′)
EmptyrecM = neuTerm [σ′F′] (Emptyrecₙ) (Emptyrecⱼ ⊢F′ ⊢m′)
(~-Emptyrec ⊢F′≡F′ ⊢m′ ⊢m′)
EmptyrecN≡M =
neuEqTerm [σF] Emptyrecₙ Emptyrecₙ
(Emptyrecⱼ ⊢F ⊢n′)
(conv (Emptyrecⱼ ⊢F′ ⊢m′)
(sym (≅-eq (escapeEq [σF]
(transEq [σF] [σ′F] [σ′F′] [σF≡σ′F] [σ′F≡σ′F′])))))
(~-Emptyrec ⊢F≡F′ ⊢n′ ⊢m′)
in EmptyrecN≡M
Emptyrec-congTerm {F} {F′} {rF = %} {lF} {lEmpty} {n} {m} {Γ} {Δ} {σ} {σ′} {l}
[Γ] [F] [F′] [F≡F′]
⊢Δ [σ] [σ′] [σ≡σ′]
(Emptyₜ (ne ⊢n′))
(Emptyₜ (ne ⊢m′)) =
let [Empty] = Emptyᵛ {ll = lEmpty} {l = l} [Γ]
[σEmpty] = proj₁ ([Empty] ⊢Δ [σ])
[σ′Empty] = proj₁ ([Empty] ⊢Δ [σ′])
[σF] = proj₁ ([F] ⊢Δ [σ])
[σ′F] = proj₁ ([F] ⊢Δ [σ′])
[σ′F′] = proj₁ ([F′] ⊢Δ [σ′])
⊢F = escape [σF]
⊢F≡F = escapeEq [σF] (reflEq [σF])
⊢F′ = escape [σ′F′]
⊢F′≡F′ = escapeEq [σ′F′] (reflEq [σ′F′])
⊢σF≡σ′F = escapeEq [σF] (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′])
⊢σ′F≡σ′F′ = escapeEq [σ′F] ([F≡F′] ⊢Δ [σ′])
⊢F≡F′ = ≅-trans ⊢σF≡σ′F ⊢σ′F≡σ′F′
[σF≡σ′F] = proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]
[σ′F≡σ′F′] = [F≡F′] ⊢Δ [σ′]
[σF≡σ′F′] = transEq [σF] [σ′F] [σ′F′] [σF≡σ′F] [σ′F≡σ′F′]
in logRelIrrEq [σF] (Emptyrecⱼ ⊢F ⊢n′) (conv (Emptyrecⱼ ⊢F′ ⊢m′)
(sym (≅-eq (escapeEq [σF]
(transEq [σF] [σ′F] [σ′F′] [σF≡σ′F] [σ′F≡σ′F′])))))
-- Validity of empty recursion.
Emptyrecᵛ : ∀ {F rF lF lEmpty n Γ l} ([Γ] : ⊩ᵛ Γ)
([Empty] : Γ ⊩ᵛ⟨ l ⟩ Empty lEmpty ^ [ % , ι lEmpty ] / [Γ])
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ])
→ ([n] : Γ ⊩ᵛ⟨ l ⟩ n ∷ Empty lEmpty ^ [ % , ι lEmpty ] / [Γ] / [Empty])
→ Γ ⊩ᵛ⟨ l ⟩ Emptyrec lF lEmpty F n ∷ F ^ [ rF , ι lF ] / [Γ] / [F]
Emptyrecᵛ {F} {rF} {lF} {lEmpty} {n} {l = l} [Γ] [Empty] [F] [n]
{Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [σn] = irrelevanceTerm {l′ = l} (proj₁ ([Empty] ⊢Δ [σ]))
(Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ)))) (proj₁ ([n] ⊢Δ [σ]))
in EmptyrecTerm {F = F} [Γ] [F] ⊢Δ [σ] [σn]
, λ {σ'} [σ′] [σ≡σ′] →
let [σ′n] = irrelevanceTerm {l′ = l} (proj₁ ([Empty] ⊢Δ [σ′]))
(Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ)))) (proj₁ ([n] ⊢Δ [σ′]))
[σn≡σ′n] = irrelevanceEqTerm {l′ = l} (proj₁ ([Empty] ⊢Δ [σ]))
(Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ))))
(proj₂ ([n] ⊢Δ [σ]) [σ′] [σ≡σ′])
congTerm = Emptyrec-congTerm {F = F} {F′ = F} [Γ] [F] [F] (reflᵛ {F} {l = l} [Γ] [F])
⊢Δ [σ] [σ′] [σ≡σ′] [σn] [σ′n]
in congTerm
-- Validity of natural recursion congurence.
Emptyrec-congᵛ : ∀ {F F′ rF lF lEmpty n n′ Γ l} ([Γ] : ⊩ᵛ Γ)
([Empty] : Γ ⊩ᵛ⟨ l ⟩ Empty lEmpty ^ [ % , ι lEmpty ] / [Γ])
([F] : Γ ⊩ᵛ⟨ l ⟩ F ^ [ rF , ι lF ] / [Γ])
([F′] : Γ ⊩ᵛ⟨ l ⟩ F′ ^ [ rF , ι lF ] / [Γ])
([F≡F′] : Γ ⊩ᵛ⟨ l ⟩ F ≡ F′ ^ [ rF , ι lF ] / [Γ] / [F])
([n] : Γ ⊩ᵛ⟨ l ⟩ n ∷ Empty lEmpty ^ [ % , ι lEmpty ] / [Γ] / [Empty])
([n′] : Γ ⊩ᵛ⟨ l ⟩ n′ ∷ Empty lEmpty ^ [ % , ι lEmpty ] / [Γ] / [Empty])
→ Γ ⊩ᵛ⟨ l ⟩ Emptyrec lF lEmpty F n ≡ Emptyrec lF lEmpty F′ n′ ∷ F ^ [ rF , ι lF ] / [Γ] / [F]
Emptyrec-congᵛ {F} {F′} {rF} {lF} {lEmpty} {n} {n′} {l = l}
[Γ] [Empty] [F] [F′] [F≡F′]
[n] [n′] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [σn] = irrelevanceTerm {l′ = l} (proj₁ ([Empty] ⊢Δ [σ]))
(Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ)))) (proj₁ ([n] ⊢Δ [σ]))
[σn′] = irrelevanceTerm {l′ = l} (proj₁ ([Empty] ⊢Δ [σ]))
(Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ)))) (proj₁ ([n′] ⊢Δ [σ]))
congTerm = Emptyrec-congTerm {F} {F′} [Γ] [F] [F′] [F≡F′]
⊢Δ [σ] [σ] (reflSubst [Γ] ⊢Δ [σ]) [σn] [σn′]
in congTerm
| {
"alphanum_fraction": 0.4478200371,
"avg_line_length": 47.6464088398,
"ext": "agda",
"hexsha": "0684d8389484929a7e3124ff6b7bf90e0a799311",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Emptyrec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Emptyrec.agda",
"max_line_length": 115,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Emptyrec.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 3935,
"size": 8624
} |
-- Non-deterministic insert and permutation with choose oracle
-- The module abstracts over the choice structure by importing it.
open import bool
module perm-keep-length
(Choice : Set)
(choose : Choice → 𝔹)
(lchoice : Choice → Choice)
(rchoice : Choice → Choice)
where
open import eq
open import bool-thms
open import nat
open import nat-thms
open import list
----------------------------------------------------------------------
-- Non-deterministic insert:
ndinsert : {a : Set} → Choice → a → 𝕃 a → 𝕃 a
ndinsert _ n [] = n :: []
ndinsert ch n (x :: xs) =
if choose ch then n :: x :: xs
else x :: ndinsert (lchoice ch) n xs
perm : {a : Set} → Choice → 𝕃 a → 𝕃 a
perm _ [] = []
perm ch (x :: xs) = ndinsert (lchoice ch) x (perm (rchoice ch) xs)
----------------------------------------------------------------------
-- Non-deterministic insertion increases the list length by one:
insert-inc-length : ∀ {a : Set} → (ch : Choice) (x : a) (xs : 𝕃 a)
→ length (ndinsert ch x xs) ≡ suc (length xs)
insert-inc-length ch x [] = refl
insert-inc-length ch x (y :: ys) with choose ch
... | tt = refl
... | ff rewrite insert-inc-length (lchoice ch) x ys = refl
-- The length of a permuted list is identical to the length of the list:
perm-length : ∀ {a : Set} → (ch : Choice) (xs : 𝕃 a)
→ length (perm ch xs) =ℕ length xs ≡ tt
perm-length ch [] = refl
perm-length ch (x :: xs)
rewrite insert-inc-length (lchoice ch) x (perm (rchoice ch) xs)
| perm-length (rchoice ch) xs
= refl
----------------------------------------------------------------------
| {
"alphanum_fraction": 0.5388379205,
"avg_line_length": 31.4423076923,
"ext": "agda",
"hexsha": "6945ac43942ce3849b9c5640d4a54234de24acee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "mihanus/curry-agda",
"max_forks_repo_path": "choices/perm-keep-length.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "mihanus/curry-agda",
"max_issues_repo_path": "choices/perm-keep-length.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "mihanus/curry-agda",
"max_stars_repo_path": "choices/perm-keep-length.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 442,
"size": 1635
} |
{-# OPTIONS --rewriting --allow-unsolved-metas #-}
postulate
C : Set
D : Set → Set
d₁ : (A : Set) → D A
d₂ : (A : Set) → (C → D A) → D A
E : (A : Set) → A → A → Set
e₁ : (A : Set) (j₁ j₂ : C → D A) →
((c : C) → E (D A) (j₁ c) (j₂ c)) →
(y : D A) →
E (D A) (d₂ A j₁) y
f : (A B : Set) → D A → D B
f₁ : (A B : Set) → E (D B) (f A B (d₁ A)) (d₁ B)
f₂ : (A B : Set) (j : C → D A) →
E (D B) (f A B (d₂ A j)) (d₂ B (λ c → f A B (j c)))
g : (A : Set) (Q : D A → Set) →
Q (d₁ A) →
((j : C → D A) → ((c : C) → Q (j c)) → Q (d₂ A j)) →
(c : D A) → Q c
{-# BUILTIN REWRITE E #-}
{-# REWRITE f₁ #-}
{-# REWRITE f₂ #-}
h : (A B : Set)
(i : D A → D B) →
E (D B) (d₁ B) (i (d₁ A)) →
(d : D A) → E (D B) (f A B d) (i d)
h A B i e₂ = g
A
(λ (d : D A) → E (D B) {!f A B d!} (i d))
e₂
(λ j q → e₁ B (λ c → f A B (j c)) (λ c → i (j c)) q (i (d₂ A j)))
| {
"alphanum_fraction": 0.3442449842,
"avg_line_length": 24.2820512821,
"ext": "agda",
"hexsha": "eec538e761c2f6f28014dcc3cc364fd393a17bc9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue1931.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue1931.agda",
"max_line_length": 67,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue1931.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 481,
"size": 947
} |
-- Andreas, 2017-11-14, issue #2849, reported by laMudri
-- Internal error, regression introduced by new pattern Internal.AbsurdP
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v tc.with.strip:30 #-}
open import Agda.Builtin.Equality
data ⊥ : Set where
data Bool : Set where
true false : Bool
data P : Bool → Set where
pt : P true
postulate
b : Bool
eq : b ≡ false
works : P b → ⊥
works p with b | eq
works () | .false | refl
test : P b → ⊥
test () rewrite eq
-- WAS (2.5.3): Internal error
-- OK error:
-- Failed to solve the following constraints:
-- Is empty: P b
-- This could also succeed, but somehow the rewrite does not
-- apply to the IsEmpty constraint generated by the absurd pattern.
-- The rewrite should be happening before the absurd pattern split.
| {
"alphanum_fraction": 0.6817610063,
"avg_line_length": 20.3846153846,
"ext": "agda",
"hexsha": "77a3185e6ee75a321913a557164a0f82bc1a2a32",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2849.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2849.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2849.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 223,
"size": 795
} |
module Proj where
open import AlonzoPrelude
showTrue : True -> String
showTrue _ = "tt"
-- data True : Set where
-- tt : True
data T4 : Set where
C : True -> True -> True -> True -> T4
g : True -> True -> True
g x y = tt
f14 : T4 -> True -> True
f14 (C x y z t) = \w -> g x t
mainS : String
mainS = showTrue $ (id ○ f14) (C tt tt tt tt) tt | {
"alphanum_fraction": 0.5873925501,
"avg_line_length": 17.45,
"ext": "agda",
"hexsha": "f698c87fb285672474339b1f36aa69cd28fa5c1b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/Alonzo/Proj.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/Alonzo/Proj.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/Alonzo/Proj.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 127,
"size": 349
} |
-- {-# OPTIONS -v tc.polarity:10 -v tc.pos.args:10 #-}
module UnsolvableLevelConstraintsInDataDef where
open import Common.Equality
data D : Set1 where
abs : ∀ E → D ≡ E → (E → D) → D
| {
"alphanum_fraction": 0.664893617,
"avg_line_length": 23.5,
"ext": "agda",
"hexsha": "71b0f15242a90e931a9db8cc2219824d7eadb3ba",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/UnsolvableLevelConstraintsInDataDef.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/UnsolvableLevelConstraintsInDataDef.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/UnsolvableLevelConstraintsInDataDef.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 62,
"size": 188
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.