Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Numbers.Naturals.Semiring
open import Numbers.Integers.Integers
open import Numbers.Integers.Addition
open import Groups.Lemmas
open import Groups.Definition
open import Groups.Cyclic.Definition
open import Semirings.Definition
module Groups.Cyclic.DefinitionLemmas {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} (G : Group S _+_) where
open Setoid S
open Group G
open Equivalence eq
elementPowerCommutes : (x : A) (n : ℕ) → (x + positiveEltPower G x n) ∼ ((positiveEltPower G x n) + x)
elementPowerCommutes x zero = transitive identRight (symmetric identLeft)
elementPowerCommutes x (succ n) = transitive (+WellDefined reflexive (elementPowerCommutes x n)) +Associative
elementPowerCollapse : (x : A) (i j : ℤ) → Setoid._∼_ S ((elementPower G x i) + (elementPower G x j)) (elementPower G x (i +Z j))
elementPowerCollapse x (nonneg a) (nonneg b) rewrite equalityCommutative (+Zinherits a b) = positiveEltPowerCollapse G x a b
elementPowerCollapse x (nonneg zero) (negSucc b) = identLeft
elementPowerCollapse x (nonneg (succ a)) (negSucc zero) = transitive (+WellDefined (elementPowerCommutes x a) reflexive) (transitive (symmetric +Associative) (transitive (+WellDefined reflexive (transitive (+WellDefined reflexive (invContravariant G)) (transitive (+WellDefined reflexive (transitive (+WellDefined (invIdent G) reflexive) identLeft)) invRight))) identRight))
elementPowerCollapse x (nonneg (succ a)) (negSucc (succ b)) = transitive (transitive (+WellDefined (elementPowerCommutes x a) reflexive) (transitive (symmetric +Associative) (+WellDefined reflexive (transitive (transitive (+WellDefined reflexive (inverseWellDefined G (transitive (+WellDefined reflexive (elementPowerCommutes x b)) +Associative))) (transitive (+WellDefined reflexive (invContravariant G)) (transitive +Associative (transitive (+WellDefined invRight (invContravariant G)) identLeft)))) (symmetric (invContravariant G)))))) (elementPowerCollapse x (nonneg a) (negSucc b))
elementPowerCollapse x (negSucc zero) (nonneg zero) = identRight
elementPowerCollapse x (negSucc zero) (nonneg (succ b)) = transitive (transitive +Associative (+WellDefined (transitive (+WellDefined (inverseWellDefined G identRight) reflexive) invLeft) reflexive)) identLeft
elementPowerCollapse x (negSucc (succ a)) (nonneg zero) = identRight
elementPowerCollapse x (negSucc (succ a)) (nonneg (succ b)) = transitive (transitive +Associative (+WellDefined (transitive (+WellDefined (invContravariant G) reflexive) (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invLeft) identRight))) reflexive)) (elementPowerCollapse x (negSucc a) (nonneg b))
elementPowerCollapse x (negSucc a) (negSucc b) = transitive (+WellDefined reflexive (invContravariant G)) (transitive (transitive (transitive +Associative (+WellDefined (transitive (symmetric (invContravariant G)) (transitive (inverseWellDefined G +Associative) (transitive (inverseWellDefined G (+WellDefined (symmetric (elementPowerCommutes x b)) reflexive)) (transitive (inverseWellDefined G (symmetric +Associative)) (transitive (invContravariant G) (+WellDefined (inverseWellDefined G (transitive (positiveEltPowerCollapse G x b a) (identityOfIndiscernablesRight _∼_ reflexive (applyEquality (positiveEltPower G x) {b +N a} {a +N b} (Semiring.commutative ℕSemiring b a))))) reflexive)))))) reflexive)) (+WellDefined (symmetric (invContravariant G)) reflexive)) (symmetric (invContravariant G)))
positiveEltPowerInverse : (m : ℕ) → (x : A) → (positiveEltPower G (inverse x) m) ∼ inverse (positiveEltPower G x m)
positiveEltPowerInverse zero x = symmetric (invIdent G)
positiveEltPowerInverse (succ m) x = transitive (+WellDefined reflexive (positiveEltPowerInverse m x)) (transitive (symmetric (invContravariant G)) (inverseWellDefined G (symmetric (elementPowerCommutes x m))))
positiveEltPowerMultiplies : (m n : ℕ) → (x : A) → (positiveEltPower G x (m *N n)) ∼ (positiveEltPower G (positiveEltPower G x n) m)
positiveEltPowerMultiplies zero n x = reflexive
positiveEltPowerMultiplies (succ m) n x = transitive (symmetric (positiveEltPowerCollapse G x n (m *N n))) (+WellDefined reflexive (positiveEltPowerMultiplies m n x))
powerZero : (m : ℕ) → positiveEltPower G 0G m ∼ 0G
powerZero zero = reflexive
powerZero (succ m) = transitive identLeft (powerZero m)
elementPowerMultiplies : (m n : ℤ) → (x : A) → (elementPower G x (m *Z n)) ∼ (elementPower G (elementPower G x n) m)
elementPowerMultiplies (nonneg m) (nonneg n) x = positiveEltPowerMultiplies m n x
elementPowerMultiplies (nonneg zero) (negSucc n) x = reflexive
elementPowerMultiplies (nonneg (succ m)) (negSucc n) x = transitive (transitive (inverseWellDefined G (transitive (transitive (elementPowerWellDefinedZ' G (nonneg (succ (n +N m *N n) +N m)) (nonneg (m *N succ n +N succ n)) (applyEquality nonneg (transitivity (applyEquality succ (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring n (m *N n) m)) (applyEquality (n +N_) (transitivity (transitivity (Semiring.commutative ℕSemiring _ m) (applyEquality (m +N_) (multiplicationNIsCommutative m n))) (multiplicationNIsCommutative (succ n) m))))) (Semiring.commutative ℕSemiring (succ n) _))) {x}) (symmetric (positiveEltPowerCollapse G x (m *N succ n) (succ n)))) (+WellDefined (positiveEltPowerMultiplies m (succ n) x) reflexive))) (invContravariant G)) (+WellDefined reflexive (symmetric (positiveEltPowerInverse m (x + positiveEltPower G x n))))
elementPowerMultiplies (negSucc m) (nonneg zero) r = transitive (symmetric (invIdent G)) (inverseWellDefined G (transitive (symmetric identLeft) (+WellDefined reflexive (symmetric (powerZero m)))))
elementPowerMultiplies (negSucc m) (nonneg (succ n)) x = inverseWellDefined G (transitive (transitive (+WellDefined reflexive (transitive (elementPowerWellDefinedZ' G (nonneg ((m +N n *N m) +N n)) (nonneg (n +N m *N succ n)) (applyEquality nonneg (transitivity (Semiring.commutative ℕSemiring _ n) (applyEquality (n +N_) (multiplicationNIsCommutative _ m)))) {x}) (symmetric (positiveEltPowerCollapse G x n (m *N succ n))))) +Associative) (+WellDefined reflexive (positiveEltPowerMultiplies m (succ n) x)))
elementPowerMultiplies (negSucc m) (negSucc n) r = transitive (transitive (transitive (transitive (elementPowerWellDefinedZ' G (nonneg (succ m *N succ n)) (nonneg (m *N succ n +N succ n)) (applyEquality nonneg (Semiring.commutative ℕSemiring (succ n) _)) {r}) (symmetric (positiveEltPowerCollapse G r (m *N succ n) (succ n)))) (transitive (elementPowerCollapse r (nonneg (m *N succ n)) (nonneg (succ n))) (transitive (transitive (elementPowerWellDefinedZ' G (nonneg (m *N succ n) +Z nonneg (succ n)) (nonneg (m *N succ n +N succ n)) (equalityCommutative (+Zinherits (m *N succ n) (succ n))) {r}) (symmetric (positiveEltPowerCollapse G r (m *N succ n) (succ n)))) (+WellDefined (positiveEltPowerMultiplies m (succ n) r) reflexive)))) (+WellDefined (transitive (symmetric (invTwice G _)) (inverseWellDefined G (symmetric (positiveEltPowerInverse m (r + positiveEltPower G r n))))) (symmetric (invTwice G _)))) (symmetric (invContravariant G))
positiveEltPowerHomAbelian : ({x y : A} → (x + y) ∼ (y + x)) → (x y : A) → (r : ℕ) → (positiveEltPower G (x + y) r) ∼ (positiveEltPower G x r + positiveEltPower G y r)
positiveEltPowerHomAbelian ab x y zero = symmetric identRight
positiveEltPowerHomAbelian ab x y (succ r) = transitive (symmetric +Associative) (transitive (+WellDefined reflexive (transitive (+WellDefined reflexive (positiveEltPowerHomAbelian ab x y r)) (transitive (+WellDefined reflexive ab) (transitive +Associative ab)))) +Associative)
elementPowerHomAbelian : ({x y : A} → (x + y) ∼ (y + x)) → (x y : A) → (r : ℤ) → (elementPower G (x + y) r) ∼ (elementPower G x r + elementPower G y r)
elementPowerHomAbelian ab x y (nonneg n) = positiveEltPowerHomAbelian ab x y n
elementPowerHomAbelian ab x y (negSucc n) = transitive (transitive (inverseWellDefined G (positiveEltPowerHomAbelian ab x y (succ n))) (inverseWellDefined G ab)) (invContravariant G)
| {
"alphanum_fraction": 0.7561902427,
"avg_line_length": 131.5806451613,
"ext": "agda",
"hexsha": "72402de561f05694959156cb60ee9c2a50b883ac",
"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/Cyclic/DefinitionLemmas.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/Cyclic/DefinitionLemmas.agda",
"max_line_length": 940,
"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/Cyclic/DefinitionLemmas.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": 2471,
"size": 8158
} |
import cedille-options
module rkt (options : cedille-options.options) where
open import string
open import char
open import io
open import maybe
open import ctxt
open import list
open import trie
open import general-util
open import monad-instances
open import toplevel-state options {IO}
open import unit
open import bool
open import functions
open import product
open import cedille-types
open import syntax-util
private
rkt-dbg-flag = ff
rkt-dbg : string → rope → rope
rkt-dbg msg out = [[ if rkt-dbg-flag then ("; " ^ msg ^ "\n") else "" ]] ⊹⊹ out
-- constructs the name of a .racket directory for the given original directory
rkt-dirname : string → string
rkt-dirname dir = combineFileNames dir ".racket"
-- constructs the fully-qualified name of a .rkt file for a .ced file at the given ced-path
{-rkt-filename : (ced-path : string) → string
rkt-filename ced-path =
let dir = takeDirectory ced-path in
let unit-name = base-filename (takeFileName ced-path) in
combineFileNames (rkt-dirname dir) (unit-name ^ ".rkt")-}
-- sanitize a Cedille identifier for Racket
-- Racket does not allow "'" as part of a legal identifier,
-- so swamp this out for "."
rkt-iden : var → var
rkt-iden = 𝕃char-to-string
∘ ((map λ c → if c =char '\'' then '.' else c)
∘ string-to-𝕃char)
-- Racket string from erase Cedile term
rkt-from-term : term → rope
rkt-from-term (Lam _ KeptLam _ v _ tm)
= [[ "(lambda (" ]] ⊹⊹ [[ rkt-iden v ]] ⊹⊹ [[ ")" ]] ⊹⊹ rkt-from-term tm ⊹⊹ [[ ")" ]]
-- TODO untested
rkt-from-term (Let _ (DefTerm _ v _ tm-def) tm-body)
= [[ "(let ([" ]] ⊹⊹ [[ rkt-iden v ]] ⊹⊹ [[ " " ]] ⊹⊹ rkt-from-term tm-def ⊹⊹ [[ "]) " ]] ⊹⊹ rkt-from-term tm-body ⊹⊹ [[ ")\n" ]]
rkt-from-term (Var _ v)
= [[ rkt-iden v ]]
rkt-from-term (App tm₁ x tm₂)
= [[ "(" ]] ⊹⊹ rkt-from-term tm₁ ⊹⊹ [[ " " ]] ⊹⊹ rkt-from-term tm₂ ⊹⊹ [[ ")" ]]
rkt-from-term (Hole x)
= [[ "(error 'cedille-hole)" ]]
rkt-from-term (Beta _ _ NoTerm)
= [[ "(lambda (x) x)\n" ]]
rkt-from-term _
= rkt-dbg "unsupported/unknown term" [[]]
-- Racket define form from var, term
rkt-define : var → term → rope
rkt-define v tm = [[ "(define " ]] ⊹⊹ [[ rkt-iden v ]] ⊹⊹ rkt-from-term tm ⊹⊹ [[ ")" ]] ⊹⊹ [[ "\n" ]]
-- Racket require form from file
rkt-require-file : string → rope
rkt-require-file fp = [[ "(require (file \"" ]] ⊹⊹ [[ fp ]] ⊹⊹ [[ "\"))" ]]
-- Racket term from Cedille term sym-info
rkt-from-sym-info : string → sym-info → rope
rkt-from-sym-info n (term-def (just (ParamsCons (Decl _ _ _ v _ _) _)) _ tm ty , _)
-- TODO not tested
= rkt-dbg "term-def: paramsCons:" (rkt-define n tm)
rkt-from-sym-info n (term-def (just ParamsNil) _ tm ty , _)
= rkt-dbg "term-def: paramsNil:" (rkt-define n tm)
rkt-from-sym-info n (term-def nothing _ tm ty , b)
-- TODO not tested
= rkt-dbg "term-def: nothing:" (rkt-define n tm)
rkt-from-sym-info n (term-udef _ _ tm , _)
= rkt-dbg "term-udef:" (rkt-define n tm)
rkt-from-sym-info n (term-decl x , _)
= rkt-dbg "term-decl" [[]]
rkt-from-sym-info n (type-decl x , _)
= rkt-dbg "type-decl:" [[]]
rkt-from-sym-info n (type-def _ _ _ _ , _)
= rkt-dbg "type-def:" [[]]
rkt-from-sym-info n (kind-def _ _ , _)
= rkt-dbg "kind-def:" [[]]
rkt-from-sym-info n (rename-def v , _)
-- TODO Not implemented!
= rkt-dbg ("rename-def: " ^ v) [[]]
rkt-from-sym-info n (var-decl , _)
= rkt-dbg "var-decl:" [[]]
rkt-from-sym-info n (const-def _ , _)
= rkt-dbg "const-def:" [[]]
rkt-from-sym-info n (datatype-def _ _ , _)
= rkt-dbg "datatype-def:" [[]]
to-rkt-file : (ced-path : string) → ctxt → include-elt → ((cede-filename : string) → string) → rope
to-rkt-file ced-path (mk-ctxt _ (syms , _) i sym-occurences _) ie rkt-filename =
rkt-header ⊹⊹ rkt-body
where
cdle-pair = trie-lookup𝕃2 syms ced-path
cdle-mod = fst cdle-pair
cdle-defs = snd cdle-pair
qual-name : string → string
qual-name name = cdle-mod ^ "." ^ name
-- lang pragma, imports, and provides
rkt-header rkt-body : rope
rkt-header =
[[ "#lang racket\n\n" ]] ⊹⊹
foldr (λ fn x → rkt-require-file (rkt-filename fn) ⊹⊹ x)
[[ "\n" ]] (include-elt.deps ie) ⊹⊹
[[ "(provide (all-defined-out))\n\n" ]]
-- in reverse order: lookup symbol defs from file,
-- pair name with info, and convert to racket
rkt-body = foldr (λ {(n , s) x → x ⊹⊹
[[ "\n" ]] ⊹⊹ rkt-from-sym-info (qual-name n) s}) [[]]
(drop-nothing (map
(λ name → maybe-map (λ syminf → name , syminf)
(trie-lookup i (qual-name name)))
cdle-defs))
{-
-- write a Racket file to .racket subdirectory from Cedille file path,
-- context, and include-elt
write-rkt-file : (ced-path : string) → ctxt → include-elt → ((cede-filename : string) → string) → IO ⊤
write-rkt-file ced-path (mk-ctxt _ (syms , _) i sym-occurences) ie rkt-filename =
let dir = takeDirectory ced-path
in createDirectoryIfMissing tt (rkt-dirname dir) >>
writeFile (rkt-filename ced-path)
(rkt-header ^ rkt-body)
where
cdle-mod = fst (trie-lookup𝕃2 syms ced-path)
cdle-defs = snd (trie-lookup𝕃2 syms ced-path)
qual-name : string → string
qual-name name = cdle-mod ^ "." ^ name
-- lang pragma, imports, and provides
rkt-header rkt-body : string
rkt-header = "#lang racket\n\n"
^ (string-concat-sep "\n"
(map (rkt-require-file ∘ rkt-filename)
(include-elt.deps ie))) ^ "\n"
^ "(provide (all-defined-out))\n\n"
-- in reverse order: lookup symbol defs from file,
-- pair name with info, and convert to racket
rkt-body = string-concat-sep "\n"
(map (λ { (n , s) → rkt-from-sym-info (qual-name n) s})
(reverse (drop-nothing
(map (λ name →
maybe-map (λ syminf → name , syminf)
(trie-lookup i (qual-name name)))
cdle-defs))))
-}
| {
"alphanum_fraction": 0.588021178,
"avg_line_length": 36.6303030303,
"ext": "agda",
"hexsha": "3463427f0f7d0f4b5ca2fef2a2ceb9284e44f406",
"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": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/rkt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"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": "xoltar/cedille",
"max_issues_repo_path": "src/rkt.agda",
"max_line_length": 131,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/rkt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2018,
"size": 6044
} |
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
open import Agda.Builtin.List
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
data Fin : Nat → Set where
zero : {n : Nat} → Fin (suc n)
suc : {n : Nat} → Fin n → Fin (suc n)
test : (x : Nat) (y : Fin x) {z : Nat} → x ≡ suc z → Set
test .(suc z) y {z} refl = Nat
-- Telescope: (z : Nat) (y : Fin (suc z))
-- agda rep: ("z" , Nat) ("y" , Fin (suc @0))
-- Patterns: test .(suc @1) @0 @1 refl = ?
macro
testDef : Term → TC _
testDef goal = do
d ← getDefinition (quote test)
`d ← quoteTC d
unify `d goal
foo : Definition
foo = testDef
fooTest : foo ≡ function
(clause
(("z" , arg (arg-info hidden relevant) (def (quote Nat) [])) ∷
("y" ,
arg (arg-info visible relevant)
(def (quote Fin)
(arg (arg-info visible relevant)
(con (quote Nat.suc)
(arg (arg-info visible relevant) (var 0 []) ∷ []))
∷ [])))
∷ [])
(arg (arg-info visible relevant)
(dot
(con (quote Nat.suc)
(arg (arg-info visible relevant) (var 1 []) ∷ [])))
∷
arg (arg-info visible relevant) (var 0) ∷
arg (arg-info hidden relevant) (var 1) ∷
arg (arg-info visible relevant) (con (quote refl) []) ∷ [])
(def (quote Nat) [])
∷ [])
fooTest = refl
defBar : (name : Name) → TC _
defBar x = do
function cls ← returnTC foo
where _ → typeError []
defineFun x cls
bar : (x : Nat) (y : Fin x) {z : Nat} → x ≡ suc z → Set
unquoteDef bar = defBar bar
| {
"alphanum_fraction": 0.4741100324,
"avg_line_length": 31.4237288136,
"ext": "agda",
"hexsha": "a21aceae91f01ef7bc2c25509af3694ff9792da1",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue2151-ClauseTelescope.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"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": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2151-ClauseTelescope.agda",
"max_line_length": 81,
"max_stars_count": null,
"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/Issue2151-ClauseTelescope.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 529,
"size": 1854
} |
open import Structure.Setoid
open import Structure.Category
open import Type
module Structure.Category.CoMonad
{ℓₒ ℓₘ ℓₑ}
{cat : CategoryObject{ℓₒ}{ℓₘ}{ℓₑ}}
where
import Function.Equals
open Function.Equals.Dependent
open import Functional.Dependent using () renaming (_∘_ to _∘ᶠⁿ_)
import Lvl
open import Logic.Predicate
open import Structure.Category.Functor
open import Structure.Category.Functor.Functors as Functors
open import Structure.Category.NaturalTransformation
open import Structure.Category.NaturalTransformation.NaturalTransformations as NaturalTransformations
open CategoryObject(cat)
open Category.ArrowNotation(category)
open Category(category)
open Functors.Wrapped
open NaturalTransformations.Raw(intro category)(intro category)
private instance _ = cat
record CoMonad (T : Object → Object) ⦃ functor : Functor(category)(category)(T) ⦄ : Type{Lvl.of(Type.of(cat))} where
open Functor(functor)
functor-object : cat →ᶠᵘⁿᶜᵗᵒʳ cat
functor-object = [∃]-intro T ⦃ functor ⦄
private Tᶠᵘⁿᶜᵗᵒʳ = functor-object
field
Η : (Tᶠᵘⁿᶜᵗᵒʳ →ᴺᵀ idᶠᵘⁿᶜᵗᵒʳ)
Μ : (Tᶠᵘⁿᶜᵗᵒʳ →ᴺᵀ (Tᶠᵘⁿᶜᵗᵒʳ ∘ᶠᵘⁿᶜᵗᵒʳ Tᶠᵘⁿᶜᵗᵒʳ))
η = [∃]-witness Η
μ = [∃]-witness Μ
η-natural : ∀{x y}{f} → (η(y) ∘ map f ≡ f ∘ η(x))
η-natural = NaturalTransformation.natural([∃]-proof Η)
μ-natural : ∀{x y}{f} → (μ(y) ∘ map f ≡ map(map f) ∘ μ(x))
μ-natural = NaturalTransformation.natural([∃]-proof Μ)
field
μ-functor-[∘]-commutativity : ((μ ∘ᶠⁿ T) ∘ᴺᵀ μ ⊜ (map ∘ᶠⁿ μ) ∘ᴺᵀ μ)
μ-functor-[∘]-identityₗ : ((map ∘ᶠⁿ η) ∘ᴺᵀ μ ⊜ idᴺᵀ)
μ-functor-[∘]-identityᵣ : ((η ∘ᶠⁿ T) ∘ᴺᵀ μ ⊜ idᴺᵀ)
module FunctionalNames where
extract : ∀{x} → (T(x) ⟶ x)
extract{x} = [∃]-witness Η(x)
duplicate : ∀{x} → (T(x) ⟶ T(T(x)))
duplicate{x} = [∃]-witness Μ(x)
| {
"alphanum_fraction": 0.6822222222,
"avg_line_length": 31.0344827586,
"ext": "agda",
"hexsha": "7e72db9fa74dfebcbe94bf78b06304e24066ba04",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Category/CoMonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Category/CoMonad.agda",
"max_line_length": 116,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Category/CoMonad.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": 803,
"size": 1800
} |
{-# OPTIONS --no-termination-check #-}
module SafeFlagNoTermination where
data Empty : Set where
inhabitant : Empty
inhabitant = inhabitant | {
"alphanum_fraction": 0.7730496454,
"avg_line_length": 20.1428571429,
"ext": "agda",
"hexsha": "5c7025e440eba4bc633ce6cff46192d2735e9278",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/SafeFlagNoTermination.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": "test/fail/SafeFlagNoTermination.agda",
"max_line_length": 38,
"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": "test/fail/SafeFlagNoTermination.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": 34,
"size": 141
} |
open import Agda.Primitive using (_⊔_)
import Categories.Category as Category
import Categories.Category.Cartesian as Cartesian
open import SingleSorted.AlgebraicTheory
import SingleSorted.Power as Power
module SingleSorted.Interpretation
{o ℓ e}
(Σ : Signature)
{𝒞 : Category.Category o ℓ e}
(cartesian-𝒞 : Cartesian.Cartesian 𝒞) where
open Signature Σ
open Category.Category 𝒞
open Power 𝒞
-- An interpretation of Σ in 𝒞
record Interpretation : Set (o ⊔ ℓ ⊔ e) where
field
interp-carrier : Obj
interp-pow : Powered interp-carrier
interp-oper : ∀ (f : oper) → Powered.pow interp-pow (oper-arity f) ⇒ interp-carrier
open Powered interp-pow
-- the interpretation of a term
interp-term : ∀ {Γ : Context} → Term Γ → (pow Γ) ⇒ interp-carrier
interp-term (tm-var x) = π x
interp-term (tm-oper f ts) = interp-oper f ∘ tuple (oper-arity f) (λ i → interp-term (ts i))
-- the interpretation of a context
interp-ctx : Context → Obj
interp-ctx Γ = pow Γ
-- the interpretation of a substitution
interp-subst : ∀ {Γ Δ} → Γ ⇒s Δ → interp-ctx Γ ⇒ interp-ctx Δ
interp-subst {Γ} {Δ} σ = tuple Δ λ i → interp-term (σ i)
-- interpretation commutes with substitution
open HomReasoning
interp-[]s : ∀ {Γ Δ} {t : Term Δ} {σ : Γ ⇒s Δ} →
interp-term (t [ σ ]s) ≈ interp-term t ∘ interp-subst σ
interp-[]s {Γ} {Δ} {tm-var x} {σ} = ⟺ (project {Γ = Δ})
interp-[]s {Γ} {Δ} {tm-oper f ts} {σ} = (∘-resp-≈ʳ
(tuple-cong
{fs = λ i → interp-term (ts i [ σ ]s)}
{gs = λ z → interp-term (ts z) ∘ interp-subst σ}
(λ i → interp-[]s {t = ts i} {σ = σ})
○ (∘-distribʳ-tuple
{Γ = oper-arity f}
{fs = λ z → interp-term (ts z)}
{g = interp-subst σ})))
○ (Equiv.refl ○ sym-assoc)
-- -- Every signature has the trivial interpretation
Trivial : Interpretation
Trivial =
let open Cartesian.Cartesian cartesian-𝒞 in
record
{ interp-carrier = ⊤
; interp-pow = StandardPowered cartesian-𝒞 ⊤
; interp-oper = λ f → ! }
record HomI (A B : Interpretation) : Set (o ⊔ ℓ ⊔ e) where
open Interpretation
open Powered
field
hom-morphism : interp-carrier A ⇒ interp-carrier B
hom-commute :
∀ (f : oper) →
hom-morphism ∘ interp-oper A f ≈
interp-oper B f ∘ tuple (interp-pow B) (oper-arity f) (λ i → hom-morphism ∘ π (interp-pow A) i)
-- The identity homomorphism
IdI : ∀ (A : Interpretation) → HomI A A
IdI A =
let open Interpretation A in
let open HomReasoning in
let open Powered interp-pow in
record
{ hom-morphism = id
; hom-commute =
λ f →
begin
(id ∘ interp-oper f) ≈⟨ identityˡ ⟩
interp-oper f ≈˘⟨ identityʳ ⟩
(interp-oper f ∘ id) ≈˘⟨ refl⟩∘⟨ unique (λ i → identityʳ ○ ⟺ identityˡ) ⟩
(interp-oper f ∘ tuple (oper-arity f) (λ i → id ∘ π i)) ∎
}
-- Compositon of homomorphisms
_∘I_ : ∀ {A B C : Interpretation} → HomI B C → HomI A B → HomI A C
_∘I_ {A} {B} {C} ϕ ψ =
let open HomI in
record { hom-morphism = hom-morphism ϕ ∘ hom-morphism ψ
; hom-commute =
let open Interpretation in
let open Powered in
let open HomReasoning in
λ f →
begin
(((hom-morphism ϕ) ∘ hom-morphism ψ) ∘ interp-oper A f) ≈⟨ assoc ⟩
(hom-morphism ϕ ∘ hom-morphism ψ ∘ interp-oper A f) ≈⟨ (refl⟩∘⟨ hom-commute ψ f) ⟩
(hom-morphism ϕ ∘
interp-oper B f ∘
tuple (interp-pow B) (oper-arity f)
(λ i → hom-morphism ψ ∘ π (interp-pow A) i)) ≈˘⟨ assoc ⟩
((hom-morphism ϕ ∘ interp-oper B f) ∘
tuple (interp-pow B) (oper-arity f)
(λ i → hom-morphism ψ ∘ π (interp-pow A) i)) ≈⟨ (hom-commute ϕ f ⟩∘⟨refl) ⟩
((interp-oper C f ∘
tuple (interp-pow C) (oper-arity f)
(λ i → hom-morphism ϕ ∘ π (interp-pow B) i))
∘
tuple (interp-pow B) (oper-arity f)
(λ i → hom-morphism ψ ∘ π (interp-pow A) i)) ≈⟨ assoc ⟩
(interp-oper C f ∘
tuple (interp-pow C) (oper-arity f)
(λ i → hom-morphism ϕ ∘ π (interp-pow B) i)
∘
tuple (interp-pow B) (oper-arity f)
(λ i → hom-morphism ψ ∘ π (interp-pow A) i)) ≈⟨ (refl⟩∘⟨ ⟺ (∘-distribʳ-tuple (interp-pow C))) ⟩
(interp-oper C f ∘
tuple (interp-pow C) (oper-arity f)
(λ x →
(hom-morphism ϕ ∘ π (interp-pow B) x) ∘
tuple (interp-pow B) (oper-arity f)
(λ i → hom-morphism ψ ∘ π (interp-pow A) i))) ≈⟨ (refl⟩∘⟨ tuple-cong (interp-pow C) λ i → assoc) ⟩
(interp-oper C f ∘
tuple (interp-pow C) (oper-arity f)
(λ z →
hom-morphism ϕ ∘
π (interp-pow B) z ∘
tuple (interp-pow B) (oper-arity f)
(λ i → hom-morphism ψ ∘ π (interp-pow A) i))) ≈⟨ (refl⟩∘⟨ tuple-cong (interp-pow C) λ i → refl⟩∘⟨ project (interp-pow B)) ⟩
(interp-oper C f ∘
tuple (interp-pow C) (oper-arity f)
(λ z → hom-morphism ϕ ∘ hom-morphism ψ ∘ π (interp-pow A) z)) ≈⟨ (refl⟩∘⟨ tuple-cong (interp-pow C) λ i → sym-assoc) ⟩
(interp-oper C f ∘
tuple (interp-pow C) (oper-arity f)
(λ z → (hom-morphism ϕ ∘ hom-morphism ψ) ∘ π (interp-pow A) z)) ∎}
| {
"alphanum_fraction": 0.4703275835,
"avg_line_length": 42.9863945578,
"ext": "agda",
"hexsha": "074f5712d92b48751ebc9c02c3bdb5c0f409c5d1",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/SingleSorted/Interpretation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/SingleSorted/Interpretation.agda",
"max_line_length": 148,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/SingleSorted/Interpretation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 1915,
"size": 6319
} |
{-# OPTIONS --without-K --safe #-}
module Data.Binary.Proofs.Bijection where
open import Relation.Binary.PropositionalEquality
open import Data.Binary.Operations.Unary
open import Data.Binary.Proofs.Unary
open import Data.Binary.Definitions
open import Data.Binary.Operations.Semantics
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Relation.Binary.PropositionalEquality.FasterReasoning
import Data.Nat.Properties as ℕ
open import Function
homo : ∀ n → ⟦ ⟦ n ⇑⟧ ⇓⟧ ≡ n
homo zero = refl
homo (suc n) = inc-homo ⟦ n ⇑⟧ ⟨ trans ⟩ cong suc (homo n)
inj : ∀ {x y} → ⟦ x ⇓⟧ ≡ ⟦ y ⇓⟧ → x ≡ y
inj {xs} {ys} eq = go (subst (IncView xs) eq (inc-view xs)) (inc-view ys)
where
go : ∀ {n xs ys} → IncView xs n → IncView ys n → xs ≡ ys
go Izero Izero = refl
go (Isuc refl xs) (Isuc refl ys) = cong inc (go xs ys)
open import Function.Bijection
𝔹↔ℕ : 𝔹 ⤖ ℕ
𝔹↔ℕ = bijection ⟦_⇓⟧ ⟦_⇑⟧ inj homo
| {
"alphanum_fraction": 0.6832779623,
"avg_line_length": 30.1,
"ext": "agda",
"hexsha": "975378e8312630f11ce0165084073ef4fe764eb0",
"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": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Binary/Proofs/Bijection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"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-binary",
"max_issues_repo_path": "Data/Binary/Proofs/Bijection.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Binary/Proofs/Bijection.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 333,
"size": 903
} |
record Foo : Set where
field
record A : Set₂ where
B : Set₁
B = Set
field
record C : Set₂ where
field
B : Foo
B = _
record D : Set₂ where
B : Set₁
B = Set
field
F : Foo
F = _
| {
"alphanum_fraction": 0.5637254902,
"avg_line_length": 9.2727272727,
"ext": "agda",
"hexsha": "f9c69361d459e156bb0917755ae343328f9565b8",
"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/Issue3803.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/Issue3803.agda",
"max_line_length": 22,
"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/Issue3803.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": 80,
"size": 204
} |
{-# OPTIONS --without-K #-}
module ScaleDegree where
open import Data.Fin using (Fin; toℕ; #_)
open import Data.Nat using (ℕ; suc; _+_)
open import Data.Nat.DivMod using (_mod_; _div_)
open import Data.Product using (_×_; _,_)
open import Data.Vec using (lookup)
open import Pitch
data ScaleDegree (n : ℕ) : Set where
scaleDegree : Fin n → ScaleDegree n
ScaleDegreeOctave : ℕ → Set
ScaleDegreeOctave n = ScaleDegree n × Octave
transposeScaleDegree : {n : ℕ} → ℕ → ScaleDegreeOctave (suc n) → ScaleDegreeOctave (suc n)
transposeScaleDegree {n} k (scaleDegree d , octave o) =
let d' = (toℕ d) + k
in scaleDegree (d' mod (suc n)) , octave (o + (d' div (suc n)))
scaleDegreeToPitchClass : {n : ℕ} → Scale n → ScaleDegree n → PitchClass
scaleDegreeToPitchClass scale (scaleDegree d) = lookup scale d
| {
"alphanum_fraction": 0.6842737095,
"avg_line_length": 30.8518518519,
"ext": "agda",
"hexsha": "d22272a141676f802f37203c1f69e9fd437e1163",
"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/ScaleDegree.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/ScaleDegree.agda",
"max_line_length": 90,
"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/ScaleDegree.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": 253,
"size": 833
} |
module Data.Maybe.Instance where
open import Class.Equality
open import Class.Monad
open import Data.Maybe
open import Data.Maybe.Properties
instance
Maybe-Monad : ∀ {a} -> Monad (Maybe {a})
Maybe-Monad = record { _>>=_ = λ x f → maybe f nothing x ; return = just }
Maybe-Eq : ∀ {A} {{_ : Eq A}} → Eq (Maybe A)
Maybe-Eq ⦃ record { _≟_ = _≟_ } ⦄ = record { _≟_ = ≡-dec _≟_ }
Maybe-EqB : ∀ {A} {{_ : Eq A}} → EqB (Maybe A)
Maybe-EqB = Eq→EqB
| {
"alphanum_fraction": 0.6118421053,
"avg_line_length": 26.8235294118,
"ext": "agda",
"hexsha": "1462aac597a19b1ef12a067b992b6bd095a06539",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Data/Maybe/Instance.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Data/Maybe/Instance.agda",
"max_line_length": 76,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Data/Maybe/Instance.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 166,
"size": 456
} |
module _ where
data Bool : Set where
true false : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
-- Not allowed:
{-# COMPILED_DATA Bool Bool True False #-}
| {
"alphanum_fraction": 0.64,
"avg_line_length": 15.3846153846,
"ext": "agda",
"hexsha": "608b566ea4075abeda56cb670be272a2cfbf17b9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/CompiledBuiltinBool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/CompiledBuiltinBool.agda",
"max_line_length": 42,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/CompiledBuiltinBool.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 49,
"size": 200
} |
module proofs where
open import lambdasyntax
open import static
open import dynamic
open import Data.Empty
open import Data.Nat
open import Function
open import Data.Vec using (Vec; [])
open import Data.Bool using (Bool; true; false)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
-- label precision
data _⊑ˡ_ : (ℓ₁ ℓ₂ : Label) → Set where
ℓ⊑✭ : ∀ {ℓ} → ℓ ⊑ˡ ✭
ℓ⊑ℓ : ∀ {ℓ} → ℓ ⊑ˡ ℓ
_⊑ˡ?_ : ∀ (ℓ₁ ℓ₂ : Label) → Dec (ℓ₁ ⊑ˡ ℓ₂)
⊤ ⊑ˡ? ⊤ = yes ℓ⊑ℓ
⊤ ⊑ˡ? ⊥ = no (λ ())
⊤ ⊑ˡ? ✭ = yes ℓ⊑✭
⊥ ⊑ˡ? ⊤ = no (λ ())
⊥ ⊑ˡ? ⊥ = yes ℓ⊑ℓ
⊥ ⊑ˡ? ✭ = yes ℓ⊑✭
✭ ⊑ˡ? ⊤ = no (λ ())
✭ ⊑ˡ? ⊥ = no (λ ())
✭ ⊑ˡ? ✭ = yes ℓ⊑✭
-- type precision
data _⊑_ : (t₁ t₂ : GType) → Set where
b⊑b : ∀ {ℓ₁ ℓ₂} → ℓ₁ ⊑ˡ ℓ₂ → bool ℓ₁ ⊑ bool ℓ₂
λ⊑λ : ∀ {s₁₁ s₂₁ s₁₂ s₂₂ ℓ₁ ℓ₂} → s₁₁ ⊑ s₂₁ → s₁₂ ⊑ s₂₂ → ℓ₁ ⊑ˡ ℓ₂ → ((s₁₁ ⇒ ℓ₁) s₁₂) ⊑ ((s₂₁ ⇒ ℓ₂) s₂₂)
lem₁ : ∀ {t₁ t₂ t₃ t₄ ℓ ℓ₁} → (x : (t₁ ⇒ ℓ) t₂ ⊑ (t₃ ⇒ ℓ₁) t₄) → t₃ ⊑ t₁
lem₁ (λ⊑λ x x₁ x₂) = {! !}
_⊑?_ : ∀ (t₁ t₂ : GType) → Dec (t₁ ⊑ t₂)
bool x ⊑? bool x₁ with x ⊑ˡ? x₁
bool x ⊑? bool x₁ | yes p = yes (b⊑b p)
bool x ⊑? bool x₁ | no ¬p = no (¬p ∘ lem)
where lem : ∀ {ℓ₁ ℓ₂ : Label} → (bool ℓ₁ ⊑ bool ℓ₂) → ℓ₁ ⊑ˡ ℓ₂
lem (b⊑b x) = x
bool x ⊑? (t₂ ⇒ x₁) t₃ = no (λ ())
bool x ⊑? err = no (λ ())
(t₁ ⇒ x) t₂ ⊑? bool x₁ = no (λ ())
(t₁ ⇒ ℓ) t₂ ⊑? (t₃ ⇒ ℓ₁) t₄ with t₃ ⊑? t₁ | t₂ ⊑? t₄
(t₁ ⇒ ℓ) t₂ ⊑? (t₃ ⇒ ℓ₁) t₄ | yes p | (yes p₁) = yes {! !}
(t₁ ⇒ ℓ) t₂ ⊑? (t₃ ⇒ ℓ₁) t₄ | yes p | (no ¬p) = no (¬p ∘ lem)
where lem : ∀ {t₁ t₂ t₃ t₄ ℓ ℓ₁} (x : (t₁ ⇒ ℓ) t₂ ⊑ (t₃ ⇒ ℓ₁) t₄) → t₂ ⊑ t₄
lem (λ⊑λ x x₁ x₂) = x₁
(t₁ ⇒ ℓ) t₂ ⊑? (t₃ ⇒ ℓ₁) t₄ | no ¬p | (yes p) = no {!!}
(t₁ ⇒ ℓ) t₂ ⊑? (t₃ ⇒ ℓ₁) t₄ | no ¬p | (no ¬p₁) = no (¬p ∘ {! !})
(t₁ ⇒ x) t₂ ⊑? err = no (λ ())
err ⊑? bool x = no (λ ())
err ⊑? (t₂ ⇒ x) t₃ = no (λ ())
err ⊑? err = no (λ ())
| {
"alphanum_fraction": 0.4616193481,
"avg_line_length": 32.2372881356,
"ext": "agda",
"hexsha": "beb1a435a01a0b612dd2214b9b99e3bad732de5b",
"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": "acf5a153e14a7bdc0c9332fa602fa369fe7add46",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kellino/TypeSystems",
"max_forks_repo_path": "Agda/Gradual Security/proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46",
"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": "kellino/TypeSystems",
"max_issues_repo_path": "Agda/Gradual Security/proofs.agda",
"max_line_length": 108,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kellino/TypeSystems",
"max_stars_repo_path": "Agda/Gradual Security/proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2017-05-26T23:06:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-27T08:05:40.000Z",
"num_tokens": 1093,
"size": 1902
} |
------------------------------------------------------------------------
-- Properties of combinatorial functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --exact-split #-}
module Math.Combinatorics.Function.Properties where
-- agda-stdlib
open import Data.Empty using (⊥-elim)
open import Data.List as List
open import Data.List.Properties
import Data.List.All as All
import Data.List.All.Properties as Allₚ
open import Data.Maybe hiding (zipWith)
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.DivMod
open import Data.Product
open import Data.Sum
open import Data.Unit using (tt)
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Decidable
-- agda-combinatorics
open import Math.Combinatorics.Function
import Math.Combinatorics.Function.Properties.Lemma as Lemma
-- agda-misc
open import Math.NumberTheory.Product.Nat
open ≤-Reasoning
-- TODO: replace with Data.Nat.Predicate
private
_≠0 : ℕ → Set
n ≠0 = False (n ≟ 0)
------------------------------------------------------------------------
-- Properties of _!
private
zero-product : ∀ m n → m * n ≡ 0 → m ≡ 0 ⊎ n ≡ 0
zero-product 0 n m*n≡0 = inj₁ refl
zero-product (suc m) 0 m*n≡0 = inj₂ refl
-- factorial never be 0
n!≢0 : ∀ n → (n !) ≢ 0
n!≢0 0 ()
n!≢0 (suc n) [1+n]!≡0 with zero-product (suc n) (n !) [1+n]!≡0
... | inj₂ n!≡0 = n!≢0 n n!≡0
-- TODO: use Data.Nat.Predicate
False[n!≟0] : ∀ n → False (n ! ≟ 0)
False[n!≟0] n = fromWitnessFalse (n!≢0 n)
1≤n! : ∀ n → 1 ≤ n !
1≤n! 0 = ≤-refl
1≤n! (suc n) = ≤-trans (1≤n! n) (m≤m+n (n !) _)
2≤[2+n]! : ∀ n → 2 ≤ (2 + n) !
2≤[2+n]! 0 = ≤-refl
2≤[2+n]! (suc n) = ≤-trans (2≤[2+n]! n) (m≤m+n ((2 + n) !) _)
!-mono-< : ∀ {m n} → suc m < n → suc m ! < n !
!-mono-< {0} {suc zero} (s≤s ())
!-mono-< {0} {suc (suc n)} _ = 2≤[2+n]! n
!-mono-< {suc m} {suc n} (s≤s 1+m<n) =
*-mono-< (s≤s 1+m<n) (!-mono-< 1+m<n)
!-mono-<-≢0 : ∀ {m n} {wit : m ≠0} → m < n → m ! < n !
!-mono-<-≢0 {suc m} {n} {tt} m<n = !-mono-< m<n
!-mono-<-≤ : ∀ {m n} → m < n → m ! ≤ n !
!-mono-<-≤ {0} {n} _ = 1≤n! n
!-mono-<-≤ {suc m} {n} 1+m<n = <⇒≤ $ !-mono-< 1+m<n
!-mono-≤ : ∀ {m n} → m ≤ n → m ! ≤ n !
!-mono-≤ {m} {n} m≤n with Lemma.≤⇒≡∨< m≤n
... | inj₁ refl = ≤-refl {m !}
... | inj₂ m<n = !-mono-<-≤ m<n
!-injective : ∀ {m n} {m≢0 : m ≠0} {n≢0 : n ≠0} → m ! ≡ n ! → m ≡ n
!-injective {m} {n} {m≢0} {n≢0} m!≡n! with <-cmp m n
... | tri< m<n _ _ = ⊥-elim $ <⇒≢ (!-mono-<-≢0 {m} {n} {m≢0} m<n) m!≡n!
... | tri≈ _ m≡n _ = m≡n
... | tri> _ _ n<m = ⊥-elim $ <⇒≢ (!-mono-<-≢0 {n} {m} {n≢0} n<m) (sym m!≡n!)
n!≤n^n : ∀ n → n ! ≤ n ^ n
n!≤n^n 0 = ≤-refl
n!≤n^n (suc n) = begin
suc n * n ! ≤⟨ *-monoʳ-≤ (suc n) (n!≤n^n n) ⟩
suc n * n ^ n ≤⟨ *-monoʳ-≤ (suc n) (Lemma.^-monoˡ-≤ n (≤-step ≤-refl)) ⟩
suc n * suc n ^ n ∎
2^n≤[1+n]! : ∀ n → 2 ^ n ≤ (suc n) !
2^n≤[1+n]! 0 = ≤-refl
2^n≤[1+n]! (suc n) = begin
2 ^ suc n ≡⟨⟩
2 * 2 ^ n ≤⟨ *-mono-≤ (m≤m+n 2 n) (2^n≤[1+n]! n) ⟩
suc (suc n) * (suc n) ! ≡⟨⟩
(suc (suc n)) ! ∎
[1+n]!/[1+n]≡n! : ∀ n → (suc n) ! / suc n ≡ n !
[1+n]!/[1+n]≡n! n =
sym $ Lemma.m*n≡o⇒m≡o/n (n !) (suc n) ((suc n) !) tt (*-comm (n !) (suc n))
-- relation with product
n!≡Π[k<n]suc : ∀ n → n ! ≡ Π< n suc
n!≡Π[k<n]suc zero = refl
n!≡Π[k<n]suc (suc n) = begin-equality
suc n * n ! ≡⟨ *-comm (suc n) (n !) ⟩
n ! * suc n ≡⟨ cong (_* suc n) $ n!≡Π[k<n]suc n ⟩
Π< n suc * suc n ∎
------------------------------------------------------------------------
-- Properties of P
P[n,1]≡n : ∀ n → P n 1 ≡ n
P[n,1]≡n 0 = refl
P[n,1]≡n (suc n) = *-identityʳ (suc n)
P[n,n]≡n! : ∀ n → P n n ≡ n !
P[n,n]≡n! 0 = refl
P[n,n]≡n! (suc n) = cong (suc n *_) (P[n,n]≡n! n)
n<k⇒P[n,k]≡0 : ∀ {n k} → n < k → P n k ≡ 0
n<k⇒P[n,k]≡0 {0} {suc k} n<k = refl
n<k⇒P[n,k]≡0 {suc n} {suc k} (s≤s n<k) = begin-equality
P (suc n) (suc k) ≡⟨⟩
suc n * P n k ≡⟨ cong (suc n *_) $ n<k⇒P[n,k]≡0 n<k ⟩
suc n * 0 ≡⟨ *-zeroʳ (suc n) ⟩
0 ∎
-- m = 3; n = 4; o = 2
-- 7 6 5 4 3 = 7 6 5 * 4 3
P-split : ∀ m n o → P (m + n) (m + o) ≡ P (m + n) m * P n o
P-split 0 n o = sym $ +-identityʳ (P n o)
P-split (suc m) n o = begin-equality
P (suc m + n) (suc m + o) ≡⟨⟩
(suc m + n) * P (m + n) (m + o) ≡⟨ cong ((suc m + n) *_) $ P-split m n o ⟩
(suc m + n) * (P (m + n) m * P n o) ≡⟨ sym $ *-assoc (suc m + n) (P (m + n) m) (P n o) ⟩
P (suc m + n) (suc m) * P n o ∎
-- proved by P-split, P[n,n]≡n!
-- m = 5; n =
-- 9 8 7 6 5
-- * 4 3 2 1 =
-- 9 8 7 6 5 4 3 2 1
P[m+n,m]*n!≡[m+n]! : ∀ m n → P (m + n) m * n ! ≡ (m + n) !
P[m+n,m]*n!≡[m+n]! m n = begin-equality
P (m + n) m * n ! ≡⟨ cong (P (m + n) m *_) $ sym $ P[n,n]≡n! n ⟩
P (m + n) m * P n n ≡⟨ sym $ P-split m n n ⟩
P (m + n) (m + n) ≡⟨ P[n,n]≡n! (m + n) ⟩
(m + n) ! ∎
-- proved by P[m+n,m]*n!≡[m+n]!
P[m+n,n]*m!≡[m+n]! : ∀ m n → P (m + n) n * m ! ≡ (m + n) !
P[m+n,n]*m!≡[m+n]! m n = begin-equality
P (m + n) n * m ! ≡⟨ cong (λ v → P v n * m !) $ +-comm m n ⟩
P (n + m) n * m ! ≡⟨ P[m+n,m]*n!≡[m+n]! n m ⟩
(n + m) ! ≡⟨ cong (_!) $ +-comm n m ⟩
(m + n) ! ∎
-- proved by P[m+n,m]*n!≡[m+n]!
P[n,k]*[n∸k]!≡n! : ∀ {n k} → k ≤ n → P n k * (n ∸ k) ! ≡ n !
P[n,k]*[n∸k]!≡n! {n} {k} k≤n = begin-equality
P n k * m ! ≡⟨ cong (λ v → P v k * m !) $ sym $ k+m≡n ⟩
P (k + m) k * m ! ≡⟨ P[m+n,m]*n!≡[m+n]! k m ⟩
(k + m) ! ≡⟨ cong (_!) $ k+m≡n ⟩
n ! ∎
where
m = n ∸ k
k+m≡n : k + m ≡ n
k+m≡n = m+[n∸m]≡n k≤n
-- proved by P[n,k]*[n∸k]!≡n!
P[n,k]≡n!/[n∸k]! : ∀ {n k} → k ≤ n → P n k ≡ _div_ (n !) ((n ∸ k) !) {False[n!≟0] (n ∸ k)}
P[n,k]≡n!/[n∸k]! {n} {k} k≤n = Lemma.m*n≡o⇒m≡o/n (P n k) ((n ∸ k) !) (n !)
(False[n!≟0] (n ∸ k)) (P[n,k]*[n∸k]!≡n! k≤n)
P[m,m∸n]*n!≡m! : ∀ {m n} → n ≤ m → P m (m ∸ n) * n ! ≡ m !
P[m,m∸n]*n!≡m! {m} {n} n≤m = begin-equality
P m o * n ! ≡⟨ sym $ cong (λ v → P v o * n !) o+n≡m ⟩
P (o + n) o * n ! ≡⟨ P[m+n,m]*n!≡[m+n]! o n ⟩
(o + n) ! ≡⟨ cong (_!) o+n≡m ⟩
m ! ∎
where
o = m ∸ n
o+n≡m : o + n ≡ m
o+n≡m = m∸n+n≡m n≤m
m!/n!≡P[m,m∸n] : ∀ {m n} → n ≤ m → (m ! / n !) {False[n!≟0] n} ≡ P m (m ∸ n)
m!/n!≡P[m,m∸n] {m} {n} n≤m =
sym $ Lemma.m≡n*o⇒n≡m/o (m !) (P m (m ∸ n)) (n !) (False[n!≟0] n)
(sym $ P[m,m∸n]*n!≡m! n≤m)
-- proved by P-split
-- m = 2; n = 7
-- 9 8 7 = 9 8 * 7
P[m+n,1+m]≡P[m+n,m]*n : ∀ m n → P (m + n) (suc m) ≡ P (m + n) m * n
P[m+n,1+m]≡P[m+n,m]*n m n = begin-equality
P (m + n) (1 + m) ≡⟨ cong (P (m + n)) $ +-comm 1 m ⟩
P (m + n) (m + 1) ≡⟨ P-split m n 1 ⟩
P (m + n) m * P n 1 ≡⟨ cong (P (m + n) m *_) $ P[n,1]≡n n ⟩
P (m + n) m * n ∎
P[m+n,1+n]≡P[m+n,n]*m : ∀ m n → P (m + n) (suc n) ≡ P (m + n) n * m
P[m+n,1+n]≡P[m+n,n]*m m n = begin-equality
P (m + n) (suc n) ≡⟨ cong (λ v → P v (suc n)) $ +-comm m n ⟩
P (n + m) (suc n) ≡⟨ P[m+n,1+m]≡P[m+n,m]*n n m ⟩
P (n + m) n * m ≡⟨ cong (λ v → P v n * m) $ +-comm n m ⟩
P (m + n) n * m ∎
P[n,1+k]≡P[n,k]*[n∸k] : ∀ n k → P n (suc k) ≡ P n k * (n ∸ k)
P[n,1+k]≡P[n,k]*[n∸k] n k with Lemma.lemma₃ k n
... | inj₁ (m , n≡m+k) = begin-equality
P n (suc k) ≡⟨ cong (λ v → P v (suc k)) n≡m+k ⟩
P (m + k) (suc k) ≡⟨ P[m+n,1+n]≡P[m+n,n]*m m k ⟩
P (m + k) k * m ≡⟨ sym $ cong₂ _*_ (cong (λ v → P v k) n≡m+k) n∸k≡m ⟩
P n k * (n ∸ k) ∎
where
n∸k≡m = Lemma.m≡n+o⇒m∸o≡n n m k n≡m+k
... | inj₂ n<k = begin-equality
P n (suc k) ≡⟨ n<k⇒P[n,k]≡0 (≤-step n<k) ⟩
0 ≡⟨ sym $ *-zeroʳ (P n k) ⟩
P n k * 0 ≡⟨ sym $ cong (P n k *_) $ m≤n⇒m∸n≡0 (<⇒≤ n<k) ⟩
P n k * (n ∸ k) ∎
P[n,1+k]≡[n∸k]*P[n,k] : ∀ n k → P n (suc k) ≡ (n ∸ k) * P n k
P[n,1+k]≡[n∸k]*P[n,k] n k = trans (P[n,1+k]≡P[n,k]*[n∸k] n k) (*-comm (P n k) (n ∸ k))
-- proved by P[n,1+k]≡[n∸k]*P[n,k] and n<k⇒P[n,k]≡0
P[1+n,1+k]≡[1+k]*P[n,k]+P[n,1+k] : ∀ n k → P (suc n) (suc k) ≡ suc k * P n k + P n (suc k)
P[1+n,1+k]≡[1+k]*P[n,k]+P[n,1+k] n k with k ≤? n
... | yes k≤n = begin-equality
suc n * P n k ≡⟨ cong (_* P n k) 1+n≡[1+k]+[n∸k] ⟩
(suc k + (n ∸ k)) * P n k ≡⟨ *-distribʳ-+ (P n k) (suc k) (n ∸ k) ⟩
suc k * P n k + (n ∸ k) * P n k ≡⟨ sym $ cong (suc k * P n k +_) $ P[n,1+k]≡[n∸k]*P[n,k] n k ⟩
suc k * P n k + P n (suc k) ∎
where
1+n≡[1+k]+[n∸k] : suc n ≡ suc k + (n ∸ k)
1+n≡[1+k]+[n∸k] = sym $ begin-equality
suc k + (n ∸ k) ≡⟨ +-assoc 1 k (n ∸ k) ⟩
suc (k + (n ∸ k)) ≡⟨ cong suc $ m+[n∸m]≡n k≤n ⟩
suc n ∎
... | no k≰n = begin-equality
P (suc n) (suc k) ≡⟨ n<k⇒P[n,k]≡0 (s≤s n<k) ⟩
0 + 0 ≡⟨ sym $ cong (_+ 0) $ *-zeroʳ (suc k) ⟩
suc k * 0 + 0 ≡⟨ sym $ cong₂ _+_ (cong (suc k *_) (n<k⇒P[n,k]≡0 n<k)) (n<k⇒P[n,k]≡0 (≤-step n<k)) ⟩
suc k * P n k + P n (suc k) ∎
where
n<k : n < k
n<k = ≰⇒> k≰n
P[1+n,n]≡[1+n]! : ∀ n → P (suc n) n ≡ (suc n) !
P[1+n,n]≡[1+n]! n = begin-equality
P (1 + n) n ≡⟨ cong (λ v → P v n) (+-comm 1 n) ⟩
P (n + 1) n ≡⟨ sym $ *-identityʳ (P (n + 1) n) ⟩
P (n + 1) n * 1 ≡⟨ sym $ P-split n 1 1 ⟩
P (n + 1) (n + 1) ≡⟨ P[n,n]≡n! (n + 1) ⟩
(n + 1) ! ≡⟨ cong (_!) (+-comm n 1) ⟩
(1 + n) ! ∎
P-split-∸-alternative : ∀ {m n o} → o ≤ m → o ≤ n → P m n ≡ P m o * P (m ∸ o) (n ∸ o)
P-split-∸-alternative {m} {n} {o} o≤m o≤n = begin-equality
P m n ≡⟨ sym $ cong₂ P o+p≡m o+q≡n ⟩
P (o + p) (o + q) ≡⟨ P-split o p q ⟩
P (o + p) o * P p q ≡⟨ cong (λ v → P v o * P p q) o+p≡m ⟩
P m o * P p q ∎
where
p = m ∸ o
q = n ∸ o
o+p≡m : o + p ≡ m
o+p≡m = m+[n∸m]≡n o≤m
o+q≡n : o + q ≡ n
o+q≡n = m+[n∸m]≡n o≤n
P-split-∸ : ∀ m n o → P m (n + o) ≡ P m n * P (m ∸ n) o
P-split-∸ m n o with n ≤? m
... | yes n≤m = begin-equality
P m (n + o) ≡⟨ sym $ cong (λ v → P v (n + o)) n+p≡m ⟩
P (n + p) (n + o) ≡⟨ P-split n p o ⟩
P (n + p) n * P p o ≡⟨ cong (λ v → P v n * P p o) n+p≡m ⟩
P m n * P p o ∎
where
p = m ∸ n
n+p≡m : n + p ≡ m
n+p≡m = m+[n∸m]≡n n≤m
... | no n≰m = begin-equality
P m (n + o) ≡⟨ n<k⇒P[n,k]≡0 m<n+o ⟩
0 ≡⟨⟩
0 * P (m ∸ n) o ≡⟨ sym $ cong (_* P (m ∸ n) o) $ n<k⇒P[n,k]≡0 m<n ⟩
P m n * P (m ∸ n) o ∎
where
m<n : m < n
m<n = ≰⇒> n≰m
m<n+o : m < n + o
m<n+o = begin-strict
m <⟨ m<n ⟩
n ≤⟨ m≤m+n n o ⟩
n + o ∎
P-slide-∸ : ∀ m n o → P m n * P (m ∸ n) o ≡ P m o * P (m ∸ o) n
P-slide-∸ m n o = begin-equality
P m n * P (m ∸ n) o ≡⟨ sym $ P-split-∸ m n o ⟩
P m (n + o) ≡⟨ cong (P m) $ +-comm n o ⟩
P m (o + n) ≡⟨ P-split-∸ m o n ⟩
P m o * P (m ∸ o) n ∎
-- Properties of P and order relation
k≤n⇒1≤P[n,k] : ∀ {n k} → k ≤ n → 1 ≤ P n k
k≤n⇒1≤P[n,k] {n} {.0} z≤n = ≤-refl
k≤n⇒1≤P[n,k] {.(suc n)} {.(suc k)} (s≤s {k} {n} k≤n) = begin
1 ≤⟨ s≤s z≤n ⟩
suc n ≡⟨ sym $ *-identityʳ (suc n) ⟩
suc n * 1 ≤⟨ *-monoʳ-≤ (suc n) (k≤n⇒1≤P[n,k] {n} {k} k≤n) ⟩
suc n * P n k ∎
k≤n⇒P[n,k]≢0 : ∀ {n k} → k ≤ n → P n k ≢ 0
k≤n⇒P[n,k]≢0 {n} {k} k≤n = Lemma.1≤n⇒n≢0 $ k≤n⇒1≤P[n,k] k≤n
P[n,k]≡0⇒n<k : ∀ {n k} → P n k ≡ 0 → n < k
P[n,k]≡0⇒n<k {n} {k} P[n,k]≡0 with n <? k
... | yes n<k = n<k
... | no n≮k = ⊥-elim $ k≤n⇒P[n,k]≢0 k≤n P[n,k]≡0
where
k≤n = ≮⇒≥ n≮k
P[n,k]≢0⇒k≤n : ∀ {n k} → P n k ≢ 0 → k ≤ n
P[n,k]≢0⇒k≤n {n} {k} P[n,k]≢0 with k ≤? n
... | yes k≤n = k≤n
... | no k≰n = ⊥-elim $ P[n,k]≢0 $ n<k⇒P[n,k]≡0 n<k
where
n<k : n < k
n<k = ≰⇒> k≰n
P[n,k]≤n^k : ∀ n k → P n k ≤ n ^ k
P[n,k]≤n^k n 0 = ≤-refl
P[n,k]≤n^k 0 (suc k) = ≤-refl
P[n,k]≤n^k (suc n) (suc k) = begin
suc n * P n k ≤⟨ *-monoʳ-≤ (suc n) $ P[n,k]≤n^k n k ⟩
suc n * n ^ k ≤⟨ *-monoʳ-≤ (suc n) $ Lemma.^-monoˡ-≤ k $ ≤-step ≤-refl ⟩
suc n * suc n ^ k ≡⟨⟩
suc n ^ suc k ∎
k≤n⇒k!≤P[n,k] : ∀ {n k} → k ≤ n → k ! ≤ P n k
k≤n⇒k!≤P[n,k] {n} {0} k≤n = ≤-refl
k≤n⇒k!≤P[n,k] {suc n} {suc k} (s≤s k≤n) = begin
suc k * k ! ≤⟨ *-mono-≤ (s≤s k≤n) (k≤n⇒k!≤P[n,k] k≤n) ⟩
suc n * P n k ∎
P[n,k]≤n! : ∀ n k → P n k ≤ n !
P[n,k]≤n! n 0 = 1≤n! n
P[n,k]≤n! 0 (suc k) = ≤-step ≤-refl
P[n,k]≤n! (suc n) (suc k) = begin
suc n * P n k ≤⟨ *-monoʳ-≤ (suc n) (P[n,k]≤n! n k) ⟩
suc n * n ! ∎
P-monoʳ-< : ∀ {n k r} → 2 ≤ n → r < n → k < r → P n k < P n r
P-monoʳ-< {suc zero} {k} {r} (s≤s ()) r<n k<r
P-monoʳ-< {n@(suc (suc n-2))} {k} {r} 2≤n r<n k<r =
*-cancelʳ-< (P n k) (P n r) $ begin-strict
P n k * (n ∸ k) ! ≡⟨ P[n,k]*[n∸k]!≡n! k≤n ⟩
n ! ≡⟨ sym $ P[n,k]*[n∸k]!≡n! r≤n ⟩
P n r * (n ∸ r) ! <⟨ Lemma.*-monoʳ-<′ (P n r) (fromWitnessFalse P[n,r]≢0)
(!-mono-<-≢0 {n ∸ r} {n ∸ k} {fromWitnessFalse n∸r≢0} n∸r<n∸k) ⟩
P n r * (n ∸ k) ! ∎
where
k≤r = <⇒≤ k<r
r≤n = <⇒≤ r<n
k≤n = ≤-trans k≤r r≤n
P[n,r]≢0 : P n r ≢ 0
P[n,r]≢0 = k≤n⇒P[n,k]≢0 {n} {r} r≤n
n∸r≢0 : n ∸ r ≢ 0
n∸r≢0 = Lemma.m<n⇒n∸m≢0 r<n
n∸r<n∸k : n ∸ r < n ∸ k
n∸r<n∸k = ∸-monoʳ-< k<r r≤n
P-monoʳ-≤ : ∀ {n k r} → r ≤ n → k ≤ r → P n k ≤ P n r
P-monoʳ-≤ {zero} {zero} {zero} r≤n k≤r = ≤-refl
P-monoʳ-≤ {zero} {suc k} {r} r≤n k≤r = z≤n
P-monoʳ-≤ {suc zero} {zero} {zero} r≤n k≤r = ≤-refl
P-monoʳ-≤ {suc zero} {zero} {suc zero} r≤n k≤r = ≤-refl
P-monoʳ-≤ {suc zero} {zero} {suc (suc r)} (s≤s ()) k≤r
P-monoʳ-≤ {suc zero} {suc zero} {suc zero} (s≤s r≤n) k≤r = ≤-refl
P-monoʳ-≤ {suc zero} {suc (suc k)} {suc r} r≤n k≤r = z≤n
P-monoʳ-≤ {suc (suc n)} {k} {r} r≤2+n k≤r with Lemma.≤⇒≡∨< r≤2+n
P-monoʳ-≤ {suc (suc n)} {k} {r} r≤2+n k≤r | inj₁ r≡2+n = begin
P (2 + n) k ≡⟨ cong (λ v → P v k) (sym r≡2+n) ⟩
P r k ≤⟨ P[n,k]≤n! r k ⟩
r ! ≡⟨ sym $ P[n,n]≡n! r ⟩
P r r ≡⟨ cong (λ v → P v r) $ r≡2+n ⟩
P (2 + n) r ∎
P-monoʳ-≤ {suc (suc n)} {k} {r} r≤2+n k≤r | inj₂ r<2+n with Lemma.≤⇒≡∨< k≤r
P-monoʳ-≤ {suc (suc n)} {k} {r} r≤2+n k≤r | inj₂ r<2+n | inj₁ k≡r = begin
P (2 + n) k ≡⟨ cong (P (2 + n)) k≡r ⟩
P (2 + n) r ∎
P-monoʳ-≤ {suc (suc n)} {k} {r} r≤2+n k≤r | inj₂ r<2+n | inj₂ k<r =
<⇒≤ (P-monoʳ-< {2 + n} {k} {r} (s≤s (s≤s z≤n)) r<2+n k<r)
P-monoˡ-< : ∀ {m n k} {wit : k ≠0} → k ≤ m → m < n → P m k < P n k
P-monoˡ-< {suc m} {suc n} {1} {wit} k≤m (s≤s m<n) = s≤s $ begin-strict
m * 1 ≡⟨ *-identityʳ m ⟩
m <⟨ m<n ⟩
n ≡⟨ sym $ *-identityʳ n ⟩
n * 1 ∎
P-monoˡ-< {suc m} {suc n} {suc (suc k-1)} {wit} (s≤s k≤m) (s≤s m<n) = begin-strict
suc m * P m (suc k-1) <⟨ *-mono-< (s≤s m<n) (P-monoˡ-< {m} {n} {suc k-1} {tt} k≤m m<n) ⟩
suc n * P n (suc k-1) ∎
P-monoˡ-≤ : ∀ {m n} k → m ≤ n → P m k ≤ P n k
P-monoˡ-≤ {m} {n} 0 m≤n = ≤-refl
P-monoˡ-≤ {m} {n} k@(suc _) m≤n with k ≤? m
P-monoˡ-≤ {m} {n} k@(suc _) m≤n | yes k≤m with Lemma.≤⇒≡∨< m≤n
P-monoˡ-≤ {m} {n} k@(suc _) m≤n | yes k≤m | inj₁ refl = ≤-refl
P-monoˡ-≤ {m} {n} k@(suc _) m≤n | yes k≤m | inj₂ m<n = <⇒≤ $ P-monoˡ-< k≤m m<n
P-monoˡ-≤ {m} {n} k@(suc _) m≤n | no k≰m = begin
P m k ≡⟨ n<k⇒P[n,k]≡0 (≰⇒> k≰m) ⟩
0 ≤⟨ z≤n ⟩
P n k ∎
P[n,k]≡product[take[k,downFrom[1+n]]] :
∀ {n k} → k ≤ n → P n k ≡ product (take k (downFrom (suc n)))
P[n,k]≡product[take[k,downFrom[1+n]]] {n} {zero} k≤n = refl
P[n,k]≡product[take[k,downFrom[1+n]]] {suc n} {suc k} (s≤s k≤n) = begin-equality
suc n * P n k ≡⟨ cong (suc n *_) $ P[n,k]≡product[take[k,downFrom[1+n]]] k≤n ⟩
suc n * product (take k (downFrom (suc n))) ∎
------------------------------------------------------------------------
-- Properties of CRec
-- proved by induction and P[1+n,1+k]≡[1+k]*P[n,k]+P[n,1+k]
CRec[n,k]*k!≡P[n,k] : ∀ n k → CRec n k * k ! ≡ P n k
CRec[n,k]*k!≡P[n,k] n 0 = refl
CRec[n,k]*k!≡P[n,k] 0 (suc k) = refl
CRec[n,k]*k!≡P[n,k] (suc n) (suc k) = begin-equality
CRec (suc n) (suc k) * suc k ! ≡⟨⟩
(CRec n k + CRec n (suc k)) * (suc k * k !) ≡⟨ Lemma.lemma₅ (CRec n k) (CRec n (suc k)) (suc k) (k !) ⟩
suc k * (CRec n k * k !) + CRec n (suc k) * suc k ! ≡⟨ cong₂ _+_ (cong (suc k *_) $ CRec[n,k]*k!≡P[n,k] n k) (CRec[n,k]*k!≡P[n,k] n (suc k)) ⟩
suc k * P n k + P n (suc k) ≡⟨ sym $ P[1+n,1+k]≡[1+k]*P[n,k]+P[n,1+k] n k ⟩
P (suc n) (suc k) ∎
[1+k]*CRec[1+n,1+k]≡[1+n]*CRec[n,k] : ∀ n k → suc k * CRec (suc n) (suc k) ≡ suc n * CRec n k
[1+k]*CRec[1+n,1+k]≡[1+n]*CRec[n,k] n k = Lemma.*-cancelʳ-≡′
(suc k * CRec (suc n) (suc k)) (suc n * CRec n k) (False[n!≟0] k) $ begin-equality
suc k * CRec (suc n) (suc k) * k ! ≡⟨ sym $ Lemma.lemma₈ (CRec (suc n) (suc k)) (suc k) (k !) ⟩
CRec (suc n) (suc k) * (suc k) ! ≡⟨ CRec[n,k]*k!≡P[n,k] (suc n) (suc k) ⟩
P (suc n) (suc k) ≡⟨⟩
suc n * P n k ≡⟨ sym $ cong (suc n *_) $ CRec[n,k]*k!≡P[n,k] n k ⟩
suc n * (CRec n k * k !) ≡⟨ sym $ *-assoc (suc n) (CRec n k) (k !) ⟩
suc n * CRec n k * k ! ∎
CRec[1+n,1+k]≡[CRec[n,k]*[1+n]]/[1+k] : ∀ n k →
CRec (suc n) (suc k) ≡ (CRec n k * suc n) / suc k
CRec[1+n,1+k]≡[CRec[n,k]*[1+n]]/[1+k] n k = Lemma.m*n≡o⇒m≡o/n
(CRec (suc n) (suc k)) (suc k) (CRec n k * suc n) tt ( begin-equality
CRec (suc n) (suc k) * suc k ≡⟨ *-comm (CRec (suc n) (suc k)) (suc k) ⟩
suc k * CRec (suc n) (suc k) ≡⟨ [1+k]*CRec[1+n,1+k]≡[1+n]*CRec[n,k] n k ⟩
suc n * CRec n k ≡⟨ *-comm (suc n) (CRec n k) ⟩
CRec n k * suc n ∎ )
------------------------------------------------------------------------
-- Properties of C
C[n,k]≡CRec[n,k] : ∀ n k → C n k ≡ CRec n k
C[n,k]≡CRec[n,k] n zero = refl
C[n,k]≡CRec[n,k] zero (suc k) = refl
C[n,k]≡CRec[n,k] (suc n) (suc k) = begin-equality
(C n k * suc n) / suc k
≡⟨ cong (λ v → (v * suc n) / suc k) $ C[n,k]≡CRec[n,k] n k ⟩
(CRec n k * suc n) / suc k
≡⟨ sym $ CRec[1+n,1+k]≡[CRec[n,k]*[1+n]]/[1+k] n k ⟩
CRec (suc n) (suc k)
∎
-- TODO prove directly
-- P n k ∣ k !
C[n,k]*k!≡P[n,k] : ∀ n k → C n k * k ! ≡ P n k
C[n,k]*k!≡P[n,k] n k = trans (cong (_* k !) (C[n,k]≡CRec[n,k] n k)) (CRec[n,k]*k!≡P[n,k] n k)
C[n,k]≡P[n,k]/k! : ∀ n k → C n k ≡ _div_ (P n k) (k !) {False[n!≟0] k}
C[n,k]≡P[n,k]/k! n k = Lemma.m*n≡o⇒m≡o/n _ _ _ (False[n!≟0] k) (C[n,k]*k!≡P[n,k] n k)
C[1+n,1+k]≡C[n,k]+C[n,1+k] : ∀ n k → C (suc n) (suc k) ≡ C n k + C n (suc k)
C[1+n,1+k]≡C[n,k]+C[n,1+k] n k = begin-equality
C (suc n) (suc k) ≡⟨ C[n,k]≡CRec[n,k] (suc n) (suc k) ⟩
CRec n k + CRec n (suc k) ≡⟨ sym $ cong₂ _+_ (C[n,k]≡CRec[n,k] n k) (C[n,k]≡CRec[n,k] n (suc k)) ⟩
C n k + C n (suc k) ∎
n<k⇒C[n,k]≡0 : ∀ {n k} → n < k → C n k ≡ 0
n<k⇒C[n,k]≡0 {n} {k} n<k = begin-equality
C n k ≡⟨ C[n,k]≡P[n,k]/k! n k ⟩
(P n k div k !) {False[n!≟0] k} ≡⟨ cong (λ v → (v div k !) {False[n!≟0] k}) $ n<k⇒P[n,k]≡0 n<k ⟩
(0 div k !) {False[n!≟0] k} ≡⟨ 0/n≡0 (k !) ⟩
0 ∎
C[n,1]≡n : ∀ n → C n 1 ≡ n
C[n,1]≡n n = begin-equality
C n 1 ≡⟨ C[n,k]≡P[n,k]/k! n 1 ⟩
P n 1 div 1 ≡⟨ n/1≡n (P n 1) ⟩
P n 1 ≡⟨ P[n,1]≡n n ⟩
n ∎
C[n,n]≡1 : ∀ n → C n n ≡ 1
C[n,n]≡1 n = begin-equality
C n n ≡⟨ C[n,k]≡P[n,k]/k! n n ⟩
(P n n div n !) {False[n!≟0] n} ≡⟨ cong (λ v → (v div n !) {False[n!≟0] n}) $ P[n,n]≡n! n ⟩
(n ! div n !) {False[n!≟0] n} ≡⟨ n/n≡1 (n !) ⟩
1 ∎
-- proved by C[n,k]*k!≡P[n,k] and P[m+n,n]*m!≡[m+n]!
C[m+n,n]*m!*n!≡[m+n]! : ∀ m n → C (m + n) n * m ! * n ! ≡ (m + n) !
C[m+n,n]*m!*n!≡[m+n]! m n = begin-equality
C (m + n) n * m ! * n ! ≡⟨ Lemma.lemma₇ (C (m + n) n) (m !) (n !) ⟩
C (m + n) n * n ! * m ! ≡⟨ cong (_* m !) $ C[n,k]*k!≡P[n,k] (m + n) n ⟩
P (m + n) n * m ! ≡⟨ P[m+n,n]*m!≡[m+n]! m n ⟩
(m + n) ! ∎
-- proved by C[m+n,n]*m!*n!≡[m+n]!
C[m+n,m]*m!*n!≡[m+n]! : ∀ m n → C (m + n) m * m ! * n ! ≡ (m + n) !
C[m+n,m]*m!*n!≡[m+n]! m n = begin-equality
C (m + n) m * m ! * n ! ≡⟨ Lemma.lemma₇ (C (m + n) m) (m !) (n !) ⟩
C (m + n) m * n ! * m ! ≡⟨ cong (λ v → C v m * n ! * m !) $ +-comm m n ⟩
C (n + m) m * n ! * m ! ≡⟨ C[m+n,n]*m!*n!≡[m+n]! n m ⟩
(n + m) ! ≡⟨ cong (_!) $ +-comm n m ⟩
(m + n) ! ∎
C[n,k]*[n∸k]!*k!≡n! : ∀ {n k} → k ≤ n → C n k * (n ∸ k) ! * k ! ≡ n !
C[n,k]*[n∸k]!*k!≡n! {n} {k} k≤n = begin-equality
C n k * m ! * k ! ≡⟨ cong (λ v → C v k * m ! * k !) $ sym $ m+k≡n ⟩
C (m + k) k * m ! * k ! ≡⟨ C[m+n,n]*m!*n!≡[m+n]! m k ⟩
(m + k) ! ≡⟨ cong (_!) $ m+k≡n ⟩
n ! ∎
where
m = n ∸ k
m+k≡n : m + k ≡ n
m+k≡n = m∸n+n≡m k≤n
private
False[m!*n!≟0] : ∀ m n → False ((m ! * n !) ≟ 0)
False[m!*n!≟0] m n = fromWitnessFalse $ Lemma.*-pres-≢0 (n!≢0 m) (n!≢0 n)
C[n,k]≡n!/[[n∸k]!*k!] : ∀ {n k} → k ≤ n →
C n k ≡ _div_ (n !) ((n ∸ k) ! * k !) {False[m!*n!≟0] (n ∸ k) k}
C[n,k]≡n!/[[n∸k]!*k!] {n} {k} k≤n = Lemma.m*n≡o⇒m≡o/n
(C n k) ((n ∸ k) ! * k !) (n !) (False[m!*n!≟0] (n ∸ k) k) $ begin-equality
C n k * ((n ∸ k) ! * k !) ≡⟨ sym $ *-assoc (C n k) ((n ∸ k) !) (k !) ⟩
C n k * (n ∸ k) ! * k ! ≡⟨ C[n,k]*[n∸k]!*k!≡n! k≤n ⟩
n ! ∎
-- proved by C[m+n,n]*m!*n!≡[m+n]! and C[m+n,m]*m!*n!≡[m+n]!
C-inv : ∀ m n → C (m + n) n ≡ C (m + n) m
C-inv m n =
Lemma.*-cancelʳ-≡′ (C (m + n) n) (C (m + n) m) (False[n!≟0] m) $
Lemma.*-cancelʳ-≡′ (C (m + n) n * m !) (C (m + n) m * m !) (False[n!≟0] n) $ begin-equality
C (m + n) n * m ! * n ! ≡⟨ C[m+n,n]*m!*n!≡[m+n]! m n ⟩
(m + n) ! ≡⟨ sym $ C[m+n,m]*m!*n!≡[m+n]! m n ⟩
C (m + n) m * m ! * n ! ∎
C-inv-∸ : ∀ {n k} → k ≤ n → C n k ≡ C n (n ∸ k)
C-inv-∸ {n} {k} k≤n = begin-equality
C n k ≡⟨ cong (λ v → C v k) $ sym $ m+k≡n ⟩
C (m + k) k ≡⟨ C-inv m k ⟩
C (m + k) m ≡⟨ cong (λ v → C v m) $ m+k≡n ⟩
C n (n ∸ k) ∎
where
m = n ∸ k
m+k≡n : m + k ≡ n
m+k≡n = m∸n+n≡m k≤n
C[m+n,1+n]*[1+n]≡C[m+n,n]*m : ∀ m n → C (m + n) (suc n) * suc n ≡ C (m + n) n * m
C[m+n,1+n]*[1+n]≡C[m+n,n]*m m n =
Lemma.*-cancelʳ-≡′ (C (m + n) (suc n) * suc n) (C (m + n) n * m) (False[n!≟0] n) $ begin-equality
C (m + n) (suc n) * suc n * n ! ≡⟨ *-assoc (C (m + n) (suc n)) (suc n) (n !) ⟩
C (m + n) (suc n) * suc n ! ≡⟨ C[n,k]*k!≡P[n,k] (m + n) (suc n) ⟩
P (m + n) (suc n) ≡⟨ P[m+n,1+n]≡P[m+n,n]*m m n ⟩
P (m + n) n * m ≡⟨ cong (_* m) $ sym $ C[n,k]*k!≡P[n,k] (m + n) n ⟩
(C (m + n) n * n !) * m ≡⟨ Lemma.lemma₇ (C (m + n) n) (n !) m ⟩
C (m + n) n * m * n ! ∎
C[n,1+k]*[1+k]≡C[n,k]*[n∸k] : ∀ n k → C n (suc k) * suc k ≡ C n k * (n ∸ k)
C[n,1+k]*[1+k]≡C[n,k]*[n∸k] n k with k ≤? n
... | yes k≤n = begin-equality
C n (suc k) * suc k ≡⟨ cong (λ v → C v (suc k) * suc k) (sym m+k≡n) ⟩
C (m + k) (suc k) * suc k ≡⟨ C[m+n,1+n]*[1+n]≡C[m+n,n]*m m k ⟩
C (m + k) k * m ≡⟨ cong (λ v → C v k * m) m+k≡n ⟩
C n k * (n ∸ k) ∎
where
m = n ∸ k
m+k≡n : m + k ≡ n
m+k≡n = m∸n+n≡m k≤n
... | no k≰n = begin-equality
C n (suc k) * suc k ≡⟨ cong (_* suc k) $ n<k⇒C[n,k]≡0 (≤-step n<k) ⟩
0 * suc k ≡⟨⟩
0 ≡⟨ sym $ *-zeroʳ (C n k) ⟩
C n k * 0 ≡⟨ cong (C n k *_) $ sym $ m≤n⇒m∸n≡0 (<⇒≤ n<k) ⟩
C n k * (n ∸ k) ∎
where
n<k = ≰⇒> k≰n
-- -- C n k = ((n + 1 - k) / k) * C n (k - 1)
C[n,1+k]≡[C[n,k]*[n∸k]]/[1+k] : ∀ n k → C n (1 + k) ≡ (C n k * (n ∸ k)) / (1 + k)
C[n,1+k]≡[C[n,k]*[n∸k]]/[1+k] n k =
Lemma.m*n≡o⇒m≡o/n (C n (suc k)) (suc k) (C n k * (n ∸ k)) tt (C[n,1+k]*[1+k]≡C[n,k]*[n∸k] n k)
-- C n k ≡ (n / k) * C (n - 1) (k - 1)
-- proved by C[n,k]*k!≡P[n,k]
[1+k]*C[1+n,1+k]≡[1+n]*C[n,k] : ∀ n k → suc k * C (suc n) (suc k) ≡ suc n * C n k
[1+k]*C[1+n,1+k]≡[1+n]*C[n,k] n k = Lemma.*-cancelʳ-≡′
(suc k * C (suc n) (suc k)) (suc n * C n k) (False[n!≟0] k) $ begin-equality
suc k * C (suc n) (suc k) * k ! ≡⟨ sym $ Lemma.lemma₈ (C (suc n) (suc k)) (suc k) (k !) ⟩
C (suc n) (suc k) * (suc k) ! ≡⟨ C[n,k]*k!≡P[n,k] (suc n) (suc k) ⟩
P (suc n) (suc k) ≡⟨⟩
suc n * P n k ≡⟨ cong (suc n *_) $ sym $ C[n,k]*k!≡P[n,k] n k ⟩
suc n * (C n k * k !) ≡⟨ sym $ *-assoc (suc n) (C n k) (k !) ⟩
suc n * C n k * k ! ∎
-- Multiply both sides by n ! * o !
C[m,n]*C[m∸n,o]≡C[m,o]*C[m∸o,n] : ∀ m n o → C m n * C (m ∸ n) o ≡ C m o * C (m ∸ o) n
C[m,n]*C[m∸n,o]≡C[m,o]*C[m∸o,n] m n o =
Lemma.*-cancelʳ-≡′ (C m n * C (m ∸ n) o) (C m o * C (m ∸ o) n) (False[n!≟0] n) $
Lemma.*-cancelʳ-≡′ (C m n * C (m ∸ n) o * n !) (C m o * C (m ∸ o) n * n !) (False[n!≟0] o) $ begin-equality
C m n * C (m ∸ n) o * n ! * o ! ≡⟨ Lemma.lemma₁₀ (C m n) (C (m ∸ n) o) (n !) (o !) ⟩
(C m n * n !) * (C (m ∸ n) o * o !) ≡⟨ cong₂ _*_ (C[n,k]*k!≡P[n,k] m n) (C[n,k]*k!≡P[n,k] (m ∸ n) o) ⟩
P m n * P (m ∸ n) o ≡⟨ P-slide-∸ m n o ⟩
P m o * P (m ∸ o) n ≡⟨ sym $ cong₂ _*_ (C[n,k]*k!≡P[n,k] m o) (C[n,k]*k!≡P[n,k] (m ∸ o) n) ⟩
(C m o * o !) * (C (m ∸ o) n * n !) ≡⟨ Lemma.lemma₁₁ (C m o) (o !) (C (m ∸ o) n) (n !) ⟩
C m o * C (m ∸ o) n * n ! * o ! ∎
k≤n⇒1≤C[n,k] : ∀ {n k} → k ≤ n → 1 ≤ C n k
k≤n⇒1≤C[n,k] {n} {k} k≤n = Lemma.*-cancelʳ-≤′ 1 (C n k) (False[n!≟0] k) $ begin
1 * k ! ≡⟨ *-identityˡ (k !) ⟩
k ! ≤⟨ k≤n⇒k!≤P[n,k] k≤n ⟩
P n k ≡⟨ sym $ C[n,k]*k!≡P[n,k] n k ⟩
C n k * k ! ∎
k≤n⇒C[n,k]≢0 : ∀ {n k} → k ≤ n → C n k ≢ 0
k≤n⇒C[n,k]≢0 {n} {k} k≤n = Lemma.1≤n⇒n≢0 $ k≤n⇒1≤C[n,k] k≤n
C[n,k]≡0⇒n<k : ∀ {n k} → C n k ≡ 0 → n < k
C[n,k]≡0⇒n<k {n} {k} C[n,k]≡0 with n <? k
... | yes n<k = n<k
... | no n≮k = ⊥-elim $ k≤n⇒C[n,k]≢0 (≮⇒≥ n≮k) C[n,k]≡0
C[n,k]≢0⇒k≤n : ∀ {n k} → C n k ≢ 0 → k ≤ n
C[n,k]≢0⇒k≤n {n} {k} C[n,k]≢0 with k ≤? n
... | yes k≤n = k≤n
... | no k≰n = ⊥-elim $ C[n,k]≢0 $ n<k⇒C[n,k]≡0 (≰⇒> k≰n)
------------------------------------------------------------------------
-- Properties of double factorial
!!-! : ∀ n → suc n !! * n !! ≡ suc n !
!!-! 0 = refl
!!-! 1 = refl
!!-! (suc (suc n)) = begin-equality
(3 + n) !! * (2 + n) !! ≡⟨⟩
(3 + n) * (1 + n) !! * ((2 + n) * n !!) ≡⟨ Lemma.lemma₉ (3 + n) (suc n !!) (2 + n) (n !!) ⟩
(3 + n) * (2 + n) * ((1 + n) !! * n !!) ≡⟨ cong ((3 + n) * (2 + n) *_) $ !!-! n ⟩
(3 + n) * (2 + n) * (suc n !) ≡⟨ *-assoc (3 + n) (2 + n) (suc n !) ⟩
(3 + n) ! ∎
[2*n]!!≡n!*2^n : ∀ n → (2 * n) !! ≡ n ! * 2 ^ n
[2*n]!!≡n!*2^n 0 = refl
[2*n]!!≡n!*2^n (suc n) = begin-equality
(2 * (1 + n)) !! ≡⟨ cong (_!!) $ *-distribˡ-+ 2 1 n ⟩
(2 + (2 * n)) !! ≡⟨⟩
(2 + 2 * n) * (2 * n) !! ≡⟨ cong ((2 + 2 * n) *_) $ [2*n]!!≡n!*2^n n ⟩
(2 + 2 * n) * (n ! * 2 ^ n) ≡⟨ cong (_* (n ! * 2 ^ n)) $ trans (sym $ *-distribˡ-+ 2 1 n) (*-comm 2 (suc n)) ⟩
(suc n * 2) * ((n !) * 2 ^ n) ≡⟨ Lemma.lemma₉ (suc n) 2 (n !) (2 ^ n) ⟩
(suc n) ! * 2 ^ suc n ∎
------------------------------------------------------------------------
-- Properties of unsigned Stirling number of the first kind
n<k⇒S1[n,k]≡0 : ∀ {n k} → n < k → S1 n k ≡ 0
n<k⇒S1[n,k]≡0 {0} {.(suc _)} (s≤s n<k) = refl
n<k⇒S1[n,k]≡0 {suc n} {.(suc m)} (s≤s {_} {m} n<k) = begin-equality
n * S1 n (suc m) + S1 n m ≡⟨ cong₂ _+_ (cong (n *_) $ n<k⇒S1[n,k]≡0 (≤-step n<k)) (n<k⇒S1[n,k]≡0 n<k) ⟩
n * 0 + 0 ≡⟨ cong (_+ 0) $ *-zeroʳ n ⟩
0 ∎
S1[1+n,1]≡n! : ∀ n → S1 (suc n) 1 ≡ n !
S1[1+n,1]≡n! 0 = refl
S1[1+n,1]≡n! (suc n) = begin-equality
suc n * S1 (suc n) 1 + S1 (suc n) 0 ≡⟨⟩
suc n * S1 (suc n) 1 + 0 ≡⟨ +-identityʳ (suc n * S1 (suc n) 1) ⟩
suc n * S1 (suc n) 1 ≡⟨ cong (suc n *_) $ S1[1+n,1]≡n! n ⟩
(suc n) ! ∎
S1[n,n]≡1 : ∀ n → S1 n n ≡ 1
S1[n,n]≡1 0 = refl
S1[n,n]≡1 (suc n) = begin-equality
n * S1 n (suc n) + S1 n n ≡⟨ cong₂ _+_ (cong (n *_) $ n<k⇒S1[n,k]≡0 {n} {suc n} ≤-refl) (S1[n,n]≡1 n) ⟩
n * 0 + 1 ≡⟨ cong (_+ 1) $ *-zeroʳ n ⟩
1 ∎
S1[1+n,n]≡C[1+n,2] : ∀ n → S1 (suc n) n ≡ C (suc n) 2
S1[1+n,n]≡C[1+n,2] 0 = refl
S1[1+n,n]≡C[1+n,2] (suc n) = begin-equality
S1 (suc (suc n)) (suc n) ≡⟨⟩
suc n * S1 (suc n) (suc n) + S1 (suc n) n ≡⟨ cong₂ _+_ (cong (suc n *_) (S1[n,n]≡1 (suc n))) (S1[1+n,n]≡C[1+n,2] n) ⟩
suc n * 1 + C (suc n) 2 ≡⟨ cong (_+ C (suc n) 2) lemma ⟩
C (suc n) 1 + C (suc n) 2 ≡⟨ sym $ C[1+n,1+k]≡C[n,k]+C[n,1+k] (suc n) 1 ⟩
C (suc (suc n)) 2 ∎
where
lemma : suc n * 1 ≡ C (suc n) 1
lemma = trans (*-identityʳ (suc n)) (sym $ C[n,1]≡n (suc n))
------------------------------------------------------------------------
-- Properties of Stirling number of the second kind
n<k⇒S2[n,k]≡0 : ∀ {n k} → n < k → S2 n k ≡ 0
n<k⇒S2[n,k]≡0 {.0} {.(suc _)} (s≤s z≤n) = refl
n<k⇒S2[n,k]≡0 {.(suc _)} {.(suc (suc _))} (s≤s (s≤s {n} {k} n≤k)) = begin-equality
S2 (suc n) (suc (suc k)) ≡⟨⟩
2+k * S2 n 2+k + S2 n (suc k) ≡⟨ cong₂ _+_ (cong (2+k *_) (n<k⇒S2[n,k]≡0 n<2+k)) (n<k⇒S2[n,k]≡0 n<1+k) ⟩
2+k * 0 + 0 ≡⟨ cong (_+ 0) $ *-zeroʳ 2+k ⟩
0 ∎
where
2+k = suc (suc k)
n<1+k : n < 1 + k
n<1+k = s≤s n≤k
n<2+k : n < 2 + k
n<2+k = ≤-step n<1+k
S2[n,n]≡1 : ∀ n → S2 n n ≡ 1
S2[n,n]≡1 0 = refl
S2[n,n]≡1 (suc n) = begin-equality
suc n * S2 n (suc n) + S2 n n ≡⟨ cong₂ _+_ (cong (suc n *_) (n<k⇒S2[n,k]≡0 {n} {suc n} ≤-refl)) (S2[n,n]≡1 n) ⟩
suc n * 0 + 1 ≡⟨ cong (_+ 1) $ *-zeroʳ (suc n) ⟩
1 ∎
S2[1+n,n]≡C[n,2] : ∀ n → S2 (suc n) n ≡ C (suc n) 2
S2[1+n,n]≡C[n,2] 0 = refl
S2[1+n,n]≡C[n,2] (suc n) = begin-equality
S2 (suc (suc n)) (suc n) ≡⟨⟩
suc n * S2 (suc n) (suc n) + S2 (suc n) n ≡⟨ cong₂ _+_ (cong (suc n *_) (S2[n,n]≡1 (suc n))) (S2[1+n,n]≡C[n,2] n) ⟩
suc n * 1 + C (suc n) 2 ≡⟨ cong (_+ C (suc n) 2) lemma ⟩
C (suc n) 1 + C (suc n) 2 ≡⟨ sym $ C[1+n,1+k]≡C[n,k]+C[n,1+k] (suc n) 1 ⟩
C (suc (suc n)) 2 ∎
where
lemma : suc n * 1 ≡ C (suc n) 1
lemma = trans (*-identityʳ (suc n)) (sym $ C[n,1]≡n (suc n))
{-
1+S2[1+n,2]≡2^n : ∀ n → 1 + S2 (suc n) 2 ≡ 2 ^ n
1+S2[1+n,2]≡2^n 0 = refl
1+S2[1+n,2]≡2^n (suc n) = {! !}
-}
------------------------------------------------------------------------
-- Properties of Lah number
L[0,k]≡0 : ∀ k → L 0 k ≡ 0
L[0,k]≡0 0 = refl
L[0,k]≡0 (suc k) = refl
L-rec : ∀ n k → L (suc n) (suc (suc k)) ≡ (n + suc (suc k)) * L n (suc (suc k)) + L n (suc k)
L-rec 0 k = sym $ trans (+-identityʳ (k * 0)) (*-zeroʳ k)
L-rec (suc n) k = refl
{-
n<k⇒L[n,k]≡0 : ∀ {n k} → n < k → L n k ≡ 0
n<k⇒Lnk≡0 (s≤s z≤n) = refl
n<k⇒Lnk≡0 {.(suc (suc n))} {.(suc (suc k))} (s≤s (s≤s {suc n} {k} n<k)) = begin
(L (suc n) (suc (suc k)) + (n + suc (suc k)) * L (suc n) (suc (suc k))) + L (suc n) (suc k)
≡⟨ cong₂ _+_ (cong₂ _+_ lemma (cong ((n + suc (suc k)) *_) {! !}))n<k⇒L[n,k]≡0 (s≤s n<k)) ⟩
0 + (n + suc (suc k)) * 0 + 0 ≡⟨ {! !} ⟩
0 ∎
where
lemma : L (suc n) (suc (suc k)) ≡ 0
lemma = n<k⇒L[n,k]≡0 (≤-step (s≤s n<k))
L[n,n] : ∀ n → L (suc n) (suc n) ≡ 1
L[n,n] 0 = refl
L[n,n] (suc n) = {! !}
-}
------------------------------------------------------------------------
-- Properties of Pochhammer symbol
Poch[0,1+k]≡0 : ∀ k → Poch 0 (suc k) ≡ 0
Poch[0,1+k]≡0 k = refl
Poch[n,1]≡n : ∀ n → Poch n 1 ≡ n
Poch[n,1]≡n 0 = refl
Poch[n,1]≡n (suc n) = cong suc (*-identityʳ n)
Poch[1+n,k]*n!≡[n+k]! : ∀ n k → Poch (suc n) k * n ! ≡ (n + k) !
Poch[1+n,k]*n!≡[n+k]! n 0 = trans (+-identityʳ (n !)) (sym $ cong (_!) $ +-identityʳ n)
Poch[1+n,k]*n!≡[n+k]! n (suc k) = begin-equality
Poch (suc n) (suc k) * n ! ≡⟨⟩
suc n * Poch (suc (suc n)) k * n ! ≡⟨ Lemma.lemma₁₂ (suc n) (Poch (suc (suc n)) k) (n !) ⟩
Poch (suc (suc n)) k * (suc n) ! ≡⟨ Poch[1+n,k]*n!≡[n+k]! (suc n) k ⟩
(suc n + k) ! ≡⟨ sym $ cong (_!) $ +-suc n k ⟩
(n + suc k) ! ∎
Poch[1,k]≡k! : ∀ k → Poch 1 k ≡ k !
Poch[1,k]≡k! k = Lemma.*-cancelʳ-≡′ (Poch 1 k) (k !) {1 !} tt $ begin-equality
Poch 1 k * 1 ! ≡⟨ Poch[1+n,k]*n!≡[n+k]! 0 k ⟩
k ! ≡⟨ sym $ *-identityʳ (k !) ⟩
k ! * 1 ! ∎
Poch[1+m,n]≡P[m+n,n] : ∀ m n → Poch (suc m) n ≡ P (m + n) n
Poch[1+m,n]≡P[m+n,n] m n =
Lemma.*-cancelʳ-≡′ (Poch (suc m) n) (P (m + n) n) (False[n!≟0] m) $ begin-equality
Poch (suc m) n * m ! ≡⟨ Poch[1+n,k]*n!≡[n+k]! m n ⟩
(m + n) ! ≡⟨ sym $ P[m+n,n]*m!≡[m+n]! m n ⟩
P (m + n) n * m ! ∎
Poch[n,k]≡P[n+k∸1,n] : ∀ n k → Poch n k ≡ P (n + k ∸ 1) k
Poch[n,k]≡P[n+k∸1,n] 0 0 = refl
Poch[n,k]≡P[n+k∸1,n] 0 (suc k) = sym $ n<k⇒P[n,k]≡0 {k} {suc k} ≤-refl
Poch[n,k]≡P[n+k∸1,n] (suc n) k = begin-equality
Poch (suc n) k ≡⟨ Poch[1+m,n]≡P[m+n,n] n k ⟩
P (n + k) k ≡⟨⟩
P (suc n + k ∸ 1) k ∎
Poch[1+[n∸k],k]≡P[n,k] : ∀ {n k} → k ≤ n → Poch (suc (n ∸ k)) k ≡ P n k
Poch[1+[n∸k],k]≡P[n,k] {n} {k} k≤n = begin-equality
Poch (suc m) k ≡⟨ Poch[1+m,n]≡P[m+n,n] m k ⟩
P (m + k) k ≡⟨ cong (λ v → P v k) m+k≡n ⟩
P n k ∎
where
m = n ∸ k
m+k≡n = m∸n+n≡m k≤n
Poch-split : ∀ m n o → Poch m (n + o) ≡ Poch m n * Poch (m + n) o
Poch-split m 0 o = begin-equality
Poch m o ≡⟨ sym $ cong (λ v → Poch v o) $ +-identityʳ m ⟩
Poch (m + 0) o ≡⟨ sym $ +-identityʳ (Poch (m + 0) o) ⟩
Poch (m + 0) o + 0 ∎
Poch-split m (suc n) o = begin-equality
m * Poch (suc m) (n + o) ≡⟨ cong (m *_) $ Poch-split (suc m) n o ⟩
m * (Poch (suc m) n * Poch (suc m + n) o) ≡⟨ sym $ *-assoc m (Poch (suc m) n) (Poch (suc m + n) o) ⟩
m * Poch (suc m) n * Poch (suc m + n) o ≡⟨ cong (λ v → m * Poch (suc m) n * Poch v o) $ sym $ +-suc m n ⟩
m * Poch (suc m) n * Poch (m + suc n) o ∎
o≤n⇒Poch[m,n]≡Poch[m+o,n∸o]*Poch[m,o] :
∀ m {n o} → o ≤ n → Poch m n ≡ Poch (m + o) (n ∸ o) * Poch m o
o≤n⇒Poch[m,n]≡Poch[m+o,n∸o]*Poch[m,o] m {n} {o} o≤n = begin-equality
Poch m n ≡⟨ cong (Poch m) n≡o+p ⟩
Poch m (o + p) ≡⟨ Poch-split m o p ⟩
Poch m o * Poch (m + o) p ≡⟨ *-comm (Poch m o) (Poch (m + o) p) ⟩
Poch (m + o) p * Poch m o ∎
where
p = n ∸ o
n≡o+p : n ≡ o + (n ∸ o)
n≡o+p = trans (sym $ m∸n+n≡m o≤n) (+-comm (n ∸ o) o)
1≤n⇒1≤Poch[n,k] : ∀ {n} k → 1 ≤ n → 1 ≤ Poch n k
1≤n⇒1≤Poch[n,k] {n} zero 1≤n = ≤-refl
1≤n⇒1≤Poch[n,k] {n} (suc k) 1≤n = begin
1 * 1 ≤⟨ *-mono-≤ 1≤n (1≤n⇒1≤Poch[n,k] k (≤-step 1≤n)) ⟩
n * Poch (suc n) k ∎
------------------------------------------------------------------------
-- Properties of Central binomial coefficient
private
2*n≡n+n : ∀ n → 2 * n ≡ n + n
2*n≡n+n n = cong (n +_) $ +-identityʳ n
CB[n]*n!*n!≡[2*n]! : ∀ n → CB n * n ! * n ! ≡ (2 * n) !
CB[n]*n!*n!≡[2*n]! n = begin-equality
C (2 * n) n * n ! * n ! ≡⟨ cong (λ v → C v n * n ! * n !) $ 2*n≡n+n n ⟩
C (n + n) n * n ! * n ! ≡⟨ C[m+n,m]*m!*n!≡[m+n]! n n ⟩
(n + n) ! ≡⟨ cong (_!) $ sym $ 2*n≡n+n n ⟩
(2 * n) ! ∎
CB[1+n]*[1+n]≡2*[1+2*n]*CB[n] : ∀ n → CB (suc n) * suc n ≡ 2 * (1 + 2 * n) * CB n
CB[1+n]*[1+n]≡2*[1+2*n]*CB[n] n = Lemma.*-cancelʳ-≡′
(CB (1 + n) * suc n)
(2 * (1 + 2 * n) * CB n)
{o = suc n * n ! * n !}
(fromWitnessFalse (Lemma.*-pres-≢0
(Lemma.*-pres-≢0 {a = suc n} (λ ()) ((n!≢0 n))) (n!≢0 n)))
( begin-equality
CB (suc n) * suc n * (suc n * n ! * n !)
≡⟨ Lemma.lemma₁₄ (CB (1 + n)) (suc n) (n !) ⟩
CB (suc n) * (suc n) ! * (suc n) !
≡⟨ CB[n]*n!*n!≡[2*n]! (suc n) ⟩
(2 * suc n) !
≡⟨ cong (_!) $ *-distribˡ-+ 2 1 n ⟩
(2 + 2 * n) !
≡⟨⟩
(2 + 2 * n) * ((1 + 2 * n) * (2 * n) !)
≡⟨ sym $ *-assoc (2 + 2 * n) (1 + 2 * n) ((2 * n) !) ⟩
(2 + 2 * n) * (1 + 2 * n) * (2 * n) !
≡⟨ cong (_* (2 * n) !) $ Lemma.lemma₁₅ n ⟩
2 * (1 + 2 * n) * (1 + n) * (2 * n) !
≡⟨ sym $ cong (2 * (1 + 2 * n) * (1 + n) *_) $ CB[n]*n!*n!≡[2*n]! n ⟩
2 * (1 + 2 * n) * (1 + n) * (CB n * n ! * n !)
≡⟨ Lemma.lemma₁₆ (2 * (1 + 2 * n)) (1 + n) (CB n) (n !) ⟩
2 * (1 + 2 * n) * CB n * (suc n * n ! * n !)
∎ )
------------------------------------------------------------------------
-- Properties of Catalan number
-- Catelan n = C (2 * n) n / suc n
private
C[2*n,1+n]*[1+n]≡CB[n]*n : ∀ n → C (2 * n) (1 + n) * (1 + n) ≡ CB n * n
C[2*n,1+n]*[1+n]≡CB[n]*n n = begin-equality
C (2 * n) (1 + n) * (1 + n) ≡⟨ cong (λ v → C v (1 + n) * (1 + n)) $ 2*n≡n+n n ⟩
C (n + n) (1 + n) * (1 + n) ≡⟨ C[m+n,1+n]*[1+n]≡C[m+n,n]*m n n ⟩
C (n + n) n * n ≡⟨ cong (λ v → C v n * n) $ sym $ 2*n≡n+n n ⟩
C (2 * n) n * n ∎
[C[2*n,n]∸C[2*n,1+n]]*[1+n]≡CB[n] : ∀ n → (C (2 * n) n ∸ C (2 * n) (1 + n)) * (1 + n) ≡ CB n
[C[2*n,n]∸C[2*n,1+n]]*[1+n]≡CB[n] n = begin-equality
(C (2 * n) n ∸ C (2 * n) (1 + n)) * (1 + n)
≡⟨ *-distribʳ-∸ (1 + n) (C (2 * n) n) (C (2 * n) (1 + n)) ⟩
C (2 * n) n * (1 + n) ∸ C (2 * n) (1 + n) * (1 + n)
≡⟨ cong (C (2 * n) n * (1 + n) ∸_) $ C[2*n,1+n]*[1+n]≡CB[n]*n n ⟩
C (2 * n) n * (1 + n) ∸ C (2 * n) n * n
≡⟨ sym $ *-distribˡ-∸ (C (2 * n) n) (1 + n) n ⟩
C (2 * n) n * (suc n ∸ n) ≡⟨ cong (C (2 * n) n *_) $ m+n∸n≡m 1 n ⟩
C (2 * n) n * 1 ≡⟨ *-identityʳ (C (2 * n) n) ⟩
C (2 * n) n ∎
Catalan[n]≡C[2*n,n]∸C[2*n,1+n] : ∀ n → Catalan n ≡ C (2 * n) n ∸ C (2 * n) (1 + n)
Catalan[n]≡C[2*n,n]∸C[2*n,1+n] n =
sym $ Lemma.m*n≡o⇒m≡o/n (C (2 * n) n ∸ C (2 * n) (1 + n)) (suc n)
(C (2 * n) n) tt ([C[2*n,n]∸C[2*n,1+n]]*[1+n]≡CB[n] n)
Catalan[n]*[1+n]≡CB[n] : ∀ n → Catalan n * (1 + n) ≡ CB n
Catalan[n]*[1+n]≡CB[n] n = begin-equality
Catalan n * (1 + n) ≡⟨ cong (_* (1 + n)) $ Catalan[n]≡C[2*n,n]∸C[2*n,1+n] n ⟩
(C (2 * n) n ∸ C (2 * n) (1 + n)) * (1 + n) ≡⟨ [C[2*n,n]∸C[2*n,1+n]]*[1+n]≡CB[n] n ⟩
C (2 * n) n ∎
[1+n]!*n!*Catalan[n]≡[2*n]! : ∀ n → (1 + n) ! * n ! * Catalan n ≡ (2 * n) !
[1+n]!*n!*Catalan[n]≡[2*n]! n = begin-equality
(suc n * n !) * n ! * Catalan n ≡⟨ Lemma.lemma₁₃ (suc n) (n !) (Catalan n) ⟩
(Catalan n * suc n) * n ! * n ! ≡⟨ cong (λ v → v * n ! * n !) $ Catalan[n]*[1+n]≡CB[n] n ⟩
CB n * n ! * n ! ≡⟨ CB[n]*n!*n!≡[2*n]! n ⟩
(2 * n) ! ∎
Catalan[n]≡[2*n]!/[[1+n]!*n!] :
∀ n → Catalan n ≡ _/_ ((2 * n) !) ((1 + n) ! * n !) {False[m!*n!≟0] (1 + n) n}
Catalan[n]≡[2*n]!/[[1+n]!*n!] n =
Lemma.m*n≡o⇒m≡o/n (Catalan n) ((1 + n) ! * n !) ((2 * n) !) (False[m!*n!≟0] (1 + n) n)
( begin-equality
Catalan n * (suc n ! * n !) ≡⟨ *-comm (Catalan n) (suc n ! * n !) ⟩
suc n ! * n ! * Catalan n ≡⟨ [1+n]!*n!*Catalan[n]≡[2*n]! n ⟩
(2 * n) ! ∎ )
Catalan[1+n]*[2+n]≡2*[1+2*n]*Catalan[n] : ∀ n →
Catalan (suc n) * (2 + n) ≡ 2 * (1 + 2 * n) * Catalan n
Catalan[1+n]*[2+n]≡2*[1+2*n]*Catalan[n] n = Lemma.*-cancelʳ-≡′
(Catalan (suc n) * (2 + n)) (2 * (1 + 2 * n) * Catalan n) {o = suc n} tt
(begin-equality
Catalan (suc n) * (2 + n) * suc n
≡⟨ cong (_* suc n) $ Catalan[n]*[1+n]≡CB[n] (suc n) ⟩
CB (suc n) * suc n ≡⟨ CB[1+n]*[1+n]≡2*[1+2*n]*CB[n] n ⟩
2 * (1 + 2 * n) * CB n
≡⟨ sym $ cong (2 * (1 + 2 * n) *_) $ Catalan[n]*[1+n]≡CB[n] n ⟩
2 * (1 + 2 * n) * (Catalan n * suc n)
≡⟨ sym $ *-assoc (2 * (1 + 2 * n)) (Catalan n) (suc n) ⟩
2 * (1 + 2 * n) * Catalan n * suc n
∎ )
{- TODO
Catalan[1+n]≡Σ[i≤n][Catalan[i]*Catalan[n∸i]] :
∀ n → Catalan (suc n) ≡ Σ[ i ≤ n ] (Catalan i * Catalan (n ∸ i))
Catalan[1+n]≡Σ[i≤n][Catalan[i]*Catalan[n∸i]] n = ?
-}
------------------------------------------------------------------
-- Properties of Multinomial coefficient
product[map[!,xs]]*Multinomial[xs]≡sum[xs]! :
∀ xs → product (List.map _! xs) * Multinomial xs ≡ sum xs !
product[map[!,xs]]*Multinomial[xs]≡sum[xs]! [] = refl
product[map[!,xs]]*Multinomial[xs]≡sum[xs]! xxs@(x ∷ xs) = begin-equality
x ! * product (List.map _! xs) * (C (sum xxs) x * Multinomial xs)
≡⟨ Lemma.lemma₁₇ (x !) (product (List.map _! xs)) (C (sum xxs) x) (Multinomial xs) ⟩
C (x + sum xs) x * x ! * (product (List.map _! xs) * Multinomial xs)
≡⟨ cong (C (sum xxs) x * x ! *_) $ product[map[!,xs]]*Multinomial[xs]≡sum[xs]! xs ⟩
C (x + sum xs) x * x ! * sum xs !
≡⟨ C[m+n,m]*m!*n!≡[m+n]! x (sum xs) ⟩
(x + sum xs) !
∎
private
1≢0 : 1 ≢ 0
1≢0 ()
product[map[!,xs]]≢0 : ∀ xs → product (List.map _! xs) ≢ 0
product[map[!,xs]]≢0 xs =
foldr-preservesᵇ {P = λ x → x ≢ 0} Lemma.*-pres-≢0
1≢0 (Allₚ.map⁺ {f = _!} $ All.universal n!≢0 xs)
Multinomial[xs]≡sum[xs]!/product[map[!,xs]] :
∀ xs → Multinomial xs ≡ _/_ (sum xs !) (product (List.map _! xs))
{fromWitnessFalse (product[map[!,xs]]≢0 xs)}
Multinomial[xs]≡sum[xs]!/product[map[!,xs]] xs = Lemma.m*n≡o⇒m≡o/n
(Multinomial xs) (product (List.map _! xs)) (sum xs !)
(fromWitnessFalse (product[map[!,xs]]≢0 xs)) (begin-equality
Multinomial xs * product (List.map _! xs)
≡⟨ *-comm (Multinomial xs) (product (List.map _! xs)) ⟩
product (List.map _! xs) * Multinomial xs
≡⟨ product[map[!,xs]]*Multinomial[xs]≡sum[xs]! xs ⟩
sum xs !
∎ )
Multinomial[[x]]≡1 : ∀ x → Multinomial (x ∷ []) ≡ 1
Multinomial[[x]]≡1 x = begin-equality
C (x + 0) x * 1 ≡⟨ *-identityʳ (C (x + 0) x) ⟩
C (x + 0) x ≡⟨ cong (λ v → C v x) $ +-identityʳ x ⟩
C x x ≡⟨ C[n,n]≡1 x ⟩
1 ∎
Multinomial[[m,n]]≡C[m+n,m] : ∀ m n → Multinomial (m ∷ n ∷ []) ≡ C (m + n) m
Multinomial[[m,n]]≡C[m+n,m] m n = begin-equality
C (m + (n + 0)) m * Multinomial (n ∷ [])
≡⟨ cong (C (m + (n + 0)) m *_) $ Multinomial[[x]]≡1 n ⟩
C (m + (n + 0)) m * 1
≡⟨ *-identityʳ (C (m + (n + 0)) m) ⟩
C (m + (n + 0)) m
≡⟨ cong (λ v → C (m + v) m) $ +-identityʳ n ⟩
C (m + n) m
∎
------------------------------------------------------------------------
-- Properties of Pascal's triangle
module _ {a} {A : Set a} where
length-gpascal : ∀ f (v0 v1 : A) n → length (gpascal f v0 v1 n) ≡ suc n
length-gpascal f v0 v1 zero = refl
length-gpascal f v0 v1 (suc n) = begin-equality
length (zipWith f (v0 ∷ ps) (ps ∷ʳ v0))
≡⟨ length-zipWith f (v0 ∷ ps) (ps ∷ʳ v0) ⟩
length (v0 ∷ ps) ⊓ length (ps ∷ʳ v0)
≡⟨ cong (suc (length ps) ⊓_) $ length-++ ps ⟩
suc (length ps) ⊓ (length ps + 1)
≡⟨ cong₂ (λ u v → suc u ⊓ v) hyp (trans (cong (_+ 1) hyp) (+-comm (suc n) 1)) ⟩
suc (suc n) ⊓ (suc (suc n))
≡⟨ ⊓-idem (suc (suc n)) ⟩
suc (suc n)
∎
where
ps = gpascal f v0 v1 n
hyp = length-gpascal f v0 v1 n
| {
"alphanum_fraction": 0.3907135032,
"avg_line_length": 40.7416904084,
"ext": "agda",
"hexsha": "d7b6a6a74cc41cf9d7f6e1ebbdc27abd5a03a164",
"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.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.agda",
"max_line_length": 144,
"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.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": 23842,
"size": 42901
} |
------------------------------------------------------------------------
-- Coinductive higher lenses
------------------------------------------------------------------------
-- Paolo Capriotti came up with these lenses, and provided an informal
-- proof showing that this lens type is pointwise equivalent to his
-- higher lenses. I turned this proof into the proof presented below,
-- with help from Andrea Vezzosi (see
-- Lens.Non-dependent.Higher.Coherently.Coinductive).
{-# OPTIONS --cubical --guardedness #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Coinductive
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
import Coherently-constant eq as CC
open import Colimit.Sequential eq as C using (∣_∣)
open import Equality.Decidable-UIP equality-with-J using (Constant)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
import Equivalence.Half-adjoint equality-with-J as HA
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 eq as T using (∥_∥; ∣_∣)
import H-level.Truncation.Propositional.Non-recursive eq as N
open import H-level.Truncation.Propositional.One-step eq as O
using (∥_∥¹; ∥_∥¹-out-^; ∥_∥¹-in-^; ∣_∣; ∣_,_∣-in-^)
open import Preimage equality-with-J using (_⁻¹_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq
import Lens.Non-dependent.Higher eq as H
import Lens.Non-dependent.Higher.Capriotti eq as Higher
open import Lens.Non-dependent.Higher.Coherently.Coinductive eq
private
variable
a b p : Level
A B : Type a
P : A → Type p
f : (x : A) → P x
------------------------------------------------------------------------
-- Weakly constant functions
-- A variant of Constant.
Constant′ :
{A : Type a} {B : Type b} →
(A → B) → Type (a ⊔ b)
Constant′ {A = A} {B = B} f =
∃ λ (g : ∥ A ∥¹ → B) → ∀ x → g ∣ x ∣ ≡ f x
-- Constant and Constant′ are pointwise equivalent.
Constant≃Constant′ : (f : A → B) → Constant f ≃ Constant′ f
Constant≃Constant′ f = Eq.↔→≃
(λ c → O.rec′ f c
, λ x → O.rec′ f c ∣ x ∣ ≡⟨⟩
f x ∎)
(λ (g , h) x y →
f x ≡⟨ sym (h x) ⟩
g ∣ x ∣ ≡⟨ cong g (O.∣∣-constant x y) ⟩
g ∣ y ∣ ≡⟨ h y ⟩∎
f y ∎)
(λ (g , h) →
let lem = O.elim λ where
.O.Elim.∣∣ʳ x →
f x ≡⟨ sym (h x) ⟩∎
g ∣ x ∣ ∎
.O.Elim.∣∣-constantʳ x y →
let g′ = O.rec′ f λ x y →
trans (sym (h x))
(trans (cong g (O.∣∣-constant x y))
(h y))
in
subst (λ z → g′ z ≡ g z) (O.∣∣-constant x y) (sym (h x)) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong g′ (O.∣∣-constant x y)))
(trans (sym (h x)) (cong g (O.∣∣-constant x y))) ≡⟨ cong (flip trans _) $ cong sym
O.rec-∣∣-constant ⟩
trans (sym (trans (sym (h x))
(trans (cong g (O.∣∣-constant x y))
(h y))))
(trans (sym (h x)) (cong g (O.∣∣-constant x y))) ≡⟨ trans (cong (flip trans _) $
trans (cong sym $ sym $ trans-assoc _ _ _) $
sym-trans _ _) $
trans-[trans-sym]- _ _ ⟩∎
sym (h y) ∎
in
Σ-≡,≡→≡
(⟨ext⟩ lem)
(⟨ext⟩ λ x →
subst (λ g → ∀ x → g ∣ x ∣ ≡ f x)
(⟨ext⟩ lem) (λ x → refl (f x)) x ≡⟨ sym $ push-subst-application _ _ ⟩
subst (λ g → g ∣ x ∣ ≡ f x) (⟨ext⟩ lem) (refl (f x)) ≡⟨ subst-∘ _ _ _ ⟩
subst (_≡ f x) (cong (_$ ∣ x ∣) (⟨ext⟩ lem)) (refl (f x)) ≡⟨ subst-trans-sym ⟩
trans (sym (cong (_$ ∣ x ∣) (⟨ext⟩ lem))) (refl (f x)) ≡⟨ trans-reflʳ _ ⟩
sym (cong (_$ ∣ x ∣) (⟨ext⟩ lem)) ≡⟨ cong sym $ cong-ext _ ⟩
sym (lem ∣ x ∣) ≡⟨⟩
sym (sym (h x)) ≡⟨ sym-sym _ ⟩∎
h x ∎))
(λ c → ⟨ext⟩ λ x → ⟨ext⟩ λ y →
trans (sym (refl _))
(trans (cong (O.rec′ f c) (O.∣∣-constant x y)) (refl _)) ≡⟨ trans (cong₂ trans sym-refl (trans-reflʳ _)) $
trans-reflˡ _ ⟩
cong (O.rec′ f c) (O.∣∣-constant x y) ≡⟨ O.rec-∣∣-constant ⟩∎
c x y ∎)
------------------------------------------------------------------------
-- Coherently constant functions
-- Coherently constant functions.
Coherently-constant :
{A : Type a} {B : Type b} (f : A → B) → Type (a ⊔ b)
Coherently-constant = Coherently Constant O.rec′
-- Coherently constant functions are weakly constant.
constant : Coherently-constant f → Constant f
constant c = c .property
-- An alternative to Coherently-constant.
Coherently-constant′ :
{A : Type a} {B : Type b} (f : A → B) → Type (a ⊔ b)
Coherently-constant′ = Coherently Constant′ (λ _ → proj₁)
-- Coherently-constant and Coherently-constant′ are pointwise
-- equivalent (assuming univalence).
Coherently-constant≃Coherently-constant′ :
Block "Coherently-constant≃Coherently-constant′" →
{A : Type a} {B : Type b} {f : A → B} →
Univalence (a ⊔ b) →
Coherently-constant f ≃ Coherently-constant′ f
Coherently-constant≃Coherently-constant′ ⊠ univ =
Coherently-cong univ
Constant≃Constant′
(λ f c →
O.rec′ f (_≃_.from (Constant≃Constant′ f) c) ≡⟨⟩
proj₁ (_≃_.to (Constant≃Constant′ f)
(_≃_.from (Constant≃Constant′ f) c)) ≡⟨ cong proj₁ $
_≃_.right-inverse-of (Constant≃Constant′ f) _ ⟩∎
proj₁ c ∎)
private
-- Some definitions used in the implementation of
-- ∃Coherently-constant′≃.
module ∃Coherently-constant′≃ where
to₁ :
(f : A → B) → Coherently-constant′ f →
∀ n → ∥ A ∥¹-in-^ n → B
to₁ f c zero = f
to₁ f c (suc n) = to₁ (proj₁ (c .property)) (c .coherent) n
to₂ :
∀ (f : A → B) (c : Coherently-constant′ f) n x →
to₁ f c (suc n) ∣ n , x ∣-in-^ ≡ to₁ f c n x
to₂ f c zero = proj₂ (c .property)
to₂ f c (suc n) = to₂ (proj₁ (c .property)) (c .coherent) n
from :
(f : ∀ n → ∥ A ∥¹-in-^ n → B) →
(∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) →
Coherently-constant′ (f 0)
from f c .property = f 1 , c 0
from f c .coherent = from (f ∘ suc) (c ∘ suc)
from-to :
(f : A → B) (c : Coherently-constant′ f) →
from (to₁ f c) (to₂ f c) P.≡ c
from-to f c i .property = (c .property P.∎) i
from-to f c i .coherent =
from-to (proj₁ (c .property)) (c .coherent) i
to₁-from :
(f : ∀ n → ∥ A ∥¹-in-^ n → B)
(c : ∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) →
∀ n x → to₁ (f 0) (from f c) n x ≡ f n x
to₁-from f c zero = refl ∘ f 0
to₁-from f c (suc n) = to₁-from (f ∘ suc) (c ∘ suc) n
to₂-from :
(f : ∀ n → ∥ A ∥¹-in-^ n → B)
(c : ∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) →
∀ n x →
trans (sym (to₁-from f c (suc n) ∣ n , x ∣-in-^))
(trans (to₂ (f 0) (from f c) n x)
(to₁-from f c n x)) ≡
c n x
to₂-from f c (suc n) = to₂-from (f ∘ suc) (c ∘ suc) n
to₂-from f c zero = λ x →
trans (sym (refl _)) (trans (c 0 x) (refl _)) ≡⟨ trans (cong (flip trans _) sym-refl) $
trans-reflˡ _ ⟩
trans (c 0 x) (refl _) ≡⟨ trans-reflʳ _ ⟩∎
c 0 x ∎
-- "Functions from A to B that are coherently constant" can be
-- expressed in a different way.
∃Coherently-constant′≃ :
(∃ λ (f : A → B) → Coherently-constant′ f)
≃
(∃ λ (f : ∀ n → ∥ A ∥¹-in-^ n → B) →
∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x)
∃Coherently-constant′≃ = Eq.↔→≃
(λ (f , c) → to₁ f c , to₂ f c)
(λ (f , c) → f 0 , from f c)
(λ (f , c) → Σ-≡,≡→≡
(⟨ext⟩ λ n → ⟨ext⟩ λ x → to₁-from f c n x)
(⟨ext⟩ λ n → ⟨ext⟩ λ x →
subst (λ f → ∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x)
(⟨ext⟩ λ n → ⟨ext⟩ λ x → to₁-from f c n x)
(to₂ (f 0) (from f c))
n x ≡⟨ trans (cong (_$ x) $ sym $
push-subst-application _ _) $
sym $ push-subst-application _ _ ⟩
subst (λ f → f (suc n) ∣ n , x ∣-in-^ ≡ f n x)
(⟨ext⟩ λ n → ⟨ext⟩ λ x → to₁-from f c n x)
(to₂ (f 0) (from f c) n x) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (λ f → f (suc n) ∣ n , x ∣-in-^)
(⟨ext⟩ λ n → ⟨ext⟩ λ x → to₁-from f c n x)))
(trans (to₂ (f 0) (from f c) n x)
(cong (λ f → f n x)
(⟨ext⟩ λ n → ⟨ext⟩ λ x → to₁-from f c n x))) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (to₂ (f 0) (from f c) n x) q))
(trans (sym $ cong-∘ _ _ _) $
trans (cong (cong _) $ cong-ext _) $
cong-ext _)
(trans (sym $ cong-∘ _ _ _) $
trans (cong (cong _) $ cong-ext _) $
cong-ext _) ⟩
trans (sym (to₁-from f c (suc n) ∣ n , x ∣-in-^))
(trans (to₂ (f 0) (from f c) n x)
(to₁-from f c n x)) ≡⟨ to₂-from f c n x ⟩∎
c n x ∎))
(λ (f , c) → cong (f ,_) $ _↔_.from ≡↔≡ $ from-to f c)
where
open ∃Coherently-constant′≃
private
-- A lemma that is used in the implementation of
-- Coherently-constant′≃.
Coherently-constant′≃-lemma :
(∃ λ (f : A → B) → Coherently-constant′ f) ≃
(∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
(∀ x → g 0 ∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) ∣ n , x ∣-in-^ ≡ g n x))
Coherently-constant′≃-lemma {A = A} {B = B} =
(∃ λ (f : A → B) → Coherently-constant′ f) ↝⟨ ∃Coherently-constant′≃ ⟩
(∃ λ (f : ∀ n → ∥ A ∥¹-in-^ n → B) →
∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) ↝⟨ Eq.↔→≃
(λ (f , eq) →
f 0 , f ∘ suc , ℕ-case (eq 0) (eq ∘ suc))
(λ (f , g , eq) → ℕ-case f g , eq)
(λ (f , g , eq) →
cong (λ eq → f , g , eq) $ ⟨ext⟩ $
ℕ-case (refl _) (λ _ → refl _))
lemma ⟩
(∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
∀ n x →
g n ∣ n , x ∣-in-^ ≡
ℕ-case {P = λ n → ∥ A ∥¹-in-^ n → B} f g n x) ↝⟨ (∃-cong λ _ → ∃-cong λ _ →
Πℕ≃ ext) ⟩□
(∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
(∀ x → g 0 ∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) ∣ n , x ∣-in-^ ≡ g n x)) □
where
-- An alternative (unused) proof of the second step above. If this
-- proof is used instead of the other one, then the proof of
-- from-Coherently-constant′≃ below fails (at least at the time of
-- writing).
second-step :
(∃ λ (f : ∀ n → ∥ A ∥¹-in-^ n → B) →
∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) ≃
(∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
∀ n x →
g n ∣ n , x ∣-in-^ ≡
ℕ-case {P = λ n → ∥ A ∥¹-in-^ n → B} f g n x)
second-step = from-bijection $ inverse $
(Σ-cong (inverse $ Πℕ≃ {k = equivalence} ext) λ _ → F.id) F.∘
Σ-assoc
abstract
lemma :
(p@(f , eq) : ∃ λ (f : ∀ n → ∥ A ∥¹-in-^ n → B) →
∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) →
(ℕ-case (f 0) (f ∘ suc) , ℕ-case (eq 0) (eq ∘ suc)) ≡ p
lemma (f , eq) =
Σ-≡,≡→≡
(⟨ext⟩ $ ℕ-case (refl _) (λ _ → refl _))
(⟨ext⟩ λ n → ⟨ext⟩ λ x →
let eq′ = ℕ-case (eq 0) (eq ∘ suc)
r = ℕ-case (refl _) (λ _ → refl _)
in
subst {y = f}
(λ f → ∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x)
(⟨ext⟩ r) eq′ n x ≡⟨ sym $
trans (push-subst-application _ _) $
cong (_$ x) $ push-subst-application _ _ ⟩
subst
(λ f → f (suc n) ∣ n , x ∣-in-^ ≡ f n x)
(⟨ext⟩ r) (eq′ n x) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (λ f → f (suc n) ∣ n , x ∣-in-^) (⟨ext⟩ r)))
(trans (eq′ n x) (cong (λ f → f n x) (⟨ext⟩ r))) ≡⟨ trans (cong (flip trans _) $
trans (cong sym $
trans (sym $ cong-∘ _ _ _) $
trans (cong (cong (_$ ∣ n , x ∣-in-^)) $
cong-ext _)
(cong-refl _))
sym-refl) $
trans-reflˡ _ ⟩
trans (eq′ n x) (cong (λ f → f n x) (⟨ext⟩ r)) ≡⟨ cong (trans _) $
trans (sym $ cong-∘ _ _ _) $
cong (cong (_$ x)) $
cong-ext _ ⟩
trans (eq′ n x) (cong (_$ x) $ r n) ≡⟨ ℕ-case
{P = λ n → ∀ x → trans (eq′ n x) (cong (_$ x) $ r n) ≡ eq n x}
(λ _ → trans (cong (trans _) $ cong-refl _) $
trans-reflʳ _)
(λ _ _ → trans (cong (trans _) $ cong-refl _) $
trans-reflʳ _)
n x ⟩∎
eq n x ∎)
-- Coherently-constant′ can be expressed in a different way.
Coherently-constant′≃ :
Block "Coherently-constant′≃" →
{f : A → B} →
Coherently-constant′ f
≃
(∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
(∀ x → g 0 ∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) ∣ n , x ∣-in-^ ≡ g n x))
Coherently-constant′≃ ⊠ {f = f} =
Eq.⟨ _
, Eq.drop-Σ-map-id _
(_≃_.is-equivalence Coherently-constant′≃-lemma)
f
⟩
-- A "computation" rule for Coherently-constant′≃.
from-Coherently-constant′≃-property :
(bl : Block "Coherently-constant′≃") →
(f : A → B)
{c@(g , g₀ , _) :
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
(∀ x → g 0 ∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) ∣ n , x ∣-in-^ ≡ g n x)} →
_≃_.from (Coherently-constant′≃ bl) c .property ≡ (g 0 , g₀)
from-Coherently-constant′≃-property
{A = A} {B = B} ⊠ f {c = c@(g , g₀ , g₊)} =
_≃_.from (Coherently-constant′≃ ⊠) c .property ≡⟨⟩
HA.inverse
(Eq.drop-Σ-map-id _
(_≃_.is-equivalence Coherently-constant′≃-lemma)
f)
c .property ≡⟨ cong (λ c → c .property) $
Eq.inverse-drop-Σ-map-id
{x = f} {eq = _≃_.is-equivalence Coherently-constant′≃-lemma} ⟩
subst Coherently-constant′
(cong proj₁ $
_≃_.right-inverse-of Coherently-constant′≃-lemma (f , c))
(proj₂ (_≃_.from Coherently-constant′≃-lemma (f , c)))
.property ≡⟨ subst-Coherently-property ⟩
subst Constant′
(cong proj₁ $
_≃_.right-inverse-of Coherently-constant′≃-lemma (f , c))
(proj₂ (_≃_.from Coherently-constant′≃-lemma (f , c)) .property) ≡⟨⟩
subst Constant′
(cong proj₁ $
trans
(cong {B = ∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
(∀ x → g 0 ∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) ∣ n , x ∣-in-^ ≡ g n x)}
(λ (f , eq) → f 0 , f ∘ suc , eq 0 , eq ∘ suc) $
_≃_.right-inverse-of ∃Coherently-constant′≃
(ℕ-case f g , ℕ-case g₀ g₊)) $
trans
(cong (λ (f , g , eq) → f , g , eq 0 , eq ∘ suc) $
cong {B = ∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
∀ n x →
g n ∣ n , x ∣-in-^ ≡
ℕ-case {P = λ n → ∥ A ∥¹-in-^ n → B} f g n x}
{x = ℕ-case g₀ g₊}
{y = ℕ-case g₀ g₊}
(λ eq → f , g , eq) $
⟨ext⟩ (ℕ-case (refl _) (λ _ → refl _))) $
cong (f ,_) (cong (g ,_) (refl _)))
(g 0 , g₀) ≡⟨ cong (flip (subst Constant′) _) lemma ⟩
subst Constant′ (refl _) (g 0 , g₀) ≡⟨ subst-refl _ _ ⟩∎
g 0 , g₀ ∎
where
lemma =
(cong proj₁ $
trans
(cong {B = ∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
(∀ x → g 0 ∣ x ∣ ≡ f x) ×
(∀ n x → g (suc n) ∣ n , x ∣-in-^ ≡ g n x)}
(λ (f , eq) → f 0 , f ∘ suc , eq 0 , eq ∘ suc) $
_≃_.right-inverse-of ∃Coherently-constant′≃
(ℕ-case f g , ℕ-case g₀ g₊)) $
trans
(cong (λ (f , g , eq) → f , g , eq 0 , eq ∘ suc) $
cong {B = ∃ λ (f : A → B) →
∃ λ (g : ∀ n → ∥ A ∥¹-in-^ (suc n) → B) →
∀ n x →
g n ∣ n , x ∣-in-^ ≡
ℕ-case {P = λ n → ∥ A ∥¹-in-^ n → B} f g n x}
{x = ℕ-case g₀ g₊}
{y = ℕ-case g₀ g₊}
(λ eq → f , g , eq) $
⟨ext⟩ (ℕ-case (refl _) (λ _ → refl _))) $
cong (f ,_) (cong (g ,_) (refl _))) ≡⟨ trans (cong-trans _ _ _) $
cong₂ trans
(trans (cong-∘ _ _ _) $
sym $ cong-∘ _ _ _)
(trans (cong-trans _ _ _) $
cong₂ trans
(trans (cong-∘ _ _ _) $
cong-∘ _ _ _)
(cong-∘ _ _ _)) ⟩
(trans
(cong (_$ 0) $ cong proj₁ $
_≃_.right-inverse-of ∃Coherently-constant′≃
(ℕ-case f g , ℕ-case g₀ g₊)) $
trans
(cong (const f) $
⟨ext⟩ (ℕ-case (refl _) (λ _ → refl _))) $
cong (const f) (cong (g ,_) (refl _))) ≡⟨ trans (cong (trans _) $
trans (cong₂ trans
(cong-const _)
(cong-const _)) $
trans-refl-refl) $
trans-reflʳ _ ⟩
(cong (_$ 0) $ cong proj₁ $
_≃_.right-inverse-of ∃Coherently-constant′≃
(ℕ-case f g , ℕ-case g₀ g₊)) ≡⟨ cong (cong (_$ 0)) $
proj₁-Σ-≡,≡→≡ _ _ ⟩
(cong (_$ 0) $ ⟨ext⟩ λ n → ⟨ext⟩ λ x →
∃Coherently-constant′≃.to₁-from (ℕ-case f g) (ℕ-case g₀ g₊) n x) ≡⟨ cong-ext _ ⟩
(⟨ext⟩ λ x →
∃Coherently-constant′≃.to₁-from (ℕ-case f g) (ℕ-case g₀ g₊) 0 x) ≡⟨⟩
(⟨ext⟩ λ _ → refl _) ≡⟨ ext-refl ⟩∎
refl _ ∎
-- Functions from ∥ A ∥ can be expressed as coherently constant
-- functions from A (assuming univalence).
∥∥→≃ :
∀ {A : Type a} {B : Type b} →
Univalence (a ⊔ b) →
(∥ A ∥ → B)
≃
(∃ λ (f : A → B) → Coherently-constant f)
∥∥→≃ {A = A} {B = B} univ =
(∥ A ∥ → B) ↝⟨ N.∥∥→≃ ⟩
(∃ λ (f : ∀ n → ∥ A ∥¹-out-^ n → B) →
∀ n x → f (suc n) ∣ x ∣ ≡ f n x) ↝⟨ (Σ-cong {k₁ = equivalence} (∀-cong ext λ n → →-cong₁ ext (O.∥∥¹-out-^≃∥∥¹-in-^ n)) λ f →
∀-cong ext λ n →
Π-cong-contra ext (inverse $ O.∥∥¹-out-^≃∥∥¹-in-^ n) λ x →
≡⇒↝ _ $ cong (λ y → f (suc n) y ≡ f n (_≃_.from (O.∥∥¹-out-^≃∥∥¹-in-^ n) x)) (
∣ _≃_.from (O.∥∥¹-out-^≃∥∥¹-in-^ n) x ∣ ≡⟨ sym $ O.∣,∣-in-^≡∣∣ n ⟩∎
_≃_.from (O.∥∥¹-out-^≃∥∥¹-in-^ (suc n))
∣ n , x ∣-in-^ ∎)) ⟩
(∃ λ (f : ∀ n → ∥ A ∥¹-in-^ n → B) →
∀ n x → f (suc n) ∣ n , x ∣-in-^ ≡ f n x) ↝⟨ inverse ∃Coherently-constant′≃ ⟩
(∃ λ (f : A → B) → Coherently-constant′ f) ↝⟨ (∃-cong λ _ → inverse $ Coherently-constant≃Coherently-constant′ ⊠ univ) ⟩□
(∃ λ (f : A → B) → Coherently-constant f) □
-- A function used in the statement of proj₂-to-∥∥→≃-property≡.
proj₁-to-∥∥→≃-constant :
{A : Type a} {B : Type b}
(univ : Univalence (a ⊔ b)) →
(f : ∥ A ∥ → B) →
Constant (proj₁ (_≃_.to (∥∥→≃ univ) f))
proj₁-to-∥∥→≃-constant _ f x y =
f ∣ x ∣ ≡⟨ cong f (T.truncation-is-proposition ∣ x ∣ ∣ y ∣) ⟩∎
f ∣ y ∣ ∎
-- A "computation rule" for ∥∥→≃.
proj₂-to-∥∥→≃-property≡ :
{A : Type a} {B : Type b}
(univ : Univalence (a ⊔ b)) →
{f : ∥ A ∥ → B} →
proj₂ (_≃_.to (∥∥→≃ univ) f) .property ≡
proj₁-to-∥∥→≃-constant univ f
proj₂-to-∥∥→≃-property≡ univ {f = f} = ⟨ext⟩ λ x → ⟨ext⟩ λ y →
let g , c = _≃_.to C.universal-property (f ∘ _≃_.to N.∥∥≃∥∥) in
proj₂ (_≃_.to (∥∥→≃ univ) f) .property x y ≡⟨⟩
_≃_.from (Coherently-constant≃Coherently-constant′ ⊠ univ)
(proj₂
(_≃_.from ∃Coherently-constant′≃
(Σ-map (λ g n → g n ∘ _≃_.from (oi n))
(λ {g} c n x →
≡⇒→ (cong (λ y → g (suc n) y ≡
g n (_≃_.from (oi n) x))
(sym $ O.∣,∣-in-^≡∣∣ n))
(c n (_≃_.from (oi n) x)))
(_≃_.to C.universal-property (f ∘ _≃_.to N.∥∥≃∥∥)))))
.property x y ≡⟨⟩
_≃_.from (Constant≃Constant′ _)
(proj₂
(_≃_.from ∃Coherently-constant′≃
(Σ-map (λ g n → g n ∘ _≃_.from (oi n))
(λ {g} c n x →
≡⇒→ (cong (λ y → g (suc n) y ≡
g n (_≃_.from (oi n) x))
(sym $ O.∣,∣-in-^≡∣∣ n))
(c n (_≃_.from (oi n) x)))
(_≃_.to C.universal-property (f ∘ _≃_.to N.∥∥≃∥∥))))
.property)
x y ≡⟨⟩
_≃_.from (Constant≃Constant′ _)
( g 1
, λ x → ≡⇒→ (cong (λ z → g 1 z ≡ g 0 x) (sym $ refl ∣ _ ∣)) (c 0 x)
) x y ≡⟨⟩
trans (sym (≡⇒→ (cong (λ z → g 1 z ≡ g 0 x) (sym $ refl ∣ _ ∣))
(c 0 x)))
(trans (cong (g 1) (O.∣∣-constant x y))
(≡⇒→ (cong (λ z → g 1 z ≡ g 0 y) (sym $ refl ∣ _ ∣)) (c 0 y))) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (cong (g 1) (O.∣∣-constant x y)) q))
(trans (cong (λ eq → ≡⇒→ (cong (λ z → g 1 z ≡ g 0 x) eq) (c 0 x))
sym-refl) $
trans (cong (λ eq → ≡⇒→ eq (c 0 x)) $
cong-refl _) $
cong (_$ c 0 x) ≡⇒→-refl)
(trans (cong (λ eq → ≡⇒→ (cong (λ z → g 1 z ≡ g 0 y) eq) (c 0 y))
sym-refl) $
trans (cong (λ eq → ≡⇒→ eq (c 0 y)) $
cong-refl _) $
cong (_$ c 0 y) ≡⇒→-refl) ⟩
trans (sym (c 0 x)) (trans (cong (g 1) (O.∣∣-constant x y)) (c 0 y)) ≡⟨⟩
trans (sym (cong (f ∘ _≃_.to N.∥∥≃∥∥) (C.∣∣≡∣∣ x)))
(trans (cong (f ∘ _≃_.to N.∥∥≃∥∥ ∘ ∣_∣) (O.∣∣-constant x y))
(cong (f ∘ _≃_.to N.∥∥≃∥∥) (C.∣∣≡∣∣ y))) ≡⟨ cong₂ (λ p q → trans (sym p) q)
(sym $ cong-∘ _ _ _)
(cong₂ trans
(sym $ cong-∘ _ _ _)
(sym $ cong-∘ _ _ _)) ⟩
trans (sym (cong f (cong (_≃_.to N.∥∥≃∥∥) (C.∣∣≡∣∣ x))))
(trans (cong f (cong (_≃_.to N.∥∥≃∥∥ ∘ ∣_∣) (O.∣∣-constant x y)))
(cong f (cong (_≃_.to N.∥∥≃∥∥) (C.∣∣≡∣∣ y)))) ≡⟨ trans (cong₂ trans
(sym $ cong-sym _ _)
(sym $ cong-trans _ _ _)) $
sym $ cong-trans _ _ _ ⟩
cong f
(trans (sym (cong (_≃_.to N.∥∥≃∥∥) (C.∣∣≡∣∣ x)))
(trans (cong (_≃_.to N.∥∥≃∥∥ ∘ ∣_∣) (O.∣∣-constant x y))
(cong (_≃_.to N.∥∥≃∥∥) (C.∣∣≡∣∣ y)))) ≡⟨ cong (cong f) $
mono₁ 1 T.truncation-is-proposition _ _ ⟩∎
cong f (T.truncation-is-proposition ∣ x ∣ ∣ y ∣) ∎
where
oi = O.∥∥¹-out-^≃∥∥¹-in-^
-- Two variants of Coherently-constant are pointwise equivalent
-- (assuming univalence).
Coherently-constant≃Coherently-constant :
{A : Type a} {B : Type b} {f : A → B} →
Univalence (a ⊔ b) →
CC.Coherently-constant f ≃ Coherently-constant f
Coherently-constant≃Coherently-constant {A = A} {B = B} {f = f} univ =
CC.Coherently-constant f ↔⟨⟩
(∃ λ (g : ∥ A ∥ → B) → f ≡ g ∘ ∣_∣) ↝⟨ (Σ-cong (∥∥→≃ univ) λ _ → F.id) ⟩
(∃ λ ((g , _) : ∃ λ (g : A → B) → Coherently-constant g) → f ≡ g) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (g : A → B) → Coherently-constant g × f ≡ g) ↝⟨ (∃-cong λ _ → ×-cong₁ λ eq → ≡⇒↝ _ $
cong Coherently-constant $ sym eq) ⟩
(∃ λ (g : A → B) → Coherently-constant f × f ≡ g) ↔⟨ ∃-comm ⟩
Coherently-constant f × (∃ λ (g : A → B) → f ≡ g) ↔⟨ (drop-⊤-right λ _ →
_⇔_.to contractible⇔↔⊤ (other-singleton-contractible _)) ⟩□
Coherently-constant f □
-- A "computation rule" for Coherently-constant≃Coherently-constant.
to-Coherently-constant≃Coherently-constant-property :
∀ {A : Type a} {B : Type b} {f : A → B}
{c : CC.Coherently-constant f} {x y}
(univ : Univalence (a ⊔ b)) →
_≃_.to (Coherently-constant≃Coherently-constant univ)
c .property x y ≡
trans (cong (_$ x) (proj₂ c))
(trans (proj₁-to-∥∥→≃-constant univ (proj₁ c) _ _)
(cong (_$ y) (sym (proj₂ c))))
to-Coherently-constant≃Coherently-constant-property
{f = f} {c = c} {x = x} {y = y} univ =
_≃_.to (Coherently-constant≃Coherently-constant univ)
c .property x y ≡⟨⟩
≡⇒→ (cong Coherently-constant $ sym (proj₂ c))
(proj₂ (_≃_.to (∥∥→≃ univ) (proj₁ c))) .property x y ≡⟨ cong (λ (c : Coherently-constant _) → c .property x y) $ sym $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst Coherently-constant (sym (proj₂ c))
(proj₂ (_≃_.to (∥∥→≃ univ) (proj₁ c))) .property x y ≡⟨ cong (λ (f : Constant _) → f x y)
subst-Coherently-property ⟩
subst Constant (sym (proj₂ c))
(proj₂ (_≃_.to (∥∥→≃ univ) (proj₁ c)) .property) x y ≡⟨ trans (cong (_$ y) $ sym $ push-subst-application _ _) $
sym $ push-subst-application _ _ ⟩
subst (λ f → f x ≡ f y) (sym (proj₂ c))
(proj₂ (_≃_.to (∥∥→≃ univ) (proj₁ c)) .property x y) ≡⟨ cong (λ (f : Constant _) → subst (λ f → f x ≡ f y) (sym (proj₂ c)) (f x y)) $
proj₂-to-∥∥→≃-property≡ univ ⟩
subst (λ f → f x ≡ f y) (sym (proj₂ c))
(proj₁-to-∥∥→≃-constant univ (proj₁ c) x y) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (_$ x) (sym (proj₂ c))))
(trans (proj₁-to-∥∥→≃-constant univ (proj₁ c) _ _)
(cong (_$ y) (sym (proj₂ c)))) ≡⟨ cong (flip trans _) $
trans (sym $ cong-sym _ _) $
cong (cong (_$ x)) $ sym-sym _ ⟩∎
trans (cong (_$ x) (proj₂ c))
(trans (proj₁-to-∥∥→≃-constant univ (proj₁ c) _ _)
(cong (_$ y) (sym (proj₂ c)))) ∎
------------------------------------------------------------------------
-- Lenses, defined as getters with coherently constant fibres
-- The lens type family.
Lens : Type a → Type b → Type (lsuc (a ⊔ b))
Lens A B = ∃ λ (get : A → B) → Coherently-constant (get ⁻¹_)
-- Some derived definitions.
module Lens {A : Type a} {B : Type b} (l : Lens A B) where
-- A getter.
get : A → B
get = proj₁ l
-- The family of fibres of the getter is coherently constant.
get⁻¹-coherently-constant : Coherently-constant (get ⁻¹_)
get⁻¹-coherently-constant = proj₂ l
-- All the getter's fibres are equivalent.
get⁻¹-constant : (b₁ b₂ : B) → get ⁻¹ b₁ ≃ get ⁻¹ b₂
get⁻¹-constant b₁ b₂ =
≡⇒≃ (get⁻¹-coherently-constant .property b₁ b₂)
-- A setter.
set : A → B → A
set a b = $⟨ _≃_.to (get⁻¹-constant (get a) b) ⟩
(get ⁻¹ get a → get ⁻¹ b) ↝⟨ _$ (a , refl _) ⟩
get ⁻¹ b ↝⟨ proj₁ ⟩□
A □
instance
-- The lenses defined above have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
-- Lens is pointwise equivalent to Higher.Lens (assuming univalence).
Higher-lens≃Lens :
{A : Type a} {B : Type b} →
Block "Higher-lens≃Lens" →
Univalence (lsuc (a ⊔ b)) →
Higher.Lens A B ≃ Lens A B
Higher-lens≃Lens {A = A} {B = B} ⊠ univ =
Higher.Lens A B ↔⟨⟩
(∃ λ (get : A → B) → CC.Coherently-constant (get ⁻¹_)) ↝⟨ (∃-cong λ _ → Coherently-constant≃Coherently-constant univ) ⟩□
(∃ λ (get : A → B) → Coherently-constant (get ⁻¹_)) □
-- The equivalence preserves getters and setters.
Higher-lens≃Lens-preserves-getters-and-setters :
{A : Type a} {B : Type b}
(bl : Block "Higher-lens≃Lens")
(univ : Univalence (lsuc (a ⊔ b))) →
Preserves-getters-and-setters-⇔ A B
(_≃_.logical-equivalence (Higher-lens≃Lens bl univ))
Higher-lens≃Lens-preserves-getters-and-setters {A = A} {B = B} bl univ =
Preserves-getters-and-setters-→-↠-⇔
(_≃_.surjection (Higher-lens≃Lens bl univ))
(λ l → get-lemma bl l , set-lemma bl l)
where
get-lemma :
∀ bl (l : Higher.Lens A B) →
Lens.get (_≃_.to (Higher-lens≃Lens bl univ) l) ≡ Higher.Lens.get l
get-lemma ⊠ _ = refl _
set-lemma :
∀ bl (l : Higher.Lens A B) →
Lens.set (_≃_.to (Higher-lens≃Lens bl univ) l) ≡ Higher.Lens.set l
set-lemma bl@⊠ l = ⟨ext⟩ λ a → ⟨ext⟩ λ b →
Lens.set (_≃_.to (Higher-lens≃Lens bl univ) l) a b ≡⟨⟩
proj₁ (≡⇒→ (≡⇒→ (cong Coherently-constant (sym get⁻¹-≡))
(proj₂ (_≃_.to (∥∥→≃ univ) H))
.property (get a) b)
(a , refl (get a))) ≡⟨ cong (λ (c : Coherently-constant (get ⁻¹_)) →
proj₁ (≡⇒→ (c .property (get a) b) (a , refl _))) $ sym $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
proj₁ (≡⇒→ (subst Coherently-constant (sym get⁻¹-≡)
(proj₂ (_≃_.to (∥∥→≃ univ) H))
.property (get a) b)
(a , refl (get a))) ≡⟨ cong (λ (c : Constant (get ⁻¹_)) →
proj₁ (≡⇒→ (c (get a) b) (a , refl _)))
subst-Coherently-property ⟩
proj₁ (≡⇒→ (subst Constant (sym get⁻¹-≡)
(proj₂ (_≃_.to (∥∥→≃ univ) H) .property)
(get a) b)
(a , refl (get a))) ≡⟨ cong (λ c → proj₁ (≡⇒→ (subst Constant (sym get⁻¹-≡) c (get a) b)
(a , refl _))) $
proj₂-to-∥∥→≃-property≡ univ ⟩
proj₁ (≡⇒→ (subst Constant (sym get⁻¹-≡)
(proj₁-to-∥∥→≃-constant univ H)
(get a) b)
(a , refl (get a))) ≡⟨ cong (λ eq → proj₁ (≡⇒→ eq (a , refl _))) $
trans (cong (_$ b) $ sym $
push-subst-application _ _) $
sym $ push-subst-application _ _ ⟩
proj₁ (≡⇒→ (subst (λ f → f (get a) ≡ f b) (sym get⁻¹-≡)
(proj₁-to-∥∥→≃-constant univ H (get a) b))
(a , refl (get a))) ≡⟨ cong (λ eq → proj₁ (≡⇒→ eq (a , refl _))) $
subst-in-terms-of-trans-and-cong ⟩
proj₁ (≡⇒→ (trans (sym (cong (_$ get a) (sym get⁻¹-≡)))
(trans (proj₁-to-∥∥→≃-constant univ H (get a) b)
(cong (_$ b) (sym get⁻¹-≡))))
(a , refl (get a))) ≡⟨⟩
proj₁ (≡⇒→ (trans (sym (cong (_$ get a) (sym get⁻¹-≡)))
(trans (cong H (T.truncation-is-proposition _ _))
(cong (_$ b) (sym get⁻¹-≡))))
(a , refl (get a))) ≡⟨ cong (λ f → proj₁ (f (a , refl _))) $
≡⇒↝-trans equivalence ⟩
proj₁ (≡⇒→ (trans (cong H (T.truncation-is-proposition _ _))
(cong (_$ b) (sym get⁻¹-≡)))
(≡⇒→ (sym (cong (_$ get a) (sym get⁻¹-≡)))
(a , refl (get a)))) ≡⟨ cong (λ f → proj₁ (f (≡⇒→ (sym (cong (_$ get a) (sym get⁻¹-≡)))
(a , refl _)))) $
≡⇒↝-trans equivalence ⟩
proj₁ (≡⇒→ (cong (_$ b) (sym get⁻¹-≡))
(≡⇒→ (cong H (T.truncation-is-proposition _ _))
(≡⇒→ (sym (cong (_$ get a) (sym get⁻¹-≡)))
(a , refl (get a))))) ≡⟨ cong₂ (λ p q → proj₁ (≡⇒→ p
(≡⇒→ (cong H (T.truncation-is-proposition _ _))
(≡⇒→ q (a , refl _)))))
(cong-sym _ _)
(trans (cong sym $ cong-sym _ _) $
sym-sym _) ⟩
proj₁ (≡⇒→ (sym $ cong (_$ b) get⁻¹-≡)
(≡⇒→ (cong H (T.truncation-is-proposition _ _))
(≡⇒→ (cong (_$ get a) get⁻¹-≡)
(a , refl (get a))))) ≡⟨ cong (λ f → proj₁ (f (≡⇒→ (cong H (T.truncation-is-proposition _ _))
(≡⇒→ (cong (_$ get a) get⁻¹-≡)
(a , refl _))))) $
≡⇒↝-sym equivalence ⟩
proj₁ (_≃_.from (≡⇒≃ (cong (_$ b) get⁻¹-≡))
(≡⇒→ (cong H (T.truncation-is-proposition _ _))
(≡⇒→ (cong (_$ get a) get⁻¹-≡)
(a , refl (get a))))) ≡⟨⟩
set a b ∎
where
open Higher.Lens l
| {
"alphanum_fraction": 0.3543564356,
"avg_line_length": 48.2676224612,
"ext": "agda",
"hexsha": "f46e9e9cb54de4412d98b7b7033f404c5ce475f2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher/Coinductive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"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/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher/Coinductive.agda",
"max_line_length": 148,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher/Coinductive.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 13182,
"size": 40400
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Comma where
open import Categories.Category
open import Categories.Functor
open import Data.Product using (_×_; ∃; _,_; proj₁; proj₂; zip; map)
open import Level
open import Relation.Binary using (Rel)
open import Categories.Support.EqReasoning
Comma :
{o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃ : Level}
{A : Category o₁ ℓ₁ e₁}
{B : Category o₂ ℓ₂ e₂}
{C : Category o₃ ℓ₃ e₃}
→ Functor A C → Functor B C
→ Category (o₁ ⊔ o₂ ⊔ ℓ₃) (ℓ₁ ⊔ ℓ₂ ⊔ e₃) (e₁ ⊔ e₂)
Comma {o₁}{ℓ₁}{e₁}
{o₂}{ℓ₂}{e₂}
{o₃}{ℓ₃}{e₃}
{A}{B}{C} T S
= record
{ Obj = Obj
; _⇒_ = Hom
; _≡_ = _≡′_
; _∘_ = _∘′_
; id = id′
; assoc = A.assoc , B.assoc
; identityˡ = A.identityˡ , B.identityˡ
; identityʳ = A.identityʳ , B.identityʳ
; equiv = record
{ refl = A.Equiv.refl , B.Equiv.refl
; sym = map A.Equiv.sym B.Equiv.sym
; trans = zip A.Equiv.trans B.Equiv.trans
}
; ∘-resp-≡ = zip A.∘-resp-≡ B.∘-resp-≡
} module Comma where
module A = Category A
module B = Category B
module C = Category C
module T = Functor T
module S = Functor S
open T using () renaming (F₀ to T₀; F₁ to T₁)
open S using () renaming (F₀ to S₀; F₁ to S₁)
infixr 9 _∘′_
infix 4 _≡′_
infix 10 _,_,_ _,_[_]
record Obj : Set (o₁ ⊔ o₂ ⊔ ℓ₃) where
eta-equality
constructor _,_,_
field
α : A.Obj
β : B.Obj
f : C [ T₀ α , S₀ β ]
record Hom (X₁ X₂ : Obj) : Set (ℓ₁ ⊔ ℓ₂ ⊔ e₃) where
eta-equality
constructor _,_[_]
open Obj X₁ renaming (α to α₁; β to β₁; f to f₁)
open Obj X₂ renaming (α to α₂; β to β₂; f to f₂)
field
g : A [ α₁ , α₂ ]
h : B [ β₁ , β₂ ]
.commutes : C.CommutativeSquare f₁ (T₁ g) (S₁ h) f₂
_≡′_ : ∀ {X₁ X₂} → Rel (Hom X₁ X₂) _
(g₁ , h₁ [ _ ]) ≡′ (g₂ , h₂ [ _ ])
= A [ g₁ ≡ g₂ ]
× B [ h₁ ≡ h₂ ]
id′ : {A : Obj} → Hom A A
id′ { A } = A.id , B.id
[ begin
C [ S₁ B.id ∘ f ]
↓⟨ S.identity ⟩∘⟨ refl ⟩
C [ C.id ∘ f ]
↓⟨ C.identityˡ ⟩
f
↑⟨ C.identityʳ ⟩
C [ f ∘ C.id ]
↑⟨ refl ⟩∘⟨ T.identity ⟩
C [ f ∘ T₁ A.id ]
∎ ]
where
open Obj A
open C.HomReasoning
open C.Equiv
_∘′_ : ∀ {X₁ X₂ X₃} → Hom X₂ X₃ → Hom X₁ X₂ → Hom X₁ X₃
_∘′_ {X₁}{X₂}{X₃} (g₁ , h₁ [ commutes₁ ]) (g₂ , h₂ [ commutes₂ ])
= A [ g₁ ∘ g₂ ] , B [ h₁ ∘ h₂ ]
[ begin
-- commutes₁ : C [ C [ S₁ h₁ ∘ f₂ ] ≡ C [ f₃ ∘ T₁ g₁ ] ]
-- commutes₂ : C [ C [ S₁ h₂ ∘ f₁ ] ≡ C [ f₂ ∘ T₁ g₂ ] ]
C [ S₁ (B [ h₁ ∘ h₂ ]) ∘ f₁ ]
↓⟨ S.homomorphism ⟩∘⟨ refl ⟩
C [ C [ S₁ h₁ ∘ S₁ h₂ ] ∘ f₁ ]
↓⟨ C.assoc ⟩
C [ S₁ h₁ ∘ C [ S₁ h₂ ∘ f₁ ] ]
↓⟨ refl ⟩∘⟨ commutes₂ ⟩
C [ S₁ h₁ ∘ C [ f₂ ∘ T₁ g₂ ] ]
↑⟨ C.assoc ⟩
C [ C [ S₁ h₁ ∘ f₂ ] ∘ T₁ g₂ ]
↓⟨ commutes₁ ⟩∘⟨ refl ⟩
C [ C [ f₃ ∘ T₁ g₁ ] ∘ T₁ g₂ ]
↓⟨ C.assoc ⟩
C [ f₃ ∘ C [ T₁ g₁ ∘ T₁ g₂ ] ]
↑⟨ refl ⟩∘⟨ T.homomorphism ⟩
C [ f₃ ∘ T₁ (A [ g₁ ∘ g₂ ]) ]
∎ ]
where
open C.HomReasoning
open C.Equiv
open Obj X₁ renaming (α to α₁; β to β₁; f to f₁)
open Obj X₂ renaming (α to α₂; β to β₂; f to f₂)
open Obj X₃ renaming (α to α₃; β to β₃; f to f₃)
_↓_ : ∀ {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃}
→ {A : Category o₁ ℓ₁ e₁}
→ {B : Category o₂ ℓ₂ e₂}
→ {C : Category o₃ ℓ₃ e₃}
→ (S : Functor B C) (T : Functor A C)
→ Category _ _ _
T ↓ S = Comma T S
Dom : {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃ : Level}
{A : Category o₁ ℓ₁ e₁}
{B : Category o₂ ℓ₂ e₂}
{C : Category o₃ ℓ₃ e₃}
→ (T : Functor A C) → (S : Functor B C)
→ Functor (Comma T S) A
Dom {A = A} {B} {C} T S = record
{ F₀ = Obj.α
; F₁ = Hom.g
; identity = refl
; homomorphism = refl
; F-resp-≡ = proj₁
}
where
open Comma T S
open A.Equiv
Cod : {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃ : Level}
{A : Category o₁ ℓ₁ e₁}
{B : Category o₂ ℓ₂ e₂}
{C : Category o₃ ℓ₃ e₃}
→ (T : Functor A C) → (S : Functor B C)
→ Functor (Comma T S) B
Cod {A = A} {B} {C} T S = record
{ F₀ = Obj.β
; F₁ = Hom.h
; identity = refl
; homomorphism = refl
; F-resp-≡ = proj₂
}
where
open Comma T S
open B.Equiv
open import Categories.Functor.Diagonal
open import Categories.FunctorCategory
open import Categories.Categories
open import Categories.NaturalTransformation
CommaF : ∀ {o ℓ e o₁ ℓ₁ e₁ o₂ ℓ₂ e₂ o₃ ℓ₃ e₃}
→ {O : Category o ℓ e }
→ {A : Category o₁ ℓ₁ e₁}
→ {B : Category o₂ ℓ₂ e₂}
→ {C : Category o₃ ℓ₃ e₃}
→ (T : Functor A C) (S : Functor O (Functors B C)) -> Functor O (Categories _ _ _)
CommaF {O = O} {A} {B} {C} T S = record
{ F₀ = λ o → Comma T (S.F₀ o)
; F₁ = λ {o₁} {o₂} f → record
{ F₀ = λ { (a Comma., b , g) → a Comma., b , (S₁.η f b C.∘ g) }
; F₁ = λ { {a₁ Comma., b₁ , g₁} {a₂ Comma., b₂ , g₂} (g Comma., h [ comm ]) →
g Comma., h [ begin S₀.F₁ o₂ h C.∘ S₁.η f b₁ C.∘ g₁
↓⟨ C.Equiv.sym C.assoc ⟩
(S₀.F₁ o₂ h C.∘ S₁.η f b₁) C.∘ g₁
↓⟨ C.∘-resp-≡ˡ (C.Equiv.sym (S₁.commute f h)) ⟩
(S₁.η f b₂ C.∘ S₀.F₁ o₁ h) C.∘ g₁
↓⟨ C.assoc ⟩
S₁.η f b₂ C.∘ S₀.F₁ o₁ h C.∘ g₁
↓⟨ C.∘-resp-≡ʳ comm ⟩
S₁.η f b₂ C.∘ g₂ C.∘ T.F₁ g
↓⟨ C.Equiv.sym C.assoc ⟩
(S₁.η f b₂ C.∘ g₂) C.∘ T.F₁ g
∎
]};
identity = TODO;
homomorphism = TODO;
F-resp-≡ = TODO }
; identity = TODO
; homomorphism = TODO
; F-resp-≡ = TODO
}
where
module C = Category C
module T = Functor T
module S = Functor S
module S₀ o = Functor (S.F₀ o)
module S₁ {a b} f = NaturalTransformation (S.F₁ {a} {b} f)
postulate TODO : ∀ {l} {A : Set l} -> A
open C.HomReasoning
| {
"alphanum_fraction": 0.4410958904,
"avg_line_length": 31.5865384615,
"ext": "agda",
"hexsha": "ffe95765b61d3bdf0736b9e92e4344bfb0b361d4",
"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/Comma.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/Comma.agda",
"max_line_length": 88,
"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/Comma.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": 2635,
"size": 6570
} |
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.Union where
open import Prelude
open import Path.Reasoning
open import Algebra
open import Algebra.Construct.Free.Semilattice.Definition
open import Algebra.Construct.Free.Semilattice.Eliminators
infixr 5 _∪_
_∪_ : 𝒦 A → 𝒦 A → 𝒦 A
_∪_ = λ xs ys → [ union′ ys ]↓ xs
where
union′ : 𝒦 A → A ↘ 𝒦 A
[ union′ ys ]-set = trunc
[ union′ ys ] x ∷ xs = x ∷ xs
[ union′ ys ][] = ys
[ union′ ys ]-dup = dup
[ union′ ys ]-com = com
∪-assoc : (xs ys zs : 𝒦 A) → (xs ∪ ys) ∪ zs ≡ xs ∪ (ys ∪ zs)
∪-assoc = λ xs ys zs → ∥ ∪-assoc′ ys zs ∥⇓ xs
where
∪-assoc′ : (ys zs : 𝒦 A) → xs ∈𝒦 A ⇒∥ (xs ∪ ys) ∪ zs ≡ xs ∪ (ys ∪ zs) ∥
∥ ∪-assoc′ ys zs ∥-prop = trunc _ _
∥ ∪-assoc′ ys zs ∥[] = refl
∥ ∪-assoc′ ys zs ∥ x ∷ xs ⟨ Pxs ⟩ = cong (x ∷_) Pxs
∪-identityʳ : (xs : 𝒦 A) → xs ∪ [] ≡ xs
∪-identityʳ = ∥ ∪-identityʳ′ ∥⇓
where
∪-identityʳ′ : xs ∈𝒦 A ⇒∥ xs ∪ [] ≡ xs ∥
∥ ∪-identityʳ′ ∥-prop = trunc _ _
∥ ∪-identityʳ′ ∥[] = refl
∥ ∪-identityʳ′ ∥ x ∷ xs ⟨ Pxs ⟩ = cong (x ∷_) Pxs
cons-distrib-∪ : (x : A) (xs ys : 𝒦 A) → x ∷ xs ∪ ys ≡ xs ∪ (x ∷ ys)
cons-distrib-∪ = λ x xs ys → ∥ cons-distrib-∪′ x ys ∥⇓ xs
where
cons-distrib-∪′ : (x : A) (ys : 𝒦 A) → xs ∈𝒦 A ⇒∥ x ∷ xs ∪ ys ≡ xs ∪ (x ∷ ys) ∥
∥ cons-distrib-∪′ x ys ∥-prop = trunc _ _
∥ cons-distrib-∪′ x ys ∥[] = refl
∥ cons-distrib-∪′ x ys ∥ z ∷ xs ⟨ Pxs ⟩ =
x ∷ ((z ∷ xs) ∪ ys) ≡⟨⟩
x ∷ z ∷ (xs ∪ ys) ≡⟨ com x z (xs ∪ ys) ⟩
z ∷ x ∷ (xs ∪ ys) ≡⟨ cong (z ∷_) Pxs ⟩
((z ∷ xs) ∪ (x ∷ ys)) ∎
∪-comm : (xs ys : 𝒦 A) → xs ∪ ys ≡ ys ∪ xs
∪-comm = λ xs ys → ∥ ∪-comm′ ys ∥⇓ xs
where
∪-comm′ : (ys : 𝒦 A) → xs ∈𝒦 A ⇒∥ xs ∪ ys ≡ ys ∪ xs ∥
∥ ∪-comm′ ys ∥-prop = trunc _ _
∥ ∪-comm′ ys ∥[] = sym (∪-identityʳ ys)
∥ ∪-comm′ ys ∥ x ∷ xs ⟨ Pxs ⟩ =
(x ∷ xs) ∪ ys ≡⟨⟩
x ∷ (xs ∪ ys) ≡⟨ cong (x ∷_) Pxs ⟩
x ∷ (ys ∪ xs) ≡⟨⟩
(x ∷ ys) ∪ xs ≡⟨ cons-distrib-∪ x ys xs ⟩
ys ∪ (x ∷ xs) ∎
∪-idem : (xs : 𝒦 A) → xs ∪ xs ≡ xs
∪-idem = ∥ ∪-idem′ ∥⇓
where
∪-idem′ : xs ∈𝒦 A ⇒∥ xs ∪ xs ≡ xs ∥
∥ ∪-idem′ ∥-prop = trunc _ _
∥ ∪-idem′ ∥[] = refl
∥ ∪-idem′ ∥ x ∷ xs ⟨ Pxs ⟩ =
((x ∷ xs) ∪ (x ∷ xs)) ≡˘⟨ cons-distrib-∪ x (x ∷ xs) xs ⟩
x ∷ x ∷ (xs ∪ xs) ≡⟨ dup x (xs ∪ xs) ⟩
x ∷ (xs ∪ xs) ≡⟨ cong (x ∷_) Pxs ⟩
x ∷ xs ∎
module _ {a} {A : Type a} where
open Semilattice
open CommutativeMonoid
open Monoid
𝒦-semilattice : Semilattice a
𝒦-semilattice .commutativeMonoid .monoid .𝑆 = 𝒦 A
𝒦-semilattice .commutativeMonoid .monoid ._∙_ = _∪_
𝒦-semilattice .commutativeMonoid .monoid .ε = []
𝒦-semilattice .commutativeMonoid .monoid .assoc = ∪-assoc
𝒦-semilattice .commutativeMonoid .monoid .ε∙ _ = refl
𝒦-semilattice .commutativeMonoid .monoid .∙ε = ∪-identityʳ
𝒦-semilattice .commutativeMonoid .comm = ∪-comm
𝒦-semilattice .idem = ∪-idem
| {
"alphanum_fraction": 0.5169133192,
"avg_line_length": 31.8876404494,
"ext": "agda",
"hexsha": "24b00b2cb299db021f03d6c69d280619d3350743",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/Union.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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/combinatorics-paper",
"max_issues_repo_path": "agda/Algebra/Construct/Free/Semilattice/Union.agda",
"max_line_length": 81,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Algebra/Construct/Free/Semilattice/Union.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": 1496,
"size": 2838
} |
module Properties.Contradiction where
data ⊥ : Set where
¬ : Set → Set
¬ A = A → ⊥
CONTRADICTION : ∀ {A : Set} → ⊥ → A
CONTRADICTION ()
| {
"alphanum_fraction": 0.6115107914,
"avg_line_length": 13.9,
"ext": "agda",
"hexsha": "e9a92ad59d09da726deef1b6e1cf9cebf019f0a5",
"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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Properties/Contradiction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"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": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Properties/Contradiction.agda",
"max_line_length": 37,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/Properties/Contradiction.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-06T08:03:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-06T08:03:00.000Z",
"num_tokens": 50,
"size": 139
} |
{-# OPTIONS --without-K #-}
module container.core where
open import level
open import sum
open import equality
open import function
module _ {li}{I : Set li} where
-- homsets in the slice category
_→ⁱ_ : ∀ {lx ly} → (I → Set lx) → (I → Set ly) → Set _
X →ⁱ Y = (i : I) → X i → Y i
-- identity of the slice category
idⁱ : ∀ {lx}{X : I → Set lx} → X →ⁱ X
idⁱ i x = x
-- composition in the slice category
_∘ⁱ_ : ∀ {lx ly lz} {X : I → Set lx}{Y : I → Set ly}{Z : I → Set lz}
→ (Y →ⁱ Z) → (X →ⁱ Y) → (X →ⁱ Z)
(f ∘ⁱ g) i = f i ∘ g i
infixl 9 _∘ⁱ_
-- extensionality
funext-isoⁱ : ∀ {lx ly} {X : I → Set lx}{Y : (i : I) → X i → Set ly}
→ {f g : (i : I)(x : X i) → Y i x}
→ (∀ i x → f i x ≡ g i x)
≅ (f ≡ g)
funext-isoⁱ {f = f}{g = g}
= (Π-ap-iso refl≅ λ i → strong-funext-iso)
·≅ strong-funext-iso
funext-invⁱ : ∀ {lx ly} {X : I → Set lx}{Y : (i : I) → X i → Set ly}
→ {f g : (i : I)(x : X i) → Y i x}
→ f ≡ g → ∀ i x → f i x ≡ g i x
funext-invⁱ = invert funext-isoⁱ
funextⁱ : ∀ {lx ly} {X : I → Set lx}{Y : (i : I) → X i → Set ly}
→ {f g : (i : I)(x : X i) → Y i x}
→ (∀ i x → f i x ≡ g i x) → f ≡ g
funextⁱ = apply funext-isoⁱ
-- Definition 1 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
record Container (li la lb : Level) : Set (lsuc (li ⊔ la ⊔ lb)) where
constructor container
field
I : Set li
A : I → Set la
B : {i : I} → A i → Set lb
r : {i : I}{a : A i} → B a → I
-- Definition 2 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
-- functor associated to this indexed container
F : ∀ {lx} → (I → Set lx) → I → Set _
F X i = Σ (A i) λ a → (b : B a) → X (r b)
F-ap-iso : ∀ {lx ly}{X : I → Set lx}{Y : I → Set ly}
→ (∀ i → X i ≅ Y i)
→ ∀ i → F X i ≅ F Y i
F-ap-iso isom i = Σ-ap-iso refl≅ λ a
→ Π-ap-iso refl≅ λ b
→ isom (r b)
-- morphism map for the functor F
imap : ∀ {lx ly}
→ {X : I → Set lx}
→ {Y : I → Set ly}
→ (X →ⁱ Y)
→ (F X →ⁱ F Y)
imap g i (a , f) = a , λ b → g (r b) (f b)
-- action of a functor on homotopies
hmap : ∀ {lx ly}
→ {X : I → Set lx}
→ {Y : I → Set ly}
→ {f g : X →ⁱ Y}
→ (∀ i x → f i x ≡ g i x)
→ (∀ i x → imap f i x ≡ imap g i x)
hmap p i (a , u) = ap (_,_ a) (funext (λ b → p (r b) (u b)))
hmap-id : ∀ {lx ly}
→ {X : I → Set lx}
→ {Y : I → Set ly}
→ (f : X →ⁱ Y)
→ ∀ i x
→ hmap (λ i x → refl {x = f i x}) i x ≡ refl
hmap-id f i (a , u) = ap (ap (_,_ a)) (funext-id _)
| {
"alphanum_fraction": 0.4441558442,
"avg_line_length": 30.2808988764,
"ext": "agda",
"hexsha": "3d6f4cf44e208c2635dda6c4ebfca12fc3e9a122",
"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": "container/core.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "container/core.agda",
"max_line_length": 80,
"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": "container/core.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": 1135,
"size": 2695
} |
-- TODO: Move these to stuff related to metric spaces
module Continuity where
open Limit
-- Statement that the point x of function f is a continous point
ContinuousPoint : (ℝ → ℝ) → ℝ → Stmt
ContinuousPoint f(x) = (⦃ limit : Lim f(x) ⦄ → (lim f(x)⦃ limit ⦄ ≡ f(x)))
-- Statement that the function f is continous
Continuous : (ℝ → ℝ) → Stmt
Continuous f = ∀{x} → ContinuousPoint f(x)
module Proofs where
-- instance postulate DifferentiablePoint-to-ContinuousPoint : ∀{f}{x}{diff} → ⦃ _ : DifferentiablePoint f(x)⦃ diff ⦄ ⦄ → ContinuousPoint f(x)
-- instance postulate Differentiable-to-Continuous : ∀{f}{diff} → ⦃ _ : Differentiable(f)⦃ diff ⦄ ⦄ → Continuous(f)
| {
"alphanum_fraction": 0.6739766082,
"avg_line_length": 40.2352941176,
"ext": "agda",
"hexsha": "b15c35006f86db1fb111bc81c19e99c4cfe51999",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Real/Continuity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Real/Continuity.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": "Structure/Real/Continuity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 222,
"size": 684
} |
-- Andreas, 2021-08-17, issue #5508, reported by james-smith-69781
-- On a case-insensitive file system, an inconsistency slipped into
-- the ModuleToSource map, leading to a failure in getting the module
-- name from the file name, in turn leading to a crash for certain errors.
module Issue5508 where -- case variant intended!
-- WAS: Crash in termination error
A : Set
A = A
record R : Set2 where
field f : Set1
record S : Set2 where
field g : Set1
record T : Set2 where
field g : Set1
open S
open T
-- Now, g is ambiguous.
-- WAS: crash in "Cannot eliminate ... with projection" error
test : R
test .g = Set
| {
"alphanum_fraction": 0.7097288676,
"avg_line_length": 20.9,
"ext": "agda",
"hexsha": "8df3987acd669b4515f65eed3fb8ef19301798cc",
"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/customised/iSSue5508.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/customised/iSSue5508.agda",
"max_line_length": 74,
"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/customised/iSSue5508.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": 177,
"size": 627
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
------------------------------------------------------------------------------
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.BlockStorage.BlockStore as BlockStore
import LibraBFT.Impl.Consensus.BlockStorage.SyncManager as SyncManager
import LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock as ExecutedBlock
import LibraBFT.Impl.Consensus.ConsensusTypes.SyncInfo as SyncInfo
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
import LibraBFT.Impl.Consensus.Liveness.ProposerElection as ProposerElection
import LibraBFT.Impl.Consensus.Liveness.ProposalGenerator as ProposalGenerator
import LibraBFT.Impl.Consensus.Liveness.RoundState as RoundState
import LibraBFT.Impl.Consensus.PersistentLivenessStorage as PersistentLivenessStorage
import LibraBFT.Impl.Consensus.SafetyRules.SafetyRules as SafetyRules
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open import Optics.All
open import Util.ByteString
open import Util.Hash
import Util.KVMap as Map
open import Util.PKCS
open import Util.Prelude
-----------------------------------------------------------------------------
open import Data.String using (String)
------------------------------------------------------------------------------
module LibraBFT.Impl.Consensus.RoundManager where
------------------------------------------------------------------------------
processCertificatesM : Instant → LBFT Unit
------------------------------------------------------------------------------
processCommitM : LedgerInfoWithSignatures → LBFT (List ExecutedBlock)
processCommitM finalityProof = pure []
------------------------------------------------------------------------------
generateProposalM
: Instant → NewRoundEvent
→ LBFT (Either ErrLog ProposalMsg)
processNewRoundEventM : Instant → NewRoundEvent → LBFT Unit
processNewRoundEventM now nre@(NewRoundEvent∙new r _ _) = do
logInfo fakeInfo -- (InfoNewRoundEvent nre)
use (lRoundManager ∙ pgAuthor) >>= λ where
nothing → logErr fakeErr -- (here ["lRoundManager.pgAuthor", "Nothing"])
(just author) → do
v ← ProposerElection.isValidProposer <$> use lProposerElection <*> pure author <*> pure r
whenD v $ do
rcvrs ← use (lRoundManager ∙ rmObmAllAuthors)
generateProposalM now nre >>= λ where
-- (Left (ErrEpochEndedNoProposals t)) -> logInfoL (lEC.|.lPM) (here ("EpochEnded":t))
(Left e) → logErr (withErrCtx (here' ("Error generating proposal" ∷ [])) e)
(Right proposalMsg) → act (BroadcastProposal proposalMsg rcvrs)
where
here' : List String → List String
here' t = "RoundManager" ∷ "processNewRoundEventM" ∷ t
abstract
processNewRoundEventM-abs = processNewRoundEventM
processNewRoundEventM-abs-≡ : processNewRoundEventM-abs ≡ processNewRoundEventM
processNewRoundEventM-abs-≡ = refl
generateProposalM now newRoundEvent =
ProposalGenerator.generateProposalM now (newRoundEvent ^∙ nreRound) ∙?∙ λ proposal →
SafetyRules.signProposalM proposal ∙?∙ λ signedProposal →
Right ∘ ProposalMsg∙new signedProposal <$> BlockStore.syncInfoM
------------------------------------------------------------------------------
ensureRoundAndSyncUpM : Instant → Round → SyncInfo → Author → Bool → LBFT (Either ErrLog Bool)
processProposalM : Block → LBFT Unit
executeAndVoteM : Block → LBFT (Either ErrLog Vote)
-- external entry point
-- TODO-2: The sync info that the peer requests if it discovers that its round
-- state is behind the sender's should be sent as an additional argument, for now.
module processProposalMsgM (now : Instant) (pm : ProposalMsg) where
step₀ : LBFT Unit
step₁ : Author → LBFT Unit
step₂ : Either ErrLog Bool → LBFT Unit
step₀ =
caseMD pm ^∙ pmProposer of λ where
nothing → logInfo fakeInfo -- proposal with no author
(just pAuthor) → step₁ pAuthor
step₁ pAuthor =
ensureRoundAndSyncUpM now (pm ^∙ pmProposal ∙ bRound) (pm ^∙ pmSyncInfo)
pAuthor true >>= step₂
step₂ =
λ where
(Left e) → logErr e
(Right true) → processProposalM (pm ^∙ pmProposal)
(Right false) → do
currentRound ← use (lRoundState ∙ rsCurrentRound)
logInfo fakeInfo -- dropping proposal for old round
abstract
processProposalMsgM = processProposalMsgM.step₀
processProposalMsgM≡ : processProposalMsgM ≡ processProposalMsgM.step₀
processProposalMsgM≡ = refl
------------------------------------------------------------------------------
module syncUpM (now : Instant) (syncInfo : SyncInfo) (author : Author) (_helpRemote : Bool) where
step₀ : LBFT (Either ErrLog Unit)
step₁ step₂ : SyncInfo → LBFT (Either ErrLog Unit)
step₃ step₄ : SyncInfo → ValidatorVerifier → LBFT (Either ErrLog Unit)
here' : List String → List String
step₀ = do
-- logEE (here' []) $ do
localSyncInfo ← BlockStore.syncInfoM
-- TODO helpRemote
step₁ localSyncInfo
step₁ localSyncInfo = do
ifD SyncInfo.hasNewerCertificates syncInfo localSyncInfo
then step₂ localSyncInfo
else ok unit
step₂ localSyncInfo = do
vv ← use (lRoundManager ∙ rmEpochState ∙ esVerifier)
SyncInfo.verifyM syncInfo vv ∙^∙ withErrCtx (here' []) ∙?∙ λ _ → step₃ localSyncInfo vv
step₃ localSyncInfo vv =
SyncManager.addCertsM {- reason -} syncInfo (BlockRetriever∙new now author) ∙^∙ withErrCtx (here' [])
∙?∙ λ _ → step₄ localSyncInfo vv
step₄ localSyncInfo vv = do
processCertificatesM now
ok unit
here' t = "RoundManager" ∷ "syncUpM" ∷ t
syncUpM : Instant → SyncInfo → Author → Bool → LBFT (Either ErrLog Unit)
syncUpM = syncUpM.step₀
------------------------------------------------------------------------------
module ensureRoundAndSyncUpM
(now : Instant) (messageRound : Round) (syncInfo : SyncInfo) (author : Author) (helpRemote : Bool) where
step₀ : LBFT (Either ErrLog Bool)
step₁ : LBFT (Either ErrLog Bool)
step₂ : LBFT (Either ErrLog Bool)
step₀ = do
currentRound ← use (lRoundState ∙ rsCurrentRound)
ifD messageRound <? currentRound
then ok false
else step₁
step₁ =
syncUpM now syncInfo author helpRemote ∙?∙ λ _ → step₂
step₂ = do
currentRound' ← use (lRoundState ∙ rsCurrentRound)
ifD messageRound /= currentRound'
then bail fakeErr -- error: after sync, round does not match local
else ok true
ensureRoundAndSyncUpM = ensureRoundAndSyncUpM.step₀
------------------------------------------------------------------------------
-- In Haskell, RoundManager.processSyncInfoMsgM is NEVER called.
--
-- When processing other messaging (i.e., Proposal and Vote) the first thing that happens,
-- before handling the specific message, is that ensureRoundAndSyncUpM is called to deal
-- with the SyncInfo message in the ProposalMsg or VoteMsg.
-- If a SyncInfo message ever did arrive by itself, all that would happen is that the
-- SyncInfo would be handled by ensureRoundAndSyncUpM (just like other messages).
-- And nothing else (except ensureRoundAndSyncUpM might do "catching up")
--
-- The only place the Haskell implementation uses SyncInfo only messages it during EpochChange.
-- And, in that case, the SyncInfo message is handled in the EpochManager, not here.
processSyncInfoMsgM : Instant → SyncInfo → Author → LBFT Unit
processSyncInfoMsgM now syncInfo peer =
-- logEE (lEC.|.lSI) (here []) $
ensureRoundAndSyncUpM now (syncInfo ^∙ siHighestRound + 1) syncInfo peer false >>= λ where
(Left e) → logErr (withErrCtx (here' []) e)
(Right _) → pure unit
where
here' : List String → List String
here' t = "RoundManager" ∷ "processSyncInfoMsgM" ∷ {- lsA peer ∷ lsSI syncInfo ∷ -} t
------------------------------------------------------------------------------
-- external entry point
processLocalTimeoutM : Instant → Epoch → Round → LBFT Unit
processLocalTimeoutM now obmEpoch round = do
-- logEE lTO (here []) $
ifMD (RoundState.processLocalTimeoutM now obmEpoch round) continue1 (pure unit)
where
here' : List String → List String
continue2 : LBFT Unit
continue3 : (Bool × Vote) → LBFT Unit
continue4 : Vote → LBFT Unit
continue1 =
ifMD (use (lRoundManager ∙ rmSyncOnly))
-- In Haskell, rmSyncOnly is ALWAYS false.
-- It is used for an unimplemented "sync only" mode for nodes.
-- "sync only" mode is an optimization for nodes catching up.
(do si ← BlockStore.syncInfoM
rcvrs ← use (lRoundManager ∙ rmObmAllAuthors)
act (BroadcastSyncInfo si rcvrs))
continue2
continue2 =
use (lRoundState ∙ rsVoteSent) >>= λ where
(just vote) →
ifD (vote ^∙ vVoteData ∙ vdProposed ∙ biRound == round)
-- already voted in this round, so resend the vote, but with a timeout signature
then continue3 (true , vote)
else local-continue2-continue
_ → local-continue2-continue
where
local-continue2-continue : LBFT Unit
local-continue2-continue =
-- have not voted in this round, so create and vote on NIL block with timeout signature
ProposalGenerator.generateNilBlockM round >>= λ where
(Left e) → logErr e
(Right nilBlock) →
executeAndVoteM nilBlock >>= λ where
(Left e) → logErr e
(Right nilVote) → continue3 (false , nilVote)
continue3 (useLastVote , timeoutVote) = do
proposer ← ProposerElection.getValidProposer <$> use lProposerElection <*> pure round
logInfo fakeInfo
-- (here [ if useLastVote then "already executed and voted, will send timeout vote"
-- else "generate nil timeout vote"
-- , "expected proposer", lsA proposer ])
if not (Vote.isTimeout timeoutVote)
then
(SafetyRules.signTimeoutM (Vote.timeout timeoutVote) >>= λ where
(Left e) → logErr (withErrCtx (here' []) e)
(Right s) → continue4 (Vote.addTimeoutSignature timeoutVote s)) -- makes it a timeout vote
else
continue4 timeoutVote
continue4 timeoutVote = do
RoundState.recordVoteM timeoutVote
timeoutVoteMsg ← VoteMsg∙new timeoutVote <$> BlockStore.syncInfoM
rcvrs ← use (lRoundManager ∙ rmObmAllAuthors)
-- IMPL-DIFF this is BroadcastVote in Haskell (an alias)
act (SendVote timeoutVoteMsg rcvrs)
here' t = "RoundManager" ∷ "processLocalTimeoutM" ∷ {-lsE obmEpoch:lsR round-} t
------------------------------------------------------------------------------
processCertificatesM now = do
syncInfo ← BlockStore.syncInfoM
maybeSMP-RWS (RoundState.processCertificatesM now syncInfo) unit (processNewRoundEventM now)
------------------------------------------------------------------------------
-- This function is broken into smaller pieces to aid in the verification
-- effort. The style of indentation used is to make side-by-side reading of the
-- Haskell prototype and Agda model easier.
module processProposalM (proposal : Block) where
step₀ : LBFT Unit
step₁ : BlockStore → (Either ObmNotValidProposerReason Unit) → LBFT Unit
step₂ : Either ErrLog Vote → LBFT Unit
step₃ : Vote → SyncInfo → LBFT Unit
step₀ = do
bs ← use lBlockStore
vp ← ProposerElection.isValidProposalM proposal
step₁ bs vp
step₁ bs vp =
ifD‖ isLeft vp ≔
logErr fakeErr -- proposer for block is not valid for this round
‖ is-nothing (BlockStore.getQuorumCertForBlock (proposal ^∙ bParentId) bs) ≔
logErr fakeErr -- QC of parent is not in BS
‖ not (maybeS (BlockStore.getBlock (proposal ^∙ bParentId) bs) false
λ parentBlock →
⌊ parentBlock ^∙ ebRound <?ℕ proposal ^∙ bRound ⌋) ≔
logErr fakeErr -- parentBlock < proposalRound
‖ otherwise≔ do
executeAndVoteM proposal >>= step₂
step₂ = λ where
(Left e) → logErr e
(Right vote) → do
RoundState.recordVoteM vote
si ← BlockStore.syncInfoM
step₃ vote si
step₃ vote si = do
recipient ← ProposerElection.getValidProposer
<$> use lProposerElection
<*> pure (proposal ^∙ bRound + 1)
act (SendVote (VoteMsg∙new vote si) (recipient ∷ []))
-- TODO-2: mkNodesInOrder1 recipient
processProposalM = processProposalM.step₀
------------------------------------------------------------------------------
module executeAndVoteM (b : Block) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : ExecutedBlock → LBFT (Either ErrLog Vote)
step₂ : ExecutedBlock → LBFT (Either ErrLog Vote)
step₃ : Vote → LBFT (Either ErrLog Vote)
step₀ =
BlockStore.executeAndInsertBlockM b ∙^∙ withErrCtx ("" ∷ []) ∙?∙ step₁
step₁ eb = do
cr ← use (lRoundState ∙ rsCurrentRound)
vs ← use (lRoundState ∙ rsVoteSent)
so ← use (lRoundManager ∙ rmSyncOnly)
ifD‖ is-just vs ≔
bail fakeErr -- error: already voted this round
‖ so ≔
bail fakeErr -- error: sync-only set
‖ otherwise≔ step₂ eb
step₂ eb = do
let maybeSignedVoteProposal' = ExecutedBlock.maybeSignedVoteProposal eb
SafetyRules.constructAndSignVoteM maybeSignedVoteProposal' {- ∙^∙ logging -}
∙?∙ step₃
step₃ vote = PersistentLivenessStorage.saveVoteM vote
∙?∙ λ _ → ok vote
executeAndVoteM = executeAndVoteM.step₀
------------------------------------------------------------------------------
processVoteM : Instant → Vote → LBFT Unit
addVoteM : Instant → Vote → LBFT Unit
newQcAggregatedM : Instant → QuorumCert → Author → LBFT Unit
newTcAggregatedM : Instant → TimeoutCertificate → LBFT Unit
processVoteMsgM : Instant → VoteMsg → LBFT Unit
processVoteMsgM now voteMsg = do
-- TODO ensureRoundAndSyncUp
processVoteM now (voteMsg ^∙ vmVote)
processVoteM now vote =
ifD not (Vote.isTimeout vote)
then (do
let nextRound = vote ^∙ vVoteData ∙ vdProposed ∙ biRound + 1
use (lRoundManager ∙ pgAuthor) >>= λ where
nothing → logErr fakeErr -- "lRoundManager.pgAuthor", "Nothing"
(just author) → do
v ← ProposerElection.isValidProposer <$> use lProposerElection
<*> pure author <*> pure nextRound
if v then continue else logErr fakeErr) -- "received vote, but I am not proposer for round"
else
continue
where
continue : LBFT Unit
continue = do
let blockId = vote ^∙ vVoteData ∙ vdProposed ∙ biId
bs ← use lBlockStore
ifD (is-just (BlockStore.getQuorumCertForBlock blockId bs))
then logInfo fakeInfo -- "block already has QC", "dropping unneeded vote"
else do
logInfo fakeInfo -- "before"
addVoteM now vote
pvA ← use lPendingVotes
logInfo fakeInfo -- "after"
addVoteM now vote = do
bs ← use lBlockStore
maybeSD (bs ^∙ bsHighestTimeoutCert) continue λ tc →
ifD vote ^∙ vRound == tc ^∙ tcRound
then logInfo fakeInfo -- "block already has TC", "dropping unneeded vote"
else continue
where
continue : LBFT Unit
continue = do
verifier ← use (rmEpochState ∙ esVerifier)
r ← RoundState.insertVoteM vote verifier
case r of λ where
(NewQuorumCertificate qc) →
newQcAggregatedM now qc (vote ^∙ vAuthor)
(NewTimeoutCertificate tc) →
newTcAggregatedM now tc
_ →
pure unit
newQcAggregatedM now qc a =
SyncManager.insertQuorumCertM qc (BlockRetriever∙new now a) >>= λ where
(Left e) → logErr e
(Right unit) → processCertificatesM now
newTcAggregatedM now tc =
BlockStore.insertTimeoutCertificateM tc >>= λ where
(Left e) → logErr e
(Right unit) → processCertificatesM now
------------------------------------------------------------------------------
-- TODO-1 PROVE IT TERMINATES
{-# TERMINATING #-}
mkRsp : BlockRetrievalRequest → (Author × Epoch × Round) → BlockStore → List Block → HashValue
→ BlockRetrievalResponse
-- external entry point
processBlockRetrievalRequestM : Instant → BlockRetrievalRequest → LBFT Unit
processBlockRetrievalRequestM _now request = do
-- logEE lSI (here []) $ do
use (lRoundManager ∙ rmObmMe) >>= λ where
nothing → logErr fakeErr -- should not happen
(just me) → continue me
where
continue : Author → LBFT Unit
continue me = do
e ← use (lRoundManager ∙ rmSafetyRules ∙ srPersistentStorage ∙ pssSafetyData ∙ sdEpoch)
r ← use (lRoundManager ∙ rmRoundState ∙ rsCurrentRound)
let meer = (me , e , r)
bs ← use lBlockStore
act (SendBRP (request ^∙ brqObmFrom) (mkRsp request meer bs [] (request ^∙ brqBlockId)))
mkRsp request meer bs blocks id =
if-dec length blocks <? request ^∙ brqNumBlocks
then
(case BlockStore.getBlock id bs of λ where
(just executedBlock) → mkRsp request meer bs (blocks ++ (executedBlock ^∙ ebBlock ∷ []))
(executedBlock ^∙ ebParentId)
nothing → BlockRetrievalResponse∙new meer
(if null blocks then BRSIdNotFound else BRSNotEnoughBlocks)
blocks)
else BlockRetrievalResponse∙new meer BRSSucceeded blocks
------------------------------------------------------------------------------
module start
(now : Instant)
(lastVoteSent : Maybe Vote)
where
step₁ step₁-abs : SyncInfo → LBFT Unit
step₂ step₂-abs : Maybe NewRoundEvent → LBFT Unit
step₃ step₄ step₃-abs step₄-abs : NewRoundEvent → LBFT Unit
step₀ : LBFT Unit
step₀ = do
syncInfo ← BlockStore.syncInfoM
step₁-abs syncInfo
step₁ syncInfo = do
RoundState.processCertificatesM-abs now syncInfo >>= step₂-abs
here' : List String → List String
here' t = "RoundManager" ∷ "start" ∷ t
step₂ = λ where
nothing →
logErr fakeErr -- (here' ["Cannot jump start a round_state from existing certificates."]))
(just nre) → step₃-abs nre
step₃ nre = do
maybeSMP (pure lastVoteSent) unit RoundState.recordVoteM
step₄-abs nre
step₄ nre = processNewRoundEventM-abs now nre -- error!("[RoundManager] Error during start: {:?}", e);
abstract
step₁-abs = step₁
step₁-abs-≡ : step₁-abs ≡ step₁
step₁-abs-≡ = refl
step₂-abs = step₂
step₂-abs-≡ : step₂-abs ≡ step₂
step₂-abs-≡ = refl
step₃-abs = step₃
step₃-abs-≡ : step₃-abs ≡ step₃
step₃-abs-≡ = refl
step₄-abs = step₄
step₄-abs-≡ : step₄-abs ≡ step₄
step₄-abs-≡ = refl
abstract
start-abs = start.step₀
start-abs-≡ : start-abs ≡ start.step₀
start-abs-≡ = refl
| {
"alphanum_fraction": 0.6224609276,
"avg_line_length": 39.0516898608,
"ext": "agda",
"hexsha": "fa0594164f9bddb67f7ec3a16bdcaf044fecb2a2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/RoundManager.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/RoundManager.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/RoundManager.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5151,
"size": 19643
} |
module Introduction.Universes where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
postulate IsEven : Nat -> Prop
data Even : Set where
even : (n : Nat) -> IsEven n -> Even
| {
"alphanum_fraction": 0.6417112299,
"avg_line_length": 14.3846153846,
"ext": "agda",
"hexsha": "cb192eab5daae544a3fcbd5ab29bbc048cf81a94",
"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": "examples/Introduction/Universes.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": "examples/Introduction/Universes.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/Introduction/Universes.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": 57,
"size": 187
} |
module Nat.Unary where
open import Data.Sum
open import Function
open import Nat.Class
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
data ℕ₁ : Set where
zero : ℕ₁
succ : ℕ₁ → ℕ₁
ind : (P : ℕ₁ → Set) → P zero → (∀ {k} → P k → P (succ k)) → ∀ n → P n
ind P z s zero = z
ind P z s (succ n) = ind (P ∘ succ) (s z) (λ {k} → s {succ k}) n
ind′ : (P : ℕ₁ → Set) → P zero → (∀ {k} → P k → P (succ k)) → ∀ n → P n
ind′ P z s zero = z
ind′ P z s (succ n) = s (ind′ P z s n)
rec : {A : Set} → A → (A → A) → ℕ₁ → A
rec {A} z s n = ind (const A) z (λ {_} → s) n
rec-succ : ∀ {A} z (s : A → A) n → rec (s z) s n ≡ s (rec z s n)
rec-succ z s zero = refl
rec-succ z s (succ n) =
begin
rec (s z) s (succ n)
≡⟨⟩
rec (s (s z)) s n
≡⟨ rec-succ (s z) s n ⟩
s (rec (s z) s n)
≡⟨⟩
s (rec z s (succ n))
∎
data _<_ : ℕ₁ → ℕ₁ → Set where
z<s : ∀ {n} → zero < succ n
s<s : ∀ {m n} → m < n → succ m < succ n
n<sn : ∀ {n} → n < succ n
n<sn {zero} = z<s
n<sn {succ n} = s<s n<sn
tighten : ∀ {m n} → m < succ n → m < n ⊎ m ≡ n
tighten {zero} {zero} z<s = inj₂ refl
tighten {zero} {succ n′} z<s = inj₁ z<s
tighten {succ m′} {succ n′} (s<s m′<sn′) with tighten m′<sn′
tighten {succ m′} {succ n′} (s<s m′<sn′) | inj₁ m′<n′ = inj₁ (s<s m′<n′)
tighten {succ m′} {succ n′} (s<s m′<sn′) | inj₂ m′≡n′ = inj₂ (cong succ m′≡n′)
SIndHyp : (ℕ₁ → Set) → ℕ₁ → Set
SIndHyp P n = ∀ {m} → m < n → P m
sind : (P : ℕ₁ → Set) → (∀ {k} → SIndHyp P k → P k) → ∀ n → P n
sind P h n = prf (succ n) {n} n<sn
where
lem : {p : ℕ₁} (hp : SIndHyp P p) → SIndHyp P (succ p)
lem hp m<sp with tighten m<sp
lem hp m<sp | inj₁ m<p = hp m<p
lem hp m<sp | inj₂ refl = h hp
prf : ∀ n → SIndHyp P n
prf = ind (SIndHyp P) (λ ()) lem
_+_ : ℕ₁ → ℕ₁ → ℕ₁
m + n = rec n succ m
+-zero : ∀ {n} → zero + n ≡ n
+-zero = refl
+-succ : ∀ {m n} → succ m + n ≡ m + succ n
+-succ = refl
instance
Nat-ℕ₁ : Nat ℕ₁
Nat-ℕ₁ = record
{ zero = zero
; succ = succ
; ind = ind
; _+_ = _+_
; +-zero = +-zero
; +-succ = λ {m n} → +-succ {m} {n}
}
| {
"alphanum_fraction": 0.4932756964,
"avg_line_length": 24.4941176471,
"ext": "agda",
"hexsha": "e1b570dd0db17f40f521addf45531c3bdffba4d6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-28T12:49:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-28T12:49:47.000Z",
"max_forks_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iblech/agda-quotients",
"max_forks_repo_path": "src/Nat/Unary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"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": "iblech/agda-quotients",
"max_issues_repo_path": "src/Nat/Unary.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b51e83acf193a556a61d44a4585a6467a383fa3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iblech/agda-quotients",
"max_stars_repo_path": "src/Nat/Unary.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-29T13:10:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-29T13:10:27.000Z",
"num_tokens": 971,
"size": 2082
} |
module Relation.Ternary.Separation.Monad.Delay where
open import Level
open import Function
open import Function using (_∘_; case_of_)
open import Relation.Binary.PropositionalEquality
open import Relation.Unary
open import Relation.Unary.PredicateTransformer hiding (_⊔_)
open import Relation.Ternary.Separation
open import Relation.Ternary.Separation.Monad
open import Relation.Ternary.Separation.Morphisms
open import Codata.Delay as D using (now; later) public
open import Data.Unit
open Monads
module _ {ℓ}
{C : Set ℓ} {u}
{{r : RawSep C}}
{{us : IsUnitalSep r u}}
where
Delay : ∀ {ℓ} i → Pt C ℓ
Delay i P c = D.Delay (P c) i
instance
delay-monad : ∀ {i} → Monad ⊤ ℓ (λ _ _ → Delay i)
Monad.return delay-monad px = D.now px
app (Monad.bind delay-monad f) ►px σ = D.bind ►px λ px → app f px σ
| {
"alphanum_fraction": 0.7218863362,
"avg_line_length": 27.5666666667,
"ext": "agda",
"hexsha": "15a2d9e64735790c8f82bba2a5d7db9ed4770bff",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Monad/Delay.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"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": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Monad/Delay.agda",
"max_line_length": 71,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Monad/Delay.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 248,
"size": 827
} |
module Cats.Trans where
open import Level using (_⊔_)
open import Cats.Category.Base
open import Cats.Functor using (Functor)
open Functor
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
where
infixr 9 _∘_
private
module C = Category C
module D = Category D
open D.≈-Reasoning
record Trans (F G : Functor C D) : Set (lo ⊔ la ⊔ la′ ⊔ l≈′) where
field
component : (c : C.Obj) → fobj F c D.⇒ fobj G c
natural : ∀ {c d} {f : c C.⇒ d}
→ component d D.∘ fmap F f D.≈ fmap G f D.∘ component c
open Trans public
id : ∀ {F} → Trans F F
id {F} = record
{ component = λ _ → D.id
; natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
_∘_ : ∀ {F G H} → Trans G H → Trans F G → Trans F H
_∘_ {F} {G} {H} θ ι = record
{ component = λ c → component θ c D.∘ component ι c
; natural = λ {c} {d} {f} →
begin
(component θ d D.∘ component ι d) D.∘ fmap F f
≈⟨ D.assoc ⟩
component θ d D.∘ component ι d D.∘ fmap F f
≈⟨ D.∘-resp-r (natural ι) ⟩
component θ d D.∘ fmap G f D.∘ component ι c
≈⟨ D.unassoc ⟩
(component θ d D.∘ fmap G f) D.∘ component ι c
≈⟨ D.∘-resp-l (natural θ) ⟩
(fmap H f D.∘ component θ c) D.∘ component ι c
≈⟨ D.assoc ⟩
fmap H f D.∘ component θ c D.∘ component ι c
∎
}
| {
"alphanum_fraction": 0.5058823529,
"avg_line_length": 24.9137931034,
"ext": "agda",
"hexsha": "53e72ba21e9717a1468cacc42026a29505830c0a",
"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": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Trans.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"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": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Trans.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Trans.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 577,
"size": 1445
} |
module IID-New-Proof-Setup where
open import LF
open import Identity
open import IID
open import IIDr
open import DefinitionalEquality
OPg : Set -> Set1
OPg I = OP I I
-- Encoding indexed inductive types as non-indexed types.
ε : {I : Set}(γ : OPg I) -> OPr I
ε (ι i) j = σ (i == j) (\_ -> ι ★)
ε (σ A γ) j = σ A (\a -> ε (γ a) j)
ε (δ H i γ) j = δ H i (ε γ j)
-- Adds a reflexivity proof.
g→rArgs : {I : Set}(γ : OPg I)(U : I -> Set)
(a : Args γ U) ->
rArgs (ε γ) U (index γ U a)
g→rArgs (ι e) U arg = (refl , ★)
g→rArgs (σ A γ) U arg = (π₀ arg , g→rArgs (γ (π₀ arg)) U (π₁ arg))
g→rArgs (δ H i γ) U arg = (π₀ arg , g→rArgs γ U (π₁ arg))
| {
"alphanum_fraction": 0.5558867362,
"avg_line_length": 24.8518518519,
"ext": "agda",
"hexsha": "b4c6e17ed3db69a5b9f03eaa8ecf41a01c6365c0",
"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": "examples/outdated-and-incorrect/iird/IID-New-Proof-Setup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/iird/IID-New-Proof-Setup.agda",
"max_line_length": 68,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/iird/IID-New-Proof-Setup.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": 273,
"size": 671
} |
module Data.Collection.Equivalence where
open import Data.Collection.Core
open import Function using (id; _∘_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; equivalence)
open Function.Equivalence.Equivalence
open import Relation.Binary.PropositionalEquality
open import Level using (zero)
open import Relation.Nullary
open import Relation.Unary
open import Relation.Binary
nach : ∀ {f t} {A : Set f} {B : Set t} → (A ⇔ B) → A → B
nach = _⟨$⟩_ ∘ to
von : ∀ {f t} {A : Set f} {B : Set t} → (A ⇔ B) → B → A
von = _⟨$⟩_ ∘ from
infixr 5 _≋_
_≋_ : Rel Membership _
A ≋ B = {x : Element} → x ∈ A ⇔ x ∈ B
≋-Reflexive : Reflexive _≋_
≋-Reflexive = equivalence id id
≋-Symmetric : Symmetric _≋_
≋-Symmetric z = record
{ to = from z
; from = to z
}
≋-Transitive : Transitive _≋_
≋-Transitive P≋Q Q≋R = equivalence (nach Q≋R ∘ nach P≋Q) (von P≋Q ∘ von Q≋R)
≋-IsEquivalence : IsEquivalence _≋_
≋-IsEquivalence = record
{ refl = equivalence id id
; sym = ≋-Symmetric
; trans = ≋-Transitive
}
≋-Setoid : Setoid _ _
≋-Setoid = record
{ Carrier = Pred Element zero
; _≈_ = _≋_
; isEquivalence = ≋-IsEquivalence
}
--------------------------------------------------------------------------------
-- Conditional Equivalence
--------------------------------------------------------------------------------
_≋[_]_ : ∀ {a} → Membership → Pred Element a → Membership → Set a
A ≋[ P ] B = {x : Element} → P x → x ∈ A ⇔ x ∈ B
-- prefix version of _≋[_]_, with the predicate being the first argument
[_]≋ : ∀ {a} → Pred Element a → Membership → Membership → Set a
[_]≋ P A B = A ≋[ P ] B
≋[]-Reflexive : ∀ {a} {P : Pred Element a} → Reflexive [ P ]≋
≋[]-Reflexive A = equivalence id id
≋[]-Symmetric : ∀ {a} {P : Pred Element a} → Symmetric [ P ]≋
≋[]-Symmetric z ∈P = record
{ to = from (z ∈P)
; from = to (z ∈P)
}
≋[]-Transitive : ∀ {a} {P : Pred Element a} → Transitive [ P ]≋
≋[]-Transitive P≋Q Q≋R ∈P = equivalence (nach (Q≋R ∈P) ∘ nach (P≋Q ∈P)) (von (P≋Q ∈P) ∘ von (Q≋R ∈P))
≋[]-IsEquivalence : ∀ {a} {P : Pred Element a} → IsEquivalence [ P ]≋
≋[]-IsEquivalence {p} = record
{ refl = λ _ → equivalence id id
; sym = ≋[]-Symmetric
; trans = ≋[]-Transitive
}
| {
"alphanum_fraction": 0.559262511,
"avg_line_length": 26.8,
"ext": "agda",
"hexsha": "2fcfa3f6ed97b0f21b28f47d89fa793270e01fdc",
"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": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/lambda-calculus",
"max_forks_repo_path": "Data/Collection/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/lambda-calculus",
"max_issues_repo_path": "Data/Collection/Equivalence.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/lambda-calculus",
"max_stars_repo_path": "Data/Collection/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 822,
"size": 2278
} |
{-# OPTIONS --universe-polymorphism #-}
-- Free category generated by a directed graph.
-- The graph is given by a type (Obj) of nodes and a (Obj × Obj)-indexed
-- Setoid of (directed) edges. Every inhabitant of the node type is
-- considered to be a (distinct) node of the graph, and (equivalence
-- classes of) inhabitants of the edge type (for a given pair of
-- nodes) are considered edges of the graph.
module Categories.Free.Core where
open import Categories.Category
open import Categories.Functor
using (Functor)
open import Categories.Support.Equivalence
open import Graphs.Graph
open import Graphs.GraphMorphism
open import Relation.Binary
using (module IsEquivalence)
open import Relation.Binary.PropositionalEquality
using ()
renaming (_≡_ to _≣_; refl to ≣-refl)
open import Data.Star
open import Categories.Support.StarEquality
open import Data.Star.Properties
using (gmap-◅◅)
open import Level using (_⊔_)
EdgeSetoid : ∀ {o ℓ e} → (G : Graph o ℓ e) (A B : Graph.Obj G) → Setoid ℓ e
EdgeSetoid G A B = Graph.edge-setoid G {A}{B}
module PathEquality {o ℓ e} (G : Graph o ℓ e) = StarEquality (EdgeSetoid G)
Free₀ : ∀ {o ℓ e} → Graph o ℓ e → Category o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e)
Free₀ {o}{ℓ}{e} G = record
{ Obj = Obj
; _⇒_ = Star _↝_
; id = ε
; _∘_ = _▻▻_
; _≡_ = _≡_
; equiv = equiv
; assoc = λ{A}{B}{C}{D} {f}{g}{h} → ▻▻-assoc {A}{B}{C}{D} f g h
; identityˡ = IsEquivalence.reflexive equiv f◅◅ε≣f
; identityʳ = IsEquivalence.reflexive equiv ≣-refl
; ∘-resp-≡ = _▻▻-cong_
}
where
open Graph G
hiding (equiv)
open PathEquality G
renaming (_≈_ to _≡_; isEquivalence to equiv)
f◅◅ε≣f : ∀ {A B}{f : Star _↝_ A B} -> (f ◅◅ ε) ≣ f
f◅◅ε≣f {f = ε} = ≣-refl
f◅◅ε≣f {f = x ◅ xs} rewrite f◅◅ε≣f {f = xs} = ≣-refl
Free₁ : ∀ {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂}
{A : Graph o₁ ℓ₁ e₁}
{B : Graph o₂ ℓ₂ e₂}
→ GraphMorphism A B → Functor (Free₀ A) (Free₀ B)
Free₁ {o₁}{ℓ₁}{e₁}{o₂}{ℓ₂}{e₂}{A}{B} G = record
{ F₀ = G₀
; F₁ = gmap G₀ G₁
; identity = refl
; homomorphism = λ {X}{Y}{Z}{f}{g} → homomorphism {X}{Y}{Z}{f}{g}
; F-resp-≡ = F-resp-≡
}
where
open GraphMorphism G
renaming (F₀ to G₀; F₁ to G₁; F-resp-≈ to G-resp-≈)
open Category.Equiv (Free₀ B)
.homomorphism : ∀ {X Y Z}
{f : Free₀ A [ X , Y ]}
{g : Free₀ A [ Y , Z ]}
→ Free₀ B [ gmap G₀ G₁ (f ◅◅ g) ≡ gmap G₀ G₁ f ◅◅ gmap G₀ G₁ g ]
homomorphism {f = f}{g} = reflexive (gmap-◅◅ G₀ G₁ f g)
.F-resp-≡ : ∀ {X Y}
{f g : Free₀ A [ X , Y ]}
→ Free₀ A [ f ≡ g ]
→ Free₀ B [ gmap G₀ G₁ f ≡ gmap G₀ G₁ g ]
F-resp-≡ {X}{Y}{f}{g} f≡g
= gmap-cong G₀ G₁ G₁ (λ x y x≈y → G-resp-≈ x≈y) f g f≡g
where
open StarCong₂ (EdgeSetoid A) (EdgeSetoid B)
| {
"alphanum_fraction": 0.5782073814,
"avg_line_length": 32.7011494253,
"ext": "agda",
"hexsha": "b3141e4bcbe49af77c9c8c9d25f96e6b833061fb",
"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/Free/Core.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/Free/Core.agda",
"max_line_length": 75,
"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/Free/Core.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": 1150,
"size": 2845
} |
-- 2010-10-06 Andreas
module TerminationRecordPatternListAppend where
data Empty : Set where
record Unit : Set where
constructor unit
data Bool : Set where
true false : Bool
T : Bool -> Set
T true = Unit
T false = Empty
-- Thorsten suggests on the Agda list thread "Coinductive families"
-- to encode lists as records
record List (A : Set) : Set where
constructor list
field
isCons : Bool
head : T isCons -> A
tail : T isCons -> List A
open List public
-- if the record constructor list was counted as structural increase
-- Thorsten's function would not be rejected
append : {A : Set} -> List A -> List A -> List A
append (list true h t) l' = list true h (\ _ -> append (t _) l')
append (list false _ _) l' = l'
-- but translating away the record pattern produces something
-- that is in any case rejected by the termination checker
append1 : {A : Set} -> List A -> List A -> List A
append1 l l' = append1' l l' (isCons l)
where append1' : {A : Set} -> List A -> List A -> Bool -> List A
append1' l l' true = list true (head l) (\ _ -> append (tail l) l')
append1' l l' false = l'
-- NEED inspect!
| {
"alphanum_fraction": 0.6556808326,
"avg_line_length": 27.4523809524,
"ext": "agda",
"hexsha": "b106dc5773c908a2a768604804fe9e75d3bde7e8",
"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/fail/TerminationRecordPatternListAppend.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/fail/TerminationRecordPatternListAppend.agda",
"max_line_length": 76,
"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/fail/TerminationRecordPatternListAppend.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 330,
"size": 1153
} |
{-# OPTIONS --without-K #-}
module Pif where
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid;
proof-irrelevance; module ≡-Reasoning)
open import Data.Nat.Properties using (m≢1+m+n; i+j≡0⇒i≡0; i+j≡0⇒j≡0)
open import Data.Nat.Properties.Simple
using (+-right-identity; +-suc; +-assoc; +-comm;
*-assoc; *-comm; *-right-zero; distribʳ-*-+)
open import Relation.Binary.Core using (Transitive)
open import Data.String using (String)
renaming (_++_ to _++S_)
open import Data.Nat.Show using (show)
open import Data.Bool using (Bool; false; true; _∧_; _∨_)
open import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_;
z≤n; s≤s; _≟_; _≤?_; module ≤-Reasoning)
open import Data.Fin
using (Fin; zero; suc; toℕ; fromℕ; _ℕ-_; _≺_;
raise; inject+; inject₁; inject≤; _≻toℕ_)
renaming (_+_ to _F+_)
open import Data.Vec
using (Vec; tabulate; []; _∷_ ; tail; lookup; zip; zipWith; splitAt;
_[_]≔_; allFin; toList)
renaming (_++_ to _++V_; map to mapV; concat to concatV)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import PiLevel0
open import Cauchy
open import Perm
open import Proofs
open import CauchyProofs
open import CauchyProofsT
open import CauchyProofsS
open import Groupoid
------------------------------------------------------------------------------
-- A combinator t₁ ⟷ t₂ denotes a permutation.
c2cauchy : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → Cauchy (size t₁)
-- the cases that do not inspect t₁ and t₂ should be at the beginning
-- so that Agda would unfold them
c2cauchy (c₁ ◎ c₂) =
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
c2cauchy (c₁ ⊕ c₂) = pcompcauchy (c2cauchy c₁) (c2cauchy c₂)
c2cauchy (c₁ ⊗ c₂) = tcompcauchy (c2cauchy c₁) (c2cauchy c₂)
c2cauchy {PLUS ZERO t} unite₊ = idcauchy (size t)
c2cauchy {t} uniti₊ = idcauchy (size t)
c2cauchy {PLUS t₁ t₂} swap₊ = swap+cauchy (size t₁) (size t₂)
c2cauchy {PLUS t₁ (PLUS t₂ t₃)} assocl₊ =
idcauchy (size t₁ + (size t₂ + size t₃))
c2cauchy {PLUS (PLUS t₁ t₂) t₃} assocr₊ =
idcauchy ((size t₁ + size t₂) + size t₃)
c2cauchy {TIMES ONE t} unite⋆ =
subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t))
c2cauchy {t} uniti⋆ = idcauchy (size t)
c2cauchy {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = swap⋆cauchy (size t₁) (size t₂)
c2cauchy {TIMES t₁ (TIMES t₂ t₃)} assocl⋆ =
idcauchy (size t₁ * (size t₂ * size t₃))
c2cauchy {TIMES (TIMES t₁ t₂) t₃} assocr⋆ =
idcauchy ((size t₁ * size t₂) * size t₃)
c2cauchy {TIMES ZERO t} distz = []
c2cauchy factorz = []
c2cauchy {TIMES (PLUS t₁ t₂) t₃} dist =
idcauchy ((size t₁ + size t₂) * size t₃)
c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} factor =
idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))
c2cauchy {t} id⟷ = idcauchy (size t)
c2perm : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → Permutation (size t₁)
-- the cases that do not inspect t₁ and t₂ should be at the beginning
-- so that Agda would unfold them
c2perm (c₁ ◎ c₂) =
scompperm
(c2perm c₁)
(subst Permutation (size≡! c₁) (c2perm c₂))
c2perm (c₁ ⊕ c₂) = pcompperm (c2perm c₁) (c2perm c₂)
c2perm (c₁ ⊗ c₂) = tcompperm (c2perm c₁) (c2perm c₂)
c2perm unfoldBool = idperm 2
c2perm foldBool = idperm 2
c2perm {PLUS ZERO t} unite₊ = idperm (size t)
c2perm {t} uniti₊ = idperm (size t)
c2perm {PLUS t₁ t₂} swap₊ = swap+perm (size t₁) (size t₂)
c2perm {PLUS t₁ (PLUS t₂ t₃)} assocl₊ =
idperm (size t₁ + (size t₂ + size t₃))
c2perm {PLUS (PLUS t₁ t₂) t₃} assocr₊ =
idperm ((size t₁ + size t₂) + size t₃)
c2perm {TIMES ONE t} unite⋆ =
subst Permutation (sym (+-right-identity (size t))) (idperm (size t))
c2perm {t} uniti⋆ = idperm (size t)
c2perm {TIMES t₁ t₂} {TIMES .t₂ .t₁} swap⋆ = swap⋆perm (size t₁) (size t₂)
c2perm {TIMES t₁ (TIMES t₂ t₃)} assocl⋆ =
idperm (size t₁ * (size t₂ * size t₃))
c2perm {TIMES (TIMES t₁ t₂) t₃} assocr⋆ =
idperm ((size t₁ * size t₂) * size t₃)
c2perm {TIMES ZERO t} distz = emptyperm
c2perm factorz = emptyperm
c2perm {TIMES (PLUS t₁ t₂) t₃} dist =
idperm ((size t₁ + size t₂) * size t₃)
c2perm {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} factor =
idperm ((size t₁ * size t₃) + (size t₂ * size t₃))
c2perm {t} id⟷ = idperm (size t)
-- Looking forward to Sec. 2.2 (Functions are functors). The
-- corresponding statement to Lemma 2.2.1 in our setting would be the
-- following. Given any *size preserving* function f : U → U, it is
-- the case that a combinator (path) c : t₁ ⟷ t₂ maps to a combinator
-- (path) ap_f(c) : f(t₁) ⟷ f(t₂).
------------------------------------------------------------------------------
-- Extensional equivalence of combinators
-- Two combinators are equivalent if they denote the same
-- permutation. Generally we would require that the two permutations
-- map the same value x to values y and z that have a path between
-- them, but because the internals of each type are discrete
-- groupoids, this reduces to saying that y and z are identical, and
-- hence that the permutations are identical.
infix 10 _∼_
_∼_ : {t₁ t₂ : U} → (c₁ c₂ : t₁ ⟷ t₂) → Set
c₁ ∼ c₂ = (c2cauchy c₁ ≡ c2cauchy c₂)
-- The relation ~ is an equivalence relation
refl∼ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → (c ∼ c)
refl∼ = refl
sym∼ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₂ ∼ c₁)
sym∼ = sym
trans∼ : {t₁ t₂ : U} {c₁ c₂ c₃ : t₁ ⟷ t₂} → (c₁ ∼ c₂) → (c₂ ∼ c₃) → (c₁ ∼ c₃)
trans∼ = trans
assoc∼ : {t₁ t₂ t₃ t₄ : U} {c₁ : t₁ ⟷ t₂} {c₂ : t₂ ⟷ t₃} {c₃ : t₃ ⟷ t₄} →
c₁ ◎ (c₂ ◎ c₃) ∼ (c₁ ◎ c₂) ◎ c₃
assoc∼ {t₁} {t₂} {t₃} {t₄} {c₁} {c₂} {c₃} =
begin (c2cauchy (c₁ ◎ (c₂ ◎ c₃))
≡⟨ refl ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy c₃))))
≡⟨ cong
(scompcauchy (c2cauchy c₁))
(subst-dist
scompcauchy
(size≡! c₁)
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy c₃))) ⟩
scompcauchy
(c2cauchy c₁)
(scompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
(subst Cauchy (size≡! c₁)
(subst Cauchy (size≡! c₂) (c2cauchy c₃))))
≡⟨ cong (λ x →
scompcauchy
(c2cauchy c₁)
(scompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
x))
(subst-trans (size≡! c₁) (size≡! c₂) (c2cauchy c₃)) ⟩
scompcauchy
(c2cauchy c₁)
(scompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
(subst Cauchy (trans (size≡! c₂) (size≡! c₁)) (c2cauchy c₃)))
≡⟨ scompassoc
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
(subst Cauchy (trans (size≡! c₂) (size≡! c₁)) (c2cauchy c₃)) ⟩
scompcauchy
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))
(subst Cauchy (trans (size≡! c₂) (size≡! c₁)) (c2cauchy c₃))
≡⟨ refl ⟩
c2cauchy ((c₁ ◎ c₂) ◎ c₃) ∎)
where open ≡-Reasoning
-- The combinators c : t₁ ⟷ t₂ are paths; we can transport
-- size-preserving properties across c. In particular, for some
-- appropriate P we want P(t₁) to map to P(t₂) via c.
-- The relation ~ validates the groupoid laws
c◎id∼c : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ◎ id⟷ ∼ c
c◎id∼c {t₁} {t₂} {c} =
begin (c2cauchy (c ◎ id⟷)
≡⟨ refl ⟩
scompcauchy
(c2cauchy c)
(subst Cauchy (size≡! c) (allFin (size t₂)))
≡⟨ cong (λ x → scompcauchy (c2cauchy c) x)
(congD! {B = Cauchy} allFin (size≡! c)) ⟩
scompcauchy (c2cauchy c) (allFin (size t₁))
≡⟨ scomprid (c2cauchy c) ⟩
c2cauchy c ∎)
where open ≡-Reasoning
id◎c∼c : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → id⟷ ◎ c ∼ c
id◎c∼c {t₁} {t₂} {c} =
begin (c2cauchy (id⟷ ◎ c)
≡⟨ refl ⟩
scompcauchy
(allFin (size t₁))
(subst Cauchy refl (c2cauchy c))
≡⟨ refl ⟩
scompcauchy (allFin (size t₁)) (c2cauchy c)
≡⟨ scomplid (c2cauchy c) ⟩
c2cauchy c ∎)
where open ≡-Reasoning
linv∼ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → c ◎ ! c ∼ id⟷
linv∼ {PLUS ZERO t} {.t} {unite₊} =
begin (c2cauchy {PLUS ZERO t} (unite₊ ◎ uniti₊)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t)) (idcauchy (size t))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {PLUS ZERO t} id⟷ ∎)
where open ≡-Reasoning
linv∼ {t} {PLUS ZERO .t} {uniti₊} =
begin (c2cauchy {t} (uniti₊ ◎ unite₊)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t)) (idcauchy (size t))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {t} id⟷ ∎)
where open ≡-Reasoning
linv∼ {PLUS t₁ t₂} {PLUS .t₂ .t₁} {swap₊} =
begin (c2cauchy {PLUS t₁ t₂} (swap₊ ◎ swap₊)
≡⟨ refl ⟩
scompcauchy
(swap+cauchy (size t₁) (size t₂))
(subst Cauchy (+-comm (size t₂) (size t₁))
(swap+cauchy (size t₂) (size t₁)))
≡⟨ swap+idemp (size t₁) (size t₂) ⟩
c2cauchy {PLUS t₁ t₂} id⟷ ∎)
where open ≡-Reasoning
linv∼ {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} {assocl₊} =
begin (c2cauchy {PLUS t₁ (PLUS t₂ t₃)} (assocl₊ ◎ assocr₊)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))
(subst Cauchy (+-assoc (size t₁) (size t₂) (size t₃))
(idcauchy ((size t₁ + size t₂) + size t₃)))
≡⟨ cong
(scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃))))
(congD! idcauchy (+-assoc (size t₁) (size t₂) (size t₃))) ⟩
scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))
(idcauchy (size t₁ + (size t₂ + size t₃)))
≡⟨ scomplid (idcauchy (size t₁ + (size t₂ + size t₃))) ⟩
c2cauchy {PLUS t₁ (PLUS t₂ t₃)} id⟷ ∎)
where open ≡-Reasoning
linv∼ {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} {assocr₊} =
begin (c2cauchy {PLUS (PLUS t₁ t₂) t₃} (assocr₊ ◎ assocl₊)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))
(subst Cauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))
(idcauchy (size t₁ + (size t₂ + size t₃))))
≡⟨ cong
(scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃)))
(congD! idcauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))) ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))
(idcauchy ((size t₁ + size t₂) + size t₃))
≡⟨ scomplid (idcauchy ((size t₁ + size t₂) + size t₃)) ⟩
c2cauchy {PLUS (PLUS t₁ t₂) t₃} id⟷ ∎)
where open ≡-Reasoning
linv∼ {TIMES ONE t} {.t} {unite⋆} =
begin (c2cauchy {TIMES ONE t} (unite⋆ ◎ uniti⋆)
≡⟨ refl ⟩
scompcauchy
(subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))
(subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))
≡⟨ cong
(λ x → scompcauchy x x)
(congD! idcauchy (sym (+-right-identity (size t)))) ⟩
scompcauchy (idcauchy (size t + 0)) (idcauchy (size t + 0))
≡⟨ scomplid (idcauchy (size t + 0)) ⟩
c2cauchy {TIMES ONE t} id⟷ ∎)
where open ≡-Reasoning
linv∼ {t} {TIMES ONE .t} {uniti⋆} =
begin (c2cauchy {t} (uniti⋆ ◎ unite⋆)
≡⟨ refl ⟩
scompcauchy
(idcauchy (size t))
(subst Cauchy (+-right-identity (size t))
(subst Cauchy (sym (+-right-identity (size t)))
(idcauchy (size t))))
≡⟨ cong
(scompcauchy (idcauchy (size t)))
(subst-trans
(+-right-identity (size t))
(sym (+-right-identity (size t)))
(idcauchy (size t))) ⟩
scompcauchy
(idcauchy (size t))
(subst Cauchy (trans (sym (+-right-identity (size t)))
(+-right-identity (size t)))
(idcauchy (size t)))
≡⟨ cong
(λ x → scompcauchy
(idcauchy (size t))
(subst Cauchy x (idcauchy (size t))))
(trans-syml (+-right-identity (size t))) ⟩
scompcauchy
(idcauchy (size t))
(subst Cauchy refl (idcauchy (size t)))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {t} id⟷ ∎)
where open ≡-Reasoning
linv∼ {TIMES t₁ t₂} {TIMES .t₂ .t₁} {swap⋆} =
begin (c2cauchy {TIMES t₁ t₂} (swap⋆ ◎ swap⋆)
≡⟨ refl ⟩
scompcauchy
(swap⋆cauchy (size t₁) (size t₂))
(subst Cauchy (*-comm (size t₂) (size t₁))
(swap⋆cauchy (size t₂) (size t₁)))
≡⟨ swap⋆idemp (size t₁) (size t₂) ⟩
c2cauchy {TIMES t₁ t₂} id⟷ ∎)
where open ≡-Reasoning
linv∼ {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} {assocl⋆} =
begin (c2cauchy {TIMES t₁ (TIMES t₂ t₃)} (assocl⋆ ◎ assocr⋆)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))
(subst Cauchy (*-assoc (size t₁) (size t₂) (size t₃))
(idcauchy ((size t₁ * size t₂) * size t₃)))
≡⟨ cong
(scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃))))
(congD! idcauchy (*-assoc (size t₁) (size t₂) (size t₃))) ⟩
scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))
(idcauchy (size t₁ * (size t₂ * size t₃)))
≡⟨ scomplid (idcauchy (size t₁ * (size t₂ * size t₃))) ⟩
c2cauchy {TIMES t₁ (TIMES t₂ t₃)} id⟷ ∎)
where open ≡-Reasoning
linv∼ {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} {assocr⋆} =
begin (c2cauchy {TIMES (TIMES t₁ t₂) t₃} (assocr⋆ ◎ assocl⋆)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))
(subst Cauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))
(idcauchy (size t₁ * (size t₂ * size t₃))))
≡⟨ cong
(scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃)))
(congD! idcauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))) ⟩
scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))
(idcauchy ((size t₁ * size t₂) * size t₃))
≡⟨ scomplid (idcauchy ((size t₁ * size t₂) * size t₃)) ⟩
c2cauchy {TIMES (TIMES t₁ t₂) t₃} id⟷ ∎)
where open ≡-Reasoning
linv∼ {TIMES ZERO t} {ZERO} {distz} = refl
linv∼ {ZERO} {TIMES ZERO t} {factorz} = refl
linv∼ {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} {dist} =
begin (c2cauchy {TIMES (PLUS t₁ t₂) t₃} (dist ◎ factor)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))
(subst Cauchy (sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))
(idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))
≡⟨ cong
(scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃)))
(congD! idcauchy
(sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))) ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))
(idcauchy ((size t₁ + size t₂) * size t₃))
≡⟨ scomplid (idcauchy ((size t₁ + size t₂) * size t₃)) ⟩
c2cauchy {TIMES (PLUS t₁ t₂) t₃} id⟷ ∎)
where open ≡-Reasoning
linv∼ {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} {factor} =
begin (c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} (factor ◎ dist)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))
(subst Cauchy (distribʳ-*-+ (size t₃) (size t₁) (size t₂))
(idcauchy ((size t₁ + size t₂) * size t₃)))
≡⟨ cong
(scompcauchy
(idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))
(congD! idcauchy
(distribʳ-*-+ (size t₃) (size t₁) (size t₂))) ⟩
scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))
(idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))
≡⟨ scomplid (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))) ⟩
c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} id⟷ ∎)
where open ≡-Reasoning
linv∼ {t} {.t} {id⟷} =
begin (c2cauchy {t} (id⟷ ◎ id⟷)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t)) (idcauchy (size t))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {t} id⟷ ∎)
where open ≡-Reasoning
linv∼ {t₁} {t₃} {_◎_ {t₂ = t₂} c₁ c₂} =
begin (c2cauchy {t₁} ((c₁ ◎ c₂) ◎ ((! c₂) ◎ (! c₁)))
≡⟨ refl ⟩
scompcauchy
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))
(subst Cauchy (trans (size≡! c₂) (size≡! c₁))
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))
≡⟨ sym (scompassoc
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
(subst Cauchy (trans (size≡! c₂) (size≡! c₁))
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))) ⟩
scompcauchy
(c2cauchy c₁)
(scompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
(subst Cauchy (trans (size≡! c₂) (size≡! c₁))
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(scompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
x))
(sym (subst-trans (size≡! c₁) (size≡! c₂)
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))) ⟩
scompcauchy
(c2cauchy c₁)
(scompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy c₂))
(subst Cauchy (size≡! c₁)
(subst Cauchy (size≡! c₂)
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))))
≡⟨ cong
(scompcauchy (c2cauchy c₁))
(sym (subst-dist scompcauchy (size≡! c₁)
(c2cauchy c₂)
(subst Cauchy (size≡! c₂)
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(c2cauchy (! c₁))))))) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₂)
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy (c2cauchy c₂) x)))
(subst-dist scompcauchy (size≡! c₂)
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy
(c2cauchy c₂)
(scompcauchy
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂)))
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) x))
(scompassoc
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂)))
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy
(scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy
x
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂))
(c2cauchy (! c₁)))))))
(linv∼ {t₂} {t₃} {c₂}) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(scompcauchy
(allFin (size t₂))
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) x))
(scomplid
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(subst Cauchy (size≡! c₂)
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) x))
(subst-trans (size≡! c₂) (size≡! (! c₂))
(c2cauchy (! c₁))) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(subst Cauchy (trans (size≡! (! c₂)) (size≡! c₂))
(c2cauchy (! c₁))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁)
(subst Cauchy x (c2cauchy (! c₁)))))
(trans
(cong (λ y → trans y (size≡! c₂)) (size≡!! c₂))
(trans-syml (size≡! c₂))) ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))
≡⟨ linv∼ {t₁} {t₂} {c₁} ⟩
c2cauchy {t₁} id⟷ ∎)
where open ≡-Reasoning
linv∼ {PLUS t₁ t₂} {PLUS t₃ t₄} {c₁ ⊕ c₂} =
begin (c2cauchy {PLUS t₁ t₂} ((c₁ ⊕ c₂) ◎ ((! c₁) ⊕ (! c₂)))
≡⟨ refl ⟩
scompcauchy
(pcompcauchy (c2cauchy c₁) (c2cauchy c₂))
(subst Cauchy (cong₂ _+_ (size≡! c₁) (size≡! c₂))
(pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))
≡⟨ cong
(scompcauchy (pcompcauchy (c2cauchy c₁) (c2cauchy c₂)))
(subst₂+
(size≡! c₁) (size≡! c₂)
(c2cauchy (! c₁)) (c2cauchy (! c₂))
pcompcauchy) ⟩
scompcauchy
(pcompcauchy (c2cauchy c₁) (c2cauchy c₂))
(pcompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))
≡⟨ pcomp-dist
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))
(c2cauchy c₂) (subst Cauchy (size≡! c₂) (c2cauchy (! c₂))) ⟩
pcompcauchy
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁))))
(scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))
≡⟨ cong₂ pcompcauchy (linv∼ {t₁} {t₃} {c₁}) (linv∼ {t₂} {t₄} {c₂}) ⟩
pcompcauchy (c2cauchy {t₁} id⟷) (c2cauchy {t₂} id⟷)
≡⟨ pcomp-id {size t₁} {size t₂} ⟩
c2cauchy {PLUS t₁ t₂} id⟷ ∎)
where open ≡-Reasoning
linv∼ {TIMES t₁ t₂} {TIMES t₃ t₄} {c₁ ⊗ c₂} =
begin (c2cauchy {TIMES t₁ t₂} ((c₁ ⊗ c₂) ◎ ((! c₁) ⊗ (! c₂)))
≡⟨ refl ⟩
scompcauchy
(tcompcauchy (c2cauchy c₁) (c2cauchy c₂))
(subst Cauchy (cong₂ _*_ (size≡! c₁) (size≡! c₂))
(tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))
≡⟨ cong
(scompcauchy (tcompcauchy (c2cauchy c₁) (c2cauchy c₂)))
(subst₂*
(size≡! c₁) (size≡! c₂)
(c2cauchy (! c₁)) (c2cauchy (! c₂))
tcompcauchy) ⟩
scompcauchy
(tcompcauchy (c2cauchy c₁) (c2cauchy c₂))
(tcompcauchy
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))
≡⟨ tcomp-dist
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁)))
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂))) ⟩
tcompcauchy
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy (! c₁))))
(scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy (! c₂))))
≡⟨ cong₂ tcompcauchy (linv∼ {t₁} {t₃} {c₁}) (linv∼ {t₂} {t₄} {c₂}) ⟩
tcompcauchy (c2cauchy {t₁} id⟷) (c2cauchy {t₂} id⟷)
≡⟨ tcomp-id {size t₁} {size t₂} ⟩
c2cauchy {TIMES t₁ t₂} id⟷ ∎)
where open ≡-Reasoning
linv∼ {PLUS ONE ONE} {BOOL} {foldBool} =
begin (c2cauchy {PLUS ONE ONE} (foldBool ◎ unfoldBool)
≡⟨ refl ⟩
scompcauchy (idcauchy 2) (idcauchy 2)
≡⟨ scomplid (idcauchy 2) ⟩
c2cauchy {PLUS ONE ONE} id⟷ ∎)
where open ≡-Reasoning
linv∼ {BOOL} {PLUS ONE ONE} {unfoldBool} =
begin (c2cauchy {BOOL} (unfoldBool ◎ foldBool)
≡⟨ refl ⟩
scompcauchy (idcauchy 2) (idcauchy 2)
≡⟨ scomplid (idcauchy 2) ⟩
c2cauchy {BOOL} id⟷ ∎)
where open ≡-Reasoning
rinv∼ : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → ! c ◎ c ∼ id⟷
rinv∼ {PLUS ZERO t} {.t} {unite₊} =
begin (c2cauchy {t} (uniti₊ ◎ unite₊)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t)) (idcauchy (size t))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {t} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {t} {PLUS ZERO .t} {uniti₊} =
begin (c2cauchy {PLUS ZERO t} (unite₊ ◎ uniti₊)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t)) (idcauchy (size t))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {PLUS ZERO t} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {PLUS t₁ t₂} {PLUS .t₂ .t₁} {swap₊} =
begin (c2cauchy {PLUS t₂ t₁} (swap₊ ◎ swap₊)
≡⟨ refl ⟩
scompcauchy
(swap+cauchy (size t₂) (size t₁))
(subst Cauchy (+-comm (size t₁) (size t₂))
(swap+cauchy (size t₁) (size t₂)))
≡⟨ swap+idemp (size t₂) (size t₁) ⟩
c2cauchy {PLUS t₂ t₁} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {PLUS t₁ (PLUS t₂ t₃)} {PLUS (PLUS .t₁ .t₂) .t₃} {assocl₊} =
begin (c2cauchy {PLUS (PLUS t₁ t₂) t₃} (assocr₊ ◎ assocl₊)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))
(subst Cauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))
(idcauchy (size t₁ + (size t₂ + size t₃))))
≡⟨ cong
(scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃)))
(congD! idcauchy (sym (+-assoc (size t₁) (size t₂) (size t₃)))) ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) + size t₃))
(idcauchy ((size t₁ + size t₂) + size t₃))
≡⟨ scomplid (idcauchy ((size t₁ + size t₂) + size t₃)) ⟩
c2cauchy {PLUS (PLUS t₁ t₂) t₃} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {PLUS (PLUS t₁ t₂) t₃} {PLUS .t₁ (PLUS .t₂ .t₃)} {assocr₊} =
begin (c2cauchy {PLUS t₁ (PLUS t₂ t₃)} (assocl₊ ◎ assocr₊)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))
(subst Cauchy (+-assoc (size t₁) (size t₂) (size t₃))
(idcauchy ((size t₁ + size t₂) + size t₃)))
≡⟨ cong
(scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃))))
(congD! idcauchy (+-assoc (size t₁) (size t₂) (size t₃))) ⟩
scompcauchy (idcauchy (size t₁ + (size t₂ + size t₃)))
(idcauchy (size t₁ + (size t₂ + size t₃)))
≡⟨ scomplid (idcauchy (size t₁ + (size t₂ + size t₃))) ⟩
c2cauchy {PLUS t₁ (PLUS t₂ t₃)} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {TIMES ONE t} {.t} {unite⋆} =
begin (c2cauchy {t} (uniti⋆ ◎ unite⋆)
≡⟨ refl ⟩
scompcauchy
(idcauchy (size t))
(subst Cauchy (+-right-identity (size t))
(subst Cauchy (sym (+-right-identity (size t)))
(idcauchy (size t))))
≡⟨ cong
(scompcauchy (idcauchy (size t)))
(subst-trans
(+-right-identity (size t))
(sym (+-right-identity (size t)))
(idcauchy (size t))) ⟩
scompcauchy
(idcauchy (size t))
(subst Cauchy (trans (sym (+-right-identity (size t)))
(+-right-identity (size t)))
(idcauchy (size t)))
≡⟨ cong
(λ x → scompcauchy
(idcauchy (size t))
(subst Cauchy x (idcauchy (size t))))
(trans-syml (+-right-identity (size t))) ⟩
scompcauchy
(idcauchy (size t))
(subst Cauchy refl (idcauchy (size t)))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {t} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {t} {TIMES ONE .t} {uniti⋆} =
begin (c2cauchy {TIMES ONE t} (unite⋆ ◎ uniti⋆)
≡⟨ refl ⟩
scompcauchy
(subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))
(subst Cauchy (sym (+-right-identity (size t))) (idcauchy (size t)))
≡⟨ cong
(λ x → scompcauchy x x)
(congD! idcauchy (sym (+-right-identity (size t)))) ⟩
scompcauchy (idcauchy (size t + 0)) (idcauchy (size t + 0))
≡⟨ scomplid (idcauchy (size t + 0)) ⟩
c2cauchy {TIMES ONE t} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {TIMES t₁ t₂} {TIMES .t₂ .t₁} {swap⋆} =
begin (c2cauchy {TIMES t₂ t₁} (swap⋆ ◎ swap⋆)
≡⟨ refl ⟩
scompcauchy
(swap⋆cauchy (size t₂) (size t₁))
(subst Cauchy (*-comm (size t₁) (size t₂))
(swap⋆cauchy (size t₁) (size t₂)))
≡⟨ swap⋆idemp (size t₂) (size t₁) ⟩
c2cauchy {TIMES t₂ t₁} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {TIMES t₁ (TIMES t₂ t₃)} {TIMES (TIMES .t₁ .t₂) .t₃} {assocl⋆} =
begin (c2cauchy {TIMES (TIMES t₁ t₂) t₃} (assocr⋆ ◎ assocl⋆)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))
(subst Cauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))
(idcauchy (size t₁ * (size t₂ * size t₃))))
≡⟨ cong
(scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃)))
(congD! idcauchy (sym (*-assoc (size t₁) (size t₂) (size t₃)))) ⟩
scompcauchy (idcauchy ((size t₁ * size t₂) * size t₃))
(idcauchy ((size t₁ * size t₂) * size t₃))
≡⟨ scomplid (idcauchy ((size t₁ * size t₂) * size t₃)) ⟩
c2cauchy {TIMES (TIMES t₁ t₂) t₃} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {TIMES (TIMES t₁ t₂) t₃} {TIMES .t₁ (TIMES .t₂ .t₃)} {assocr⋆} =
begin (c2cauchy {TIMES t₁ (TIMES t₂ t₃)} (assocl⋆ ◎ assocr⋆)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))
(subst Cauchy (*-assoc (size t₁) (size t₂) (size t₃))
(idcauchy ((size t₁ * size t₂) * size t₃)))
≡⟨ cong
(scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃))))
(congD! idcauchy (*-assoc (size t₁) (size t₂) (size t₃))) ⟩
scompcauchy (idcauchy (size t₁ * (size t₂ * size t₃)))
(idcauchy (size t₁ * (size t₂ * size t₃)))
≡⟨ scomplid (idcauchy (size t₁ * (size t₂ * size t₃))) ⟩
c2cauchy {TIMES t₁ (TIMES t₂ t₃)} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {TIMES ZERO t} {ZERO} {distz} = refl
rinv∼ {ZERO} {TIMES ZERO t} {factorz} = refl
rinv∼ {TIMES (PLUS t₁ t₂) t₃} {PLUS (TIMES .t₁ .t₃) (TIMES .t₂ .t₃)} {dist} =
begin (c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} (factor ◎ dist)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))
(subst Cauchy (distribʳ-*-+ (size t₃) (size t₁) (size t₂))
(idcauchy ((size t₁ + size t₂) * size t₃)))
≡⟨ cong
(scompcauchy
(idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))
(congD! idcauchy
(distribʳ-*-+ (size t₃) (size t₁) (size t₂))) ⟩
scompcauchy (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))
(idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃)))
≡⟨ scomplid (idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))) ⟩
c2cauchy {PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {PLUS (TIMES t₁ t₃) (TIMES t₂ .t₃)} {TIMES (PLUS .t₁ .t₂) .t₃} {factor} =
begin (c2cauchy {TIMES (PLUS t₁ t₂) t₃} (dist ◎ factor)
≡⟨ refl ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))
(subst Cauchy (sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))
(idcauchy ((size t₁ * size t₃) + (size t₂ * size t₃))))
≡⟨ cong
(scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃)))
(congD! idcauchy
(sym (distribʳ-*-+ (size t₃) (size t₁) (size t₂)))) ⟩
scompcauchy (idcauchy ((size t₁ + size t₂) * size t₃))
(idcauchy ((size t₁ + size t₂) * size t₃))
≡⟨ scomplid (idcauchy ((size t₁ + size t₂) * size t₃)) ⟩
c2cauchy {TIMES (PLUS t₁ t₂) t₃} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {t} {.t} {id⟷} =
begin (c2cauchy {t} (id⟷ ◎ id⟷)
≡⟨ refl ⟩
scompcauchy (idcauchy (size t)) (idcauchy (size t))
≡⟨ scomplid (idcauchy (size t)) ⟩
c2cauchy {t} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {t₁} {t₃} {_◎_ {t₂ = t₂} c₁ c₂} =
begin (c2cauchy {t₃} (((! c₂) ◎ (! c₁)) ◎ (c₁ ◎ c₂))
≡⟨ refl ⟩
scompcauchy
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁))))
(subst Cauchy (trans (size≡! (! c₁)) (size≡! (! c₂)))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))
≡⟨ sym (scompassoc
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))
(subst Cauchy (trans (size≡! (! c₁)) (size≡! (! c₂)))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))) ⟩
scompcauchy
(c2cauchy (! c₂))
(scompcauchy
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))
(subst Cauchy (trans (size≡! (! c₁)) (size≡! (! c₂)))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(scompcauchy
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))
x))
(sym (subst-trans (size≡! (! c₂)) (size≡! (! c₁))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))) ⟩
scompcauchy
(c2cauchy (! c₂))
(scompcauchy
(subst Cauchy (size≡! (! c₂)) (c2cauchy (! c₁)))
(subst Cauchy (size≡! (! c₂))
(subst Cauchy (size≡! (! c₁))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))))
≡⟨ cong
(scompcauchy (c2cauchy (! c₂)))
(sym (subst-dist scompcauchy (size≡! (! c₂))
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))))) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(scompcauchy
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁))
(scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(scompcauchy (c2cauchy (! c₁)) x)))
(subst-dist scompcauchy (size≡! (! c₁))
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₂))) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(scompcauchy
(c2cauchy (! c₁))
(scompcauchy
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) x))
(scompassoc
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(scompcauchy
(scompcauchy
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁)))
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(scompcauchy
x
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))))
(rinv∼ {t₁} {t₂} {c₁}) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(scompcauchy
(allFin (size t₂))
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) x))
(scomplid
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂)))) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(subst Cauchy (size≡! (! c₁))
(subst Cauchy (size≡! c₁) (c2cauchy c₂))))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) x))
(subst-trans (size≡! (! c₁)) (size≡! c₁) (c2cauchy c₂)) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(subst Cauchy (trans (size≡! c₁) (size≡! (! c₁)))
(c2cauchy c₂)))
≡⟨ cong
(λ x → scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂))
(subst Cauchy x (c2cauchy c₂))))
(trans
(cong (λ y → trans (size≡! c₁) y) (size≡!! c₁))
(trans-symr (size≡! c₁))) ⟩
scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy c₂))
≡⟨ rinv∼ {t₂} {t₃} {c₂} ⟩
c2cauchy {t₃} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {PLUS t₁ t₂} {PLUS t₃ t₄} {c₁ ⊕ c₂} =
begin (c2cauchy {PLUS t₃ t₄} (((! c₁) ⊕ (! c₂)) ◎ (c₁ ⊕ c₂))
≡⟨ refl ⟩
scompcauchy
(pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))
(subst Cauchy (cong₂ _+_ (size≡! (! c₁)) (size≡! (! c₂)))
(pcompcauchy (c2cauchy c₁) (c2cauchy c₂)))
≡⟨ cong
(scompcauchy (pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))
(subst₂+
(size≡! (! c₁)) (size≡! (! c₂))
(c2cauchy c₁) (c2cauchy c₂)
pcompcauchy) ⟩
scompcauchy
(pcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))
(pcompcauchy
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))
(subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))
≡⟨ pcomp-dist
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))
(c2cauchy (! c₂)) (subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)) ⟩
pcompcauchy
(scompcauchy
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁)))
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))
≡⟨ cong₂ pcompcauchy (rinv∼ {t₁} {t₃} {c₁}) (rinv∼ {t₂} {t₄} {c₂}) ⟩
pcompcauchy (c2cauchy {t₃} id⟷) (c2cauchy {t₄} id⟷)
≡⟨ pcomp-id {size t₃} {size t₄} ⟩
c2cauchy {PLUS t₃ t₄} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {TIMES t₁ t₂} {TIMES t₃ t₄} {c₁ ⊗ c₂} =
begin (c2cauchy {TIMES t₃ t₄} (((! c₁) ⊗ (! c₂)) ◎ (c₁ ⊗ c₂))
≡⟨ refl ⟩
scompcauchy
(tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))
(subst Cauchy (cong₂ _*_ (size≡! (! c₁)) (size≡! (! c₂)))
(tcompcauchy (c2cauchy c₁) (c2cauchy c₂)))
≡⟨ cong
(scompcauchy (tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂))))
(subst₂*
(size≡! (! c₁)) (size≡! (! c₂))
(c2cauchy c₁) (c2cauchy c₂)
tcompcauchy) ⟩
scompcauchy
(tcompcauchy (c2cauchy (! c₁)) (c2cauchy (! c₂)))
(tcompcauchy
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))
(subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))
≡⟨ tcomp-dist
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁))
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)) ⟩
tcompcauchy
(scompcauchy
(c2cauchy (! c₁))
(subst Cauchy (size≡! (! c₁)) (c2cauchy c₁)))
(scompcauchy
(c2cauchy (! c₂))
(subst Cauchy (size≡! (! c₂)) (c2cauchy c₂)))
≡⟨ cong₂ tcompcauchy (rinv∼ {t₁} {t₃} {c₁}) (rinv∼ {t₂} {t₄} {c₂}) ⟩
tcompcauchy (c2cauchy {t₃} id⟷) (c2cauchy {t₄} id⟷)
≡⟨ tcomp-id {size t₃} {size t₄} ⟩
c2cauchy {TIMES t₃ t₄} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {PLUS ONE ONE} {BOOL} {foldBool} =
begin (c2cauchy {BOOL} (unfoldBool ◎ foldBool)
≡⟨ refl ⟩
scompcauchy (idcauchy 2) (idcauchy 2)
≡⟨ scomplid (idcauchy 2) ⟩
c2cauchy {BOOL} id⟷ ∎)
where open ≡-Reasoning
rinv∼ {BOOL} {PLUS ONE ONE} {unfoldBool} =
begin (c2cauchy {PLUS ONE ONE} (foldBool ◎ unfoldBool)
≡⟨ refl ⟩
scompcauchy (idcauchy 2) (idcauchy 2)
≡⟨ scomplid (idcauchy 2) ⟩
c2cauchy {PLUS ONE ONE} id⟷ ∎)
where open ≡-Reasoning
resp∼ : {t₁ t₂ t₃ : U} {c₁ c₂ : t₁ ⟷ t₂} {c₃ c₄ : t₂ ⟷ t₃} →
(c₁ ∼ c₂) → (c₃ ∼ c₄) → (c₁ ◎ c₃ ∼ c₂ ◎ c₄)
resp∼ {t₁} {t₂} {t₃} {c₁} {c₂} {c₃} {c₄} c₁∼c₂ c₃∼c₄ =
begin (c2cauchy (c₁ ◎ c₃)
≡⟨ refl ⟩
scompcauchy
(c2cauchy c₁)
(subst Cauchy (size≡! c₁) (c2cauchy c₃))
≡⟨ cong₂
(λ x y → scompcauchy x (subst Cauchy (size≡! c₁) y))
c₁∼c₂ c₃∼c₄ ⟩
scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₁) (c2cauchy c₄))
≡⟨ cong
(λ x → scompcauchy (c2cauchy c₂) (subst Cauchy x (c2cauchy c₄)))
(size∼! c₁ c₂) ⟩
scompcauchy
(c2cauchy c₂)
(subst Cauchy (size≡! c₂) (c2cauchy c₄))
≡⟨ refl ⟩
c2cauchy (c₂ ◎ c₄) ∎)
where open ≡-Reasoning
-- The equivalence ∼ of paths makes U a 1groupoid: the points are
-- types (t : U); the 1paths are ⟷; and the 2paths between them are
-- based on extensional equivalence ∼
G : 1Groupoid
G = record
{ set = U
; _↝_ = _⟷_
; _≈_ = _∼_
; id = id⟷
; _∘_ = λ p q → q ◎ p
; _⁻¹ = !
; lneutr = λ c → c◎id∼c {c = c}
; rneutr = λ c → id◎c∼c {c = c}
; assoc = λ c₃ c₂ c₁ → assoc∼ {c₁ = c₁} {c₂ = c₂} {c₃ = c₃}
; equiv = record {
refl = λ {c} → refl∼ {c = c}
; sym = λ {c₁} {c₂} → sym∼ {c₁ = c₁} {c₂ = c₂}
; trans = λ {c₁} {c₂} {c₃} → trans∼ {c₁ = c₁} {c₂ = c₂} {c₃ = c₃}
}
; linv = λ c → linv∼ {c = c}
; rinv = λ c → rinv∼ {c = c}
; ∘-resp-≈ = λ {t₁} {t₂} {t₃} {p} {q} {r} {s} p∼q r∼s →
resp∼ {t₁} {t₂} {t₃} {r} {s} {p} {q} r∼s p∼q
}
-- There are additional laws that should hold:
--
-- assoc⊕∼ : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
-- {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
-- c₁ ⊕ (c₂ ⊕ c₃) ∼ assocl₊ ◎ ((c₁ ⊕ c₂) ⊕ c₃) ◎ assocr₊
--
-- assoc⊗∼ : {t₁ t₂ t₃ t₄ t₅ t₆ : U}
-- {c₁ : t₁ ⟷ t₂} {c₂ : t₃ ⟷ t₄} {c₃ : t₅ ⟷ t₆} →
-- c₁ ⊗ (c₂ ⊗ c₃) ∼ assocl⋆ ◎ ((c₁ ⊗ c₂) ⊗ c₃) ◎ assocr⋆
--
-- but we will turn our attention to completeness below (in Pif2) in a more
-- systematic way.
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4673349758,
"avg_line_length": 42.4945848375,
"ext": "agda",
"hexsha": "d3c5b30a83d3d6e2bb5d7e6beda3ed76c869d830",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/Pif.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/Pif.agda",
"max_line_length": 81,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/Pif.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 19037,
"size": 47084
} |
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Cubical.Path
data D : Set where
c : (@0 x y : D) → x ≡ y
| {
"alphanum_fraction": 0.5892857143,
"avg_line_length": 16,
"ext": "agda",
"hexsha": "158fe1231413cb81d57c05aecc2bd023b4374f3d",
"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/Issue5434-2.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/Issue5434-2.agda",
"max_line_length": 37,
"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/Issue5434-2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 40,
"size": 112
} |
{-
Axiom of Finite Choice
- Yep, it's a theorem actually.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet.FiniteChoice where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_)
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Data.Empty
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.SumFin
open import Cubical.Data.FinSet.Base
open import Cubical.Data.FinSet.Properties
private
variable
ℓ ℓ' : Level
choice≃Fin :
{n : ℕ}(Y : Fin n → Type ℓ) → ((x : Fin n) → ∥ Y x ∥) ≃ ∥ ((x : Fin n) → Y x) ∥
choice≃Fin {n = 0} Y =
isContr→≃Unit (isContrΠ⊥)
⋆ Unit≃Unit*
⋆ invEquiv (propTruncIdempotent≃ isPropUnit*)
⋆ propTrunc≃ (invEquiv (isContr→≃Unit* (isContrΠ⊥ {A = Y})))
choice≃Fin {n = suc n} Y =
Π⊎≃
⋆ Σ-cong-equiv-fst (ΠUnit (λ x → ∥ Y (inl x) ∥))
⋆ Σ-cong-equiv-snd (λ _ → choice≃Fin {n = n} (λ x → Y (inr x)))
⋆ Σ-cong-equiv-fst (propTrunc≃ (invEquiv (ΠUnit (λ x → Y (inl x)))))
⋆ ∥∥-×-≃
⋆ propTrunc≃ (invEquiv (Π⊎≃ {E = Y}))
module _
(X : Type ℓ)(p : isFinOrd X)
(Y : X → Type ℓ') where
private
e = p .snd
choice≃' : ((x : X) → ∥ Y x ∥) ≃ ∥ ((x : X) → Y x) ∥
choice≃' =
equivΠ {B' = λ x → ∥ Y (invEq e x) ∥} e (transpFamily p)
⋆ choice≃Fin _
⋆ propTrunc≃ (invEquiv (equivΠ {B' = λ x → Y (invEq e x)} e (transpFamily p)))
module _
(X : FinSet ℓ)
(Y : X .fst → Type ℓ') where
choice≃ : ((x : X .fst) → ∥ Y x ∥) ≃ ∥ ((x : X .fst) → Y x) ∥
choice≃ =
Prop.rec
(isOfHLevel≃ 1 (isPropΠ (λ x → isPropPropTrunc)) isPropPropTrunc)
(λ p → choice≃' (X .fst) (_ , p) Y) (X .snd .snd)
choice : ((x : X .fst) → ∥ Y x ∥) → ∥ ((x : X .fst) → Y x) ∥
choice = choice≃ .fst
| {
"alphanum_fraction": 0.5939167556,
"avg_line_length": 26.3943661972,
"ext": "agda",
"hexsha": "eb5657278b99a77e9372e52fc0eea40953e0b3c3",
"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/FinSet/FiniteChoice.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/FinSet/FiniteChoice.agda",
"max_line_length": 82,
"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/FinSet/FiniteChoice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 810,
"size": 1874
} |
module CS410-Monoid where
open import CS410-Prelude
record Monoid (M : Set) : Set where
field
-- OPERATIONS ----------------------------------------
e : M
op : M -> M -> M
-- LAWS ----------------------------------------------
lunit : forall m -> op e m == m
runit : forall m -> op m e == m
assoc : forall m m' m'' ->
op m (op m' m'') == op (op m m') m''
| {
"alphanum_fraction": 0.3814180929,
"avg_line_length": 25.5625,
"ext": "agda",
"hexsha": "46d0a07ba9c60bb8cb47a8d3b065cd89284faf2a",
"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": "CS410-Monoid.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": "CS410-Monoid.agda",
"max_line_length": 58,
"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": "CS410-Monoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 114,
"size": 409
} |
------------------------------------------------------------------------
-- A combinator for running two computations in parallel
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Delay-monad.Parallel where
import Equality.Propositional as Eq
open import Prelude
open import Prelude.Size
open import Conat Eq.equality-with-J as Conat
using (zero; suc; force; max)
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Delay-monad.Bisimilarity.Kind
open import Delay-monad.Monad
import Delay-monad.Sequential as S
private
variable
a b : Level
A B : Type a
i : Size
k : Kind
f f₁ f₂ g : Delay (A → B) ∞
x x₁ x₂ y y₁ y₂ : Delay A ∞
f′ : Delay′ (A → B) ∞
x′ : Delay′ A ∞
h : A → B
z : A
------------------------------------------------------------------------
-- The _⊛_ operator
-- Parallel composition of computations.
infixl 6 _⊛_
_⊛_ : Delay (A → B) i → Delay A i → Delay B i
now f ⊛ now x = now (f x)
now f ⊛ later x = later λ { .force → now f ⊛ x .force }
later f ⊛ now x = later λ { .force → f .force ⊛ now x }
later f ⊛ later x = later λ { .force → f .force ⊛ x .force }
-- The number of later constructors in f ⊛ x is bisimilar to the
-- maximum of the number of later constructors in f and the number of
-- later constructors in x.
steps-⊛∼max-steps-steps :
Conat.[ i ] steps (f ⊛ x) ∼ max (steps f) (steps x)
steps-⊛∼max-steps-steps {f = now _} {x = now _} = zero
steps-⊛∼max-steps-steps {f = now _} {x = later _} = suc λ { .force → steps-⊛∼max-steps-steps }
steps-⊛∼max-steps-steps {f = later _} {x = now _} = suc λ { .force → steps-⊛∼max-steps-steps }
steps-⊛∼max-steps-steps {f = later _} {x = later _} = suc λ { .force → steps-⊛∼max-steps-steps }
-- Rearrangement lemmas for _⊛_.
later-⊛ :
later f′ ⊛ x ∼ later (record { force = f′ .force ⊛ drop-later x })
later-⊛ {x = now _} = later λ { .force → _ ∎ }
later-⊛ {x = later _} = later λ { .force → _ ∎ }
⊛-later :
f ⊛ later x′ ∼ later (record { force = drop-later f ⊛ x′ .force })
⊛-later {f = now _} = later λ { .force → _ ∎ }
⊛-later {f = later _} = later λ { .force → _ ∎ }
-- The _⊛_ operator preserves strong and weak bisimilarity and
-- expansion.
infixl 6 _⊛-cong_
_⊛-cong_ :
[ i ] f₁ ⟨ k ⟩ f₂ →
[ i ] x₁ ⟨ k ⟩ x₂ →
[ i ] f₁ ⊛ x₁ ⟨ k ⟩ f₂ ⊛ x₂
now ⊛-cong now = now
now ⊛-cong later q = later λ { .force → now ⊛-cong q .force }
now ⊛-cong laterˡ q = laterˡ (now ⊛-cong q)
now ⊛-cong laterʳ q = laterʳ (now ⊛-cong q)
later p ⊛-cong now = later λ { .force → p .force ⊛-cong now }
laterˡ p ⊛-cong now = laterˡ (p ⊛-cong now)
laterʳ p ⊛-cong now = laterʳ (p ⊛-cong now)
later p ⊛-cong later q = later λ { .force → p .force ⊛-cong q .force }
laterʳ p ⊛-cong laterʳ q = laterʳ (p ⊛-cong q)
laterˡ p ⊛-cong laterˡ q = laterˡ (p ⊛-cong q)
later {x = f₁} {y = f₂} p ⊛-cong laterˡ {x = x₁} {y = x₂} q =
later f₁ ⊛ later x₁ ∼⟨ (later λ { .force → _ ∎ }) ⟩
later (record { force = f₁ .force ⊛ x₁ .force }) ?⟨ (later λ { .force → p .force ⊛-cong drop-laterʳ q }) ⟩∼
later (record { force = f₂ .force ⊛ drop-later x₂ }) ∼⟨ symmetric later-⊛ ⟩
later f₂ ⊛ x₂ ∎
later {x = f₁} {y = f₂} p ⊛-cong laterʳ {x = x₁} {y = x₂} q =
later f₁ ⊛ x₁ ∼⟨ later-⊛ ⟩
later (record { force = f₁ .force ⊛ drop-later x₁ }) ≈⟨ (later λ { .force → p .force ⊛-cong drop-laterˡ q }) ⟩∼
later (record { force = f₂ .force ⊛ x₂ .force }) ∼⟨ (later λ { .force → _ ∎ }) ⟩
later f₂ ⊛ later x₂ ∎
laterˡ {x = f₁} {y = f₂} p ⊛-cong later {x = x₁} {y = x₂} q =
later f₁ ⊛ later x₁ ∼⟨ (later λ { .force → _ ∎ }) ⟩
later (record { force = f₁ .force ⊛ x₁ .force }) ?⟨ (later λ { .force → drop-laterʳ p ⊛-cong q .force }) ⟩∼
later (record { force = drop-later f₂ ⊛ x₂ .force }) ∼⟨ symmetric ⊛-later ⟩
f₂ ⊛ later x₂ ∎
laterʳ {x = f₁} {y = f₂} p ⊛-cong later {x = x₁} {y = x₂} q =
f₁ ⊛ later x₁ ∼⟨ ⊛-later ⟩
later (record { force = drop-later f₁ ⊛ x₁ .force }) ≈⟨ (later λ { .force → drop-laterˡ p ⊛-cong q .force }) ⟩∼
later (record { force = f₂ .force ⊛ x₂ .force }) ∼⟨ (later λ { .force → _ ∎ }) ⟩
later f₂ ⊛ later x₂ ∎
laterˡ {x = f₁} {y = f₂} p ⊛-cong laterʳ {x = x₁} {y = x₂} q =
later f₁ ⊛ x₁ ∼⟨ later-⊛ ⟩
later (record { force = f₁ .force ⊛ drop-later x₁ }) ≈⟨ (later λ { .force → drop-laterʳ p ⊛-cong drop-laterˡ q }) ⟩∼
later (record { force = drop-later f₂ ⊛ x₂ .force }) ∼⟨ symmetric ⊛-later ⟩
f₂ ⊛ later x₂ ∎
laterʳ {x = f₁} {y = f₂} p ⊛-cong laterˡ {x = x₁} {y = x₂} q =
f₁ ⊛ later x₁ ∼⟨ ⊛-later ⟩
later (record { force = drop-later f₁ ⊛ x₁ .force }) ≈⟨ (later λ { .force → drop-laterˡ p ⊛-cong drop-laterʳ q }) ⟩∼
later (record { force = f₂ .force ⊛ drop-later x₂ }) ∼⟨ symmetric later-⊛ ⟩
later f₂ ⊛ x₂ ∎
-- The _⊛_ operator is (kind of) commutative.
⊛-comm : [ i ] f ⊛ x ∼ map′ (flip _$_) x ⊛ f
⊛-comm {f = now f} {x = now x} = reflexive _
⊛-comm {f = now f} {x = later x} = later λ { .force → ⊛-comm }
⊛-comm {f = later f} {x = now x} = later λ { .force → ⊛-comm }
⊛-comm {f = later f} {x = later x} = later λ { .force → ⊛-comm }
-- The function map′ can be expressed using _⊛_.
map∼now-⊛ : [ i ] map′ h x ∼ now h ⊛ x
map∼now-⊛ {x = now x} = now
map∼now-⊛ {x = later x} = later λ { .force → map∼now-⊛ }
-- The applicative functor laws hold up to strong bisimilarity.
now-id-⊛ : [ i ] now id ⊛ x ∼ x
now-id-⊛ {x = now x} = now
now-id-⊛ {x = later x} = later λ { .force → now-id-⊛ }
now-∘-⊛-⊛-⊛ :
[ i ] now (λ f → f ∘_) ⊛ f ⊛ g ⊛ x ∼ f ⊛ (g ⊛ x)
now-∘-⊛-⊛-⊛ {f = now _} {g = now _} {x = now _} = now
now-∘-⊛-⊛-⊛ {f = now _} {g = now _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-∘-⊛-⊛-⊛ {f = now _} {g = later _} {x = now _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-∘-⊛-⊛-⊛ {f = now _} {g = later _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-∘-⊛-⊛-⊛ {f = later _} {g = now _} {x = now _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-∘-⊛-⊛-⊛ {f = later _} {g = now _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-∘-⊛-⊛-⊛ {f = later _} {g = later _} {x = now _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-∘-⊛-⊛-⊛ {f = later _} {g = later _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ }
now-⊛-now : [ i ] now h ⊛ now z ∼ now (h z)
now-⊛-now = now
⊛-now : [ i ] f ⊛ now z ∼ now (λ f → f z) ⊛ f
⊛-now {f = now f} = now
⊛-now {f = later f} = later λ { .force → ⊛-now }
-- Sequential composition is an expansion of parallel composition.
⊛≳⊛ : [ i ] f S.⊛ x ≳ f ⊛ x
⊛≳⊛ {f = now f} {x = now x} = now (f x) ∎
⊛≳⊛ {f = now f} {x = later x} = later λ { .force →
now f S.⊛ x .force ≳⟨ ⊛≳⊛ ⟩∎
now f ⊛ x .force ∎ }
⊛≳⊛ {f = later f} {x = now x} = later λ { .force →
f .force S.⊛ now x ≳⟨ ⊛≳⊛ ⟩∎
f .force ⊛ now x ∎ }
⊛≳⊛ {f = later f} {x = later x} = later λ { .force →
f .force S.⊛ later x ≳⟨ ((f .force ∎) >>=-cong λ _ → laterˡ (_ ∎)) ⟩
f .force S.⊛ x .force ≳⟨ ⊛≳⊛ ⟩∎
f .force ⊛ x .force ∎ }
------------------------------------------------------------------------
-- The _∣_ operator
-- Parallel composition of computations.
infix 10 _∣_
_∣_ : Delay A i → Delay B i → Delay (A × B) i
x ∣ y = map′ _,_ x ⊛ y
-- The number of later constructors in x ∣ y is bisimilar to the
-- maximum of the number of later constructors in x and the number of
-- later constructors in y.
steps-∣∼max-steps-steps :
Conat.[ i ] steps (x ∣ y) ∼ max (steps x) (steps y)
steps-∣∼max-steps-steps {x = x} {y = y} =
steps (x ∣ y) Conat.∼⟨ Conat.reflexive-∼ _ ⟩
steps (map′ _,_ x ⊛ y) Conat.∼⟨ steps-⊛∼max-steps-steps ⟩
max (steps (map′ _,_ x)) (steps y) Conat.∼⟨ Conat.max-cong (steps-map′ x) (Conat.reflexive-∼ _) ⟩∎
max (steps x) (steps y) ∎∼
-- The _∣_ operator preserves strong and weak bisimilarity and
-- expansion.
infix 10 _∣-cong_
_∣-cong_ :
[ i ] x₁ ⟨ k ⟩ x₂ →
[ i ] y₁ ⟨ k ⟩ y₂ →
[ i ] x₁ ∣ y₁ ⟨ k ⟩ x₂ ∣ y₂
p ∣-cong q = map-cong _,_ p ⊛-cong q
-- The _∣_ operator is commutative (up to swapping of results).
∣-comm : [ i ] x ∣ y ∼ map′ swap (y ∣ x)
∣-comm {x = x} {y = y} =
x ∣ y ∼⟨⟩
map′ _,_ x ⊛ y ∼⟨ ⊛-comm ⟩
map′ (flip _$_) y ⊛ map′ _,_ x ∼⟨ map∼now-⊛ ⊛-cong map∼now-⊛ ⟩
now (flip _$_) ⊛ y ⊛ (now _,_ ⊛ x) ∼⟨ symmetric now-∘-⊛-⊛-⊛ ⟩
now (λ f → f ∘_) ⊛ (now (flip _$_) ⊛ y) ⊛ now _,_ ⊛ x ∼⟨ symmetric now-∘-⊛-⊛-⊛ ⊛-cong (_ ∎) ⊛-cong (_ ∎) ⟩
now _∘_ ⊛ now (λ f → f ∘_) ⊛ now (flip _$_) ⊛ y ⊛ now _,_ ⊛ x ∼⟨⟩
now (λ x f y → f y x) ⊛ y ⊛ now _,_ ⊛ x ∼⟨ ⊛-now ⊛-cong (_ ∎) ⟩
now (_$ _,_) ⊛ (now (λ x f y → f y x) ⊛ y) ⊛ x ∼⟨ symmetric now-∘-⊛-⊛-⊛ ⊛-cong (_ ∎) ⟩
now _∘_ ⊛ now (_$ _,_) ⊛ now (λ x f y → f y x) ⊛ y ⊛ x ∼⟨⟩
now (curry swap) ⊛ y ⊛ x ∼⟨⟩
now _∘_ ⊛ now (swap ∘_) ⊛ now _,_ ⊛ y ⊛ x ∼⟨ now-∘-⊛-⊛-⊛ ⊛-cong (_ ∎) ⟩
now (swap ∘_) ⊛ (now _,_ ⊛ y) ⊛ x ∼⟨ (_ ∎) ⊛-cong symmetric map∼now-⊛ ⊛-cong (_ ∎) ⟩
now (swap ∘_) ⊛ map′ _,_ y ⊛ x ∼⟨⟩
now _∘_ ⊛ now swap ⊛ map′ _,_ y ⊛ x ∼⟨ now-∘-⊛-⊛-⊛ ⟩
now swap ⊛ (map′ _,_ y ⊛ x) ∼⟨ symmetric map∼now-⊛ ⟩
map′ swap (map′ _,_ y ⊛ x) ∼⟨⟩
map′ swap (y ∣ x) ∎
-- Sequential composition is an expansion of parallel composition.
∣≳∣ : [ i ] x S.∣ y ≳ x ∣ y
∣≳∣ {x = x} {y = y} =
x S.∣ y ∼⟨⟩
map′ _,_ x S.⊛ y ≳⟨ ⊛≳⊛ ⟩
map′ _,_ x ⊛ y ∼⟨⟩
x ∣ y ∎
| {
"alphanum_fraction": 0.4540550954,
"avg_line_length": 42.3755102041,
"ext": "agda",
"hexsha": "2d53eaf871bec9e4bddbf7cba151651d82881501",
"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": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Parallel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"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/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Parallel.agda",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Parallel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4489,
"size": 10382
} |
{-# OPTIONS --allow-exec #-}
open import Agda.Builtin.FromNat
open import Data.Bool.Base using (T; Bool; if_then_else_)
open import Data.String using (String; _++_; lines)
open import Data.Nat.Base using (ℕ)
open import Data.Fin using (Fin)
import Data.Fin.Literals as Fin
import Data.Nat.Literals as Nat
open import Data.Vec.Base using (Vec)
open import Data.Float.Base using (Float; _≤ᵇ_)
open import Data.List.Base using (List; []; _∷_)
open import Data.Unit.Base using (⊤; tt)
open import Relation.Nullary using (does)
open import Relation.Binary.Core using (Rel)
open import Reflection.Argument
open import Reflection.Term
open import Reflection.External
open import Reflection.TypeChecking.Monad
open import Reflection.TypeChecking.Monad.Syntax
open import Reflection.Show using (showTerm)
open import Vehicle.Utils
module Vehicle where
------------------------------------------------------------------------
-- Metadata
------------------------------------------------------------------------
VEHICLE_COMMAND : String
VEHICLE_COMMAND = "vehicle"
------------------------------------------------------------------------
-- Checking
------------------------------------------------------------------------
record CheckArgs : Set where
field
proofCache : String
checkCmd : CheckArgs → CmdSpec
checkCmd checkArgs = cmdSpec VEHICLE_COMMAND
( "check"
∷ ("--proofCache=" ++ proofCache)
∷ []) ""
where open CheckArgs checkArgs
checkSuccessful : String → Bool
checkSuccessful output = "verified" ⊆ output
postulate valid : ∀ {a} {A : Set a} → A
`valid : Term
`valid = def (quote valid) (hArg unknown ∷ [])
checkSpecificationMacro : CheckArgs → Term → TC ⊤
checkSpecificationMacro args hole = do
goal ← inferType hole
-- (showTerm goal)
output ← runCmdTC (checkCmd args)
if checkSuccessful output
then unify hole `valid
else typeError (strErr ("Error: " ++ output) ∷ [])
macro
checkSpecification : CheckArgs → Term → TC ⊤
checkSpecification = checkSpecificationMacro
------------------------------------------------------------------------
-- Other
------------------------------------------------------------------------
instance
finNumber : ∀ {n} -> Number (Fin n)
finNumber {n} = Fin.number n
natNumber : Number ℕ
natNumber = Nat.number
| {
"alphanum_fraction": 0.5934782609,
"avg_line_length": 28.0487804878,
"ext": "agda",
"hexsha": "1d71d14468762a1049607a8ce6a921da3f961221",
"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": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vehicle-lang/vehicle",
"max_forks_repo_path": "src/agda/Vehicle.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T20:49:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-07T14:09:13.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vehicle-lang/vehicle",
"max_issues_repo_path": "src/agda/Vehicle.agda",
"max_line_length": 72,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vehicle-lang/vehicle",
"max_stars_repo_path": "src/agda/Vehicle.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-17T18:51:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-10T12:56:42.000Z",
"num_tokens": 499,
"size": 2300
} |
module Theory where
open import Data.List using (List; []; _∷_; _++_)
open import Data.Fin using () renaming (zero to fzero; suc to fsuc)
open import Relation.Binary using (Rel)
open import Level using (suc; _⊔_)
open import Syntax
record Theory ℓ₁ ℓ₂ ℓ₃ : Set (suc (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)) where
field
Sg : Signature ℓ₁ ℓ₂
open Signature Sg
open Term Sg
field
Ax : forall Γ A -> Rel (Γ ⊢ A) ℓ₃
infix 3 _⊢_≡_
infix 3 _⊨_≡_
data _⊢_≡_ : forall Γ {A} -> Γ ⊢ A -> Γ ⊢ A -> Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)
data _⊨_≡_ : forall Γ {Γ′} -> Γ ⊨ Γ′ -> Γ ⊨ Γ′ -> Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)
-- Theorems
data _⊢_≡_ where
ax : forall {Γ A e₁ e₂} -> Ax Γ A e₁ e₂ -> Γ ⊢ e₁ ≡ e₂
refl : forall {Γ} {A} {e : Γ ⊢ A} -> Γ ⊢ e ≡ e
sym : forall {Γ} {A} {e₁ : Γ ⊢ A} {e₂} -> Γ ⊢ e₁ ≡ e₂ -> Γ ⊢ e₂ ≡ e₁
trans : forall {Γ} {A} {e₁ : Γ ⊢ A} {e₂ e₃} -> Γ ⊢ e₁ ≡ e₂ -> Γ ⊢ e₂ ≡ e₃ -> Γ ⊢ e₁ ≡ e₃
sub/id : forall {Γ} {A} {e : Γ ⊢ A} -> Γ ⊢ e [ id ] ≡ e
sub/∙ : forall {Γ} {A} {Γ′ Γ′′} {e : Γ′′ ⊢ A} {γ : Γ′ ⊨ Γ′′} {δ}
-> Γ ⊢ e [ γ ∙ δ ] ≡ e [ γ ] [ δ ]
eta/Unit : forall {Γ} (e : Γ ⊢ Unit) -> Γ ⊢ unit ≡ e
beta/*₁ : forall {Γ} {A B} (e₁ : Γ ⊢ A) (e₂ : Γ ⊢ B) -> Γ ⊢ fst (pair e₁ e₂) ≡ e₁
beta/*₂ : forall {Γ} {A B} (e₁ : Γ ⊢ A) (e₂ : Γ ⊢ B) -> Γ ⊢ snd (pair e₁ e₂) ≡ e₂
eta/* : forall {Γ} {A B} (e : Γ ⊢ A * B) -> Γ ⊢ pair (fst e) (snd e) ≡ e
beta/=> : forall {Γ} {A B} (e : A ∷ Γ ⊢ B) (e′ : Γ ⊢ A) -> Γ ⊢ app (abs e) e′ ≡ e [ ext id e′ ]
eta/=> : forall {Γ} {A B} (e : Γ ⊢ A => B) -> Γ ⊢ abs (app (e [ weaken ]) var) ≡ e
-- cong
cong/func : forall {Γ} {f : Func} {e e′ : Γ ⊢ dom f}
-> Γ ⊢ e ≡ e′
-> Γ ⊢ func f e ≡ func f e′
cong/sub : forall {Γ Γ′} {γ γ′ : Γ ⊨ Γ′} {A} {e e′ : Γ′ ⊢ A}
-> Γ ⊨ γ ≡ γ′
-> Γ′ ⊢ e ≡ e′
-> Γ ⊢ e [ γ ] ≡ e′ [ γ′ ]
cong/pair : forall {Γ} {A B} {e₁ e₁′ : Γ ⊢ A} {e₂ e₂′ : Γ ⊢ B}
-> Γ ⊢ e₁ ≡ e₁′
-> Γ ⊢ e₂ ≡ e₂′
-> Γ ⊢ pair e₁ e₂ ≡ pair e₁′ e₂′
cong/fst : forall {Γ} {A B} {e e′ : Γ ⊢ A * B}
-> Γ ⊢ e ≡ e′
-> Γ ⊢ fst e ≡ fst e′
cong/snd : forall {Γ} {A B} {e e′ : Γ ⊢ A * B}
-> Γ ⊢ e ≡ e′
-> Γ ⊢ snd e ≡ snd e′
cong/abs : forall {Γ} {A B} {e e′ : A ∷ Γ ⊢ B}
-> A ∷ Γ ⊢ e ≡ e′
-> Γ ⊢ abs e ≡ abs e′
cong/app : forall {Γ} {A B} {e₁ e₁′ : Γ ⊢ A => B} {e₂ e₂′ : Γ ⊢ A}
-> Γ ⊢ e₁ ≡ e₁′
-> Γ ⊢ e₂ ≡ e₂′
-> Γ ⊢ app e₁ e₂ ≡ app e₁′ e₂′
-- subst commutes with term formers
comm/func : forall Γ Γ′ (γ : Γ ⊨ Γ′) f e
-> Γ ⊢ func f e [ γ ] ≡ func f (e [ γ ])
comm/unit : forall Γ Γ′ (γ : Γ ⊨ Γ′)
-> Γ ⊢ unit [ γ ] ≡ unit
comm/pair : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e₁ : Γ′ ⊢ A} {e₂ : Γ′ ⊢ B}
-> Γ ⊢ pair e₁ e₂ [ γ ] ≡ pair (e₁ [ γ ]) (e₂ [ γ ])
comm/fst : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e : Γ′ ⊢ A * B}
-> Γ ⊢ fst e [ γ ] ≡ fst (e [ γ ])
comm/snd : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e : Γ′ ⊢ A * B}
-> Γ ⊢ snd e [ γ ] ≡ snd (e [ γ ])
comm/abs : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e : A ∷ Γ′ ⊢ B}
-> Γ ⊢ (abs e) [ γ ] ≡ abs (e [ ext (γ ∙ weaken) var ])
comm/app : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e₁ : Γ′ ⊢ A => B} {e₂}
-> Γ ⊢ app e₁ e₂ [ γ ] ≡ app (e₁ [ γ ]) (e₂ [ γ ])
var/ext : forall {Γ Γ′} (γ : Γ ⊨ Γ′) {A} (e : Γ ⊢ A)
-> Γ ⊢ var [ ext γ e ] ≡ e
data _⊨_≡_ where
refl : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> Γ ⊨ γ ≡ γ
sym : forall {Γ Γ′} {γ γ′ : Γ ⊨ Γ′} -> Γ ⊨ γ ≡ γ′ -> Γ ⊨ γ′ ≡ γ
trans : forall {Γ Γ′} {γ₁ γ₂ γ₃ : Γ ⊨ Γ′}
-> Γ ⊨ γ₁ ≡ γ₂
-> Γ ⊨ γ₂ ≡ γ₃
-> Γ ⊨ γ₁ ≡ γ₃
id∙ˡ : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> Γ ⊨ id ∙ γ ≡ γ
id∙ʳ : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> Γ ⊨ γ ∙ id ≡ γ
assoc∙ : forall {Γ Γ′ Γ′′ Γ′′′} {γ₁ : Γ′′ ⊨ Γ′′′} {γ₂ : Γ′ ⊨ Γ′′} {γ₃ : Γ ⊨ Γ′}
-> Γ ⊨ (γ₁ ∙ γ₂) ∙ γ₃ ≡ γ₁ ∙ (γ₂ ∙ γ₃)
!-unique : forall {Γ} {γ : Γ ⊨ []} -> Γ ⊨ ! ≡ γ
η-pair : forall {Γ : Context} {A : Type}
-> A ∷ Γ ⊨ ext weaken var ≡ id
ext∙ : forall {Γ Γ′ Γ′′} {γ : Γ′ ⊨ Γ′′} {γ′ : Γ ⊨ Γ′} {A} {e : Γ′ ⊢ A}
-> Γ ⊨ ext γ e ∙ γ′ ≡ ext (γ ∙ γ′) (e [ γ′ ])
weaken/ext : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A} {e : Γ ⊢ A}
-> Γ ⊨ weaken ∙ ext γ e ≡ γ
cong/ext : forall {Γ Γ′} {γ γ′ : Γ ⊨ Γ′} {A} {e e′ : Γ ⊢ A}
-> Γ ⊨ γ ≡ γ′
-> Γ ⊢ e ≡ e′
-> Γ ⊨ ext γ e ≡ ext γ′ e′
cong/∙ : forall {Γ Γ′ Γ′′} {γ γ′ : Γ′ ⊨ Γ′′} {δ δ′ : Γ ⊨ Γ′}
-> Γ′ ⊨ γ ≡ γ′
-> Γ ⊨ δ ≡ δ′
-> Γ ⊨ γ ∙ δ ≡ γ′ ∙ δ′
×id′-∙ : forall {Γ Γ′ Γ′′} {γ′ : Γ ⊨ Γ′} {γ : Γ′ ⊨ Γ′′} {A}
-> A ∷ Γ ⊨ γ ×id′ ∙ γ′ ×id′ ≡ (γ ∙ γ′) ×id′
×id′-∙ = trans ext∙ (cong/ext (trans assoc∙ (trans (cong/∙ refl weaken/ext) (sym assoc∙))) (var/ext _ _))
×id′-ext : forall {Γ Γ′ Γ′′} {γ′ : Γ ⊨ Γ′} {γ : Γ′ ⊨ Γ′′} {A} {e : Γ ⊢ A}
-> Γ ⊨ γ ×id′ ∙ ext γ′ e ≡ ext (γ ∙ γ′) e
×id′-ext = trans ext∙ (cong/ext (trans assoc∙ (cong/∙ refl weaken/ext)) (var/ext _ _))
open import Relation.Binary.Bundles
TermSetoid : forall {Γ : Context} {A : Type} -> Setoid (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)
TermSetoid {Γ} {A} = record
{ Carrier = Γ ⊢ A
; _≈_ = λ e₁ e₂ → Γ ⊢ e₁ ≡ e₂
;isEquivalence = record { refl = refl ; sym = sym ; trans = trans }
}
SubstSetoid : forall {Γ : Context} {Γ′ : Context} -> Setoid (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)
SubstSetoid {Γ} {Γ′} = record
{ Carrier = Γ ⊨ Γ′
; _≈_ = λ γ₁ γ₂ → Γ ⊨ γ₁ ≡ γ₂
;isEquivalence = record { refl = refl ; sym = sym ; trans = trans }
}
open import Categories.Category
open import Categories.Category.CartesianClosed
module _ {o ℓ e} (𝒞 : Category o ℓ e) (CC : CartesianClosed 𝒞) {ℓ₁ ℓ₂ ℓ₃} (Th : Theory ℓ₁ ℓ₂ ℓ₃) where
open Category 𝒞
open import Data.Product using (Σ-syntax)
open Theory Th
open import Semantics 𝒞 CC Sg
Model : Set (o ⊔ ℓ ⊔ e ⊔ ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)
Model = Σ[ M ∈ Structure ] forall {Γ A e₁ e₂} -> Ax Γ A e₁ e₂ -> ⟦ e₁ ⟧ M ≈ ⟦ e₂ ⟧ M
| {
"alphanum_fraction": 0.4176381145,
"avg_line_length": 36.0914634146,
"ext": "agda",
"hexsha": "a3a0a788b01dfc85cf58b06c06568c2dc98fc544",
"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": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Theory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"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": "elpinal/exsub-ccc",
"max_issues_repo_path": "Theory.agda",
"max_line_length": 107,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Theory.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 2997,
"size": 5919
} |
module Prelude.Unit where
data Unit : Set where
unit : Unit
| {
"alphanum_fraction": 0.7301587302,
"avg_line_length": 12.6,
"ext": "agda",
"hexsha": "a1faad9bcffd8fb4ac9dd34073bae31d434acbad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/epic/Prelude/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/epic/Prelude/Unit.agda",
"max_line_length": 25,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/epic/Prelude/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 16,
"size": 63
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bounded vectors (inefficient implementation)
------------------------------------------------------------------------
-- Vectors of a specified maximum length.
module Data.Star.BoundedVec where
open import Data.Star
open import Data.Star.Nat
open import Data.Star.Decoration
open import Data.Star.Pointer
open import Data.Star.List using (List)
open import Data.Unit
open import Function
import Data.Maybe as Maybe
open import Relation.Binary
open import Relation.Binary.Consequences
------------------------------------------------------------------------
-- The type
-- Finite sets decorated with elements (note the use of suc).
BoundedVec : Set → ℕ → Set
BoundedVec a n = Any (λ _ → a) (λ _ → ⊤) (suc n)
[] : ∀ {a n} → BoundedVec a n
[] = this tt
infixr 5 _∷_
_∷_ : ∀ {a n} → a → BoundedVec a n → BoundedVec a (suc n)
_∷_ = that
------------------------------------------------------------------------
-- Increasing the bound
-- Note that this operation is linear in the length of the list.
↑ : ∀ {a n} → BoundedVec a n → BoundedVec a (suc n)
↑ {a} = gmap inc lift
where
inc = Maybe.map (map-NonEmpty suc)
lift : Pointer (λ _ → a) (λ _ → ⊤) =[ inc ]⇒
Pointer (λ _ → a) (λ _ → ⊤)
lift (step x) = step x
lift (done _) = done _
------------------------------------------------------------------------
-- Conversions
fromList : ∀ {a} → (xs : List a) → BoundedVec a (length xs)
fromList ε = []
fromList (x ◅ xs) = x ∷ fromList xs
toList : ∀ {a n} → BoundedVec a n → List a
toList xs = gmap (const tt) decoration (init xs)
| {
"alphanum_fraction": 0.5137724551,
"avg_line_length": 26.935483871,
"ext": "agda",
"hexsha": "7d0cfdb4a44aa0cfb5abffe82130ab69ae752f19",
"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/Data/Star/BoundedVec.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/Data/Star/BoundedVec.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/Data/Star/BoundedVec.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": 431,
"size": 1670
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module homotopy.SmashFmapConn where
module _ {i} {j} {A : Type i} (B : A → Type j) where
custom-assoc : {a₀ a₁ a₂ a₃ : A}
{b₀ : B a₀} {b₁ b₁' b₁'' : B a₁} {b₂ : B a₂} {b₃ : B a₃}
{p : a₀ == a₁} (p' : b₀ == b₁ [ B ↓ p ])
(q' : b₁ == b₁')
(r' : b₁' == b₁'')
{s : a₁ == a₂} (s' : b₁'' == b₂ [ B ↓ s ])
{t : a₂ == a₃} (t' : b₂ == b₃ [ B ↓ t ])
→ p' ∙ᵈ (((q' ∙ r') ◃ s') ∙ᵈ t')
==
((p' ▹ q') ▹ r') ∙ᵈ s' ∙ᵈ t'
custom-assoc {p = idp} p'@idp q'@idp r'@idp {s = idp} s'@idp {t = idp} t' = idp
transp-over : {a₀ a₁ : A} (p : a₀ == a₁) (b₀ : B a₀)
→ b₀ == transport B p b₀ [ B ↓ p ]
transp-over p b₀ = from-transp B p (idp {a = transport B p b₀})
transp-over-naturality : ∀ {a₀ a₁ : A} (p : a₀ == a₁)
{b₀ b₀' : B a₀} (q : b₀ == b₀')
→ q ◃ transp-over p b₀'
==
transp-over p b₀ ▹ ap (transport B p) q
transp-over-naturality p@idp q@idp = idp
to-transp-over : {a₀ a₁ : A} {p : a₀ == a₁}
{b₀ : B a₀} {b₁ : B a₁} (q : b₀ == b₁ [ B ↓ p ])
→ q ▹ ! (to-transp q) == transp-over p b₀
to-transp-over {p = idp} q@idp = idp
module _ {i} {j} {S* : Type i} (P* : S* → Type j) where
-- cpa = custom path algebra
cpa₁ : {s₁ s₂ t : S*} (p* : P* s₂) (p₁ : s₁ == t) (p₂ : s₂ == t)
→ transport P* (! (p₁ ∙ ! p₂)) p* == transport P* p₂ p* [ P* ↓ p₁ ]
cpa₁ p* p₁@idp p₂@idp = idp
-- cpac = custom path algebra coherence
cpac₁ : ∀ {k} {C : Type k} (f : C → S*)
{c₁ c₂ : C} (q : c₁ == c₂)
(d : Π C (P* ∘ f))
{t : S*} (p₁ : f c₁ == t) (p₂ : f c₂ == t)
(r : ap f q == p₁ ∙' ! p₂)
{u : P* (f c₂)} (v : u == transport P* (! (p₂ ∙ ! p₂)) (d c₂))
{u' : P* (f c₁)} (v' : u' == transport P* (! (p₁ ∙ ! p₂)) (d c₂))
→ (v' ∙
ap (λ pp → transport P* pp (d c₂)) (ap ! (! (r ∙ ∙'=∙ p₁ (! p₂))) ∙ !-ap f q) ∙
to-transp {B = P*} {p = ap f (! q)}
(↓-ap-in P* f (apd d (! q)))) ◃
apd d q
==
↓-ap-out= P* f q (r ∙ ∙'=∙ p₁ (! p₂))
((v' ◃ cpa₁ (d c₂) p₁ p₂) ∙ᵈ !ᵈ (v ◃ cpa₁ (d c₂) p₂ p₂)) ▹
(v ∙ ap (λ pp → transport P* (! pp) (d c₂)) (!-inv-r p₂))
cpac₁ f q@idp d p₁@.idp p₂@idp r@idp v@idp v'@idp = idp
cpa₂ : ∀ {k} {C : Type k} (f : C → S*)
{c₁ c₂ : C} (q : c₁ == c₂)
(d : Π C (P* ∘ f))
{s t : S*} (p : f c₁ == s) (r : s == t) (u : f c₂ == t)
(h : ap f q == p ∙' (r ∙ ! u))
→ transport P* p (d c₁)
==
transport P* u (d c₂)
[ P* ↓ r ]
cpa₂ f q@idp d [email protected] r@idp u@idp h@idp = idp
cpac₂ : ∀ {k} {C : Type k} (f : C → S*)
{c₁ c₂ c₃ : C} (q : c₁ == c₂) (q' : c₃ == c₂)
(d : Π C (P* ∘ f))
{s t : S*} (p : f c₁ == s) (p' : f c₃ == f c₂) (r : s == t) (u : f c₂ == t)
(h : ap f q == p ∙' (r ∙ ! u))
(h' : ap f q' == p' ∙' u ∙ ! u)
{x : P* (f c₂)} (x' : x == transport P* p' (d c₃))
{y : P* (f c₁)} (y' : y == d c₁)
→ ↓-ap-out=
P*
f
q
(h ∙ ∙'=∙ p (r ∙ ! u))
((y' ◃ transp-over P* p (d c₁)) ∙ᵈ cpa₂ f q d p r u h ∙ᵈ !ᵈ (x' ◃ cpa₂ f q' d p' u u h')) ▹
(x' ∙
ap (λ pp → transport P* pp (d c₃))
(! (∙-unit-r p') ∙
ap (p' ∙_) (! (!-inv-r u)) ∙
! (h' ∙ ∙'=∙ p' (u ∙ ! u))) ∙
to-transp (↓-ap-in P* f (apd d q')))
==
y' ◃ apd d q
cpac₂ f q@idp q'@idp d [email protected] p'@.idp r@idp u@idp h@idp h'@idp x'@idp y'@idp = idp
module _ {i} {j} {k} {A : Ptd i} {A' : Ptd j} (f : A ⊙→ A') (B : Ptd k)
{m n : ℕ₋₂}
(f-is-m-conn : has-conn-fibers m (fst f))
(B-is-Sn-conn : is-connected (S n) (de⊙ B)) where
private
a₀ = pt A
a₀' = pt A'
b₀ = pt B
module ConnIn (P : A' ∧ B → (n +2+ m) -Type (lmax i (lmax j k)))
(d : ∀ (ab : A ∧ B) → fst (P (∧-fmap f (⊙idf B) ab))) where
h : ∀ (b : de⊙ B)
→ (∀ (a' : de⊙ A') → fst (P (smin a' b)))
→ (∀ (a : de⊙ A) → fst (P (smin (fst f a) b)))
h b s = s ∘ fst f
Q : de⊙ B → n -Type (lmax i (lmax j k))
Q b = Q' , Q'-level
where
Q' : Type (lmax i (lmax j k))
Q' = hfiber (h b) (λ a → d (smin a b))
Q'-level : has-level n Q'
Q'-level =
conn-extend-general
{n = m} {k = n}
f-is-m-conn
(λ a → P (smin a b))
(λ a → d (smin a b))
s₀ : ∀ (a' : de⊙ A') → fst (P (smin a' b₀))
s₀ a' = transport (fst ∘ P) (! (∧-norm-l a')) (d smbasel)
∧-fmap-smgluel-β-∙' : ∀ (a : de⊙ A) →
ap (∧-fmap f (⊙idf B)) (smgluel a)
==
smgluel (fst f a) ∙' ! (smgluel a₀')
∧-fmap-smgluel-β-∙' a =
∧-fmap-smgluel-β' f (⊙idf B) a ∙
∙=∙' (smgluel (fst f a)) (! (smgluel a₀'))
∧-fmap-smgluel-β-∙ : ∀ (a : de⊙ A) →
ap (∧-fmap f (⊙idf B)) (smgluel a)
==
smgluel (fst f a) ∙ ! (smgluel a₀')
∧-fmap-smgluel-β-∙ a =
∧-fmap-smgluel-β-∙' a ∙
∙'=∙ (smgluel (fst f a)) (! (smgluel a₀'))
∧-fmap-smgluer-β-∙' : ∀ (b : de⊙ B) →
ap (∧-fmap f (⊙idf B)) (smgluer b)
==
ap (λ a' → smin a' b) (snd f) ∙' ∧-norm-r b
∧-fmap-smgluer-β-∙' b =
∧-fmap-smgluer-β' f (⊙idf B) b ∙
∙=∙' (ap (λ a' → smin a' b) (snd f)) (∧-norm-r b)
∧-fmap-smgluer-β-∙ : ∀ (b : de⊙ B) →
ap (∧-fmap f (⊙idf B)) (smgluer b)
==
ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b
∧-fmap-smgluer-β-∙ b =
∧-fmap-smgluer-β-∙' b ∙
∙'=∙ (ap (λ a' → smin a' b) (snd f)) (∧-norm-r b)
s₀-f : ∀ (a : de⊙ A) → s₀ (fst f a) == d (smin a b₀)
s₀-f a =
ap (λ p → transport (λ a'b → fst (P a'b)) p (d smbasel)) q ∙
to-transp {B = fst ∘ P}
{p = ap (∧-fmap f (⊙idf B)) (! (smgluel a))}
(↓-ap-in (fst ∘ P)
(∧-fmap f (⊙idf B))
(apd d (! (smgluel a))))
where
q : ! (∧-norm-l (fst f a)) == ap (∧-fmap f (⊙idf B)) (! (smgluel a))
q = ap ! (! (∧-fmap-smgluel-β-∙ a)) ∙ !-ap (∧-fmap f (⊙idf B)) (smgluel a)
q₀ : fst (Q b₀)
q₀ = s₀ , s₀-lies-over-pt
where
s₀-lies-over-pt : h b₀ s₀ == (λ a → d (smin a b₀))
s₀-lies-over-pt = λ= s₀-f
q : ∀ (b : de⊙ B) → fst (Q b)
q = conn-extend {n = n} {h = cst b₀}
(pointed-conn-out (de⊙ B) b₀ {{B-is-Sn-conn}})
Q
(λ _ → q₀)
q-f : q b₀ == q₀
q-f = conn-extend-β {n = n} {h = cst b₀}
(pointed-conn-out (de⊙ B) b₀ {{B-is-Sn-conn}})
Q
(λ _ → q₀)
unit
s : ∀ (a' : de⊙ A') (b : de⊙ B) → fst (P (smin a' b))
s a' b = fst (q b) a'
s-b₀ : ∀ (a' : de⊙ A') → s a' b₀ == s₀ a'
s-b₀ a' = ap (λ u → fst u a') q-f
s-f : ∀ (a : de⊙ A) (b : de⊙ B)
→ s (fst f a) b == d (smin a b)
s-f a b = app= (snd (q b)) a
s-f-b₀ : ∀ (a : de⊙ A)
→ s-f a b₀ == s-b₀ (fst f a) ∙ s₀-f a
s-f-b₀ a =
app= (snd (q b₀)) a
=⟨ ↓-app=cst-out' (apd (λ u → app= (snd u) a) q-f) ⟩
s-b₀ (fst f a) ∙' app= (snd q₀) a
=⟨ ap (s-b₀ (fst f a) ∙'_) (app=-β s₀-f a) ⟩
s-b₀ (fst f a) ∙' s₀-f a
=⟨ ∙'=∙ (s-b₀ (fst f a)) (s₀-f a) ⟩
s-b₀ (fst f a) ∙ s₀-f a =∎
s-a₀' : ∀ (b : de⊙ B) →
s a₀' b
==
transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))
s-a₀' b = ↯ $
s a₀' b
=⟪ ! (to-transp (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)))) ⟫
transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (s (fst f a₀) b)
=⟪ ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)))
(s-f a₀ b) ⟫
transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b)) ∎∎
section-smbasel : fst (P smbasel)
section-smbasel = transport (fst ∘ P) (smgluel a₀') (d smbasel)
section-smbaser : fst (P smbaser)
section-smbaser = transport (fst ∘ P) (smgluer b₀) (d smbaser)
section-smgluel' : ∀ (a' : de⊙ A') → s₀ a' == section-smbasel [ fst ∘ P ↓ smgluel a' ]
section-smgluel' a' = cpa₁ (fst ∘ P) (d smbasel) (smgluel a') (smgluel a₀')
section-smgluel : ∀ (a' : de⊙ A') → s a' b₀ == section-smbasel [ fst ∘ P ↓ smgluel a' ]
section-smgluel a' = s-b₀ a' ◃ section-smgluel' a'
section-smgluer' : ∀ (b : de⊙ B) →
transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))
==
section-smbaser
[ fst ∘ P ↓ smgluer b ]
section-smgluer' b =
cpa₂
(fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluer b)
d
(ap (λ a' → smin a' b) (snd f))
(smgluer b)
(smgluer b₀)
(∧-fmap-smgluer-β-∙' b)
section-smgluer : ∀ (b : de⊙ B) → s a₀' b == section-smbaser [ fst ∘ P ↓ smgluer b ]
section-smgluer b = s-a₀' b ◃ section-smgluer' b
module Section =
SmashElim
{P = fst ∘ P}
s
section-smbasel
section-smbaser
section-smgluel
section-smgluer
section : Π (A' ∧ B) (fst ∘ P)
section = Section.f
is-section-smbasel : s a₀' b₀ == d smbasel
is-section-smbasel = ↯ $
s a₀' b₀
=⟪ s-b₀ a₀' ⟫
s₀ a₀'
=⟪idp⟫
transport (fst ∘ P) (! (∧-norm-l a₀')) (d smbasel)
=⟪ ap (λ p → transport (fst ∘ P) (! p) (d smbasel))
(!-inv-r (smgluel a₀')) ⟫
d smbasel ∎∎
is-section-smgluel : ∀ (a : de⊙ A) →
s-f a b₀ ◃ apd d (smgluel a)
==
apd (section ∘ ∧-fmap f (⊙idf B)) (smgluel a) ▹
is-section-smbasel
is-section-smgluel a =
s-f a b₀ ◃ apd d (smgluel a)
=⟨ ap (_◃ apd d (smgluel a)) (s-f-b₀ a) ⟩
(s-b₀ (fst f a) ∙ s₀-f a) ◃ apd d (smgluel a)
=⟨ cpac₁
(fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluel a)
d
(smgluel (fst f a))
(smgluel a₀')
(∧-fmap-smgluel-β-∙' a)
(s-b₀ a₀')
(s-b₀ (fst f a)) ⟩
↓-ap-out= (fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluel a)
(∧-fmap-smgluel-β-∙ a)
(section-smgluel (fst f a) ∙ᵈ !ᵈ (section-smgluel a₀')) ▹
is-section-smbasel
=⟨ ! $ ap (_▹ is-section-smbasel) $
ap (↓-ap-out= (fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluel a)
(∧-fmap-smgluel-β-∙ a)) $
apd-section-norm-l (fst f a) ⟩
↓-ap-out= (fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluel a)
(∧-fmap-smgluel-β-∙ a)
(apd section (∧-norm-l (fst f a))) ▹
is-section-smbasel
=⟨ ! $ ap (_▹ is-section-smbasel) $
apd-∘'' section
(∧-fmap f (⊙idf B))
(smgluel a)
(∧-fmap-smgluel-β-∙ a) ⟩
apd (section ∘ ∧-fmap f (⊙idf B)) (smgluel a) ▹
is-section-smbasel =∎
where
apd-section-norm-l : ∀ (a' : de⊙ A') →
apd section (∧-norm-l a')
==
section-smgluel a' ∙ᵈ !ᵈ (section-smgluel a₀')
apd-section-norm-l a' =
apd section (∧-norm-l a')
=⟨ apd-∙ section (smgluel a') (! (smgluel a₀')) ⟩
apd section (smgluel a') ∙ᵈ apd section (! (smgluel a₀'))
=⟨ ap2 _∙ᵈ_ (Section.smgluel-β a')
(apd-! section (smgluel a₀') ∙
ap !ᵈ (Section.smgluel-β a₀')) ⟩
section-smgluel a' ∙ᵈ !ᵈ (section-smgluel a₀') =∎
is-section-smbaser : s a₀' b₀ == d smbaser
is-section-smbaser = ↯ $
s a₀' b₀
=⟪ s-a₀' b₀ ⟫
transport (fst ∘ P) (ap (λ a' → smin a' b₀) (snd f)) (d (smin a₀ b₀))
=⟪ ap (λ p → transport (fst ∘ P) p (d (smin a₀ b₀))) (↯ r) ⟫
transport (fst ∘ P) (ap (∧-fmap f (⊙idf B)) (smgluer b₀)) (d (smin a₀ b₀))
=⟪ to-transp (↓-ap-in (fst ∘ P) (∧-fmap f (⊙idf B)) (apd d (smgluer b₀))) ⟫
d smbaser ∎∎
where
r : ap (λ a' → smin a' b₀) (snd f) =-= ap (∧-fmap f (⊙idf B)) (smgluer b₀)
r =
ap (λ a' → smin a' b₀) (snd f)
=⟪ ! (∙-unit-r _) ⟫
ap (λ a' → smin a' b₀) (snd f) ∙ idp
=⟪ ap (ap (λ a' → smin a' b₀) (snd f) ∙_)
(! (!-inv-r (smgluer b₀))) ⟫
ap (λ a' → smin a' b₀) (snd f) ∙ ∧-norm-r b₀
=⟪ ! (∧-fmap-smgluer-β-∙ b₀) ⟫
ap (∧-fmap f (⊙idf B)) (smgluer b₀) ∎∎
is-section-smgluer : ∀ (b : de⊙ B) →
s-f a₀ b ◃
apd d (smgluer b)
==
apd (section ∘ ∧-fmap f (⊙idf B)) (smgluer b) ▹
is-section-smbaser
is-section-smgluer b = ! $
apd (section ∘ ∧-fmap f (⊙idf B)) (smgluer b) ▹
is-section-smbaser
=⟨ ap (_▹ is-section-smbaser) $
apd-∘'' section
(∧-fmap f (⊙idf B))
(smgluer b)
(∧-fmap-smgluer-β-∙ b) ⟩
↓-ap-out= (fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluer b)
(∧-fmap-smgluer-β-∙ b)
(apd section (ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b)) ▹
is-section-smbaser
=⟨ ap (_▹ is-section-smbaser) $
ap (↓-ap-out= (fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluer b)
(∧-fmap-smgluer-β-∙ b)) $
apd-section-helper ⟩
↓-ap-out= (fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluer b)
(∧-fmap-smgluer-β-∙ b)
((s-f a₀ b ◃ transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))) ∙ᵈ
section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)) ▹
is-section-smbaser
=⟨ cpac₂
(fst ∘ P)
(∧-fmap f (⊙idf B))
(smgluer b)
(smgluer b₀)
d
(ap (λ a' → smin a' b) (snd f))
(ap (λ a' → smin a' b₀) (snd f))
(smgluer b)
(smgluer b₀)
(∧-fmap-smgluer-β-∙' b)
(∧-fmap-smgluer-β-∙' b₀)
(s-a₀' b₀)
(s-f a₀ b) ⟩
s-f a₀ b ◃
apd d (smgluer b) =∎
where
apd-section-helper :
apd section (ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b)
==
(s-f a₀ b ◃ transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))) ∙ᵈ
section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)
apd-section-helper =
apd section (ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b)
=⟨ apd-∙ section (ap (λ a' → smin a' b) (snd f)) (∧-norm-r b) ⟩
apd section (ap (λ a' → smin a' b) (snd f)) ∙ᵈ
apd section (∧-norm-r b)
=⟨ ap2 _∙ᵈ_
(apd-∘''' section (λ a' → smin a' b) (snd f))
(apd-∙ section (smgluer b) (! (smgluer b₀))) ⟩
↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ∙ᵈ
apd section (smgluer b) ∙ᵈ apd section (! (smgluer b₀))
=⟨ ap (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ∙ᵈ_) $
ap2 _∙ᵈ_
(Section.smgluer-β b)
(apd-! section (smgluer b₀) ∙
ap !ᵈ (Section.smgluer-β b₀)) ⟩
↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ∙ᵈ
section-smgluer b ∙ᵈ !ᵈ (section-smgluer b₀)
=⟨ custom-assoc (fst ∘ P)
(↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)))
(! (to-transp (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)))))
(ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b))
(section-smgluer' b)
(!ᵈ (section-smgluer b₀)) ⟩
((↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ▹
! (to-transp (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f))))) ▹
ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) ∙ᵈ
section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)
=⟨ ap (λ u → (u ▹ ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) ∙ᵈ
section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)) $
to-transp-over (fst ∘ P) $
↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ⟩
(transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (s (fst f a₀) b) ▹
ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) ∙ᵈ
section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)
=⟨ ! $ ap (_∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)) $
transp-over-naturality (fst ∘ P)
(ap (λ a' → smin a' b) (snd f))
(s-f a₀ b) ⟩
(s-f a₀ b ◃ transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))) ∙ᵈ
section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀) =∎
is-section : section ∘ ∧-fmap f (⊙idf B) ∼ d
is-section =
Smash-PathOver-elim
{P = λ ab → fst (P (∧-fmap f (⊙idf B) ab))}
(section ∘ ∧-fmap f (⊙idf B))
d
s-f
is-section-smbasel
is-section-smbaser
is-section-smgluel
is-section-smgluer
{- Proposition 4.3.2 in Guillaume Brunerie's thesis -}
∧-fmap-conn-l : has-conn-fibers (n +2+ m) (∧-fmap f (⊙idf B))
∧-fmap-conn-l = conn-in (λ P → ConnIn.section P , ConnIn.is-section P)
private
∧-swap-conn : ∀ {i} {j} (X : Ptd i) (Y : Ptd j) (n : ℕ₋₂)
→ has-conn-fibers n (∧-swap X Y)
∧-swap-conn X Y n yx =
Trunc-preserves-level {n = -2} n $
equiv-is-contr-map (∧-swap-is-equiv X Y) yx
∧-fmap-conn-r : ∀ {i} {j} {k}
(A : Ptd i) {B : Ptd j} {B' : Ptd k} (g : B ⊙→ B')
{k l : ℕ₋₂}
→ is-connected (S k) (de⊙ A)
→ has-conn-fibers l (fst g)
→ has-conn-fibers (k +2+ l) (∧-fmap (⊙idf A) g)
∧-fmap-conn-r A {B} {B'} g {k} {l} A-is-Sk-conn g-is-l-conn =
transport
(has-conn-fibers (k +2+ l))
(λ= (∧-swap-fmap (⊙idf A) g)) $
∘-conn (∧-swap A B)
(∧-swap B' A ∘ ∧-fmap g (⊙idf A))
(∧-swap-conn A B _) $
∘-conn (∧-fmap g (⊙idf A))
(∧-swap B' A)
(∧-fmap-conn-l g A g-is-l-conn A-is-Sk-conn)
(∧-swap-conn B' A _)
private
∘-conn' : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
{n m : ℕ₋₂} (g : B → C) (f : A → B)
→ has-conn-fibers m g
→ has-conn-fibers n f
→ has-conn-fibers (minT n m) (g ∘ f)
∘-conn' {n = n} {m = m} g f g-conn f-conn =
∘-conn f g
(λ b → connected-≤T (minT≤l n m) {{f-conn b}})
(λ c → connected-≤T (minT≤r n m) {{g-conn c}})
{- Proposition 4.3.5 in Guillaume Brunerie's thesis -}
∧-fmap-conn : ∀ {i i' j j'}
{A : Ptd i} {A' : Ptd i'} (f : A ⊙→ A')
{B : Ptd j} {B' : Ptd j'} (g : B ⊙→ B')
{m n k l : ℕ₋₂}
→ is-connected (S k) (de⊙ A')
→ is-connected (S n) (de⊙ B)
→ has-conn-fibers m (fst f)
→ has-conn-fibers l (fst g)
→ has-conn-fibers (minT (n +2+ m) (k +2+ l)) (∧-fmap f g)
∧-fmap-conn {A = A} {A'} f {B} {B'} g {m} {n} {k} {l}
A'-is-Sk-conn B-is-Sn-conn f-is-m-conn g-is-l-conn =
transport (has-conn-fibers (minT (n +2+ m) (k +2+ l))) p $
∘-conn' (∧-fmap (⊙idf A') g)
(∧-fmap f (⊙idf B))
(∧-fmap-conn-r A' g A'-is-Sk-conn g-is-l-conn)
(∧-fmap-conn-l f B f-is-m-conn B-is-Sn-conn)
where
p : ∧-fmap (⊙idf A') g ∘ ∧-fmap f (⊙idf B) == ∧-fmap f g
p =
∧-fmap (⊙idf A') g ∘ ∧-fmap f (⊙idf B)
=⟨ ! (λ= (∧-fmap-comp f (⊙idf A') (⊙idf B) g)) ⟩
∧-fmap (⊙idf A' ⊙∘ f) (g ⊙∘ ⊙idf B)
=⟨ ap (λ h → ∧-fmap h g) (⊙λ= (⊙∘-unit-l f)) ⟩
∧-fmap f g =∎
| {
"alphanum_fraction": 0.4145400288,
"avg_line_length": 36.3970037453,
"ext": "agda",
"hexsha": "1e40acdb1a115bbc26058f50a2804839d534fd36",
"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": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/SmashFmapConn.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"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": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/SmashFmapConn.agda",
"max_line_length": 102,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/SmashFmapConn.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": 8872,
"size": 19436
} |
{-# OPTIONS --allow-unsolved-metas #-}
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- CS410 2017/18 Exercise 1 VECTORS AND FRIENDS (worth 25%)
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- NOTE (19/9/17) This file is currently incomplete: more will arrive on
-- GitHub.
-- MARK SCHEME (transcribed from paper): the (m) numbers add up to slightly
-- more than 25, so should be taken as the maximum number of marks losable on
-- the exercise. In fact, I did mark it negatively, but mostly because it was
-- done so well (with Agda's help) that it was easier to find the errors.
------------------------------------------------------------------------------
-- Dependencies
------------------------------------------------------------------------------
open import CS410-Prelude
------------------------------------------------------------------------------
-- Vectors
------------------------------------------------------------------------------
data Vec (X : Set) : Nat -> Set where -- like lists, but length-indexed
[] : Vec X zero
_,-_ : {n : Nat} -> X -> Vec X n -> Vec X (suc n)
infixr 4 _,-_ -- the "cons" operator associates to the right
-- I like to use the asymmetric ,- to remind myself that the element is to
-- the left and the rest of the list is to the right.
-- Vectors are useful when there are important length-related safety
-- properties.
------------------------------------------------------------------------------
-- Heads and Tails
------------------------------------------------------------------------------
-- We can rule out nasty head and tail errors by insisting on nonemptiness!
--??--1.1-(2)-----------------------------------------------------------------
vHead : {X : Set}{n : Nat} -> Vec X (suc n) -> X
vHead xs = {!!}
vTail : {X : Set}{n : Nat} -> Vec X (suc n) -> Vec X n
vTail xs = {!!}
vHeadTailFact : {X : Set}{n : Nat}(xs : Vec X (suc n)) ->
(vHead xs ,- vTail xs) == xs
vHeadTailFact xs = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Concatenation and its Inverse
------------------------------------------------------------------------------
--??--1.2-(2)-----------------------------------------------------------------
_+V_ : {X : Set}{m n : Nat} -> Vec X m -> Vec X n -> Vec X (m +N n)
xs +V ys = {!!}
infixr 4 _+V_
vChop : {X : Set}(m : Nat){n : Nat} -> Vec X (m +N n) -> Vec X m * Vec X n
vChop m xs = {!!}
vChopAppendFact : {X : Set}{m n : Nat}(xs : Vec X m)(ys : Vec X n) ->
vChop m (xs +V ys) == (xs , ys)
vChopAppendFact xs ys = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Map, take I
------------------------------------------------------------------------------
-- Implement the higher-order function that takes an operation on
-- elements and does it to each element of a vector. Use recursion
-- on the vector.
-- Note that the type tells you the size remains the same.
-- Show that if the elementwise function "does nothing", neither does
-- its vMap. "map of identity is identity"
-- Show that two vMaps in a row can be collapsed to just one, or
-- "composition of maps is map of compositions"
--??--1.3-(2)-----------------------------------------------------------------
vMap : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n
vMap f xs = {!!}
vMapIdFact : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) ->
{n : Nat}(xs : Vec X n) -> vMap f xs == xs
vMapIdFact feq xs = {!!}
vMapCpFact : {X Y Z : Set}{f : Y -> Z}{g : X -> Y}{h : X -> Z}
(heq : (x : X) -> f (g x) == h x) ->
{n : Nat}(xs : Vec X n) ->
vMap f (vMap g xs) == vMap h xs
vMapCpFact heq xs = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- vMap and +V
------------------------------------------------------------------------------
-- Show that if you've got two vectors of Xs and a function from X to Y,
-- and you want to concatenate and map, it doesn't matter which you do
-- first.
--??--1.4-(1)-----------------------------------------------------------------
vMap+VFact : {X Y : Set}(f : X -> Y) ->
{m n : Nat}(xs : Vec X m)(xs' : Vec X n) ->
vMap f (xs +V xs') == (vMap f xs +V vMap f xs')
vMap+VFact f xs xs' = {!!}
--??--------------------------------------------------------------------------
-- Think about what you could prove, relating vMap with vHead, vTail, vChop...
-- Now google "Philip Wadler" "Theorems for Free"
------------------------------------------------------------------------------
-- Applicative Structure (giving mapping and zipping cheaply)
------------------------------------------------------------------------------
--??--1.5-(2)-----------------------------------------------------------------
-- HINT: you will need to override the default invisibility of n to do this.
vPure : {X : Set} -> X -> {n : Nat} -> Vec X n
vPure x {n} = {!!}
_$V_ : {X Y : Set}{n : Nat} -> Vec (X -> Y) n -> Vec X n -> Vec Y n
fs $V xs = {!!}
infixl 3 _$V_ -- "Application associates to the left,
-- rather as we all did in the sixties." (Roger Hindley)
-- Pattern matching and recursion are forbidden for the next two tasks.
-- implement vMap again, but as a one-liner
vec : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n
vec f xs = {!!}
-- implement the operation which pairs up corresponding elements
vZip : {X Y : Set}{n : Nat} -> Vec X n -> Vec Y n -> Vec (X * Y) n
vZip xs ys = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Applicative Laws
------------------------------------------------------------------------------
-- According to "Applicative programming with effects" by
-- Conor McBride and Ross Paterson
-- some laws should hold for applicative functors.
-- Check that this is the case.
--??--1.6-(2)-----------------------------------------------------------------
vIdentity : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) ->
{n : Nat}(xs : Vec X n) -> (vPure f $V xs) == xs
vIdentity feq xs = {!!}
vHomomorphism : {X Y : Set}(f : X -> Y)(x : X) ->
{n : Nat} -> (vPure f $V vPure x) == vPure (f x) {n}
vHomomorphism f x {n} = {!!}
vInterchange : {X Y : Set}{n : Nat}(fs : Vec (X -> Y) n)(x : X) ->
(fs $V vPure x) == (vPure (_$ x) $V fs)
vInterchange fs x = {!!}
vComposition : {X Y Z : Set}{n : Nat}
(fs : Vec (Y -> Z) n)(gs : Vec (X -> Y) n)(xs : Vec X n) ->
(vPure _<<_ $V fs $V gs $V xs) == (fs $V (gs $V xs))
vComposition fs gs xs = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Order-Preserving Embeddings (also known in the business as "thinnings")
------------------------------------------------------------------------------
-- What have these to do with Pascal's Triangle?
data _<=_ : Nat -> Nat -> Set where
oz : zero <= zero
os : {n m : Nat} -> n <= m -> suc n <= suc m
o' : {n m : Nat} -> n <= m -> n <= suc m
-- Find all the values in each of the following <= types.
-- This is a good opportunity to learn to use C-c C-a with the -l option
-- (a.k.a. "google the type" without "I feel lucky")
-- The -s n option also helps.
--??--1.7-(1)-----------------------------------------------------------------
all0<=4 : Vec (0 <= 4) {!!}
all0<=4 = {!!}
all1<=4 : Vec (1 <= 4) {!!}
all1<=4 = {!!}
all2<=4 : Vec (2 <= 4) {!!}
all2<=4 = {!!}
all3<=4 : Vec (3 <= 4) {!!}
all3<=4 = {!!}
all4<=4 : Vec (4 <= 4) {!!}
all4<=4 = {!!}
-- Prove the following. A massive case analysis "rant" is fine.
no5<=4 : 5 <= 4 -> Zero
no5<=4 th = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Order-Preserving Embeddings Select From Vectors
------------------------------------------------------------------------------
-- Use n <= m to encode the choice of n elements from an m-Vector.
-- The os constructor tells you to take the next element of the vector;
-- the o' constructor tells you to omit the next element of the vector.
--??--1.8-(2)-----------------------------------------------------------------
_<?=_ : {X : Set}{n m : Nat} -> n <= m -> Vec X m
-> Vec X n
th <?= xs = {!!}
-- it shouldn't matter whether you map then select or select then map
vMap<?=Fact : {X Y : Set}(f : X -> Y)
{n m : Nat}(th : n <= m)(xs : Vec X m) ->
vMap f (th <?= xs) == (th <?= vMap f xs)
vMap<?=Fact f th xs = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Our Favourite Thinnings
------------------------------------------------------------------------------
-- Construct the identity thinning and the empty thinning.
--??--1.9-(1)-----------------------------------------------------------------
oi : {n : Nat} -> n <= n
oi {n} = {!!}
oe : {n : Nat} -> 0 <= n
oe {n} = {!!}
--??--------------------------------------------------------------------------
-- Show that all empty thinnings are equal to yours.
--??--1.10-(1)----------------------------------------------------------------
oeUnique : {n : Nat}(th : 0 <= n) -> th == oe
oeUnique i = {!!}
--??--------------------------------------------------------------------------
-- Show that there are no thinnings of form big <= small (TRICKY)
-- Then show that all the identity thinnings are equal to yours.
-- Note that you can try the second even if you haven't finished the first.
-- HINT: you WILL need to expose the invisible numbers.
-- HINT: check CS410-Prelude for a reminder of >=
--??--1.11-(3)----------------------------------------------------------------
oTooBig : {n m : Nat} -> n >= m -> suc n <= m -> Zero
oTooBig {n} {m} n>=m th = {!!}
oiUnique : {n : Nat}(th : n <= n) -> th == oi
oiUnique th = {!!}
--??--------------------------------------------------------------------------
-- Show that the identity thinning selects the whole vector
--??--1.12-(1)----------------------------------------------------------------
id-<?= : {X : Set}{n : Nat}(xs : Vec X n) -> (oi <?= xs) == xs
id-<?= xs = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Composition of Thinnings
------------------------------------------------------------------------------
-- Define the composition of thinnings and show that selecting by a
-- composite thinning is like selecting then selecting again.
-- A small bonus applies to minimizing the length of the proof.
-- To collect the bonus, you will need to think carefully about
-- how to make the composition as *lazy* as possible.
--??--1.13-(3)----------------------------------------------------------------
_o>>_ : {p n m : Nat} -> p <= n -> n <= m -> p <= m
th o>> th' = {!!}
cp-<?= : {p n m : Nat}(th : p <= n)(th' : n <= m) ->
{X : Set}(xs : Vec X m) ->
((th o>> th') <?= xs) == (th <?= (th' <?= xs))
cp-<?= th th' xs = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Thinning Dominoes
------------------------------------------------------------------------------
--??--1.14-(3)----------------------------------------------------------------
idThen-o>> : {n m : Nat}(th : n <= m) -> (oi o>> th) == th
idThen-o>> th = {!!}
idAfter-o>> : {n m : Nat}(th : n <= m) -> (th o>> oi) == th
idAfter-o>> th = {!!}
assoc-o>> : {q p n m : Nat}(th0 : q <= p)(th1 : p <= n)(th2 : n <= m) ->
((th0 o>> th1) o>> th2) == (th0 o>> (th1 o>> th2))
assoc-o>> th0 th1 th2 = {!!}
--??--------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Vectors as Arrays
------------------------------------------------------------------------------
-- We can use 1 <= n as the type of bounded indices into a vector and do
-- a kind of "array projection". First we select a 1-element vector from
-- the n-element vector, then we take its head to get the element out.
vProject : {n : Nat}{X : Set} -> Vec X n -> 1 <= n -> X
vProject xs i = vHead (i <?= xs)
-- Your (TRICKY) mission is to reverse the process, tabulating a function
-- from indices as a vector. Then show that these operations are inverses.
--??--1.15-(3)----------------------------------------------------------------
-- HINT: composition of functions
vTabulate : {n : Nat}{X : Set} -> (1 <= n -> X) -> Vec X n
vTabulate {n} f = {!!}
-- This should be easy if vTabulate is correct.
vTabulateProjections : {n : Nat}{X : Set}(xs : Vec X n) ->
vTabulate (vProject xs) == xs
vTabulateProjections xs = {!!}
-- HINT: oeUnique
vProjectFromTable : {n : Nat}{X : Set}(f : 1 <= n -> X)(i : 1 <= n) ->
vProject (vTabulate f) i == f i
vProjectFromTable f i = {!!}
--??--------------------------------------------------------------------------
| {
"alphanum_fraction": 0.3686579963,
"avg_line_length": 36.2538860104,
"ext": "agda",
"hexsha": "75c052b25e1ac227bc906c3434739d59a9849bd2",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"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": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex1.agda",
"max_line_length": 78,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/course/2017-conor_mcbride_cs410/CS410-17-master/exercises/Ex1.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 3240,
"size": 13994
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A categorical view of Vec
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Categorical {a n} where
open import Category.Applicative using (RawApplicative)
open import Category.Applicative.Indexed using (Morphism)
open import Category.Functor as Fun using (RawFunctor)
import Function.Identity.Categorical as Id
open import Category.Monad using (RawMonad)
open import Data.Fin using (Fin)
open import Data.Vec as Vec hiding (_⊛_)
open import Data.Vec.Properties
open import Function
------------------------------------------------------------------------
-- Functor and applicative
functor : RawFunctor (λ (A : Set a) → Vec A n)
functor = record
{ _<$>_ = map
}
applicative : RawApplicative (λ (A : Set a) → Vec A n)
applicative = record
{ pure = replicate
; _⊛_ = Vec._⊛_
}
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {f F} (App : RawApplicative {f} F) where
open RawApplicative App
sequenceA : ∀ {A n} → Vec (F A) n → F (Vec A n)
sequenceA [] = pure []
sequenceA (x ∷ xs) = _∷_ <$> x ⊛ sequenceA xs
mapA : ∀ {a} {A : Set a} {B n} → (A → F B) → Vec A n → F (Vec B n)
mapA f = sequenceA ∘ map f
forA : ∀ {a} {A : Set a} {B n} → Vec A n → (A → F B) → F (Vec B n)
forA = flip mapA
module _ {m M} (Mon : RawMonad {m} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM : ∀ {A n} → Vec (M A) n → M (Vec A n)
sequenceM = sequenceA App
mapM : ∀ {a} {A : Set a} {B n} → (A → M B) → Vec A n → M (Vec B n)
mapM = mapA App
forM : ∀ {a} {A : Set a} {B n} → Vec A n → (A → M B) → M (Vec B n)
forM = forA App
------------------------------------------------------------------------
-- Other
-- lookup is a functor morphism from Vec to Identity.
lookup-functor-morphism : (i : Fin n) → Fun.Morphism functor Id.functor
lookup-functor-morphism i = record
{ op = flip lookup i
; op-<$> = lookup-map i
}
-- lookup is an applicative functor morphism.
lookup-morphism : (i : Fin n) → Morphism applicative Id.applicative
lookup-morphism i = record
{ op = flip lookup i
; op-pure = lookup-replicate i
; op-⊛ = lookup-⊛ i
}
| {
"alphanum_fraction": 0.5333614865,
"avg_line_length": 28.1904761905,
"ext": "agda",
"hexsha": "637551cbc10f9a8b39d0bdbaf122bd1b9224ff1c",
"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/Vec/Categorical.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Categorical.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/Vec/Categorical.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 692,
"size": 2368
} |
-- A placeholder module so that we can write a main. Agda compilation
-- does not work without a main so batch compilation is bound to give
-- errors. For travis builds, we want batch compilation and this is
-- module can be imported to serve that purpose. There is nothing
-- useful that can be achieved from this module though.
module io.placeholder where
open import hott.core.universe
postulate
Unit : Type₀
IO : Type₀ → Type₀
dummyMain : IO Unit
{-# COMPILED_TYPE Unit () #-}
{-# COMPILED_TYPE IO IO #-}
{-# COMPILED dummyMain (return ()) #-}
{-# BUILTIN IO IO #-}
| {
"alphanum_fraction": 0.6347031963,
"avg_line_length": 32.85,
"ext": "agda",
"hexsha": "0335351996fb313017d0013157f90455a4e20326",
"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": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/io/placeholder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"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": "piyush-kurur/hott",
"max_issues_repo_path": "agda/io/placeholder.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/io/placeholder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 153,
"size": 657
} |
open import Mockingbird.Forest using (Forest)
import Mockingbird.Forest.Birds as Birds
-- The Master Forest
module Mockingbird.Problems.Chapter18 {b ℓ} (forest : Forest {b} {ℓ})
⦃ _ : Birds.HasStarling forest ⦄
⦃ _ : Birds.HasKestrel forest ⦄ where
open import Data.Maybe using (Maybe; nothing; just)
open import Data.Product using (_×_; _,_; proj₁; ∃-syntax)
open import Data.Vec using (Vec; []; _∷_; _++_)
open import Data.Vec.Relation.Unary.Any.Properties using (++⁺ʳ)
open import Function using (_$_)
open import Level using (_⊔_)
open import Mockingbird.Forest.Combination.Vec forest using (⟨_⟩; here; there; [_]; _⟨∙⟩_∣_; _⟨∙⟩_; [#_])
open import Mockingbird.Forest.Combination.Vec.Properties forest using (subst′; weaken-++ˡ; weaken-++ʳ; ++-comm)
open import Relation.Unary using (_∈_)
open Forest forest
open import Mockingbird.Forest.Birds forest
problem₁ : HasIdentity
problem₁ = record
{ I = S ∙ K ∙ K
; isIdentity = λ x → begin
S ∙ K ∙ K ∙ x ≈⟨ isStarling K K x ⟩
K ∙ x ∙ (K ∙ x) ≈⟨ isKestrel x (K ∙ x) ⟩
x ∎
}
private instance hasIdentity = problem₁
problem₂ : HasMockingbird
problem₂ = record
{ M = S ∙ I ∙ I
; isMockingbird = λ x → begin
S ∙ I ∙ I ∙ x ≈⟨ isStarling I I x ⟩
I ∙ x ∙ (I ∙ x) ≈⟨ congʳ $ isIdentity x ⟩
x ∙ (I ∙ x) ≈⟨ congˡ $ isIdentity x ⟩
x ∙ x ∎
}
private instance hasMockingbird = problem₂
problem₃ : HasThrush
problem₃ = record
{ T = S ∙ (K ∙ (S ∙ I)) ∙ K
; isThrush = λ x y → begin
S ∙ (K ∙ (S ∙ I)) ∙ K ∙ x ∙ y ≈⟨ congʳ $ isStarling (K ∙ (S ∙ I)) K x ⟩
K ∙ (S ∙ I) ∙ x ∙ (K ∙ x) ∙ y ≈⟨ (congʳ $ congʳ $ isKestrel (S ∙ I) x) ⟩
S ∙ I ∙ (K ∙ x) ∙ y ≈⟨ isStarling I (K ∙ x) y ⟩
I ∙ y ∙ (K ∙ x ∙ y) ≈⟨ congʳ $ isIdentity y ⟩
y ∙ (K ∙ x ∙ y) ≈⟨ congˡ $ isKestrel x y ⟩
y ∙ x ∎
}
-- TODO: Problem 4.
I∈⟨S,K⟩ : I ∈ ⟨ S ∷ K ∷ [] ⟩
I∈⟨S,K⟩ = subst′ refl $ [# 0 ] ⟨∙⟩ [# 1 ] ⟨∙⟩ [# 1 ]
-- Try to strengthen a proof of X ∈ ⟨ y ∷ xs ⟩ to X ∈ ⟨ xs ⟩, which can be done
-- if y does not occur in X.
strengthen : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ y ∷ xs ⟩ → Maybe (X ∈ ⟨ xs ⟩)
-- NOTE: it could be the case that y ∈ xs, but checking that requires decidable
-- equality.
strengthen [ here X≈y ] = nothing
strengthen [ there X∈xs ] = just [ X∈xs ]
strengthen (Y∈⟨y,xs⟩ ⟨∙⟩ Z∈⟨y,xs⟩ ∣ YZ≈X) = do
Y∈⟨xs⟩ ← strengthen Y∈⟨y,xs⟩
Z∈⟨xs⟩ ← strengthen Z∈⟨y,xs⟩
just $ Y∈⟨xs⟩ ⟨∙⟩ Z∈⟨xs⟩ ∣ YZ≈X
where
open import Data.Maybe.Categorical using (monad)
open import Category.Monad using (RawMonad)
open RawMonad (monad {b ⊔ ℓ})
eliminate : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ y ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ xs ⟩ × X′ ∙ y ≈ X)
eliminate {X = X} {y} [ here X≈y ] = (I , weaken-++ˡ I∈⟨S,K⟩ , trans (isIdentity y) (sym X≈y))
eliminate {X = X} {y} [ there X∈xs ] = (K ∙ X , [# 1 ] ⟨∙⟩ [ ++⁺ʳ (S ∷ K ∷ []) X∈xs ] , isKestrel X y)
eliminate {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨y,xs⟩ [ here Z≈y ] YZ≈X) with strengthen Y∈⟨y,xs⟩
... | just Y∈⟨xs⟩ = (Y , weaken-++ʳ (S ∷ K ∷ []) Y∈⟨xs⟩ , trans (congˡ (sym Z≈y)) YZ≈X)
... | nothing =
let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate Y∈⟨y,xs⟩
SY′Iy≈X : S ∙ Y′ ∙ I ∙ y ≈ X
SY′Iy≈X = begin
S ∙ Y′ ∙ I ∙ y ≈⟨ isStarling Y′ I y ⟩
Y′ ∙ y ∙ (I ∙ y) ≈⟨ congʳ $ Y′y≈Y ⟩
Y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩
Y ∙ y ≈˘⟨ congˡ Z≈y ⟩
Y ∙ Z ≈⟨ YZ≈X ⟩
X ∎
in (S ∙ Y′ ∙ I , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ weaken-++ˡ I∈⟨S,K⟩ , SY′Iy≈X)
eliminate {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨y,xs⟩ Z∈⟨y,xs⟩ YZ≈X) =
let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate Y∈⟨y,xs⟩
(Z′ , Z′∈⟨S,K,xs⟩ , Z′y≈Z) = eliminate Z∈⟨y,xs⟩
SY′Z′y≈X : S ∙ Y′ ∙ Z′ ∙ y ≈ X
SY′Z′y≈X = begin
S ∙ Y′ ∙ Z′ ∙ y ≈⟨ isStarling Y′ Z′ y ⟩
Y′ ∙ y ∙ (Z′ ∙ y) ≈⟨ congʳ Y′y≈Y ⟩
Y ∙ (Z′ ∙ y) ≈⟨ congˡ Z′y≈Z ⟩
Y ∙ Z ≈⟨ YZ≈X ⟩
X ∎
in (S ∙ Y′ ∙ Z′ , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ Z′∈⟨S,K,xs⟩ , SY′Z′y≈X)
module _ (x y : Bird) where
-- Example: y-eliminating the expression y should give I.
_ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ]) ≈ I
_ = refl
-- Example: y-eliminating the expression x should give Kx.
_ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 1 ]) ≈ K ∙ x
_ = refl
-- Example: y-eliminating the expression xy should give x (Principle 3).
_ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 1 ] ⟨∙⟩ [# 0 ]) ≈ x
_ = refl
-- Example: y-eliminating the expression yx should give SI(Kx).
_ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ] ⟨∙⟩ [# 1 ]) ≈ S ∙ I ∙ (K ∙ x)
_ = refl
-- Example: y-eliminating the expression yy should give SII.
_ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ] ⟨∙⟩ [# 0 ]) ≈ S ∙ I ∙ I
_ = refl
strengthen-SK : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ y ∷ xs ⟩ → Maybe (X ∈ ⟨ S ∷ K ∷ xs ⟩)
strengthen-SK {y = y} {xs} X∈⟨S,K,y,xs⟩ = do
let X∈⟨y,xs,S,K⟩ = ++-comm (S ∷ K ∷ []) (y ∷ xs) X∈⟨S,K,y,xs⟩
X∈⟨xs,S,K⟩ ← strengthen X∈⟨y,xs,S,K⟩
let X∈⟨S,K,xs⟩ = ++-comm xs (S ∷ K ∷ []) X∈⟨xs,S,K⟩
just X∈⟨S,K,xs⟩
where
open import Data.Maybe.Categorical using (monad)
open import Category.Monad using (RawMonad)
open RawMonad (monad {b ⊔ ℓ})
-- TODO: formulate eliminate or eliminate-SK in terms of the other.
eliminate-SK : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ y ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ xs ⟩ × X′ ∙ y ≈ X)
eliminate-SK {X = X} {y} [ here X≈S ] = (K ∙ S , [# 1 ] ⟨∙⟩ [# 0 ] , trans (isKestrel S y) (sym X≈S))
eliminate-SK {X = X} {y} [ there (here X≈K) ] = (K ∙ K , [# 1 ] ⟨∙⟩ [# 1 ] , trans (isKestrel K y) (sym X≈K))
eliminate-SK {X = X} {y} [ there (there (here X≈y)) ] = (I , weaken-++ˡ I∈⟨S,K⟩ , trans (isIdentity y) (sym X≈y))
eliminate-SK {X = X} {y} [ there (there (there X∈xs)) ] = (K ∙ X , ([# 1 ] ⟨∙⟩ [ (++⁺ʳ (S ∷ K ∷ []) X∈xs) ]) , isKestrel X y)
eliminate-SK {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨S,K,y,xs⟩ [ there (there (here Z≈y)) ] YZ≈X) with strengthen-SK Y∈⟨S,K,y,xs⟩
... | just Y∈⟨S,K,xs⟩ = (Y , Y∈⟨S,K,xs⟩ , trans (congˡ (sym Z≈y)) YZ≈X)
... | nothing =
let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate-SK Y∈⟨S,K,y,xs⟩
SY′Iy≈X : S ∙ Y′ ∙ I ∙ y ≈ X
SY′Iy≈X = begin
S ∙ Y′ ∙ I ∙ y ≈⟨ isStarling Y′ I y ⟩
Y′ ∙ y ∙ (I ∙ y) ≈⟨ congʳ $ Y′y≈Y ⟩
Y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩
Y ∙ y ≈˘⟨ congˡ Z≈y ⟩
Y ∙ Z ≈⟨ YZ≈X ⟩
X ∎
in (S ∙ Y′ ∙ I , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ weaken-++ˡ I∈⟨S,K⟩ , SY′Iy≈X)
eliminate-SK {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨S,K,y,xs⟩ Z∈⟨S,K,y,xs⟩ YZ≈X) =
let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate-SK Y∈⟨S,K,y,xs⟩
(Z′ , Z′∈⟨S,K,xs⟩ , Z′y≈Z) = eliminate-SK Z∈⟨S,K,y,xs⟩
SY′Z′y≈X : S ∙ Y′ ∙ Z′ ∙ y ≈ X
SY′Z′y≈X = begin
S ∙ Y′ ∙ Z′ ∙ y ≈⟨ isStarling Y′ Z′ y ⟩
Y′ ∙ y ∙ (Z′ ∙ y) ≈⟨ congʳ Y′y≈Y ⟩
Y ∙ (Z′ ∙ y) ≈⟨ congˡ Z′y≈Z ⟩
Y ∙ Z ≈⟨ YZ≈X ⟩
X ∎
in (S ∙ Y′ ∙ Z′ , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ Z′∈⟨S,K,xs⟩ , SY′Z′y≈X)
module _ (x y : Bird) where
-- Example: y-eliminating the expression y should give I.
_ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ]) ≈ I
_ = refl
-- Example: y-eliminating the expression x should give Kx.
_ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 3 ]) ≈ K ∙ x
_ = refl
-- Example: y-eliminating the expression xy should give x (Principle 3).
_ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 3 ] ⟨∙⟩ [# 2 ]) ≈ x
_ = refl
-- Example: y-eliminating the expression yx should give SI(Kx).
_ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ] ⟨∙⟩ [# 3 ]) ≈ S ∙ I ∙ (K ∙ x)
_ = refl
-- Example: y-eliminating the expression yy should give SII.
_ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ] ⟨∙⟩ [# 2 ]) ≈ S ∙ I ∙ I
_ = refl
infixl 6 _∙ⁿ_
_∙ⁿ_ : ∀ {n} → (A : Bird) (xs : Vec Bird n) → Bird
A ∙ⁿ [] = A
A ∙ⁿ (x ∷ xs) = A ∙ⁿ xs ∙ x
eliminateAll′ : ∀ {n X} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ [] ⟩ × X′ ∙ⁿ xs ≈ X)
eliminateAll′ {X = X} {[]} X∈⟨S,K⟩ = (X , X∈⟨S,K⟩ , refl)
eliminateAll′ {X = X} {x ∷ xs} X∈⟨S,K,x,xs⟩ =
let (X′ , X′∈⟨S,K,xs⟩ , X′x≈X) = eliminate-SK X∈⟨S,K,x,xs⟩
(X″ , X″∈⟨S,K⟩ , X″xs≈X′) = eliminateAll′ X′∈⟨S,K,xs⟩
X″∙ⁿxs∙x≈X : X″ ∙ⁿ xs ∙ x ≈ X
X″∙ⁿxs∙x≈X = begin
X″ ∙ⁿ xs ∙ x ≈⟨ congʳ X″xs≈X′ ⟩
X′ ∙ x ≈⟨ X′x≈X ⟩
X ∎
in (X″ , X″∈⟨S,K⟩ , X″∙ⁿxs∙x≈X)
-- TOOD: can we do this in some way without depending on xs : Vec Bird n?
eliminateAll : ∀ {n X} {xs : Vec Bird n} → X ∈ ⟨ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ [] ⟩ × X′ ∙ⁿ xs ≈ X)
eliminateAll X∈⟨xs⟩ = eliminateAll′ $ weaken-++ʳ (S ∷ K ∷ []) X∈⟨xs⟩
| {
"alphanum_fraction": 0.4658810325,
"avg_line_length": 41.4418604651,
"ext": "agda",
"hexsha": "0375b2e0eb5d382a3d8f5598afd8da468a1f4bad",
"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": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Problems/Chapter18.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"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": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Problems/Chapter18.agda",
"max_line_length": 125,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Problems/Chapter18.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 4411,
"size": 8910
} |
-- Andreas, 2017-01-12, re #2386
-- Correct error message for wrong BUILTIN UNIT
data Bool : Set where
true false : Bool
{-# BUILTIN UNIT Bool #-}
-- Error WAS:
-- The builtin UNIT must be a datatype with 1 constructors
-- when checking the pragma BUILTIN UNIT Bool
-- Expected error:
-- Builtin UNIT must be a singleton record type
-- when checking the pragma BUILTIN UNIT Bool
| {
"alphanum_fraction": 0.7246753247,
"avg_line_length": 24.0625,
"ext": "agda",
"hexsha": "e8bc0d8e985723332ad62465af9f30895b1ac850",
"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/WrongBuiltinUnit.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/WrongBuiltinUnit.agda",
"max_line_length": 58,
"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/WrongBuiltinUnit.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": 96,
"size": 385
} |
open import FRP.JS.Bool using ( not )
open import FRP.JS.Nat using ( ) renaming ( _≟_ to _≟n_ )
open import FRP.JS.String using ( _≟_ ; _≤_ ; _<_ ; length )
open import FRP.JS.QUnit using ( TestSuite ; ok ; test ; _,_ )
module FRP.JS.Test.String where
tests : TestSuite
tests =
( test "≟"
( ok "abc ≟ abc" ("abc" ≟ "abc")
, ok "ε ≟ abc" (not ("" ≟ "abc"))
, ok "a ≟ abc" (not ("a" ≟ "abc"))
, ok "abc ≟ ABC" (not ("abc" ≟ "ABC")) )
, test "length"
( ok "length ε" (length "" ≟n 0)
, ok "length a" (length "a" ≟n 1)
, ok "length ab" (length "ab" ≟n 2)
, ok "length abc" (length "abc" ≟n 3)
, ok "length \"\\\"" (length "\"\\\"" ≟n 3)
, ok "length åäö⊢ξ∀" (length "åäö⊢ξ∀" ≟n 6)
, ok "length ⟨line-terminators⟩" (length "\r\n\x2028\x2029" ≟n 4) )
, test "≤"
( ok "abc ≤ abc" ("abc" ≤ "abc")
, ok "abc ≤ ε" (not ("abc" ≤ ""))
, ok "abc ≤ a" (not ("abc" ≤ "a"))
, ok "abc ≤ ab" (not ("abc" ≤ "a"))
, ok "abc ≤ ABC" (not ("abc" ≤ "ABC"))
, ok "ε ≤ abc" ("" ≤ "abc")
, ok "a ≤ abc" ("a" ≤ "abc")
, ok "ab ≤ abc" ("a" ≤ "abc")
, ok "ABC ≤ abc" ("ABC" ≤ "abc") )
, test "<"
( ok "abc < abc" (not ("abc" < "abc"))
, ok "abc < ε" (not ("abc" < ""))
, ok "abc < a" (not ("abc" < "a"))
, ok "abc < ab" (not ("abc" < "a"))
, ok "abc < ABC" (not ("abc" < "ABC"))
, ok "ε < abc" ("" < "abc")
, ok "a < abc" ("a" < "abc")
, ok "ab < abc" ("a" < "abc")
, ok "ABC < abc" ("ABC" < "abc") ) ) | {
"alphanum_fraction": 0.4384564205,
"avg_line_length": 35.7857142857,
"ext": "agda",
"hexsha": "a60c3833e092bd5dc47411887b9684eb8c06ae7b",
"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": "test/agda/FRP/JS/Test/String.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": "test/agda/FRP/JS/Test/String.agda",
"max_line_length": 71,
"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": "test/agda/FRP/JS/Test/String.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": 640,
"size": 1503
} |
-- Andreas, 2017-11-06, issue #2840 reported by wenkokke
Id : (F : Set → Set) → Set → Set
Id F = F
data D (A : Set) : Set where
c : Id _ A
-- WAS: internal error in positivity checker
-- EXPECTED: success, or
-- The target of a constructor must be the datatype applied to its
-- parameters, _F_2 A isn't
-- when checking the constructor c in the declaration of D
| {
"alphanum_fraction": 0.6829268293,
"avg_line_length": 24.6,
"ext": "agda",
"hexsha": "3d73782800f4489c62dc7019dfd6980ed6171630",
"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/Issue2840.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/Issue2840.agda",
"max_line_length": 66,
"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/Issue2840.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": 112,
"size": 369
} |
------------------------------------------------------------------------
-- This module proves that the context-sensitive language aⁿbⁿcⁿ can
-- be recognised
------------------------------------------------------------------------
-- This is obvious given the proof in
-- TotalRecognisers.LeftRecursion.ExpressiveStrength but the code
-- below provides a non-trivial example of the use of the parser
-- combinators.
module TotalRecognisers.LeftRecursion.NotOnlyContextFree where
open import Algebra
open import Codata.Musical.Notation
open import Data.Bool using (Bool; true; false; _∨_)
open import Function
open import Data.List as List using (List; []; _∷_; _++_; [_])
import Data.List.Properties
private
module ListMonoid {A : Set} =
Monoid (Data.List.Properties.++-monoid A)
open import Data.Nat as Nat using (ℕ; zero; suc; _+_)
import Data.Nat.Properties as NatProp
private
module NatCS = CommutativeSemiring NatProp.+-*-commutativeSemiring
import Data.Nat.Solver
open Data.Nat.Solver.+-*-Solver
open import Data.Product
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open ≡-Reasoning
import TotalRecognisers.LeftRecursion
import TotalRecognisers.LeftRecursion.Lib as Lib
------------------------------------------------------------------------
-- The alphabet
data Tok : Set where
a b c : Tok
_≟_ : Decidable (_≡_ {A = Tok})
a ≟ a = yes refl
a ≟ b = no λ()
a ≟ c = no λ()
b ≟ a = no λ()
b ≟ b = yes refl
b ≟ c = no λ()
c ≟ a = no λ()
c ≟ b = no λ()
c ≟ c = yes refl
open TotalRecognisers.LeftRecursion Tok
open Lib Tok
private
open module TokTok = Lib.Tok Tok _≟_ using (tok)
------------------------------------------------------------------------
-- An auxiliary definition and a boring lemma
infixr 8 _^^_
_^^_ : Tok → ℕ → List Tok
_^^_ = flip List.replicate
private
shallow-comm : ∀ i n → i + suc n ≡ suc (i + n)
shallow-comm i n =
solve 2 (λ i n → i :+ (con 1 :+ n) := con 1 :+ i :+ n) refl i n
------------------------------------------------------------------------
-- Some lemmas relating _^^_, _^_ and tok
tok-^-complete : ∀ t i → t ^^ i ∈ tok t ^ i
tok-^-complete t zero = empty
tok-^-complete t (suc i) =
add-♭♯ ⟨ false ^ i ⟩-nullable TokTok.complete · tok-^-complete t i
tok-^-sound : ∀ t i {s} → s ∈ tok t ^ i → s ≡ t ^^ i
tok-^-sound t zero empty = refl
tok-^-sound t (suc i) (t∈ · s∈)
with TokTok.sound (drop-♭♯ ⟨ false ^ i ⟩-nullable t∈)
... | refl = cong (_∷_ t) (tok-^-sound t i s∈)
------------------------------------------------------------------------
-- aⁿbⁿcⁿ
-- The context-sensitive language { aⁿbⁿcⁿ | n ∈ ℕ } can be recognised
-- using the parser combinators defined in this development.
private
-- The two functions below are not actually mutually recursive, but
-- are placed in a mutual block to ensure that the constraints
-- generated by the second function can be used to instantiate the
-- underscore in the body of the first.
mutual
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index : ℕ → Bool
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index _ = _
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ : (i : ℕ) → P (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index i)
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ i = cast lem (♯? (tok a) · ♯ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ (suc i))
∣ tok b ^ i ⊙ tok c ^ i
where lem = left-zero (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i))
aⁿbⁿcⁿ : P true
aⁿbⁿcⁿ = aⁿbⁱ⁺ⁿcⁱ⁺ⁿ 0
-- Let us prove that aⁿbⁿcⁿ is correctly defined.
aⁿbⁿcⁿ-string : ℕ → List Tok
aⁿbⁿcⁿ-string n = a ^^ n ++ b ^^ n ++ c ^^ n
private
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string : ℕ → ℕ → List Tok
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string n i = a ^^ n ++ b ^^ (i + n) ++ c ^^ (i + n)
aⁿbⁿcⁿ-complete : ∀ n → aⁿbⁿcⁿ-string n ∈ aⁿbⁿcⁿ
aⁿbⁿcⁿ-complete n = aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete n 0
where
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete : ∀ n i → aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string n i ∈ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ i
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete zero i with i + 0 | proj₂ NatCS.+-identity i
... | .i | refl = ∣-right {n₁ = false} (helper b · helper c)
where
helper = λ (t : Tok) →
add-♭♯ ⟨ false ^ i ⟩-nullable (tok-^-complete t i)
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete (suc n) i with i + suc n | shallow-comm i n
... | .(suc i + n) | refl =
∣-left $ cast {eq = lem} (
add-♭♯ (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i)) TokTok.complete ·
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete n (suc i))
where lem = left-zero (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i))
aⁿbⁿcⁿ-sound : ∀ {s} → s ∈ aⁿbⁿcⁿ → ∃ λ n → s ≡ aⁿbⁿcⁿ-string n
aⁿbⁿcⁿ-sound = aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound 0
where
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound : ∀ {s} i → s ∈ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ i →
∃ λ n → s ≡ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string n i
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound i (∣-left (cast (t∈ · s∈)))
with TokTok.sound (drop-♭♯ (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i)) t∈)
... | refl with aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound (suc i) s∈
... | (n , refl) = suc n , (begin
a ^^ suc n ++ b ^^ (suc i + n) ++ c ^^ (suc i + n)
≡⟨ cong (λ i → a ^^ suc n ++ b ^^ i ++ c ^^ i)
(sym (shallow-comm i n)) ⟩
a ^^ suc n ++ b ^^ (i + suc n) ++ c ^^ (i + suc n)
∎)
aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound i (∣-right (_·_ {s₁} {s₂} s₁∈ s₂∈)) = 0 , (begin
s₁ ++ s₂
≡⟨ cong₂ _++_ (tok-^-sound b i
(drop-♭♯ ⟨ false ^ i ⟩-nullable s₁∈))
(tok-^-sound c i
(drop-♭♯ ⟨ false ^ i ⟩-nullable s₂∈)) ⟩
b ^^ i ++ c ^^ i
≡⟨ cong (λ i → b ^^ i ++ c ^^ i)
(sym (proj₂ NatCS.+-identity i)) ⟩
b ^^ (i + 0) ++ c ^^ (i + 0)
∎)
| {
"alphanum_fraction": 0.5442461071,
"avg_line_length": 32.1097560976,
"ext": "agda",
"hexsha": "0c294ae34d91922b576ed6b760b7ba4ea705319d",
"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": "TotalRecognisers/LeftRecursion/NotOnlyContextFree.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": "TotalRecognisers/LeftRecursion/NotOnlyContextFree.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": "TotalRecognisers/LeftRecursion/NotOnlyContextFree.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": 2153,
"size": 5266
} |
postulate
Nat : Set
Fin : Nat → Set
Finnat : Nat → Set
fortytwo : Nat
finnatic : Finnat fortytwo
_==_ : Finnat fortytwo → Finnat fortytwo → Set
record Fixer : Set where
field fix : ∀ {x} → Finnat x → Finnat fortytwo
open Fixer {{...}}
postulate
Fixidentity : {{_ : Fixer}} → Set
instance
fixidentity : {{fx : Fixer}} {{fxi : Fixidentity}} {f : Finnat fortytwo} → fix f == f
InstanceWrapper : Set
iwrap : InstanceWrapper
instance
IrrFixerInstance : .InstanceWrapper → Fixer
instance
FixerInstance : Fixer
FixerInstance = IrrFixerInstance iwrap
instance
postulate FixidentityInstance : Fixidentity
it : ∀ {a} {A : Set a} {{x : A}} → A
it {{x}} = x
fails : Fixer.fix FixerInstance finnatic == finnatic
fails = fixidentity
works : Fixer.fix FixerInstance finnatic == finnatic
works = fixidentity {{fx = it}}
works₂ : Fixer.fix FixerInstance finnatic == finnatic
works₂ = fixidentity {{fxi = it}}
| {
"alphanum_fraction": 0.6787234043,
"avg_line_length": 22.380952381,
"ext": "agda",
"hexsha": "6b43b6eb3065584a6d82bcab5c360136597d3ed8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue2607b.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue2607b.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue2607b.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-07T10:49:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-07T10:49:57.000Z",
"num_tokens": 302,
"size": 940
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Automatic solvers for equations over lists
------------------------------------------------------------------------
-- See README.Nat for examples of how to use similar solvers
{-# OPTIONS --without-K --safe #-}
module Data.List.Solver where
import Algebra.Solver.Monoid as Solver
open import Data.List.Properties using (++-monoid)
------------------------------------------------------------------------
-- A module for automatically solving propositional equivalences
-- containing _++_
module ++-Solver {a} {A : Set a} =
Solver (++-monoid A) renaming (id to nil)
| {
"alphanum_fraction": 0.491202346,
"avg_line_length": 31,
"ext": "agda",
"hexsha": "5fee0b16e94449e37ec3554d94580b9d63812f4b",
"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/Solver.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/Solver.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/List/Solver.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 117,
"size": 682
} |
{-# OPTIONS --allow-unsolved-metas #-}
module Cat.Categories.Cube where
open import Cat.Prelude
open import Level
open import Data.Bool hiding (T)
open import Data.Sum hiding ([_,_])
open import Data.Unit
open import Data.Empty
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Cat.Category
open import Cat.Category.Functor
-- See chapter 1 for a discussion on how presheaf categories are CwF's.
-- See section 6.8 in Huber's thesis for details on how to implement the
-- categorical version of CTT
open Category hiding (_<<<_)
open Functor
module _ {ℓ ℓ' : Level} (Ns : Set ℓ) where
private
-- Ns is the "namespace"
ℓo = (suc zero ⊔ ℓ)
FiniteDecidableSubset : Set ℓ
FiniteDecidableSubset = Ns → Dec ⊤
isTrue : Bool → Set
isTrue false = ⊥
isTrue true = ⊤
elmsof : FiniteDecidableSubset → Set ℓ
elmsof P = Σ Ns (λ σ → True (P σ)) -- (σ : Ns) → isTrue (P σ)
𝟚 : Set
𝟚 = Bool
module _ (I J : FiniteDecidableSubset) where
Hom' : Set ℓ
Hom' = elmsof I → elmsof J ⊎ 𝟚
isInl : {ℓa ℓb : Level} {A : Set ℓa} {B : Set ℓb} → A ⊎ B → Set
isInl (inj₁ _) = ⊤
isInl (inj₂ _) = ⊥
Def : Set ℓ
Def = (f : Hom') → Σ (elmsof I) (λ i → isInl (f i))
rules : Hom' → Set ℓ
rules f = (i j : elmsof I)
→ case (f i) of λ
{ (inj₁ (fi , _)) → case (f j) of λ
{ (inj₁ (fj , _)) → fi ≡ fj → i ≡ j
; (inj₂ _) → Lift _ ⊤
}
; (inj₂ _) → Lift _ ⊤
}
Hom = Σ Hom' rules
module Raw = RawCategory
-- The category of names and substitutions
Rawℂ : RawCategory ℓ ℓ -- ℓo (lsuc lzero ⊔ ℓo)
Raw.Object Rawℂ = FiniteDecidableSubset
Raw.Arrow Rawℂ = Hom
Raw.identity Rawℂ {o} = inj₁ , λ { (i , ii) (j , jj) eq → Σ≡ eq {!refl!} }
Raw._<<<_ Rawℂ = {!!}
postulate IsCategoryℂ : IsCategory Rawℂ
ℂ : Category ℓ ℓ
raw ℂ = Rawℂ
isCategory ℂ = IsCategoryℂ
| {
"alphanum_fraction": 0.58190091,
"avg_line_length": 25.6883116883,
"ext": "agda",
"hexsha": "f21e55190e4c3b3204bb485ece6d982c17045211",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-06T19:34:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-13T12:44:41.000Z",
"max_forks_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ajnavarro/language-dataset",
"max_forks_repo_path": "data/github.com/fredefox/cat/e7f56486076cc561ceb0529b05725c01d7d1b154/src/Cat/Categories/Cube.agda",
"max_issues_count": 91,
"max_issues_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_issues_repo_issues_event_max_datetime": "2022-03-21T04:17:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-11-11T15:41:26.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ajnavarro/language-dataset",
"max_issues_repo_path": "data/github.com/fredefox/cat/e7f56486076cc561ceb0529b05725c01d7d1b154/src/Cat/Categories/Cube.agda",
"max_line_length": 78,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "34e2980af98ff2ded500619edce3e0907a6e9050",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ajnavarro/language-dataset",
"max_stars_repo_path": "data/github.com/fredefox/cat/e7f56486076cc561ceb0529b05725c01d7d1b154/src/Cat/Categories/Cube.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-11T09:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-08-07T11:54:33.000Z",
"num_tokens": 703,
"size": 1978
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Algebra.Magma
module Cubical.Algebra.Magma.Construct.Opposite {ℓ} (M : Magma ℓ) where
open import Cubical.Foundations.Prelude
open Magma M
_•ᵒᵖ_ : Op₂ Carrier
y •ᵒᵖ x = x • y
Op-isMagma : IsMagma Carrier _•ᵒᵖ_
Op-isMagma = record { is-set = is-set }
Mᵒᵖ : Magma ℓ
Mᵒᵖ = record { isMagma = Op-isMagma }
| {
"alphanum_fraction": 0.7122302158,
"avg_line_length": 19.8571428571,
"ext": "agda",
"hexsha": "75d317fe5b751e2c765b986c467593241a236b35",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Algebra/Magma/Construct/Opposite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Algebra/Magma/Construct/Opposite.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Algebra/Magma/Construct/Opposite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 164,
"size": 417
} |
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Homomorphism.Setoid (Σ : Signature) where
open import Fragment.Algebra.Algebra Σ
open import Fragment.Algebra.Homomorphism.Base Σ
open import Level using (Level; _⊔_)
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
private
variable
a b ℓ₁ ℓ₂ : Level
module _
{A : Algebra {a} {ℓ₁}}
{B : Algebra {b} {ℓ₂}}
where
open Setoid ∥ B ∥/≈
infix 4 _≗_
_≗_ : Rel (A ⟿ B) (a ⊔ ℓ₂)
f ≗ g = ∣ f ∣⃗ ~ ∣ g ∣⃗
where open import Fragment.Setoid.Morphism renaming (_≗_ to _~_)
≗-refl : ∀ {f} → f ≗ f
≗-refl = refl
≗-sym : ∀ {f g} → f ≗ g → g ≗ f
≗-sym f≗g {x} = sym (f≗g {x})
≗-trans : ∀ {f g h} → f ≗ g → g ≗ h → f ≗ h
≗-trans f≗g g≗h {x} = trans (f≗g {x}) (g≗h {x})
≗-isEquivalence : IsEquivalence _≗_
≗-isEquivalence = record { refl = λ {f} → ≗-refl {f}
; sym = λ {f g} → ≗-sym {f} {g}
; trans = λ {f g h} → ≗-trans {f} {g} {h}
}
_⟿_/≗ : Algebra {a} {ℓ₁} → Algebra {b} {ℓ₂} → Setoid _ _
A ⟿ B /≗ = record { Carrier = A ⟿ B
; _≈_ = _≗_
; isEquivalence = ≗-isEquivalence
}
| {
"alphanum_fraction": 0.5007727975,
"avg_line_length": 25.88,
"ext": "agda",
"hexsha": "b1afebc6caea8d328c433760841d6aed8e743fdb",
"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/Setoid.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/Setoid.agda",
"max_line_length": 68,
"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/Setoid.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": 516,
"size": 1294
} |
{-# OPTIONS --guardedness #-}
module Prelude where
open import Class.Equality public
open import Class.Functor public
open import Class.Monad public
open import Class.Monoid public
open import Class.Show public
open import Class.Traversable public
open import Data.Bool hiding (_≟_; _<_; _<?_; _≤_; _≤?_) public
open import Data.Bool.Instance public
open import Data.Char using (Char) public
open import Data.Char.Instance public
open import Data.Empty public
open import Data.Empty.Instance public
open import Data.Fin using (Fin) public
open import Data.List using (List; []; [_]; _∷_; drop; boolFilter; filter; head; reverse; _++_; zipWith; foldl; intersperse; map; null; span; break; allFin; length; mapMaybe; or; and) public
open import Data.List.Exts public
open import Data.List.Instance public
open import Data.Maybe using (Maybe; just; nothing; maybe; from-just; is-just; is-nothing; _<∣>_) public
open import Data.Maybe.Instance public
open import Data.Nat hiding (_+_; _≟_) public
open import Data.Nat.Instance public
open import Data.Product using (_×_; _,_; proj₁; proj₂; ∃-syntax; -,_; Σ; swap; Σ-syntax; map₁; map₂) public
open import Data.Product.Instance public
open import Data.String using (String; unwords; unlines; padRight; _<+>_) public
open import Data.String.Exts public
open import Data.String.Instance public
open import Data.Sum using (_⊎_; inj₁; inj₂; from-inj₁; from-inj₂) public
open import Data.Sum.Instance public
open import Data.Unit.Instance public
open import Data.Unit.Polymorphic using (⊤; tt) public
open import IO using (IO; putStr) public
open import IO.Finite using (getLine) public
open import IO.Exts public
open import IO.Instance public
open import System.Environment public
open import System.Exit public
open import Function public
open import Relation.Nullary using (Dec; yes; no) public
open import Relation.Nullary.Decidable using (⌊_⌋) public
open import Relation.Nullary.Negation public
open import Relation.Unary using (Decidable) public
open import Relation.Binary.PropositionalEquality using (_≡_; refl) public
| {
"alphanum_fraction": 0.7809937289,
"avg_line_length": 42.306122449,
"ext": "agda",
"hexsha": "f4fbb5383a9229a03b0caef12033371fc13b2111",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Prelude.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Prelude.agda",
"max_line_length": 190,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 538,
"size": 2073
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bundles for types of functions
------------------------------------------------------------------------
-- The contents of this file should usually be accessed from `Function`.
-- Note that these bundles differ from those found elsewhere in other
-- library hierarchies as they take Setoids as parameters. This is
-- because a function is of no use without knowing what its domain and
-- codomain is, as well which equalities are being considered over them.
-- One consequence of this is that they are not built from the
-- definitions found in `Function.Structures` as is usually the case in
-- other library hierarchies, as this would duplicate the equality
-- axioms.
{-# OPTIONS --without-K --safe #-}
module Function.Bundles where
import Function.Definitions as FunctionDefinitions
import Function.Structures as FunctionStructures
open import Level using (Level; _⊔_; suc)
open import Data.Product using (proj₁; proj₂)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as ≡
using (_≡_)
open Setoid using (isEquivalence)
private
variable
a b ℓ₁ ℓ₂ : Level
------------------------------------------------------------------------
-- Setoid bundles
module _ (From : Setoid a ℓ₁) (To : Setoid b ℓ₂) where
open Setoid From using () renaming (Carrier to A; _≈_ to _≈₁_)
open Setoid To using () renaming (Carrier to B; _≈_ to _≈₂_)
open FunctionDefinitions _≈₁_ _≈₂_
open FunctionStructures _≈₁_ _≈₂_
record Injection : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
cong : f Preserves _≈₁_ ⟶ _≈₂_
injective : Injective f
isCongruent : IsCongruent f
isCongruent = record
{ cong = cong
; isEquivalence₁ = isEquivalence From
; isEquivalence₂ = isEquivalence To
}
open IsCongruent isCongruent public using (module Eq₁; module Eq₂)
isInjection : IsInjection f
isInjection = record
{ isCongruent = isCongruent
; injective = injective
}
record Surjection : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
cong : f Preserves _≈₁_ ⟶ _≈₂_
surjective : Surjective f
isCongruent : IsCongruent f
isCongruent = record
{ cong = cong
; isEquivalence₁ = isEquivalence From
; isEquivalence₂ = isEquivalence To
}
open IsCongruent isCongruent public using (module Eq₁; module Eq₂)
isSurjection : IsSurjection f
isSurjection = record
{ isCongruent = isCongruent
; surjective = surjective
}
record Bijection : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
cong : f Preserves _≈₁_ ⟶ _≈₂_
bijective : Bijective f
injective : Injective f
injective = proj₁ bijective
surjective : Surjective f
surjective = proj₂ bijective
injection : Injection
injection = record
{ cong = cong
; injective = injective
}
surjection : Surjection
surjection = record
{ cong = cong
; surjective = surjective
}
open Injection injection public using (isInjection)
open Surjection surjection public using (isSurjection)
isBijection : IsBijection f
isBijection = record
{ isInjection = isInjection
; surjective = surjective
}
open IsBijection isBijection public using (module Eq₁; module Eq₂)
record Equivalence : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
g : B → A
cong₁ : f Preserves _≈₁_ ⟶ _≈₂_
cong₂ : g Preserves _≈₂_ ⟶ _≈₁_
record LeftInverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
g : B → A
cong₁ : f Preserves _≈₁_ ⟶ _≈₂_
cong₂ : g Preserves _≈₂_ ⟶ _≈₁_
inverseˡ : Inverseˡ f g
isCongruent : IsCongruent f
isCongruent = record
{ cong = cong₁
; isEquivalence₁ = isEquivalence From
; isEquivalence₂ = isEquivalence To
}
open IsCongruent isCongruent public using (module Eq₁; module Eq₂)
isLeftInverse : IsLeftInverse f g
isLeftInverse = record
{ isCongruent = isCongruent
; cong₂ = cong₂
; inverseˡ = inverseˡ
}
equivalence : Equivalence
equivalence = record
{ cong₁ = cong₁
; cong₂ = cong₂
}
record RightInverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
g : B → A
cong₁ : f Preserves _≈₁_ ⟶ _≈₂_
cong₂ : g Preserves _≈₂_ ⟶ _≈₁_
inverseʳ : Inverseʳ f g
isCongruent : IsCongruent f
isCongruent = record
{ cong = cong₁
; isEquivalence₁ = isEquivalence From
; isEquivalence₂ = isEquivalence To
}
isRightInverse : IsRightInverse f g
isRightInverse = record
{ isCongruent = isCongruent
; cong₂ = cong₂
; inverseʳ = inverseʳ
}
equivalence : Equivalence
equivalence = record
{ cong₁ = cong₁
; cong₂ = cong₂
}
record BiEquivalence : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
g₁ : B → A
g₂ : B → A
cong₁ : f Preserves _≈₁_ ⟶ _≈₂_
cong₂ : g₁ Preserves _≈₂_ ⟶ _≈₁_
cong₃ : g₂ Preserves _≈₂_ ⟶ _≈₁_
record BiInverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
g₁ : B → A
g₂ : B → A
cong₁ : f Preserves _≈₁_ ⟶ _≈₂_
cong₂ : g₁ Preserves _≈₂_ ⟶ _≈₁_
cong₃ : g₂ Preserves _≈₂_ ⟶ _≈₁_
inverseˡ : Inverseˡ f g₁
inverseʳ : Inverseʳ f g₂
f-isCongruent : IsCongruent f
f-isCongruent = record
{ cong = cong₁
; isEquivalence₁ = isEquivalence From
; isEquivalence₂ = isEquivalence To
}
isBiInverse : IsBiInverse f g₁ g₂
isBiInverse = record
{ f-isCongruent = f-isCongruent
; cong₂ = cong₂
; inverseˡ = inverseˡ
; cong₃ = cong₃
; inverseʳ = inverseʳ
}
biEquivalence : BiEquivalence
biEquivalence = record
{ cong₁ = cong₁
; cong₂ = cong₂
; cong₃ = cong₃
}
record Inverse : Set (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂) where
field
f : A → B
f⁻¹ : B → A
cong₁ : f Preserves _≈₁_ ⟶ _≈₂_
cong₂ : f⁻¹ Preserves _≈₂_ ⟶ _≈₁_
inverse : Inverseᵇ f f⁻¹
inverseˡ : Inverseˡ f f⁻¹
inverseˡ = proj₁ inverse
inverseʳ : Inverseʳ f f⁻¹
inverseʳ = proj₂ inverse
leftInverse : LeftInverse
leftInverse = record
{ cong₁ = cong₁
; cong₂ = cong₂
; inverseˡ = inverseˡ
}
rightInverse : RightInverse
rightInverse = record
{ cong₁ = cong₁
; cong₂ = cong₂
; inverseʳ = inverseʳ
}
open LeftInverse leftInverse public using (isLeftInverse)
open RightInverse rightInverse public using (isRightInverse)
isInverse : IsInverse f f⁻¹
isInverse = record
{ isLeftInverse = isLeftInverse
; inverseʳ = inverseʳ
}
open IsInverse isInverse public using (module Eq₁; module Eq₂)
------------------------------------------------------------------------
-- Bundles specialised for propositional equality
infix 3 _↣_ _↠_ _⤖_ _⇔_ _↩_ _↪_ _↩↪_ _↔_
_↣_ : Set a → Set b → Set _
A ↣ B = Injection (≡.setoid A) (≡.setoid B)
_↠_ : Set a → Set b → Set _
A ↠ B = Surjection (≡.setoid A) (≡.setoid B)
_⤖_ : Set a → Set b → Set _
A ⤖ B = Bijection (≡.setoid A) (≡.setoid B)
_⇔_ : Set a → Set b → Set _
A ⇔ B = Equivalence (≡.setoid A) (≡.setoid B)
_↩_ : Set a → Set b → Set _
A ↩ B = LeftInverse (≡.setoid A) (≡.setoid B)
_↪_ : Set a → Set b → Set _
A ↪ B = RightInverse (≡.setoid A) (≡.setoid B)
_↩↪_ : Set a → Set b → Set _
A ↩↪ B = BiInverse (≡.setoid A) (≡.setoid B)
_↔_ : Set a → Set b → Set _
A ↔ B = Inverse (≡.setoid A) (≡.setoid B)
-- We now define some constructors for the above that
-- automatically provide the required congruency proofs.
module _ {A : Set a} {B : Set b} where
open FunctionDefinitions {A = A} {B} _≡_ _≡_
mk↣ : ∀ {f : A → B} → Injective f → A ↣ B
mk↣ {f} inj = record
{ f = f
; cong = ≡.cong f
; injective = inj
}
mk↠ : ∀ {f : A → B} → Surjective f → A ↠ B
mk↠ {f} surj = record
{ f = f
; cong = ≡.cong f
; surjective = surj
}
mk⤖ : ∀ {f : A → B} → Bijective f → A ⤖ B
mk⤖ {f} bij = record
{ f = f
; cong = ≡.cong f
; bijective = bij
}
mk⇔ : ∀ (f : A → B) (g : B → A) → A ⇔ B
mk⇔ f g = record
{ f = f
; g = g
; cong₁ = ≡.cong f
; cong₂ = ≡.cong g
}
mk↩ : ∀ {f : A → B} {g : B → A} → Inverseˡ f g → A ↩ B
mk↩ {f} {g} invˡ = record
{ f = f
; g = g
; cong₁ = ≡.cong f
; cong₂ = ≡.cong g
; inverseˡ = invˡ
}
mk↪ : ∀ {f : A → B} {g : B → A} → Inverseʳ f g → A ↪ B
mk↪ {f} {g} invʳ = record
{ f = f
; g = g
; cong₁ = ≡.cong f
; cong₂ = ≡.cong g
; inverseʳ = invʳ
}
mk↩↪ : ∀ {f : A → B} {g₁ : B → A} {g₂ : B → A}
→ Inverseˡ f g₁ → Inverseʳ f g₂ → A ↩↪ B
mk↩↪ {f} {g₁} {g₂} invˡ invʳ = record
{ f = f
; g₁ = g₁
; g₂ = g₂
; cong₁ = ≡.cong f
; cong₂ = ≡.cong g₁
; cong₃ = ≡.cong g₂
; inverseˡ = invˡ
; inverseʳ = invʳ
}
mk↔ : ∀ {f : A → B} {f⁻¹ : B → A} → Inverseᵇ f f⁻¹ → A ↔ B
mk↔ {f} {f⁻¹} inv = record
{ f = f
; f⁻¹ = f⁻¹
; cong₁ = ≡.cong f
; cong₂ = ≡.cong f⁻¹
; inverse = inv
}
| {
"alphanum_fraction": 0.5409142503,
"avg_line_length": 25.5026315789,
"ext": "agda",
"hexsha": "a16fc2cb11b1b30403cb97d9e1b8b326a63cd0f0",
"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/Function/Bundles.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/Function/Bundles.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/Function/Bundles.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": 3425,
"size": 9691
} |
module NF.Product where
open import NF
open import Data.Product
open import Relation.Binary.PropositionalEquality
instance
nf, : {A : Set}{B : A -> Set}{a : A}{b : B a}{{nfa : NF a}}{{nfb : NF b}} -> NF {Σ A B} (a , b)
Sing.unpack (NF.!! (nf, {B = B} {a = a} {b = b} {{nfa}})) = nf a , subst B (sym nf≡) (nf b)
Sing.eq (NF.!! (nf, {{nfa}} {{nfb}})) rewrite nf≡ {{nfa}} | nf≡ {{nfb}} = refl
{-# INLINE nf, #-} | {
"alphanum_fraction": 0.5393794749,
"avg_line_length": 34.9166666667,
"ext": "agda",
"hexsha": "9ca60645427a6c2ee4ed9fa114d5093ed42f09df",
"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": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yanok/normalize-via-instances",
"max_forks_repo_path": "src/NF/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"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": "yanok/normalize-via-instances",
"max_issues_repo_path": "src/NF/Product.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yanok/normalize-via-instances",
"max_stars_repo_path": "src/NF/Product.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 167,
"size": 419
} |
module Tactic.Nat.Coprime.Decide where
open import Prelude
open import Prelude.Equality.Unsafe
open import Prelude.List.Relations.Any
open import Prelude.List.Relations.All
open import Prelude.List.Relations.Properties
open import Numeric.Nat
open import Tactic.Nat.Coprime.Problem
private
infix 4 _isIn_
_isIn_ : Nat → Exp → Bool
x isIn atom y = isYes (x == y)
x isIn a ⊗ b = x isIn a || x isIn b
proves : Nat → Nat → Formula → Bool
proves x y (a ⋈ b) = x isIn a && y isIn b || x isIn b && y isIn a
hypothesis : Nat → Nat → List Formula → Bool
hypothesis x y Γ = any? (proves x y) Γ
canProve' : List Formula → Exp → Exp → Bool
canProve' Γ (atom x) (atom y) = hypothesis x y Γ
canProve' Γ a (b ⊗ c) = canProve' Γ a b && canProve' Γ a c
canProve' Γ (a ⊗ b) c = canProve' Γ a c && canProve' Γ b c
canProve : Problem → Bool
canProve (Γ ⊨ a ⋈ b) = canProve' Γ a b
-- Soundness proof --
private
invert-&&₁ : ∀ {a b} → (a && b) ≡ true → a ≡ true
invert-&&₁ {false} ()
invert-&&₁ {true} prf = refl
invert-&&₂ : ∀ {a b} → (a && b) ≡ true → b ≡ true
invert-&&₂ {false} ()
invert-&&₂ {true} prf = prf
invert-|| : ∀ a {b} → (a || b) ≡ true → Either (a ≡ true) (b ≡ true)
invert-|| false prf = right prf
invert-|| true prf = left prf
sound-eq : (a b : Nat) → isYes (a == b) ≡ true → a ≡ b
sound-eq a b ok with a == b
sound-eq a b ok | yes a=b = a=b
sound-eq a b () | no _
sound-any : ∀ {A : Set} (p : A → Bool) xs → any? p xs ≡ true → Any (λ x → p x ≡ true) xs
sound-any p [] ()
sound-any p (x ∷ xs) ok with p x | graphAt p x
... | false | _ = suc (sound-any p xs ok)
... | true | ingraph eq = zero eq
private
syntax WithHyps Γ (λ ρ → A) = ρ ∈ Γ ⇒ A
WithHyps : List Formula → (Env → Set) → Set
WithHyps Γ F = ∀ ρ → All (⟦_⟧f ρ) Γ → F ρ
sound-isIn' : ∀ x y a b → (x isIn a) ≡ true → (y isIn b) ≡ true → ∀ ρ → ⟦ a ⋈ b ⟧f ρ → Coprime (ρ x) (ρ y)
sound-isIn-⊗-l : ∀ x y a b c → (x isIn a) ≡ true → (y isIn b ⊗ c) ≡ true →
∀ ρ → ⟦ a ⋈ b ⊗ c ⟧f ρ → Coprime (ρ x) (ρ y)
sound-isIn-⊗-l x y a b c oka okbc ρ H =
case invert-|| (y isIn b) okbc of λ where
(left okb) → sound-isIn' x y a b oka okb ρ (mul-coprime-l (⟦ a ⟧e ρ) (⟦ b ⟧e ρ) (⟦ c ⟧e ρ) H)
(right okc) → sound-isIn' x y a c oka okc ρ (mul-coprime-r (⟦ a ⟧e ρ) (⟦ b ⟧e ρ) (⟦ c ⟧e ρ) H)
sound-isIn' x y (atom x') (atom y') oka okb ρ H =
case₂ sound-eq x x' oka , sound-eq y y' okb of λ where
refl refl → H
sound-isIn' x y a@(atom _) (b ⊗ c) oka okbc ρ H = sound-isIn-⊗-l x y a b c oka okbc ρ H
sound-isIn' x y a@(_ ⊗ _) (b ⊗ c) oka okbc ρ H = sound-isIn-⊗-l x y a b c oka okbc ρ H
sound-isIn' x y (a ⊗ b) c@(atom _) okab okc ρ H =
let nf = λ e → ⟦ e ⟧e ρ
H' = coprime-sym _ (nf c) H
in
case invert-|| (x isIn a) okab of λ where
(left oka) → sound-isIn' x y a c oka okc ρ
(coprime-sym (nf c) _
(mul-coprime-l (nf c) (nf a) (nf b) H'))
(right okb) → sound-isIn' x y b c okb okc ρ
(coprime-sym (nf c) _
(mul-coprime-r (nf c) (nf a) _ H'))
sound-isIn : ∀ x y a b → (x isIn a && y isIn b) ≡ true → ∀ ρ → ⟦ a ⋈ b ⟧f ρ → Coprime (ρ x) (ρ y)
sound-isIn x y a b ok = sound-isIn' x y a b (invert-&&₁ ok) (invert-&&₂ ok)
sound-proves : ∀ x y φ → proves x y φ ≡ true → ∀ ρ → ⟦ φ ⟧f ρ → Coprime (ρ x) (ρ y)
sound-proves x y (a ⋈ b) ok ρ H =
case invert-|| (x isIn a && y isIn b) ok of λ where
(left ok) → sound-isIn x y a b ok ρ H
(right ok) → sound-isIn x y b a ok ρ (coprime-sym (⟦ a ⟧e ρ) _ H)
sound-hyp : ∀ x y Γ → hypothesis x y Γ ≡ true → ρ ∈ Γ ⇒ Coprime (ρ x) (ρ y)
sound-hyp x y Γ ok ρ Ξ =
case lookupAny Ξ (sound-any (proves x y) Γ ok) of λ where
(φ , H , okφ) → sound-proves x y φ okφ ρ H
sound' : ∀ Γ a b → canProve' Γ a b ≡ true → ρ ∈ Γ ⇒ ⟦ a ⋈ b ⟧f ρ
sound-⊗-r : ∀ Γ a b c → (canProve' Γ a b && canProve' Γ a c) ≡ true → ρ ∈ Γ ⇒ ⟦ a ⋈ b ⊗ c ⟧f ρ
sound-⊗-r Γ a b c ok ρ Ξ =
let a⋈b : ⟦ a ⋈ b ⟧f ρ
a⋈b = sound' Γ a b (invert-&&₁ ok) ρ Ξ
a⋈c : ⟦ a ⋈ c ⟧f ρ
a⋈c = sound' Γ a c (invert-&&₂ ok) ρ Ξ
in coprime-mul-r (⟦ a ⟧e ρ) _ _ a⋈b a⋈c
sound' Γ (atom x) (atom y) ok ρ Ξ = sound-hyp x y Γ ok ρ Ξ
sound' Γ a@(atom _) (b ⊗ c) ok ρ Ξ = sound-⊗-r Γ a b c ok ρ Ξ
sound' Γ a@(_ ⊗ _) (b ⊗ c) ok ρ Ξ = sound-⊗-r Γ a b c ok ρ Ξ
sound' Γ (a ⊗ b) c@(atom _) ok ρ Ξ =
let a⋈c : ⟦ a ⋈ c ⟧f ρ
a⋈c = sound' Γ a c (invert-&&₁ ok) ρ Ξ
b⋈c : ⟦ b ⋈ c ⟧f ρ
b⋈c = sound' Γ b c (invert-&&₂ ok) ρ Ξ
in coprime-mul-l (⟦ a ⟧e ρ) _ _ a⋈c b⋈c
sound : ∀ Q → canProve Q ≡ true → ∀ ρ → ⟦ Q ⟧p ρ
sound Q@(Γ ⊨ a ⋈ b) ok ρ = curryProblem Q ρ (sound' Γ a b ok ρ)
| {
"alphanum_fraction": 0.5177898702,
"avg_line_length": 38.224,
"ext": "agda",
"hexsha": "768ab8d0cdb4ec2db10f3c4fc2025665e5b53e6c",
"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": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Coprime/Decide.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"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": "t-more/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Coprime/Decide.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Coprime/Decide.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2166,
"size": 4778
} |
module Network.Primitive where
open import Data.Nat
open import Data.String
open import Data.Unit
open import Foreign.Haskell
open import IO.Primitive
postulate
withSocketsDo : ∀ {a} {A : Set a} → IO A → IO A
connectTo : String → Integer → IO Handle
{-# IMPORT Network #-}
{-# IMPORT Text.Read #-}
{-# COMPILED withSocketsDo (\_ _ -> Network.withSocketsDo) #-}
{-# COMPILED connectTo (\s i -> Network.connectTo s $ Network.PortNumber (fromIntegral i)) #-}
| {
"alphanum_fraction": 0.7002141328,
"avg_line_length": 27.4705882353,
"ext": "agda",
"hexsha": "5472bc68bbc46436bf770b2d598770d7825568ea",
"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": "06defd709b073f951723d7e717fcf96ee30567eb",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ilya-fiveisky/agda-network",
"max_forks_repo_path": "src/Network/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "06defd709b073f951723d7e717fcf96ee30567eb",
"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": "ilya-fiveisky/agda-network",
"max_issues_repo_path": "src/Network/Primitive.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "06defd709b073f951723d7e717fcf96ee30567eb",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ilya-fiveisky/agda-network",
"max_stars_repo_path": "src/Network/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 124,
"size": 467
} |
open import Nat
open import Prelude
open import List
open import contexts
open import core
module results-checks where
Coerce-preservation : ∀{Δ Σ' r v τ} →
Δ , Σ' ⊢ r ·: τ →
Coerce r := v →
Σ' ⊢ v ::ⱽ τ
Coerce-preservation (TAFix x x₁) ()
Coerce-preservation (TAApp ta-r ta-r₁) ()
Coerce-preservation TAUnit CoerceUnit = TSVUnit
Coerce-preservation (TAPair ta-r1 ta-r2) (CoercePair c-r1 c-r2)
= TSVPair (Coerce-preservation ta-r1 c-r1) (Coerce-preservation ta-r2 c-r2)
Coerce-preservation (TAFst ta-r) ()
Coerce-preservation (TASnd ta-r) ()
Coerce-preservation (TACtor h1 h2 ta-r) (CoerceCtor c-r)
= TSVCtor h1 h2 (Coerce-preservation ta-r c-r)
Coerce-preservation (TACase x x₁ ta-r x₂ x₃) ()
Coerce-preservation (TAHole x x₁) ()
{- TODO : We should revive this - it's a good sanity check.
Of course, we have to decide what version of "complete" we want to use
for results
-- all complete finals (that type-check) are values
mutual
complete-finals-values : ∀{Δ Σ' r τ} →
Δ , Σ' ⊢ r ·: τ →
r rcomplete →
r final →
r value
complete-finals-values (TALam Γ⊢E _) (RCLam E-cmp e-cmp) (FLam E-fin) =
VLam (env-complete-final-values Γ⊢E E-cmp E-fin) e-cmp
complete-finals-values (TAFix Γ⊢E _) (RCFix E-cmp e-cmp) (FFix E-fin) =
VFix (env-complete-final-values Γ⊢E E-cmp E-fin) e-cmp
complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2)
with complete-finals-values ta1 cmp1 fin1
complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VLam _ _ = abort (h1 refl)
complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VFix _ _ = abort (h2 refl)
complete-finals-values (TAApp () ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VTpl _
complete-finals-values (TAApp () ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VCon _
complete-finals-values (TAApp ta1 ta2) (RCAp cmp1 cmp2) (FAp fin1 fin2 h1 h2) | VPF _ = {!!}
complete-finals-values (TATpl ∥rs⊫=∥τs∥ ta) (RCTpl h1) (FTpl h2) =
VTpl λ {i} i<∥rs∥ → complete-finals-values (ta i<∥rs∥ (tr (λ y → i < y) ∥rs⊫=∥τs∥ i<∥rs∥)) (h1 i<∥rs∥) (h2 i<∥rs∥)
complete-finals-values (TAGet i<∥τs∥ ta) (RCGet cmp) (FGet fin x) = {!!}
complete-finals-values (TACtor _ _ ta) (RCCtor cmp) (FCon fin) =
VCon (complete-finals-values ta cmp fin)
complete-finals-values (TACase x x₁ ta x₂ x₃) (RCCase x₄ cmp x₅) (FCase fin x₆ x₇) = {!!}
complete-finals-values (TAHole _ _) () fin
complete-finals-values (TAPF x) (RCPF x₁) (FPF x₂) = {!!}
env-complete-final-values : ∀{Δ Σ' Γ E} →
Δ , Σ' , Γ ⊢ E →
E env-complete →
E env-final →
E env-values
env-complete-final-values ta (ENVC E-cmp) (EF E-fin) =
EF (λ rx∈E → complete-finals-values (π2 (π2 (env-all-E ta rx∈E))) (E-cmp rx∈E) (E-fin rx∈E))
-}
| {
"alphanum_fraction": 0.5772969583,
"avg_line_length": 50.619047619,
"ext": "agda",
"hexsha": "67d27ca86841f9ec697f44b4586a608b40a6e638",
"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": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnat-myth-",
"max_forks_repo_path": "results-checks.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"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": "hazelgrove/hazelnat-myth-",
"max_issues_repo_path": "results-checks.agda",
"max_line_length": 120,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnat-myth-",
"max_stars_repo_path": "results-checks.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z",
"num_tokens": 1122,
"size": 3189
} |
module Nats.Add.Invert where
open import Equality
open import Nats
open import Nats.Add.Comm
open import Function
------------------------------------------------------------------------
-- internal stuffs
private
lemma′ : ∀ a b → (suc a ≡ suc b) → (a ≡ b)
lemma′ _ _ refl = refl
lemma : ∀ a b → (suc (a + suc a) ≡ suc (b + suc b)) → (a + a ≡ b + b)
lemma a b
rewrite nat-add-comm a $ suc a
| nat-add-comm b $ suc b
= lemma′ (a + a) (b + b) ∘ lemma′ (suc $ a + a) (suc $ b + b)
+-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b
+-invert zero zero ev = refl
+-invert zero (suc b) ()
+-invert (suc a) zero ()
+-invert (suc a) (suc b) = cong suc ∘ +-invert a b ∘ lemma a b
------------------------------------------------------------------------
-- public aliases
nat-add-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b
nat-add-invert = +-invert
nat-add-invert-1 : ∀ a b → (suc a ≡ suc b) → (a ≡ b)
nat-add-invert-1 = lemma′
| {
"alphanum_fraction": 0.452653486,
"avg_line_length": 26.6944444444,
"ext": "agda",
"hexsha": "8a0cfb7f342fcd1675a8f825847c77e3ad1ace32",
"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": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Nats/Add/Invert.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"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": "ice1k/Theorems",
"max_issues_repo_path": "src/Nats/Add/Invert.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Nats/Add/Invert.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 322,
"size": 961
} |
-- Minimal propositional logic, vector-based de Bruijn approach, initial encoding
module Vi.Mp where
open import Lib using (Nat; suc; _+_; Fin; fin; Vec; _,_; proj; VMem; mem)
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Nat -> Set
Cx n = Vec Ty n
isTrue : forall {tn} -> Ty -> Fin tn -> Cx tn -> Set
isTrue a i tc = VMem a i tc
-- Terms
module Mp where
infixl 1 _$_
infixr 0 lam=>_
data Tm {tn} (tc : Cx tn) : Ty -> Set where
var : forall {a i} -> isTrue a i tc -> Tm tc a
lam=>_ : forall {a b} -> Tm (tc , a) b -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b)
fst : forall {a b} -> Tm tc (a && b) -> Tm tc a
snd : forall {a b} -> Tm tc (a && b) -> Tm tc b
left : forall {a b} -> Tm tc a -> Tm tc (a || b)
right : forall {a b} -> Tm tc b -> Tm tc (a || b)
case' : forall {a b c} -> Tm tc (a || b) -> Tm (tc , a) c -> Tm (tc , b) c -> Tm tc c
syntax pair' x y = [ x , y ]
syntax case' xy x y = case xy => x => y
v : forall {tn} (k : Nat) {tc : Cx (suc (k + tn))} -> Tm tc (proj tc (fin k))
v i = var (mem i)
Thm : Ty -> Set
Thm a = forall {tn} {tc : Cx tn} -> Tm tc a
open Mp public
-- Example theorems
c1 : forall {a b} -> Thm (a && b <=> b && a)
c1 =
[ lam=> [ snd (v 0) , fst (v 0) ]
, lam=> [ snd (v 0) , fst (v 0) ]
]
c2 : forall {a b} -> Thm (a || b <=> b || a)
c2 =
[ lam=>
(case v 0
=> right (v 0)
=> left (v 0))
, lam=>
(case v 0
=> right (v 0)
=> left (v 0))
]
i1 : forall {a} -> Thm (a && a <=> a)
i1 =
[ lam=> fst (v 0)
, lam=> [ v 0 , v 0 ]
]
i2 : forall {a} -> Thm (a || a <=> a)
i2 =
[ lam=>
(case v 0
=> v 0
=> v 0)
, lam=> left (v 0)
]
l3 : forall {a} -> Thm ((a => a) <=> TRUE)
l3 =
[ lam=> lam=> v 0
, lam=> lam=> v 0
]
l1 : forall {a b c} -> Thm (a && (b && c) <=> (a && b) && c)
l1 =
[ lam=>
[ [ fst (v 0) , fst (snd (v 0)) ]
, snd (snd (v 0))
]
, lam=>
[ fst (fst (v 0))
, [ snd (fst (v 0)) , snd (v 0) ]
]
]
l2 : forall {a} -> Thm (a && TRUE <=> a)
l2 =
[ lam=> fst (v 0)
, lam=> [ v 0 , lam=> v 0 ]
]
l4 : forall {a b c} -> Thm (a && (b || c) <=> (a && b) || (a && c))
l4 =
[ lam=>
(case snd (v 0)
=> left [ fst (v 1) , v 0 ]
=> right [ fst (v 1) , v 0 ])
, lam=>
(case v 0
=> [ fst (v 0) , left (snd (v 0)) ]
=> [ fst (v 0) , right (snd (v 0)) ])
]
l6 : forall {a b c} -> Thm (a || (b && c) <=> (a || b) && (a || c))
l6 =
[ lam=>
(case v 0
=> [ left (v 0) , left (v 0) ]
=> [ right (fst (v 0)) , right (snd (v 0)) ])
, lam=>
(case fst (v 0)
=> left (v 0)
=>
case snd (v 1)
=> left (v 0)
=> right [ v 1 , v 0 ])
]
l7 : forall {a} -> Thm (a || TRUE <=> TRUE)
l7 =
[ lam=> lam=> v 0
, lam=> right (v 0)
]
l9 : forall {a b c} -> Thm (a || (b || c) <=> (a || b) || c)
l9 =
[ lam=>
(case v 0
=> left (left (v 0))
=>
case v 0
=> left (right (v 0))
=> right (v 0))
, lam=>
(case v 0
=>
case v 0
=> left (v 0)
=> right (left (v 0))
=> right (right (v 0)))
]
l11 : forall {a b c} -> Thm ((a => (b && c)) <=> (a => b) && (a => c))
l11 =
[ lam=>
[ lam=> fst (v 1 $ v 0)
, lam=> snd (v 1 $ v 0)
]
, lam=>
lam=> [ fst (v 1) $ v 0 , snd (v 1) $ v 0 ]
]
l12 : forall {a} -> Thm ((a => TRUE) <=> TRUE)
l12 =
[ lam=> lam=> v 0
, lam=> lam=> v 1
]
l13 : forall {a b c} -> Thm ((a => (b => c)) <=> ((a && b) => c))
l13 =
[ lam=>
lam=> v 1 $ fst (v 0) $ snd (v 0)
, lam=>
lam=>
lam=> v 2 $ [ v 1 , v 0 ]
]
l16 : forall {a b c} -> Thm (((a && b) => c) <=> (a => (b => c)))
l16 =
[ lam=>
lam=>
lam=> v 2 $ [ v 1 , v 0 ]
, lam=>
lam=> v 1 $ fst (v 0) $ snd (v 0)
]
l17 : forall {a} -> Thm ((TRUE => a) <=> a)
l17 =
[ lam=> v 0 $ (lam=> v 0)
, lam=> lam=> v 1
]
l19 : forall {a b c} -> Thm (((a || b) => c) <=> (a => c) && (b => c))
l19 =
[ lam=>
[ lam=> v 1 $ left (v 0)
, lam=> v 1 $ right (v 0)
]
, lam=>
lam=>
(case v 0
=> fst (v 2) $ (v 0)
=> snd (v 2) $ (v 0))
]
| {
"alphanum_fraction": 0.3715577476,
"avg_line_length": 21.2489082969,
"ext": "agda",
"hexsha": "08fbda97d4013fb034c90dd5ddea0c768526e8d2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Vi/Mp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Vi/Mp.agda",
"max_line_length": 90,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Vi/Mp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 2029,
"size": 4866
} |
module Auto-EqualityReasoning where
-- equality reasoning, computation and induction
open import Auto.Prelude
module AdditionCommutative where
lemma : ∀ n m → (n + succ m) ≡ succ (n + m)
lemma n m = {!-c!} -- h0
{-
lemma zero m = refl
lemma (succ x) m = cong succ (lemma x m)
-}
lemma' : ∀ n m → (n + succ m) ≡ succ (n + m)
lemma' zero m = refl
lemma' (succ n) m = cong succ (lemma' n m)
addcommut : ∀ n m → (n + m) ≡ (m + n)
addcommut n m = {!-c lemma'!} -- h1
{-
addcommut zero zero = refl
addcommut zero (succ x) = sym (cong succ (addcommut x zero)) -- solution does not pass termination check
addcommut (succ x) m = begin (succ (x + m) ≡⟨ cong succ (addcommut x m) ⟩ (succ (m + x) ≡⟨ sym (lemma' m x) ⟩ ((m + succ x) ∎)))
-}
| {
"alphanum_fraction": 0.5997340426,
"avg_line_length": 25.9310344828,
"ext": "agda",
"hexsha": "dc0f12b07f4201a08753371c60465b549eb80696",
"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/Auto-EqualityReasoning.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/Auto-EqualityReasoning.agda",
"max_line_length": 129,
"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/Auto-EqualityReasoning.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": 272,
"size": 752
} |
open import Category
module Iso (ℂ : Cat) where
private open module C = Cat (η-Cat ℂ)
data _≅_ (A B : Obj) : Set where
iso : (i : A ─→ B)(j : B ─→ A) ->
i ∘ j == id -> j ∘ i == id ->
A ≅ B
| {
"alphanum_fraction": 0.5050505051,
"avg_line_length": 15.2307692308,
"ext": "agda",
"hexsha": "a26ef3e41c623d4b9b49f6a3037a08bea2ac6a3f",
"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": "examples/outdated-and-incorrect/cat/Iso.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/cat/Iso.agda",
"max_line_length": 37,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/cat/Iso.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": 83,
"size": 198
} |
module Tactic.Nat.Refute where
open import Prelude
open import Builtin.Reflection
open import Tactic.Reflection.Quote
open import Tactic.Reflection
open import Tactic.Nat.Reflect
open import Tactic.Nat.NF
open import Tactic.Nat.Exp
open import Tactic.Nat.Auto
open import Tactic.Nat.Auto.Lemmas
open import Tactic.Nat.Simpl.Lemmas
open import Tactic.Nat.Simpl
data Impossible : Set where
invalidEquation : ⊤
invalidEquation = _
refutation : ∀ {a} {A : Set a} {Atom : Set} {{_ : Eq Atom}} {{_ : Ord Atom}} eq (ρ : Env Atom) →
¬ CancelEq eq ρ → ExpEq eq ρ → A
refutation exp ρ !eq eq = ⊥-elim (!eq (complicateEq exp ρ eq))
refute-tactic : Term → TC Term
refute-tactic prf =
inferType prf >>= λ a →
caseM termToEq a of λ
{ nothing → pure $ failedProof (quote invalidEquation) a
; (just (eqn , Γ)) → pure $
def (quote refutation)
$ vArg (` eqn)
∷ vArg (quotedEnv Γ)
∷ vArg absurd-lam
∷ vArg prf ∷ []
}
macro
refute : Term → Tactic
refute prf hole = unify hole =<< refute-tactic prf
| {
"alphanum_fraction": 0.6707897241,
"avg_line_length": 25.0238095238,
"ext": "agda",
"hexsha": "26616ce0cd3a3205b3be0efde8c5f3d922e85798",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Refute.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Refute.agda",
"max_line_length": 96,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Refute.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 335,
"size": 1051
} |
------------------------------------------------------------------------
-- Up-to techniques for CCS
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.Up-to.CCS {ℓ} {Name : Type ℓ} where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Bijection equality-with-J using (_↔_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import Bisimilarity.CCS
import Bisimilarity.Equational-reasoning-instances
open import Equational-reasoning
open import Indexed-container
open import Labelled-transition-system.CCS Name
open import Relation
open import Bisimilarity CCS
open import Bisimilarity.Step CCS _[_]⟶_ using (Step; Step↔StepC)
open import Bisimilarity.Up-to CCS
-- Up to context for a very simple kind of context.
Up-to-! : Trans₂ ℓ (Proc ∞)
Up-to-! R (P , Q) =
∃ λ P′ → ∃ λ Q′ → P ≡ ! P′ × R (P′ , Q′) × ! Q′ ≡ Q
-- This transformer is size-preserving.
up-to-!-size-preserving : Size-preserving Up-to-!
up-to-!-size-preserving R⊆∼i (P′ , Q′ , refl , P′RQ′ , refl) =
!-cong (R⊆∼i P′RQ′)
-- Up to context for CCS (for polyadic contexts).
Up-to-context : Trans₂ ℓ (Proc ∞)
Up-to-context R (P , Q) =
∃ λ n →
∃ λ (C : Context ∞ n) →
∃ λ Ps →
∃ λ Qs →
Equal ∞ P (C [ Ps ])
×
Equal ∞ Q (C [ Qs ])
×
∀ x → R (Ps x , Qs x)
-- Up to context is monotone.
up-to-context-monotone : Monotone Up-to-context
up-to-context-monotone R⊆S =
Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id $ Σ-map id
(R⊆S ∘_)
-- Up to context is size-preserving.
up-to-context-size-preserving : Size-preserving Up-to-context
up-to-context-size-preserving
R⊆∼i {P , Q} (_ , C , Ps , Qs , eq₁ , eq₂ , Ps∼Qs) =
P ∼⟨ ≡→∼ eq₁ ⟩
C [ Ps ] ∼⟨ C [ R⊆∼i ∘ Ps∼Qs ]-cong ⟩
C [ Qs ] ∼⟨ symmetric (≡→∼ eq₂) ⟩■
Q
-- Note that up to context is not compatible (assuming that Name is
-- inhabited).
--
-- This counterexample is a minor variant of one due to Pous and
-- Sangiorgi, who state that up to context would have been compatible
-- if the Step function had been defined in a slightly different way
-- (see Remark 6.4.2 in "Enhancements of the bisimulation proof
-- method").
¬-up-to-context-compatible : Name → ¬ Compatible Up-to-context
¬-up-to-context-compatible x comp = contradiction
where
a = x , true
b = x , false
c = a
d = a
a≢b : ¬ a ≡ b
a≢b ()
data R : Rel₂ ℓ (Proc ∞) where
base : R (! name a ∙ (b ∙) , ! name a ∙ (c ∙))
data S₀ : Rel₂ ℓ (Proc ∞) where
base : S₀ (! name a ∙ (b ∙) ∣ b ∙ , ! name a ∙ (c ∙) ∣ c ∙)
S : Rel₂ ℓ (Proc ∞)
S = Up-to-bisimilarity S₀
d!ab[R]d!ac : Up-to-context R ( name d ∙ (! name a ∙ (b ∙))
, name d ∙ (! name a ∙ (c ∙))
)
d!ab[R]d!ac =
1
, name d · (λ { .force → hole fzero })
, (λ _ → ! name a ∙ (b ∙))
, (λ _ → ! name a ∙ (c ∙))
, refl · (λ { .force → Proc-refl _ })
, refl · (λ { .force → Proc-refl _ })
, (λ _ → base)
¬!ab[S]!ac : ¬ Up-to-context S (! name a ∙ (b ∙) , ! name a ∙ (c ∙))
¬!ab[S]!ac (n , C , Ps , Qs , !ab≡C[Ps] , !ac≡C[Qs] , PsSQs) =
$⟨ Matches-[] C ⟩
Matches ∞ (C [ Ps ]) C ↝⟨ Matches-cong (Proc-sym !ab≡C[Ps]) ⟩
Matches ∞ (! name a ∙ (b ∙)) C ↝⟨ helper !ab≡C[Ps] !ac≡C[Qs] ⟩□
⊥ □
where
helper : Equal ∞ (! name a ∙ (b ∙)) (C [ Ps ]) →
Equal ∞ (! name a ∙ (c ∙)) (C [ Qs ]) →
¬ Matches ∞ (! name a ∙ (b ∙)) C
helper !ab≡ _ (hole x) = case PsSQs x of λ where
(_ , Ps[x]∼!ab∣b , _ , base , _) →
$⟨ Ps[x]∼!ab∣b ⟩
Ps x ∼ ! name a ∙ (b ∙) ∣ b ∙ ↝⟨ transitive {a = ℓ} (≡→∼ !ab≡) ⟩
! name a ∙ (b ∙) ∼ ! name a ∙ (b ∙) ∣ b ∙ ↝⟨ (λ !ab∼!ab∣b → Σ-map id proj₁ $ StepC.right-to-left !ab∼!ab∣b (par-right action)) ⟩
(∃ λ P′ → ! name a ∙ (b ∙) [ name b ]⟶ P′) ↝⟨ cancel-name ∘ !-only ·-only ∘ proj₂ ⟩
a ≡ b ↝⟨ a≢b ⟩□
⊥ □
helper (! ab≡) (! ac≡) (! hole x) = case PsSQs x of λ where
(_ , Ps[x]∼!ab∣b , _ , base , _) →
$⟨ Ps[x]∼!ab∣b ⟩
Ps x ∼ ! name a ∙ (b ∙) ∣ b ∙ ↝⟨ transitive {a = ℓ} (≡→∼ ab≡) ⟩
name a ∙ (b ∙) ∼ ! name a ∙ (b ∙) ∣ b ∙ ↝⟨ (λ ab∼!ab∣b → Σ-map id proj₁ $ StepC.right-to-left ab∼!ab∣b (par-right action)) ⟩
(∃ λ P′ → name a ∙ (b ∙) [ name b ]⟶ P′) ↝⟨ cancel-name ∘ ·-only ∘ proj₂ ⟩
a ≡ b ↝⟨ a≢b ⟩□
⊥ □
helper (! (_ · b≡′)) (! (_ · c≡′)) (! action {C = C} M) =
case force C , force b≡′ , force c≡′ , force M {j = ∞} ⦂
(∃ λ C → Equal ∞ _ (C [ Ps ]) ×
Equal ∞ _ (C [ Qs ]) × Matches ∞ _ C) of λ where
(._ , b≡ , _ , hole x) → case PsSQs x of λ where
(_ , Ps[x]∼!ab∣b , _ , base , _) →
$⟨ Ps[x]∼!ab∣b ⟩
Ps x ∼ ! name a ∙ (b ∙) ∣ b ∙ ↝⟨ transitive {a = ℓ} (≡→∼ b≡) ⟩
b ∙ ∼ ! name a ∙ (b ∙) ∣ b ∙ ↝⟨ (λ b∼!ab∣b → Σ-map id proj₁ $
StepC.right-to-left b∼!ab∣b (par-left (replication (par-right action)))) ⟩
(∃ λ P′ → b ∙ [ name a ]⟶ P′) ↝⟨ cancel-name ∘ ·-only ∘ proj₂ ⟩
b ≡ a ↝⟨ a≢b ∘ sym ⟩□
⊥ □
(._ , _ , c≡b · _ , action _) →
$⟨ c≡b ⟩
name c ≡ name b ↝⟨ cancel-name ⟩
c ≡ b ↝⟨ a≢b ⟩□
⊥ □
R⊆StepS : R ⊆ ⟦ StepC ⟧ S
R⊆StepS base = StepC.⟨ lr , rl ⟩
where
lr : ∀ {P′ μ} →
! name a ∙ (b ∙) [ μ ]⟶ P′ →
∃ λ Q′ → ! name a ∙ (c ∙) [ μ ]⟶ Q′ × S (P′ , Q′)
lr {P′} {μ} !ab[μ]⟶P′ = case 6-1-3-2 !ab[μ]⟶P′ of λ where
(inj₁ (.(b ∙) , action , P′∼!ab∣b)) →
! name a ∙ (c ∙) ∣ c ∙
, replication (par-right action)
, _
, (P′ ∼⟨ P′∼!ab∣b ⟩■
! name a ∙ (b ∙) ∣ b ∙)
, _
, base
, (! name a ∙ (c ∙) ∣ c ∙ ■)
(inj₂ (μ≡τ , _)) → ⊥-elim $ name≢τ (
name a ≡⟨ !-only ·-only !ab[μ]⟶P′ ⟩
μ ≡⟨ μ≡τ ⟩∎
τ ∎)
rl : ∀ {Q′ μ} →
! name a ∙ (c ∙) [ μ ]⟶ Q′ →
∃ λ P′ → ! name a ∙ (b ∙) [ μ ]⟶ P′ × S (P′ , Q′)
rl {Q′} {μ} !ac[μ]⟶Q′ = case 6-1-3-2 !ac[μ]⟶Q′ of λ where
(inj₁ (.(c ∙) , action , Q′∼!ac∣c)) →
! name a ∙ (b ∙) ∣ b ∙
, replication (par-right action)
, _
, (! name a ∙ (b ∙) ∣ b ∙ ■)
, _
, base
, (! name a ∙ (c ∙) ∣ c ∙ ∼⟨ symmetric Q′∼!ac∣c ⟩■
Q′)
(inj₂ (μ≡τ , _)) → ⊥-elim $ name≢τ (
name a ≡⟨ !-only ·-only !ac[μ]⟶Q′ ⟩
μ ≡⟨ μ≡τ ⟩∎
τ ∎)
-- Note the use of compatibility in [R]⊆Step[S].
[R]⊆Step[S] : Up-to-context R ⊆ ⟦ StepC ⟧ (Up-to-context S)
[R]⊆Step[S] =
Up-to-context R ⊆⟨ up-to-context-monotone (λ {x} → R⊆StepS {x}) ⟩
Up-to-context (⟦ StepC ⟧ S) ⊆⟨ comp ⟩∎
⟦ StepC ⟧ (Up-to-context S) ∎
contradiction : ⊥
contradiction =
$⟨ d!ab[R]d!ac ⟩
Up-to-context R ( name d ∙ (! name a ∙ (b ∙))
, name d ∙ (! name a ∙ (c ∙))
) ↝⟨ [R]⊆Step[S] ⟩
⟦ StepC ⟧ (Up-to-context S) ( name d ∙ (! name a ∙ (b ∙))
, name d ∙ (! name a ∙ (c ∙))
) ↝⟨ (λ s → StepC.left-to-right s action) ⟩
(∃ λ P → name d ∙ (! name a ∙ (c ∙)) [ name d ]⟶ P ×
Up-to-context S (! name a ∙ (b ∙) , P)) ↝⟨ (λ { (P , d!ac[d]⟶P , !ab[S]P) →
subst (Up-to-context S ∘ (_ ,_)) (·-only⟶ d!ac[d]⟶P) !ab[S]P }) ⟩
Up-to-context S (! name a ∙ (b ∙) , ! name a ∙ (c ∙)) ↝⟨ ¬!ab[S]!ac ⟩□
⊥ □
| {
"alphanum_fraction": 0.3994768755,
"avg_line_length": 36.0987124464,
"ext": "agda",
"hexsha": "01a44862711aaebda43ee01ee380a71cf8af4dfb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/Up-to/CCS.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/up-to",
"max_issues_repo_path": "src/Bisimilarity/Up-to/CCS.agda",
"max_line_length": 138,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/Up-to/CCS.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3315,
"size": 8411
} |
-- Minimal propositional logic, de Bruijn approach, initial encoding
module Bi.Mp where
open import Lib using (List; _,_; LMem; lzero; lsuc)
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set
Cx = List Ty
isTrue : Ty -> Cx -> Set
isTrue a tc = LMem a tc
-- Terms
module Mp where
infixl 1 _$_
infixr 0 lam=>_
data Tm (tc : Cx) : Ty -> Set where
var : forall {a} -> isTrue a tc -> Tm tc a
lam=>_ : forall {a b} -> Tm (tc , a) b -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b)
fst : forall {a b} -> Tm tc (a && b) -> Tm tc a
snd : forall {a b} -> Tm tc (a && b) -> Tm tc b
left : forall {a b} -> Tm tc a -> Tm tc (a || b)
right : forall {a b} -> Tm tc b -> Tm tc (a || b)
case' : forall {a b c} -> Tm tc (a || b) -> Tm (tc , a) c -> Tm (tc , b) c -> Tm tc c
syntax pair' x y = [ x , y ]
syntax case' xy x y = case xy => x => y
v0 : forall {tc a} -> Tm (tc , a) a
v0 = var lzero
v1 : forall {tc a b} -> Tm (tc , a , b) a
v1 = var (lsuc lzero)
v2 : forall {tc a b c} -> Tm (tc , a , b , c) a
v2 = var (lsuc (lsuc lzero))
Thm : Ty -> Set
Thm a = forall {tc} -> Tm tc a
open Mp public
-- Example theorems
c1 : forall {a b} -> Thm (a && b <=> b && a)
c1 =
[ lam=> [ snd v0 , fst v0 ]
, lam=> [ snd v0 , fst v0 ]
]
c2 : forall {a b} -> Thm (a || b <=> b || a)
c2 =
[ lam=>
(case v0
=> right v0
=> left v0)
, lam=>
(case v0
=> right v0
=> left v0)
]
i1 : forall {a} -> Thm (a && a <=> a)
i1 =
[ lam=> fst v0
, lam=> [ v0 , v0 ]
]
i2 : forall {a} -> Thm (a || a <=> a)
i2 =
[ lam=>
(case v0
=> v0
=> v0)
, lam=> left v0
]
l3 : forall {a} -> Thm ((a => a) <=> TRUE)
l3 =
[ lam=> lam=> v0
, lam=> lam=> v0
]
l1 : forall {a b c} -> Thm (a && (b && c) <=> (a && b) && c)
l1 =
[ lam=>
[ [ fst v0 , fst (snd v0) ]
, snd (snd v0)
]
, lam=>
[ fst (fst v0)
, [ snd (fst v0) , snd v0 ]
]
]
l2 : forall {a} -> Thm (a && TRUE <=> a)
l2 =
[ lam=> fst v0
, lam=> [ v0 , lam=> v0 ]
]
l4 : forall {a b c} -> Thm (a && (b || c) <=> (a && b) || (a && c))
l4 =
[ lam=>
(case snd v0
=> left [ fst v1 , v0 ]
=> right [ fst v1 , v0 ])
, lam=>
(case v0
=> [ fst v0 , left (snd v0) ]
=> [ fst v0 , right (snd v0) ])
]
l6 : forall {a b c} -> Thm (a || (b && c) <=> (a || b) && (a || c))
l6 =
[ lam=>
(case v0
=> [ left v0 , left v0 ]
=> [ right (fst v0) , right (snd v0) ])
, lam=>
(case fst v0
=> left v0
=>
case snd v1
=> left v0
=> right [ v1 , v0 ])
]
l7 : forall {a} -> Thm (a || TRUE <=> TRUE)
l7 =
[ lam=> lam=> v0
, lam=> right v0
]
l9 : forall {a b c} -> Thm (a || (b || c) <=> (a || b) || c)
l9 =
[ lam=>
(case v0
=> left (left v0)
=>
case v0
=> left (right v0)
=> right v0)
, lam=>
(case v0
=>
case v0
=> left v0
=> right (left v0)
=> right (right v0))
]
l11 : forall {a b c} -> Thm ((a => (b && c)) <=> (a => b) && (a => c))
l11 =
[ lam=>
[ lam=> fst (v1 $ v0)
, lam=> snd (v1 $ v0)
]
, lam=>
lam=> [ fst v1 $ v0 , snd v1 $ v0 ]
]
l12 : forall {a} -> Thm ((a => TRUE) <=> TRUE)
l12 =
[ lam=> lam=> v0
, lam=> lam=> v1
]
l13 : forall {a b c} -> Thm ((a => (b => c)) <=> ((a && b) => c))
l13 =
[ lam=>
lam=> v1 $ fst v0 $ snd v0
, lam=>
lam=>
lam=> v2 $ [ v1 , v0 ]
]
l16 : forall {a b c} -> Thm (((a && b) => c) <=> (a => (b => c)))
l16 =
[ lam=>
lam=>
lam=> v2 $ [ v1 , v0 ]
, lam=>
lam=> v1 $ fst v0 $ snd v0
]
l17 : forall {a} -> Thm ((TRUE => a) <=> a)
l17 =
[ lam=> v0 $ (lam=> v0)
, lam=> lam=> v1
]
l19 : forall {a b c} -> Thm (((a || b) => c) <=> (a => c) && (b => c))
l19 =
[ lam=>
[ lam=> v1 $ left v0
, lam=> v1 $ right v0
]
, lam=>
lam=>
(case v0
=> fst v2 $ v0
=> snd v2 $ v0)
]
| {
"alphanum_fraction": 0.3861449647,
"avg_line_length": 19.9021276596,
"ext": "agda",
"hexsha": "81cab47c5ded61c711cdb20d2f04a0b1affdb8cd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Bi/Mp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Bi/Mp.agda",
"max_line_length": 90,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Bi/Mp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 1879,
"size": 4677
} |
{-
Function types
A , B : Set -- Set = Type
A → B : Set
Products and sums
A × B : Set
A ⊎ B : Set -- disjoint union
Don't have A ∪ B : Set! And neither A ∩ B : Set.
These are evil operations, because they depend on elements.
-}
record _×_ (A B : Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B
open _×_
variable
A B C : Set
{-
_,_ : A → B → A × B
proj₁ (a , b) = a -- copattern matching
proj₂ (a , b) = b
-}
curry : (A × B → C) → (A → B → C)
curry f a b = f (a , b)
uncurry : (A → B → C) → (A × B → C)
uncurry g x = g (proj₁ x) (proj₂ x)
{-
These two functions are inverses.
How is this isomorphism called? Adjunction.
Explains the relation between functions and product.
Functions are "right adjoint" to product.
-}
data _⊎_ (A B : Set) : Set where
inj₁ : A → A ⊎ B
inj₂ : B → A ⊎ B
case : (A → C) → (B → C) → (A ⊎ B → C)
case f g (inj₁ a) = f a -- x C-c C-c
case f g (inj₂ b) = g b
-- uncurry case
uncase : (A ⊎ B → C) → (A → C) × (B → C)
proj₁ (uncase f) a = f (inj₁ a)
proj₂ (uncase f) b = f (inj₂ b)
{-
These functions are inverse to each other they witness that ⊎ is a left
adjoint (of the diagonal).
If functions are the right adjoint of products what is the left adjoint of
sums (⊎)?
-}
-- data is defined by constructors _⊎_ , _×_
-- codata (record) is defined by destructors _×_ , _→_
{-
data _×'_ (A B : Set) : Set where
_,_ : A → B → A ×' B
proj₁' : A × B → A
proj₁' (a , b) = a -- pattern matching
-}
-- What about nullary, empty product, empty sum?
record ⊤ : Set where -- the unit type, it has exactly one element tt.
constructor tt
{-
tt : ⊤
tt = record {}
-}
data ⊥ : Set where -- this is the empty type, no elements.
case⊥ : ⊥ → C
case⊥ () -- impossible pattern
-- In classical propositional logic: prop = Bool
prop = Set -- the type of evidence: propositions as type explanations
-- in HoTT prop = hprop = types with at most inhabitant
variable
P Q R : prop
infixl 5 _∧_
_∧_ : prop → prop → prop
P ∧ Q = P × Q
infixl 3 _∨_
_∨_ : prop → prop → prop
P ∨ Q = P ⊎ Q
infixr 2 _⇒_
_⇒_ : prop → prop → prop
P ⇒ Q = P → Q
True : prop
True = ⊤
False : prop
False = ⊥
¬ : prop → prop
¬ P = P ⇒ False
infix 1 _⇔_
_⇔_ : prop → prop → prop
P ⇔ Q = (P ⇒ Q) ∧ (Q ⇒ P)
deMorgan : ¬ (P ∨ Q) ⇔ ¬ P ∧ ¬ Q
proj₁ deMorgan x = (λ p → x (inj₁ p)) , λ q → x (inj₂ q)
proj₂ deMorgan y (inj₁ p) = proj₁ y p
proj₂ deMorgan y (inj₂ q) = proj₂ y q
-- the other direction is no logical truth in intuitionistic logic
deMorgan' : (¬ P ∨ ¬ Q) ⇒ ¬ (P ∧ Q)
deMorgan' (inj₁ x) z = x (proj₁ z)
deMorgan' (inj₂ x) z = x (proj₂ z)
| {
"alphanum_fraction": 0.5810862134,
"avg_line_length": 20.7322834646,
"ext": "agda",
"hexsha": "4e8a9111ea1e86ec26d8392a9759878f1f76a9a5",
"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": "f328e596d98a7d052b34144447dd14de0f57e534",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FoxySeta/mgs-2021",
"max_forks_repo_path": "Type Theory/notes-02-tuesday.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534",
"max_issues_repo_issues_event_max_datetime": "2021-07-14T20:35:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-07-14T20:34:53.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "FoxySeta/mgs-2021",
"max_issues_repo_path": "Type Theory/notes-02-tuesday.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FoxySeta/mgs-2021",
"max_stars_repo_path": "Type Theory/notes-02-tuesday.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1023,
"size": 2633
} |
module Structure.Function.Domain.Proofs where
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
import Lvl
open import Functional
open import Function.Domains
open import Function.Equals
import Function.Names as Names
open import Lang.Instance
open import Logic
open import Logic.Classical
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Logic.Predicate
open import Structure.Setoid
open import Structure.Setoid.Uniqueness
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Relator.Properties
open import Structure.Relator
open import Syntax.Transitivity
open import Type
open import Type.Dependent
private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₒ₁ ℓₒ₂ : Lvl.Level
private variable T A B C : Type{ℓ}
module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ (f : A → B) where
injective-to-unique : Injective(f) → ∀{y} → Unique(x ↦ f(x) ≡ y)
injective-to-unique (intro(inj)) {y} {x₁}{x₂} fx₁y fx₂y =
inj{x₁}{x₂} (fx₁y 🝖 symmetry(_≡_) fx₂y)
instance
bijective-to-injective : ⦃ bij : Bijective(f) ⦄ → Injective(f)
Injective.proof(bijective-to-injective ⦃ intro(bij) ⦄) {x₁}{x₂} (fx₁fx₂) =
([∃!]-existence-eq (bij {f(x₂)}) {x₁} (fx₁fx₂))
🝖 symmetry(_≡_) ([∃!]-existence-eq (bij {f(x₂)}) {x₂} (reflexivity(_≡_)))
-- ∀{y : B} → ∃!(x ↦ f(x) ≡ y)
-- ∃!(x ↦ f(x) ≡ f(x₂))
-- ∀{x} → (f(x) ≡ f(x₂)) → (x ≡ [∃!]-witness e)
-- (f(x₁) ≡ f(x₂)) → (x₁ ≡ [∃!]-witness e)
--
-- ∀{y : B} → ∃!(x ↦ f(x) ≡ y)
-- ∃!(x ↦ f(x) ≡ f(x₂))
-- ∀{x} → (f(x) ≡ f(x₂)) → (x ≡ [∃!]-witness e)
-- (f(x₂) ≡ f(x₂)) → (x₂ ≡ [∃!]-witness e)
instance
bijective-to-surjective : ⦃ bij : Bijective(f) ⦄ → Surjective(f)
Surjective.proof(bijective-to-surjective ⦃ intro(bij) ⦄) {y} =
[∃!]-existence (bij {y})
instance
injective-surjective-to-bijective : ⦃ inj : Injective(f) ⦄ → ⦃ surj : Surjective(f) ⦄ → Bijective(f)
Bijective.proof(injective-surjective-to-bijective ⦃ inj ⦄ ⦃ intro(surj) ⦄) {y} =
[∃!]-intro surj (injective-to-unique inj)
injective-surjective-bijective-equivalence : (Injective(f) ∧ Surjective(f)) ↔ Bijective(f)
injective-surjective-bijective-equivalence =
[↔]-intro
(\bij → [∧]-intro (bijective-to-injective ⦃ bij = bij ⦄) (bijective-to-surjective ⦃ bij = bij ⦄))
(\{([∧]-intro inj surj) → injective-surjective-to-bijective ⦃ inj = inj ⦄ ⦃ surj = surj ⦄})
module _ {A : Type{ℓₒ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ where
instance
injective-relator : UnaryRelator(Injective{A = A}{B = B})
Injective.proof (UnaryRelator.substitution injective-relator {f₁}{f₂} (intro f₁f₂) (intro inj-f₁)) f₂xf₂y = inj-f₁ (f₁f₂ 🝖 f₂xf₂y 🝖 symmetry(_≡_) f₁f₂)
module _ {A : Type{ℓₒ₁}} {B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ where
instance
surjective-relator : UnaryRelator(Surjective{A = A}{B = B})
Surjective.proof (UnaryRelator.substitution surjective-relator {f₁}{f₂} (intro f₁f₂) (intro surj-f₁)) {y} = [∃]-map-proof (\{x} f₁xf₁y → symmetry(_≡_) (f₁f₂{x}) 🝖 f₁xf₁y) (surj-f₁{y})
module _ {A : Type{ℓₒ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ where
instance
bijective-relator : UnaryRelator(Bijective{A = A}{B = B})
UnaryRelator.substitution bijective-relator {f₁}{f₂} f₁f₂ bij-f₁ = injective-surjective-to-bijective(f₂) ⦃ substitute₁(Injective) f₁f₂ (bijective-to-injective(f₁)) ⦄ ⦃ substitute₁(Surjective) f₁f₂ (bijective-to-surjective(f₁)) ⦄ where
instance _ = bij-f₁
module _
{A : Type{ℓₒ₁}}
{B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
where
invᵣ-surjective : (f : A → B) ⦃ surj : Surjective(f) ⦄ → (B → A)
invᵣ-surjective _ ⦃ surj ⦄ (y) = [∃]-witness(Surjective.proof surj{y})
module _
{A : Type{ℓₒ₁}}
{B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B}
where
surjective-to-inverseᵣ : ⦃ surj : Surjective(f) ⦄ → Inverseᵣ(f)(invᵣ-surjective f)
surjective-to-inverseᵣ ⦃ intro surj ⦄ = intro([∃]-proof surj)
module _
{A : Type{ℓₒ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} {f⁻¹ : B → A}
where
inverseᵣ-to-surjective : ⦃ inverᵣ : Inverseᵣ(f)(f⁻¹) ⦄ → Surjective(f)
Surjective.proof inverseᵣ-to-surjective {y} = [∃]-intro (f⁻¹(y)) ⦃ inverseᵣ(f)(f⁻¹) ⦄
Inverse-symmetry : Inverse(f)(f⁻¹) → Inverse(f⁻¹)(f)
Inverse-symmetry ([∧]-intro (intro inverₗ) (intro inverᵣ)) = [∧]-intro (intro inverᵣ) (intro inverₗ)
module _
{A : Type{ℓₒ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓₒ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B}
where
invertibleᵣ-to-surjective : ⦃ inverᵣ : Invertibleᵣ(f) ⦄ → Surjective(f)
∃.witness (Surjective.proof(invertibleᵣ-to-surjective ⦃ inverᵣ ⦄) {y}) = [∃]-witness inverᵣ(y)
∃.proof (Surjective.proof(invertibleᵣ-to-surjective ⦃ inverᵣ ⦄) {y}) = inverseᵣ _ _ ⦃ [∧]-elimᵣ([∃]-proof inverᵣ) ⦄
-- Every surjective function has a right inverse with respect to function composition.
-- One of the right inverse functions of a surjective function f.
-- Specifically the one that is used in the constructive proof of surjectivity for f.
-- Without assuming that the value used in the proof of surjectivity constructs a function, this would be unprovable because it is not guaranteed in arbitrary setoids.
-- Note: The usual formulation of this proposition (without assuming `inv-func`) is equivalent to the axiom of choice from set theory in classical logic.
surjective-to-invertibleᵣ : ⦃ surj : Surjective(f) ⦄ ⦃ inv-func : Function(invᵣ-surjective f) ⦄ → Invertibleᵣ(f)
∃.witness (surjective-to-invertibleᵣ) = invᵣ-surjective f
∃.proof (surjective-to-invertibleᵣ ⦃ surj = intro surj ⦄ ⦃ inv-func = inv-func ⦄) = [∧]-intro inv-func (intro([∃]-proof surj))
invertibleᵣ-when-surjective : Invertibleᵣ(f) ↔ Σ(Surjective(f)) (surj ↦ Function(invᵣ-surjective f ⦃ surj ⦄))
invertibleᵣ-when-surjective =
[↔]-intro
(surj ↦ surjective-to-invertibleᵣ ⦃ Σ.left surj ⦄ ⦃ Σ.right surj ⦄)
(inverᵣ ↦ intro (invertibleᵣ-to-surjective ⦃ inverᵣ ⦄) ([∧]-elimₗ([∃]-proof inverᵣ)))
module _
{A : Type{ℓ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} {f⁻¹ : B → A} ⦃ inverᵣ : Inverseᵣ(f)(f⁻¹) ⦄
where
-- Note: This states that a function which is injective and surjective (bijective) is a function, but another way of satisfying this proposition is from a variant of axiom of choice which directly state that the right inverse of a surjective function always exist.
inverseᵣ-function : ⦃ inj : Injective(f) ⦄ → Function(f⁻¹)
Function.congruence (inverseᵣ-function) {y₁}{y₂} y₁y₂ =
injective(f) (
f(f⁻¹(y₁)) 🝖-[ inverseᵣ(f)(f⁻¹) ]
y₁ 🝖-[ y₁y₂ ]
y₂ 🝖-[ inverseᵣ(f)(f⁻¹) ]-sym
f(f⁻¹(y₂)) 🝖-end
)
-- The right inverse is injective when f is a surjective function.
inverseᵣ-injective : ⦃ func : Function(f) ⦄ → Injective(f⁻¹)
Injective.proof(inverseᵣ-injective) {x₁}{x₂} (invᵣfx₁≡invᵣfx₂) =
x₁ 🝖-[ inverseᵣ(f)(f⁻¹) ]-sym
f(f⁻¹(x₁)) 🝖-[ congruence₁(f) {f⁻¹(x₁)} {f⁻¹(x₂)} (invᵣfx₁≡invᵣfx₂) ]
f(f⁻¹(x₂)) 🝖-[ inverseᵣ(f)(f⁻¹) ]
x₂ 🝖-end
-- The right inverse is surjective when the surjective f is injective.
inverseᵣ-surjective : ⦃ inj : Injective(f) ⦄ → Surjective(f⁻¹)
∃.witness (Surjective.proof inverseᵣ-surjective {x}) = f(x)
∃.proof (Surjective.proof inverseᵣ-surjective {x}) =
injective(f) (
f(f⁻¹(f(x))) 🝖-[ inverseᵣ(f)(f⁻¹) ]
f(x) 🝖-end
)
-- The right inverse is a left inverse when the surjective f is injective.
inverseᵣ-inverseₗ : ⦃ inj : Injective(f) ⦄ → Inverseₗ(f)(f⁻¹)
inverseᵣ-inverseₗ = intro([∃]-proof(surjective(f⁻¹) ⦃ inverseᵣ-surjective ⦄))
-- The right inverse is bijective when the surjective f is injective.
inverseᵣ-bijective : ⦃ func : Function(f) ⦄ ⦃ inj : Injective(f) ⦄ → Bijective(f⁻¹)
inverseᵣ-bijective = injective-surjective-to-bijective(f⁻¹) ⦃ inverseᵣ-injective ⦄ ⦃ inverseᵣ-surjective ⦄
inverseᵣ-inverse : ⦃ inj : Injective(f) ⦄ → Inverse(f)(f⁻¹)
inverseᵣ-inverse = [∧]-intro inverseᵣ-inverseₗ inverᵣ
-- The right inverse is an unique right inverse when f is injective.
inverseᵣ-unique-inverseᵣ : ⦃ inj : Injective(f) ⦄ → ∀{g} → (f ∘ g ⊜ id) → (g ⊜ f⁻¹)
inverseᵣ-unique-inverseᵣ {g = g} (intro p) = intro $ \{x} →
g(x) 🝖-[ inverseₗ(f)(f⁻¹) ⦃ inverseᵣ-inverseₗ ⦄ ]-sym
f⁻¹(f(g(x))) 🝖-[ congruence₁(f⁻¹) ⦃ inverseᵣ-function ⦄ p ]
f⁻¹(x) 🝖-end
-- The right inverse is an unique left inverse function.
inverseᵣ-unique-inverseₗ : ∀{g} ⦃ _ : Function(g) ⦄ → (g ∘ f ⊜ id) → (g ⊜ f⁻¹)
inverseᵣ-unique-inverseₗ {g = g} (intro p) = intro $ \{x} →
g(x) 🝖-[ congruence₁(g) (inverseᵣ(f)(f⁻¹)) ]-sym
g(f(f⁻¹(x))) 🝖-[ p{f⁻¹(x)} ]
f⁻¹(x) 🝖-end
-- The right inverse is invertible.
inverseᵣ-invertibleᵣ : ⦃ func : Function(f) ⦄ ⦃ inj : Injective(f) ⦄ → Invertibleᵣ(f⁻¹)
∃.witness inverseᵣ-invertibleᵣ = f
∃.proof (inverseᵣ-invertibleᵣ ⦃ func = func ⦄) = [∧]-intro func inverseᵣ-inverseₗ
-- TODO: invᵣ-unique-function : ∀{g} → (invᵣ(f) ∘ g ⊜ id) → (g ⊜ f)
module _
{A : Type{ℓ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} {f⁻¹ : B → A} ⦃ inverₗ : Inverseₗ(f)(f⁻¹) ⦄
where
inverseₗ-surjective : Surjective(f⁻¹)
inverseₗ-surjective = inverseᵣ-to-surjective
inverseₗ-to-injective : ⦃ invₗ-func : Function(f⁻¹) ⦄ → Injective(f)
inverseₗ-to-injective = inverseᵣ-injective
module _
{A : Type{ℓ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} ⦃ func : Function(f) ⦄
{f⁻¹ : B → A} ⦃ inv-func : Function(f⁻¹) ⦄
where
inverseₗ-to-inverseᵣ : ⦃ surj : Surjective(f) ⦄ ⦃ inverₗ : Inverseₗ(f)(f⁻¹) ⦄ → Inverseᵣ(f)(f⁻¹)
Inverseᵣ.proof inverseₗ-to-inverseᵣ {x} with [∃]-intro y ⦃ p ⦄ ← surjective f{x} =
f(f⁻¹(x)) 🝖-[ congruence₁(f) (congruence₁(f⁻¹) p) ]-sym
f(f⁻¹(f(y))) 🝖-[ congruence₁(f) (inverseₗ(f)(f⁻¹)) ]
f(y) 🝖-[ p ]
x 🝖-end
module _ ⦃ surj : Surjective(f) ⦄ ⦃ inverₗ : Inverseₗ(f)(f⁻¹) ⦄ where
inverseₗ-injective : Injective(f⁻¹)
Injective.proof inverseₗ-injective {x}{y} p =
x 🝖-[ inverseᵣ(f)(f⁻¹) ⦃ inverseₗ-to-inverseᵣ ⦄ ]-sym
f(f⁻¹(x)) 🝖-[ congruence₁(f) p ]
f(f⁻¹(y)) 🝖-[ inverseᵣ(f)(f⁻¹) ⦃ inverseₗ-to-inverseᵣ ⦄ ]
y 🝖-end
inverseₗ-bijective : Bijective(f⁻¹)
inverseₗ-bijective = injective-surjective-to-bijective(f⁻¹) ⦃ inverseₗ-injective ⦄ ⦃ inverseₗ-surjective ⦄
inverseₗ-to-surjective : Surjective(f)
inverseₗ-to-surjective = inverseᵣ-surjective ⦃ inj = inverseₗ-injective ⦄
inverseₗ-to-bijective : Bijective(f)
inverseₗ-to-bijective = injective-surjective-to-bijective(f) ⦃ inverseₗ-to-injective ⦄ ⦃ inverseₗ-to-surjective ⦄
module _
{A : Type{ℓ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} {f⁻¹ : B → A} ⦃ inver : Inverse(f)(f⁻¹) ⦄
where
inverse-to-surjective : Surjective(f)
inverse-to-surjective = inverseᵣ-to-surjective ⦃ inverᵣ = [∧]-elimᵣ inver ⦄
module _ ⦃ inv-func : Function(f⁻¹) ⦄ where
inverse-to-injective : Injective(f)
inverse-to-injective = inverseₗ-to-injective ⦃ inverₗ = [∧]-elimₗ inver ⦄
inverse-to-bijective : Bijective(f)
inverse-to-bijective = injective-surjective-to-bijective(f) ⦃ inj = inverse-to-injective ⦄ ⦃ surj = inverse-to-surjective ⦄
inverse-surjective : Surjective(f⁻¹)
inverse-surjective = inverseₗ-surjective ⦃ inverₗ = [∧]-elimₗ inver ⦄
module _ ⦃ func : Function(f) ⦄ where
inverse-injective : Injective(f⁻¹)
inverse-injective = inverseᵣ-injective ⦃ inverᵣ = [∧]-elimᵣ inver ⦄ ⦃ func = func ⦄
inverse-bijective : Bijective(f⁻¹)
inverse-bijective = injective-surjective-to-bijective(f⁻¹) ⦃ inj = inverse-injective ⦄ ⦃ surj = inverse-surjective ⦄
inverse-function-when-injective : Function(f⁻¹) ↔ Injective(f)
inverse-function-when-injective =
[↔]-intro
(inj ↦ inverseᵣ-function ⦃ inverᵣ = [∧]-elimᵣ inver ⦄ ⦃ inj = inj ⦄)
(inv-func ↦ inverse-to-injective ⦃ inv-func = inv-func ⦄)
function-when-inverse-injective : Function(f) ↔ Injective(f⁻¹)
function-when-inverse-injective =
[↔]-intro
(inv-inj ↦ intro(\{x y} → xy ↦ injective(f⁻¹) ⦃ inv-inj ⦄ (
f⁻¹(f(x)) 🝖-[ inverseₗ(f)(f⁻¹) ⦃ [∧]-elimₗ inver ⦄ ]
x 🝖-[ xy ]
y 🝖-[ inverseₗ(f)(f⁻¹) ⦃ [∧]-elimₗ inver ⦄ ]-sym
f⁻¹(f(y)) 🝖-end
)))
(func ↦ inverse-injective ⦃ func = func ⦄)
-- TODO: inverse-function-when-bijective : Function(f⁻¹) ↔ Bijective(f)
-- Surjective(f) ↔ Injective(f⁻¹)
-- Injective(f) ↔ Surjective(f⁻¹)
module _
{A : Type{ℓ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{f : A → B} ⦃ inver : Invertible(f) ⦄
where
invertible-elimₗ : Invertibleₗ(f)
invertible-elimₗ = [∃]-map-proof (Tuple.mapRight [∧]-elimₗ) inver
invertible-elimᵣ : Invertibleᵣ(f)
invertible-elimᵣ = [∃]-map-proof (Tuple.mapRight [∧]-elimᵣ) inver
module _
{A : Type{ℓ₁}} ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
{B : Type{ℓ₂}} ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
where
private variable f : A → B
-- invertible-intro : ⦃ inverₗ : Invertibleₗ(f) ⦄ ⦃ inverᵣ : Invertibleᵣ(f) ⦄ → Invertible(f)
-- invertible-intro = {!!}
bijective-to-invertible : ⦃ bij : Bijective(f) ⦄ → Invertible(f)
bijective-to-invertible {f = f} ⦃ bij = bij ⦄ = [∃]-intro f⁻¹ ⦃ [∧]-intro f⁻¹-function ([∧]-intro f⁻¹-inverseₗ f⁻¹-inverseᵣ) ⦄ where
f⁻¹ : B → A
f⁻¹ = invᵣ-surjective f ⦃ bijective-to-surjective(f) ⦄
f⁻¹-inverseᵣ : Inverseᵣ(f)(f⁻¹)
f⁻¹-inverseᵣ = surjective-to-inverseᵣ ⦃ surj = bijective-to-surjective(f) ⦄
f⁻¹-inverseₗ : Inverseₗ(f)(f⁻¹)
f⁻¹-inverseₗ = inverseᵣ-inverseₗ ⦃ inverᵣ = f⁻¹-inverseᵣ ⦄ ⦃ inj = bijective-to-injective(f) ⦄
f⁻¹-function : Function(f⁻¹)
f⁻¹-function = inverseᵣ-function ⦃ inverᵣ = f⁻¹-inverseᵣ ⦄ ⦃ inj = bijective-to-injective(f) ⦄
invertible-to-bijective : ⦃ inver : Invertible(f) ⦄ → Bijective(f)
invertible-to-bijective {f} ⦃ ([∃]-intro f⁻¹ ⦃ [∧]-intro func inver ⦄) ⦄ =
injective-surjective-to-bijective(f)
⦃ inj = inverse-to-injective ⦃ inver = inver ⦄ ⦃ inv-func = func ⦄ ⦄
⦃ surj = inverse-to-surjective ⦃ inver = inver ⦄ ⦄
invertible-when-bijective : Invertible(f) ↔ Bijective(f)
invertible-when-bijective = [↔]-intro (bij ↦ bijective-to-invertible ⦃ bij ⦄) (inver ↦ invertible-to-bijective ⦃ inver ⦄)
| {
"alphanum_fraction": 0.6223709369,
"avg_line_length": 43.975975976,
"ext": "agda",
"hexsha": "941c8714875d4226adf031897a0fb979924d8dbd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Function/Domain/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Function/Domain/Proofs.agda",
"max_line_length": 266,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Function/Domain/Proofs.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": 6403,
"size": 14644
} |
module Eval where
open import Coinduction
open import Data.Bool
open import Data.Fin using (Fin)
import Data.Fin as F
open import Data.Product using (Σ; _,_)
import Data.Product as P
open import Data.Stream using (Stream; _∷_)
import Data.Stream as S
open import Data.Vec using (Vec; []; _∷_)
import Data.Vec as V
open import Relation.Binary.PropositionalEquality
open import Types
⟦_⟧ᵗ : Type → Set
⟦ 𝔹 ⟧ᵗ = Bool
⟦ 𝔹⁺ n ⟧ᵗ = Vec Bool n
⟦ ℂ τ ⟧ᵗ = Stream ⟦ τ ⟧ᵗ
⟦ σ ⇒ τ ⟧ᵗ = ⟦ σ ⟧ᵗ → ⟦ τ ⟧ᵗ
⟦ σ × τ ⟧ᵗ = P._×_ ⟦ σ ⟧ᵗ ⟦ τ ⟧ᵗ
data Env : ∀ {n} → Ctx n → Set where
[] : Env []
_∷_ : ∀ {n} {Γ : Ctx n} {τ} → ⟦ τ ⟧ᵗ → Env Γ → Env (τ ∷ Γ)
lookupEnv : ∀ {n} {Γ : Ctx n} (i : Fin n) → Env Γ → ⟦ V.lookup i Γ ⟧ᵗ
lookupEnv F.zero (x ∷ env) = x
lookupEnv (F.suc i) (x ∷ env) = lookupEnv i env
private
runReg : ∀ {σ τ} → (⟦ τ ⟧ᵗ → ⟦ τ ⟧ᵗ P.× ⟦ σ ⟧ᵗ) → ⟦ τ ⟧ᵗ → Stream ⟦ σ ⟧ᵗ
runReg f s with f s
runReg f s | s′ , x = x ∷ ♯ (runReg f s′)
_⟦_⟧ : ∀ {n} {Γ : Ctx n} {τ} → Env Γ → Term Γ τ → ⟦ τ ⟧ᵗ
env ⟦ bitI ⟧ = true
env ⟦ bitO ⟧ = false
env ⟦ [] ⟧ = []
env ⟦ x ∷ xs ⟧ = env ⟦ x ⟧ ∷ env ⟦ xs ⟧
env ⟦ x nand y ⟧ with env ⟦ x ⟧ | env ⟦ y ⟧
env ⟦ x nand y ⟧ | true | true = false
env ⟦ x nand y ⟧ | _ | _ = true
env ⟦ reg xt ft ⟧ = runReg (env ⟦ ft ⟧) (env ⟦ xt ⟧)
env ⟦ pair xt yt ⟧ = (env ⟦ xt ⟧) , (env ⟦ yt ⟧)
env ⟦ latest t ⟧ = S.head (env ⟦ t ⟧)
env ⟦ head t ⟧ = V.head (env ⟦ t ⟧)
env ⟦ tail t ⟧ = V.tail (env ⟦ t ⟧)
env ⟦ var i refl ⟧ = lookupEnv i env
env ⟦ f ∙ x ⟧ = (env ⟦ f ⟧) (env ⟦ x ⟧)
env ⟦ lam t ⟧ = λ x → (x ∷ env) ⟦ t ⟧
| {
"alphanum_fraction": 0.5122410546,
"avg_line_length": 30.0566037736,
"ext": "agda",
"hexsha": "f7e5cbcb04e01469f3762f501dfc519735edd5d7",
"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": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bens/hwlc",
"max_forks_repo_path": "Eval.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"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": "bens/hwlc",
"max_issues_repo_path": "Eval.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bens/hwlc",
"max_stars_repo_path": "Eval.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 787,
"size": 1593
} |
open import MLib.Algebra.PropertyCode
open import MLib.Algebra.PropertyCode.Structures
module MLib.Matrix.Mul {c ℓ} (struct : Struct bimonoidCode c ℓ) where
open import MLib.Prelude
open import MLib.Matrix.Core
open import MLib.Matrix.Equality struct
open import MLib.Matrix.Plus struct
open import MLib.Algebra.Operations struct
open FunctionProperties
open Table using (head; tail; rearrange; fromList; toList; _≗_)
1● : ∀ {n} → Matrix S n n
1● i j with i Fin.≟ j
1● i j | yes _ = 1′
1● i j | no _ = 0′
infixl 7 _⊗_
_⊗_ : ∀ {m n o} → Matrix S m n → Matrix S n o → Matrix S m o
_⊗_ {n = n} A B i k = ∑[ j < n ] (A i j *′ B j k)
⊗-cong : ∀ {m n o} {A A′ : Matrix S m n} {B B′ : Matrix S n o} → A ≈ A′ → B ≈ B′ → (A ⊗ B) ≈ (A′ ⊗ B′)
⊗-cong A≈A′ B≈B′ i k = sumₜ-cong (λ j → cong * (A≈A′ i j) (B≈B′ j k))
open _≃_
1●-cong-≃ : ∀ {m n} → m ≡ n → 1● {m} ≃ 1● {n}
1●-cong-≃ ≡.refl = ≃-refl
⊗-cong-≃ : ∀ {m n o m′ n′ o′} (A : Matrix S m n) (B : Matrix S n o) (A′ : Matrix S m′ n′) (B′ : Matrix S n′ o′) → A ≃ A′ → B ≃ B′ → (A ⊗ B) ≃ (A′ ⊗ B′)
⊗-cong-≃ A B A′ B′ p q .m≡p = p .m≡p
⊗-cong-≃ A B A′ B′ p q .n≡q = q .n≡q
⊗-cong-≃ {n = n} {n′ = n′} A B A′ B′ p q .equal {i} {i′} {k} {k′} i≅i′ k≅k′ =
begin
(A ⊗ B ) i k ≡⟨⟩
∑[ j < n ] (A i j *′ B j k) ≈⟨ sumₜ-cong′ {n} {n′} (p .n≡q , λ _ _ j≅j′ → cong * (p .equal i≅i′ j≅j′) (q .equal j≅j′ k≅k′)) ⟩
∑[ j′ < n′ ] (A′ i′ j′ *′ B′ j′ k′) ≡⟨⟩
(A′ ⊗ B′) i′ k′ ∎
where
open EqReasoning S.setoid
⊗-assoc :
⦃ props : Has ( * ⟨ distributesOverˡ ⟩ₚ +
∷ * ⟨ distributesOverʳ ⟩ₚ +
∷ associative on *
∷ 0# is leftZero for *
∷ 0# is rightZero for *
∷ 0# is leftIdentity for +
∷ associative on +
∷ commutative on +
∷ []) ⦄
→ ∀ {m n p q} (A : Matrix S m n) (B : Matrix S n p) (C : Matrix S p q)
→ ((A ⊗ B) ⊗ C) ≈ (A ⊗ (B ⊗ C))
⊗-assoc ⦃ props ⦄ {m} {n} {p} {q} A B C i l =
begin
((A ⊗ B) ⊗ C) i l ≡⟨⟩
∑[ k < p ] (∑[ j < n ] (A i j *′ B j k) *′ C k l) ≈⟨ sumₜ-cong {p} (λ k → sumDistribʳ ⦃ weaken props ⦄ {n} _ _) ⟩
∑[ k < p ] (∑[ j < n ] ((A i j *′ B j k) *′ C k l)) ≈⟨ sumₜ-cong {p} (λ k → sumₜ-cong {n} (λ j → from props (associative on *) _ _ _)) ⟩
∑[ k < p ] (∑[ j < n ] (A i j *′ (B j k *′ C k l))) ≈⟨ ∑-comm ⦃ weaken props ⦄ p n _ ⟩
∑[ j < n ] (∑[ k < p ] (A i j *′ (B j k *′ C k l))) ≈⟨ sumₜ-cong {n} (λ j → S.sym (sumDistribˡ ⦃ weaken props ⦄ {p} _ _)) ⟩
∑[ j < n ] (A i j *′ ∑[ k < p ] (B j k *′ C k l)) ≡⟨⟩
(A ⊗ (B ⊗ C)) i l ∎
where open EqReasoning S.setoid
1-*-comm :
⦃ props : Has (1# is leftIdentity for * ∷ 1# is rightIdentity for * ∷ 0# is leftZero for * ∷ 0# is rightZero for * ∷ []) ⦄ →
∀ {n} (i j : Fin n) x → 1● i j *′ x ≈′ x *′ 1● i j
1-*-comm i j x with i Fin.≟ j
1-*-comm ⦃ props ⦄ i j x | yes p = S.trans (from props (1# is leftIdentity for *) _) (S.sym (from props (1# is rightIdentity for *) _))
1-*-comm ⦃ props ⦄ i j x | no ¬p = S.trans (from props (0# is leftZero for *) _) (S.sym (from props (0# is rightZero for *) _))
1-selectˡ :
⦃ props : Has (1# is leftIdentity for * ∷ 0# is leftZero for * ∷ []) ⦄ →
∀ {n} (i : Fin n) t j → (1● i j *′ lookup t j) ≈′ lookup (Table.select 0′ i t) j
1-selectˡ i t j with i Fin.≟ j | j Fin.≟ i
1-selectˡ ⦃ props ⦄ i t .i | yes ≡.refl | yes q = from props (1# is leftIdentity for *) _
1-selectˡ .j t j | yes ≡.refl | no ¬q = ⊥-elim (¬q ≡.refl)
1-selectˡ i t .i | no ¬p | yes ≡.refl = ⊥-elim (¬p ≡.refl)
1-selectˡ ⦃ props ⦄ i t j | no _ | no ¬p = from props (0# is leftZero for *) _
1-selectʳ :
⦃ props : Has (1# is rightIdentity for * ∷ 0# is rightZero for * ∷ []) ⦄ →
∀ {n} (i : Fin n) t j → (lookup t j *′ 1● j i) ≈′ lookup (Table.select 0′ i t) j
1-selectʳ i t j with i Fin.≟ j | j Fin.≟ i
1-selectʳ ⦃ props ⦄ i t .i | yes ≡.refl | yes q = from props (1# is rightIdentity for *) _
1-selectʳ .j t j | yes ≡.refl | no ¬q = ⊥-elim (¬q ≡.refl)
1-selectʳ i t .i | no ¬p | yes ≡.refl = ⊥-elim (¬p ≡.refl)
1-selectʳ ⦃ props ⦄ i t j | no _ | no ¬p = from props (0# is rightZero for *) _
1-sym : ∀ {n} (i j : Fin n) → 1● i j ≈′ 1● j i
1-sym i j with i Fin.≟ j | j Fin.≟ i
1-sym i j | yes _ | yes _ = S.refl
1-sym i j | no _ | no _ = S.refl
1-sym i .i | yes ≡.refl | no ¬q = ⊥-elim (¬q ≡.refl)
1-sym i .i | no ¬p | yes ≡.refl = ⊥-elim (¬p ≡.refl)
⊗-identityˡ :
⦃ props : Has ( 1# is leftIdentity for *
∷ 0# is leftZero for *
∷ 0# is leftIdentity for +
∷ 0# is rightIdentity for +
∷ associative on +
∷ commutative on +
∷ []) ⦄ →
∀ {m n} → ∀ (A : Matrix S m n) → (1● ⊗ A) ≈ A
⊗-identityˡ ⦃ props ⦄ {m} A i k =
begin
∑[ j < m ] (1● i j *′ A j k) ≈⟨ sumₜ-cong (1-selectˡ ⦃ weaken props ⦄ i _) ⟩
sumₜ (Table.select 0′ i (tabulate (λ x → A x k))) ≈⟨ select-sum ⦃ weaken props ⦄ {m} _ ⟩
A i k ∎
where open EqReasoning S.setoid
⊗-identityʳ :
⦃ props : Has ( 1# is rightIdentity for *
∷ 0# is rightZero for *
∷ 0# is leftIdentity for +
∷ 0# is rightIdentity for +
∷ associative on +
∷ commutative on +
∷ []) ⦄ →
∀ {m n} → ∀ (A : Matrix S m n) → (A ⊗ 1●) ≈ A
⊗-identityʳ ⦃ props ⦄ {n = n} A i k =
begin
∑[ j < n ] (A i j *′ 1● j k) ≈⟨ sumₜ-cong (1-selectʳ ⦃ weaken props ⦄ k _) ⟩
sumₜ (Table.select 0′ k (tabulate (A i))) ≈⟨ select-sum ⦃ weaken props ⦄ {n} _ ⟩
A i k ∎
where open EqReasoning S.setoid
⊗-distributesOverˡ-⊕ :
⦃ props : Has (* ⟨ distributesOverˡ ⟩ₚ + ∷ 0# is leftIdentity for + ∷ associative on + ∷ commutative on + ∷ []) ⦄ →
∀ {m n o} (M : Matrix S m n) (A B : Matrix S n o) →
M ⊗ (A ⊕ B) ≈ (M ⊗ A) ⊕ (M ⊗ B)
⊗-distributesOverˡ-⊕ ⦃ props ⦄ {n = n} M A B i k =
begin
∑[ j < n ] (M i j *′ (A j k +′ B j k)) ≈⟨ sumₜ-cong (λ j → from props (* ⟨ distributesOverˡ ⟩ₚ +) (M i j) (A j k) (B j k)) ⟩
∑[ j < n ] (M i j *′ A j k +′ M i j *′ B j k) ≈⟨ S.sym (∑-+′-hom ⦃ weaken props ⦄ n (λ j → M i j *′ A j k) (λ j → M i j *′ B j k)) ⟩
∑[ j < n ] (M i j *′ A j k) +′ ∑[ j < n ] (M i j *′ B j k) ∎
where open EqReasoning S.setoid
| {
"alphanum_fraction": 0.4592215014,
"avg_line_length": 45.2727272727,
"ext": "agda",
"hexsha": "b3ee13ac05c3cd55f8d89f089c2aacdb3e1da46c",
"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": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Matrix/Mul.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"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": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Matrix/Mul.agda",
"max_line_length": 151,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Matrix/Mul.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2980,
"size": 6474
} |
import Parametric.Syntax.Type as Type
import Parametric.Syntax.Term as Term
import Parametric.Syntax.MType as MType
module Parametric.Syntax.MTerm
{Base : Type.Structure}
(Const : Term.Structure Base)
where
open Type.Structure Base
open MType.Structure Base
open Term.Structure Base Const
-- Our extension points are sets of primitives, indexed by the
-- types of their arguments and their return type.
-- We want different types of constants; some produce values, some produce
-- computations. In all cases, arguments are assumed to be values (though
-- individual primitives might require thunks).
ValConstStructure : Set₁
ValConstStructure = ValType → Set
CompConstStructure : Set₁
CompConstStructure = CompType → Set
CbnToCompConstStructure : CompConstStructure → Set
CbnToCompConstStructure CompConst = ∀ {τ} → Const τ → CompConst (cbnToCompType τ)
CbvToCompConstStructure : CompConstStructure → Set
CbvToCompConstStructure CompConst = ∀ {τ} → Const τ → CompConst (cbvToCompType τ)
module
Structure
(ValConst : ValConstStructure) (CompConst : CompConstStructure)
(cbnToCompConst : CbnToCompConstStructure CompConst)
(cbvToCompConst : CbvToCompConstStructure CompConst) where
mutual
-- Analogues of Terms
Vals : ValContext → ValContext → Set
Vals Γ = DependentList (Val Γ)
Comps : ValContext → List CompType → Set
Comps Γ = DependentList (Comp Γ)
data Val Γ : (τ : ValType) → Set where
vVar : ∀ {τ} (x : ValVar Γ τ) → Val Γ τ
-- XXX Do we need thunks? The draft in the paper doesn't have them.
-- However, they will start being useful if we deal with CBN source
-- languages.
vThunk : ∀ {τ} → Comp Γ τ → Val Γ (U τ)
vConst : ∀ {τ} →
(c : ValConst τ) →
Val Γ τ
data Comp Γ : (τ : CompType) → Set where
cConst : ∀ {τ} →
(c : CompConst τ) →
Comp Γ τ
cForce : ∀ {τ} → Val Γ (U τ) → Comp Γ τ
cReturn : ∀ {τ} (v : Val Γ τ) → Comp Γ (F τ)
{-
-- Originally, M to x in N. But here we have no names!
_into_ : ∀ {σ τ} →
(e₁ : Comp Γ (F σ)) →
(e₂ : Comp (σ •• Γ) τ) →
Comp Γ τ
-}
-- The following constructor is the main difference between CBPV and this
-- monadic calculus. This is better for the caching transformation.
_into_ : ∀ {σ τ} →
(e₁ : Comp Γ (F σ)) →
(e₂ : Comp (σ •• Γ) (F τ)) →
Comp Γ (F τ)
cAbs : ∀ {σ τ} →
(t : Comp (σ •• Γ) τ) →
Comp Γ (σ ⇛ τ)
cApp : ∀ {σ τ} →
(s : Comp Γ (σ ⇛ τ)) →
(t : Val Γ σ) →
Comp Γ τ
weaken-val : ∀ {Γ₁ Γ₂ τ} →
(Γ₁≼Γ₂ : Γ₁ ≼≼ Γ₂) →
Val Γ₁ τ →
Val Γ₂ τ
weaken-comp : ∀ {Γ₁ Γ₂ τ} →
(Γ₁≼Γ₂ : Γ₁ ≼≼ Γ₂) →
Comp Γ₁ τ →
Comp Γ₂ τ
weaken-val Γ₁≼Γ₂ (vVar x) = vVar (weaken-val-var Γ₁≼Γ₂ x)
weaken-val Γ₁≼Γ₂ (vThunk x) = vThunk (weaken-comp Γ₁≼Γ₂ x)
weaken-val Γ₁≼Γ₂ (vConst c) = vConst c
weaken-comp Γ₁≼Γ₂ (cConst c) = cConst c
weaken-comp Γ₁≼Γ₂ (cForce x) = cForce (weaken-val Γ₁≼Γ₂ x)
weaken-comp Γ₁≼Γ₂ (cReturn v) = cReturn (weaken-val Γ₁≼Γ₂ v)
weaken-comp Γ₁≼Γ₂ (_into_ {σ} c c₁) = (weaken-comp Γ₁≼Γ₂ c) into (weaken-comp (keep σ •• Γ₁≼Γ₂) c₁)
weaken-comp Γ₁≼Γ₂ (cAbs {σ} c) = cAbs (weaken-comp (keep σ •• Γ₁≼Γ₂) c)
weaken-comp Γ₁≼Γ₂ (cApp s t) = cApp (weaken-comp Γ₁≼Γ₂ s) (weaken-val Γ₁≼Γ₂ t)
fromCBN : ∀ {Γ τ} (t : Term Γ τ) → Comp (fromCBNCtx Γ) (cbnToCompType τ)
fromCBN (const c) = cConst (cbnToCompConst c)
fromCBN (var x) = cForce (vVar (fromVar cbnToValType x))
fromCBN (app s t) = cApp (fromCBN s) (vThunk (fromCBN t))
fromCBN (abs t) = cAbs (fromCBN t)
-- To satisfy termination checking, we'd need to inline fromCBV and weaken: fromCBV needs to produce a term in a bigger context.
-- But let's ignore that.
{-# TERMINATING #-}
fromCBV : ∀ {Γ τ} (t : Term Γ τ) → Comp (fromCBVCtx Γ) (cbvToCompType τ)
fromCBV (const c) = cConst (cbvToCompConst c)
fromCBV (app s t) =
(fromCBV s) into
(fromCBV (weaken (drop _ • ≼-refl) t) into
cApp (cForce (vVar (vThat vThis))) (vVar vThis))
-- Values
fromCBV (var x) = cReturn (vVar (fromVar cbvToValType x))
fromCBV (abs t) = cReturn (vThunk (cAbs (fromCBV t)))
-- This reflects the CBV conversion of values in TLCA '99, but we can't write
-- this because it's partial on the Term type. Instead, we duplicate thunking
-- at the call site.
{-
fromCBVToVal : ∀ {Γ τ} (t : Term Γ τ) → Val (fromCBVCtx Γ) (cbvToValType τ)
fromCBVToVal (var x) = vVar (fromVar cbvToValType x)
fromCBVToVal (abs t) = vThunk (cAbs (fromCBV t))
fromCBVToVal (const c args) = {!!}
fromCBVToVal (app t t₁) = {!!} -- Not a value
-}
| {
"alphanum_fraction": 0.625772098,
"avg_line_length": 34.7777777778,
"ext": "agda",
"hexsha": "9f25c83dad67c732b6c00019e8cdb5ad0a835eb3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Parametric/Syntax/MTerm.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Parametric/Syntax/MTerm.agda",
"max_line_length": 130,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Parametric/Syntax/MTerm.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": 1698,
"size": 4695
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra.Bundles
module Algebra.Properties.Lattice {l₁ l₂} (L : Lattice l₁ l₂) where
open Lattice L
open import Algebra.Structures _≈_
open import Algebra.Definitions _≈_
import Algebra.Properties.Semilattice as SemilatticeProperties
open import Relation.Binary
import Relation.Binary.Lattice as R
open import Relation.Binary.Reasoning.Setoid setoid
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; module Equivalence)
open import Data.Product using (_,_; swap)
------------------------------------------------------------------------
-- _∧_ is a semilattice
∧-idem : Idempotent _∧_
∧-idem x = begin
x ∧ x ≈⟨ ∧-congˡ (sym (∨-absorbs-∧ _ _)) ⟩
x ∧ (x ∨ x ∧ x) ≈⟨ ∧-absorbs-∨ _ _ ⟩
x ∎
∧-isMagma : IsMagma _∧_
∧-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ∧-cong
}
∧-isSemigroup : IsSemigroup _∧_
∧-isSemigroup = record
{ isMagma = ∧-isMagma
; assoc = ∧-assoc
}
∧-isBand : IsBand _∧_
∧-isBand = record
{ isSemigroup = ∧-isSemigroup
; idem = ∧-idem
}
∧-isSemilattice : IsSemilattice _∧_
∧-isSemilattice = record
{ isBand = ∧-isBand
; comm = ∧-comm
}
∧-semilattice : Semilattice l₁ l₂
∧-semilattice = record
{ isSemilattice = ∧-isSemilattice
}
open SemilatticeProperties ∧-semilattice public
using
( ∧-isOrderTheoreticMeetSemilattice
; ∧-isOrderTheoreticJoinSemilattice
; ∧-orderTheoreticMeetSemilattice
; ∧-orderTheoreticJoinSemilattice
)
------------------------------------------------------------------------
-- _∨_ is a semilattice
∨-idem : Idempotent _∨_
∨-idem x = begin
x ∨ x ≈⟨ ∨-congˡ (sym (∧-idem _)) ⟩
x ∨ x ∧ x ≈⟨ ∨-absorbs-∧ _ _ ⟩
x ∎
∨-isMagma : IsMagma _∨_
∨-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = ∨-cong
}
∨-isSemigroup : IsSemigroup _∨_
∨-isSemigroup = record
{ isMagma = ∨-isMagma
; assoc = ∨-assoc
}
∨-isBand : IsBand _∨_
∨-isBand = record
{ isSemigroup = ∨-isSemigroup
; idem = ∨-idem
}
∨-isSemilattice : IsSemilattice _∨_
∨-isSemilattice = record
{ isBand = ∨-isBand
; comm = ∨-comm
}
∨-semilattice : Semilattice l₁ l₂
∨-semilattice = record
{ isSemilattice = ∨-isSemilattice
}
open SemilatticeProperties ∨-semilattice public
using ()
renaming
( ∧-isOrderTheoreticMeetSemilattice to ∨-isOrderTheoreticMeetSemilattice
; ∧-isOrderTheoreticJoinSemilattice to ∨-isOrderTheoreticJoinSemilattice
; ∧-orderTheoreticMeetSemilattice to ∨-orderTheoreticMeetSemilattice
; ∧-orderTheoreticJoinSemilattice to ∨-orderTheoreticJoinSemilattice
)
------------------------------------------------------------------------
-- The dual construction is also a lattice.
∧-∨-isLattice : IsLattice _∧_ _∨_
∧-∨-isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ∧-comm
; ∨-assoc = ∧-assoc
; ∨-cong = ∧-cong
; ∧-comm = ∨-comm
; ∧-assoc = ∨-assoc
; ∧-cong = ∨-cong
; absorptive = swap absorptive
}
∧-∨-lattice : Lattice _ _
∧-∨-lattice = record
{ isLattice = ∧-∨-isLattice
}
------------------------------------------------------------------------
-- Every algebraic lattice can be turned into an order-theoretic one.
open SemilatticeProperties ∧-semilattice public using (poset)
open Poset poset using (_≤_; isPartialOrder)
∨-∧-isOrderTheoreticLattice : R.IsLattice _≈_ _≤_ _∨_ _∧_
∨-∧-isOrderTheoreticLattice = record
{ isPartialOrder = isPartialOrder
; supremum = supremum
; infimum = infimum
}
where
open R.MeetSemilattice ∧-orderTheoreticMeetSemilattice using (infimum)
open R.JoinSemilattice ∨-orderTheoreticJoinSemilattice using (x≤x∨y; y≤x∨y; ∨-least)
renaming (_≤_ to _≤′_)
-- An alternative but equivalent interpretation of the order _≤_.
sound : ∀ {x y} → x ≤′ y → x ≤ y
sound {x} {y} y≈y∨x = sym $ begin
x ∧ y ≈⟨ ∧-congˡ y≈y∨x ⟩
x ∧ (y ∨ x) ≈⟨ ∧-congˡ (∨-comm y x) ⟩
x ∧ (x ∨ y) ≈⟨ ∧-absorbs-∨ x y ⟩
x ∎
complete : ∀ {x y} → x ≤ y → x ≤′ y
complete {x} {y} x≈x∧y = sym $ begin
y ∨ x ≈⟨ ∨-congˡ x≈x∧y ⟩
y ∨ (x ∧ y) ≈⟨ ∨-congˡ (∧-comm x y) ⟩
y ∨ (y ∧ x) ≈⟨ ∨-absorbs-∧ y x ⟩
y ∎
supremum : R.Supremum _≤_ _∨_
supremum x y =
sound (x≤x∨y x y) ,
sound (y≤x∨y x y) ,
λ z x≤z y≤z → sound (∨-least (complete x≤z) (complete y≤z))
∨-∧-orderTheoreticLattice : R.Lattice _ _ _
∨-∧-orderTheoreticLattice = record
{ isLattice = ∨-∧-isOrderTheoreticLattice
}
------------------------------------------------------------------------
-- One can replace the underlying equality with an equivalent one.
replace-equality : {_≈′_ : Rel Carrier l₂} →
(∀ {x y} → x ≈ y ⇔ (x ≈′ y)) → Lattice _ _
replace-equality {_≈′_} ≈⇔≈′ = record
{ _≈_ = _≈′_
; _∧_ = _∧_
; _∨_ = _∨_
; isLattice = record
{ isEquivalence = record
{ refl = to ⟨$⟩ refl
; sym = λ x≈y → to ⟨$⟩ sym (from ⟨$⟩ x≈y)
; trans = λ x≈y y≈z → to ⟨$⟩ trans (from ⟨$⟩ x≈y) (from ⟨$⟩ y≈z)
}
; ∨-comm = λ x y → to ⟨$⟩ ∨-comm x y
; ∨-assoc = λ x y z → to ⟨$⟩ ∨-assoc x y z
; ∨-cong = λ x≈y u≈v → to ⟨$⟩ ∨-cong (from ⟨$⟩ x≈y) (from ⟨$⟩ u≈v)
; ∧-comm = λ x y → to ⟨$⟩ ∧-comm x y
; ∧-assoc = λ x y z → to ⟨$⟩ ∧-assoc x y z
; ∧-cong = λ x≈y u≈v → to ⟨$⟩ ∧-cong (from ⟨$⟩ x≈y) (from ⟨$⟩ u≈v)
; absorptive = (λ x y → to ⟨$⟩ ∨-absorbs-∧ x y)
, (λ x y → to ⟨$⟩ ∧-absorbs-∨ x y)
}
} where open module E {x y} = Equivalence (≈⇔≈′ {x} {y})
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
∧-idempotent = ∧-idem
{-# WARNING_ON_USAGE ∧-idempotent
"Warning: ∧-idempotent was deprecated in v1.1.
Please use ∧-idem instead."
#-}
∨-idempotent = ∨-idem
{-# WARNING_ON_USAGE ∨-idempotent
"Warning: ∨-idempotent was deprecated in v1.1.
Please use ∨-idem instead."
#-}
isOrderTheoreticLattice = ∨-∧-isOrderTheoreticLattice
{-# WARNING_ON_USAGE isOrderTheoreticLattice
"Warning: isOrderTheoreticLattice was deprecated in v1.1.
Please use ∨-∧-isOrderTheoreticLattice instead."
#-}
orderTheoreticLattice = ∨-∧-orderTheoreticLattice
{-# WARNING_ON_USAGE orderTheoreticLattice
"Warning: orderTheoreticLattice was deprecated in v1.1.
Please use ∨-∧-orderTheoreticLattice instead."
#-}
| {
"alphanum_fraction": 0.5540619521,
"avg_line_length": 28.8776371308,
"ext": "agda",
"hexsha": "f29a552778e18411c64cfe3514e15d48a86f142c",
"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/Algebra/Properties/Lattice.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/Algebra/Properties/Lattice.agda",
"max_line_length": 86,
"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/Algebra/Properties/Lattice.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": 2566,
"size": 6844
} |
postulate
A : Set
works : Set
works = let B : {X : Set} → Set
B = let _ = Set in A
in A
fails : Set
fails = let B : {X : Set} → Set
B = A -- Set !=< {X : Set} → Set
in A
| {
"alphanum_fraction": 0.4147465438,
"avg_line_length": 15.5,
"ext": "agda",
"hexsha": "bc2e081bca9d14c6ee67095a8484c60b64a5d52c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue4131.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue4131.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue4131.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": 78,
"size": 217
} |
{-# OPTIONS --safe #-}
module Cubical.Data.Int.MoreInts.DiffInt where
open import Cubical.Data.Int.MoreInts.DiffInt.Base public
open import Cubical.Data.Int.MoreInts.DiffInt.Properties public
| {
"alphanum_fraction": 0.8031088083,
"avg_line_length": 32.1666666667,
"ext": "agda",
"hexsha": "66354a320c048b78ad338f90f81aedf9c9d8bc5f",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Data/Int/MoreInts/DiffInt.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Data/Int/MoreInts/DiffInt.agda",
"max_line_length": 63,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Data/Int/MoreInts/DiffInt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 45,
"size": 193
} |
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Weight biased leftist tree that proves both priority and rank --
-- invariants and uses single-pass merging algorithm. --
----------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module SinglePassMerge.CombinedProofs where
open import Basics
open import TwoPassMerge.RankProof
using ( makeT-lemma )
renaming ( proof-1 to proof-1a; proof-2 to proof-2a )
open import SinglePassMerge.RankProof
using ( proof-1b; proof-2b )
open import Sized
data Heap : {i : Size} → Priority → Rank → Set where
empty : {i : Size} {b : Priority} → Heap {↑ i} b zero
node : {i : Size} {b : Priority} → (p : Priority) → p ≥ b → {l r : Rank} →
l ≥ r → Heap {i} p l → Heap {i} p r → Heap {↑ i} b (suc (l + r))
-- Here we combined previously conducted proofs of rank and priority
-- invariants in the same way we did it for two-pass merging algorithm
-- in TwoPassMerge.CombinedProofs. The most important thing here is
-- that we use order function both when comparing priorities and ranks
-- of new subtrees. This gives us evidence that required invariants
-- hold.
merge : {i j : Size} {b : Priority} {l r : Rank} → Heap {i} b l → Heap {j} b r
→ Heap {∞} b (l + r)
merge empty h2 = h2
merge {_} .{_} {b} {suc l} {zero} h1 empty
= subst (Heap b)
(sym (+0 (suc l)))
h1
merge .{_} .{_} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {_} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {_} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
with order p1 p2
| order l1-rank (r1-rank + suc (l2-rank + r2-rank))
| order l2-rank (r2-rank + suc (l1-rank + r1-rank))
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i}.{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| le p1≤p2
| ge l1≥r1+h2
| _
= subst (Heap b)
(proof-1a l1-rank r1-rank l2-rank r2-rank)
(node p1 p1≥b l1≥r1+h2 l1 (merge r1 (node p2 p1≤p2 l2≥r2 l2 r2)))
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| le p1≤p2
| le l1≤r1+h2
| _
= subst (Heap b)
(proof-1b l1-rank r1-rank l2-rank r2-rank)
(node p1 p1≥b l1≤r1+h2 (merge r1 (node p2 p1≤p2 l2≥r2 l2 r2)) l1)
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| ge p1≥p2
| _
| ge l2≥r2+h1
= subst (Heap b)
(proof-2a l1-rank r1-rank l2-rank r2-rank)
(node p2 p2≥b l2≥r2+h1 l2 (merge r2 (node p1 p1≥p2 l1≥r1 l1 r1)))
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| ge p1≥p2
| _
| le l2≤r2+h1
= subst (Heap b)
(proof-2b l1-rank r1-rank l2-rank r2-rank)
(node p2 p2≥b l2≤r2+h1 (merge r2 (node p1 p1≥p2 l1≥r1 l1 r1)) l2)
| {
"alphanum_fraction": 0.52597226,
"avg_line_length": 44.8414634146,
"ext": "agda",
"hexsha": "755fdb68572a5172e0ff215de410938aa9cb79a4",
"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": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/SinglePassMerge/CombinedProofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"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": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/SinglePassMerge/CombinedProofs.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/SinglePassMerge/CombinedProofs.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 1533,
"size": 3677
} |
module PiQ.Examples where
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Data.Maybe
open import Data.Nat
open import Data.Nat.Properties
open import Relation.Binary.PropositionalEquality
open import PiQ.Syntax
open import PiQ.Opsem
open import PiQ.Eval
open import PiQ.Interp
-----------------------------------------------------------------------------
-- Patterns and data definitions
pattern 𝔹 = 𝟙 +ᵤ 𝟙
pattern 𝔽 = inj₁ tt
pattern 𝕋 = inj₂ tt
𝔹+ : ℕ → 𝕌
𝔹+ 0 = 𝟘
𝔹+ 1 = 𝔹
𝔹+ (suc (suc n)) = 𝔹 +ᵤ (𝔹+ (suc n))
𝔹^ : ℕ → 𝕌
𝔹^ 0 = 𝟙
𝔹^ 1 = 𝔹
𝔹^ (suc (suc n)) = 𝔹 ×ᵤ 𝔹^ (suc n)
𝔹* : ℕ → 𝕌
𝔹* n = 𝔹^ (1 + n)
𝔽^ : (n : ℕ) → ⟦ 𝔹^ n ⟧
𝔽^ 0 = tt
𝔽^ 1 = 𝔽
𝔽^ (suc (suc n)) = 𝔽 , 𝔽^ (suc n)
-----------------------------------------------------------------------------
-- Adaptors
[A+B]+C=[C+B]+A : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (C +ᵤ B) +ᵤ A
[A+B]+C=[C+B]+A = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ swap₊
[A+B]+C=[A+C]+B : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (A +ᵤ C) +ᵤ B
[A+B]+C=[A+C]+B = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ assocl₊
[A+B]+[C+D]=[A+C]+[B+D] : {A B C D : 𝕌} →
(A +ᵤ B) +ᵤ (C +ᵤ D) ↔ (A +ᵤ C) +ᵤ (B +ᵤ D)
[A+B]+[C+D]=[A+C]+[B+D] = assocl₊ ⨾ (assocr₊ ⊕ id↔) ⨾ ((id↔ ⊕ swap₊) ⊕ id↔) ⨾ (assocl₊ ⊕ id↔) ⨾ assocr₊
Ax[BxC]=Bx[AxC] : {A B C : 𝕌} → A ×ᵤ (B ×ᵤ C) ↔ B ×ᵤ (A ×ᵤ C)
Ax[BxC]=Bx[AxC] = assocl⋆ ⨾ (swap⋆ ⊗ id↔) ⨾ assocr⋆
[AxB]×C=[A×C]xB : ∀ {A B C} → (A ×ᵤ B) ×ᵤ C ↔ (A ×ᵤ C) ×ᵤ B
[AxB]×C=[A×C]xB = assocr⋆ ⨾ (id↔ ⊗ swap⋆) ⨾ assocl⋆
[A×B]×[C×D]=[A×C]×[B×D] : {A B C D : 𝕌} → (A ×ᵤ B) ×ᵤ (C ×ᵤ D) ↔ (A ×ᵤ C) ×ᵤ (B ×ᵤ D)
[A×B]×[C×D]=[A×C]×[B×D] = assocl⋆ ⨾ (assocr⋆ ⊗ id↔) ⨾ ((id↔ ⊗ swap⋆) ⊗ id↔) ⨾ (assocl⋆ ⊗ id↔) ⨾ assocr⋆
-- FST2LAST(b₁,b₂,…,bₙ) = (b₂,…,bₙ,b₁)
FST2LAST : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
FST2LAST {0} = id↔
FST2LAST {1} = id↔
FST2LAST {2} = swap⋆
FST2LAST {suc (suc (suc n))} = Ax[BxC]=Bx[AxC] ⨾ (id↔ ⊗ FST2LAST)
FST2LAST⁻¹ : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
FST2LAST⁻¹ = ! FST2LAST
-----------------------------------------------------------------------------
-- Reversible Conditionals
-- not(b) = ¬b
NOT : 𝔹 ↔ 𝔹
NOT = swap₊
-- cnot(b₁,b₂) = (b₁,b₁ xor b₂)
CNOT : 𝔹 ×ᵤ 𝔹 ↔ 𝔹 ×ᵤ 𝔹
CNOT = dist ⨾ (id↔ ⊕ (id↔ ⊗ swap₊)) ⨾ factor
-- CIF(c₁,c₂)(𝔽,a) = (𝔽,c₁ a)
-- CIF(c₁,c₂)(𝕋,a) = (𝕋,c₂ a)
CIF : {A : 𝕌} → (c₁ c₂ : A ↔ A) → 𝔹 ×ᵤ A ↔ 𝔹 ×ᵤ A
CIF c₁ c₂ = dist ⨾ ((id↔ ⊗ c₁) ⊕ (id↔ ⊗ c₂)) ⨾ factor
CIF₁ CIF₂ : {A : 𝕌} → (c : A ↔ A) → 𝔹 ×ᵤ A ↔ 𝔹 ×ᵤ A
CIF₁ c = CIF c id↔
CIF₂ c = CIF id↔ c
-- toffoli(b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (b₁ ∧ … ∧ bₙ))
TOFFOLI : {n : ℕ} → 𝔹^ n ↔ 𝔹^ n
TOFFOLI {0} = id↔
TOFFOLI {1} = swap₊
TOFFOLI {suc (suc n)} = CIF₂ TOFFOLI
-- TOFFOLI(b₁,…,bₙ,b) = (b₁,…,bₙ,b xor (¬b₁ ∧ … ∧ ¬bₙ))
TOFFOLI' : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
TOFFOLI' {0} = id↔
TOFFOLI' {1} = swap₊
TOFFOLI' {suc (suc n)} = CIF₁ TOFFOLI'
-- reset(b₁,b₂,…,bₙ) = (b₁ xor (b₂ ∨ … ∨ bₙ),b₂,…,bₙ)
RESET : ∀ {n} → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
RESET {0} = id↔
RESET {1} = swap⋆ ⨾ CNOT ⨾ swap⋆
RESET {suc (suc n)} = Ax[BxC]=Bx[AxC] ⨾ CIF RESET (swap₊ ⊗ id↔) ⨾ Ax[BxC]=Bx[AxC]
-----------------------------------------------------------------------------
-- Reversible Copy
-- copy(𝔽,b₁,…,bₙ) = (b₁,b₁,…,bₙ)
COPY : ∀ {n} → 𝔹 ×ᵤ 𝔹^ n ↔ 𝔹 ×ᵤ 𝔹^ n
COPY {0} = id↔
COPY {1} = swap⋆ ⨾ CNOT ⨾ swap⋆
COPY {suc (suc n)} = assocl⋆ ⨾ (COPY {1} ⊗ id↔) ⨾ assocr⋆
-----------------------------------------------------------------------------
-- Arithmetic
-- incr(b̅) = incr(b̅ + 1)
INCR : ∀ {n} → 𝔹^ n ↔ 𝔹^ n
INCR {0} = id↔
INCR {1} = swap₊
INCR {suc (suc n)} = (id↔ ⊗ INCR) ⨾ FST2LAST ⨾ TOFFOLI' ⨾ FST2LAST⁻¹
-----------------------------------------------------------------------------
-- Control flow
zigzag : 𝔹 ↔ 𝔹
zigzag = uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ [A+B]+C=[C+B]+A ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l
zigzagₜᵣ = evalₜᵣ zigzag 𝔽
-----------------------------------------------------------------------------
-- Iteration
trace₊ : ∀ {A B C} → A +ᵤ C ↔ B +ᵤ C → A ↔ B
trace₊ f = uniti₊r ⨾ (id↔ ⊕ η₊) ⨾ assocl₊ ⨾ (f ⊕ id↔) ⨾ assocr₊ ⨾ (id↔ ⊕ ε₊) ⨾ unite₊r
-----------------------------------------------------------------------------
-- Ancilla Management
trace⋆ : ∀ {A B C} → (c : ⟦ C ⟧) → A ×ᵤ C ↔ B ×ᵤ C → A ↔ B
trace⋆ c f = uniti⋆r ⨾ (id↔ ⊗ ηₓ c) ⨾ assocl⋆ ⨾
(f ⊗ id↔) ⨾
assocr⋆ ⨾ (id↔ ⊗ εₓ _) ⨾ unite⋆r
-----------------------------------------------------------------------------
-- Higher-Order Combinators
hof- : {A B : 𝕌} → (A ↔ B) → (𝟘 ↔ - A +ᵤ B)
hof- c = η₊ ⨾ (c ⊕ id↔) ⨾ swap₊
comp- : {A B C : 𝕌} → (- A +ᵤ B) +ᵤ (- B +ᵤ C) ↔ (- A +ᵤ C)
comp- = assocl₊ ⨾ (assocr₊ ⊕ id↔) ⨾ ((id↔ ⊕ ε₊) ⊕ id↔) ⨾ (unite₊r ⊕ id↔)
app- : {A B : 𝕌} → (- A +ᵤ B) +ᵤ A ↔ B
app- = swap₊ ⨾ assocl₊ ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l
curry- : {A B C : 𝕌} → (A +ᵤ B ↔ C) → (A ↔ - B +ᵤ C)
curry- c = uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ swap₊ ⨾ assocl₊ ⨾ (c ⊕ id↔) ⨾ swap₊
hof/ : {A B : 𝕌} → (A ↔ B) → (v : ⟦ A ⟧) → (𝟙 ↔ 𝟙/ v ×ᵤ B)
hof/ c v = ηₓ v ⨾ (c ⊗ id↔) ⨾ swap⋆
comp/ : {A B C : 𝕌} {v : ⟦ A ⟧} → (w : ⟦ B ⟧) →
(𝟙/ v ×ᵤ B) ×ᵤ (𝟙/ w ×ᵤ C) ↔ (𝟙/ v ×ᵤ C)
comp/ w = assocl⋆ ⨾ (assocr⋆ ⊗ id↔) ⨾ ((id↔ ⊗ εₓ w) ⊗ id↔) ⨾ (unite⋆r ⊗ id↔)
app/ : {A B : 𝕌} → (v : ⟦ A ⟧) → (𝟙/ v ×ᵤ B) ×ᵤ A ↔ B
app/ v = swap⋆ ⨾ assocl⋆ ⨾ (εₓ _ ⊗ id↔) ⨾ unite⋆l
curry/ : {A B C : 𝕌} → (A ×ᵤ B ↔ C) → (v : ⟦ B ⟧) → (A ↔ 𝟙/ v ×ᵤ C)
curry/ c v = uniti⋆l ⨾ (ηₓ v ⊗ id↔) ⨾ swap⋆ ⨾ assocl⋆ ⨾ (c ⊗ id↔) ⨾ swap⋆
-----------------------------------------------------------------------------
-- Algebraic Identities
inv- : {A : 𝕌} → A ↔ - (- A)
inv- = uniti₊r ⨾ (id↔ ⊕ η₊) ⨾ assocl₊ ⨾ (ε₊ ⊕ id↔) ⨾ unite₊l
dist- : {A B : 𝕌} → - (A +ᵤ B) ↔ - A +ᵤ - B
dist- =
uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ uniti₊l ⨾ (η₊ ⊕ id↔) ⨾ assocl₊ ⨾
([A+B]+[C+D]=[A+C]+[B+D] ⊕ id↔) ⨾
(swap₊ ⊕ id↔) ⨾ assocr₊ ⨾ (id↔ ⊕ ε₊) ⨾ unite₊r
neg- : {A B : 𝕌} → (A ↔ B) → (- A ↔ - B)
neg- c =
uniti₊r ⨾ (id↔ ⊕ η₊) ⨾
(id↔ ⊕ ! c ⊕ id↔) ⨾ assocl₊ ⨾
((swap₊ ⨾ ε₊) ⊕ id↔) ⨾ unite₊l
inv/ : {A : 𝕌} {v : ⟦ A ⟧} → A ↔ (𝟙/_ {𝟙/ v} ↻)
inv/ = uniti⋆r ⨾ (id↔ ⊗ ηₓ _) ⨾ assocl⋆ ⨾ (εₓ _ ⊗ id↔) ⨾ unite⋆l
dist/ : {A B : 𝕌} {a : ⟦ A ⟧} {b : ⟦ B ⟧} → 𝟙/ (a , b) ↔ 𝟙/ a ×ᵤ 𝟙/ b
dist/ {A} {B} {a} {b} =
uniti⋆l ⨾ (ηₓ b ⊗ id↔) ⨾ uniti⋆l ⨾ (ηₓ a ⊗ id↔) ⨾ assocl⋆ ⨾
([A×B]×[C×D]=[A×C]×[B×D] ⊗ id↔) ⨾
(swap⋆ ⊗ id↔) ⨾ assocr⋆ ⨾ (id↔ ⊗ εₓ (a , b)) ⨾ unite⋆r
neg/ : {A B : 𝕌} {a : ⟦ A ⟧} {b : ⟦ B ⟧} → (A ↔ B) → (𝟙/ a ↔ 𝟙/ b)
neg/ {A} {B} {a} {b} c =
uniti⋆r ⨾ (id↔ ⊗ ηₓ _) ⨾
(id↔ ⊗ ! c ⊗ id↔) ⨾ assocl⋆ ⨾
((swap⋆ ⨾ εₓ _) ⊗ id↔) ⨾ unite⋆l
dist×- : {A B : 𝕌} → (- A) ×ᵤ B ↔ - (A ×ᵤ B)
dist×- =
uniti₊r ⨾ (id↔ ⊕ η₊) ⨾ assocl₊ ⨾
((factor ⨾ ((swap₊ ⨾ ε₊) ⊗ id↔) ⨾ absorbr) ⊕ id↔) ⨾
unite₊l
neg× : {A B : 𝕌} → A ×ᵤ B ↔ (- A) ×ᵤ (- B)
neg× = inv- ⨾ neg- (! dist×- ⨾ swap⋆) ⨾ ! dist×- ⨾ swap⋆
fracDist : ∀ {A B} {a : ⟦ A ⟧} {b : ⟦ B ⟧} → 𝟙/ a ×ᵤ 𝟙/ b ↔ 𝟙/ (a , b)
fracDist =
uniti⋆l ⨾ ((ηₓ _ ⨾ swap⋆) ⊗ id↔) ⨾ assocr⋆ ⨾
(id↔ ⊗ ([A×B]×[C×D]=[A×C]×[B×D] ⨾ (εₓ _ ⊗ εₓ _) ⨾ unite⋆l)) ⨾ unite⋆r
mulFrac : ∀ {A B C D} {b : ⟦ B ⟧} {d : ⟦ D ⟧}
→ (A ×ᵤ 𝟙/ b) ×ᵤ (C ×ᵤ 𝟙/ d) ↔ (A ×ᵤ C) ×ᵤ (𝟙/ (b , d))
mulFrac = [A×B]×[C×D]=[A×C]×[B×D] ⨾ (id↔ ⊗ fracDist)
addFracCom : ∀ {A B C} {v : ⟦ C ⟧}
→ (A ×ᵤ 𝟙/ v) +ᵤ (B ×ᵤ 𝟙/ v) ↔ (A +ᵤ B) ×ᵤ (𝟙/ v)
addFracCom = factor
addFrac : ∀ {A B C D} → (v : ⟦ C ⟧) → (w : ⟦ D ⟧)
→ (A ×ᵤ 𝟙/_ {C} v) +ᵤ (B ×ᵤ 𝟙/_ {D} w) ↔
((A ×ᵤ D) +ᵤ (C ×ᵤ B)) ×ᵤ (𝟙/_ {C ×ᵤ D} (v , w))
addFrac v w = ((uniti⋆r ⨾ (id↔ ⊗ ηₓ w)) ⊕ (uniti⋆l ⨾ (ηₓ v ⊗ id↔))) ⨾
[A×B]×[C×D]=[A×C]×[B×D] ⊕ [A×B]×[C×D]=[A×C]×[B×D] ⨾
((id↔ ⊗ fracDist) ⊕ (id↔ ⊗ fracDist)) ⨾ factor
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
| {
"alphanum_fraction": 0.379590766,
"avg_line_length": 32.1687763713,
"ext": "agda",
"hexsha": "dde3057f6866d5d19e73f5f5e66251b3a796928f",
"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": "PiQ/Examples.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": "PiQ/Examples.agda",
"max_line_length": 103,
"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": "PiQ/Examples.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": 4617,
"size": 7624
} |
{-# OPTIONS -v treeless.opt:20 -v treeless.opt.unused:30 #-}
module _ where
open import Common.Prelude
-- First four arguments are unused.
maybe : ∀ {a b} {A : Set a} {B : Set b} → B → (A → B) → Maybe A → B
maybe z f nothing = z
maybe z f (just x) = f x
mapMaybe : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → Maybe A → Maybe B
mapMaybe f x = maybe nothing (λ y → just (f y)) x
maybeToNat : Maybe Nat → Nat
maybeToNat m = maybe 0 (λ x → x) m
foldr : {A B : Set} → (A → B → B) → B → List A → B
foldr f z [] = z
foldr f z (x ∷ xs) = f x (foldr f z xs)
main : IO Unit
main = printNat (maybeToNat (just 42))
,, printNat (maybeToNat (mapMaybe (10 +_) (just 42)))
,, printNat (foldr _+_ 0 (1 ∷ 2 ∷ 3 ∷ 4 ∷ []))
| {
"alphanum_fraction": 0.5674547983,
"avg_line_length": 27.6538461538,
"ext": "agda",
"hexsha": "5bddf3f5f48c134a09c25de1909b4f2a4e002c87",
"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/Compiler/simple/UnusedArguments.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/Compiler/simple/UnusedArguments.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/Compiler/simple/UnusedArguments.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": 283,
"size": 719
} |
open import Agda.Builtin.Nat
data D : Nat → Set where
c : (n : Nat) → D n
foo : (m : Nat) → D (suc m) → Nat
foo m (c (suc n)) = m + n
| {
"alphanum_fraction": 0.5289855072,
"avg_line_length": 17.25,
"ext": "agda",
"hexsha": "847b9d231c20943d05d01c298bedda93aa0603e9",
"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/Issue2896.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/Issue2896.agda",
"max_line_length": 33,
"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/Issue2896.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": 138
} |
open import Agda.Builtin.Char
open import Agda.Builtin.List
open import Agda.Builtin.Equality
data ⊥ : Set where
infix 4 _≢_
_≢_ : {A : Set} → A → A → Set
x ≢ y = x ≡ y → ⊥
<?> = '\xFFFD'
infix 0 _∋_
_∋_ : (A : Set) → A → A
A ∋ x = x
_ = primNatToChar 0xD7FF ≢ <?> ∋ λ ()
_ = primNatToChar 0xD800 ≡ <?> ∋ refl
_ = primNatToChar 0xDFFF ≡ <?> ∋ refl
_ = primNatToChar 0xE000 ≢ <?> ∋ λ ()
| {
"alphanum_fraction": 0.5816326531,
"avg_line_length": 17.8181818182,
"ext": "agda",
"hexsha": "5b2d3bf93c4cf9762554e09866ce043bfc98e91d",
"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/Issue4999.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/Issue4999.agda",
"max_line_length": 37,
"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/Issue4999.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": 180,
"size": 392
} |
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
data Irr (A : Set) : Set where
irr : .(x : A) → Irr A
data D {A : Set} : Irr A → Set where
-- x is mistakenly marked as forced here!
d : (x : A) → D (irr x)
unD : ∀ {A i} → D i → A
unD (d x) = x
dtrue=dfalse : d true ≡ d false
dtrue=dfalse = refl
_$≡_ : ∀ {A B : Set} (f : A → B) {x y} → x ≡ y → f x ≡ f y
f $≡ refl = refl
true=false : true ≡ false
true=false = unD $≡ dtrue=dfalse
data ⊥ : Set where
loop : ⊥
loop with true=false
... | ()
| {
"alphanum_fraction": 0.5664739884,
"avg_line_length": 17.8965517241,
"ext": "agda",
"hexsha": "a3398c2e89acb26418ba7d04f606356ed2b4b2f2",
"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/Fail/Issue2819.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/Fail/Issue2819.agda",
"max_line_length": 58,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue2819.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 208,
"size": 519
} |
open import Numeral.Natural
open import Relator.Equals
open import Type.Properties.Decidable
open import Type
module Formalization.ClassicalPredicateLogic.Syntax.Substitution
{ℓₚ ℓᵥ ℓₒ}
(Prop : ℕ → Type{ℓₚ})
(Var : Type{ℓᵥ}) ⦃ var-eq-dec : Decidable(2)(_≡_ {T = Var}) ⦄
(Obj : ℕ → Type{ℓₒ})
where
open import Data.Boolean
open import Data.ListSized
import Data.ListSized.Functions as List
open import Formalization.ClassicalPredicateLogic.Syntax(Prop)(Var)(Obj)
private variable n : ℕ
substituteTerm : Var → Term → Term → Term
substituteTerm₊ : Var → Term → List(Term)(n) → List(Term)(n)
substituteTerm v t (var x) = if(decide(2)(_≡_) v x) then t else (var x)
substituteTerm v t (func f x) = func f (substituteTerm₊ v t x)
substituteTerm₊ {0} v t ∅ = ∅
substituteTerm₊ {𝐒(n)} v t (x ⊰ xs) = (substituteTerm v t x ⊰ substituteTerm₊ {n} v t xs)
substitute : Var → Term → Formula → Formula
substitute v t (f $ x) = f $ List.map (substituteTerm v t) x
substitute v t ⊤ = ⊤
substitute v t ⊥ = ⊥
substitute v t (φ ∧ ψ) = (substitute v t φ) ∧ (substitute v t ψ)
substitute v t (φ ∨ ψ) = (substitute v t φ) ∨ (substitute v t ψ)
substitute v t (φ ⟶ ψ) = (substitute v t φ) ⟶ (substitute v t ψ)
substitute v t (Ɐ(x) φ) = Ɐ(x) (if(decide(2)(_≡_) v x) then φ else (substitute v t φ))
substitute v t (∃(x) φ) = ∃(x) (if(decide(2)(_≡_) v x) then φ else (substitute v t φ))
| {
"alphanum_fraction": 0.654854713,
"avg_line_length": 39.1944444444,
"ext": "agda",
"hexsha": "7a2eba2db5c6ce1e6e4e83af40239c6f839c3e3a",
"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": "Formalization/ClassicalPredicateLogic/Syntax/Substitution.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": "Formalization/ClassicalPredicateLogic/Syntax/Substitution.agda",
"max_line_length": 89,
"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": "Formalization/ClassicalPredicateLogic/Syntax/Substitution.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": 535,
"size": 1411
} |
-- The (pre)category of (small) categories
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Categories where
open import Cubical.Categories.Category.Base
open import Cubical.Categories.Category.Precategory
open import Cubical.Categories.Functor.Base
open import Cubical.Categories.Functor.Properties
open import Cubical.Foundations.Prelude
module _ (ℓ ℓ' : Level) where
open Precategory
CatPrecategory : Precategory (ℓ-suc (ℓ-max ℓ ℓ')) (ℓ-max ℓ ℓ')
CatPrecategory .ob = Category ℓ ℓ'
CatPrecategory .Hom[_,_] = Functor
CatPrecategory .id = 𝟙⟨ _ ⟩
CatPrecategory ._⋆_ G H = H ∘F G
CatPrecategory .⋆IdL _ = F-lUnit
CatPrecategory .⋆IdR _ = F-rUnit
CatPrecategory .⋆Assoc _ _ _ = F-assoc
-- TODO: what is required for Functor C D to be a set?
| {
"alphanum_fraction": 0.7367741935,
"avg_line_length": 29.8076923077,
"ext": "agda",
"hexsha": "7ce6b89a2f4696ebfd9a672c98a2e20608ad9c18",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/Categories.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/Categories.agda",
"max_line_length": 64,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/Categories.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 246,
"size": 775
} |
{-# OPTIONS --without-K #-}
module Pi0Semiring where
import Level
open import PiU
open import PiLevel0
open import Algebra using (CommutativeSemiring)
open import Algebra.Structures
using (IsSemigroup; IsCommutativeMonoid; IsCommutativeSemiring)
------------------------------------------------------------------------------
-- Commutative semiring structure of U
typesPlusIsSG : IsSemigroup _⟷_ PLUS
typesPlusIsSG = record {
isEquivalence = record { refl = id⟷ ; sym = ! ; trans = _◎_ } ;
assoc = λ t₁ t₂ t₃ → assocr₊ {t₁} {t₂} {t₃} ;
∙-cong = _⊕_
}
typesTimesIsSG : IsSemigroup _⟷_ TIMES
typesTimesIsSG = record {
isEquivalence = record { refl = id⟷ ; sym = ! ; trans = _◎_ } ;
assoc = λ t₁ t₂ t₃ → assocr⋆ {t₁} {t₂} {t₃} ;
∙-cong = _⊗_
}
typesPlusIsCM : IsCommutativeMonoid _⟷_ PLUS ZERO
typesPlusIsCM = record {
isSemigroup = typesPlusIsSG ;
identityˡ = λ t → unite₊l {t} ;
comm = λ t₁ t₂ → swap₊ {t₁} {t₂}
}
typesTimesIsCM : IsCommutativeMonoid _⟷_ TIMES ONE
typesTimesIsCM = record {
isSemigroup = typesTimesIsSG ;
identityˡ = λ t → unite⋆l {t} ;
comm = λ t₁ t₂ → swap⋆ {t₁} {t₂}
}
typesIsCSR : IsCommutativeSemiring _⟷_ PLUS TIMES ZERO ONE
typesIsCSR = record {
+-isCommutativeMonoid = typesPlusIsCM ;
*-isCommutativeMonoid = typesTimesIsCM ;
distribʳ = λ t₁ t₂ t₃ → dist {t₂} {t₃} {t₁} ;
zeroˡ = λ t → absorbr {t}
}
typesCSR : CommutativeSemiring Level.zero Level.zero
typesCSR = record {
Carrier = U ;
_≈_ = _⟷_ ;
_+_ = PLUS ;
_*_ = TIMES ;
0# = ZERO ;
1# = ONE ;
isCommutativeSemiring = typesIsCSR
}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.6021634615,
"avg_line_length": 25.6,
"ext": "agda",
"hexsha": "291624ab2602e7a17b001193f29b65afdfe8bf44",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Pi0Semiring.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Pi0Semiring.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Pi0Semiring.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 582,
"size": 1664
} |
module NF.List {A : Set} where
open import NF
open import Data.List
open import Relation.Binary.PropositionalEquality
instance
nf[] : NF {List A} []
Sing.unpack (NF.!! nf[]) = []
Sing.eq (NF.!! nf[]) = refl
{-# INLINE nf[] #-}
nf∷ : {x : A}{{nfx : NF x}}{t : List A}{{nft : NF t}} -> NF (x ∷ t)
Sing.unpack (NF.!! (nf∷ {x} {t})) = nf x ∷ nf t
Sing.eq (NF.!! (nf∷ {{nfx}} {{nft}})) rewrite nf≡ {{nfx}} | nf≡ {{nft}} = refl
{-# INLINE nf∷ #-} | {
"alphanum_fraction": 0.5249457701,
"avg_line_length": 25.6111111111,
"ext": "agda",
"hexsha": "2ba1bd1af6e2d6adc4c621918f9d85e183c9df6f",
"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": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yanok/normalize-via-instances",
"max_forks_repo_path": "src/NF/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"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": "yanok/normalize-via-instances",
"max_issues_repo_path": "src/NF/List.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yanok/normalize-via-instances",
"max_stars_repo_path": "src/NF/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 181,
"size": 461
} |
module Sessions.Semantics.Process where
open import Level
open import Size
open import Data.Nat
open import Data.Sum
open import Data.Product
open import Data.Unit
open import Data.Bool
open import Debug.Trace
open import Function
open import Relation.Unary hiding (Empty)
open import Relation.Unary.PredicateTransformer using (PT)
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Sessions.Syntax.Types
open import Sessions.Syntax.Values
open import Sessions.Syntax.Expr
open import Sessions.Semantics.Commands
open import Relation.Ternary.Separation
open import Relation.Ternary.Separation.Allstar
open import Relation.Ternary.Separation.Construct.Market
open import Relation.Ternary.Separation.Construct.Product
open import Relation.Ternary.Separation.Morphisms
open import Relation.Ternary.Separation.Monad
open import Relation.Ternary.Separation.Bigstar
open import Relation.Ternary.Separation.Monad.Free Cmd δ as Free hiding (step)
open import Relation.Ternary.Separation.Monad.State
open import Relation.Ternary.Separation.Monad.Error
open Monads using (Monad; str; typed-str)
open Monad {{...}}
data Exc : Set where
outOfFuel : Exc
delay : Exc
open import Sessions.Semantics.Runtime delay
open import Sessions.Semantics.Communication delay
data Thread : Pred RCtx 0ℓ where
forked : ∀[ Comp unit ⇒ Thread ]
main : ∀ {a} → ∀[ Comp a ⇒ Thread ]
Pool : Pred RCtx 0ℓ
Pool = Bigstar Thread
St = Π₂ Pool ✴ Channels
open ExceptMonad {A = RCtx} Exc
open StateWithErr {C = RCtx} Exc
onPool : ∀ {P} → ∀[ (Pool ─✴ Except Exc (P ✴ Pool)) ⇒ State? St P ]
app (onPool f) (lift (snd pool ×⟨ σ , σ₁ ⟩ chs) k) (offerᵣ σ₂) with resplit σ₂ σ₁ k
... | _ , _ , τ₁ , τ₂ , τ₃ =
case app f pool τ₁ of λ where
(error e) → partial (inj₁ e)
(✓ (p ×⟨ σ₃ ⟩ p')) →
let _ , _ , τ₄ , τ₅ , τ₆ = resplit σ₃ τ₂ τ₃
in return (inj p ×⟨ offerᵣ τ₄ ⟩ lift (snd p' ×⟨ σ , τ₅ ⟩ chs) τ₆)
onChannels : ∀ {P} → ∀[ State? Channels P ⇒ State? St P ]
app (onChannels f) μ (offerᵣ σ₃) with ○≺●ᵣ μ
... | inj pool ×⟨ offerᵣ σ₄ ⟩ chs with ⊎-assoc σ₃ (⊎-comm σ₄)
... | _ , τ₁ , τ₂ = do
px ×⟨ σ₄ ⟩ ●chs ×⟨ σ₅ ⟩ inj pool ←
mapM (app f chs (offerᵣ τ₁) &⟨ J Pool ∥ offerₗ τ₂ ⟩ inj pool) ✴-assocᵣ
return (px ×⟨ σ₄ ⟩ app (○≺●ₗ pool) ●chs (⊎-comm σ₅))
enqueue : ∀[ Thread ⇒ State? St Emp ]
enqueue thr =
onPool (wand λ pool σ → return (empty ×⟨ ⊎-idˡ ⟩ (app (append thr) pool σ)))
-- Smart reschedule of a thread:
-- Escalates out-of-fuel erros in threads, and discards terminated workers.
reschedule : ∀[ Thread ⇒ State? St Emp ]
reschedule (forked (partial (pure (inj₁ _)))) = raise outOfFuel
reschedule (forked (partial (pure (inj₂ tt)))) = return empty
reschedule thr@(forked (partial (impure _))) = enqueue thr
reschedule (main (partial (pure (inj₁ _)))) = raise outOfFuel
reschedule thr@(main (partial (pure (inj₂ _)))) = enqueue thr
reschedule thr@(main (partial (impure _))) = enqueue thr
{- Select the next thread that is not done -}
dequeue : ε[ State? St (Emp ∪ Thread) ]
dequeue =
onPool (wandit (λ pool →
case (find isImpure pool) of λ where
(error e) → return (inj₁ empty ×⟨ ⊎-idˡ ⟩ pool)
(✓ (thr ×⟨ σ ⟩ pool')) → return (inj₂ thr ×⟨ σ ⟩ pool')))
where
isImpure : ∀ {Φ} → Thread Φ → Bool
isImpure (main (partial (pure _))) = false
isImpure (main (partial (impure _))) = true
isImpure (forked (partial (pure _))) = false
isImpure (forked (partial (impure _))) = true
module _ where
handle : ∀ {Φ} → (c : Cmd Φ) → State? St (δ c) Φ
handle (fork thr) = trace "handle:fork" $ enqueue (forked thr)
handle (mkchan α) = trace "handle:mkchan" $ onChannels newChan
handle (send (ch ×⟨ σ ⟩ v)) = trace "handle:send" $ onChannels (app (send! ch) v σ)
handle (receive ch) = trace "handle:recv" $ onChannels (receive? ch)
handle (close ch) = trace "handle:close" $ onChannels (closeChan ch)
step : ∀[ Thread ⇒ State? St Thread ]
step thr@(main (partial c)) = do
c' ← Free.step handle c
return (main (partial c'))
step (forked (partial c)) = do
c' ← Free.step handle c
return (forked (partial c'))
-- try the first computation; if it fails with a 'delay' exception,
-- then queue t
_orDelay_ : ∀[ State? St Emp ⇒ Thread ⇒ State? St Emp ]
c orDelay t = do
c orElse λ where
delay → enqueue t
outOfFuel → raise outOfFuel
-- Run a pool of threads in round-robing fashion
-- until all have terminated, or fuel runs out
run : ℕ → ε[ State? St Emp ]
run zero = raise outOfFuel
run (suc n) = do
inj₂ thr ← dequeue
-- if we cannot dequeue a thunked thread, we're done
where (inj₁ e) → return e
-- otherwise we take a step
empty ← trace "run:step" (do thr' ← step thr; enqueue thr') orDelay thr
-- rinse and repeat
run n
start : ℕ → Thread ε → ∃ λ Φ → Except Exc (● St) Φ
start n thr = -, do
let μ = lift (snd [ thr ] ×⟨ ⊎-idʳ ⟩ nil) ⊎-idʳ
inj empty ×⟨ σ ⟩ μ ← app (run n) μ (offerᵣ ⊎-idˡ)
case ⊎-id⁻ˡ σ of λ where
refl → return μ
where open ExceptMonad {A = Market RCtx} Exc
| {
"alphanum_fraction": 0.6486382075,
"avg_line_length": 34.2847682119,
"ext": "agda",
"hexsha": "ef2fadc1fe2fb343cd904db23825f83412f2a1f0",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Sessions/Semantics/Process.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"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": "laMudri/linear.agda",
"max_issues_repo_path": "src/Sessions/Semantics/Process.agda",
"max_line_length": 87,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Sessions/Semantics/Process.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 1738,
"size": 5177
} |
module nat-log where
open import bool
open import eq
open import nat
open import nat-thms
open import nat-division
open import product
data log-result (x : ℕ)(b : ℕ) : Set where
pos-power : (e : ℕ) → (s : ℕ) → b pow e + s ≡ x → log-result x b
no-power : x < b ≡ tt → log-result x b
-- as a first version, we do not try to prove termination of this function
{-# NON_TERMINATING #-}
log : (x : ℕ) → (b : ℕ) → x =ℕ 0 ≡ ff → b =ℕ 0 ≡ ff → log-result x b
log x b p1 p2 with x ÷ b ! p2
log x b p1 p2 | 0 , r , u1 , u2 rewrite u1 = no-power u2
log x b p1 p2 | (suc q) , r , u1 , u2 with log (suc q) b refl p2
log x b p1 p2 | (suc q) , r , u1 , u2 | no-power u rewrite sym u1 =
pos-power 1 (b * q + r) lem
where lem : b * 1 + (b * q + r) ≡ b + q * b + r
lem rewrite *1{b} | *comm b q = +assoc b (q * b) r
log x b p1 p2 | (suc q) , r , u1 , u2 | pos-power e s u rewrite sym u1 =
pos-power (suc e) (b * s + r) lem
where lem : b * b pow e + (b * s + r) ≡ b + q * b + r
lem rewrite +assoc (b * b pow e) (b * s) r | sym (*distribl b (b pow e) s) | *comm b (b pow e + s) =
sym (cong (λ i → i * b + r) (sym u))
| {
"alphanum_fraction": 0.542432196,
"avg_line_length": 38.1,
"ext": "agda",
"hexsha": "0485f8716af69901ed9a257f3b996e0f40ca51a8",
"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": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "nat-log.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"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": "heades/AUGL",
"max_issues_repo_path": "nat-log.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "nat-log.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 468,
"size": 1143
} |
module Data.Vec where
open import Prelude
open import Data.Nat
open import Data.Fin hiding (_==_; _<_)
open import Logic.Structure.Applicative
open import Logic.Identity
open import Logic.Base
infixl 90 _#_
infixr 50 _::_
infixl 45 _!_ _[!]_
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
-- Indexing
_!_ : {n : Nat}{A : Set} -> Vec A n -> Fin n -> A
x :: xs ! fzero = x
x :: xs ! fsuc i = xs ! i
-- Insertion
insert : {n : Nat}{A : Set} -> Fin (suc n) -> A -> Vec A n -> Vec A (suc n)
insert fzero y xs = y :: xs
insert (fsuc i) y (x :: xs) = x :: insert i y xs
-- Index view
data IndexView {A : Set} : {n : Nat}(i : Fin n) -> Vec A n -> Set where
ixV : {n : Nat}{i : Fin (suc n)}(x : A)(xs : Vec A n) ->
IndexView i (insert i x xs)
_[!]_ : {A : Set}{n : Nat}(xs : Vec A n)(i : Fin n) -> IndexView i xs
x :: xs [!] fzero = ixV x xs
x :: xs [!] fsuc i = aux xs i (xs [!] i)
where
aux : {n : Nat}(xs : Vec _ n)(i : Fin n) ->
IndexView i xs -> IndexView (fsuc i) (x :: xs)
aux .(insert i y xs) i (ixV y xs) = ixV y (x :: xs)
-- Build a vector from an indexing function (inverse of _!_)
build : {n : Nat}{A : Set} -> (Fin n -> A) -> Vec A n
build {zero } f = []
build {suc _} f = f fzero :: build (f ∘ fsuc)
-- Constant vectors
vec : {n : Nat}{A : Set} -> A -> Vec A n
vec {zero } _ = []
vec {suc m} x = x :: vec x
-- Vector application
_#_ : {n : Nat}{A B : Set} -> Vec (A -> B) n -> Vec A n -> Vec B n
[] # [] = []
(f :: fs) # (x :: xs) = f x :: fs # xs
-- Vectors of length n form an applicative structure
ApplicativeVec : {n : Nat} -> Applicative (\A -> Vec A n)
ApplicativeVec {n} = applicative (vec {n}) (_#_ {n})
-- Map
map : {n : Nat}{A B : Set} -> (A -> B) -> Vec A n -> Vec B n
map f xs = vec f # xs
-- Zip
zip : {n : Nat}{A B C : Set} -> (A -> B -> C) -> Vec A n -> Vec B n -> Vec C n
zip f xs ys = vec f # xs # ys
module Elem where
infix 40 _∈_ _∉_
data _∈_ {A : Set}(x : A) : {n : Nat}(xs : Vec A n) -> Set where
hd : {n : Nat} {xs : Vec A n} -> x ∈ x :: xs
tl : {n : Nat}{y : A}{xs : Vec A n} -> x ∈ xs -> x ∈ y :: xs
data _∉_ {A : Set}(x : A) : {n : Nat}(xs : Vec A n) -> Set where
nl : x ∉ []
cns : {n : Nat}{y : A}{xs : Vec A n} -> x ≢ y -> x ∉ xs -> x ∉ y :: xs
∉=¬∈ : {A : Set}{x : A}{n : Nat}{xs : Vec A n} -> x ∉ xs -> ¬ (x ∈ xs)
∉=¬∈ nl ()
∉=¬∈ {A} (cns x≠x _) hd = elim-False (x≠x refl)
∉=¬∈ {A} (cns _ ne) (tl e) = ∉=¬∈ ne e
∈=¬∉ : {A : Set}{x : A}{n : Nat}{xs : Vec A n} -> x ∈ xs -> ¬ (x ∉ xs)
∈=¬∉ e ne = ∉=¬∈ ne e
find : {A : Set}{n : Nat} -> ((x y : A) -> x ≡ y \/ x ≢ y) ->
(x : A)(xs : Vec A n) -> x ∈ xs \/ x ∉ xs
find _ _ [] = \/-IR nl
find eq y (x :: xs) = aux x y (eq y x) (find eq y xs) where
aux : forall x y -> y ≡ x \/ y ≢ x -> y ∈ xs \/ y ∉ xs -> y ∈ x :: xs \/ y ∉ x :: xs
aux x .x (\/-IL refl) _ = \/-IL hd
aux x y (\/-IR y≠x) (\/-IR y∉xs) = \/-IR (cns y≠x y∉xs)
aux x y (\/-IR _) (\/-IL y∈xs) = \/-IL (tl y∈xs)
delete : {A : Set}{n : Nat}(x : A)(xs : Vec A (suc n)) -> x ∈ xs -> Vec A n
delete .x (x :: xs) hd = xs
delete {A}{zero } _ ._ (tl ())
delete {A}{suc _} y (x :: xs) (tl p) = x :: delete y xs p
| {
"alphanum_fraction": 0.4665239988,
"avg_line_length": 31.7572815534,
"ext": "agda",
"hexsha": "22a89f05142f5e36c4eabccf0a771db34960c2cc",
"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": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Vec.agda",
"max_line_length": 88,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Vec.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": 1395,
"size": 3271
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of products
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Product.Properties where
open import Data.Product
open import Function using (_∘_)
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (yes; no)
------------------------------------------------------------------------
-- Equality
module _ {a b} {A : Set a} {B : A → Set b} where
,-injectiveˡ : ∀ {a c} {b : B a} {d : B c} → (a , b) ≡ (c , d) → a ≡ c
,-injectiveˡ refl = refl
-- See also Data.Product.Properties.WithK.,-injectiveʳ.
| {
"alphanum_fraction": 0.484496124,
"avg_line_length": 29.7692307692,
"ext": "agda",
"hexsha": "30b954ce2c5ebbf9bec299e6002632cf1b79c11a",
"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/Product/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Product/Properties.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/Product/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 169,
"size": 774
} |
{-# OPTIONS --rewriting --cubical #-}
open import Common.Prelude
open import Common.Path
{-# BUILTIN REWRITE _≡_ #-}
postulate is-refl : ∀ {A : Set} {x : A} → (x ≡ x) → Bool
postulate is-refl-true : ∀ {A}{x} → is-refl {A} {x} refl ≡ true
{-# REWRITE is-refl-true #-}
test₁ : ∀ {x} → is-refl {Nat} {x} refl ≡ true
test₁ = refl
test₂ : is-refl {Nat} (λ _ → 42) ≡ true
test₂ = refl
postulate
Cl : Set
module M (A B C : Set)(f : C -> A)(g : C -> B) where
data PO : Set where
inl : A → PO
inr : B → PO
push : (c : C) → inl (f c) ≡ inr (g c)
-- elimination under clocks
module E (D : (Cl → PO) → Set)
(l : (x : Cl → A) → D (\ k → inl (x k)))
(r : (x : Cl → B) → D (\ k → inr (x k)))
(p : (x : Cl → C) → PathP (\ i → D (\ k → push (x k) i)) (l \ k → (f (x k))) (r \ k → (g (x k))))
where
postulate
elim : (h : Cl → PO) → D h
beta1 : (x : Cl → A) → elim (\ k → inl (x k)) ≡ l x
beta2 : (x : Cl → B) → elim (\ k → inr (x k)) ≡ r x
{-# REWRITE beta1 beta2 #-}
_ : {x : Cl → A} → elim (\ k → inl (x k)) ≡ l x
_ = refl
_ : {x : Cl → B} → elim (\ k → inr (x k)) ≡ r x
_ = refl
postulate
beta3 : (x : Cl → C)(i : I) → elim (\ k → push (x k) i) ≡ p x i
{-# REWRITE beta3 #-}
_ : {x : Cl → C}{i : I} → elim (\ k → push (x k) i) ≡ p x i
_ = refl
-- Testing outside the module too
open M
open E
variable
A B C : Set
f : C → A
g : C → B
_ : {x : Cl → A} →
elim A B C f g (\ h → (k : Cl) → h k ≡ h k) (\ x k → refl) (\ _ _ → refl)
(\ c i k → refl) (\ k → inl (x k)) ≡ \ k → refl
_ = refl
_ : {c : Cl → C}{i : I} →
elim A B C f g (\ h → (k : Cl) → h k ≡ h k) (\ x k → refl) (\ _ _ → refl)
(\ c i k → refl) (\ k → push (c k) i) ≡ \ k → refl
_ = refl
| {
"alphanum_fraction": 0.4297612438,
"avg_line_length": 23.3896103896,
"ext": "agda",
"hexsha": "26185a98214adf1184cc698208e6f692dc613a05",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/HigherOrderPathRewriting.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/HigherOrderPathRewriting.agda",
"max_line_length": 108,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/HigherOrderPathRewriting.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": 757,
"size": 1801
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Rings.Definition
open import Rings.IntegralDomains.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
module Fields.FieldOfFractions.Addition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (I : IntegralDomain R) where
open import Fields.FieldOfFractions.Setoid I
fieldOfFractionsPlus : fieldOfFractionsSet → fieldOfFractionsSet → fieldOfFractionsSet
fieldOfFractionsSet.num (fieldOfFractionsPlus (record { num = a ; denom = b ; denomNonzero = b!=0 }) (record { num = c ; denom = d ; denomNonzero = d!=0 })) = (a * d) + (b * c)
fieldOfFractionsSet.denom (fieldOfFractionsPlus (record { num = a ; denom = b ; denomNonzero = b!=0 }) (record { num = c ; denom = d ; denomNonzero = d!=0 })) = b * d
fieldOfFractionsSet.denomNonzero (fieldOfFractionsPlus (record { num = a ; denom = b ; denomNonzero = b!=0 }) (record { num = c ; denom = d ; denomNonzero = d!=0 })) = λ pr → exFalso (d!=0 (IntegralDomain.intDom I pr b!=0))
--record { num = ((a * d) + (b * c)) ; denom = b * d ; denomNonzero = λ pr → exFalso (d!=0 (IntegralDomain.intDom I pr b!=0)) }
plusWellDefined : {a b c d : fieldOfFractionsSet} → (Setoid._∼_ fieldOfFractionsSetoid a c) → (Setoid._∼_ fieldOfFractionsSetoid b d) → Setoid._∼_ fieldOfFractionsSetoid (fieldOfFractionsPlus a b) (fieldOfFractionsPlus c d)
plusWellDefined {record { num = a ; denom = b ; denomNonzero = b!=0 }} {record { num = c ; denom = d ; denomNonzero = d!=0 }} {record { num = e ; denom = f ; denomNonzero = f!=0 }} {record { num = g ; denom = h ; denomNonzero = h!=0 }} af=be ch=dg = need
where
open Setoid S
open Ring R
open Equivalence eq
have1 : (c * h) ∼ (d * g)
have1 = ch=dg
have2 : (a * f) ∼ (b * e)
have2 = af=be
need : (((a * d) + (b * c)) * (f * h)) ∼ ((b * d) * (((e * h) + (f * g))))
need = transitive (transitive (Ring.*Commutative R) (transitive (Ring.*DistributesOver+ R) (Group.+WellDefined (Ring.additiveGroup R) (transitive *Associative (transitive (*WellDefined (*Commutative) reflexive) (transitive (*WellDefined *Associative reflexive) (transitive (*WellDefined (*WellDefined have2 reflexive) reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined (transitive (transitive (symmetric *Associative) (*WellDefined reflexive *Commutative)) *Associative) reflexive) (symmetric *Associative))))))))) (transitive *Commutative (transitive (transitive (symmetric *Associative) (*WellDefined reflexive (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined have1 reflexive) (transitive (symmetric *Associative) (*WellDefined reflexive *Commutative))))))) *Associative))))) (symmetric (Ring.*DistributesOver+ R))
| {
"alphanum_fraction": 0.6880515954,
"avg_line_length": 86.6470588235,
"ext": "agda",
"hexsha": "50b9d3de1d020995ceaf5e4f297b309dbb7be4f6",
"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/FieldOfFractions/Addition.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/FieldOfFractions/Addition.agda",
"max_line_length": 970,
"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/FieldOfFractions/Addition.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": 936,
"size": 2946
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Groups.Definition
module Groups.Actions.Definition where
record GroupAction {m n o p : _} {A : Set m} {S : Setoid {m} {o} A} {_·_ : A → A → A} {B : Set n} (G : Group S _·_) (X : Setoid {n} {p} B) : Set (m ⊔ n ⊔ o ⊔ p) where
open Group G
open Setoid S renaming (_∼_ to _∼G_)
open Setoid X renaming (_∼_ to _∼X_)
field
action : A → B → B
actionWellDefined1 : {g h : A} → {x : B} → (g ∼G h) → action g x ∼X action h x
actionWellDefined2 : {g : A} → {x y : B} → (x ∼X y) → action g x ∼X action g y
identityAction : {x : B} → action 0G x ∼X x
associativeAction : {x : B} → {g h : A} → action (g · h) x ∼X action g (action h x)
| {
"alphanum_fraction": 0.5890410959,
"avg_line_length": 42.2631578947,
"ext": "agda",
"hexsha": "c7dbb810b893f1c03fa888c485c388bb8421bf8c",
"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/Actions/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Actions/Definition.agda",
"max_line_length": 166,
"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/Actions/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 313,
"size": 803
} |
-- A minor variant of code reported by Andreas Abel.
-- Andreas, 2011-10-04
--
-- Agda's coinduction is incompatible with initial algebras
--
-- Sized types are needed to formulate initial algebras in general:
--
{-# OPTIONS --sized-types #-}
--
-- We need to skip the positivity check since we cannot communicate
-- to Agda that we only want strictly positive F's in the definition of Mu
--
{-# OPTIONS --no-positivity-check #-}
--
module _ where
open import Agda.Builtin.Coinduction renaming (∞ to co)
open import Agda.Builtin.Size
-- initial algebras
data Mu (F : Set → Set) : Size → Set where
inn : ∀ {i} → F (Mu F i) → Mu F (↑ i)
iter : ∀ {F : Set → Set}
(map : ∀ {A B} → (A → B) → F A → F B)
{A} → (F A → A) → ∀ {i} → Mu F i → A
iter map s (inn t) = s (map (iter map s) t)
-- the co functor (aka Lift functor)
F : Set → Set
F A = co A
map : ∀ {A B : Set} → (A → B) → co A → co B
map f a = ♯ f (♭ a)
-- the least fixed-point of co is inhabited
bla : Mu F ∞
bla = inn (♯ bla)
-- and goal!
data ⊥ : Set where
false : ⊥
false = iter map ♭ bla
-- note that co is indeed strictly positive, as the following
-- direct definition of Mu F ∞ is accepted
data Bla : Set where
c : co Bla → Bla
{- -- if we inline ♭ map into iter, the termination checker detects the cheat
iter' : Bla → ⊥
iter' (c t) = ♭ (♯ iter' (♭ t))
-- iter' (c t) = ♭ (map iter' t)
-}
-- Again, I want to emphasize that the problem is not with sized types.
-- I have only used sized types to communicate to Agda that initial algebras
-- (F, iter) are ok. Once we have initial algebras, we can form the
-- initial algebra of the co functor and abuse the guardedness checker
-- to construct an inhabitant in this empty initial algebra.
--
-- Agda's coinduction mechanism confuses constructor and coconstructors.
-- Convenient, but, as you have seen...
| {
"alphanum_fraction": 0.6442048518,
"avg_line_length": 26.1267605634,
"ext": "agda",
"hexsha": "10ba03a5545ee26c676b3ee95a49fada4c6e021f",
"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": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "caryoscelus/agda",
"max_forks_repo_path": "test/Fail/Issue1946-4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"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": "caryoscelus/agda",
"max_issues_repo_path": "test/Fail/Issue1946-4.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "caryoscelus/agda",
"max_stars_repo_path": "test/Fail/Issue1946-4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 565,
"size": 1855
} |
module Prelude where
id : {a : Set} -> a -> a
id x = x
infixr 0 _$_
_$_ : {a b : Set} -> (a -> b) -> a -> b
f $ x = f x
data Bool : Set where
True : Bool
False : Bool
_&&_ : Bool -> Bool -> Bool
True && b = b
False && _ = False
data Pair (a b : Set) : Set where
pair : a -> b -> Pair a b
fst : {a b : Set} -> Pair a b -> a
fst (pair x y) = x
snd : {a b : Set} -> Pair a b -> b
snd (pair x y) = y
data Either (a b : Set) : Set where
left : a -> Either a b
right : b -> Either a b
data Maybe (a : Set) : Set where
Nothing : Maybe a
Just : a -> Maybe a
data Unit : Set where
unit : Unit
data Absurd : Set where
absurdElim : {whatever : Set} -> Absurd -> whatever
absurdElim ()
-- data Pi {a : Set} (f : a -> Set) : Set where
-- pi : ((x : a) -> f x) -> Pi f
--
-- apply : {a : Set} -> {f : a -> Set} -> Pi f -> (x : a) -> f x
-- apply (pi f) x = f x
T : Bool -> Set
T True = Unit
T False = Absurd
andT : {x y : Bool} -> T x -> T y -> T (x && y)
andT {True} {True} _ _ = unit
andT {True} {False} _ ()
andT {False} {_} () _
T' : {a : Set} -> (a -> a -> Bool) -> (a -> a -> Set)
T' f x y = T (f x y)
data Not (a : Set) : Set where
not : (a -> Absurd) -> Not a
-- Not : Set -> Set
-- Not a = a -> Absurd
contrapositive : {a b : Set} -> (a -> b) -> Not b -> Not a
contrapositive p (not nb) = not (\a -> nb (p a))
private
notDistribOut' : {a b : Set} -> Not a -> Not b -> Either a b -> Absurd
notDistribOut' (not na) _ (left a) = na a
notDistribOut' _ (not nb) (right b) = nb b
notDistribOut : {a b : Set} -> Not a -> Not b -> Not (Either a b)
notDistribOut na nb = not (notDistribOut' na nb)
notDistribIn : {a b : Set} -> Not (Either a b) -> Pair (Not a) (Not b)
notDistribIn (not nab) = pair (not (\a -> nab (left a)))
(not (\b -> nab (right b)))
data _<->_ (a b : Set) : Set where
iff : (a -> b) -> (b -> a) -> a <-> b
iffLeft : {a b : Set} -> (a <-> b) -> (a -> b)
iffLeft (iff l _) = l
iffRight : {a b : Set} -> (a <-> b) -> (b -> a)
iffRight (iff _ r) = r
Dec : (A : Set) -> Set
Dec A = Either A (Not A)
| {
"alphanum_fraction": 0.4653024911,
"avg_line_length": 23.6631578947,
"ext": "agda",
"hexsha": "2b8658986bd497c6aa7ace23ee959160d482b898",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/AIM4/bag/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": "examples/AIM4/bag/Prelude.agda",
"max_line_length": 74,
"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/AIM4/bag/Prelude.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": 865,
"size": 2248
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Construction.PathsOf where
-- "Free Category on a Quiver" Construction, i.e. the category of paths of the quiver.
-- Note the use of Categories.Morphism.HeterogeneousIdentity as well as
-- Relation.Binary.PropositionalEquality.Subst.Properties which are needed
-- for F-resp-≈.
open import Level
open import Function using (_$_)
open import Relation.Binary.PropositionalEquality using (refl; sym)
open import Relation.Binary.PropositionalEquality.Subst.Properties using (module TransportStar)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.Construct.Closure.ReflexiveTransitive.Properties
open import Data.Quiver
open import Data.Quiver.Morphism
open import Data.Quiver.Paths using (module Paths)
open import Categories.Category
import Categories.Category.Construction.PathCategory as PC
open import Categories.Category.Instance.Quivers
open import Categories.Category.Instance.StrictCats
open import Categories.Functor using (Functor)
open import Categories.Functor.Equivalence using (_≡F_)
import Categories.Morphism.HeterogeneousIdentity as HId
import Categories.Morphism.Reasoning as MR
private
variable
o o′ ℓ ℓ′ e e′ : Level
G₁ G₂ : Quiver o ℓ e
⇒toPathF : {G₁ G₂ : Quiver o ℓ e} → Morphism G₁ G₂ → Functor (PC.PathCategory G₁) (PC.PathCategory G₂)
⇒toPathF {G₁ = G₁} {G₂} G⇒ = record
{ F₀ = F₀ G⇒
; F₁ = qmap G⇒
; identity = Paths.refl G₂
; homomorphism = λ {_} {_} {_} {f} {g} → Paths.≡⇒≈* G₂ $ gmap-◅◅ (F₀ G⇒) (F₁ G⇒) f g
; F-resp-≈ = λ { {f = f} → map-resp G⇒ f}
}
where open Morphism
⇒toPathF-resp-≃ : {f g : Morphism G₁ G₂} → f ≃ g → ⇒toPathF f ≡F ⇒toPathF g
⇒toPathF-resp-≃ {G₂ = G} {f} {g} f≈g = record
{ eq₀ = λ _ → F₀≡
; eq₁ = λ h →
let open Category.HomReasoning (PC.PathCategory G)
open HId (PC.PathCategory G)
open TransportStar (Quiver._⇒_ G)
in begin
qmap f h ◅◅ (hid F₀≡) ≈˘⟨ hid-subst-cod (qmap f h) F₀≡ ⟩
qmap f h ▸* F₀≡ ≈⟨ map-F₁≡ f≈g h ⟩
F₀≡ ◂* qmap g h ≈⟨ hid-subst-dom F₀≡ (qmap g h) ⟩
hid F₀≡ ◅◅ qmap g h ∎
}
where
open _≃_ f≈g
PathsOf : Functor (Quivers o ℓ e) (StrictCats o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e))
PathsOf = record
{ F₀ = PC.PathCategory
; F₁ = ⇒toPathF
; identity = λ {G} → record
{ eq₀ = λ _ → refl
; eq₁ = λ f → toSquare (PC.PathCategory G) (Paths.≡⇒≈* G $ gmap-id f)
}
; homomorphism = λ {_} {_} {G} {f} {g} → record
{ eq₀ = λ _ → refl
; eq₁ = λ h → toSquare (PC.PathCategory G) (Paths.≡⇒≈* G (sym $ gmap-∘ (F₀ g) (F₁ g) (F₀ f) (F₁ f) h) )
}
; F-resp-≈ = ⇒toPathF-resp-≃
}
where
open Morphism using (F₀; F₁)
open MR using (toSquare)
| {
"alphanum_fraction": 0.6562043796,
"avg_line_length": 35.5844155844,
"ext": "agda",
"hexsha": "1be27f2b9269c6b6ed1d8033aa7208d2bd609093",
"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/Construction/PathsOf.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/Construction/PathsOf.agda",
"max_line_length": 107,
"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/Construction/PathsOf.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": 1014,
"size": 2740
} |
{-# OPTIONS --cubical --safe #-}
module Data.Binary.Conversion.Strict where
open import Data.Binary.Definition
open import Data.Binary.Increment.Strict
import Data.Nat as ℕ
import Data.Nat.Properties as ℕ
open import Data.Nat using (ℕ; suc; zero)
open import Data.Nat.Fold
open import Strict
open import Data.Nat.DivMod
open import Data.Bool
⟦_⇑⟧′ : ℕ → 𝔹
⟦_⇑⟧′ = foldl-ℕ inc′ 0ᵇ
⟦_⇓⟧′ : 𝔹 → ℕ
⟦ 0ᵇ ⇓⟧′ = zero
⟦ 1ᵇ xs ⇓⟧′ = let! xs′ =! ⟦ xs ⇓⟧′ in! 1 ℕ.+ xs′ ℕ.* 2
⟦ 2ᵇ xs ⇓⟧′ = let! xs′ =! ⟦ xs ⇓⟧′ in! 2 ℕ.+ xs′ ℕ.* 2
| {
"alphanum_fraction": 0.6335877863,
"avg_line_length": 23.8181818182,
"ext": "agda",
"hexsha": "5ff80a310bead861081031c24f61b9fd0799271a",
"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/Binary/Conversion/Strict.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/Binary/Conversion/Strict.agda",
"max_line_length": 54,
"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/Binary/Conversion/Strict.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": 238,
"size": 524
} |
-- Module for BCCs, CCCs and BCCCs
module CategoryTheory.BCCCs where
open import CategoryTheory.Categories
open import CategoryTheory.BCCCs.Cartesian public
open import CategoryTheory.BCCCs.Cocartesian public
open import CategoryTheory.BCCCs.Closed public
-- Bicartesian categories
record Bicartesian {n} (ℂ : Category n) : Set (lsuc n) where
field
cart : Cartesian ℂ
cocart : Cocartesian ℂ
-- Cartesian closed categories
record CartesianClosed {n} (ℂ : Category n) : Set (lsuc n) where
field
cart : Cartesian ℂ
closed : Closed cart
-- Bicartesian closed categories
record BicartesianClosed {n} (ℂ : Category n) : Set (lsuc n) where
field
cart : Cartesian ℂ
cocart : Cocartesian ℂ
closed : Closed cart
open Cartesian cart public
open Cocartesian cocart public
open Closed closed public
| {
"alphanum_fraction": 0.7103762828,
"avg_line_length": 28.2903225806,
"ext": "agda",
"hexsha": "348f81f7d54ac78d44738797cee4768415b9644c",
"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/CategoryTheory/BCCCs.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/CategoryTheory/BCCCs.agda",
"max_line_length": 66,
"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/CategoryTheory/BCCCs.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": 240,
"size": 877
} |
{-
Copyright 2019 Lisandra Silva
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}
open import Prelude
open import Data.Bool renaming (_≟_ to _B≟_)
open import Data.Fin renaming (_≟_ to _F≟_)
open import Agda.Builtin.Sigma
open import Relation.Nullary.Negation using (contradiction ; contraposition)
open import StateMachineModel
{-
PROCESS 0 || PROCESS 1
repeat || repeat
s₀: thinking₀ = false; || r₀: thinking₁ = false;
s₁: turn = 1; || r₁: turn = 0;
s₂: await thinking₁ ∨ turn ≡ 0; || r₂: await thinking₀ ∨ turn ≡ 1;
“critical section”; || “critical section”;
s₃: thinking₀ = true; || r₃: thinking₁ = true;
forever || forever
-}
module Examples.Peterson where
{- Because of the atomicity assumptions, we can view a concurrent program as a
state transition system. Simply associate with each process a control
variable that indicates the atomic statement to be executed next by the
process.
The state of the program is defined by the values of the data variables and
control variables.
-}
record State : Set where
field
-- Data variables : updated in assignemnt statements
thinking₀ thinking₁ : Bool
turn : Fin 2
-- Control varibales : updated acording to the control flow of the program
control₀ control₁ : Fin 4
open State
-- Events : corresponding to the atomic statements
data MyEvent : Set where
es₀ es₁ es₂₁ es₂₂ es₃ er₀ er₁ er₂₁ er₂₂ er₃ : MyEvent
{- Enabled conditions : predicate on the state variables.
In any state, an atomic statement can be executed if and only if it is
pointed to by a control variable and is enabled.
-}
MyEnabled : MyEvent → State → Set
MyEnabled es₀ st = control₀ st ≡ 0F
MyEnabled es₁ st = control₀ st ≡ 1F
MyEnabled es₂₁ st = control₀ st ≡ 2F × thinking₁ st ≡ true
MyEnabled es₂₂ st = control₀ st ≡ 2F × turn st ≡ 0F
MyEnabled es₃ st = control₀ st ≡ 3F
MyEnabled er₀ st = control₁ st ≡ 0F
MyEnabled er₁ st = control₁ st ≡ 1F
MyEnabled er₂₁ st = control₁ st ≡ 2F × thinking₀ st ≡ true
MyEnabled er₂₂ st = control₁ st ≡ 2F × turn st ≡ 1F
MyEnabled er₃ st = control₁ st ≡ 3F
{- Actions : executing the statement results in a new state.
Thus each statement execution corresponds to a state transition.
-}
MyAction : ∀ {preState} {event} → MyEnabled event preState → State
-- Process 1
MyAction {ps} {es₀} x = record ps { thinking₀ = false -- want to access CS
; control₀ = 1F } -- next statement
MyAction {ps} {es₁} x = record ps { turn = 1F -- gives turn to other proc
; control₀ = 2F } -- next stmt
MyAction {ps} {es₂₁} x = record ps { control₀ = 3F } -- next stmt
MyAction {ps} {es₂₂} x = record ps { control₀ = 3F } -- next stmt
MyAction {ps} {es₃} x = record ps { thinking₀ = true -- releases the CS
; control₀ = 0F } -- loop
-- Proccess 2
MyAction {ps} {er₀} x = record ps { thinking₁ = false
; control₁ = 1F }
MyAction {ps} {er₁} x = record ps { turn = 0F
; control₁ = 2F }
MyAction {ps} {er₂₁} x = record ps { control₁ = 3F }
MyAction {ps} {er₂₂} x = record ps { control₁ = 3F }
MyAction {ps} {er₃} x = record ps { thinking₁ = true
; control₁ = 0F }
initialState : State
initialState = record
{ thinking₀ = true
; thinking₁ = true
; turn = 0F
; control₀ = 0F
; control₁ = 0F
}
MyStateMachine : StateMachine State MyEvent
MyStateMachine = record
{ initial = _≡ initialState
; enabled = MyEnabled
; action = MyAction
}
-- Each process has its own EventSet with its statements
Proc0-EvSet : EventSet {Event = MyEvent}
Proc0-EvSet ev = ev ≡ es₁ ⊎ ev ≡ es₂₁ ⊎ ev ≡ es₂₂ ⊎ ev ≡ es₃
Proc1-EvSet : EventSet {Event = MyEvent}
Proc1-EvSet ev = ev ≡ er₁ ⊎ ev ≡ er₂₁ ⊎ ev ≡ er₂₂ ⊎ ev ≡ er₃
-- And both EventSets have weak-fairness
data MyWeakFairness : EventSet → Set where
wf-p0 : MyWeakFairness Proc0-EvSet
wf-p1 : MyWeakFairness Proc1-EvSet
MySystem : System State MyEvent
MySystem = record
{ stateMachine = MyStateMachine
; weakFairness = MyWeakFairness
}
-----------------------------------------------------------------------------
-- PROOFS
-----------------------------------------------------------------------------
open LeadsTo State MyEvent MySystem
inv-c₁≡[0-4] : Invariant MyStateMachine λ st → ∃[ f ] (control₁ st ≡ f)-- ([∃ f ∶ (_≡ f) ∘ control₁ ])
inv-c₁≡[0-4] (init refl) = 0F , refl
inv-c₁≡[0-4] (step {event = es₀} rs enEv) = inv-c₁≡[0-4] rs
inv-c₁≡[0-4] (step {event = es₁} rs enEv) = inv-c₁≡[0-4] rs
inv-c₁≡[0-4] (step {event = es₂₁} rs enEv) = inv-c₁≡[0-4] rs
inv-c₁≡[0-4] (step {event = es₂₂} rs enEv) = inv-c₁≡[0-4] rs
inv-c₁≡[0-4] (step {event = es₃} rs enEv) = inv-c₁≡[0-4] rs
inv-c₁≡[0-4] (step {event = er₀} rs enEv) = 1F , refl
inv-c₁≡[0-4] (step {event = er₁} rs enEv) = 2F , refl
inv-c₁≡[0-4] (step {event = er₂₁} rs enEv) = 3F , refl
inv-c₁≡[0-4] (step {event = er₂₂} rs enEv) = 3F , refl
inv-c₁≡[0-4] (step {event = er₃} rs enEv) = 0F , refl
inv-¬think₁ : Invariant
MyStateMachine
λ st → control₀ st ≡ 1F ⊎ control₀ st ≡ 2F ⊎ control₀ st ≡ 3F
→ thinking₀ st ≡ false
inv-¬think₁ (init refl) (inj₂ (inj₁ ()))
inv-¬think₁ (init refl) (inj₂ (inj₂ ()))
inv-¬think₁ (step {event = es₀} rs enEv) x = refl
inv-¬think₁ (step {event = es₁} rs enEv) x = inv-¬think₁ rs (inj₁ enEv)
inv-¬think₁ (step {event = es₂₁} rs enEv) x = inv-¬think₁ rs (inj₂ (inj₁ (fst enEv)))
inv-¬think₁ (step {event = es₂₂} rs enEv) x = inv-¬think₁ rs (inj₂ (inj₁ (fst enEv)))
inv-¬think₁ (step {event = es₃} rs enEv) (inj₂ (inj₁ ()))
inv-¬think₁ (step {event = es₃} rs enEv) (inj₂ (inj₂ ()))
inv-¬think₁ (step {event = er₀} rs enEv) x = inv-¬think₁ rs x
inv-¬think₁ (step {event = er₁} rs enEv) x = inv-¬think₁ rs x
inv-¬think₁ (step {event = er₂₁} rs enEv) x = inv-¬think₁ rs x
inv-¬think₁ (step {event = er₂₂} rs enEv) x = inv-¬think₁ rs x
inv-¬think₁ (step {event = er₃} rs enEv) x = inv-¬think₁ rs x
inv-think₂ : Invariant
MyStateMachine
λ st → control₁ st ≡ 0F
→ thinking₁ st ≡ true
inv-think₂ (init refl) x = refl
inv-think₂ (step {event = es₀} rs enEv) x = inv-think₂ rs x
inv-think₂ (step {event = es₁} rs enEv) x = inv-think₂ rs x
inv-think₂ (step {event = es₂₁} rs enEv) x = inv-think₂ rs x
inv-think₂ (step {event = es₂₂} rs enEv) x = inv-think₂ rs x
inv-think₂ (step {event = es₃} rs enEv) x = inv-think₂ rs x
inv-think₂ (step {event = er₃} rs enEv) x = refl
inv-¬think₂ : Invariant
MyStateMachine
λ st → control₁ st ≡ 1F ⊎ control₁ st ≡ 2F ⊎ control₁ st ≡ 3F
→ thinking₁ st ≡ false
inv-¬think₂ (init refl) (inj₂ (inj₁ ()))
inv-¬think₂ (init refl) (inj₂ (inj₂ ()))
inv-¬think₂ (step {event = es₀} rs enEv) x = inv-¬think₂ rs x
inv-¬think₂ (step {event = es₁} rs enEv) x = inv-¬think₂ rs x
inv-¬think₂ (step {event = es₂₁} rs enEv) x = inv-¬think₂ rs x
inv-¬think₂ (step {event = es₂₂} rs enEv) x = inv-¬think₂ rs x
inv-¬think₂ (step {event = es₃} rs enEv) x = inv-¬think₂ rs x
inv-¬think₂ (step {event = er₀} rs enEv) x = refl
inv-¬think₂ (step {event = er₁} rs enEv) x = inv-¬think₂ rs (inj₁ enEv)
inv-¬think₂ (step {event = er₂₁} rs enEv) x = inv-¬think₂ rs (inj₂ (inj₁ (fst enEv)))
inv-¬think₂ (step {event = er₂₂} rs enEv) x = inv-¬think₂ rs (inj₂ (inj₁ (fst enEv)))
inv-¬think₂ (step {event = er₃} rs enEv) (inj₂ (inj₁ ()))
inv-¬think₂ (step {event = er₃} rs enEv) (inj₂ (inj₂ ()))
proc0-1-l-t-2 : (_≡ 1F) ∘ control₀ l-t (_≡ 2F) ∘ control₀
proc0-1-l-t-2 = viaEvSet
Proc0-EvSet
wf-p0
(λ { es₁ (inj₁ refl) → hoare λ { _ _ → refl }
; es₂₁ (inj₂ (inj₁ refl)) → hoare λ { refl () }
; es₂₂ (inj₂ (inj₂ (inj₁ refl))) → hoare λ { refl () }
; es₃ (inj₂ (inj₂ (inj₂ refl))) → hoare λ { refl () }
})
(λ { es₀ _ → hoare λ { () refl }
; es₁ x → ⊥-elim (x (inj₁ refl))
; es₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; es₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; es₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl))))
; er₀ _ → hoare λ z _ → inj₁ z
; er₁ _ → hoare λ z _ → inj₁ z
; er₂₁ _ → hoare λ z _ → inj₁ z
; er₂₂ _ → hoare λ z _ → inj₁ z
; er₃ _ → hoare λ z _ → inj₁ z
})
λ _ x → es₁ , inj₁ refl , x
P⊆P₀⊎P₁ : ∀ {ℓ} {A : Set ℓ} (x : Fin 2)
→ A → A × x ≡ 0F ⊎ A × x ≡ 1F
P⊆P₀⊎P₁ 0F a = inj₁ (a , refl)
P⊆P₀⊎P₁ 1F a = inj₂ (a , refl)
-- y4
turn≡0-l-t-Q : ((_≡ 2F) ∘ control₀ ∩ (_≡ 0F) ∘ turn ) l-t (_≡ 3F) ∘ control₀
turn≡0-l-t-Q =
viaEvSet
Proc0-EvSet
wf-p0
(λ { es₁ (inj₁ refl) → hoare λ { () refl }
; es₂₁ (inj₂ (inj₁ refl)) → hoare λ _ _ → refl
; es₂₂ (inj₂ (inj₂ (inj₁ refl))) → hoare λ _ _ → refl
; es₃ (inj₂ (inj₂ (inj₂ refl))) → hoare λ { () refl } })
( λ { es₀ _ → hoare λ { () refl }
; es₁ x → ⊥-elim (x (inj₁ refl))
; es₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; es₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; es₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl))))
; er₀ _ → hoare (λ z _ → inj₁ z)
; er₁ _ → hoare (λ z _ → inj₁ ((fst z) , refl) )
; er₂₁ _ → hoare (λ z _ → inj₁ z)
; er₂₂ _ → hoare (λ z _ → inj₁ z)
; er₃ _ → hoare (λ z _ → inj₁ z)
} )
λ { _ (c₀≡2 , tu≡0) → es₂₂ , inj₂ (inj₂ (inj₁ refl)) , c₀≡2 , tu≡0 }
-- I think I could prove this with the Proc1EvSet
Pl-tQ∨c₁≡1 : (λ preSt → ( control₀ preSt ≡ 2F × turn preSt ≡ 1F )
× control₁ preSt ≡ 0F)
l-t
λ posSt → control₀ posSt ≡ 3F
⊎ (( control₀ posSt ≡ 2F × turn posSt ≡ 1F )
× control₁ posSt ≡ 1F )
Pl-tQ∨c₁≡1 =
viaEvSet
Proc0-EvSet
wf-p0
(λ { es₁ (inj₁ refl) → hoare λ { () refl }
; es₂₁ (inj₂ (inj₁ refl)) → hoare λ { _ _ → inj₁ refl }
; es₂₂ (inj₂ (inj₂ (inj₁ refl))) → hoare λ { _ _ → inj₁ refl }
; es₃ (inj₂ (inj₂ (inj₂ refl))) → hoare λ { () refl } })
( λ { es₀ _ → hoare λ { () refl }
; es₁ x → ⊥-elim (x (inj₁ refl))
; es₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; es₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; es₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl))))
; er₀ _ → hoare λ { x₁ enEv → inj₂ (inj₂ (fst x₁ , refl)) }
; er₁ _ → hoare λ { () refl }
; er₂₁ _ → hoare λ { () (refl , _) }
; er₂₂ _ → hoare λ { () (refl , _) }
; er₃ _ → hoare λ { () refl }
})
λ { rs ((c₀≡2 , _) , c₁≡0)
→ es₂₁ , inj₂ (inj₁ refl) , c₀≡2 , inv-think₂ rs c₁≡0 }
l-t-turn≡0 : ((_≡ 2F) ∘ control₀ ∩ (_≡ 1F) ∘ turn) ∩ (_≡ 1F) ∘ control₁
l-t
(_≡ 2F) ∘ control₀ ∩ (_≡ 0F) ∘ turn
l-t-turn≡0 =
viaUseInv
inv-¬think₂
( viaEvSet
Proc1-EvSet
wf-p1
( λ { er₁ (inj₁ refl) → hoare λ { ((x , _) , _) _ _ → fst x , refl }
; er₂₁ (inj₂ (inj₁ refl)) → hoare λ { () (refl , _) _ }
; er₂₂ (inj₂ (inj₂ (inj₁ refl))) → hoare λ { () (refl , _) _ }
; er₃ (inj₂ (inj₂ (inj₂ refl))) → hoare λ { () refl _ }
}
)
( λ { es₀ _ → hoare λ { () refl }
; es₁ _ → hoare λ { () refl }
; es₂₁ _ → hoare λ { ((_ , c₂≡2) , x) (_ , refl)
→ contradiction (x (inj₁ c₂≡2)) λ () }
; es₂₂ _ → hoare λ { () (_ , refl) }
; es₃ _ → hoare λ { () refl }
; er₀ _ → hoare λ { () refl }
; er₁ x → ⊥-elim (x (inj₁ refl))
; er₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; er₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; er₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl)))) }
)
λ _ x → er₁ , inj₁ refl , (snd ∘ fst) x
)
l-t-c₁≡3 : (λ preSt → ( control₀ preSt ≡ 2F × turn preSt ≡ 1F )
× control₁ preSt ≡ 2F)
l-t
(λ posSt → ( control₀ posSt ≡ 2F
× turn posSt ≡ 1F )
× control₁ posSt ≡ 3F)
l-t-c₁≡3 =
viaUseInv
inv-¬think₂
( viaEvSet
Proc1-EvSet
wf-p1
( λ { er₁ (inj₁ refl) → hoare λ { () refl _ }
; er₂₁ (inj₂ (inj₁ refl))
→ hoare λ { ((x , _) , _) _ _ → x , refl }
; er₂₂ (inj₂ (inj₂ (inj₁ refl)))
→ hoare λ { ((x , _) , _) _ _ → x , refl }
; er₃ (inj₂ (inj₂ (inj₂ refl))) → hoare λ { () refl _ }
}
)
( λ { es₀ _ → hoare λ { () refl }
; es₁ _ → hoare λ { () refl }
; es₂₁ _ → hoare λ { ((_ , c₂≡3) , x) (_ , refl)
→ contradiction (x (inj₂ (inj₁ c₂≡3))) λ () }
; es₂₂ _ → hoare λ { () (_ , refl) }
; es₃ _ → hoare λ { () refl }
; er₀ _ → hoare λ { () refl }
; er₁ x → ⊥-elim (x (inj₁ refl))
; er₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; er₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; er₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl))))
}
)
λ _ x → er₂₂ , inj₂ (inj₂ (inj₁ refl)) , (snd ∘ fst) x , (snd ∘ fst ∘ fst) x
)
l-t-c₁≡0 : (λ preSt → ( control₀ preSt ≡ 2F × turn preSt ≡ 1F )
× control₁ preSt ≡ 3F)
l-t
(λ posSt → ( control₀ posSt ≡ 2F × turn posSt ≡ 1F )
× control₁ posSt ≡ 0F)
l-t-c₁≡0 =
viaUseInv
inv-¬think₂
( viaEvSet
Proc1-EvSet
wf-p1
( λ { er₁ (inj₁ refl) → hoare λ { () refl _ }
; er₂₁ (inj₂ (inj₁ refl)) → hoare λ { () (refl , _) _ }
; er₂₂ (inj₂ (inj₂ (inj₁ refl))) → hoare λ { () (refl , _) _ }
; er₃ (inj₂ (inj₂ (inj₂ refl)))
→ hoare λ { x _ _ → (fst ∘ fst) x , refl }
}
)
( λ { es₀ _ → hoare λ { () refl }
; es₁ _ → hoare λ { () refl }
; es₂₁ _ → hoare λ { ((_ , c₂≡4) , x) (_ , refl)
→ contradiction (x (inj₂ (inj₂ c₂≡4))) λ () }
; es₂₂ _ → hoare λ { () (_ , refl) }
; es₃ _ → hoare λ { () refl }
; er₀ _ → hoare λ { () refl }
; er₁ x → ⊥-elim (x (inj₁ refl))
; er₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; er₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; er₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl))))
}
)
λ _ x → er₃ , inj₂ (inj₂ (inj₂ refl)) , (snd ∘ fst) x
)
P∧c₁≡1⇒Q : ((_≡ 2F) ∘ control₀ ∩ (_≡ 1F) ∘ turn) ∩ (_≡ 1F) ∘ control₁
l-t
(_≡ 3F) ∘ control₀
P∧c₁≡1⇒Q = viaTrans l-t-turn≡0 turn≡0-l-t-Q
P∧c₁≡0⇒Q : ((_≡ 2F) ∘ control₀ ∩ (_≡ 1F) ∘ turn) ∩ (_≡ 0F) ∘ control₁
l-t
(_≡ 3F) ∘ control₀
P∧c₁≡0⇒Q = viaTrans2 Pl-tQ∨c₁≡1 P∧c₁≡1⇒Q
P∧c₁≡3⇒Q : ((_≡ 2F) ∘ control₀ ∩ (_≡ 1F) ∘ turn) ∩ (_≡ 3F) ∘ control₁
l-t
(_≡ 3F) ∘ control₀
P∧c₁≡3⇒Q = viaTrans l-t-c₁≡0 P∧c₁≡0⇒Q
P∧c₁≡2⇒Q : ((_≡ 2F) ∘ control₀ ∩ (_≡ 1F) ∘ turn) ∩ (_≡ 2F) ∘ control₁
l-t
(_≡ 3F) ∘ control₀
P∧c₁≡2⇒Q = viaTrans l-t-c₁≡3 P∧c₁≡3⇒Q
P⊆c₂≡0⊎c₂≢0 : ∀ {ℓ} {A : Set ℓ} (x : Fin 4) → A
→ A × x ≡ 0F ⊎ A × x ≢ 0F
P⊆c₂≡0⊎c₂≢0 0F a = inj₁ (a , refl)
P⊆c₂≡0⊎c₂≢0 (suc x) a = inj₂ (a , (λ ()))
P⊆c₂≡1⊎c₂≢1 : ∀ {ℓ} {A : Set ℓ} (x : Fin 4) → A × x ≢ 0F
→ A × x ≡ 1F ⊎ A × x ≢ 0F × x ≢ 1F
P⊆c₂≡1⊎c₂≢1 0F (a , x≢0) = ⊥-elim (x≢0 refl)
P⊆c₂≡1⊎c₂≢1 1F (a , x≢0) = inj₁ (a , refl)
P⊆c₂≡1⊎c₂≢1 (suc (suc x)) (a , x≢0) = inj₂ (a , x≢0 , λ ())
P⊆c₂≡2⊎c₂≡3 : ∀ {ℓ} {A : Set ℓ} (x : Fin 4) → A × x ≢ 0F × x ≢ 1F
→ A × x ≡ 2F ⊎ A × x ≡ 3F
P⊆c₂≡2⊎c₂≡3 0F (a , x≢0 , x≢1) = ⊥-elim (x≢0 refl)
P⊆c₂≡2⊎c₂≡3 1F (a , x≢0 , x≢1) = ⊥-elim (x≢1 refl)
P⊆c₂≡2⊎c₂≡3 2F (a , x≢0 , x≢1) = inj₁ (a , refl)
P⊆c₂≡2⊎c₂≡3 3F (a , x≢0 , x≢1) = inj₂ (a , refl)
turn≡1-l-t-Q : ((_≡ 2F) ∘ control₀ ∩ (_≡ 1F) ∘ turn ) l-t (_≡ 3F) ∘ control₀
turn≡1-l-t-Q = viaAllVal
inv-c₁≡[0-4]
λ { 0F → P∧c₁≡0⇒Q
; 1F → P∧c₁≡1⇒Q
; 2F → P∧c₁≡2⇒Q
; 3F → P∧c₁≡3⇒Q }
proc0-2-l-t-3 : (_≡ 2F) ∘ control₀ l-t (_≡ 3F) ∘ control₀
proc0-2-l-t-3 = viaDisj
(λ {st} c₀≡2 → P⊆P₀⊎P₁ (turn st) c₀≡2 )
turn≡0-l-t-Q
turn≡1-l-t-Q
proc1-1-l-t-2 : (λ preSt → control₁ preSt ≡ 1F)
l-t
λ posSt → control₁ posSt ≡ 2F
proc1-1-l-t-2 =
viaEvSet
Proc1-EvSet
wf-p1
( λ { er₁ (inj₁ refl) → hoare λ { x enEv → refl }
; er₂₁ (inj₂ (inj₁ refl)) → hoare λ { refl () }
; er₂₂ (inj₂ (inj₂ (inj₁ refl))) → hoare λ { refl () }
; er₃ (inj₂ (inj₂ (inj₂ refl))) → hoare λ { refl () }
}
)
( λ { es₀ _ → hoare λ z _ → inj₁ z
; es₁ _ → hoare λ z _ → inj₁ z
; es₂₁ _ → hoare λ z _ → inj₁ z
; es₂₂ _ → hoare λ z _ → inj₁ z
; es₃ _ → hoare λ z _ → inj₁ z
; er₀ _ → hoare λ _ _ → inj₁ refl
; er₁ x → ⊥-elim (x (inj₁ refl))
; er₂₁ x → ⊥-elim (x (inj₂ (inj₁ refl)))
; er₂₂ x → ⊥-elim (x (inj₂ (inj₂ (inj₁ refl))))
; er₃ x → ⊥-elim (x (inj₂ (inj₂ (inj₂ refl))))
}
)
λ _ x → er₁ , inj₁ refl , x
-- The proofs are the same as proc0-2-l-t-3 but symmetric.
-- We will postulate by now!
postulate
proc1-2-l-t-3 : ( λ preSt → control₁ preSt ≡ 2F )
l-t
λ posSt → control₁ posSt ≡ 3F
-- We proved this via transitivity :
-- control₀ fstSt ≡ 1F l-t control₀ someSt ≡ 2F l-t control₀ ≡ 3F
proc0-live : (λ preSt → control₀ preSt ≡ 1F) l-t (λ posSt → control₀ posSt ≡ 3F)
proc0-live = viaTrans proc0-1-l-t-2 proc0-2-l-t-3
proc1-live : (λ preSt → control₁ preSt ≡ 1F) l-t (λ posSt → control₁ posSt ≡ 3F)
proc1-live = viaTrans proc1-1-l-t-2 proc1-2-l-t-3
------------------------------------------------------------------------------
-- Liveness property
------------------------------------------------------------------------------
-- If Process 1 (Process 2) wants to access the critical section, which
-- means its control variable is in 1F (it just expressed its will in
-- accessing the CS in r₀) then it will eventually access the CS
progress : ( (_≡ 1F) ∘ control₀ l-t (_≡ 3F) ∘ control₀ )
× ( (_≡ 1F) ∘ control₁ l-t (_≡ 3F) ∘ control₁ )
progress = proc0-live , proc1-live
| {
"alphanum_fraction": 0.4742639891,
"avg_line_length": 37.7132352941,
"ext": "agda",
"hexsha": "ea5cf81eb55f641c30808187b4ecd563ba60f79c",
"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": "391e148f391dc2d246249193788a0d203285b38e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "lisandrasilva/agda-liveness",
"max_forks_repo_path": "src/Examples/Peterson.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"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": "lisandrasilva/agda-liveness",
"max_issues_repo_path": "src/Examples/Peterson.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "lisandrasilva/agda-liveness",
"max_stars_repo_path": "src/Examples/Peterson.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7988,
"size": 20516
} |
module Interaction-and-input-file where
| {
"alphanum_fraction": 0.85,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "cd2eff691d6c84570814a097ba1d439e9d905bd1",
"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/Interaction-and-input-file.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/Interaction-and-input-file.agda",
"max_line_length": 39,
"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/Interaction-and-input-file.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": 7,
"size": 40
} |
-- Reported and fixed by Andrea Vezzosi.
module Issue898 where
id : {A : Set} -> A -> A
id = ?
| {
"alphanum_fraction": 0.618556701,
"avg_line_length": 13.8571428571,
"ext": "agda",
"hexsha": "b159fbe585bf8f625363b5fdd26fa3ead0b89232",
"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/Issue898.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/Issue898.agda",
"max_line_length": 40,
"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/Issue898.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": 31,
"size": 97
} |
module Data.Word.Primitive where
postulate
Word : Set
Word8 : Set
Word16 : Set
Word32 : Set
Word64 : Set
{-# FOREIGN GHC import qualified Data.Word #-}
{-# COMPILE GHC Word = type Data.Word.Word #-}
{-# COMPILE GHC Word8 = type Data.Word.Word8 #-}
{-# COMPILE GHC Word16 = type Data.Word.Word16 #-}
{-# COMPILE GHC Word32 = type Data.Word.Word32 #-}
{-# COMPILE GHC Word64 = type Data.Word.Word64 #-}
| {
"alphanum_fraction": 0.6682808717,
"avg_line_length": 25.8125,
"ext": "agda",
"hexsha": "a0be182aed94143b387cf0bb10e5be2f6659f0f6",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "121d6c66cba34b4c15b437366b80c65dd2b02a8d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-system-io",
"max_forks_repo_path": "src/Data/Word/Primitive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "121d6c66cba34b4c15b437366b80c65dd2b02a8d",
"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/agda-system-io",
"max_issues_repo_path": "src/Data/Word/Primitive.agda",
"max_line_length": 50,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "121d6c66cba34b4c15b437366b80c65dd2b02a8d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-system-io",
"max_stars_repo_path": "src/Data/Word/Primitive.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 110,
"size": 413
} |
module Numeral.FixedPositional where
import Lvl
open import Data using (<>)
open import Data.List
open import Data.Boolean hiding (elim)
open import Data.Boolean.Stmt
open import Numeral.Finite
open import Numeral.Natural
open import Functional
open import Syntax.Number
open import Type
private variable ℓ : Lvl.Level
private variable z : Bool
private variable b n : ℕ
-- A formalization of the fixed positional radix numeral system for the notation of numbers.
-- Each number is represented by a list of digits.
-- Digits are a finite set of ordered objects starting with zero (0), and a finite number of its successors.
-- Examples using radix 10 (b = 10):
-- ∅ represents 0
-- # 0 represents 0
-- # 0 · 0 represents 0
-- # 2 represents 2
-- # 1 · 3 represents 13
-- # 5 · 0 · 4 · 0 · 0 represents 50400
-- # 0 · 5 · 0 · 4 · 0 · 0 represents 50400
-- # 0 · 0 · 0 · 5 · 0 · 4 · 0 · 0 represents 50400
-- # 5 · 0 · 4 · 0 · 0 · 0 represents 504000
-- Example using radix 2 (b = 2):
-- # 1 · 1 represents 3
-- # 0 · 1 · 0 · 1 · 1 represents 11
-- Note: The radix is also called base.
-- Note: This representation is in little endian: The deepest digit in the list is the most significant digit (greatest), and the first position of the list is the least significant digit. Note that the (_·_) operator is a reversed list cons operator, so it constructs a list from right to left when written without parenthesis.
Positional = List ∘ 𝕟
pattern # n = n ⊰ ∅
pattern _·_ a b = b ⊰ a
infixl 100 _·_
private variable x y : Positional(b)
private variable d : 𝕟(n)
-- Two positionals are equal when the sequence of digits in the lists are the same.
-- But also, when there are zeroes at the most significant positions, they should be skipped.
-- Examples:
-- # 4 · 5 ≡ₚₒₛ # 4 · 5
-- # 0 · 0 · 4 · 5 ≡ₚₒₛ # 4 · 5
-- # 4 · 5 ≡ₚₒₛ # 0 · 0 · 4 · 5
-- # 0 · 0 · 4 · 5 ≡ₚₒₛ # 0 · 4 · 5
data _≡ₚₒₛ_ : Positional b → Positional b → Type{Lvl.𝟎} where
empty : (_≡ₚₒₛ_ {b} ∅ ∅)
skipₗ : (x ≡ₚₒₛ ∅) → (x · 𝟎 ≡ₚₒₛ ∅)
skipᵣ : (∅ ≡ₚₒₛ y) → (∅ ≡ₚₒₛ y · 𝟎)
step : (x ≡ₚₒₛ y) → (x · d ≡ₚₒₛ y · d)
module _ where
open import Numeral.Natural.Oper
-- Converts a positional to a number by adding the first digit and multiplying the rest with the radix.
-- Examples in radix 10 (b = 10):
-- to-ℕ (# 1 · 2 · 3) = 10 ⋅ (10 ⋅ (10 ⋅ 0 + 1) + 2) + 3 = ((0 + 100) + 20) + 3 = 100 + 20 + 3 = 123
-- to-ℕ (# a · b · c) = 10 ⋅ (10 ⋅ (10 ⋅ 0 + a) + b) + c = (10² ⋅ a) + (10¹ ⋅ b) + c = (10² ⋅ a) + (10¹ ⋅ b) + (10⁰ ⋅ c)
to-ℕ : Positional b → ℕ
to-ℕ ∅ = 𝟎
to-ℕ {b} (l · n) = (b ⋅ (to-ℕ l)) + (𝕟-to-ℕ n)
import Data.List.Functions as List
open import Logic.Propositional
open import Numeral.Finite.Proofs
open import Numeral.Natural.Inductions
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.FlooredDivision.Proofs
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Modulo.Proofs
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Decidable
open import Numeral.Natural.Relation.Order.Proofs
open import Structure.Relator.Ordering
import Structure.Relator.Names as Names
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Syntax.Transitivity
open import Type.Properties.Decidable
open import Type.Properties.Decidable.Proofs
-- Converts a number to its positional representation in the specified radix.
-- This is done by extracting the next digit using modulo of the radix and then dividing the rest.
-- This is the inverse of to-ℕ.
from-ℕ-rec : ⦃ b-size : IsTrue(b >? 1) ⦄ → (x : ℕ) → ((prev : ℕ) ⦃ _ : prev < x ⦄ → Positional(b)) → Positional(b)
from-ℕ-rec b@{𝐒(𝐒 _)} 𝟎 _ = ∅
from-ℕ-rec b@{𝐒(𝐒 _)} n@(𝐒 _) prev = (prev(n ⌊/⌋ b) ⦃ [⌊/⌋]-ltₗ {n}{b} ⦄) · (ℕ-to-𝕟 (n mod b) ⦃ [↔]-to-[→] decider-true (mod-maxᵣ{n}{b}) ⦄)
from-ℕ : ℕ → Positional(b)
from-ℕ {0} = const ∅
from-ℕ {1} = List.repeat 𝟎
from-ℕ b@{𝐒(𝐒 _)} = Strict.Properties.wellfounded-recursion(_<_) from-ℕ-rec
instance
[≡ₚₒₛ]-reflexivity : Reflexivity(_≡ₚₒₛ_ {b})
[≡ₚₒₛ]-reflexivity = intro p where
p : Names.Reflexivity(_≡ₚₒₛ_ {b})
p {x = ∅} = empty
p {x = _ ⊰ _} = _≡ₚₒₛ_.step p
instance
[≡ₚₒₛ]-symmetry : Symmetry(_≡ₚₒₛ_ {b})
[≡ₚₒₛ]-symmetry = intro p where
p : Names.Symmetry(_≡ₚₒₛ_ {b})
p empty = empty
p (skipₗ eq) = skipᵣ (p eq)
p (skipᵣ eq) = skipₗ (p eq)
p (_≡ₚₒₛ_.step eq) = _≡ₚₒₛ_.step (p eq)
instance
[≡ₚₒₛ]-transitivity : Transitivity(_≡ₚₒₛ_ {b})
[≡ₚₒₛ]-transitivity = intro p where
p : Names.Transitivity(_≡ₚₒₛ_ {b})
p empty empty = empty
p empty (skipᵣ b) = skipᵣ b
p (skipₗ a) empty = skipₗ a
p (skipₗ a) (skipᵣ b) = _≡ₚₒₛ_.step (p a b)
p (skipᵣ a) (skipₗ b) = p a b
p (skipᵣ a) (_≡ₚₒₛ_.step b) = skipᵣ (p a b)
p (_≡ₚₒₛ_.step a) (skipₗ b) = skipₗ (p a b)
p (_≡ₚₒₛ_.step a) (_≡ₚₒₛ_.step b) = _≡ₚₒₛ_.step (p a b)
instance
[≡ₚₒₛ]-equivalence : Equivalence(_≡ₚₒₛ_ {b})
[≡ₚₒₛ]-equivalence = intro
open import Structure.Setoid using (Equiv ; intro)
Positional-equiv : Equiv(Positional(b))
Positional-equiv {b} = intro _ ⦃ [≡ₚₒₛ]-equivalence {b} ⦄
open import Lang.Instance
open import Numeral.Natural.Relation.Proofs
open import Structure.Function
open import Structure.Operator
open import Relator.Equals
open import Relator.Equals.Proofs
from-ℕ-digit : ⦃ b-size : IsTrue(b >? 1) ⦄ → ⦃ _ : IsTrue(n <? b) ⦄ → (from-ℕ {b} n ≡ₚₒₛ ℕ-to-𝕟 n ⊰ ∅)
from-ℕ-digit b@{𝐒(𝐒 bb)} {n} = Strict.Properties.wellfounded-recursion-intro(_<_) {rec = from-ℕ-rec} {φ = \{n} expr → ⦃ _ : IsTrue(n <? b) ⦄ → (expr ≡ₚₒₛ (ℕ-to-𝕟 n ⊰ ∅))} p {n} where
p : (y : ℕ) → _ → _ → ⦃ _ : IsTrue(y <? b) ⦄ → (from-ℕ y ≡ₚₒₛ (ℕ-to-𝕟 y ⊰ ∅))
p 𝟎 prev eq = skipᵣ empty
p (𝐒 y) prev eq ⦃ ord ⦄ =
from-ℕ (𝐒(y)) 🝖[ _≡ₚₒₛ_ ]-[ sub₂(_≡_)(_≡ₚₒₛ_) (eq{y} ⦃ reflexivity(_≤_) ⦄) ]
from-ℕ (𝐒(y) ⌊/⌋ b) · ℕ-to-𝕟 (𝐒(y) mod b) ⦃ yb-ord? ⦄ 🝖[ _≡ₚₒₛ_ ]-[ _≡ₚₒₛ_.step (prev ⦃ [⌊/⌋]-ltₗ{𝐒 y}{b} ⦄ ⦃ div-ord ⦄) ]
∅ · ℕ-to-𝕟 (𝐒(y) ⌊/⌋ b) ⦃ div-ord ⦄ · ℕ-to-𝕟 (𝐒(y) mod b) ⦃ yb-ord? ⦄ 🝖[ _≡ₚₒₛ_ ]-[ sub₂(_≡_)(_≡ₚₒₛ_) (congruence₂ᵣ(_·_)(_) (congruence-ℕ-to-𝕟 ⦃ infer ⦄ ⦃ yb-ord? ⦄ (mod-lesser-than-modulus {𝐒 y}{𝐒 bb} ⦃ yb-ord ⦄))) ]
∅ · ℕ-to-𝕟 (𝐒(y) ⌊/⌋ b) ⦃ div-ord ⦄ · ℕ-to-𝕟 (𝐒(y)) 🝖[ _≡ₚₒₛ_ ]-[ _≡ₚₒₛ_.step (sub₂(_≡_)(_≡ₚₒₛ_) (congruence₂ᵣ(_·_)(_) (congruence-ℕ-to-𝕟 ⦃ infer ⦄ ⦃ div-ord ⦄ ([⌊/⌋]-zero {𝐒 y}{b} yb-ord2)))) ]
∅ · 𝟎 · ℕ-to-𝕟 (𝐒(y)) 🝖[ _≡ₚₒₛ_ ]-[ _≡ₚₒₛ_.step (skipₗ empty) ]
∅ · ℕ-to-𝕟 (𝐒(y)) 🝖-end
where
yb-ord? = [↔]-to-[→] decider-true (mod-maxᵣ {𝐒(y)}{b} ⦃ infer ⦄)
yb-ord = [↔]-to-[←] (decider-true ⦃ [<]-decider ⦄) ord
yb-ord2 = [↔]-to-[←] (decider-true ⦃ [<]-decider ⦄) ord
div-ord = [↔]-to-[→] decider-true ([⌊/⌋]-preserve-[<]ₗ {𝐒 y}{b}{b} yb-ord2)
from-ℕ-step : ⦃ b-size : IsTrue(b >? 1) ⦄
→ let pos = [↔]-to-[←] Positive-greater-than-zero ([≤]-predecessor ([↔]-to-[←] (decider-true ⦃ [<]-decider {1}{b} ⦄) b-size))
in (from-ℕ {b} n ≡ₚₒₛ (from-ℕ {b} ((n ⌊/⌋ b) ⦃ pos ⦄)) · (ℕ-to-𝕟 ((n mod b) ⦃ pos ⦄) ⦃ [↔]-to-[→] decider-true (mod-maxᵣ{n}{b} ⦃ pos ⦄) ⦄))
from-ℕ-step b@{𝐒(𝐒 bb)} {n} = Strict.Properties.wellfounded-recursion-intro(_<_) {rec = from-ℕ-rec} {φ = \{n} expr → (expr ≡ₚₒₛ from-ℕ {b} (n ⌊/⌋ b) · (ℕ-to-𝕟 (n mod b) ⦃ ord n ⦄))} p {n} where
ord = \n → [↔]-to-[→] decider-true (mod-maxᵣ{n}{b})
p : (y : ℕ) → _ → _ → Strict.Properties.accessible-recursion(_<_) from-ℕ-rec y ≡ₚₒₛ from-ℕ (y ⌊/⌋ b) · ℕ-to-𝕟 (y mod b) ⦃ ord y ⦄
p 𝟎 prev eq = skipᵣ empty
p (𝐒 y) prev eq = (sub₂(_≡_)(_≡ₚₒₛ_) (eq {y} ⦃ reflexivity(_≤_) ⦄))
open import Numeral.Natural.Oper.FlooredDivision.Proofs.Inverse
open import Numeral.Natural.Oper.Proofs
open import Structure.Operator.Properties
from-ℕ-step-invs : ⦃ b-size : IsTrue(b >? 1) ⦄ → (from-ℕ {b} ((b ⋅ n) + (𝕟-to-ℕ d)) ≡ₚₒₛ (from-ℕ {b} n) · d)
from-ℕ-step-invs b@{𝐒(𝐒 bb)} {n}{d} =
from-ℕ (b ⋅ n + 𝕟-to-ℕ d) 🝖[ _≡ₚₒₛ_ ]-[ from-ℕ-step {n = b ⋅ n + 𝕟-to-ℕ d} ]
from-ℕ ((b ⋅ n + 𝕟-to-ℕ d) ⌊/⌋ b) · (ℕ-to-𝕟 ((b ⋅ n + 𝕟-to-ℕ d) mod b) ⦃ _ ⦄) 🝖[ _≡ₚₒₛ_ ]-[ sub₂(_≡_)(_≡ₚₒₛ_) (congruence₂(_·_) (congruence₁(from-ℕ) r) (congruence-ℕ-to-𝕟 ⦃ infer ⦄ ⦃ ord1 ⦄ ⦃ ord2 ⦄ q 🝖 ℕ-𝕟-inverse)) ]
from-ℕ n · d 🝖-end where
ord1 = [↔]-to-[→] decider-true (mod-maxᵣ{(b ⋅ n) + (𝕟-to-ℕ d)}{b})
ord2 = [↔]-to-[→] decider-true ([<]-of-𝕟-to-ℕ {b}{d})
q =
((b ⋅ n) + 𝕟-to-ℕ d) mod b 🝖[ _≡_ ]-[ congruence₁(_mod b) (commutativity(_+_) {b ⋅ n}{𝕟-to-ℕ d}) ]
(𝕟-to-ℕ d + (b ⋅ n)) mod b 🝖[ _≡_ ]-[ mod-of-modulus-sum-multiple {𝕟-to-ℕ d}{b}{n} ]
(𝕟-to-ℕ d) mod b 🝖[ _≡_ ]-[ mod-lesser-than-modulus ⦃ [≤]-without-[𝐒] [<]-of-𝕟-to-ℕ ⦄ ]
𝕟-to-ℕ d 🝖-end
r =
(b ⋅ n + 𝕟-to-ℕ d) ⌊/⌋ b 🝖[ _≡_ ]-[ [⌊/⌋][+]-distributivityᵣ {b ⋅ n}{𝕟-to-ℕ d}{b} ]
((b ⋅ n) ⌊/⌋ b) + ((𝕟-to-ℕ d) ⌊/⌋ b) 🝖[ _≡_ ]-[ congruence₂(_+_) ([⌊/⌋][swap⋅]-inverseOperatorᵣ {b}{n}) ([⌊/⌋]-zero ([<]-of-𝕟-to-ℕ {b}{d})) ]
n + 𝟎 🝖[ _≡_ ]-[]
n 🝖-end
open import Numeral.Natural.Oper.DivMod.Proofs
open import Structure.Function.Domain
import Structure.Function.Names as Names
instance
from-to-inverse : ⦃ b-size : IsTrue(b >? 1) ⦄ → Inverseᵣ ⦃ Positional-equiv{b} ⦄ from-ℕ to-ℕ
from-to-inverse b@{𝐒(𝐒 _)} = intro p where
p : Names.Inverses ⦃ Positional-equiv{b} ⦄ from-ℕ to-ℕ
p{x = ∅} = empty
p{x = x · n} = from-ℕ-step-invs{b}{to-ℕ x}{n} 🝖 _≡ₚₒₛ_.step (p{x = x})
instance
to-from-inverse : ⦃ b-size : IsTrue(b >? 1) ⦄ → Inverseᵣ(to-ℕ{b}) (from-ℕ{b})
to-from-inverse {b@(𝐒(𝐒 bb))} = intro (\{n} → Strict.Properties.wellfounded-recursion-intro(_<_) {rec = from-ℕ-rec {b}} {φ = \{n} expr → (to-ℕ expr ≡ n)} p {n}) where
p : (y : ℕ) → _ → _ → (to-ℕ {b} (from-ℕ {b} y) ≡ y)
p 𝟎 _ _ = [≡]-intro
p (𝐒 y) prev eq =
to-ℕ {b} (from-ℕ (𝐒 y)) 🝖[ _≡_ ]-[ congruence₁(to-ℕ) (eq {𝐒(y) ⌊/⌋ b} ⦃ ord2 ⦄) ]
to-ℕ {b} ((from-ℕ (𝐒(y) ⌊/⌋ b)) · (ℕ-to-𝕟 (𝐒(y) mod b) ⦃ _ ⦄)) 🝖[ _≡_ ]-[]
(b ⋅ to-ℕ {b} (from-ℕ {b} (𝐒(y) ⌊/⌋ b))) + 𝕟-to-ℕ (ℕ-to-𝕟 (𝐒(y) mod b) ⦃ _ ⦄) 🝖[ _≡_ ]-[ congruence₂(_+_) (congruence₂ᵣ(_⋅_)(b) (prev{𝐒(y) ⌊/⌋ b} ⦃ ord2 ⦄)) (𝕟-ℕ-inverse {b}{𝐒(y) mod b} ⦃ ord1 ⦄) ]
(b ⋅ (𝐒(y) ⌊/⌋ b)) + (𝐒(y) mod b) 🝖[ _≡_ ]-[ [⌊/⌋][mod]-is-division-with-remainder-pred-commuted {𝐒 y}{b} ]
𝐒(y) 🝖-end
where
ord1 = [↔]-to-[→] decider-true (mod-maxᵣ{𝐒(y)}{b})
ord2 = [⌊/⌋]-ltₗ {𝐒 y}{b}
instance
to-ℕ-function : ⦃ b-size : IsTrue(b >? 1) ⦄ → Function ⦃ Positional-equiv ⦄ ⦃ [≡]-equiv ⦄ (to-ℕ {b})
to-ℕ-function {b} = intro p where
p : Names.Congruence₁ ⦃ Positional-equiv ⦄ ⦃ [≡]-equiv ⦄ (to-ℕ {b})
p empty = reflexivity(_≡_)
p (skipₗ xy) rewrite p xy = reflexivity(_≡_)
p (skipᵣ {y = ∅} xy) = reflexivity(_≡_)
p (skipᵣ {y = 𝟎 ⊰ y} (skipᵣ xy))
rewrite symmetry(_≡_) (p xy) = reflexivity(_≡_)
p (_≡ₚₒₛ_.step xy)
rewrite p xy = reflexivity(_≡_)
open import Logic.Predicate
open import Structure.Function.Domain.Proofs
instance
from-ℕ-bijective : ⦃ b-size : IsTrue(b >? 1) ⦄ → Bijective ⦃ [≡]-equiv ⦄ ⦃ Positional-equiv ⦄ (from-ℕ {b})
from-ℕ-bijective = [↔]-to-[→] (invertible-when-bijective ⦃ _ ⦄ ⦃ _ ⦄) ([∃]-intro to-ℕ ⦃ [∧]-intro infer ([∧]-intro infer infer) ⦄)
instance
to-ℕ-bijective : ⦃ b-size : IsTrue(b >? 1) ⦄ → Bijective ⦃ Positional-equiv ⦄ ⦃ [≡]-equiv ⦄ (to-ℕ {b})
to-ℕ-bijective = [↔]-to-[→] (invertible-when-bijective ⦃ _ ⦄ ⦃ _ ⦄) ([∃]-intro from-ℕ ⦃ [∧]-intro ([≡]-to-function ⦃ Positional-equiv ⦄) ([∧]-intro infer infer) ⦄)
import Data.Option.Functions as Option
open import Function.Names
open import Numeral.Natural.Relation.Order.Proofs
-- TODO: Trying to define a bijection, but not really possible because not all functions
PositionalSequence : List(𝕟(𝐒 b)) → (ℕ → 𝕟(𝐒 b))
PositionalSequence l n = (List.index₀ n l) Option.or 𝟎
sequencePositional : (f : ℕ → 𝕟(𝐒 b)) → ∃(N ↦ (f ∘ (_+ N) ⊜ const 𝟎)) → List(𝕟(𝐒 b))
sequencePositional f ([∃]-intro 𝟎) = ∅
sequencePositional f ([∃]-intro (𝐒 N) ⦃ p ⦄) = f(𝟎) ⊰ sequencePositional (f ∘ 𝐒) ([∃]-intro N ⦃ \{n} → p{n} ⦄)
| {
"alphanum_fraction": 0.5257547521,
"avg_line_length": 53.4462151394,
"ext": "agda",
"hexsha": "02772f709c2b06e4a2c9fc2699357d125d45cbb4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/FixedPositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/FixedPositional.agda",
"max_line_length": 328,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/FixedPositional.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": 6165,
"size": 13415
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.