Search is not available for this dataset
text
string | meta
dict |
---|---|
-- Andreas, 2018-06-14, issue #2513, surviving shape-irrelevance annotations.
record Foo (A : Set) : Set where
field
@shape-irrelevant foo : A
test : ∀ A → Foo A → A
test A = Foo.foo
| {
"alphanum_fraction": 0.6596858639,
"avg_line_length": 21.2222222222,
"ext": "agda",
"hexsha": "acc61c6f93a941d39cefaae685d6684b30e352f8",
"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/ShapeIrrelevantField.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/ShapeIrrelevantField.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/ShapeIrrelevantField.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": 64,
"size": 191
} |
module context-properties where
open import utility
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.Properties
open import Esterel.Lang.CanFunction
open import Esterel.Lang.CanFunction.Properties
using (canₛ-⊆-FV ; canₛₕ-⊆-FV ; canθₛ-E₁⟦p⟧⊆canθₛ-p ; canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p)
open import Esterel.Environment
open import Esterel.Context
open import Esterel.Context.Properties public -- 'public' for backward compatibility
open import Data.Product
using (Σ ; Σ-syntax ; ∃ ; proj₁ ; proj₂ ; _,_ ; _,′_ ; _×_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Data.Bool
using (Bool ; true ; false ; if_then_else_)
open import Data.List
using (List ; _∷_ ; [] ; _++_ ; map)
open import Data.List.Properties
using (map-id ; map-cong ; map-compose)
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 ; _+_ ; _≟_)
open import Data.Nat.Properties.Simple
using (+-comm)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.Empty
open import sn-calculus
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
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
infix 20 _~_
infix 20 _a~_
data _~_ : EvaluationContext → EvaluationContext → Set where
hole : [] ~ []
parr : ∀{p p' E E'} → E ~ E' → (epar₁ p ∷ E) ~ (epar₁ p' ∷ E')
parl : ∀{p p' E E'} → E ~ E' → (epar₂ p ∷ E) ~ (epar₂ p' ∷ E')
seq : ∀{p p' E E'} → E ~ E' → (eseq p ∷ E) ~ (eseq p' ∷ E')
loopˢ : ∀{p p' E E'} → E ~ E' → (eloopˢ p ∷ E) ~ (eloopˢ p' ∷ E')
susp : ∀{S E E'} → E ~ E' → (esuspend S ∷ E) ~ (esuspend S ∷ E')
trp : ∀{E E'} → E ~ E' → (etrap ∷ E) ~ (etrap ∷ E')
data R : Term → Set where
mit : ∀{S} → R (emit S)
<== : ∀{s e} → R (s ⇐ e)
:== : ∀{x e} → R (x ≔ e)
pres : ∀{S p q} → R (present S ∣⇒ p ∣⇒ q)
iff : ∀{x p q} → R (if x ∣⇒ p ∣⇒ q)
shrd : ∀{s e p} → R (shared s ≔ e in: p)
varr : ∀{x e p} → R (var x ≔ e in: p)
~ref : (E : EvaluationContext) → E ~ E
~ref [] = hole
~ref (epar₁ q ∷ E) = parr (~ref E)
~ref (epar₂ p ∷ E) = parl (~ref E)
~ref (eseq q ∷ E) = seq (~ref E)
~ref (eloopˢ q ∷ E) = loopˢ (~ref E)
~ref (esuspend S ∷ E) = susp (~ref E)
~ref (etrap ∷ E) = trp (~ref E)
~sym : ∀{E1 E2} → E1 ~ E2 → E2 ~ E1
~sym hole = hole
~sym (parr eq) = parr (~sym eq)
~sym (parl eq) = parl (~sym eq)
~sym (seq eq) = seq (~sym eq)
~sym (loopˢ eq) = loopˢ (~sym eq)
~sym (susp eq) = susp (~sym eq)
~sym (trp eq) = trp (~sym eq)
~:: : ∀{E E' Ei} → (Ei ∷ E) ~ (Ei ∷ E') → E ~ E'
~:: (parr ~) = ~
~:: (parl ~) = ~
~:: (seq ~) = ~
~:: (loopˢ ~) = ~
~:: (susp ~) = ~
~:: (trp ~) = ~
CB-rho-rho-imp-dist : ∀{p q θ θ' BV FV A A'} → CorrectBinding ((ρ⟨ θ , A ⟩· p) ∥ (ρ⟨ θ' , A' ⟩· q)) BV FV → distinct (Dom θ) (Dom θ')
CB-rho-rho-imp-dist (CBpar{BVp = BVp}{BVq = BVq} (CBρ cb) (CBρ cb₁) x x₁ x₂ x₃) = dist++b x
ddb-r-rec : ∀{E' q BV FV θ θ' r s A A'} → CorrectBinding ((ρ⟨ θ , A ⟩· r) ∥ q) BV FV → q ≐ E' ⟦ (ρ⟨ θ' , A' ⟩· s) ⟧e → (distinct (Dom θ) (Dom θ'))
ddb-r-rec {[]} {ρ⟨ θ' , A' ⟩· p} (CBpar cb cb₁ x x₁ x₂ x₃) dehole = CB-rho-rho-imp-dist (CBpar cb cb₁ x x₁ x₂ x₃)
ddb-r-rec {.(epar₁ _) ∷ E'} (CBpar cb (CBpar cb₁ cb₂ x x₁ x₂ x₃) x₄ x₅ x₆ x₇) (depar₁ eq2)
= ddb-r-rec {E'} (CBpar cb cb₁ (dist++ˡ x₄) (dist++ˡ x₅) (dist++ˡ x₆) (dist'++ˡ x₇)) eq2
ddb-r-rec {.(epar₂ _) ∷ E'} (CBpar cb (CBpar{BVp = BVp}{FVp = FVp@(S , s , xs)} cb₁ cb₂ x x₁ x₂ x₃) x₄ x₅ x₆ x₇) (depar₂ eq2)
= ddb-r-rec {E'} (CBpar cb cb₂ (dist++ʳ{VL2 = BVp} x₄) (dist++ʳ{VL2 = BVp} x₅) (dist++ʳ{VL2 = FVp} x₆) (dist'++ʳ{V2 = xs} x₇)) eq2
ddb-r-rec {.(esuspend _) ∷ E'}{q = (suspend _ S)} (CBpar cb (CBsusp cb₁ x) x₁ x₂ x₃ x₄) (desuspend eq2)
= ddb-r-rec {E'} (CBpar cb cb₁ x₁ x₂ (dist::{S = S} x₃) x₄) eq2
ddb-r-rec {.etrap ∷ E'} (CBpar cb (CBtrap cb₁) x₁ x₂ x₃ x₄) (detrap eq2)
= ddb-r-rec {E'} (CBpar cb cb₁ x₁ x₂ x₃ x₄) eq2
ddb-r-rec {.(eseq _) ∷ E'} (CBpar cb (CBseq cb₁ cb₂ x) x₁ x₂ x₃ x₄) (deseq eq2)
= ddb-r-rec ((CBpar cb cb₁ (dist++ˡ x₁) (dist++ˡ x₂) (dist++ˡ x₃) (dist'++ˡ x₄))) eq2
ddb-r-rec {.(eloopˢ _) ∷ E'} (CBpar cb (CBloopˢ cb₁ cb₂ x _) x₁ x₂ x₃ x₄) (deloopˢ eq2)
= ddb-r-rec ((CBpar cb cb₁ (dist++ˡ x₁) (dist++ˡ x₂) (dist++ˡ x₃) (dist'++ˡ x₄))) eq2
dist++l2 : ∀{VL1 VL2 VL3} → (distinct (VL2 U̬ VL3) VL1) → (distinct VL2 VL1)
dist++l2 d = (distinct-sym (dist++ˡ (distinct-sym d)))
dist'++l2 : ∀{A VL1 VL2 VL3} → (distinct'{A} (VL2 ++ VL3) VL1) → (distinct' VL2 VL1)
dist'++l2 d = (distinct'-sym (dist'++ˡ (distinct'-sym d)))
dist++r2 : ∀{VL1 VL2 VL3} → (distinct (VL2 U̬ VL3) VL1) → (distinct VL3 VL1)
dist++r2{VL2 = VL2} d = (distinct-sym (dist++ʳ{VL2 = VL2} (distinct-sym d)))
dist'++r2 : ∀{A VL1 VL2 VL3} → (distinct'{A} (VL2 ++ VL3) VL1) → (distinct' VL3 VL1)
dist'++r2{VL2 = VL2} d = (distinct'-sym (dist'++ʳ{V2 = VL2} (distinct'-sym d)))
dist::2 : ∀{VL1 VL2 S} → (distinct (+S S VL1) VL2) → (distinct VL1 VL2)
dist::2{S = S} d = (distinct-sym ( dist::{S = S} (distinct-sym d) ))
decomp-distinct-binding : ∀{E E' p q BV FV θ θ' r s A A'} → CorrectBinding (p ∥ q) BV FV → p ≐ E ⟦ (ρ⟨ θ , A ⟩· r) ⟧e → q ≐ E' ⟦ (ρ⟨ θ' , A' ⟩· s) ⟧e → (distinct (Dom θ) (Dom θ'))
decomp-distinct-binding {[]} {E} (CBpar cb cb₁ x₁ x₂ x₃ x₄) dehole eq2 = ddb-r-rec (CBpar cb cb₁ x₁ x₂ x₃ x₄) eq2
decomp-distinct-binding {x ∷ E} {[]} (CBpar cb cb₁ x₁ x₂ x₃ x₄) eq1 dehole = distinct-sym (ddb-r-rec {x ∷ E} (CBpar cb₁ cb (distinct-sym x₁) (distinct-sym x₃) (distinct-sym x₂) (distinct'-sym x₄)) eq1)
decomp-distinct-binding {.(epar₁ _) ∷ E} {x₁ ∷ E'} (CBpar{BVq = BVq} (CBpar cb cb₁ x x₂ x₃ x₄) cb₂ x₅ x₆ x₇ x₈) (depar₁ eq1) eq2
= decomp-distinct-binding (CBpar cb cb₂ (dist++l2 x₅) (dist++l2 x₆) (dist++l2 x₇) (dist'++l2 x₈)) eq1 eq2
decomp-distinct-binding {.(epar₂ _) ∷ E} {x₁ ∷ E'} (CBpar (CBpar{BVp = BVp}{FVp = FVp@(S , s , xs)}{BVq = BVq} cb cb₁ x x₂ x₃ x₄) cb₂ x₅ x₆ x₇ x₈) (depar₂ eq1) eq2
= decomp-distinct-binding (CBpar cb₁ cb₂ (dist++r2{VL2 = BVp} x₅) (dist++r2{VL2 = FVp} x₆) (dist++r2{VL2 = BVp} x₇) (dist'++r2{VL2 = xs} x₈)) eq1 eq2
decomp-distinct-binding {.(eseq _) ∷ E} {x₁ ∷ E'} (CBpar (CBseq cb cb₁ x) cb₂ x₂ x₃ x₄ x₅) (deseq eq1) eq2
= decomp-distinct-binding {E} ((CBpar cb cb₂ (dist++l2 x₂) (dist++l2 x₃) (dist++l2 x₄) (dist'++l2 x₅))) eq1 eq2
decomp-distinct-binding {.(eloopˢ _) ∷ E} {x₁ ∷ E'} (CBpar (CBloopˢ cb cb₁ x _) cb₂ x₂ x₃ x₄ x₅) (deloopˢ eq1) eq2
= decomp-distinct-binding {E} ((CBpar cb cb₂ (dist++l2 x₂) (dist++l2 x₃) (dist++l2 x₄) (dist'++l2 x₅))) eq1 eq2
decomp-distinct-binding {.(esuspend _) ∷ E} {x₁ ∷ E'} {p = (suspend _ S)} (CBpar (CBsusp cb x) cb₁ x₂ x₃ x₄ x₅) (desuspend eq1) eq2
= decomp-distinct-binding {E} (CBpar cb cb₁ x₂ ( (dist::2{S = S} x₃) ) x₄ x₅) eq1 eq2
decomp-distinct-binding {.etrap ∷ E} {x₁ ∷ E'} (CBpar (CBtrap cb) cb₁ x₂ x₃ x₄ x₅) (detrap eq1) eq2
= decomp-distinct-binding ((CBpar cb cb₁ x₂ x₃ x₄ x₅)) eq1 eq2
data _a~_ : EvaluationContext → EvaluationContext → Set where
parr : ∀{p p' E E'} → E a~ E' → (epar₁ p ∷ E) a~ (epar₁ p' ∷ E')
parl : ∀{p p' E E'} → E a~ E' → (epar₂ p ∷ E) a~ (epar₂ p' ∷ E')
seq : ∀{p p' E E'} → E a~ E' → (eseq p ∷ E) a~ (eseq p' ∷ E')
loopˢ : ∀{p p' E E'} → E a~ E' → (eloopˢ p ∷ E) a~ (eloopˢ p' ∷ E')
susp : ∀{S E E'} → E a~ E' → (esuspend S ∷ E) a~ (esuspend S ∷ E')
trp : ∀{E E'} → E a~ E' → (etrap ∷ E) a~ (etrap ∷ E')
par : ∀{p q E E'} → (epar₂ p ∷ E) a~ (epar₁ q ∷ E')
par2 : ∀{p q E E'} → (epar₁ p ∷ E) a~ (epar₂ q ∷ E')
a~-sym : ∀{E E'} → E a~ E' → E' a~ E
a~-sym (parr ~) = parr (a~-sym ~)
a~-sym (parl ~) = parl (a~-sym ~)
a~-sym (seq ~) = seq (a~-sym ~)
a~-sym (loopˢ ~) = loopˢ (a~-sym ~)
a~-sym (susp ~) = susp (a~-sym ~)
a~-sym (trp ~) = trp (a~-sym ~)
a~-sym par = par2
a~-sym par2 = par
decomp-maint-bind : ∀{E E' p r s θ θ' BV FV A A'} → CorrectBinding p BV FV
→ p ≐ E ⟦ (ρ⟨ θ , A ⟩· r ) ⟧e
→ p ≐ E' ⟦ (ρ⟨ θ' , A' ⟩· s ) ⟧e
→ (E ≡ E' × r ≡ s × θ ≡ θ' × A ≡ A') ⊎ ((distinct (Dom θ) (Dom θ')) × E a~ E')
decomp-maint-bind {[]} {[]} {.(ρ⟨ _ , _ ⟩· _)} bv dehole dehole = inj₁ (refl , refl , refl , refl)
decomp-maint-bind {[]} {x ∷ E'} {.(ρ⟨ _ , _ ⟩· _)} bv dehole ()
decomp-maint-bind {.(epar₁ _) ∷ E} {[]} {.(_ ∥ _)} bv (depar₁ d1) ()
decomp-maint-bind {.(epar₂ _) ∷ E} {[]} {.(_ ∥ _)} bv (depar₂ d1) ()
decomp-maint-bind {.(eseq _) ∷ E} {[]} {.(_ >> _)} bv (deseq d1) ()
decomp-maint-bind {.(eloopˢ _) ∷ E} {[]} {.(loopˢ _ _)} bv (deloopˢ d1) ()
decomp-maint-bind {.(esuspend _) ∷ E} {[]} {.(suspend _ _)} bv (desuspend d1) ()
decomp-maint-bind {.etrap ∷ E} {[]} {.(trap _)} bv (detrap d1) ()
decomp-maint-bind {(epar₁ q) ∷ E} {(epar₂ p) ∷ E'} {.(_ ∥ _)} bv (depar₁ d1) (depar₂ d2) = inj₂ ((decomp-distinct-binding bv d1 d2) , par2 )
decomp-maint-bind {.(epar₂ _) ∷ E} {.(epar₁ _) ∷ E'} {.(_ ∥ _)} bv (depar₂ d1) (depar₁ d2) with (decomp-distinct-binding bv d2 d1)
... | c = inj₂ ((distinct-sym c) , par)
decomp-maint-bind {.(epar₁ _) ∷ E} {.(epar₁ _) ∷ E'} {.(_ ∥ _)} (CBpar bv bv₁ x x₁ x₂ x₃) (depar₁ d1) (depar₁ d2) with decomp-maint-bind bv d1 d2
... | inj₁ (eq1 , eq2 , eq3 , eq4) rewrite eq1 | eq2 | eq3 | eq4 = inj₁ (refl , refl , refl , refl)
... | inj₂ (y , neg) = inj₂ (y , parr neg)
decomp-maint-bind {.(epar₂ _) ∷ E} {.(epar₂ _) ∷ E'} {.(_ ∥ _)} (CBpar bv bv₁ x x₁ x₂ x₃) (depar₂ d1) (depar₂ d2) with decomp-maint-bind bv₁ d1 d2
... | inj₁ (eq1 , eq2 , eq3 , eq4) rewrite eq1 | eq2 | eq3 | eq4 = inj₁ (refl , refl , refl , refl)
... | inj₂ (y , neg) = inj₂ (y , parl neg)
decomp-maint-bind {.(eseq _) ∷ E} {.(eseq _) ∷ E'} {.(_ >> _)} (CBseq bv bv₁ x) (deseq d1) (deseq d2) with decomp-maint-bind bv d1 d2
... | inj₁ (eq1 , eq2 , eq3 , eq4) rewrite eq1 | eq2 | eq3 | eq4 = inj₁ (refl , refl , refl , refl)
... | inj₂ (y , neg) = inj₂ (y , seq neg)
decomp-maint-bind {.(eloopˢ _) ∷ E} {.(eloopˢ _) ∷ E'} {.(loopˢ _ _)} (CBloopˢ bv bv₁ x _) (deloopˢ d1) (deloopˢ d2) with decomp-maint-bind bv d1 d2
... | inj₁ (eq1 , eq2 , eq3 , eq4) rewrite eq1 | eq2 | eq3 | eq4 = inj₁ (refl , refl , refl , refl)
... | inj₂ (y , neg) = inj₂ (y , loopˢ neg)
decomp-maint-bind {.(esuspend _) ∷ E} {.(esuspend _) ∷ E'} {.(suspend _ _)} (CBsusp bv x) (desuspend d1) (desuspend d2) with decomp-maint-bind bv d1 d2
... | inj₁ (eq1 , eq2 , eq3 , eq4) rewrite eq1 | eq2 | eq3 | eq4 = inj₁ (refl , refl , refl , refl)
... | inj₂ (y , neg) = inj₂ (y , susp neg)
decomp-maint-bind {.etrap ∷ E} {.etrap ∷ E'} {.(trap _)} (CBtrap bv) (detrap d1) (detrap d2) with decomp-maint-bind bv d1 d2
... | inj₁ (eq1 , eq2 , eq3 , eq4) rewrite eq1 | eq2 | eq3 | eq4 = inj₁ (refl , refl , refl , refl)
... | inj₂ (y , neg) = inj₂ (y , trp neg)
data ->E-view : ∀{p q pin qin E θ θ' A A'} → (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q) → p ≐ E ⟦ pin ⟧e → q ≐ E ⟦ qin ⟧e → Set where
vmerge : ∀{θ₁ θ₂ r p E A A'' dec} → ∀{dec2 : E ⟦ p ⟧e ≐ E ⟦ p ⟧e} → (->E-view{A = A} (rmerge{θ₁}{θ₂}{r}{p}{E}{A}{A''} dec) dec dec2)
vis-present : ∀{θ S r p q E S∈ ineq dec A} → ∀{dec2 : E ⟦ p ⟧e ≐ E ⟦ p ⟧e} → (->E-view{A = A} (ris-present{θ}{S}{r}{p}{q}{E} S∈ ineq dec) dec dec2)
vis-absent : ∀{θ S r p q E S∈ ineq dec A} → ∀{dec2 : E ⟦ q ⟧e ≐ E ⟦ q ⟧e} → (->E-view{A = A} (ris-absent{θ}{S}{r}{p}{q}{E} S∈ ineq dec) dec dec2)
vemit : ∀{θ r S E S∈ ¬S≡a dec} → ∀{dec2 : E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e} → (->E-view (remit{θ}{r}{S}{E} S∈ ¬S≡a dec) dec dec2)
vraise-shared : ∀{θ r s e p E e' dec A} → ∀{dec2 : E ⟦ (ρ⟨ (Θ SigMap.empty ShrMap.[ s ↦ (SharedVar.old ,′ (δ e'))] VarMap.empty) , WAIT ⟩· p) ⟧e ≐ E ⟦ (ρ⟨ (Θ SigMap.empty ShrMap.[ s ↦ (SharedVar.old ,′ (δ e'))] VarMap.empty) , WAIT ⟩· p) ⟧e}
→ (->E-view{A = A} (rraise-shared{θ}{r}{s}{e}{p}{E} e' dec) dec dec2)
vset-shared-value-old : ∀{θ r s e E e' s∈ ineq dec} → ∀{dec2 : E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e} → (->E-view (rset-shared-value-old{θ}{r}{s}{e}{E} e' s∈ ineq dec) dec dec2)
vset-shared-value-new : ∀{θ r s e E e' s∈ ineq dec} → ∀{dec2 : E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e} → (->E-view (rset-shared-value-new{θ}{r}{s}{e}{E} e' s∈ ineq dec) dec dec2)
vraise-var : ∀{θ r x p e E e' dec A} → ∀{dec2 : E ⟦ (ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p) ⟧e ≐ E ⟦ (ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p) ⟧e}
→ (->E-view{A = A} (rraise-var{θ}{r}{x}{p}{e}{E} e' dec) dec dec2)
vset-var : ∀{θ r x e E x∈ e' dec A} → ∀{dec2 : E ⟦ nothin ⟧e ≐ E ⟦ nothin ⟧e}→ (->E-view{A = A} (rset-var{θ}{r}{x}{e}{E} x∈ e' dec) dec dec2)
vif-false : ∀{θ r p q x E x∈ ineq dec A} → ∀{dec2 : E ⟦ q ⟧e ≐ E ⟦ q ⟧e} → (->E-view{A = A} (rif-false{θ}{r}{p}{q}{x}{E} x∈ ineq dec) dec dec2)
vif-true : ∀{θ r p q x E n x∈ ineq dec A} → ∀{dec2 : E ⟦ p ⟧e ≐ E ⟦ p ⟧e} → (->E-view{A = A} (rif-true{θ}{r}{p}{q}{x}{E}{n} x∈ ineq dec) dec dec2)
data ->pot-view : ∀{p θ q θ' A A'} → (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q) → p ≡ q → A ≡ A' → Set where
vabsence : ∀{θ p A} S S∈ θS≡unknown S∉can-p-θ → (->pot-view{A = A} (rabsence{θ}{p}{S} S∈ θS≡unknown S∉can-p-θ) refl refl)
vreadyness : ∀{θ p A} s s∈ θs≡old⊎θs≡new s∉can-p-θ → (->pot-view{A = A} (rreadyness{θ}{p}{s} s∈ θs≡old⊎θs≡new s∉can-p-θ) refl refl)
data ->θview : ∀{p θ q θ' A A'} → (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q) → Set where
->θE-view : ∀{p q pin qin E θ θ' A A'}
→ ∀{red : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q)}
→ ∀{pin : p ≐ E ⟦ pin ⟧e}
→ ∀{qin : q ≐ E ⟦ qin ⟧e}
→ ->E-view red pin qin
→ ->θview red
->θpot-view : ∀{p θ q θ' A A'}
→ ∀{red : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q)}
→ ∀{eq : p ≡ q}
→ ∀{eq2 : A ≡ A'}
→ ->pot-view red eq eq2
→ ->θview red
-- views for the term inside an ->E-view reduction
data ->E-view-term : Term → Set where
evt-merge : ∀ {θ p A} → ->E-view-term (ρ⟨ θ , A ⟩· p)
evt-present : ∀ {S p q} → ->E-view-term (present S ∣⇒ p ∣⇒ q)
evt-emit : ∀ {S} → ->E-view-term (emit S)
evt-raise-shared : ∀ {s e p} → ->E-view-term (shared s ≔ e in: p)
evt-set-shared : ∀ {s e} → ->E-view-term (s ⇐ e)
evt-raise-var : ∀ {x e p} → ->E-view-term (var x ≔ e in: p)
evt-set-var : ∀ {x e} → ->E-view-term (x ≔ e)
evt-if : ∀ {x p q} → ->E-view-term (if x ∣⇒ p ∣⇒ q)
->E-view-inner-term : ∀ {E pin poin p po θ θo A Ao} →
{ p≐E⟦pin⟧ : p ≐ E ⟦ pin ⟧e } →
{ po≐E⟦poin⟧ : po ≐ E ⟦ poin ⟧e } →
{ ρθ·psn⟶₁ρθo·po : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θo , Ao ⟩· po } →
->E-view ρθ·psn⟶₁ρθo·po p≐E⟦pin⟧ po≐E⟦poin⟧ →
->E-view-term pin
->E-view-inner-term vmerge = evt-merge
->E-view-inner-term vis-present = evt-present
->E-view-inner-term vis-absent = evt-present
->E-view-inner-term vemit = evt-emit
->E-view-inner-term vraise-shared = evt-raise-shared
->E-view-inner-term vset-shared-value-old = evt-set-shared
->E-view-inner-term vset-shared-value-new = evt-set-shared
->E-view-inner-term vraise-var = evt-raise-var
->E-view-inner-term vset-var = evt-set-var
->E-view-inner-term vif-false = evt-if
->E-view-inner-term vif-true = evt-if
-- terms inside the hole of an ->E-view cannot be done
done-E-view-term-disjoint : ∀ {p} → done p → ->E-view-term p → ⊥
done-E-view-term-disjoint (dhalted hnothin) ()
done-E-view-term-disjoint (dhalted (hexit n)) ()
done-E-view-term-disjoint (dpaused ppause) ()
done-E-view-term-disjoint (dpaused (pseq p/paused)) ()
done-E-view-term-disjoint (dpaused (ploopˢ p/paused)) ()
done-E-view-term-disjoint (dpaused (ppar p/paused q/paused)) ()
done-E-view-term-disjoint (dpaused (psuspend p/paused)) ()
done-E-view-term-disjoint (dpaused (ptrap p/paused)) ()
unwrap-rho : ∀{E₁ E p θ θ' pin q qin po qo A A'}
→ (red : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q))
→ (peq : p ≐ (E₁ ∷ E) ⟦ pin ⟧e)
→ (qeq : q ≐ (E₁ ∷ E) ⟦ qin ⟧e)
→ (poeq : po ≐ E ⟦ pin ⟧e)
→ (qoeq : qo ≐ E ⟦ qin ⟧e)
→ (->E-view red peq qeq)
→ Σ[ redo ∈ (ρ⟨ θ , A ⟩· po) sn⟶₁ (ρ⟨ θ' , A' ⟩· qo) ] (->E-view redo poeq qoeq)
unwrap-rho{E = E}{θ = θ}{θ' = θ'}{qin = qin}{po = po} red@(rmerge{θ₁}{θ₂} .peq) peq qeq poeq qoeq (vmerge) with sym (unplug qoeq)
... | refl = rmerge poeq , vmerge{θ}{_}{po}{qin}{E}{_}{_}{poeq}
unwrap-rho (ris-present S∈ ineq .peq) peq qeq poeq qoeq vis-present with sym (unplug qoeq)
... | refl = (ris-present S∈ ineq poeq) , vis-present
unwrap-rho (ris-absent S∈ ineq .peq) peq qeq poeq qoeq vis-absent with sym (unplug qoeq)
... | refl = (ris-absent S∈ ineq poeq) , vis-absent
unwrap-rho (remit x eq .peq) peq qeq poeq qoeq vemit with sym (unplug qoeq)
... | refl = (remit x eq poeq) , vemit
unwrap-rho (rraise-shared x .peq) peq qeq poeq qoeq vraise-shared with sym (unplug qoeq)
... | refl = rraise-shared x poeq , vraise-shared
unwrap-rho (rset-shared-value-old a b c .peq) peq qeq poeq qoeq vset-shared-value-old with sym (unplug qoeq)
... | refl = (rset-shared-value-old a b c poeq) , vset-shared-value-old
unwrap-rho (rset-shared-value-new a b c .peq) peq qeq poeq qoeq vset-shared-value-new with sym (unplug qoeq)
... | refl = (rset-shared-value-new a b c poeq) , vset-shared-value-new
unwrap-rho (rraise-var a .peq) peq qeq poeq qoeq vraise-var with sym (unplug qoeq)
... | refl = (rraise-var a poeq) , vraise-var
unwrap-rho (rset-var a b .peq) peq qeq poeq qoeq vset-var with sym (unplug qoeq)
... | refl = (rset-var a b poeq) , vset-var
unwrap-rho (rif-false a b .peq) peq qeq poeq qoeq vif-false with sym (unplug qoeq)
... | refl = rif-false a b poeq , vif-false
unwrap-rho (rif-true a b .peq) peq qeq poeq qoeq vif-true with sym (unplug qoeq)
... | refl = rif-true a b poeq , vif-true
wrap-rho : ∀{θ θ' pout qout pin qin E po qo A A'}
→ (red : (ρ⟨ θ , A ⟩· pout) sn⟶₁ (ρ⟨ θ' , A' ⟩· qout))
→ (peq : pout ≐ E ⟦ pin ⟧e)
→ (qeq : qout ≐ E ⟦ qin ⟧e)
→ ->E-view red peq qeq
→ (E₁ : EvaluationContext1)
→ (poeq : po ≐ (E₁ ∷ E) ⟦ pin ⟧e)
→ (qoeq : qo ≐ (E₁ ∷ E) ⟦ qin ⟧e)
→ Σ[ redo ∈ (ρ⟨ θ , A ⟩· po) sn⟶₁ (ρ⟨ θ' , A' ⟩· qo) ] ->E-view redo poeq qoeq
wrap-rho .(rmerge peq) peq qeq vmerge Eo poeq qoeq with sym (unplug qoeq)
... | refl = rmerge poeq , vmerge
wrap-rho (ris-present S∈ ineq .peq) peq qeq vis-present Eo poeq qoeq with sym (unplug qoeq)
... | refl = ris-present S∈ ineq poeq , vis-present
wrap-rho (ris-absent S∈ ineq .peq) peq qeq vis-absent Eo poeq qoeq with sym (unplug qoeq)
... | refl = ris-absent S∈ ineq poeq , vis-absent
wrap-rho (remit S∈ eq .peq) peq qeq vemit Eo poeq qoeq with sym (unplug qoeq)
... | refl = remit S∈ eq poeq , vemit
wrap-rho (rraise-shared a .peq) peq qeq vraise-shared Eo poeq qoeq with sym (unplug qoeq)
... | refl = rraise-shared a poeq , vraise-shared
wrap-rho (rset-shared-value-old a b c .peq) peq qeq vset-shared-value-old Eo poeq qoeq with sym (unplug qoeq)
... | refl = rset-shared-value-old a b c poeq , vset-shared-value-old
wrap-rho (rset-shared-value-new a b c .peq) peq qeq vset-shared-value-new Eo poeq qoeq with sym (unplug qoeq)
... | refl = rset-shared-value-new a b c poeq , vset-shared-value-new
wrap-rho (rraise-var a .peq) peq qeq vraise-var Eo poeq qoeq with sym (unplug qoeq)
... | refl = rraise-var a poeq , vraise-var
wrap-rho (rset-var a b .peq) peq qeq vset-var Eo poeq qoeq with sym (unplug qoeq)
... | refl = rset-var a b poeq , vset-var
wrap-rho (rif-false a b .peq) peq qeq vif-false Eo poeq qoeq with sym (unplug qoeq)
... | refl = rif-false a b poeq , vif-false
wrap-rho (rif-true a b .peq) peq qeq vif-true Eo poeq qoeq with sym (unplug qoeq)
... | refl = rif-true a b poeq , vif-true
wrap-rho-pot : ∀ {E₁ pin θ θ' pin≡pin E₁⟦nothin⟧ BV FV A A≡A} →
-- distinct (Dom θ) (FV (E₁ ⟦ nothin ⟧))
E₁⟦nothin⟧ ≐ (E₁ ∷ []) ⟦ nothin ⟧e →
CorrectBinding E₁⟦nothin⟧ BV FV →
distinct (Dom θ) FV →
(ρθpinsn⟶₁ρθ'qin : ρ⟨ θ , A ⟩· pin sn⟶₁ ρ⟨ θ' , A ⟩· pin) →
->pot-view ρθpinsn⟶₁ρθ'qin pin≡pin A≡A →
∃ λ po →
Σ[ po≐E₁⟦pin⟧ ∈ po ≐ (E₁ ∷ []) ⟦ pin ⟧e ]
Σ[ ρθE₁⟦pin⟧sn⟶₁ρθ'E₁⟦pin⟧ ∈ ρ⟨ θ , A ⟩· po sn⟶₁ ρ⟨ θ' , A ⟩· po ]
->pot-view ρθE₁⟦pin⟧sn⟶₁ρθ'E₁⟦pin⟧ refl refl
wrap-rho-pot {epar₁ q} {pin} {θ} {FV = FV} (depar₁ dehole) cb Domθ≠FV
.(rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-p)
(vabsence S S∈ θS≡unknown S∉canθ-θ-p)
= _ , depar₁ dehole ,
rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env ,
vabsence S S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env
where
S∉canθ-θ-E₁⟦p⟧-[]env =
S∉canθ-θ-p ∘
canθₛ-E₁⟦p⟧⊆canθₛ-p (sig θ) 0 []env (depar₁ dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
S (proj₁ Domθ≠FV (Signal.unwrap S) S∈)
wrap-rho-pot {epar₂ p} {pin} {θ} {FV = FV} (depar₂ dehole) cb Domθ≠FV
.(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
= _ , depar₂ dehole ,
rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env ,
vabsence S S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env
where
S∉canθ-θ-E₁⟦p⟧-[]env =
S∉can-p-θ ∘
canθₛ-E₁⟦p⟧⊆canθₛ-p (sig θ) 0 []env (depar₂ dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
S (proj₁ Domθ≠FV (Signal.unwrap S) S∈)
wrap-rho-pot {eseq q} {pin} {θ} {FV = FV} (deseq dehole) cb Domθ≠FV
.(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
= _ , deseq dehole ,
rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env ,
vabsence S S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env
where
S∉canθ-θ-E₁⟦p⟧-[]env =
S∉can-p-θ ∘
canθₛ-E₁⟦p⟧⊆canθₛ-p (sig θ) 0 []env (deseq dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
S (proj₁ Domθ≠FV (Signal.unwrap S) S∈)
wrap-rho-pot {eloopˢ q} {pin} {θ} {FV = FV} (deloopˢ dehole) cb Domθ≠FV
.(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
= _ , deloopˢ dehole ,
rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env ,
vabsence S S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env
where
S∉canθ-θ-E₁⟦p⟧-[]env =
S∉can-p-θ ∘
canθₛ-E₁⟦p⟧⊆canθₛ-p (sig θ) 0 []env (deloopˢ dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
S (proj₁ Domθ≠FV (Signal.unwrap S) S∈)
wrap-rho-pot {esuspend S'} {pin} {θ} {FV = FV} (desuspend dehole) cb Domθ≠FV
.(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
= _ , desuspend dehole ,
rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env ,
vabsence S S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env
where
S∉canθ-θ-E₁⟦p⟧-[]env =
S∉can-p-θ ∘
canθₛ-E₁⟦p⟧⊆canθₛ-p (sig θ) 0 []env (desuspend dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
S (proj₁ Domθ≠FV (Signal.unwrap S) S∈)
wrap-rho-pot {etrap} {pin} {θ} {FV = FV} (detrap dehole) cb Domθ≠FV
.(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)
(vabsence S S∈ θS≡unknown S∉can-p-θ)
= _ , detrap dehole ,
rabsence {S = S} S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env ,
vabsence S S∈ θS≡unknown S∉canθ-θ-E₁⟦p⟧-[]env
where
S∉canθ-θ-E₁⟦p⟧-[]env =
S∉can-p-θ ∘
canθₛ-E₁⟦p⟧⊆canθₛ-p (sig θ) 0 []env (detrap dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
S (proj₁ Domθ≠FV (Signal.unwrap S) S∈)
wrap-rho-pot {epar₁ q} {pin} {θ} {FV = FV} (depar₁ dehole) cb Domθ≠FV
.(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
= _ , depar₁ dehole ,
rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env ,
vreadyness s s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env
where
s∉canθ-θ-E₁⟦p⟧-[]env =
s∉can-p-θ ∘
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (sig θ) 0 []env (depar₁ dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
s (proj₁ (proj₂ Domθ≠FV) (SharedVar.unwrap s) s∈)
wrap-rho-pot {epar₂ p} {pin} {θ} {FV = FV} (depar₂ dehole) cb Domθ≠FV
.(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
= _ , depar₂ dehole ,
rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env ,
vreadyness s s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env
where
s∉canθ-θ-E₁⟦p⟧-[]env =
s∉can-p-θ ∘
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (sig θ) 0 []env (depar₂ dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
s (proj₁ (proj₂ Domθ≠FV) (SharedVar.unwrap s) s∈)
wrap-rho-pot {eseq q} {pin} {θ} {FV = FV} (deseq dehole) cb Domθ≠FV
.(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
= _ , deseq dehole ,
rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env ,
vreadyness s s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env
where
s∉canθ-θ-E₁⟦p⟧-[]env =
s∉can-p-θ ∘
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (sig θ) 0 []env (deseq dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
s (proj₁ (proj₂ Domθ≠FV) (SharedVar.unwrap s) s∈)
wrap-rho-pot {eloopˢ q} {pin} {θ} {FV = FV} (deloopˢ dehole) cb Domθ≠FV
.(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
= _ , deloopˢ dehole ,
rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env ,
vreadyness s s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env
where
s∉canθ-θ-E₁⟦p⟧-[]env =
s∉can-p-θ ∘
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (sig θ) 0 []env (deloopˢ dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
s (proj₁ (proj₂ Domθ≠FV) (SharedVar.unwrap s) s∈)
wrap-rho-pot {esuspend S} {pin} {θ} {FV = FV} (desuspend dehole) cb Domθ≠FV
.(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
= _ , desuspend dehole ,
rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env ,
vreadyness s s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env
where
s∉canθ-θ-E₁⟦p⟧-[]env =
s∉can-p-θ ∘
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (sig θ) 0 []env (desuspend dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
s (proj₁ (proj₂ Domθ≠FV) (SharedVar.unwrap s) s∈)
wrap-rho-pot {etrap} {pin} {θ} {FV = FV} (detrap dehole) cb Domθ≠FV
.(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)
(vreadyness s s∈ θs≡old⊎θs≡new s∉can-p-θ)
= _ , detrap dehole ,
rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env ,
vreadyness s s∈ θs≡old⊎θs≡new s∉canθ-θ-E₁⟦p⟧-[]env
where
s∉canθ-θ-E₁⟦p⟧-[]env =
s∉can-p-θ ∘
canθₛₕ-E₁⟦p⟧⊆canθₛₕ-p (sig θ) 0 []env (detrap dehole) cb
(subst (λ dom → distinct' dom (proj₁ FV))
(sym (map-id (proj₁ (Dom θ))))
(proj₁ Domθ≠FV))
s (proj₁ (proj₂ Domθ≠FV) (SharedVar.unwrap s) s∈)
-- p and p' are not important at all; we use them to extract the
-- distinctness condition of FV E₁ and Dom θ
wrap-rho-pot' : ∀ {θ θ' E₁ E pin p p' BV FV A} →
p ≐ (E₁ ∷ E) ⟦ ρ⟨ θ , A ⟩· p' ⟧e →
CorrectBinding p BV FV →
(ρθpinsn⟶₁ρθ'pin : ρ⟨ θ , A ⟩· pin sn⟶₁ ρ⟨ θ' , A ⟩· pin) →
->pot-view ρθpinsn⟶₁ρθ'pin refl refl →
∃ λ po →
Σ[ po≐E₁⟦pin⟧ ∈ po ≐ (E₁ ∷ []) ⟦ pin ⟧e ]
Σ[ ρθE₁⟦pin⟧sn⟶₁ρθ'E₁⟦pin⟧ ∈ ρ⟨ θ , A ⟩· po sn⟶₁ ρ⟨ θ' , A ⟩· po ]
->pot-view ρθE₁⟦pin⟧sn⟶₁ρθ'E₁⟦pin⟧ refl refl
wrap-rho-pot' {θ} (depar₁ p≐E⟦ρθp'⟧) (CBpar cbp cbq _ _ BVp≠FVq _) ρθpinsn⟶₁ρθ'pin pot
with binding-extract cbp p≐E⟦ρθp'⟧
... | (BVρθ , _) , (BVρθ⊆BVp , _) , CBρ _ =
wrap-rho-pot (depar₁ dehole) cb' (⊆-respect-distinct-left (∪-unjoin-⊆ˡ {xs³ = Dom θ} BVρθ⊆BVp) BVp≠FVq) ρθpinsn⟶₁ρθ'pin pot
where cb' = CBpar CBnothing cbq distinct-empty-left distinct-empty-left distinct-empty-left (λ _ ())
wrap-rho-pot' {θ} (depar₂ q≐E⟦ρθp'⟧) (CBpar cbp cbq _ FVp≠BVq _ _) ρθpinsn⟶₁ρθ'pin pot
with binding-extract cbq q≐E⟦ρθp'⟧
... | (BVρθ , _) , (BVρθ⊆BVq , _) , CBρ _ = -- Test your eyesight : 1) ⊃ 2) ∪ 3) ⊂ 4) ∩
wrap-rho-pot (depar₂ dehole) cb' -- hack to delete (_∪ base) in (distinct (FVq ∪ base))
(⊆-respect-distinct-right (∪-join-⊆ ⊆-refl ⊆-empty-left) -- using (FVq ∪ base) ⊆ FVq here
(⊆-respect-distinct-left (∪-unjoin-⊆ˡ {xs³ = Dom θ} BVρθ⊆BVq) (distinct-sym FVp≠BVq)))
ρθpinsn⟶₁ρθ'pin pot
where cb' = CBpar cbp CBnothing distinct-empty-right distinct-empty-right distinct-empty-right (λ _ _ ())
wrap-rho-pot' {θ} (deseq p≐E⟦ρθp'⟧) (CBseq cbp cbq BVp≠FVq) ρθpinsn⟶₁ρθ'pin pot
with binding-extract cbp p≐E⟦ρθp'⟧
... | (BVρθ , _) , (BVρθ⊆BVp , _) , CBρ _ =
wrap-rho-pot (deseq dehole) cb' (⊆-respect-distinct-left (∪-unjoin-⊆ˡ {xs³ = Dom θ} BVρθ⊆BVp) BVp≠FVq) ρθpinsn⟶₁ρθ'pin pot
where cb' = CBseq CBnothing cbq distinct-empty-left
wrap-rho-pot' {θ} (deloopˢ p≐E⟦ρθp'⟧) (CBloopˢ cbp cbq BVp≠FVq BVq≠FVq) ρθpinsn⟶₁ρθ'pin pot
with binding-extract cbp p≐E⟦ρθp'⟧
... | (BVρθ , _) , (BVρθ⊆BVp , _) , CBρ _ =
wrap-rho-pot (deloopˢ dehole) cb' (⊆-respect-distinct-left (∪-unjoin-⊆ˡ {xs³ = Dom θ} BVρθ⊆BVp) BVp≠FVq) ρθpinsn⟶₁ρθ'pin pot
where cb' = CBloopˢ CBnothing cbq distinct-empty-left BVq≠FVq
wrap-rho-pot' {θ} (desuspend p≐E⟦ρθp'⟧) (CBsusp cb [S]≠BVp) ρθpinsn⟶₁ρθ'pin pot
with binding-extract cb p≐E⟦ρθp'⟧
... | (BVρθ , _) , (BVρθ⊆BVp , _) , CBρ _ =
wrap-rho-pot (desuspend dehole) cb'
((distinct'-sym (⊆¹-respect-distinct'-right
(proj₁ (∪¹-unjoin-⊆¹ (proj₁ (Dom θ)) (proj₁ BVρθ⊆BVp))) [S]≠BVp)) ,′
(λ _ _ ()) ,′ (λ _ _ ()))
ρθpinsn⟶₁ρθ'pin pot
where cb' = CBsusp CBnothing (λ _ _ ())
wrap-rho-pot' {θ} (detrap p≐E⟦ρθp'⟧) cb@(CBtrap cb') ρθpinsn⟶₁ρθ'pin pot =
wrap-rho-pot (detrap dehole) (CBtrap CBnothing) distinct-empty-right ρθpinsn⟶₁ρθ'pin pot
E-view-main-bind : ∀{El Er p il ir iol ior ql qr θ θl θr A Al Ar}
→ ∀{redl : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θl , Al ⟩· ql) }
→ ∀{redr : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θr , Ar ⟩· qr) }
→ ∀{dec1l : p ≐ El ⟦ il ⟧e}
→ ∀{dec2l : ql ≐ El ⟦ iol ⟧e}
→ ∀{dec1r : p ≐ Er ⟦ ir ⟧e}
→ ∀{dec2r : qr ≐ Er ⟦ ior ⟧e}
→ ->E-view redl dec1l dec2l
→ ->E-view redr dec1r dec2r
→ (El ≡ Er × ql ≡ qr × θl ≡ θr × Al ≡ Ar) ⊎ (El a~ Er)
E-view-main-bind {epar₁ q ∷ El} {epar₂ p ∷ Er} v1 v2 = inj₂ par2
E-view-main-bind {epar₂ p ∷ El} {epar₁ q ∷ Er} v1 v2 = inj₂ par
E-view-main-bind {[]} {[]} {(present S ∣⇒ _ ∣⇒ _)}{θ = θ} {redl = (ris-present ∈1 eq1 dehole)} {(ris-absent ∈2 eq2 dehole)} {dehole} {dehole} {dehole} {dehole} vis-present vis-absent with sig-stats-∈-irr{S}{θ} ∈1 ∈2
... | k with trans (sym (trans k eq2)) eq1
... | ()
E-view-main-bind {[]} {[]} {(present S ∣⇒ _ ∣⇒ _)}{θ = θ} {redl = (ris-absent ∈1 eq1 dehole)} {(ris-present ∈2 eq2 dehole)} {dehole} {dehole} {dehole} {dehole} vis-absent vis-present with sig-stats-∈-irr{S}{θ} ∈1 ∈2
... | k with trans (sym (trans k eq2)) eq1
... | ()
E-view-main-bind {[]} {[]} {(if x ∣⇒ _ ∣⇒ _)}{θ = θ} {redl = (rif-false ∈1 eq1 dehole)} {(rif-true ∈2 eq2 dehole)} {dehole} {dehole} {dehole} {dehole} vif-false vif-true with var-vals-∈-irr{x}{θ} ∈1 ∈2
... | k with trans (sym (trans k eq2)) eq1
... | ()
E-view-main-bind {[]} {[]} {(if x ∣⇒ _ ∣⇒ _)}{θ = θ} {redl = (rif-true ∈1 eq1 dehole)} {(rif-false ∈2 eq2 dehole)} {dehole} {dehole} {dehole} {dehole} vif-true vif-false with var-vals-∈-irr{x}{θ} ∈1 ∈2
... | k with trans (sym (trans k eq2)) eq1
... | ()
E-view-main-bind {[]} {[]} {(s ⇐ _)}{θ = θ} {redl = (rset-shared-value-new _ ∈1 eq1 dehole)} {(rset-shared-value-old _ ∈2 eq2 dehole)} {dehole} {dehole} {dehole} {dehole} vset-shared-value-new vset-shared-value-old
with shr-stats-∈-irr{s}{θ} ∈1 ∈2
... | k with trans (sym (trans k eq2)) eq1
... | ()
E-view-main-bind {[]} {[]} {(s ⇐ _)}{θ = θ} {redl = (rset-shared-value-old _ ∈1 eq1 dehole)} {(rset-shared-value-new _ ∈2 eq2 dehole)} {dehole} {dehole} {dehole} {dehole} vset-shared-value-old vset-shared-value-new with shr-stats-∈-irr{s}{θ} ∈1 ∈2
... | k with trans (sym (trans k eq2)) eq1
... | ()
E-view-main-bind {[]} {[]} {.(ρ⟨ _ , _ ⟩· _)} {redl = .(rmerge dehole)} {.(rmerge dehole)} {dehole} {dehole} {dehole} {dehole} vmerge vmerge = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(present _ ∣⇒ _ ∣⇒ _)} {redl = .(ris-present _ _ dehole)} {.(ris-present _ _ dehole)} {dehole} {dehole} {dehole} {dehole} vis-present vis-present = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(present _ ∣⇒ _ ∣⇒ _)} {redl = .(ris-absent _ _ dehole)} {.(ris-absent _ _ dehole)} {dehole} {dehole} {dehole} {dehole} vis-absent vis-absent = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(emit _)} {redl = .(remit _ _ dehole)} {.(remit _ _ dehole)} {dehole} {dehole} {dehole} {dehole} vemit vemit = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(shared _ ≔ _ in: _)} {redl = (rraise-shared e' dehole)} {(rraise-shared e'' dehole)} {dehole} {dehole} {dehole} {dehole} vraise-shared vraise-shared
rewrite δ-e-irr e' e'' = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(_ ⇐ _)} {redl = (rset-shared-value-old e' _ _ dehole)} {(rset-shared-value-old e'' _ _ dehole)} {dehole} {dehole} {dehole} {dehole} vset-shared-value-old vset-shared-value-old
rewrite δ-e-irr e' e'' = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {(s ⇐ _)}{θ = θ} {redl = (rset-shared-value-new e' s∈' _ dehole)} {(rset-shared-value-new e'' s∈'' _ dehole)} {dehole} {dehole} {dehole} {dehole} vset-shared-value-new vset-shared-value-new
rewrite δ-e-irr e' e'' | (shr-vals-∈-irr{s}{θ} s∈' s∈'') = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(var _ ≔ _ in: _)} {redl = (rraise-var e' dehole)} {(rraise-var e'' dehole)} {dehole} {dehole} {dehole} {dehole} vraise-var vraise-var
rewrite δ-e-irr e' e'' = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {(x ≔ e)} {redl = (rset-var{e = .e} _ e' dehole)} {(rset-var{e = .e} _ e'' dehole)} {dehole} {dehole} {dehole} {dehole} vset-var vset-var
rewrite δ-e-irr e' e'' = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(if _ ∣⇒ _ ∣⇒ _)} {redl = .(rif-false _ _ dehole)} {.(rif-false _ _ dehole)} {dehole} {dehole} {dehole} {dehole} vif-false vif-false = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {[]} {.(if _ ∣⇒ _ ∣⇒ _)} {redl = .(rif-true _ _ dehole)} {.(rif-true _ _ dehole)} {dehole} {dehole} {dehole} {dehole} vif-true vif-true = inj₁ (refl , refl , refl , refl)
E-view-main-bind {[]} {.(epar₁ _) ∷ Er} {.(_ ∥ _)} {redl = redl} {redr} {dehole} {dec2l} {depar₁ dec1r} {dec2r} () v2
E-view-main-bind {[]} {.(epar₂ _) ∷ Er} {.(_ ∥ _)} {redl = redl} {redr} {dehole} {dec2l} {depar₂ dec1r} {dec2r} () v2
E-view-main-bind {[]} {.(eseq _) ∷ Er} {.(_ >> _)} {redl = redl} {redr} {dehole} {dec2l} {deseq dec1r} {dec2r} () v2
E-view-main-bind {[]} {.(eloopˢ _) ∷ Er} {.(loopˢ _ _)} {redl = redl} {redr} {dehole} {dec2l} {deloopˢ dec1r} {dec2r} () v2
E-view-main-bind {[]} {.(esuspend _) ∷ Er} {.(suspend _ _)} {redl = redl} {redr} {dehole} {dec2l} {desuspend dec1r} {dec2r} () v2
E-view-main-bind {[]} {.etrap ∷ Er} {.(trap _)} {redl = redl} {redr} {dehole} {dec2l} {detrap dec1r} {dec2r} () v2
E-view-main-bind {.(epar₁ _) ∷ El} {[]} {.(_ ∥ _)} {redl = redl} {redr} {depar₁ dec1l} {dec2l} {dehole} {dec2r} v1 ()
E-view-main-bind {.(epar₂ _) ∷ El} {[]} {.(_ ∥ _)} {redl = redl} {redr} {depar₂ dec1l} {dec2l} {dehole} {dec2r} v1 ()
E-view-main-bind {.(eseq _) ∷ El} {[]} {.(_ >> _)} {redl = redl} {redr} {deseq dec1l} {dec2l} {dehole} {dec2r} v1 ()
E-view-main-bind {.(eloopˢ _) ∷ El} {[]} {.(loopˢ _ _)} {redl = redl} {redr} {deloopˢ dec1l} {dec2l} {dehole} {dec2r} v1 ()
E-view-main-bind {.(esuspend _) ∷ El} {[]} {.(suspend _ _)} {redl = redl} {redr} {desuspend dec1l} {dec2l} {dehole} {dec2r} v1 ()
E-view-main-bind {.etrap ∷ El} {[]} {.(trap _)} {redl = redl} {redr} {detrap dec1l} {dec2l} {dehole} {dec2r} v1 ()
E-view-main-bind {epar₁ q ∷ El} {epar₁ .q ∷ Er} {dec1l = depar₁ dec1l} {depar₁ dec2l} {depar₁ dec1r} {depar₁ dec2r} v1 v2 with unwrap-rho _ _ _ dec1l dec2l v1 | unwrap-rho _ _ _ dec1r dec2r v2
... | (redil , viewil) | (redir , viewir) with E-view-main-bind viewil viewir
... | (inj₁ (refl , refl , refl , refl)) = inj₁ (refl , refl , refl , refl)
... | (inj₂ y) = inj₂ (parr y)
E-view-main-bind {.(epar₂ _) ∷ El} {.(epar₂ _) ∷ Er} {.(_ ∥ _)} {dec1l = depar₂ dec1l} {depar₂ dec2l} {depar₂ dec1r} {depar₂ dec2r} v1 v2 with unwrap-rho _ _ _ dec1l dec2l v1 | unwrap-rho _ _ _ dec1r dec2r v2
... | (redil , viewil) | (redir , viewir) with E-view-main-bind viewil viewir
... | (inj₁ (refl , refl , refl , refl)) = inj₁ (refl , refl , refl , refl)
... | (inj₂ y) = inj₂ (parl y)
E-view-main-bind {.(eseq _) ∷ El} {.(eseq _) ∷ Er} {.(_ >> _)} {dec1l = deseq dec1l} {deseq dec2l} {deseq dec1r} {deseq dec2r} v1 v2 with unwrap-rho _ _ _ dec1l dec2l v1 | unwrap-rho _ _ _ dec1r dec2r v2
... | (redil , viewil) | (redir , viewir) with E-view-main-bind viewil viewir
... | (inj₁ (refl , refl , refl , refl)) = inj₁ (refl , refl , refl , refl)
... | (inj₂ y) = inj₂ (seq y)
E-view-main-bind {.(eloopˢ _) ∷ El} {.(eloopˢ _) ∷ Er} {.(loopˢ _ _)} {dec1l = deloopˢ dec1l} {deloopˢ dec2l} {deloopˢ dec1r} {deloopˢ dec2r} v1 v2 with unwrap-rho _ _ _ dec1l dec2l v1 | unwrap-rho _ _ _ dec1r dec2r v2
... | (redil , viewil) | (redir , viewir) with E-view-main-bind viewil viewir
... | (inj₁ (refl , refl , refl , refl)) = inj₁ (refl , refl , refl , refl)
... | (inj₂ y) = inj₂ (loopˢ y)
E-view-main-bind {.(esuspend _) ∷ El} {.(esuspend _) ∷ Er} {.(suspend _ _)} {dec1l = desuspend dec1l} {desuspend dec2l} {desuspend dec1r} {desuspend dec2r} v1 v2 with unwrap-rho _ _ _ dec1l dec2l v1 | unwrap-rho _ _ _ dec1r dec2r v2
... | (redil , viewil) | (redir , viewir) with E-view-main-bind viewil viewir
... | (inj₁ (refl , refl , refl , refl)) = inj₁ (refl , refl , refl , refl)
... | (inj₂ y) = inj₂ (susp y)
E-view-main-bind {.etrap ∷ El} {.etrap ∷ Er} {.(trap _)} {dec1l = detrap dec1l} {detrap dec2l} {detrap dec1r} {detrap dec2r} v1 v2 with unwrap-rho _ _ _ dec1l dec2l v1 | unwrap-rho _ _ _ dec1r dec2r v2
... | (redil , viewil) | (redir , viewir) with E-view-main-bind viewil viewir
... | (inj₁ (refl , refl , refl , refl)) = inj₁ (refl , refl , refl , refl)
... | (inj₂ y) = inj₂ (trp y)
get-view : ∀{θ θ' p q A A'}
→ (red : (ρ⟨ θ , A ⟩· p) sn⟶₁ (ρ⟨ θ' , A' ⟩· q))
→ (Σ[ E ∈ EvaluationContext ]
Σ[ pin ∈ Term ]
Σ[ qin ∈ Term ]
Σ[ peq ∈ (p ≐ E ⟦ pin ⟧e) ]
Σ[ qeq ∈ (q ≐ E ⟦ qin ⟧e) ]
(->E-view{p}{q}{pin}{qin}{E}{θ}{θ'}{A}{A'} red peq qeq ))
⊎ Σ[ eq ∈ (p ≡ q) ] Σ[ eq2 ∈ (A ≡ A') ] (->pot-view red eq eq2)
get-view (ris-present S∈ x x₁) = inj₁ (_ , _ , _ , x₁ , Erefl , vis-present)
get-view (ris-absent S∈ x x₁) = inj₁ (_ , _ , _ , x₁ , Erefl , vis-absent)
get-view (remit S∈ _ x) = inj₁ (_ , _ , _ , x , Erefl , vemit)
get-view (rraise-shared e' x) = inj₁ (_ , _ , _ , x , Erefl , vraise-shared)
get-view (rset-shared-value-old e' s∈ x x₁) = inj₁ (_ , _ , _ , x₁ , Erefl , vset-shared-value-old)
get-view (rset-shared-value-new e' s∈ x x₁) = inj₁ (_ , _ , _ , x₁ , Erefl , vset-shared-value-new)
get-view (rraise-var e' x₁) = inj₁ (_ , _ , _ , x₁ , Erefl , vraise-var)
get-view (rset-var x∈ e' x₁) = inj₁ (_ , _ , _ , x₁ , Erefl , vset-var)
get-view (rif-false x∈ x₁ x₂) = inj₁ (_ , _ , _ , x₂ , Erefl , vif-false)
get-view (rif-true x∈ x₁ x₂) = inj₁ (_ , _ , _ , x₂ , Erefl , vif-true)
get-view (rmerge x) = inj₁ (_ , _ , _ , x , Erefl , vmerge)
get-view (rabsence {S = S} S∈ x x₁) = inj₂ (refl , refl , vabsence S S∈ x x₁)
get-view (rreadyness {s = s} s∈ x x₁) = inj₂ (refl , refl , vreadyness s s∈ x x₁)
| {
"alphanum_fraction": 0.5636815064,
"avg_line_length": 58.8697539797,
"ext": "agda",
"hexsha": "d5c9e9a28824a2d09389df13481927b0ae30dd50",
"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/context-properties.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/context-properties.agda",
"max_line_length": 249,
"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/context-properties.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": 19152,
"size": 40679
} |
{-# OPTIONS --subtyping #-}
open import Agda.Builtin.Equality
postulate
A : Set
mutual
I : (A -> A) → .A → A
I f = _
testQ : {f : .A -> A} → I f ≡ f
testQ = refl
| {
"alphanum_fraction": 0.5227272727,
"avg_line_length": 12.5714285714,
"ext": "agda",
"hexsha": "7dee20fb230570a8b42c8f593dea5f38319c87d2",
"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": "test/Fail/Issue4390irrelevance-subtyping.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2015-09-15T15:49:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-09-15T15:49:15.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4390irrelevance-subtyping.agda",
"max_line_length": 33,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4390irrelevance-subtyping.agda",
"max_stars_repo_stars_event_max_datetime": "2016-05-20T13:58:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-05-20T13:58:52.000Z",
"num_tokens": 70,
"size": 176
} |
module stateDependentIO where
open import Level using (_⊔_ ) renaming (suc to lsuc; zero to lzero)
open import Size renaming (Size to AgdaSize)
open import NativeIO
open import Function
module _ {γ ρ μ} where
record IOInterfaceˢ : Set (lsuc (γ ⊔ ρ ⊔ μ )) where
field
StateIOˢ : Set γ
Commandˢ : StateIOˢ → Set ρ
Responseˢ : (s : StateIOˢ) → Commandˢ s → Set μ
nextIOˢ : (s : StateIOˢ) → (c : Commandˢ s) → Responseˢ s c
→ StateIOˢ
open IOInterfaceˢ public
module _ {α γ ρ μ}(i : IOInterfaceˢ {γ} {ρ} {μ} )
(let S = StateIOˢ i) (let C = Commandˢ i)
(let R = Responseˢ i) (let next = nextIOˢ i)
where
mutual
record IOˢ (i : AgdaSize) (A : S → Set α) (s : S)
: Set (lsuc (α ⊔ γ ⊔ ρ ⊔ μ )) where
coinductive
constructor delay
field forceˢ : {j : Size< i} → IOˢ' j A s
data IOˢ' (i : AgdaSize) (A : S → Set α) : S
→ Set (lsuc (α ⊔ γ ⊔ ρ ⊔ μ )) where
doˢ' : {s : S} → (c : C s) → (f : (r : R s c)
→ IOˢ i A (next s c r) )
→ IOˢ' i A s
returnˢ' : {s : S} → (a : A s) → IOˢ' i A s
open IOˢ public
module _ {α γ ρ μ}{I : IOInterfaceˢ {γ} {ρ} {μ}}
(let S = StateIOˢ I) (let C = Commandˢ I)
(let R = Responseˢ I) (let next = nextIOˢ I) where
returnIOˢ : ∀{i}{A : S → Set α} {s : S} (a : A s) → IOˢ I i A s
forceˢ (returnIOˢ a) = returnˢ' a
doˢ : ∀{i}{A : S → Set α} {s : S}
(c : C s) (f : (r : R s c) → IOˢ I i A (next s c r)) → IOˢ I i A s
forceˢ (doˢ c f) = doˢ' c f
module _ {γ ρ}{I : IOInterfaceˢ {γ} {ρ} {lzero}}
(let S = StateIOˢ I) (let C = Commandˢ I)
(let R = Responseˢ I) (let next = nextIOˢ I) where
{-# NON_TERMINATING #-}
translateIOˢ : ∀{A : Set }{s : S}
→ (translateLocal : (s : S) → (c : C s) → NativeIO (R s c))
→ IOˢ I ∞ (λ s → A) s
→ NativeIO A
translateIOˢ {A} {s} translateLocal p = case (forceˢ p {_}) of
λ{ (doˢ' {.s} c f) → (translateLocal s c) native>>= λ r →
translateIOˢ translateLocal (f r)
; (returnˢ' a) → nativeReturn a
}
| {
"alphanum_fraction": 0.4779411765,
"avg_line_length": 33.5072463768,
"ext": "agda",
"hexsha": "491304ca79325dc2be013c5c3f79d6621b6e87e5",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/stateDependentIO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"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": "agda/ooAgda",
"max_issues_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/stateDependentIO.agda",
"max_line_length": 76,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "presentationsAndExampleCode/agdaImplementorsMeetingGlasgow22April2016AntonSetzer/stateDependentIO.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 912,
"size": 2312
} |
module New.FunctionLemmas where
open import New.Changes
module BinaryValid
{A : Set} {{CA : ChAlg A}}
{B : Set} {{CB : ChAlg B}}
{C : Set} {{CC : ChAlg C}}
(f : A → B → C) (df : A → Ch A → B → Ch B → Ch C)
where
binary-valid-preserve-hp =
∀ a da (ada : valid a da)
b db (bdb : valid b db)
→ valid (f a b) (df a da b db)
binary-valid-eq-hp =
∀ a da (ada : valid a da)
b db (bdb : valid b db)
→ (f ⊕ df) (a ⊕ da) (b ⊕ db) ≡ f a b ⊕ df a da b db
binary-valid :
binary-valid-preserve-hp →
binary-valid-eq-hp →
valid f df
binary-valid ext-valid proof a da ada =
(λ b db bdb → ext-valid a da ada b db bdb , lem2 b db bdb)
, ext lem1
where
lem1 : ∀ b → f (a ⊕ da) b ⊕ df (a ⊕ da) (nil (a ⊕ da)) b (nil b) ≡
f a b ⊕ df a da b (nil b)
lem1 b
rewrite sym (update-nil b)
| proof a da ada b (nil b) (nil-valid b)
| update-nil b = refl
lem2 : ∀ b (db : Ch B) (bdb : valid b db) →
f a (b ⊕ db) ⊕ df a da (b ⊕ db) (nil (b ⊕ db)) ≡
f a b ⊕ df a da b db
lem2 b db bdb
rewrite sym (proof a da ada (b ⊕ db) (nil (b ⊕ db)) (nil-valid (b ⊕ db)))
| update-nil (b ⊕ db) = proof a da ada b db bdb
module TernaryValid
{A : Set} {{CA : ChAlg A}}
{B : Set} {{CB : ChAlg B}}
{C : Set} {{CC : ChAlg C}}
{D : Set} {{CD : ChAlg D}}
(f : A → B → C → D) (df : A → Ch A → B → Ch B → C → Ch C → Ch D)
where
ternary-valid-preserve-hp =
∀ a da (ada : valid a da)
b db (bdb : valid b db)
c dc (cdc : valid c dc)
→ valid (f a b c) (df a da b db c dc)
-- These are explicit definitions only to speed up typechecking.
CA→B→C→D : ChAlg (A → B → C → D)
CA→B→C→D = funCA
f⊕df = (_⊕_ {{CA→B→C→D}} f df)
-- Already this definition takes a while to typecheck.
ternary-valid-eq-hp =
∀ a (da : Ch A {{CA}}) (ada : valid {{CA}} a da)
b (db : Ch B {{CB}}) (bdb : valid {{CB}} b db)
c (dc : Ch C {{CC}}) (cdc : valid {{CC}} c dc)
→ f⊕df (a ⊕ da) (b ⊕ db) (c ⊕ dc) ≡ f a b c ⊕ df a da b db c dc
ternary-valid :
ternary-valid-preserve-hp →
ternary-valid-eq-hp →
valid f df
ternary-valid ext-valid proof a da ada =
binary-valid
(λ b db bdb c dc cdc → ext-valid a da ada b db bdb c dc cdc)
lem2
, ext (λ b → ext (lem1 b))
where
open BinaryValid (f a) (df a da)
lem1 : ∀ b c → f⊕df (a ⊕ da) b c ≡ (f a ⊕ df a da) b c
lem1 b c
rewrite sym (update-nil b)
| sym (update-nil c)
|
proof
a da ada
b (nil b) (nil-valid b)
c (nil c) (nil-valid c)
| update-nil b
| update-nil c = refl
-- rewrite
-- sym
-- (proof
-- (a ⊕ da) (nil (a ⊕ da)) (nil-valid (a ⊕ da))
-- b (nil b) (nil-valid b)
-- c (nil c) (nil-valid c))
-- | update-nil (a ⊕ da)
-- | update-nil b
-- | update-nil c = {! !}
lem2 : ∀ b db (bdb : valid b db)
c dc (cdc : valid c dc) →
(f a ⊕ df a da) (b ⊕ db) (c ⊕ dc)
≡ f a b c ⊕ df a da b db c dc
lem2 b db bdb c dc cdc
rewrite sym
(proof
a da ada
(b ⊕ db) (nil (b ⊕ db)) (nil-valid (b ⊕ db))
(c ⊕ dc) (nil (c ⊕ dc)) (nil-valid (c ⊕ dc))
)
| update-nil (b ⊕ db)
| update-nil (c ⊕ dc) = proof a da ada b db bdb c dc cdc
| {
"alphanum_fraction": 0.4668778802,
"avg_line_length": 30.4561403509,
"ext": "agda",
"hexsha": "e40aa41a1e6c00f5b90ded5eb113d673eb86fbfc",
"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": "New/FunctionLemmas.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": "New/FunctionLemmas.agda",
"max_line_length": 81,
"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": "New/FunctionLemmas.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": 1300,
"size": 3472
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Relation.Nullary.Omniscience where
open import Prelude
open import Relation.Nullary.Decidable
open import Relation.Nullary.Decidable.Properties
open import Relation.Nullary.Decidable.Logic
open import Relation.Nullary
open import Data.Bool using (bool)
private
variable
p : Level
P : A → Type p
Omniscient Exhaustible Prop-Omniscient : ∀ p {a} → Type a → Type _
Omniscient p A = ∀ {P : A → Type p} → (∀ x → Dec (P x)) → Dec (∃ x × P x)
Exhaustible p A = ∀ {P : A → Type p} → (∀ x → Dec (P x)) → Dec (∀ x → P x)
Omniscient→Exhaustible : Omniscient p A → Exhaustible p A
Omniscient→Exhaustible omn P? =
map-dec
(λ ¬∃P x → Dec→Stable _ (P? x) (¬∃P ∘ (x ,_)))
(λ ¬∃P ∀P → ¬∃P λ p → p .snd (∀P (p .fst)))
(! (omn (! ∘ P?)))
Prop-Omniscient p A = ∀ {P : A → Type p} → (∀ x → Dec (P x)) → Dec ∥ ∃ x × P x ∥
| {
"alphanum_fraction": 0.610738255,
"avg_line_length": 28.8387096774,
"ext": "agda",
"hexsha": "4751454493ad47710c645c50f4990e0afd58582a",
"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/Nullary/Omniscience.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/Nullary/Omniscience.agda",
"max_line_length": 80,
"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/Nullary/Omniscience.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": 325,
"size": 894
} |
-- Andreas, 2017-06-20, issue #2613, reported by Jonathan Prieto.
-- Regression introduced by fix of #2458 (which is obsolete since #2403)
module _ where
open import Agda.Builtin.Nat
module Prop' (n : Nat) where
data Prop' : Set where
_∧_ _∨_ : Prop' → Prop' → Prop'
open Prop' zero
data DView : Prop' → Set where
case₁ : (a b c : Prop') → DView ((a ∨ b) ∧ c)
case₂ : (a : Prop') → DView a
dView : (p : Prop') → DView p
dView ((a ∨ b) ∧ c) = case₁ _ _ _
dView a = case₂ _
dist-∧ : Prop' → Prop'
dist-∧ p with dView p
dist-∧ .((a ∨ b) ∧ c) | case₁ a b c = dist-∧ (a ∧ c)
dist-∧ a | case₂ .a = a
-- WAS:
-- Termination checking failed for the following functions:
-- dist-∧
-- Problematic calls:
-- dist-∧ (a ∧ c)
-- Should succeed.
| {
"alphanum_fraction": 0.578343949,
"avg_line_length": 22.4285714286,
"ext": "agda",
"hexsha": "815190f05ed7a2830bf1ee9d9a8711d43cf35215",
"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/Issue2613.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/Issue2613.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/Issue2613.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": 285,
"size": 785
} |
module #11 where
{-
Show that for any type A, we have ¬¬¬A → ¬A.
-}
open import Data.Empty
open import Relation.Nullary
tripleNeg : ∀{x}{A : Set x} → ¬ (¬ (¬ A)) → ¬ A
tripleNeg = λ z z₁ → z (λ z₂ → z₂ z₁)
| {
"alphanum_fraction": 0.5754716981,
"avg_line_length": 17.6666666667,
"ext": "agda",
"hexsha": "f1f544455857b0489fcedf647eab13f12bfb705b",
"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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter1/#11.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"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": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter1/#11.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter1/#11.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 83,
"size": 212
} |
{-# OPTIONS --safe #-}
module Cubical.Data.Vec where
open import Cubical.Data.Vec.Base public
open import Cubical.Data.Vec.Properties public
open import Cubical.Data.Vec.NAry public
open import Cubical.Data.Vec.OperationsNat public
| {
"alphanum_fraction": 0.8025751073,
"avg_line_length": 29.125,
"ext": "agda",
"hexsha": "b20c81ffc2c3b46e6baa6e44307b64ea3af9157f",
"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": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Data/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"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": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Data/Vec.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Data/Vec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 57,
"size": 233
} |
------------------------------------------------------------------------------
-- Properties related with lists of natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.List.PropertiesI where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.List
open import FOTC.Data.List
------------------------------------------------------------------------------
-- See the ATP version.
postulate ++-ListN : ∀ {ms ns} → ListN ms → ListN ns → ListN (ms ++ ns)
map-ListN : ∀ f {ns} → (∀ {n} → N n → N (f · n)) → ListN ns → ListN (map f ns)
map-ListN f h lnnil = subst ListN (sym (map-[] f)) lnnil
map-ListN f h (lncons {n} {ns} Nn Lns) =
subst ListN (sym (map-∷ f n ns)) (lncons (h Nn) (map-ListN f h Lns))
| {
"alphanum_fraction": 0.4494382022,
"avg_line_length": 39.16,
"ext": "agda",
"hexsha": "6b9da4e1680cb4861bb3e85bbb45abc1a1ca896f",
"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/FOTC/Data/Nat/List/PropertiesI.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/FOTC/Data/Nat/List/PropertiesI.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/FOTC/Data/Nat/List/PropertiesI.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": 245,
"size": 979
} |
-- a hodge-podge of tests
module Test where
import Test.Class
import Test.EquivalenceExtensionṖroperty
import Test.EquivalenceṖroperty
import Test.EquivalentCandidates
import Test.EquivalentCandidates-2
import Test.Factsurj3
import Test.Functor -- FIXME doesn't work with open import Everything
import Test.ProblemWithDerivation
import Test.ProblemWithDerivation-2
import Test.ProblemWithDerivation-3
import Test.ProblemWithDerivation-4
import Test.ProblemWithDerivation-5
import Test.ProblemWithLevelZero
import Test.ProblemWithSym
import Test.ṖropertyFacts -- FIXME doesn't work with open import Everything
import Test.ṖropertyFactsSubstitunction
import Test.SubstitunctionPropId
import Test.Surjcollation -- FIXME remove commented import block?
import Test.Surjidentity
import Test.SurjidentityI
import Test.SurjidentityP
import Test.Symmetrical
import Test.SymmetricalSubstitunction
import Test.Test0
import Test.Test1
import Test.Test2
import Test.Test3
import Test.Test4
import Test.Test5
import Test.Test6
import Test.Test7
import Test.Thickandthin
import Test.Transassociativity
import Test.UnifiesSubstitunction
import Test.𝓢urjectivityWithOverlapping𝓢urjection
| {
"alphanum_fraction": 0.8657604078,
"avg_line_length": 29.425,
"ext": "agda",
"hexsha": "898dd38655e5164deed65da1e72a45b9983769e5",
"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": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Test.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Test.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 309,
"size": 1177
} |
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path using (_≡_)
open import Agda.Builtin.Sigma using (Σ; fst; _,_)
postulate
Is-proposition : Set → Set
subst : ∀ {A : Set} (P : A → Set) {x y} → x ≡ y → P x → P y
Proposition : Set₁
Proposition = Σ _ Is-proposition
data _/_ (A : Set) (R : A → A → Proposition) : Set where
[_] : A → A / R
resp : ∀ {x y} → fst (R x y) → [ x ] ≡ [ y ]
variable
A : Set
R : A → A → Proposition
postulate
F : (P : A / R → Set)
(p-[] : ∀ x → P [ x ]) →
(∀ {x y} (r : fst (R x y)) → subst P (resp r) (p-[] x) ≡ p-[] y) →
Set
F' : (A : Set)
(R : A → A → Proposition)
(P : A / R → Set)
(p-[] : ∀ x → P [ x ]) →
(∀ {x y} (r : fst (R x y)) → subst P (resp r) (p-[] x) ≡ p-[] y) →
Set
F' A R = F {A = A} {R = R}
| {
"alphanum_fraction": 0.4487804878,
"avg_line_length": 23.4285714286,
"ext": "agda",
"hexsha": "34735d17c6db3427e1dc7f3160a25a003c2edf19",
"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/Issue3695.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/Issue3695.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/Issue3695.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": 345,
"size": 820
} |
module _ where
module A where
infix 0 c
syntax c x = + x
data D₁ : Set where
b : D₁
c : D₁ → D₁
module B where
infix 1 c
syntax c x = + x
data D₂ : Set where
c : A.D₁ → D₂
open A
open B
test₁ : D₂
test₁ = + + + b
test₂ : D₂ → D₁
test₂ (+ + x) = x
test₂ (+ b) = + + + b
| {
"alphanum_fraction": 0.5098039216,
"avg_line_length": 9.8709677419,
"ext": "agda",
"hexsha": "e99f36eafb2b3c7f8717873d837d47d009c8c3ec",
"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/Issue1194i.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/Issue1194i.agda",
"max_line_length": 23,
"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/Issue1194i.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": 131,
"size": 306
} |
{-# OPTIONS --prop --rewriting #-}
module Examples.TreeSum where
open import Calf.CostMonoid
open import Calf.CostMonoids using (ℕ²-ParCostMonoid)
parCostMonoid = ℕ²-ParCostMonoid
open ParCostMonoid parCostMonoid
open import Calf costMonoid
open import Calf.ParMetalanguage parCostMonoid
open import Calf.Types.Nat
open import Calf.Types.Bounded costMonoid
open import Relation.Binary.PropositionalEquality as Eq using (_≡_; refl; _≢_; module ≡-Reasoning)
open import Data.Nat as Nat using (_+_; _⊔_)
open import Data.Nat.Properties as N using ()
open import Data.Product
add : cmp (Π nat λ _ → Π nat λ _ → F nat)
add m n = step (F nat) (1 , 1) (ret (m + n))
add/cost : cmp (Π nat λ _ → Π nat λ _ → cost)
add/cost m n = (1 , 1) ⊕ 𝟘
add/cost/closed : cmp (Π nat λ _ → Π nat λ _ → cost)
add/cost/closed m n = (1 , 1)
add/cost≤add/cost/closed : ∀ m n → ◯ (add/cost m n ≤ add/cost/closed m n)
add/cost≤add/cost/closed m n u = ≤-reflexive (⊕-identityʳ (1 , 1))
add≤add/cost : ∀ m n → IsBounded nat (add m n) (add/cost m n)
add≤add/cost m n = bound/step (1 , 1) _ bound/ret
add≤add/cost/closed : ∀ m n → IsBounded nat (add m n) (add/cost/closed m n)
add≤add/cost/closed m n = bound/relax (add/cost≤add/cost/closed m n) (add≤add/cost m n)
data Tree : Set where
leaf : val nat → Tree
node : Tree → Tree → Tree
tree : tp pos
tree = U (meta Tree)
sum : cmp (Π tree λ _ → F nat)
sum (leaf x) = ret x
sum (node t₁ t₂) =
bind (F nat) (sum t₁ & sum t₂) λ (n₁ , n₂) →
add n₁ n₂
sum/total : ∀ t → ◯ (∃ λ n → sum t ≡ ret n)
sum/total (leaf x) u = x , refl
sum/total (node t₁ t₂) u =
let (n₁ , ≡₁) = sum/total t₁ u
(n₂ , ≡₂) = sum/total t₂ u
in
n₁ + n₂ , (
let open ≡-Reasoning in
begin
(bind (F nat) (sum t₁ & sum t₂) λ (n₁ , n₂) →
add n₁ n₂)
≡⟨ Eq.cong₂ (λ e₁ e₂ → bind (F nat) (e₁ & e₂) _) ≡₁ ≡₂ ⟩
add n₁ n₂
≡⟨⟩
step (F nat) (1 , 1) (ret (n₁ + n₂))
≡⟨ step/ext (F nat) _ (1 , 1) u ⟩
ret (n₁ + n₂)
∎
)
sum/cost : cmp (Π tree λ _ → cost)
sum/cost (leaf x) = 𝟘
sum/cost (node t₁ t₂) =
bind cost (sum t₁ & sum t₂) λ (n₁ , n₂) → (sum/cost t₁ ⊗ sum/cost t₂) ⊕
add/cost/closed n₁ n₂
size : val tree → val nat
size (leaf x) = 0
size (node t₁ t₂) = suc (size t₁ + size t₂)
depth : val tree → val nat
depth (leaf x) = 0
depth (node t₁ t₂) = suc (depth t₁ ⊔ depth t₂)
sum/cost/closed : cmp (Π tree λ _ → cost)
sum/cost/closed t = size t , depth t
sum/cost≤sum/cost/closed : ∀ t → ◯ (sum/cost t ≤ sum/cost/closed t)
sum/cost≤sum/cost/closed (leaf x) u = ≤-refl
sum/cost≤sum/cost/closed (node t₁ t₂) u =
let (_ , ≡₁) = sum/total t₁ u
(_ , ≡₂) = sum/total t₂ u
in
begin
sum/cost (node t₁ t₂)
≡⟨⟩
(bind cost (sum t₁ & sum t₂) λ (n₁ , n₂) → (sum/cost t₁ ⊗ sum/cost t₂) ⊕
add/cost/closed n₁ n₂)
≡⟨ Eq.cong₂ (λ e₁ e₂ → bind cost (e₁ & e₂) λ (n₁ , n₂) → (sum/cost t₁ ⊗ sum/cost t₂) ⊕ _) ≡₁ ≡₂ ⟩
sum/cost t₁ ⊗ sum/cost t₂ ⊕ (1 , 1)
≤⟨ ⊕-monoˡ-≤ (1 , 1) (⊗-mono-≤ (sum/cost≤sum/cost/closed t₁ u) (sum/cost≤sum/cost/closed t₂ u)) ⟩
sum/cost/closed t₁ ⊗ sum/cost/closed t₂ ⊕ (1 , 1)
≡⟨⟩
(size t₁ , depth t₁) ⊗ (size t₂ , depth t₂) ⊕ (1 , 1)
≡⟨⟩
size t₁ + size t₂ + 1 , depth t₁ ⊔ depth t₂ + 1
≡⟨ Eq.cong₂ _,_ (N.+-comm _ 1) (N.+-comm _ 1) ⟩
suc (size t₁ + size t₂) , suc (depth t₁ ⊔ depth t₂)
≡⟨⟩
sum/cost/closed (node t₁ t₂)
∎
where open ≤-Reasoning
sum≤sum/cost : ∀ t → IsBounded nat (sum t) (sum/cost t)
sum≤sum/cost (leaf x) = bound/ret
sum≤sum/cost (node t₁ t₂) =
bound/bind (sum/cost t₁ ⊗ sum/cost t₂) _ (bound/par (sum≤sum/cost t₁) (sum≤sum/cost t₂)) λ (n₁ , n₂) →
add≤add/cost/closed n₁ n₂
sum≤sum/cost/closed : ∀ t → IsBounded nat (sum t) (sum/cost/closed t)
sum≤sum/cost/closed t = bound/relax (sum/cost≤sum/cost/closed t) (sum≤sum/cost t)
| {
"alphanum_fraction": 0.5950326797,
"avg_line_length": 30.8467741935,
"ext": "agda",
"hexsha": "1e927dca48e9ea6b6b2d06784b58bdb668cc1033",
"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/Examples/TreeSum.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/Examples/TreeSum.agda",
"max_line_length": 104,
"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/Examples/TreeSum.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": 1684,
"size": 3825
} |
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.Core where
open import Level
open import Categories.Category
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Properties
import Categories.Morphism as Morphism
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e o′ ℓ′ e′ : Level
C D E : Category o ℓ e
record NaturalTransformation {C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
(F G : Functor C D) : Set (o ⊔ ℓ ⊔ ℓ′ ⊔ e′) where
eta-equality
private
module F = Functor F
module G = Functor G
open F using (F₀; F₁)
open Category D hiding (op)
field
η : ∀ X → D [ F₀ X , G.F₀ X ]
commute : ∀ {X Y} (f : C [ X , Y ]) → η Y ∘ F₁ f ≈ G.F₁ f ∘ η X
-- We introduce an extra proof to ensure the opposite of the opposite of a natural
-- transformation is definitionally equal to itself.
sym-commute : ∀ {X Y} (f : C [ X , Y ]) → G.F₁ f ∘ η X ≈ η Y ∘ F₁ f
op : NaturalTransformation G.op F.op
op = record
{ η = η
; commute = sym-commute
; sym-commute = commute
}
-- Just like `Category`, we introduce a helper definition to ease the actual
-- construction of a natural transformation.
record NTHelper {C : Category o ℓ e}
{D : Category o′ ℓ′ e′}
(F G : Functor C D) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module G = Functor G
open Functor F using (F₀; F₁)
open Category D hiding (op)
field
η : ∀ X → D [ F₀ X , G.F₀ X ]
commute : ∀ {X Y} (f : C [ X , Y ]) → η Y ∘ F₁ f ≈ G.F₁ f ∘ η X
ntHelper : ∀ {F G : Functor C D} → NTHelper F G → NaturalTransformation F G
ntHelper {D = D} α = record
{ η = η
; commute = commute
; sym-commute = λ f → Equiv.sym (commute f)
}
where open NTHelper α
open Category D
id : ∀ {F : Functor C D} → NaturalTransformation F F
id {D = D} = ntHelper record
{ η = λ _ → D.id
; commute = λ _ → D.identityˡ ○ ⟺ D.identityʳ
}
where
module D = Category D
open D.HomReasoning
infixr 9 _∘ᵥ_ _∘ₕ_ _∘ˡ_ _∘ʳ_
-- "Vertical composition"
_∘ᵥ_ : ∀ {F G H : Functor C D} →
NaturalTransformation G H → NaturalTransformation F G → NaturalTransformation F H
_∘ᵥ_ {C = C} {D = D} {F} {G} {H} X Y = ntHelper record
{ η = λ q → D [ X.η q ∘ Y.η q ]
; commute = λ f → glue (X.commute f) (Y.commute f)
}
where module X = NaturalTransformation X
module Y = NaturalTransformation Y
open MR D
-- "Horizontal composition"
_∘ₕ_ : ∀ {F G : Functor C D} {H I : Functor D E} →
NaturalTransformation H I → NaturalTransformation F G → NaturalTransformation (H ∘F F) (I ∘F G)
_∘ₕ_ {E = E} {F} {I = I} Y X = ntHelper record
{ η = λ q → E [ I₁ (X.η q) ∘ Y.η (F.F₀ q) ]
; commute = λ f → glue ([ I ]-resp-square (X.commute f)) (Y.commute (F.F₁ f))
}
where module F = Functor F
module X = NaturalTransformation X
module Y = NaturalTransformation Y
open Functor I renaming (F₀ to I₀; F₁ to I₁)
open MR E
_∘ˡ_ : ∀ {G H : Functor C D} (F : Functor D E) → NaturalTransformation G H → NaturalTransformation (F ∘F G) (F ∘F H)
_∘ˡ_ F α = ntHelper record
{ η = λ X → F₁ (η X)
; commute = λ f → [ F ]-resp-square (commute f)
}
where open Functor F
open NaturalTransformation α
_∘ʳ_ : ∀ {G H : Functor D E} → NaturalTransformation G H → (F : Functor C D) → NaturalTransformation (G ∘F F) (H ∘F F)
_∘ʳ_ {D = D} {E = E} {G = G} {H = H} α F = ntHelper record
{ η = λ X → η (F₀ X)
; commute = λ f → commute (F₁ f)
}
where open Functor F
open NaturalTransformation α
id∘id⇒id : {C : Category o ℓ e} → NaturalTransformation {C = C} {D = C} (idF ∘F idF) idF
id∘id⇒id {C = C} = ntHelper record { η = λ _ → Category.id C ; commute = λ f → MR.id-comm-sym C {f = f} }
id⇒id∘id : {C : Category o ℓ e} → NaturalTransformation {C = C} {D = C} idF (idF ∘F idF)
id⇒id∘id {C = C} = ntHelper record { η = λ _ → Category.id C ; commute = λ f → MR.id-comm-sym C {f = f} }
module _ {F : Functor C D} where
open Category.HomReasoning D
open Functor F
open Category D
open MR D
private module D = Category D
F⇒F∘id : NaturalTransformation F (F ∘F idF)
F⇒F∘id = ntHelper record { η = λ _ → D.id ; commute = λ _ → id-comm-sym }
F⇒id∘F : NaturalTransformation F (idF ∘F F)
F⇒id∘F = ntHelper record { η = λ _ → D.id ; commute = λ _ → id-comm-sym }
F∘id⇒F : NaturalTransformation (F ∘F idF) F
F∘id⇒F = ntHelper record { η = λ _ → D.id ; commute = λ _ → id-comm-sym }
id∘F⇒F : NaturalTransformation (idF ∘F F) F
id∘F⇒F = ntHelper record { η = λ _ → D.id ; commute = λ _ → id-comm-sym }
| {
"alphanum_fraction": 0.5839831401,
"avg_line_length": 34.1366906475,
"ext": "agda",
"hexsha": "2ca779fca16d55a29a990f0c7954af7a4b33baa6",
"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": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/NaturalTransformation/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"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": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/NaturalTransformation/Core.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/NaturalTransformation/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1725,
"size": 4745
} |
------------------------------------------------------------------------
-- An alternative characterisation of the information ordering, along
-- with related results
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
open import Prelude hiding (⊥)
module Partiality-monad.Inductive.Alternative-order
{a} {A : Type a} where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Bijection equality-with-J using (_↔_)
open import Double-negation equality-with-J as DN
open import Equality.Path.Isomorphisms.Univalence equality-with-paths
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
as Trunc
open import Monad equality-with-J
open import Nat equality-with-J
open import Univalence-axiom equality-with-J
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Eliminators
------------------------------------------------------------------------
-- An alternative characterisation of λ x y → now x ⊑ y
-- This characterisation uses a technique from the first edition of
-- the HoTT book (Theorems 11.3.16 and 11.3.32).
--
-- The characterisation was developed together with Paolo Capriotti.
-- A binary relation, defined using structural recursion.
private
now[_]≲-args : A → Arguments-nd (lsuc a) a A
now[ x ]≲-args = record
{ P = Proposition a
; Q = λ P Q → proj₁ P → proj₁ Q
; pe = Prelude.⊥ , ⊥-propositional
; po = λ y → ∥ x ≡ y ∥ , truncation-is-proposition
; pl = λ { s (now-x≲s[_] , _) → ∥ ∃ (λ n → proj₁ (now-x≲s[ n ])) ∥
, truncation-is-proposition
}
; pa = λ now-x≲y now-x≲z now-x≲y→now-x≲z now-x≲z→now-x≲y →
$⟨ record { to = now-x≲y→now-x≲z; from = now-x≲z→now-x≲y } ⟩
proj₁ now-x≲y ⇔ proj₁ now-x≲z ↝⟨ _↔_.to (⇔↔≡″ ext prop-ext) ⟩□
now-x≲y ≡ now-x≲z □
; ps = ps
; qr = λ { _ (now-x≲y , _) →
now-x≲y ↝⟨ id ⟩□
now-x≲y □
}
; qt = λ { _ _ (P , _) (Q , _) (R , _) P→Q Q→R →
P ↝⟨ P→Q ⟩
Q ↝⟨ Q→R ⟩□
R □
}
; qe = λ { _ (now-x≲⊥ , _) →
Prelude.⊥ ↝⟨ ⊥-elim ⟩□
now-x≲⊥ □
}
; qu = λ { s (now-x≲s[_] , _) n →
proj₁ now-x≲s[ n ] ↝⟨ ∣_∣ ∘ (n ,_) ⟩□
∥ ∃ (λ n → proj₁ now-x≲s[ n ]) ∥ □
}
; ql = λ { s ub is-ub (now-x≲s[_] , _) now-x≲ub now-x≲s[]→now-x≲ub →
∥ ∃ (λ n → proj₁ now-x≲s[ n ]) ∥ ↝⟨ Trunc.rec (proj₂ now-x≲ub) (uncurry now-x≲s[]→now-x≲ub) ⟩□
proj₁ now-x≲ub □
}
; qp = λ _ now-x≲z → Π-closure ext 1 λ _ →
proj₂ now-x≲z
}
where
abstract
ps : Is-set (Proposition a)
ps = Is-set-∃-Is-proposition ext prop-ext
infix 4 now[_]≲_
now[_]≲_ : A → A ⊥ → Type a
now[ x ]≲ y = proj₁ (⊥-rec-nd now[ x ]≲-args y)
-- The relation is propositional.
now[]≲-propositional : ∀ {x y} → Is-proposition (now[ x ]≲ y)
now[]≲-propositional = proj₂ (⊥-rec-nd now[ _ ]≲-args _)
-- If a computation terminates with a certain value, then all larger
-- computations terminate with the same value (according to now[_]≲_).
larger-terminate-with-same-value≲ :
∀ {x y} → x ⊑ y → ∀ {z} → now[ z ]≲ x → now[ z ]≲ y
larger-terminate-with-same-value≲ x⊑y =
⊑-rec-nd now[ _ ]≲-args x⊑y
-- "Evaluation" lemmas for now[_]≲_.
now[]≲never : ∀ {x} → (now[ x ]≲ never) ≡ Prelude.⊥
now[]≲never {x} =
now[ x ]≲ never ≡⟨ cong proj₁ (⊥-rec-nd-never now[ x ]≲-args) ⟩∎
Prelude.⊥ ∎
now[]≲now : ∀ {x y} → (now[ x ]≲ now y) ≡ ∥ x ≡ y ∥
now[]≲now {x} {y} =
now[ x ]≲ now y ≡⟨ cong proj₁ (⊥-rec-nd-now now[ x ]≲-args y) ⟩∎
∥ x ≡ y ∥ ∎
now[]≲⨆ : ∀ {x s} → (now[ x ]≲ ⨆ s) ≡ ∥ (∃ λ n → now[ x ]≲ s [ n ]) ∥
now[]≲⨆ {x} {s} =
now[ x ]≲ ⨆ s ≡⟨ cong proj₁ (⊥-rec-nd-⨆ now[ x ]≲-args s) ⟩∎
∥ (∃ λ n → now[ x ]≲ s [ n ]) ∥ ∎
-- now[_]≲_ is pointwise equivalent to λ x y → now x ⊑ y.
now⊑≃now[]≲ : ∀ {x y} → (now x ⊑ y) ≃ (now[ x ]≲ y)
now⊑≃now[]≲ {x} {y} =
_↔_.to (Eq.⇔↔≃ ext ⊑-propositional now[]≲-propositional)
(record { to = now x ⊑ y ↝⟨ larger-terminate-with-same-value≲ ⟩
(∀ {z} → now[ z ]≲ now x → now[ z ]≲ y) ↝⟨ (λ hyp {_} eq → hyp (≡⇒→ (sym now[]≲now) eq)) ⟩
(∀ {z} → ∥ z ≡ x ∥ → now[ z ]≲ y) ↝⟨ (λ hyp → hyp ∣ refl ∣) ⟩□
now[ x ]≲ y □
; from = ⊥-rec-⊥ from-args _
})
where
from-args : Arguments-⊥ a A
from-args = record
{ P = λ y → now[ x ]≲ y → now x ⊑ y
; pe = now[ x ]≲ never ↝⟨ ≡⇒↝ _ now[]≲never ⟩
Prelude.⊥ ↝⟨ ⊥-elim ⟩□
now x ⊑ never □
; po = λ y →
now[ x ]≲ now y ↝⟨ ≡⇒↝ _ now[]≲now ⟩
∥ x ≡ y ∥ ↝⟨ Trunc.rec ⊑-propositional (
x ≡ y ↝⟨ cong now ⟩
now x ≡ now y ↝⟨ flip (subst (now x ⊑_)) (⊑-refl _) ⟩□
now x ⊑ now y □) ⟩□
now x ⊑ now y □
; pl = λ s now-x≲s→now-x⊑s →
now[ x ]≲ ⨆ s ↝⟨ ≡⇒↝ _ now[]≲⨆ ⟩
∥ ∃ (λ n → now[ x ]≲ s [ n ]) ∥ ↝⟨ Trunc.rec ⊑-propositional (uncurry λ n now-x≲s[n] →
now x ⊑⟨ now-x≲s→now-x⊑s n now-x≲s[n] ⟩
s [ n ] ⊑⟨ upper-bound s n ⟩■
⨆ s ■) ⟩□
now x ⊑ ⨆ s □
; pp = λ _ → Π-closure ext 1 λ _ →
⊑-propositional
}
------------------------------------------------------------------------
-- Some properties that follow from the equivalence between now[_]≲_
-- and λ x y → now x ⊑ y
-- An equivalence between "now x ⊑ never" and an empty type.
--
-- This lemma was proved together with Paolo Capriotti.
now⊑never≃⊥ : {x : A} → (now x ⊑ never) ≃ Prelude.⊥ {ℓ = a}
now⊑never≃⊥ {x} =
now x ⊑ never ↝⟨ now⊑≃now[]≲ ⟩
now[ x ]≲ never ↝⟨ ≡⇒↝ _ now[]≲never ⟩□
Prelude.⊥ □
-- Defined values of the form now x are never smaller than or equal to
-- never.
--
-- This lemma was proved together with Paolo Capriotti.
now⋢never : (x : A) → ¬ now x ⊑ never
now⋢never x =
now x ⊑ never ↔⟨ now⊑never≃⊥ ⟩
Prelude.⊥ ↝⟨ ⊥-elim ⟩□
⊥₀ □
-- Defined values of the form now x are never equal to never.
now≢never : (x : A) → now x ≢ never
now≢never x =
now x ≡ never ↝⟨ _≃_.from equality-characterisation-⊥ ⟩
now x ⊑ never × now x ⊒ never ↝⟨ proj₁ ⟩
now x ⊑ never ↝⟨ now⋢never x ⟩□
⊥₀ □
-- There is an equivalence between "now x is smaller than or equal
-- to now y" and "x is merely equal to y".
now⊑now≃∥≡∥ : {x y : A} → (now x ⊑ now y) ≃ ∥ x ≡ y ∥
now⊑now≃∥≡∥ {x} {y} =
now x ⊑ now y ↝⟨ now⊑≃now[]≲ ⟩
now[ x ]≲ now y ↝⟨ ≡⇒↝ _ now[]≲now ⟩□
∥ x ≡ y ∥ □
-- There is an equivalence between "now x is equal to now y" and "x
-- is merely equal to y".
now≡now≃∥≡∥ : {x y : A} → (now x ≡ now y) ≃ ∥ x ≡ y ∥
now≡now≃∥≡∥ {x} {y} =
now x ≡ now y ↝⟨ inverse equality-characterisation-⊥ ⟩
now x ⊑ now y × now x ⊒ now y ↝⟨ now⊑now≃∥≡∥ ×-cong now⊑now≃∥≡∥ ⟩
∥ x ≡ y ∥ × ∥ y ≡ x ∥ ↝⟨ _↔_.to (Eq.⇔↔≃ ext (×-closure 1 truncation-is-proposition
truncation-is-proposition)
truncation-is-proposition)
(record { to = proj₁
; from = λ ∥x≡y∥ → ∥x≡y∥ , ∥∥-map sym ∥x≡y∥
}) ⟩□
∥ x ≡ y ∥ □
-- There is an equivalence between "now x is smaller than or equal to
-- now y" and "now x is equal to now y".
now⊑now≃now≡now : {x y : A} → (now x ⊑ now y) ≃ (now x ≡ now y)
now⊑now≃now≡now {x} {y} =
now x ⊑ now y ↝⟨ now⊑now≃∥≡∥ ⟩
∥ x ≡ y ∥ ↝⟨ inverse now≡now≃∥≡∥ ⟩□
now x ≡ now y □
-- A computation can terminate with at most one value.
termination-value-merely-unique :
∀ {x y z} → x ⇓ y → x ⇓ z → ∥ y ≡ z ∥
termination-value-merely-unique {x} {y} {z} x⇓y x⇓z =
_≃_.to now≡now≃∥≡∥ (
now y ≡⟨ sym x⇓y ⟩
x ≡⟨ x⇓z ⟩∎
now z ∎)
-- There is an equivalence between now x ⊑ ⨆ s and
-- ∥ ∃ (λ n → now x ⊑ s [ n ]) ∥.
now⊑⨆≃∥∃now⊑∥ :
∀ {s : Increasing-sequence A} {x} →
(now x ⊑ ⨆ s) ≃ ∥ ∃ (λ n → now x ⊑ s [ n ]) ∥
now⊑⨆≃∥∃now⊑∥ {s} {x} =
now x ⊑ ⨆ s ↝⟨ now⊑≃now[]≲ ⟩
now[ x ]≲ ⨆ s ↝⟨ ≡⇒↝ _ now[]≲⨆ ⟩
∥ (∃ λ n → now[ x ]≲ s [ n ]) ∥ ↝⟨ ∥∥-cong (∃-cong λ _ → inverse now⊑≃now[]≲) ⟩□
∥ (∃ λ n → now x ⊑ s [ n ]) ∥ □
-- If x is larger than or equal to now y, then x is equal to now y.
now⊑→⇓ : ∀ {x} {y : A} → now y ⊑ x → x ⇓ y
now⊑→⇓ {x} {y} = ⊥-rec-⊥ (record
{ P = λ x → now y ⊑ x → x ⇓ y
; pe = now y ⊑ never ↝⟨ now⋢never y ⟩
Prelude.⊥ ↝⟨ ⊥-elim ⟩□
never ≡ now y □
; po = λ x →
now y ⊑ now x ↔⟨ now⊑now≃∥≡∥ ⟩
∥ y ≡ x ∥ ↝⟨ ∥∥-map sym ⟩
∥ x ≡ y ∥ ↝⟨ Trunc.rec ⊥-is-set (cong now) ⟩□
now x ≡ now y □
; pl = λ s hyp →
now y ⊑ ⨆ s ↝⟨ (λ p → p , _≃_.to now⊑⨆≃∥∃now⊑∥ p) ⟩
now y ⊑ ⨆ s × ∥ (∃ λ n → now y ⊑ s [ n ]) ∥ ↝⟨ uncurry (λ p → Trunc.rec ⊥-is-set (uncurry λ n →
now y ⊑ s [ n ] ↝⟨ (λ now⊑ _ n≤m → ⊑-trans now⊑ (later-larger s n≤m)) ⟩
(∀ m → n ≤ m → now y ⊑ s [ m ]) ↝⟨ (∀-cong _ λ _ → ∀-cong _ λ _ → hyp _) ⟩
(∀ m → n ≤ m → s [ m ] ≡ now y) ↝⟨ (∀-cong _ λ _ → ∀-cong _ λ _ → flip (subst (_ ⊑_)) (⊑-refl _)) ⟩
(∀ m → n ≤ m → s [ m ] ⊑ now y) ↝⟨ upper-bound-≤→upper-bound s ⟩
(∀ n → s [ n ] ⊑ now y) ↝⟨ least-upper-bound _ _ ⟩
⨆ s ⊑ now y ↝⟨ flip antisymmetry p ⟩□
⨆ s ≡ now y □)) ⟩□
⨆ s ≡ now y □
; pp = λ _ → Π-closure ext 1 λ _ →
⊥-is-set
})
x
-- If a computation terminates with a certain value, then all larger
-- computations terminate with the same value.
--
-- Capretta proved a similar result in "General Recursion via
-- Coinductive Types".
larger-terminate-with-same-value : {x y : A ⊥} → x ⊑ y → x ≼ y
larger-terminate-with-same-value now-x⊑y _ refl = now⊑→⇓ now-x⊑y
-- If one element in an increasing sequence terminates with a given
-- value, then this value is the sequence's least upper bound.
terminating-element-is-⨆ :
∀ (s : Increasing-sequence A) {n x} →
s [ n ] ⇓ x → ⨆ s ⇓ x
terminating-element-is-⨆ s {n} {x} =
larger-terminate-with-same-value (upper-bound s n) x
-- The relation _≼_ is contained in _⊑_.
--
-- Capretta proved a similar result in "General Recursion via
-- Coinductive Types".
≼→⊑ : {x y : A ⊥} → x ≼ y → x ⊑ y
≼→⊑ {x} {y} = ⊥-rec-⊥
(record
{ P = λ x → x ≼ y → x ⊑ y
; pe = never ≼ y ↝⟨ (λ _ → never⊑ y) ⟩□
never ⊑ y □
; po = λ x →
now x ≼ y ↝⟨ (λ hyp → hyp x refl) ⟩
y ⇓ x ↔⟨ inverse equality-characterisation-⊥ ⟩
y ⊑ now x × y ⊒ now x ↝⟨ proj₂ ⟩□
now x ⊑ y □
; pl = λ s s≼y→s⊑y →
⨆ s ≼ y ↝⟨ id ⟩
(∀ z → ⨆ s ⇓ z → y ⇓ z) ↝⟨ (λ hyp n z →
s [ n ] ⇓ z ↝⟨ larger-terminate-with-same-value (upper-bound s n) z ⟩
⨆ s ⇓ z ↝⟨ hyp z ⟩□
y ⇓ z □) ⟩
(∀ n z → s [ n ] ⇓ z → y ⇓ z) ↝⟨ id ⟩
(∀ n → s [ n ] ≼ y) ↝⟨ (λ hyp n → s≼y→s⊑y n (hyp n)) ⟩
(∀ n → s [ n ] ⊑ y) ↝⟨ least-upper-bound s y ⟩□
⨆ s ⊑ y □
; pp = λ _ →
Π-closure ext 1 λ _ →
⊑-propositional
})
x
-- The two relations _≼_ and _⊑_ are pointwise equivalent.
--
-- Capretta proved a similar result in "General Recursion via
-- Coinductive Types".
≼≃⊑ : {x y : A ⊥} → (x ≼ y) ≃ (x ⊑ y)
≼≃⊑ = _↔_.to (Eq.⇔↔≃ ext ≼-propositional ⊑-propositional)
(record { to = ≼→⊑
; from = larger-terminate-with-same-value
})
-- An alternative characterisation of _⇓_.
⇓≃now⊑ : ∀ {x} {y : A} → (x ⇓ y) ≃ (now y ⊑ x)
⇓≃now⊑ {x} {y} =
_↔_.to (Eq.⇔↔≃ ext ⊥-is-set ⊑-propositional) (record
{ to = x ≡ now y ↔⟨ inverse equality-characterisation-⊥ ⟩
x ⊑ now y × x ⊒ now y ↝⟨ proj₂ ⟩□
now y ⊑ x □
; from = now y ⊑ x ↝⟨ larger-terminate-with-same-value ⟩
(∀ z → now y ⇓ z → x ⇓ z) ↝⟨ (λ hyp → hyp y refl) ⟩□
x ⇓ y □
})
-- Another alternative characterisation of _⇓_.
⇓≃now[]≲ : ∀ {x y} → (x ⇓ y) ≃ (now[ y ]≲ x)
⇓≃now[]≲ {x} {y} =
x ⇓ y ↝⟨ ⇓≃now⊑ ⟩
now y ⊑ x ↝⟨ now⊑≃now[]≲ ⟩□
now[ y ]≲ x □
-- Two corollaries of ⇓≃now[]≲.
never⇓≃⊥ : {x : A} → (never ⇓ x) ≃ Prelude.⊥ {ℓ = a}
never⇓≃⊥ {x = x} =
never ≡ now x ↝⟨ ⇓≃now[]≲ ⟩
now[ x ]≲ never ↝⟨ ≡⇒↝ _ now[]≲never ⟩□
Prelude.⊥ □
⨆⇓≃∥∃⇓∥ :
∀ {s : Increasing-sequence A} {x} →
(⨆ s ⇓ x) ≃ ∥ ∃ (λ n → s [ n ] ⇓ x) ∥
⨆⇓≃∥∃⇓∥ {s} {x} =
⨆ s ⇓ x ↝⟨ ⇓≃now[]≲ ⟩
now[ x ]≲ ⨆ s ↝⟨ ≡⇒↝ _ now[]≲⨆ ⟩
∥ ∃ (λ n → now[ x ]≲ s [ n ]) ∥ ↝⟨ ∥∥-cong (∃-cong λ _ → inverse ⇓≃now[]≲) ⟩□
∥ ∃ (λ n → s [ n ] ⇓ x) ∥ □
-- If x does not terminate, then x is equal to never.
¬⇓→⇑ : {x : A ⊥} → ¬ (∃ λ y → x ⇓ y) → x ⇑
¬⇓→⇑ {x} = ⊥-rec-⊥
(record
{ P = λ x → ¬ (∃ λ y → x ⇓ y) → x ⇑
; pe = ¬ ∃ (never ⇓_) ↝⟨ const refl ⟩□
never ⇑ □
; po = λ x →
¬ ∃ (now x ⇓_) ↝⟨ _$ (x , refl) ⟩
⊥₀ ↝⟨ ⊥-elim ⟩□
now x ⇑ □
; pl = λ s ih →
¬ ∃ (⨆ s ⇓_) ↔⟨ →-cong ext (∃-cong (λ _ → ⨆⇓≃∥∃⇓∥)) F.id ⟩
¬ ∃ (λ x → ∥ ∃ (λ n → s [ n ] ⇓ x) ∥) ↝⟨ (λ { hyp (n , x , s[n]⇓x) → hyp (x , ∣ n , s[n]⇓x ∣) }) ⟩
¬ ∃ (λ n → ∃ λ x → s [ n ] ⇓ x) ↝⟨ (λ hyp n → ih n (hyp ∘ (n ,_))) ⟩
(∀ n → s [ n ] ⇑) ↝⟨ sym ∘ _↔_.to equality-characterisation-increasing ⟩
constˢ never ≡ s ↝⟨ flip (subst (λ s → ⨆ s ⇑)) ⨆-const ⟩□
⨆ s ⇑ □
; pp = λ _ → Π-closure ext 1 λ _ →
⊥-is-set
})
x
-- In the double-negation monad a computation is either terminating or
-- non-terminating.
now-or-never : (x : A ⊥) → ¬ ¬ ((∃ λ y → x ⇓ y) ⊎ x ⇑)
now-or-never x = run (map (⊎-map id ¬⇓→⇑) excluded-middle)
-- _⊑_ is a flat order, in the sense that distinct elements that are
-- distinct from never are unrelated.
flat-order : {x y : A ⊥} → x ≢ y → ¬ x ⇑ → ¬ y ⇑ → ¬ (x ⊑ y)
flat-order {x} {y} x≢y never≢x never≢y x⊑y = ¬¬¬⊥ $
¬⇑→¬¬⇓ never≢x >>= λ x⇓ →
¬⇑→¬¬⇓ never≢y >>= λ y⇓ →
return (⊥-elim $ ¬x⇓×y⇓ (x⇓ , y⇓))
where
-- The computations x and y cannot both terminate.
¬x⇓×y⇓ : ¬ ((∃ λ z → x ⇓ z) × (∃ λ z → y ⇓ z))
¬x⇓×y⇓ ((xz , refl) , (yz , refl)) = x≢y (
now xz ≡⟨ _≃_.to now⊑now≃now≡now (
now xz ⊑⟨ x⊑y ⟩■
now yz ■) ⟩∎
now yz ∎)
-- Computations that fail to be equal to never do not fail to
-- terminate.
¬⇑→¬¬⇓ : {x : A ⊥} → ¬ x ⇑ → ¬¬ (∃ λ y → x ⇓ y)
run (¬⇑→¬¬⇓ ¬x⇑) = ¬x⇑ ∘ ¬⇓→⇑
-- Some "constructors" for □.
□-never :
∀ {ℓ} {P : A → Type ℓ} →
□ P never
□-never {P = P} y =
never ⇓ y ↔⟨ ⇓≃now[]≲ ⟩
now[ y ]≲ never ↔⟨ ≡⇒↝ bijection now[]≲never ⟩
Prelude.⊥ ↝⟨ ⊥-elim ⟩□
P y □
□-now :
∀ {ℓ} {P : A → Type ℓ} {x} →
Is-proposition (P x) →
P x → □ P (now x)
□-now {P = P} {x} P-prop p y =
now x ⇓ y ↔⟨ now≡now≃∥≡∥ ⟩
∥ x ≡ y ∥ ↝⟨ (λ ∥x≡y∥ →
Trunc.rec (Trunc.rec (H-level-propositional ext 1)
(λ x≡y → subst (Is-proposition ∘ P) x≡y P-prop)
∥x≡y∥)
(λ x≡y → subst P x≡y p)
∥x≡y∥) ⟩□
P y □
□-⨆ :
∀ {ℓ} {P : A → Type ℓ} →
(∀ x → Is-proposition (P x)) →
∀ {s} → (∀ n → □ P (s [ n ])) → □ P (⨆ s)
□-⨆ {P = P} P-prop {s} p y =
⨆ s ⇓ y ↔⟨ ⨆⇓≃∥∃⇓∥ ⟩
∥ ∃ (λ n → s [ n ] ⇓ y) ∥ ↝⟨ Trunc.rec (P-prop y) (uncurry λ n s[n]⇓y → p n y s[n]⇓y) ⟩□
P y □
-- One "non-constructor" and one "constructor" for ◇.
◇-never :
∀ {ℓ} {P : A → Type ℓ} →
¬ ◇ P never
◇-never {P = P} =
◇ P never ↝⟨ id ⟩
∥ (∃ λ y → never ⇓ y × P y) ∥ ↝⟨ Trunc.rec ⊥-propositional (now≢never _ ∘ sym ∘ proj₁ ∘ proj₂) ⟩□
⊥₀ □
◇-⨆ :
∀ {ℓ} {P : A → Type ℓ} →
∀ {s n} → ◇ P (s [ n ]) → ◇ P (⨆ s)
◇-⨆ {P = P} =
∥∥-map (Σ-map id (λ {x} → Σ-map {Q = λ _ → P x}
(terminating-element-is-⨆ _) id))
------------------------------------------------------------------------
-- An alternative characterisation of _⊑_
-- This characterisation uses a technique from the first edition of
-- the HoTT book (Theorems 11.3.16 and 11.3.32).
--
-- The characterisation was developed together with Paolo Capriotti.
-- A binary relation, defined using structural recursion.
private
≲-args : Arguments-nd (lsuc a) a A
≲-args = record
{ P = A ⊥ → Proposition a
; Q = λ P Q → ∀ z → proj₁ (Q z) → proj₁ (P z)
; pe = λ _ → ↑ _ ⊤ , ↑-closure 1 (mono₁ 0 ⊤-contractible)
; po = λ x y → ⊥-rec-nd now[ x ]≲-args y
; pl = λ { _ (s[_]≲ , _) y → (∀ n → proj₁ (s[ n ]≲ y))
, Π-closure ext 1 λ n →
proj₂ (s[ n ]≲ y)
}
; pa = λ x≲ y≲ y≲→x≲ x≲→y≲ → ⟨ext⟩ λ z →
$⟨ record { to = x≲→y≲ z; from = y≲→x≲ z } ⟩
proj₁ (x≲ z) ⇔ proj₁ (y≲ z) ↝⟨ _↔_.to (⇔↔≡″ ext prop-ext) ⟩□
x≲ z ≡ y≲ z □
; ps = ps
; qr = λ _ x≲ z →
proj₁ (x≲ z) ↝⟨ id ⟩□
proj₁ (x≲ z) □
; qt = λ _ _ P Q R Q→P R→Q z →
proj₁ (R z) ↝⟨ R→Q z ⟩
proj₁ (Q z) ↝⟨ Q→P z ⟩□
proj₁ (P z) □
; qe = λ _ ⊥≲ z →
proj₁ (⊥≲ z) ↝⟨ _ ⟩□
↑ _ ⊤ □
; qu = λ { s (s[_]≲ , _) n z →
(∀ m → proj₁ (s[ m ]≲ z)) ↝⟨ (_$ n) ⟩□
proj₁ (s[ n ]≲ z) □
}
; ql = λ { _ _ _ (s[_]≲ , _) ub≲ ub≲→s[]≲ z →
proj₁ (ub≲ z) ↝⟨ flip (flip ub≲→s[]≲ z) ⟩□
(∀ n → proj₁ (s[ n ]≲ z)) □
}
; qp = λ x≲ y≲ → Π-closure ext 1 λ z →
Π-closure ext 1 λ _ →
proj₂ (x≲ z)
}
where
abstract
ps : Is-set (A ⊥ → Proposition a)
ps =
Π-closure ext 2 λ _ →
Is-set-∃-Is-proposition ext prop-ext
infix 4 _≲_
_≲_ : A ⊥ → A ⊥ → Type a
x ≲ y = proj₁ (⊥-rec-nd ≲-args x y)
-- The relation is propositional.
≲-propositional : ∀ x y → Is-proposition (x ≲ y)
≲-propositional x y = proj₂ (⊥-rec-nd ≲-args x y)
-- A form of transitivity involving _⊑_ and _≲_.
⊑≲-trans : ∀ {x y} (z : A ⊥) → x ⊑ y → y ≲ z → x ≲ z
⊑≲-trans z x⊑y = ⊑-rec-nd ≲-args x⊑y z
-- "Evaluation" lemmas for _≲_.
never≲ : ∀ {y} → (never ≲ y) ≡ ↑ _ ⊤
never≲ {y} = cong (proj₁ ∘ (_$ _)) (
⊥-rec-nd ≲-args never ≡⟨ ⊥-rec-nd-never ≲-args ⟩∎
(λ _ → ↑ _ ⊤ , _) ∎)
⨆≲ : ∀ {s y} → (⨆ s ≲ y) ≡ ∀ n → s [ n ] ≲ y
⨆≲ {s} {y} = cong (proj₁ ∘ (_$ _)) (
⊥-rec-nd ≲-args (⨆ s) ≡⟨ ⊥-rec-nd-⨆ ≲-args s ⟩∎
(λ y → (∀ n → s [ n ] ≲ y) , _) ∎)
now≲ : ∀ {x y} → (now x ≲ y) ≡ (now[ x ]≲ y)
now≲ {x} {y} =
now x ≲ y ≡⟨ cong (proj₁ ∘ (_$ _)) (⊥-rec-nd-now ≲-args x) ⟩∎
now[ x ]≲ y ∎
now≲never : ∀ {x} → (now x ≲ never) ≡ Prelude.⊥
now≲never {x} =
now x ≲ never ≡⟨ now≲ ⟩
now[ x ]≲ never ≡⟨ now[]≲never ⟩∎
Prelude.⊥ ∎
now≲now : ∀ {x y} → (now x ≲ now y) ≡ ∥ x ≡ y ∥
now≲now {x} {y} =
now x ≲ now y ≡⟨ now≲ ⟩
now[ x ]≲ now y ≡⟨ now[]≲now ⟩∎
∥ x ≡ y ∥ ∎
now≲⨆ : ∀ {x s} → (now x ≲ ⨆ s) ≡ ∥ (∃ λ n → now x ≲ s [ n ]) ∥
now≲⨆ {x} {s} =
now x ≲ ⨆ s ≡⟨ now≲ ⟩
now[ x ]≲ ⨆ s ≡⟨ now[]≲⨆ ⟩
∥ (∃ λ n → now[ x ]≲ s [ n ]) ∥ ≡⟨ cong (λ P → ∥ ∃ P ∥) (⟨ext⟩ λ _ → sym now≲) ⟩∎
∥ (∃ λ n → now x ≲ s [ n ]) ∥ ∎
-- _≲_ is reflexive.
≲-refl : ∀ x → x ≲ x
≲-refl = ⊥-rec-⊥ (record
{ pe = $⟨ _ ⟩
↑ _ ⊤ ↝⟨ ≡⇒↝ bijection $ sym never≲ ⟩□
never ≲ never □
; po = λ x → $⟨ ∣ refl ∣ ⟩
∥ x ≡ x ∥ ↝⟨ ≡⇒↝ bijection $ sym now≲now ⟩□
now x ≲ now x □
; pl = λ s →
(∀ n → s [ n ] ≲ s [ n ]) ↝⟨ (λ s≲s n → ⨆-lemma s (s [ n ]) n (s≲s n)) ⟩
(∀ n → s [ n ] ≲ ⨆ s) ↔⟨ ≡⇒↝ bijection $ sym ⨆≲ ⟩□
⨆ s ≲ ⨆ s □
; pp = λ x → ≲-propositional x x
})
where
⨆-lemma : ∀ s x n → x ≲ s [ n ] → x ≲ ⨆ s
⨆-lemma s = ⊥-rec-⊥
(record
{ P = λ x → ∀ n → x ≲ s [ n ] → x ≲ ⨆ s
; pe = λ n →
never ≲ s [ n ] ↔⟨ ≡⇒↝ bijection $ never≲ ⟩
↑ _ ⊤ ↔⟨ ≡⇒↝ bijection $ sym never≲ ⟩□
never ≲ ⨆ s □
; po = λ x n →
now x ≲ s [ n ] ↝⟨ ∣_∣ ∘ (n ,_) ⟩
∥ (∃ λ n → now x ≲ s [ n ]) ∥ ↔⟨ ≡⇒↝ bijection $ sym now≲⨆ ⟩□
now x ≲ ⨆ s □
; pl = λ s′ →
(∀ m n → s′ [ m ] ≲ s [ n ] → s′ [ m ] ≲ ⨆ s) ↝⟨ (λ hyp n s′≲s m → hyp m n (s′≲s m)) ⟩
(∀ n → (∀ m → s′ [ m ] ≲ s [ n ]) →
(∀ m → s′ [ m ] ≲ ⨆ s)) ↝⟨ ∀-cong _ (λ _ →
≡⇒↝ _ $ sym $ cong₂ (λ x y → x → y) ⨆≲ ⨆≲) ⟩□
(∀ n → ⨆ s′ ≲ s [ n ] → ⨆ s′ ≲ ⨆ s) □
; pp = λ x → Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
≲-propositional x (⨆ s)
})
-- _⊑_ and _≲_ are pointwise equivalent.
⊑≃≲ : ∀ {x y} → (x ⊑ y) ≃ (x ≲ y)
⊑≃≲ {x} {y} =
_↔_.to (Eq.⇔↔≃ ext ⊑-propositional (≲-propositional x y))
(record { to = λ x⊑y → ⊑≲-trans _ x⊑y (≲-refl y)
; from = ⊥-rec-⊥ from-args _ _
})
where
from-args : Arguments-⊥ a A
from-args = record
{ P = λ x → ∀ y → x ≲ y → x ⊑ y
; pe = λ y _ → never⊑ y
; po = λ x y →
now x ≲ y ↝⟨ ≡⇒↝ _ now≲ ⟩
now[ x ]≲ y ↔⟨ inverse now⊑≃now[]≲ ⟩□
now x ⊑ y □
; pl = λ s s≲→s⊑ y →
⨆ s ≲ y ↝⟨ ≡⇒↝ _ ⨆≲ ⟩
(∀ n → s [ n ] ≲ y) ↝⟨ (λ s[_]≲y n → s≲→s⊑ n y s[ n ]≲y) ⟩
(∀ n → s [ n ] ⊑ y) ↝⟨ least-upper-bound s y ⟩□
⨆ s ⊑ y □
; pp = λ _ → Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
⊑-propositional
}
| {
"alphanum_fraction": 0.3892087238,
"avg_line_length": 35.7312312312,
"ext": "agda",
"hexsha": "715583d01b5204fe1518f5e1f571eaa9f9f4f8ff",
"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": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Inductive/Alternative-order.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"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/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Inductive/Alternative-order.agda",
"max_line_length": 128,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Inductive/Alternative-order.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 10555,
"size": 23797
} |
------------------------------------------------------------------------------
-- Testing the translation of the universal quantified propositional symbols
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PropositionalSymbol where
postulate D : Set
postulate id : {P : Set} → P → P
{-# ATP prove id #-}
| {
"alphanum_fraction": 0.4166666667,
"avg_line_length": 32.25,
"ext": "agda",
"hexsha": "9b26c3ed5eacb7a84f8257643dc953e654f1bc6e",
"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/non-fol-theorems/PropositionalSymbol.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/non-fol-theorems/PropositionalSymbol.agda",
"max_line_length": 78,
"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/non-fol-theorems/PropositionalSymbol.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": 80,
"size": 516
} |
-- 2014-06-02 Andrea & Andreas
module _ where
open import Common.Equality
open import Common.Product
postulate
A : Set
F : Set → Set
test : let M : Set
M = _
N : Set × Set → Set
N = _
in ∀ {X : Set}
→ M ≡ F (N (X , X))
× N (A , A) ≡ A
test = refl , refl
-- Here, we can prune the argument of N,
-- since M does not depend on X,
-- and the argument is a pair with a bad rigid
-- in *each* component.
| {
"alphanum_fraction": 0.5329087049,
"avg_line_length": 18.84,
"ext": "agda",
"hexsha": "d813228becb47eeef99f22363bf133ae90d82104",
"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/PruneRecord.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/PruneRecord.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/Succeed/PruneRecord.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": 145,
"size": 471
} |
-- Semantics of syntactic kits and explicit substitutions
module Semantics.Substitution.Kits where
open import Syntax.Types
open import Syntax.Context renaming (_,_ to _,,_)
open import Syntax.Terms
open import Syntax.Substitution.Kits
open import Semantics.Types
open import Semantics.Context
open import Semantics.Terms
open import CategoryTheory.Categories
open import CategoryTheory.Instances.Reactive renaming (top to Top)
open import CategoryTheory.Functor
open import CategoryTheory.Comonad
open import TemporalOps.Diamond
open import TemporalOps.Box
open import TemporalOps.Linear
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality as ≡
using (_≡_ ; refl)
open Comonad W-□
private module F-□ = Functor F-□
-- Semantic interpretation of kits, grouping together
-- lemmas for the kit operations
record ⟦Kit⟧ {𝒮 : Schema} (k : Kit 𝒮) : Set where
open Kit k
field
-- Interpretation of the syntactic entity of the given scheme
⟦_⟧ : ∀{A Δ} -> 𝒮 Δ A -> ⟦ Δ ⟧ₓ ⇴ ⟦ A ⟧ⱼ
-- Variable conversion lemma
⟦𝓋⟧ : ∀ A Δ
-> ⟦ 𝓋 {Δ ,, A} top ⟧ ≈ π₂
-- Term conversion lemma
⟦𝓉⟧ : ∀{A Δ} (T : 𝒮 Δ A)
-> ⟦ 𝓉 T ⟧ₘ ≈ ⟦ T ⟧
-- Weakening map lemma
⟦𝓌⟧ : ∀ B {Δ A} (T : 𝒮 Δ A)
-> ⟦ 𝓌 {B} T ⟧ ≈ ⟦ T ⟧ ∘ π₁
-- Context stabilisation lemma
⟦𝒶⟧ : ∀{A Δ} (T : 𝒮 Δ (A always))
-> F-□.fmap ⟦ 𝒶 T ⟧ ∘ ⟦ Δ ˢ⟧□ ≈ δ.at ⟦ A ⟧ₜ ∘ ⟦ T ⟧
-- | Interpretation of substitutions and combinators
module ⟦K⟧ {𝒮} {k : Kit 𝒮} (⟦k⟧ : ⟦Kit⟧ k) where
open ⟦Kit⟧ ⟦k⟧
open Kit k
-- Denotation of substitutions as a map between contexts
⟦subst⟧ : ∀{Γ Δ} -> Subst 𝒮 Γ Δ -> ⟦ Δ ⟧ₓ ⇴ ⟦ Γ ⟧ₓ
⟦subst⟧ ● = !
⟦subst⟧ (σ ▸ T) = ⟨ ⟦subst⟧ σ , ⟦ T ⟧ ⟩
-- Simplified context stabilisation lemma for non-boxed stabilisation
⟦𝒶⟧′ : ∀{A Δ} (T : 𝒮 Δ (A always))
-> ⟦ 𝒶 T ⟧ ∘ ⟦ Δ ˢ⟧ ≈ ⟦ T ⟧
⟦𝒶⟧′ {A} {Δ} T {n} {⟦Δ⟧} rewrite ⟦ˢ⟧-factor Δ {n} {⟦Δ⟧}
= □-≡ n n (⟦𝒶⟧ T) n
-- Denotation of weakening
⟦⁺⟧ : ∀ A {Γ Δ} -> (σ : Subst 𝒮 Γ Δ)
-> ⟦subst⟧ (_⁺_ {A} σ k) ≈ ⟦subst⟧ σ ∘ π₁
⟦⁺⟧ A ● = refl
⟦⁺⟧ A (_▸_ {B} σ T) {n} {a} rewrite ⟦⁺⟧ A σ {n} {a}
| ⟦𝓌⟧ A T {n} {a} = refl
-- Denotation of lifting
⟦↑⟧ : ∀ A {Δ Γ} -> (σ : Subst 𝒮 Γ Δ)
-> ⟦subst⟧ (_↑_ {A} σ k) ≈ (⟦subst⟧ σ * id)
⟦↑⟧ A {Δ} ● {n} {a} rewrite ⟦𝓋⟧ A Δ {n} {a} = refl
⟦↑⟧ A {Δ} (σ ▸ T) {n} {a} rewrite ⟦⁺⟧ A σ {n} {a}
| ⟦𝓌⟧ A T {n} {a}
| ⟦𝓋⟧ A Δ {n} {a} = refl
-- Denotation of stabilisation (naturality condition for ⟦_ˢ⟧□)
⟦↓ˢ⟧ : ∀ {Γ Δ} -> (σ : Subst 𝒮 Γ Δ)
-> F-□.fmap (⟦subst⟧ (σ ↓ˢ k)) ∘ ⟦ Δ ˢ⟧□ ≈ ⟦ Γ ˢ⟧□ ∘ ⟦subst⟧ σ
⟦↓ˢ⟧ ● = refl
⟦↓ˢ⟧ (_▸_ {A now} σ T) {n} {a} rewrite ⟦↓ˢ⟧ σ {n} {a} = refl
⟦↓ˢ⟧ {Δ = Δ} (_▸_ {A always}{Γ} σ T) {n} {a} = ext lemma
where
lemma : ∀ l -> (F-□.fmap (⟦subst⟧ ((σ ▸ T) ↓ˢ k)) ∘ ⟦ Δ ˢ⟧□) n a l
≡ (⟦ Γ ,, A always ˢ⟧□ ∘ ⟦subst⟧ (σ ▸ T)) n a l
lemma l rewrite □-≡ n l (⟦↓ˢ⟧ σ {n} {a}) l
| □-≡ n l (⟦𝒶⟧ T {n} {a}) l = refl
-- Simplified denotation of stabilisation
⟦↓ˢ⟧′ : ∀ {Γ Δ} -> (σ : Subst 𝒮 Γ Δ)
-> ⟦subst⟧ (σ ↓ˢ k) ∘ ⟦ Δ ˢ⟧ ≈ ⟦ Γ ˢ⟧ ∘ ⟦subst⟧ σ
⟦↓ˢ⟧′ {Γ} {Δ} σ {n} {a} rewrite ⟦ˢ⟧-factor Δ {n} {a}
| □-≡ n n (⟦↓ˢ⟧ σ {n} {a}) n
| ⟦ˢ⟧-factor Γ {n} {(⟦subst⟧ σ n a)} = refl
-- Denotation of stabilisation idempotence
⟦ˢˢ⟧ : ∀ Γ -> F-□.fmap (⟦subst⟧ (Γ ˢˢₛ k)) ∘ ⟦ Γ ˢ ˢ⟧□ ∘ ⟦ Γ ˢ⟧ ≈ ⟦ Γ ˢ⟧□
⟦ˢˢ⟧ ∙ = refl
⟦ˢˢ⟧ (Γ ,, B now) = ⟦ˢˢ⟧ Γ
⟦ˢˢ⟧ (Γ ,, B always) {n} {⟦Γˢ⟧ , □⟦B⟧} = ext lemma
where
lemma : ∀ l → (F-□.fmap (⟦subst⟧ ((Γ ,, B always) ˢˢₛ k))
∘ ⟦ (Γ ,, B always) ˢ ˢ⟧□
∘ ⟦ Γ ,, B always ˢ⟧) n (⟦Γˢ⟧ , □⟦B⟧) l
≡ (⟦ Γ ˢ⟧□ n ⟦Γˢ⟧ l , □⟦B⟧)
lemma l rewrite ⟦𝓋⟧ (B always) (Γ ˢ ˢ) {l} {⟦ Γ ˢ ˢ⟧□ n (⟦ Γ ˢ⟧ n ⟦Γˢ⟧) l , □⟦B⟧}
| ⟦⁺⟧ (B always) (Γ ˢˢₛ k) {l} {(⟦ Γ ˢ ˢ⟧□ n (⟦ Γ ˢ⟧ n ⟦Γˢ⟧) l , □⟦B⟧)}
| □-≡ n l (⟦ˢˢ⟧ Γ {n} {⟦Γˢ⟧}) l = refl
-- Denotation of identity substitution
⟦idₛ⟧ : ∀ {Γ} -> ⟦subst⟧ (idₛ {Γ} k) ≈ id
⟦idₛ⟧ {∙} = refl
⟦idₛ⟧ {Γ ,, A} {n} {⟦Γ⟧ , ⟦A⟧}
rewrite ⟦⁺⟧ A {Γ} (idₛ k) {n} {⟦Γ⟧ , ⟦A⟧}
| ⟦idₛ⟧ {Γ} {n} {⟦Γ⟧}
| ⟦𝓋⟧ A Γ {n} {⟦Γ⟧ , ⟦A⟧} = refl
-- | Other lemmas
-- Substitution by the Γ ˢ ⊆ Γ subcontext substitution is the same as
-- stabilising the context
⟦subst⟧-Γˢ⊆Γ : ∀ Γ -> ⟦subst⟧ (Γˢ⊆Γ Γ ⊆ₛ k) ≈ ⟦ Γ ˢ⟧
⟦subst⟧-Γˢ⊆Γ ∙ = refl
⟦subst⟧-Γˢ⊆Γ (Γ ,, A now) {n} {⟦Γ⟧ , ⟦A⟧}
rewrite ⟦⁺⟧ (A now) (Γˢ⊆Γ Γ ⊆ₛ k) {n} {⟦Γ⟧ , ⟦A⟧} = ⟦subst⟧-Γˢ⊆Γ Γ
⟦subst⟧-Γˢ⊆Γ (Γ ,, A always) {n} {⟦Γ⟧ , ⟦A⟧}
rewrite ⟦↑⟧ (A always) (Γˢ⊆Γ Γ ⊆ₛ k) {n} {⟦Γ⟧ , ⟦A⟧}
| ⟦subst⟧-Γˢ⊆Γ Γ {n} {⟦Γ⟧} = refl
-- Interpretation of substitution and selection can be commuted
⟦subst⟧-handle : ∀{Δ Γ A B C} -> (σ : Subst 𝒮 Γ Δ)
-> {⟦C₁⟧ : ⟦ Γ ˢ ⟧ₓ ⊗ ⟦ A ⟧ₜ ⊗ ◇ ⟦ B ⟧ₜ ⇴ ◇ ⟦ C ⟧ₜ}
-> {⟦C₂⟧ : ⟦ Γ ˢ ⟧ₓ ⊗ ◇ ⟦ A ⟧ₜ ⊗ ⟦ B ⟧ₜ ⇴ ◇ ⟦ C ⟧ₜ}
-> {⟦C₃⟧ : ⟦ Γ ˢ ⟧ₓ ⊗ ⟦ A ⟧ₜ ⊗ ⟦ B ⟧ₜ ⇴ ◇ ⟦ C ⟧ₜ}
-> (handle
(⟦C₁⟧ ∘ (⟦subst⟧ (_↑_ {Event B now} (_↑_ {A now} (σ ↓ˢ k) k) k)))
(⟦C₂⟧ ∘ (⟦subst⟧ (_↑_ {B now} (_↑_ {Event A now} (σ ↓ˢ k) k) k)))
(⟦C₃⟧ ∘ (⟦subst⟧ (_↑_ {B now} (_↑_ {A now} (σ ↓ˢ k) k) k))))
≈ handle ⟦C₁⟧ ⟦C₂⟧ ⟦C₃⟧ ∘ (⟦subst⟧ (σ ↓ˢ k) * id)
⟦subst⟧-handle {A = A} {B} σ {n = n} {⟦Δ⟧ , inj₁ (inj₁ (⟦A⟧ , ⟦◇B⟧))}
rewrite ⟦↑⟧ (Event B now) (_↑_ {A now} (σ ↓ˢ k) k) {n} {(⟦Δ⟧ , ⟦A⟧) , ⟦◇B⟧}
| ⟦↑⟧ (A now) (σ ↓ˢ k) {n} {⟦Δ⟧ , ⟦A⟧} = refl
⟦subst⟧-handle {A = A} {B} σ {n = n} {⟦Δ⟧ , inj₁ (inj₂ (⟦B⟧ , ⟦◇A⟧))}
rewrite ⟦↑⟧ (B now) (_↑_ {Event A now} (σ ↓ˢ k) k) {n} {(⟦Δ⟧ , ⟦B⟧) , ⟦◇A⟧}
| ⟦↑⟧ (Event A now) (σ ↓ˢ k) {n} {⟦Δ⟧ , ⟦B⟧} = refl
⟦subst⟧-handle {A = A} {B} σ {n = n} {⟦Δ⟧ , inj₂ (⟦A⟧ , ⟦B⟧)}
rewrite ⟦↑⟧ (B now) (_↑_ {A now} (σ ↓ˢ k) k) {n} {(⟦Δ⟧ , ⟦A⟧) , ⟦B⟧}
| ⟦↑⟧ (A now) (σ ↓ˢ k) {n} {⟦Δ⟧ , ⟦A⟧} = refl
| {
"alphanum_fraction": 0.4286837553,
"avg_line_length": 41.2922077922,
"ext": "agda",
"hexsha": "67eecdc1d67a055edbd9eb2d0504ef74dae4ba4f",
"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/Semantics/Substitution/Kits.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/Semantics/Substitution/Kits.agda",
"max_line_length": 93,
"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/Semantics/Substitution/Kits.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": 3408,
"size": 6359
} |
------------------------------------------------------------------------
-- Some alternative definitions of the concept of being an equivalence
------------------------------------------------------------------------
-- Partly based on the blog post "Universal properties without
-- function extensionality" by Mike Shulman
-- (https://homotopytypetheory.org/2014/11/02/universal-properties-without-function-extensionality/),
-- and the corresponding code in the Coq HoTT library
-- (https://github.com/HoTT/HoTT).
{-# OPTIONS --without-K --safe #-}
open import Equality
module Equivalence.Path-split
{e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection eq as B using (_↔_)
open import Embedding eq using (Embedding)
open import Equality.Decision-procedures eq
open import Equivalence eq as Eq using (_≃_; Is-equivalence)
open import Equivalence.Erased.Basics eq using (Is-equivalenceᴱ)
open import Function-universe eq as F hiding (id; _∘_)
open import H-level eq as H-level
open import H-level.Closure eq
open import Surjection eq using (Split-surjective; _↠_)
private
variable
a b c d p : Level
A B : Type a
x y : A
f : A → B
k : Kind
n : ℕ
------------------------------------------------------------------------
-- Path-split
-- An alternative definition of "Is-equivalence".
Path-split : {A : Type a} {B : Type b} → ℕ → (A → B) → Type (a ⊔ b)
Path-split zero f = ↑ _ ⊤
Path-split (suc n) f =
Split-surjective f ×
(∀ x y → Path-split n (cong {x = x} {y = y} f))
private
-- A lemma.
eq→emb : Is-equivalence f → Is-equivalence (cong {x = x} {y = y} f)
eq→emb eq =
Embedding.is-embedding (from-isomorphism Eq.⟨ _ , eq ⟩) _ _
-- Equivalences are path-split.
Is-equivalence→Path-split : Is-equivalence f → Path-split n f
Is-equivalence→Path-split {n = zero} eq = _
Is-equivalence→Path-split {n = suc n} eq =
_≃_.split-surjective Eq.⟨ _ , eq ⟩
, λ x y → Is-equivalence→Path-split (eq→emb eq)
private
-- Path-split n f holds, for n ≥ 2, iff f is an equivalence.
Path-split⇔Is-equivalence :
Path-split (2 + n) f ⇔ Is-equivalence f
Path-split⇔Is-equivalence {f = f} = record
{ to = λ (s , p) →
let inv = proj₁ ∘ s
is-inv = proj₂ ∘ s
in _≃_.is-equivalence $ Eq.↔⇒≃ (record
{ surjection = record
{ right-inverse-of = is-inv
}
; left-inverse-of = λ x → $⟨ is-inv (f x) ⟩
f (inv (f x)) ≡ f x ↝⟨ proj₁ ∘ proj₁ (p _ _) ⟩
inv (f x) ≡ x □
})
; from = Is-equivalence→Path-split
}
-- If f is an equivalence, then Split-surjective f is contractible
-- (assuming extensionality).
Split-surjective-contractible-for-equivalences :
∀ {a b} {A : Type a} {B : Type b} {f : A → B} →
Extensionality b (a ⊔ b) →
Is-equivalence f →
Contractible (Split-surjective f)
Split-surjective-contractible-for-equivalences
{A = A} {B = B} {f = f} ext eq =
propositional⇒inhabited⇒contractible
(Π-closure ext 1 λ y →
let surj : (∃ λ x → x ≡ _≃_.from A≃B y) ↠ (∃ λ x → f x ≡ y)
surj = ∃-cong λ x →
x ≡ _≃_.from A≃B y ↔⟨ inverse $ Eq.≃-≡ A≃B ⟩
f x ≡ f (_≃_.from A≃B y) ↝⟨ ≡⇒↝ _ $ cong (_ ≡_) $ _≃_.right-inverse-of A≃B _ ⟩□
f x ≡ y □
in
H-level.respects-surjection surj 1 $
mono₁ 0 $
singleton-contractible _)
(_≃_.split-surjective A≃B)
where
A≃B : A ≃ B
A≃B = Eq.⟨ _ , eq ⟩
-- If f is an equivalence, then Path-split n f is contractible
-- (assuming extensionality).
Path-split-contractible-for-equivalences :
{A : Type a} {B : Type b} {f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-equivalence f →
Contractible (Path-split n f)
Path-split-contractible-for-equivalences {n = zero} _ _ =
↑-closure 0 $
⊤-contractible
Path-split-contractible-for-equivalences
{a = a} {b = b} {n = suc n} {A = A} {B = B} {f = f} ext eq =
×-closure 0
(Split-surjective-contractible-for-equivalences
(lower-extensionality a lzero ext) eq)
(Π-closure (lower-extensionality b lzero ext) 0 λ _ →
Π-closure (lower-extensionality b lzero ext) 0 λ _ →
Path-split-contractible-for-equivalences
ext (eq→emb eq))
-- Path-split n is pointwise propositional for n ≥ 2 (assuming
-- extensionality).
Path-split-propositional :
{A : Type a} {B : Type b} {f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-proposition (Path-split (2 + n) f)
Path-split-propositional ext =
[inhabited⇒contractible]⇒propositional λ p →
Path-split-contractible-for-equivalences ext $
_⇔_.to Path-split⇔Is-equivalence p
-- There is a bijection between Path-split n f, for n ≥ 2, and
-- Is-equivalence f (assuming extensionality).
Path-split↔Is-equivalence :
{A : Type a} {B : Type b} {f : A → B} →
Path-split (2 + n) f ↝[ a ⊔ b ∣ a ⊔ b ] Is-equivalence f
Path-split↔Is-equivalence =
generalise-ext?-prop
Path-split⇔Is-equivalence
Path-split-propositional
(λ ext → Eq.propositional ext _)
-- Another alternative definition of "Is-equivalence".
Path-split-∞ : {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b)
Path-split-∞ f = ∀ n → Path-split n f
-- Path-split-∞ is pointwise propositional (assuming extensionality).
Path-split-∞-propositional :
{A : Type a} {B : Type b} {f : A → B} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-proposition (Path-split-∞ f)
Path-split-∞-propositional ext =
[inhabited⇒contractible]⇒propositional λ p →
Π-closure (lower-extensionality _ lzero ext) 0 λ _ →
Path-split-contractible-for-equivalences ext $
_⇔_.to Path-split⇔Is-equivalence (p 2)
-- There is a bijection between Path-split-∞ f and Is-equivalence f
-- (assuming extensionality).
Path-split-∞↔Is-equivalence :
{A : Type a} {B : Type b} {f : A → B} →
Path-split-∞ f ↝[ a ⊔ b ∣ a ⊔ b ] Is-equivalence f
Path-split-∞↔Is-equivalence =
generalise-ext?-prop
(record
{ to = λ p → _⇔_.to Path-split⇔Is-equivalence (p 2)
; from = λ eq _ → Is-equivalence→Path-split eq
})
Path-split-∞-propositional
(λ ext → Eq.propositional ext _)
-- A preservation lemma for Path-split.
Path-split-cong :
{A : Type a} {B : Type b} {C : Type c} {D : Type d}
{f : A → B} {g : C → D} →
Extensionality? k (a ⊔ b ⊔ c ⊔ d) (a ⊔ b ⊔ c ⊔ d) →
(A≃C : A ≃ C) (B≃D : B ≃ D) →
(∀ x → g (_≃_.to A≃C x) ≡ _≃_.to B≃D (f x)) →
∀ n → Path-split n f ↝[ k ] Path-split n g
Path-split-cong
{a = a} {b = b} {c = c} {d = d} {k = k} {f = f} {g = g}
ext A≃C B≃D hyp = λ where
zero →
↑ _ ⊤ ↔⟨ B.↑↔ ⟩
⊤ ↔⟨ inverse B.↑↔ ⟩□
↑ _ ⊤ □
(suc n) →
(Split-surjective f ↔⟨⟩
(∀ y → ∃ λ x → f x ≡ y) ↝⟨ (Π-cong (lower-extensionality? k (a ⊔ c) lzero ext) B≃D λ y →
Σ-cong A≃C λ x →
(f x ≡ y) ↔⟨ inverse $ Eq.≃-≡ B≃D ⟩
(_≃_.to B≃D (f x) ≡ _≃_.to B≃D y) ↝⟨ ≡⇒↝ _ $ cong (_≡ _) $ sym $ hyp x ⟩□
(g (_≃_.to A≃C x) ≡ _≃_.to B≃D y) □) ⟩
(∀ y → ∃ λ x → g x ≡ y) ↔⟨⟩
Split-surjective g □)
×-cong
(Π-cong (lower-extensionality? k (b ⊔ d) lzero ext) A≃C λ x →
Π-cong (lower-extensionality? k (b ⊔ d) lzero ext) A≃C λ y →
Path-split-cong ext
(x ≡ y ↝⟨ inverse $ Eq.≃-≡ A≃C ⟩□
_≃_.to A≃C x ≡ _≃_.to A≃C y □)
(f x ≡ f y ↝⟨ inverse $ Eq.≃-≡ B≃D ⟩
_≃_.to B≃D (f x) ≡ _≃_.to B≃D (f y) ↝⟨ ≡⇒↝ _ $ cong₂ _≡_ (sym $ hyp x) (sym $ hyp y) ⟩□
g (_≃_.to A≃C x) ≡ g (_≃_.to A≃C y) □)
(λ x≡y →
cong g (cong (_≃_.to A≃C) x≡y) ≡⟨ cong-∘ _ _ _ ⟩
cong (g ∘ _≃_.to A≃C) x≡y ≡⟨ elim¹
(λ {y} x≡y →
cong (g ∘ _≃_.to A≃C) x≡y ≡
trans (trans (hyp x) (cong (_≃_.to B≃D ∘ f) x≡y))
(sym $ hyp y))
(
cong (g ∘ _≃_.to A≃C) (refl _) ≡⟨ cong-refl _ ⟩
refl _ ≡⟨ sym $ trans-symʳ _ ⟩
trans (hyp x) (sym $ hyp x) ≡⟨ cong (flip trans _) $
trans (sym $ trans-reflʳ _) $
cong (trans _) $ sym $ cong-refl _ ⟩∎
trans (trans (hyp x) (cong (_≃_.to B≃D ∘ f) (refl _)))
(sym $ hyp x) ∎)
_ ⟩
trans (trans (hyp x) (cong (_≃_.to B≃D ∘ f) x≡y))
(sym $ hyp y) ≡⟨ trans (cong (flip trans _) $ sym $
subst-trans _) $
trans-subst ⟩
subst (_ ≡_) (sym $ hyp y)
(subst (_≡ _) (sym $ hyp x)
(cong (_≃_.to B≃D ∘ f) x≡y)) ≡⟨ trans (cong (subst _ _) $
subst-in-terms-of-≡⇒↝ equivalence _ _ _) $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
_≃_.to (≡⇒↝ _ (cong (_ ≡_) (sym $ hyp y)))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) (sym $ hyp x)))
(cong (_≃_.to B≃D ∘ f) x≡y)) ≡⟨ cong (_$ cong (_≃_.to B≃D ∘ f) x≡y) $ sym $
≡⇒↝-trans equivalence ⟩
_≃_.to
(≡⇒↝ _ $
trans (cong (_≡ _) (sym $ hyp x))
(cong (_ ≡_) (sym $ hyp y)))
(cong (_≃_.to B≃D ∘ f) x≡y) ≡⟨⟩
_≃_.to (≡⇒↝ _ $ cong₂ _≡_ (sym $ hyp x) (sym $ hyp y))
(cong (_≃_.to B≃D ∘ f) x≡y) ≡⟨ cong (_≃_.to (≡⇒↝ _ _)) $ sym $
cong-∘ _ _ _ ⟩∎
_≃_.to (≡⇒↝ _ $ cong₂ _≡_ (sym $ hyp x) (sym $ hyp y))
(cong (_≃_.to B≃D) (cong f x≡y)) ∎)
n)
------------------------------------------------------------------------
-- Extendable along
-- Is-[ n ]-extendable-along-[ f ] P means that P is n-extendable
-- along f.
Is-[_]-extendable-along-[_] :
{A : Type a} {B : Type b} →
ℕ → (A → B) → (B → Type c) → Type (a ⊔ b ⊔ c)
Is-[ zero ]-extendable-along-[ f ] P = ↑ _ ⊤
Is-[ suc n ]-extendable-along-[ f ] P =
((g : ∀ x → P (f x)) →
∃ λ (h : ∀ x → P x) → ∀ x → h (f x) ≡ g x) ×
((g h : ∀ x → P x) →
Is-[ n ]-extendable-along-[ f ] (λ x → g x ≡ h x))
-- Is-∞-extendable-along-[ f ] P means that P is ∞-extendable along f.
Is-∞-extendable-along-[_] :
{A : Type a} {B : Type b} →
(A → B) → (B → Type c) → Type (a ⊔ b ⊔ c)
Is-∞-extendable-along-[ f ] P =
∀ n → Is-[ n ]-extendable-along-[ f ] P
-- In the presence of extensionality Is-[_]-extendable-along-[_] can
-- be expressed using Path-split.
Is-extendable-along≃Path-split :
{A : Type a} {B : Type b} {P : B → Type p} {f : A → B} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
∀ n →
Is-[ n ]-extendable-along-[ f ] P ≃
Path-split n (λ (g : ∀ x → P x) → g ∘ f)
Is-extendable-along≃Path-split {a = a} {b = b} {p = p} {f = f} ext =
λ where
zero → Eq.id
(suc n) →
(∀-cong (lower-extensionality b lzero ext) λ g →
∃-cong λ h →
(∀ x → h (f x) ≡ g x) ↝⟨ Eq.extensionality-isomorphism
(lower-extensionality (b ⊔ p) (a ⊔ b) ext) ⟩□
h ∘ f ≡ g □)
×-cong
(∀-cong (lower-extensionality a lzero ext) λ g →
∀-cong (lower-extensionality a lzero ext) λ h →
Is-[ n ]-extendable-along-[ f ] (λ x → g x ≡ h x) ↝⟨ Is-extendable-along≃Path-split ext n ⟩
Path-split n (_∘ f) ↝⟨ Path-split-cong ext
(Eq.extensionality-isomorphism ext₁)
(Eq.extensionality-isomorphism ext₂)
(λ eq →
cong (_∘ f) (apply-ext (Eq.good-ext ext₁) eq) ≡⟨ Eq.cong-pre-∘-good-ext ext₂ ext₁ _ ⟩∎
apply-ext (Eq.good-ext ext₂) (eq ∘ f) ∎)
n ⟩□
Path-split n (cong (_∘ f)) □)
where
ext₁ = lower-extensionality (a ⊔ p) (a ⊔ b) ext
ext₂ = lower-extensionality (b ⊔ p) (a ⊔ b) ext
-- In the presence of extensionality Is-∞-extendable-along-[_] can
-- be expressed using Path-split-∞.
Is-∞-extendable-along≃Path-split-∞ :
{A : Type a} {B : Type b} {P : B → Type p} {f : A → B} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
Is-∞-extendable-along-[ f ] P ≃
Path-split-∞ (λ (g : ∀ x → P x) → g ∘ f)
Is-∞-extendable-along≃Path-split-∞ ext =
∀-cong (lower-extensionality _ lzero ext) $
Is-extendable-along≃Path-split ext
-- Is-[ 2 + n ]-extendable-along-[ f ] P is propositional (assuming
-- extensionality).
Is-extendable-along-propositional :
{A : Type a} {B : Type b} {P : B → Type p} {f : A → B} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
Is-proposition (Is-[ 2 + n ]-extendable-along-[ f ] P)
Is-extendable-along-propositional ext =
H-level-cong _ 1 (inverse $ Is-extendable-along≃Path-split ext _) $
Path-split-propositional ext
-- Is-∞-extendable-along-[ f ] P is propositional (assuming
-- extensionality).
Is-∞-extendable-along-propositional :
{A : Type a} {B : Type b} {P : B → Type p} {f : A → B} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
Is-proposition (Is-∞-extendable-along-[ f ] P)
Is-∞-extendable-along-propositional ext =
H-level-cong _ 1 (inverse $ Is-∞-extendable-along≃Path-split-∞ ext) $
Path-split-∞-propositional ext
-- In the presence of extensionality Is-∞-extendable-along-[_] can be
-- expressed using Is-equivalence.
Is-∞-extendable-along≃Is-equivalence :
{A : Type a} {B : Type b} {P : B → Type p} {f : A → B} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
Is-∞-extendable-along-[ f ] P ≃
Is-equivalence (λ (g : ∀ x → P x) → g ∘ f)
Is-∞-extendable-along≃Is-equivalence {P = P} {f = f} ext =
Is-∞-extendable-along-[ f ] P ↝⟨ Is-∞-extendable-along≃Path-split-∞ ext ⟩
Path-split-∞ (_∘ f) ↝⟨ Path-split-∞↔Is-equivalence ext ⟩□
Is-equivalence (_∘ f) □
-- The definitions below are not taken directly from "Universal
-- properties without function extensionality".
-- A type B is P-null for a predicate P of type A → Type p if the
-- function const of type B → P x → B is an equivalence for each x.
--
-- This definition is based on one from "Modalities in Homotopy Type
-- Theory" by Rijke, Shulman and Spitters.
_-Null_ : {A : Type a} → (A → Type p) → Type b → Type (a ⊔ b ⊔ p)
P -Null B = ∀ x → Is-equivalence (const ⦂ (B → P x → B))
-- A variant of _-Null_ with erased proofs.
_-Nullᴱ_ : {A : Type a} → (A → Type p) → Type b → Type (a ⊔ b ⊔ p)
P -Nullᴱ B = ∀ x → Is-equivalenceᴱ (const ⦂ (B → P x → B))
-- Is-∞-extendable-along-[_] can sometimes be replaced by
-- Is-equivalence const.
Is-∞-extendable-along≃Is-equivalence-const :
{A : Type a} {B : Type b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Is-∞-extendable-along-[ (λ (_ : A) → lift tt) ] (λ (_ : ↑ a ⊤) → B) ≃
Is-equivalence (const ⦂ (B → A → B))
Is-∞-extendable-along≃Is-equivalence-const {a = a} {A = A} {B = B} ext =
Is-∞-extendable-along-[ (λ _ → lift tt) ] (λ (_ : ↑ a ⊤) → B) ↝⟨ Is-∞-extendable-along≃Is-equivalence ext ⟩
Is-equivalence (_∘ (λ _ → lift tt) ⦂ ((↑ a ⊤ → B) → (A → B))) ↝⟨ inverse $
Is-equivalence≃Is-equivalence-∘ʳ
(_≃_.is-equivalence $ Eq.↔→≃ (_$ lift tt) const refl refl) ext ⟩□
Is-equivalence (const ⦂ (B → A → B)) □
-- A corollary of Is-∞-extendable-along≃Is-equivalence-const.
Π-Is-∞-extendable-along≃Null :
{A : Type a} {P : A → Type p} {B : Type b} →
Extensionality (a ⊔ b ⊔ p) (b ⊔ p) →
(∀ x → Is-∞-extendable-along-[ (λ (_ : P x) → lift tt) ]
(λ (_ : ↑ p ⊤) → B)) ≃
P -Null B
Π-Is-∞-extendable-along≃Null {a = a} {p = p} {b = b} ext =
∀-cong (lower-extensionality (b ⊔ p) lzero ext) λ _ →
Is-∞-extendable-along≃Is-equivalence-const
(lower-extensionality a lzero ext)
private
-- If const is an equivalence from Bool to B → Bool, then B is not
-- not inhabited (assuming extensionality).
Is-equivalence-const→¬¬ :
{B : Type b} →
Extensionality b lzero →
Is-equivalence (const ⦂ (Bool → B → Bool)) →
¬ ¬ B
Is-equivalence-const→¬¬ {B = B} ext =
curry
(Is-equivalence (const ⦂ (Bool → B → Bool)) × ¬ B →⟨ Σ-map Eq.⟨ _ ,_⟩ (Eq.↔⇒≃ ∘ inverse ∘ B.⊥↔uninhabited) ⟩
Bool ≃ (B → Bool) × B ≃ ⊥ →⟨ (λ (≃B→ , B≃) → →-cong ext B≃ F.id F.∘ ≃B→) ⟩
Bool ≃ (⊥ → Bool) →⟨ Π⊥↔⊤ ext F.∘_ ⟩
Bool ≃ ⊤ →⟨ (λ eq → _≃_.to (Eq.≃-≡ eq) (refl _)) ⟩
true ≡ false →⟨ Bool.true≢false ⟩□
⊥ □)
-- If const is an equivalence from Bool to B → Bool, and equality is
-- decidable for B, then B is a proposition.
Is-equivalence-const→Decidable-equality→Is-proposition :
Is-equivalence (const ⦂ (Bool → B → Bool)) →
Decidable-equality B →
Is-proposition B
Is-equivalence-const→Decidable-equality→Is-proposition
{B = B} eq _≟_ x y = x≡y
where
lemma :
(f g : B → Bool) → f ≢ g →
(h : B → Bool) → f ≡ h ⊎ g ≡ h
lemma = $⟨ helper ⟩
((x y : Bool) → x ≢ y → (z : Bool) → x ≡ z ⊎ y ≡ z) →⟨ (Π-cong _ equiv λ x → Π-cong _ equiv λ y →
→-cong-→ (→-cong-→ (_≃_.from (Eq.≃-≡ equiv)) id) $
Π-cong _ equiv λ z →
_≃_.from (Eq.≃-≡ equiv ⊎-cong Eq.≃-≡ equiv)) ⟩□
((f g : B → Bool) → f ≢ g → (h : B → Bool) → f ≡ h ⊎ g ≡ h) □
where
equiv : Bool ≃ (B → Bool)
equiv = Eq.⟨ _ , eq ⟩
true≡⊎false≡ : (b : Bool) → true ≡ b ⊎ false ≡ b
true≡⊎false≡ true = inj₁ (refl _)
true≡⊎false≡ false = inj₂ (refl _)
helper : (x y : Bool) → x ≢ y → (z : Bool) → x ≡ z ⊎ y ≡ z
helper true true t≢t = ⊥-elim $ t≢t (refl _)
helper true false _ = true≡⊎false≡
helper false true _ = _↔_.to ⊎-comm ∘ true≡⊎false≡
helper false false f≢f = ⊥-elim $ f≢f (refl _)
f₁ f₂ f₃ : B → Bool
f₁ _ = true
f₂ _ = false
f₃ z = if x ≟ z then true else false
f₁≢f₂ : f₁ ≢ f₂
f₁≢f₂ f₁≡f₂ = Bool.true≢false $ cong (_$ x) f₁≡f₂
f₁≡f₃→x≡y : f₁ ≡ f₃ → x ≡ y
f₁≡f₃→x≡y f₁≡f₃ = helper (x ≟ y) (cong (_$ y) f₁≡f₃)
where
helper :
(d : Dec (x ≡ y)) →
true ≡ if d then true else false →
x ≡ y
helper (yes x≡y) _ = x≡y
helper (no _) true≡false =
⊥-elim $ Bool.true≢false true≡false
f₂≢f₃ : f₂ ≢ f₃
f₂≢f₃ =
f₂ ≡ f₃ →⟨ cong (_$ x) ⟩
false ≡ if x ≟ x then true else false →⟨ flip trans (helper (x ≟ x)) ⟩
false ≡ true →⟨ Bool.true≢false ∘ sym ⟩□
⊥ □
where
helper :
(d : Dec (x ≡ x)) →
if d then true else false ≡ true
helper (yes _) = refl _
helper (no x≢x) = ⊥-elim $ x≢x $ refl _
f₁≡⊎f₂≡ : (f : B → Bool) → f₁ ≡ f ⊎ f₂ ≡ f
f₁≡⊎f₂≡ = lemma f₁ f₂ f₁≢f₂
x≡y : x ≡ y
x≡y with f₁≡⊎f₂≡ f₃
… | inj₁ f₁≡f₃ = f₁≡f₃→x≡y f₁≡f₃
… | inj₂ f₂≡f₃ = ⊥-elim $ f₂≢f₃ f₂≡f₃
-- If f is an equivalence, then n-extendability along f is
-- contractible (assuming extensionality).
Is-extendable-along-contractible-for-equivalences :
{A : Type a} {B : Type b} {f : A → B} {P : B → Type p} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
Is-equivalence f →
∀ n → Contractible (Is-[ n ]-extendable-along-[ f ] P)
Is-extendable-along-contractible-for-equivalences _ _ zero =
↑-closure 0 ⊤-contractible
Is-extendable-along-contractible-for-equivalences
{a = a} {b = b} {p = p} {f = f} {P = P} ext eq (suc n) =
×-closure 0
(Π-closure (lower-extensionality b lzero ext) 0 λ g →
$⟨ singleton-contractible _ ⟩
Contractible (∃ λ h → h ≡ subst P (inv _) ∘ g ∘ f⁻¹) ↝⟨ H-level-cong _ 0 (lemma g) ⦂ (_ → _) ⟩□
Contractible (∃ λ h → ∀ x → h (f x) ≡ g x) □)
(Π-closure (lower-extensionality a lzero ext) 0 λ _ →
Π-closure (lower-extensionality a lzero ext) 0 λ _ →
Is-extendable-along-contractible-for-equivalences ext eq n)
where
f⁻¹ = _≃_.from Eq.⟨ _ , eq ⟩
inv = _≃_.left-inverse-of (inverse Eq.⟨ _ , eq ⟩)
lemma : ∀ _ → _ ≃ _
lemma g =
(∃ λ h → h ≡ subst P (inv _) ∘ g ∘ f⁻¹) ↔⟨ (∃-cong λ h → inverse $
∘from≡↔≡∘to′ (lower-extensionality p (a ⊔ b) ext) (inverse Eq.⟨ _ , eq ⟩)) ⟩
(∃ λ h → h ∘ f ≡ g) ↝⟨ (∃-cong λ _ → inverse $
Eq.extensionality-isomorphism (lower-extensionality (b ⊔ p) (a ⊔ b) ext)) ⟩□
(∃ λ h → ∀ x → h (f x) ≡ g x) □
-- If f is an equivalence, then ∞-extendability along f is
-- contractible (assuming extensionality).
Is-∞-extendable-along-contractible-for-equivalences :
{A : Type a} {B : Type b} {f : A → B} {P : B → Type p} →
Extensionality (a ⊔ b ⊔ p) (a ⊔ b ⊔ p) →
Is-equivalence f →
Contractible (Is-∞-extendable-along-[ f ] P)
Is-∞-extendable-along-contractible-for-equivalences ext eq =
Π-closure (lower-extensionality _ lzero ext) 0 λ n →
Is-extendable-along-contractible-for-equivalences ext eq n
------------------------------------------------------------------------
-- Alternatives to Is-[_]-extendable-along-[_] and
-- Is-∞-extendable-along-[_]
-- A variant of Is-[_]-extendable-along-[_].
Is-[_]-extendable-along-const-tt-[_] :
ℕ → Type a → Type b → Type (a ⊔ b)
Is-[ zero ]-extendable-along-const-tt-[ A ] B = ↑ _ ⊤
Is-[ suc n ]-extendable-along-const-tt-[ A ] B =
((g : A → B) → ∃ λ (x : B) → ∀ y → x ≡ g y) ×
((x y : B) → Is-[ n ]-extendable-along-const-tt-[ A ] (x ≡ y))
-- A variant of Is-∞-extendable-along-[_].
Is-∞-extendable-along-const-tt-[_] :
Type a → Type b → Type (a ⊔ b)
Is-∞-extendable-along-const-tt-[ A ] B =
∀ n → Is-[ n ]-extendable-along-const-tt-[ A ] B
-- In some cases Is-[_]-extendable-along-[_] and
-- Is-∞-extendable-along-[_] can be replaced by the variants.
≃Is-extendable-along-const-tt :
{A : Type a} {B : Type b} →
Extensionality? k (a ⊔ b) (a ⊔ b) →
∀ n →
Is-[ n ]-extendable-along-[ (λ (_ : A) → lift tt) ]
(λ (_ : ↑ a ⊤) → B) ↝[ k ]
Is-[ n ]-extendable-along-const-tt-[ A ] B
≃Is-extendable-along-const-tt _ zero = F.id
≃Is-extendable-along-const-tt {a = a} {k = k} ext (suc n) =
(∀-cong ext λ _ →
Σ-cong (Eq.↔→≃ (_$ lift tt) const refl refl) λ _ →
F.id)
×-cong
Π-cong ext′ (Eq.↔→≃ (_$ lift tt) const refl refl) λ _ →
Π-cong ext′ (Eq.↔→≃ (_$ lift tt) const refl refl) λ _ →
≃Is-extendable-along-const-tt ext n
where
ext′ = lower-extensionality? k a lzero ext
≃Is-∞-extendable-along-const-tt :
{A : Type a} {B : Type b} →
Extensionality? k (a ⊔ b) (a ⊔ b) →
Is-∞-extendable-along-[ (λ (_ : A) → lift tt) ] (λ (_ : ↑ a ⊤) → B)
↝[ k ]
Is-∞-extendable-along-const-tt-[ A ] B
≃Is-∞-extendable-along-const-tt {k = k} ext =
∀-cong (lower-extensionality? k _ lzero ext) λ n →
≃Is-extendable-along-const-tt ext n
-- Preservation lemmas for Is-[_]-extendable-along-[_] and
-- Is-∞-extendable-along-[_].
Is-extendable-along-const-tt-cong :
{A : Type a} {B : Type b} {C : Type c} →
Extensionality? k (a ⊔ b ⊔ c) (a ⊔ b ⊔ c) →
(A≃B : A ≃ B)
(A→≃B→ : {C : Type c} → (A → C) ≃ (B → C)) →
({C : Type c} (f : A → C) (x : A) →
_≃_.to A→≃B→ f (_≃_.to A≃B x) ≡ f x) →
∀ n →
Is-[ n ]-extendable-along-const-tt-[ A ] C ↝[ k ]
Is-[ n ]-extendable-along-const-tt-[ B ] C
Is-extendable-along-const-tt-cong _ _ _ _ zero =
↑ _ ⊤ ↔⟨ B.↑↔ ⟩
⊤ ↔⟨ inverse B.↑↔ ⟩□
↑ _ ⊤ □
Is-extendable-along-const-tt-cong
{a = a} {b = b} {c = c} {k = k} ext A≃B A→≃B→ hyp (suc n) =
(Π-cong ext A→≃B→ λ g →
∃-cong λ x →
Π-cong (lower-extensionality? k c (a ⊔ b) ext) A≃B λ y →
x ≡ g y ↝⟨ ≡⇒↝ _ $ cong (_ ≡_) $ sym $ hyp g y ⟩□
x ≡ _≃_.to A→≃B→ g (_≃_.to A≃B y) □)
×-cong
(∀-cong (lower-extensionality? k (a ⊔ b) lzero ext) λ x →
∀-cong (lower-extensionality? k (a ⊔ b) lzero ext) λ y →
Is-extendable-along-const-tt-cong ext A≃B A→≃B→ hyp n)
Is-∞-extendable-along-const-tt-cong :
{A : Type a} {B : Type b} {C : Type c} →
Extensionality? k (a ⊔ b ⊔ c) (a ⊔ b ⊔ c) →
(A≃B : A ≃ B)
(A→≃B→ : {C : Type c} → (A → C) ≃ (B → C)) →
({C : Type c} (f : A → C) (x : A) →
_≃_.to A→≃B→ f (_≃_.to A≃B x) ≡ f x) →
Is-∞-extendable-along-const-tt-[ A ] C ↝[ k ]
Is-∞-extendable-along-const-tt-[ B ] C
Is-∞-extendable-along-const-tt-cong {k = k} ext A≃B A→≃B→ hyp =
∀-cong (lower-extensionality? k _ lzero ext) λ n →
Is-extendable-along-const-tt-cong ext A≃B A→≃B→ hyp n
| {
"alphanum_fraction": 0.479449465,
"avg_line_length": 39.4143070045,
"ext": "agda",
"hexsha": "066c62821371906dbe8851610c0af2eddfe23c29",
"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/Equivalence/Path-split.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/Equivalence/Path-split.agda",
"max_line_length": 135,
"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/Equivalence/Path-split.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": 9846,
"size": 26447
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Rational Literals
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Rational.Literals where
open import Agda.Builtin.FromNat
open import Agda.Builtin.FromNeg
open import Data.Unit
open import Data.Nat
open import Data.Nat.Coprimality
open import Data.Integer
open import Data.Rational hiding (-_)
fromℤ : ℤ → ℚ
fromℤ z = record
{ numerator = z
; denominator-1 = zero
; isCoprime = sym (1-coprimeTo ∣ z ∣)
}
number : Number ℚ
number = record
{ Constraint = λ _ → ⊤
; fromNat = λ n → fromℤ (+ n)
}
negative : Negative ℚ
negative = record
{ Constraint = λ _ → ⊤
; fromNeg = λ n → fromℤ (- (+ n))
}
| {
"alphanum_fraction": 0.5350553506,
"avg_line_length": 21.972972973,
"ext": "agda",
"hexsha": "7b4c73f6c76c104431c22b88e59a22563541ffbc",
"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/Rational/Literals.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/Rational/Literals.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/Data/Rational/Literals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 216,
"size": 813
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Functor.Algebra where
open import Level hiding (lift)
open import Categories.Category
open import Categories.Functor
record F-Algebra {o ℓ e} {C : Category o ℓ e} (F : Endofunctor C) : Set (o ⊔ ℓ) where
constructor _,_
open Category C
open Functor F
field
A : Obj
α : F₀ A ⇒ A
lift : ∀ {o ℓ e} {C : Category o ℓ e} {F : Endofunctor C} → F-Algebra F → F-Algebra F
lift {F = F} (A , α) = record { A = F₀ A; α = F₁ α }
where
open Functor F | {
"alphanum_fraction": 0.6467181467,
"avg_line_length": 25.9,
"ext": "agda",
"hexsha": "785fea12c09ce85e293c334f6a0bda14de688e70",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Functor/Algebra.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Functor/Algebra.agda",
"max_line_length": 85,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Functor/Algebra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 178,
"size": 518
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
{-
Note: this module is for cohomology theories,
so the commuting squares below do not
care about the proof of pointedness,
because any cohomology theory is independent
of the possibly different proofs of pointedness.
-}
module homotopy.PtdMapSequence where
infix 15 _⊙⊣|
infixr 10 _⊙→⟨_⟩_
data PtdMapSequence {i} : (X : Ptd i) (Y : Ptd i) → Type (lsucc i) where
_⊙⊣| : (X : Ptd i) → PtdMapSequence X X
_⊙→⟨_⟩_ : (X : Ptd i) {Y Z : Ptd i}
→ (X ⊙→ Y) → PtdMapSequence Y Z
→ PtdMapSequence X Z
{- maps between two pointed map sequences -}
infix 15 _⊙↓|
infixr 10 _⊙↓⟨_⟩_
data PtdMapSeqMap {i₀ i₁} : {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
(⊙seq₀ : PtdMapSequence X₀ Y₀) (⊙seq₁ : PtdMapSequence X₁ Y₁)
(⊙hX : X₀ ⊙→ X₁) (⊙fY : Y₀ ⊙→ Y₁) → Type (lsucc (lmax i₀ i₁)) where
_⊙↓| : {X₀ : Ptd i₀} {X₁ : Ptd i₁} (f : X₀ ⊙→ X₁) → PtdMapSeqMap (X₀ ⊙⊣|) (X₁ ⊙⊣|) f f
_⊙↓⟨_⟩_ : ∀ {X₀ Y₀ Z₀ : Ptd i₀} {X₁ Y₁ Z₁ : Ptd i₁}
→ {⊙f₀ : X₀ ⊙→ Y₀} {⊙seq₀ : PtdMapSequence Y₀ Z₀}
→ {⊙f₁ : X₁ ⊙→ Y₁} {⊙seq₁ : PtdMapSequence Y₁ Z₁}
→ (⊙hX : X₀ ⊙→ X₁) {⊙hY : Y₀ ⊙→ Y₁} {⊙hZ : Z₀ ⊙→ Z₁}
→ CommSquare (fst ⊙f₀) (fst ⊙f₁) (fst ⊙hX) (fst ⊙hY)
→ PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hY ⊙hZ
→ PtdMapSeqMap (X₀ ⊙→⟨ ⊙f₀ ⟩ ⊙seq₀) (X₁ ⊙→⟨ ⊙f₁ ⟩ ⊙seq₁) ⊙hX ⊙hZ
{- equivalences between two pointed map sequences -}
is-⊙seq-equiv : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
{⊙seq₀ : PtdMapSequence X₀ Y₀} {⊙seq₁ : PtdMapSequence X₁ Y₁}
{⊙hX : X₀ ⊙→ X₁} {⊙hY : Y₀ ⊙→ Y₁}
→ PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY
→ Type (lmax i₀ i₁)
is-⊙seq-equiv (⊙h ⊙↓|) = is-equiv (fst ⊙h)
is-⊙seq-equiv (⊙h ⊙↓⟨ _ ⟩ ⊙seq) = is-equiv (fst ⊙h) × is-⊙seq-equiv ⊙seq
PtdMapSeqEquiv : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
(⊙seq₀ : PtdMapSequence X₀ Y₀) (⊙seq₁ : PtdMapSequence X₁ Y₁)
(⊙hX : X₀ ⊙→ X₁) (⊙hY : Y₀ ⊙→ Y₁) → Type (lsucc (lmax i₀ i₁))
PtdMapSeqEquiv ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY
= Σ (PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY) is-⊙seq-equiv
{- Doesn't seem useful.
infix 15 _⊙↕⊣|
infixr 10 _⊙↕⟨_⟩↕_
_⊙↕⊣| : ∀ {i} {X₀ X₁ : Ptd i} (⊙eq : X₀ ⊙≃ X₁)
→ PtdMapSequenceEquiv (X₀ ⊙⊣|) (X₁ ⊙⊣|) (⊙–> ⊙eq) (⊙–> ⊙eq)
⊙eq ⊙↕⊣| = (⊙–> ⊙eq ⊙↓⊣|) , snd ⊙eq
_⊙↕⟨_⟩↕_ : ∀ {i} {X₀ X₁ : Ptd i} → (⊙eqX : X₀ ⊙≃ X₁)
→ ∀ {Y₀ Y₁ : Ptd i} {⊙f : X₀ ⊙→ Y₀} {⊙g : X₁ ⊙→ Y₁} {⊙eqY : Y₀ ⊙≃ Y₁}
→ ⊙CommutingSquare ⊙f ⊙g (⊙–> ⊙eqX) (⊙–> ⊙eqY)
→ ∀ {Z₀ Z₁ : Ptd i} {⊙eqZ : Z₀ ⊙≃ Z₁} {⊙seq₀ : PtdMapSequence Y₀ Z₀} {⊙seq₁ : PtdMapSequence Y₁ Z₁}
→ PtdMapSequenceEquiv ⊙seq₀ ⊙seq₁ (⊙–> ⊙eqY) (⊙–> ⊙eqZ)
→ PtdMapSequenceEquiv (X₀ ⊙⟨ ⊙f ⟩→ ⊙seq₀) (X₁ ⊙⟨ ⊙g ⟩→ ⊙seq₁) (⊙–> ⊙eqX) (⊙–> ⊙eqZ)
(⊙hX , hX-is-equiv) ⊙↕⟨ sqr ⟩↕ (⊙seq-map , ⊙seq-map-is-equiv) =
(⊙hX ⊙↓⟨ sqr ⟩↓ ⊙seq-map) , hX-is-equiv , ⊙seq-map-is-equiv
-}
private
is-⊙seq-equiv-head : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
{⊙seq₀ : PtdMapSequence X₀ Y₀} {⊙seq₁ : PtdMapSequence X₁ Y₁}
{⊙hX : X₀ ⊙→ X₁} {⊙hY : Y₀ ⊙→ Y₁}
{seq-map : PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY}
→ is-⊙seq-equiv seq-map → is-equiv (fst ⊙hX)
is-⊙seq-equiv-head {seq-map = ξ ⊙↓|} ise = ise
is-⊙seq-equiv-head {seq-map = ξ ⊙↓⟨ _ ⟩ _} ise = fst ise
private
ptd-map-seq-map-index-type : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
{⊙seq₀ : PtdMapSequence X₀ Y₀} {⊙seq₁ : PtdMapSequence X₁ Y₁}
{⊙hX : X₀ ⊙→ X₁} {⊙hY : Y₀ ⊙→ Y₁}
→ ℕ → PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY → Type (lmax i₀ i₁)
ptd-map-seq-map-index-type _ (_ ⊙↓|) = Lift ⊤
ptd-map-seq-map-index-type O (_⊙↓⟨_⟩_ {⊙f₀ = ⊙f₀} {⊙f₁ = ⊙f₁} ⊙hX {⊙hY} _ _)
= CommSquare (fst ⊙f₀) (fst ⊙f₁) (fst ⊙hX) (fst ⊙hY)
ptd-map-seq-map-index-type (S n) (_ ⊙↓⟨ _ ⟩ seq-map)
= ptd-map-seq-map-index-type n seq-map
abstract
ptd-map-seq-map-index : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
{⊙seq₀ : PtdMapSequence X₀ Y₀} {⊙seq₁ : PtdMapSequence X₁ Y₁}
{⊙hX : X₀ ⊙→ X₁} {⊙hY : Y₀ ⊙→ Y₁}
(n : ℕ) (seq-map : PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY)
→ ptd-map-seq-map-index-type n seq-map
ptd-map-seq-map-index _ (_ ⊙↓|) = lift tt
ptd-map-seq-map-index O (_ ⊙↓⟨ □ ⟩ _) = □
ptd-map-seq-map-index (S n) (_ ⊙↓⟨ _ ⟩ seq-map)
= ptd-map-seq-map-index n seq-map
private
ptd-map-seq-equiv-index-type : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
{⊙seq₀ : PtdMapSequence X₀ Y₀} {⊙seq₁ : PtdMapSequence X₁ Y₁}
{⊙hX : X₀ ⊙→ X₁} {⊙hY : Y₀ ⊙→ Y₁}
→ ℕ → PtdMapSeqMap ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY → Type (lmax i₀ i₁)
ptd-map-seq-equiv-index-type {⊙hX = ⊙hX} O _ = is-equiv (fst ⊙hX)
ptd-map-seq-equiv-index-type (S _) (_ ⊙↓|) = Lift ⊤
ptd-map-seq-equiv-index-type (S n) (_ ⊙↓⟨ _ ⟩ seq-map)
= ptd-map-seq-equiv-index-type n seq-map
abstract
ptd-map-seq-equiv-index : ∀ {i₀ i₁} {X₀ Y₀ : Ptd i₀} {X₁ Y₁ : Ptd i₁}
{⊙seq₀ : PtdMapSequence X₀ Y₀} {⊙seq₁ : PtdMapSequence X₁ Y₁}
{⊙hX : X₀ ⊙→ X₁} {⊙hY : Y₀ ⊙→ Y₁}
(n : ℕ) (seq-equiv : PtdMapSeqEquiv ⊙seq₀ ⊙seq₁ ⊙hX ⊙hY)
→ ptd-map-seq-equiv-index-type n (fst seq-equiv)
ptd-map-seq-equiv-index O (seq-map , ise) = is-⊙seq-equiv-head ise
ptd-map-seq-equiv-index (S _) ((_ ⊙↓|) , _) = lift tt
ptd-map-seq-equiv-index (S n) ((_ ⊙↓⟨ _ ⟩ seq-map) , ise)
= ptd-map-seq-equiv-index n (seq-map , snd ise)
| {
"alphanum_fraction": 0.5516911905,
"avg_line_length": 41.2047244094,
"ext": "agda",
"hexsha": "898b7e6b22d2e320fa69bb50b42309b1a10d2620",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/PtdMapSequence.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/PtdMapSequence.agda",
"max_line_length": 110,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/PtdMapSequence.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 2831,
"size": 5233
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using () renaming (Category to Setoid-Category)
open import Categories.Category.Monoidal
module Categories.Enriched.NaturalTransformation.NaturalIsomorphism
{o ℓ e} {V : Setoid-Category o ℓ e} (M : Monoidal V) where
open import Level
open import Categories.Category.Construction.EnrichedFunctors M
open import Categories.Enriched.Category M
open import Categories.Enriched.Functor M renaming (id to idF)
open import Categories.Enriched.NaturalTransformation M renaming (id to idNT)
open import Categories.Functor.Properties using ([_]-resp-Iso)
open import Categories.Morphism as Morphism using (Iso)
open import Categories.Category.Monoidal.Reasoning M
open import Relation.Binary using (IsEquivalence)
open Setoid-Category V renaming (Obj to ObjV; id to idV)
module M = Monoidal M
open M hiding (unitorˡ; unitorʳ; associator)
open NaturalTransformation
module NaturalIsomorphism = Morphism._≅_
open NaturalIsomorphism
-- A natural isomorphism |α : F ≅ G : C → D| is an isomorphism of F
-- and G in the functor category [C , D] between C and D.
module _ {c d} {C : Category c} {D : Category d} where
NaturalIsomorphism : (F G : Functor C D) → Set (ℓ ⊔ e ⊔ c)
NaturalIsomorphism F G = F ≅ G
where open Morphism (EnrichedFunctors C D) using (_≅_)
-- A commonly used shorthand for NaturalIsomorphism
infix 4 _≃_
_≃_ = NaturalIsomorphism
module _ {F G : Functor C D} where
private
module F = Functor F
module G = Functor G
open Morphism (Underlying D) using (_≅_)
-- Natural isomorphisms are pointwise isomorphisms: each component
-- |α [ X ]| is an isomorphism |F X ≅ G X|.
infixl 16 _ᵢ[_]
_ᵢ[_] : NaturalIsomorphism F G → ∀ X → F.₀ X ≅ G.₀ X
α ᵢ[ X ] = record
{ from = from α [ X ]
; to = to α [ X ]
; iso = record { isoˡ = isoˡ α ; isoʳ = isoʳ α }
}
≃-isEquivalence : IsEquivalence _≃_
≃-isEquivalence = Morphism.≅-isEquivalence (EnrichedFunctors C D)
module ≃ = IsEquivalence ≃-isEquivalence
id : {F : Functor C D} → F ≃ F
id = ≃.refl
_⁻¹ : {F G : Functor C D} → F ≃ G → G ≃ F
α ⁻¹ = ≃.sym α
infixr 9 _ⓘᵥ_
_ⓘᵥ_ : {F G H : Functor C D} → G ≃ H → F ≃ G → F ≃ H
α ⓘᵥ β = ≃.trans β α
private
module D = Underlying D
-- Left and right unitors
unitorˡ : {F : Functor C D} → idF ∘F F ≃ F
unitorˡ {F} = record
{ from = record
{ comp = λ _ → D.id
; commute = (refl⟩∘⟨ refl⟩⊗⟨ identityˡ ⟩∘⟨refl) ○ comm
}
; to = record
{ comp = λ _ → D.id
; commute = comm ○ (refl⟩∘⟨ ⟺ identityˡ ⟩⊗⟨refl ⟩∘⟨refl)
}
; iso = record { isoˡ = D.identity² ; isoʳ = D.identity² }
}
where comm = commute (idNT {F = F})
unitorʳ : {F : Functor C D} → F ∘F idF ≃ F
unitorʳ {F} = record
{ from = record
{ comp = λ _ → D.id
; commute = (refl⟩∘⟨ refl⟩⊗⟨ identityʳ ⟩∘⟨refl) ○ comm
}
; to = record
{ comp = λ _ → D.id
; commute = comm ○ (refl⟩∘⟨ ⟺ identityʳ ⟩⊗⟨refl ⟩∘⟨refl)
}
; iso = record { isoˡ = D.identity² ; isoʳ = D.identity² }
}
where comm = commute (idNT {F = F})
module _ {c d e} {C : Category c} {D : Category d} {E : Category e} where
open NaturalIsomorphism
-- Left- and right-hand composition with a functor
infixr 9 _ⓘₕ_ _ⓘˡ_ _ⓘʳ_
_ⓘˡ_ : {F G : Functor C D} (H : Functor D E) → F ≃ G → H ∘F F ≃ H ∘F G
H ⓘˡ α = record
{ from = H ∘ˡ from α
; to = H ∘ˡ to α
; iso = record { isoˡ = iso.isoˡ ; isoʳ = iso.isoʳ }
}
where
module iso {X} = Iso ([ UnderlyingFunctor H ]-resp-Iso (iso (α ᵢ[ X ])))
_ⓘʳ_ : {G H : Functor D E} → G ≃ H → (F : Functor C D) → G ∘F F ≃ H ∘F F
α ⓘʳ F = record
{ from = from α ∘ʳ F
; to = to α ∘ʳ F
; iso = record { isoˡ = isoˡ (α ᵢ[ F.₀ _ ]) ; isoʳ = isoʳ (α ᵢ[ F.₀ _ ]) }
}
where module F = Functor F
-- Horizontal composition
_ⓘₕ_ : {H I : Functor D E} {F G : Functor C D} →
H ≃ I → F ≃ G → (H ∘F F) ≃ (I ∘F G)
_ⓘₕ_ {_} {I} {F} {_} α β = (I ⓘˡ β) ⓘᵥ (α ⓘʳ F)
module _ {b c d e} {B : Category b} {C : Category c}
{D : Category d} {E : Category e} where
open NaturalIsomorphism
private
module E = Category E
module UE = Underlying E
-- Associator
associator : {F : Functor D E} {G : Functor C D} {H : Functor B C} →
(F ∘F G) ∘F H ≃ F ∘F (G ∘F H)
associator {F} {G} {H} = record
{ from = record
{ comp = λ _ → E.id
; commute = (refl⟩∘⟨ refl⟩⊗⟨ assoc ⟩∘⟨refl) ○ comm
}
; to = record
{ comp = λ _ → E.id
; commute = comm ○ (refl⟩∘⟨ ⟺ assoc ⟩⊗⟨refl ⟩∘⟨refl)
}
; iso = record { isoˡ = UE.identity² ; isoʳ = UE.identity² }
}
where comm = commute (idNT {F = F ∘F (G ∘F H)})
| {
"alphanum_fraction": 0.5784660154,
"avg_line_length": 29.5153374233,
"ext": "agda",
"hexsha": "5e9425f867b22f8a412d81ab88fb8bde7a3906af",
"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/Enriched/NaturalTransformation/NaturalIsomorphism.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/Enriched/NaturalTransformation/NaturalIsomorphism.agda",
"max_line_length": 79,
"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/Enriched/NaturalTransformation/NaturalIsomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1864,
"size": 4811
} |
open import Agda.Builtin.Equality
postulate
A : Set
a : A
b : A
mutual
Meta : A → A → A → A
Meta = ?
_ : Meta a ≡ Meta b
_ = refl
| {
"alphanum_fraction": 0.5442176871,
"avg_line_length": 10.5,
"ext": "agda",
"hexsha": "a90fa9fe8bab9823d95956594838142b053ed9d5",
"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/Issue3114.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/Issue3114.agda",
"max_line_length": 33,
"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/Issue3114.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": 60,
"size": 147
} |
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Structures.LeftAction where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.SIP
open import Cubical.Structures.Auto
module _ {ℓ ℓ' : Level} (A : Type ℓ') where
LeftActionStructure : Type ℓ → Type (ℓ-max ℓ ℓ')
LeftActionStructure X = A → X → X
LeftActionEquivStr = AutoEquivStr LeftActionStructure
leftActionUnivalentStr : UnivalentStr _ LeftActionEquivStr
leftActionUnivalentStr = autoUnivalentStr LeftActionStructure
| {
"alphanum_fraction": 0.7744916821,
"avg_line_length": 30.0555555556,
"ext": "agda",
"hexsha": "fadf1189e8f29819de781b8e26842cd3adc276de",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Structures/LeftAction.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Structures/LeftAction.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Structures/LeftAction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 154,
"size": 541
} |
{-# OPTIONS --cubical #-}
module Cubical.Categories.Functor where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Categories.Category
private
variable
ℓ𝒞 ℓ𝒞' ℓ𝒟 ℓ𝒟' : Level
record Functor (𝒞 : Precategory ℓ𝒞 ℓ𝒞') (𝒟 : Precategory ℓ𝒟 ℓ𝒟') : Type (ℓ-max (ℓ-max ℓ𝒞 ℓ𝒞') (ℓ-max ℓ𝒟 ℓ𝒟')) where
no-eta-equality
open Precategory
field
F-ob : 𝒞 .ob → 𝒟 .ob
F-hom : {x y : 𝒞 .ob} → 𝒞 .hom x y → 𝒟 .hom (F-ob x) (F-ob y)
F-idn : {x : 𝒞 .ob} → F-hom (𝒞 .idn x) ≡ 𝒟 .idn (F-ob x)
F-seq : {x y z : 𝒞 .ob} (f : 𝒞 .hom x y) (g : 𝒞 .hom y z) → F-hom (𝒞 .seq f g) ≡ 𝒟 .seq (F-hom f) (F-hom g)
is-full = (x y : _) (F[f] : 𝒟 .hom (F-ob x) (F-ob y)) → ∥ Σ (𝒞 .hom x y) (λ f → F-hom f ≡ F[f]) ∥
is-faithful = (x y : _) (f g : 𝒞 .hom x y) → F-hom f ≡ F-hom g → f ≡ g
| {
"alphanum_fraction": 0.567535545,
"avg_line_length": 33.76,
"ext": "agda",
"hexsha": "c05b44d115f67cd689a5799aa38ab0f19535b8d7",
"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": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/Categories/Functor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"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": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/Categories/Functor.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/Categories/Functor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 434,
"size": 844
} |
------------------------------------------------------------------------
-- A relational semantics which uses closures and environments
------------------------------------------------------------------------
module Lambda.Closure.Relational where
open import Codata.Musical.Notation
open import Data.Empty
open import Data.List hiding (lookup)
open import Data.Product
open import Data.Vec using (Vec; _∷_; []; lookup)
open import Function.Base
open import
Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import Lambda.Syntax using (Tm; con; var; ƛ; _·_)
open Lambda.Syntax.Closure Tm
open import Lambda.VirtualMachine as VM
open VM.Relational
open StarReasoning _⟶_
open InfiniteSequence
------------------------------------------------------------------------
-- Big-step semantics
-- For terminating computations.
infix 4 _⊢_⇓_
data _⊢_⇓_ {n} (ρ : Env n) : Tm n → Value → Set where
var : ∀ {x} → ρ ⊢ var x ⇓ lookup ρ x
con : ∀ {i} → ρ ⊢ con i ⇓ con i
ƛ : ∀ {t} → ρ ⊢ ƛ t ⇓ ƛ t ρ
app : ∀ {t₁ t₂ n t} {ρ′ : Env n} {v v′}
(t₁⇓ : ρ ⊢ t₁ ⇓ ƛ t ρ′)
(t₂⇓ : ρ ⊢ t₂ ⇓ v′)
(t₁t₂⇓ : v′ ∷ ρ′ ⊢ t ⇓ v) →
ρ ⊢ t₁ · t₂ ⇓ v
-- For non-terminating computations.
infix 4 _⊢_⇑
data _⊢_⇑ {n} (ρ : Env n) : Tm n → Set where
app : ∀ {t₁ t₂ n t} {ρ′ : Env n} {v′}
(t₁⇓ : ρ ⊢ t₁ ⇓ ƛ t ρ′)
(t₂⇓ : ρ ⊢ t₂ ⇓ v′)
(t₁t₂⇑ : ∞ (v′ ∷ ρ′ ⊢ t ⇑)) →
ρ ⊢ t₁ · t₂ ⇑
·ˡ : ∀ {t₁ t₂}
(t₁⇑ : ∞ (ρ ⊢ t₁ ⇑)) →
ρ ⊢ t₁ · t₂ ⇑
·ʳ : ∀ {t₁ t₂ v}
(t₁⇓ : ρ ⊢ t₁ ⇓ v)
(t₂⇑ : ∞ (ρ ⊢ t₂ ⇑)) →
ρ ⊢ t₁ · t₂ ⇑
-- For crashing computations.
infix 4 _⊢_↯
_⊢_↯ : ∀ {n} → Env n → Tm n → Set
ρ ⊢ t ↯ = ¬ (∃ λ v → ρ ⊢ t ⇓ v) × ¬ (ρ ⊢ t ⇑)
------------------------------------------------------------------------
-- The semantics is deterministic
deterministic⇓ : ∀ {n} {ρ : Env n} {t v₁ v₂} →
ρ ⊢ t ⇓ v₁ → ρ ⊢ t ⇓ v₂ → v₁ ≡ v₂
deterministic⇓ var var = P.refl
deterministic⇓ con con = P.refl
deterministic⇓ ƛ ƛ = P.refl
deterministic⇓ (app t₁⇓ t₂⇓ t₁t₂⇓) (app t₁⇓′ t₂⇓′ t₁t₂⇓′)
with deterministic⇓ t₁⇓ t₁⇓′ | deterministic⇓ t₂⇓ t₂⇓′
... | P.refl | P.refl = deterministic⇓ t₁t₂⇓ t₁t₂⇓′
deterministic⇓⇑ : ∀ {n} {ρ : Env n} {t v} →
ρ ⊢ t ⇓ v → ρ ⊢ t ⇑ → ⊥
deterministic⇓⇑ var ()
deterministic⇓⇑ con ()
deterministic⇓⇑ ƛ ()
deterministic⇓⇑ (app t₁⇓ t₂⇓ t₁t₂⇓) (app t₁⇓′ t₂⇓′ t₁t₂⇑)
with deterministic⇓ t₁⇓ t₁⇓′ | deterministic⇓ t₂⇓ t₂⇓′
... | P.refl | P.refl = deterministic⇓⇑ t₁t₂⇓ (♭ t₁t₂⇑)
deterministic⇓⇑ (app t₁⇓ t₂⇓ t₁t₂⇓) (·ˡ t₁⇑) =
deterministic⇓⇑ t₁⇓ (♭ t₁⇑)
deterministic⇓⇑ (app t₁⇓ t₂⇓ t₁t₂⇓) (·ʳ t₁⇓′ t₂⇑) =
deterministic⇓⇑ t₂⇓ (♭ t₂⇑)
------------------------------------------------------------------------
-- Compiler "correctness"
-- The proofs below establish that the compiler in
-- Lambda.VirtualMachine preserves the semantics above (_⊢_⇓_ and
-- _⊢_⇑, not necessarily _⊢_↯), given that the virtual machine is
-- deterministic.
correct⇓′ : ∀ {n ρ c s v} {t : Tm n} →
ρ ⊢ t ⇓ v →
⟨ comp t c , s , comp-env ρ ⟩ ⟶⋆
⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩
correct⇓′ {ρ = ρ} {c} {s} (var {x}) = begin
⟨ var x ∷ c , s , comp-env ρ ⟩ ⟶⟨ var ⟩
⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → ⟨ c , val v ∷ s , comp-env ρ ⟩)
(lookup-hom x ρ) ⟩
⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ∎
correct⇓′ {ρ = ρ} {c} {s} (con {i}) = begin
⟨ con i ∷ c , s , comp-env ρ ⟩ ⟶⟨ con ⟩
⟨ c , val (Lambda.Syntax.Closure.con i) ∷ s , comp-env ρ ⟩ ∎
correct⇓′ {ρ = ρ} {c} {s} (ƛ {t}) = begin
⟨ clo (comp t [ ret ]) ∷ c , s , comp-env ρ ⟩ ⟶⟨ clo ⟩
⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ∎
correct⇓′ {ρ = ρ} {c} {s} {v} (app {t₁} {t₂} {t = t} {ρ′} {v′ = v′} t₁⇓ t₂⇓ t₁t₂⇓) = begin
⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₁⇓ ⟩
⟨ comp t₂ (app ∷ c) , val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₂⇓ ⟩
⟨ app ∷ c , val (comp-val v′) ∷ val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⟨ app ⟩
⟨ comp t [ ret ] , ret c (comp-env ρ) ∷ s , comp-val v′ ∷ comp-env ρ′ ⟩ ⟶⋆⟨ correct⇓′ t₁t₂⇓ ⟩
⟨ [ ret ] , val (comp-val v) ∷ ret c (comp-env ρ) ∷ s , comp-val v′ ∷ comp-env ρ′ ⟩ ⟶⟨ ret ⟩
⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ∎
correct⇑′ : ∀ {n ρ c s} {t : Tm n} →
ρ ⊢ t ⇑ → ⟨ comp t c , s , comp-env ρ ⟩ ⟶∞′
correct⇑′ {ρ = ρ} {c} {s} (app {t₁} {t₂} {t = t} {ρ′} {v′} t₁⇓ t₂⇓ t₁t₂⇑) =
⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₁⇓ ⟩′
⟨ comp t₂ (app ∷ c) , val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₂⇓ ⟩′
⟨ app ∷ c , val (comp-val v′) ∷ val (comp-val (ƛ t ρ′)) ∷ s , comp-env ρ ⟩ ⟶⟨ app ⟩′ ♯
(⟨ comp t [ ret ] , ret c (comp-env ρ) ∷ s , comp-val v′ ∷ comp-env ρ′ ⟩ ⟶∞⟨ correct⇑′ (♭ t₁t₂⇑) ⟩)
correct⇑′ {ρ = ρ} {c} {s} (·ˡ {t₁} {t₂} t₁⇑) =
⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶∞⟨ correct⇑′ (♭ t₁⇑) ⟩
correct⇑′ {ρ = ρ} {c} {s} (·ʳ {t₁} {t₂} {v} t₁⇓ t₂⇑) =
⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ⟶⋆⟨ correct⇓′ t₁⇓ ⟩′
⟨ comp t₂ (app ∷ c) , val (comp-val v) ∷ s , comp-env ρ ⟩ ⟶∞⟨ correct⇑′ (♭ t₂⇑) ⟩
correct⇓ : ∀ {t v} →
[] ⊢ t ⇓ v →
∃ λ s → ⟨ comp t [] , [] , [] ⟩ ⟶⋆ s × s ⇓ comp-val v
correct⇓ t⇓ = (_ , correct⇓′ t⇓ , final)
correct⇑ : ∀ {t} → [] ⊢ t ⇑ → ⟨ comp t [] , [] , [] ⟩ ⟶∞
correct⇑ = InfiniteSequence.sound ∘ correct⇑′
| {
"alphanum_fraction": 0.4153334389,
"avg_line_length": 44.1468531469,
"ext": "agda",
"hexsha": "4563dc1c5145e7851a354ec1706b7dbe3a9d0271",
"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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/Closure/Relational.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"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/codata",
"max_issues_repo_path": "Lambda/Closure/Relational.agda",
"max_line_length": 138,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/Closure/Relational.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 2779,
"size": 6313
} |
module Prelude where
data _==_ {A : Set}(x : A) : A → Set where
refl : x == x
J : {A : Set} {x y : A} (P : (x y : A) → x == y -> Set) →
(∀ z → P z z refl) → (p : x == y) → P x y p
J P h refl = h _
| {
"alphanum_fraction": 0.4174757282,
"avg_line_length": 20.6,
"ext": "agda",
"hexsha": "ad29bea2628f2f232232bf5421ae0017bbb352e7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "src/prototyping/term/examples/Prelude.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": "src/prototyping/term/examples/Prelude.agda",
"max_line_length": 57,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "src/prototyping/term/examples/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 93,
"size": 206
} |
{-# OPTIONS --universe-polymorphism #-}
module CompareLevel where
open import Common.Level
postulate
X : Set
Foo : (a b : Level) → Set (a ⊔ b) → Set
Bar : Foo _ _ X -- solve _1 ⊔ _2 = 0
postulate
id : ∀ {a}{A : Set a} → A → A
apply : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) → A → B
a b : Level
Any : (ℓ : Level) → Set ℓ
any : ∀ {ℓ} → Any ℓ
-- Too aggressive level solving can cause a problem here.
foo : Any (a ⊔ b)
foo =
apply {_}{_} id any
| {
"alphanum_fraction": 0.539748954,
"avg_line_length": 21.7272727273,
"ext": "agda",
"hexsha": "aa77baee833461dff5df6101ed9db26271ad3972",
"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/CompareLevel.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/CompareLevel.agda",
"max_line_length": 61,
"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/CompareLevel.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": 187,
"size": 478
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Properties.Functors where
open import Categories.Category.Complete.Properties
using ( Functors-Complete
; evalF-Continuous)
public
open import Categories.Category.Cocomplete.Properties
using (Functors-Cocomplete)
public
| {
"alphanum_fraction": 0.7763578275,
"avg_line_length": 26.0833333333,
"ext": "agda",
"hexsha": "a81ad19bc64a9db13bd4207898475e5a61c5382a",
"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": "src/Categories/Category/Construction/Properties/Functors.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": "src/Categories/Category/Construction/Properties/Functors.agda",
"max_line_length": 65,
"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": "src/Categories/Category/Construction/Properties/Functors.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": 63,
"size": 313
} |
-- Andreas, 2012-01-10
-- {-# OPTIONS -v tc.constr.findInScope:50 #-}
module InstanceGuessesMeta2 where
open import Common.Level
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
record takeClass {a}
(F : Set a → Set a)
(G : Set a → ℕ → Set a) : Set (lsuc a) where
field
take : {A : Set a} → (n : ℕ) → F A → G A n
take : ∀ {a} {A : Set a} {F : Set a → Set a} {G : Set a → ℕ → Set a}
{{takeA : takeClass F G}} →
(n : ℕ) → F A → G A n
take {{takeA}} = takeClass.take takeA
postulate
List : ∀ {a} → Set a → Set a
BVec : ∀ {a} → Set a → ℕ → Set a
toList : ∀ {a}{A : Set a}{n : ℕ} → BVec A n → List A
-- universe polymorphic instance
takeInstanceList : {a : Level} → takeClass (List {a = a}) BVec
take0 : {A : Set} → List A → BVec A zero
take0 l = take zero l
take1 : {A : Set} → List A → List A
take1 l = toList (take (suc zero) l)
| {
"alphanum_fraction": 0.5545243619,
"avg_line_length": 25.3529411765,
"ext": "agda",
"hexsha": "0846feb16c7554f4fa650e8eca19a8aaf3777c3a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "test/succeed/InstanceGuessesMeta2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"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": "larrytheliquid/agda",
"max_issues_repo_path": "test/succeed/InstanceGuessesMeta2.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/InstanceGuessesMeta2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 340,
"size": 862
} |
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.Agsy.AddTotality where
open import Relation.Binary.PropositionalEquality
infixl 9 _+_
------------------------------------------------------------------------------
postulate
D : Set
zero : D
succ : D → D
data N : D → Set where
zN : N zero
sN : ∀ {n} → N n → N (succ n)
postulate
_+_ : D → D → D
+-0x : ∀ d → zero + d ≡ d
+-Sx : ∀ d e → succ d + e ≡ succ (d + e)
+-N : ∀ {m n} → N m → N n → N (m + n)
+-N {m} {n} Nm Nn = {!-c -m -t 20!} -- No solution found at time out (20s).
+-N₁ : ∀ {m n} → N m → N n → N (m + n)
+-N₁ zN Nn = {!-m!} -- No solution found
+-N₁ (sN Nm) Nn = {!-m!} -- No solution found.
| {
"alphanum_fraction": 0.4415437003,
"avg_line_length": 24.4722222222,
"ext": "agda",
"hexsha": "57df3545a769712919a7d92f9ea0a28a84cef572",
"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/Agsy/AddTotality.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/Agsy/AddTotality.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": "notes/FOT/Agsy/AddTotality.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": 299,
"size": 881
} |
module Relation.Unary.Monotone.Prefix {ℓ}{T : Set ℓ} where
open import Data.List.Prefix
open import Data.List as List
open import Data.List.Membership.Propositional
open import Data.List.All as All
open import Relation.Unary.Monotone (⊑-preorder {A = T})
instance
open Monotone
any-monotone : ∀ {x : T} → Monotone (λ xs → x ∈ xs)
wk any-monotone ext l = ∈-⊒ l ext
| {
"alphanum_fraction": 0.7165775401,
"avg_line_length": 24.9333333333,
"ext": "agda",
"hexsha": "c4b828de8d36fdb1644fc618b9cbc6a622c9a808",
"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/Relation/Unary/Monotone/Prefix.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/Relation/Unary/Monotone/Prefix.agda",
"max_line_length": 58,
"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/Relation/Unary/Monotone/Prefix.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": 122,
"size": 374
} |
module Terms where
import Level
open import Data.Unit as Unit
open import Data.List as List
open import Data.Product as Product
open import Categories.Category using (Category)
open import Types
open import Common.Context GType
using (Ctx; Var; zero; ctx-cat; ctx-bin-coproducts)
renaming (succ to succ′)
open Categories.Category.Category ctx-cat
renaming ( _⇒_ to _▹_
; _≡_ to _≈_
; _∘_ to _●_
; id to ctx-id
)
open import Categories.Object.BinaryCoproducts ctx-cat
open BinaryCoproducts ctx-bin-coproducts
-- | Signatures over which we can define terms
Sig = Ctx
-- | Typed patterns
data Pat : (a : GType) → Set where
var′ : ∀{a : GType} (x : Var [ a ] a) → Pat a
κ₁′ : ∀{a₁ a₂ : GType} (p : Pat a₁) → Pat (a₁ ⊕ a₂)
κ₂′ : ∀{a₁ a₂ : GType} (p : Pat a₂) → Pat (a₁ ⊕ a₂)
α′ : ∀{a : Type [ tt ]} (p : Pat (unfold-μ a)) → Pat (μ a)
-- | Context defined by a pattern (this is either empty or contains a single
-- variable).
pat-ctx : ∀ {a} → Pat a → Ctx
pat-ctx {a} (var′ x) = [ a ]
pat-ctx (κ₁′ x) = pat-ctx x
pat-ctx (κ₂′ x) = pat-ctx x
pat-ctx (α′ x) = pat-ctx x
-- | Typed copatterns
data Copat : (a b : GType) → Set where
· : ∀{a} → Copat a a
app′ : ∀{a b c : GType} (q : Copat (b ⇒ c) a)
(p : Pat c) → Copat c a
π₁′ : ∀{a₁ a₂ a : GType} (q : Copat (a₁ ⊗ a₂) a) → Copat a₁ a
π₂′ : ∀{a₁ a₂ a : GType} (q : Copat (a₁ ⊗ a₂) a) → Copat a₂ a
ξ′ : ∀{b : Type [ tt ]} {a : GType} (q : Copat (ν b) a) → Copat (unfold-ν b) a
-- | Context defined by a copattern
copat-ctx : ∀ { a b} → Copat a b → Ctx
copat-ctx · = []
copat-ctx (app′ q p) = (copat-ctx q) ∐ (pat-ctx p)
copat-ctx (π₁′ q) = copat-ctx q
copat-ctx (π₂′ q) = copat-ctx q
copat-ctx (ξ′ q) = copat-ctx q
mutual
-- | A clause { q₁ ↦ t₁ ; ... ; qₙ ↦ tₙ } defines the body of a λ-abstraction
-- of the definition of a symbol in a signature.
record Clause {Δ : Sig} {Γ : Ctx} {a : GType} : Set where
inductive
field
body : List (
Σ GType (λ b →
Σ (Copat a b) (λ q →
(Term {Δ} ((copat-ctx q) ∐ Γ) b)))
)
-- | Terms typed in a context
data Term {Δ : Sig} (Γ : Ctx) : GType → Set where
var : ∀{a : GType} (x : Var Γ a) → Term Γ a
κ₁ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ a₁) → Term Γ (a₁ ⊕ a₂)
κ₂ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ a₂) → Term Γ (a₁ ⊕ a₂)
α : ∀{a : Type [ tt ]} (t : Term {Δ} Γ (unfold-μ a)) → Term Γ (μ a)
app : ∀{a b : GType} (t : Term {Δ} Γ (a ⇒ b))
(s : Term {Δ} Γ a) → Term Γ b
π₁ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ (a₁ ⊗ a₂)) → Term Γ a₁
π₂ : ∀{a₁ a₂ : GType} (t : Term {Δ} Γ (a₁ ⊗ a₂)) → Term Γ a₂
ξ : ∀{a : Type [ tt ]} (t : Term {Δ} Γ (ν a)) → Term Γ (unfold-ν a)
svar : ∀{a : GType} (f : Var Δ a) → Term Γ a
abs : ∀{a : GType} (D : Clause {Δ} {Γ} {a}) → Term Γ a
rlet : ∀{a : GType} {Δ' : Sig} →
(Ω : Definition Δ') → Term {Δ ∐ Δ'} Γ a → Term {Δ} Γ a
-- | A definition consists of a signature and its definition
data DeclBlock : Sig → Set where
empty : DeclBlock []
record Definition (Δ : Sig) : Set where
inductive
field
defs : List (Σ GType (λ a → (Var Δ a) × Clause {Δ} {[]} {a}))
open Definition
TermWDef : GType → Set
TermWDef a = Σ Sig (λ Δ → (Definition Δ) × (Term {Δ} [] a))
---------- Convenience
_↦_ : ∀{Δ : Sig} {Γ : Ctx} {a b : GType}
(q : Copat a b) (t : Term {Δ} ((copat-ctx q) ∐ Γ) b) →
(Σ GType (λ b →
Σ (Copat a b) (λ q →
(Term {Δ} ((copat-ctx q) ∐ Γ) b))))
_↦_ {b = b} q t = b , q , t
_≝_ : ∀{Δ : Sig} {a : GType}
(f : Var Δ a) (c : Clause {Δ} {[]} {a}) →
Σ GType (λ a → (Var Δ a) × Clause {Δ} {[]} {a})
_≝_ {a = a} f c = a , (f , c)
--------------------------------
------ Examples
-- 〈〉 : Term [] unit
-- 〈〉 = ?
{-
hd : ∀ {a : GType} → Term (Str a) → Term a
hd t = π₁ (ξ q)
hd′ : ∀ {a b : GType} → Copat (Str a) b → Copat a b
hd′ q = π₁′ (ξ′ q)
ones : TermWDef (Str Nat)
ones = Δ , def , (svar o)
where
Δ : Sig
Δ = [ Str Nat ]
o : Var [ Str Nat ] (Str Nat)
o = zero
o-def : Clause {[ Str Nat ]} {[]} {Str Nat}
o-def = record
{ body =
[ (· ↦ svar o) ]
}
def : Definition Δ
def = record
{ defs =
[ o ≝ o-def ]
}
-}
| {
"alphanum_fraction": 0.4586434191,
"avg_line_length": 32.4344827586,
"ext": "agda",
"hexsha": "dcc9ffee72b6e33fce411b14f177f834ab26b5c9",
"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": "TypeTheory/SimpleOTT/Terms.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": "TypeTheory/SimpleOTT/Terms.agda",
"max_line_length": 86,
"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": "TypeTheory/SimpleOTT/Terms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1841,
"size": 4703
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Matrix where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat hiding (_+_ ; +-comm)
open import Cubical.Data.Vec
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Structures.CommRing
private
variable
ℓ : Level
A : Type ℓ
-- Equivalence between Vec matrix and Fin function matrix
FinMatrix : (A : Type ℓ) (m n : ℕ) → Type ℓ
FinMatrix A m n = FinVec (FinVec A n) m
VecMatrix : (A : Type ℓ) (m n : ℕ) → Type ℓ
VecMatrix A m n = Vec (Vec A n) m
FinMatrix→VecMatrix : {m n : ℕ} → FinMatrix A m n → VecMatrix A m n
FinMatrix→VecMatrix M = FinVec→Vec (λ fm → FinVec→Vec (λ fn → M fm fn))
VecMatrix→FinMatrix : {m n : ℕ} → VecMatrix A m n → FinMatrix A m n
VecMatrix→FinMatrix M fn fm = lookup fm (lookup fn M)
FinMatrix→VecMatrix→FinMatrix : {m n : ℕ} (M : FinMatrix A m n)
→ VecMatrix→FinMatrix (FinMatrix→VecMatrix M) ≡ M
FinMatrix→VecMatrix→FinMatrix {m = zero} M = funExt λ f → ⊥.rec (¬Fin0 f)
FinMatrix→VecMatrix→FinMatrix {n = zero} M = funExt₂ λ _ f → ⊥.rec (¬Fin0 f)
FinMatrix→VecMatrix→FinMatrix {m = suc m} {n = suc n} M = funExt₂ goal
where
goal : (fm : Fin (suc m)) (fn : Fin (suc n)) →
VecMatrix→FinMatrix (_ ∷ FinMatrix→VecMatrix (λ z → M (suc z))) fm fn ≡ M fm fn
goal zero zero = refl
goal zero (suc fn) i = FinVec→Vec→FinVec (λ z → M zero (suc z)) i fn
goal (suc fm) fn i = FinMatrix→VecMatrix→FinMatrix (λ z → M (suc z)) i fm fn
VecMatrix→FinMatrix→VecMatrix : {m n : ℕ} (M : VecMatrix A m n)
→ FinMatrix→VecMatrix (VecMatrix→FinMatrix M) ≡ M
VecMatrix→FinMatrix→VecMatrix {m = zero} [] = refl
VecMatrix→FinMatrix→VecMatrix {m = suc m} (M ∷ MS) i =
Vec→FinVec→Vec M i ∷ VecMatrix→FinMatrix→VecMatrix MS i
FinMatrixIsoVecMatrix : (A : Type ℓ) (m n : ℕ) → Iso (FinMatrix A m n) (VecMatrix A m n)
FinMatrixIsoVecMatrix A m n =
iso FinMatrix→VecMatrix VecMatrix→FinMatrix VecMatrix→FinMatrix→VecMatrix FinMatrix→VecMatrix→FinMatrix
FinMatrix≃VecMatrix : {m n : ℕ} → FinMatrix A m n ≃ VecMatrix A m n
FinMatrix≃VecMatrix {_} {A} {m} {n} = isoToEquiv (FinMatrixIsoVecMatrix A m n)
FinMatrix≡VecMatrix : (A : Type ℓ) (m n : ℕ) → FinMatrix A m n ≡ VecMatrix A m n
FinMatrix≡VecMatrix _ _ _ = ua FinMatrix≃VecMatrix
-- We could have constructed the above Path as follows, but that
-- doesn't reduce as nicely as ua isn't on the toplevel:
--
-- FinMatrix≡VecMatrix : (A : Type ℓ) (m n : ℕ) → FinMatrix A m n ≡ VecMatrix A m n
-- FinMatrix≡VecMatrix A m n i = FinVec≡Vec (FinVec≡Vec A n i) m i
-- Experiment using addition. Transport commutativity from one
-- representation to the the other and relate the transported
-- operation with a more direct definition.
module _ (R' : CommRing {ℓ}) where
open CommRing R' renaming ( Carrier to R )
addFinMatrix : ∀ {m n} → FinMatrix R m n → FinMatrix R m n → FinMatrix R m n
addFinMatrix M N = λ k l → M k l + N k l
addFinMatrixComm : ∀ {m n} → (M N : FinMatrix R m n) → addFinMatrix M N ≡ addFinMatrix N M
addFinMatrixComm M N i k l = +-comm (M k l) (N k l) i
addVecMatrix : ∀ {m n} → VecMatrix R m n → VecMatrix R m n → VecMatrix R m n
addVecMatrix {m} {n} = transport (λ i → FinMatrix≡VecMatrix R m n i
→ FinMatrix≡VecMatrix R m n i
→ FinMatrix≡VecMatrix R m n i)
addFinMatrix
addMatrixPath : ∀ {m n} → PathP (λ i → FinMatrix≡VecMatrix R m n i
→ FinMatrix≡VecMatrix R m n i
→ FinMatrix≡VecMatrix R m n i)
addFinMatrix addVecMatrix
addMatrixPath {m} {n} i = transp (λ j → FinMatrix≡VecMatrix R m n (i ∧ j)
→ FinMatrix≡VecMatrix R m n (i ∧ j)
→ FinMatrix≡VecMatrix R m n (i ∧ j))
(~ i) addFinMatrix
addVecMatrixComm : ∀ {m n} → (M N : VecMatrix R m n) → addVecMatrix M N ≡ addVecMatrix N M
addVecMatrixComm {m} {n} = transport (λ i → (M N : FinMatrix≡VecMatrix R m n i)
→ addMatrixPath i M N ≡ addMatrixPath i N M)
addFinMatrixComm
-- More direct definition of addition for VecMatrix:
addVec : ∀ {m} → Vec R m → Vec R m → Vec R m
addVec [] [] = []
addVec (x ∷ xs) (y ∷ ys) = x + y ∷ addVec xs ys
addVecLem : ∀ {m} → (M N : Vec R m)
→ FinVec→Vec (λ l → lookup l M + lookup l N) ≡ addVec M N
addVecLem {zero} [] [] = refl
addVecLem {suc m} (x ∷ xs) (y ∷ ys) = cong (λ zs → x + y ∷ zs) (addVecLem xs ys)
addVecMatrix' : ∀ {m n} → VecMatrix R m n → VecMatrix R m n → VecMatrix R m n
addVecMatrix' [] [] = []
addVecMatrix' (M ∷ MS) (N ∷ NS) = addVec M N ∷ addVecMatrix' MS NS
-- The key lemma relating addVecMatrix and addVecMatrix'
addVecMatrixEq : ∀ {m n} → (M N : VecMatrix R m n) → addVecMatrix M N ≡ addVecMatrix' M N
addVecMatrixEq {zero} {n} [] [] j = transp (λ i → Vec (Vec R n) 0) j []
addVecMatrixEq {suc m} {n} (M ∷ MS) (N ∷ NS) =
addVecMatrix (M ∷ MS) (N ∷ NS)
≡⟨ transportUAop₂ FinMatrix≃VecMatrix addFinMatrix (M ∷ MS) (N ∷ NS) ⟩
FinVec→Vec (λ l → lookup l M + lookup l N) ∷ _
≡⟨ (λ i → addVecLem M N i ∷ FinMatrix→VecMatrix (λ k l → lookup l (lookup k MS) + lookup l (lookup k NS))) ⟩
addVec M N ∷ _
≡⟨ cong (λ X → addVec M N ∷ X) (sym (transportUAop₂ FinMatrix≃VecMatrix addFinMatrix MS NS) ∙ addVecMatrixEq MS NS) ⟩
addVec M N ∷ addVecMatrix' MS NS ∎
-- By binary funext we get an equality as functions
addVecMatrixEqFun : ∀ {m} {n} → addVecMatrix {m} {n} ≡ addVecMatrix'
addVecMatrixEqFun i M N = addVecMatrixEq M N i
-- We then directly get the properties about addVecMatrix'
addVecMatrixComm' : ∀ {m n} → (M N : VecMatrix R m n) → addVecMatrix' M N ≡ addVecMatrix' N M
addVecMatrixComm' M N = sym (addVecMatrixEq M N) ∙∙ addVecMatrixComm M N ∙∙ addVecMatrixEq N M
-- TODO: prove more properties about addition of matrices for both
-- FinMatrix and VecMatrix
-- TODO: define multiplication of matrices and do the same kind of
-- reasoning as we did for addition
| {
"alphanum_fraction": 0.6192083461,
"avg_line_length": 43.744966443,
"ext": "agda",
"hexsha": "2585c1fb1329adc8096d92d1d75a97bc1251478a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Algebra/Matrix.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"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": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Algebra/Matrix.agda",
"max_line_length": 123,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Algebra/Matrix.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2176,
"size": 6518
} |
module OldBasicILP.UntypedSyntax.Common where
open import Common.UntypedContext public
-- Types parametrised by closed, untyped representations.
module ClosedSyntax
(Proof : Set)
where
infixr 10 _⦂_
infixl 9 _∧_
infixr 7 _▻_
data Ty : Set where
α_ : Atom → Ty
_▻_ : Ty → Ty → Ty
_⦂_ : Proof → Ty → Ty
_∧_ : Ty → Ty → Ty
⊤ : Ty
-- Additional useful types.
infixr 7 _▻⋯▻_
_▻⋯▻_ : Cx Ty → Ty → Ty
∅ ▻⋯▻ B = B
(Ξ , A) ▻⋯▻ B = Ξ ▻⋯▻ (A ▻ B)
| {
"alphanum_fraction": 0.5685483871,
"avg_line_length": 17.1034482759,
"ext": "agda",
"hexsha": "23483e43f042e0eacbb52a09434ed8f56af264f9",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "OldBasicILP/UntypedSyntax/Common.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "OldBasicILP/UntypedSyntax/Common.agda",
"max_line_length": 57,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "OldBasicILP/UntypedSyntax/Common.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 217,
"size": 496
} |
open import Nat
open import Prelude
open import core
open import disjointness
module elaboration-generality where
mutual
elaboration-generality-synth : {Γ : tctx} {e : hexp} {τ : htyp} {d : ihexp} {Δ : hctx} →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
Γ ⊢ e => τ
elaboration-generality-synth ESConst = SConst
elaboration-generality-synth (ESVar x₁) = SVar x₁
elaboration-generality-synth (ESLam apt ex) with elaboration-generality-synth ex
... | ih = SLam apt ih
elaboration-generality-synth (ESAp dis _ a x₁ x₂ x₃) = SAp dis a x₁ (elaboration-generality-ana x₃)
elaboration-generality-synth ESEHole = SEHole
elaboration-generality-synth (ESNEHole dis ex) = SNEHole (elab-disjoint-new-synth ex dis) (elaboration-generality-synth ex)
elaboration-generality-synth (ESAsc x) = SAsc (elaboration-generality-ana x)
elaboration-generality-ana : {Γ : tctx} {e : hexp} {τ τ' : htyp} {d : ihexp} {Δ : hctx} →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
Γ ⊢ e <= τ
elaboration-generality-ana (EALam apt m ex) = ALam apt m (elaboration-generality-ana ex)
elaboration-generality-ana (EASubsume x x₁ x₂ x₃) = ASubsume (elaboration-generality-synth x₂) x₃
elaboration-generality-ana EAEHole = ASubsume SEHole TCHole1
elaboration-generality-ana (EANEHole dis x) = ASubsume (SNEHole (elab-disjoint-new-synth x dis) (elaboration-generality-synth x)) TCHole1
| {
"alphanum_fraction": 0.6553365058,
"avg_line_length": 54.4814814815,
"ext": "agda",
"hexsha": "052a530a803b9c9d64d33b4d1a517b9a4061321a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "elaboration-generality.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "elaboration-generality.agda",
"max_line_length": 141,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "elaboration-generality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 512,
"size": 1471
} |
open import Functional using (id)
import Structure.Logic.Constructive.NaturalDeduction
module Structure.Logic.Constructive.Functions.Properties {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} ⦃ constructiveLogicSign : _ ⦄ where
open Structure.Logic.Constructive.NaturalDeduction.ConstructiveLogicSignature {ℓₗ} {Formula} {ℓₘₗ} {Proof} {ℓₒ} {Domain} (constructiveLogicSign)
open import Structure.Logic.Constructive.Functions(Domain)
open import Syntax.Function
-- States whether the function f is defined on the element x.
-- Whether f(x) yields/returns an element in the domain.
-- In other words: Whether the logic can interpret f(x) as anything meaningful.
Defined : Function → Domain → Formula
Defined f(x) = ∃ₗ(y ↦ f(x) ≡ y)
-- States whether the function f can yield/return the element y.
Value : Function → Domain → Formula
Value f(y) = ∃ₗ(x ↦ f(x) ≡ y)
Injective : Function → Formula
Injective(f) = ∀ₗ(x ↦ ∀ₗ(y ↦ (f(x) ≡ f(y)) ⟶ (x ≡ y)))
Surjective : Function → Formula
Surjective(f) = ∀ₗ(y ↦ ∃ₗ(x ↦ f(x) ≡ y))
Bijective : Function → Formula
Bijective(f) =
Injective(f)
∧ Surjective(f)
Preserving₁ : Function → Function → Function → Formula
Preserving₁(f)(g₁)(g₂) = ∀ₗ(x ↦ f(g₁(x)) ≡ g₂(f(x)))
Preserving₂ : Function → BinaryOperator → BinaryOperator → Formula
Preserving₂(f)(_▫₁_)(_▫₂_) = ∀ₗ(x ↦ ∀ₗ(y ↦ f(x ▫₁ y) ≡ (f(x) ▫₂ f(y))))
Fixpoint : Function → Domain → Formula
Fixpoint f(x) = (f(x) ≡ x)
| {
"alphanum_fraction": 0.6952850106,
"avg_line_length": 36.4358974359,
"ext": "agda",
"hexsha": "723453903abf619871362a5f4c4cc7e30307f62a",
"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/Structure/Logic/Constructive/Functions/Properties.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/Structure/Logic/Constructive/Functions/Properties.agda",
"max_line_length": 144,
"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/Structure/Logic/Constructive/Functions/Properties.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": 472,
"size": 1421
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Finite maps with indexed keys and values, based on AVL trees
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Data.Product as Prod
open import Relation.Binary
open import Relation.Binary.PropositionalEquality using (_≡_; cong; subst)
import Data.AVL.Value
module Data.AVL.IndexedMap
{i k v ℓ}
{Index : Set i} {Key : Index → Set k} (Value : Index → Set v)
{_<_ : Rel (∃ Key) ℓ}
(isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_)
where
import Data.AVL
open import Data.Bool
open import Data.List.Base as List using (List)
open import Data.Maybe.Base as Maybe
open import Function
open import Level
-- Key/value pairs.
KV : Set (i ⊔ k ⊔ v)
KV = ∃ λ i → Key i × Value i
-- Conversions.
private
fromKV : KV → Σ[ ik ∈ ∃ Key ] Value (proj₁ ik)
fromKV (i , k , v) = ((i , k) , v)
toKV : Σ[ ik ∈ ∃ Key ] Value (proj₁ ik) → KV
toKV ((i , k) , v) = (i , k , v)
-- The map type.
private
open module AVL =
Data.AVL (record { isStrictTotalOrder = isStrictTotalOrder })
using () renaming (Tree to Map')
Map = Map' (AVL.MkValue (Value ∘ proj₁) (subst Value ∘′ cong proj₁))
-- Repackaged functions.
empty : Map
empty = AVL.empty
singleton : ∀ {i} → Key i → Value i → Map
singleton k v = AVL.singleton (-, k) v
insert : ∀ {i} → Key i → Value i → Map → Map
insert k v = AVL.insert (-, k) v
delete : ∀ {i} → Key i → Map → Map
delete k = AVL.delete (-, k)
lookup : ∀ {i} → Key i → Map → Maybe (Value i)
lookup k m = AVL.lookup (-, k) m
infix 4 _∈?_
_∈?_ : ∀ {i} → Key i → Map → Bool
_∈?_ k = AVL._∈?_ (-, k)
headTail : Map → Maybe (KV × Map)
headTail m = Maybe.map (Prod.map toKV id) (AVL.headTail m)
initLast : Map → Maybe (Map × KV)
initLast m = Maybe.map (Prod.map id toKV) (AVL.initLast m)
fromList : List KV → Map
fromList = AVL.fromList ∘ List.map fromKV
toList : Map → List KV
toList = List.map toKV ∘ AVL.toList
| {
"alphanum_fraction": 0.5871062992,
"avg_line_length": 24.1904761905,
"ext": "agda",
"hexsha": "b7cafecb83d015598e00cbbb5201eb1faa1f4684",
"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/AVL/IndexedMap.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/AVL/IndexedMap.agda",
"max_line_length": 74,
"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/AVL/IndexedMap.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 630,
"size": 2032
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Showing booleans
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Bool.Show where
open import Data.Bool.Base using (Bool; false; true)
open import Data.String.Base using (String)
show : Bool → String
show true = "true"
show false = "false"
| {
"alphanum_fraction": 0.4575471698,
"avg_line_length": 24.9411764706,
"ext": "agda",
"hexsha": "daa414f783074eda8b1b13f9c628922687c8722d",
"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/Bool/Show.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/Bool/Show.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/Bool/Show.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": 72,
"size": 424
} |
{-# OPTIONS --cubical --safe #-}
open import Algebra
module Algebra.SemiringLiterals {r} (rng : Semiring r) where
open Semiring rng
open import Literals.Number
open import Data.Nat.Literals
open import Data.Unit
import Data.Unit.UniversePolymorphic as Poly
open import Data.Nat.DivMod
open import Data.Nat using (ℕ; suc; zero)
open import Data.Nat.Properties
open import Data.Bool
open import Strict
2# : 𝑅
2# = 1# + 1#
sringFromNatRec : ℕ → ℕ → 𝑅
sringFromNatRec zero _ = 0#
sringFromNatRec (suc 0) _ = 1#
sringFromNatRec (suc 1) _ = 2#
sringFromNatRec (suc 2) _ = 1# + 2#
sringFromNatRec (suc n) (suc w) =
let! r =! sringFromNatRec (n ÷ 2) w in!
if even n
then 1# + (r * 2#)
else (1# + r) * 2#
sringFromNatRec _ zero = 0# -- will not happen
sringFromNat : ℕ → 𝑅
sringFromNat n = sringFromNatRec n n
instance
numberRng : Number 𝑅
Number.Constraint numberRng _ = Poly.⊤
Number.fromNat numberRng n = sringFromNat n
| {
"alphanum_fraction": 0.683557394,
"avg_line_length": 23.5853658537,
"ext": "agda",
"hexsha": "2be0212a5dc49487e11ea6a222c0b9e2e8a25f11",
"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": "Algebra/SemiringLiterals.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": "Algebra/SemiringLiterals.agda",
"max_line_length": 60,
"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": "Algebra/SemiringLiterals.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": 353,
"size": 967
} |
{-# OPTIONS --without-K --safe #-}
module Util.Relation.Binary.PropositionalEquality where
open import Relation.Binary.PropositionalEquality public
open import Data.Product using (uncurry)
open import Util.Prelude
private
variable
α β γ γ′ δ : Level
A B C A′ B′ C′ : Set α
trans-unassoc : {a b c d : A} (p : a ≡ b) {q : b ≡ c} {r : c ≡ d}
→ trans p (trans q r) ≡ trans (trans p q) r
trans-unassoc p = sym (trans-assoc p)
Σ-≡⁻ : {A : Set α} {B : A → Set β} {x y : Σ A B}
→ x ≡ y
→ Σ[ p ∈ (proj₁ x ≡ proj₁ y) ] subst B p (proj₂ x) ≡ proj₂ y
Σ-≡⁻ refl = refl , refl
Σ-≡⁺ : {A : Set α} {B : A → Set β} {x y : Σ A B}
→ Σ[ p ∈ (proj₁ x ≡ proj₁ y) ] subst B p (proj₂ x) ≡ proj₂ y
→ x ≡ y
Σ-≡⁺ (refl , refl) = refl
Σ-≡⁺∘Σ-≡⁻ : {A : Set α} {B : A → Set β} {x y : Σ A B}
→ (p : x ≡ y)
→ Σ-≡⁺ (Σ-≡⁻ p) ≡ p
Σ-≡⁺∘Σ-≡⁻ refl = refl
Σ-≡⁻∘Σ-≡⁺ : {A : Set α} {B : A → Set β} {x y : Σ A B}
→ (p : Σ[ p ∈ (proj₁ x ≡ proj₁ y) ] subst B p (proj₂ x) ≡ proj₂ y)
→ Σ-≡⁻ (Σ-≡⁺ p) ≡ p
Σ-≡⁻∘Σ-≡⁺ (refl , refl) = refl
×-≡⁺ : {x y : A × B}
→ (proj₁ x ≡ proj₁ y) × (proj₂ x ≡ proj₂ y)
→ x ≡ y
×-≡⁺ (refl , refl) = refl
×-≡⁻ : {x y : A × B}
→ x ≡ y
→ (proj₁ x ≡ proj₁ y) × (proj₂ x ≡ proj₂ y)
×-≡⁻ refl = refl , refl
×-≡⁺∘×-≡⁻ : {x y : A × B} (p : x ≡ y)
→ ×-≡⁺ (×-≡⁻ p) ≡ p
×-≡⁺∘×-≡⁻ refl = refl
×-≡⁻∘×-≡⁺ : {x y : A × B} (p : (proj₁ x ≡ proj₁ y) × (proj₂ x ≡ proj₂ y))
→ ×-≡⁻ (×-≡⁺ p) ≡ p
×-≡⁻∘×-≡⁺ (refl , refl) = refl
cast : A ≡ B → A → B
cast = subst (λ x → x)
cast-refl : {x : A} → cast refl x ≡ x
cast-refl = refl
cast-trans : (B≡C : B ≡ C) (A≡B : A ≡ B) {x : A}
→ cast B≡C (cast A≡B x) ≡ cast (trans A≡B B≡C) x
cast-trans refl refl = refl
subst-trans : ∀ {P : A → Set β} {x y z : A} {p : P x}
→ (x≡y : x ≡ y) (y≡z : y ≡ z)
→ subst P y≡z (subst P x≡y p) ≡ subst P (trans x≡y y≡z) p
subst-trans refl refl = refl
subst₂-trans : (C : A → B → Set γ)
→ {a₀ a₁ a₂ : A} (p : a₀ ≡ a₁) (p′ : a₁ ≡ a₂)
→ {b₀ b₁ b₂ : B} (q : b₀ ≡ b₁) (q′ : b₁ ≡ b₂)
→ {x : C a₀ b₀}
→ subst₂ C p′ q′ (subst₂ C p q x) ≡ subst₂ C (trans p p′) (trans q q′) x
subst₂-trans C refl refl refl refl = refl
subst₂-subst₂-sym : (C : A → B → Set γ)
→ {a a′ : A} (p : a ≡ a′)
→ {b b′ : B} (q : b ≡ b′)
→ {x : C a′ b′}
→ subst₂ C p q (subst₂ C (sym p) (sym q) x) ≡ x
subst₂-subst₂-sym C refl refl = refl
subst₂-sym-subst₂ : (C : A → B → Set γ)
→ {a a′ : A} (p : a ≡ a′)
→ {b b′ : B} (q : b ≡ b′)
→ {x : C a b}
→ subst₂ C (sym p) (sym q) (subst₂ C p q x) ≡ x
subst₂-sym-subst₂ C refl refl = refl
subst₂-cong : (C : A′ → B′ → Set γ)
→ (f : A → A′) (g : B → B′)
→ {a a′ : A} (p : a ≡ a′)
→ {b b′ : B} (q : b ≡ b′)
→ {x : C (f a) (g b)}
→ subst₂ C (cong f p) (cong g q) x ≡ subst₂ (λ a b → C (f a) (g b)) p q x
subst₂-cong C f g refl refl = refl
subst₂≡subst : ∀ {la} {A : Set la} {lb} {B : Set lb} {lc} (C : A → B → Set lc)
→ ∀ {a a′} (p : a ≡ a′) {b b′} (q : b ≡ b′) {x : C a b}
→ subst₂ C p q x ≡ subst (uncurry C) (cong₂ _,_ p q) x
subst₂≡subst C refl refl = refl
subst₂-application : (C : A → B → Set γ) {C′ : A′ → B′ → Set γ′}
→ {fa : A′ → A} {fb : B′ → B}
→ {a a′ : A′} {b b′ : B′} {c : C (fa a) (fb b)}
→ (g : ∀ a b → C (fa a) (fb b) → C′ a b)
→ (eqa : a ≡ a′)
→ (eqb : b ≡ b′)
→ subst₂ C′ eqa eqb (g a b c)
≡ g a′ b′ (subst₂ C (cong fa eqa) (cong fb eqb) c)
subst₂-application _ _ refl refl = refl
subst₂-application′ : {C : A → B → Set γ} (C′ : A′ → B′ → Set γ′)
→ {fa : A → A′} {fb : B → B′}
→ {a a′ : A} {b b′ : B} {c : C a b}
→ (g : ∀ a b → C a b → C′ (fa a) (fb b))
→ (eqa : a ≡ a′)
→ (eqb : b ≡ b′)
→ subst₂ C′ (cong fa eqa) (cong fb eqb) (g a b c)
≡ g a′ b′ (subst₂ C eqa eqb c)
subst₂-application′ _ _ refl refl = refl
cong₂-dep : {A : Set α} {B : A → Set β} {C : Set γ}
→ (f : (a : A) → B a → C)
→ {x y : A} (p : x ≡ y)
→ {u : B x} {v : B y} (q : subst B p u ≡ v)
→ f x u ≡ f y v
cong₂-dep f refl refl = refl
cong₃-dep : {A : Set α} {B : A → Set β} {C : (a : A) → B a → Set γ}
→ {D : Set δ}
→ (f : (a : A) (b : B a) → C a b → D)
→ {x y : A} (p : x ≡ y)
→ {u : B x} {v : B y} (q : subst B p u ≡ v)
→ {w : C x u} {z : C y v} (r : subst (λ i → C (proj₁ i) (proj₂ i)) (Σ-≡⁺ (p , q)) w ≡ z)
→ f x u w ≡ f y v z
cong₃-dep f refl refl refl = refl
| {
"alphanum_fraction": 0.4477507029,
"avg_line_length": 26.0243902439,
"ext": "agda",
"hexsha": "59fd394fc1bdfed7bb06c2e9662f449f9f87351f",
"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": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis-code",
"max_forks_repo_path": "src/Util/Relation/Binary/PropositionalEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"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": "JLimperg/msc-thesis-code",
"max_issues_repo_path": "src/Util/Relation/Binary/PropositionalEquality.agda",
"max_line_length": 90,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis-code",
"max_stars_repo_path": "src/Util/Relation/Binary/PropositionalEquality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z",
"num_tokens": 2239,
"size": 4268
} |
{-# OPTIONS --without-K #-}
module MidiEvent where
open import Data.Fin using (Fin; #_)
open import Data.List using (List; _∷_; []; concat; map)
open import Data.Nat using (ℕ; _+_; _⊔_)
open import Data.Product using (_×_; _,_; proj₁)
open import Data.String using (String)
open import Data.Vec using (toList)
open import Function using (_∘_)
open import Music using (Melody; melody; Counterpoint; cp; Harmony; melody→notes; harmony→counterpoint)
open import Note using (Note; tone; rest; duration)
open import Pitch using (Pitch)
-- General MIDI instrument numbers range from 1 to 128,
-- so this is the actual instrument number minus 1.
InstrumentNumber-1 : Set
InstrumentNumber-1 = Fin 128
Tick : Set
Tick = ℕ
Velocity : Set
Velocity = Fin 128
defaultVelocity : Velocity
defaultVelocity = # 60
-- percussion is channel 10, so 9 as Channel-1
Channel-1 : Set
Channel-1 = Fin 16
-- in bpm
Tempo : Set
Tempo = ℕ
record MidiEvent : Set where
constructor midiEvent
field
pitch : Pitch -- Pitch was defined to correspond to MIDI pitch
start : Tick
stop : Tick
velocity : Velocity
record MidiTrack : Set where
constructor track
field
trackName : String
instrumentNumber : InstrumentNumber-1
channel : Channel-1
tempo : Tempo -- initial tempo
events : List MidiEvent
notes→events : Velocity → List Note → List MidiEvent
notes→events v ns = me 0 ns where
me : Tick → List Note → List MidiEvent
me t [] = []
me t (tone (duration d) p ∷ ns) = midiEvent p t (t + d) v ∷ me (t + d) ns
me t (rest (duration d) ∷ ns) = me (t + d) ns
melody→events : {n : ℕ} → Velocity → Melody n → List MidiEvent
melody→events v = notes→events v ∘ melody→notes
counterpoint→events : {v d : ℕ} → Velocity → Counterpoint v d → List MidiEvent
counterpoint→events v (cp ms) = concat (map (melody→events v) (toList ms))
harmony→events : {v d : ℕ} → Velocity → Harmony v d → List MidiEvent
harmony→events v = counterpoint→events v ∘ harmony→counterpoint
| {
"alphanum_fraction": 0.6590801328,
"avg_line_length": 29.7042253521,
"ext": "agda",
"hexsha": "394574739d493bd03a6c3f6c040e62b35acb35d5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "doc/icfp20/code/MidiEvent.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "doc/icfp20/code/MidiEvent.agda",
"max_line_length": 110,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "doc/icfp20/code/MidiEvent.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 594,
"size": 2109
} |
{-# OPTIONS --without-K --safe #-}
module TypeTheory.HoTT.Data.Empty.Properties where
-- agda-stdlib
open import Data.Empty
-- agda-misc
open import TypeTheory.HoTT.Base
isProp-⊥ : isProp ⊥
isProp-⊥ x = ⊥-elim x
| {
"alphanum_fraction": 0.7037037037,
"avg_line_length": 16.6153846154,
"ext": "agda",
"hexsha": "59d3773fc633d117360040174f707dd4fcc17349",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "TypeTheory/HoTT/Data/Empty/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "TypeTheory/HoTT/Data/Empty/Properties.agda",
"max_line_length": 50,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "TypeTheory/HoTT/Data/Empty/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 71,
"size": 216
} |
{-# OPTIONS --without-K --safe #-}
module Math.Combinatorics.Function.Properties.Lemma where
open import Data.Unit using (tt)
open import Data.Product
open import Data.Sum
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.DivMod
open import Data.Nat.Solver using (module +-*-Solver)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Function
open import Algebra.FunctionProperties
open ≤-Reasoning
1≤n⇒n≢0 : ∀ {n} → 1 ≤ n → n ≢ 0
1≤n⇒n≢0 .{suc _} (s≤s z≤n) ()
-- TODO: use m<n⇒0<n∸m
m<n⇒n∸m≢0 : ∀ {m n} → m < n → n ∸ m ≢ 0
m<n⇒n∸m≢0 {m} {n} m<n n∸m≡0 = (λ x → x (sym n∸m≡0)) $ <⇒≢ $ +-cancelʳ-< 0 (n ∸ m) $ begin-strict
m <⟨ m<n ⟩
n ≡⟨ sym $ m∸n+n≡m (<⇒≤ m<n) ⟩
(n ∸ m) + m ∎
≤⇒≡∨< : ∀ {m n} → m ≤ n → (m ≡ n) ⊎ (m < n)
≤⇒≡∨< {m} {n} m≤n with m ≟ n
... | yes m≡n = inj₁ m≡n
... | no m≢n = inj₂ (≤∧≢⇒< m≤n m≢n)
^-monoˡ-≤ : ∀ n → (_^ n) Preserves _≤_ ⟶ _≤_
^-monoˡ-≤ 0 {m} {o} m≤o = ≤-refl
^-monoˡ-≤ (suc n) {m} {o} m≤o = begin
m ^ suc n ≡⟨⟩
m * m ^ n ≤⟨ *-mono-≤ m≤o (^-monoˡ-≤ n m≤o) ⟩
o * o ^ n ≡⟨⟩
o ^ suc n ∎
1≤[1+m]^n : ∀ m n → 1 ≤ (1 + m) ^ n
1≤[1+m]^n m zero = ≤-refl
1≤[1+m]^n m (suc n) = begin
1 * 1 ≤⟨ *-mono-≤ (s≤s {0} {m} z≤n) (1≤[1+m]^n m n) ⟩
suc m * suc m ^ n ∎
^-monoʳ-≤ : ∀ n → (suc n ^_) Preserves _≤_ ⟶ _≤_
^-monoʳ-≤ n {.0} {o} z≤n = begin
1 ≤⟨ 1≤[1+m]^n n o ⟩
suc n ^ o ∎
^-monoʳ-≤ n {.(suc _)} {.(suc _)} (s≤s {m} {o} m≤o) = begin
suc n ^ suc m ≡⟨⟩
suc n * suc n ^ m ≤⟨ *-monoʳ-≤ (suc n) (^-monoʳ-≤ n m≤o) ⟩
suc n * suc n ^ o ≡⟨⟩
suc n ^ suc o ∎
^-mono-≤ : ∀ {m n o p} → m ≤ n → o ≤ p → suc m ^ o ≤ suc n ^ p
^-mono-≤ {m} {n} {o} {p} m≤n o≤p = begin
suc m ^ o ≤⟨ ^-monoˡ-≤ o (s≤s m≤n) ⟩
suc n ^ o ≤⟨ ^-monoʳ-≤ n o≤p ⟩
suc n ^ p ∎
*-cancelʳ-≤′ : ∀ m n {o} → False (o ≟ 0) → m * o ≤ n * o → m ≤ n
*-cancelʳ-≤′ m n {suc o} tt = *-cancelʳ-≤ m n o
-- TODO upadte stdlib
*-cancelʳ-≡′ : ∀ m n {o} → False (o ≟ 0) → m * o ≡ n * o → m ≡ n
*-cancelʳ-≡′ m n {suc o} tt = *-cancelʳ-≡ m n
*-monoʳ-<′ : ∀ n → False (n ≟ 0) → (n *_) Preserves _<_ ⟶ _<_
*-monoʳ-<′ (suc n) tt gt = *-monoʳ-< n gt
*-monoˡ-<′ : ∀ n → False (n ≟ 0) → (_* n) Preserves _<_ ⟶ _<_
*-monoˡ-<′ (suc n) tt gt = *-monoˡ-< n gt
m≡n+o⇒m∸o≡n : ∀ m n o → m ≡ n + o → m ∸ o ≡ n
m≡n+o⇒m∸o≡n m n o m≡n+o = trans (cong (_∸ o) m≡n+o) (m+n∸n≡m n o)
lemma₃ : ∀ m n → (∃ λ o → (n ≡ o + m)) ⊎ (n < m)
lemma₃ m n with compare m n
lemma₃ m .(suc (m + k)) | less .m k = inj₁ (suc k , cong suc (+-comm m k))
lemma₃ m .m | equal .m = inj₁ (0 , +-identityˡ m)
lemma₃ .(suc (n + k)) n | greater .n k = inj₂ (s≤s (≤-stepsʳ k ≤-refl))
m≡n*o⇒n≡m/o : ∀ m n o → (wit : False (o ≟ 0)) → m ≡ n * o → n ≡ _/_ m o {wit}
m≡n*o⇒n≡m/o m n o@(suc o-1) tt m≡n*o = sym $ begin-equality
m / o ≡⟨ cong (_/ o) $ m≡n*o ⟩
(n * o) / o ≡⟨ m*n/n≡m n o ⟩
n ∎
m*n≡o⇒m≡o/n : ∀ m n o → (wit : False (n ≟ 0)) → m * n ≡ o → m ≡ _/_ o n {wit}
m*n≡o⇒m≡o/n m n o wit m*n≡o = m≡n*o⇒n≡m/o o m n wit (sym m*n≡o)
*-pres-≢0 : ∀ {a b} → a ≢ 0 → b ≢ 0 → a * b ≢ 0
*-pres-≢0 {0} {b} a≢0 b≢0 a*b≡0 = a≢0 refl
*-pres-≢0 {suc a} {0} a≢0 b≢0 a*b≡0 = b≢0 refl
-- TODO numbering
lemma₅ : ∀ m n o p → (m + n) * (o * p) ≡ (o * (m * p)) + n * (o * p)
lemma₅ = solve 4 (λ m n o p →
(m :+ n) :* (o :* p) := (o :* (m :* p)) :+ (n :* (o :* p))) refl
where open +-*-Solver
lemma₇ : ∀ m n o → m * n * o ≡ m * o * n
lemma₇ = solve 3 (λ m n o → m :* n :* o := m :* o :* n) refl
where open +-*-Solver
lemma₈ : ∀ m n o → m * (n * o) ≡ n * m * o
lemma₈ = solve 3 (λ m n o → m :* (n :* o) := n :* m :* o) refl
where open +-*-Solver
lemma₉ : ∀ m n o p → m * n * (o * p) ≡ (m * o) * (n * p)
lemma₉ = solve 4 (λ m n o p → m :* n :* (o :* p) := (m :* o) :* (n :* p)) refl
where open +-*-Solver
lemma₁₀ : ∀ m n o p → m * n * o * p ≡ (m * o) * (n * p)
lemma₁₀ = solve 4 (λ m n o p → m :* n :* o :* p := (m :* o) :* (n :* p)) refl
where open +-*-Solver
lemma₁₁ : ∀ m n o p → (m * n) * (o * p) ≡ m * o * p * n
lemma₁₁ = solve 4 (λ m n o p → (m :* n) :* (o :* p) := m :* o :* p :* n) refl
where open +-*-Solver
lemma₁₂ : ∀ m n o → m * n * o ≡ n * (m * o)
lemma₁₂ = solve 3 (λ m n o → m :* n :* o := n :* (m :* o)) refl
where open +-*-Solver
lemma₁₃ : ∀ m n o → m * n * n * o ≡ o * m * n * n
lemma₁₃ = solve 3 (λ m n o → m :* n :* n :* o := o :* m :* n :* n) refl
where open +-*-Solver
lemma₁₄ : ∀ m n o → m * n * (n * o * o) ≡ m * (n * o) * (n * o)
lemma₁₄ = solve 3 (λ m n o → m :* n :* (n :* o :* o) := m :* (n :* o) :* (n :* o)) refl
where open +-*-Solver
lemma₁₅ : ∀ n → (2 + 2 * n) * (1 + 2 * n) ≡ 2 * (1 + 2 * n) * (1 + n)
lemma₁₅ = solve 1 (λ n →
(con 2 :+ con 2 :* n) :* (con 1 :+ con 2 :* n) :=
con 2 :* (con 1 :+ con 2 :* n) :* (con 1 :+ n)
) refl
where open +-*-Solver
lemma₁₆ : ∀ m n o p → m * n * (o * p * p) ≡ m * o * (n * p * p)
lemma₁₆ = solve 4 (λ m n o p →
m :* n :* (o :* p :* p) := m :* o :* (n :* p :* p)
) refl
where open +-*-Solver
lemma₁₇ : ∀ m n o p → m * n * (o * p) ≡ o * m * (n * p)
lemma₁₇ = solve 4 (λ m n o p → m :* n :* (o :* p) := o :* m :* (n :* p)) refl
where open +-*-Solver
| {
"alphanum_fraction": 0.4378306878,
"avg_line_length": 34.1419354839,
"ext": "agda",
"hexsha": "d4863411b92ab67ec7ef5199b09113a0a03b2854",
"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": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-combinatorics",
"max_forks_repo_path": "Math/Combinatorics/Function/Properties/Lemma.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"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": "rei1024/agda-combinatorics",
"max_issues_repo_path": "Math/Combinatorics/Function/Properties/Lemma.agda",
"max_line_length": 96,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-combinatorics",
"max_stars_repo_path": "Math/Combinatorics/Function/Properties/Lemma.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-25T07:25:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-25T08:24:15.000Z",
"num_tokens": 2850,
"size": 5292
} |
module Semantics where
open import Syntax public
-- Kripke models.
record Model : Set₁ where
infix 3 _⊩ᵅ_
field
World : Set
_≤_ : World → World → Set
refl≤ : ∀ {w} → w ≤ w
trans≤ : ∀ {w w′ w″} → w ≤ w′ → w′ ≤ w″ → w ≤ w″
idtrans≤ : ∀ {w w′} → (p : w ≤ w′) → trans≤ refl≤ p ≡ p
_⊩ᵅ_ : World → Atom → Set
mono⊩ᵅ : ∀ {P w w′} → w ≤ w′ → w ⊩ᵅ P → w′ ⊩ᵅ P
idmono⊩ᵅ : ∀ {P w} → (s : w ⊩ᵅ P) → mono⊩ᵅ {P} refl≤ s ≡ s
open Model {{…}} public
-- Forcing in a particular world.
module _ {{_ : Model}} where
infix 3 _⊩_
_⊩_ : World → Type → Set
w ⊩ α P = w ⊩ᵅ P
w ⊩ A ⇒ B = ∀ {w′} → w ≤ w′ → w′ ⊩ A → w′ ⊩ B
w ⊩ A ⩕ B = w ⊩ A ∧ w ⊩ B
w ⊩ ⫪ = ⊤
infix 3 _⊩⋆_
_⊩⋆_ : World → Stack Type → Set
w ⊩⋆ ∅ = ⊤
w ⊩⋆ Ξ , A = w ⊩⋆ Ξ ∧ w ⊩ A
-- Function extensionality.
postulate
funext : ∀ {X : Set} {Y : X → Set} {f g : ∀ x → Y x} →
(∀ x → f x ≡ g x) →
(λ x → f x) ≡ (λ x → g x)
⟨funext⟩ : ∀ {X : Set} {Y : X → Set} {f g : ∀ {x} → Y x} →
(∀ {x} → f {x} ≡ g {x}) →
(λ {x} → f {x}) ≡ (λ {x} → g {x})
extfun : ∀ {X : Set} {Y : X → Set} {f g : ∀ x → Y x} →
(λ x → f x) ≡ (λ x → g x) →
(∀ x → f x ≡ g x)
extfun refl = λ x → refl
⟨extfun⟩ : ∀ {X : Set} {Y : X → Set} {f g : ∀ {x} → Y x} →
(λ {x} → f {x}) ≡ (λ {x} → g {x}) →
(∀ {x} → f {x} ≡ g {x})
⟨extfun⟩ refl = refl
-- Monotonicity of forcing with respect to constructive accessibility.
module _ {{_ : Model}} where
mono⊩ : ∀ {A w w′} → w ≤ w′ → w ⊩ A → w′ ⊩ A
mono⊩ {α P} p s = mono⊩ᵅ p s
mono⊩ {A ⇒ B} p s = λ p′ → s (trans≤ p p′)
mono⊩ {A ⩕ B} p s = mono⊩ {A} p (π₁ s) , mono⊩ {B} p (π₂ s)
mono⊩ {⫪} p s = ∙
mono⊩⋆ : ∀ {Ξ w w′} → w ≤ w′ → w ⊩⋆ Ξ → w′ ⊩⋆ Ξ
mono⊩⋆ {∅} p ∙ = ∙
mono⊩⋆ {Ξ , A} p (σ , s) = mono⊩⋆ {Ξ} p σ , mono⊩ {A} p s
-- TODO: Naming things.
module _ {{_ : Model}} where
idmono⊩ : ∀ {A w} → (s : w ⊩ A) → mono⊩ {A} refl≤ s ≡ s
idmono⊩ {α P} s = idmono⊩ᵅ s
idmono⊩ {A ⇒ B} s = ⟨funext⟩ λ {w′} → funext λ p → cong s (idtrans≤ p)
idmono⊩ {A ⩕ B} s = cong² _,_ (idmono⊩ {A} (π₁ s)) (idmono⊩ {B} (π₂ s))
idmono⊩ {⫪} s = refl
idmono⊩⋆ : ∀ {Ξ w} → (γ : w ⊩⋆ Ξ) → mono⊩⋆ refl≤ γ ≡ γ
idmono⊩⋆ {∅} ∙ = refl
idmono⊩⋆ {Ξ , A} (σ , s) = cong² _,_ (idmono⊩⋆ σ) (idmono⊩ {A} s)
-- TODO: Naming things.
module _ {{_ : Model}} where
_⟪_⊫_⟫ : World → Context → Type → Set
w ⟪ Γ ⊫ A ⟫ = w ⊩⋆ Γ → w ⊩ A
-- Evaluation equipment.
module _ {{_ : Model}} where
⟪var⟫ : ∀ {A Γ w} → A ∈ Γ → w ⟪ Γ ⊫ A ⟫
⟪var⟫ top = λ { (γ , s) → s }
⟪var⟫ (pop i) = λ { (γ , s) → ⟪var⟫ i γ }
⟪lam⟫ : ∀ {A B Γ w} → (∀ {w′} → w′ ⟪ Γ , A ⊫ B ⟫) → w ⟪ Γ ⊫ A ⇒ B ⟫
⟪lam⟫ ⟪d⟫ = λ γ p s → ⟪d⟫ (mono⊩⋆ p γ , s)
⟪app⟫ : ∀ {A B Γ w} → w ⟪ Γ ⊫ A ⇒ B ⟫ → w ⟪ Γ ⊫ A ⟫ → w ⟪ Γ ⊫ B ⟫
⟪app⟫ ⟪d⟫ ⟪e⟫ = λ γ → ⟪d⟫ γ refl≤ (⟪e⟫ γ)
⟪pair⟫ : ∀ {A B Γ w} → w ⟪ Γ ⊫ A ⟫ → w ⟪ Γ ⊫ B ⟫ → w ⟪ Γ ⊫ A ⩕ B ⟫
⟪pair⟫ ⟪d⟫ ⟪e⟫ = λ γ → ⟪d⟫ γ , ⟪e⟫ γ
⟪fst⟫ : ∀ {A B Γ w} → w ⟪ Γ ⊫ A ⩕ B ⟫ → w ⟪ Γ ⊫ A ⟫
⟪fst⟫ ⟪d⟫ = λ γ → π₁ (⟪d⟫ γ)
⟪snd⟫ : ∀ {A B Γ w} → w ⟪ Γ ⊫ A ⩕ B ⟫ → w ⟪ Γ ⊫ B ⟫
⟪snd⟫ ⟪d⟫ = λ γ → π₂ (⟪d⟫ γ)
⟪unit⟫ : ∀ {Γ w} → w ⟪ Γ ⊫ ⫪ ⟫
⟪unit⟫ = λ γ → ∙
-- Shorthand for variables.
module _ {{_ : Model}} where
⟪v₀⟫ : ∀ {A Γ w} → w ⟪ Γ , A ⊫ A ⟫
⟪v₀⟫ {A} = ⟪var⟫ {A} i₀
-- Forcing in all worlds, or semantic entailment.
module _ {{_ : Model}} where
infix 3 _⊨_
_⊨_ : Context → Type → Set
Γ ⊨ A = ∀ {w} → w ⟪ Γ ⊫ A ⟫
-- Evaluation, or soundness of the semantics with respect to the syntax.
module _ {{_ : Model}} where
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) = ⟪var⟫ i
eval (lam {A} {B} d) = ⟪lam⟫ {A} {B} (eval d)
eval (app {A} {B} d e) = ⟪app⟫ {A} {B} (eval d) (eval e)
eval (pair {A} {B} d e) = ⟪pair⟫ {A} {B} (eval d) (eval e)
eval (fst {A} {B} d) = ⟪fst⟫ {A} {B} (eval d)
eval (snd {A} {B} d) = ⟪snd⟫ {A} {B} (eval d)
eval unit = ⟪unit⟫
-- The canonical model.
private
instance
canon : Model
canon = record
{ World = Context
; _≤_ = _⊆_
; refl≤ = refl⊆
; trans≤ = trans⊆
; idtrans≤ = idtrans⊆
; _⊩ᵅ_ = λ Γ P → Γ ⊢ⁿᵉ α P
; mono⊩ᵅ = mono⊢ⁿᵉ
; idmono⊩ᵅ = idmono⊢ⁿᵉ
}
-- Soundness and completeness of the canonical model with respect to the syntax.
mutual
evalᶜ : ∀ {A Γ} → Γ ⊢ⁿᵉ A → Γ ⊩ A
evalᶜ {α P} d = d
evalᶜ {A ⇒ B} d = λ p e → evalᶜ (appⁿᵉ (mono⊢ⁿᵉ p d) (quotᶜ e))
evalᶜ {A ⩕ B} d = evalᶜ (fstⁿᵉ d) , evalᶜ (sndⁿᵉ d)
evalᶜ {⫪} d = ∙
quotᶜ : ∀ {A Γ} → Γ ⊩ A → Γ ⊢ⁿᶠ A
quotᶜ {α P} s = neⁿᶠ s
quotᶜ {A ⇒ B} s = lamⁿᶠ (quotᶜ (s weak⊆ (evalᶜ {A} v₀ⁿᵉ)))
quotᶜ {A ⩕ B} s = pairⁿᶠ (quotᶜ (π₁ s)) (quotᶜ (π₂ s))
quotᶜ {⫪} s = unitⁿᶠ
-- Reflexivity of simultaneous forcing.
refl⊩⋆ : ∀ {Γ} → Γ ⊩⋆ Γ
refl⊩⋆ {∅} = ∙
refl⊩⋆ {Γ , A} = mono⊩⋆ weak⊆ refl⊩⋆ , evalᶜ {A} v₀ⁿᵉ
-- Quotation, or completeness of the semantics with respect to the syntax.
quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ⁿᶠ A
quot s = quotᶜ (s refl⊩⋆)
-- Normalisation by evaluation.
nbe : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ⁿᶠ A
nbe = quot ∘ eval
| {
"alphanum_fraction": 0.4280492497,
"avg_line_length": 25.99,
"ext": "agda",
"hexsha": "4b711e97163937746308d07f6cf7c256b7097469",
"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": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/nbe-correctness",
"max_forks_repo_path": "src/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5",
"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/nbe-correctness",
"max_issues_repo_path": "src/Semantics.agda",
"max_line_length": 80,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "54e9a83a8db4e33a33bf5dae5b2d651ad38aa3d5",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/nbe-correctness",
"max_stars_repo_path": "src/Semantics.agda",
"max_stars_repo_stars_event_max_datetime": "2017-03-23T18:51:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-23T06:25:23.000Z",
"num_tokens": 2858,
"size": 5198
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
{-# OPTIONS --allow-unsolved-metas #-}
-- This module proves the two "VotesOnce" proof obligations for our fake handler
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
import LibraBFT.Concrete.Properties.VotesOnce as VO
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types hiding (EpochConfigFor)
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Consensus.ChainedBFT.EventProcessor.Properties sha256 sha256-cr
open import LibraBFT.Impl.Handle sha256 sha256-cr
open import LibraBFT.Impl.Handle.Properties sha256 sha256-cr
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Properties.Aux
open import LibraBFT.Impl.Util.Util
open import LibraBFT.Concrete.System impl-sps-avp
open import LibraBFT.Concrete.System.Parameters
open EpochConfig
open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK
open Structural impl-sps-avp
-- In this module, we prove the two implementation obligations for the VotesOnce rule. Note
-- that it is not yet 100% clear that the obligations are the best definitions to use. See comments
-- in Concrete.VotesOnce. We will want to prove these obligations for the fake/simple
-- implementation (or some variant on it) and streamline the proof before we proceed to tackle more
-- ambitious properties.
module LibraBFT.Impl.Properties.VotesOnce where
-- TODO-1: It seems that vo₂ should be proved via a couple of invocations of this property;
-- the proofs are quite similar.
newVoteSameEpochGreaterRound : ∀ {e}{pre : SystemState e}{pid initd' s' outs v m pk}
→ ReachableSystemState pre
→ StepPeerState {e} pid (availEpochs pre) (msgPool pre) (initialised pre) (peerStates pre pid) initd' (s' , outs)
→ v ⊂Msg m → m ∈ outs → (sig : WithVerSig pk v)
→ ¬ MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
→ (v ^∙ vEpoch) ≡ (₋epEC (peerStates pre pid)) ^∙ epEpoch
× suc ((₋epEC (peerStates pre pid)) ^∙ epLastVotedRound) ≡ (v ^∙ vRound) -- New vote for higher round than last voted
× (v ^∙ vRound) ≡ ((₋epEC s') ^∙ epLastVotedRound) -- Last voted round is round of new vote
newVoteSameEpochGreaterRound _ (step-init _) v⊂m m∈outs sig = ⊥-elim (¬Any[] m∈outs)
newVoteSameEpochGreaterRound {pre = pre} {pid} {m = m} r (step-msg {(_ , nm)} msg∈pool pinit) v⊂m m∈outs sig vnew
rewrite pinit
with nm
...| P msg
with msgsToSendWereSent {pid} {0} {P msg} {m} {peerStates pre pid} m∈outs
...| vm , refl , vmSent
with msgsToSendWereSent1 {pid} {0} {msg} {vm} {peerStates pre pid} vmSent
...| _ , v∈outs
rewrite SendVote-inj-v (Any-singleton⁻ v∈outs)
| SendVote-inj-si (Any-singleton⁻ v∈outs)
with v⊂m
-- Rebuilding keeps the same signature, and the SyncInfo included with the
-- VoteMsg sent comprises QCs from the peer's state. Votes represented in
-- those QCS have signatures that have been sent before, contradicting the
-- assumption that v's signature has not been sent before.
...| vote∈qc {vs = vs} {qc} vs∈qc v≈rbld (inV qc∈m)
rewrite cong ₋vSignature v≈rbld
| procPMCerts≡ {0} {msg} {peerStates pre pid} {vm} v∈outs
= ⊥-elim (vnew (qcVotesSentB4 r pinit refl qc∈m refl vs∈qc))
...| vote∈vm {si} = refl , refl , refl
-- Always true, so far, as no epoch changes.
noEpochChangeYet : ∀ {e}{pre : SystemState e}{pid}{initd' ppre ppost msgs}
→ ReachableSystemState pre
→ ppre ≡ peerStates pre pid
→ StepPeerState pid (availEpochs pre) (msgPool pre) (initialised pre) ppre initd' (ppost , msgs)
→ (₋epEC ppre) ^∙ epEpoch ≡ (₋epEC ppost) ^∙ epEpoch
noEpochChangeYet _ ppre≡ (step-init ix) = {!!}
noEpochChangeYet _ ppre≡ (step-msg {(_ , m)} _ _)
with m
...| P p = refl
...| V v = refl
...| C c = refl
-- We resist the temptation to combine this with the noEpochChangeYet because in future there will be epoch changes
lastVoteRound-mono : ∀ {e}{pre : SystemState e}{pid}{initd' ppre ppost msgs}
→ ReachableSystemState pre
→ ppre ≡ peerStates pre pid
→ StepPeerState pid (availEpochs pre) (msgPool pre) (initialised pre) ppre initd' (ppost , msgs)
→ (₋epEC ppre) ^∙ epEpoch ≡ (₋epEC ppost) ^∙ epEpoch
→ (₋epEC ppre) ^∙ epLastVotedRound ≤ (₋epEC ppost) ^∙ epLastVotedRound
lastVoteRound-mono _ ppre≡ (step-init ix) _ = {!!}
lastVoteRound-mono _ ppre≡ (step-msg {(_ , m)} _ _)
with m
...| P p = const (≤-step (≤-reflexive refl))
...| V v = const (≤-reflexive refl)
...| C c = const (≤-reflexive refl)
-- This is the information we can establish about the state after the first time a signature is
-- sent, and that we can carry forward to subsequent states, so we can use it to prove
-- VO.ImplObligation₁.
LvrProp : CarrierProp
LvrProp v ep = ( v ^∙ vEpoch ≢ (₋epEC ep) ^∙ epEpoch
⊎ (v ^∙ vEpoch ≡ (₋epEC ep) ^∙ epEpoch × v ^∙ vRound ≤ (₋epEC ep) ^∙ epLastVotedRound))
LvrCarrier = PropCarrier LvrProp
firstSendEstablishes : ∀ {e} → Vote → PK → (origSt : SystemState e) → SystemStateRel Step
firstSendEstablishes _ _ _ (step-epoch _) = Lift (ℓ+1 0ℓ) ⊥
firstSendEstablishes _ _ _ (step-peer (step-cheat _ _)) = Lift (ℓ+1 0ℓ) ⊥
firstSendEstablishes {e} v' pk origSt sysStep@(step-peer {e'} {pid'} {pre = pre} pstep@(step-honest _)) =
( ReachableSystemState pre
× ¬ MsgWithSig∈ pk (signature v' unit) (msgPool pre)
× LvrCarrier pk (₋vSignature v') (StepPeer-post pstep)
)
isValidNewPart⇒fSE : ∀ {e e' pk v'}{pre : SystemState e} {post : SystemState e'} {theStep : Step pre post}
→ Meta-Honest-PK pk
→ (ivnp : IsValidNewPart (₋vSignature v') pk theStep)
→ firstSendEstablishes v' pk pre theStep
isValidNewPart⇒fSE {pre = pre} {theStep = step-peer {pid = β} {outs = outs} pstep} hpk (_ , ¬sentb4 , mws , _)
with Any-++⁻ (List-map (β ,_) outs) (msg∈pool mws)
-- TODO-1 : Much of this proof is not specific to the particular property being proved, and could be
-- refactored into Yasm.Properties. See proof of unwind and refactor to avoid redundancy?
...| inj₂ furtherBack = ⊥-elim (¬sentb4 (MsgWithSig∈-transp mws furtherBack))
...| inj₁ thisStep
with pstep
...| step-cheat fm isCheat
with thisStep
...| here refl
with isCheat (msg⊆ mws) (msgSigned mws)
...| inj₁ dis = ⊥-elim (hpk dis)
...| inj₂ sentb4 rewrite msgSameSig mws = ⊥-elim (¬sentb4 sentb4)
isValidNewPart⇒fSE {e}{pk = pk}{pre = pre}{theStep = step-peer {.e} {β} {postst} {outs} {.pre} pstep} hpk (r , ¬sentb4 , mws , vpk)
| inj₁ thisStep
| step-honest {.β} {postst} {outs} {init'} hstep
with Any-satisfied-∈ (Any-map⁻ thisStep)
...| nm , refl , nm∈outs
with hstep
...| step-init _ = ⊥-elim (¬Any[] nm∈outs)
...| step-msg {m} m∈pool _
with impl-sps-avp {m = msgWhole mws} r hpk hstep nm∈outs (msg⊆ mws) (msgSigned mws)
...| inj₂ sentb4 rewrite msgSameSig mws = ⊥-elim (¬sentb4 sentb4)
...| inj₁ (vpk' , _)
with sameEpoch⇒sameEC vpk vpk' refl
...| refl
with newVoteSameEpochGreaterRound r hstep (msg⊆ mws) nm∈outs (msgSigned mws)
(subst (λ sig → ¬ MsgWithSig∈ pk sig (msgPool pre))
(sym (msgSameSig mws))
¬sentb4)
...| refl , refl , newlvr
with noEpochChangeYet {ppre = peerStates pre β} r refl hstep
...| eids≡
with StepPeer-post-lemma pstep
...| post≡ = r , ¬sentb4 , mkCarrier (step-s r (step-peer pstep)) mws vpk
(inj₂ ( trans eids≡ (auxEid post≡)
, ≤-reflexive (trans newlvr (auxLvr post≡))))
where auxEid = cong (_^∙ epEpoch ∘ ₋epEC)
auxLvr = cong (_^∙ epLastVotedRound ∘ ₋epEC)
ImplPreservesLvr : PeerStepPreserves LvrProp
-- We don't have a real model for the initial peer state, so we can't prove this case yet.
-- Eventually, we'll prove something like a peer doesn't initialize to an epoch for which
-- it has already sent votes.
ImplPreservesLvr r _ (step-init ix) = {!!}
ImplPreservesLvr {pre = pre} r prop (step-msg {m} m∈pool inited)
with carrProp prop
...| preprop
with noEpochChangeYet r refl (step-msg m∈pool inited)
...| stepDNMepoch
with preprop
...| inj₁ diffEpoch = inj₁ λ x → diffEpoch (trans x (sym stepDNMepoch))
...| inj₂ (sameEpoch , rnd≤ppre)
with (msgPart (carrSent prop)) ^∙ vEpoch ≟ (₋epEC (peerStates pre (msgSender (carrSent prop)))) ^∙ epEpoch
...| no neq = ⊥-elim (neq sameEpoch)
...| yes refl
with lastVoteRound-mono r refl (step-msg m∈pool inited)
...| es≡⇒lvr≤
= inj₂ (stepDNMepoch , ≤-trans rnd≤ppre (es≡⇒lvr≤ stepDNMepoch))
LvrCarrier-transp* : ∀ {e e' pk sig} {start : SystemState e}{final : SystemState e'}
→ LvrCarrier pk sig start
→ (step* : Step* start final)
→ LvrCarrier pk sig final
LvrCarrier-transp* lvrc step-0 = lvrc
LvrCarrier-transp* lvrc (step-s s* s) = Carrier-transp LvrProp ImplPreservesLvr s (LvrCarrier-transp* lvrc s*)
fSE⇒rnd≤lvr : ∀ {v' pk e'}
→ {final : SystemState e'}
→ Meta-Honest-PK pk
→ ∀ {d d'}{pre : SystemState d}{post : SystemState d'}{theStep : Step pre post}
→ firstSendEstablishes v' pk post theStep
→ Step* post final
→ LvrCarrier pk (signature v' unit) final
fSE⇒rnd≤lvr _ {theStep = step-epoch _} ()
fSE⇒rnd≤lvr hpk {theStep = step-peer (step-honest _)} (_ , _ , lvrc) step* = LvrCarrier-transp* lvrc step*
vo₁ : VO.ImplObligation₁
-- Initialization doesn't send any messages at all so far. In future it may send messages, but
-- probably not containing Votes?
vo₁ r (step-init _) _ _ m∈outs = ⊥-elim (¬Any[] m∈outs)
vo₁ {e} {pid} {pk = pk} {pre = pre} r (step-msg m∈pool ps≡)
{v' = v'} hpk v⊂m m∈outs sig ¬sentb4 vpb v'⊂m' m'∈pool sig' refl rnds≡
with newVoteSameEpochGreaterRound {e} {pre} {pid = pid} r
(step-msg m∈pool ps≡) v⊂m m∈outs sig ¬sentb4
...| eIds≡' , suclvr≡v'rnd , _
-- Use unwind to find the step that first sent the signature for v', then Any-Step-elim to
-- prove that going from the poststate of that step to pre results in a state in which the
-- round of v' is at most the last voted round recorded in the peerState of the peer that
-- sent v'
with Any-Step-elim {Q = LvrCarrier pk (₋vSignature v') pre}
(fSE⇒rnd≤lvr {v'} hpk)
(Any-Step-⇒ (λ _ ivnp → isValidNewPart⇒fSE {v' = v'} hpk ivnp)
(unwind r hpk v'⊂m' m'∈pool sig'))
...| mkCarrier r' mws vpf' preprop
-- The fake/trivial handler always sends a vote for its current epoch, but for a
-- round greater than its last voted round
with sameHonestSig⇒sameVoteData hpk (msgSigned mws) sig' (msgSameSig mws)
...| inj₁ hb = ⊥-elim (PerState.meta-sha256-cr pre r hb)
...| inj₂ refl
-- Both votes have the same epochID, therefore same EpochConfig
with sameEpoch⇒sameEC vpb vpf' refl
-- Both peers are allowed to sign for the same PK, so they are the same peer
...| refl rewrite NodeId-PK-OK-injective (vp-ec vpb) (vp-sender-ok vpb) (vp-sender-ok vpf')
with noEpochChangeYet r' refl (step-msg m∈pool ps≡)
...| stepDNMepoch
with preprop
...| inj₁ diffEpoch = ⊥-elim (diffEpoch eIds≡')
...| inj₂ (sameEpoch , v'rnd≤lvr)
-- So we have proved both that the round of v' is ≤ the lastVotedRound of
-- the peer's state and that the round of v' is one greater than that value,
-- which leads to a contradiction
= ⊥-elim (1+n≰n (≤-trans (≤-reflexive suclvr≡v'rnd)
(≤-trans (≤-reflexive rnds≡) v'rnd≤lvr)))
-- TODO-1: This proof should be refactored to reduce redundant reasoning about the two votes. The
-- newVoteSameEpochGreaterRound property uses similar reasoning.
vo₂ : VO.ImplObligation₂
vo₂ _ (step-init _) _ _ m∈outs _ _ _ _ _ _ _ _ = ⊥-elim (¬Any[] m∈outs)
vo₂ {pid = pid} {pre = pre} r (step-msg {_ , nm} _ pinit) {m = m} {m' = m'}
hpk v⊂m m∈outs sig vnew vpk v'⊂m' m'∈outs sig' v'new vpk' es≡ rnds≡
with nm
...| P msg
with msgsToSendWereSent {pid} {0} {P msg} {m} {peerStates pre pid} m∈outs
...| vm , refl , vmSent
with msgsToSendWereSent1 {pid} {0} {msg} {vm} {peerStates pre pid} vmSent
...| _ , v∈outs
with v⊂m
-- Rebuilding keeps the same signature, and the SyncInfo included with the
-- VoteMsg sent comprises QCs from the peer's state. Votes represented in
-- those QCS have signatures that have been sent before, contradicting the
-- assumption that v's signature has not been sent before.
...| vote∈qc {vs = vs} {qc} vs∈qc v≈rbld (inV qc∈m)
rewrite cong ₋vSignature v≈rbld
| procPMCerts≡ {0} {msg} {peerStates pre pid} {vm} v∈outs
| SendVote-inj-v (Any-singleton⁻ v∈outs)
= ⊥-elim (vnew (qcVotesSentB4 r pinit refl qc∈m refl vs∈qc))
...| vote∈vm {si}
with m'
...| P _ = ⊥-elim (P≢V (Any-singleton⁻ m'∈outs))
...| C _ = ⊥-elim (C≢V (Any-singleton⁻ m'∈outs))
...| V vm'
-- Because the handler sends only one message, the two VoteMsgs vm and vm' are the same
rewrite V-inj (trans (Any-singleton⁻ m'∈outs) (sym (Any-singleton⁻ m∈outs)))
with v'⊂m'
-- Both votes are the vote in the (single) VoteMsg, so their biIds must be the same
...| vote∈vm = refl
-- Here we use the same reasoning as above to show that v' is not new
...| vote∈qc vs∈qc v≈rbld (inV qc∈m)
rewrite cong ₋vSignature v≈rbld
| procPMCerts≡ {0} {msg} {peerStates pre pid} {vm} v∈outs
= ⊥-elim (v'new (qcVotesSentB4 r pinit refl qc∈m refl vs∈qc))
| {
"alphanum_fraction": 0.6051736782,
"avg_line_length": 54.5418181818,
"ext": "agda",
"hexsha": "8dff56dbb6dd7c76d37f0478d6e2331630f34c35",
"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": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Properties/VotesOnce.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"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": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Properties/VotesOnce.agda",
"max_line_length": 149,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Properties/VotesOnce.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4827,
"size": 14999
} |
-- Andreas, 2017-01-26
-- A hopefully exhaustive list of reasons why a function cannot
-- be projection-like. The correctness is ensured by triggering
-- a crash if any of the functions in this file is projection-like.
{-# OPTIONS -v tc.proj.like.crash:1000 #-}
data ⊥ : Set where
record ⊤ : Set where
data Bool : Set where
true false : Bool
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
-- Not projection-like because recursive.
-- (Could be changed).
id' : ∀{A} (xs : List A) → List A
id' [] = []
id' (x ∷ xs) = x ∷ id' xs
-- Not projection-like because constructor-headed.
-- (Could this be changed?)
NonEmpty : ∀{A} (xs : List A) → Set
NonEmpty [] = ⊥
NonEmpty (x ∷ xs) = ⊤
-- Not projection-like because of absurd match.
-- Reason: we cannot infer the value of @A@ for stuck @head [] p@.
head : ∀{A} (xs : List A) (p : NonEmpty xs) → A
head [] ()
head (x ∷ xs) _ = x
-- Not projection-like because of matching on non-principal argument.
-- Reason: we cannot infer the value of @A@ for @dropHeadIf (x ∷ xs) b@.
-- (Constructor applications are not inferable in general.)
dropHeadIf : ∀{A} (xs : List A) (b : Bool) → List A
dropHeadIf (_ ∷ xs) true = xs
dropHeadIf xs _ = xs
-- Not projection-like because of deep matching.
-- Reason: we cannot infer @A@ for @drop2 (x ∷ xs)@.
drop2 : ∀{A} (xs : List A) → List A
drop2 (_ ∷ (_ ∷ xs)) = xs
drop2 xs = xs
-- Not projection-like because @abstract@.
-- Reason: @tail []@ is stuck outside of the abstract block.
abstract
tail : ∀{A} (xs : List A) → List A
tail [] = []
tail (_ ∷ xs) = xs
-- Not projection-like because mutually defined.
mutual
odds : ∀{A} (xs : List A) → List A
odds [] = []
odds (x ∷ xs) = evens xs
postulate
evens : ∀{A} (xs : List A) → List A
-- evens [] = []
-- evens (x ∷ xs) = x ∷ odds xs
-- Not projection-like because no parameters.
IsTrue : Bool → Set
IsTrue true = ⊤
IsTrue false = ⊥
-- Not projection-like because type can reduce.
idTrue : (b : Bool) (p : IsTrue b) → Bool
idTrue b p = b
-- Not projection-like because it returns a paramter
par : {A : Set} (xs : List A) → Set
par {A} xs = A
| {
"alphanum_fraction": 0.6150320807,
"avg_line_length": 24.2444444444,
"ext": "agda",
"hexsha": "81729f795ab78508339b1d8c514aeb5e8d52d269",
"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": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Blaisorblade/Agda",
"max_forks_repo_path": "test/Succeed/NotProjectionLike.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"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": "Blaisorblade/Agda",
"max_issues_repo_path": "test/Succeed/NotProjectionLike.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "802a28aa8374f15fe9d011ceb80317fdb1ec0949",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Blaisorblade/Agda",
"max_stars_repo_path": "test/Succeed/NotProjectionLike.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": 706,
"size": 2182
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Experiments.CohomologyGroups where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.KcompPrelims
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.Pushout
open import Cubical.HITs.Sn
open import Cubical.HITs.SetTruncation
renaming (rec to sRec ; elim to sElim ; elim2 to sElim2)
hiding (map)
open import Cubical.HITs.PropositionalTruncation
renaming (rec to pRec ; ∥_∥ to ∥_∥₁ ; ∣_∣ to ∣_∣₁)
hiding (map)
open import Cubical.Data.Bool
open import Cubical.Data.Sigma
open import Cubical.Data.Int
open import Cubical.Algebra.Group
open GroupIso
open GroupHom
open BijectionIso
-- --------------------------H¹(S¹) -----------------------------------
{-
In order to apply Mayer-Vietoris, we need the following lemma.
Given the following diagram
a ↦ (a , 0) ψ ϕ
A --> A × A -------> B ---> C
If ψ is an isomorphism and ϕ is surjective with ker ϕ ≡ {ψ (a , a) ∣ a ∈ A}, then C ≅ B
-}
diagonalIso : ∀ {ℓ ℓ' ℓ''} {A : Group {ℓ}} (B : Group {ℓ'}) {C : Group {ℓ''}}
(ψ : GroupIso (dirProd A A) B) (ϕ : GroupHom B C)
→ isSurjective _ _ ϕ
→ ((x : ⟨ B ⟩) → isInKer B C ϕ x
→ ∃[ y ∈ ⟨ A ⟩ ] x ≡ (fun (map ψ)) (y , y))
→ ((x : ⟨ B ⟩) → (∃[ y ∈ ⟨ A ⟩ ] x ≡ (fun (map ψ)) (y , y))
→ isInKer B C ϕ x)
→ GroupIso A C
diagonalIso {A = A} B {C = C} ψ ϕ issurj ker→diag diag→ker = BijectionIsoToGroupIso bijIso
where
open GroupStr
module A = GroupStr (snd A)
module B = GroupStr (snd B)
module C = GroupStr (snd C)
module A×A = GroupStr (snd (dirProd A A))
module ψ = GroupIso ψ
module ϕ = GroupHom ϕ
ψ⁻ = inv ψ
fstProj : GroupHom A (dirProd A A)
fun fstProj a = a , GroupStr.0g (snd A)
isHom fstProj g0 g1 i = (g0 A.+ g1) , GroupStr.lid (snd A) (GroupStr.0g (snd A)) (~ i)
bijIso : BijectionIso A C
map' bijIso = compGroupHom fstProj (compGroupHom (map ψ) ϕ)
inj bijIso a inker = pRec (isSetCarrier A _ _)
(λ {(a' , id) → (cong fst (sym (leftInv ψ (a , GroupStr.0g (snd A))) ∙∙ cong ψ⁻ id ∙∙ leftInv ψ (a' , a')))
∙ cong snd (sym (leftInv ψ (a' , a')) ∙∙ cong ψ⁻ (sym id) ∙∙ leftInv ψ (a , GroupStr.0g (snd A)))})
(ker→diag _ inker)
surj bijIso c =
pRec propTruncIsProp
(λ { (b , id) → ∣ (fst (ψ⁻ b) A.+ (A.- snd (ψ⁻ b)))
, ((sym (GroupStr.rid (snd C) _)
∙∙ cong ((fun ϕ) ((fun (map ψ)) (fst (ψ⁻ b) A.+ (A.- snd (ψ⁻ b)) , GroupStr.0g (snd A))) C.+_)
(sym (diag→ker (fun (map ψ) ((snd (ψ⁻ b)) , (snd (ψ⁻ b))))
∣ (snd (ψ⁻ b)) , refl ∣₁))
∙∙ sym ((isHom ϕ) _ _))
∙∙ cong (fun ϕ) (sym ((isHom (map ψ)) _ _)
∙∙ cong (fun (map ψ)) (ΣPathP (sym (GroupStr.assoc (snd A) _ _ _)
∙∙ cong (fst (ψ⁻ b) A.+_) (GroupStr.invl (snd A) _)
∙∙ GroupStr.rid (snd A) _
, (GroupStr.lid (snd A) _)))
∙∙ rightInv ψ b)
∙∙ id) ∣₁ })
(issurj c)
H¹-S¹≅ℤ : GroupIso intGroup (coHomGr 1 (S₊ 1))
H¹-S¹≅ℤ =
diagonalIso (coHomGr 0 (S₊ 0))
(invGroupIso H⁰-S⁰≅ℤ×ℤ)
(K.d 0)
(λ x → K.Ker-i⊂Im-d 0 x
(ΣPathP (isOfHLevelSuc 0 (isContrHⁿ-Unit 0) _ _
, isOfHLevelSuc 0 (isContrHⁿ-Unit 0) _ _)))
((sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
(λ x inker
→ pRec propTruncIsProp
(λ {((f , g) , id') → helper x f g id' inker})
((K.Ker-d⊂Im-Δ 0 ∣ x ∣₂ inker)))))
((sElim (λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ F surj
→ pRec (setTruncIsSet _ _)
(λ { (x , id) → K.Im-Δ⊂Ker-d 0 ∣ F ∣₂
∣ (∣ (λ _ → x) ∣₂ , ∣ (λ _ → 0) ∣₂) ,
(cong ∣_∣₂ (funExt (surjHelper x))) ∙ sym id ∣₁ })
surj) )
□ invGroupIso (coHomPushout≅coHomSn 0 1)
where
module K = MV Unit Unit (S₊ 0) (λ _ → tt) (λ _ → tt)
surjHelper : (x : Int) (x₁ : S₊ 0) → x -[ 0 ]ₖ 0 ≡ S0→Int (x , x) x₁
surjHelper x true = Iso.leftInv (Iso-Kn-ΩKn+1 0) x
surjHelper x false = Iso.leftInv (Iso-Kn-ΩKn+1 0) x
helper : (F : S₊ 0 → Int) (f g : ∥ (Unit → Int) ∥₂)
(id : GroupHom.fun (K.Δ 0) (f , g) ≡ ∣ F ∣₂)
→ isInKer (coHomGr 0 (S₊ 0))
(coHomGr 1 (Pushout (λ _ → tt) (λ _ → tt)))
(K.d 0)
∣ F ∣₂
→ ∃[ x ∈ Int ] ∣ F ∣₂ ≡ inv H⁰-S⁰≅ℤ×ℤ (x , x)
helper F =
sElim2 (λ _ _ → isOfHLevelΠ 2 λ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
λ f g id inker
→ pRec propTruncIsProp
(λ ((a , b) , id2)
→ sElim2 {C = λ f g → GroupHom.fun (K.Δ 0) (f , g) ≡ ∣ F ∣₂ → _ }
(λ _ _ → isOfHLevelΠ 2 λ _ → isOfHLevelSuc 1 propTruncIsProp)
(λ f g id → ∣ (helper2 f g .fst) , (sym id ∙ sym (helper2 f g .snd)) ∣₁)
a b id2)
(MV.Ker-d⊂Im-Δ _ _ (S₊ 0) (λ _ → tt) (λ _ → tt) 0 ∣ F ∣₂ inker)
where
helper2 : (f g : Unit → Int)
→ Σ[ x ∈ Int ] (inv H⁰-S⁰≅ℤ×ℤ (x , x))
≡ GroupHom.fun (K.Δ 0) (∣ f ∣₂ , ∣ g ∣₂)
helper2 f g = (f _ -[ 0 ]ₖ g _) , cong ∣_∣₂ (funExt λ {true → refl ; false → refl})
| {
"alphanum_fraction": 0.4527027027,
"avg_line_length": 46.1843971631,
"ext": "agda",
"hexsha": "c4741763fcc09c566086b3e2fdc03713233cb8cd",
"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": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/Experiments/CohomologyGroups.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"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": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/Experiments/CohomologyGroups.agda",
"max_line_length": 142,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/Experiments/CohomologyGroups.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2287,
"size": 6512
} |
module Sec2 where
open import Sec4
data Bool : Set where
T : Bool
F : Bool
_∣∣_ : Bool → Bool → Bool
_ ∣∣ F = F
_ ∣∣ T = T
_&_ : Bool → Bool → Bool
_ & F = F
F & T = F
T & T = T
_==>_ : Bool → Bool → Bool
F ==> _ = T
T ==> F = F
T ==> T = T
not : Bool -> Bool
not T = F
not F = T
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
_+_ : ∀ (m : ℕ) → ∀ (n : ℕ) → ℕ
Z + m = m
(S n) + m = S (n + m)
_*_ : ℕ → ℕ → ℕ
Z * m = Z
(S n) * m = (n * m) + m
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN BOOL Bool #-}
_≤_ : ℕ → ℕ → Bool
Z ≤ _ = T
(S n) ≤ Z = F
(S n) ≤ (S m) = n ≤ m
_<_ : ℕ → ℕ → Bool
Z < (S _) = T
Z < Z = F
(S n) < (S m) = n < m
(S n) < Z = F
_≥_ : ℕ → ℕ → Bool
m ≥ n = n ≤ m
_>_ : ℕ → ℕ → Bool
m > n = n < m
-- XXX: == on Nat
_==_ : ℕ → ℕ → Bool
x == y = (x ≥ y) & (x ≤ y)
_-_ : ℕ → ℕ → ℕ
Z - _ = Z
(S n) - Z = (S n)
(S n) - (S m) = n - m
K : {A B : Set} → A → B → A
K x _ = x
SC : {A B C : Set} → (A → B → C) → (A → B) → A → C
SC f g x = f x (g x)
-- XXX: The list type
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
length : {A : Set} → List A → ℕ
length [] = Z
length (x ∷ m) = 1 + length m
test : List ℕ
test = 2 ∷ (3 ∷ [])
test1 : ℕ
test1 = length test
data So : Bool → Set where
ok : So T
private head : {A : Set} → (x : List A) → So ((length x) ≥ 1) → A
head [] ()
head (x ∷ x₁) _ = x
private tail : {A : Set} → (x : List A) → So ((length x) ≥ 1) → List A
tail [] ()
tail (x ∷ x₁) _ = x₁
if_then_else_ : {A : Set} → Bool → A → A → A
if T then x else _ = x
if F then _ else y = y
private filter : {A : Set} → (A → Bool) → List A → List A
filter cmp [] = []
filter cmp (x ∷ x₁) = if (cmp x)
then x ∷ (filter cmp x₁)
else filter cmp x₁
_++_ : {A : Set} → List A → List A → List A
[] ++ r = r
(x ∷ l) ++ r = x ∷ (l ++ r)
insert : (a : ℕ) → (List ℕ) → (List ℕ)
insert a [] = (a ∷ [])
insert a (x ∷ l) = if (a ≤ x)
then (a ∷ (x ∷ l))
else (x ∷ (insert a l))
tt2 : List ℕ
tt2 = insert 9 (0 ∷ (8 ∷ []))
private foldl : {A : Set} → (A → A → A) → List A → A → A
foldl _ [] y = y
foldl f (x ∷ x₁) y = foldl f x₁ (f x y)
-- XXX: injective tuple
data _+′_ (A B : Set) : Set where
inl : (x : A) → A +′ B
inr : (x : B) → A +′ B
case : {A B C : Set} → (A +′ B) → (f₁ : (A → C)) → (f₂ : (B → C)) → C
case (inl x) f₁ _ = f₁ x
case (inr x) _ f₂ = f₂ x
-- XXX: Proof of transitivity of >
T> : (a b c : ℕ) → So (a > b) → So (b > c) → So (a > c)
T> Z Z Z () y
T> Z Z (S c) () y
T> Z (S b) c () y
T> (S a) Z Z ok ()
T> (S a) Z (S c) ok ()
T> (S a) (S b) Z x y = ok
T> (S a) (S b) (S c) x y = T> a b c x y
-- XXX: Tuple type
data _Π_ (A B : Set) : Set where
<_,_> : (x : A) → (y : B) → A Π B
private zip : {A B : Set} → (xs : List A) → (ys : List B) → So ((length xs) == (length ys)) → List (A Π B)
zip [] [] k = []
zip [] (x ∷ ys) ()
zip (x ∷ xs) [] ()
zip (x ∷ xs) (y ∷ ys) k = < x , y > ∷ zip xs ys k
-- TODO: Write unzip later on
-- unzip : {A B : Set} → List (A Π B) → (List A Π List B)
-- unzip xs = {!!}
test5 : List (ℕ Π ℕ)
test5 = zip ((1 ∷ [])) (2 ∷ []) ok
infix 4 _≡_
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
{-# BUILTIN REFL refl #-}
-- XXX: Transitivity of ℕ
ℕ-trans : ∀ {x y z : ℕ} → (x ≡ y) → (y ≡ z) → (x ≡ z)
ℕ-trans refl refl = refl
-- XXX: Symmetry of ℕ
sym : ∀ {x y : ℕ} → (x ≡ y) → (y ≡ x)
sym refl = refl
-- XXX: Congruence of ℕ
cong : ∀ {x y : ℕ} → (x ≡ y) → (1 + x) ≡ (1 + y)
cong refl = refl
plus-z : ∀ (y : ℕ) → ((y + Z) ≡ y)
plus-z Z = refl
plus-z (S y) = cong (plus-z y)
assoc-+ : ∀ (a b c : ℕ) → ((a + b) + c) ≡ (a + (b + c))
assoc-+ Z y z = refl
assoc-+ (S x) y z = cong (assoc-+ x y z)
t1 : ∀ (x y : ℕ) → (x + S y) ≡ S (x + y)
t1 Z y = refl
t1 (S x) y = cong (t1 x y)
-- See this: https://github.com/dvanhorn/play/blob/master/agda/Rewrite.agda
-- for examples of rewrite.
-- Also read: http://agda.readthedocs.io/en/latest/language/with-abstraction.html#generalisation
commute-+ : ∀ (x y : ℕ) → ((x + y) ≡ (y + x))
commute-+ Z y rewrite plus-z y = refl
commute-+ (S x) y rewrite t1 y x = cong (commute-+ x y)
mult-z : ∀ (y : ℕ) → ((y * Z) ≡ Z)
mult-z Z = refl
mult-z (S y) rewrite plus-z (y * Z) = mult-z y
lemma-1 : ∀ {a b : ℕ} → ∀ (n : ℕ) → (a ≡ b) → (n + a ≡ n + b)
lemma-1 _ refl = refl
c-* : ∀ (m n : ℕ) → (m * S n) ≡ (m * n) + m
c-* Z n rewrite commute-+ (n * Z) Z
| mult-z n = refl
c-* (S m) n rewrite
commute-+ (m * S n) (S n)
| commute-+ ((m * n) + n) (S m)
| commute-+ m ((m * n) + n)
| assoc-+ (m * n) n m
| commute-+ (m * n) (n + m)
| assoc-+ n m (m * n)
| commute-+ m (m * n)
= cong (lemma-1 n (c-* m n))
commute-* : ∀ (m n : ℕ) → (m * n) ≡ (n * m)
commute-* m Z = mult-z m
commute-* m (S n) rewrite c-* m n
| commute-+ (m * n) m
| commute-+ (n * m) m = lemma-1 m (commute-* m n)
lemma-2 : ∀ (m n x : ℕ) → (m + n) * x ≡ ((m * x) + (n * x))
lemma-2 m n Z rewrite mult-z (m + n)
| mult-z m
| mult-z n = refl
lemma-2 m n (S x) rewrite c-* (m + n) x
| c-* m x
| c-* n x
| assoc-+ (m * x) m ((n * x) + n)
| commute-+ m ((n * x) + n)
| assoc-+ (n * x) n m
| commute-+ n m
| commute-+ (n * x) (m + n)
| commute-+ (m * x) ((m + n) + (n * x))
| assoc-+ (m + n) (n * x) (m * x)
| commute-+ (m + n) ((n * x) + (m * x))
| commute-+ (n * x) (m * x)
| commute-+ ((m * x) + (n * x)) (m + n)
| commute-+ ((m + n) * x) (m + n) = lemma-1 (m + n) (lemma-2 m n x)
assoc-* : ∀ (a b c : ℕ) → ((a * b) * c) ≡ (a * (b * c))
assoc-* Z b c = refl
assoc-* (S a) b c rewrite lemma-2 (a * b) b c
| commute-+ ((a * b) * c) (b * c)
| commute-+ (a * (b * c)) (b * c) = lemma-1 (b * c) (assoc-* a b c)
distributivity-+-* : ∀ (a b c : ℕ) → (a * (b + c)) ≡ ((a * b) + (a * c))
distributivity-+-* a b c rewrite commute-* a (b + c)
| commute-* a b
| commute-* a c
| lemma-2 b c a = refl
-- XXX: factorial function on naturals
fact : ∀ (x : ℕ) → ℕ
fact Z = (S Z)
fact (S Z) = (S Z)
fact (S x) = x * (fact x)
-- TODO: Relation on ℕ and >
_>⋆_ : ℕ → ℕ → Prop
Z >⋆ Z = ⊥
S x >⋆ Z = ⊤
Z >⋆ S y = ⊥
S x >⋆ S y = x >⋆ y
lem : (m n : ℕ) → (p : n >⋆ Z) → (m + n) >⋆ 0
lem Z n p = p
lem (S m) n p = ⋆
-- XXX: Theorem; factorial of any natural number is > 0
-- XXX: page-124, problem 4.35, Type Theory and functional programming
thm : ∀ (x : ℕ) → (fact x) >⋆ Z
thm Z = ⋆
thm (S Z) = ⋆
thm (S (S x)) = lem (x * fact (S x)) (fact (S x)) (thm (S x))
_<=_ : ∀ (m n : ℕ) → Prop
Z <= n = ⊤
S m <= Z = ⊥
S m <= S n = m <= n
-- symm : ∀ (m n : ℕ) → (p : m <= n) → (n <= m)
-- symm Z Z p = ⋆
-- symm Z (S n) p = {!!}
-- symm (S m) Z p = ⋆
-- symm (S m) (S n) p = symm m n p
transm : ∀ (m n p : ℕ) → (m <= n) → (n <= p) → (m <= p)
transm Z n p p1 p2 = ⋆
transm (S m) Z Z p1 p2 = p1
transm (S m) (S n) Z p1 p2 = p2
transm (S m) Z (S p) () p2
transm (S m) (S n) (S p) p1 p2 = transm m n p p1 p2
-- Show that 2 + 3 ≡ 3 + 2
eqq : 2 + 3 ≡ 3 + 2
eqq = refl
| {
"alphanum_fraction": 0.4121220302,
"avg_line_length": 23.9741100324,
"ext": "agda",
"hexsha": "4f34cab0e95a39838c46224d170303df502aad57",
"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": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "amal029/agda-tutorial-dybjer",
"max_forks_repo_path": "Sec2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"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": "amal029/agda-tutorial-dybjer",
"max_issues_repo_path": "Sec2.agda",
"max_line_length": 106,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "amal029/agda-tutorial-dybjer",
"max_stars_repo_path": "Sec2.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:52:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:52:30.000Z",
"num_tokens": 3243,
"size": 7408
} |
{-# OPTIONS --without-K #-}
module algebra.monoid where
open import algebra.monoid.core public
open import algebra.monoid.morphism public
open import algebra.monoid.mset public
| {
"alphanum_fraction": 0.7932960894,
"avg_line_length": 25.5714285714,
"ext": "agda",
"hexsha": "0cfed5fcaf33e632cd834827c795f3c572bb85f2",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/algebra/monoid.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/algebra/monoid.agda",
"max_line_length": 42,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/algebra/monoid.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 39,
"size": 179
} |
{-# OPTIONS --type-in-type --no-termination-check
#-}
module Containers where
record Sigma (A : Set) (B : A -> Set) : Set where
field fst : A
snd : B fst
open Sigma
_*_ : (A B : Set) -> Set
A * B = Sigma A \_ -> B
data Zero : Set where
record One : Set where
data PROP : Set where
Absu : PROP
Triv : PROP
_/\_ : PROP -> PROP -> PROP
All : (S : Set) -> (S -> PROP) -> PROP
Prf : PROP -> Set
Prf Absu = Zero
Prf Triv = One
Prf (P /\ Q) = Prf P * Prf Q
Prf (All S P) = (x : S) -> Prf (P x)
_,_ : forall {A B} -> (a : A) -> B a -> Sigma A B
a , b = record { fst = a ; snd = b }
split : ∀ {A B} {C : Sigma A B -> Set} ->
(f : (a : A) -> (b : B a) -> C (a , b)) -> (ab : Sigma A B) -> C ab
split f ab = f (fst ab) (snd ab)
data _+_ (A B : Set) : Set where
l : A -> A + B
r : B -> A + B
cases : ∀ {A B} {C : A + B -> Set} ->
((a : A) -> C (l a)) -> ((b : B) -> C (r b)) ->
(ab : A + B) -> C ab
cases f g (l a) = f a
cases f g (r b) = g b
rearrange : ∀ {A B X} (C : A → Set) (D : B → Set) (f : Sigma A C → X) →
Sigma (A + B) (cases C D) → X + Sigma B D
rearrange {A} {B} {X} C D f = split {A + B} (cases (\a c → l (f (a , c))) (\b d → r (b , d)))
data CON (I : Set) : Set where
?? : I -> CON I
PrfC : PROP -> CON I
_*C_ : CON I -> CON I -> CON I
PiC : (S : Set) -> (S -> CON I) -> CON I
SiC : (S : Set) -> (S -> CON I) -> CON I
MuC : (O : Set) -> (O -> CON (I + O)) -> O -> CON I
mutual
data Mu {I : Set} (O : Set) (D : O -> CON (I + O))
(X : I -> Set) : O -> Set where
inm : {o : O} -> [| D o |] (cases X (Mu O D X)) -> Mu O D X o
[|_|]_ : {I : Set} -> (CON I) -> (I -> Set) -> Set
[| ?? i |] X = X i
[| PrfC p |] X = Prf p
[| C *C D |] X = [| C |] X * [| D |] X
[| PiC S C |] X = (s : S) -> [| C s |] X
[| SiC S C |] X = Sigma S \s -> [| C s |] X
[| MuC O C o |] X = Mu O C X o
outm : {I O : Set} {D : O -> CON (I + O)} {X : I -> Set} {o : O} ->
Mu O D X o -> [| D o |] (cases X (Mu O D X))
outm (inm x) = x
Everywhere : {I : Set} -> (D : CON I) -> (J : I -> Set) -> (X : Set) ->
(Sigma I J -> X) -> [| D |] J -> CON X
Everywhere (?? i) J X c t = ?? (c (i , t))
Everywhere (PrfC p) J X c t = PrfC Triv
Everywhere (C *C D) J X c t =
Everywhere C J X c (fst t) *C Everywhere D J X c (snd t)
Everywhere (PiC S C) J X c t = PiC S (\s -> Everywhere (C s) J X c (t s))
Everywhere (SiC S C) J X c t = Everywhere (C (fst t)) J X c (snd t)
Everywhere (MuC O C o) J X c t = MuC (Sigma O (Mu O C J)) (\ot' ->
Everywhere (C (fst ot'))
(cases J (Mu O C J))
(X + (Sigma O (Mu O C J)))
(split (cases(\i j -> l (c (i , j)))
(\o'' t'' -> r (o'' , t''))))
(outm (snd ot')))
(o , t)
everywhere : {I : Set} -> (D : CON I) -> (J : I -> Set) -> (X : Set) ->
(c : Sigma I J -> X) -> (Y : X -> Set) ->
(f : (ij : Sigma I J) -> Y (c ij)) -> (t : [| D |] J) ->
[| Everywhere D J X c t |] Y
everywhere (?? i) J X c Y f t = f (i , t)
everywhere (PrfC p) J X c Y f t = _
everywhere (C *C D) J X c Y f t =
everywhere C J X c Y f (fst t) , everywhere D J X c Y f (snd t)
everywhere (PiC S C) J X c Y f t = \s -> everywhere (C s) J X c Y f (t s)
everywhere (SiC S C) J X c Y f t = everywhere (C (fst t)) J X c Y f (snd t)
everywhere (MuC O C o) J X c Y f (inm t) =
inm (everywhere (C o) (cases J (Mu O C J)) (X + Sigma O (Mu O C J)) (
(split (cases (\i j -> l (c (i , j))) (\o t -> r (o , t)))))
(cases Y (split \o'' t'' -> [| Everywhere (MuC O C o'') J X c t'' |] Y))
(split (cases (\i j -> f (i , j))
(\o'' t'' -> everywhere (MuC O C o'') J X c Y f t'')))
t)
induction : {I O : Set} (D : O -> CON (I + O)) (J : I -> Set) (X : Set)
(c : Sigma I J -> X) (Y : X -> Set) (f : (ij : Sigma I J) -> Y (c ij))
(P : Sigma O (Mu O D J) -> Set) ->
({o : O} (v : [| D o |] cases J (Mu O D J)) ->
[| Everywhere (D o) _ (X + Sigma O (Mu O D J))
(split (cases (\i j -> l (c (i , j)))
(\o v -> r (o , v)))) v |] cases Y P ->
P (o , inm v)) ->
(o : O) (v : Mu O D J o) -> P (o , v)
induction {I} {O} D J X c Y f P p o (inm v) =
p v (everywhere {I + O} (D o)
(λ x -> cases {I} {O} {\_ -> Set} J
(Mu O D J) x) ((X + Sigma O (Mu O D J)))
(rearrange J (Mu O D J) c) (cases Y P)
(split {I + O} (cases (\i j -> f (i , j))
(\o v -> induction D J X c Y f P p o v))) v) | {
"alphanum_fraction": 0.3844901282,
"avg_line_length": 37.7923076923,
"ext": "agda",
"hexsha": "4e439e1d2e4594da5ecbb14fb1e15ca3c456b465",
"lang": "Agda",
"max_forks_count": 12,
"max_forks_repo_forks_event_max_datetime": "2022-02-11T01:57:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-08-14T21:36:35.000Z",
"max_forks_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mietek/epigram",
"max_forks_repo_path": "models/Containers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"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": "mietek/epigram",
"max_issues_repo_path": "models/Containers.agda",
"max_line_length": 95,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "8c46f766bddcec2218ddcaa79996e087699a75f2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mietek/epigram",
"max_stars_repo_path": "models/Containers.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T01:55:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-09T17:36:19.000Z",
"num_tokens": 1922,
"size": 4913
} |
module Everything where
-- basic utilities
open import Library
open import Isomorphism
-- basic category theory
open import Categories
open import Categories.Sets
open import Categories.Families
open import Categories.Initial
open import Categories.Terminal
open import Categories.CoProducts
open import Categories.PushOuts
open import Categories.Setoids -- should be replaced by standard libary def
open import Functors
open import Functors.Fin
open import Functors.FullyFaithful
open import Naturals
-- basic examples
open import Monoids
open import FunctorCat
-- ordinary monads
open import Monads
open import Monads.MonadMorphs
open import Adjunctions
open import Adjunctions.Adj2Mon
open import Monads.Kleisli
open import Monads.Kleisli.Functors
open import Monads.Kleisli.Adjunction
open import Monads.EM
open import Monads.EM.Functors
open import Monads.EM.Adjunction
open import Monads.CatofAdj
open import Monads.CatofAdj.InitAdj
open import Monads.CatofAdj.TermAdjObj
open import Monads.CatofAdj.TermAdjHom
open import Monads.CatofAdj.TermAdjUniq
open import Monads.CatofAdj.TermAdj
-- relative monads
open import RMonads
open import RMonads.RMonadMorphs
open import RAdjunctions
open import RAdjunctions.RAdj2RMon
open import RMonads.REM
open import RMonads.REM.Functors
open import RMonads.REM.Adjunction
open import RMonads.RKleisli
open import RMonads.RKleisli.Functors
open import RMonads.RKleisli.Adjunction
open import RMonads.Restriction
open import RMonads.SpecialCase
open import RMonads.CatofRAdj
open import RMonads.CatofRAdj.InitRAdj
open import RMonads.CatofRAdj.TermRAdjObj
open import RMonads.CatofRAdj.TermRAdjHom
open import RMonads.CatofRAdj.TermRAdj
open import RMonads.Modules
-- rmonad examples
open import WellScopedTerms
open import WellScopedTermsModel
open import WellTypedTerms
open import WellTypedTermsModel
open import Lawvere
| {
"alphanum_fraction": 0.8530351438,
"avg_line_length": 26.0833333333,
"ext": "agda",
"hexsha": "fe70ae438e865cc0c32bbb52a9c87e38bcc94a9d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Everything.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Everything.agda",
"max_line_length": 75,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 517,
"size": 1878
} |
open import Auto
open import Algebra
open import Data.List using (_∷_; [];_++_;List)
open import Data.Nat using (ℕ; suc; zero; _+_)
open import Data.Product using (_×_; ∃₂; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; cong; sym)
open import Reflection
module Auto.Example.Even where
private
n+0≡n : ∀ n → n + 0 ≡ n
n+0≡n zero = refl
n+0≡n (suc n) = cong suc (n+0≡n n)
m+1+n≡1+m+n : ∀ m n → m + suc n ≡ suc (m + n)
m+1+n≡1+m+n zero n = refl
m+1+n≡1+m+n (suc m) n = cong suc (m+1+n≡1+m+n m n)
data Even : ℕ → Set where
isEven0 : Even 0
isEven+2 : ∀ {n} → Even n → Even (suc (suc n))
even+ : ∀ {n m} → Even n → Even m → Even (n + m)
even+ isEven0 e2 = e2
even+ (isEven+2 e1) e2 = isEven+2 (even+ e1 e2)
isEven-2 : ∀ {n} → Even (2 + n) → Even n
isEven-2 (isEven+2 n) = n
simple : ∀ {n} → Even n → Even (n + 2)
simple e = even+ e (isEven+2 isEven0)
rules : HintDB
rules = [] << quote isEven0
<< quote isEven+2
<< quote even+
test₁ : Even 4
test₁ = tactic (auto 5 rules)
test₂ : ∀ {n} → Even n → Even (n + 2)
test₂ = tactic (auto 5 rules)
test₃ : ∀ {n} → Even n → Even (4 + n)
test₃ = tactic (auto 5 rules)
test₄ : ∀ {n} → Even n → Even (n + 2)
test₄ = tactic (auto 5 rules)
-- attempting to prove an impossible goal (e.g. evenness of n + 3
-- for all n) will result in searchSpaceExhausted
goal₁ = quoteTerm (∀ {n} → Even n → Even (n + 3))
fail₁ : unquote (auto 5 rules goal₁) ≡ throw searchSpaceExhausted
fail₁ = refl
-- attempting to convert an unsupported expression (e.g. a lambda
-- term) will result in unsupportedSyntax
goal₂ = quoteTerm (∃₂ λ m n → Even (m + n))
fail₂ : unquote (auto 5 rules goal₂) ≡ throw unsupportedSyntax
fail₂ = refl
| {
"alphanum_fraction": 0.5904139434,
"avg_line_length": 29.1428571429,
"ext": "agda",
"hexsha": "28cca0cdc7eec2bb2af85b82a9a5d26534ba7ba9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2019-07-07T07:37:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-10T10:47:30.000Z",
"max_forks_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/AutoInAgda",
"max_forks_repo_path": "src/Auto/Example/Even.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_issues_repo_issues_event_max_datetime": "2017-11-06T16:49:27.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-11-03T09:46:19.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wenkokke/AutoInAgda",
"max_issues_repo_path": "src/Auto/Example/Even.agda",
"max_line_length": 88,
"max_stars_count": 22,
"max_stars_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/AutoInAgda",
"max_stars_repo_path": "src/Auto/Example/Even.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-20T15:04:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-07-18T18:14:09.000Z",
"num_tokens": 699,
"size": 1836
} |
{-# OPTIONS --rewriting #-}
--{-# OPTIONS --exact-split #-}
--{-# OPTIONS --show-implicit #-}
module NaturalDeduction
where
module CustomPrelude where
open import Prelude public
renaming (_==_ to _≟_) -- TODO ask Agda to rename Eq._==_ to Eq._≟_
hiding (force) -- needed by ∞Delay
{-# BUILTIN REWRITE _≡_ #-}
{-# DISPLAY Eq._==_ _ = _≟_ #-}
open import Container.List renaming (_∈_ to _∈C_; lookup∈ to lookup∈C) public
_∈C?_ : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ (a : A) → (xs : List A) → Dec (a ∈C xs)
a ∈C? [] = no λ ()
a ∈C? (x ∷ xs) with a ≟ x
… | yes a≡x rewrite a≡x = yes (zero refl)
… | no a≢x with a ∈C? xs
… | yes a∈xs = yes (suc a∈xs)
… | no a∉xs = no (λ {(zero a≡x) → a≢x a≡x ; (suc a∈xs) → a∉xs a∈xs})
_≢_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ
x ≢ y = ¬ (x ≡ y)
infix 0 _↔_
_↔_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
P ↔ Q = (P → Q) × (Q → P)
infix 0 _←⊗→_
_←⊗→_ : {ℓ¹ : Level} → Set ℓ¹ → {ℓ² : Level} → Set ℓ² → Set (ℓ¹ ⊔ ℓ²)
P ←⊗→ Q = (P → ¬ Q) × (Q → ¬ P)
∃ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
∃ = Σ _
∄ : ∀ {ℓᴬ ℓᴮ} {A : Set ℓᴬ} (B : A → Set ℓᴮ) → Set (ℓᴬ ⊔ ℓᴮ)
∄ = ¬_ ∘ ∃
infixl 4 _⊎_
_⊎_ = Either
{-# DISPLAY Either = _⊎_ #-}
--open import Agda.Builtin.Size public
open import Size public
open import Control.Monad.State public
open import Control.Monad.Identity public
open import Container.Traversable public
sequence : ∀ {a b} {A : Set a} {F : Set a → Set b} ⦃ _ : Applicative F ⦄ → List (F A) → F ⊤′
sequence [] = pure tt
sequence (x ∷ xs) = x *> sequence xs
open import Tactic.Nat public
open import Tactic.Deriving.Eq public
mutual
data Delay (i : Size) (A : Set) : Set where
now : A → Delay i A
later : ∞Delay i A → Delay i A
record ∞Delay (i : Size) (A : Set) : Set where
coinductive
field
force : {j : Size< i} → Delay j A
open ∞Delay public
module BindDelay
where
mutual
bindDelay : ∀ {i A B} → Delay i A → (A → Delay i B) → Delay i B
bindDelay (now a) f = f a
bindDelay (later ∞a) f = later (bind∞Delay ∞a f)
bind∞Delay : ∀ {i A B} → ∞Delay i A → (A → Delay i B) → ∞Delay i B
force (bind∞Delay ∞a f) = bindDelay (force ∞a) f
module _
where
open BindDelay
open BindDelay public using () renaming (bind∞Delay to _∞>>=_)
instance FunctorDelay : {i : Size} → Functor (Delay i)
Functor.fmap FunctorDelay f x = bindDelay x $ now ∘ f
instance ApplicativeDelay : {i : Size} → Applicative (Delay i)
Applicative.pure ApplicativeDelay x = now x
Applicative._<*>_ ApplicativeDelay (now f) x = f <$> x
Applicative._<*>_ ApplicativeDelay (later ∞f) x = later ∘ bind∞Delay ∞f $ flip fmap x
Applicative.super ApplicativeDelay = FunctorDelay
instance MonadDelay : {i : Size} → Monad (Delay i)
Monad._>>=_ MonadDelay = bindDelay
Monad.super MonadDelay = ApplicativeDelay
{-# DISPLAY BindDelay.bindDelay x f = x >>= f #-}
mutual
data _∼_ {i : Size} {A : Set} : (a? b? : Delay ∞ A) → Set where
∼now : ∀ a → now a ∼ now a
∼later : ∀ {a∞ b∞} (eq : a∞ ∞∼⟨ i ⟩∼ b∞) → later a∞ ∼ later b∞
_∼⟨_⟩∼_ = λ {A} a? i b? → _∼_ {i}{A} a? b?
record _∞∼⟨_⟩∼_ {A} (a∞ : ∞Delay ∞ A) i (b∞ : ∞Delay ∞ A) : Set where
coinductive
field
∼force : {j : Size< i} → force a∞ ∼⟨ j ⟩∼ force b∞
open _∞∼⟨_⟩∼_ public
_∞∼_ = λ {i} {A} a∞ b∞ → _∞∼⟨_⟩∼_ {A} a∞ i b∞
mutual
∼refl : ∀{i A} (a? : Delay ∞ A) → a? ∼⟨ i ⟩∼ a?
∼refl (now a) = ∼now a
∼refl (later a∞) = ∼later (∞∼refl a∞)
∞∼refl : ∀{i A} (a∞ : ∞Delay ∞ A) → a∞ ∞∼⟨ i ⟩∼ a∞
∼force (∞∼refl a∞) = ∼refl (force a∞)
mutual
∼sym : ∀{i A}{a? b? : Delay ∞ A } → a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ a?
∼sym (∼now a) = ∼now a
∼sym (∼later eq) = ∼later (∞∼sym eq)
∞∼sym : ∀{i A}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ a∞
∼force (∞∼sym eq) = ∼sym (∼force eq)
mutual
∼trans : ∀{i A}{a? b? c? : Delay ∞ A} →
a? ∼⟨ i ⟩∼ b? → b? ∼⟨ i ⟩∼ c? → a? ∼⟨ i ⟩∼ c?
∼trans (∼now a) (∼now .a) = ∼now a
∼trans (∼later eq) (∼later eq′) = ∼later (∞∼trans eq eq′)
∞∼trans : ∀{i A}{a∞ b∞ c∞ : ∞Delay ∞ A} →
a∞ ∞∼⟨ i ⟩∼ b∞ → b∞ ∞∼⟨ i ⟩∼ c∞ → a∞ ∞∼⟨ i ⟩∼ c∞
∼force (∞∼trans eq eq′) = ∼trans (∼force eq) (∼force eq′)
--∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
--∞∼setoid : (i : Size) (A : Set) → Setoid lzero lzero
mutual
bind-assoc : ∀{i A B C} (m : Delay ∞ A)
{k : A → Delay ∞ B} {l : B → Delay ∞ C} →
((m >>= k) >>= l) ∼⟨ i ⟩∼ (m >>= λ a → (k a >>= l))
bind-assoc (now a) = ∼refl _
bind-assoc (later a∞) = ∼later (∞bind-assoc a∞)
∞bind-assoc : ∀{i A B C} (a∞ : ∞Delay ∞ A)
{k : A → Delay ∞ B} {l : B → Delay ∞ C} →
((a∞ ∞>>= k) ∞>>= l) ∞∼⟨ i ⟩∼ (a∞ ∞>>= λ a → (k a >>= l))
∼force (∞bind-assoc a∞) = bind-assoc (force a∞)
mutual
bind-cong-l : ∀{i A B}{a? b? : Delay ∞ A} → a? ∼⟨ i ⟩∼ b? →
(k : A → Delay ∞ B) → (a? >>= k) ∼⟨ i ⟩∼ (b? >>= k)
bind-cong-l (∼now a) k = ∼refl _
bind-cong-l (∼later eq) k = ∼later (∞bind-cong-l eq k)
∞bind-cong-l : ∀{i A B}{a∞ b∞ : ∞Delay ∞ A} → a∞ ∞∼⟨ i ⟩∼ b∞ →
(k : A → Delay ∞ B) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (b∞ ∞>>= k)
∼force (∞bind-cong-l eq k) = bind-cong-l (∼force eq) k
mutual
bind-cong-r : ∀{i A B}(a? : Delay ∞ A){k l : A → Delay ∞ B} →
(∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a? >>= k) ∼⟨ i ⟩∼ (a? >>= l)
bind-cong-r (now a) h = h a
bind-cong-r (later a∞) h = ∼later (∞bind-cong-r a∞ h)
∞bind-cong-r : ∀{i A B}(a∞ : ∞Delay ∞ A){k l : A → Delay ∞ B} →
(∀ a → (k a) ∼⟨ i ⟩∼ (l a)) → (a∞ ∞>>= k) ∞∼⟨ i ⟩∼ (a∞ ∞>>= l)
∼force (∞bind-cong-r a∞ h) = bind-cong-r (force a∞) h
map-compose : ∀{i A B C} (a? : Delay ∞ A) {f : A → B} {g : B → C} →
(g <$> (f <$> a?)) ∼⟨ i ⟩∼ ((g ∘ f) <$> a?)
map-compose a? = bind-assoc a?
map-cong : ∀{i A B}{a? b? : Delay ∞ A} (f : A → B) →
a? ∼⟨ i ⟩∼ b? → (f <$> a?) ∼⟨ i ⟩∼ (f <$> b?)
map-cong f eq = bind-cong-l eq (now ∘ f)
data _⇓_ {A : Set} : (a? : Delay ∞ A) (a : A) → Set where
now⇓ : ∀{a} → now a ⇓ a
later⇓ : ∀{a} {a∞ : ∞Delay ∞ A} → force a∞ ⇓ a → later a∞ ⇓ a
_⇓ : {A : Set} (x : Delay ∞ A) → Set
x ⇓ = ∃ λ a → x ⇓ a
map⇓ : ∀{A B}{a : A}{a? : Delay ∞ A}(f : A → B) → a? ⇓ a → (f <$> a?) ⇓ f a
map⇓ f now⇓ = now⇓
map⇓ f (later⇓ a⇓) = later⇓ (map⇓ f a⇓)
bind⇓ : ∀{A B}(f : A → Delay ∞ B){?a : Delay ∞ A}{a : A}{b : B} →
?a ⇓ a → f a ⇓ b → (?a >>= f) ⇓ b
bind⇓ f now⇓ q = q
bind⇓ f (later⇓ p) q = later⇓ (bind⇓ f p q)
infixl 4 _>>=⇓_
_>>=⇓_ : ∀{A B}{f : A → Delay ∞ B}{?a : Delay ∞ A}{a : A}{b : B} →
?a ⇓ a → f a ⇓ b → (?a >>= f) ⇓ b
_>>=⇓_ = bind⇓ _
infixl 4 _⇓>>=⇓_
_⇓>>=⇓_ : ∀{A B}{f : A → Delay ∞ B}{?a : Delay ∞ A}{b : B} →
(?a⇓ : ?a ⇓) → f (fst ?a⇓) ⇓ b → (?a >>= f) ⇓ b
_⇓>>=⇓_ (_ , a⇓) = bind⇓ _ a⇓
_⇓Dec>>=⇓_else⇓_ : ∀{A B}{f-yes : A → Delay ∞ B}{f-no : ¬ A → Delay ∞ B}{?a : Delay ∞ (Dec A)}{b : B} →
(?a⇓ : ?a ⇓) →
((a : A) → f-yes a ⇓ b) →
((¬a : ¬ A) → f-no ¬a ⇓ b) →
((?a >>= (λ { (yes y) → f-yes y ; (no n) → f-no n }))) ⇓ b
(yes y , y⇓) ⇓Dec>>=⇓ fy⇓ else⇓ fn⇓ = y⇓ >>=⇓ fy⇓ y
(no n , n⇓) ⇓Dec>>=⇓ fy⇓ else⇓ fn⇓ = n⇓ >>=⇓ fn⇓ n
_⇓DecEq>>=⇓_else⇓_ : ∀{A : Set} {A₁ A₂ : A} {B}{f-yes : A₁ ≡ A₂ → Delay ∞ B}{f-no : A₁ ≢ A₂ → Delay ∞ B}{?a : Delay ∞ (Dec (A₁ ≡ A₂))}{b : B} →
(?a⇓ : ?a ⇓) →
((eq : A₁ ≡ A₂) → f-yes eq ⇓ b) →
((¬eq : A₁ ≢ A₂) → f-no ¬eq ⇓ b) →
((?a >>= (λ { (yes refl) → f-yes refl ; (no n) → f-no n }))) ⇓ b
(yes refl , y⇓) ⇓DecEq>>=⇓ fy⇓ else⇓ fn⇓ = y⇓ >>=⇓ fy⇓ refl
(no n , n⇓) ⇓DecEq>>=⇓ fy⇓ else⇓ fn⇓ = n⇓ >>=⇓ fn⇓ n
app⇓ : ∀{A}{B}{f? : Delay ∞ (A → B)}{f : A → B}{x? : Delay ∞ A}{x : A} → f? ⇓ f → x? ⇓ x → (f? <*> x?) ⇓ f x
app⇓ now⇓ now⇓ = now⇓
app⇓ now⇓ (later⇓ x?) = later⇓ $ map⇓ _ x?
app⇓ (later⇓ f?) now⇓ = later⇓ $ bind⇓ _ f? now⇓
app⇓ (later⇓ ⇓f) (later⇓ ⇓x) = later⇓ $ bind⇓ _ ⇓f $ later⇓ $ bind⇓ _ ⇓x now⇓
subst∼⇓ : ∀{A}{a? a?′ : Delay ∞ A}{a : A} → a? ⇓ a → a? ∼ a?′ → a?′ ⇓ a
subst∼⇓ now⇓ (∼now a) = now⇓
subst∼⇓ (later⇓ p) (∼later eq) = later⇓ (subst∼⇓ p (∼force eq))
{-
traverse⇓' : ∀{A}{B}{f? : A → Delay ∞ B}{T : Set → Set}⦃ _ : Traversable T ⦄{X : T A} → (∀ x → f? x ⇓) → ∀ (x : T A) → traverse f? x ⇓
traverse⇓' x₁ x₂ = {!!} , {!!}
-}
{-
traverse⇓ : ∀{A}{B}{f : A → B}{T : Set → Set}⦃ _ : Traversable T ⦄{X : T A} → (∀ x → f? x ⇓) → ∀ (x : T A) → traverse f x ⇓
traverse⇓ x₁ x₂ = {!!} , {!!}
-}
traverse-list⇓ : ∀{A}{B} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : List A) → traverse f? xs ⇓
traverse-list⇓ f? f?⇓ [] = [] , now⇓
traverse-list⇓ f? f?⇓ (x ∷ xs)
with f?⇓ x | traverse-list⇓ f? f?⇓ xs
… | y , y⇓ | ys , ys⇓ = y ∷ ys , app⇓ (map⇓ _ y⇓) ys⇓
{-
traverse-vec⇓' : ∀{A}{B}{𝑎} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : Vector A 𝑎) → traverse f? xs ⇓
traverse-vec⇓' f? f?⇓ [] = [] , now⇓
traverse-vec⇓' f? f?⇓ (x ∷ xs)
with f?⇓ x | traverse-vec⇓' f? f?⇓ xs
… | y , y⇓ | ys , ys⇓ = y ∷ ys , app⇓ (map⇓ _ y⇓) ys⇓
traverse-vec⇓ : ∀{A}{B}{𝑎} (f : A → B) → (xs : Vector (Delay ∞ A) 𝑎) → traverse {!f!} xs ⇓
traverse-vec⇓ = {!!}
-}
{-
traverse-vec⇓ : ∀{A}{B}{𝑎} (f? : A → Delay ∞ B) → (∀ x → f? x ⇓) → (xs : Vec A 𝑎) → traverse {!f!} xs ⇓
-}
open CustomPrelude
record Successor {ℓᴬ} (A : Set ℓᴬ) {ℓᴮ} (B : Set ℓᴮ) : Set (ℓᴬ ⊔ ℓᴮ)
where
field
⊹ : A → B
open Successor ⦃ … ⦄
instance SuccessorNat : Successor Nat Nat
Successor.⊹ SuccessorNat = suc
instance SuccessorLevel : Successor Level Level
Successor.⊹ SuccessorLevel = lsuc
record Membership {ℓ} (m : Set ℓ) (M : Set ℓ) : Set (⊹ ℓ)
where
field
_∈_ : m → M → Set ℓ
_∉_ : m → M → Set ℓ
xor-membership : ∀ {x : m} {X : M} → x ∈ X ←⊗→ x ∉ X
open Membership ⦃ … ⦄
data _∈L_ {ℓ} {A : Set ℓ} (a : A) : List A → Set ℓ
where
zero : {as : List A} → a ∈L (a ∷ as)
suc : {x : A} {as : List A} → a ∈L as → a ∈L (x ∷ as)
instance Successor∈L : ∀ {ℓ} {A : Set ℓ} {a : A} {x : A} {as : List A} → Successor (a ∈L as) $ a ∈L (x ∷ as)
Successor.⊹ Successor∈L = suc
instance MembershipList : ∀ {ℓ} {A : Set ℓ} → Membership A $ List A
Membership._∈_ MembershipList = _∈L_
Membership._∉_ MembershipList x X = ¬ x ∈ X
Membership.xor-membership MembershipList = (λ x x₁ → x₁ x) , (λ x x₁ → x x₁)
record DecidableMembership {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set (⊹ ℓ)
where
field _∈?_ : (x : m) → (X : M) → Dec $ x ∈ X
field _∉?_ : (x : m) → (X : M) → Dec $ x ∉ X
open DecidableMembership ⦃ … ⦄
instance DecidableMembershipList : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → DecidableMembership A $ List A
DecidableMembership._∈?_ (DecidableMembershipList {ℓ} {A}) = _∈L?_
where
_∈L?_ : (a : A) → (xs : List A) → Dec (a ∈ xs)
a ∈L? [] = no λ ()
a ∈L? (x ∷ xs) with a ≟ x
… | yes a≡x rewrite a≡x = yes zero
… | no a≢x with a ∈L? xs
… | yes a∈xs = yes (⊹ a∈xs)
… | no a∉xs = no (λ {zero → a≢x refl ; (suc a∈xs) → a∉xs a∈xs})
DecidableMembership._∉?_ (DecidableMembershipList {ℓ} {A}) = {!!}
_⊆_ : ∀ {ℓ} {A : Set ℓ} → List A → List A → Set ℓ
_⊆_ {A = A} R S = ∀ {x : A} → x ∈ R → x ∈ S
record VariableName : Set
where
constructor ⟨_⟩
field
name : Nat
open VariableName
instance EqVariableName : Eq VariableName
Eq._==_ EqVariableName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
record FunctionName : Set
where
constructor ⟨_⟩
field
name : Nat
open FunctionName
instance EqFunctionName : Eq FunctionName
Eq._==_ EqFunctionName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
record PredicateName : Set
where
constructor ⟨_⟩
field
name : Nat
open PredicateName
instance EqPredicateName : Eq PredicateName
Eq._==_ EqPredicateName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
record Arity : Set
where
constructor ⟨_⟩
field
arity : Nat
open Arity
instance EqArity : Eq Arity
Eq._==_ EqArity _ = decEq₁ (cong arity) ∘ (_≟_ on arity $ _)
record Vector (A : Set) (𝑎 : Arity) : Set
where
constructor ⟨_⟩
field
vector : Vec A (arity 𝑎)
open Vector
instance EqVector : {A : Set} ⦃ _ : Eq A ⦄ {𝑎 : Arity} → Eq (Vector A 𝑎)
Eq._==_ EqVector _ = decEq₁ (cong vector) ∘ (_≟_ on vector $ _)
data ITerm : Nat → Set
where
variable : VariableName → ITerm zero
function : FunctionName → {arity : Nat} → (τs : Vec (Σ Nat ITerm) arity) → {n : Nat} → n ≡ sum (vecToList $ (fst <$> τs)) → ITerm (suc n)
mutual
eqITerm : ∀ {n} → (x y : ITerm n) → Dec (x ≡ y)
eqITerm = {!!}
{-
eqITerm : ∀ {n} → (x y : ITerm n) → Dec (x ≡ y)
eqITerm {.0} (variable x) (variable x₁) = {!!}
eqITerm {.(suc n)} (function x {arity = arity₁} τs {n = n} x₁) (function x₂ {arity = arity₂} τs₁ {n = .n} x₃) with x ≟ x₂ | arity₁ ≟ arity₂
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function .x {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) with eqITerms τs τs₁
eqITerm {.(suc n)} (function x₁ {arity₁} τs {n} x₄) (function .x₁ {.arity₁} .τs {.n} x₅) | yes refl | (yes refl) | (yes refl) rewrite x₄ | x₅ = yes refl
eqITerm {.(suc n)} (function x₁ {arity₁} τs {n} x₄) (function .x₁ {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) | (no x) = {!!}
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | yes x₁ | (no x₃) = {!!}
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (yes x₃) = {!!}
eqITerm {.(suc n)} (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (no x₃) = {!!}
-}
eqITerms : ∀ {n} → (x y : Vec (Σ Nat ITerm) n) → Dec (x ≡ y)
eqITerms {.0} [] [] = {!!}
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) with fst₁ ≟ fst₂
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl with eqITerm snd₁ snd₂
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | yes refl with eqITerms x₁ y
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | yes refl | yes refl = yes refl
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | yes refl | no ref = {!!}
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | yes refl | no ref = {!!}
eqITerms (_∷_ {n = n} (fst₁ , snd₁) x₁) (_∷_ {n = .n} (fst₂ , snd₂) y) | no ref = {!!}
instance EqITerm : ∀ {n} → Eq (ITerm n)
Eq._==_ EqITerm = eqITerm
{-
instance EqITerm : ∀ {n} → Eq (ITerm n)
Eq._==_ EqITerm (variable x) (variable x₁) = {!!}
Eq._==_ EqITerm (function x {arity = arity₁} τs {n = n} x₁) (function x₂ {arity = arity₂} τs₁ {n = .n} x₃) with x ≟ x₂ | arity₁ ≟ arity₂
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function .x {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) with τs ≟ τs₁
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function .x {.arity₁} τs₁ {.n} x₅) | yes refl | (yes refl) | τs≡τs₁ = {!!}
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | yes x₁ | (no x₃) = {!!}
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (yes x₃) = {!!}
Eq._==_ EqITerm (function x {arity₁} τs {n} x₄) (function x₂ {arity₂} τs₁ {.n} x₅) | no x₁ | (no x₃) = {!!}
-}
mutual
data Term : Set
where
variable : VariableName → Term
function : FunctionName → Terms → Term
record Terms : Set
where
constructor ⟨_⟩
inductive
field
{arity} : Arity
terms : Vector Term arity
open Terms
termVariable-inj : ∀ {𝑥₁ 𝑥₂} → Term.variable 𝑥₁ ≡ variable 𝑥₂ → 𝑥₁ ≡ 𝑥₂
termVariable-inj refl = refl
termFunction-inj₁ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → 𝑓₁ ≡ 𝑓₂
termFunction-inj₁ refl = refl
termFunction-inj₂ : ∀ {𝑓₁ 𝑓₂ τ₁s τ₂s} → Term.function 𝑓₁ τ₁s ≡ function 𝑓₂ τ₂s → τ₁s ≡ τ₂s
termFunction-inj₂ refl = refl
terms-inj : ∀ {𝑎} → {τs₁ τs₂ : Vector Term 𝑎} → (τs₁≡τs₂ : (Terms.⟨_⟩ {𝑎} τs₁) ≡ ⟨ τs₂ ⟩) → τs₁ ≡ τs₂
terms-inj refl = refl
mutual
termToITerm : Term → Σ Nat ITerm
termToITerm (variable x) = _ , (variable x)
termToITerm (function x x₁) = {!!}
termsToVec : Terms → Σ Nat (λ arity → Σ (Vec (Σ Nat ITerm) arity) λ τs → Σ Nat λ n → n ≡ sum (vecToList $ (fst <$> τs)))
termsToVec (⟨_⟩ {arity = arity₁} ⟨ vector₁ ⟩) = {!!}
iTermToTerm : Σ Nat ITerm → Term
iTermToTerm = {!!}
eq-term-round : ∀ τ → iTermToTerm (termToITerm τ) ≡ τ
eq-term-round = {!!}
eq-iterm-round : ∀ τ → termToITerm (iTermToTerm τ) ≡ τ
eq-iterm-round = {!!}
instance EqTerm : Eq Term
Eq._==_ EqTerm x y with termToITerm x | graphAt termToITerm x | termToITerm y | graphAt termToITerm y
Eq._==_ EqTerm x y | ix | ingraph eqx | iy | ingraph eqy with ix ≟ iy
Eq._==_ EqTerm x y | ix | ingraph eqx | .ix | ingraph eqy | yes refl = yes $ ((cong iTermToTerm eqy ⟨≡⟩ʳ cong iTermToTerm eqx) ⟨≡⟩ eq-term-round x) ʳ⟨≡⟩ eq-term-round y
Eq._==_ EqTerm x y | ix | ingraph eqx | iy | ingraph eqy | no neq = {!!}
instance EqTerms : Eq Terms
EqTerms = {!!}
{-
module _ {i : Size}
where
mutual
EqTerm⇑ : (x y : Term) → Delay i ∘ Dec $ x ≡ y
EqTerm⇑ (variable _) (variable _) = now (decEq₁ termVariable-inj $ _≟_ _ _)
EqTerm⇑ (function 𝑓₁ τ₁s) (function 𝑓₂ τ₂s) =
{-
τ₁s≟τ₂s ← EqTerms⇑ τ₁s τ₂s -|
(now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s)
-}
EqTerms⇑ τ₁s τ₂s >>= λ
τ₁s≟τ₂s → now $ decEq₂ termFunction-inj₁ termFunction-inj₂ (𝑓₁ ≟ 𝑓₂) τ₁s≟τ₂s
EqTerm⇑ (variable _) (function _ _) = now $ no λ ()
EqTerm⇑ (function _ _) (variable _) = now $ no λ ()
EqTerms⇑ : (x y : Terms) → Delay i ∘ Dec $ x ≡ y
EqTerms⇑ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s)
with 𝑎₁ ≟ 𝑎₂
… | no 𝑎₁≢𝑎₂ = now $ no λ {τ₁≡τ₂ → 𝑎₁≢𝑎₂ (cong arity τ₁≡τ₂)}
… | yes refl =
EqVectorTerm⇑ τ₁s τ₂s >>= λ
{ (yes refl) → now $ yes refl
; (no τ₁s≢τ₂s) → now $ no (λ ⟨τ₁s⟩≡⟨τ₂s⟩ → τ₁s≢τ₂s (terms-inj ⟨τ₁s⟩≡⟨τ₂s⟩)) }
EqVectorTerm⇑ : ∀ {n} → (x y : Vector Term n) → Delay i ∘ Dec $ x ≡ y
EqVectorTerm⇑ ⟨ [] ⟩ ⟨ [] ⟩ = now (yes refl)
EqVectorTerm⇑ ⟨ τ₁ ∷ τ₁s ⟩ ⟨ τ₂ ∷ τ₂s ⟩ =
EqTerm⇑ τ₁ τ₂ >>= λ
{ (yes refl) → EqVectorTerm⇑ ⟨ τ₁s ⟩ ⟨ τ₂s ⟩ >>= λ
{ (yes refl) → now $ yes refl
; (no τ₁s≢τ₂s) → now $ no λ τ₁₁s≡τ₁₂s → τ₁s≢τ₂s $ cong ⟨_⟩ ((vcons-inj-tail (cong vector τ₁₁s≡τ₁₂s))) }
; (no τ₁≢τ₂) → now $ no λ τ₁₁s≡τ₂₂s → τ₁≢τ₂ $ vcons-inj-head (cong vector τ₁₁s≡τ₂₂s) }
EqVectorTerm⇓ : ∀ {n} → (x y : Vector Term n) → EqVectorTerm⇑ x y ⇓
EqVectorTerm⇓ ⟨ [] ⟩ ⟨ [] ⟩ = _ , now⇓
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable 𝑥₂ ∷ τ₂s ⟩
with 𝑥₁ ≟ 𝑥₂
… | yes refl with EqVectorTerm⇓ ⟨ τ₁s ⟩ ⟨ τ₂s ⟩
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable .𝑥₁ ∷ .τ₁s ⟩ | yes refl | (yes refl , snd₁) = _ , snd₁ >>=⇓ now⇓
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable .𝑥₁ ∷ τ₂s ⟩ | yes refl | (no x , snd₁) = _ , snd₁ >>=⇓ now⇓
EqVectorTerm⇓ ⟨ variable 𝑥₁ ∷ τ₁s ⟩ ⟨ variable 𝑥₂ ∷ τ₂s ⟩ | no 𝑥₁≢𝑥₂ = _ , now⇓
EqVectorTerm⇓ ⟨ variable x ∷ τ₁s ⟩ ⟨ function x₁ x₂ ∷ τ₂s ⟩ = _ , now⇓
EqVectorTerm⇓ ⟨ function x x₁ ∷ τ₁s ⟩ ⟨ variable x₂ ∷ τ₂s ⟩ = _ , now⇓
EqVectorTerm⇓ ⟨ function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s ⟩ ⟨ function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s ⟩
with 𝑎₁ ≟ 𝑎₂ | 𝑓₁ ≟ 𝑓₂
… | no 𝑎₁≢𝑎₂ | no 𝑓₁≢𝑓₂ = _ , now⇓
… | no 𝑎₁≢𝑎₂ | yes refl = _ , now⇓
… | yes refl | no 𝑓₁≢𝑓₂
with EqVectorTerm⇓ τ₁s τ₂s
… | (no τ₁s≢τ₂s , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
… | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
EqVectorTerm⇓ ⟨ function 𝑓₁ (⟨_⟩ {𝑎₁} τ₁s) ∷ τ₁₂s ⟩ ⟨ function 𝑓₂ (⟨_⟩ {𝑎₂} τ₂s) ∷ τ₂₂s ⟩ | yes refl | yes refl
with EqVectorTerm⇓ τ₁s τ₂s | EqVectorTerm⇓ ⟨ τ₁₂s ⟩ ⟨ τ₂₂s ⟩
… | (no τ₁s≢τ₂s , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
… | (yes refl , τ⇓) | (no τ₁₂s≢τ₂₂s , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓)
… | (no τ₁s≢τ₂s , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ now⇓
… | (yes refl , τ⇓) | (yes refl , τs⇓) = _ , τ⇓ >>=⇓ now⇓ >>=⇓ now⇓ >>=⇓ (τs⇓ >>=⇓ now⇓)
EqTerms⇓ : (x y : Terms) → EqTerms⇑ x y ⇓
EqTerms⇓ (⟨_⟩ {𝑎₁} τ₁s) (⟨_⟩ {𝑎₂} τ₂s)
with 𝑎₁ ≟ 𝑎₂
… | no 𝑎₁≢𝑎₂ = _ , now⇓
… | yes refl
with EqVectorTerm⇓ τ₁s τ₂s
… | (yes refl , τ⇓) = _ , τ⇓ >>=⇓ now⇓
… | (no _ , τ⇓) = _ , τ⇓ >>=⇓ now⇓
EqTerm⇓ : (x y : Term) → EqTerm⇑ x y ⇓
EqTerm⇓ (variable x) (variable x₁) = _ , now⇓
EqTerm⇓ (function _ τ₁s) (function _ τ₂s)
with EqTerms⇓ τ₁s τ₂s
… | (_ , τ⇓) = _ , τ⇓ >>=⇓ now⇓
EqTerm⇓ (variable x) (function x₁ x₂) = _ , now⇓
EqTerm⇓ (function x x₁) (variable x₂) = _ , now⇓
instance EqTerm : Eq Term
EqTerm = record { _==_ = λ x y → fst (EqTerm⇓ x y) }
instance EqTerms : Eq Terms
Eq._==_ EqTerms x y = fst (EqTerms⇓ x y)
-}
record Unifiable (F : Set) (T : Set) (U₁ U₂ : Set) (σ : (T → F) → F → F) : Set₁ where
field
_≈u≈_ : (φ₁ φ₂ : F) → Set
unifier : (φ₁ φ₂ : F) → φ₁ ≈u≈ φ₂ → (F → F) × (F → F)
unifier-law : (φ₁ φ₂ : F) → (=u= : φ₁ ≈u≈ φ₂) → (let u = unifier φ₁ φ₂ =u=) → (fst u) φ₁ ≡ (snd u) φ₂
{-
{-# TERMINATING #-}
-- substitute 𝑥ₛ τₛ τ = τ, where all occurrences of 𝑥ₛ are replaced by τₛ
substitute : VariableName → Term → Term → Term
substitute 𝑥ₛ τₛ τ@(variable 𝑥) = ifYes 𝑥ₛ ≟ 𝑥 then τₛ else τ
substitute 𝑥ₛ τₛ (function 𝑓 ⟨ ⟨ τs ⟩ ⟩) = function 𝑓 ⟨ ⟨ substitute 𝑥ₛ τₛ <$> τs ⟩ ⟩
-}
mutual
substituteTerm⇑ : VariableName → Term → ∀ {i} → Term → Delay i Term
substituteTerm⇑ 𝑥ₛ τₛ τ@(variable 𝑥) = now $ ifYes 𝑥ₛ ≟ 𝑥 then τₛ else τ
substituteTerm⇑ 𝑥ₛ τₛ (function 𝑓 τs) =
substituteTerms⇑ 𝑥ₛ τₛ τs >>= λ τsₛ →
now $ function 𝑓 τsₛ
substituteTerms⇑ : VariableName → Term → ∀ {i} → Terms → Delay i Terms
substituteTerms⇑ 𝑥ₛ τₛ ⟨ ⟨ [] ⟩ ⟩ = now ⟨ ⟨ [] ⟩ ⟩
substituteTerms⇑ 𝑥ₛ τₛ ⟨ ⟨ τ ∷ τs ⟩ ⟩ =
let τs = substituteTerms⇑ 𝑥ₛ τₛ ⟨ ⟨ τs ⟩ ⟩
τ = substituteTerm⇑ 𝑥ₛ τₛ τ in
τs >>= λ { ⟨ ⟨ τs ⟩ ⟩ →
τ >>= λ { τ →
now $ ⟨ ⟨ τ ∷ τs ⟩ ⟩ } }
substituteTerms⇓ : (𝑥ₛ : VariableName) → (τₛ : Term) → (τs : Terms) → substituteTerms⇑ 𝑥ₛ τₛ τs ⇓
substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ [] ⟩ ⟩ = _ , now⇓
substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ (variable 𝑥) ∷ τs ⟩ ⟩ = _ , substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ now⇓
substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ (function 𝑓 τs₁) ∷ τs ⟩ ⟩ = _ , substituteTerms⇓ 𝑥ₛ τₛ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ ((substituteTerms⇓ 𝑥ₛ τₛ τs₁ ⇓>>=⇓ now⇓) >>=⇓ now⇓)
substituteTerm⇓ : (𝑥ₛ : VariableName) → (τₛ : Term) → (τ : Term) → substituteTerm⇑ 𝑥ₛ τₛ τ ⇓
substituteTerm⇓ 𝑥ₛ τₛ (variable 𝑥) = _ , now⇓
substituteTerm⇓ 𝑥ₛ τₛ (function 𝑓 τs) = _ , substituteTerms⇓ 𝑥ₛ τₛ τs ⇓>>=⇓ now⇓
substitute : VariableName → Term → Term → Term
substitute 𝑥ₛ τₛ τ = fst $ substituteTerm⇓ 𝑥ₛ τₛ τ
{-
record StructureSuitableForSubstitution : Set where
field
(∀ x xs → x ∈ xs → )
VariableConstructor : VariableName → Term
FunctionConstructor : FunctionName → (a : Nat) → (ts : Vec Term a) → Term
∀ v' → VariableConstructor v' ≡ τ → τₛ ≡ substitute 𝑥ₛ τₛ τ
∀ f' → FunctionConstructor f' ≡ τ → ∀ τ' → τ' ∈ τ → τₛ ≡ substitute 𝑥ₛ τₛ τ
constructor-bases : Vec Set #constructors
eq : ∀ x → x ∈ constructor-bases → Eq x
substitute : → constructor-base Structure → Structure
datatype-constructor₁ : constructor-base₁ → datatype
MEMBERSHIP : ELEMENT → STRUCTURE → Set
ELEMENT → MEMBERSHIP e s → Σ STRUCTURE
VariableConstructor → Term
FunctionConstructor → Term
substitute : VariableConstructor → Term → Term → Term
substitute
-}
instance MembershipTermTerms : Membership Term Terms
Membership._∈_ MembershipTermTerms = _ᵗ∈ᵗˢ_ where
data _ᵗ∈ᵗˢ_ (τ : Term) : Terms → Set
where
zero : τ ᵗ∈ᵗˢ ⟨ ⟨ τ ∷ [] ⟩ ⟩
suc : ∀ {τs} → τ ᵗ∈ᵗˢ τs → τ ᵗ∈ᵗˢ ⟨ ⟨ τ ∷ vector (terms τs) ⟩ ⟩
Membership._∉_ MembershipTermTerms x X = ¬ x ∈ X
fst (Membership.xor-membership MembershipTermTerms) x₁ x₂ = x₂ x₁
snd (Membership.xor-membership MembershipTermTerms) x₁ x₂ = x₁ x₂
instance MembershipVariableNameTerm : Membership VariableName Term
Membership._∈_ MembershipVariableNameTerm = _ᵛ∈ᵗ_ where
data _ᵛ∈ᵗ_ (𝑥 : VariableName) : Term → Set
where
variable : 𝑥 ᵛ∈ᵗ variable 𝑥
function : ∀ 𝑓 {τ : Term} {τs} → {_ : 𝑥 ∈ τ} → τ ∈ τs → 𝑥 ᵛ∈ᵗ function 𝑓 τs
Membership._∉_ MembershipVariableNameTerm x X = ¬ x ∈ X
fst (Membership.xor-membership MembershipVariableNameTerm) x₁ x₂ = x₂ x₁
snd (Membership.xor-membership MembershipVariableNameTerm) x₁ x₂ = x₁ x₂
data 𝕃 {𝑨} (𝐴 : Set 𝑨) : Set 𝑨
data _∉𝕃_ {𝑨} {𝐴 : Set 𝑨} (x : 𝐴) : 𝕃 𝐴 → Set 𝑨
data 𝕃 {𝑨} (𝐴 : Set 𝑨) where
∅ : 𝕃 𝐴
✓ : {x₀ : 𝐴} → {x₁s : 𝕃 𝐴} → x₀ ∉𝕃 x₁s → 𝕃 𝐴
instance Successor𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} → {x₀ : 𝐴} → {x₁s : 𝕃 𝐴} → Successor (x₀ ∉𝕃 x₁s) (𝕃 𝐴)
Successor.⊹ Successor𝕃 = ✓
data _∉𝕃_ {𝑨} {𝐴 : Set 𝑨} (𝔞 : 𝐴) where
∅ : 𝔞 ∉𝕃 ∅
● : ∀ {x₀} → 𝔞 ≢ x₀ → ∀ {x₁s} → 𝔞 ∉𝕃 x₁s → (x₀∉x₁s : x₀ ∉𝕃 x₁s) → 𝔞 ∉𝕃 ✓ x₀∉x₁s
data _∈𝕃_ {𝑨} {𝐴 : Set 𝑨} : (𝔞 : 𝐴) → 𝕃 𝐴 → Set {-𝑨-} where
here : (𝔞 : 𝐴) {xs : 𝕃 𝐴} (𝔞∉xs : 𝔞 ∉𝕃 xs) → 𝔞 ∈𝕃 (✓ 𝔞∉xs)
there : {x : 𝐴} {xs : 𝕃 𝐴} (x∉xs : x ∉𝕃 xs) {𝔞 : 𝐴} → 𝔞 ∈𝕃 xs → 𝔞 ∈𝕃 ✓ x∉xs
∈→¬∉ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → x ∈𝕃 xs → ¬ x ∉𝕃 xs
∈→¬∉ {𝑨} {𝐴} {.𝔞} {.(✓ {_} {_} {𝔞} {xs} 𝔞∉xs)} (here 𝔞 {xs = xs} 𝔞∉xs) (● {x₀ = .𝔞} x {x₁s = .xs} x₂ .𝔞∉xs) = x refl
∈→¬∉ {𝑨} {𝐴} {x₁} {.(✓ {_} {_} {x} {∅} ∅)} (there {x = x} {xs = .∅} ∅ {𝔞 = .x₁} ()) (● {x₀ = .x} x₃ {x₁s = .∅} ∅ .∅)
∈→¬∉ {𝑨} {𝐴} {.𝔞} {.(✓ {_} {_} {x} {✓ {_} {_} {𝔞} {x₁s} x∉xs} (● {_} {_} {_} {𝔞} x₁ {x₁s} x∉xs₁ x∉xs))} (there {x = x} {xs = .(✓ {_} {_} {𝔞} {x₁s} x∉xs)} (● {x₀ = .𝔞} x₁ {x₁s = x₁s} x∉xs₁ x∉xs) {𝔞 = .𝔞} (here 𝔞 {xs = .x₁s} .x∉xs)) (● {x₀ = .x} x₃ {x₁s = .(✓ {_} {_} {𝔞} {x₁s} x∉xs)} (● {x₀ = .𝔞} x₂ {x₁s = .x₁s} x₄ .x∉xs) .(● {_} {_} {_} {𝔞} x₁ {x₁s} x∉xs₁ x∉xs)) = x₂ refl
∈→¬∉ {𝑨} {𝐴} {x} {.(✓ {_} {_} {x₁} {✓ {_} {_} {x₀} {x₁s} x∉xs} (● {_} {_} {_} {x₀} x₂ {x₁s} x∉xs₁ x∉xs))} (there {x = x₁} {xs = .(✓ {_} {_} {x₀} {x₁s} x∉xs)} (● {x₀ = x₀} x₂ {x₁s = x₁s} x∉xs₁ x∉xs) {𝔞 = .x} (there {x = .x₀} {xs = .x₁s} .x∉xs {𝔞 = .x} x₃)) (● {x₀ = .x₁} x₄ {x₁s = .(✓ {_} {_} {x₀} {x₁s} x∉xs)} (● {x₀ = .x₀} x₅ {x₁s = .x₁s} x₆ .x∉xs) .(● {_} {_} {_} {x₀} x₂ {x₁s} x∉xs₁ x∉xs)) = ∈→¬∉ x₃ x₆
∉→¬∈ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → x ∉𝕃 xs → ¬ x ∈𝕃 xs
∉→¬∈ {𝑨} {𝐴} {x} {.∅} ∅ ()
∉→¬∈ {𝑨} {𝐴} {.𝔞} {.(✓ {_} {_} {𝔞} {x₁s} x₁)} (● {x₀ = .𝔞} x {x₁s = x₁s} x₂ x₁) (here 𝔞 {xs = .x₁s} .x₁) = x refl
∉→¬∈ {𝑨} {𝐴} {x} {.(✓ {_} {_} {x₀} {x₁s} x₁)} (● {x₀ = x₀} x₂ {x₁s = x₁s} x₃ x₁) (there {x = .x₀} {xs = .x₁s} .x₁ {𝔞 = .x} x₄) = ∉→¬∈ x₃ x₄
foo : ∀ {𝑨} {𝐴 : Set 𝑨} {x x₀ : 𝐴} (x₁ : _≡_ {𝑨} {𝐴} x x₀) (x₂ : _∈𝕃_ {𝑨} {𝐴} x (✓ {_} {_} {x₀} {∅} ∅) → ⊥) → ⊥
foo {𝑨} {𝐴} {x} {.x} refl x₂ = x₂ (here x ∅)
foo₂ : (𝑨 : Level)
(𝐴 : Set 𝑨 )
(x₀ : 𝐴 )
(x₁s : 𝕃 𝐴 )
(x₁ : x₀ ∉𝕃 x₁s )
(x : 𝐴 )
(x₂ : 𝐴 )
(x₃ : x₂ ≡ x₀ → ⊥ )
(x₄ : x₂ ∉𝕃 x₁s )
(x₅ : ¬ (x ∈𝕃 ✓ (● x₃ x₄ x₁)) )
(x₆ : x ≡ x₂) → ⊥
foo₂ 𝑨 𝐴 x₀ x₁s x₁ x .x x₃ x₄ x₅ refl = x₅ (here x (● x₃ x₄ x₁)) -- x₅ (here x (● x₃ x₄ x₁))
foo₃ : (𝑨 : Level)
(𝐴 : Set 𝑨 )
(x₀ : 𝐴 )
(x₁s : 𝕃 𝐴 )
(x₁ : x₀ ∉𝕃 x₁s )
(x : 𝐴 )
(x₂ : 𝐴 )
(x₃ : x₂ ≡ x₀ → ⊥ )
(x₄ : x₂ ∉𝕃 x₁s )
(x₅ : ¬ (x ∈𝕃 ✓ (● x₃ x₄ x₁)) )
(x₆ : x ≡ x₀)
→ ⊥
foo₃ 𝑨 𝐴 x₀ x₁s x₁ .x₀ x₂ x₃ x₄ x₅ refl = x₅ (there (● x₃ x₄ x₁) (here x₀ x₁))
¬∈→∉ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → ¬ x ∈𝕃 xs → x ∉𝕃 xs
¬∈→∉ {𝑨} {𝐴} {x} {∅} x₁ = ∅
¬∈→∉ {𝑨} {𝐴} {x} {✓ {x₀ = x₀} {x₁s = .∅} ∅} x₂ = ● (λ {x₁ → foo x₁ x₂}) ∅ ∅
¬∈→∉ {𝑨} {𝐴} {x} {✓ {x₀ = x₂} {x₁s = .(✓ {_} {_} {x₀} {x₁s} x₁)} (● {x₀ = x₀} x₃ {x₁s = x₁s} x₄ x₁)} x₅ = ● (λ {x₆ → foo₂ 𝑨 𝐴 x₀ x₁s x₁ x x₂ x₃ x₄ x₅ x₆}) (● (λ {x₆ → foo₃ 𝑨 𝐴 x₀ x₁s x₁ _ x₂ x₃ x₄ x₅ x₆}) (¬∈→∉ (λ z → x₅ (there (● x₃ x₄ x₁) (there x₁ z)))) x₁) (● x₃ x₄ x₁)
¬∉→∈ : ∀ {𝑨} {𝐴 : Set 𝑨} {x : 𝐴} {xs : 𝕃 𝐴} → ¬ x ∉𝕃 xs → x ∈𝕃 xs
¬∉→∈ {𝑨} {𝐴} {x} {∅} x₁ = ⊥-elim (x₁ ∅)
¬∉→∈ {𝑨} {𝐴} {x} {✓ {x₀ = x₀} {x₁s = ∅} ∅} x₂ = {!⊥-elim!}
¬∉→∈ {𝑨} {𝐴} {x₁} {✓ {x₀ = x₂} {x₁s = ✓ {x₀ = x₀} {x₁s = x₁s} x} (● {x₀ = .x₀} x₃ {x₁s = .x₁s} x₄ .x)} x₅ = {!!}
pattern tail= x₁s = ✓ {x₁s = x₁s} _
pattern 𝕃⟦_⟧ x₀ = ✓ {x₀ = x₀} ∅
pattern _₀∷₁_∷⟦_⟧ x₀ x₁ x₂s = ✓ {x₀ = x₀} (● {x₁} _ {x₂s} _ _)
--{-# DISPLAY ✓ {x₀ = x₀} (● {x₁} _ {x₂s} _ _) = _₀∷₁_∷⟦_⟧ x₀ x₁ x₂s #-}
pattern _↶_↷_ x₀∉x₂s x₀≢x₁ x₁∉x₂s = ● x₀≢x₁ x₀∉x₂s x₁∉x₂s
pattern _₀∷₁⟦_⟧ x₀ x₁s = ● {x₀} _ {x₁s} _ _
instance Membership𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} → Membership 𝐴 (𝕃 𝐴)
Membership._∉_ Membership𝕃 x xs = x ∉𝕃 xs
Membership._∈_ Membership𝕃 x xs = ¬ x ∉𝕃 xs
fst (Membership.xor-membership Membership𝕃) x₁ x₂ = x₁ x₂
snd (Membership.xor-membership Membership𝕃) x₁ x₂ = x₂ x₁
{-# DISPLAY _∉𝕃_ = _∉_ #-}
add-1-preserves-∈𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} {x₀ : 𝐴} {x₁s : 𝕃 𝐴} (x₀∉x₁s : x₀ ∉ x₁s) {x : 𝐴} → x ∈ x₁s → x ∈ ✓ x₀∉x₁s
add-1-preserves-∈𝕃 x₀∉x₁s x₁ (● x₃ x₄ x₂) = x₁ x₄
--{-# DISPLAY #-}
_∉𝕃?_ : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ → (x : 𝐴) (xs : 𝕃 𝐴) → Dec (x ∉𝕃 xs)
_∉𝕃?_ x ∅ = yes ∅
_∉𝕃?_ x 𝕃⟦ x₀ ⟧ with x ≟ x₀
… | yes refl = no λ {(● x₂ _ .∅) → x₂ refl}
… | no x≢x₀ = yes (● x≢x₀ ∅ ∅)
_∉𝕃?_ x (✓ {x₀ = x₀} (● {x₁} x₀≢x₁ {x₂s} x₀∉x₂s x₁∉x₂s)) with x ≟ x₀
… | yes refl = no λ { (● x₃ _ _) → x₃ refl}
… | no x≢x₀ with x ≟ x₁
… | yes refl = no λ { ((_ ↶ x≢x ↷ _) ↶ _ ↷ _) → x≢x refl }
… | no x≢x₁ with x ∉𝕃? x₂s
_∉𝕃?_ x₁ (✓ {x₂} (● {x₀} x₃ {.∅} x₄ x₀∉x₁s)) | no x≢x₀ | (no x≢x₁) | (yes ∅) = yes (● x≢x₀ (● x≢x₁ ∅ x₀∉x₁s) (● _ _ x₀∉x₁s))
_∉𝕃?_ x₁ (✓ {x₄} (● {x₃} x₅ {.(✓ asdf)} x₆ x₀∉x₁s)) | no x≢x₀ | (no x≢x₁) | (yes (● x₂ asdf₁ asdf)) = yes (● x≢x₀ (● x≢x₁ (● x₂ asdf₁ asdf) x₀∉x₁s) (● x₅ x₆ x₀∉x₁s))
… | no x∈x₂s = no λ { (● {_} x₃ {.(✓ x₁∉x₂s)} (● x₄ x∉x₀s .x₁∉x₂s) .(● x₀≢x₁ x₀∉x₂s x₁∉x₂s)) → x∈x₂s x∉x₀s}
instance DecidableMembership𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ → DecidableMembership 𝐴 (𝕃 𝐴)
DecidableMembership._∉?_ DecidableMembership𝕃 = _∉𝕃?_
DecidableMembership._∈?_ DecidableMembership𝕃 x X with _∉𝕃?_ x X
… | yes x∉X = no (λ x₁ → x₁ x∉X)
… | no x∈X = yes x∈X
x∈singleton→x=singleton : ∀ {𝑨} {𝐴 : Set 𝑨} {x₀ : 𝐴} ⦃ _ : Eq 𝐴 ⦄ {x₀∉∅ : _∉_ ⦃ Membership𝕃 ⦄ x₀ 𝕃.∅} {x : 𝐴} → x ∈ ✓ x₀∉∅ → x ≡ x₀
x∈singleton→x=singleton {𝑨} {𝐴} {x₀} {∅} {x} x₁ with x ≟ x₀
x∈singleton→x=singleton {𝑨} {𝐴} {x₀} {∅} {x} x₁ | yes refl = refl
x∈singleton→x=singleton {𝑨} {𝐴} {x₀} {∅} {x} x∈x₀ | no x≢x₀ = ⊥-elim (x∈x₀ (● x≢x₀ ∅ ∅))
foo₄ : (𝑨 : Level )
(𝐴 : Set 𝑨 )
(x₁ : 𝐴 )
(x₂s : 𝕃 𝐴 )
(x₁∉x₂s : x₁ ∉ x₂s )
(x₀ : 𝐴 )
(x₀≢x₁ : x₀ ≡ x₁ → ⊥ )
(x₀∉x₂s : x₀ ∉ x₂s )
(x : 𝐴 )
(x∈x₀∉x₁s : x ∉ ✓ (● x₀≢x₁ x₀∉x₂s x₁∉x₂s) → ⊥ )
(x≢x₀ : x ≡ x₀ → ⊥ )
(x≢x₁ : x ≡ x₁ → ⊥ )
(x∉x₂s : x ∉ x₂s )
(x₂ : x ≡ x₀ ) → ⊥
foo₄ 𝑨 𝐴 x₁ x₂s x₁∉x₂s x₀ x₀≢x₁ x₀∉x₂s .x₀ x∈x₀∉x₁s x≢x₀ x≢x₁ x∉x₂s refl = x≢x₀ refl
if-diff-then-somewhere-else-∈𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ {x₀ : 𝐴} (x₁s : 𝕃 𝐴) {x₀∉x₁s : x₀ ∉ x₁s} {x : 𝐴} → x ∈ ✓ x₀∉x₁s → x ≢ x₀ → x ∈ x₁s
if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} ∅ {∅} {x} x∈x₀∉∅ x≢x₀ ∅ = x≢x₀ (x∈singleton→x=singleton x∈x₀∉∅)
if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} (✓ {x₀ = x₁} {x₁s = x₂s} x₁∉x₂s) {● x₀≢x₁ x₀∉x₂s ._} {x} x∈x₀∉x₁s x≢x₀ (● x≢x₁ x∉x₂s _) = x∈x₀∉x₁s (● (λ {x₂ → foo₄ 𝑨 𝐴 x₁ x₂s x₁∉x₂s x₀ x₀≢x₁ x₀∉x₂s _ x∈x₀∉x₁s x≢x₀ x≢x₁ x∉x₂s x₂}) (● x≢x₁ x∉x₂s x₁∉x₂s) (● x₀≢x₁ x₀∉x₂s x₁∉x₂s))
--if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} .∅ {x₀∉x₁s} {x} x∈x₀s x≢x₀ ∅ = {!!}
--if-diff-then-somewhere-else-∈𝕃 {𝑨} {𝐴} {x₀} ._ {x₀∉x₁s} {x} x∈x₀s x≢x₀ (● {x₀ = x₁} x≢x₁ {x₁s = x₂s} x∉x₂s x₁∉x₂s) = {!!}
record TotalUnion {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set ℓ
where
field
union : M → M → M
unionLaw1 : ∀ {x : m} {X₁ X₂ : M} → x ∈ X₁ → x ∈ union X₁ X₂
unionLaw2 : ∀ {x : m} {X₁ X₂ : M} → x ∈ X₂ → x ∈ union X₁ X₂
unionLaw3 : ∀ {x : m} {X₁ X₂ : M} → x ∈ union X₁ X₂ → x ∈ X₁ ⊎ x ∈ X₂
open TotalUnion ⦃ … ⦄
{-# DISPLAY TotalUnion.union _ = union #-}
add1-then-∈𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ {x₀ : 𝐴} (x₁s : 𝕃 𝐴) {x₀∉x₁s : x₀ ∉ x₁s} → x₀ ∈ ✓ {x₀ = x₀} x₀∉x₁s
add1-then-∈𝕃 {𝑨} {𝐴} {{x}} {x₀} x₁s {.x₁} (● {x₀ = .x₀} x₂ {x₁s = .x₁s} x₃ x₁) = x₂ refl
module ModuleTotalUnion𝕃 {ℓ} (A : Set ℓ) ⦃ _ : Eq A ⦄ where
-- TODO aribtrarily moves from l₀s to r₀s, so a union of 10 and 2 elements takes longer than a union of 2 and 10 elements
totalUnion : 𝕃 A → 𝕃 A → 𝕃 A
totalUnion ∅ ∅ = ∅
totalUnion ∅ r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) = r₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) ∅ = l₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) with l₀ ∉? r₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) | no l₀∈r₀s = totalUnion l₁s r₀s
totalUnion l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s) r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s) | yes l₀∉r₀s = totalUnion l₁s (✓ l₀∉r₀s)
totalUnionLaw2 : ∀ {x : A} {X₁ X₂ : 𝕃 A} → x ∈ X₂ → x ∈ totalUnion X₁ X₂
totalUnionLaw2 {x₁} {∅} {∅} x₂ x₃ = x₂ x₃
totalUnionLaw2 {x₁} {∅} {✓ x₂} x₃ x₄ = x₃ x₄
totalUnionLaw2 {x₁} {✓ x₂} {∅} x₃ x₄ = x₃ ∅
totalUnionLaw2 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈r₀s x∉l₀s∪r₀s with l₀ ∉? r₀s
totalUnionLaw2 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈r₀s x∉l₀s∪r₀s | no l₀∈r₀s = totalUnionLaw2 {X₁ = l₁s} x∈r₀s $ x∉l₀s∪r₀s
totalUnionLaw2 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈r₀s x∉l₀s∪r₀s | yes l₀∉r₀s = (totalUnionLaw2 {X₁ = l₁s} $ add-1-preserves-∈𝕃 l₀∉r₀s x∈r₀s) $ x∉l₀s∪r₀s
totalUnionLaw1 : ∀ {x : A} {X₁ X₂ : 𝕃 A} → x ∈ X₁ → x ∈ totalUnion X₁ X₂
totalUnionLaw1 {x₁} {∅} {∅} x₂ x₃ = x₂ x₃
totalUnionLaw1 {x₁} {∅} {✓ {x₀ = x₀} {x₁s = X₂} x₂} x₃ x₄ = x₃ ∅
totalUnionLaw1 {x₁} {✓ {x₀ = x₀} {x₁s = X₁} x₂} {∅} x₃ x₄ = x₃ x₄
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s with l₀ ∉? r₀s
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | no l₀∈r₀s with x ≟ l₀
totalUnionLaw1 {.l₀} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | no l₀∈r₀s | yes refl = totalUnionLaw2 {X₁ = l₁s} l₀∈r₀s $ x∉l₀s∪r₀s
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | no l₀∈r₀s | no x≢l₀ = let x∈l₁s = if-diff-then-somewhere-else-∈𝕃 l₁s x∈l₀s x≢l₀ in totalUnionLaw1 x∈l₁s $ x∉l₀s∪r₀s
-- with x ≟ l₀
-- = {!!}
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | yes l₀∉r₀s with x ≟ l₀
--totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} l₀∈l₀s l₀∉l₀s∪r₀s | yes l₀∉r₀s | yes refl = {!l₀∉r₀s!}
totalUnionLaw1 {.l₀} {✓ {l₀} {l₁s} l₀∉l₁s} {✓ {r₀} {r₁s} r₀∉r₁s} l₀∈l₀s l₀∉l₁s∪l₀r₀s | yes (● l₀≢r₀ l₀∉r₁s .r₀∉r₁s) | (yes refl) =
let l₀∈l₀r₀s : l₀ ∈ (✓ (● l₀≢r₀ l₀∉r₁s r₀∉r₁s))
l₀∈l₀r₀s = add1-then-∈𝕃 (✓ r₀∉r₁s)
in totalUnionLaw2 {X₁ = l₁s} l₀∈l₀r₀s $ l₀∉l₁s∪l₀r₀s
totalUnionLaw1 {x} {l₀s@(✓ {x₀ = l₀} {x₁s = l₁s} l₀∉l₁s)} {r₀s@(✓ {x₀ = r₀} {x₁s = r₁s} r₀∉r₁s)} x∈l₀s x∉l₀s∪r₀s | yes l₀∉r₀s | no x≢l₀ = let x∈l₁s = if-diff-then-somewhere-else-∈𝕃 l₁s x∈l₀s x≢l₀ in totalUnionLaw1 x∈l₁s $ x∉l₀s∪r₀s
totalUnionLaw3 : ∀ {x : A} {X₁ X₂ : 𝕃 A} → x ∈ totalUnion X₁ X₂ → x ∈ X₁ ⊎ x ∈ X₂
totalUnionLaw3 = {!!}
instance TotalUnion𝕃 : ∀ {𝑨} {𝐴 : Set 𝑨} ⦃ _ : Eq 𝐴 ⦄ → TotalUnion 𝐴 (𝕃 𝐴)
TotalUnion.union TotalUnion𝕃 = ModuleTotalUnion𝕃.totalUnion _
TotalUnion.unionLaw1 TotalUnion𝕃 = ModuleTotalUnion𝕃.totalUnionLaw1 _
TotalUnion.unionLaw2 (TotalUnion𝕃 {𝑨} {𝐴} {{x}}) {x₁} {X₁} {X₂} x₂ x₃ = ModuleTotalUnion𝕃.totalUnionLaw2 𝐴 {X₁ = X₁} {X₂ = X₂} x₂ x₃
TotalUnion.unionLaw3 TotalUnion𝕃 = ModuleTotalUnion𝕃.totalUnionLaw3 _
mutual
data FTerm : 𝕃 VariableName → Set
where
variable : (𝑥 : VariableName) → FTerm (𝕃⟦ 𝑥 ⟧)
function : (𝑓 : FunctionName) → ..{𝑥s : 𝕃 VariableName} {arity : Nat} → (τs : FTerms 𝑥s arity) → FTerm 𝑥s
data FTerms : 𝕃 VariableName → Nat → Set
where
[] : FTerms ∅ zero
_∷_ : ∀ ..{𝑥s' 𝑥s : 𝕃 VariableName} → FTerm 𝑥s' → {n : Nat} → FTerms 𝑥s n → FTerms (union {m = VariableName} 𝑥s' 𝑥s) (⊹ n)
instance MembershipVariableNameFTerm : ∀ {𝑥s} → Membership VariableName (FTerm 𝑥s)
MembershipVariableNameFTerm = {!!}
record TotalIntersection {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set ℓ
where
field
intersection : M → M → M
intersectionLaw1 : ∀ {x : m} {X₁ X₂ : M} → x ∈ intersection X₁ X₂ → x ∈ X₁
intersectionLaw2 : ∀ {x : m} {X₁ X₂ : M} → x ∈ intersection X₁ X₂ → x ∈ X₂
intersectionLaw3 : ∀ {x : m} {X₁ X₂ : M} → x ∈ X₁ × x ∈ X₂ → x ∈ intersection X₁ X₂
open TotalIntersection ⦃ … ⦄
{-# DISPLAY TotalIntersection.intersection _ = intersection #-}
instance Intersection𝕃 : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → TotalIntersection A (𝕃 A)
Intersection𝕃 = {!!}
data HasUniqueValues (A : Set) : List A → Set
where
[] : HasUniqueValues A []
_∷_ : {x : A} → {xs : List A} → x ∉ xs → (uxs : HasUniqueValues A xs) → HasUniqueValues A (x ∷ xs)
record AList (A : Set) (B : Set) : Set
where
field
domain : List A
uniquedomain : HasUniqueValues A domain
range : ∀ {x : A} → x ∈ domain → B
open AList
mutual
subst : AList VariableName (∃ FTerm) → ∃ FTerm → ∃ FTerm
subst x t@(.(✓ ∅) , variable 𝑥) with 𝑥 ∈? domain x
… | yes x∈D = range x x∈D
… | no x∉D = t
subst x (fst₁ , function 𝑓 {𝑥s = 𝑥s} {arity = a} τs) with substs x a (𝑥s , τs)
subst x (fst₁ , function 𝑓 {.fst₁} {arity₁} τs) | fst₂ , snd₁ = fst₂ , (function 𝑓 snd₁)
substs : AList VariableName (∃ FTerm) → (a : Nat) → ∃ (flip FTerms a) → ∃ (flip FTerms a)
substs x .0 (.∅ , []) = ∅ , []
substs x .(suc _) (._ , (x₁ ∷ snd₁)) with {!subst x (_ , x₁)!}
substs x .(suc _) (._ , (x₁ ∷ snd₁)) | sb = {!!}
-- indexed by the number of function symbols contained
data DTerm : Nat → Set
where
variable : (𝑥 : VariableName) → DTerm zero
function : (𝑓 : FunctionName) → {arity : Nat} → (τs : Vec (∃ DTerm) arity) → DTerm (suc (sum (fst <$> vecToList τs)))
mutual
substD : VariableName → ∃ DTerm → {n : Nat} → DTerm n → ∃ DTerm
substD x x₁ (variable 𝑥) = ifYes 𝑥 ≟ x then x₁ else _ , variable 𝑥
substD x x₁ (function 𝑓 τs) with substsD x x₁ τs
substD x x₁ (function 𝑓 τs) | ss = suc (sum (fst <$> vecToList ss)) , function 𝑓 {_} ss
substsD : VariableName → ∃ DTerm → {n : Nat} → Vec (Σ Nat DTerm) n → Vec (Σ Nat DTerm) n
substsD x x₁ [] = []
substsD x x₁ (x₂ ∷ x₃) with substD x x₁ (snd x₂) | substsD x x₁ x₃
substsD x x₁ (x₂ ∷ x₃) | fst₁ , snd₁ | sss = (fst₁ , snd₁) ∷ sss
data HDTerm : Set where
⟨_⟩ : {n : Nat} → DTerm n → HDTerm
substituteD : (AList VariableName HDTerm) → HDTerm → HDTerm
substituteD = {!!}
amgu : HDTerm → HDTerm → (AList VariableName HDTerm) → Maybe (AList VariableName HDTerm)
amgu ⟨ variable 𝑥 ⟩ ⟨ variable 𝑥₁ ⟩ f = {!!}
amgu ⟨ variable 𝑥 ⟩ ⟨ function 𝑓 τs ⟩ f = {!!}
amgu ⟨ function 𝑓 τs ⟩ ⟨ variable 𝑥 ⟩ f = {!!}
amgu ⟨ function 𝑓 τs₁ ⟩ ⟨ function 𝑓₁ τs ⟩ f = {!!}
-- {-
-- data AList : 𝕃 VariableName → Set
-- where
-- [] : AList ∅
-- _∷_ :
-- -}
-- record JohnUnification {𝑥s₁} (τ₁ : FTerm 𝑥s₁) {𝑥s₂} (τ₂ : FTerm 𝑥s₂) (_ : intersection {m = VariableName} 𝑥s₁ 𝑥s₂ ≡ ∅) : Set where
-- field
-- u₁ u₂ : AList VariableName (∃ FTerm)
-- unification-law₁ : fst (subst u₁ (𝑥s₁ , τ₁)) ≡ fst (subst u₂ (𝑥s₂ , τ₂))
-- unification-law₂ : snd (subst u₁ (𝑥s₁ , τ₁)) ≡ transport FTerm (sym unification-law₁) (snd (subst u₂ (𝑥s₂ , τ₂)))
-- record UnificationEquation (𝑥s : 𝕃 VariableName) : Set
-- where
-- field
-- {lhs-terms} : 𝕃 VariableName
-- lhs : FTerm lhs-terms
-- {rhs-terms} : 𝕃 VariableName
-- rhs : FTerm rhs-terms
-- lhs∪rhs-terms : 𝑥s ≡ union {m = VariableName} lhs-terms rhs-terms
-- open UnificationEquation
-- number-of-variables-that-occur-more-than-once : ∀ {n-eqn} → Vec (∃ λ 𝑥s → UnificationEquation 𝑥s) n-eqn → Nat
-- number-of-variables-that-occur-more-than-once {zero} [] = 0
-- number-of-variables-that-occur-more-than-once {suc n-eqn} x = {!!}
-- number-of-function-symbols : ∀ {𝑥s} → FTerm 𝑥s → Nat
-- number-of-function-symbols = {!!}
-- record UnificationProblem (n-var n-lhs n-eqn : Nat) : Set
-- where
-- field
-- equations : Vec (∃ λ 𝑥s → UnificationEquation 𝑥s) n-eqn
-- n-var-law : number-of-variables-that-occur-more-than-once equations ≤ n-var
-- n-lhs-law : (sum ∘ vecToList $ number-of-function-symbols ∘ lhs ∘ snd <$> equations) ≤ n-lhs
-- instance MembershipUnificationEquationUnificationProblem : ∀ {n-var n-lhs n-eqn 𝑥s} → Membership (UnificationEquation 𝑥s) (UnificationProblem n-var n-lhs n-eqn)
-- MembershipUnificationEquationUnificationProblem = {!!}
-- instance MembershipVariableNameUnificationProblem : ∀ {n-var n-lhs n-eqn} → Membership VariableName (UnificationProblem n-var n-lhs n-eqn)
-- MembershipVariableNameUnificationProblem = {!!}
-- deletable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- deletable = {!!}
-- deletable? : ∀ {𝑥s} → (eq : UnificationEquation 𝑥s) → Dec (deletable eq)
-- deletable? = {!!}
-- u-deletable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → deletable εq × εq ∈ up)
-- u-deletable? {n-var} {n-lhs} {zero} up = no {!!}
-- u-deletable? {n-var} {n-lhs} {suc n-eqn} up = {!!}
-- deleteRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var n-lhs (suc n-eqn)} {𝑥s} {εq : UnificationEquation 𝑥s} → deletable εq → εq ∈ up → UnificationProblem n-var n-lhs n-eqn
-- deleteRule = {!!}
-- decomposable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- decomposable = {!!}
-- decomposable? : ∀ {𝑥s} → (eq : UnificationEquation 𝑥s) → Dec (decomposable eq)
-- decomposable? = {!!}
-- u-decomposable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var (suc n-lhs) n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → decomposable εq × εq ∈ up)
-- u-decomposable? = {!!}
-- decomposeRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var (suc n-lhs) n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → decomposable εq → εq ∈ up → UnificationProblem n-var n-lhs n-eqn
-- decomposeRule = {!!}
-- swapable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- swapable = {!!}
-- swapable? : ∀ {𝑥s} → (eq : UnificationEquation 𝑥s) → Dec (swapable eq)
-- swapable? = {!!}
-- u-swapable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var (suc n-lhs) n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → swapable εq × εq ∈ up)
-- u-swapable? = {!!}
-- swapRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var (suc n-lhs) n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → swapable εq → εq ∈ up → UnificationProblem n-var n-lhs n-eqn
-- swapRule = {!!}
-- eliminatable : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem n-var n-lhs n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → (εq∈up : εq ∈ up) → Set
-- eliminatable = {!!}
-- u-eliminatable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem (suc n-var) n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → ∃ λ (εq∈up : εq ∈ up) → eliminatable {up = up} {εq = εq} εq∈up)
-- u-eliminatable? = {!!}
-- eliminateRule : ∀ {n-var n-lhs n-eqn} {up : UnificationProblem (suc n-var) n-lhs n-eqn} {𝑥s} {εq : UnificationEquation 𝑥s} → {εq∈up : εq ∈ up} → eliminatable {up = up} {εq = εq} εq∈up → UnificationProblem n-var n-lhs n-eqn
-- eliminateRule = {!!}
-- conflictable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- conflictable = {!!}
-- conflictable? : ∀ {𝑥s} → (εq : UnificationEquation 𝑥s) → Dec (conflictable εq)
-- conflictable? = {!!}
-- u-conflictable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → conflictable εq × εq ∈ up)
-- u-conflictable? = {!!}
-- checkable : ∀ {𝑥s} → UnificationEquation 𝑥s → Set
-- checkable = {!!}
-- checkable? : ∀ {𝑥s} → (εq : UnificationEquation 𝑥s) → Dec (checkable εq)
-- checkable? = {!!}
-- u-checkable? : ∀ {n-var n-lhs n-eqn} (up : UnificationProblem n-var n-lhs n-eqn) → Dec (∃ λ 𝑥s → ∃ λ (εq : UnificationEquation 𝑥s) → checkable εq × εq ∈ up)
-- u-checkable? = {!!}
-- record HasNegation (A : Set) : Set
-- where
-- field
-- ~ : A → A
-- open HasNegation ⦃ … ⦄
-- {-# DISPLAY HasNegation.~ _ = ~ #-}
-- data Formula : Set
-- where
-- atomic : PredicateName → Terms → Formula
-- logical : Formula →
-- Formula →
-- Formula
-- quantified : VariableName → Formula → Formula
-- formulaAtomic-inj₁ : ∀ {𝑃₁ τs₁ 𝑃₂ τs₂} → Formula.atomic 𝑃₁ τs₁ ≡ atomic 𝑃₂ τs₂ → 𝑃₁ ≡ 𝑃₂
-- formulaAtomic-inj₁ refl = refl
-- formulaAtomic-inj₂ : ∀ {𝑃₁ τs₁ 𝑃₂ τs₂} → Formula.atomic 𝑃₁ τs₁ ≡ atomic 𝑃₂ τs₂ → τs₁ ≡ τs₂
-- formulaAtomic-inj₂ refl = refl
-- formulaLogical-inj₁ : ∀ {φ₁₁ φ₁₂ φ₂₁ φ₂₂} → Formula.logical φ₁₁ φ₁₂ ≡ logical φ₂₁ φ₂₂ → φ₁₁ ≡ φ₂₁
-- formulaLogical-inj₁ refl = refl
-- formulaLogical-inj₂ : ∀ {φ₁₁ φ₁₂ φ₂₁ φ₂₂} → Formula.logical φ₁₁ φ₁₂ ≡ logical φ₂₁ φ₂₂ → φ₁₂ ≡ φ₂₂
-- formulaLogical-inj₂ refl = refl
-- formulaQuantified-inj₁ : ∀ {𝑥₁ φ₁ 𝑥₂ φ₂} → Formula.quantified 𝑥₁ φ₁ ≡ quantified 𝑥₂ φ₂ → 𝑥₁ ≡ 𝑥₂
-- formulaQuantified-inj₁ refl = refl
-- formulaQuantified-inj₂ : ∀ {𝑥₁ φ₁ 𝑥₂ φ₂} → Formula.quantified 𝑥₁ φ₁ ≡ quantified 𝑥₂ φ₂ → φ₁ ≡ φ₂
-- formulaQuantified-inj₂ refl = refl
-- instance EqFormula : Eq Formula
-- Eq._==_ EqFormula (atomic 𝑃₁ τs₁)
-- (atomic 𝑃₂ τs₂)
-- = decEq₂ formulaAtomic-inj₁
-- formulaAtomic-inj₂
-- (𝑃₁ ≟ 𝑃₂)
-- (τs₁ ≟ τs₂)
-- Eq._==_ EqFormula (logical φ₁₁ φ₁₂)
-- (logical φ₂₁ φ₂₂)
-- = decEq₂ formulaLogical-inj₁ formulaLogical-inj₂ (φ₁₁ ≟ φ₂₁) (φ₁₂ ≟ φ₂₂)
-- Eq._==_ EqFormula (quantified 𝑥₁ φ₁) (quantified 𝑥₂ φ₂) = decEq₂ formulaQuantified-inj₁ formulaQuantified-inj₂ (𝑥₁ ≟ 𝑥₂) (φ₁ ≟ φ₂)
-- Eq._==_ EqFormula (atomic _ _) (logical _ _) = no λ ()
-- Eq._==_ EqFormula (atomic _ _) (quantified _ _) = no λ ()
-- Eq._==_ EqFormula (logical _ _) (atomic _ _) = no λ ()
-- Eq._==_ EqFormula (logical _ _) (quantified _ _) = no λ ()
-- Eq._==_ EqFormula (quantified _ _) (atomic _ _) = no λ ()
-- Eq._==_ EqFormula (quantified _ _) (logical _ _) = no λ ()
-- data IsFormula : Formula → Set
-- where
-- ⟨_⟩ : (φ : Formula) → IsFormula φ
-- record 𝓕ormula (Is𝓕ormula : Formula → Set) : Set
-- where
-- constructor ⟨_⟩
-- field
-- {formula} : Formula
-- is𝓕ormula : Is𝓕ormula formula
-- open 𝓕ormula
-- 𝑃[_♭_] : PredicateName → Terms → Formula
-- 𝑃[_♭_] = atomic
-- {-# DISPLAY atomic = 𝑃[_♭_] #-}
-- record HasNeitherNor (A : Set) : Set
-- where
-- field
-- _⊗_ : A → A → A
-- open HasNeitherNor ⦃ … ⦄
-- instance HasNeitherNorFormula : HasNeitherNor Formula
-- HasNeitherNor._⊗_ HasNeitherNorFormula = logical
-- {-# DISPLAY logical = _⊗_ #-}
-- instance HasNegationFormula : HasNegation Formula
-- HasNegation.~ HasNegationFormula φ = φ ⊗ φ
-- data IsLiteralFormula : Formula → Set
-- where
-- atomic : (𝑃 : PredicateName) → (τs : Terms) → IsLiteralFormula $ 𝑃[ 𝑃 ♭ τs ]
-- logical : (𝑃 : PredicateName) → (τs : Terms) → IsLiteralFormula ∘ ~ $ 𝑃[ 𝑃 ♭ τs ]
-- eqIsLiteralFormula : ∀ {φ} → (lf₁ lf₂ : IsLiteralFormula φ) → lf₁ ≡ lf₂
-- eqIsLiteralFormula (atomic _ _) (atomic _ _) = refl
-- eqIsLiteralFormula (logical _ _) (logical _ _) = refl
-- instance EqIsLiteralFormula : ∀ {φ} → Eq (IsLiteralFormula φ)
-- Eq._==_ EqIsLiteralFormula lf₁ lf₂ = yes $ eqIsLiteralFormula lf₁ lf₂
-- record LiteralFormula : Set
-- where
-- constructor ⟨_⟩
-- field
-- {formula} : Formula
-- isLiteralFormula : IsLiteralFormula formula
-- open LiteralFormula
-- instance EqLiteralFormula : Eq LiteralFormula
-- Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂)
-- with φ₁ ≟ φ₂
-- … | no φ₁≢φ₂ = no (λ {refl → φ₁≢φ₂ refl})
-- Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂) | yes refl = case (eqIsLiteralFormula lf₁ lf₂) of λ {refl → yes refl}
-- instance HasNegationLiteralFormula : HasNegation LiteralFormula
-- HasNegation.~ HasNegationLiteralFormula ⟨ atomic 𝑃 τs ⟩ = ⟨ logical 𝑃 τs ⟩
-- HasNegation.~ HasNegationLiteralFormula ⟨ logical 𝑃 τs ⟩ = ⟨ atomic 𝑃 τs ⟩
-- data IsPropositionalFormula : Formula → Set
-- where
-- atomic : (𝑃 : PredicateName) → (τs : Terms) → IsPropositionalFormula $ 𝑃[ 𝑃 ♭ τs ]
-- logical : {φ₁ : Formula} → IsPropositionalFormula φ₁ → {φ₂ : Formula} → IsPropositionalFormula φ₂ → IsPropositionalFormula (φ₁ ⊗ φ₂)
-- instance EqIsPropositionalFormula : ∀ {φ} → Eq (IsPropositionalFormula φ)
-- Eq._==_ EqIsPropositionalFormula (atomic _ _) (atomic _ _ ) = yes refl
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) with φ₁₁ ≟ φ₂₁ | φ₁₂ ≟ φ₂₂
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) | yes refl | yes refl = yes refl
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) | yes refl | no φ₁₂≢φ₂₂ = no λ {refl → φ₁₂≢φ₂₂ refl}
-- Eq._==_ EqIsPropositionalFormula (logical φ₁₁ φ₁₂) (logical φ₂₁ φ₂₂) | no φ₁₁≢φ₂₁ | _ = no λ {refl → φ₁₁≢φ₂₁ refl}
-- {-
-- -- need to use coinduction to prove this
-- foo : ¬ ∃ λ φ → ∃ λ (p₁ : IsPropositionalFormula φ) → ∃ λ (p₂ : IsPropositionalFormula φ) → p₁ ≢ p₂
-- foo (atomic x x₁ , atomic .x .x₁ , atomic .x .x₁ , snd₁) = snd₁ refl
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical fst₅ fst₆ , snd₁) with fst₃ ≟ fst₅ | fst₄ ≟ fst₆
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical .fst₃ .fst₄ , snd₁) | yes refl | (yes refl) = snd₁ refl
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical .fst₃ fst₆ , snd₁) | yes refl | (no x₁) = foo (fst₂ , fst₄ , fst₆ , λ xs → x₁ xs)
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical fst₅ fst₆ , snd₁) | no x | (yes x₁) = {!!}
-- foo (logical fst₁ fst₂ , logical fst₃ fst₄ , logical fst₅ fst₆ , snd₁) | no x | (no x₁) = {!!}
-- foo (quantified x fst₁ , () , fst₃ , snd₁)
-- -}
-- record PropositionalFormula : Set
-- where
-- constructor ⟨_⟩
-- field
-- {formula} : Formula
-- isPropositionalFormula : IsPropositionalFormula formula
-- open PropositionalFormula
-- instance HasNegationPropositionalFormula : HasNegation PropositionalFormula
-- HasNegation.~ HasNegationPropositionalFormula ⟨ φ ⟩ = ⟨ logical φ φ ⟩
-- instance HasNeitherNorPropositionalFormula : HasNeitherNor PropositionalFormula
-- HasNeitherNor._⊗_ HasNeitherNorPropositionalFormula ⟨ φ₁ ⟩ ⟨ φ₂ ⟩ = ⟨ logical φ₁ φ₂ ⟩
-- {-# DISPLAY IsPropositionalFormula.logical = _⊗_ #-}
-- record 𝓐ssertion (A : Set) : Set
-- where
-- no-eta-equality
-- instance 𝓐ssertionList : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ → 𝓐ssertion (List A)
-- 𝓐ssertionList = record {}
-- instance 𝓐ssertionFormula : 𝓐ssertion Formula
-- 𝓐ssertionFormula = record {}
-- instance 𝓐ssertionLiteralFormula : 𝓐ssertion LiteralFormula
-- 𝓐ssertionLiteralFormula = record {}
-- infix 15 _⊢_
-- record 𝓢equent (A : Set) ⦃ _ : 𝓐ssertion A ⦄ : Set
-- where
-- constructor _⊢_
-- field
-- antecedents : List A
-- consequents : List A
-- open 𝓢equent ⦃ … ⦄
-- instance Eq𝓢equent : {A : Set} ⦃ _ : Eq A ⦄ ⦃ _ : 𝓐ssertion A ⦄ → Eq (𝓢equent A)
-- Eq._==_ Eq𝓢equent (antecedents₁ ⊢ consequents₁) (antecedents₂ ⊢ consequents₂) = {!antecedents₁ ≟ antecedents₂!}
-- instance 𝓐ssertion𝓢equent : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ → 𝓐ssertion (𝓢equent A)
-- 𝓐ssertion𝓢equent = record {}
-- instance 𝓐ssertion𝓕ormula : {Is𝓕ormula : Formula → Set} → 𝓐ssertion (𝓕ormula Is𝓕ormula)
-- 𝓐ssertion𝓕ormula = record {}
-- infix 15 _╱_
-- record Sequent : Set
-- where
-- constructor _╱_
-- field
-- statement : Formula
-- suppositions : List Formula
-- open Sequent
-- instance EqSequent : Eq Sequent
-- Eq._==_ EqSequent ( φᵗ₁ ╱ φˢs₁ ) ( φᵗ₂ ╱ φˢs₂ ) = decEq₂ (cong statement) (cong suppositions) (φᵗ₁ ≟ φᵗ₂) (φˢs₁ ≟ φˢs₂)
-- instance HasNegationSequent : HasNegation Sequent
-- HasNegation.~ HasNegationSequent ( φᵗ ╱ φˢs ) = ~ φᵗ ╱ φˢs
-- record IsLiteralSequent (Φ : Sequent) : Set
-- where
-- constructor _╱_
-- field
-- isLiteralStatement : IsLiteralFormula (statement Φ)
-- isLiteralSuppositions : All IsLiteralFormula (suppositions Φ)
-- open IsLiteralSequent
-- instance EqIsLiteralSequent : ∀ {Φ} → Eq (IsLiteralSequent Φ)
-- Eq._==_ EqIsLiteralSequent ( φᵗ₁ ╱ φˢs₁ ) ( φᵗ₂ ╱ φˢs₂ ) = decEq₂ (cong isLiteralStatement) (cong isLiteralSuppositions) (φᵗ₁ ≟ φᵗ₂) (φˢs₁ ≟ φˢs₂)
-- record LiteralSequent : Set
-- where
-- constructor ⟨_⟩
-- field
-- {sequent} : Sequent
-- isLiteralSequent : IsLiteralSequent sequent
-- open LiteralSequent
-- pattern ⟪_,_⟫ h s = ⟨_⟩ {h} s
-- pattern ⟪_⟫ h = (⟨_⟩ {h} _)
-- instance EqLiteralSequent : Eq LiteralSequent
-- Eq._==_ EqLiteralSequent ⟪ Φ₁ ⟫ ⟪ Φ₂ ⟫ with Φ₁ ≟ Φ₂
-- Eq._==_ EqLiteralSequent ⟨ !Φ₁ ⟩ ⟨ !Φ₂ ⟩ | yes refl with !Φ₁ ≟ !Φ₂
-- Eq._==_ EqLiteralSequent _ _ | yes refl | yes refl = yes refl
-- Eq._==_ EqLiteralSequent ⟨ Φ₁ ⟩ ⟨ Φ₂ ⟩ | yes refl | no !Φ₁≢!Φ₂ = no λ {refl → !Φ₁≢!Φ₂ refl}
-- Eq._==_ EqLiteralSequent ⟨ Φ₁ ⟩ ⟨ Φ₂ ⟩ | no Φ₁≢Φ₂ = no λ {refl → Φ₁≢Φ₂ refl}
-- instance HasNegationLiteralSequent : HasNegation LiteralSequent
-- HasNegation.~ HasNegationLiteralSequent ⟨ atomic 𝑃 τs ╱ φˢs ⟩ = ⟨ logical 𝑃 τs ╱ φˢs ⟩
-- HasNegation.~ HasNegationLiteralSequent ⟨ logical 𝑃 τs ╱ φˢs ⟩ = ⟨ atomic 𝑃 τs ╱ φˢs ⟩
-- infix 13 _¶_
-- record Problem : Set
-- where
-- constructor _¶_
-- field
-- inferences : List Sequent
-- interest : Sequent
-- open Problem
-- instance EqProblem : Eq Problem
-- EqProblem = {!!}
-- record IsLiteralProblem (𝔓 : Problem) : Set
-- where
-- constructor _¶_
-- field
-- {problem} : Problem
-- isLiteralInferences : All IsLiteralSequent (inferences 𝔓)
-- isLiteralInterest : IsLiteralSequent (interest 𝔓)
-- open IsLiteralProblem
-- instance EqIsLiteralProblem : ∀ {𝔓} → Eq (IsLiteralProblem 𝔓)
-- EqIsLiteralProblem = {!!}
-- record LiteralProblem : Set
-- where
-- constructor ⟨_⟩
-- field
-- {problem} : Problem
-- isLiteralProblem : IsLiteralProblem problem
-- open LiteralProblem
-- instance EqLiteralProblem : Eq LiteralProblem
-- EqLiteralProblem = {!!}
-- record Element : Set
-- where
-- constructor ⟨_⟩
-- field
-- element : Nat
-- instance EqElement : Eq Element
-- Eq._==_ EqElement ⟨ ε₁ ⟩ ⟨ ε₂ ⟩ with ε₁ ≟ ε₂
-- Eq._==_ EqElement ⟨ _ ⟩ ⟨ _ ⟩ | yes refl = yes refl
-- Eq._==_ EqElement ⟨ _ ⟩ ⟨ _ ⟩ | no ε₁≢ε₂ = no λ {refl → ε₁≢ε₂ refl}
-- record Elements : Set
-- where
-- constructor ⟨_⟩
-- field
-- {arity} : Arity
-- elements : Vector Element arity
-- open Elements
-- instance EqElements : Eq Elements
-- Eq._==_ EqElements (⟨_⟩ {𝑎₁} εs₁) (⟨_⟩ {𝑎₂} εs₂)
-- with 𝑎₁ ≟ 𝑎₂
-- … | no 𝑎₁≢𝑎₂ = no λ {refl → 𝑎₁≢𝑎₂ refl}
-- … | yes refl
-- with εs₁ ≟ εs₂
-- … | yes refl = yes refl
-- … | no εs₁≢εs₂ = no λ {refl → εs₁≢εs₂ refl}
-- record TruthValue : Set
-- where
-- constructor ⟨_⟩
-- field
-- truthValue : Bool
-- record Interpretation : Set
-- where
-- field
-- μ⟦_⟧ : VariableName → Element
-- 𝑓⟦_⟧ : FunctionName → Elements → Element
-- 𝑃⟦_⟧ : PredicateName → Elements → TruthValue
-- open Interpretation
-- mutual
-- τ⇑⟦_⟧ : Interpretation → {i : Size} → Term → Delay i Element
-- τ⇑⟦ I ⟧ (variable 𝑥) = now $ μ⟦ I ⟧ 𝑥
-- τ⇑⟦ I ⟧ (function 𝑓 τs) = 𝑓⟦ I ⟧ 𝑓 ∘ ⟨_⟩ <$> τs⇑⟦ I ⟧ τs
-- τs⇑⟦_⟧ : Interpretation → {i : Size} → (τs : Terms) → Delay i (Vector Element (arity τs))
-- τs⇑⟦ I ⟧ ⟨ ⟨ [] ⟩ ⟩ = now ⟨ [] ⟩
-- τs⇑⟦ I ⟧ ⟨ ⟨ τ ∷ τs ⟩ ⟩ = τ⇑⟦ I ⟧ τ >>= (λ t → τs⇑⟦ I ⟧ ⟨ ⟨ τs ⟩ ⟩ >>= λ ts → now ⟨ t ∷ vector ts ⟩)
-- τs⇓⟦_⟧ : (I : Interpretation) → (τs : Terms) → τs⇑⟦ I ⟧ τs ⇓
-- τs⇓⟦ I ⟧ ⟨ ⟨ [] ⟩ ⟩ = _ , now⇓
-- τs⇓⟦ I ⟧ ⟨ ⟨ variable 𝑥 ∷ τs ⟩ ⟩ = _ , τs⇓⟦ I ⟧ ⟨ ⟨ τs ⟩ ⟩ ⇓>>=⇓ now⇓
-- τs⇓⟦ I ⟧ ⟨ ⟨ function 𝑓₁ τs₁ ∷ τs₂ ⟩ ⟩ =
-- _ , τs⇓⟦ I ⟧ τs₁ ⇓>>=⇓ now⇓ >>=⇓ (τs⇓⟦ I ⟧ ⟨ ⟨ τs₂ ⟩ ⟩ ⇓>>=⇓ now⇓)
-- τ⇓⟦_⟧ : (I : Interpretation) → (τ : Term) → τ⇑⟦ I ⟧ τ ⇓
-- τ⇓⟦ I ⟧ (variable 𝑥) = _ , now⇓
-- τ⇓⟦ I ⟧ (function 𝑓 τs) = _ , τs⇓⟦ I ⟧ τs ⇓>>=⇓ now⇓
-- τ⟦_⟧ : (I : Interpretation) → {i : Size} → (τ : Term) → Element
-- τ⟦ I ⟧ τ = fst (τ⇓⟦ I ⟧ τ)
-- record HasSatisfaction (A : Set) ⦃ _ : 𝓐ssertion A ⦄ : Set₁
-- where
-- field
-- _⊨_ : Interpretation → A → Set
-- _⊭_ : Interpretation → A → Set
-- _⊭_ I = ¬_ ∘ I ⊨_
-- open HasSatisfaction ⦃ … ⦄
-- {-# DISPLAY HasSatisfaction._⊨_ _ = _⊨_ #-}
-- {-# DISPLAY HasSatisfaction._⊭_ _ = _⊭_ #-}
-- record _≞_/_ (𝓘 : Interpretation) (I : Interpretation) (𝑥 : VariableName) : Set
-- where
-- field
-- μEquality : {𝑥′ : VariableName} → 𝑥′ ≢ 𝑥 → μ⟦ 𝓘 ⟧ 𝑥 ≡ μ⟦ I ⟧ 𝑥′
-- 𝑓Equality : (𝑓 : FunctionName) (μs : Elements) → 𝑓⟦ 𝓘 ⟧ 𝑓 μs ≡ 𝑓⟦ I ⟧ 𝑓 μs
-- 𝑃Equality : (𝑃 : PredicateName) → (μs : Elements) → 𝑃⟦ 𝓘 ⟧ 𝑃 μs ≡ 𝑃⟦ I ⟧ 𝑃 μs
-- instance HasSatisfactionFormula : HasSatisfaction Formula
-- HasSatisfaction._⊨_ HasSatisfactionFormula I (atomic 𝑃 τs) = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ true ⟩
-- HasSatisfaction._⊨_ HasSatisfactionFormula I (logical φ₁ φ₂) = ¬ I ⊨ φ₁ × ¬ I ⊨ φ₂
-- HasSatisfaction._⊨_ HasSatisfactionFormula I (quantified 𝑥 φ) = (𝓘 : Interpretation) → 𝓘 ≞ I / 𝑥 → 𝓘 ⊨ φ
-- instance HasSatisfaction𝓕ormula : {Is𝓕ormula : Formula → Set} → HasSatisfaction (𝓕ormula Is𝓕ormula)
-- HasSatisfaction._⊨_ HasSatisfaction𝓕ormula I ⟪ φ ⟫ = I ⊨ φ
-- instance HasSatisfactionLiteralFormula : HasSatisfaction LiteralFormula
-- HasSatisfaction._⊨_ HasSatisfactionLiteralFormula I ⟨ atomic 𝑃 τs ⟩ = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ true ⟩
-- HasSatisfaction._⊨_ HasSatisfactionLiteralFormula I ⟨ logical 𝑃 τs ⟩ = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ false ⟩
-- instance HasSatisfactionList : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ → HasSatisfaction $ List A
-- HasSatisfaction._⊨_ HasSatisfactionList I [] = ⊤
-- HasSatisfaction._⊨_ HasSatisfactionList I (x ∷ xs) = I ⊨ x × I ⊨ xs
-- instance 𝓐ssertionSequent : 𝓐ssertion Sequent
-- 𝓐ssertionSequent = record {}
-- instance 𝓐ssertionLiteralSequent : 𝓐ssertion LiteralSequent
-- 𝓐ssertionLiteralSequent = record {}
-- instance 𝓐ssertionProblem : 𝓐ssertion Problem
-- 𝓐ssertionProblem = record {}
-- instance 𝓐ssertionLiteralProblem : 𝓐ssertion LiteralProblem
-- 𝓐ssertionLiteralProblem = record {}
-- instance HasSatisfactionSequent : HasSatisfaction Sequent
-- HasSatisfaction._⊨_ HasSatisfactionSequent I (φᵗ ╱ φˢs) = I ⊨ φˢs → I ⊨ φᵗ
-- instance HasSatisfactionLiteralSequent : HasSatisfaction LiteralSequent
-- HasSatisfaction._⊨_ HasSatisfactionLiteralSequent I Φ = I ⊨ sequent Φ
-- instance HasSatisfactionProblem : HasSatisfaction Problem
-- HasSatisfaction._⊨_ HasSatisfactionProblem I (Φ⁺s ¶ Φ⁻) = I ⊨ Φ⁺s → I ⊨ Φ⁻
-- instance HasSatisfactionLiteralProblem : HasSatisfaction LiteralProblem
-- HasSatisfaction._⊨_ HasSatisfactionLiteralProblem I 𝔓 = I ⊨ problem 𝔓
-- record HasDecidableSatisfaction (A : Set) ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ : Set₁
-- where
-- field
-- _⊨?_ : (I : Interpretation) → (x : A) → Dec (I ⊨ x)
-- open HasDecidableSatisfaction ⦃ … ⦄
-- {-# DISPLAY HasDecidableSatisfaction._⊨?_ _ = _⊨?_ #-}
-- instance HasDecidableSatisfactionFormula : HasDecidableSatisfaction Formula
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionFormula I (atomic 𝑃 τs) = {!!}
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionFormula I (logical φ₁ φ₂) = {!!}
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionFormula I (quantified 𝑥 φ) = {!!}
-- instance HasDecidableSatisfactionLiteralFormula : HasDecidableSatisfaction LiteralFormula
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionLiteralFormula
-- I ⟨ atomic 𝑃 τs ⟩
-- with 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩
-- … | ⟨ true ⟩ = yes refl
-- … | ⟨ false ⟩ = no λ ()
-- HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionLiteralFormula
-- I ⟨ logical 𝑃 τs ⟩
-- with 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩
-- … | ⟨ true ⟩ = no λ ()
-- … | ⟨ false ⟩ = yes refl
-- module _ {A} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄
-- where
-- ⊨_ : A → Set
-- ⊨ x = (I : Interpretation) → I ⊨ x
-- ⊭_ : A → Set
-- ⊭_ = ¬_ ∘ ⊨_
-- record HasDecidableValidation (A : Set) ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSatisfaction A ⦄ : Set₁
-- where
-- field
-- ⊨?_ : (x : A) → Dec $ ⊨ x
-- instance HasDecidableValidationFormula : HasDecidableValidation Formula
-- HasDecidableValidation.⊨?_ HasDecidableValidationFormula (atomic 𝑃 τs) = {!!}
-- HasDecidableValidation.⊨?_ HasDecidableValidationFormula (logical φ₁ φ₂) = {!!}
-- HasDecidableValidation.⊨?_ HasDecidableValidationFormula (quantified 𝑥 φ) = {!!}
-- instance HasDecidableValidationLiteralFormula : HasDecidableValidation LiteralFormula
-- HasDecidableValidationLiteralFormula = {!!}
-- instance HasDecidableValidationSequent : HasDecidableValidation Sequent
-- HasDecidableValidationSequent = {!!}
-- instance HasDecidableValidationLiteralSequent : HasDecidableValidation LiteralSequent
-- HasDecidableValidationLiteralSequent = {!!}
-- instance HasDecidableValidationProblem : HasDecidableValidation Problem
-- HasDecidableValidationProblem = {!!}
-- instance HasDecidableValidationLiteralProblem : HasDecidableValidation LiteralProblem
-- HasDecidableValidationLiteralProblem = {!!}
-- postulate
-- substituteFormula : (VariableName → Term) → Formula → Formula
-- record Unifier : Set
-- where
-- field
-- unifier-left unifier-right : VariableName → Term
-- open Unifier
-- record _Unifies_and_ (υ : Unifier) (φ₁ φ₂ : Formula) : Set
-- where
-- field
-- unification-law : substituteFormula (unifier-left υ) φ₁ ≡ substituteFormula (unifier-right υ) φ₂
-- record HasSubstantiveDischarge (+ : Set) (- : Set) : Set₁
-- where
-- field
-- _≽_ : + → - → Set
-- _⋡_ : + → - → Set
-- + ⋡ - = ¬ + ≽ -
-- open HasSubstantiveDischarge ⦃ … ⦄
-- {-# DISPLAY HasSubstantiveDischarge._≽_ _ = _≽_ #-}
-- instance HasSubstantiveDischargeList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ → HasSubstantiveDischarge (List A) A
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeList +s - = {!!} -- ∃ λ c → (c ∈ +s) × c ≽ -
-- instance HasSubstantiveDischargeListList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ → HasSubstantiveDischarge (List A) (List A)
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeListList +s -s = {!!} -- ∀ i → i ∈ -s → +s ≽ i
-- instance HasSubstantiveDischargeFormulaFormula : HasSubstantiveDischarge Formula Formula
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeFormulaFormula φ₁ φ₂ = ∃ λ υ → υ Unifies φ₁ and φ₂
-- instance HasSubstantiveDischargeSequentSequent : HasSubstantiveDischarge Sequent Sequent
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeSequentSequent (+ᵗ ╱ +ᵖs) (-ᵗ ╱ -ᵖs) = {!!} -- +ᵗ ≽ -ᵗ × +ᵖs ≽ -ᵖs -- use "unification into", from John's "Natural Deduction"
-- instance HasSubstantiveDischargeProblemProblem : HasSubstantiveDischarge Problem Problem
-- HasSubstantiveDischarge._≽_ HasSubstantiveDischargeProblemProblem (+s ¶ +) (-s ¶ -) = {!!} -- + ≽ - × +s ≽ -s
-- record HasDecidableSubstantiveDischarge (+ : Set) (- : Set) ⦃ _ : HasSubstantiveDischarge (+) (-) ⦄ : Set₁
-- where
-- field
-- _≽?_ : (+ : +) → (- : -) → Dec $ + ≽ -
-- open HasDecidableSubstantiveDischarge ⦃ … ⦄
-- {-# DISPLAY HasDecidableSubstantiveDischarge._≽?_ _ = _≽?_ #-}
-- instance HasDecidableSubstantiveDischargeList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ ⦃ _ : HasDecidableSubstantiveDischarge A A ⦄ ⦃ _ : Eq A ⦄ → HasDecidableSubstantiveDischarge (List A) A
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeList +s - = {!!}
-- instance HasDecidableSubstantiveDischargeListList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A A ⦄ ⦃ _ : HasDecidableSubstantiveDischarge A A ⦄ ⦃ _ : Eq A ⦄ → HasDecidableSubstantiveDischarge (List A) (List A)
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeListList +s -s = {!!}
-- instance HasDecidableSubstantiveDischargeFormulaFormula : HasDecidableSubstantiveDischarge Formula Formula
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeFormulaFormula = {!!} -- _≟_
-- instance HasDecidableSubstantiveDischargeSequentSequent : HasDecidableSubstantiveDischarge Sequent Sequent
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeSequentSequent = {!!}
-- instance HasDecidableSubstantiveDischargeProblemProblem : HasDecidableSubstantiveDischarge Problem Problem
-- HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeProblemProblem = {!!}
-- record SubstantiveDischargeIsConsistent (+ : Set) (- : Set) ⦃ _ : HasNegation (-) ⦄ ⦃ _ : HasSubstantiveDischarge (+) (-) ⦄ : Set₁
-- where
-- field
-- ≽-consistent : {+ : +} → { - : - } → + ≽ - → + ⋡ ~ -
-- open SubstantiveDischargeIsConsistent ⦃ … ⦄
-- {-# DISPLAY SubstantiveDischargeIsConsistent.≽-consistent _ = ≽-consistent #-}
-- record SubstantiveDischargeIsReflexive (A : Set) ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁
-- where
-- field
-- ≽-reflexive : (x : A) → x ≽ x
-- open SubstantiveDischargeIsReflexive ⦃ … ⦄
-- {-
-- record SubstantiveDischargeIsReflexive (A : Set) ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁
-- where
-- field
-- ≽-reflexive : {x : A} → x ≽ x
-- open SubstantiveDischargeIsReflexive ⦃ … ⦄
-- -}
-- {-# DISPLAY SubstantiveDischargeIsReflexive.≽-reflexive _ = ≽-reflexive #-}
-- record HasVacuousDischarge (A : Set) ⦃ _ : HasNegation A ⦄ ⦃ _ : HasSubstantiveDischarge A A ⦄ : Set₁
-- where
-- ◁_ : List A → Set
-- ◁ +s = ∃ λ (s : A) → (+s ≽ s) × (+s ≽ ~ s)
-- ⋪_ : List A → Set
-- ⋪_ = ¬_ ∘ ◁_
-- open HasVacuousDischarge ⦃ … ⦄
-- {-# DISPLAY HasVacuousDischarge.◁_ _ = ◁_ #-}
-- {-# DISPLAY HasVacuousDischarge.⋪_ _ = ⋪_ #-}
-- infixr 1 ,_
-- pattern ,_ p = _ , p
-- pattern ◁pattern c₁∈xs c₁≽s c₂∈xs c₂≽~s = , (((, (c₁∈xs , c₁≽s)) , (, (c₂∈xs , c₂≽~s))))
-- record HasDecidableVacuousDischarge (A : Set)
-- ⦃ _ : HasNegation A ⦄
-- ⦃ _ : HasSubstantiveDischarge A A ⦄
-- ⦃ _ : HasVacuousDischarge A ⦄
-- --⦃ _ : HasDecidableSubstantiveDischarge A A ⦄
-- --⦃ _ : SubstantiveDischargeIsConsistent A A ⦄
-- --⦃ _ : SubstantiveDischargeIsReflexive A ⦄
-- ⦃ _ : Eq A ⦄
-- : Set₁
-- where
-- field
-- ◁?_ : (x : List A) → Dec $ ◁ x
-- instance HasDecidableVacuousDischarge𝓢equent : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : Eq A ⦄ ⦃ _ : HasNegation (𝓢equent A) ⦄ ⦃ _ : HasSubstantiveDischarge (𝓢equent A) (𝓢equent A) ⦄ ⦃ _ : HasVacuousDischarge (𝓢equent A) ⦄ → HasDecidableVacuousDischarge (𝓢equent A)
-- HasDecidableVacuousDischarge𝓢equent = {!!}
-- {-
-- instance
-- ◁? [] = no (λ { (_ , (_ , () , _) , _)})
-- ◁? (x ∷ xs) with xs ≽? ~ x
-- ◁? (x ∷ xs) | yes (, ~x!∈xs , ~x!≽~x) = yes $ , (((, (here xs , ≽-reflexive x)) , (, (there _ ~x!∈xs , ~x!≽~x))))
-- ◁? (x ∷ xs) | no xs⋡~x with ◁? xs
-- ◁? (x ∷ xs) | no xs⋡~x | yes (◁pattern c₁∈xs c₁≽s c₂∈xs c₂≽~s) = yes (◁pattern (there _ c₁∈xs) c₁≽s (there _ c₂∈xs) c₂≽~s)
-- ◁? (x ∷ xs) | no xs⋡~x | no ⋪xs = no λ
-- { (◁pattern (here .xs) x≽s (here .xs) c₂≽~s) → {!xs⋡~x!}
-- ; (◁pattern (here .xs) x≽s (there _ c₂∈xs) c₂≽~s) → {!xs⋡~x!}
-- ; (◁pattern (there _ c₁∈xs) c₁≽s c₂∈xxs c₂≽~s) → {!xs⋡~x!} }
-- -}
-- --{-⋪xs (◁pattern {!!} c₁≽s {!!} c₂≽~s)-}
-- open HasDecidableVacuousDischarge ⦃ … ⦄
-- {-# DISPLAY HasDecidableVacuousDischarge.◁?_ _ = ◁?_ #-}
-- instance HasDecidableVacuousDischargeFormula : HasDecidableVacuousDischarge Formula
-- HasDecidableVacuousDischarge.◁?_ HasDecidableVacuousDischargeFormula [] = {!!}
-- HasDecidableVacuousDischarge.◁?_ HasDecidableVacuousDischargeFormula (φ ∷ φs) = {!!}
-- record HasSalvation (A : Set) : Set₁
-- where
-- field
-- -- {isVacuouslyDischargable} : Set
-- -- ⦃ hasVacuousDischarge ⦄ : HasVacuousDischarge isVacuouslyDischargable
-- ▷_ : A → Set
-- open HasSalvation ⦃ … ⦄
-- instance
-- HasSalvation𝓢equent : {A : Set} ⦃ _ : 𝓐ssertion A ⦄ ⦃ _ : HasSubstantiveDischarge A A ⦄ ⦃ _ : HasNegation A ⦄ ⦃ _ : HasVacuousDischarge A ⦄ → HasSalvation $ 𝓢equent A
-- HasSalvation.▷_ HasSalvation𝓢equent (φᵖs ⊢ φᵗs) = (◁ φᵖs) ⊎ (φᵖs ≽ φᵗs)
-- {-# DISPLAY HasSalvation.▷_ _ = ▷_ #-}
-- record HasDecidableSalvation (A : Set) ⦃ _ : HasSalvation A ⦄ : Set₁
-- where
-- field
-- ▷?_ : (x : A) → Dec $ ▷_ x
-- open HasDecidableSalvation ⦃ … ⦄
-- {-# DISPLAY HasDecidableSalvation.▷?_ _ = ▷?_ #-}
-- ∀[_♭_] : VariableName → Formula → Formula
-- ∀[_♭_] = quantified
-- {-# DISPLAY quantified = ∀[_♭_] #-}
-- _∧_ : Formula → Formula → Formula
-- φ₁ ∧ φ₂ = ~ φ₁ ⊗ ~ φ₂
-- _∨_ : Formula → Formula → Formula
-- φ₁ ∨ φ₂ = ~ (φ₁ ⊗ φ₂)
-- _⊃_ : Formula → Formula → Formula
-- φ₁ ⊃ φ₂ = ~ φ₁ ∨ φ₂
-- _⟷_ : Formula → Formula → Formula
-- φ₁ ⟷ φ₂ = (φ₁ ⊗ (φ₂ ⊗ φ₂)) ⊗ ((φ₁ ⊗ φ₁) ⊗ φ₂) -- TODO check that this is logically equivalent to the more verbose, (φ₁ ⊃ φ₂) ∧ (φ₂ ⊃ φ₁)
-- data TermCode : Set
-- where
-- variable : VariableName → TermCode
-- function : FunctionName → Arity → TermCode
-- termCode-function-inj₁ : ∀ {𝑓₁ 𝑓₂ arity₁ arity₂} → TermCode.function 𝑓₁ arity₁ ≡ function 𝑓₂ arity₂ → 𝑓₁ ≡ 𝑓₂
-- termCode-function-inj₁ refl = refl
-- termCode-function-inj₂ : ∀ {𝑓₁ 𝑓₂ arity₁ arity₂} → TermCode.function 𝑓₁ arity₁ ≡ function 𝑓₂ arity₂ → arity₁ ≡ arity₂
-- termCode-function-inj₂ refl = refl
-- instance
-- EqTermCode : Eq TermCode
-- Eq._==_ EqTermCode (variable 𝑥₁) (variable 𝑥₂) with 𝑥₁ ≟ 𝑥₂
-- … | yes 𝑥₁≡𝑥₂ rewrite 𝑥₁≡𝑥₂ = yes refl
-- … | no 𝑥₁≢𝑥₂ = no (λ { refl → 𝑥₁≢𝑥₂ refl})
-- Eq._==_ EqTermCode (variable x) (function x₁ x₂) = no (λ ())
-- Eq._==_ EqTermCode (function x x₁) (variable x₂) = no (λ ())
-- Eq._==_ EqTermCode (function 𝑓₁ 𝑎₁) (function 𝑓₂ 𝑎₂) = decEq₂ termCode-function-inj₁ termCode-function-inj₂ (𝑓₁ ≟ 𝑓₂) (𝑎₁ ≟ 𝑎₂)
-- mutual
-- encodeTerm : Term → List TermCode
-- encodeTerm (variable 𝑥) = variable 𝑥 ∷ []
-- encodeTerm (function 𝑓 (⟨_⟩ {arity} τs)) = function 𝑓 arity ∷ encodeTerms τs
-- encodeTerms : {arity : Arity} → Vector Term arity → List TermCode
-- encodeTerms ⟨ [] ⟩ = []
-- encodeTerms ⟨ τ ∷ τs ⟩ = encodeTerm τ ++ encodeTerms ⟨ τs ⟩
-- mutual
-- decodeTerm : Nat → StateT (List TermCode) Maybe Term
-- decodeTerm zero = lift nothing
-- decodeTerm (suc n) = do
-- caseM get of λ
-- { [] → lift nothing
-- ; (variable 𝑥 ∷ _) →
-- modify (drop 1) ~|
-- return (variable 𝑥)
-- ; (function 𝑓 arity ∷ _) →
-- modify (drop 1) ~|
-- decodeFunction n 𝑓 arity }
-- decodeFunction : Nat → FunctionName → Arity → StateT (List TermCode) Maybe Term
-- decodeFunction n 𝑓 arity = do
-- τs ← decodeTerms n arity -|
-- return (function 𝑓 ⟨ τs ⟩)
-- decodeTerms : Nat → (arity : Arity) → StateT (List TermCode) Maybe (Vector Term arity)
-- decodeTerms n ⟨ zero ⟩ = return ⟨ [] ⟩
-- decodeTerms n ⟨ suc arity ⟩ = do
-- τ ← decodeTerm n -|
-- τs ← decodeTerms n ⟨ arity ⟩ -|
-- return ⟨ τ ∷ vector τs ⟩
-- .decode-is-inverse-of-encode : ∀ τ → runStateT (decodeTerm ∘ length $ encodeTerm τ) (encodeTerm τ) ≡ (just $ τ , [])
-- decode-is-inverse-of-encode (variable 𝑥) = refl
-- decode-is-inverse-of-encode (function 𝑓 ⟨ ⟨ [] ⟩ ⟩) = {!!}
-- decode-is-inverse-of-encode (function 𝑓 ⟨ ⟨ variable 𝑥 ∷ τs ⟩ ⟩) = {!!}
-- decode-is-inverse-of-encode (function 𝑓 ⟨ ⟨ function 𝑓' τs' ∷ τs ⟩ ⟩) = {!!}
-- module ExampleEncodeDecode where
-- example-Term : Term
-- example-Term =
-- (function ⟨ 2 ⟩
-- ⟨ ⟨ ( variable ⟨ 0 ⟩ ∷
-- function ⟨ 3 ⟩ ⟨ ⟨ variable ⟨ 2 ⟩ ∷ [] ⟩ ⟩ ∷
-- variable ⟨ 5 ⟩ ∷ [] )
-- ⟩ ⟩
-- )
-- -- function ⟨ 2 ⟩ ⟨ 3 ⟩ ∷ variable ⟨ 0 ⟩ ∷ function ⟨ 3 ⟩ ⟨ 1 ⟩ ∷ variable ⟨ 2 ⟩ ∷ variable ⟨ 5 ⟩ ∷ []
-- example-TermCodes : List TermCode
-- example-TermCodes = encodeTerm example-Term
-- example-TermDecode : Maybe (Term × List TermCode)
-- example-TermDecode = runStateT (decodeTerm (length example-TermCodes)) example-TermCodes
-- example-verified : example-TermDecode ≡ (just $ example-Term , [])
-- example-verified = refl
-- example-bad : runStateT (decodeTerm 2) (function ⟨ 2 ⟩ ⟨ 2 ⟩ ∷ variable ⟨ 0 ⟩ ∷ []) ≡ nothing
-- example-bad = refl
-- record TermNode : Set
-- where
-- inductive
-- field
-- children : List (TermCode × TermNode)
-- number : Nat
-- open TermNode
-- _child∈_ : TermCode → TermNode → Set
-- _child∈_ 𝔠 𝔫 = 𝔠 ∈ (fst <$> children 𝔫)
-- _child∉_ : TermCode → TermNode → Set
-- 𝔠 child∉ 𝔫 = ¬ (𝔠 child∈ 𝔫)
-- _child∈?_ : (𝔠 : TermCode) → (𝔫 : TermNode) → Dec $ 𝔠 child∈ 𝔫
-- c child∈? record { children = cs } = c ∈? (fst <$> cs)
-- getChild : {𝔠 : TermCode} → (𝔫 : TermNode) → 𝔠 child∈ 𝔫 → TermNode
-- getChild {𝔠} (record { children = [] ; number = number₁ }) ()
-- getChild {._} (record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }) zero = snd₁
-- getChild {𝔠} (𝔫@record { children = x ∷ children₁ ; number = number₁ }) (suc x₁) = getChild record 𝔫 { children = children₁ } x₁
-- addChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 child∉ 𝔫 → TermNode → TermNode
-- addChild {𝔠} 𝔫 𝔠∉𝔫 𝔫' =
-- record 𝔫 { children = (𝔠 , 𝔫') ∷ children 𝔫 }
-- setChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 child∈ 𝔫 → TermNode → TermNode
-- setChild {𝔠} record { children = [] ; number = number₁ } () 𝔫'
-- setChild 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } (zero) 𝔫' =
-- record 𝔫 { children = ((fst₁ , 𝔫') ∷ children₁) }
-- setChild {𝔠} 𝔫@record { children = (x ∷ children₁) ; number = number₁ } (suc 𝔠∈𝔫) 𝔫' =
-- record 𝔫 { children = (x ∷ children (setChild (record 𝔫 { children = children₁ }) 𝔠∈𝔫 𝔫')) }
-- setGet-ok : ∀ {𝔠} 𝔫 → (𝔠∈𝔫 : 𝔠 child∈ 𝔫) → setChild 𝔫 𝔠∈𝔫 (getChild 𝔫 𝔠∈𝔫) ≡ 𝔫
-- setGet-ok record { children = [] ; number = number₁ } ()
-- setGet-ok record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } (zero) = refl
-- setGet-ok record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } (suc 𝔠∈𝔫) rewrite setGet-ok (record { children = children₁ ; number = number₁ }) 𝔠∈𝔫 = refl
-- storeTermCodes : List TermCode → Nat → StateT TermNode Identity Nat
-- storeTermCodes [] 𝔑 = return 𝔑
-- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- 𝔫 ← get -|
-- case 𝔠 child∈? 𝔫 of λ
-- { (no 𝔠∉tests) →
-- let 𝔑' , 𝔫' = runIdentity $
-- runStateT
-- (storeTermCodes 𝔠s $ suc 𝔑)
-- (record
-- { children = []
-- ; number = suc 𝔑 }) in
-- put ((addChild 𝔫 𝔠∉tests 𝔫')) ~|
-- return 𝔑'
-- ; (yes 𝔠∈tests) →
-- let 𝔑' , 𝔫' = runIdentity $
-- runStateT
-- (storeTermCodes 𝔠s $ suc 𝔑)
-- ((getChild 𝔫 𝔠∈tests)) in
-- put ((setChild 𝔫 𝔠∈tests 𝔫')) ~|
-- return 𝔑' }
-- storeTermCodes[] : (𝔫 : TermNode) (𝔑 : Nat) → (runIdentity $ runStateT (storeTermCodes [] 𝔑) 𝔫) ≡ (𝔑 , 𝔫)
-- storeTermCodes[] 𝔫 𝔑 = refl
-- --{-# REWRITE storeTermCodes[] #-}
-- storeTermCodes' : List TermCode → StateT Nat (StateT TermNode Identity) ⊤
-- storeTermCodes' 𝔠s =
-- 𝔑 ← get -|
-- tn ← lift get -|
-- (let 𝔑' , tn' = runIdentity $ runStateT (storeTermCodes 𝔠s 𝔑) tn in
-- put 𝔑' ~| lift (put tn') ~| return tt)
-- mutual
-- storeTerm : Term → StateT Nat (StateT TermNode Identity) ⊤
-- storeTerm τ@(variable _) = storeTermCodes' (encodeTerm τ)
-- storeTerm τ@(function _ τs) = storeTermCodes' (encodeTerm τ) ~| storeTerms τs
-- storeTerms : Terms → StateT Nat (StateT TermNode Identity) ⊤
-- storeTerms ⟨ ⟨ [] ⟩ ⟩ = return tt
-- storeTerms ⟨ ⟨ τ ∷ τs ⟩ ⟩ = storeTerm τ ~| storeTerms ⟨ ⟨ τs ⟩ ⟩ ~| return tt
-- module ExampleStoreTerm where
-- example-Term₁ : Term
-- example-Term₁ =
-- (function ⟨ 2 ⟩
-- ⟨ ⟨ variable ⟨ 0 ⟩
-- ∷ function ⟨ 3 ⟩
-- ⟨ ⟨ variable ⟨ 2 ⟩ ∷ [] ⟩ ⟩
-- ∷ variable ⟨ 5 ⟩
-- ∷ []
-- ⟩ ⟩
-- )
-- example-Term₂ : Term
-- example-Term₂ =
-- (function ⟨ 2 ⟩
-- ⟨ ⟨ variable ⟨ 0 ⟩
-- ∷ variable ⟨ 2 ⟩
-- ∷ function ⟨ 3 ⟩
-- ⟨ ⟨ variable ⟨ 2 ⟩ ∷ [] ⟩ ⟩
-- ∷ variable ⟨ 5 ⟩
-- ∷ []
-- ⟩ ⟩
-- )
-- topNode : TermNode
-- topNode = record { children = [] ; number = 0 }
-- example-storeTerm : (⊤ × Nat) × TermNode
-- example-storeTerm = runIdentity $ runStateT (runStateT (storeTerm example-Term₁ >> storeTerm example-Term₂) 0) topNode
-- NodeStateT = StateT TermNode
-- TopNodeState = StateT Nat (NodeStateT Identity)
-- storeLiteralFormulaTerms : LiteralFormula → StateT Nat (StateT TermNode Identity) ⊤
-- storeLiteralFormulaTerms ⟨ atomic 𝑃 τs ⟩ = storeTerms τs
-- storeLiteralFormulaTerms ⟨ logical 𝑃 τs ⟩ = storeTerms τs
-- storeSequentLiteralFormulaTerms : 𝓢equent LiteralFormula → StateT Nat (StateT TermNode Identity) ⊤′
-- storeSequentLiteralFormulaTerms (φˢs ⊢ φᵗ) = sequence $ storeLiteralFormulaTerms <$> ({!φᵗ!} ∷ φˢs)
-- record FindTermNode (A : Set) : Set
-- where
-- field
-- findTermNode : A → TermNode → Maybe TermNode
-- open FindTermNode ⦃ … ⦄
-- instance
-- FindTermNodeTermCode : FindTermNode TermCode
-- FindTermNode.findTermNode FindTermNodeTermCode termCode record { children = [] ; number = number₁ } = nothing
-- FindTermNode.findTermNode FindTermNodeTermCode termCode 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } = ifYes fst₁ ≟ termCode then just snd₁ else findTermNode termCode record 𝔫 { children = children₁ }
-- FindTermNodeTermCodes : FindTermNode (List TermCode)
-- FindTermNode.findTermNode FindTermNodeTermCodes [] node = just node
-- FindTermNode.findTermNode FindTermNodeTermCodes (x ∷ termCodes) node = join $ findTermNode termCodes <$> findTermNode x node
-- FindTermNodeTerm : FindTermNode Term
-- FindTermNode.findTermNode FindTermNodeTerm term node = findTermNode (encodeTerm term) node
-- -- This is starting to get difficult. We need Agda to know that the Term is encoded in the TermNode. Then we can drop the Maybe
-- getInterpretationOfTerm : Term → TermNode → Maybe Element
-- getInterpretationOfTerm τ node = ⟨_⟩ ∘ number <$> findTermNode (encodeTerm τ) node
-- FindTermNodeTermCode-ok : ∀ {𝔠 𝔫} → 𝔠 child∈ 𝔫 → IsJust (findTermNode 𝔠 𝔫)
-- FindTermNodeTermCode-ok {𝔠} {record { children = [] ; number = number₁ }} ()
-- --FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ = case (fst₁ ≟_) 𝔠 , graphAt {B = λ 𝑐 → Dec (fst₁ ≡ 𝑐)} (fst₁ ≟_) 𝔠 of λ { (yes x , snd₂) → {!!} ; (no x , snd₂) → {!!}} --λ { ((yes ===) , (inspect s1)) → {!!} ; ((no =n=) , inspect s2) → {!!} }
-- --FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ = case fst₁ ≟ 𝔠 of λ { (yes refl) → {!!} ; (no x) → {!!}}
-- FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ with fst₁ ≟ 𝔠
-- FindTermNodeTermCode-ok {𝔠} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} x₁ | yes eq2 = tt
-- FindTermNodeTermCode-ok {.fst₁} {record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} (zero) | no neq = ⊥-elim (neq refl)
-- FindTermNodeTermCode-ok {𝔠} {𝔫@record { children = (fst₁ , snd₁) ∷ children₁ ; number = number₁ }} (suc x₁) | no neq = FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} x₁
-- Justified : ∀ {a} {A : Set a} → (m : Maybe A) → IsJust m → ∃ λ x → m ≡ just x
-- Justified nothing ()
-- Justified (just x) x₁ = _ , refl
-- storeTerm-ok : ∀ τ 𝔫 𝔑 → IsJust (findTermNode τ (snd (runIdentity (runStateT (runStateT (storeTerm τ) 𝔑) 𝔫))))
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 with variable 𝑥 child∈? 𝔫
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 | no x with TermCode.variable 𝑥 ≟ variable 𝑥
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 | no x | yes _ = tt
-- storeTerm-ok (variable 𝑥) 𝔫 𝔑 | no x | no variable𝑥≢variable𝑥 = ⊥-elim (variable𝑥≢variable𝑥 refl)
-- --storeTerm-ok (variable 𝑥) 𝔫 𝔑 | yes vx∈𝔫 rewrite setGet-ok 𝔫 vx∈𝔫 = {!𝔫!}
-- storeTerm-ok (variable 𝑥) record { children = [] ; number = number₁ } 𝔑 | yes ()
-- --storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 rewrite setGet-ok 𝔫 vx∈𝔫 = {!!}
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 rewrite setGet-ok 𝔫 vx∈𝔫 with fst₁ ≟ variable 𝑥
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | yes eq = tt
-- --… | no neq = case vx∈𝔫 of λ { (here .(map fst children₁)) → ⊥-elim (neq refl) ; (there .fst₁ asdf) → case graphAt FindTermNodeTermCode-ok asdf of λ { (ingraph sss) → {!!} } } -- storeTerm-ok x {!record 𝔫 { children = children₁ }!} 𝔑 -- x record 𝔫 { children = children₁ } 𝔑
-- --… | no neq = case vx∈𝔫 of λ { (here .(map fst children₁)) → ⊥-elim (neq refl) ; (there .fst₁ asdf) → case inspect $ FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} asdf of λ { (.(FindTermNodeTermCode-ok asdf) , ingraph refl) → {!!}} } -- storeTerm-ok x {!record 𝔫 { children = children₁ }!} 𝔑 -- x record 𝔫 { children = children₁ } 𝔑
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq with vx∈𝔫
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq | zero = ⊥-elim (neq refl)
-- --storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq | there dfdsf fdsdfs with FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} fdsdfs | graphAt (FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }}) fdsdfs
-- --… | frfrrf | ingraph tttttt = transport _ (snd $ Justified (FindTermNode.findTermNode FindTermNodeTermCode (variable 𝑥) (record { children = children₁ ; number = number₁ })) (FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} fdsdfs)) _
-- storeTerm-ok x@(variable 𝑥) 𝔫@record { children = ((fst₁ , snd₁) ∷ children₁) ; number = number₁ } 𝔑 | yes vx∈𝔫 | no neq | suc fdsdfs rewrite (snd $ Justified (FindTermNode.findTermNode FindTermNodeTermCode (variable 𝑥) (record { children = children₁ ; number = number₁ })) (FindTermNodeTermCode-ok {𝔫 = record 𝔫 { children = children₁ }} fdsdfs)) = tt
-- storeTerm-ok (function 𝑥 𝑎) 𝔫 𝔑 with (function 𝑥 (arity 𝑎)) child∈? 𝔫
-- storeTerm-ok (function 𝑥 ⟨ ⟨ [] ⟩ ⟩) 𝔫 𝔑 | no x with Eq._==_ EqFunctionName ⟨ name 𝑥 ⟩ ⟨ name 𝑥 ⟩
-- storeTerm-ok (function 𝑥 ⟨ ⟨ [] ⟩ ⟩) 𝔫 𝔑 | no x | (yes refl) = tt
-- … | no neq = ⊥-elim (neq refl)
-- --storeTerm-ok τ₀@(function 𝑓 ⟨ τ₁ ∷ τ₂s ⟩) 𝔫 𝔑 | no 𝔠₁∉𝔫 = {!τ₁!}
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₁∉𝔫 with variable 𝑥 child∈? 𝔫
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) with 𝑓₀ ≟ 𝑓₀
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | yes refl with TermCode.variable 𝑥 ≟ variable 𝑥
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | yes refl | yes eq = tt
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | yes refl | no neq = ⊥-elim (neq refl)
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥 ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (yes 𝔠₁∈𝔫) | no neq = ⊥-elim (neq refl)
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) with 𝑓₀ ≟ 𝑓₀
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | yes refl with TermCode.variable 𝑥₁ ≟ variable 𝑥₁
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | yes refl | yes 𝔠₁≡𝔠₁ = tt
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | yes refl | no 𝔠₁≢𝔠₁ = ⊥-elim (𝔠₁≢𝔠₁ refl)
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ [] ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | (no 𝔠₁∉𝔫) | no 𝑓₀≢𝑓₀ = ⊥-elim (𝑓₀≢𝑓₀ refl) -- rewrite setGet-ok 𝔫 𝔠₁∈𝔫
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ τ₂ ∷ τ₃s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 with variable 𝑥₁ child∈? 𝔫
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ τ₂ ∷ τ₃s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | yes 𝔠₁∈𝔫 = {!!}
-- storeTerm-ok (function 𝑓₀ ⟨ ⟨ variable 𝑥₁ ∷ τ₂ ∷ τ₃s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₀∉𝔫 | no 𝔠₁∉𝔫 = {!!}
-- storeTerm-ok τ₀@(function 𝑓₀ ⟨ ⟨ function 𝑓₁ τ₁s ∷ τ₂s ⟩ ⟩) 𝔫 𝔑 | no 𝔠₁∉𝔫 = {!!}
-- storeTerm-ok (function 𝑥 x₁) 𝔫 𝔑 | yes x = {!!}
-- mutual
-- storeTermVerifiably' : (τ : Term) → StateT Nat (StateT (Σ TermNode λ n → IsJust (findTermNode τ n)) Identity) ⊤
-- storeTermVerifiably' (variable x) = {!!}
-- storeTermVerifiably' (function x x₁) = {!!}
-- storeTermVerifiably : Term → StateT Nat (StateT TermNode Identity) ⊤
-- storeTermVerifiably τ@(variable _) = storeTermCodes' (encodeTerm τ)
-- storeTermVerifiably τ@(function _ τs) = storeTermCodes' (encodeTerm τ) ~| storeTermsVerifiably τs
-- storeTermsVerifiably : Terms → StateT Nat (StateT TermNode Identity) ⊤
-- storeTermsVerifiably ⟨ ⟨ [] ⟩ ⟩ = return tt
-- storeTermsVerifiably ⟨ ⟨ τ ∷ τs ⟩ ⟩ = storeTermVerifiably τ ~| storeTermsVerifiably ⟨ ⟨ τs ⟩ ⟩ ~| return tt
-- Theorem1 : {Φ : 𝓢equent (𝓢equent LiteralFormula)} → {!⊨!} Φ ↔ {!▷!} Φ
-- Theorem1 = {!!}
-- {-
-- Theorem1 {Φ@(χs ¶ ι)} = Theorem1a , Theorem1b
-- where
-- Theorem1a : ⊨ Φ → ▷ Φ
-- Theorem1a with ▷? Φ
-- … | yes ▷Φ = const ▷Φ
-- … | no ⋫Φ =
-- let I , I⊨χs , I⊭ι = Lemma1a in
-- λ I→I⊨cs→I⊨i → ⊥-elim $ I⊭ι $ I→I⊨cs→I⊨i I I⊨χs
-- where
-- Lemma1a : ∃ λ I → I ⊨ χs × I ⊭ ι
-- -- To construct the interpretation, consider a unique list, τ₀, τ₁, …, τₙ, of terms in ι ∷ χs. For each term, τ, we find <TODO> interpretations, 𝓘, such that for any I ∈ 𝓘, and any i ∈ 0, …, n, τ⟦ I ⟧ τᵢ = i. For each formula φ ∈ ι ∷ χs, we find <TODO> an interpretation I ∈ 𝓘 such that 𝑃⟦ I ⟧ φ = true when φ ∈ χs and 𝑃⟦ I ⟧ φ = false when φ = ι.
-- -- For all terms in ι ∷ χs, find a coding into Nat that uniquely determines each term. To do this, compute the maximum functional depth of terms, D, the maximal arity of terms, A, the maximal function name, F, and the maximal variable name, V. Each term can then be coded into Fin V + (D₀ = F + F * V + F * V ^ 2 + ... + F * V ^ A) + (D₀ ...
-- -- Encode each term in a discrimination network. Each new term stored is assigned a unique id
-- Lemma1a = {!!}
-- where
-- Theorem1b : ▷ Φ → ⊨ Φ
-- Theorem1b = {!!}
-- -}
-- negationEliminationRule : (I : Interpretation) (φ : Formula) → I ⊨ ~ (~ φ) → I ⊨ φ
-- negationEliminationRule I φ (¬[I⊭φ×I⊭φ] , _) with I ⊨? φ
-- … | yes I⊨φ = I⊨φ
-- … | no I⊭φ = ⊥-elim $ ¬[I⊭φ×I⊭φ] $ I⊭φ , I⊭φ
-- -- justifieds simplification and ... more?
-- simplificationRule₁ : (I : Interpretation) (φ₁ φ₂ : Formula) → I ⊨ Formula.logical φ₁ φ₂ → I ⊨ Formula.logical φ₁ φ₁
-- simplificationRule₁ I φ₁ φ₂ x = (fst x) , (fst x)
-- simplificationRule₂ : (I : Interpretation) (φ₁ φ₂ : Formula) → I ⊨ Formula.logical φ₁ φ₂ → I ⊨ Formula.logical φ₂ φ₂
-- simplificationRule₂ I φ₁ φ₂ x = snd x , snd x
-- -- logical (logical (logical p p) q) (logical (logical p p) q)
-- {-
-- conditionalizationRule : (I : Interpretation) (p q : Formula) → I ⊨ q → I ⊨ (p ⊃ q ╱ (p ∷ []) )
-- conditionalizationRule I p q ⊨q (_ , _) = let prf = λ { (_ , ⊭q) → ⊭q ⊨q} in prf , prf
-- --let ⊨p = {!-⊨p p (here [])!} in (λ { (x , ~q) → ~q ⊨q}) , (λ { (x , y) → y ⊨q})
-- -}
-- modusPonens : (I : Interpretation) (p q : Formula) → I ⊨ p → I ⊨ (p ⊃ q) → I ⊨ q
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) with I ⊨? q
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | yes x = x
-- modusPonens I p q P (~[~p&~p&~q] , ~[~p&~p&~q]²) | no x = ⊥-elim (~[~p&~p&~q] ((λ { (x₁ , y) → y P}) , (λ x₁ → x x₁)))
-- -- -- -- -- -- data SkolemFormula {ι : Size} (α : Alphabet) : Set where
-- -- -- -- -- -- atomic : Predication α → SkolemFormula α
-- -- -- -- -- -- logical : {ι¹ : Size< ι} → SkolemFormula {ι¹} α → {ι² : Size< ι} → SkolemFormula {ι²} α → SkolemFormula {ι} α
-- -- -- -- -- -- record Alphabet₊ᵥ (α : Alphabet) : Set where
-- -- -- -- -- -- constructor α₊ᵥ⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- .one-variable-is-added : (number ∘ variables $ alphabet) ≡ suc (number ∘ variables $ α)
-- -- -- -- -- -- .there-are-no-functions-of-maximal-arity : number (functions alphabet) zero ≡ zero
-- -- -- -- -- -- .shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → number (functions alphabet) (suc ytira₁) ≡ number (functions α) ytira₀
-- -- -- -- -- -- open Alphabet₊ᵥ
-- -- -- -- -- -- record Alphabet₊ₛ (α : Alphabet) : Set where
-- -- -- -- -- -- constructor α₊ₛ⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- open Alphabet₊ₛ
-- -- -- -- -- -- {-
-- -- -- -- -- -- toSkolemFormula
-- -- -- -- -- -- ∀x(F x v₀ v₁) ⟿ F v₀ v₁ v₂
-- -- -- -- -- -- ∃x(F x v₀ v₁) ⟿ F (s₀͍₂ v₀ v₁) v₀ v₁
-- -- -- -- -- -- ∀x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F v₀ (s₀͍₂ v₁ v₂) v₂
-- -- -- -- -- -- ∃x(F x (s₀͍₂ v₀ v₁) v₁) ⟿ F (s₀͍₂ v₀ v₁) (s₁͍₂ v₁ v₂) v₂
-- -- -- -- -- -- F v₀ ⊗ G v₀ ⟿ F v₀ ⊗ G v₀
-- -- -- -- -- -- ∀x(F x v₀ v₁) ⊗ ∀x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₂ v₃ ⊗ G v₁ (s₀͍₂ v₀ v₃) v₃
-- -- -- -- -- -- ∀x(F x v₀ v₁) ⊗ ∃x(G x (s₀͍₂ x v₁) v₁) ⟿ F v₀ v₁ v₂ ⊗ G (s₀͍₁ v₂) (s₁͍₂ (s₀͍₂ v₂) v₂) v₂
-- -- -- -- -- -- Φ₀ = ∃x(G x (s₀͍₂ x v₁) v₁) has alphabet of 2 variables, skolem functions: 0, 0, 1
-- -- -- -- -- -- this is existential {α₊ₛ} Φ₁, where
-- -- -- -- -- -- Φ₁ = G (s₀͍₂ v₀ v₁) (s₁͍₂ (s₀͍₂ v₀ v₁)) v₁
-- -- -- -- -- -- α₊ₛ = ⟨ 2 , 0 ∷ 0 ∷ 2 ∷ [] ⟩
-- -- -- -- -- -- maybe Φ₋₁ = ∀y∃x(G x (s₀͍₂ x v₀) v₀)
-- -- -- -- -- -- and Φ₋₂ = ∀z∀y∃x(G x (s₀͍₂ x z) z), finally having no free variables, but nevertheless having skolem functions! these are user-defined functions, so this notion of Alphabet is somehow wrong. we have also left out constants (i.e. user-defined skolem-functions of arity 0)
-- -- -- -- -- -- Instead, take the alphabet as defining
-- -- -- -- -- -- a stack of free variables
-- -- -- -- -- -- a matrix (triangle?) of skolem functions
-- -- -- -- -- -- Let's try to reverse Φ₁ from a Skolem to a 1st-order formula. Is there a unique way to do it?
-- -- -- -- -- -- Φ₀' = ∀x(G (s₀͍₂ x v₀) (s₁͍₂ (s₀͍₂ x v₀)) v₀
-- -- -- -- -- -- Nope!
-- -- -- -- -- -- toSkolemFormula of
-- -- -- -- -- -- -}
-- -- -- -- -- -- -- toSkolemFormula (logical Φ₁ Φ₂) ⟿
-- -- -- -- -- -- -- let α' , φ₁ = toSkolemFormula Φ₁
-- -- -- -- -- -- -- Φ₂' = transcodeToAugmentedAlphabet Φ₂ α'
-- -- -- -- -- -- -- α'' , φ₂' = toSkolemFormula Φ₂'
-- -- -- -- -- -- -- φ₁' = transcodeToAugmentedAlphabet φ₁ α''
-- -- -- -- -- -- {-
-- -- -- -- -- -- given Δv = #varibles α' - #variables α
-- -- -- -- -- -- for every variable v in α, v in Φ, v stays the same in Φ'
-- -- -- -- -- -- for the added variable v⁺ in α₊ - α, v⁺ in Φ, v⁺ ⟿ v⁺ + Δv in transcode (universal {α₊} Φ)
-- -- -- -- -- -- α'₊ = α' + 1 variable
-- -- -- -- -- -- -}
-- -- -- -- -- -- -- record AddVariable (A : Alphabet → Set) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- addVariableToAlphabet : {α : Alphabet} → A α → {α₊ : Alphabet} → Alphabet₊ᵥ α₊ → A α₊
-- -- -- -- -- -- -- instance
-- -- -- -- -- -- -- AddVariableFirstOrderFormula : AddVariable FirstOrderFormula
-- -- -- -- -- -- -- AddVariableFirstOrderFormula = {!!}
-- -- -- -- -- -- -- #variables = number ∘ variables
-- -- -- -- -- -- -- #functions_ofArity_ : Alphabet → Nat → Nat
-- -- -- -- -- -- -- #functions α⟨ V⟨ #variables ⟩ , S⟨ #functions ⟩ ⟩ ofArity arity = if′ lessNat arity (suc #variables) then #functions (natToFin arity) else 0
-- -- -- -- -- -- -- record _⊇_ (α' α : Alphabet) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- at-least-as-many-variables : #variables α' ≥ #variables α
-- -- -- -- -- -- -- at-least-as-many-functions : ∀ {arity} → arity < #variables α → #functions α' ofArity arity ≥ #functions α ofArity arity
-- -- -- -- -- -- -- record AddAlphabet (α-top α-bottom : Alphabet) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- record Transcodeable (A : Alphabet → Set) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- transcode : {α' α : Alphabet} → ⦃ _ : α' ⊇ α ⦄ → A α → A α'
-- -- -- -- -- -- -- open Transcodeable ⦃ … ⦄
-- -- -- -- -- -- -- record TransferAlphabet {α' α : Alphabet} (α'⊇α : α' ⊇ α) (α₊ : Alphabet₊ᵥ α) (Φ : FirstOrderFormula (alphabet α₊)) : Set where
-- -- -- -- -- -- -- field
-- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- firstOrderFormula : FirstOrderFormula alphabet
-- -- -- -- -- -- -- instance
-- -- -- -- -- -- -- TranscodeablePredication : Transcodeable Predication
-- -- -- -- -- -- -- TranscodeablePredication = {!!}
-- -- -- -- -- -- -- TranscodeableAlphabet+Variable : Transcodeable Alphabet₊ᵥ
-- -- -- -- -- -- -- TranscodeableAlphabet+Variable = {!!}
-- -- -- -- -- -- -- TranscodeableSkolemFormula : Transcodeable SkolemFormula
-- -- -- -- -- -- -- TranscodeableSkolemFormula = {!!}
-- -- -- -- -- -- -- TranscodeableFirstOrderFormula : Transcodeable FirstOrderFormula
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (atomic p) = atomic (transcode p)
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (logical Φ₁ Φ₂) = logical (transcode Φ₁) (transcode Φ₂)
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula {α'} {α} ⦃ α'⊇α ⦄ (universal {α₊} Φ) = {!!} -- universal {_} {_} {transcode α₊} (transcode Φ)
-- -- -- -- -- -- -- Transcodeable.transcode TranscodeableFirstOrderFormula (existential Φ) = {!!}
-- -- -- -- -- -- -- --(α' α : Alphabet) (α'⊇α : α' ⊇ α) (α₊ : Alphabet+Variable α) (Φ : FirstOrderFormula (alphabet α₊)) → Σ _ λ (α''' : Alphabet) → FirstOrderFormula α'''
-- -- -- -- -- -- -- --FirstOrderFormula (alphabet α₊)
-- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- --transcodeIntoAugmentedAlphabet :
-- -- -- -- -- -- -- -- --toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- --record IsEquivalentFormulas {α₀ : Alphabet} (φ₀ : SkolemFormula α₀) {α₁ : Alphabet} (Φ₁ : FirstOrderFormula α₁) : Set where
-- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- .atomicCase : {p : Predication α₀} → φ₀ ≡ atomic p → Φ₁ ≡ atomic p
-- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- record Alphabet+Alphabet (α₀ α₁ α₂ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- alphabet :
-- -- -- -- -- -- -- -- -- -- ∀xφ₁(x) ⊗ φ₂ ⟿ ∀x(φ₁ ⊗ φ₂)
-- -- -- -- -- -- -- -- -- -- hasQuantifiers : FirstOrderFormula α → Bool
-- -- -- -- -- -- -- -- -- --record Skolemization {α : Alphabet} (φ : FirstOrderFormula α) : Set where
-- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- -- -- -- skolemization : SkolemFormula alphabet
-- -- -- -- -- -- -- -- -- record _IsAugmentationOf_ (α₁ α₀ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- record AugmentedAlphabet (α : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- constructor ⟨_⟩
-- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- alphabet : Alphabet
-- -- -- -- -- -- -- -- -- ..laws : alphabet ≡ α
-- -- -- -- -- -- -- -- -- open AugmentedAlphabet
-- -- -- -- -- -- -- -- -- trivialAugmentation : (α : Alphabet) → AugmentedAlphabet α
-- -- -- -- -- -- -- -- -- trivialAugmentation = {!!}
-- -- -- -- -- -- -- -- -- record DisjointRelativeUnion {α : Alphabet} (α¹ α² : AugmentedAlphabet α) : Set where
-- -- -- -- -- -- -- -- -- constructor ⟨_⟩
-- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- augmentation : AugmentedAlphabet α
-- -- -- -- -- -- -- -- -- .laws : {!!}
-- -- -- -- -- -- -- -- -- open DisjointRelativeUnion
-- -- -- -- -- -- -- -- -- disjointRelativeUnion : {α : Alphabet} → (α¹ α² : AugmentedAlphabet α) → DisjointRelativeUnion α¹ α²
-- -- -- -- -- -- -- -- -- disjointRelativeUnion = {!!}
-- -- -- -- -- -- -- -- -- -- inAugmentedAlphabet : {α : Alphabet} → (α¹ : AugmentedAlphabet α) → SkolemFormula α → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- -- -- inAugmentedAlphabet = {!!}
-- -- -- -- -- -- -- -- -- -- toSkolemFormula : {α : Alphabet} → FirstOrderFormula α → Σ _ λ (α¹ : AugmentedAlphabet α) → SkolemFormula (alphabet α¹)
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (atomic 𝑃) = trivialAugmentation α₀ , atomic 𝑃
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) with toSkolemFormula φ₁ | toSkolemFormula φ₂
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (logical φ₁ φ₂) | α¹ , Φ₁ | α² , Φ₂ = augmentation (disjointRelativeUnion α¹ α²) , logical {!inAugmentedAlphabet (augmentation (disjointRelativeUnion α¹ α²)) Φ₁!} {!Φ₂!}
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (universal x) = {!!}
-- -- -- -- -- -- -- -- -- -- toSkolemFormula {α₀} (existential x) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- … | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- --VariableName = Fin ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- --FunctionArity = Fin ∘ suc ∘ size
-- -- -- -- -- -- -- -- -- -- -- -- -- --FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- |v| : Nat -- number of variables
-- -- -- -- -- -- -- -- -- -- -- -- -- -- |f| : Fin (suc |v|) → Nat -- number of functions of each arity, |v| through 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- open Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- VariableName = Fin ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionArity = Fin ∘ suc ∘ |v|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName = λ alphabet ytira → Fin (|f| alphabet ytira)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- variable : VariableName alphabet → Term alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {arity : FunctionArity alphabet} →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- FunctionName alphabet (natToFin (|v| alphabet) - arity) →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀ {j : Size< i} → Vec (Term {j} alphabet) (finToNat arity) →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateArity = Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- PredicateName = Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a zeroth-order formula? (i.e. no quantifiers)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data NQFormula {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → NQFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → NQFormula {j} alphabet → {k : Size< i} → NQFormula {k} alphabet → NQFormula {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedByVariable (alphabet₀ alphabet₁ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- one-variable-is-added : |v| alphabet₁ ≡ suc (|v| alphabet₀)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function-domain-is-zero-at-new-variable : |f| alphabet₁ zero ≡ 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- shifted-function-matches : ∀ {ytira₀ ytira₁} → finToNat ytira₁ ≡ finToNat ytira₀ → |f| alphabet₁ (suc ytira₁) ≡ |f| alphabet₀ ytira₀
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentVariables (alphabet₀ : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet₁ : Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentation : AugmentedByVariable alphabet₀ alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- open AugmentVariables
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : (alphabet : Alphabet) → AugmentVariables alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables ⟨ |v| , |f| ⟩ =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- { alphabet₁ = ⟨ suc |v| , (λ { zero → zero ; (suc ytira) → |f| ytira}) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; augmentation =
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- { one-variable-is-added = refl
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; function-domain-is-zero-at-new-variable = refl
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ; shifted-function-matches = cong |f| ∘ finToNat-inj } }
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |f|₀ = |f|₀ + 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions ⟨ |v| , |f| ⟩ = ⟨ |v| , (λ { zero → suc (|f| zero) ; (suc ytira) → |f| (suc ytira) }) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data QFormula {i : Size} (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- atomic : PredicateName → ∀ {arity} → Vec (Term alphabet) arity → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- logical : {j : Size< i} → QFormula {j} alphabet → {k : Size< i} → QFormula {k} alphabet → QFormula {i} alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- universal : QFormula (alphabet₁ (augmentVariables alphabet)) → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- existential : QFormula (augmentFunctions alphabet) → QFormula alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Assignment (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- μ : VariableName alphabet → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑓 : ∀ {arity} → FunctionName alphabet arity → Vec Domain (finToNat arity) → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm : ∀ {i alphabet} → Assignment alphabet → Term {i} alphabet → Domain
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm ⟨ μ , _ ⟩ (variable x) = μ x
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateTerm 𝑎@(⟨ μ , 𝑓 ⟩) (function f x) = 𝑓 f (evaluateTerm 𝑎 <$> x)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Interpretation (alphabet : Alphabet) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constructor ⟨_,_⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- open Assignment
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑎 : Assignment alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 𝑃 : PredicateName → ∀ {arity} → Vec Domain arity → Bool
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula : ∀ {i alphabet} → Interpretation alphabet → NQFormula {i} alphabet → Bool
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula ⟨ 𝑎 , 𝑃 ⟩ (atomic name terms) = 𝑃 name $ evaluateTerm 𝑎 <$> terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- evaluateNQFormula I (logical formula₁ formula₂) = not (evaluateNQFormula I formula₁) && not (evaluateNQFormula I formula₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula : ∀ {alphabet₀} → QFormula alphabet₀ → Σ _ λ alphabet₁ → NQFormula alphabet₁
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (atomic name terms) = alphabet₀ , atomic name terms
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (logical formula₁ formula₂) with toNQFormula formula₁ | toNQFormula formula₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- … | alphabet₁ , nqFormula₁ | alphabet₂ , nqFormula₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (universal formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- toNQFormula {alphabet₀} (existential formula) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record IsADisjointUnionOfNQFormulas
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {alphabet₁ alphabet₂ alphabet₁₊₂ : Alphabet}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁ : NQFormula alphabet₁)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₂ : NQFormula alphabet₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (formula₁₊₂ : NQFormula alphabet₁₊₂)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- alphabet-size : |v| alphabet₁₊₂ ≡ |v| alphabet₁ + |v| alphabet₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --|f| alphabet₁₊₂ ytira
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----record AlphabetSummed (alphabet₀ alphabet₁ : Alphabet)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets : Alphabet → Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --addAlphabets ⟨ |v|₁ , |f|₁ ⟩ ⟨ |v|₂ , |f|₂ ⟩ = ⟨ (|v|₁ + |v|₂) , (λ x → if′ finToNat x ≤? |v|₁ && finToNat x ≤? |v|₂ then {!!} else {!!}) ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup : ∀ {alphabet₁} → Formula alphabet₁ → ∀ {alphabet₂} → Formula alphabet₂ → Σ _ λ alphabet₁₊₂ → Formula alphabet₁₊₂ × Formula alphabet₁₊₂
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- sup {⟨ |v|₁ , |a|₁ , |f|₁ ⟩} φ₁ {⟨ |v|₂ , |a|₂ , |f|₂ ⟩} φ₂ = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf : ∀ {alphabet} → Formula alphabet → Σ _ λ alphabet+ → Formula₀ alphabet+
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- pnf = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --universal (P 0) = ∀ x → P x
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (∀ x ∃ y (P x y)) ∨ (∀ x ∃ y (P x y))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- P x₀ (s₀͍₁ x₀) ∨ P x₁ (s₁͍₁ x₁)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| : (arity : Arity) → Vec ℕ (suc |a|) → Vec ℕ (++arity (max arity |a|))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- extended|f| = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a variable to the alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables : Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentVariables = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN : ∀ {n} → Fin n → (Fin n → Nat) → Fin n → Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- increaseTabulationAtN = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record AugmentedFunctions {|a| : Arity} (arity : Arity) (|f| : Vec ℕ (++arity |a|)) : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA : ℕ
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- maxA-law : max arity |a| ≡ maxA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ++|f| : Vec ℕ maxA
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- f-law : increaseTabulationAt arity (indexVec |f|)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- {-
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- define
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ⊗ b ≡ False a and False b
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- now, we can define
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ¬a = a ⊗ a ≡ False a and False a
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∨ b = ¬(a ⊗ b) ≡ False (False a and False b) and False (False a and False b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a ∧ b = ¬(¬a ∨ ¬b) = ¬(¬(¬a ⊗ ¬b)) = ¬a ⊗ ¬b = False (False a and False a) and False (False b and False b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a → b = ¬a ∨ b = (a ⊗ a) ∨ b = ¬((a ⊗ a) ⊗ b) = ((a ⊗ a) ⊗ b) ⊗ ((a ⊗ a) ⊗ b)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- conversion to prenex
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∀xF ⊗ G ⟿ ∃x(F ⊗ wk(G))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ∃xF ⊗ G ⟿ ∀x(F ⊗ wk(G))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∀xG ⟿ ∃x(wk(F) ⊗ G)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- F ⊗ ∃xG ⟿ ∀x(wk(F) ⊗ G)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ========================
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- (a ⊗ ∀xB) ⊗ c ⟿ ∃x(wk(a) ⊗ B) ⊗ c ⟿ ∀x((wk(a) ⊗ B) ⊗ wk(c))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF : (arity : Arity) → ∀ {|a| : Arity} → Vec ℕ (++arity |a|) → Vec ℕ (++arity (max arity |a|))
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- with decBool (lessNat |a| arity)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x with compare arity |a|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.(suc (k + arity))} |f| | yes x | less (diff k refl) = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl with lessNat arity arity
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {.arity} |f| | yes x | equal refl | false = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF zero {.zero} |f| | yes true | equal refl | true = {!!} ∷ []
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF (suc arity) {.(suc arity)} |f| | yes true | equal refl | true = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | yes x | greater gt = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x with decBool (lessNat arity |a|)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | yes x = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentF arity {|a|} |f| | no x₁ | no x = {!!}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- = case arity <? |a| of λ { false → {!!} ; true → {!!} }
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- add a function of a given arity to the alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions : Arity → Alphabet → Alphabet
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- augmentFunctions arity ⟨ |v| , |a| , |f| ⟩ = ⟨ |v| , max arity |a| , augmentF arity |f| ⟩
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data DomainSignifier : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- free : Nat → DomainSignifier
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartiallyAppliedFunction : Nat → Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- constant : PartiallyAppliedFunction 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : ∀ {n} → PartiallyAppliedFunction 0 → PartiallyAppliedFunction (suc n)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Term = PartiallyAppliedFunction 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data PartialyAppliedPredicate : Nat → Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- statement : PartialyAppliedPredicate 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- partial : ∀
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Language : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Name = String
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- record Function : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- field
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- name : Name
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- number-of-arguments : Nat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Vec
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Function : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Term : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function : Function →
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- data Sentence : Set where
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- predication : Name →
-- -- -- -- -- -- {-
-- -- -- -- -- -- record Variables : Set where
-- -- -- -- -- -- constructor V⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- number : Nat
-- -- -- -- -- -- open Variables
-- -- -- -- -- -- record Functions (υ : Variables) : Set where
-- -- -- -- -- -- constructor S⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- number : Fin (suc (number υ)) → Nat
-- -- -- -- -- -- open Functions
-- -- -- -- -- -- record Alphabet : Set where
-- -- -- -- -- -- constructor α⟨_,_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- variables : Variables
-- -- -- -- -- -- functions : Functions variables
-- -- -- -- -- -- open Alphabet
-- -- -- -- -- -- record Variable (α : Alphabet) : Set where
-- -- -- -- -- -- constructor v⟨_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- name : Fin (number (variables α))
-- -- -- -- -- -- open Variable
-- -- -- -- -- -- record Function (α : Alphabet) : Set where
-- -- -- -- -- -- constructor s⟨_,_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- arity : Fin ∘ suc ∘ number ∘ variables $ α
-- -- -- -- -- -- name : Fin $ number (functions α) arity
-- -- -- -- -- -- open Function
-- -- -- -- -- -- data Term (𝑽 : Nat) : Set where
-- -- -- -- -- -- variable : Fin 𝑽 → Term 𝑽
-- -- -- -- -- -- function : (𝑓 : Function α) → {ι₋₁ : Size< ι₀} → Vec (Term {ι₋₁} α) (finToNat (arity 𝑓)) →
-- -- -- -- -- -- Term {ι₀} α
-- -- -- -- -- -- record Predication (alphabet : Alphabet) : Set where
-- -- -- -- -- -- constructor P⟨_,_,_⟩
-- -- -- -- -- -- field
-- -- -- -- -- -- name : Nat
-- -- -- -- -- -- arity : Nat
-- -- -- -- -- -- terms : Vec (Term alphabet) arity
-- -- -- -- -- -- open Predication
-- -- -- -- -- -- -}
-- -- module NotUsed where
-- -- -- thought it might be easier to use this
-- -- module UsingContainerList where
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : List (TermCode × TermNode)
-- -- number : Nat
-- -- open TermNode
-- -- _child∈_ : TermCode → TermNode → Set
-- -- _child∈_ 𝔠 𝔫 = Any ((𝔠 ≡_) ∘ fst) (children 𝔫)
-- -- -- this still has a lambda problem, albeit weirder
-- -- module RememberChildren where
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- tests : List TermCode
-- -- children : ∀ {𝔠} → 𝔠 ∈ tests → TermNode
-- -- number : Nat
-- -- open TermNode
-- -- addChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 ∉ tests 𝔫 → TermNode → TermNode
-- -- addChild {𝔠} 𝔫 𝔠∉tests𝔫 𝔫' =
-- -- record 𝔫
-- -- { tests = 𝔠 ∷ tests 𝔫
-- -- ; children = λ
-- -- { (here _) → 𝔫'
-- -- ; (there _ 𝔠'∈tests) → children 𝔫 𝔠'∈tests }}
-- -- setChild : {𝔠 : TermCode} (𝔫 : TermNode) → 𝔠 ∈ tests 𝔫 → TermNode → TermNode
-- -- setChild {𝔠} 𝔫 𝔠∈tests𝔫 𝔫' =
-- -- record 𝔫
-- -- { children = λ {𝔠'} 𝔠'∈tests𝔫' → ifYes 𝔠' ≟ 𝔠 then 𝔫' else children 𝔫 𝔠'∈tests𝔫' }
-- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity Nat
-- -- storeTermCodes [] 𝔑 = return 𝔑
-- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case 𝔠 ∈? tests 𝔫 of λ
-- -- { (no 𝔠∉tests) →
-- -- let 𝔑' , 𝔫' = runIdentity $
-- -- runStateT
-- -- (storeTermCodes 𝔠s $ suc 𝔑)
-- -- (record
-- -- { tests = []
-- -- ; children = λ ()
-- -- ; number = suc 𝔑 }) in
-- -- put (addChild 𝔫 𝔠∉tests 𝔫') ~|
-- -- return 𝔑'
-- -- ; (yes 𝔠∈tests) →
-- -- let 𝔑' , 𝔫' = runIdentity $
-- -- runStateT
-- -- (storeTermCodes 𝔠s $ suc 𝔑)
-- -- (children 𝔫 𝔠∈tests) in
-- -- put (setChild 𝔫 𝔠∈tests 𝔫') ~|
-- -- return 𝔑' }
-- -- topNode : TermNode
-- -- topNode = record { tests = [] ; children = λ () ; number = 0 }
-- -- example-store : TermNode
-- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodes example-TermCodes 0) topNode
-- -- foo : TermNode × TermNode
-- -- foo =
-- -- {!example-store!} ,
-- -- {!snd ∘ runIdentity $ runStateT (storeTermCodes example-TermCodes 10) example-store!}
-- -- -- using a lambda for the children results in extra unnecessary structure when adding to an existing node; perhaps using an explicit mapping? or use another field to state what codes are present in the mapping?
-- -- module NoParents where
-- -- mutual
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : TermCode → Maybe TermNode -- Map TermCode TermNode
-- -- self : TermCode
-- -- number : Nat
-- -- record TopTermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : TermCode → Maybe TermNode
-- -- open TermNode
-- -- open TopTermNode
-- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity ⊤
-- -- storeTermCodes [] _ = return tt
-- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- storeTermCodesAtTop : List TermCode → Nat → StateT TopTermNode Identity ⊤
-- -- storeTermCodesAtTop [] _ = return tt
-- -- storeTermCodesAtTop (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- initialTopNode : TopTermNode
-- -- initialTopNode = record { children = const nothing }
-- -- example-store : TopTermNode
-- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 0) initialTopNode
-- -- foo : TopTermNode × TopTermNode
-- -- foo =
-- -- {!example-store!} ,
-- -- {!snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 10) example-store!}
-- -- -- it's tricky to keep the parents up to date when the children change (viz adolescence)
-- -- module FirstTryWithParent where
-- -- mutual
-- -- record TermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- parent : TopTermNode ⊎ TermNode
-- -- self : TermCode
-- -- children : TermCode → Maybe TermNode -- Map TermCode TermNode
-- -- number : Nat
-- -- record TopTermNode : Set
-- -- where
-- -- inductive
-- -- field
-- -- children : TermCode → Maybe TermNode
-- -- open TermNode
-- -- open TopTermNode
-- -- storeTermCodes : List TermCode → Nat → StateT TermNode Identity ⊤
-- -- storeTermCodes [] _ = return tt
-- -- storeTermCodes (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { parent = right 𝔫
-- -- ; self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- storeTermCodesAtTop : List TermCode → Nat → StateT TopTermNode Identity ⊤
-- -- storeTermCodesAtTop [] _ = return tt
-- -- storeTermCodesAtTop (𝔠 ∷ 𝔠s) 𝔑 =
-- -- 𝔫 ← get -|
-- -- case children 𝔫 𝔠 of λ
-- -- { nothing →
-- -- put
-- -- (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- (runStateT
-- -- (storeTermCodes 𝔠s (suc 𝔑))
-- -- (record
-- -- { parent = left 𝔫
-- -- ; self = 𝔠
-- -- ; children = const nothing
-- -- ; number = suc 𝔑 }))
-- -- else
-- -- children 𝔫 𝔠' } ) ~|
-- -- return tt
-- -- ; (just 𝔫') →
-- -- put (record 𝔫
-- -- { children =
-- -- λ 𝔠' →
-- -- ifYes 𝔠' ≟ 𝔠 then
-- -- just ∘ snd ∘ runIdentity $
-- -- runStateT (storeTermCodes 𝔠s 𝔑) 𝔫'
-- -- else
-- -- children 𝔫 𝔠' }) ~|
-- -- return tt }
-- -- initialTopNode : TopTermNode
-- -- initialTopNode = record { children = const nothing }
-- -- example-store : TopTermNode
-- -- example-store = snd ∘ runIdentity $ runStateT (storeTermCodesAtTop example-TermCodes 0) initialTopNode
-- -- foo : TopTermNode
-- -- foo = {!example-store!}
-- --
-- --
-- -- _⟪_⟫_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
-- -- A → (A → B → C) → B → C
-- -- x ⟪ f ⟫ y = f x y
-- --
-- -- {-
-- -- infixr 9 _∘₂′_
-- -- _∘₂′_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
-- -- (C → D) → (A → B → C) → (A → B → D)
-- -- _∘₂′_ = _∘′_ ∘ _∘′_
-- -- {-# INLINE _∘₂′_ #-}
-- --
-- -- infixr 9 _∘₂′_
-- -- _∘₂′_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} →
-- -- (C → D) → (A → B → C) → (A → B → D)
-- -- _∘₂′_ = _∘′_ ∘ _∘′_
-- -- {-# INLINE _∘₂′_ #-}
-- -- -}
-- -- {-
-- -- infixr 9 _∘₂_
-- -- _∘₂_ : ∀ {a b c d} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c} {D : ∀ x → B x → C x
-- -- (f : ∀ {x} (y : B x) → C x y) (g : ∀ x → B x) →
-- -- ∀ x → C x (g x)
-- -- _∘₂_ = _∘′_ ∘ _∘′_
-- -- {-# INLINE _∘₂′_ #-}
-- -- -}
| {
"alphanum_fraction": 0.5080441961,
"avg_line_length": 45.3652822151,
"ext": "agda",
"hexsha": "5925c2476392ff67cae40b24e95200609d0beadd",
"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": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/NaturalDeduction.monolithic.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/NaturalDeduction.monolithic.agda",
"max_line_length": 405,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/NaturalDeduction.monolithic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 54015,
"size": 127794
} |
open import Nat
open import Prelude
open import contexts
open import core
open import type-assignment-unicity
module canonical-indeterminate-forms where
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at base type
data cif-base : (Δ : hctx) (d : iexp) → Set where
CIFBEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇⦈⟨ u , σ ⟩) ×
((u :: b [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-base Δ d
CIFBNEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: b [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-base Δ d
CIFBAp : ∀ {Δ d} →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ] Σ[ τ2 ∈ typ ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2 ==> b) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : typ) (d1' : iexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-base Δ d
CIFBFst : ∀{Δ d} →
Σ[ d' ∈ iexp ] Σ[ τ2 ∈ typ ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: b ⊗ τ2) ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-base Δ d
CIFBSnd : ∀{Δ d} →
Σ[ d' ∈ iexp ] Σ[ τ1 ∈ typ ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ1 ⊗ b) ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-base Δ d
CIFBCast : ∀ {Δ d} →
Σ[ d' ∈ iexp ]
((d == d' ⟨ ⦇·⦈ ⇒ b ⟩) ×
(Δ , ∅ ⊢ d' :: ⦇·⦈) ×
(d' indet) ×
((d'' : iexp) (τ' : typ) → d' ≠ (d'' ⟨ τ' ⇒ ⦇·⦈ ⟩))
)
→ cif-base Δ d
CIFBFailedCast : ∀ {Δ d} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == d' ⟨ τ' ⇒⦇⦈⇏ b ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ b)
)
→ cif-base Δ d
canonical-indeterminate-forms-base : ∀{Δ d} →
Δ , ∅ ⊢ d :: b →
d indet →
cif-base Δ d
canonical-indeterminate-forms-base TAConst ()
canonical-indeterminate-forms-base (TAVar x₁) ()
canonical-indeterminate-forms-base (TAAp wt wt₁) (IAp x ind x₁) = CIFBAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-base (TAEHole x x₁) IEHole = CIFBEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-base (TANEHole x wt x₁) (INEHole x₂) = CIFBNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-base (TACast wt x) (ICastHoleGround x₁ ind x₂) = CIFBCast (_ , refl , wt , ind , x₁)
canonical-indeterminate-forms-base (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = CIFBFailedCast (_ , _ , refl , x , x₅ , x₇)
canonical-indeterminate-forms-base (TAFst wt) (IFst ind h1 h2) = CIFBFst (_ , _ , refl , wt , ind , h1 , h2)
canonical-indeterminate-forms-base (TASnd wt) (ISnd ind h1 h2) = CIFBSnd (_ , _ , refl , wt , ind , h1 , h2)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at arrow type
data cif-arr : (Δ : hctx) (d : iexp) (τ1 τ2 : typ) → Set where
CIFAEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇⦈⟨ u , σ ⟩) ×
((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-arr Δ d τ1 τ2
CIFANEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-arr Δ d τ1 τ2
CIFAAp : ∀{d Δ τ1 τ2} →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ] Σ[ τ2' ∈ typ ] Σ[ τ1 ∈ typ ] Σ[ τ2 ∈ typ ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ==> τ2)) ×
(Δ , ∅ ⊢ d2 :: τ2') ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : typ) (d1' : iexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFAFst : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: (τ1 ==> τ2) ⊗ τ') ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFASnd : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊗ (τ1 ==> τ2)) ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFACast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ1 ∈ typ ] Σ[ τ2 ∈ typ ] Σ[ τ1' ∈ typ ] Σ[ τ2' ∈ typ ]
((d == d' ⟨ (τ1' ==> τ2') ⇒ (τ1 ==> τ2) ⟩) ×
(Δ , ∅ ⊢ d' :: τ1' ==> τ2') ×
(d' indet) ×
((τ1' ==> τ2') ≠ (τ1 ==> τ2))
)
→ cif-arr Δ d τ1 τ2
CIFACastHole : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ iexp ]
((d == (d' ⟨ ⦇·⦈ ⇒ ⦇·⦈ ==> ⦇·⦈ ⟩)) ×
(τ1 == ⦇·⦈) ×
(τ2 == ⦇·⦈) ×
(Δ , ∅ ⊢ d' :: ⦇·⦈) ×
(d' indet) ×
((d'' : iexp) (τ' : typ) → d' ≠ (d'' ⟨ τ' ⇒ ⦇·⦈ ⟩))
)
→ cif-arr Δ d τ1 τ2
CIFAFailedCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == (d' ⟨ τ' ⇒⦇⦈⇏ ⦇·⦈ ==> ⦇·⦈ ⟩) ) ×
(τ1 == ⦇·⦈) ×
(τ2 == ⦇·⦈) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ (⦇·⦈ ==> ⦇·⦈))
)
→ cif-arr Δ d τ1 τ2
canonical-indeterminate-forms-arr : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d indet →
cif-arr Δ d τ1 τ2
canonical-indeterminate-forms-arr (TAVar x₁) ()
canonical-indeterminate-forms-arr (TALam _ wt) ()
canonical-indeterminate-forms-arr (TAAp wt wt₁) (IAp x ind x₁) = CIFAAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-arr (TAEHole x x₁) IEHole = CIFAEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-arr (TANEHole x wt x₁) (INEHole x₂) = CIFANEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-arr (TACast wt x) (ICastArr x₁ ind) = CIFACast (_ , _ , _ , _ , _ , refl , wt , ind , x₁)
canonical-indeterminate-forms-arr (TACast wt TCHole2) (ICastHoleGround x₁ ind GHole) = CIFACastHole (_ , refl , refl , refl , wt , ind , x₁)
canonical-indeterminate-forms-arr (TAFailedCast x x₁ GHole x₃) (IFailedCast x₄ x₅ GHole x₇) = CIFAFailedCast (_ , _ , refl , refl , refl , x , x₅ , x₇)
canonical-indeterminate-forms-arr (TAFst wt) (IFst ind h1 h2) = CIFAFst (_ , _ , refl , wt , ind , h1 , h2)
canonical-indeterminate-forms-arr (TASnd wt) (ISnd ind h1 h2) = CIFASnd (_ , _ , refl , wt , ind , h1 , h2)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at hole type
data cif-hole : (Δ : hctx) (d : iexp) → Set where
CIFHEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇⦈⟨ u , σ ⟩) ×
((u :: ⦇·⦈ [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-hole Δ d
CIFHNEHole : ∀ {Δ d} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: ⦇·⦈ [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-hole Δ d
CIFHAp : ∀ {Δ d} →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ] Σ[ τ2 ∈ typ ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: (τ2 ==> ⦇·⦈)) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : typ) (d1' : iexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-hole Δ d
CIFHFst : ∀{Δ d} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: ⦇·⦈ ⊗ τ') ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-hole Δ d
CIFHSnd : ∀{Δ d} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊗ ⦇·⦈) ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-hole Δ d
CIFHCast : ∀ {Δ d} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == d' ⟨ τ' ⇒ ⦇·⦈ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(d' indet)
)
→ cif-hole Δ d
canonical-indeterminate-forms-hole : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇·⦈ →
d indet →
cif-hole Δ d
canonical-indeterminate-forms-hole (TAVar x₁) ()
canonical-indeterminate-forms-hole (TAAp wt wt₁) (IAp x ind x₁) = CIFHAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-hole (TAEHole x x₁) IEHole = CIFHEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-hole (TANEHole x wt x₁) (INEHole x₂) = CIFHNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-hole (TACast wt x) (ICastGroundHole x₁ ind) = CIFHCast (_ , _ , refl , wt , x₁ , ind)
canonical-indeterminate-forms-hole (TACast wt x) (ICastHoleGround x₁ ind ())
canonical-indeterminate-forms-hole (TAFailedCast x x₁ () x₃) (IFailedCast x₄ x₅ x₆ x₇)
canonical-indeterminate-forms-hole (TAFst wt) (IFst ind h1 h2) = CIFHFst (_ , _ , refl , wt , ind , h1 , h2)
canonical-indeterminate-forms-hole (TASnd wt) (ISnd ind h1 h2) = CIFHSnd (_ , _ , refl , wt , ind , h1 , h2)
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for indeterminates at product type
data cif-prod : (Δ : hctx) (d : iexp) (τ1 τ2 : typ) → Set where
CIFPEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ]
((d == ⦇⦈⟨ u , σ ⟩) ×
((u :: (τ1 ⊗ τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-prod Δ d τ1 τ2
CIFPNEHole : ∀{d Δ τ1 τ2} →
Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ] Σ[ Γ ∈ tctx ]
((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) ×
(Δ , ∅ ⊢ d' :: τ') ×
(d' final) ×
((u :: (τ1 ⊗ τ2) [ Γ ]) ∈ Δ) ×
(Δ , ∅ ⊢ σ :s: Γ)
)
→ cif-prod Δ d τ1 τ2
CIFPAp : ∀{d Δ τ1 τ2} →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ] Σ[ τ2' ∈ typ ] Σ[ τ1 ∈ typ ] Σ[ τ2 ∈ typ ]
((d == d1 ∘ d2) ×
(Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ⊗ τ2)) ×
(Δ , ∅ ⊢ d2 :: τ2') ×
(d1 indet) ×
(d2 final) ×
((τ3 τ4 τ3' τ4' : typ) (d1' : iexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPFst : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == fst d') ×
(Δ , ∅ ⊢ d' :: (τ1 ⊗ τ2) ⊗ τ') ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPSnd : ∀{Δ d τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == snd d') ×
(Δ , ∅ ⊢ d' :: τ' ⊗ (τ1 ⊗ τ2)) ×
(d' indet) ×
(∀{d1 d2} → d' ≠ ⟨ d1 , d2 ⟩) ×
(∀{d'' τ1 τ2 τ3 τ4} → d' ≠ (d'' ⟨ τ1 ⊗ τ2 ⇒ τ3 ⊗ τ4 ⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPPair1 : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ]
((d == ⟨ d1 , d2 ⟩) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
d1 indet ×
d2 final
)
→ cif-prod Δ d τ1 τ2
CIFPPair2 : ∀{Δ d τ1 τ2} →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ]
((d == ⟨ d1 , d2 ⟩) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2) ×
d1 final ×
d2 indet
)
→ cif-prod Δ d τ1 τ2
CIFPCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ1 ∈ typ ] Σ[ τ2 ∈ typ ] Σ[ τ1' ∈ typ ] Σ[ τ2' ∈ typ ]
((d == d' ⟨ (τ1' ⊗ τ2') ⇒ (τ1 ⊗ τ2) ⟩) ×
(Δ , ∅ ⊢ d' :: τ1' ⊗ τ2') ×
(d' indet) ×
((τ1' ⊗ τ2') ≠ (τ1 ⊗ τ2)) ×
((τ1' ⊗ τ2') ~ (τ1 ⊗ τ2))
)
→ cif-prod Δ d τ1 τ2
CIFPCastHole : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ iexp ]
((d == (d' ⟨ ⦇·⦈ ⇒ ⦇·⦈ ⊗ ⦇·⦈ ⟩)) ×
(τ1 == ⦇·⦈) ×
(τ2 == ⦇·⦈) ×
(Δ , ∅ ⊢ d' :: ⦇·⦈) ×
(d' indet) ×
((d'' : iexp) (τ' : typ) → d' ≠ (d'' ⟨ τ' ⇒ ⦇·⦈ ⟩))
)
→ cif-prod Δ d τ1 τ2
CIFPFailedCast : ∀{d Δ τ1 τ2} →
Σ[ d' ∈ iexp ] Σ[ τ' ∈ typ ]
((d == (d' ⟨ τ' ⇒⦇⦈⇏ ⦇·⦈ ⊗ ⦇·⦈ ⟩) ) ×
(τ1 == ⦇·⦈) ×
(τ2 == ⦇·⦈) ×
(Δ , ∅ ⊢ d' :: τ') ×
(τ' ground) ×
(τ' ≠ (⦇·⦈ ⊗ ⦇·⦈) ×
d' final))
→ cif-prod Δ d τ1 τ2
canonical-indeterminate-forms-prod : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ⊗ τ2) →
d indet →
cif-prod Δ d τ1 τ2
canonical-indeterminate-forms-prod (TAVar x₁) ()
canonical-indeterminate-forms-prod (TAAp wt wt₁) (IAp x ind x₁) = CIFPAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x)
canonical-indeterminate-forms-prod (TAEHole x x₁) IEHole = CIFPEHole (_ , _ , _ , refl , x , x₁)
canonical-indeterminate-forms-prod (TANEHole x wt x₁) (INEHole x₂) = CIFPNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁)
canonical-indeterminate-forms-prod (TACast wt x) (ICastProd x₁ ind) = CIFPCast (_ , _ , _ , _ , _ , refl , wt , ind , x₁ , x)
canonical-indeterminate-forms-prod (TACast wt TCHole2) (ICastHoleGround x₁ ind GProd) = CIFPCastHole (_ , refl , refl , refl , wt , ind , x₁)
canonical-indeterminate-forms-prod (TAFailedCast wt x GProd x₂) (IFailedCast x₃ x₄ GProd x₆) = CIFPFailedCast (_ , _ , refl , refl , refl , wt , x₄ , x₆ , x₃)
canonical-indeterminate-forms-prod (TAFst wt) (IFst ind h1 h2) = CIFPFst (_ , _ , refl , wt , ind , h1 , h2)
canonical-indeterminate-forms-prod (TASnd wt) (ISnd ind h1 h2) = CIFPSnd (_ , _ , refl , wt , ind , h1 , h2)
canonical-indeterminate-forms-prod (TAPair wt wt₁) (IPair1 ind x) = CIFPPair1 (_ , _ , refl , wt , wt₁ , ind , x)
canonical-indeterminate-forms-prod (TAPair wt wt₁) (IPair2 x ind) = CIFPPair2 (_ , _ , refl , wt , wt₁ , x , ind)
canonical-indeterminate-forms-coverage : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d indet →
τ ≠ b →
((τ1 : typ) (τ2 : typ) → τ ≠ (τ1 ==> τ2)) →
τ ≠ ⦇·⦈ →
((τ1 : typ) (τ2 : typ) → τ ≠ (τ1 ⊗ τ2)) →
⊥
canonical-indeterminate-forms-coverage TAConst () nb na nh
canonical-indeterminate-forms-coverage (TAVar x₁) () nb na nh
canonical-indeterminate-forms-coverage (TALam _ wt) () nb na nh
canonical-indeterminate-forms-coverage {τ = b} (TAAp wt wt₁) (IAp x ind x₁) nb na nh _ = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TAAp wt wt₁) (IAp x ind x₁) nb na nh _ = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAAp wt wt₁) (IAp x ind x₁) nb na nh _ = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TAEHole x x₁) IEHole nb na nh _ = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TAEHole x x₁) IEHole nb na nh _ = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAEHole x x₁) IEHole nb na nh _ = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TANEHole x wt x₁) (INEHole x₂) nb na nh _ = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TANEHole x wt x₁) (INEHole x₂) nb na nh _ = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TANEHole x wt x₁) (INEHole x₂) nb na nh _ = na τ τ₁ refl
canonical-indeterminate-forms-coverage (TACast wt x) (ICastArr x₁ ind) nb na nh _ = na _ _ refl
canonical-indeterminate-forms-coverage (TACast wt x) (ICastGroundHole x₁ ind) nb na nh _ = nh refl
canonical-indeterminate-forms-coverage {τ = b} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh _ = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh _ = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh _ = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) z _ _ _ = z refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) _ _ z _ = z refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) _ z _ _ = z τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = b} (TAFst wt) (IFst ind x _) nb na nh np = nb refl
canonical-indeterminate-forms-coverage {τ = b} (TASnd wt) (ISnd ind x _) nb na nh np = nb refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TAFst wt) (IFst ind x _) nb na nh np = nh refl
canonical-indeterminate-forms-coverage {τ = ⦇·⦈} (TASnd wt) (ISnd ind x _) nb na nh np = nh refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAFst wt) (IFst ind x _) nb na nh np = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TASnd wt) (ISnd ind x _) nb na nh np = na τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TAAp wt wt₁) (IAp x ind x₁) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TAEHole x x₁) IEHole nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TANEHole x wt x₁) (INEHole x₂) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TACast wt x) (ICastProd x₁ ind) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TAFailedCast wt x x₁ x₂) (IFailedCast x₃ x₄ x₅ x₆) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TAFst wt) (IFst ind x _) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TASnd wt) (ISnd ind x _) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TAPair wt wt₁) (IPair1 ind x) nb na nh np = np τ τ₁ refl
canonical-indeterminate-forms-coverage {τ = τ ⊗ τ₁} (TAPair wt wt₁) (IPair2 x ind) nb na nh np = np τ τ₁ refl
| {
"alphanum_fraction": 0.4570943976,
"avg_line_length": 46.8163771712,
"ext": "agda",
"hexsha": "cc09199c4d757b949f6c8ef54c11800e9e5c8368",
"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": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "canonical-indeterminate-forms.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "canonical-indeterminate-forms.agda",
"max_line_length": 160,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "canonical-indeterminate-forms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 8083,
"size": 18867
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.ZCohomology.Properties where
open import Cubical.ZCohomology.Base
open import Cubical.HITs.Sn
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.NatMinusTwo.Base
open import Cubical.Data.Empty
open import Cubical.Data.Sigma
open import Cubical.Data.Prod.Base
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation
open import Cubical.HITs.Nullification
open import Cubical.Data.Int
open import Cubical.Data.Nat
open import Cubical.HITs.Truncation
open import Cubical.HITs.Pushout
open import Cubical.Data.Sum.Base
open import Cubical.Data.HomotopyGroup
open import Cubical.Data.Bool
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
{- Equivalence between cohomology of A and reduced cohomology of (A + 1) -}
coHomRed+1Equiv : (n : ℕ) →
(A : Set ℓ) →
(coHom n A) ≡ (coHomRed n ((A ⊎ Unit , inr (tt))))
coHomRed+1Equiv zero A i = ∥ helpLemma {C = (Int , pos 0)} i ∥₀
module coHomRed+1 where
helpLemma : {C : Pointed ℓ} → ( (A → (typ C)) ≡ ((((A ⊎ Unit) , inr (tt)) →* C)))
helpLemma {C = C} = isoToPath (iso map1
map2
(λ b → linvPf b)
(λ _ → refl))
where
map1 : (A → typ C) → ((((A ⊎ Unit) , inr (tt)) →* C))
map1 f = map1' , refl module helpmap where
map1' : A ⊎ Unit → fst C
map1' (inl x) = f x
map1' (inr x) = pt C
map2 : ((((A ⊎ Unit) , inr (tt)) →* C)) → (A → typ C)
map2 (g , pf) x = g (inl x)
linvPf : (b :((((A ⊎ Unit) , inr (tt)) →* C))) → map1 (map2 b) ≡ b
linvPf (f , snd) i = (λ x → helper x i) , λ j → snd ((~ i) ∨ j)
where
helper : (x : A ⊎ Unit) → ((helpmap.map1') (map2 (f , snd)) x) ≡ f x
helper (inl x) = refl
helper (inr tt) = sym snd
coHomRed+1Equiv (suc n) A i = ∥ coHomRed+1.helpLemma A i {C = ((coHomK (suc n)) , ∣ north ∣)} i ∥₀
| {
"alphanum_fraction": 0.6078167116,
"avg_line_length": 35.3333333333,
"ext": "agda",
"hexsha": "bee12fee4474014786898516931ac5fd2740ee29",
"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": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"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": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/Properties.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 769,
"size": 2226
} |
------------------------------------------------------------------------
-- Examples
------------------------------------------------------------------------
module StructurallyRecursiveDescentParsing.Examples where
open import Data.List
open import Data.Vec using ([]; _∷_)
open import Data.Nat
open import Data.Bool
open import Data.Char using (Char)
import Data.Char.Properties as C
import Data.String as S
open S using (String)
open import Codata.Musical.Notation
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import StructurallyRecursiveDescentParsing.Index
open import StructurallyRecursiveDescentParsing.Grammar
open import StructurallyRecursiveDescentParsing.DepthFirst
open import StructurallyRecursiveDescentParsing.Lib
open Token C.decSetoid
-- Some functions used to simplify the examples a little.
infix 5 _∈?_/_ _∈?_
_∈?_/_ : ∀ {NT i R} →
String → Parser NT Char i R → Grammar NT Char → List R
s ∈? p / g = parseComplete (⟦ p ⟧ g) (S.toList s)
_∈?_ : ∀ {i R} → String → Parser EmptyNT Char i R → List R
s ∈? p = s ∈? p / emptyGrammar
module Ex₁ where
mutual
-- e ∷= 0 + e | 0
data Nonterminal : NonTerminalType where
e : Nonterminal i Char
private
i = _
grammar : Grammar Nonterminal Char
grammar e = tok '0' ⊛> tok '+' ⊛> ! e
∣ tok '0'
ex₁ : "0+0" ∈? ! e / grammar ≡ [ '0' ]
ex₁ = P.refl
module Ex₂ where
mutual
-- e ∷= f + e | f
-- f ∷= 0 | 0 * f | ( e )
data Nonterminal : NonTerminalType where
expr : Nonterminal i₁ Char
factor : Nonterminal i₂ Char
private
i₁ = _
i₂ = _
grammar : Grammar Nonterminal Char
grammar expr = ! factor ⊛> tok '+' ⊛> ! expr
∣ ! factor
grammar factor = tok '0'
∣ tok '0' ⊛> tok '*' ⊛> ! factor
∣ tok '(' ⊛> ! expr <⊛ tok ')'
ex₁ : "(0*)" ∈? ! expr / grammar ≡ []
ex₁ = P.refl
ex₂ : "0*(0+0)" ∈? ! expr / grammar ≡ [ '0' ]
ex₂ = P.refl
{-
module Ex₃ where
mutual
-- This is not allowed:
-- e ∷= f + e | f
-- f ∷= 0 | f * 0 | ( e )
data Nonterminal : NonTerminalType where
expr : Nonterminal i₁ Char
factor : Nonterminal i₂ Char
private
i₁ = _
i₂ = _
grammar : Grammar Nonterminal Char
grammar expr = ! factor ⊛> tok '+' ⊛> ! expr
∣ ! factor
grammar factor = tok '0'
∣ ! factor ⊛> tok '*' ⊛> tok '0'
∣ tok '(' ⊛> ! expr <⊛ tok ')'
-}
module Ex₄ where
mutual
-- The language aⁿbⁿcⁿ, which is not context free.
-- The non-terminal top returns the number of 'a' characters
-- parsed.
data NT : NonTerminalType where
top : NT i₁ ℕ -- top ∷= aⁿbⁿcⁿ
as : ℕ → NT i₂ ℕ -- as n ∷= aˡ⁺¹bⁿ⁺ˡ⁺¹cⁿ⁺ˡ⁺¹
bcs : Char → ℕ → NT i₃ ℕ -- bcs x n ∷= xⁿ⁺¹
private
i₁ = _
i₂ = _
i₃ = _
grammar : Grammar NT Char
grammar top = return 0 ∣ ! (as zero)
grammar (as n) = suc <$ tok 'a' ⊛
( ! (as (suc n))
∣ _+_ <$> ! (bcs 'b' n) ⊛ ! (bcs 'c' n)
)
grammar (bcs c zero) = tok c ⊛> return 0
grammar (bcs c (suc n)) = tok c ⊛> ! (bcs c n)
ex₁ : "aaabbbccc" ∈? ! top / grammar ≡ [ 3 ]
ex₁ = P.refl
ex₂ : "aaabbccc" ∈? ! top / grammar ≡ []
ex₂ = P.refl
module Ex₄′ where
mutual
-- A monadic variant of Ex₄.
aⁿbⁿcⁿ = return 0
∣ tok 'a' + !>>= λ as → ♯
(let n = length as in
exactly n (tok 'b') ⊛>
exactly n (tok 'c') ⊛>
return n)
ex₁ : "aaabbbccc" ∈? aⁿbⁿcⁿ ≡ [ 3 ]
ex₁ = P.refl
ex₂ : "aaabbccc" ∈? aⁿbⁿcⁿ ≡ []
ex₂ = P.refl
module Ex₅ where
mutual
-- A grammar making use of a parameterised parser from the
-- library.
data NT : NonTerminalType where
a : NT i₁ Char
as : NT i₂ ℕ
private
i₁ = _
i₂ = _
grammar : Grammar NT Char
grammar a = tok 'a'
grammar as = length <$> ! a ⋆
ex₁ : "aaaaa" ∈? ! as / grammar ≡ [ 5 ]
ex₁ = P.refl
module Ex₆ where
mutual
-- A grammar which uses the chain≥ combinator.
data NT : NonTerminalType where
op : NT i₁ (ℕ → ℕ → ℕ)
expr : (a : Assoc) → NT i₂ ℕ
private
i₁ = _
i₂ = _
grammar : Grammar NT Char
grammar op = _+_ <$ tok '+'
∣ _*_ <$ tok '*'
∣ _∸_ <$ tok '∸'
grammar (expr a) = chain≥ 0 a number (! op)
ex₁ : "12345" ∈? number / grammar ≡ [ 12345 ]
ex₁ = P.refl
ex₂ : "1+5*2∸3" ∈? ! (expr left) / grammar ≡ [ 9 ]
ex₂ = P.refl
ex₃ : "1+5*2∸3" ∈? ! (expr right) / grammar ≡ [ 1 ]
ex₃ = P.refl
module Ex₇ where
mutual
-- A proper expression example.
data NT : NonTerminalType where
expr : NT i₁ ℕ
term : NT i₂ ℕ
factor : NT i₃ ℕ
addOp : NT i₄ (ℕ → ℕ → ℕ)
mulOp : NT i₅ (ℕ → ℕ → ℕ)
private
i₁ = _
i₂ = _
i₃ = _
i₄ = _
i₅ = _
grammar : Grammar NT Char
grammar expr = chain≥ 0 left (! term) (! addOp)
grammar term = chain≥ 0 left (! factor) (! mulOp)
grammar factor = tok '(' ⊛> ! expr <⊛ tok ')'
∣ number
grammar addOp = _+_ <$ tok '+'
∣ _∸_ <$ tok '∸'
grammar mulOp = _*_ <$ tok '*'
ex₁ : "1+5*2∸3" ∈? ! expr / grammar ≡ [ 8 ]
ex₁ = P.refl
ex₂ : "1+5*(2∸3)" ∈? ! expr / grammar ≡ [ 1 ]
ex₂ = P.refl
module Ex₈ where
mutual
-- An example illustrating the use of one grammar within another.
data NT : NonTerminalType where
lib : ∀ {i R} (nt : Ex₇.NT i R) → NT i R
exprs : NT i (List ℕ)
private
i = _
expr = lib Ex₇.expr
grammar : Grammar NT Char
grammar (lib nt) = mapNT lib (Ex₇.grammar nt)
grammar exprs = ! expr sepBy tok ','
ex₁ : "1,2∸1" ∈? ! exprs / grammar ≡ [ 1 ∷ 1 ∷ [] ]
ex₁ = P.refl
module Ex₉ where
mutual
-- An example illustrating the use of one grammar within another
-- when the inner grammar contains non-terminals parameterised on
-- parsers, and the outer grammar instantiates one of these
-- parsers with an outer non-terminal.
infix 55 _★ _∔
data LibraryNT (NT : NonTerminalType) (Tok : Set) :
NonTerminalType where
_★ : ∀ {c R} → Parser NT Tok (false ◇ c) R →
LibraryNT NT Tok (i₁ c) (List R)
_∔ : ∀ {c R} → Parser NT Tok (false ◇ c) R →
LibraryNT NT Tok (i₂ c) (List R)
private
i₁ i₂ : _ → _
i₁ = _
i₂ = _
library : ∀ {NT Tok} → (∀ {i R} → LibraryNT NT Tok i R → NT i R) →
∀ {i R} → LibraryNT NT Tok i R → Parser NT Tok i R
library lift (p ★) = return [] ∣ ! (lift (p ∔))
library lift (p ∔) = p >>= λ x →
! (lift (p ★)) >>= λ xs →
return (x ∷ xs)
mutual
data NT : NonTerminalType where
lib : ∀ {i R} → LibraryNT NT Char i R → NT i R
a : NT i₃ Char
as : NT i₄ (List Char)
private
i₃ = _
i₄ = _
grammar : Grammar NT Char
grammar (lib nt) = library lib nt
grammar a = tok 'a'
grammar as = ! (lib (! a ★))
ex₁ : "aa" ∈? ! as / grammar ≡ [ 'a' ∷ 'a' ∷ [] ]
ex₁ = P.refl
| {
"alphanum_fraction": 0.4998650836,
"avg_line_length": 23.38170347,
"ext": "agda",
"hexsha": "e60e435f5a4682292afc2c8b6fe63d56e312457b",
"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": "StructurallyRecursiveDescentParsing/Examples.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": "StructurallyRecursiveDescentParsing/Examples.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": "StructurallyRecursiveDescentParsing/Examples.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": 2501,
"size": 7412
} |
module Issue261 where
postulate
List : Set → Set
nil : ∀ A → List A
Nat : Set
works-now : List Nat
works-now with nil _
... | xs = xs
| {
"alphanum_fraction": 0.6153846154,
"avg_line_length": 11.9166666667,
"ext": "agda",
"hexsha": "a27bddaab6ef80c1758d428d380c21e8e72eaa9a",
"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/Issue261.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/Issue261.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/Succeed/Issue261.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": 47,
"size": 143
} |
module _ where
module A where
data D : Set where
!_ : D
module B where
data D : Set where
!_ : D
open A
test : B.D
test = !_
| {
"alphanum_fraction": 0.5734265734,
"avg_line_length": 8.4117647059,
"ext": "agda",
"hexsha": "ec270cc0748bc4e1e7440c562cc72e18f4c2ebbe",
"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/Sections-16.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/Sections-16.agda",
"max_line_length": 20,
"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/Sections-16.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": 48,
"size": 143
} |
------------------------------------------------------------------------
-- An alternative definition of the partiality monad: a variant of the
-- delay monad quotiented by a notion of weak bisimilarity
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --sized-types #-}
module Partiality-monad.Coinductive.Alternative where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (⊥)
open import Bijection equality-with-J using (_↔_)
open import Function-universe equality-with-J hiding (⊥↔⊥)
open import H-level equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
open import Quotient equality-with-paths
import Delay-monad.Alternative as A
import Delay-monad.Alternative.Equivalence as A
import Delay-monad.Alternative.Weak-bisimilarity as A
import Delay-monad.Bisimilarity as B
import Partiality-monad.Coinductive as C
-- The partiality monad, defined as the alternative definition of the
-- delay monad quotiented by weak bisimilarity.
_⊥ : ∀ {a} → Type a → Type a
A ⊥ = A.Delay A / A._≈_
-- The partiality monad is a set.
⊥-is-set : ∀ {a} {A : Type a} → Is-set (A ⊥)
⊥-is-set = /-is-set
-- This definition of the partiality monad is isomorphic to the one in
-- Partiality-monad.Coinductive, for sets, assuming extensionality.
⊥↔⊥ : ∀ {a} {A : Type a} →
Is-set A →
B.Extensionality a →
A ⊥ ↔ A C.⊥
⊥↔⊥ {A = A} A-set delay-ext = D↔D /-cong lemma
where
D↔D = A.Delay↔Delay delay-ext
lemma : (x y : A.Delay A) →
x A.≈ y ⇔ ∥ _↔_.to D↔D x B.≈ _↔_.to D↔D y ∥
lemma x y =
x A.≈ y ↔⟨ inverse $ ∥∥↔ (A.≈-propositional x y) ⟩
∥ x A.≈ y ∥ ↝⟨ ∥∥-cong-⇔ (A.≈⇔≈ A-set x y) ⟩□
∥ _↔_.to D↔D x B.≈ _↔_.to D↔D y ∥ □
| {
"alphanum_fraction": 0.6049649217,
"avg_line_length": 34.3148148148,
"ext": "agda",
"hexsha": "15cc22a92483117e9f1055a3d083e6070a7dd6a0",
"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": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Coinductive/Alternative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"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/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Coinductive/Alternative.agda",
"max_line_length": 81,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Coinductive/Alternative.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 613,
"size": 1853
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Indexed binary relations
------------------------------------------------------------------------
-- The contents of this module should be accessed via
-- `Relation.Binary.Indexed.Heterogeneous`.
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Indexed.Heterogeneous.Definitions where
open import Level
import Relation.Binary.Core as B
import Relation.Binary.Definitions as B
import Relation.Binary.PropositionalEquality.Core as P
open import Relation.Binary.Indexed.Heterogeneous.Core
private
variable
i a ℓ : Level
I : Set i
------------------------------------------------------------------------
-- Simple properties of indexed binary relations
Reflexive : (A : I → Set a) → IRel A ℓ → Set _
Reflexive _ _∼_ = ∀ {i} → B.Reflexive (_∼_ {i})
Symmetric : (A : I → Set a) → IRel A ℓ → Set _
Symmetric _ _∼_ = ∀ {i j} → B.Sym (_∼_ {i} {j}) _∼_
Transitive : (A : I → Set a) → IRel A ℓ → Set _
Transitive _ _∼_ = ∀ {i j k} → B.Trans _∼_ (_∼_ {j}) (_∼_ {i} {k})
| {
"alphanum_fraction": 0.5411334552,
"avg_line_length": 30.3888888889,
"ext": "agda",
"hexsha": "8df0b73e9f94e7ba62219372e659930a48f06b83",
"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/Binary/Indexed/Heterogeneous/Definitions.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/Binary/Indexed/Heterogeneous/Definitions.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/Binary/Indexed/Heterogeneous/Definitions.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": 285,
"size": 1094
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Data.Dyck.Empty where
open import Prelude
open import Data.Nat using (_+_)
open import Data.Vec.Iterated using (Vec; _∷_; []; foldlN; head)
private
variable
n : ℕ
--------------------------------------------------------------------------------
-- Binary trees: definition and associated functions
--------------------------------------------------------------------------------
data Tree (A : Type a) : Type a where
◇ : Tree A
[_] : A → Tree A
_*_ : Tree A → Tree A → Tree A
--------------------------------------------------------------------------------
-- Programs: definition and associated functions
--------------------------------------------------------------------------------
data Prog (A : Type a) : ℕ → Type a where
halt : Prog A 1
push : A → Prog A (1 + n) → Prog A n
pull : Prog A (1 + n) → Prog A (2 + n)
skip : Prog A (1 + n) → Prog A n
--------------------------------------------------------------------------------
-- Conversion from a Prog to a Tree
--------------------------------------------------------------------------------
prog→tree⊙ : Prog A n → Vec (Tree A) n → Tree A
prog→tree⊙ halt (v ∷ []) = v
prog→tree⊙ (push v is) st = prog→tree⊙ is ([ v ] ∷ st)
prog→tree⊙ (pull is) (t₁ ∷ t₂ ∷ st) = prog→tree⊙ is (t₂ * t₁ ∷ st)
prog→tree⊙ (skip is) st = prog→tree⊙ is (◇ ∷ st)
prog→tree : Prog A zero → Tree A
prog→tree ds = prog→tree⊙ ds []
--------------------------------------------------------------------------------
-- Conversion from a Tree to a Prog
--------------------------------------------------------------------------------
tree→prog⊙ : Tree A → Prog A (suc n) → Prog A n
tree→prog⊙ [ x ] = push x
tree→prog⊙ (xs * ys) = tree→prog⊙ xs ∘ tree→prog⊙ ys ∘ pull
tree→prog⊙ ◇ = skip
tree→prog : Tree A → Prog A zero
tree→prog tr = tree→prog⊙ tr halt
--------------------------------------------------------------------------------
-- Proof of isomorphism
--------------------------------------------------------------------------------
tree→prog→tree⊙ : {is : Prog A (1 + n)} {st : Vec (Tree A) n} (e : Tree A) →
prog→tree⊙ (tree→prog⊙ e is) st ≡ prog→tree⊙ is (e ∷ st)
tree→prog→tree⊙ [ x ] = refl
tree→prog→tree⊙ (xs * ys) = tree→prog→tree⊙ xs ; tree→prog→tree⊙ ys
tree→prog→tree⊙ ◇ = refl
prog→tree→prog⊙ : {st : Vec (Tree A) n} (is : Prog A n) →
tree→prog (prog→tree⊙ is st) ≡ foldlN (Prog A) tree→prog⊙ is st
prog→tree→prog⊙ halt = refl
prog→tree→prog⊙ (push i is) = prog→tree→prog⊙ is
prog→tree→prog⊙ (pull is) = prog→tree→prog⊙ is
prog→tree→prog⊙ (skip is) = prog→tree→prog⊙ is
prog-iso : Prog A zero ⇔ Tree A
prog-iso .fun = prog→tree
prog-iso .inv = tree→prog
prog-iso .rightInv = tree→prog→tree⊙
prog-iso .leftInv = prog→tree→prog⊙
| {
"alphanum_fraction": 0.4275210084,
"avg_line_length": 36.1518987342,
"ext": "agda",
"hexsha": "c0deed6c44901db67886d2088dea5b00b9803b70",
"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": "Data/Dyck/Empty.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": "Data/Dyck/Empty.agda",
"max_line_length": 80,
"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": "Data/Dyck/Empty.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": 872,
"size": 2856
} |
{-
Holey congruence where there is a 'general' `cong` function available, as in one
that works for any given function.
-}
open import Holes.Prelude
-- NOTE: Why can't we accept the actual functions as arguments instead of quoted
-- versions? Because macros don't play nicely with modules.
module Holes.Cong.General
(quote-cong : Name)
(quote-sym : Name)
where
open Holes.Prelude public using (quote-term)
import Holes.Term as HTerm
-- NOTE: This doesn't work! The place that uses the macros has to import
-- Holes.Term using (⌞_⌟) manually.
-- open HTerm using (⌞_⌟) public
open HTerm
private
-- If the given term is one that has arguments, returns them.
getArgs : Term → Maybe (List (Arg Term))
getArgs (var x args) = just args
getArgs (con c args) = just args
getArgs (def f args) = just args
getArgs (pat-lam cs args) = just args
getArgs _ = nothing
-- In a list of arguments, returns the relevant ones for a binary relation.
≈relevantArgs : List (Arg Term) → Maybe (Term × Term)
≈relevantArgs (_ ∷ _ ∷ arg _ x ∷ arg _ y ∷ []) = just (x , y)
≈relevantArgs _ = nothing
-- Given a type of the form `x ≡ y`, returns the pair `x , y`.
decompose≈ : Term → Maybe (Term × Term)
decompose≈ = getArgs >=> ≈relevantArgs
applyCong : Term → Term → Term
applyCong lambda inner-equality =
def quote-cong
( basicArg lambda -- f : A → B
∷ basicArg inner-equality -- x ≈ y
∷ [])
applySym : Term → Term
applySym equality =
def quote-sym
( basicArg equality -- i ≈ j
∷ [])
autoCongWithType : Term → Type → TC Term
autoCongWithType equalityTerm targetType =
-- Try to decompose the goal type, which should be of the form `x ≈ y`, into
-- `x` and `y`. Throw a type error if this is not possible.
liftMaybe ( strErr "Term is not of the form x ≈ y:"
∷ termErr targetType
∷ []) (decompose≈ targetType) >>=² λ goalLhs _ →
-- Try to extract the holes in the LHS. Throw a type error if this is not
-- possible.
checkedTermToHoley′ (printHoleyErr goalLhs) goalLhs >>=² λ _ lhsHoley →
-- Construct a lambda expression into the holes in the LHS.
return (holeyToLam lhsHoley) >>= λ lhsLam →
-- Apply the `cong` function with our newly constructed lambda and the
-- provided equality term. Most implicit arguments are left unknown, and
-- then inferred by Agda when we call `checkType`.
return (applyCong lhsLam equalityTerm) >>= λ congTerm →
-- Try to check the type of the cong term. If it doesn't work, try it
-- symmetrically. If that doesn't work, try the first again so that the user
-- gets a nicer error message.
checkType congTerm targetType
⟨ catchTC ⟩
checkType (applySym congTerm) targetType
⟨ catchTC ⟩
checkType congTerm targetType
-- `checkType` hopefully returns to us the `cong` call with filled implicit
-- arguments. Assuming the user's logic is correct, this is what we need to
-- prove the goal.
cong!′ : Term → Term → TC ⊤
cong!′ equalityTerm target =
inferType target >>=
autoCongWithType equalityTerm >>=
unify target
macro
cong! : Term → Term → TC ⊤
cong! = cong!′
| {
"alphanum_fraction": 0.6595481275,
"avg_line_length": 32.9693877551,
"ext": "agda",
"hexsha": "2469e194c521321ce888b154249a85f9dff12f08",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-02T18:57:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-01-27T14:57:39.000Z",
"max_forks_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-holes",
"max_forks_repo_path": "src/Holes/Cong/General.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_issues_repo_issues_event_max_datetime": "2020-08-31T20:58:33.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-16T10:47:58.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-holes",
"max_issues_repo_path": "src/Holes/Cong/General.agda",
"max_line_length": 80,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-holes",
"max_stars_repo_path": "src/Holes/Cong/General.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-03T15:02:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-01-28T10:56:46.000Z",
"num_tokens": 921,
"size": 3231
} |
open import FRP.JS.Nat using ( ℕ ) renaming ( _<_ to _<N_ ; _≤_ to _≤N_ )
open import FRP.JS.Bool using ( Bool ; true ; false ; not )
module FRP.JS.Char where
infix 4 _≟_ _≠_ _<_ _≤_
open import FRP.JS.Primitive public using ( Char )
private
primitive
primCharToNat : Char → ℕ
primCharEquality : Char → Char → Bool
toNat : Char → ℕ
toNat = primCharToNat
{-# COMPILED_JS toNat function(c) { return c.charCodeAt(0); } #-}
_≟_ : Char → Char → Bool
_≟_ = primCharEquality
{-# COMPILED_JS _≟_ function(c) { return function(d) { return c === d; }; } #-}
_≠_ : Char → Char → Bool
c ≠ d = not (c ≟ d)
{-# COMPILED_JS _≠_ function(c) { return function(d) { return c !== d; }; } #-}
_<_ : Char → Char → Bool
c < d = toNat c <N toNat d
{-# COMPILED_JS _<_ function(c) { return function(d) { return c < d; }; } #-}
_≤_ : Char → Char → Bool
c ≤ d = toNat c ≤N toNat d
{-# COMPILED_JS _≤_ function(c) { return function(d) { return c <= d; }; } #-}
| {
"alphanum_fraction": 0.609832636,
"avg_line_length": 24.5128205128,
"ext": "agda",
"hexsha": "9730bb9edae83ed1c7c9f45c384a5776be88f9fc",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "src/agda/FRP/JS/Char.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "src/agda/FRP/JS/Char.agda",
"max_line_length": 79,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/Char.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 339,
"size": 956
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Groupoid where
open import Level using (Level; suc; _⊔_)
open import Categories.Category using (Category)
import Categories.Morphism
record IsGroupoid {o ℓ e} (C : Category o ℓ e) : Set (o ⊔ ℓ ⊔ e) where
open Category C public
open Categories.Morphism C
infix 10 _⁻¹
field
_⁻¹ : ∀ {A B} → A ⇒ B → B ⇒ A
iso : ∀ {A B} {f : A ⇒ B} → Iso f (f ⁻¹)
module iso {A B f} = Iso (iso {A} {B} {f})
equiv-obj : ∀ {A B} → A ⇒ B → A ≅ B
equiv-obj f = record
{ from = f
; to = _
; iso = iso
}
-- this definition doesn't seem to 'carry its weight'
equiv-obj-sym : ∀ {A B} → A ⇒ B → B ≅ A
equiv-obj-sym f = ≅.sym (equiv-obj f)
-- A groupoid is a category that has a groupoid structure
record Groupoid (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
field
category : Category o ℓ e
isGroupoid : IsGroupoid category
open IsGroupoid isGroupoid public
| {
"alphanum_fraction": 0.6006224066,
"avg_line_length": 23.512195122,
"ext": "agda",
"hexsha": "5c8b0c643fd6690d26a9ac08205eb5fb71f4bfec",
"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": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Groupoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"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": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Groupoid.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Groupoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 343,
"size": 964
} |
module plfa.part1.Midterm where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
-- you can add any import definitions that you need
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_; _>_; z≤n; s≤s; _≤?_)
open import Data.Nat.Properties using (+-assoc; +-suc; *-suc; +-comm; *-distribˡ-+; *-identityʳ)
open import Relation.Nullary using (yes; no)
open import plfa.part1.Induction using (*-distrib-+; *-zero)
-- used for rewrite
simplify : ∀ {A : Set} (x : A) → x ≡ x
simplify x = refl
sum : ℕ → ℕ
sum 0 = 0
sum n@(suc sn) = sum sn + n
-- Problem 1
-- remove the "postulate" and prove this theorem, which is a version of
-- sum n ≡ n * (n + 1) / 2
---postulate
simple : ∀ (n : ℕ) → (sum n) * 2 ≡ (suc n) * n
simple zero = refl
simple (suc n) rewrite *-distrib-+ (sum n) (suc n) 2
| simple n
| simplify n
| *-suc n n
| +-comm n (n * n)
| sym (+-assoc n (n * n) n)
| +-comm n (n * n) | +-assoc (n * n) n n
| sym (+-suc (n * n) (n + n)) | sym (+-assoc n (n * n) (suc (n + n)))
| +-comm n (n * n)
| sym (+-suc (n * n) n)
| +-assoc (n * n) n (suc (n + n))
| sym (+-suc (n * n) (n + suc (n + n)))
| sym (+-suc n (suc (n + n)))
| sym (+-assoc (n * n) n (suc (suc (n + n))))
| *-suc n 1
| *-identityʳ n = refl
-- Problem 2
-- remove the postulate and implement this function, which gives an Natural
-- number approximation of square root
postulate
sqrt : ℕ → ℕ
-- you can run these test cases
-- _ : sqrt 0 ≡ 0
-- _ = refl
-- _ : sqrt 1 ≡ 1
-- _ = refl
-- _ : sqrt 2 ≡ 1
-- _ = refl
-- _ : sqrt 3 ≡ 1
-- _ = refl
-- _ : sqrt 4 ≡ 2
-- _ = refl
-- _ : sqrt 5 ≡ 2
-- _ = refl
-- _ : sqrt 6 ≡ 2
-- _ = refl
-- _ : sqrt 7 ≡ 2
-- _ = refl
-- _ : sqrt 8 ≡ 2
-- _ = refl
-- _ : sqrt 9 ≡ 3
-- _ = refl
-- _ : sqrt 10 ≡ 3
-- _ = refl
-- _ : sqrt 11 ≡ 3
-- _ = refl
-- _ : sqrt 12 ≡ 3
-- _ = refl
-- _ : sqrt 13 ≡ 3
-- _ = refl
-- _ : sqrt 14 ≡ 3
-- _ = refl
-- _ : sqrt 15 ≡ 3
-- _ = refl
-- _ : sqrt 16 ≡ 4
-- _ = refl
-- _ : sqrt 17 ≡ 4
-- _ = refl
-- _ : sqrt 18 ≡ 4
-- _ = refl
-- _ : sqrt 19 ≡ 4
-- _ = refl
-- _ : sqrt 20 ≡ 4
-- _ = refl
-- _ : sqrt 21 ≡ 4
-- _ = refl
-- _ : sqrt 22 ≡ 4
-- _ = refl
-- _ : sqrt 23 ≡ 4
-- _ = refl
-- _ : sqrt 24 ≡ 4
-- _ = refl
-- _ : sqrt 24 ≡ 4
-- _ = refl
-- _ : sqrt 24 ≡ 4
-- _ = refl
-- _ : sqrt 25 ≡ 5
-- _ = refl
-- _ : sqrt 26 ≡ 5
-- _ = refl
-- _ : sqrt 27 ≡ 5
-- _ = refl
| {
"alphanum_fraction": 0.4688812524,
"avg_line_length": 23.5945945946,
"ext": "agda",
"hexsha": "609407830588d0fba1168a13dec1826f4125322c",
"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": "a30af28dc669502ec79d36379afd6925ad8f74da",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "zrz1996/plfa.github.io",
"max_forks_repo_path": "src/plfa/part1/Midterm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a30af28dc669502ec79d36379afd6925ad8f74da",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "zrz1996/plfa.github.io",
"max_issues_repo_path": "src/plfa/part1/Midterm.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a30af28dc669502ec79d36379afd6925ad8f74da",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "zrz1996/plfa.github.io",
"max_stars_repo_path": "src/plfa/part1/Midterm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1073,
"size": 2619
} |
{-# OPTIONS --erased-cubical --safe #-}
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_ ; _>_; _<_; _≥_; z≤n; s≤s)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
module Nat where
-- Useful functions for natural numbers
_-_ : (n m : ℕ) → {m ≤ n} → ℕ
(n - zero) {z≤n} = n
(suc n - suc m) {s≤s p} = _-_ n m {p}
_-_⟨_⟩ : (n m : ℕ) → (m ≤ n) → ℕ
_-_⟨_⟩ n m m≤n = _-_ n m {m≤n}
m+n-m=n : (m n : ℕ) → {m≤n : m ≤ n} → m + (n - m ⟨ m≤n ⟩) ≡ n
m+n-m=n zero n {z≤n} = refl
m+n-m=n (suc m) (suc n) {s≤s m≤n} = cong suc (m+n-m=n m n {m≤n})
<-∨-≥ : (m n : ℕ) → m < n ⊎ m ≥ n
<-∨-≥ zero zero = inj₂ z≤n
<-∨-≥ zero (suc n) = inj₁ (s≤s z≤n)
<-∨-≥ (suc m) zero = inj₂ z≤n
<-∨-≥ (suc m) (suc n) with <-∨-≥ m n
... | inj₁ m<n = inj₁ (s≤s m<n)
... | inj₂ m≥n = inj₂ (s≤s m≥n)
| {
"alphanum_fraction": 0.4701912261,
"avg_line_length": 29.6333333333,
"ext": "agda",
"hexsha": "6f8d556cf941e7e6756adbc3781dbb684089d2e8",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Nat.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Nat.agda",
"max_line_length": 89,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 451,
"size": 889
} |
{-# OPTIONS --sized-types --show-implicit #-}
module SizedTypesScopeViolationInMeta where
open import Size
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {↑ size}
suc : {size : Size} -> Nat {size} -> Nat {↑ size}
-- exposing a bug in size constraint solving
-- *** Exception: Inconsistent meta: _73 [[CtxId 420],[CtxId 418]]
A : Set1
A = (Id : {i : Size} -> Nat {_} -> Set)
(k : Size)(m : Nat {↑ k}) -> Id {k} m
->
(j : Size)(n : Nat {j}) -> Id {j} n
{-
mutual
-- id : {i : Size} -> Nat {_} -> Nat {i} -- FAILS
id : {i : Size} -> Nat {i} -> Nat {i}
id x = x
succ : {i : Size} -> Nat {i} -> Nat {↑ i}
succ x = suc (id x)
-}
| {
"alphanum_fraction": 0.5169366716,
"avg_line_length": 22.6333333333,
"ext": "agda",
"hexsha": "7a2296431ec4ed257335cd028748faffd02987c5",
"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/bugs/SizedTypesScopeViolationInMeta.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/bugs/SizedTypesScopeViolationInMeta.agda",
"max_line_length": 66,
"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/bugs/SizedTypesScopeViolationInMeta.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": 246,
"size": 679
} |
module sv20.assign1.First where
{- Code partially taken from the book "Programming Language Foundations in
- Agda" by Philip Wadler, Wen Kokke, Jeremy Siek and many others. The book
- can be found at https://plfa.github.io/
-
- Based on chapter 1 - Natural numbers - https://plfa.github.io/Naturals/
-
- The solution for the homework can be found from line 161
-}
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
-- Gives us the power of writing `3` to mean `suc (suc (suc zero))` :)
{-# BUILTIN NATURAL ℕ #-}
import Relation.Binary.PropositionalEquality as Eq
open import Function.Base using (flip)
open Eq using (_≡_; _≢_; refl; cong; sym; trans)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
_+_ : ℕ → ℕ → ℕ
zero + n = n -- +-def₀
(suc m) + n = suc (m + n) -- +-def₁
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
_^_ : ℕ → ℕ → ℕ
n ^ zero = suc zero
n ^ (suc m) = n * (n ^ m)
-- Monus
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
infixl 6 _+_ _∸_
infixl 7 _*_
infixr 8 _^_
assoc-+ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
assoc-+ zero n p = refl
assoc-+ (suc m) n p rewrite assoc-+ m n p = refl
comm-+₀ : ∀ (m : ℕ) → m + zero ≡ m
comm-+₀ zero = refl
-- Proofs on natural numbers can be written in a manner that ressembles a pen
-- and paper proof. For example:
comm-+₀ (suc n) =
begin
suc n + zero
≡⟨⟩ -- By addition definition
suc (n + zero)
≡⟨ cong suc (comm-+₀ n) ⟩
suc n
∎
-- But often, proofs are written for Agda to check them and not to humans to
-- read them. The above proof can be written succintly as:
--comm-+₀ (suc n) rewrite comm-+₀ n = refl
succ_right : ∀ (n m : ℕ) → suc (n + m) ≡ n + suc m
succ_right zero m = refl
succ_right (suc n) m rewrite succ_right n m = refl
--succ_right (suc n) m = cong suc (succ_right n m)
--succ_right (suc n) m =
-- begin
-- suc (suc n + m)
-- ≡⟨⟩
-- suc (suc (n + m))
-- ≡⟨ cong suc (succ_right n m) ⟩
-- suc (n + suc m)
-- ≡⟨⟩
-- suc n + suc m
-- ∎
comm-+ : ∀ (n m : ℕ) → n + m ≡ m + n
comm-+ zero n = sym (comm-+₀ n)
comm-+ (suc n) m rewrite comm-+ n m | succ_right m n = refl
--comm-+ (suc n) m = trans (cong suc (comm-+ n m)) (succ_right m n)
--comm-+ (suc n) m =
-- begin
-- suc n + m
-- ≡⟨⟩ -- +-def₁
-- suc (n + m)
-- ≡⟨ cong suc (comm-+ n m) ⟩
-- suc (m + n)
-- ≡⟨ succ_right m n ⟩
-- m + suc n
-- ∎
swap-m-n-+ : ∀ (m n p) → m + (n + p) ≡ n + (m + p)
swap-m-n-+ m n p rewrite
sym (assoc-+ m n p)
| sym (assoc-+ n m p)
| comm-+ m n
= refl
right-zero-* : ∀ (n : ℕ) → n * 0 ≡ 0
right-zero-* zero = refl
right-zero-* (suc n) rewrite right-zero-* n = refl
suc-right-* : ∀ (m n) → m * suc n ≡ m + m * n
suc-right-* zero n = refl
suc-right-* (suc m) n
rewrite
suc-right-* m n
| sym (assoc-+ n m (m * n))
| comm-+ n m
| assoc-+ m n (m * n)
= refl
comm-* : ∀ (m n : ℕ) → m * n ≡ n * m
comm-* zero n rewrite right-zero-* n = refl
comm-* (suc m) n
rewrite
comm-* m n
| suc-right-* n m
= refl
distr-*-+ : ∀ (m n p) → (m + n) * p ≡ m * p + n * p
distr-*-+ zero _ _ = refl
distr-*-+ (suc m) n p
rewrite
distr-*-+ m n p
| assoc-+ p (m * p) (n * p)
= refl
distl-*-+ : ∀ (p m n) → p * (m + n) ≡ p * m + p * n
distl-*-+ zero _ _ = refl
distl-*-+ (suc p) m n
rewrite
distl-*-+ p m n
| sym (assoc-+ (m + n) (p * m) (p * n))
| sym (assoc-+ (m + p * m) n (p * n))
| assoc-+ m n (p * m)
| comm-+ n (p * m)
| assoc-+ m (p * m) n
= refl
assoc-* : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
assoc-* zero n p = refl
assoc-* (suc m) n p
rewrite
assoc-* m n p
| distr-*-+ n (m * n) p
| assoc-* m n p
= refl
swap-m-n-* : ∀ (m n p) → m * (n * p) ≡ n * (m * p)
swap-m-n-* m n p rewrite
sym (assoc-* m n p)
| sym (assoc-* n m p)
| comm-* m n
= refl
------------------------------------------------------------------------------------------
-- HOMEWORK SOLUTION --
------------------------------------------------------------------------------------------
-- We want to proof that:
distr-^-* : ∀ (m n p) → (m * n) ^ p ≡ (m ^ p) * (n ^ p)
-- We will prove the `distr-^-*` by induction. To prove something by induction
-- in Agda, we use recursion.
-- The first basic case is when `p = 0`
distr-^-* m n zero =
begin
(m * n) ^ zero
≡⟨⟩ -- The builtin option "NATURAL" allows us to write `0` instead of `zero`
(m * n) ^ 0
≡⟨⟩ -- because: n ^ zero = suc zero
suc 0
≡⟨⟩ -- because: zero + n = n
suc (0 + 0)
≡⟨⟩ -- because: (suc m) + n = suc (m + n)
suc 0 + 0
≡⟨⟩ -- Agda builtin option "NATURAL" allows us to write `1` instead of `suc 0`
1 + 0
≡⟨⟩ -- because: zero * n = zero
1 + 0 * 1
≡⟨⟩ -- because: (suc m) * n = n + (m * n)
suc 0 * 1
≡⟨⟩ -- `1` instead of `suc 0`
1 * 1
≡⟨⟩ -- because: n ^ zero = suc zero
1 * (n ^ 0)
≡⟨⟩ -- because: n ^ zero = suc zero
(m ^ 0) * (n ^ 0)
∎
-- Agda computes every expression it is given until it can't apply any more
-- rules, i.e, Agda reduces every expression to its normal form.
-- For example, if we give Agda the expression `2 + 1`, it will apply the
-- rule `(suc m) + n = suc (m + n)` until it arrives to
-- `suc (suc (suc zero))`, `3`.
--
-- Notice that every line in the previous proof reduces to `1`. This means
-- that Agda read the previous proof as:
--
--distr-^-* m n zero =
-- begin
-- 1
-- ≡⟨⟩
-- 1
-- ≡⟨⟩ -- ...
-- 1
-- ≡⟨⟩
-- 1
-- ∎
--
-- So we could have written a shorter proof saying that `1 ≡⟨⟩ 1 ∎` and it
-- would sufficient for Agda to approve our proof.
--
--distr-^-* _ _ zero = 1 ≡⟨⟩ 1 ∎
--
-- In fact, `1 ≡⟨⟩ 1 ∎` can be written as `refl` in Agda.
--
--distr-^-* _ _ zero = refl
-- The following two base cases can be easily proven with the same technique as
-- the previous proof:
distr-^-* zero _ (suc p) = refl
-- For the last base case, we need a little more human involvement because the
-- expressions do not reduce completly to a common normal form.
distr-^-* (suc m) zero (suc p) =
begin
(suc m * 0) ^ suc p
≡⟨⟩ -- Agda reduces the expression to
m * 0 * (m * 0) ^ p
-- Applying `right-zero-*` (`n * 0 ≡ 0`) lemma to the left side
≡⟨ cong (_* (m * 0) ^ p) (right-zero-* m) ⟩
0 * (m * 0) ^ p
≡⟨⟩ -- reduces to
0
-- Applying `sym ∘ right-zero-*` (`0 ≡ n * 0`) lemma to the left side
≡⟨ sym (right-zero-* (suc m ^ suc p)) ⟩
(suc m ^ suc p) * 0
≡⟨⟩ -- reduces to
(suc m ^ p + m * suc m ^ p) * 0
≡⟨⟩ -- reduced from our goal
(suc m ^ suc p) * (0 ^ suc p)
∎
--
-- Notice how the previous proof required us to tell Agda which "lemmas" to use
-- to be able to link the left side of the proof with the right side.
--
-- As before, we have more ways to write the previous proof. We can forgo all
-- the intermediate steps and tell Agda which lemmas the proof needs.
--
--distr-^-* (suc m) 0 (suc p) =
-- trans
-- (cong (_* (m * 0) ^ p) (right-zero-* m))
-- (sym (right-zero-* (suc m ^ suc p)))
--
-- An even shorter proof can be written using `rewrite`. `rewrite` will try to
-- apply the `lemmas` we tell it to apply once, descending order. If the
-- rewriting process works by the end, we will only need `refl` to indicate
-- that both sides of the proof are the same.
--
--distr-^-* (suc m) zero (suc p)
-- rewrite
---- We start with what we want to proof:
----
---- (suc m * zero) ^ suc p ≡ suc m ^ suc p * zero ^ suc p
----
---- which reduces to
----
---- m * 0 * (m * 0) ^ p ≡ (suc m ^ p + m * suc m ^ p) * 0
----
-- right-zero-* m -- asking to rewrite all appearances of `m * 0` for `0`
----
---- λ m p → 0 * 0 ^ p ≡ (suc m ^ p + m * suc m ^ p) * 0
----
---- which reduces to
----
---- 0 ≡ (suc m ^ p + m * suc m ^ p) * 0
----
-- -- asking to rewrite all appearances of `(suc m ^ suc p) * 0` for `0`
-- -- (notice that: `(suc m ^ suc p)` reduces to `(suc m ^ p + m * suc m ^ p)`)
-- | right-zero-* (suc m ^ suc p)
----
---- 0 ≡ 0
----
---- We have arrived to a expression where both sides are equal. Thus we have
---- found a proof.
-- = refl
--
-- The final part of the inductive proof requires us to proof the inductive
-- case:
distr-^-* (suc m) (suc n) (suc p)
rewrite
-- First we start with expression:
--
-- (m * n) ^ p ≡ (m ^ p) * (n ^ p)
--
-- Reducing the expression to its normal form:
--
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡ (suc m ^ p + m * suc m ^ p) * (suc n ^ p + n * suc n ^ p)
-- Applying distributivity of _+_ over _*_
distr-*-+ (suc m ^ p) (m * suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * (suc n ^ p + n * suc n ^ p)
-- + m * suc m ^ p * (suc n ^ p + n * suc n ^ p)
| assoc-* m (suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * (suc n ^ p + n * suc n ^ p)
-- + m * (suc m ^ p * (suc n ^ p + n * suc n ^ p))
| distl-*-+ (suc m ^ p) (suc n ^ p) (n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| comm-* m (suc n)
-- suc (n + (m + n * m)) ^ p
-- + (n + (m + n * m)) * suc (n + (m + n * m)) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| comm-* n m
-- suc (n + (m + m * n)) ^ p
-- + (n + (m + m * n)) * suc (n + (m + m * n)) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| sym (suc-right-* m n)
-- suc (n + m * suc n) ^ p
-- + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distr-^-* (suc m) (suc n) p -- INDUCTIVE HYPOTHESIS!!
-- suc m ^ p * suc n ^ p + (n + m * suc n) * (suc m ^ p * suc n ^ p)
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distr-*-+ n (m * suc n) (suc m ^ p * suc n ^ p)
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + m * suc n * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distl-*-+ m (suc m ^ p * suc n ^ p) (suc m ^ p * (n * suc n ^ p))
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + m * suc n * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| comm-* m (suc n)
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + (m + n * m) * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| distr-*-+ m (n * m) (suc m ^ p * suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| swap-m-n-* n (suc m ^ p) (suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| swap-m-n-* (suc m ^ p) n (suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (n * (suc m ^ p * suc n ^ p)))
| sym (assoc-* m n (suc m ^ p * suc n ^ p))
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * n * (suc m ^ p * suc n ^ p))
| comm-* m n
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
| assoc-+ (suc m ^ p * suc n ^ p) (n * (suc m ^ p * suc n ^ p))
(m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
--
-- We finally find that the two expressions are equal!
--
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
--
-- QED
= refl
-- The full proof without comments:
--distr-^-* : ∀ (m n p) → (m * n) ^ p ≡ (m ^ p) * (n ^ p)
--distr-^-* _ _ zero = refl
--distr-^-* zero _ (suc p) = refl
--distr-^-* (suc m) zero (suc p)
-- rewrite
-- right-zero-* m
-- | right-zero-* (suc m ^ suc p)
-- = refl
--distr-^-* (suc m) (suc n) (suc p)
-- rewrite
-- distr-*-+ (suc m ^ p) (m * suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- | assoc-* m (suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- | distl-*-+ (suc m ^ p) (suc n ^ p) (n * suc n ^ p)
-- | comm-* m (suc n)
-- | comm-* n m
-- | sym (suc-right-* m n)
-- | distr-^-* (suc m) (suc n) p
-- | distr-*-+ n (m * suc n) (suc m ^ p * suc n ^ p)
-- | distl-*-+ m (suc m ^ p * suc n ^ p) (suc m ^ p * (n * suc n ^ p))
-- | comm-* m (suc n)
-- | distr-*-+ m (n * m) (suc m ^ p * suc n ^ p)
-- | swap-m-n-* n (suc m ^ p) (suc n ^ p)
-- | swap-m-n-* (suc m ^ p) n (suc n ^ p)
-- | sym (assoc-* m n (suc m ^ p * suc n ^ p))
-- | comm-* m n
-- | assoc-+ (suc m ^ p * suc n ^ p) (n * (suc m ^ p * suc n ^ p))
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
-- = refl
| {
"alphanum_fraction": 0.4507169706,
"avg_line_length": 32.1387024609,
"ext": "agda",
"hexsha": "35a717f46694c7e210750fc4912ce475eb357857",
"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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/sv20/assign1/First.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/sv20/assign1/First.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/sv20/assign1/First.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6031,
"size": 14366
} |
{-# OPTIONS --without-K --safe #-}
-- Identity-on-Objects Functor for (Object-)Unbundled Categories
module Categories.Functor.IdentityOnObjects where
open import Data.Product using (_,_)
open import Function using () renaming (id to id→)
open import Level
open import Categories.Category.Unbundled using (Category)
open import Categories.Category.Unbundled.Properties using (pack′)
open import Categories.Category.Unbundled.Utilities using (module Equiv)
open import Categories.Functor.Core using (Functor)
private
variable
o ℓ e ℓ′ e′ : Level
record IdentityOnObjects {Obj : Set o} (C : Category Obj ℓ e) (D : Category Obj ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ ℓ′ ⊔ e′) where
eta-equality
private module C = Category C
private module D = Category D
field
F₁ : ∀ {A B} → (A C.⇒ B) → A D.⇒ B
identity : ∀ {A} → F₁ (C.id {A}) D.≈ D.id
homomorphism : ∀ {X Y Z} {f : X C.⇒ Y} {g : Y C.⇒ Z} →
F₁ (g C.∘ f) D.≈ F₁ g D.∘ F₁ f
F-resp-≈ : ∀ {A B} {f g : A C.⇒ B} → f C.≈ g → F₁ f D.≈ F₁ g
IOO⇒Functor : {Ob : Set o} {C : Category Ob ℓ e} {D : Category Ob ℓ′ e′} →
(F : IdentityOnObjects C D) → Functor (pack′ C) (pack′ D)
IOO⇒Functor F = record { F₀ = id→; IOO }
where module IOO = IdentityOnObjects F
id-IOO : {Obj : Set o} {C : Category Obj ℓ e} → IdentityOnObjects C C
id-IOO {C = C} = record { F₁ = id→ ; identity = refl ; homomorphism = refl ; F-resp-≈ = id→ }
where open Equiv C
| {
"alphanum_fraction": 0.6243055556,
"avg_line_length": 34.2857142857,
"ext": "agda",
"hexsha": "f060a475c68bfa9d49de47085a6d7d2d8a360d06",
"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": "src/Categories/Functor/IdentityOnObjects.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": "src/Categories/Functor/IdentityOnObjects.agda",
"max_line_length": 120,
"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": "src/Categories/Functor/IdentityOnObjects.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": 526,
"size": 1440
} |
{-# OPTIONS --no-termination-check #-}
module Data.Nat where
import Prelude
import Data.Bool as Bool
open Prelude
open Bool
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN SUC suc #-}
{-# BUILTIN ZERO zero #-}
infix 40 _==_ _<_ _≤_ _>_ _≥_
infixl 60 _+_ _-_
infixl 70 _*_
infixr 80 _^_
infix 100 _!
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
_-_ : Nat -> Nat -> Nat
zero - m = zero
suc n - zero = suc n
suc n - suc m = n - m
_*_ : Nat -> Nat -> Nat
zero * m = zero
suc n * m = m + n * m
_^_ : Nat -> Nat -> Nat
n ^ zero = 1
n ^ suc m = n * n ^ m
_! : Nat -> Nat
zero ! = 1
suc n ! = suc n * n !
{-# BUILTIN NATPLUS _+_ #-}
{-# BUILTIN NATMINUS _-_ #-}
{-# BUILTIN NATTIMES _*_ #-}
_==_ : Nat -> Nat -> Bool
zero == zero = true
zero == suc _ = false
suc _ == zero = false
suc n == suc m = n == m
_<_ : Nat -> Nat -> Bool
n < zero = false
zero < suc m = true
suc n < suc m = n < m
_≤_ : Nat -> Nat -> Bool
n ≤ m = n < suc m
_>_ = flip _<_
_≥_ = flip _≤_
{-# BUILTIN NATEQUALS _==_ #-}
{-# BUILTIN NATLESS _<_ #-}
divSucAux : Nat -> Nat -> Nat -> Nat -> Nat
divSucAux k m zero j = k
divSucAux k m (suc n) zero = divSucAux (suc k) m n m
divSucAux k m (suc n) (suc j) = divSucAux k m n j
modSucAux : Nat -> Nat -> Nat -> Nat -> Nat
modSucAux k m zero j = k
modSucAux k m (suc n) zero = modSucAux zero m n m
modSucAux k m (suc n) (suc j) = modSucAux (suc k) m n j
{-# BUILTIN NATDIVSUCAUX divSucAux #-}
{-# BUILTIN NATMODSUCAUX modSucAux #-}
div : Nat -> Nat -> Nat
div n zero = zero
div n (suc m) = divSucAux zero m n m
mod : Nat -> Nat -> Nat
mod n zero = zero
mod n (suc m) = modSucAux zero m n m
gcd : Nat -> Nat -> Nat
gcd a 0 = a
gcd a b = gcd b (mod a b)
lcm : Nat -> Nat -> Nat
lcm a b = div (a * b) (gcd a b)
even : Nat -> Bool
even n = mod n 2 == 0
odd : Nat -> Bool
odd n = mod n 2 == 1
| {
"alphanum_fraction": 0.5511363636,
"avg_line_length": 18.6153846154,
"ext": "agda",
"hexsha": "e289f8e720a38125e310343964f35c430fe76e8b",
"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": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "examples/lib/Data/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"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": "np/agda-git-experiment",
"max_issues_repo_path": "examples/lib/Data/Nat.agda",
"max_line_length": 55,
"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/lib/Data/Nat.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": 753,
"size": 1936
} |
module Categories.Functor.Monoidal where
| {
"alphanum_fraction": 0.8780487805,
"avg_line_length": 20.5,
"ext": "agda",
"hexsha": "045a43f0e89183494dec1ee68b67db7ff2aec7fa",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Functor/Monoidal.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Functor/Monoidal.agda",
"max_line_length": 40,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Functor/Monoidal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 9,
"size": 41
} |
-- Andreas, 2016-09-20 issue #2197
-- We are now only turning eta-equality on after positivity check.
-- This is at the end of the mutual block.
module _ where
open import Common.Equality
module Works where
mutual
record ⊤ : Set where
eta-equality
test : ∀ {x y : ⊤} → x ≡ y
test = refl
mutual
record ⊤ : Set where
test : ∀ {x y : ⊤} → x ≡ y
test = refl
-- Fails, as eta-equality is only turned on after mutual block.
| {
"alphanum_fraction": 0.6323851204,
"avg_line_length": 17.5769230769,
"ext": "agda",
"hexsha": "07e355aa67200fe9d36cc67a802b5cc9161539f1",
"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/NoEtaInMutual.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/NoEtaInMutual.agda",
"max_line_length": 67,
"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/NoEtaInMutual.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": 142,
"size": 457
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.XModule where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
open import Cubical.Homotopy.Base
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Structures.LeftAction
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.DStructures.Structures.Constant
open import Cubical.DStructures.Structures.Type
open import Cubical.DStructures.Structures.Group
open import Cubical.DStructures.Structures.Action
private
variable
ℓ ℓ' : Level
-------------------------------------------------
-- Definitions and properties of
-- equivariance and peiffer condition
-------------------------------------------------
module _ ((((G₀ , H) , _α_) , isAct) : Action ℓ ℓ') (φ : GroupHom H G₀) where
open GroupNotation₀ G₀
open GroupNotationᴴ H
private
f = GroupHom.fun φ
-- α is equivariant w.r.t φ if φ (g α h) ≡ g + (φ h) - g
isEquivariant : Type (ℓ-max ℓ ℓ')
isEquivariant = (g : ⟨ G₀ ⟩) → (h : ⟨ H ⟩) → f (g α h) ≡ (g +₀ f h) -₀ g
-- G₀ is a set, so isEquivariant is a proposition
isPropIsEquivariant : isProp isEquivariant
isPropIsEquivariant = isPropΠ2 (λ g h → set₀ (f (g α h)) ((g +₀ f h) -₀ g))
-- (α, φ) satisfies the peiffer condition, if
-- (φ h) α h' ≡ h + h' - h
isPeiffer : Type ℓ'
isPeiffer = (h h' : ⟨ H ⟩) → (f h) α h' ≡ (h +ᴴ h') -ᴴ h
-- H is a set, so isPeiffer is a proposition
isPropIsPeiffer : isProp isPeiffer
isPropIsPeiffer = isPropΠ2 (λ h h' → setᴴ ((f h) α h') ((h +ᴴ h') -ᴴ h))
module _ (ℓ ℓ' : Level) where
----------------------
-- Define the types of
-- - Actions α with a morphism φ
-- - Precrossed modules
-- - Crossed modules
-- and add URG structures to them
----------------------
ActionB = Σ[ (((G₀ , H) , _α_) , isAct) ∈ Action ℓ ℓ' ] (GroupHom H G₀)
PreXModule = Σ[ (α , φ) ∈ ActionB ] (isEquivariant α φ)
XModule = Σ[ ((α , φ) , isEqui) ∈ PreXModule ] (isPeiffer α φ)
-- displayed over 𝒮-Action, a morphism back
-- by lifting the morphism back over Grp² twice
𝒮ᴰ-Action\PreXModuleStr : URGStrᴰ (𝒮-Action ℓ ℓ')
(λ (((G , H) , _) , _) → GroupHom H G)
(ℓ-max ℓ ℓ')
𝒮ᴰ-Action\PreXModuleStr = VerticalLift2-𝒮ᴰ (𝒮-group ℓ ×𝒮 𝒮-group ℓ')
(𝒮ᴰ-G²\B ℓ ℓ')
(𝒮ᴰ-G²\Las ℓ ℓ')
(𝒮ᴰ-G²Las\Action ℓ ℓ')
𝒮-PreXModuleStr : URGStr ActionB (ℓ-max ℓ ℓ')
𝒮-PreXModuleStr = ∫⟨ 𝒮-Action ℓ ℓ' ⟩ 𝒮ᴰ-Action\PreXModuleStr
-- add equivariance condition
-- use that equivariance is a proposition
𝒮ᴰ-PreXModule : URGStrᴰ 𝒮-PreXModuleStr
(λ (α , φ) → isEquivariant α φ)
ℓ-zero
𝒮ᴰ-PreXModule = Subtype→Sub-𝒮ᴰ (λ (α , φ) → isEquivariant α φ , isPropIsEquivariant α φ)
𝒮-PreXModuleStr
𝒮-PreXModule : URGStr PreXModule (ℓ-max ℓ ℓ')
𝒮-PreXModule = ∫⟨ 𝒮-PreXModuleStr ⟩ 𝒮ᴰ-PreXModule
-- add the proposition isPeiffer to precrossed modules
𝒮ᴰ-XModule : URGStrᴰ 𝒮-PreXModule
(λ ((α , φ) , isEqui) → isPeiffer α φ)
ℓ-zero
𝒮ᴰ-XModule = Subtype→Sub-𝒮ᴰ (λ ((α , φ) , isEqui) → isPeiffer α φ , isPropIsPeiffer α φ)
𝒮-PreXModule
𝒮-XModule : URGStr XModule (ℓ-max ℓ ℓ')
𝒮-XModule = ∫⟨ 𝒮-PreXModule ⟩ 𝒮ᴰ-XModule
| {
"alphanum_fraction": 0.5938992042,
"avg_line_length": 34.2727272727,
"ext": "agda",
"hexsha": "e6cbea46ddfe8c336f9fbd07aa0011c3e692cebd",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/DStructures/Structures/XModule.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/DStructures/Structures/XModule.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/DStructures/Structures/XModule.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1351,
"size": 3770
} |
module Vector where
open import OscarPrelude
open import Arity
record Vector (A : Set) (𝑎 : Arity) : Set
where
constructor ⟨_⟩
field
vector : Vec A (arity 𝑎)
open Vector public
instance EqVector : {A : Set} ⦃ _ : Eq A ⦄ {𝑎 : Arity} → Eq (Vector A 𝑎)
Eq._==_ EqVector _ = decEq₁ (cong vector) ∘ (_≟_ on vector $ _)
| {
"alphanum_fraction": 0.6493902439,
"avg_line_length": 19.2941176471,
"ext": "agda",
"hexsha": "5c60850ebfecb53aa3473c8175eeef217785b159",
"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": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/Vector.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/Vector.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/Vector.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 123,
"size": 328
} |
{-
Type-level differentiation in Agda; or differentiation of functors!
Most things below are just restatements of elementary category theory.
The new things are Diff, which defines the derivative of an arbitrary
functor from Set to Set, and _+++_ _***_ _∘∘∘_ which show how to
differentiate sums, products and compositions of such functors.
-}
{-# OPTIONS --type-in-type #-} -- needed in (fun (Diff f) x)
module DiffFunctor where
-- ( syntax )
infix 6 _[_]
infix 5 _∘∘_
infix 5 _∘∘∘_
infix 4 _**_
infix 4 _***_
infix 3 _++_
infix 2 _=>_
-- Numbers are formalised as sets!
Num = Set
-- ( addition of numbers )
data _+_ (a : Num) (b : Num) : Num where
inl : a -> a + b
inr : b -> a + b
[_,_] : {a b c : Num} -> (a -> c) -> (b -> c) -> (a + b -> c)
[ a , b ] (inl x) = a x
[ a , b ] (inr x) = b x
map[+] : {a₀ b₀ a₁ b₁ : Num} -> (a₀ -> a₁) -> (b₀ -> b₁) -> (a₀ + b₀ -> a₁ + b₁)
map[+] a b (inl x) = inl (a x)
map[+] a b (inr x) = inr (b x)
-- ( multiplication of numbers )
data _*_ (a : Num) (b : Num) : Num where
pair : a -> b -> a * b
⟨_,_⟩ : {a b c : Num} -> (c -> a) -> (c -> b) -> (c -> a * b)
⟨ a , b ⟩ x = pair (a x) (b x)
map[*] : {a₀ b₀ a₁ b₁ : Num} -> (a₀ -> a₁) -> (b₀ -> b₁) -> (a₀ * b₀ -> a₁ * b₁)
map[*] a b (pair x y) = pair (a x) (b y)
-- Functions are formalised as functors!
record Fun : Set where
constructor _[_]
field
fun : Num -> Num
map : {x y : Num} -> (u : x -> y) -> (fun x -> fun y)
open Fun
-- ( pointwise addition of functions )
_++_ : Fun -> Fun -> Fun
fun (f ++ g) x = fun f x + fun g x
map (f ++ g) u = map[+] (map f u) (map g u)
-- ( pointwise multiplication of functions )
_**_ : Fun -> Fun -> Fun
fun (f ** g) x = fun f x * fun g x
map (f ** g) u = map[*] (map f u) (map g u)
-- ( composition of functions )
_∘∘_ : Fun -> Fun -> Fun
fun (f ∘∘ g) x = fun f (fun g x)
map (f ∘∘ g) u = map f (map g u)
-- Differentiation is parametric consumption of a resource!
-- You are supposed to use dx : h precisely once, like in linear logic.
Diff : Fun -> Fun
fun (Diff f) x = {h : Num} -> (dx : h) -> fun f (x + h)
map (Diff f) u f[x+·] dx = map f (map[+] u (\dx -> dx)) (f[x+·] dx)
-- A differentiation rule is a natural transformation! (in reverse)
_=>_ : Fun -> Fun -> Set
f => g = ((x : Num) -> fun f x -> fun g x)
-- (omitting naturality conditions)
-- ( derivative of sum )
_+++_ : (f g : Fun) -> Diff f ++ Diff g => Diff (f ++ g)
(f +++ g) x (inl f[x+·]) dx = inl (f[x+·] dx)
(f +++ g) x (inr g[x+·]) dx = inr (g[x+·] dx)
-- (derivative of product )
_***_ : (f g : Fun) -> Diff f ** g ++ f ** Diff g => Diff (f ** g)
(f *** g) x (inl (pair f[x+·] g[x])) dx = pair (f[x+·] dx) (map g inl g[x])
(f *** g) x (inr (pair f[x] g[x+·])) dx = pair (map f inl f[x]) (g[x+·] dx)
-- ( derivative of composition )
_∘∘∘_ : (f g : Fun) -> Diff f ∘∘ g ** Diff g => Diff (f ∘∘ g)
(f ∘∘∘ g) x (pair f[g[x]+·] g[x+·]) {h} dx = f[g[x+dx]]
where
f[g[x+dx]] : fun (f ∘∘ g) (x + h)
f[g[x+dx]] = map f [ map g inl , g[x+·] ] (f[g[x]+·] dx)
{-
Things that need to be done:
- Define higher order derivatives as follows:
HighDiff n f x = forall h. h |n| -> f (x + h)
Here h |n| stands for n copies of the resource h. Try to show
n! -> Diff^n f => HighDiff n f.
- Explore differential calculus in several variables.
- Explore integration and differential equations. (hard)
- Solve partial differential equations. (good luck)
- Explore inverse functions. (hard)
- Write some examples, such as
0 => Diff (Const a)
1 => Diff Id
n * Id^(n-1) => Diff Id^n
List ** List => Diff List
derivatives of linear transformations
-}
| {
"alphanum_fraction": 0.5428020919,
"avg_line_length": 29.7786885246,
"ext": "agda",
"hexsha": "c92356c9fd5d84c2b9570b84cb4f2fd025b3c0e9",
"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": "e56caa8dfeb8d5a033ae2f06782bbeb67ced58d1",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JoelSjogren/diff-functor",
"max_forks_repo_path": "DiffFunctor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e56caa8dfeb8d5a033ae2f06782bbeb67ced58d1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JoelSjogren/diff-functor",
"max_issues_repo_path": "DiffFunctor.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e56caa8dfeb8d5a033ae2f06782bbeb67ced58d1",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JoelSjogren/diff-functor",
"max_stars_repo_path": "DiffFunctor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1359,
"size": 3633
} |
module Long where
data Nat : Set where
z : Nat
s : (n : Nat) → Nat
data Exp : Set where
val : (n : Nat) → Exp
throw : Exp
data Maybe (A : Set) : Set where
Just : A → Maybe A
Nothing : Maybe A
abstract
s′ : Nat → Nat
s′ = s
eval : Exp → Maybe Nat
eval (val n) = ?
eval throw = ?
data D : Nat → Set where
d : D z
foo : D {!!}
foo = {!!}
bar : D z
bar = {!!}
baz : Maybe {!!}
baz = {!!}
| {
"alphanum_fraction": 0.5131894484,
"avg_line_length": 11.9142857143,
"ext": "agda",
"hexsha": "5e26c417e47425324bfe84733fe98aecfd7eed53",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Long.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/interaction/Long.agda",
"max_line_length": 32,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/interaction/Long.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": 150,
"size": 417
} |
open import Prelude
module Implicits.Syntax.Type.Unification where
open import Data.Maybe as Maybe
open import Data.Unit
open import Implicits.Syntax
open import Implicits.Syntax.Type.Unification.McBride as McBride using (
substitute; asub; AList; _//_) public
open import Data.Vec.Properties
open import Data.Nat as N using ()
open import Data.Nat.Properties.Simple
open import Category.Monad
open import Data.Fin.Substitution
open import Implicits.Substitutions
open import Implicits.Syntax.MetaType public
open import Implicits.Substitutions.Lemmas
open McBride using (substitute; asub; AList; ASub; _//_; asub-weaken) public
private
module M = MetaTypeMetaSubst
module T = MetaTypeTypeSubst
-- Just a bit stricter than mcbride.mgu
-- We require here as well that all meta variables are instantiated
-- (this is equivalent to the ⊢unamb constraint in Oliveira)
mgu : ∀ {m ν} (a : MetaType m ν) → (b : SimpleType ν) → Maybe (Sub (flip MetaType ν) m zero)
mgu a b with McBride.mgu a (simpl b)
mgu a b | just (zero , u) = just (asub u)
mgu a b | just (suc m , _) = nothing
mgu a b | nothing = nothing
Unifier : ∀ {m ν} → (MetaType m ν) → SimpleType ν → (Sub (flip MetaType ν) m zero) → Set
Unifier {m} a b u = from-meta (a M./ u) ≡ (simpl b)
Unifiable : ∀ {m ν} → (MetaType m ν) → SimpleType ν → Set
Unifiable a τ = ∃ (Unifier a τ)
◁-Unifiable : ∀ {m ν} → MetaType m ν → SimpleType ν → Set
◁-Unifiable x τ = Unifiable (x M.◁m) τ
meta-weaken = M.weaken
smeta-weaken = M.smeta-weaken
open-meta = M.open-meta
| {
"alphanum_fraction": 0.7225509533,
"avg_line_length": 33.0652173913,
"ext": "agda",
"hexsha": "132c9dfb5242f064ac0c1e19f9cc45b351805aff",
"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/Syntax/Type/Unification.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/Syntax/Type/Unification.agda",
"max_line_length": 92,
"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/Syntax/Type/Unification.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": 476,
"size": 1521
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise lifting of relations to lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Pointwise where
open import Function
open import Function.Inverse using (Inverse)
open import Data.Product hiding (map)
open import Data.List.Base as List hiding (map; head; tail)
open import Data.List.Properties using (≡-dec)
open import Data.Fin using (Fin) renaming (zero to fzero; suc to fsuc)
open import Data.Nat using (ℕ; zero; suc)
open import Level
open import Relation.Nullary
open import Relation.Nullary.Negation using (contradiction)
import Relation.Nullary.Decidable as Dec using (map′)
open import Relation.Unary as U using (Pred)
open import Relation.Binary renaming (Rel to Rel₂)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
infixr 5 _∷_
data Pointwise {a b ℓ} {A : Set a} {B : Set b}
(_∼_ : REL A B ℓ) : List A → List B → Set (a ⊔ b ⊔ ℓ) where
[] : Pointwise _∼_ [] []
_∷_ : ∀ {x xs y ys} (x∼y : x ∼ y) (xs∼ys : Pointwise _∼_ xs ys) →
Pointwise _∼_ (x ∷ xs) (y ∷ ys)
------------------------------------------------------------------------
-- Operations
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
head : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
head (x∼y ∷ xs∼ys) = x∼y
tail : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) →
Pointwise _∼_ xs ys
tail (x∼y ∷ xs∼ys) = xs∼ys
rec : ∀ {c} (P : ∀ {xs ys} → Pointwise _∼_ xs ys → Set c) →
(∀ {x y xs ys} {xs∼ys : Pointwise _∼_ xs ys} →
(x∼y : x ∼ y) → P xs∼ys → P (x∼y ∷ xs∼ys)) →
P [] →
∀ {xs ys} (xs∼ys : Pointwise _∼_ xs ys) → P xs∼ys
rec P c n [] = n
rec P c n (x∼y ∷ xs∼ys) = c x∼y (rec P c n xs∼ys)
map : ∀ {ℓ₂} {_≈_ : REL A B ℓ₂} →
_≈_ ⇒ _∼_ → Pointwise _≈_ ⇒ Pointwise _∼_
map ≈⇒∼ [] = []
map ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ map ≈⇒∼ xs≈ys
------------------------------------------------------------------------
-- Relational properties
reflexive : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
{_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →
_≈_ ⇒ _∼_ → Pointwise _≈_ ⇒ Pointwise _∼_
reflexive ≈⇒∼ [] = []
reflexive ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ reflexive ≈⇒∼ xs≈ys
refl : ∀ {a ℓ} {A : Set a} {_∼_ : Rel₂ A ℓ} →
Reflexive _∼_ → Reflexive (Pointwise _∼_)
refl rfl {[]} = []
refl rfl {x ∷ xs} = rfl ∷ refl rfl
symmetric : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
{_≈_ : REL A B ℓ₁} {_∼_ : REL B A ℓ₂} →
Sym _≈_ _∼_ → Sym (Pointwise _≈_) (Pointwise _∼_)
symmetric sym [] = []
symmetric sym (x∼y ∷ xs∼ys) = sym x∼y ∷ symmetric sym xs∼ys
transitive : ∀ {a b c ℓ₁ ℓ₂ ℓ₃}
{A : Set a} {B : Set b} {C : Set c}
{_≋_ : REL A B ℓ₁} {_≈_ : REL B C ℓ₂} {_∼_ : REL A C ℓ₃} →
Trans _≋_ _≈_ _∼_ →
Trans (Pointwise _≋_) (Pointwise _≈_) (Pointwise _∼_)
transitive trans [] [] = []
transitive trans (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =
trans x∼y y∼z ∷ transitive trans xs∼ys ys∼zs
antisymmetric : ∀ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b}
{_≤_ : REL A B ℓ₁} {_≤′_ : REL B A ℓ₂} {_≈_ : REL A B ℓ₃} →
Antisym _≤_ _≤′_ _≈_ →
Antisym (Pointwise _≤_) (Pointwise _≤′_) (Pointwise _≈_)
antisymmetric antisym [] [] = []
antisymmetric antisym (x∼y ∷ xs∼ys) (y∼x ∷ ys∼xs) =
antisym x∼y y∼x ∷ antisymmetric antisym xs∼ys ys∼xs
respects₂ : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
_∼_ Respects₂ _≈_ →
(Pointwise _∼_) Respects₂ (Pointwise _≈_)
respects₂ {_≈_ = _≈_} {_∼_} resp = resp¹ , resp²
where
resp¹ : ∀ {xs} → (Pointwise _∼_ xs) Respects (Pointwise _≈_)
resp¹ [] [] = []
resp¹ (x≈y ∷ xs≈ys) (z∼x ∷ zs∼xs) =
proj₁ resp x≈y z∼x ∷ resp¹ xs≈ys zs∼xs
resp² : ∀ {ys} → (flip (Pointwise _∼_) ys) Respects (Pointwise _≈_)
resp² [] [] = []
resp² (x≈y ∷ xs≈ys) (x∼z ∷ xs∼zs) =
proj₂ resp x≈y x∼z ∷ resp² xs≈ys xs∼zs
decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} →
Decidable _∼_ → Decidable (Pointwise _∼_)
decidable dec [] [] = yes []
decidable dec [] (y ∷ ys) = no (λ ())
decidable dec (x ∷ xs) [] = no (λ ())
decidable dec (x ∷ xs) (y ∷ ys) with dec x y
... | no ¬x∼y = no (¬x∼y ∘ head)
... | yes x∼y with decidable dec xs ys
... | no ¬xs∼ys = no (¬xs∼ys ∘ tail)
... | yes xs∼ys = yes (x∼y ∷ xs∼ys)
isEquivalence : ∀ {a ℓ} {A : Set a} {_≈_ : Rel₂ A ℓ} →
IsEquivalence _≈_ → IsEquivalence (Pointwise _≈_)
isEquivalence eq = record
{ refl = refl Eq.refl
; sym = symmetric Eq.sym
; trans = transitive Eq.trans
} where module Eq = IsEquivalence eq
isPreorder : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
IsPreorder _≈_ _∼_ → IsPreorder (Pointwise _≈_) (Pointwise _∼_)
isPreorder pre = record
{ isEquivalence = isEquivalence Pre.isEquivalence
; reflexive = reflexive Pre.reflexive
; trans = transitive Pre.trans
} where module Pre = IsPreorder pre
isPartialOrder : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_≤_ : Rel₂ A ℓ₂} →
IsPartialOrder _≈_ _≤_ →
IsPartialOrder (Pointwise _≈_) (Pointwise _≤_)
isPartialOrder po = record
{ isPreorder = isPreorder PO.isPreorder
; antisym = antisymmetric PO.antisym
} where module PO = IsPartialOrder po
isDecEquivalence : ∀ {a ℓ} {A : Set a} {_≈_ : Rel₂ A ℓ} →
IsDecEquivalence _≈_ →
IsDecEquivalence (Pointwise _≈_)
isDecEquivalence eq = record
{ isEquivalence = isEquivalence DE.isEquivalence
; _≟_ = decidable DE._≟_
} where module DE = IsDecEquivalence eq
preorder : ∀ {p₁ p₂ p₃} → Preorder p₁ p₂ p₃ → Preorder _ _ _
preorder p = record
{ isPreorder = isPreorder (Preorder.isPreorder p)
}
poset : ∀ {c ℓ₁ ℓ₂} → Poset c ℓ₁ ℓ₂ → Poset _ _ _
poset p = record
{ isPartialOrder = isPartialOrder (Poset.isPartialOrder p)
}
setoid : ∀ {c ℓ} → Setoid c ℓ → Setoid _ _
setoid s = record
{ isEquivalence = isEquivalence (Setoid.isEquivalence s)
}
decSetoid : ∀ {c ℓ} → DecSetoid c ℓ → DecSetoid _ _
decSetoid d = record
{ isDecEquivalence = isDecEquivalence (DecSetoid.isDecEquivalence d)
}
------------------------------------------------------------------------
-- tabulate
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
tabulate⁺ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →
(∀ i → f i ∼ g i) → Pointwise _∼_ (tabulate f) (tabulate g)
tabulate⁺ {zero} f∼g = []
tabulate⁺ {suc n} f∼g = f∼g fzero ∷ tabulate⁺ (f∼g ∘ fsuc)
tabulate⁻ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →
Pointwise _∼_ (tabulate f) (tabulate g) → (∀ i → f i ∼ g i)
tabulate⁻ {zero} [] ()
tabulate⁻ {suc n} (x∼y ∷ xs∼ys) fzero = x∼y
tabulate⁻ {suc n} (x∼y ∷ xs∼ys) (fsuc i) = tabulate⁻ xs∼ys i
------------------------------------------------------------------------
-- _++_
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
++⁺ : ∀ {ws xs ys zs} → Pointwise _∼_ ws xs → Pointwise _∼_ ys zs →
Pointwise _∼_ (ws ++ ys) (xs ++ zs)
++⁺ [] ys∼zs = ys∼zs
++⁺ (w∼x ∷ ws∼xs) ys∼zs = w∼x ∷ ++⁺ ws∼xs ys∼zs
------------------------------------------------------------------------
-- concat
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
concat⁺ : ∀ {xss yss} → Pointwise (Pointwise _∼_) xss yss →
Pointwise _∼_ (concat xss) (concat yss)
concat⁺ [] = []
concat⁺ (xs∼ys ∷ xss∼yss) = ++⁺ xs∼ys (concat⁺ xss∼yss)
------------------------------------------------------------------------
-- length
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
Pointwise-length : ∀ {xs ys} → Pointwise _∼_ xs ys →
length xs ≡ length ys
Pointwise-length [] = P.refl
Pointwise-length (x∼y ∷ xs∼ys) = P.cong ℕ.suc (Pointwise-length xs∼ys)
------------------------------------------------------------------------
-- reverse
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
reverseAcc⁺ : ∀ {as bs as′ bs′} → Pointwise R as′ bs′ → Pointwise R as bs →
Pointwise R (reverseAcc as′ as) (reverseAcc bs′ bs)
reverseAcc⁺ rs′ [] = rs′
reverseAcc⁺ rs′ (r ∷ rs) = reverseAcc⁺ (r ∷ rs′) rs
reverse⁺ : ∀ {as bs} → Pointwise R as bs → Pointwise R (reverse as) (reverse bs)
reverse⁺ = reverseAcc⁺ []
------------------------------------------------------------------------
-- map
module _ {a b c d r} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
{R : REL C D r} where
map⁺ : ∀ {as bs} (f : A → C) (g : B → D) →
Pointwise (λ a b → R (f a) (g b)) as bs →
Pointwise R (List.map f as) (List.map g bs)
map⁺ f g [] = []
map⁺ f g (r ∷ rs) = r ∷ map⁺ f g rs
map⁻ : ∀ {as bs} (f : A → C) (g : B → D) →
Pointwise R (List.map f as) (List.map g bs) →
Pointwise (λ a b → R (f a) (g b)) as bs
map⁻ {[]} {[]} f g [] = []
map⁻ {[]} {b ∷ bs} f g rs with Pointwise-length rs
... | ()
map⁻ {a ∷ as} {[]} f g rs with Pointwise-length rs
... | ()
map⁻ {a ∷ as} {b ∷ bs} f g (r ∷ rs) = r ∷ map⁻ f g rs
------------------------------------------------------------------------
-- filter
module _ {a b r p q} {A : Set a} {B : Set b} {R : REL A B r}
{P : Pred A p} {Q : Pred B q} (P? : U.Decidable P) (Q? : U.Decidable Q)
(P⇒Q : ∀ {a b} → R a b → P a → Q b) (Q⇒P : ∀ {a b} → R a b → Q b → P a)
where
filter⁺ : ∀ {as bs} → Pointwise R as bs → Pointwise R (filter P? as) (filter Q? bs)
filter⁺ [] = []
filter⁺ {a ∷ _} {b ∷ _} (r ∷ rs) with P? a | Q? b
... | yes p | yes q = r ∷ filter⁺ rs
... | yes p | no ¬q = contradiction (P⇒Q r p) ¬q
... | no ¬p | yes q = contradiction (Q⇒P r q) ¬p
... | no ¬p | no ¬q = filter⁺ rs
------------------------------------------------------------------------
-- replicate
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
replicate⁺ : ∀ {a b} → R a b → ∀ n → Pointwise R (replicate n a) (replicate n b)
replicate⁺ r 0 = []
replicate⁺ r (suc n) = r ∷ replicate⁺ r n
------------------------------------------------------------------------
-- Irrelevance
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
irrelevant : Irrelevant R → Irrelevant (Pointwise R)
irrelevant R-irr [] [] = P.refl
irrelevant R-irr (r ∷ rs) (r₁ ∷ rs₁) =
P.cong₂ _∷_ (R-irr r r₁) (irrelevant R-irr rs rs₁)
------------------------------------------------------------------------
-- Properties of propositional pointwise
module _ {a} {A : Set a} where
Pointwise-≡⇒≡ : Pointwise {A = A} _≡_ ⇒ _≡_
Pointwise-≡⇒≡ [] = P.refl
Pointwise-≡⇒≡ (P.refl ∷ xs∼ys) with Pointwise-≡⇒≡ xs∼ys
... | P.refl = P.refl
≡⇒Pointwise-≡ : _≡_ ⇒ Pointwise {A = A} _≡_
≡⇒Pointwise-≡ P.refl = refl P.refl
Pointwise-≡↔≡ : Inverse (setoid (P.setoid A)) (P.setoid (List A))
Pointwise-≡↔≡ = record
{ to = record { _⟨$⟩_ = id; cong = Pointwise-≡⇒≡ }
; from = record { _⟨$⟩_ = id; cong = ≡⇒Pointwise-≡ }
; inverse-of = record
{ left-inverse-of = λ _ → refl P.refl
; right-inverse-of = λ _ → P.refl
}
}
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
Rel = Pointwise
{-# WARNING_ON_USAGE Rel
"Warning: Rel was deprecated in v0.15.
Please use Pointwise instead."
#-}
Rel≡⇒≡ = Pointwise-≡⇒≡
{-# WARNING_ON_USAGE Rel≡⇒≡
"Warning: Rel≡⇒≡ was deprecated in v0.15.
Please use Pointwise-≡⇒≡ instead."
#-}
≡⇒Rel≡ = ≡⇒Pointwise-≡
{-# WARNING_ON_USAGE ≡⇒Rel≡
"Warning: ≡⇒Rel≡ was deprecated in v0.15.
Please use ≡⇒Pointwise-≡ instead."
#-}
Rel↔≡ = Pointwise-≡↔≡
{-# WARNING_ON_USAGE Rel↔≡
"Warning: Rel↔≡ was deprecated in v0.15.
Please use Pointwise-≡↔≡ instead."
#-}
-- Version 1.0
decidable-≡ = ≡-dec
{-# WARNING_ON_USAGE decidable-≡
"Warning: decidable-≡ was deprecated in v1.0.
Please use ≡-dec from `Data.List.Properties` instead."
#-}
| {
"alphanum_fraction": 0.48809429,
"avg_line_length": 35.6732954545,
"ext": "agda",
"hexsha": "ffcbf9c59c505cf1a8da3dd70dbc1e79c93f6c27",
"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/Binary/Pointwise.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/Binary/Pointwise.agda",
"max_line_length": 85,
"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/Binary/Pointwise.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4840,
"size": 12557
} |
------------------------------------------------------------------------
-- Identifiers
------------------------------------------------------------------------
{-# OPTIONS --guardedness #-}
module Examples.Identifier where
open import Codata.Musical.Notation
open import Data.Bool
open import Data.Char
open import Data.List.NonEmpty
open import Data.Product
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Relation.Nullary
open import Grammar.Infinite as Grammar
using (Grammar) hiding (module Grammar)
open import Pretty using (Doc; Pretty-printer)
open import Renderer
open import Utilities
-- Lower-case (ASCII) characters.
is-lower : Char → Bool
is-lower t = ('a' ≤?C t) ∧ (t ≤?C 'z')
-- A problematic attempt to define a grammar and a corresponding
-- pretty-printer for identifiers.
module Problematic where
-- The grammar can be defined.
identifier : Grammar (List⁺ Char)
identifier = (proj₁ <$> sat is-lower) +
where open Grammar
-- However, it is impossible to define a corresponding
-- pretty-printer.
no-printer : ¬ Pretty-printer identifier
no-printer identifier-printer = no-doc (identifier-printer [ 'A' ])
where
open Grammar
lemma : ∀ {p : Char → Bool} {t s s′} →
t ∷ s ∈ (proj₁ <$> sat p) + · s′ → T (p t)
lemma (⊛-sem (<$>-sem (<$>-sem {x = _ , ok} _)) _) = ok
no-doc : ¬ Doc identifier [ 'A' ]
no-doc d = lemma (proj₂ (Renderer.string-exists d))
-- Identifiers.
Identifier : Set
Identifier = List⁺ (∃ λ t → T (is-lower t))
identifier : Grammar Identifier
identifier = sat is-lower +
where open Grammar
identifier-printer : Pretty-printer identifier
identifier-printer = map+ (sat is-lower)
where open Pretty
-- Identifiers possibly followed by whitespace.
identifier-w : Grammar Identifier
identifier-w = identifier <⊛ whitespace ⋆
where open Grammar
identifier-w-printer : Pretty-printer identifier-w
identifier-w-printer n = identifier-printer n <⊛ nil-⋆
where open Pretty
test : render 80 (identifier-w-printer (str⁺ "aaa")) ≡ "aaa"
test = refl
| {
"alphanum_fraction": 0.6481303931,
"avg_line_length": 26.4050632911,
"ext": "agda",
"hexsha": "67efd3eaf696f0994db1a87f3fe2aae12be60545",
"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": "b956803ba90b6c5f57bbbaab01bb18485d948492",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/pretty",
"max_forks_repo_path": "Examples/Identifier.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492",
"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/pretty",
"max_issues_repo_path": "Examples/Identifier.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/pretty",
"max_stars_repo_path": "Examples/Identifier.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 523,
"size": 2086
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Sets.EquivalenceRelations
open import Numbers.Naturals.Semiring
open import Numbers.Integers.Definition
open import Numbers.Naturals.Order
open import LogicalFormulae
open import Groups.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Rings.Definition
open import Fields.Fields
open import Fields.Orders.Partial.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Fields.Orders.Total.Archimedean {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} {c : _} {_<_ : A → A → Set c} {pOrder : SetoidPartialOrder S _<_} {F : Field R} (p : PartiallyOrderedField F pOrder) where
open Setoid S
open Equivalence eq
open Ring R
open Group additiveGroup
open import Groups.Lemmas additiveGroup
open import Groups.Cyclic.Definition additiveGroup
open import Groups.Cyclic.DefinitionLemmas additiveGroup
open import Groups.Orders.Archimedean (toGroup R (PartiallyOrderedField.oRing p))
open import Rings.Orders.Partial.Lemmas (PartiallyOrderedField.oRing p)
open import Rings.InitialRing R
open SetoidPartialOrder pOrder
open PartiallyOrderedRing (PartiallyOrderedField.oRing p)
open Field F
ArchimedeanField : Set (a ⊔ c)
ArchimedeanField = (x : A) → (0R < x) → Sg ℕ (λ n → x < (fromN n))
private
lemma : (r : A) (N : ℕ) → (positiveEltPower 1R N * r) ∼ positiveEltPower r N
lemma r zero = timesZero'
lemma r (succ n) = transitive *DistributesOver+' (+WellDefined identIsIdent (lemma r n))
findBound : (0<1 : 0R < 1R) → (r s : A) (N : ℕ) → (1R < r) → (s < positiveEltPower 1R N) → s < positiveEltPower r N
findBound _ r s zero 1<r s<N = s<N
findBound 0<1 r s (succ N) 1<r s<N = <Transitive s<N (<WellDefined (transitive *Commutative identIsIdent) (lemma r (succ N)) (ringCanMultiplyByPositive' (fromNPreservesOrder 0<1 (succIsPositive N)) 1<r))
archFieldToGrp : ((x y : A) → 0R < x → (x * y) ∼ 1R → 0R < y) → ArchimedeanField → Archimedean
archFieldToGrp reciprocalPositive a r s 0<r 0<s with allInvertible r (λ r=0 → irreflexive (<WellDefined reflexive r=0 0<r))
... | inv , prInv with a inv (reciprocalPositive r inv 0<r (transitive *Commutative prInv))
... | N , invBound with a s 0<s
... | Ns , nSBound = (Ns *N N) , <WellDefined reflexive (symmetric (elementPowerMultiplies (nonneg Ns) (nonneg N) r)) (findBound (<WellDefined reflexive (transitive *Commutative prInv) (orderRespectsMultiplication 0<r (reciprocalPositive r inv 0<r (transitive *Commutative prInv)))) (positiveEltPower r N) s Ns m nSBound)
where
m : 1R < positiveEltPower r N
m = <WellDefined prInv (lemma r N) (ringCanMultiplyByPositive 0<r invBound)
archToArchField : 0R < 1R → Archimedean → ArchimedeanField
archToArchField 0<1 arch a 0<a with arch 1R a 0<1 0<a
... | N , pr = N , pr
| {
"alphanum_fraction": 0.7347956132,
"avg_line_length": 49.3278688525,
"ext": "agda",
"hexsha": "700107ba1726076910a1c735563ccc78d0e31459",
"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": "Fields/Orders/Total/Archimedean.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": "Fields/Orders/Total/Archimedean.agda",
"max_line_length": 321,
"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": "Fields/Orders/Total/Archimedean.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": 973,
"size": 3009
} |
-- ------------------------------------------------------------------------------------------------------
-- | ███████╗ ██████╗ ██╗ ██╗ ██╗██╗███╗ ██╗ ██████╗ ██████╗ ██╗███╗ ██╗ ██████╗ ███████╗ |
-- | ██╔════╝██╔═══██╗██║ ██║ ██║██║████╗ ██║██╔════╝ ██╔══██╗██║████╗ ██║██╔════╝ ██╔════╝ |
-- | ███████╗██║ ██║██║ ██║ ██║██║██╔██╗ ██║██║ ███╗ ██████╔╝██║██╔██╗ ██║██║ ███╗███████╗ |
-- | ╚════██║██║ ██║██║ ╚██╗ ██╔╝██║██║╚██╗██║██║ ██║ ██╔══██╗██║██║╚██╗██║██║ ██║╚════██║ |
-- | ███████║╚██████╔╝███████╗ ╚████╔╝ ██║██║ ╚████║╚██████╔╝ ██║ ██║██║██║ ╚████║╚██████╔╝███████║ |
-- | ╚══════╝ ╚═════╝ ╚══════╝ ╚═══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ |
-- | |
-- | ██╗███╗ ██╗ █████╗ ██████╗ ██████╗ █████╗ |
-- | ██║████╗ ██║ ██╔══██╗██╔════╝ ██╔══██╗██╔══██╗ |
-- | ██║██╔██╗ ██║ ███████║██║ ███╗██║ ██║███████║ |
-- | ██║██║╚██╗██║ ██╔══██║██║ ██║██║ ██║██╔══██║ |
-- | ██║██║ ╚████║ ██║ ██║╚██████╔╝██████╔╝██║ ██║ |
-- | ╚═╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ |
-- ------------------------------------------------------------------------------------------------------
--
-- Donnacha Oisín Kidney
-- 17 April 2019
--
-- Compiled with Agda version 2.6.1, and standard library commit 84d7962cfd90379a6d1d5ef2cdd9d3ae411ee603
-- This contains the worked-through source code for:
--
-- "Automatically And Efficiently Illustrating Polynomial Equalities in Agda"
--
-- We present a new library which automates the construction of equivalence
-- proofs between polynomials over commutative rings and semirings in the
-- programming language Agda. It is asymptotically faster than Agda's existing
-- solver. We use Agda's reflection machinery to provide a simple interface to
-- the solver, and demonstrate an interesting use of the constructed relations:
-- step-by-step solutions.
--
-- Which is (at time of writing) a work-in-progress.
--
-- This code is available on github:
-- https://github.com/oisdk/agda-ring-solver
--
-- As is the paper:
-- https://github.com/oisdk/agda-ring-solver-report
module README where
--------------------------------------------------------------------------------
-- There are 3 main contributions in this library: --
-- --
-- * A solver for polynomials over "almost commutative rings". --
-- Agda already has one these in the standard library, but this one --
-- is much more efficient. "Almost commutative rings" encapsulates a --
-- bunch of things, including ℕ. --
-- --
-- * A reflection-based interface. --
-- Not many people used the old solver, mainly (I think) because the --
-- interface was difficult and irritating. This library provides a --
-- super-simple interface using reflection. --
-- --
-- * An implementation of "step-by-step solutions". --
-- I don't know a huge amount about computer algebra systems, but I --
-- have used Wolfram Alpha countless times (especially when I was in --
-- school) to help with basic maths. I was able to get this solver to --
-- produce step-by-step solutions, and learned something about the --
-- theory behind them along the way. --
--------------------------------------------------------------------------------
--
-- ██████╗ ███████╗███╗ ██╗ ██████╗██╗ ██╗███╗ ███╗ █████╗ ██████╗ ██╗ ██╗███████╗
-- ██╔══██╗██╔════╝████╗ ██║██╔════╝██║ ██║████╗ ████║██╔══██╗██╔══██╗██║ ██╔╝██╔════╝
-- ██████╔╝█████╗ ██╔██╗ ██║██║ ███████║██╔████╔██║███████║██████╔╝█████╔╝ ███████╗ ███████╗
-- ██╔══██╗██╔══╝ ██║╚██╗██║██║ ██╔══██║██║╚██╔╝██║██╔══██║██╔══██╗██╔═██╗ ╚════██║ ╚════██║
-- ██████╔╝███████╗██║ ╚████║╚██████╗██║ ██║██║ ╚═╝ ██║██║ ██║██║ ██║██║ ██╗███████║ ██║
-- ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ██║
-- ██║
-- ███████╗██╗ ██╗ █████╗ ███╗ ███╗██████╗ ██╗ ███████╗███████╗ ██║
-- ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║██╔══██╗██║ ██╔════╝██╔════╝ ██║
-- █████╗ ╚███╔╝ ███████║██╔████╔██║██████╔╝██║ █████╗ ███████╗ ████████████████████╗ ██║
-- ██╔══╝ ██╔██╗ ██╔══██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝ ╚════██║ ╚═════════════════██║ ██║
-- ███████╗██╔╝ ██╗██║ ██║██║ ╚═╝ ██║██║ ███████╗███████╗███████║ ██║ ██║
-- ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝╚══════╝ ██║ ██║
-- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- You can ignore this bit! We're just overloading the literals Agda uses for -- ██║ ██║
-- numbers This bit isn't necessary if you're just using Nats, or if you -- ██║ ██║
-- construct your type directly. We only really do it here so that we can use -- ██║ ██║
-- different numeric types in the same file. -- ██║ ██║
-- ██║ ██║
open import Agda.Builtin.FromNat -- ██║ ██║
open import Data.Nat using (ℕ; suc) -- ██║ ██║
open import Data.Integer using (ℤ) -- ██║ ██║
-- ██║ ██║
instance -- ██║ ██║
numberNat : Number ℕ -- ██║ ██║
numberNat = Data.Nat.Literals.number -- ██║ ██║
where import Data.Nat.Literals -- ██║ ██║
-- ██║ ██║
instance -- ██║ ██║
numberInt : Number ℤ -- ██║ ██║
numberInt = Data.Integer.Literals.number -- ██║ ██║
where import Data.Integer.Literals -- ██║ ██║
-- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- Imports! -- ██║ ██║
-- ██║ ██║
open import Polynomial.Simple.AlmostCommutativeRing -- ██║ ██║
open import Polynomial.Simple.AlmostCommutativeRing.Instances -- ██║ ██║
open import Polynomial.Simple.Reflection -- ██║ ██║
open import Data.List as List using (List; _∷_; []) -- ██║ ██║
open import Function -- ██║ ██║
open import Relation.Binary.PropositionalEquality as ≡ using (subst; _≡_) -- ██║ ██║
open import Data.Bool as Bool using (Bool; true; false; if_then_else_) -- ██║ ██║
open import Data.Unit using (⊤; tt) -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- -- ██║ ██║
-- 8888888888',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888' -- ██║ ██║
-- ,8',8888888888888 -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- -- ██║ ██║
module IntExamples where -- ██║ ██║
open AlmostCommutativeRing Int.ring -- ██║ ██║
-- Everything is automatic: you just ask Agda to solve it and it does! -- ██╗ ██║ ██║
lemma₁ : ∀ x y → x + y * 1 + 3 ≈ 3 + 1 + y + x + - 1 -- ████║ ██║ ██║
lemma₁ = solve Int.ring -- ██████████║ ██║
-- ████╔═██║ ██║
lemma₂ : ∀ x y → (x + y) ^ 2 ≈ x ^ 2 + 2 * x * y + y ^ 2 -- ██║ ██║ ██║
lemma₂ = solve Int.ring -- ╚═╝ ██║ ██║
-- ██║ ██║
open import Relation.Binary.Reasoning.Inference setoid -- ██║ ██║
-- ██║ ██║
-- It can interact with manual proofs as well. -- ██║ ██║
lemma₃ : ∀ x y → x + y * 1 + 3 ≈ 2 + 1 + y + x -- ██║ ██║
lemma₃ x y = begin -- ██║ ██║
x + y * 1 + 3 ≈⟨ +-comm x (y * 1) ⟨ +-cong ⟩ refl ⟩ -- ██║ ██║
y * 1 + x + 3 ≈⟨ solveOver (x ∷ y ∷ []) Int.ring ⟩ -- ██║ ██║
3 + y + x ≡⟨⟩ -- ██║ ██║
2 + 1 + y + x ∎ -- ██║ ██║
-- ██║ ██║
open Int.Reflection -- ██║ ██║
-- ██║ ██║
-- There's a shorthand included for Int and Nat. -- ██║ ██║
lemma₄ : ∀ x y → x + y * 1 + 3 ≈ 2 + 1 + y + x -- ██║ ██║
lemma₄ x y = begin -- ██║ ██║
x + y * 1 + 3 ≈⟨ +-comm x (y * 1) ⟨ +-cong ⟩ refl ⟩ -- ██║ ██║
y * 1 + x + 3 ≈⟨ ∀⟨ x ∷ y ∷ [] ⟩ ⟩ -- ██║ ██║
3 + y + x ≡⟨⟩ -- ██║ ██║
2 + 1 + y + x ∎ -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- -- ██║ ██║
-- b. 8 -- ██║ ██║
-- 888o. 8 -- ██║ ██║
-- Y88888o. 8 -- ██║ ██║
-- .`Y888888o. 8 -- ██║ ██║
-- 8o. `Y888888o. 8 -- ██║ ██║
-- 8`Y8o. `Y88888o8 -- ██║ ██║
-- 8 `Y8o. `Y8888 -- ██║ ██║
-- 8 `Y8o. `Y8 -- ██║ ██║
-- 8 `Y8o.` -- ██║ ██║
-- 8 `Yo -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- -- ██║ ██║
module NatExamples where -- ██║ ██║
open AlmostCommutativeRing Nat.ring -- ██╗ ██║ ██║
-- The solver is flexible enough to work with Nats (even though it asks -- ████║ ██║ ██║
-- for rings!) -- ██████████║ ██║
lemma₁ : ∀ x y → x + y * 1 + 3 ≈ 2 + 1 + y + x -- ████╔═██║ ██║
lemma₁ = solve Nat.ring -- ██║ ██║ ██║
-- ╚═╝ ██║ ██║
lemma₂ : ∀ x y → x + y * 1 + 3 ≈ 2 + suc y + x -- ██║ ██║
lemma₂ = solve Nat.ring -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- -- ██║ ██║
-- ##### # # ####### ##### # # ### # # ##### -- ██║ ██║
-- # # # # # # # # # # ## # # # -- ██║ ██║
-- # # # # # # # # # # # # -- ██║ ██║
-- # ####### ##### # ### # # # # # #### -- ██║ ██║
-- # # # # # # # # # # # # # -- ██║ ██║
-- # # # # # # # # # # # ## # # -- ██║ ██║
-- ##### # # ####### ##### # # ### # # ##### -- ██║ ██║
-- -- ██║ ██║
-- ### # # # # # ###### ### # # # ####### ##### -- ██║ ██║
-- # ## # # # # # # # # # # ## # # # # -- ██║ ██║
-- # # # # # # # # # # # # # # # # # # -- ██║ ██║
-- # # # # # # # # ###### # # # # # # # ##### -- ██║ ██║
-- # # # # # # ####### # # # ####### # # # # # -- ██║ ██║
-- # # ## # # # # # # # # # # ## # # # -- ██║ ██║
-- ### # # # # # # # ### # # # # # ##### -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- The solver makes it easy to prove invariants, without having to rewrite -- ██║ ██║
-- proof code every time something changes in the data structure. -- ██║ ██║
-- -- ██║ ██║
module _ {a} {A : Set a} (_≤_ : A → A → Bool) where -- ██║ ██║
-- A Skew Heap, indexed by its size. -- ██║ ██║
data Tree : ℕ → Set a where -- ██║ ██║
leaf : Tree 0 -- ██║ ██║
node : ∀ {n m} → A → Tree n → Tree m → Tree (n + m + 1) -- ██║ ██║
-- ██║ ██║
-- A substitution operator, to clean things up. -- ██║ ██║
_⇒_ : ∀ {n} → Tree n → ∀ {m} → n ≈ m → Tree m -- ██║ ██║
x ⇒ n≈m = subst Tree n≈m x -- ██║ ██║
-- ██║ ██║
open Nat.Reflection -- ██║ ██║
-- ██║ ██║
-- _∪_ : ∀ {n m} → Tree n → Tree m → Tree (n + m) -- ██║ ██║
-- leaf ∪ ys = ys -- ██║ ██║
-- node {a} {b} x xl xr ∪ leaf = -- ██║ ██║
-- node x xl xr ⇒ ∀⟨ a ∷ b ∷ [] ⟩ -- ██╗ ██║ ██║
-- node {a} {b} x xl xr ∪ node {c} {d} y yl yr = if x ≤ y -- ████║ ██║ ██║
-- then node x (node y yl yr ∪ xr) xl -- ██████████║ ██║
-- ⇒ ∀⟨ a ∷ b ∷ c ∷ d ∷ [] ⟩ -- ████╔═██║ ██║
-- else (node y (node x xl xr ∪ yr) yl -- ██║ ██║ ██║
-- ⇒ ∀⟨ a ∷ b ∷ c ∷ d ∷ [] ⟩) -- ╚═╝ ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- -- ██║ ██║
-- 8888888 8888888888 8 8888 8 8 8888888888 -- ██║ ██║
-- 8 8888 8 8888 8 8 8888 -- ██║ ██║
-- 8 8888 8 8888 8 8 8888 -- ██║ ██║
-- 8 8888 8 8888 8 8 8888 -- ██║ ██║
-- 8 8888 8 8888 8 8 888888888888 -- ██║ ██║
-- 8 8888 8 8888 8 8 8888 -- ██║ ██║
-- 8 8888 8 8888888888888 8 8888 -- ██║ ██║
-- 8 8888 8 8888 8 8 8888 -- ██║ ██║
-- 8 8888 8 8888 8 8 8888 -- ██║ ██║
-- 8 8888 8 8888 8 8 888888888888 -- ██║ ██║
-- -- ██║ ██║
-- ,o888888o. 8 8888 8 888888888o. -- ██║ ██║
-- . 8888 `88. 8 8888 8 8888 `^888. -- ██║ ██║
-- ,8 8888 `8b 8 8888 8 8888 `88. -- ██║ ██║
-- 88 8888 `8b 8 8888 8 8888 `88 -- ██║ ██║
-- 88 8888 88 8 8888 8 8888 88 -- ██║ ██║
-- 88 8888 88 8 8888 8 8888 88 -- ██║ ██║
-- 88 8888 ,8P 8 8888 8 8888 ,88 -- ██║ ██║
-- `8 8888 ,8P 8 8888 8 8888 ,88' -- ██║ ██║
-- ` 8888 ,88' 8 8888 8 8888 ,o88P' -- ██║ ██║
-- `8888888P' 8 888888888888 8 888888888P' -- ██║ ██║
-- -- ██║ ██║
-- `8.`888b ,8' .8. `8.`8888. ,8' -- ██║ ██║
-- `8.`888b ,8' .888. `8.`8888. ,8' -- ██║ ██║
-- `8.`888b ,8' :88888. `8.`8888. ,8' -- ██║ ██║
-- `8.`888b .b ,8' . `88888. `8.`8888.,8' -- ██║ ██║
-- `8.`888b 88b ,8' .8. `88888. `8.`88888' -- ██║ ██║
-- `8.`888b .`888b,8' .8`8. `88888. `8. 8888 -- ██║ ██║
-- `8.`888b8.`8888' .8' `8. `88888. `8 8888 -- ██║ ██║
-- `8.`888`8.`88' .8' `8. `88888. 8 8888 -- ██║ ██║
-- `8.`8' `8,`' .888888888. `88888. 8 8888 -- ██║ ██║
-- `8.` `8' .8' `8. `88888. 8 8888 -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- Previously, you had to construct the expression you wanted to solve twice: -- ██║ ██║
-- once in the type signature, and again using the special solver syntax. -- ██║ ██║
-- -- ██║ ██║
-- This is difficult to learn, and error-prone: if I change an x + y -- ██║ ██║
-- somewhere to a y + x, I *also* have to change the proofs now! The -- ██║ ██║
-- reflection-based solver will automatically construct the new proof. -- ██║ ██║
-- -- ██║ ██║
module OldSolver where -- ██║ ██║
open import Data.Nat -- ██║ ██║
open import Data.Nat.Solver using (module +-*-Solver) -- ██║ ██║
open +-*-Solver -- ██║ ██║
-- ██╗ ██║ ██║
--lemma : ∀ x y → x + y * 1 + 3 ≡ 2 + 1 + y + x -- ████║ ██║ ██║
--lemma = +-*-Solver.solve 2 -- ██████████║ ██║
-- (λ x y → x :+ y :* con 1 :+ con 3 := con 2 :+ con 1 :+ y :+ x) ≡.refl -- ████╔═██║ ██║
-- -- ██║ ██║ ██║
-------------------------------------------------------------------------------- ╚═╝ ██║ ██║
-- -- ██║ ██║
-- d888888o. 8888888 8888888888 8 8888888888 8 888888888o -- ██║ ██║
-- .`8888:' `88. 8 8888 8 8888 8 8888 `88. -- ██║ ██║
-- 8.`8888. Y8 8 8888 8 8888 8 8888 `88 -- ██║ ██║
-- `8.`8888. 8 8888 8 8888 8 8888 ,88 -- ██║ ██║
-- `8.`8888. 8 8888 8 888888888888 8 8888. ,88' -- ██║ ██║
-- `8.`8888. 8 8888 8 8888 8 888888888P' -- ██║ ██║
-- `8.`8888. 8 8888 8 8888 8 8888 -- ██║ ██║
-- 8b `8.`8888. 8 8888 8 8888 8 8888 -- ██║ ██║
-- `8b. ;8.`8888 8 8888 8 8888 8 8888 -- ██║ ██║
-- `Y8888P ,88P' 8 8888 8 888888888888 8 8888 -- ██║ ██║
-- -- ██║ ██║
-- 8 888888888o `8.`8888. ,8' -- ██║ ██║
-- 8 8888 `88. `8.`8888. ,8' -- ██║ ██║
-- 8 8888 `88 `8.`8888. ,8' -- ██║ ██║
-- 8 8888 ,88 `8.`8888.,8' -- ██║ ██║
-- 8 8888. ,88' `8.`88888' -- ██║ ██║
-- 8 8888888888 `8. 8888 -- ██║ ██║
-- 8 8888 `88. `8 8888 -- ██║ ██║
-- 8 8888 88 8 8888 -- ██║ ██║
-- 8 8888 ,88' 8 8888 -- ██║ ██║
-- 8 888888888P 8 8888 -- ██║ ██║
-- -- ██║ ██║
-- d888888o. 8888888 8888888888 8 8888888888 8 888888888o -- ██║ ██║
-- .`8888:' `88. 8 8888 8 8888 8 8888 `88. -- ██║ ██║
-- 8.`8888. Y8 8 8888 8 8888 8 8888 `88 -- ██║ ██║
-- `8.`8888. 8 8888 8 8888 8 8888 ,88 -- ██║ ██║
-- `8.`8888. 8 8888 8 888888888888 8 8888. ,88' -- ██║ ██║
-- `8.`8888. 8 8888 8 8888 8 888888888P' -- ██║ ██║
-- `8.`8888. 8 8888 8 8888 8 8888 -- ██║ ██║
-- 8b `8.`8888. 8 8888 8 8888 8 8888 -- ██║ ██║
-- `8b. ;8.`8888 8 8888 8 8888 8 8888 -- ██║ ██║
-- `Y8888P ,88P' 8 8888 8 888888888888 8 8888 -- ██║ ██║
-- -- ██║ ██║
-------------------------------------------------------------------------------- ██║ ██║
-- Don't understand why something works? Wanna get it explained to you? Now -- ██║ ██║
-- you can! The solver can generate step-by-step, human-readable solutions -- ██║ ██║
-- for learning purposes. -- ██║ ██║
-- -- ██║ ██║
module TracedExamples where -- ██║ ██║
import Data.Nat.Show -- ██║ ██║
open import EqBool -- ██║ ██║
open import Relation.Traced Nat.ring Data.Nat.Show.show public -- ██║ ██║
open AlmostCommutativeRing tracedRing -- ██║ ██║
-- ██║ ██║
lemma : ∀ x y → x + y * 1 + 3 ≈ 2 + 1 + y + x -- ██║ ██║
lemma = solve tracedRing -- ██║ ██║
-- ██╗██║ ██║
explained -- ████║██║ ██║
: showProof (lemma "x" "y") ≡ "x + y + 3" -- █████████║ ██║
∷ " ={ +-comm(x, y + 3) }" -- ████╔══╝ ██║
∷ "y + 3 + x" -- ██║ ██║
∷ " ={ +-comm(y, 3) }" -- ╚═╝ ██║
∷ "3 + y + x" -- ██║
∷ [] -- ██║
explained = ≡.refl -- ██║
-------------------------------------------------------------------------------- ██║
-- -- ██║
-- The new solver uses a sparse representation, which is much faster than the -- ██║
-- dense one the old solver used. The following graph shows the time (in -- ██║
-- seconds) to prove that: -- ██║
-- -- ██║
-- (1 + x₁¹ + x₂² + x₃³ + x₄⁴ + x₅⁵)ᵈ -- ██║
-- -- ██║
-- is equal to its expanded form. (to run the benchmarks yourself, run the -- ██║
-- run_benchmarks.py file. You'll need python 3 and sympy.) -- ██║
-- -- ██║
-- 540 | * = old * -- ██║
-- 525 | + = new * -- ██║
-- 510 | * -- ██║
-- 495 | * -- ██║
-- 480 | * -- ██║
-- 465 | * -- ██║
-- 450 | * -- ██║
-- 435 | * -- ██║
-- 420 | * -- ██║
-- 405 | * -- ██║
-- 390 | * -- ██║
-- 375 | * -- ██║
-- 360 | * -- ██║
-- 345 | * -- ██║
-- 330 | * -- ██║
-- 315 | * -- ██║
-- 300 | * -- ██║
-- 285 | * -- ██║
-- 270 | * -- ██║
-- 255 | * -- ██║
-- 240 | * -- ██╗██║
-- 225 | * -- ████║██║
-- 210 | * -- █████████║
-- 195 | * -- ████╔══╝
-- 180 | * -- ██║
-- 165 | * -- ╚═╝
-- 150 | * --
-- 135 | * --
-- 120 | * --
-- 105 | * --
-- 90 | * --
-- 75 | * --
-- 60 | ** --
-- 45 | ** --
-- 30 | ** +++++ --
-- 15 | ***** +++++++++ --
-- 0 | *****************************************+++++++++ --
-- ------------------------------------------------------------------ --
-- d = 1 2 3 4 5 6 7 8 --
--------------------------------------------------------------------------------
--
-- * How does it work? Why is it fast?
-- The solver works by converting expressions to "Horner Normal Form".
-- This representation is special: x + y is represented in the same way
-- as y + x. This is what lets us check that two expressions are equal.
-- The implementation here is *sparse*, also, which is why it's faster
-- than the old implementation.
--
-- Want to learn more? Then this is the place for you:
import Polynomial.NormalForm
--
-- * Prove it!
-- The type of proofs we need are *homomorphisms*. They basically mean
-- that the operations on the normal form correspond to the operations
-- on expressions. Also, we don't use propositional equality: we use
-- any equivalence relation the user supplies.
--
-- Don't believe me? Check it out:
import Polynomial.Homomorphism
--
-- * How do I use it?
-- Copy the examples above! For the full solver, check out:
import Polynomial.Solver
--
-- * Wait! Don't!
-- The "full" solver lets you use different types for the coefficient
-- and carrier. You probably don't want that, unless you need the extra
-- efficiency. You'll want the *simple* solver:
import Polynomial.Simple.Solver
--
-- * Is that all?
-- No! As it happens, even the simple solver is complicated to use.
-- You'll *actually* want to use the reflection-based interface:
import Polynomial.Simple.Reflection
--
-- * And what about the step-by-step stuff?
-- That all uses the same underlying solver as the other stuff, with a
-- special *relation*. You can check that out here:
import Relation.Traced
| {
"alphanum_fraction": 0.1875727945,
"avg_line_length": 87.2789598109,
"ext": "agda",
"hexsha": "a518cac9ce211adcbadedbc6a948991dccd2d775",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z",
"max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/agda-ring-solver",
"max_forks_repo_path": "src/README.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/agda-ring-solver",
"max_issues_repo_path": "src/README.agda",
"max_line_length": 105,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/agda-ring-solver",
"max_stars_repo_path": "src/README.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z",
"num_tokens": 8759,
"size": 36919
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by posets
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.Properties.Poset
{p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where
open Relation.Binary.Poset P hiding (trans)
import Relation.Binary.NonStrictToStrict as Conv
open Conv _≈_ _≤_
------------------------------------------------------------------------
-- Posets can be turned into strict partial orders
strictPartialOrder : StrictPartialOrder _ _ _
strictPartialOrder = record
{ isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = irrefl
; trans = trans isPartialOrder
; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
}
}
open StrictPartialOrder strictPartialOrder
| {
"alphanum_fraction": 0.5353535354,
"avg_line_length": 29.7,
"ext": "agda",
"hexsha": "1171bc539e3ebab02b7887326f81660393085963",
"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": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/Poset.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"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": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/Poset.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/Properties/Poset.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 191,
"size": 891
} |
postulate
f : {A B : Set₁} (C : Set) → A → B → C
module _ (A B C : Set) where
test : (X : Set) → Set → Set → X
test = f { A₁ = Set } { B₁ = Set }
| {
"alphanum_fraction": 0.461038961,
"avg_line_length": 19.25,
"ext": "agda",
"hexsha": "826532a598501e7bc01073b6bbe025bcdaa950a6",
"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/Issue952.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/Issue952.agda",
"max_line_length": 40,
"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/Issue952.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": 68,
"size": 154
} |
--
-- Created by Dependently-Typed Lambda Calculus on 2020-09-23
-- Commerce
-- Author: dplaindoux
--
{-# OPTIONS --without-K --safe #-}
module Commerce where
open import Relation.Nullary using (Reflects; Dec; yes; no)
open import Data.Bool using (Bool; true; false)
open import Data.Nat using (ℕ; _+_; _≥?_; _≥_)
open import Agda.Builtin.Nat using (_-_)
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎; step-≡)
module Customer where
record Account : Set where
field
balance : ℕ
account : ℕ -> Account
account n = record { balance = n }
_↑_ : Account → ℕ → Account
c ↑ n = account (Account.balance c + n)
_↓_ : Account → ℕ → Account
c ↓ n = account (Account.balance c - n )
infixl 50 _↑_
infixl 50 _↓_
module Product where
record Item : Set where
field
price : ℕ
data Basket : Set where
∅ : Basket
_then_ : Item → Basket → Basket
total : Basket → ℕ
total ∅ = 0
total (a then b) = Item.price a + total b
module Payment where
open Customer
open Product
pay : (c : Account) → (p : Basket) → {Account.balance c ≥ total p} → Account
pay c p = c ↓ total p
module Front where
pay? : Account → Basket → Account
pay? c p with Account.balance c ≥? total p
... | yes proof = pay c p {proof}
... | no _ = c | {
"alphanum_fraction": 0.5974025974,
"avg_line_length": 23.9836065574,
"ext": "agda",
"hexsha": "41d0d317e6790ad8101fb3da9aebf84f650d0670",
"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": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "d-plaindoux/colca",
"max_forks_repo_path": "src/exercices/Commerce.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"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": "d-plaindoux/colca",
"max_issues_repo_path": "src/exercices/Commerce.agda",
"max_line_length": 80,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "a81447af3ab2ba898bb7d57be71369abbba12d81",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "d-plaindoux/colca",
"max_stars_repo_path": "src/exercices/Commerce.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-04T09:35:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-03-12T18:31:14.000Z",
"num_tokens": 427,
"size": 1463
} |
{-
This second-order signature was created from the following second-order syntax description:
syntax PropLog | PR
type
* : 0-ary
term
false : * | ⊥
or : * * -> * | _∨_ l20
true : * | ⊤
and : * * -> * | _∧_ l30
not : * -> * | ¬_ r50
theory
(⊥U∨ᴸ) a |> or (false, a) = a
(⊥U∨ᴿ) a |> or (a, false) = a
(∨A) a b c |> or (or(a, b), c) = or (a, or(b, c))
(∨C) a b |> or(a, b) = or(b, a)
(⊤U∧ᴸ) a |> and (true, a) = a
(⊤U∧ᴿ) a |> and (a, true) = a
(∧A) a b c |> and (and(a, b), c) = and (a, and(b, c))
(∧D∨ᴸ) a b c |> and (a, or (b, c)) = or (and(a, b), and(a, c))
(∧D∨ᴿ) a b c |> and (or (a, b), c) = or (and(a, c), and(b, c))
(⊥X∧ᴸ) a |> and (false, a) = false
(⊥X∧ᴿ) a |> and (a, false) = false
(¬N∨ᴸ) a |> or (not (a), a) = false
(¬N∨ᴿ) a |> or (a, not (a)) = false
(∧C) a b |> and(a, b) = and(b, a)
(∨I) a |> or(a, a) = a
(∧I) a |> and(a, a) = a
(¬²) a |> not(not (a)) = a
(∨D∧ᴸ) a b c |> or (a, and (b, c)) = and (or(a, b), or(a, c))
(∨D∧ᴿ) a b c |> or (and (a, b), c) = and (or(a, c), or(b, c))
(∨B∧ᴸ) a b |> or (and (a, b), a) = a
(∨B∧ᴿ) a b |> or (a, and (a, b)) = a
(∧B∨ᴸ) a b |> and (or (a, b), a) = a
(∧B∨ᴿ) a b |> and (a, or (a, b)) = a
(⊤X∨ᴸ) a |> or (true, a) = true
(⊤X∨ᴿ) a |> or (a, true) = true
(¬N∧ᴸ) a |> and (not (a), a) = false
(¬N∧ᴿ) a |> and (a, not (a)) = false
(DM∧) a b |> not (and (a, b)) = or (not(a), not(b))
(DM∨) a b |> not (or (a, b)) = and (not(a), not(b))
-}
module PropLog.Signature where
open import SOAS.Context
open import SOAS.Common
open import SOAS.Syntax.Signature *T public
open import SOAS.Syntax.Build *T public
-- Operator symbols
data PRₒ : Set where
falseₒ orₒ trueₒ andₒ notₒ : PRₒ
-- Term signature
PR:Sig : Signature PRₒ
PR:Sig = sig λ
{ falseₒ → ⟼₀ *
; orₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
; trueₒ → ⟼₀ *
; andₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
; notₒ → (⊢₀ *) ⟼₁ *
}
open Signature PR:Sig public
| {
"alphanum_fraction": 0.4507401736,
"avg_line_length": 26.8356164384,
"ext": "agda",
"hexsha": "d2cfd0354e787a9c95846a6b08b2d0681c2d82b9",
"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": "out/PropLog/Signature.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": "out/PropLog/Signature.agda",
"max_line_length": 91,
"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": "out/PropLog/Signature.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": 1023,
"size": 1959
} |
------------------------------------------------------------------------------
-- The gcd program is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the gcd program using
-- the Euclid's algorithm.
-- N.B This module does not contain combined proofs, but it imports
-- modules which contain combined proofs.
module FOTC.Program.GCD.Partial.CorrectnessProofATP where
open import FOTC.Base
open import FOTC.Data.Nat.Divisibility.NotBy0.PropertiesATP using ( 0∤x ; x∣S→x≤S )
open import FOTC.Data.Nat.Type
open import FOTC.Program.GCD.Partial.CommonDivisorATP using ( gcdCD )
open import FOTC.Program.GCD.Partial.Definitions using ( x≢0≢y ; gcdSpec )
open import FOTC.Program.GCD.Partial.DivisibleATP using ( gcdDivisible )
open import FOTC.Program.GCD.Partial.GCD using ( gcd )
import FOTC.Program.GCD.Partial.GreatestAnyCommonDivisor
open module GreatestAnyCommonDivisorATP =
FOTC.Program.GCD.Partial.GreatestAnyCommonDivisor x∣S→x≤S 0∤x
using ( gcdGACD )
open import FOTC.Program.GCD.Partial.TotalityATP using ( gcd-N )
------------------------------------------------------------------------------
-- The gcd is correct.
postulate gcdCorrect : ∀ {m n} → N m → N n → x≢0≢y m n → gcdSpec m n (gcd m n)
{-# ATP prove gcdCorrect gcdCD gcdGACD gcd-N gcdDivisible #-}
| {
"alphanum_fraction": 0.6129666012,
"avg_line_length": 41.2702702703,
"ext": "agda",
"hexsha": "110bec4a351baac0a38d018e55018f1824f5e6f1",
"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/FOTC/Program/GCD/Partial/CorrectnessProofATP.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/FOTC/Program/GCD/Partial/CorrectnessProofATP.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": "src/fot/FOTC/Program/GCD/Partial/CorrectnessProofATP.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": 379,
"size": 1527
} |
open import Agda.Primitive.Cubical
record Bad : IUniv where
| {
"alphanum_fraction": 0.8032786885,
"avg_line_length": 15.25,
"ext": "agda",
"hexsha": "7b5189a3e14bd6396848dfab9008e14350daba21",
"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/IUnivRecord.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/IUnivRecord.agda",
"max_line_length": 34,
"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/IUnivRecord.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": 18,
"size": 61
} |
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Homomorphism.Equivalence (Σ : Signature) where
open import Fragment.Algebra.Algebra Σ
open import Fragment.Algebra.Homomorphism.Base Σ
open import Fragment.Algebra.Homomorphism.Properties Σ
open import Fragment.Algebra.Homomorphism.Setoid Σ
open import Level using (Level; _⊔_)
open import Relation.Binary using (Setoid; IsEquivalence)
import Relation.Binary.Reasoning.Setoid as Reasoning
private
variable
a b c ℓ₁ ℓ₂ ℓ₃ : Level
A : Algebra {a} {ℓ₁}
B : Algebra {b} {ℓ₂}
C : Algebra {c} {ℓ₃}
module _
(A : Algebra {a} {ℓ₁})
(B : Algebra {b} {ℓ₂})
where
infix 3 _≃_
record _≃_ : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
_⃗ : A ⟿ B
_⃖ : B ⟿ A
invˡ : _⃗ ⊙ _⃖ ≗ id
invʳ : _⃖ ⊙ _⃗ ≗ id
open _≃_ public
private
≃-refl : A ≃ A
≃-refl {A = A} = record { _⃗ = id
; _⃖ = id
; invˡ = λ {_} → refl
; invʳ = λ {_} → refl
}
where open Setoid ∥ A ∥/≈
≃-sym : A ≃ B → B ≃ A
≃-sym f = record { _⃗ = f ⃖
; _⃖ = f ⃗
; invˡ = invʳ f
; invʳ = invˡ f
}
≃-inv : ∀ (g : B ≃ C) (f : A ≃ B)
→ (g ⃗ ⊙ f ⃗) ⊙ (f ⃖ ⊙ g ⃖) ≗ id
≃-inv {B = B} {C = C} g f = begin
(g ⃗ ⊙ f ⃗) ⊙ (f ⃖ ⊙ g ⃖)
≈⟨ ⊙-assoc (g ⃗) (f ⃗) (f ⃖ ⊙ g ⃖) ⟩
g ⃗ ⊙ (f ⃗ ⊙ (f ⃖ ⊙ g ⃖))
≈⟨ ⊙-congˡ (g ⃗) (f ⃗ ⊙ (f ⃖ ⊙ g ⃖)) ((f ⃗ ⊙ f ⃖) ⊙ g ⃖) (⊙-assoc (f ⃗) (f ⃖) (g ⃖)) ⟩
g ⃗ ⊙ ((f ⃗ ⊙ f ⃖) ⊙ g ⃖)
≈⟨ ⊙-congˡ (g ⃗) ((f ⃗ ⊙ f ⃖) ⊙ g ⃖) (id ⊙ g ⃖) (⊙-congʳ (g ⃖) (f ⃗ ⊙ f ⃖) id (invˡ f)) ⟩
g ⃗ ⊙ (id ⊙ g ⃖)
≈⟨ ⊙-congˡ (g ⃗) (id ⊙ g ⃖) (g ⃖) (id-unitˡ {f = g ⃖}) ⟩
g ⃗ ⊙ g ⃖
≈⟨ invˡ g ⟩
id
∎
where open Reasoning (C ⟿ C /≗)
≃-trans : A ≃ B → B ≃ C → A ≃ C
≃-trans f g = record { _⃗ = g ⃗ ⊙ f ⃗
; _⃖ = f ⃖ ⊙ g ⃖
; invˡ = ≃-inv g f
; invʳ = ≃-inv (≃-sym f) (≃-sym g)
}
≃-isEquivalence : IsEquivalence (_≃_ {a} {ℓ₁} {a} {ℓ₁})
≃-isEquivalence =
record { refl = ≃-refl
; sym = ≃-sym
; trans = ≃-trans
}
≃-setoid : ∀ {a ℓ} → Setoid _ _
≃-setoid {a} {ℓ} = record { Carrier = Algebra {a} {ℓ}
; _≈_ = _≃_ {a} {ℓ} {a} {ℓ}
; isEquivalence = ≃-isEquivalence
}
| {
"alphanum_fraction": 0.4042718447,
"avg_line_length": 27.688172043,
"ext": "agda",
"hexsha": "f2f82c5a83d3697f08cc5bc1f002d28ea90a7f3a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Algebra/Homomorphism/Equivalence.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Algebra/Homomorphism/Equivalence.agda",
"max_line_length": 93,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Algebra/Homomorphism/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 1206,
"size": 2575
} |
module Cat where
open import Agda.Primitive
open import CS410-Prelude
open import CS410-Nat
open import CS410-Monoid
open import CS410-Vec
record Cat {k}{l}(O : Set k)(_>>_ : O -> O -> Set l) : Set (lsuc (k ⊔ l)) where
field
-- OPERATIONS ---------------------------------------------------------
iden : {X : O} -> X >> X
comp : {R S T : O} -> S >> T -> R >> S -> R >> T
-- KLUDGE -------------------------------------------------------------
Eq : {S T : O} -> S >> T -> S >> T -> Set l
-- LAWS ---------------------------------------------------------------
idenL : {S T : O}(f : S >> T) -> Eq (comp iden f) f
idenR : {S T : O}(f : S >> T) -> Eq (comp f iden) f
assoc : {Q R S T : O}(f : S >> T)(g : R >> S)(h : Q >> R) ->
Eq (comp f (comp g h)) (comp (comp f g) h)
SetCat : Cat Set (\ S T -> S -> T)
SetCat = record
{ iden = id
; comp = _o_
; Eq = \ f g -> forall x -> f x == g x
; idenL = λ {S} {T} f x → refl
; idenR = λ {S} {T} f x → refl
; assoc = λ {Q} {R} {S} {T} f g h x → refl
}
N>=Cat : Cat Nat _N>=_
N>=Cat = record
{ iden = \ {n} -> N>=refl n
; comp = \ {l}{m}{n} -> N>=trans l m n
; Eq = \ _ _ -> One
; idenL = λ {S} {T} f → <>
; idenR = λ {S} {T} f → <>
; assoc = λ {Q} {R} {S} {T} f g h → <>
} where
N>=refl : (n : Nat) -> n N>= n
N>=refl zero = <>
N>=refl (suc n) = N>=refl n
N>=trans : forall l m n -> m N>= n -> l N>= m -> l N>= n
N>=trans l m zero mn lm = <>
N>=trans l zero (suc n) () lm
N>=trans zero (suc m) (suc n) mn ()
N>=trans (suc l) (suc m) (suc n) mn lm = N>=trans l m n mn lm
MonCat : forall {X} -> Monoid X -> Cat One \ _ _ -> X
MonCat M = record
{ iden = e
; comp = op
; Eq = _==_
; idenL = lunit
; idenR = runit
; assoc = assoc
} where open Monoid M
record Functor {k l}{ObjS : Set k}{_>S>_ : ObjS -> ObjS -> Set l}
{m n}{ObjT : Set m}{_>T>_ : ObjT -> ObjT -> Set n}
(CS : Cat ObjS _>S>_)(CT : Cat ObjT _>T>_)
: Set (lsuc (k ⊔ l ⊔ m ⊔ n)) where
open Cat
field
-- OPERATIONS ---------------------------------------------------------
Map : ObjS -> ObjT
map : {A B : ObjS} -> A >S> B -> Map A >T> Map B
-- LAWS ---------------------------------------------------------------
mapId : {A : ObjS} -> Eq CT (map (iden CS {A})) (iden CT {Map A})
mapComp : {A B C : ObjS}(f : B >S> C)(g : A >S> B) ->
Eq CT (map (comp CS f g)) (comp CT (map f) (map g))
mapEq : {A B : ObjS}{f g : A >S> B} ->
Eq CS f g -> Eq CT (map f) (map g)
data List (X : Set) : Set where -- X scopes over the whole declaration...
[] : List X -- ...so you can use it here...
_::_ : X -> List X -> List X -- ...and here.
infixr 3 _::_
listMap : {A B : Set} → (A → B) → List A → List B
listMap f [] = []
listMap f (a :: as) = f a :: listMap f as
list : Functor SetCat SetCat
list = record
{ Map = List
; map = listMap
; mapId = {!!}
; mapComp = {!!}
; mapEq = {!!}
}
{-
goo : Functor (MonCat +Mon) SetCat
goo = ?
-}
hoo : (X : Set) -> Functor N>=Cat SetCat
hoo X = record
{ Map = Vec X
; map = {!!}
; mapId = {!!}
; mapComp = {!!}
; mapEq = {!!}
}
| {
"alphanum_fraction": 0.3812908729,
"avg_line_length": 31.9727272727,
"ext": "agda",
"hexsha": "03aeee38b261b17dceda848f7fc71b4e08132a7a",
"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": "Cat.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": "Cat.agda",
"max_line_length": 79,
"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": "Cat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1205,
"size": 3517
} |
module Relation.Equality where
open import Data.Product
-- Identity Types
--
{-
The type of identifications of two (x y : A).
While this can be read as propositional equality, in HoTT identity
can be (and is) elevated to a data type.
-}
data _≡_ {a}{A : Set a}(x : A) : A → Set a where
refl : x ≡ x
cong : ∀ {a b} {A : Set a}{B : Set b} (f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
-- Path Induction over the Identity Type
--
ind₌ : ∀ {a c}{A : Set a} → (C : (x y : A) → (x ≡ y) → Set c) → ((x : A) → C x x refl) → (x y : A) → (p : x ≡ y) → C x y p
ind₌ C c x .x refl = c x
| {
"alphanum_fraction": 0.5516666667,
"avg_line_length": 25,
"ext": "agda",
"hexsha": "3e38bf261ad705c3c6bbe22fc04af86708bdced7",
"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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Relation/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"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": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Relation/Equality.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Relation/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 237,
"size": 600
} |
{-
Basic theory about h-levels/n-types:
- Basic properties of isContr, isProp and isSet (definitions are in Prelude)
- Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.HLevels where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence using (ua ; univalence)
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-zero; +-comm)
HLevel : Type₀
HLevel = ℕ
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
A : Type ℓ
B : A → Type ℓ
C : (x : A) → B x → Type ℓ
D : (x : A) (y : B x) → C x y → Type ℓ
E : (x : A) (y : B x) → (z : C x y) → D x y z → Type ℓ
w x y z : A
n : HLevel
isOfHLevel : HLevel → Type ℓ → Type ℓ
isOfHLevel 0 A = isContr A
isOfHLevel 1 A = isProp A
isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y)
isOfHLevelFun : (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isOfHLevelFun n f = ∀ b → isOfHLevel n (fiber f b)
TypeOfHLevel : ∀ ℓ → HLevel → Type (ℓ-suc ℓ)
TypeOfHLevel ℓ n = TypeWithStr ℓ (isOfHLevel n)
hProp hSet hGroupoid h2Groupoid : ∀ ℓ → Type (ℓ-suc ℓ)
hProp ℓ = TypeOfHLevel ℓ 1
hSet ℓ = TypeOfHLevel ℓ 2
hGroupoid ℓ = TypeOfHLevel ℓ 3
h2Groupoid ℓ = TypeOfHLevel ℓ 4
-- lower h-levels imply higher h-levels
isOfHLevelSuc : (n : HLevel) → isOfHLevel n A → isOfHLevel (suc n) A
isOfHLevelSuc 0 = isContr→isProp
isOfHLevelSuc 1 = isProp→isSet
isOfHLevelSuc (suc (suc n)) h a b = isOfHLevelSuc (suc n) (h a b)
isSet→isGroupoid : isSet A → isGroupoid A
isSet→isGroupoid = isOfHLevelSuc 2
isGroupoid→is2Groupoid : isGroupoid A → is2Groupoid A
isGroupoid→is2Groupoid = isOfHLevelSuc 3
isOfHLevelPlus : (m : HLevel) → isOfHLevel n A → isOfHLevel (m + n) A
isOfHLevelPlus zero hA = hA
isOfHLevelPlus (suc m) hA = isOfHLevelSuc _ (isOfHLevelPlus m hA)
isOfHLevelPlus' : (m : HLevel) → isOfHLevel m A → isOfHLevel (m + n) A
isOfHLevelPlus' {A = A} {n = n} m hA = subst (λ m → isOfHLevel m A) (+-comm n m) (isOfHLevelPlus n hA )
isContr→isOfHLevel : (n : HLevel) → isContr A → isOfHLevel n A
isContr→isOfHLevel {A = A} n cA = isOfHLevelPlus' 0 cA
isProp→isOfHLevelSuc : (n : HLevel) → isProp A → isOfHLevel (suc n) A
isProp→isOfHLevelSuc {A = A} n pA = isOfHLevelPlus' 1 pA
-- hlevel of path and dependent path types
isProp→isContrPath : isProp A → (x y : A) → isContr (x ≡ y)
isProp→isContrPath h x y = h x y , isProp→isSet h x y _
isContr→isContrPath : isContr A → (x y : A) → isContr (x ≡ y)
isContr→isContrPath cA = isProp→isContrPath (isContr→isProp cA)
isOfHLevelPath' : (n : HLevel) → isOfHLevel (suc n) A → (x y : A) → isOfHLevel n (x ≡ y)
isOfHLevelPath' 0 = isProp→isContrPath
isOfHLevelPath' (suc n) h x y = h x y
isOfHLevelPath'⁻ : (n : HLevel) → ((x y : A) → isOfHLevel n (x ≡ y)) → isOfHLevel (suc n) A
isOfHLevelPath'⁻ zero h x y = h x y .fst
isOfHLevelPath'⁻ (suc n) h = h
isOfHLevelPath : (n : HLevel) → isOfHLevel n A → (x y : A) → isOfHLevel n (x ≡ y)
isOfHLevelPath 0 h x y = isContr→isContrPath h x y
isOfHLevelPath (suc n) h x y = isOfHLevelSuc n (isOfHLevelPath' n h x y)
isOfHLevelPathP' : {A : I → Type ℓ} (n : HLevel)
→ isOfHLevel (suc n) (A i1)
→ (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y)
isOfHLevelPathP' {A = A} n h x y = transport⁻ (λ i → isOfHLevel n (PathP≡Path A x y i))
(isOfHLevelPath' n h _ _)
isOfHLevelPathP : {A : I → Type ℓ} (n : HLevel)
→ isOfHLevel n (A i1)
→ (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y)
isOfHLevelPathP {A = A} n h x y = transport⁻ (λ i → isOfHLevel n (PathP≡Path A x y i))
(isOfHLevelPath n h _ _)
-- h-level of isOfHLevel
isPropIsOfHLevel : (n : HLevel) → isProp (isOfHLevel n A)
isPropIsOfHLevel 0 = isPropIsContr
isPropIsOfHLevel 1 = isPropIsProp
isPropIsOfHLevel (suc (suc n)) f g i a b =
isPropIsOfHLevel (suc n) (f a b) (g a b) i
isPropIsSet : isProp (isSet A)
isPropIsSet = isPropIsOfHLevel 2
isPropIsGroupoid : isProp (isGroupoid A)
isPropIsGroupoid = isPropIsOfHLevel 3
isPropIs2Groupoid : isProp (is2Groupoid A)
isPropIs2Groupoid = isPropIsOfHLevel 4
TypeOfHLevel≡ : (n : HLevel) {X Y : TypeOfHLevel ℓ n} → ⟨ X ⟩ ≡ ⟨ Y ⟩ → X ≡ Y
TypeOfHLevel≡ n = Σ≡Prop (λ _ → isPropIsOfHLevel n)
-- Fillers for cubes from h-level
isSet→isSet' : isSet A → isSet' A
isSet→isSet' {A = A} Aset a₀₋ a₁₋ a₋₀ a₋₁ =
transport⁻ (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋) (Aset _ _ _ _)
isSet'→isSet : isSet' A → isSet A
isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl
isSet→SquareP :
{A : I → I → Type ℓ}
(isSet : (i j : I) → isSet (A i j))
{a₀₀ : A i0 i0} {a₀₁ : A i0 i1} (a₀₋ : PathP (λ j → A i0 j) a₀₀ a₀₁)
{a₁₀ : A i1 i0} {a₁₁ : A i1 i1} (a₁₋ : PathP (λ j → A i1 j) a₁₀ a₁₁)
(a₋₀ : PathP (λ i → A i i0) a₀₀ a₁₀) (a₋₁ : PathP (λ i → A i i1) a₀₁ a₁₁)
→ SquareP A a₀₋ a₁₋ a₋₀ a₋₁
isSet→SquareP isset a₀₋ a₁₋ a₋₀ a₋₁ =
transport (sym (PathP≡Path _ _ _))
(isOfHLevelPathP' 1 (isset _ _) _ _ _ _ )
isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A
isGroupoid→isGroupoid' {A = A} Agpd a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
transport⁻ (PathP≡Path (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋)
(isGroupoid→isPropSquare _ _ _ _ _ _)
where
isGroupoid→isPropSquare :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ isProp (Square a₀₋ a₁₋ a₋₀ a₋₁)
isGroupoid→isPropSquare a₀₋ a₁₋ a₋₀ a₋₁ =
transport⁻
(cong isProp (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋))
(Agpd _ _ _ _)
isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A
isGroupoid'→isGroupoid Agpd' x y p q r s = Agpd' r s refl refl refl refl
-- hlevels are preserved by retracts (and consequently equivalences)
isContrRetract
: ∀ {B : Type ℓ}
→ (f : A → B) (g : B → A)
→ (h : retract f g)
→ (v : isContr B) → isContr A
fst (isContrRetract f g h (b , p)) = g b
snd (isContrRetract f g h (b , p)) x = (cong g (p (f x))) ∙ (h x)
isPropRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isProp B → isProp A
isPropRetract f g h p x y i =
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (p (f x) (f y) i))
isSetRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isSet B → isSet A
isSetRetract f g h set x y p q i j =
hcomp (λ k → λ { (i = i0) → h (p j) k
; (i = i1) → h (q j) k
; (j = i0) → h x k
; (j = i1) → h y k})
(g (set (f x) (f y)
(cong f p) (cong f q) i j))
isGroupoidRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isGroupoid B → isGroupoid A
isGroupoidRetract f g h grp x y p q P Q i j k =
hcomp ((λ l → λ { (i = i0) → h (P j k) l
; (i = i1) → h (Q j k) l
; (j = i0) → h (p k) l
; (j = i1) → h (q k) l
; (k = i0) → h x l
; (k = i1) → h y l}))
(g (grp (f x) (f y) (cong f p) (cong f q)
(cong (cong f) P) (cong (cong f) Q) i j k))
is2GroupoidRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ is2Groupoid B → is2Groupoid A
is2GroupoidRetract f g h grp x y p q P Q R S i j k l =
hcomp (λ r → λ { (i = i0) → h (R j k l) r
; (i = i1) → h (S j k l) r
; (j = i0) → h (P k l) r
; (j = i1) → h (Q k l) r
; (k = i0) → h (p l) r
; (k = i1) → h (q l) r
; (l = i0) → h x r
; (l = i1) → h y r})
(g (grp (f x) (f y) (cong f p) (cong f q)
(cong (cong f) P) (cong (cong f) Q)
(cong (cong (cong f)) R) (cong (cong (cong f)) S) i j k l))
isOfHLevelRetract
: (n : HLevel) {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isOfHLevel n B → isOfHLevel n A
isOfHLevelRetract 0 = isContrRetract
isOfHLevelRetract 1 = isPropRetract
isOfHLevelRetract 2 = isSetRetract
isOfHLevelRetract 3 = isGroupoidRetract
isOfHLevelRetract 4 = is2GroupoidRetract
isOfHLevelRetract (suc (suc (suc (suc (suc n))))) f g h ofLevel x y p q P Q R S =
isOfHLevelRetract (suc n) (cong (cong (cong (cong f))))
(λ s i j k l →
hcomp (λ r → λ { (i = i0) → h (R j k l) r
; (i = i1) → h (S j k l) r
; (j = i0) → h (P k l) r
; (j = i1) → h (Q k l) r
; (k = i0) → h (p l) r
; (k = i1) → h (q l) r
; (l = i0) → h x r
; (l = i1) → h y r})
(g (s i j k l)))
(λ s i j k l m →
hcomp (λ n → λ { (i = i1) → s j k l m
; (j = i0) → h (R k l m) (i ∨ n)
; (j = i1) → h (S k l m) (i ∨ n)
; (k = i0) → h (P l m) (i ∨ n)
; (k = i1) → h (Q l m) (i ∨ n)
; (l = i0) → h (p m) (i ∨ n)
; (l = i1) → h (q m) (i ∨ n)
; (m = i0) → h x (i ∨ n)
; (m = i1) → h y (i ∨ n) })
(h (s j k l m) i))
(ofLevel (f x) (f y)
(cong f p) (cong f q)
(cong (cong f) P) (cong (cong f) Q)
(cong (cong (cong f)) R) (cong (cong (cong f)) S))
isOfHLevelRetractFromIso : {A : Type ℓ} {B : Type ℓ'} (n : HLevel) → Iso A B → isOfHLevel n B → isOfHLevel n A
isOfHLevelRetractFromIso n e hlev = isOfHLevelRetract n (Iso.fun e) (Iso.inv e) (Iso.leftInv e) hlev
isOfHLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : HLevel) → A ≃ B → isOfHLevel n A → isOfHLevel n B
isOfHLevelRespectEquiv n eq = isOfHLevelRetract n (invEq eq) (eq .fst) (retEq eq)
isContrRetractOfConstFun : {A : Type ℓ} {B : Type ℓ'} (b₀ : B)
→ Σ[ f ∈ (B → A) ] ((x : A) → (f ∘ (λ _ → b₀)) x ≡ x)
→ isContr A
fst (isContrRetractOfConstFun b₀ ret) = ret .fst b₀
snd (isContrRetractOfConstFun b₀ ret) y = ret .snd y
-- h-level of Σ-types
isContrΣ : isContr A → ((x : A) → isContr (B x)) → isContr (Σ A B)
isContrΣ {A = A} {B = B} (a , p) q =
let h : (x : A) (y : B x) → (q x) .fst ≡ y
h x y = (q x) .snd y
in (( a , q a .fst)
, ( λ x i → p (x .fst) i
, h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i))
isContrΣ′ : (ca : isContr A) → isContr (B (fst ca)) → isContr (Σ A B)
isContrΣ′ ca cb = isContrΣ ca (λ x → subst _ (snd ca x) cb)
section-Σ≡Prop
: (pB : (x : A) → isProp (B x)) {u v : Σ A B}
→ section (Σ≡Prop pB {u} {v}) (cong fst)
section-Σ≡Prop {A = A} pB {u} {v} p j i =
(p i .fst) , isProp→PathP (λ i → isOfHLevelPath 1 (pB (fst (p i)))
(Σ≡Prop pB {u} {v} (cong fst p) i .snd)
(p i .snd) )
refl refl i j
isEquiv-Σ≡Prop
: (pB : (x : A) → isProp (B x)) {u v : Σ A B}
→ isEquiv (Σ≡Prop pB {u} {v})
isEquiv-Σ≡Prop {A = A} pB {u} {v} = isoToIsEquiv (iso (Σ≡Prop pB) (cong fst) (section-Σ≡Prop pB) (λ _ → refl))
isPropΣ : isProp A → ((x : A) → isProp (B x)) → isProp (Σ A B)
isPropΣ pA pB t u = Σ≡Prop pB (pA (t .fst) (u .fst))
isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n (Σ A B)
isOfHLevelΣ 0 = isContrΣ
isOfHLevelΣ 1 = isPropΣ
isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y =
isOfHLevelRetractFromIso (suc n)
(invIso (IsoΣPathTransportPathΣ _ _))
(isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ x → h2 _ _ _)
isSetΣ : isSet A → ((x : A) → isSet (B x)) → isSet (Σ A B)
isSetΣ = isOfHLevelΣ 2
isGroupoidΣ : isGroupoid A → ((x : A) → isGroupoid (B x)) → isGroupoid (Σ A B)
isGroupoidΣ = isOfHLevelΣ 3
is2GroupoidΣ : is2Groupoid A → ((x : A) → is2Groupoid (B x)) → is2Groupoid (Σ A B)
is2GroupoidΣ = isOfHLevelΣ 4
-- h-level of ×
isProp× : {A : Type ℓ} {B : Type ℓ'} → isProp A → isProp B → isProp (A × B)
isProp× pA pB = isPropΣ pA (λ _ → pB)
isProp×2 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''}
→ isProp A → isProp B → isProp C → isProp (A × B × C)
isProp×2 pA pB pC = isProp× pA (isProp× pB pC)
isProp×3 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''}
→ isProp A → isProp B → isProp C → isProp D → isProp (A × B × C × D)
isProp×3 pA pB pC pD = isProp×2 pA pB (isProp× pC pD)
isOfHLevel× : ∀ {A : Type ℓ} {B : Type ℓ'} n → isOfHLevel n A → isOfHLevel n B
→ isOfHLevel n (A × B)
isOfHLevel× n hA hB = isOfHLevelΣ n hA (λ _ → hB)
isSet× : ∀ {A : Type ℓ} {B : Type ℓ'} → isSet A → isSet B → isSet (A × B)
isSet× = isOfHLevel× 2
isGroupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → isGroupoid A → isGroupoid B
→ isGroupoid (A × B)
isGroupoid× = isOfHLevel× 3
is2Groupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → is2Groupoid A → is2Groupoid B
→ is2Groupoid (A × B)
is2Groupoid× = isOfHLevel× 4
-- h-level of Π-types
isOfHLevelΠ : ∀ n → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n ((x : A) → B x)
isOfHLevelΠ 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i
isOfHLevelΠ 1 h f g i x = (h x) (f x) (g x) i
isOfHLevelΠ 2 h f g F G i j z = h z (f z) (g z) (funExt⁻ F z) (funExt⁻ G z) i j
isOfHLevelΠ 3 h f g p q P Q i j k z =
h z (f z) (g z)
(funExt⁻ p z) (funExt⁻ q z)
(cong (λ f → funExt⁻ f z) P) (cong (λ f → funExt⁻ f z) Q) i j k
isOfHLevelΠ 4 h f g p q P Q R S i j k l z =
h z (f z) (g z)
(funExt⁻ p z) (funExt⁻ q z)
(cong (λ f → funExt⁻ f z) P) (cong (λ f → funExt⁻ f z) Q)
(cong (cong (λ f → funExt⁻ f z)) R) (cong (cong (λ f → funExt⁻ f z)) S) i j k l
isOfHLevelΠ (suc (suc (suc (suc (suc n))))) h f g p q P Q R S =
isOfHLevelRetract (suc n)
(cong (cong (cong funExt⁻))) (cong (cong (cong funExt))) (λ _ → refl)
(isOfHLevelΠ (suc (suc (suc (suc n)))) (λ x → h x (f x) (g x))
(funExt⁻ p) (funExt⁻ q)
(cong funExt⁻ P) (cong funExt⁻ Q)
(cong (cong funExt⁻) R) (cong (cong funExt⁻) S))
isPropΠ : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x)
isPropΠ = isOfHLevelΠ 1
isPropΠ2 : (h : (x : A) (y : B x) → isProp (C x y))
→ isProp ((x : A) (y : B x) → C x y)
isPropΠ2 h = isPropΠ λ x → isPropΠ λ y → h x y
isPropΠ3 : (h : (x : A) (y : B x) (z : C x y) → isProp (D x y z))
→ isProp ((x : A) (y : B x) (z : C x y) → D x y z)
isPropΠ3 h = isPropΠ λ x → isPropΠ λ y → isPropΠ λ z → h x y z
isPropΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isProp (E x y z w))
→ isProp ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w)
isPropΠ4 h = isPropΠ λ _ → isPropΠ3 λ _ → h _ _
isPropImplicitΠ : (h : (x : A) → isProp (B x)) → isProp ({x : A} → B x)
isPropImplicitΠ h f g i {x} = h x (f {x}) (g {x}) i
isProp→ : {A : Type ℓ} {B : Type ℓ'} → isProp B → isProp (A → B)
isProp→ pB = isPropΠ λ _ → pB
isSetΠ : ((x : A) → isSet (B x)) → isSet ((x : A) → B x)
isSetΠ = isOfHLevelΠ 2
isSetΠ2 : (h : (x : A) (y : B x) → isSet (C x y))
→ isSet ((x : A) (y : B x) → C x y)
isSetΠ2 h = isSetΠ λ x → isSetΠ λ y → h x y
isSetΠ3 : (h : (x : A) (y : B x) (z : C x y) → isSet (D x y z))
→ isSet ((x : A) (y : B x) (z : C x y) → D x y z)
isSetΠ3 h = isSetΠ λ x → isSetΠ λ y → isSetΠ λ z → h x y z
isGroupoidΠ : ((x : A) → isGroupoid (B x)) → isGroupoid ((x : A) → B x)
isGroupoidΠ = isOfHLevelΠ 3
isGroupoidΠ2 : (h : (x : A) (y : B x) → isGroupoid (C x y)) → isGroupoid ((x : A) (y : B x) → C x y)
isGroupoidΠ2 h = isGroupoidΠ λ _ → isGroupoidΠ λ _ → h _ _
isGroupoidΠ3 : (h : (x : A) (y : B x) (z : C x y) → isGroupoid (D x y z))
→ isGroupoid ((x : A) (y : B x) (z : C x y) → D x y z)
isGroupoidΠ3 h = isGroupoidΠ λ _ → isGroupoidΠ2 λ _ → h _ _
isGroupoidΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isGroupoid (E x y z w))
→ isGroupoid ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w)
isGroupoidΠ4 h = isGroupoidΠ λ _ → isGroupoidΠ3 λ _ → h _ _
is2GroupoidΠ : ((x : A) → is2Groupoid (B x)) → is2Groupoid ((x : A) → B x)
is2GroupoidΠ = isOfHLevelΠ 4
isOfHLevelΠ⁻ : ∀ {A : Type ℓ} {B : Type ℓ'} n
→ isOfHLevel n (A → B) → (A → isOfHLevel n B)
isOfHLevelΠ⁻ 0 h x = fst h x , λ y → funExt⁻ (snd h (const y)) x
isOfHLevelΠ⁻ 1 h x y z = funExt⁻ (h (const y) (const z)) x
isOfHLevelΠ⁻ (suc (suc n)) h x y z =
isOfHLevelΠ⁻ (suc n) (subst (isOfHLevel (suc n)) (sym funExtPath) (h (const y) (const z))) x
-- h-level of A ≃ B and A ≡ B
isOfHLevel≃
: ∀ n {A : Type ℓ} {B : Type ℓ'}
→ (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B)
isOfHLevel≃ zero {A = A} {B = B} hA hB = isContr→Equiv hA hB , contr
where
contr : (y : A ≃ B) → isContr→Equiv hA hB ≡ y
contr y = Σ≡Prop isPropIsEquiv (funExt (λ a → snd hB (fst y a)))
isOfHLevel≃ (suc n) {A = A} {B = B} hA hB =
isOfHLevelΣ (suc n) (isOfHLevelΠ _ λ _ → hB)
λ a → isOfHLevelPlus' 1 (isPropIsEquiv a)
isOfHLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) →
isOfHLevel n (A ≡ B)
isOfHLevel≡ n hA hB = isOfHLevelRetract n (fst univalence) ua (secEq univalence) (isOfHLevel≃ n hA hB)
isOfHLevel⁺≃ₗ
: ∀ n {A : Type ℓ} {B : Type ℓ'}
→ isOfHLevel (suc n) A → isOfHLevel (suc n) (A ≃ B)
isOfHLevel⁺≃ₗ zero pA e = isOfHLevel≃ 1 pA (isOfHLevelRespectEquiv 1 e pA) e
isOfHLevel⁺≃ₗ (suc n) hA e = isOfHLevel≃ m hA (isOfHLevelRespectEquiv m e hA) e
where
m = suc (suc n)
isOfHLevel⁺≃ᵣ
: ∀ n {A : Type ℓ} {B : Type ℓ'}
→ isOfHLevel (suc n) B → isOfHLevel (suc n) (A ≃ B)
isOfHLevel⁺≃ᵣ zero pB e
= isOfHLevel≃ 1 (isPropRetract (e .fst) (invEq e) (secEq e) pB) pB e
isOfHLevel⁺≃ᵣ (suc n) hB e
= isOfHLevel≃ m (isOfHLevelRetract m (e .fst) (invEq e) (secEq e) hB) hB e
where
m = suc (suc n)
isOfHLevel⁺≡ₗ
: ∀ n → {A B : Type ℓ}
→ isOfHLevel (suc n) A → isOfHLevel (suc n) (A ≡ B)
isOfHLevel⁺≡ₗ zero pA P = isOfHLevel≡ 1 pA (subst isProp P pA) P
isOfHLevel⁺≡ₗ (suc n) hA P
= isOfHLevel≡ m hA (subst (isOfHLevel m) P hA) P
where
m = suc (suc n)
isOfHLevel⁺≡ᵣ
: ∀ n → {A B : Type ℓ}
→ isOfHLevel (suc n) B → isOfHLevel (suc n) (A ≡ B)
isOfHLevel⁺≡ᵣ zero pB P = isOfHLevel≡ 1 (subst⁻ isProp P pB) pB P
isOfHLevel⁺≡ᵣ (suc n) hB P
= isOfHLevel≡ m (subst⁻ (isOfHLevel m) P hB) hB P
where
m = suc (suc n)
-- h-level of TypeOfHLevel
isPropHContr : isProp (TypeOfHLevel ℓ 0)
isPropHContr x y = Σ≡Prop (λ _ → isPropIsContr) (isOfHLevel≡ 0 (x .snd) (y .snd) .fst)
isOfHLevelTypeOfHLevel : ∀ n → isOfHLevel (suc n) (TypeOfHLevel ℓ n)
isOfHLevelTypeOfHLevel zero = isPropHContr
isOfHLevelTypeOfHLevel (suc n) (X , a) (Y , b) =
isOfHLevelRetract (suc n) (cong fst) (Σ≡Prop λ _ → isPropIsOfHLevel (suc n))
(section-Σ≡Prop λ _ → isPropIsOfHLevel (suc n))
(isOfHLevel≡ (suc n) a b)
isSetHProp : isSet (hProp ℓ)
isSetHProp = isOfHLevelTypeOfHLevel 1
-- h-level of lifted type
isOfHLevelLift : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A)
isOfHLevelLift n = isOfHLevelRetract n lower lift λ _ → refl
----------------------------
-- More consequences of isProp and isContr
inhProp→isContr : A → isProp A → isContr A
inhProp→isContr x h = x , h x
extend : isContr A → (∀ φ → (u : Partial φ A) → Sub A φ u)
extend (x , p) φ u = inS (hcomp (λ { j (φ = i1) → p (u 1=1) j }) x)
isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ}
→ (extend : ∀ φ → Partial φ A → A)
→ (∀ u → u ≡ (extend i1 λ { _ → u}))
→ isContr A
isContrPartial→isContr {A = A} extend law
= ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y)
where ex = extend i0 empty
module Aux (y : A) (i : I) where
φ = ~ i ∨ i
u : Partial φ A
u = λ { (i = i0) → ex ; (i = i1) → y }
v = extend φ u
-- Dependent h-level over a type
isOfHLevelDep : HLevel → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
isOfHLevelDep 0 {A = A} B = {a : A} → Σ[ b ∈ B a ] ({a' : A} (b' : B a') (p : a ≡ a') → PathP (λ i → B (p i)) b b')
isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1
isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1)
isOfHLevel→isOfHLevelDep : (n : HLevel)
→ {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B
isOfHLevel→isOfHLevelDep 0 h {a} =
(h a .fst , λ b' p → isProp→PathP (λ i → isContr→isProp (h (p i))) (h a .fst) b')
isOfHLevel→isOfHLevelDep 1 h = λ b0 b1 p → isProp→PathP (λ i → h (p i)) b0 b1
isOfHLevel→isOfHLevelDep (suc (suc n)) {A = A} {B} h {a0} {a1} b0 b1 =
isOfHLevel→isOfHLevelDep (suc n) (λ p → helper a1 p b1)
where
helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) →
isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)
helper a1 p b1 = J (λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1))
(λ _ → h _ _ _) p b1
isContrDep→isPropDep : isOfHLevelDep 0 B → isOfHLevelDep 1 B
isContrDep→isPropDep {B = B} Bctr {a0 = a0} b0 b1 p i
= comp (λ k → B (p (i ∧ k))) (λ k → λ where
(i = i0) → Bctr .snd b0 refl k
(i = i1) → Bctr .snd b1 p k)
(c0 .fst)
where
c0 = Bctr {a0}
isPropDep→isSetDep : isOfHLevelDep 1 B → isOfHLevelDep 2 B
isPropDep→isSetDep {B = B} Bprp b0 b1 b2 b3 p i j
= comp (λ k → B (p (i ∧ k) (j ∧ k))) (λ k → λ where
(j = i0) → Bprp b0 b0 refl k
(i = i0) → Bprp b0 (b2 j) (λ k → p i0 (j ∧ k)) k
(i = i1) → Bprp b0 (b3 j) (λ k → p k (j ∧ k)) k
(j = i1) → Bprp b0 b1 (λ k → p (i ∧ k) (j ∧ k)) k)
b0
isOfHLevelDepSuc : (n : HLevel) → isOfHLevelDep n B → isOfHLevelDep (suc n) B
isOfHLevelDepSuc 0 = isContrDep→isPropDep
isOfHLevelDepSuc 1 = isPropDep→isSetDep
isOfHLevelDepSuc (suc (suc n)) Blvl b0 b1 = isOfHLevelDepSuc (suc n) (Blvl b0 b1)
isPropDep→isSetDep'
: isOfHLevelDep 1 B
→ {p : w ≡ x} {q : y ≡ z} {r : w ≡ y} {s : x ≡ z}
→ {tw : B w} {tx : B x} {ty : B y} {tz : B z}
→ (sq : Square p q r s)
→ (tp : PathP (λ i → B (p i)) tw tx)
→ (tq : PathP (λ i → B (q i)) ty tz)
→ (tr : PathP (λ i → B (r i)) tw ty)
→ (ts : PathP (λ i → B (s i)) tx tz)
→ SquareP (λ i j → B (sq i j)) tp tq tr ts
isPropDep→isSetDep' {B = B} Bprp {p} {q} {r} {s} {tw} sq tp tq tr ts i j
= comp (λ k → B (sq (i ∧ k) (j ∧ k))) (λ k → λ where
(i = i0) → Bprp tw (tp j) (λ k → p (k ∧ j)) k
(i = i1) → Bprp tw (tq j) (λ k → sq (i ∧ k) (j ∧ k)) k
(j = i0) → Bprp tw (tr i) (λ k → r (k ∧ i)) k
(j = i1) → Bprp tw (ts i) (λ k → sq (k ∧ i) (j ∧ k)) k)
tw
isOfHLevelΣ' : ∀ n → isOfHLevel n A → isOfHLevelDep n B → isOfHLevel n (Σ A B)
isOfHLevelΣ' 0 Actr Bctr .fst = (Actr .fst , Bctr .fst)
isOfHLevelΣ' 0 Actr Bctr .snd (x , y) i
= Actr .snd x i , Bctr .snd y (Actr .snd x) i
isOfHLevelΣ' 1 Alvl Blvl (w , y) (x , z) i .fst = Alvl w x i
isOfHLevelΣ' 1 Alvl Blvl (w , y) (x , z) i .snd = Blvl y z (Alvl w x) i
isOfHLevelΣ' {A = A} {B = B} (suc (suc n)) Alvl Blvl (w , y) (x , z)
= isOfHLevelRetract (suc n)
(λ p → (λ i → p i .fst) , λ i → p i .snd)
ΣPathP
(λ x → refl)
(isOfHLevelΣ' (suc n) (Alvl w x) (Blvl y z))
| {
"alphanum_fraction": 0.5272945163,
"avg_line_length": 39.0936995153,
"ext": "agda",
"hexsha": "a6184060e2da0ca54acc72dd2af5a4d1b80243d7",
"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": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Foundations/HLevels.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"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": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Foundations/HLevels.agda",
"max_line_length": 150,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Foundations/HLevels.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 10958,
"size": 24199
} |
-- {-# OPTIONS -v interaction.case:10 -v tc.cover:40 #-}
module Issue635 where
record Pointed : Set₁ where
field
Carrier : Set
empty : Carrier
equal : Carrier → Carrier → Set
record PointedMorphism (M₁ M₂ : Pointed) : Set where
constructor morph
module M₁ = Pointed M₁
module M₂ = Pointed M₂
field
f : M₁.Carrier → M₂.Carrier
.identity : M₂.equal (f M₁.empty) M₂.empty
g : ∀ (M₁ M₂ : Pointed) → PointedMorphism M₁ M₂ → PointedMorphism M₁ M₂
g M₁ M₂ (morph f identity) = morph f identity
f : ∀ {M₁ M₂ : Pointed} → PointedMorphism M₁ M₂ → PointedMorphism M₁ M₂
f x = {!x!}
{- WAS:
case splitting on x in that hole produces this monstrosity:
f {.Splitting.recCon-NOT-PRINTED Carrier empty times equal} {.Splitting.recCon-NOT-PRINTED Carrier₁ empty₁ times₁ equal₁} (morph f identity) = ?
-}
-- Andreas, 2013-03-21
-- NOW: case splitting on x yields pattern (morph f identity)
| {
"alphanum_fraction": 0.6941694169,
"avg_line_length": 28.40625,
"ext": "agda",
"hexsha": "cb68009bca24fbad5176a5e6ba1f5b856bb400d3",
"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/interaction/Issue635.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/interaction/Issue635.agda",
"max_line_length": 144,
"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/interaction/Issue635.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": 297,
"size": 909
} |
module Termination.Sized.DeBruijnBase where
open import Data.Maybe
open import Data.Maybe.Effectful
open import Function -- composition, identity
open import Relation.Binary.PropositionalEquality hiding ( subst )
open ≡-Reasoning
open import Effect.Functor
fmap : {A B : Set} -> (A -> B) -> Maybe A -> Maybe B
fmap = RawFunctor._<$>_ functor
-- OR:
-- open RawFunctor MaybeFunctor using () renaming (_<$>_ to fmap)
fmapExt : {A B : Set}{f g : A -> B} ->
(forall a -> f a ≡ g a) -> forall m -> fmap f m ≡ fmap g m
fmapExt f≡g nothing = refl
fmapExt f≡g (just a) = cong just (f≡g a)
fmapLaw1 : {A : Set}(a : Maybe A) -> fmap id a ≡ a
fmapLaw1 nothing = refl
fmapLaw1 (just a) = refl
fmapLaw2 : {A B C : Set}(f : B -> C)(g : A -> B) ->
forall m -> fmap f (fmap g m) ≡ fmap (f ∘ g) m
fmapLaw2 f g nothing = refl
fmapLaw2 f g (just a) = refl
-- untyped de Bruijn terms
data Lam (A : Set) : Set where
var : A -> Lam A
app : Lam A -> Lam A -> Lam A
abs : Lam (Maybe A) -> Lam A
-- functoriality of Lam
lam : {A B : Set} -> (A -> B) -> Lam A -> Lam B
lam f (var a) = var (f a)
lam f (app t1 t2) = app (lam f t1) (lam f t2)
lam f (abs r) = abs (lam (fmap f) r)
lamExt : {A B : Set}{f g : A -> B} ->
(forall a -> f a ≡ g a) -> forall t -> lam f t ≡ lam g t
lamExt f≡g (var a) = cong var (f≡g a)
lamExt f≡g (abs r) = cong abs (lamExt (fmapExt f≡g) r)
lamExt f≡g (app r s) = cong₂ app (lamExt f≡g r) (lamExt f≡g s)
lamLaw1 : {A : Set}(t : Lam A) -> lam id t ≡ t
lamLaw1 (var a) = refl
lamLaw1 (app r s) = begin
lam id (app r s)
≡⟨ refl ⟩
app (lam id r) (lam id s)
≡⟨ cong (app (lam id r)) (lamLaw1 s) ⟩
app (lam id r) s
≡⟨ cong (\ x -> app x s) (lamLaw1 r) ⟩
app r s
∎
lamLaw1 (abs t) = begin
lam id (abs t)
≡⟨ refl ⟩
abs (lam (fmap id) t)
≡⟨ cong abs (lamExt {g = id} fmapLaw1 t) ⟩
abs (lam id t)
≡⟨ cong abs (lamLaw1 t) ⟩
abs t
∎
lamLaw2 : {A B C : Set}(f : B -> C)(g : A -> B) ->
forall t -> lam f (lam g t) ≡ lam (f ∘ g) t
lamLaw2 f g (var a) = refl
lamLaw2 f g (app r s) = cong₂ app (lamLaw2 f g r) (lamLaw2 f g s)
lamLaw2 f g (abs t) = begin
lam f (lam g (abs t))
≡⟨ refl ⟩
lam f (abs (lam (fmap g) t))
≡⟨ refl ⟩
abs (lam (fmap f) (lam (fmap g) t))
≡⟨ cong abs (lamLaw2 (fmap f) (fmap g) t) ⟩
abs (lam (fmap f ∘ fmap g) t)
≡⟨ cong abs (lamExt (fmapLaw2 f g) t) ⟩
abs (lam (fmap (f ∘ g)) t)
≡⟨ refl ⟩
lam (f ∘ g) (abs t)
∎
-- lifting a substitution A -> Lam B under a binder
lift : {A B : Set} -> (A -> Lam B) -> Maybe A -> Lam (Maybe B)
lift f nothing = var nothing
lift f (just a) = lam just (f a)
-- extensionality of lifting
liftExt : {A B : Set}{f g : A -> Lam B} ->
((a : A) -> f a ≡ g a) -> (t : Maybe A) -> lift f t ≡ lift g t
liftExt H nothing = refl
liftExt H (just a) = cong (lam just) $ H a
-- simultaneous substitution
subst : {A B : Set} -> (A -> Lam B) -> Lam A -> Lam B
subst f (var a) = f a
subst f (app t1 t2) = app (subst f t1) (subst f t2)
subst f (abs r) = abs (subst (lift f) r)
-- extensionality of subst
substExt : {A B : Set}{f g : A -> Lam B} ->
((a : A) -> f a ≡ g a) -> (t : Lam A) -> subst f t ≡ subst g t
substExt H (var a) = H a
substExt {f = f}{g = g} H (app t1 t2) = begin
subst f (app t1 t2)
≡⟨ refl ⟩
app (subst f t1) (subst f t2)
≡⟨ cong (\ x -> app x (subst f t2)) (substExt H t1) ⟩
app (subst g t1) (subst f t2)
≡⟨ cong (\ x -> app (subst g t1) x) (substExt H t2) ⟩
app (subst g t1) (subst g t2)
∎
substExt {f = f}{g = g} H (abs r) = begin
subst f (abs r)
≡⟨ refl ⟩
abs (subst (lift f) r)
≡⟨ cong abs (substExt (liftExt H) r) ⟩
abs (subst (lift g) r)
≡⟨ refl ⟩
subst g (abs r)
∎
-- Lemma: lift g ∘ fmap f = lift (g ∘ f)
liftLaw1 : {A B C : Set}(f : A -> B)(g : B -> Lam C)(t : Maybe A) ->
lift g (fmap f t) ≡ lift (g ∘ f) t
liftLaw1 f g nothing = begin
lift g (fmap f nothing)
≡⟨ refl ⟩
lift g nothing
≡⟨ refl ⟩
var nothing
≡⟨ refl ⟩
lift (g ∘ f) nothing
∎
liftLaw1 f g (just a) = begin
lift g (fmap f (just a))
≡⟨ refl ⟩
lift g (just (f a))
≡⟨ refl ⟩
lam just (g (f a))
≡⟨ refl ⟩
lift (g ∘ f) (just a)
∎
-- Lemma: subst g ∘ lam f t = subst (g ∘ f)
substLaw1 : {A B C : Set}(f : A -> B)(g : B -> Lam C)(t : Lam A) ->
subst g (lam f t) ≡ subst (g ∘ f) t
substLaw1 f g (var a) = refl
substLaw1 f g (app t1 t2) = begin
subst g (lam f (app t1 t2))
≡⟨ refl ⟩
subst g (app (lam f t1) (lam f t2))
≡⟨ refl ⟩
app (subst g (lam f t1)) (subst g (lam f t2))
≡⟨ cong (\ x -> app x (subst g (lam f t2))) (substLaw1 f g t1) ⟩
app (subst (g ∘ f) t1) (subst g (lam f t2))
≡⟨ cong (\ x -> app (subst (g ∘ f) t1) x) (substLaw1 f g t2) ⟩
app (subst (g ∘ f) t1) (subst (g ∘ f) t2)
∎
substLaw1 f g (abs r) =
begin subst g (lam f (abs r))
≡⟨ refl ⟩
subst g (abs (lam (fmap f) r))
≡⟨ refl ⟩
abs (subst (lift g) (lam (fmap f) r))
≡⟨ cong abs (substLaw1 (fmap f) (lift g) r) ⟩
abs (subst (lift g ∘ fmap f) r)
≡⟨ cong abs (substExt {f = lift g ∘ fmap f} {g = lift (g ∘ f)} (liftLaw1 f g) r) ⟩
abs (subst (lift (g ∘ f)) r)
∎
-- Lemma: lift (lam f ∘ g) = lam f ∘ subst g
liftLaw2 : {A B C : Set}(f : B -> C)(g : A -> Lam B)(t : Maybe A) ->
lift (lam f ∘ g) t ≡ lam (fmap f) (lift g t)
liftLaw2 f g nothing = begin
lift (lam f ∘ g) nothing
≡⟨ refl ⟩
var nothing
≡⟨ refl ⟩
var (fmap f nothing)
≡⟨ refl ⟩
lam (fmap f) (var nothing)
≡⟨ refl ⟩
lam (fmap f) (lift g nothing)
∎
liftLaw2 f g (just a) = begin
lift (lam f ∘ g) (just a)
≡⟨ refl ⟩
lam just (lam f (g a))
≡⟨ lamLaw2 just f (g a) ⟩
lam (just ∘ f) (g a)
≡⟨ lamExt (\ a -> refl) (g a) ⟩
lam (fmap f ∘ just) (g a)
≡⟨ sym (lamLaw2 (fmap f) just (g a)) ⟩
lam (fmap f) (lam just (g a))
≡⟨ refl ⟩
lam (fmap f) (lift g (just a))
∎
-- Lemma: subst (lam f ∘ g) = lam f ∘ subst g
substLaw2 : {A B C : Set}(f : B -> C)(g : A -> Lam B)(t : Lam A) ->
subst (lam f ∘ g) t ≡ lam f (subst g t)
substLaw2 f g (var a) = refl
substLaw2 f g (app r s) = begin
subst (lam f ∘ g) (app r s)
≡⟨ refl ⟩
app (subst (lam f ∘ g) r) (subst (lam f ∘ g) s)
≡⟨ cong (app (subst (lam f ∘ g) r)) (substLaw2 f g s) ⟩
app (subst (lam f ∘ g) r) (lam f (subst g s))
≡⟨ cong (\ x -> app x (lam f (subst g s))) (substLaw2 f g r) ⟩
app (lam f (subst g r)) (lam f (subst g s))
≡⟨ refl ⟩
lam f (app (subst g r) (subst g s))
≡⟨ refl ⟩
lam f (subst g (app r s))
∎
substLaw2 f g (abs t) = begin
subst (lam f ∘ g) (abs t)
≡⟨ refl ⟩
abs (subst (lift (lam f ∘ g)) t)
≡⟨ cong abs (substExt (liftLaw2 f g) t) ⟩
abs (subst (lam (fmap f) ∘ (lift g)) t)
≡⟨ cong abs (substLaw2 (fmap f) (lift g) t) ⟩
abs (lam (fmap f) (subst (lift g) t))
≡⟨ refl ⟩
lam f (abs (subst (lift g) t))
≡⟨ refl ⟩
lam f (subst g (abs t))
∎
| {
"alphanum_fraction": 0.5178341212,
"avg_line_length": 28.847107438,
"ext": "agda",
"hexsha": "749ed16a9679c68522e10e61c50f2eae9fb9d6b8",
"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": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/LibSucceed/Termination/Sized/DeBruijnBase.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/LibSucceed/Termination/Sized/DeBruijnBase.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/LibSucceed/Termination/Sized/DeBruijnBase.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3038,
"size": 6981
} |
{-# OPTIONS --without-K #-}
module sum where
open import level using (Level; _⊔_)
open import function.core
infixr 4 _,_
infixr 2 _×_
infixr 1 _⊎_
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
_×_ : {l k : Level} (A : Set l) (B : Set k) → Set (l ⊔ k)
A × B = Σ A λ _ → B
uncurry : ∀ {a b c} {A : Set a} {B : A → Set b} {C : (x : A) → (B x) → Set c}
→ ((x : A) → (y : B x) → C x y) → ((xy : Σ A B) → C (proj₁ xy) (proj₂ xy))
uncurry f (a , b) = f a b
uncurry' : ∀ {i j k}{X : Set i}{Y : Set j}{Z : Set k}
→ (X → Y → Z)
→ (X × Y) → Z
uncurry' f (x , y) = f x y
data _⊎_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
inj₁ : (x : A) → A ⊎ B
inj₂ : (y : B) → A ⊎ B
[_,⊎_] : ∀ {i i' j}{A : Set i}{A' : Set i'}{B : Set j}
→ (A → B) → (A' → B)
→ A ⊎ A' → B
[ f ,⊎ f' ] (inj₁ a) = f a
[ f ,⊎ f' ] (inj₂ a') = f' a'
map-⊎ : ∀ {i i' j j'}{A : Set i}{A' : Set i'}
→ {B : Set j}{B' : Set j'}
→ (A → B) → (A' → B')
→ A ⊎ A' → B ⊎ B'
map-⊎ g g' = [ inj₁ ∘' g ,⊎ inj₂ ∘' g' ]
| {
"alphanum_fraction": 0.4145907473,
"avg_line_length": 24.4347826087,
"ext": "agda",
"hexsha": "5e37eb1d9c791b710707b0dc6a6ac10651099ec8",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "sum.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sum.agda",
"max_line_length": 82,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "sum.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 554,
"size": 1124
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Abstractions used in the reflection machinery
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Reflection.Abstraction where
open import Data.List.Base as List using (List)
open import Data.Product using (_×_; _,_; uncurry; <_,_>)
import Data.String as String
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
private
variable
A B : Set
------------------------------------------------------------------------
-- Re-exporting the builtins publically
open import Agda.Builtin.Reflection public using (Abs)
open Abs public
-- Pattern synonyms
------------------------------------------------------------------------
-- Operations
map : (A → B) → Abs A → Abs B
map f (abs s x) = abs s (f x)
------------------------------------------------------------------------
-- Decidable equality
abs-injective₁ : ∀ {i i′} {a a′ : A} → abs i a ≡ abs i′ a′ → i ≡ i′
abs-injective₁ refl = refl
abs-injective₂ : ∀ {i i′} {a a′ : A} → abs i a ≡ abs i′ a′ → a ≡ a′
abs-injective₂ refl = refl
abs-injective : ∀ {i i′} {a a′ : A} → abs i a ≡ abs i′ a′ → i ≡ i′ × a ≡ a′
abs-injective = < abs-injective₁ , abs-injective₂ >
-- We often need decidability of equality for Abs A when implementing it
-- for A. Unfortunately ≡-dec makes the termination checker unhappy.
-- Instead, we can match on both Abs A and use unAbs-dec for an obviously
-- decreasing recursive call.
unAbs : Abs A → A
unAbs (abs s a) = a
unAbs-dec : {x y : Abs A} → Dec (unAbs x ≡ unAbs y) → Dec (x ≡ y)
unAbs-dec {x = abs i a} {abs i′ a′} a≟a′ =
Dec.map′ (uncurry (cong₂ abs)) abs-injective ((i String.≟ i′) ×-dec a≟a′)
≡-dec : Decidable {A = A} _≡_ → Decidable {A = Abs A} _≡_
≡-dec _≟_ x y = unAbs-dec (unAbs x ≟ unAbs y)
| {
"alphanum_fraction": 0.5467590302,
"avg_line_length": 31.578125,
"ext": "agda",
"hexsha": "52fb0b640dd57c3a2470a6c7df05fbe39b66db5b",
"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/Reflection/Abstraction.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/Reflection/Abstraction.agda",
"max_line_length": 75,
"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/Reflection/Abstraction.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": 555,
"size": 2021
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Functions.Definition
open import Groups.Definition
open import Sets.EquivalenceRelations
open import Groups.Homomorphisms.Definition
open import Groups.Lemmas
module Groups.Homomorphisms.Lemmas {a b c d : _} {A : Set a} {S : Setoid {a} {c} A} {B : Set b} {T : Setoid {b} {d} B} {_+A_ : A → A → A} {_+B_ : B → B → B} {G : Group S _+A_} {H : Group T _+B_} {f : A → B} (hom : GroupHom G H f) where
imageOfIdentityIsIdentity : Setoid._∼_ T (f (Group.0G G)) (Group.0G H)
imageOfIdentityIsIdentity = Equivalence.symmetric (Setoid.eq T) t
where
open Group H
open Setoid T
id2 : Setoid._∼_ S (Group.0G G) ((Group.0G G) +A (Group.0G G))
id2 = Equivalence.symmetric (Setoid.eq S) (Group.identRight G)
r : f (Group.0G G) ∼ f (Group.0G G) +B f (Group.0G G)
s : 0G +B f (Group.0G G) ∼ f (Group.0G G) +B f (Group.0G G)
t : 0G ∼ f (Group.0G G)
t = groupsHaveRightCancellation H (f (Group.0G G)) 0G (f (Group.0G G)) s
s = Equivalence.transitive (Setoid.eq T) identLeft r
r = Equivalence.transitive (Setoid.eq T) (GroupHom.wellDefined hom id2) (GroupHom.groupHom hom)
groupHomsCompose : {o t : _} {C : Set o} {U : Setoid {o} {t} C} {_+C_ : C → C → C} {I : Group U _+C_} {g : B → C} (gHom : GroupHom H I g) → GroupHom G I (g ∘ f)
GroupHom.wellDefined (groupHomsCompose {I} {f} gHom) {x} {y} pr = GroupHom.wellDefined gHom (GroupHom.wellDefined hom pr)
GroupHom.groupHom (groupHomsCompose {U = U} {_+C_ = _·C_} {I} {g} gHom) {x} {y} = answer
where
open Group I
answer : (Setoid._∼_ U) ((g ∘ f) (x +A y)) ((g ∘ f) x ·C (g ∘ f) y)
answer = (Equivalence.transitive (Setoid.eq U)) (GroupHom.wellDefined gHom (GroupHom.groupHom hom {x} {y}) ) (GroupHom.groupHom gHom {f x} {f y})
homRespectsInverse : {x : A} → Setoid._∼_ T (f (Group.inverse G x)) (Group.inverse H (f x))
homRespectsInverse {x} = rightInversesAreUnique H {f x} {f (Group.inverse G x)} (transitive (symmetric (GroupHom.groupHom hom)) (transitive (GroupHom.wellDefined hom (Group.invLeft G)) imageOfIdentityIsIdentity))
where
open Setoid T
open Equivalence eq
zeroImpliesInverseZero : {x : A} → Setoid._∼_ T (f x) (Group.0G H) → Setoid._∼_ T (f (Group.inverse G x)) (Group.0G H)
zeroImpliesInverseZero {x} fx=0 = transitive homRespectsInverse (transitive (inverseWellDefined H fx=0) (invIdent H))
where
open Setoid T
open Equivalence eq
homRespectsInverse' : {a b : A} → Setoid._∼_ T (f (Group.inverse G a) +B f (Group.inverse G b)) (Group.inverse H (f (b +A a)))
homRespectsInverse' {a} {b} = transitive (symmetric (GroupHom.groupHom hom)) (transitive (GroupHom.wellDefined hom (Equivalence.symmetric (Setoid.eq S) (invContravariant G))) (homRespectsInverse))
where
open Setoid T
open Equivalence eq
| {
"alphanum_fraction": 0.6652512385,
"avg_line_length": 55.4117647059,
"ext": "agda",
"hexsha": "557aa3119742c8ac6d9b179cbad0ed01d968eab3",
"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": "Groups/Homomorphisms/Lemmas.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": "Groups/Homomorphisms/Lemmas.agda",
"max_line_length": 235,
"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": "Groups/Homomorphisms/Lemmas.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": 1045,
"size": 2826
} |
-- Some proposition constructors.
{-# OPTIONS --without-K --safe #-}
module Tools.Nullary where
open import Relation.Nullary using (¬_; Dec; yes; no) public
open import Relation.Nullary.Decidable using (isYes) public
-- If A and B are logically equivalent, then so are Dec A and Dec B.
map : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {B : Set ℓ₂} → (A → B) → (B → A) → Dec A → Dec B
map f g (yes p) = yes (f p)
map f g (no ¬p) = no (λ x → ¬p (g x))
| {
"alphanum_fraction": 0.6275862069,
"avg_line_length": 29,
"ext": "agda",
"hexsha": "6713ebf842e8e9975081e5176110b562550d2640",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-11-27T15:58:33.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-10-18T14:18:20.000Z",
"max_forks_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Tools/Nullary.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_issues_repo_issues_event_max_datetime": "2021-02-22T10:37:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-22T12:49:23.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Tools/Nullary.agda",
"max_line_length": 77,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Tools/Nullary.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:01:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-20T03:05:21.000Z",
"num_tokens": 147,
"size": 435
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.