{"size":717,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module test.StringLiteral where\n\nopen import Type\nopen import Declarative\nopen import Builtin\nopen import Builtin.Constant.Type\nopen import Builtin.Constant.Term Ctx\u22c6 Kind * # _\u22a2\u22c6_ con size\u22c6\n\n-- zerepoch\/zerepoch-core\/test\/data\/stringLiteral.plc\n\npostulate str1 : ByteString\n{-# FOREIGN GHC import qualified Data.ByteString.Char8 as BS #-}\n{-# COMPILE GHC str1 = BS.pack \"4321758fabce1aa4780193f\" #-}\n\nopen import Relation.Binary.PropositionalEquality\nopen import Agda.Builtin.TrustMe\n\nlemma1 : length str1 \u2261 23\nlemma1 = primTrustMe\n\nopen import Data.Nat\n\nlemma1' : BoundedB 100 str1\nlemma1' rewrite lemma1 = gen _ _ _\n\nstringLit : \u2200{\u0393} \u2192 \u0393 \u22a2 con bytestring (size\u22c6 100)\nstringLit = con (bytestring 100 str1 lemma1')\n","avg_line_length":25.6071428571,"max_line_length":64,"alphanum_fraction":0.7656903766} {"size":1573,"ext":"agda","lang":"Agda","max_stars_count":5.0,"content":"-- a few random examples\nmodule Test where\nimport Agda.Builtin.Bool\n\ndata Nat : Set where zero : Nat -- Comment which gets eaten\n suc : Nat -> Nat --Comment which is preserved\n\nplus {- preserved comment {- which may be nested -} -} :\n{- comment after Colon, also preserved-}\n{-comments are essentially whitespace, even through they get parsed-} Nat -> {-comment, preserved-} Nat -> Nat\n{-# BUILTIN NATURAL\nNat #-}\n\nplus zero m = m\nplus (suc n) m = suc (plus n m)\n\n{-# BUILTIN NATPLUS plus #-}\n\n--excess brackets are not preserved\nminus : ((Nat)) -> Nat\n-- We can nest holes correctly\nminus a = {! ? {! Hole inside hole !} !}\n\n-- Seriously long and complicated function type\nfunc : {A : Set} ->\n {B : A -> Set} ->\n {C : (x : A) -> B x -> Set} ->\n (f : {x : A} -> (y : B x) -> C x y) ->\n (g : (x : A) -> B x) ->\n (x : A) ->\n C x (g x)\nfunc f g x = f (g x)\n\n-- Holes can go here as well\nid : {a : Set} -> a -> {! !}\nid x = x\n\n-- and the code from the planning report, rewritten in Baby-Agda\n\ndata List (A : Set) : Set where\n empty : List A\n cons : A -> List A -> List A\n\nappend : {A : Set} -> List A -> List A -> List A\nappend empty ys = ys\nappend (cons x xs) ys = cons x (append xs ys)\n\n-- proposed code after refactoring\n\ndata List2 (A : Set) : Nat -> Set where\n empty2 : List2 A 0\n cons2 : {n : Nat} -> A -> List2 A n -> List2 A (plus 1 n)\n\nappend2 : {n : Nat} -> {m : Nat} -> {A : Set} ->\n List2 A m -> List2 A n -> List2 A (plus m n)\nappend2 empty2 ys = ys\nappend2 (cons2 x xs) ys = cons2 x (append2 xs ys)\n","avg_line_length":27.1206896552,"max_line_length":114,"alphanum_fraction":0.5708836618} {"size":2669,"ext":"agda","lang":"Agda","max_stars_count":4.0,"content":"module SystemF.BigStep.Types where\n\nopen import Prelude\n\n-- types are indexed by the number of open tvars\ninfixl 10 _\u21d2_\ndata Type (n : \u2115) : Set where\n Unit : Type n\n \u03bd : (i : Fin n) \u2192 Type n\n _\u21d2_ : Type n \u2192 Type n \u2192 Type n\n \u2200' : Type (suc n) \u2192 Type n\n\nopen import Data.Fin.Substitution\nopen import Data.Vec\n\nmodule App {T} (l : Lift T Type )where\n open Lift l hiding (var)\n _\/_ : \u2200 {m n} \u2192 Type m \u2192 Sub T m n \u2192 Type n\n Unit \/ s = Unit\n \u03bd i \/ s = lift (lookup i s)\n (a \u21d2 b) \/ s = (a \/ s) \u21d2 (b \/ s)\n \u2200' x \/ s = \u2200' (x \/ (s \u2191))\n\n open Application (record { _\/_ = _\/_ }) using (_\/\u2736_)\n\n open import Data.Star\n\n Unit-\/\u2736-\u2191\u2736 : \u2200 k {m n} (\u03c1s : Subs T m n) \u2192 Unit \/\u2736 \u03c1s \u2191\u2736 k \u2261 Unit\n Unit-\/\u2736-\u2191\u2736 k \u03b5 = refl\n Unit-\/\u2736-\u2191\u2736 k (x \u25c5 \u03c1s) = cong\u2082 _\/_ (Unit-\/\u2736-\u2191\u2736 k \u03c1s) refl\n\n \u2200-\/\u2736-\u2191\u2736 : \u2200 k {m n t} (\u03c1s : Subs T m n) \u2192\n \u2200' t \/\u2736 \u03c1s \u2191\u2736 k \u2261 \u2200' (t \/\u2736 \u03c1s \u2191\u2736 suc k)\n \u2200-\/\u2736-\u2191\u2736 k \u03b5 = refl\n \u2200-\/\u2736-\u2191\u2736 k (\u03c1 \u25c5 \u03c1s) = cong\u2082 _\/_ (\u2200-\/\u2736-\u2191\u2736 k \u03c1s) refl\n\n \u21d2-\/\u2736-\u2191\u2736 : \u2200 k {m n t\u2081 t\u2082} (\u03c1s : Subs T m n) \u2192\n t\u2081 \u21d2 t\u2082 \/\u2736 \u03c1s \u2191\u2736 k \u2261 (t\u2081 \/\u2736 \u03c1s \u2191\u2736 k) \u21d2 (t\u2082 \/\u2736 \u03c1s \u2191\u2736 k)\n \u21d2-\/\u2736-\u2191\u2736 k \u03b5 = refl\n \u21d2-\/\u2736-\u2191\u2736 k (\u03c1 \u25c5 \u03c1s) = cong\u2082 _\/_ (\u21d2-\/\u2736-\u2191\u2736 k \u03c1s) refl\n\ntmSubst : TermSubst Type\ntmSubst = record { var = \u03bd; app = App._\/_ }\n\nopen TermSubst tmSubst hiding (var; subst) public\n\nmodule Lemmas where\n\n open import Data.Fin.Substitution.Lemmas\n\n tyLemmas : TermLemmas Type\n tyLemmas = record\n { termSubst = tmSubst\n ; app-var = refl\n ; \/\u2736-\u2191\u2736 = Lemma.\/\u2736-\u2191\u2736\n }\n where\n module Lemma {T\u2081 T\u2082} {lift\u2081 : Lift T\u2081 Type} {lift\u2082 : Lift T\u2082 Type} where\n\n open Lifted lift\u2081 using () renaming (_\u2191\u2736_ to _\u2191\u2736\u2081_; _\/\u2736_ to _\/\u2736\u2081_)\n open Lifted lift\u2082 using () renaming (_\u2191\u2736_ to _\u2191\u2736\u2082_; _\/\u2736_ to _\/\u2736\u2082_)\n\n \/\u2736-\u2191\u2736 : \u2200 {m n} (\u03c1s\u2081 : Subs T\u2081 m n) (\u03c1s\u2082 : Subs T\u2082 m n) \u2192\n (\u2200 k x \u2192 \u03bd x \/\u2736\u2081 \u03c1s\u2081 \u2191\u2736\u2081 k \u2261 \u03bd x \/\u2736\u2082 \u03c1s\u2082 \u2191\u2736\u2082 k) \u2192\n \u2200 k t \u2192 t \/\u2736\u2081 \u03c1s\u2081 \u2191\u2736\u2081 k \u2261 t \/\u2736\u2082 \u03c1s\u2082 \u2191\u2736\u2082 k\n \/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp k Unit =\n begin _ \u2261\u27e8 App.Unit-\/\u2736-\u2191\u2736 _ k \u03c1s\u2081 \u27e9 Unit \u2261\u27e8 sym $ App.Unit-\/\u2736-\u2191\u2736 _ k \u03c1s\u2082 \u27e9 _ \u220e\n \/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp k (\u03bd i) = hyp k i\n \/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp k (a \u21d2 b) = begin\n _ \u2261\u27e8 App.\u21d2-\/\u2736-\u2191\u2736 _ k \u03c1s\u2081 \u27e9\n (a \/\u2736\u2081 \u03c1s\u2081 \u2191\u2736\u2081 k) \u21d2 (b \/\u2736\u2081 \u03c1s\u2081 \u2191\u2736\u2081 k) \u2261\u27e8 cong\u2082 _\u21d2_ (\/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp k a)\n ((\/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp k b)) \u27e9\n (a \/\u2736\u2082 \u03c1s\u2082 \u2191\u2736\u2082 k) \u21d2 (b \/\u2736\u2082 \u03c1s\u2082 \u2191\u2736\u2082 k) \u2261\u27e8 sym $ App.\u21d2-\/\u2736-\u2191\u2736 _ k \u03c1s\u2082 \u27e9\n _ \u220e\n \/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp k (\u2200' x) = begin\n _ \u2261\u27e8 App.\u2200-\/\u2736-\u2191\u2736 _ k \u03c1s\u2081 \u27e9\n \u2200' (x \/\u2736\u2081 \u03c1s\u2081 \u2191\u2736\u2081 (suc k)) \u2261\u27e8 cong \u2200' (\/\u2736-\u2191\u2736 \u03c1s\u2081 \u03c1s\u2082 hyp (suc k) x) \u27e9\n \u2200' (x \/\u2736\u2082 \u03c1s\u2082 \u2191\u2736\u2082 (suc k)) \u2261\u27e8 sym $ App.\u2200-\/\u2736-\u2191\u2736 _ k \u03c1s\u2082 \u27e9\n _ \u220e\n\n open TermLemmas tyLemmas public hiding (var)\n","avg_line_length":32.5487804878,"max_line_length":86,"alphanum_fraction":0.4499812664} {"size":432,"ext":"agda","lang":"Agda","max_stars_count":1.0,"content":"\n-- This module is used to illustrate how to import a non-parameterised module.\nmodule examples.syntax.ModuleA where\n\n data Nat : Set where\n zero : Nat\n suc : Nat -> Nat\n plus : Nat -> Nat -> Nat\n\n eval : Nat -> Nat\n eval zero\t\t = zero\n eval (suc x)\t\t = suc (eval x)\n eval (plus zero y)\t = eval y\n eval (plus (suc x) y)\t = suc (eval (plus x y))\n eval (plus (plus x y) z) = eval (plus x (plus y z))\n\n","avg_line_length":25.4117647059,"max_line_length":78,"alphanum_fraction":0.5787037037} {"size":1086,"ext":"agda","lang":"Agda","max_stars_count":6.0,"content":"open import Relation.Binary.Core\n\nmodule BBSTree.Properties {A : Set} \n (_\u2264_ : A \u2192 A \u2192 Set)\n (trans\u2264 : Transitive _\u2264_) where\n\nopen import BBSTree _\u2264_\nopen import Bound.Total A\nopen import Bound.Total.Order.Properties _\u2264_ trans\u2264\nopen import List.Order.Simple _\u2264_\nopen import List.Order.Simple.Properties _\u2264_ trans\u2264\nopen import List.Sorted _\u2264_\n\nlemma-bbst-*\u2264 : {b : Bound}(x : A) \u2192 (t : BBSTree b (val x)) \u2192 flatten t *\u2264 x\nlemma-bbst-*\u2264 x (bslf _) = lenx\nlemma-bbst-*\u2264 x (bsnd {x = y} b\u2264y y\u2264x l r) = lemma-++-*\u2264 (lemma-LeB\u2264 y\u2264x) (lemma-bbst-*\u2264 y l) (lemma-bbst-*\u2264 x r)\n\nlemma-bbst-\u2264* : {b : Bound}(x : A) \u2192 (t : BBSTree (val x) b) \u2192 x \u2264* flatten t\nlemma-bbst-\u2264* x (bslf _) = genx\nlemma-bbst-\u2264* x (bsnd {x = y} x\u2264y y\u2264t l r) = lemma-\u2264*-++ (lemma-LeB\u2264 x\u2264y) (lemma-bbst-\u2264* x l) (lemma-bbst-\u2264* y r)\n\nlemma-bbst-sorted : {b t : Bound}(t : BBSTree b t) \u2192 Sorted (flatten t)\nlemma-bbst-sorted (bslf _) = nils\nlemma-bbst-sorted (bsnd {x = x} b\u2264x x\u2264t l r) = lemma-sorted++ (lemma-bbst-*\u2264 x l) (lemma-bbst-\u2264* x r) (lemma-bbst-sorted l) (lemma-bbst-sorted r)\n","avg_line_length":43.44,"max_line_length":145,"alphanum_fraction":0.6012891344} {"size":2329,"ext":"agda","lang":"Agda","max_stars_count":301.0,"content":"{-# OPTIONS --safe #-}\nmodule Cubical.Data.Unit.Properties where\n\nopen import Cubical.Core.Everything\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Isomorphism\n\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Unit.Base\nopen import Cubical.Data.Prod.Base\n\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Univalence\n\nopen import Cubical.Reflection.StrictEquiv\n\nisContrUnit : isContr Unit\nisContrUnit = tt , \u03bb {tt \u2192 refl}\n\nisPropUnit : isProp Unit\nisPropUnit _ _ i = tt -- definitionally equal to: isContr\u2192isProp isContrUnit\n\nisSetUnit : isSet Unit\nisSetUnit = isProp\u2192isSet isPropUnit\n\nisOfHLevelUnit : (n : HLevel) \u2192 isOfHLevel n Unit\nisOfHLevelUnit n = isContr\u2192isOfHLevel n isContrUnit\n\nmodule _ {\u2113} (A : Type \u2113) where\n UnitToType\u2243 : (Unit \u2192 A) \u2243 A\n unquoteDef UnitToType\u2243 = defStrictEquiv UnitToType\u2243 (\u03bb f \u2192 f _) const\n\nUnitToTypePath : \u2200 {\u2113} (A : Type \u2113) \u2192 (Unit \u2192 A) \u2261 A\nUnitToTypePath A = ua (UnitToType\u2243 A)\n\nisContr\u2192Iso2 : \u2200 {\u2113 \u2113'} {A : Type \u2113} {B : Type \u2113'} \u2192 isContr A \u2192 Iso (A \u2192 B) B\nIso.fun (isContr\u2192Iso2 iscontr) f = f (fst iscontr)\nIso.inv (isContr\u2192Iso2 iscontr) b _ = b\nIso.rightInv (isContr\u2192Iso2 iscontr) _ = refl\nIso.leftInv (isContr\u2192Iso2 iscontr) f = funExt \u03bb x \u2192 cong f (snd iscontr x)\n\ndiagonal-unit : Unit \u2261 Unit \u00d7 Unit\ndiagonal-unit = isoToPath (iso (\u03bb x \u2192 tt , tt) (\u03bb x \u2192 tt) (\u03bb {(tt , tt) i \u2192 tt , tt}) \u03bb {tt i \u2192 tt})\n\nfibId : \u2200 {\u2113} (A : Type \u2113) \u2192 (fiber (\u03bb (x : A) \u2192 tt) tt) \u2261 A\nfibId A = ua e\n where\n unquoteDecl e = declStrictEquiv e fst (\u03bb a \u2192 a , refl)\n\nisContr\u2192\u2243Unit : \u2200 {\u2113} {A : Type \u2113} \u2192 isContr A \u2192 A \u2243 Unit\nisContr\u2192\u2243Unit contr = isoToEquiv (iso (\u03bb _ \u2192 tt) (\u03bb _ \u2192 fst contr) (\u03bb _ \u2192 refl) \u03bb _ \u2192 snd contr _)\n\nisContr\u2192\u2261Unit : {A : Type\u2080} \u2192 isContr A \u2192 A \u2261 Unit\nisContr\u2192\u2261Unit contr = ua (isContr\u2192\u2243Unit contr)\n\nisContrUnit* : \u2200 {\u2113} \u2192 isContr (Unit* {\u2113})\nisContrUnit* = tt* , \u03bb _ \u2192 refl\n\nisPropUnit* : \u2200 {\u2113} \u2192 isProp (Unit* {\u2113})\nisPropUnit* _ _ = refl\n\nisOfHLevelUnit* : \u2200 {\u2113} (n : HLevel) \u2192 isOfHLevel n (Unit* {\u2113})\nisOfHLevelUnit* zero = tt* , \u03bb _ \u2192 refl\nisOfHLevelUnit* (suc zero) _ _ = refl\nisOfHLevelUnit* (suc (suc zero)) _ _ _ _ _ _ = tt*\nisOfHLevelUnit* (suc (suc (suc n))) = isOfHLevelPlus 3 (isOfHLevelUnit* n)\n","avg_line_length":32.8028169014,"max_line_length":100,"alphanum_fraction":0.6865607557} {"size":460,"ext":"agda","lang":"Agda","max_stars_count":29.0,"content":"-- a simple error monad\nmodule error where\n\nopen import level\nopen import string\n\ninfixr 0 _\u226b=err_ _\u226berr_\n\ndata error-t{\u2113}(A : Set \u2113) : Set \u2113 where\n no-error : A \u2192 error-t A\n yes-error : string \u2192 error-t A\n\n_\u226b=err_ : \u2200{\u2113 \u2113'}{A : Set \u2113}{B : Set \u2113'} \u2192 error-t A \u2192 (A \u2192 error-t B) \u2192 error-t B\n(no-error a) \u226b=err f = f a\n(yes-error e) \u226b=err _ = yes-error e\n\n_\u226berr_ : \u2200{\u2113 \u2113'}{A : Set \u2113}{B : Set \u2113'} \u2192 error-t A \u2192 error-t B \u2192 error-t B\na \u226berr b = a \u226b=err \u03bb _ \u2192 b\n\n","avg_line_length":23.0,"max_line_length":82,"alphanum_fraction":0.5804347826} {"size":467,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\nopen import lib.types.Truncation\nopen import lib.types.Pi\n\nmodule lib.types.Choice where\n\nunchoose : \u2200 {i j} {n : \u2115\u208b\u2082} {A : Type i} {B : A \u2192 Type j}\n \u2192 Trunc n (\u03a0 A B) \u2192 \u03a0 A (Trunc n \u2218 B)\nunchoose = Trunc-rec (\u03a0-level \u03bb _ \u2192 Trunc-level) (\u03bb f \u2192 [_] \u2218 f)\n\nhas-choice : \u2200 {i} (n : \u2115\u208b\u2082) (A : Type i) j \u2192 Type (lmax i (lsucc j))\nhas-choice {i} n A j = (B : A \u2192 Type j) \u2192 is-equiv (unchoose {n = n} {A} {B})\n","avg_line_length":31.1333333333,"max_line_length":77,"alphanum_fraction":0.5824411135} {"size":181,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"postulate\n R : Set \u2192 Set1\n r : {X : Set} {{ _ : R X }} \u2192 X \u2192 Set\n A : Set\n a : A\n\ninstance\n RI : R A\n -- RI = {!!} -- uncommenting lets instance resolution succeed\n\nfoo : r a\n","avg_line_length":15.0833333333,"max_line_length":63,"alphanum_fraction":0.5248618785} {"size":6400,"ext":"agda","lang":"Agda","max_stars_count":29.0,"content":"-- Basic intuitionistic modal logic S4, without \u2228, \u22a5, or \u25c7.\n-- Canonical model equipment for Kripke-style semantics.\n\nmodule BasicIS4.Equipment.KripkeDyadicCanonical where\n\nopen import BasicIS4.Syntax.Common public\n\n\n\n\nmodule Syntax\n (_\u22a2_ : Cx\u00b2 Ty Ty \u2192 Ty \u2192 Set)\n (mono\u00b2\u22a2 : \u2200 {A \u03a0 \u03a0\u2032} \u2192 \u03a0 \u2286\u00b2 \u03a0\u2032 \u2192 \u03a0 \u22a2 A \u2192 \u03a0\u2032 \u22a2 A)\n (up : \u2200 {A \u03a0} \u2192 \u03a0 \u22a2 (\u25a1 A) \u2192 \u03a0 \u22a2 (\u25a1 \u25a1 A))\n (down : \u2200 {A \u03a0} \u2192 \u03a0 \u22a2 (\u25a1 A) \u2192 \u03a0 \u22a2 A)\n (lift : \u2200 {A \u0393 \u0394} \u2192 (\u0393 \u204f \u0394) \u22a2 A \u2192 (\u25a1\u22c6 \u0393 \u204f \u0394) \u22a2 (\u25a1 A))\n where\n\n\n -- Worlds.\n\n World\u1d9c : Set\n World\u1d9c = Cx\u00b2 Ty Ty\n\n\n -- Intuitionistic accessibility.\n\n infix 3 _\u2264\u1d9c_\n _\u2264\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _\u2264\u1d9c_ = _\u2286\u00b2_\n\n refl\u2264\u1d9c : \u2200 {w} \u2192 w \u2264\u1d9c w\n refl\u2264\u1d9c = refl\u2286\u00b2\n\n trans\u2264\u1d9c : \u2200 {w w\u2032 w\u2033} \u2192 w \u2264\u1d9c w\u2032 \u2192 w\u2032 \u2264\u1d9c w\u2033 \u2192 w \u2264\u1d9c w\u2033\n trans\u2264\u1d9c = trans\u2286\u00b2\n\n bot\u2264\u1d9c : \u2200 {w} \u2192 \u2205\u00b2 \u2264\u1d9c w\n bot\u2264\u1d9c = bot\u2286\u00b2\n\n\n -- The canonical modal accessibility, based on the T axiom.\n\n infix 3 _R\u1d9c_\n _R\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n w R\u1d9c w\u2032 = \u2200 {A} \u2192 w \u22a2 (\u25a1 A) \u2192 w\u2032 \u22a2 A\n\n reflR\u1d9c : \u2200 {w} \u2192 w R\u1d9c w\n reflR\u1d9c = down\n\n transR\u1d9c : \u2200 {w w\u2032 w\u2033} \u2192 w R\u1d9c w\u2032 \u2192 w\u2032 R\u1d9c w\u2033 \u2192 w R\u1d9c w\u2033\n transR\u1d9c \u03b6 \u03b6\u2032 = \u03b6\u2032 \u2218 \u03b6 \u2218 up\n\n botR\u1d9c : \u2200 {w} \u2192 \u2205\u00b2 R\u1d9c w\n botR\u1d9c = mono\u00b2\u22a2 bot\u2264\u1d9c \u2218 down\n\n liftR\u1d9c : \u2200 {\u0393 \u0394} \u2192 \u0393 \u204f \u0394 R\u1d9c \u25a1\u22c6 \u0393 \u204f \u0394\n liftR\u1d9c = down \u2218 lift \u2218 down\n\n\n -- Composition of accessibility.\n\n infix 3 _\u2264\u2a3eR\u1d9c_\n _\u2264\u2a3eR\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _\u2264\u2a3eR\u1d9c_ = _\u2264\u1d9c_ \u2a3e _R\u1d9c_\n\n infix 3 _R\u2a3e\u2264\u1d9c_\n _R\u2a3e\u2264\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _R\u2a3e\u2264\u1d9c_ = _R\u1d9c_ \u2a3e _\u2264\u1d9c_\n\n refl\u2264\u2a3eR\u1d9c : \u2200 {w} \u2192 w \u2264\u2a3eR\u1d9c w\n refl\u2264\u2a3eR\u1d9c {w} = w , (refl\u2264\u1d9c , reflR\u1d9c)\n\n reflR\u2a3e\u2264\u1d9c : \u2200 {w} \u2192 w R\u2a3e\u2264\u1d9c w\n reflR\u2a3e\u2264\u1d9c {w} = w , (reflR\u1d9c , refl\u2264\u1d9c)\n\n\n -- Persistence condition, after Iemhoff; included by Ono.\n --\n -- w\u2032 v\u2032 \u2192 v\u2032\n -- \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf \u2192 \u25cf\n -- \u2502 \u2192 \u2571\n -- \u2264 \u03be,\u03b6 \u2192 R\n -- \u2502 \u2192 \u2571\n -- \u25cf \u2192 \u25cf\n -- w \u2192 w\n\n \u2264\u2a3eR\u2192R\u1d9c : \u2200 {v\u2032 w} \u2192 w \u2264\u2a3eR\u1d9c v\u2032 \u2192 w R\u1d9c v\u2032\n \u2264\u2a3eR\u2192R\u1d9c (w\u2032 , (\u03be , \u03b6)) = \u03b6 \u2218 mono\u00b2\u22a2 \u03be\n\n\n -- Brilliance condition, after Iemhoff.\n --\n -- v\u2032 \u2192 v\u2032\n -- \u25cf \u2192 \u25cf\n -- \u2502 \u2192 \u2571\n -- \u03b6,\u03be \u2264 \u2192 R\n -- \u2502 \u2192 \u2571\n -- \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc \u2192 \u25cf\n -- w v \u2192 w\n\n R\u2a3e\u2264\u2192R\u1d9c : \u2200 {w v\u2032} \u2192 w R\u2a3e\u2264\u1d9c v\u2032 \u2192 w R\u1d9c v\u2032\n R\u2a3e\u2264\u2192R\u1d9c (v , (\u03b6 , \u03be)) = mono\u00b2\u22a2 \u03be \u2218 \u03b6\n\n\n -- Minor persistence condition, included by Bo\u017ei\u0107 and Do\u0161en.\n --\n -- w\u2032 v\u2032 \u2192 v\u2032\n -- \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf \u2192 \u25cf\n -- \u2502 \u2192 \u2502\n -- \u2264 \u03be,\u03b6 \u2192 \u2264\n -- \u2502 \u2192 \u2502\n -- \u25cf \u2192 \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc\n -- w \u2192 w v\n --\n -- w\u2033 \u2192 w\u2033\n -- \u25cf \u2192 \u25cf\n -- \u2502 \u2192 \u2502\n -- \u03be\u2032,\u03b6\u2032 \u2264 \u2192 \u2502\n -- \u2502 \u2192 \u2502\n -- \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc \u2192 \u2264\n -- \u2502 v\u2032 \u2192 \u2502\n -- \u03be,\u03b6 \u2264 \u2192 \u2502\n -- \u2502 \u2192 \u2502\n -- \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc \u2192 \u25cf\u2500\u2500\u2500\u2500\u2500\u2500\u2500R\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25cc\n -- w v \u2192 w v\u2033\n\n \u2264\u2a3eR\u2192R\u2a3e\u2264\u1d9c : \u2200 {v\u2032 w} \u2192 w \u2264\u2a3eR\u1d9c v\u2032 \u2192 w R\u2a3e\u2264\u1d9c v\u2032\n \u2264\u2a3eR\u2192R\u2a3e\u2264\u1d9c {v\u2032} \u03be,\u03b6 = v\u2032 , (\u2264\u2a3eR\u2192R\u1d9c \u03be,\u03b6 , refl\u2264\u1d9c)\n\n transR\u2a3e\u2264\u1d9c : \u2200 {w\u2032 w w\u2033} \u2192 w R\u2a3e\u2264\u1d9c w\u2032 \u2192 w\u2032 R\u2a3e\u2264\u1d9c w\u2033 \u2192 w R\u2a3e\u2264\u1d9c w\u2033\n transR\u2a3e\u2264\u1d9c {w\u2032} (v , (\u03b6 , \u03be)) (v\u2032 , (\u03b6\u2032 , \u03be\u2032)) = let v\u2033 , (\u03b6\u2033 , \u03be\u2033) = \u2264\u2a3eR\u2192R\u2a3e\u2264\u1d9c (w\u2032 , (\u03be , \u03b6\u2032))\n in v\u2033 , (transR\u1d9c \u03b6 \u03b6\u2033 , trans\u2264\u1d9c \u03be\u2033 \u03be\u2032)\n\n \u2264\u2192R\u1d9c : \u2200 {v\u2032 w} \u2192 w \u2264\u1d9c v\u2032 \u2192 w R\u1d9c v\u2032\n \u2264\u2192R\u1d9c {v\u2032} \u03be = \u2264\u2a3eR\u2192R\u1d9c (v\u2032 , (\u03be , reflR\u1d9c))\n\n\n -- Minor brilliance condition, included by Ewald and Alechina et al.\n --\n -- v\u2032 \u2192 w\u2032 v\u2032\n -- \u25cf \u2192 \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf\n -- \u2502 \u2192 \u2502\n -- \u03b6,\u03be \u2264 \u2192 \u2264\n -- \u2502 \u2192 \u2502\n -- \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc \u2192 \u25cf\n -- w v \u2192 w\n --\n -- v\u2032 w\u2033 \u2192 v\u2033 w\u2033\n -- \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf \u2192 \u25cc\u2500\u2500\u2500\u2500\u2500\u2500\u2500R\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25cf\n -- \u2502 \u2192 \u2502\n -- \u2264 \u03be\u2032,\u03b6\u2032 \u2192 \u2502\n -- v \u2502 \u2192 \u2502\n -- \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf \u2192 \u2264\n -- \u2502 w\u2032 \u2192 \u2502\n -- \u2264 \u03be,\u03b6 \u2192 \u2502\n -- \u2502 \u2192 \u2502\n -- \u25cf \u2192 \u25cf\n -- w \u2192 w\n\n R\u2a3e\u2264\u2192\u2264\u2a3eR\u1d9c : \u2200 {w v\u2032} \u2192 w R\u2a3e\u2264\u1d9c v\u2032 \u2192 w \u2264\u2a3eR\u1d9c v\u2032\n R\u2a3e\u2264\u2192\u2264\u2a3eR\u1d9c {w} \u03b6,\u03be = w , (refl\u2264\u1d9c , R\u2a3e\u2264\u2192R\u1d9c \u03b6,\u03be)\n\n trans\u2264\u2a3eR\u1d9c : \u2200 {w\u2032 w w\u2033} \u2192 w \u2264\u2a3eR\u1d9c w\u2032 \u2192 w\u2032 \u2264\u2a3eR\u1d9c w\u2033 \u2192 w \u2264\u2a3eR\u1d9c w\u2033\n trans\u2264\u2a3eR\u1d9c {w\u2032} (v , (\u03be , \u03b6)) (v\u2032 , (\u03be\u2032 , \u03b6\u2032)) = let v\u2033 , (\u03be\u2033 , \u03b6\u2033) = R\u2a3e\u2264\u2192\u2264\u2a3eR\u1d9c (w\u2032 , (\u03b6 , \u03be\u2032))\n in v\u2033 , (trans\u2264\u1d9c \u03be \u03be\u2033 , transR\u1d9c \u03b6\u2033 \u03b6\u2032)\n\n \u2264\u2192R\u1d9c\u2032 : \u2200 {w v\u2032} \u2192 w \u2264\u1d9c v\u2032 \u2192 w R\u1d9c v\u2032\n \u2264\u2192R\u1d9c\u2032 {w} \u03be = R\u2a3e\u2264\u2192R\u1d9c (w , (reflR\u1d9c , \u03be))\n\n\n -- Infimum (greatest lower bound) of accessibility.\n --\n -- w\u2032\n -- \u25cf\n -- \u2502\n -- \u2264 \u03be,\u03b6\n -- \u2502\n -- \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf\n -- w v\n\n infix 3 _\u2264\u2293R\u1d9c_\n _\u2264\u2293R\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _\u2264\u2293R\u1d9c_ = _\u2264\u1d9c_ \u2293 _R\u1d9c_\n\n infix 3 _R\u2293\u2264\u1d9c_\n _R\u2293\u2264\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _R\u2293\u2264\u1d9c_ = _R\u1d9c_ \u2293 _\u2264\u1d9c_\n\n \u2264\u2293R\u2192R\u2293\u2264\u1d9c : \u2200 {w\u2032 v} \u2192 w\u2032 \u2264\u2293R\u1d9c v \u2192 v R\u2293\u2264\u1d9c w\u2032\n \u2264\u2293R\u2192R\u2293\u2264\u1d9c (w , (\u03be , \u03b6)) = w , (\u03b6 , \u03be)\n\n R\u2293\u2264\u2192\u2264\u2293R\u1d9c : \u2200 {w\u2032 v} \u2192 v R\u2293\u2264\u1d9c w\u2032 \u2192 w\u2032 \u2264\u2293R\u1d9c v\n R\u2293\u2264\u2192\u2264\u2293R\u1d9c (w , (\u03b6 , \u03be)) = w , (\u03be , \u03b6)\n\n\n -- Supremum (least upper bound) of accessibility.\n --\n -- w\u2032 v\u2032\n -- \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc\n -- \u2502\n -- \u03be,\u03b6 \u2264\n -- \u2502\n -- \u25cf\n -- v\n\n infix 3 _\u2264\u2294R\u1d9c_\n _\u2264\u2294R\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _\u2264\u2294R\u1d9c_ = _\u2264\u1d9c_ \u2294 _R\u1d9c_\n\n infix 3 _R\u2294\u2264\u1d9c_\n _R\u2294\u2264\u1d9c_ : World\u1d9c \u2192 World\u1d9c \u2192 Set\n _R\u2294\u2264\u1d9c_ = _R\u1d9c_ \u2294 _\u2264\u1d9c_\n\n \u2264\u2294R\u2192R\u2294\u2264\u1d9c : \u2200 {w\u2032 v} \u2192 w\u2032 \u2264\u2294R\u1d9c v \u2192 v R\u2294\u2264\u1d9c w\u2032\n \u2264\u2294R\u2192R\u2294\u2264\u1d9c (v\u2032 , (\u03be , \u03b6)) = v\u2032 , (\u03b6 , \u03be)\n\n R\u2294\u2264\u2192\u2264\u2294R\u1d9c : \u2200 {w\u2032 v} \u2192 v R\u2294\u2264\u1d9c w\u2032 \u2192 w\u2032 \u2264\u2294R\u1d9c v\n R\u2294\u2264\u2192\u2264\u2294R\u1d9c (v\u2032 , (\u03b6 , \u03be)) = v\u2032 , (\u03be , \u03b6)\n\n\n -- Infimum-to-supremum condition, included by Ewald.\n --\n -- w\u2032 \u2192 w\u2032 v\u2032\n -- \u25cf \u2192 \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc\n -- \u2502 \u2192 \u2502\n -- \u2264 \u03be,\u03b6 \u2192 \u2264\n -- \u2502 \u2192 \u2502\n -- \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf \u2192 \u25cf\n -- w v \u2192 v\n\n -- NOTE: This could be more precise.\n \u2264\u2293R\u2192\u2264\u2294R\u1d9c : \u2200 {v w\u2032} \u2192 w\u2032 \u2264\u2293R\u1d9c v \u2192 v \u2264\u2294R\u1d9c w\u2032\n \u2264\u2293R\u2192\u2264\u2294R\u1d9c {v} {w\u2032} (w , (\u03be , \u03b6)) =\n (w\u2032 \u29fa\u00b2 v) , (weak\u2286\u00b2\u29fa\u2082 , mono\u00b2\u22a2 (weak\u2286\u00b2\u29fa\u2081 v) \u2218 down)\n\n\n -- Supremum-to-infimum condition.\n --\n -- w\u2032 v\u2032 \u2192 w\u2032\n -- \u25cf\u2500\u2500\u2500R\u2500\u2500\u2500\u25cc \u2192 \u25cf\n -- \u2502 \u2192 \u2502\n -- \u03be,\u03b6 \u2264 \u2192 \u2264\n -- \u2502 \u2192 \u2502\n -- \u25cf \u2192 \u25cc\u2500\u2500\u2500R\u2500\u2500\u2500\u25cf\n -- v \u2192 w v\n\n -- NOTE: This could be more precise.\n \u2264\u2294R\u2192\u2264\u2293R\u1d9c : \u2200 {w\u2032 v} \u2192 v \u2264\u2294R\u1d9c w\u2032 \u2192 w\u2032 \u2264\u2293R\u1d9c v\n \u2264\u2294R\u2192\u2264\u2293R\u1d9c (v\u2032 , (\u03be , \u03b6)) = \u2205\u00b2 , (bot\u2264\u1d9c , botR\u1d9c)\n","avg_line_length":25.4980079681,"max_line_length":95,"alphanum_fraction":0.29125} {"size":3091,"ext":"agda","lang":"Agda","max_stars_count":29.0,"content":"module OlderBasicILP.Direct.Translation where\n\nopen import Common.Context public\n\n-- import OlderBasicILP.Direct.Hilbert.Sequential as HS\nimport OlderBasicILP.Direct.Hilbert.Nested as HN\nimport OlderBasicILP.Direct.Gentzen as G\n\n-- open HS using () renaming (_\u22a2\u00d7_ to HS\u27e8_\u22a2\u00d7_\u27e9 ; _\u22a2_ to HS\u27e8_\u22a2_\u27e9) public\nopen HN using () renaming (_\u22a2_ to HN\u27e8_\u22a2_\u27e9 ; _\u22a2\u22c6_ to HN\u27e8_\u22a2\u22c6_\u27e9) public\nopen G using () renaming (_\u22a2_ to G\u27e8_\u22a2_\u27e9 ; _\u22a2\u22c6_ to G\u27e8_\u22a2\u22c6_\u27e9) public\n\n\n-- Translation from sequential Hilbert-style to nested.\n\n-- hs\u2192hn : \u2200 {A \u0393} \u2192 HS\u27e8 \u0393 \u22a2 A \u27e9 \u2192 HN\u27e8 \u0393 \u22a2 A \u27e9\n-- hs\u2192hn = ?\n\n\n-- Translation from nested Hilbert-style to sequential.\n\n-- hn\u2192hs : \u2200 {A \u0393} \u2192 HN\u27e8 \u0393 \u22a2 A \u27e9 \u2192 HS\u27e8 \u0393 \u22a2 A \u27e9\n-- hn\u2192hs = ?\n\n\n-- Deduction theorem for sequential Hilbert-style.\n\n-- hs-lam : \u2200 {A B \u0393} \u2192 HS\u27e8 \u0393 , A \u22a2 B \u27e9 \u2192 HS\u27e8 \u0393 \u22a2 A \u25bb B \u27e9\n-- hs-lam = hn\u2192hs \u2218 HN.lam \u2218 hs\u2192hn\n\n\n-- Translation from Hilbert-style to Gentzen-style.\n\nmutual\n hn\u2192g\u1d47\u1d52\u02e3 : HN.Box \u2192 G.Box\n hn\u2192g\u1d47\u1d52\u02e3 HN.[ t ] = {!G.[ hn\u2192g t ]!}\n\n hn\u2192g\u1d40 : HN.Ty \u2192 G.Ty\n hn\u2192g\u1d40 (HN.\u03b1 P) = G.\u03b1 P\n hn\u2192g\u1d40 (A HN.\u25bb B) = hn\u2192g\u1d40 A G.\u25bb hn\u2192g\u1d40 B\n hn\u2192g\u1d40 (T HN.\u2982 A) = hn\u2192g\u1d47\u1d52\u02e3 T G.\u2982 hn\u2192g\u1d40 A\n hn\u2192g\u1d40 (A HN.\u2227 B) = hn\u2192g\u1d40 A G.\u2227 hn\u2192g\u1d40 B\n hn\u2192g\u1d40 HN.\u22a4 = G.\u22a4\n\n hn\u2192g\u1d40\u22c6 : Cx HN.Ty \u2192 Cx G.Ty\n hn\u2192g\u1d40\u22c6 \u2205 = \u2205\n hn\u2192g\u1d40\u22c6 (\u0393 , A) = hn\u2192g\u1d40\u22c6 \u0393 , hn\u2192g\u1d40 A\n\n hn\u2192g\u2071 : \u2200 {A \u0393} \u2192 A \u2208 \u0393 \u2192 hn\u2192g\u1d40 A \u2208 hn\u2192g\u1d40\u22c6 \u0393\n hn\u2192g\u2071 top = top\n hn\u2192g\u2071 (pop i) = pop (hn\u2192g\u2071 i)\n\n hn\u2192g : \u2200 {A \u0393} \u2192 HN\u27e8 \u0393 \u22a2 A \u27e9 \u2192 G\u27e8 hn\u2192g\u1d40\u22c6 \u0393 \u22a2 hn\u2192g\u1d40 A \u27e9\n hn\u2192g (HN.var i) = G.var (hn\u2192g\u2071 i)\n hn\u2192g (HN.app t u) = G.app (hn\u2192g t) (hn\u2192g u)\n hn\u2192g HN.ci = G.ci\n hn\u2192g HN.ck = G.ck\n hn\u2192g HN.cs = G.cs\n hn\u2192g (HN.box t) = {!G.box (hn\u2192g t)!}\n hn\u2192g HN.cdist = {!G.cdist!}\n hn\u2192g HN.cup = {!G.cup!}\n hn\u2192g HN.cdown = G.cdown\n hn\u2192g HN.cpair = G.cpair\n hn\u2192g HN.cfst = G.cfst\n hn\u2192g HN.csnd = G.csnd\n hn\u2192g HN.unit = G.unit\n\n-- hs\u2192g : \u2200 {A \u0393} \u2192 HS\u27e8 \u0393 \u22a2 A \u27e9 \u2192 G\u27e8 \u0393 \u22a2 A \u27e9\n-- hs\u2192g = hn\u2192g \u2218 hs\u2192hn\n\n\n-- Translation from Gentzen-style to Hilbert-style.\n\nmutual\n g\u2192hn\u1d47\u1d52\u02e3 : G.Box \u2192 HN.Box\n g\u2192hn\u1d47\u1d52\u02e3 G.[ t ] = {!HN.[ g\u2192hn t ]!}\n\n g\u2192hn\u1d40 : G.Ty \u2192 HN.Ty\n g\u2192hn\u1d40 (G.\u03b1 P) = HN.\u03b1 P\n g\u2192hn\u1d40 (A G.\u25bb B) = g\u2192hn\u1d40 A HN.\u25bb g\u2192hn\u1d40 B\n g\u2192hn\u1d40 (T G.\u2982 A) = g\u2192hn\u1d47\u1d52\u02e3 T HN.\u2982 g\u2192hn\u1d40 A\n g\u2192hn\u1d40 (A G.\u2227 B) = g\u2192hn\u1d40 A HN.\u2227 g\u2192hn\u1d40 B\n g\u2192hn\u1d40 G.\u22a4 = HN.\u22a4\n\n g\u2192hn\u1d40\u22c6 : Cx G.Ty \u2192 Cx HN.Ty\n g\u2192hn\u1d40\u22c6 \u2205 = \u2205\n g\u2192hn\u1d40\u22c6 (\u0393 , A) = g\u2192hn\u1d40\u22c6 \u0393 , g\u2192hn\u1d40 A\n\n g\u2192hn\u2071 : \u2200 {A \u0393} \u2192 A \u2208 \u0393 \u2192 g\u2192hn\u1d40 A \u2208 g\u2192hn\u1d40\u22c6 \u0393\n g\u2192hn\u2071 top = top\n g\u2192hn\u2071 (pop i) = pop (g\u2192hn\u2071 i)\n\n g\u2192hn : \u2200 {A \u0393} \u2192 G\u27e8 \u0393 \u22a2 A \u27e9 \u2192 HN\u27e8 g\u2192hn\u1d40\u22c6 \u0393 \u22a2 g\u2192hn\u1d40 A \u27e9\n g\u2192hn (G.var i) = HN.var (g\u2192hn\u2071 i)\n g\u2192hn (G.lam t) = HN.lam (g\u2192hn t)\n g\u2192hn (G.app t u) = HN.app (g\u2192hn t) (g\u2192hn u)\n-- g\u2192hn (G.multibox ts u) = {!HN.multibox (g\u2192hn\u22c6 ts) (g\u2192hn u)!}\n g\u2192hn (G.down t) = HN.down (g\u2192hn t)\n g\u2192hn (G.pair t u) = HN.pair (g\u2192hn t) (g\u2192hn u)\n g\u2192hn (G.fst t) = HN.fst (g\u2192hn t)\n g\u2192hn (G.snd t) = HN.snd (g\u2192hn t)\n g\u2192hn G.unit = HN.unit\n\n g\u2192hn\u22c6 : \u2200 {\u039e \u0393} \u2192 G\u27e8 \u0393 \u22a2\u22c6 \u039e \u27e9 \u2192 HN\u27e8 g\u2192hn\u1d40\u22c6 \u0393 \u22a2\u22c6 g\u2192hn\u1d40\u22c6 \u039e \u27e9\n g\u2192hn\u22c6 {\u2205} \u2219 = \u2219\n g\u2192hn\u22c6 {\u039e , A} (ts , t) = g\u2192hn\u22c6 ts , g\u2192hn t\n\n-- g\u2192hs : \u2200 {A \u0393} \u2192 G\u27e8 \u0393 \u22a2 A \u27e9 \u2192 HS\u27e8 \u0393 \u22a2 A \u27e9\n-- g\u2192hs = hn\u2192hs \u2218 g\u2192hn\n","avg_line_length":28.1,"max_line_length":71,"alphanum_fraction":0.484309285} {"size":8585,"ext":"agda","lang":"Agda","max_stars_count":6.0,"content":"open import Relation.Binary.Core\n\nmodule PLRTree.Drop.Complete {A : Set} \n (_\u2264_ : A \u2192 A \u2192 Set)\n (tot\u2264 : Total _\u2264_) where\n\nopen import Data.Sum\nopen import PLRTree {A} \nopen import PLRTree.Complete {A}\nopen import PLRTree.Compound {A}\nopen import PLRTree.Drop _\u2264_ tot\u2264\nopen import PLRTree.DropLast.Complete _\u2264_ tot\u2264\nopen import PLRTree.Equality {A}\nopen import PLRTree.Order.Properties {A}\nopen import PLRTree.Push.Complete _\u2264_ tot\u2264\n\nlemma-setRoot-complete : {t : PLRTree}(x : A) \u2192 Complete t \u2192 Complete (setRoot x t)\nlemma-setRoot-complete x leaf = leaf\nlemma-setRoot-complete x (perfect _ cl cr l\u2243r) = perfect x cl cr l\u2243r\nlemma-setRoot-complete x (left _ cl cr l\u22d8r) = left x cl cr l\u22d8r\nlemma-setRoot-complete x (right _ cl cr l\u22d9r) = right x cl cr l\u22d9r\n\nlemma-drop-complete : {t : PLRTree} \u2192 Complete t \u2192 Complete (drop t)\nlemma-drop-complete leaf = leaf\nlemma-drop-complete (perfect _ _ _ \u2243lf) = leaf\nlemma-drop-complete (perfect {node perfect x' l' r'} {node perfect x'' l'' r''} x (perfect .x' cl' cr' _) (perfect .x'' cl'' cr'' _) (\u2243nd .x' .x'' l'\u2243r' l''\u2243r'' l'\u2243l'')) = \n let z = last (node perfect x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = dropLast (node perfect x (node perfect x' l' r') (node perfect x'' l'' r'')) ;\n ct' = right x (perfect x' cl' cr' l'\u2243r') (lemma-dropLast-complete (perfect x'' cl'' cr'' l''\u2243r'')) (lemma-dropLast-\u2243 (\u2243nd x' x'' l'\u2243r' l''\u2243r'' l'\u2243l'') compound) \n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\nlemma-drop-complete (left {l} {r} x cl cr l\u22d8r)\n with l | r | l\u22d8r | lemma-dropLast-\u22d8 l\u22d8r\n... | leaf | _ | () | _ \n... | node perfect x' l' r' | _ | () | _ \n... | node left x' l' r' | node perfect x'' l'' r'' | l\u22d8 .x' .x'' l'\u22d8r' l''\u2243r'' r'\u2243l'' | inj\u2081 ld\u22d8r \n with dropLast (node left x' l' r') | ld\u22d8r | lemma-dropLast-complete cl\n... | leaf | () | _\n... | node perfect _ _ _ | () | _\n... | node left x''' l''' r''' | ld\u22d8r' | cld = \n let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;\n ct' = left x cld cr ld\u22d8r'\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node right x''' l''' r''' | ld\u22d8r' | cld = \n let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;\n ct' = left x cld cr ld\u22d8r'\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\nlemma-drop-complete (left x cl cr l\u22d8r) | node left x' l' r' | node perfect x'' l'' r'' | l\u22d8 .x' .x'' l'\u22d8r' l''\u2243r'' r'\u2243l'' | inj\u2082 ld\u2243r \n with dropLast (node left x' l' r') | ld\u2243r | lemma-dropLast-complete cl\n... | leaf | () | _\n... | node perfect x''' l''' r''' | ld\u2243r' | cld = \n let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;\n ct' = perfect x cld cr ld\u2243r'\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node left _ _ _ | () | _\n... | node right _ _ _ | () | _\nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' l' r' | leaf | () | _ \nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x\u22d8 .x' .x'' .x''' | inj\u2081 () \nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x\u22d8 .x' .x'' .x''' | inj\u2082 x'\u2243x''' = \n let z = last (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) compound ;\n t' = dropLast (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) ;\n ct' = perfect x (perfect x' leaf leaf \u2243lf) cr x'\u2243x'''\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' l' r' | node perfect x'' l'' r'' | r\u22d8 .x' .x'' l\u22d9r l''\u2243r'' l'\u22d7l'' | inj\u2081 ld\u22d8r \n with dropLast (node right x' l' r') | ld\u22d8r | lemma-dropLast-complete cl\n... | leaf | () | _\n... | node perfect _ _ _ | () | _\n... | node left x''' l''' r''' | ld\u22d8r' | cld = \n let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;\n ct' = left x cld cr ld\u22d8r'\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node right x''' l''' r''' | ld\u22d8r' | cld = \n let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;\n ct' = left x cld cr ld\u22d8r'\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' l' r' | node perfect x'' l'' r'' | r\u22d8 .x' .x'' l\u22d9r l''\u2243r'' l'\u22d7l'' | inj\u2082 ld\u2243r \n with dropLast (node right x' l' r') | ld\u2243r | lemma-dropLast-complete cl\n... | leaf | () | _\n... | node perfect x''' l''' r''' | ld\u2243r' | cld = \n let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;\n ct' = perfect x cld cr ld\u2243r'\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node left _ _ _ | () | _\n... | node right _ _ _ | () | _ \nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' l' r' | node left x'' l'' r'' | () | _ \nlemma-drop-complete (left x cl cr l\u22d8r) | node right x' l' r' | node right x'' l'' r'' | () | _\nlemma-drop-complete (right {l} {r} x cl cr l\u22d9r) \n with l | r | l\u22d9r | lemma-dropLast-\u22d9 l\u22d9r\n... | leaf | leaf | \u22d9p () | _\n... | node perfect x' leaf leaf | leaf | \u22d9p (\u22d7lf .x') | _ = cl\n... | node perfect _ _ (node _ _ _ _) | leaf | \u22d9p () | _\n... | node perfect _ (node _ _ _ _) _ | leaf | \u22d9p () | _\n... | node left _ _ _ | leaf | \u22d9p () | _\n... | node right _ _ _ | leaf | \u22d9p () | _\n... | leaf | node perfect _ _ _ | \u22d9p () | _\n... | node perfect x' l' r' | node perfect x'' l'' r'' | \u22d9p (\u22d7nd .x' .x'' l'\u2243r' l''\u2243r'' l'\u22d7l'') | _ = \n let z = last (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;\n t' = dropLast (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) ;\n ct' = left x (lemma-dropLast-complete cl) cr (lemma-dropLast-\u22d7 (\u22d7nd x' x'' l'\u2243r' l''\u2243r'' l'\u22d7l'') compound)\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node left _ _ _ | node perfect _ _ _ | \u22d9p () | _\n... | node right _ _ _ | node perfect _ _ _ | \u22d9p () | _\n... | leaf | node left _ _ _ | \u22d9p () | _\n... | node perfect x' l' r' | node left x'' l'' r'' | _ | inj\u2081 l\u22d9rd = \n let z = last (node right x (node perfect x' l' r') (node left x'' l'' r'')) compound ;\n t' = dropLast (node right x (node perfect x' l' r') (node left x'' l'' r'')) ;\n ct' = right x cl (lemma-dropLast-complete cr) l\u22d9rd\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node perfect _ _ _ | node left _ _ _ | _ | inj\u2082 () \n... | node left _ _ _ | node left _ _ _ | \u22d9p () | _\n... | node right _ _ _ | node left _ _ _ | \u22d9p () | _\n... | leaf | node right _ _ _ | \u22d9p () | _\n... | node perfect x' l' r' | node right x'' l'' r'' | _ | inj\u2081 l\u22d9rd = \n let z = last (node right x (node perfect x' l' r') (node right x'' l'' r'')) compound ;\n t' = dropLast (node right x (node perfect x' l' r') (node right x'' l'' r'')) ;\n ct' = right x cl (lemma-dropLast-complete cr) l\u22d9rd\n in lemma-push-complete (lemma-setRoot-complete z ct') (\u227a-wf (setRoot z t'))\n... | node perfect _ _ _ | node right _ _ _ | _ | inj\u2082 ()\n... | node left _ _ _ | node right _ _ _ | \u22d9p () | _ \n... | node right _ _ _ | node right _ _ _ | \u22d9p () | _\n","avg_line_length":68.1349206349,"max_line_length":183,"alphanum_fraction":0.5097262667} {"size":6441,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --cubical --no-import-sorts --safe #-}\n\nmodule Cubical.Relation.Binary.Definitions where\n\nopen import Cubical.Core.Everything\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Logic hiding (_\u21d2_; _\u21d4_; \u00ac_)\nopen import Cubical.Foundations.HLevels\n\nopen import Cubical.Data.Maybe.Base using (Maybe)\nopen import Cubical.Data.Sum.Base using (_\u228e_)\nopen import Cubical.Data.Sigma.Base\nopen import Cubical.HITs.PropositionalTruncation.Base\n\nopen import Cubical.Relation.Binary.Base\nopen import Cubical.Relation.Nullary.Decidable\n\nprivate\n variable\n a b c \u2113 \u2113\u2032 \u2113\u2032\u2032 \u2113\u2032\u2032\u2032 : Level\n A : Type a\n B : Type b\n C : Type c\n\n\n------------------------------------------------------------------------\n-- Basic defintions\n------------------------------------------------------------------------\n\n\ninfix 7 _\u21d2_ _\u21d4_ _=[_]\u21d2_\ninfix 8 _\u27f6_Respects_ _Respects_ _Respects\u02e1_ _Respects\u02b3_ _Respects\u2082_\n\nidRel : (A : Type \u2113) \u2192 Rel A \u2113\nidRel A a b .fst = \u2225 a \u2261 b \u2225\nidRel A _ _ .snd = squash\n\ninvRel : REL A B \u2113\u2032 \u2192 REL B A \u2113\u2032\ninvRel R b a = R a b\n\ncompRel : REL A B \u2113\u2032 \u2192 REL B C \u2113\u2032\u2032 \u2192 REL A C _\ncompRel R S a c .fst = \u2203[ b \u2208 _ ] \u27e8 R a b \u27e9 \u00d7 \u27e8 S b c \u27e9\ncompRel R S _ _ .snd = squash\n\ngraphRel : {B : Type b} \u2192 (A \u2192 B) \u2192 isSet B \u2192 REL A B b\ngraphRel f isSetB a b .fst = f a \u2261 b\ngraphRel f isSetB a b .snd = isSetB (f a) b\n\n\n-- Implication\/containment - could also be written _\u2286_.\n-- and corresponding notion of equivalence\n\n_\u21d2_ : REL A B \u2113 \u2192 REL A B \u2113\u2032 \u2192 Type _\nP \u21d2 Q = \u2200 {x y} \u2192 \u27e8 P x y \u27e9 \u2192 \u27e8 Q x y \u27e9\n\n_\u21d4_ : REL A B \u2113 \u2192 REL A B \u2113\u2032 \u2192 Type _\nP \u21d4 Q = P \u21d2 Q \u00d7 Q \u21d2 P\n\n-- Generalised implication - if P \u2261 Q it can be read as \"f preserves P\".\n\n_=[_]\u21d2_ : Rel A \u2113 \u2192 (A \u2192 B) \u2192 Rel B \u2113\u2032 \u2192 Type _\nP =[ f ]\u21d2 Q = P \u21d2 (Q on f)\n\n-- A synonym for _=[_]\u21d2_.\n\n_Preserves_\u27f6_ : (A \u2192 B) \u2192 Rel A \u2113 \u2192 Rel B \u2113\u2032 \u2192 Type _\nf Preserves P \u27f6 Q = P =[ f ]\u21d2 Q\n\n-- An endomorphic variant of _Preserves_\u27f6_.\n\n_Preserves_ : (A \u2192 A) \u2192 Rel A \u2113 \u2192 Type _\nf Preserves P = f Preserves P \u27f6 P\n\n-- A binary variant of _Preserves_\u27f6_.\n\n_Preserves\u2082_\u27f6_\u27f6_ : (A \u2192 B \u2192 C) \u2192 Rel A \u2113 \u2192 Rel B \u2113\u2032 \u2192 Rel C \u2113\u2032\u2032 \u2192 Type _\n_\u2219_ Preserves\u2082 P \u27f6 Q \u27f6 R = \u2200 {x y u v} \u2192 \u27e8 P x y \u27e9 \u2192 \u27e8 Q u v \u27e9 \u2192 \u27e8 R (x \u2219 u) (y \u2219 v) \u27e9\n\n\n------------------------------------------------------------------------\n-- Property predicates\n------------------------------------------------------------------------\n\n-- Reflexivity.\n\nReflexive : Rel A \u2113 \u2192 Type _\nReflexive _\u223c_ = \u2200 {x} \u2192 \u27e8 x \u223c x \u27e9\n\n-- Equality can be converted to proof of relation.\n\nFromEq : Rel A \u2113 \u2192 Type _\nFromEq _\u223c_ = _\u2261\u209a_ \u21d2 _\u223c_\n\n-- Irreflexivity.\n\nIrreflexive : Rel A \u2113 \u2192 Type _\nIrreflexive _<_ = \u2200 {x} \u2192 \u00ac \u27e8 x < x \u27e9\n\n-- Relation implies inequality.\n\nToNotEq : Rel A \u2113 \u2192 Type _\nToNotEq _<_ = _<_ \u21d2 _\u2262\u209a_\n\n-- Generalised symmetry.\n\nSym : REL A B \u2113 \u2192 REL B A \u2113\u2032 \u2192 Type _\nSym P Q = P \u21d2 flip Q\n\n-- Symmetry.\n\nSymmetric : Rel A \u2113 \u2192 Type _\nSymmetric _\u223c_ = Sym _\u223c_ _\u223c_\n\n-- Generalised transitivity.\n\nTrans : REL A B \u2113 \u2192 REL B C \u2113\u2032 \u2192 REL A C \u2113\u2032\u2032 \u2192 Type _\nTrans P Q R = \u2200 {i j k} \u2192 \u27e8 P i j \u27e9 \u2192 \u27e8 Q j k \u27e9 \u2192 \u27e8 R i k \u27e9\n\n-- A flipped variant of generalised transitivity.\n\nTransFlip : REL A B \u2113 \u2192 REL B C \u2113\u2032 \u2192 REL A C \u2113\u2032\u2032 \u2192 Type _\nTransFlip P Q R = \u2200 {i j k} \u2192 \u27e8 Q j k \u27e9 \u2192 \u27e8 P i j \u27e9 \u2192 \u27e8 R i k \u27e9\n\n-- Transitivity.\n\nTransitive : Rel A \u2113 \u2192 Type _\nTransitive _\u223c_ = Trans _\u223c_ _\u223c_ _\u223c_\n\n-- Generalised antisymmetry.\n\nAntisym : REL A B \u2113 \u2192 REL B A \u2113\u2032 \u2192 REL A B \u2113\u2032\u2032 \u2192 Type _\nAntisym R S E = \u2200 {i j} \u2192 \u27e8 R i j \u27e9 \u2192 \u27e8 S j i \u27e9 \u2192 \u27e8 E i j \u27e9\n\n-- Antisymmetry.\n\nAntisymmetric : Rel A \u2113 \u2192 Type _\nAntisymmetric _\u2264_ = Antisym _\u2264_ _\u2264_ _\u2261\u209a_\n\n-- Asymmetry.\n\nAsymmetric : Rel A \u2113 \u2192 Type _\nAsymmetric _<_ = \u2200 {x y} \u2192 \u27e8 x < y \u27e9 \u2192 \u00ac \u27e8 y < x \u27e9\n\n-- Generalised connex - exactly one of the two relations holds.\n\nRawConnex : REL A B \u2113 \u2192 REL B A \u2113\u2032 \u2192 Type _\nRawConnex P Q = \u2200 x y \u2192 \u27e8 P x y \u27e9 \u228e \u27e8 Q y x \u27e9\n\n-- Totality.\n\nRawTotal : Rel A \u2113 \u2192 Type _\nRawTotal _\u223c_ = RawConnex _\u223c_ _\u223c_\n\n-- Truncated connex - Preserves propositions.\n\nConnex : REL A B \u2113 \u2192 REL B A \u2113\u2032 \u2192 Type _\nConnex P Q = \u2200 x y \u2192 \u27e8 P x y \u2294 Q y x \u27e9\n\n-- Truncated totality.\n\nTotal : Rel A \u2113 \u2192 Type _\nTotal _\u223c_ = Connex _\u223c_ _\u223c_\n\n-- Generalised trichotomy - exactly one of three types has a witness.\n\ndata Tri (A : Type a) (B : Type b) (C : Type c) : Type (\u2113-max a (\u2113-max b c)) where\n tri< : ( a : A) (\u00acb : \u00ac B) (\u00acc : \u00ac C) \u2192 Tri A B C\n tri\u2261 : (\u00aca : \u00ac A) ( b : B) (\u00acc : \u00ac C) \u2192 Tri A B C\n tri> : (\u00aca : \u00ac A) (\u00acb : \u00ac B) ( c : C) \u2192 Tri A B C\n\n-- Trichotomy.\n\nTrichotomous : Rel A \u2113 \u2192 Type _\nTrichotomous _<_ = \u2200 x y \u2192 Tri \u27e8 x < y \u27e9 (x \u2261 y) \u27e8 x > y\u00a0\u27e9\n where _>_ = flip _<_\n\n-- Maximum element.\n\nMaximum : REL A B \u2113 \u2192 B \u2192 Type _\nMaximum _\u2264_ g = \u2200 x \u2192 \u27e8 x \u2264 g \u27e9\n\n-- Minimum element\n\nMinimum : REL A B \u2113 \u2192 A \u2192 Type _\nMinimum _\u2264_ l = \u2200 x \u2192 \u27e8 l \u2264 x \u27e9\n\n-- Unary relations respecting a binary relation.\n\n_\u27f6_Respects_ : (A \u2192 hProp \u2113) \u2192 (B \u2192 hProp \u2113\u2032) \u2192 REL A B \u2113\u2032\u2032 \u2192 Type _\nP \u27f6 Q Respects _\u223c_ = \u2200 {x y} \u2192 \u27e8 x \u223c y \u27e9 \u2192 \u27e8 P x \u27e9 \u2192 \u27e8 Q y \u27e9\n\n-- Unary relation respects a binary relation.\n\n_Respects_ : (A \u2192 hProp \u2113) \u2192 Rel A \u2113\u2032 \u2192 Type _\nP Respects _\u223c_ = P \u27f6 P Respects _\u223c_\n\n-- Right respecting - relatedness is preserved on the right by some equivalence.\n\n_Respects\u02b3_ : REL A B \u2113 \u2192 Rel B \u2113\u2032 \u2192 Type _\n_\u223c_ Respects\u02b3 _\u2248_ = \u2200 {x} \u2192 (x \u223c_) Respects _\u2248_\n\n-- Left respecting - relatedness is preserved on the left by some equivalence.\n\n_Respects\u02e1_ : REL A B \u2113 \u2192 Rel A \u2113\u2032 \u2192 Type _\n_\u223c_ Respects\u02e1 _\u2248_ = \u2200 {y} \u2192 (_\u223c y) Respects _\u2248_\n\n-- Respecting - relatedness is preserved on both sides by some equivalence.\n\n_Respects\u2082_ : Rel A \u2113 \u2192 Rel A \u2113\u2032 \u2192 Type _\n_\u223c_ Respects\u2082 _\u2248_ = (_\u223c_ Respects\u02b3 _\u2248_) \u00d7 (_\u223c_ Respects\u02e1 _\u2248_)\n\n-- Substitutivity - any two related elements satisfy exactly the same\n-- set of unary relations. Note that only the various derivatives\n-- of propositional equality can satisfy this property.\n\nSubstitutive : Rel A \u2113 \u2192 (\u2113\u2032 : Level) \u2192 Type _\nSubstitutive {A = A} _\u223c_ p = (P : A \u2192 hProp p) \u2192 P Respects _\u223c_\n\n-- Decidability - it is possible to determine whether a given pair of\n-- elements are related.\n\nDecidable : REL A B \u2113 \u2192 Type _\nDecidable _\u223c_ = \u2200 x y \u2192 Dec \u27e8 x \u223c y \u27e9\n\n-- Weak decidability - it is sometimes possible to determine if a given\n-- pair of elements are related.\n\nWeaklyDecidable : REL A B \u2113 \u2192 Type _\nWeaklyDecidable _\u223c_ = \u2200 x y \u2192 Maybe \u27e8 x \u223c y \u27e9\n\n-- Universal - all pairs of elements are related\n\nUniversal : REL A B \u2113 \u2192 Type _\nUniversal _\u223c_ = \u2200 x y \u2192 \u27e8 x \u223c y \u27e9\n\n-- Non-emptiness - at least one pair of elements are related.\n\nNonEmpty : REL A B \u2113 \u2192 Type _\nNonEmpty _\u223c_ = \u2203[ x \u2208 _ ] \u2203[ y \u2208 _ ] \u27e8 x \u223c y \u27e9\n","avg_line_length":26.6157024793,"max_line_length":86,"alphanum_fraction":0.581120944} {"size":398,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module Dave.Logic.Bool where\n \n data Bool : Set where\n false : Bool\n true : Bool \n\n \u00ac_ : Bool \u2192 Bool\n \u00ac true = false\n \u00ac false = true\n\n _\u2227_ : Bool \u2192 Bool \u2192 Bool\n a \u2227 true = a\n a \u2227 false = false\n\n if_then_else_ : {A : Set} \u2192 Bool \u2192 A \u2192 A \u2192 A\n if false then a else b = b\n if true then a else b = a\n\n identity : {A : Set} \u2192 A \u2192 A\n identity a = a\n","avg_line_length":18.9523809524,"max_line_length":48,"alphanum_fraction":0.4974874372} {"size":2269,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module regular-star where\n\nopen import Level renaming ( suc to Suc ; zero to Zero )\nopen import Data.List \nopen import Data.Nat hiding ( _\u225f_ )\nopen import Data.Fin hiding ( _+_ )\nopen import Data.Empty \nopen import Data.Unit \nopen import Data.Product\n-- open import Data.Maybe\nopen import Relation.Nullary\nopen import Relation.Binary.PropositionalEquality hiding ( [_] )\nopen import logic\nopen import nat\nopen import automaton\nopen import regular-language \n\nopen import nfa\nopen import sbconst2\nopen import finiteSet\nopen import finiteSetUtil\nopen import Relation.Binary.PropositionalEquality hiding ( [_] )\nopen import regular-concat\n\nopen Automaton\nopen FiniteSet\n\nopen RegularLanguage\n\nStar-NFA : {\u03a3 : Set} \u2192 (A : RegularLanguage \u03a3 ) \u2192 NAutomaton (states A ) \u03a3 \nStar-NFA {\u03a3} A = record { N\u03b4 = \u03b4nfa ; Nend = nend } \n module Star-NFA where\n \u03b4nfa : states A \u2192 \u03a3 \u2192 states A \u2192 Bool\n \u03b4nfa q i q\u2081 with aend (automaton A) q\n ... | true = equal? (afin A) ( astart A) q\u2081 \n ... | false = equal? (afin A) (\u03b4 (automaton A) q i) q\u2081\n nend : states A \u2192 Bool\n nend q = aend (automaton A) q\n\nStar-NFA-start : {\u03a3 : Set} \u2192 (A : RegularLanguage \u03a3 ) \u2192 states A \u2192 Bool\nStar-NFA-start A q = equal? (afin A) (astart A) q \\\/ aend (automaton A) q\n\nSNFA-exist : {\u03a3 : Set} \u2192 (A : RegularLanguage \u03a3 ) \u2192 (states A \u2192 Bool) \u2192 Bool\nSNFA-exist A qs = exists (afin A) qs \n\nM-Star : {\u03a3 : Set} \u2192 (A : RegularLanguage \u03a3 ) \u2192 RegularLanguage \u03a3\nM-Star {\u03a3} A = record {\n states = states A \u2192 Bool\n ; astart = Star-NFA-start A \n ; afin = fin\u2192 (afin A)\n ; automaton = subset-construction (SNFA-exist A ) (Star-NFA A ) \n } \n \nopen Split\n\nopen _\u2227_\n\nopen NAutomaton\nopen import Data.List.Properties\n\nclosed-in-star : {\u03a3 : Set} \u2192 (A B : RegularLanguage \u03a3 ) \u2192 ( x : List \u03a3 ) \u2192 isRegular (Star (contain A) ) x ( M-Star A )\nclosed-in-star {\u03a3} A B x = \u2261-Bool-func closed-in-star\u2192 closed-in-star\u2190 where\n NFA = (Star-NFA A )\n\n closed-in-star\u2192 : Star (contain A) x \u2261 true \u2192 contain (M-Star A ) x \u2261 true\n closed-in-star\u2192 star = {!!}\n\n open Found\n\n closed-in-star\u2190 : contain (M-Star A ) x \u2261 true \u2192 Star (contain A) x \u2261 true\n closed-in-star\u2190 C with subset-construction-lemma\u2190 (SNFA-exist A ) NFA {!!} x C \n ... | CC = {!!}\n\n\n\n\n","avg_line_length":29.4675324675,"max_line_length":121,"alphanum_fraction":0.6412516527} {"size":9825,"ext":"agda","lang":"Agda","max_stars_count":14.0,"content":"{-# OPTIONS --without-K --safe #-}\n\n-- Singleton type and its 'inverse'\n\nmodule Singleton where\n\nopen import Data.Unit using (\u22a4; tt)\nopen import Data.Sum\nopen import Data.Product\nopen import Relation.Binary.PropositionalEquality\n using (_\u2261_; refl; sym; trans; subst; cong ; cong\u2082 ; inspect ; [_])\n-- open import Level\n-- using (zero)\n-- open import Axiom.Extensionality.Propositional\n-- using (Extensionality)\n\nis-contr : Set \u2192 Set\nis-contr A = \u03a3 A (\u03bb a \u2192 (x : A) \u2192 a \u2261 x)\n\nis-prop : Set \u2192 Set\nis-prop A = (x y : A) \u2192 x \u2261 y\n\nis-set : Set \u2192 Set\nis-set A = (x y : A) \u2192 is-prop (x \u2261 y)\n\ncontr-prop : {A : Set} \u2192 is-contr A \u2192 is-prop A\ncontr-prop (a , \u03d5) x y = trans (sym (\u03d5 x)) (\u03d5 y)\n\napd : \u2200 {a b} {A : Set a} {B : A \u2192 Set b} (f : (x : A) \u2192 B x) {x y} \u2192 (p : x \u2261 y) \u2192 subst B p (f x) \u2261 f y\napd f refl = refl\n\nprop-set : {A : Set} \u2192 is-prop A \u2192 is-set A\nprop-set {A} \u03d5 x y p q = trans (l p) (sym (l q))\n where g : (z : A) \u2192 x \u2261 z\n g z = \u03d5 x z\n unitr : {y z : A} (p : y \u2261 z) \u2192 refl \u2261 trans (sym p) p\n unitr refl = refl\n l : {y z : A} (p : y \u2261 z) \u2192 p \u2261 trans (sym (g y)) (g z)\n l refl = unitr (g _)\n\nprop-contr : {A : Set} \u2192 is-prop A \u2192 A \u2192 is-contr A\nprop-contr \u03d5 a = a , \u03d5 a\n\n------------------------------------------------------------------------------\n-- Singleton type: A type with a distinguished point\n-- The 'interesting' part is that the point is both a parameter\n-- and a field.\n\n{--\nrecord Singleton (A : Set) (v : A) : Set where\n constructor \u21d1\n field\n \u25cf : A\n v\u2261\u25cf : v \u2261 \u25cf\n\nopen Singleton public\n--}\n\nSingleton : (A : Set) \u2192 (v : A) \u2192 Set\nSingleton A v = \u2203 (\u03bb \u25cf \u2192 v \u2261 \u25cf)\n\n-- Singleton types are contractible:\npointed-contr : {A : Set} {v : A} \u2192 is-contr (Singleton A v)\n--pointed-contr {A} {v} = \u21d1 v refl , \u03bb { (\u21d1 \u25cf refl) \u2192 refl }\npointed-contr {A} {v} = (v , refl) , \u03bb { ( \u25cf , refl) \u2192 refl }\n\n-- and thus have all paths between them:\npointed-all-paths : {A : Set} {v : A} {p q : Singleton A v} \u2192 p \u2261 q\npointed-all-paths = contr-prop pointed-contr _ _\n\n-- What does Singleton of Singleton do?\n-- Values of type Singleton A v are of the form (w , p) where p : v \u2261 w\n-- Values of type Singleton (Singleton A v) x\n\nssv : (A : Set) (v : A) (x : Singleton A v) \u2192 Singleton (Singleton A v) x\nssv A v (.v , refl) = (v , refl) , refl\n\n{--\nss=s : (A : Set) (v : A) (x : Singleton A v) \u2192 Singleton (Singleton A v) x \u2261 Singleton A v\nss=s A v (.v , refl) with pointed-contr {A} {v}\n... | (.v , refl) , f = let p = f (v , refl) in {!!} -- ??\n--}\n------------------------------------------------------------------------------\n-- The 'reciprocal' of a Singleton type is a function that accepts exactly\n-- that point, and returns no information. It acts as a 'witness' that\n-- the right point has been fed to it.\n{--\nRecip : (A : Set) \u2192 (v : A) \u2192 Set\nRecip A v = (w : A) \u2192 (v \u2261 w) \u2192 \u22a4\n--}\n\nRecip : (A : Set) \u2192 (v : A) \u2192 Set\nRecip A v = Singleton A v \u2192 \u22a4\n\n-- Recip A v = Singleton A v \u2192 \u22a4\n\n-- Recip is also contractible, if we're thinking of homotopy types.\n-- We need funext to prove it which is not --safe\n\n-- posulate\n-- funext : Extensionality zero zero\n\n-- recip-contr : {A : Set} {v : A} \u2192 is-contr (Recip A v)\n-- recip-contr = (\u03bb _ _ \u2192 tt) , \u03bb r \u2192 funext \u03bb _ \u2192 funext \u03bb _ \u2192 refl\n\n\n------------------------------------------------------------------------------\n\n-- Recip' : {A : Set} {v : A} \u2192 Singleton A v \u2192 Set\n-- Recip' {A} {v} (\u21d1 w v\u2261w) = v \u2261 w\n\n-- Recip'-ptd : {A : Set} {v : A} \u2192 (p : Singleton A v) \u2192 Singleton (Recip' p) (v\u2261\u25cf p)\n-- Recip'-ptd (\u21d1 w v\u2261w) = \u21d1 v\u2261w refl\n\n-- family of path types from arbitrary w to a fixed v\n\nRecip' : (A : Set) \u2192 (v : A) \u2192 Set\nRecip' A v = (w : A) \u2192 v \u2261 w\n\n-- If A is a n-type, Recip' is a (n-1)-type\n\n-- recip'-contr : {A : Set} {v : A} \u2192 is-prop A \u2192 is-contr (Recip' A v)\n-- recip'-contr {A} {v} \u03d5 = (\u03bb w \u2192 \u03d5 v w) , \u03bb r \u2192 funext \u03bb x \u2192 prop-set \u03d5 v x (\u03d5 v x) (r x)\n\n-- recip'-prop : {A : Set} {v : A} \u2192 is-set A \u2192 is-prop (Recip' A v)\n-- recip'-prop \u03d5 r s = funext (\u03bb x \u2192 \u03d5 _ x (r x) (s x))\n\n------------------------------------------------------------------------------\n-- Singleton is an idempotent bimonad on pointed sets\n-- (need to check some coherences)\n\n\u2219Set = \u03a3 Set (\u03bb X \u2192 X)\n\n\u2219Set[_,_] : \u2219Set \u2192 \u2219Set \u2192 Set\n\u2219Set[ (A , a) , (B , b) ] = \u03a3 (A \u2192 B) \u03bb f \u2192 f a \u2261 b\n\n_\u2219\u00d7_ : \u2219Set \u2192 \u2219Set \u2192 \u2219Set\n(A , a) \u2219\u00d7 (B , b) = (A \u00d7 B) , (a , b)\n\n-- left version, there's also a right version\n-- note that this isn't a coproduct\n-- wedge sum is the coproduct\n_\u2219+_ : \u2219Set \u2192 \u2219Set \u2192 \u2219Set\n(A , a) \u2219+ (B , b) = (A \u228e B) , inj\u2081 a\n\n\u2219id : \u2200{\u2219A} \u2192 \u2219Set[ \u2219A , \u2219A ]\n\u2219id = (\u03bb a \u2192 a) , refl\n\n_\u2218_ : \u2200 {\u2219A \u2219B \u2219C} \u2192 \u2219Set[ \u2219A , \u2219B ] \u2192 \u2219Set[ \u2219B , \u2219C ] \u2192 \u2219Set[ \u2219A , \u2219C ]\n(f , p) \u2218 (g , q) = (\u03bb x \u2192 g (f x)) , trans (cong g p) q\n\n-- terminal and initial\n\u22191 : \u2219Set\n\u22191 = \u22a4 , tt\n\n\u2219![_] : \u2200 \u2219A \u2192 \u2219Set[ \u2219A , \u22191 ]\n\u2219![ (A , a) ] = (\u03bb _ \u2192 tt) , refl\n\n\u2219!-uniq : \u2200 {\u2219A} {x : \u2219A .proj\u2081} \u2192 (\u2219f : \u2219Set[ \u2219A , \u22191 ]) \u2192 (\u2219f .proj\u2081) x \u2261 (\u2219![ \u2219A ] .proj\u2081) x\n\u2219!-uniq {A , a} {x} (f , p) = refl\n\n\u2219\u00a1[_] : \u2200 \u2219A \u2192 \u2219Set[ \u22191 , \u2219A ]\n\u2219\u00a1[ A , a ] = (\u03bb _ \u2192 a) , refl\n\n\u2219\u00a1-uniq : \u2200 {\u2219A} \u2192 (\u2219f : \u2219Set[ \u22191 , \u2219A ]) \u2192 (\u2219f .proj\u2081) tt \u2261 (\u2219\u00a1[ \u2219A ] .proj\u2081) tt\n\u2219\u00a1-uniq (f , p) = p\n\nrecord \u2219Iso[_,_] (\u2219A \u2219B : \u2219Set) : Set where\n constructor iso\n field\n \u2219f : \u2219Set[ \u2219A , \u2219B ]\n \u2219g : \u2219Set[ \u2219B , \u2219A ]\n f = \u2219f .proj\u2081\n g = \u2219g .proj\u2081\n field\n f-g : \u2200 b \u2192 f (g b) \u2261 b\n g-f : \u2200 a \u2192 g (f a) \u2261 a\n\nopen \u2219Iso[_,_]\n\n\u2219Iso\u207b\u00b9 : \u2200 {\u2219A \u2219B} \u2192 \u2219Iso[ \u2219A , \u2219B ] \u2192 \u2219Iso[ \u2219B , \u2219A ]\n\u2219Iso\u207b\u00b9 (iso \u2219f \u2219g f-g g-f) = iso \u2219g \u2219f g-f f-g\n\nSing : \u2219Set \u2192 \u2219Set\nSing (A , a) = Singleton A a , a , refl\n\nSing[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ \u2219A , \u2219B ] \u2192 \u2219Set[ Sing \u2219A , Sing \u2219B ]\nSing[ (A , a) , (B , .(f a)) ] (f , refl) = (\u03bb { (x , refl) \u2192 f x , refl }) , refl\n\n-- monad\n\u03b7[_] : \u2200 \u2219A \u2192 \u2219Set[ \u2219A , Sing \u2219A ]\n\u03b7[ (A , a) ] = (\u03bb x \u2192 a , refl) , refl\n\n-- Sing(A) is terminal\n\u03b7-uniq : \u2200 {\u2219A} {x : \u2219A .proj\u2081} \u2192 (\u2219f : \u2219Set[ \u2219A , Sing \u2219A ]) \u2192 (\u2219f .proj\u2081) x \u2261 (\u03b7[ \u2219A ] .proj\u2081) x\n\u03b7-uniq {A , a} (f , p) = pointed-all-paths\n\nSing\u22431 : \u2200 {\u2219A} \u2192 \u2219Iso[ Sing \u2219A , \u22191 ]\nSing\u22431 {\u2219A@(A , a)} = iso \u2219![ Sing \u2219A ] ( ((\u03bb _ \u2192 a) , refl) \u2218 \u03b7[ \u2219A ]) (\u03bb _ \u2192 refl) (\u03bb _ \u2192 pointed-all-paths)\n\n\u03bc[_] : \u2200 \u2219A \u2192 \u2219Iso[ Sing (Sing \u2219A) , Sing \u2219A ]\n\u03bc[ (A , a) ] = iso ((\u03bb { (.(a , refl) , refl) \u2192 a , refl }) , refl)\n ((\u03bb { (a , refl) \u2192 (a , refl) , refl }) , refl)\n (\u03bb { (a , refl) \u2192 refl})\n (\u03bb { ((a , refl) , refl) \u2192 refl })\n\n-- check\nS\u03b7-\u03bc : \u2200 {\u2219A} \u2192 ((Sing[ \u2219A , Sing \u2219A ] \u03b7[ \u2219A ] \u2218 (\u03bc[ \u2219A ] .\u2219f)) .proj\u2081) (\u2219A .proj\u2082 , refl) \u2261 (\u2219A .proj\u2082 , refl)\nS\u03b7-\u03bc = refl\n\n\u03b7S-\u03bc : \u2200 {\u2219A} \u2192 ((Sing[ Sing \u2219A , Sing (Sing \u2219A) ] \u03b7[ Sing \u2219A ] \u2218 (\u03bc[ Sing \u2219A ] .\u2219f)) .proj\u2081) ((\u2219A .proj\u2082 , refl) , refl) \u2261 ((\u2219A .proj\u2082 , refl) , refl)\n\u03b7S-\u03bc = refl\n\n-- strength\n\u03c3\u00d7[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing \u2219A \u2219\u00d7 \u2219B , Sing (\u2219A \u2219\u00d7 \u2219B) ]\n\u03c3\u00d7[ (A , a) , (B , b) ] = (\u03bb { ((a , refl) , _) \u2192 (a , b) , refl }) , refl\n\n\u03c4\u00d7[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ \u2219A \u2219\u00d7 Sing \u2219B , Sing (\u2219A \u2219\u00d7 \u2219B) ]\n\u03c4\u00d7[ (A , a) , (B , b) ] = (\u03bb { (_ , (b , refl)) \u2192 (a , b) , refl }) , refl\n\n\u03c3+[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing \u2219A \u2219+ \u2219B , Sing (\u2219A \u2219+ \u2219B) ]\n\u03c3+[ (A , a) , (B , b) ] = (\u03bb _ \u2192 inj\u2081 a , refl) , refl\n\n\u03c4+[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ \u2219A \u2219+ Sing \u2219B , Sing (\u2219A \u2219+ \u2219B) ]\n\u03c4+[ (A , a) , (B , b) ] = (\u03bb _ \u2192 inj\u2081 a , refl) , refl\n\n-- comonad\n\u03b5[_] : \u2200 \u2219A \u2192 \u2219Set[ Sing \u2219A , \u2219A ]\n\u03b5[ (A , a) ] = (\u03bb { (x , refl) \u2192 x }) , refl\n\n\u03b4[_] : \u2200 \u2219A \u2192 \u2219Iso[ Sing \u2219A , Sing (Sing \u2219A) ]\n\u03b4[ \u2219A ] = \u2219Iso\u207b\u00b9 \u03bc[ \u2219A ]\n\n-- check\n\u03b4-S\u03b5 : \u2200 {\u2219A} \u2192 ((\u03b4[ \u2219A ] .\u2219f \u2218 Sing[ Sing \u2219A , \u2219A ] \u03b5[ \u2219A ]) .proj\u2081) (\u2219A .proj\u2082 , refl) \u2261 (\u2219A .proj\u2082 , refl)\n\u03b4-S\u03b5 = refl\n\n\u03b4-\u03b5S : \u2200 {\u2219A} \u2192 ((\u03b4[ Sing \u2219A ] .\u2219f \u2218 Sing[ Sing (Sing \u2219A) , Sing \u2219A ] \u03b5[ Sing \u2219A ]) .proj\u2081) ((\u2219A .proj\u2082 , refl) , refl) \u2261 ((\u2219A .proj\u2082 , refl) , refl)\n\u03b4-\u03b5S = refl\n\n-- costrength\n\u03c3'\u00d7[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing (\u2219A \u2219\u00d7 \u2219B) , Sing \u2219A \u2219\u00d7 \u2219B ]\n\u03c3'\u00d7[ (A , a) , (B , b) ] = (\u03bb { (.(a , b) , refl) \u2192 (a , refl) , b }) , refl\n\n\u03c4'\u00d7[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing (\u2219A \u2219\u00d7 \u2219B) , \u2219A \u2219\u00d7 Sing \u2219B ]\n\u03c4'\u00d7[ (A , a) , (B , b) ] = (\u03bb { (.(a , b) , refl) \u2192 a , (b , refl) }) , refl\n\n\u03c3'+[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing (\u2219A \u2219+ \u2219B) , Sing \u2219A \u2219+ \u2219B ]\n\u03c3'+[ (A , a) , (B , b) ] = (\u03bb _ \u2192 inj\u2081 (a , refl)) , refl\n\n\u03c4'+[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing (\u2219A \u2219+ \u2219B) , \u2219A \u2219+ Sing \u2219B ]\n\u03c4'+[ (A , a) , (B , b) ] = (\u03bb _ \u2192 inj\u2081 a) , refl\n\n-- even better, strong monoidal functor\n\u03bd\u00d7[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Iso[ Sing \u2219A \u2219\u00d7 Sing \u2219B , Sing (\u2219A \u2219\u00d7 \u2219B) ]\n\u03bd\u00d7[ (A , a) , (B , b) ] = iso ((\u03bb _ \u2192 (a , b) , refl) , refl)\n ((\u03bb _ \u2192 (a , refl) , b , refl) , refl)\n (\u03bb { (.(a , b) , refl) \u2192 refl })\n (\u03bb { ((a , refl) , (b , refl)) \u2192 refl })\n\n-- this one is only lax\n\u03bd+[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ Sing \u2219A \u2219+ Sing \u2219B , Sing (\u2219A \u2219+ \u2219B) ]\n\u03bd+[ (A , a) , (B , b) ] = (\u03bb _ \u2192 inj\u2081 a , refl) , refl\n\n-- free pointed set\nU : \u2219Set \u2192 Set\nU = proj\u2081\n\nU[_,_] : \u2200 \u2219A \u2219B \u2192 \u2219Set[ \u2219A , \u2219B ] \u2192 (U \u2219A \u2192 U \u2219B)\nU[ _ , _ ] = proj\u2081\n\nF : Set \u2192 \u2219Set\nF A = (A \u228e \u22a4) , inj\u2082 tt\n\nF[_,_] : \u2200 A B \u2192 (A \u2192 B) \u2192 \u2219Set[ F A , F B ]\nF[ A , B ] f = (\u03bb { (inj\u2081 a) \u2192 inj\u2081 (f a) ; (inj\u2082 tt) \u2192 inj\u2082 tt }) , refl\n\n->adj : \u2200 {A \u2219B} \u2192 (A \u2192 U \u2219B) \u2192 \u2219Set[ F A , \u2219B ]\n->adj f = (\u03bb { (inj\u2081 a) \u2192 f a ; (inj\u2082 tt) \u2192 _ }) , refl\n\n<-adj : \u2200 {A \u2219B} \u2192 \u2219Set[ F A , \u2219B ] \u2192 (A \u2192 U \u2219B)\n<-adj (f , refl) a = f (inj\u2081 a)\n\n\u03b7-adj : \u2200 {A} \u2192 (A \u2192 U (F A))\n\u03b7-adj = <-adj \u2219id\n\n\u03b5-adj : \u2200 {\u2219A} \u2192 \u2219Set[ F (U \u2219A), \u2219A ]\n\u03b5-adj = ->adj \u03bb x \u2192 x\n\n-- maybe monad\nT : Set \u2192 Set\nT A = U (F A)\n\nT-\u03b7[_] : \u2200 A \u2192 (A \u2192 T A)\nT-\u03b7[ A ] = \u03b7-adj\n\nT-\u03bc[_] : \u2200 A \u2192 (T (T A) \u2192 T A)\nT-\u03bc[ A ] = U[ F (T A) , F A ] \u03b5-adj\n\n-- comaybe comonad\nD : \u2219Set \u2192 \u2219Set\nD \u2219A = F (U \u2219A)\n\nD-\u03b5[_] : \u2200 \u2219A \u2192 \u2219Set[ D \u2219A , \u2219A ]\nD-\u03b5[ \u2219A ] = \u03b5-adj\n\nD-\u03b4[_] : \u2200 \u2219A \u2192 \u2219Set[ D \u2219A , D (D \u2219A) ]\nD-\u03b4[ \u2219A ] = F[ U \u2219A , U (D \u2219A) ] \u03b7-adj\n\n-- but also\nD-\u03b7[_] : \u2200 \u2219A \u2192 \u2219Set[ \u2219A , D \u2219A ]\nD-\u03b7[ \u2219A ] = (\u03bb _ \u2192 inj\u2082 tt) , refl\n-- D \u2219A is not contractible\n\n-- distributive laws?\n-- same as \u2219Set[ \u22191 , D \u22191 ] so follows D-\u03b7\n\u039b : \u2200 {\u2219A} \u2192 \u2219Set[ Sing (D \u2219A) , D (Sing \u2219A) ]\n\u039b = (\u03bb { (.(inj\u2082 tt) , refl) \u2192 inj\u2082 tt }) , refl\n","avg_line_length":30.7993730408,"max_line_length":151,"alphanum_fraction":0.4375572519} {"size":152,"ext":"agda","lang":"Agda","max_stars_count":301.0,"content":"{-# OPTIONS --safe #-}\nmodule Cubical.HITs.Torus where\n\nopen import Cubical.HITs.Torus.Base public\n\n-- open import Cubical.HITs.Torus.Properties public\n","avg_line_length":21.7142857143,"max_line_length":51,"alphanum_fraction":0.7631578947} {"size":3215,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --without-K --rewriting #-}\n\nopen import HoTT\nopen import homotopy.PtdAdjoint\n\nmodule homotopy.SuspAdjointLoop {i} where\n\nprivate\n SuspFunctor : PtdFunctor i i\n SuspFunctor = record {\n obj = \u2299Susp;\n arr = \u2299Susp-fmap;\n id = \u2299Susp-fmap-idf;\n comp = \u2299Susp-fmap-\u2218}\n\n LoopFunctor : PtdFunctor i i\n LoopFunctor = record {\n obj = \u2299\u03a9;\n arr = \u2299\u03a9-fmap;\n id = \u03bb _ \u2192 \u2299\u03a9-fmap-idf;\n comp = \u2299\u03a9-fmap-\u2218}\n\n module _ (X : Ptd i) where\n\n \u03b7 : de\u2299 X \u2192 \u03a9 (\u2299Susp X)\n \u03b7 x = \u03c3loop X x\n\n module E = SuspRec (pt X) (pt X) (idf _)\n\n \u03b5 : de\u2299 (\u2299Susp (\u2299\u03a9 X)) \u2192 de\u2299 X\n \u03b5 = E.f\n\n \u2299\u03b7 : X \u2299\u2192 \u2299\u03a9 (\u2299Susp X)\n \u2299\u03b7 = (\u03b7 , \u03c3loop-pt)\n\n \u2299\u03b5 : \u2299Susp (\u2299\u03a9 X) \u2299\u2192 X\n \u2299\u03b5 = (\u03b5 , idp)\n\n \u03b7-natural : {X Y : Ptd i} (f : X \u2299\u2192 Y)\n \u2192 \u2299\u03b7 Y \u2299\u2218 f == \u2299\u03a9-fmap (\u2299Susp-fmap f) \u2299\u2218 \u2299\u03b7 X\n \u03b7-natural {X = X} (f , idp) = \u2299\u03bb='\n (\u03bb x \u2192 ! $\n ap-\u2219 (Susp-fmap f) (merid x) (! (merid (pt X)))\n \u2219 SuspFmap.merid-\u03b2 f x\n \u22192 (ap-! (Susp-fmap f) (merid (pt X))\n \u2219 ap ! (SuspFmap.merid-\u03b2 f (pt X))))\n (pt-lemma (Susp-fmap f) (merid (pt X)) (SuspFmap.merid-\u03b2 f (pt X)))\n where\n pt-lemma : \u2200 {i j} {A : Type i} {B : Type j} (f : A \u2192 B)\n {x y : A} (p : x == y) {q : f x == f y} (\u03b1 : ap f p == q)\n \u2192 !-inv-r q == ap (ap f) (!-inv-r p) \u2219 idp\n [ _== idp \u2193 ! (ap-\u2219 f p (! p) \u2219 \u03b1 \u22192 (ap-! f p \u2219 ap ! \u03b1)) ]\n pt-lemma f idp idp = idp\n\n \u03b5-natural : {X Y : Ptd i} (f : X \u2299\u2192 Y)\n \u2192 \u2299\u03b5 Y \u2299\u2218 \u2299Susp-fmap (\u2299\u03a9-fmap f) == f \u2299\u2218 \u2299\u03b5 X\n \u03b5-natural (f , idp) = \u2299\u03bb='\n (SuspElim.f idp idp\n (\u03bb p \u2192 \u2193-='-from-square $ vert-degen-square $\n ap-\u2218 (\u03b5 _) (Susp-fmap (ap f)) (merid p)\n \u2219 ap (ap (\u03b5 _)) (SuspFmap.merid-\u03b2 (ap f) p)\n \u2219 E.merid-\u03b2 _ (ap f p)\n \u2219 ap (ap f) (! (E.merid-\u03b2 _ p))\n \u2219 \u2218-ap f (\u03b5 _) (merid p)))\n idp\n\n \u03b5\u03a3-\u03a3\u03b7 : (X : Ptd i) \u2192 \u2299\u03b5 (\u2299Susp X) \u2299\u2218 \u2299Susp-fmap (\u2299\u03b7 X) == \u2299idf _\n \u03b5\u03a3-\u03a3\u03b7 X = \u2299\u03bb='\n (SuspElim.f\n idp\n (merid (pt X))\n (\u03bb x \u2192 \u2193-='-from-square $\n (ap-\u2218 (\u03b5 (\u2299Susp X)) (Susp-fmap (\u03b7 X)) (merid x)\n \u2219 ap (ap (\u03b5 (\u2299Susp X))) (SuspFmap.merid-\u03b2 (\u03b7 X) x)\n \u2219 E.merid-\u03b2 _ (merid x \u2219 ! (merid (pt X))))\n \u2219v\u22a1 square-lemma (merid x) (merid (pt X))\n \u22a1v\u2219 ! (ap-idf (merid x))))\n idp\n where\n square-lemma : \u2200 {i} {A : Type i} {x y z : A}\n (p : x == y) (q : z == y)\n \u2192 Square idp (p \u2219 ! q) p q\n square-lemma idp idp = ids\n\n \u03a9\u03b5-\u03b7\u03a9 : (X : Ptd i) \u2192 \u2299\u03a9-fmap (\u2299\u03b5 X) \u2299\u2218 \u2299\u03b7 (\u2299\u03a9 X) == \u2299idf _\n \u03a9\u03b5-\u03b7\u03a9 X = \u2299\u03bb='\n (\u03bb p \u2192 ap-\u2219 (\u03b5 X) (merid p) (! (merid idp))\n \u2219 (E.merid-\u03b2 X p \u22192 (ap-! (\u03b5 X) (merid idp) \u2219 ap ! (E.merid-\u03b2 X idp)))\n \u2219 \u2219-unit-r _)\n (pt-lemma (\u03b5 X) (merid idp) (E.merid-\u03b2 X idp))\n where\n pt-lemma : \u2200 {i j} {A : Type i} {B : Type j} (f : A \u2192 B)\n {x y : A} (p : x == y) {q : f x == f y} (\u03b1 : ap f p == q)\n \u2192 ap (ap f) (!-inv-r p) \u2219 idp == idp\n [ _== idp \u2193 ap-\u2219 f p (! p) \u2219 (\u03b1 \u22192 (ap-! f p \u2219 ap ! \u03b1)) \u2219 !-inv-r q ]\n pt-lemma f idp idp = idp\n\nmodule Eta = E\n\nadj : CounitUnitAdjoint SuspFunctor LoopFunctor\nadj = record {\n \u03b7 = \u2299\u03b7;\n \u03b5 = \u2299\u03b5;\n\n \u03b7-natural = \u03b7-natural;\n \u03b5-natural = \u03b5-natural;\n\n \u03b5F-F\u03b7 = \u03b5\u03a3-\u03a3\u03b7;\n G\u03b5-\u03b7G = \u03a9\u03b5-\u03b7\u03a9}\n\nhadj = counit-unit-to-hom adj\n\nopen CounitUnitAdjoint adj public\nopen HomAdjoint hadj public\n","avg_line_length":27.9565217391,"max_line_length":79,"alphanum_fraction":0.4590979782} {"size":16601,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --without-K --rewriting #-}\n\nopen import lib.Basics\n\nmodule lib.types.Sigma where\n\n-- pointed [\u03a3]\n\u2299\u03a3 : \u2200 {i j} (X : Ptd i) \u2192 (de\u2299 X \u2192 Ptd j) \u2192 Ptd (lmax i j)\n\u2299\u03a3 \u2299[ A , a\u2080 ] Y = \u2299[ \u03a3 A (de\u2299 \u2218 Y) , (a\u2080 , pt (Y a\u2080)) ]\n\n-- Cartesian product\n_\u00d7_ : \u2200 {i j} (A : Type i) (B : Type j) \u2192 Type (lmax i j)\nA \u00d7 B = \u03a3 A (\u03bb _ \u2192 B)\n\n_\u2299\u00d7_ : \u2200 {i j} \u2192 Ptd i \u2192 Ptd j \u2192 Ptd (lmax i j)\nX \u2299\u00d7 Y = \u2299\u03a3 X (\u03bb _ \u2192 Y)\n\ninfixr 80 _\u00d7_ _\u2299\u00d7_\n\n-- XXX Do we really need two versions of [\u2299fst]?\n\u2299fst\u1d48 : \u2200 {i j} {X : Ptd i} (Y : de\u2299 X \u2192 Ptd j) \u2192 \u2299\u03a3 X Y \u2299\u2192 X\n\u2299fst\u1d48 Y = fst , idp\n\n\u2299fst : \u2200 {i j} {X : Ptd i} {Y : Ptd j} \u2192 X \u2299\u00d7 Y \u2299\u2192 X\n\u2299fst = \u2299fst\u1d48 _\n\n\u2299snd : \u2200 {i j} {X : Ptd i} {Y : Ptd j} \u2192 X \u2299\u00d7 Y \u2299\u2192 Y\n\u2299snd = (snd , idp)\n\nfanout : \u2200 {i j k} {A : Type i} {B : Type j} {C : Type k}\n \u2192 (A \u2192 B) \u2192 (A \u2192 C) \u2192 (A \u2192 B \u00d7 C)\nfanout f g x = f x , g x\n\n\u2299fanout-pt : \u2200 {i j} {A : Type i} {B : Type j}\n {a\u2080 a\u2081 : A} (p : a\u2080 == a\u2081) {b\u2080 b\u2081 : B} (q : b\u2080 == b\u2081)\n \u2192 (a\u2080 , b\u2080) == (a\u2081 , b\u2081) :> A \u00d7 B\n\u2299fanout-pt = pair\u00d7=\n\n\u2299fanout : \u2200 {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n \u2192 X \u2299\u2192 Y \u2192 X \u2299\u2192 Z \u2192 X \u2299\u2192 Y \u2299\u00d7 Z\n\u2299fanout (f , fpt) (g , gpt) = fanout f g , \u2299fanout-pt fpt gpt\n\ndiag : \u2200 {i} {A : Type i} \u2192 (A \u2192 A \u00d7 A)\ndiag a = a , a\n\n\u2299diag : \u2200 {i} {X : Ptd i} \u2192 X \u2299\u2192 X \u2299\u00d7 X\n\u2299diag = ((\u03bb x \u2192 (x , x)) , idp)\n\n\u2299\u00d7-inl : \u2200 {i j} (X : Ptd i) (Y : Ptd j) \u2192 X \u2299\u2192 X \u2299\u00d7 Y\n\u2299\u00d7-inl X Y = (\u03bb x \u2192 x , pt Y) , idp\n\n\u2299\u00d7-inr : \u2200 {i j} (X : Ptd i) (Y : Ptd j) \u2192 Y \u2299\u2192 X \u2299\u00d7 Y\n\u2299\u00d7-inr X Y = (\u03bb y \u2192 pt X , y) , idp\n\n\u2299fst-fanout : \u2200 {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (f : X \u2299\u2192 Y) (g : X \u2299\u2192 Z)\n \u2192 \u2299fst \u2299\u2218 \u2299fanout f g == f\n\u2299fst-fanout (f , idp) (g , idp) = idp\n\n\u2299snd-fanout : \u2200 {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}\n (f : X \u2299\u2192 Y) (g : X \u2299\u2192 Z)\n \u2192 \u2299snd \u2299\u2218 \u2299fanout f g == g\n\u2299snd-fanout (f , idp) (g , idp) = idp\n\n\u2299fanout-pre\u2218 : \u2200 {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}\n (f : Y \u2299\u2192 Z) (g : Y \u2299\u2192 W) (h : X \u2299\u2192 Y)\n \u2192 \u2299fanout f g \u2299\u2218 h == \u2299fanout (f \u2299\u2218 h) (g \u2299\u2218 h)\n\u2299fanout-pre\u2218 (f , idp) (g , idp) (h , idp) = idp\n\nmodule _ {i j} {A : Type i} {B : A \u2192 Type j} where\n\n pair : (a : A) (b : B a) \u2192 \u03a3 A B\n pair a b = (a , b)\n\n -- pair= has already been defined\n\n fst= : {ab a'b' : \u03a3 A B} (p : ab == a'b') \u2192 (fst ab == fst a'b')\n fst= = ap fst\n\n snd= : {ab a'b' : \u03a3 A B} (p : ab == a'b')\n \u2192 (snd ab == snd a'b' [ B \u2193 fst= p ])\n snd= {._} {_} idp = idp\n\n fst=-\u03b2 : {a a' : A} (p : a == a')\n {b : B a} {b' : B a'} (q : b == b' [ B \u2193 p ])\n \u2192 fst= (pair= p q) == p\n fst=-\u03b2 idp idp = idp\n\n snd=-\u03b2 : {a a' : A} (p : a == a')\n {b : B a} {b' : B a'} (q : b == b' [ B \u2193 p ])\n \u2192 snd= (pair= p q) == q [ (\u03bb v \u2192 b == b' [ B \u2193 v ]) \u2193 fst=-\u03b2 p q ]\n snd=-\u03b2 idp idp = idp\n\n pair=-\u03b7 : {ab a'b' : \u03a3 A B} (p : ab == a'b')\n \u2192 p == pair= (fst= p) (snd= p)\n pair=-\u03b7 {._} {_} idp = idp\n\n pair== : {a a' : A} {p p' : a == a'} (\u03b1 : p == p')\n {b : B a} {b' : B a'} {q : b == b' [ B \u2193 p ]} {q' : b == b' [ B \u2193 p' ]}\n (\u03b2 : q == q' [ (\u03bb u \u2192 b == b' [ B \u2193 u ]) \u2193 \u03b1 ])\n \u2192 pair= p q == pair= p' q'\n pair== idp idp = idp\n\nmodule _ {i j} {A : Type i} {B : Type j} where\n\n fst\u00d7= : {ab a'b' : A \u00d7 B} (p : ab == a'b') \u2192 (fst ab == fst a'b')\n fst\u00d7= = ap fst\n\n snd\u00d7= : {ab a'b' : A \u00d7 B} (p : ab == a'b')\n \u2192 (snd ab == snd a'b')\n snd\u00d7= = ap snd\n\n fst\u00d7=-\u03b2 : {a a' : A} (p : a == a')\n {b b' : B} (q : b == b')\n \u2192 fst\u00d7= (pair\u00d7= p q) == p\n fst\u00d7=-\u03b2 idp idp = idp\n\n snd\u00d7=-\u03b2 : {a a' : A} (p : a == a')\n {b b' : B} (q : b == b')\n \u2192 snd\u00d7= (pair\u00d7= p q) == q\n snd\u00d7=-\u03b2 idp idp = idp\n\n pair\u00d7=-\u03b7 : {ab a'b' : A \u00d7 B} (p : ab == a'b')\n \u2192 p == pair\u00d7= (fst\u00d7= p) (snd\u00d7= p)\n pair\u00d7=-\u03b7 {._} {_} idp = idp\n\nmodule _ {i j} {A : Type i} {B : A \u2192 Type j} where\n\n =\u03a3 : (x y : \u03a3 A B) \u2192 Type (lmax i j)\n =\u03a3 (a , b) (a' , b') = \u03a3 (a == a') (\u03bb p \u2192 b == b' [ B \u2193 p ])\n\n =\u03a3-econv : (x y : \u03a3 A B) \u2192 (=\u03a3 x y) \u2243 (x == y)\n =\u03a3-econv x y =\n equiv (\u03bb pq \u2192 pair= (fst pq) (snd pq)) (\u03bb p \u2192 fst= p , snd= p)\n (\u03bb p \u2192 ! (pair=-\u03b7 p))\n (\u03bb pq \u2192 pair= (fst=-\u03b2 (fst pq) (snd pq)) (snd=-\u03b2 (fst pq) (snd pq)))\n\n =\u03a3-conv : (x y : \u03a3 A B) \u2192 (=\u03a3 x y) == (x == y)\n =\u03a3-conv x y = ua (=\u03a3-econv x y)\n\n\u03a3= : \u2200 {i j} {A A' : Type i} (p : A == A') {B : A \u2192 Type j} {B' : A' \u2192 Type j}\n (q : B == B' [ (\u03bb X \u2192 (X \u2192 Type j)) \u2193 p ]) \u2192 \u03a3 A B == \u03a3 A' B'\n\u03a3= idp idp = idp\n\ninstance\n \u03a3-level : \u2200 {i j} {n : \u2115\u208b\u2082} {A : Type i} {P : A \u2192 Type j}\n \u2192 has-level n A \u2192 ((x : A) \u2192 has-level n (P x))\n \u2192 has-level n (\u03a3 A P)\n \u03a3-level {n = \u27e8-2\u27e9} p q = has-level-in ((contr-center p , (contr-center (q (contr-center p)))) , lemma)\n where abstract lemma = \u03bb y \u2192 pair= (contr-path p _) (from-transp! _ _ (contr-path (q _) _))\n \u03a3-level {n = S n} p q = has-level-in lemma where\n abstract\n lemma = \u03bb x y \u2192 equiv-preserves-level (=\u03a3-econv x y)\n {{\u03a3-level (has-level-apply p _ _) (\u03bb _ \u2192\n equiv-preserves-level ((to-transp-equiv _ _)\u207b\u00b9) {{has-level-apply (q _) _ _}})}}\n\n\u00d7-level : \u2200 {i j} {n : \u2115\u208b\u2082} {A : Type i} {B : Type j}\n \u2192 (has-level n A \u2192 has-level n B \u2192 has-level n (A \u00d7 B))\n\u00d7-level pA pB = \u03a3-level pA (\u03bb x \u2192 pB)\n\n-- Equivalences in a \u03a3-type\n\n\u03a3-fmap-l : \u2200 {i j k} {A : Type i} {B : Type j} (P : B \u2192 Type k)\n \u2192 (f : A \u2192 B) \u2192 (\u03a3 A (P \u2218 f) \u2192 \u03a3 B P)\n\u03a3-fmap-l P f (a , r) = (f a , r)\n\n\u00d7-fmap-l : \u2200 {i\u2080 i\u2081 j} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081} (B : Type j)\n \u2192 (f : A\u2080 \u2192 A\u2081) \u2192 (A\u2080 \u00d7 B \u2192 A\u2081 \u00d7 B)\n\u00d7-fmap-l B = \u03a3-fmap-l (\u03bb _ \u2192 B)\n\n\u03a3-isemap-l : \u2200 {i j k} {A : Type i} {B : Type j} (P : B \u2192 Type k) {h : A \u2192 B}\n \u2192 is-equiv h \u2192 is-equiv (\u03a3-fmap-l P h)\n\u03a3-isemap-l {A = A} {B = B} P {h} e = is-eq _ g f-g g-f\n where f = \u03a3-fmap-l P h\n\n g : \u03a3 B P \u2192 \u03a3 A (P \u2218 h)\n g (b , s) = (is-equiv.g e b , transport P (! (is-equiv.f-g e b)) s)\n\n f-g : \u2200 y \u2192 f (g y) == y\n f-g (b , s) = pair= (is-equiv.f-g e b) (transp-\u2193 P (is-equiv.f-g e b) s)\n\n g-f : \u2200 x \u2192 g (f x) == x\n g-f (a , r) =\n pair= (is-equiv.g-f e a)\n (transport (\u03bb q \u2192 transport P (! q) r == r [ P \u2218 h \u2193 is-equiv.g-f e a ])\n (is-equiv.adj e a)\n (transp-ap-\u2193 P h (is-equiv.g-f e a) r))\n\n\u00d7-isemap-l : \u2200 {i\u2080 i\u2081 j} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081} (B : Type j) {h : A\u2080 \u2192 A\u2081}\n \u2192 is-equiv h \u2192 is-equiv (\u00d7-fmap-l B h)\n\u00d7-isemap-l B = \u03a3-isemap-l (\u03bb _ \u2192 B)\n\n\u03a3-emap-l : \u2200 {i j k} {A : Type i} {B : Type j} (P : B \u2192 Type k)\n \u2192 (e : A \u2243 B) \u2192 (\u03a3 A (P \u2218 \u2013> e) \u2243 \u03a3 B P)\n\u03a3-emap-l P (f , e) = _ , \u03a3-isemap-l P e\n\n\u00d7-emap-l : \u2200 {i\u2080 i\u2081 j} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081} (B : Type j)\n \u2192 (e : A\u2080 \u2243 A\u2081) \u2192 (A\u2080 \u00d7 B \u2243 A\u2081 \u00d7 B)\n\u00d7-emap-l B = \u03a3-emap-l (\u03bb _ \u2192 B)\n\n\u03a3-fmap-r : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n \u2192 (\u2200 x \u2192 B x \u2192 C x) \u2192 (\u03a3 A B \u2192 \u03a3 A C)\n\u03a3-fmap-r h (a , b) = (a , h a b)\n\n\u00d7-fmap-r : \u2200 {i j\u2080 j\u2081} (A : Type i) {B\u2080 : Type j\u2080} {B\u2081 : Type j\u2081}\n \u2192 (h : B\u2080 \u2192 B\u2081) \u2192 (A \u00d7 B\u2080 \u2192 A \u00d7 B\u2081)\n\u00d7-fmap-r A h = \u03a3-fmap-r (\u03bb _ \u2192 h)\n\n\u03a3-isemap-r : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n {h : \u2200 x \u2192 B x \u2192 C x} \u2192 (\u2200 x \u2192 is-equiv (h x)) \u2192 is-equiv (\u03a3-fmap-r h)\n\u03a3-isemap-r {A = A} {B = B} {C = C} {h} k = is-eq _ g f-g g-f\n where f = \u03a3-fmap-r h\n\n g : \u03a3 A C \u2192 \u03a3 A B\n g (a , c) = (a , is-equiv.g (k a) c)\n\n f-g : \u2200 p \u2192 f (g p) == p\n f-g (a , c) = pair= idp (is-equiv.f-g (k a) c)\n\n g-f : \u2200 p \u2192 g (f p) == p\n g-f (a , b) = pair= idp (is-equiv.g-f (k a) b)\n\n\u00d7-isemap-r : \u2200 {i j\u2080 j\u2081} (A : Type i) {B\u2080 : Type j\u2080} {B\u2081 : Type j\u2081}\n \u2192 {h : B\u2080 \u2192 B\u2081} \u2192 is-equiv h \u2192 is-equiv (\u00d7-fmap-r A h)\n\u00d7-isemap-r A e = \u03a3-isemap-r (\u03bb _ \u2192 e)\n\n\u03a3-emap-r : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n \u2192 (\u2200 x \u2192 B x \u2243 C x) \u2192 (\u03a3 A B \u2243 \u03a3 A C)\n\u03a3-emap-r k = _ , \u03a3-isemap-r (\u03bb x \u2192 snd (k x))\n\n\u00d7-emap-r : \u2200 {i j\u2080 j\u2081} (A : Type i) {B\u2080 : Type j\u2080} {B\u2081 : Type j\u2081}\n \u2192 (e : B\u2080 \u2243 B\u2081) \u2192 (A \u00d7 B\u2080 \u2243 A \u00d7 B\u2081)\n\u00d7-emap-r A e = \u03a3-emap-r (\u03bb _ \u2192 e)\n\nhfiber-\u03a3-fmap-r : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n \u2192 (h : \u2200 x \u2192 B x \u2192 C x) \u2192 {a : A} \u2192 (c : C a)\n \u2192 hfiber (\u03a3-fmap-r h) (a , c) \u2243 hfiber (h a) c\nhfiber-\u03a3-fmap-r h {a} c = equiv to from to-from from-to\n\n where to : hfiber (\u03a3-fmap-r h) (a , c) \u2192 hfiber (h a) c\n to ((_ , b) , idp) = b , idp\n\n from : hfiber (h a) c \u2192 hfiber (\u03a3-fmap-r h) (a , c)\n from (b , idp) = (a , b) , idp\n\n abstract\n to-from : (x : hfiber (h a) c) \u2192 to (from x) == x\n to-from (b , idp) = idp\n\n from-to : (x : hfiber (\u03a3-fmap-r h) (a , c)) \u2192 from (to x) == x\n from-to ((_ , b) , idp) = idp\n\n{-\n-- 2016\/08\/20 favonia: no one is using the following two functions.\n\n-- Two ways of simultaneously applying equivalences in each component.\nmodule _ {i\u2080 i\u2081 j\u2080 j\u2081} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081}\n {B\u2080 : A\u2080 \u2192 Type j\u2080} {B\u2081 : A\u2081 \u2192 Type j\u2081} where\n \u03a3-emap : (u : A\u2080 \u2243 A\u2081) (v : \u2200 a \u2192 B\u2080 (<\u2013 u a) \u2243 B\u2081 a) \u2192 \u03a3 A\u2080 B\u2080 \u2243 \u03a3 A\u2081 B\u2081\n \u03a3-emap u v = \u03a3 A\u2080 B\u2080 \u2243\u27e8 \u03a3-emap-l _ (u \u207b\u00b9) \u207b\u00b9 \u27e9\n \u03a3 A\u2081 (B\u2080 \u2218 <\u2013 u) \u2243\u27e8 \u03a3-emap-r v \u27e9\n \u03a3 A\u2081 B\u2081 \u2243\u220e\n\n \u03a3-emap' : (u : A\u2080 \u2243 A\u2081) (v : \u2200 a \u2192 B\u2080 a \u2243 B\u2081 (\u2013> u a)) \u2192 \u03a3 A\u2080 B\u2080 \u2243 \u03a3 A\u2081 B\u2081\n \u03a3-emap' u v = \u03a3 A\u2080 B\u2080 \u2243\u27e8 \u03a3-emap-r v \u27e9\n \u03a3 A\u2080 (B\u2081 \u2218 \u2013> u) \u2243\u27e8 \u03a3-emap-l _ u \u27e9\n \u03a3 A\u2081 B\u2081 \u2243\u220e\n-}\n\n\u00d7-fmap : \u2200 {i\u2080 i\u2081 j\u2080 j\u2081} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081} {B\u2080 : Type j\u2080} {B\u2081 : Type j\u2081}\n \u2192 (h : A\u2080 \u2192 A\u2081) (k : B\u2080 \u2192 B\u2081) \u2192 (A\u2080 \u00d7 B\u2080 \u2192 A\u2081 \u00d7 B\u2081)\n\u00d7-fmap u v = \u00d7-fmap-r _ v \u2218 \u00d7-fmap-l _ u\n\n\u2299\u00d7-fmap : \u2200 {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}\n \u2192 X \u2299\u2192 X' \u2192 Y \u2299\u2192 Y' \u2192 X \u2299\u00d7 Y \u2299\u2192 X' \u2299\u00d7 Y'\n\u2299\u00d7-fmap (f , fpt) (g , gpt) = \u00d7-fmap f g , pair\u00d7= fpt gpt\n\n\u00d7-isemap : \u2200 {i\u2080 i\u2081 j\u2080 j\u2081} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081} {B\u2080 : Type j\u2080} {B\u2081 : Type j\u2081}\n {h : A\u2080 \u2192 A\u2081} {k : B\u2080 \u2192 B\u2081} \u2192 is-equiv h \u2192 is-equiv k \u2192 is-equiv (\u00d7-fmap h k)\n\u00d7-isemap eh ek = \u00d7-isemap-r _ ek \u2218ise \u00d7-isemap-l _ eh\n\n\u00d7-emap : \u2200 {i\u2080 i\u2081 j\u2080 j\u2081} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081} {B\u2080 : Type j\u2080} {B\u2081 : Type j\u2081}\n \u2192 (u : A\u2080 \u2243 A\u2081) (v : B\u2080 \u2243 B\u2081) \u2192 (A\u2080 \u00d7 B\u2080 \u2243 A\u2081 \u00d7 B\u2081)\n\u00d7-emap u v = \u00d7-emap-r _ v \u2218e \u00d7-emap-l _ u\n\n\u2299\u00d7-emap : \u2200 {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}\n \u2192 X \u2299\u2243 X' \u2192 Y \u2299\u2243 Y' \u2192 X \u2299\u00d7 Y \u2299\u2243 X' \u2299\u00d7 Y'\n\u2299\u00d7-emap (F , F-ise) (G , G-ise) = \u2299\u00d7-fmap F G , \u00d7-isemap F-ise G-ise\n\n-- Implementation of [_\u2219'_] on \u03a3\n\u03a3-\u2219' : \u2200 {i j} {A : Type i} {B : A \u2192 Type j}\n {x y z : A} {p : x == y} {p' : y == z}\n {u : B x} {v : B y} {w : B z}\n (q : u == v [ B \u2193 p ]) (r : v == w [ B \u2193 p' ])\n \u2192 (pair= p q \u2219' pair= p' r) == pair= (p \u2219' p') (q \u2219'\u1d48 r)\n\u03a3-\u2219' {p = idp} {p' = idp} q idp = idp\n\n-- Implementation of [_\u2219_] on \u03a3\n\u03a3-\u2219 : \u2200 {i j} {A : Type i} {B : A \u2192 Type j}\n {x y z : A} {p : x == y} {p' : y == z}\n {u : B x} {v : B y} {w : B z}\n (q : u == v [ B \u2193 p ]) (r : v == w [ B \u2193 p' ])\n \u2192 (pair= p q \u2219 pair= p' r) == pair= (p \u2219 p') (q \u2219\u1d48 r)\n\u03a3-\u2219 {p = idp} {p' = idp} idp r = idp\n\n-- Implementation of [!] on \u03a3\n\u03a3-! : \u2200 {i j} {A : Type i} {B : A \u2192 Type j}\n {x y : A} {p : x == y}\n {u : B x} {v : B y}\n (q : u == v [ B \u2193 p ])\n \u2192 ! (pair= p q) == pair= (! p) (!\u1d48 q)\n\u03a3-! {p = idp} idp = idp\n\n-- Implementation of [_\u2219'_] on \u00d7\n\u00d7-\u2219' : \u2200 {i j} {A : Type i} {B : Type j}\n {x y z : A} (p : x == y) (p' : y == z)\n {u v w : B} (q : u == v) (q' : v == w)\n \u2192 (pair\u00d7= p q \u2219' pair\u00d7= p' q') == pair\u00d7= (p \u2219' p') (q \u2219' q')\n\u00d7-\u2219' idp idp q idp = idp\n\n-- Implementation of [_\u2219_] on \u00d7\n\u00d7-\u2219 : \u2200 {i j} {A : Type i} {B : Type j}\n {x y z : A} (p : x == y) (p' : y == z)\n {u v w : B} (q : u == v) (q' : v == w)\n \u2192 (pair\u00d7= p q \u2219 pair\u00d7= p' q') == pair\u00d7= (p \u2219 p') (q \u2219 q')\n\u00d7-\u2219 idp idp idp r = idp\n\n-- Implementation of [!] on \u00d7\n\u00d7-! : \u2200 {i j} {A : Type i} {B : Type j}\n {x y : A} (p : x == y) {u v : B} (q : u == v)\n \u2192 ! (pair\u00d7= p q) == pair\u00d7= (! p) (! q)\n\u00d7-! idp idp = idp\n\n-- Special case of [ap-,]\nap-cst,id : \u2200 {i j} {A : Type i} (B : A \u2192 Type j)\n {a : A} {x y : B a} (p : x == y)\n \u2192 ap (\u03bb x \u2192 _,_ {B = B} a x) p == pair= idp p\nap-cst,id B idp = idp\n\n-- hfiber fst == B\nmodule _ {i j} {A : Type i} {B : A \u2192 Type j} where\n\n private\n to : \u2200 a \u2192 hfiber (fst :> (\u03a3 A B \u2192 A)) a \u2192 B a\n to a ((.a , b) , idp) = b\n\n from : \u2200 (a : A) \u2192 B a \u2192 hfiber (fst :> (\u03a3 A B \u2192 A)) a\n from a b = (a , b) , idp\n\n to-from : \u2200 (a : A) (b : B a) \u2192 to a (from a b) == b\n to-from a b = idp\n\n from-to : \u2200 a b\u2032 \u2192 from a (to a b\u2032) == b\u2032\n from-to a ((.a , b) , idp) = idp\n\n hfiber-fst : \u2200 a \u2192 hfiber (fst :> (\u03a3 A B \u2192 A)) a \u2243 B a\n hfiber-fst a = to a , is-eq (to a) (from a) (to-from a) (from-to a)\n\n{- Dependent paths in a \u03a3-type -}\nmodule _ {i j k} {A : Type i} {B : A \u2192 Type j} {C : (a : A) \u2192 B a \u2192 Type k}\n where\n\n \u2193-\u03a3-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x r} {s' : C x' r'}\n (q : r == r' [ B \u2193 p ])\n \u2192 s == s' [ uncurry C \u2193 pair= p q ]\n \u2192 (r , s) == (r' , s') [ (\u03bb x \u2192 \u03a3 (B x) (C x)) \u2193 p ]\n \u2193-\u03a3-in {p = idp} idp t = pair= idp t\n\n \u2193-\u03a3-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x r} {s' : C x' r'}\n \u2192 (r , s) == (r' , s') [ (\u03bb x \u2192 \u03a3 (B x) (C x)) \u2193 p ]\n \u2192 r == r' [ B \u2193 p ]\n \u2193-\u03a3-fst {p = idp} u = fst= u\n\n \u2193-\u03a3-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x r} {s' : C x' r'}\n \u2192 (u : (r , s) == (r' , s') [ (\u03bb x \u2192 \u03a3 (B x) (C x)) \u2193 p ])\n \u2192 s == s' [ uncurry C \u2193 pair= p (\u2193-\u03a3-fst u) ]\n \u2193-\u03a3-snd {p = idp} idp = idp\n\n \u2193-\u03a3-\u03b2-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x r} {s' : C x' r'}\n (q : r == r' [ B \u2193 p ])\n (t : s == s' [ uncurry C \u2193 pair= p q ])\n \u2192 \u2193-\u03a3-fst (\u2193-\u03a3-in q t) == q\n \u2193-\u03a3-\u03b2-fst {p = idp} idp idp = idp\n\n \u2193-\u03a3-\u03b2-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x r} {s' : C x' r'}\n (q : r == r' [ B \u2193 p ])\n (t : s == s' [ uncurry C \u2193 pair= p q ])\n \u2192 \u2193-\u03a3-snd (\u2193-\u03a3-in q t) == t\n [ (\u03bb q' \u2192 s == s' [ uncurry C \u2193 pair= p q' ]) \u2193 \u2193-\u03a3-\u03b2-fst q t ]\n \u2193-\u03a3-\u03b2-snd {p = idp} idp idp = idp\n\n \u2193-\u03a3-\u03b7 : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x r} {s' : C x' r'}\n (u : (r , s) == (r' , s') [ (\u03bb x \u2192 \u03a3 (B x) (C x)) \u2193 p ])\n \u2192 \u2193-\u03a3-in (\u2193-\u03a3-fst u) (\u2193-\u03a3-snd u) == u\n \u2193-\u03a3-\u03b7 {p = idp} idp = idp\n\n{- Dependent paths in a \u00d7-type -}\nmodule _ {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n where\n\n \u2193-\u00d7-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}\n {s : C x} {s' : C x'}\n \u2192 r == r' [ B \u2193 p ]\n \u2192 s == s' [ C \u2193 p ]\n \u2192 (r , s) == (r' , s') [ (\u03bb x \u2192 B x \u00d7 C x) \u2193 p ]\n \u2193-\u00d7-in {p = idp} q t = pair\u00d7= q t\n\n{- Dependent paths over a \u00d7-type -}\nmodule _ {i j k} {A : Type i} {B : Type j} (C : A \u2192 B \u2192 Type k)\n where\n\n \u2193-over-\u00d7-in : {x x' : A} {p : x == x'} {y y' : B} {q : y == y'}\n {u : C x y} {v : C x' y} {w : C x' y'}\n \u2192 u == v [ (\u03bb a \u2192 C a y) \u2193 p ]\n \u2192 v == w [ (\u03bb b \u2192 C x' b) \u2193 q ]\n \u2192 u == w [ uncurry C \u2193 pair\u00d7= p q ]\n \u2193-over-\u00d7-in {p = idp} {q = idp} idp idp = idp\n\n \u2193-over-\u00d7-in' : {x x' : A} {p : x == x'} {y y' : B} {q : y == y'}\n {u : C x y} {v : C x y'} {w : C x' y'}\n \u2192 u == v [ (\u03bb b \u2192 C x b) \u2193 q ]\n \u2192 v == w [ (\u03bb a \u2192 C a y') \u2193 p ]\n \u2192 u == w [ uncurry C \u2193 pair\u00d7= p q ]\n \u2193-over-\u00d7-in' {p = idp} {q = idp} idp idp = idp\n\nmodule _ where\n -- An orphan lemma.\n \u2193-cst\u00d7app-in : \u2200 {i j k} {A : Type i}\n {B : Type j} {C : A \u2192 B \u2192 Type k}\n {a\u2081 a\u2082 : A} (p : a\u2081 == a\u2082)\n {b\u2081 b\u2082 : B} (q : b\u2081 == b\u2082)\n {c\u2081 : C a\u2081 b\u2081}{c\u2082 : C a\u2082 b\u2082}\n \u2192 c\u2081 == c\u2082 [ uncurry C \u2193 pair\u00d7= p q ]\n \u2192 (b\u2081 , c\u2081) == (b\u2082 , c\u2082) [ (\u03bb x \u2192 \u03a3 B (C x)) \u2193 p ]\n \u2193-cst\u00d7app-in idp idp idp = idp\n\n{- pair= and pair\u00d7= where one argument is reflexivity -}\npair=-idp-l : \u2200 {i j} {A : Type i} {B : A \u2192 Type j} (a : A) {b\u2081 b\u2082 : B a}\n (q : b\u2081 == b\u2082) \u2192 pair= {B = B} idp q == ap (\u03bb y \u2192 (a , y)) q\npair=-idp-l _ idp = idp\n\npair\u00d7=-idp-l : \u2200 {i j} {A : Type i} {B : Type j} (a : A) {b\u2081 b\u2082 : B}\n (q : b\u2081 == b\u2082) \u2192 pair\u00d7= idp q == ap (\u03bb y \u2192 (a , y)) q\npair\u00d7=-idp-l _ idp = idp\n\npair\u00d7=-idp-r : \u2200 {i j} {A : Type i} {B : Type j} {a\u2081 a\u2082 : A} (p : a\u2081 == a\u2082)\n (b : B) \u2192 pair\u00d7= p idp == ap (\u03bb x \u2192 (x , b)) p\npair\u00d7=-idp-r idp _ = idp\n\npair\u00d7=-split-l : \u2200 {i j} {A : Type i} {B : Type j} {a\u2081 a\u2082 : A} (p : a\u2081 == a\u2082)\n {b\u2081 b\u2082 : B} (q : b\u2081 == b\u2082)\n \u2192 pair\u00d7= p q == ap (\u03bb a \u2192 (a , b\u2081)) p \u2219 ap (\u03bb b \u2192 (a\u2082 , b)) q\npair\u00d7=-split-l idp idp = idp\n\npair\u00d7=-split-r : \u2200 {i j} {A : Type i} {B : Type j} {a\u2081 a\u2082 : A} (p : a\u2081 == a\u2082)\n {b\u2081 b\u2082 : B} (q : b\u2081 == b\u2082)\n \u2192 pair\u00d7= p q == ap (\u03bb b \u2192 (a\u2081 , b)) q \u2219 ap (\u03bb a \u2192 (a , b\u2082)) p\npair\u00d7=-split-r idp idp = idp\n\n-- Commutativity of products and derivatives.\nmodule _ {i j} {A : Type i} {B : Type j} where\n \u00d7-comm : \u03a3 A (\u03bb _ \u2192 B) \u2243 \u03a3 B (\u03bb _ \u2192 A)\n \u00d7-comm = equiv (\u03bb {(a , b) \u2192 (b , a)}) (\u03bb {(b , a) \u2192 (a , b)}) (\u03bb _ \u2192 idp) (\u03bb _ \u2192 idp)\n\nmodule _ {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k} where\n \u03a3\u2082-\u00d7-comm : \u03a3 (\u03a3 A B) (\u03bb ab \u2192 C (fst ab)) \u2243 \u03a3 (\u03a3 A C) (\u03bb ac \u2192 B (fst ac))\n \u03a3\u2082-\u00d7-comm = \u03a3-assoc \u207b\u00b9 \u2218e \u03a3-emap-r (\u03bb a \u2192 \u00d7-comm) \u2218e \u03a3-assoc\n\nmodule _ {i j k} {A : Type i} {B : Type j} {C : A \u2192 B \u2192 Type k} where\n \u03a3\u2081-\u00d7-comm : \u03a3 A (\u03bb a \u2192 \u03a3 B (\u03bb b \u2192 C a b)) \u2243 \u03a3 B (\u03bb b \u2192 \u03a3 A (\u03bb a \u2192 C a b))\n \u03a3\u2081-\u00d7-comm = \u03a3-assoc \u2218e \u03a3-emap-l _ \u00d7-comm \u2218e \u03a3-assoc \u207b\u00b9\n","avg_line_length":34.730125523,"max_line_length":104,"alphanum_fraction":0.4013011264} {"size":65,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --without-K --safe #-}\n\nmodule Cham.Inference where\n\n","avg_line_length":13.0,"max_line_length":34,"alphanum_fraction":0.6615384615} {"size":504,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"{-# OPTIONS --prop #-}\n\nmodule Issue3526-2 where\n\nopen import Agda.Builtin.Equality\n\nrecord Truth (P : Prop) : Set where\n constructor [_]\n field\n truth : P\nopen Truth public\n\ndata \u22a5' : Prop where\n\n\u22a5 = Truth \u22a5'\n\n\u00ac : Set \u2192 Set\n\u00ac A = A \u2192 \u22a5\n\nunique : {A : Set} (x y : \u00ac A) \u2192 x \u2261 y\nunique x y = refl\n\n\u22a5-elim : (A : Set) \u2192 \u22a5 \u2192 A\n\u22a5-elim A b = {!!}\n\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.Unit\n\nset : Bool \u2192 Set\nset false = \u22a5\nset true = \u22a4\n\nset-elim : \u2200 b \u2192 set b \u2192 Set\nset-elim b x = {!!}\n\n","avg_line_length":14.0,"max_line_length":38,"alphanum_fraction":0.5753968254} {"size":852,"ext":"agda","lang":"Agda","max_stars_count":4.0,"content":"{-# OPTIONS --safe --warning=error --without-K #-}\n\nopen import Agda.Primitive using (Level; lzero; lsuc; _\u2294_)\nopen import LogicalFormulae\nopen import Sets.EquivalenceRelations\nopen import Setoids.Setoids\n\nmodule Setoids.Subset {a b : _} {A : Set a} (S : Setoid {a} {b} A) where\n\nopen Setoid S\nopen Equivalence eq\n\nsubset : {c : _} (pred : A \u2192 Set c) \u2192 Set (a \u2294 b \u2294 c)\nsubset pred = ({x y : A} \u2192 x \u223c y \u2192 pred x \u2192 pred y)\n\nsubsetSetoid : {c : _} {pred : A \u2192 Set c} \u2192 (subs : subset pred) \u2192 Setoid (Sg A pred)\nSetoid._\u223c_ (subsetSetoid subs) (x , predX) (y , predY) = Setoid._\u223c_ S x y\nEquivalence.reflexive (Setoid.eq (subsetSetoid subs)) {a , b} = reflexive\nEquivalence.symmetric (Setoid.eq (subsetSetoid subs)) {a , prA} {b , prB} x = symmetric x\nEquivalence.transitive (Setoid.eq (subsetSetoid subs)) {a , prA} {b , prB} {c , prC} x y = transitive x y\n","avg_line_length":40.5714285714,"max_line_length":105,"alphanum_fraction":0.6596244131} {"size":1468,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --safe --experimental-lossy-unification #-}\nmodule Cubical.Algebra.Polynomials.UnivariateList.Polyn-nPoly where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\n\nopen import Cubical.Data.Nat renaming (_+_ to _+n_; _\u00b7_ to _\u00b7n_)\nopen import Cubical.Data.Vec\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Algebra.Ring\nopen import Cubical.Algebra.CommRing\n\nopen import Cubical.Algebra.CommRing.Instances.Polynomials.UnivariatePolyList\nopen import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly\n\nopen import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly0-A\nopen import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[Am[X]]-Anm[X]\nopen import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.AB-An[X]Bn[X]\nopen import Cubical.Algebra.Polynomials.UnivariateList.Poly1-1Poly\n\nopen CommRingEquivs renaming (compCommRingEquiv to _\u2218-ecr_ ; invCommRingEquiv to inv-ecr)\n\nprivate variable\n \u2113 : Level\n\n\n-----------------------------------------------------------------------------\n-- Definition\n\nEquiv-Polyn-nPoly : (A' : CommRing \u2113) \u2192 (n : \u2115) \u2192 CommRingEquiv (PolyCommRing A' n) (nUnivariatePolyList A' n)\nEquiv-Polyn-nPoly A' zero = CRE-Poly0-A A'\nEquiv-Polyn-nPoly A' (suc n) = inv-ecr _ _ (CRE-PolyN\u2218M-PolyN+M A' 1 n)\n \u2218-ecr (lift-equiv-poly _ _ 1 (Equiv-Polyn-nPoly A' n)\n \u2218-ecr CRE-Poly1-Poly: (nUnivariatePolyList A' n))\n","avg_line_length":40.7777777778,"max_line_length":110,"alphanum_fraction":0.7098092643} {"size":4568,"ext":"agda","lang":"Agda","max_stars_count":1.0,"content":"{-# OPTIONS --safe #-}\n\nmodule Cubical.Data.FinSet.Properties where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Function\nopen import Cubical.Foundations.Structure\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.Equiv\n\nopen import Cubical.HITs.PropositionalTruncation\n\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Empty renaming (rec to EmptyRec)\nopen import Cubical.Data.Sigma\n\nopen import Cubical.Data.Fin\nopen import Cubical.Data.SumFin renaming (Fin to SumFin) hiding (discreteFin)\nopen import Cubical.Data.FinSet.Base\n\nopen import Cubical.Relation.Nullary\nopen import Cubical.Relation.Nullary.DecidableEq\nopen import Cubical.Relation.Nullary.HLevels\n\nprivate\n variable\n \u2113 \u2113' \u2113'' : Level\n A : Type \u2113\n B : Type \u2113'\n\n-- infix operator to more conveniently compose equivalences\n\n_\u22c6_ = compEquiv\n\ninfixr 30 _\u22c6_\n\n-- useful implications\n\nEquivPresIsFinSet : A \u2243 B \u2192 isFinSet A \u2192 isFinSet B\nEquivPresIsFinSet e = rec isPropIsFinSet (\u03bb (n , p) \u2192 \u2223 n , compEquiv (invEquiv e) p \u2223)\n\nisFinSetFin : {n : \u2115} \u2192 isFinSet (Fin n)\nisFinSetFin = \u2223 _ , pathToEquiv refl \u2223\n\nisFinSetUnit : isFinSet Unit\nisFinSetUnit = \u2223 1 , Unit\u2243Fin1 \u2223\n\nisFinSet\u2192Discrete : isFinSet A \u2192 Discrete A\nisFinSet\u2192Discrete = rec isPropDiscrete (\u03bb (_ , p) \u2192 EquivPresDiscrete (invEquiv p) discreteFin)\n\nisContr\u2192isFinSet : isContr A \u2192 isFinSet A\nisContr\u2192isFinSet h = \u2223 1 , isContr\u2192\u2243Unit* h \u22c6 invEquiv (Unit\u2243Unit* ) \u22c6 Unit\u2243Fin1 \u2223\n\nisDecProp\u2192isFinSet : isProp A \u2192 Dec A \u2192 isFinSet A\nisDecProp\u2192isFinSet h (yes p) = isContr\u2192isFinSet (inhProp\u2192isContr p h)\nisDecProp\u2192isFinSet h (no \u00acp) = \u2223 0 , uninhabEquiv \u00acp \u00acFin0 \u2223\n\n{-\n\nAlternative definition of finite sets\n\nA set is finite if it is merely equivalent to `Fin n` for some `n`. We\ncan translate this to code in two ways: a truncated sigma of a nat and\nan equivalence, or a sigma of a nat and a truncated equivalence. We\nprove that both formulations are equivalent.\n\n-}\n\nisFinSet' : Type \u2113 \u2192 Type \u2113\nisFinSet' A = \u03a3[ n \u2208 \u2115 ] \u2225 A \u2243 Fin n \u2225\n\nFinSet' : (\u2113 : Level) \u2192 Type (\u2113-suc \u2113)\nFinSet' \u2113 = TypeWithStr _ isFinSet'\n\nisPropIsFinSet' : isProp (isFinSet' A)\nisPropIsFinSet' {A = A} (n , equivn) (m , equivm) =\n \u03a3\u2261Prop (\u03bb _ \u2192 isPropPropTrunc) n\u2261m\n where\n Fin-n\u2243Fin-m : \u2225 Fin n \u2243 Fin m \u2225\n Fin-n\u2243Fin-m = rec\n isPropPropTrunc\n (rec\n (isProp\u03a0 \u03bb _ \u2192 isPropPropTrunc)\n (\u03bb hm hn \u2192 \u2223 Fin n \u2243\u27e8 invEquiv hn \u27e9 A \u2243\u27e8 hm \u27e9 Fin m \u25a0 \u2223)\n equivm\n )\n equivn\n\n Fin-n\u2261Fin-m : \u2225 Fin n \u2261 Fin m \u2225\n Fin-n\u2261Fin-m = rec isPropPropTrunc (\u2223_\u2223 \u2218 ua) Fin-n\u2243Fin-m\n\n \u2225n\u2261m\u2225 : \u2225 n \u2261 m \u2225\n \u2225n\u2261m\u2225 = rec isPropPropTrunc (\u2223_\u2223 \u2218 Fin-inj n m) Fin-n\u2261Fin-m\n\n n\u2261m : n \u2261 m\n n\u2261m = rec (isSet\u2115 n m) (\u03bb p \u2192 p) \u2225n\u2261m\u2225\n\n-- logical equivalence of two definitions\n\nisFinSet\u2192isFinSet' : isFinSet A \u2192 isFinSet' A\nisFinSet\u2192isFinSet' \u2223 n , equiv \u2223 = n , \u2223 equiv \u2223\nisFinSet\u2192isFinSet' (squash p q i) = isPropIsFinSet' (isFinSet\u2192isFinSet' p) (isFinSet\u2192isFinSet' q) i\n\nisFinSet'\u2192isFinSet : isFinSet' A \u2192 isFinSet A\nisFinSet'\u2192isFinSet (n , \u2223 isFinSet-A \u2223) = \u2223 n , isFinSet-A \u2223\nisFinSet'\u2192isFinSet (n , squash p q i) = isPropIsFinSet (isFinSet'\u2192isFinSet (n , p)) (isFinSet'\u2192isFinSet (n , q)) i\n\nisFinSet\u2261isFinSet' : isFinSet A \u2261 isFinSet' A\nisFinSet\u2261isFinSet' {A = A} = hPropExt isPropIsFinSet isPropIsFinSet' isFinSet\u2192isFinSet' isFinSet'\u2192isFinSet\n\nFinSet\u2192FinSet' : FinSet \u2113 \u2192 FinSet' \u2113\nFinSet\u2192FinSet' (A , isFinSetA) = A , isFinSet\u2192isFinSet' isFinSetA\n\nFinSet'\u2192FinSet : FinSet' \u2113 \u2192 FinSet \u2113\nFinSet'\u2192FinSet (A , isFinSet'A) = A , isFinSet'\u2192isFinSet isFinSet'A\n\nFinSet\u2243FinSet' : FinSet \u2113 \u2243 FinSet' \u2113\nFinSet\u2243FinSet' =\n isoToEquiv\n (iso FinSet\u2192FinSet' FinSet'\u2192FinSet\n (\u03bb _ \u2192 \u03a3\u2261Prop (\u03bb _ \u2192 isPropIsFinSet') refl)\n (\u03bb _ \u2192 \u03a3\u2261Prop (\u03bb _ \u2192 isPropIsFinSet) refl))\n\nFinSet\u2261FinSet' : FinSet \u2113 \u2261 FinSet' \u2113\nFinSet\u2261FinSet' = ua FinSet\u2243FinSet'\n\n-- cardinality of finite sets\n\ncard : FinSet \u2113 \u2192 \u2115\ncard = fst \u2218 snd \u2218 FinSet\u2192FinSet'\n\n-- definitions to reduce problems about FinSet to SumFin\n\n\u2243Fin : Type \u2113 \u2192 Type \u2113\n\u2243Fin A = \u03a3[ n \u2208 \u2115 ] A \u2243 Fin n\n\n\u2243SumFin : Type \u2113 \u2192 Type \u2113\n\u2243SumFin A = \u03a3[ n \u2208 \u2115 ] A \u2243 SumFin n\n\n\u2243Fin\u2192SumFin : \u2243Fin A \u2192 \u2243SumFin A\n\u2243Fin\u2192SumFin (n , e) = n , compEquiv e (invEquiv (SumFin\u2243Fin _))\n\n\u2243SumFin\u2192Fin : \u2243SumFin A \u2192 \u2243Fin A\n\u2243SumFin\u2192Fin (n , e) = n , compEquiv e (SumFin\u2243Fin _)\n\ntranspFamily :\n {A : Type \u2113}{B : A \u2192 Type \u2113'}\n \u2192 ((n , e) : \u2243SumFin A) \u2192 (x : A) \u2192 B x \u2243 B (invEq e (e .fst x))\ntranspFamily {B = B} (n , e) x = pathToEquiv (\u03bb i \u2192 B (retEq e x (~ i)))\n","avg_line_length":29.8562091503,"max_line_length":114,"alphanum_fraction":0.6762259194} {"size":2681,"ext":"agda","lang":"Agda","max_stars_count":30.0,"content":"module Generic.Property.Eq where\n\nopen import Generic.Core\n\nSemEq : \u2200 {i \u03b2} {I : Set i} -> Desc I \u03b2 -> Set\nSemEq (var i) = \u22a4\nSemEq (\u03c0 i q C) = \u22a5\nSemEq (D \u229b E) = SemEq D \u00d7 SemEq E\n\nmutual\n ExtendEq : \u2200 {i \u03b2} {I : Set i} -> Desc I \u03b2 -> Set \u03b2\n ExtendEq (var i) = \u22a4\n ExtendEq (\u03c0 i q C) = ExtendEq\u1d47 i C q\n ExtendEq (D \u229b E) = SemEq D \u00d7 ExtendEq E\n\n ExtendEq\u1d47 : \u2200 {\u03b9 \u03b1 \u03b2 \u03b3 q} {I : Set \u03b9} i -> Binder \u03b1 \u03b2 \u03b3 i q I -> \u03b1 \u2264\u2113 \u03b2 -> Set \u03b2\n ExtendEq\u1d47 (arg-info v r) (coerce (A , D)) q = Coerce\u2032 q $ RelEq r A \u00d7 \u2200 {x} -> ExtendEq (D x)\n\ninstance\n {-# TERMINATING #-} -- Why?\n DataEq : \u2200 {i \u03b2} {I : Set i} {D : Data (Desc I \u03b2)} {j}\n {{eqD : All ExtendEq (consTypes D)}} -> Eq (\u03bc D j)\n DataEq {\u03b9} {\u03b2} {I} {D\u2080} = record { _\u225f_ = decMu } where\n mutual\n decSem : \u2200 D {{eqD : SemEq D}} -> IsSet (\u27e6 D \u27e7 (\u03bc D\u2080))\n decSem (var i) d\u2081 d\u2082 = decMu d\u2081 d\u2082\n decSem (\u03c0 i q C) {{()}}\n decSem (D \u229b E) {{eqD , eqE}} p\u2081 p\u2082 =\n decProd (decSem D {{eqD}}) (decSem E {{eqE}}) p\u2081 p\u2082\n\n decExtend : \u2200 {j} D {{eqD : ExtendEq D}} -> IsSet (Extend D (\u03bc D\u2080) j)\n decExtend (var i) lrefl lrefl = yes refl\n decExtend (\u03c0 i q C) p\u2081 p\u2082 = decExtend\u1d47 i C q p\u2081 p\u2082\n decExtend (D \u229b E) {{eqD , eqE}} p\u2081 p\u2082 =\n decProd (decSem D {{eqD}}) (decExtend E {{eqE}}) p\u2081 p\u2082\n\n decExtend\u1d47 : \u2200 {\u03b1 \u03b3 q j} i (C : Binder \u03b1 \u03b2 \u03b3 i q I) q {{eqC : ExtendEq\u1d47 i C q}}\n -> IsSet (Extend\u1d47 i C q (\u03bc D\u2080) j)\n decExtend\u1d47 (arg-info v r) (coerce (A , D)) q {{eqC}} p\u2081 p\u2082 =\n split q eqC \u03bb eqA eqD ->\n decCoerce\u2032 q (decProd (_\u225f_ {{EqRelValue {{eqA}}}}) (decExtend (D _) {{eqD}})) p\u2081 p\u2082\n\n decAny : \u2200 {j} (Ds : List (Desc I \u03b2)) {{eqD : All ExtendEq Ds}}\n -> \u2200 d a b ns -> IsSet (Node D\u2080 (packData d a b Ds ns) j)\n decAny [] d a b tt () ()\n decAny (D \u2237 []) {{eqD , _}} d a b (_ , ns) e\u2081 e\u2082 = decExtend D {{eqD}} e\u2081 e\u2082\n decAny (D \u2237 E \u2237 Ds) {{eqD , eqDs}} d a b (_ , ns) s\u2081 s\u2082 =\n decSum (decExtend D {{eqD}}) (decAny (E \u2237 Ds) {{eqDs}} d a b ns) s\u2081 s\u2082\n\n decMu : \u2200 {j} -> IsSet (\u03bc D\u2080 j)\n decMu (node e\u2081) (node e\u2082) = dcong node node-inj $ decAny (consTypes D\u2080)\n (dataName D\u2080)\n (parsTele D\u2080)\n (indsTele D\u2080)\n (consNames D\u2080)\n e\u2081\n e\u2082\n","avg_line_length":46.224137931,"max_line_length":95,"alphanum_fraction":0.4192465498} {"size":444,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"\nmodule Agda.Builtin.String where\n\nopen import Agda.Builtin.Bool\nopen import Agda.Builtin.List\nopen import Agda.Builtin.Char\n\npostulate String : Set\n{-# BUILTIN STRING String #-}\n\nprimitive\n primStringToList : String \u2192 List Char\n primStringFromList : List Char \u2192 String\n primStringAppend : String \u2192 String \u2192 String\n primStringEquality : String \u2192 String \u2192 Bool\n primShowChar : Char \u2192 String\n primShowString : String \u2192 String\n","avg_line_length":24.6666666667,"max_line_length":47,"alphanum_fraction":0.7364864865} {"size":1296,"ext":"agda","lang":"Agda","max_stars_count":6.0,"content":"open import Type\n\nmodule Graph.Properties.Proofs where\n\nopen import Data.Either.Proofs\nopen import Functional\nopen import Function.Equals\nopen import Lang.Instance\nopen import Logic\nopen import Logic.Propositional\nopen import Logic.Propositional.Theorems\nimport Lvl\nopen import Graph\nopen import Graph.Properties\nopen import Relator.Equals.Proofs.Equiv\nopen import Structure.Setoid.Uniqueness\nopen import Structure.Relator.Properties\nopen import Type.Properties.Singleton\n\nmodule _ {\u2113\u2081 \u2113\u2082} {V : Type{\u2113\u2081}} (_\u27f6_ : Graph{\u2113\u2081}{\u2113\u2082}(V)) where\n instance\n undirect-undirected : Undirected(undirect(_\u27f6_))\n Undirected.reversable undirect-undirected = intro [\u2228]-symmetry\n Undirected.reverse-involution undirect-undirected = intro (_\u229c_.proof swap-involution)\n\n -- [++]-visits : \u2200{ae be a\u2081 b\u2081 a\u2082 b\u2082}{e : ae \u27f6 be}{w\u2081 : Walk(_\u27f6_) a\u2081 b\u2081}{w\u2082 : Walk(_\u27f6_) a\u2082 b\u2082} \u2192 (Visits(_\u27f6_) e w\u2081) \u2228 (Visits(_\u27f6_) e w\u2082) \u2192 Visits(_\u27f6_) e (w\u2081 ++ w\u2082)\n\n complete-singular-is-undirected : \u2983 CompleteWithLoops(_\u27f6_) \u2984 \u2192 \u2983 Singular(_\u27f6_) \u2984 \u2192 Undirected(_\u27f6_)\n Undirected.reversable complete-singular-is-undirected = intro(const (completeWithLoops(_\u27f6_)))\n Undirected.reverse-involution complete-singular-is-undirected = intro(singular(_\u27f6_))\n\n -- traceable-is-connected : \u2983 Traceable(_\u27f6_) \u2984 \u2192 Connected(_\u27f6_)\n","avg_line_length":39.2727272727,"max_line_length":165,"alphanum_fraction":0.7307098765} {"size":551,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module AocIO where\nopen import IO.Primitive public\nopen import Data.String as String\nopen import Data.List as List\n\npostulate\n getLine : IO Costring\n getArgs : IO (List String)\n getProgName : IO String\n\n{-# COMPILE GHC getLine = getLine #-}\n{-# FOREIGN GHC import qualified Data.Text as Text #-}\n{-# FOREIGN GHC import qualified Data.Text.IO as Text #-}\n{-# FOREIGN GHC import System.Environment (getArgs, getProgName) #-}\n{-# COMPILE GHC getArgs = fmap (map Text.pack) getArgs #-}\n{-# COMPILE GHC getProgName = fmap Text.pack getProgName #-}\n","avg_line_length":32.4117647059,"max_line_length":68,"alphanum_fraction":0.720508167} {"size":1199,"ext":"agda","lang":"Agda","max_stars_count":301.0,"content":"{-\n\nDefinition of finitely indexed types\n\nA type is finitely indexed if, for some `n`, there merely exists a\nsurjective function from `Fin n` to it. Note that a type doesn't need\nto be a set in order for it to be finitely indexed. For example, the\ncircle is finitely indexed.\n\nThis definition is weaker than `isFinSet`.\n\n-}\n\n{-# OPTIONS --safe #-}\n\nmodule Cubical.Data.FinInd where\n\nopen import Cubical.Data.Nat\nopen import Cubical.Data.Fin\nopen import Cubical.Data.Sigma\nopen import Cubical.Data.FinSet\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Functions.Surjection\nopen import Cubical.HITs.PropositionalTruncation as PT\nopen import Cubical.HITs.S1\n\nprivate\n variable\n \u2113 : Level\n A : Type \u2113\n\nisFinInd : Type \u2113 \u2192 Type \u2113\nisFinInd A = \u2203[ n \u2208 \u2115 ] Fin n \u21a0 A\n\nisFinSet\u2192isFinInd : isFinSet A \u2192 isFinInd A\nisFinSet\u2192isFinInd = PT.rec\n squash\n \u03bb (n , equiv) \u2192\n \u2223 n , invEq equiv , section\u2192isSurjection (retEq equiv) \u2223\n\nisFinInd-S\u00b9 : isFinInd S\u00b9\nisFinInd-S\u00b9 = \u2223 1 , f , isSurjection-f \u2223\n where\n f : Fin 1 \u2192 S\u00b9\n f _ = base\n isSurjection-f : isSurjection f\n isSurjection-f b = PT.map (\u03bb base\u2261b \u2192 fzero , base\u2261b) (isConnectedS\u00b9 b)\n","avg_line_length":24.4693877551,"max_line_length":75,"alphanum_fraction":0.7222685571} {"size":505,"ext":"agda","lang":"Agda","max_stars_count":5.0,"content":"------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Floating point numbers\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Float where\n\n------------------------------------------------------------------------\n-- Re-export base definitions and decidability of equality\n\nopen import Data.Float.Base public\nopen import Data.Float.Properties using (_\u2248?_; __ (PushoutDiag f g) {fsuc fzero} {fzero} tt (lift a) = lift (f a)\n _<$>_ (PushoutDiag f g) {fsuc fzero} {fsuc (fsuc fzero)} tt (lift a) = lift (g a)\n\nmodule _ {\u2113 \u2113' \u2113''} {A : Type \u2113} {B : Type \u2113'} {C : Type \u2113''} {f : A \u2192 B} {g : A \u2192 C} where\n\n PushoutCocone : Cocone _ (PushoutDiag f g) (Pushout f g)\n leg PushoutCocone fzero (lift b) = inl b\n leg PushoutCocone (fsuc fzero) (lift a) = inr (g a)\n leg PushoutCocone (fsuc (fsuc fzero)) (lift c) = inr c\n com PushoutCocone {fsuc fzero} {fzero} tt i (lift a) = push a i\n com PushoutCocone {fsuc fzero} {fsuc (fsuc fzero)} tt i (lift a) = inr (g a)\n\n private\n module _ \u2113q (Y : Type \u2113q) where\n\n fwd : (Pushout f g \u2192 Y) \u2192 Cocone \u2113q (PushoutDiag f g) Y\n fwd = postcomp PushoutCocone\n\n module _ (C : Cocone \u2113q (PushoutDiag f g) Y) where\n coml : \u2200 a \u2192 leg C fzero (lift (f a)) \u2261 leg C (fsuc fzero) (lift a)\n comr : \u2200 a \u2192 leg C (fsuc (fsuc fzero)) (lift (g a)) \u2261 leg C (fsuc fzero) (lift a)\n coml a i = com C {j = fsuc fzero} {k = fzero} tt i (lift a)\n comr a i = com C {j = fsuc fzero} {k = fsuc (fsuc fzero)} tt i (lift a)\n\n bwd : Cocone \u2113q (PushoutDiag f g) Y \u2192 (Pushout f g \u2192 Y)\n bwd C (inl b) = leg C fzero (lift b)\n bwd C (inr c) = leg C (fsuc (fsuc fzero)) (lift c)\n bwd C (push a i) = (coml C a \u2219 sym (comr C a)) i\n\n bwd-fwd : \u2200 F \u2192 bwd (fwd F) \u2261 F\n bwd-fwd F i (inl b) = F (inl b)\n bwd-fwd F i (inr c) = F (inr c)\n bwd-fwd F i (push a j) = compPath-filler (coml (fwd F) a) (sym (comr (fwd F) a)) (~ i) j\n\n fwd-bwd : \u2200 C \u2192 fwd (bwd C) \u2261 C\n leg (fwd-bwd C i) fzero (lift b) = leg C fzero (lift b)\n leg (fwd-bwd C i) (fsuc fzero) (lift a) = comr C a i\n leg (fwd-bwd C i) (fsuc (fsuc fzero)) (lift c) = leg C (fsuc (fsuc fzero)) (lift c)\n com (fwd-bwd C i) {fsuc fzero} {fzero} tt j (lift a) -- coml (fwd-bwd C i) = ...\n = compPath-filler (coml C a) (sym (comr C a)) (~ i) j\n com (fwd-bwd C i) {fsuc fzero} {fsuc (fsuc fzero)} tt j (lift a) -- comr (fwd-bwd C i) = ...\n = comr C a (i \u2227 j)\n\n eqv : isEquiv {A = (Pushout f g \u2192 Y)} {B = Cocone \u2113q (PushoutDiag f g) Y} (postcomp PushoutCocone)\n eqv = isoToIsEquiv (iso fwd bwd fwd-bwd bwd-fwd)\n\n isColimPushout : isColimit (PushoutDiag f g) (Pushout f g)\n cone isColimPushout = PushoutCocone\n univ isColimPushout = eqv\n\n colim\u2243Pushout : colim (PushoutDiag f g) \u2243 Pushout f g\n colim\u2243Pushout = uniqColimit colimIsColimit isColimPushout\n\n","avg_line_length":43.4871794872,"max_line_length":104,"alphanum_fraction":0.5766509434} {"size":2559,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"\nmodule Path where\n\nopen import Basics hiding (_==_)\nopen import Proc\nimport Graph\n\nprivate open module G = Graph Nat\n\ndata Node : Set where\n node : Nat -> Node\n stop : Node\n\n_==_ : Node -> Node -> Bool\nstop == stop = true\nnode zero == node zero = true\nnode (suc n) == node (suc m) = node n == node m\n_ == _ = false\n\ndata U : Set where\n int : U\n ext : U\n\ndata Name : Set where\n fwd-edge : Nat -> Nat -> Name\n bwd-edge : Nat -> Node -> Name\n start : Nat -> Name\n finish : Nat -> Name\n\nN : U -> Set\nN int = Name\nN ext = False\n\ndata Msg : Set where\n forward : Node -> Node -> Msg\n backward : Node -> Msg\n\nT : U -> Set\nT int = Msg\nT ext = Node\n\nprivate\n module Impl where\n private module P = ProcDef U T N\n open P hiding (_!_)\n\n P = Proc int\n\n infixr 40 _!_\n _!_ : Msg -> P -> P\n m ! p = P._!_ (lift m) p\n\n fwd : Nat -> Nat -> Msg\n fwd from to = forward (node from) (node to)\n\n fwd-runner : Nat -> Nat -> P\n fwd-runner from to = > react\n where\n react : Msg -> P\n react (forward from' to') =\n if to' == node from\n then fwd from to ! def (bwd-edge from from')\n else def (fwd-edge from to)\n react (backward _) = o\n\n bwd-runner : Nat -> Node -> P\n bwd-runner from w = > react\n where\n react : Msg -> P\n react (backward n) =\n if n == w then o\n else if n == node from\n then backward w ! o\n else def (bwd-edge from w)\n react (forward _ _) = def (bwd-edge from w)\n\n pitcher : Nat -> P\n pitcher n = forward stop (node n) ! o\n\n batter : Nat -> P\n batter n = > react\n where\n react : Msg -> P\n react (forward from to) =\n if to == node n\n then backward from ! o\n else def (start n)\n react _ = def (start n)\n\n env : Env\n env int (fwd-edge from to) = fwd-runner from to\n env int (bwd-edge from w) = bwd-runner from w\n env int (start n) = batter n\n env int (finish n) = pitcher n\n env ext ()\n\n edges : Graph -> P\n edges [] = o\n edges (edge x y :: G) = def (fwd-edge x y) || edges G\n\n \u03c6 : Tran ext int\n \u03c6 = record { upV = up; downV = down }\n where\n down : Node -> Lift Msg\n down x = lift (backward x)\n\n up : Msg -> Lift Node\n up (forward _ _) = bot\n up (backward x) = lift x\n\n main : Graph -> Nat -> Nat -> Proc ext\n main G x y = \u03c6 \/| def (finish y) || def (start x) || edges G\n\nopen Impl public\n\nparam : Param\nparam = record\n { U = U\n ; T = T\n ; Name = N\n ; env = env\n }\n","avg_line_length":20.8048780488,"max_line_length":62,"alphanum_fraction":0.5279406018} {"size":489,"ext":"agda","lang":"Agda","max_stars_count":1.0,"content":"-- Andreas, 2018-05-28, issue #3095, fail on attempt to make hidden parent variable visible\n\ndata Nat : Set where\n suc : {n : Nat} \u2192 Nat\n\ndata IsSuc : Nat \u2192 Set where\n isSuc : \u2200{n} \u2192 IsSuc (suc {n})\n\ntest : \u2200{m} \u2192 IsSuc m \u2192 Set\ntest p = aux p\n where\n aux : \u2200{n} \u2192 IsSuc n \u2192 Set\n aux isSuc = {!.m!} -- Split on .m here\n\n-- Context:\n-- p : IsSuc .m\n-- .m : Nat\n-- .n : Nat\n\n-- Expected error:\n-- Cannot split on module parameter .m\n-- when checking that the expression ? has type Set\n","avg_line_length":21.2608695652,"max_line_length":91,"alphanum_fraction":0.6032719836} {"size":1159,"ext":"agda","lang":"Agda","max_stars_count":5.0,"content":"{-# OPTIONS --without-K --safe #-}\nmodule Categories.Category.Instance.StrictGroupoids where\n\n-- The 'strict' category of groupoids.\n-- The difference here is that _\u2248_ is not |NaturalIsomorphism| but |_\u2261F_|\n\nopen import Level\nopen import Relation.Binary.PropositionalEquality using (refl)\n\nopen import Categories.Category using (Category)\nopen import Categories.Category.Groupoid using (Groupoid)\nopen import Categories.Category.Instance.Groupoids using (F-resp-\u207b\u00b9)\nopen import Categories.Functor using (Functor; id; _\u2218F_)\nopen import Categories.Functor.Equivalence\n\nprivate\n variable\n o \u2113 e : Level\n\nopen Groupoid using (category)\n\nGroupoids : \u2200 o \u2113 e \u2192 Category (suc (o \u2294 \u2113 \u2294 e)) (o \u2294 \u2113 \u2294 e) (o \u2294 \u2113 \u2294 e)\nGroupoids o \u2113 e = record\n { Obj = Groupoid o \u2113 e\n ; _\u21d2_ = \u03bb G H \u2192 Functor (category G) (category H)\n ; _\u2248_ = _\u2261F_\n ; id = id\n ; _\u2218_ = _\u2218F_\n ; assoc = \u03bb {_ _ _ _ F G H} \u2192 \u2261F-assoc {F = F} {G} {H}\n ; sym-assoc = \u03bb {_ _ _ _ F G H} \u2192 \u2261F-sym-assoc {F = F} {G} {H}\n ; identity\u02e1 = \u2261F-identity\u02e1\n ; identity\u02b3 = \u2261F-identity\u02b3\n ; identity\u00b2 = \u2261F-identity\u00b2\n ; equiv = \u2261F-equiv\n ; \u2218-resp-\u2248 = \u2218F-resp-\u2261F\n }\n","avg_line_length":31.3243243243,"max_line_length":73,"alphanum_fraction":0.6350301984} {"size":2515,"ext":"agda","lang":"Agda","max_stars_count":2.0,"content":"module LC.Reduction where \n\n\nopen import LC.Base \nopen import LC.Subst \n\nopen import Data.Nat\nopen import Data.Nat.Properties\nopen import Relation.Nullary\n\n-- \u03b2-reduction\ninfix 3 _\u03b2\u2192_\ndata _\u03b2\u2192_ : Term \u2192 Term \u2192 Set where \n\n \u03b2-\u019b-\u2219 : \u2200 {M N} \u2192 ((\u019b M) \u2219 N) \u03b2\u2192 (M [ N ])\n\n \u03b2-\u019b : \u2200 {M N} \u2192 M \u03b2\u2192 N \u2192 \u019b M \u03b2\u2192 \u019b N\n\n \u03b2-\u2219-l : \u2200 {L M N} \u2192 M \u03b2\u2192 N \u2192 M \u2219 L \u03b2\u2192 N \u2219 L\n\n \u03b2-\u2219-r : \u2200 {L M N} \u2192 M \u03b2\u2192 N \u2192 L \u2219 M \u03b2\u2192 L \u2219 N\n\nopen import Relation.Binary.Construct.Closure.ReflexiveTransitive \n\ninfix 2 _\u03b2\u2192*_ \n_\u03b2\u2192*_ : Term \u2192 Term \u2192 Set\n_\u03b2\u2192*_ = Star _\u03b2\u2192_\n{-# DISPLAY Star _\u03b2\u2192_ = _\u03b2\u2192*_ #-}\n\nopen import Relation.Binary.PropositionalEquality hiding ([_]; preorder)\n\n\u2261\u21d2\u03b2\u2192* : \u2200 {M N} \u2192 M \u2261 N \u2192 M \u03b2\u2192* N\n\u2261\u21d2\u03b2\u2192* refl = \u03b5\n\ncong-var : \u2200 {x y} \u2192 x \u2261 y \u2192 var x \u03b2\u2192* var y\ncong-var {x} {y} refl = \u03b5\n\ncong-\u019b : {M N : Term} \u2192 M \u03b2\u2192* N \u2192 \u019b M \u03b2\u2192* \u019b N\ncong-\u019b = gmap _ \u03b2-\u019b\n\ncong-\u2219-l : {L M N : Term} \u2192 M \u03b2\u2192* N \u2192 M \u2219 L \u03b2\u2192* N \u2219 L\ncong-\u2219-l = gmap _ \u03b2-\u2219-l\n\ncong-\u2219-r : {L M N : Term} \u2192 M \u03b2\u2192* N \u2192 L \u2219 M \u03b2\u2192* L \u2219 N\ncong-\u2219-r = gmap _ \u03b2-\u2219-r \n\ncong-\u2219 : {M M' N N' : Term} \u2192 M \u03b2\u2192* M' \u2192 N \u03b2\u2192* N' \u2192 M \u2219 N \u03b2\u2192* M' \u2219 N'\ncong-\u2219 M\u2192M' N\u2192N' = (cong-\u2219-l M\u2192M') \u25c5\u25c5 (cong-\u2219-r N\u2192N')\n\n\nopen import LC.Subst.Term\n\ncong-lift : {n i : \u2115} {M N : Term} \u2192 M \u03b2\u2192 N \u2192 lift n i M \u03b2\u2192* lift n i N\ncong-lift (\u03b2-\u019b M\u2192N) = cong-\u019b (cong-lift M\u2192N)\ncong-lift (\u03b2-\u019b-\u2219 {M} {N}) = \u03b2-\u019b-\u2219 \u25c5 \u2261\u21d2\u03b2\u2192* (lemma M N)\ncong-lift (\u03b2-\u2219-l M\u2192N) = cong-\u2219-l (cong-lift M\u2192N)\ncong-lift (\u03b2-\u2219-r M\u2192N) = cong-\u2219-r (cong-lift M\u2192N)\n\ncong-[]-r : \u2200 L {M N i} \u2192 M \u03b2\u2192 N \u2192 L [ M \/ i ] \u03b2\u2192* L [ N \/ i ]\ncong-[]-r (var x) {M} {N} {i} M\u2192N with match x i \n... | Under _ = \u03b5\n... | Exact _ = cong-lift M\u2192N\n... | Above _ _ = \u03b5\ncong-[]-r (\u019b L) M\u2192N = cong-\u019b (cong-[]-r L M\u2192N)\ncong-[]-r (K \u2219 L) M\u2192N = cong-\u2219 (cong-[]-r K M\u2192N) (cong-[]-r L M\u2192N)\n\n\ncong-[]-l : \u2200 {M N L i} \u2192 M \u03b2\u2192 N \u2192 M [ L \/ i ] \u03b2\u2192* N [ L \/ i ]\ncong-[]-l {\u019b M} (\u03b2-\u019b M\u2192N) = cong-\u019b (cong-[]-l M\u2192N)\ncong-[]-l {.(\u019b K) \u2219 M} {L = L} (\u03b2-\u019b-\u2219 {K}) = \u03b2-\u019b-\u2219 \u25c5 \u2261\u21d2\u03b2\u2192* (subst-lemma K M L)\ncong-[]-l {K \u2219 M} (\u03b2-\u2219-l M\u2192N) = cong-\u2219-l (cong-[]-l M\u2192N)\ncong-[]-l {K \u2219 M} (\u03b2-\u2219-r M\u2192N) = cong-\u2219-r (cong-[]-l M\u2192N)\n\n\ncong-[] : {M M' N N' : Term} \u2192 M \u03b2\u2192* M' \u2192 N \u03b2\u2192* N' \u2192 M [ N ] \u03b2\u2192* M' [ N' ]\ncong-[] {M} \u03b5 \u03b5 = \u03b5\ncong-[] {M} {N = L} {N'} \u03b5 (_\u25c5_ {j = N} L\u2192N N\u2192N') = M[L]\u2192M[N] \u25c5\u25c5 M[N]\u2192M[N']\n where \n M[L]\u2192M[N] : M [ L ] \u03b2\u2192* M [ N ]\n M[L]\u2192M[N] = cong-[]-r M L\u2192N\n\n M[N]\u2192M[N'] : M [ N ] \u03b2\u2192* M [ N' ]\n M[N]\u2192M[N'] = cong-[] {M} \u03b5 N\u2192N'\ncong-[] {M} (K\u2192M \u25c5 M\u2192M') N\u2192N' = cong-[]-l K\u2192M \u25c5\u25c5 cong-[] M\u2192M' N\u2192N'\n","avg_line_length":29.5882352941,"max_line_length":79,"alphanum_fraction":0.4381709742} {"size":634,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"module Issue734a where\n\nmodule M\u2081 (Z : Set\u2081) where\n\n postulate\n P : Set\n Q : Set \u2192 Set\n\nmodule M\u2082 (X Y : Set) where\n\n module M\u2081\u2032 = M\u2081 Set\n open M\u2081\u2032\n\n p : P\n p = {!!}\n\n -- Previous and current agda2-goal-and-context:\n\n -- Y : Set\n -- X : Set\n -- ---------\n -- Goal: P\n\n q : Q X\n q = {!!}\n\n -- Previous and current agda2-goal-and-context:\n\n -- Y : Set\n -- X : Set\n -- -----------\n -- Goal: Q X\n\npostulate X : Set\n\npp : M\u2082.M\u2081\u2032.P X X\npp = {!!}\n\n -- Previous agda2-goal-and-context:\n\n -- ----------------\n -- Goal: M\u2081.P Set\n\n -- Current agda2-goal-and-context:\n\n -- --------------------\n -- Goal: M\u2082.M\u2081\u2032.P X X\n","avg_line_length":13.2083333333,"max_line_length":49,"alphanum_fraction":0.4747634069} {"size":217,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"module Issue564 where\n\nopen import Agda.Primitive using (Level) renaming (lzero to zero)\n\npostulate\n A : Level \u2192 Set\n\nmodule M \u2113 where\n postulate a : A \u2113\n\npostulate\n P : A zero \u2192 Set\n\nopen M zero\n\np : P a\np = {!!}\n","avg_line_length":12.0555555556,"max_line_length":65,"alphanum_fraction":0.668202765} {"size":349,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"\nopen import Agda.Builtin.Nat\n\n-- splitting on a 'with' argument should not expand the ellipsis\nfoo : Nat \u2192 Nat\nfoo m with 0\n... | n = {!n!}\n\n-- splitting on variable hidden by ellipsis should expand the ellipsis\nbar : Nat \u2192 Nat\nbar m with 0\n... | n = {!m!}\n\n-- test case with nested with\nbaz : Nat \u2192 Nat\nbaz m with m\n... | n with n\n... | p = {!p!}\n","avg_line_length":18.3684210526,"max_line_length":70,"alphanum_fraction":0.6303724928} {"size":239,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --without-K #-}\nopen import HoTT.Base\nopen import HoTT.Equivalence\n\nmodule HoTT.Equivalence.Empty where\n\nopen variables\n\n\ud835\udfce-equiv : {A : \ud835\udcb0 i} \u2192 \u00ac A \u2192 \ud835\udfce {i} \u2243 A\n\ud835\udfce-equiv \u00aca = \ud835\udfce-rec , qinv\u2192isequiv (\ud835\udfce-rec \u2218 \u00aca , \ud835\udfce-ind , \ud835\udfce-rec \u2218 \u00aca)\n","avg_line_length":21.7272727273,"max_line_length":67,"alphanum_fraction":0.6317991632} {"size":2266,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module MLib.Algebra.PropertyCode where\n\nopen import MLib.Prelude\nopen import MLib.Finite\n\nopen import MLib.Algebra.PropertyCode.RawStruct public\nopen import MLib.Algebra.PropertyCode.Core as Core public\n using (Property; Properties; Code; IsSubcode; _\u2208\u209a_; _\u21d2\u209a_; \u27e6_\u27e7P)\n renaming (\u21d2\u209a-weaken to weaken)\n\nopen Core.PropKind public\nopen Core.PropertyC using (_on_; _is_for_; _\u27e8_\u27e9\u209a_) public\n\nimport Relation.Unary as U using (Decidable)\nopen import Relation.Binary as B using (Setoid)\n\nopen import Data.List.All as All using (All; _\u2237_; []) public\nopen import Data.List.Any using (Any; here; there)\nopen import Data.Bool using (_\u2228_)\n\nopen import Category.Applicative\n\nrecord Struct {k} (code : Code k) c \u2113 : Set (suc\u02e1 (c \u2294\u02e1 \u2113 \u2294\u02e1 k)) where\n open Code code public\n\n field\n rawStruct : RawStruct K c \u2113\n \u03a0 : Properties code\n\n open RawStruct rawStruct public\n\n open Properties \u03a0 public\n\n field\n reify : \u2200 {\u03c0} \u2192 \u03c0 \u2208\u209a \u03a0 \u2192 \u27e6 \u03c0 \u27e7P rawStruct\n\n Has\u209a : (\u03a0\u2032 : Properties code) \u2192 Set\n Has\u209a \u03a0\u2032 = \u03a0\u2032 \u21d2\u209a \u03a0\n\n Has : List (Property K) \u2192 Set\n Has = Has\u209a \u2218 Core.fromList\n\n Has\u2081 : Property K \u2192 Set\n Has\u2081 \u03c0 = Has\u209a (Core.singleton \u03c0)\n\n use : \u2200 \u03c0 \u2983 has\u03c0 : \u03c0 \u2208\u209a \u03a0 \u2984 \u2192 \u27e6 \u03c0 \u27e7P rawStruct\n use _ \u2983 has\u03c0 \u2984 = reify has\u03c0\n\n from : \u2200 {\u03a0\u2032} (has\u03a0\u2032 : Has\u209a \u03a0\u2032) \u03c0 \u2983 has\u03c0 : \u03c0 \u2208\u209a \u03a0\u2032 \u2984 \u2192 \u27e6 \u03c0 \u27e7P rawStruct\n from has\u03a0\u2032 _ \u2983 has\u03c0 \u2984 = use _ \u2983 Core.\u21d2\u209a-MP has\u03c0 has\u03a0\u2032 \u2984\n\n substruct : \u2200 {k\u2032} {code\u2032 : Code k\u2032} \u2192 IsSubcode code\u2032 code \u2192 Struct code\u2032 c \u2113\n substruct isSub = record\n { rawStruct = record\n { Carrier = Carrier\n ; _\u2248_ = _\u2248_\n ; appOp = appOp \u2218 Core.subK\u2192supK isSub\n ; isRawStruct = isRawStruct\u2032\n }\n ; \u03a0 = Core.subcodeProperties isSub \u03a0\n ; reify = Core.reinterpret isSub rawStruct isRawStruct\u2032 _ \u2218 reify \u2218 Core.fromSubcode isSub\n }\n where\n isRawStruct\u2032 = record\n { isEquivalence = isEquivalence\n ; cong\u207f = cong\u207f \u2218 Core.subK\u2192supK isSub\n }\n\n toSubstruct :\n \u2200 {k\u2032} {code\u2032 : Code k\u2032} (isSub : IsSubcode code\u2032 code) \u2192\n \u2200 {\u03a0\u2032 : Properties code\u2032} (has\u03a0\u2032 : Has\u209a (Core.supcodeProperties isSub \u03a0\u2032)) \u2192\n \u03a0\u2032 \u21d2\u209a Core.subcodeProperties isSub \u03a0\n toSubstruct isSub has\u03a0\u2032 = Core.\u2192\u209a-\u21d2\u209a \u03bb \u03c0 has\u03c0 \u2192\n Core.fromSupcode isSub\n (Core.\u21d2\u209a-\u2192\u209a has\u03a0\u2032\n (Core.mapProperty (Core.subK\u2192supK isSub) \u03c0)\n (Core.fromSupcode\u2032 isSub has\u03c0))\n","avg_line_length":29.0512820513,"max_line_length":94,"alphanum_fraction":0.645631068} {"size":589,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"\nmodule Chain\n {U : Set}(T : U -> Set)\n (_==_ : {a b : U} -> T a -> T b -> Set)\n (refl : {a : U}(x : T a) -> x == x)\n (trans : {a b c : U}(x : T a)(y : T b)(z : T c) -> x == y -> y == z -> x == z)\n where\n\ninfix 30 _\u223c_\ninfix 3 proof_\ninfixl 2 _\u2261_by_\ninfix 1 _qed\n\ndata _\u223c_ {a b : U}(x : T a)(y : T b) : Set where\n prf : x == y -> x \u223c y\n\nproof_ : {a : U}(x : T a) -> x \u223c x\nproof x = prf (refl x)\n\n_\u2261_by_ : {a b c : U}{x : T a}{y : T b} -> x \u223c y -> (z : T c) -> y == z -> x \u223c z\nprf p \u2261 z by q = prf (trans _ _ _ p q)\n\n_qed : {a b : U}{x : T a}{y : T b} -> x \u223c y -> x == y\nprf p qed = p\n","avg_line_length":23.56,"max_line_length":80,"alphanum_fraction":0.4108658744} {"size":560,"ext":"agda","lang":"Agda","max_stars_count":3.0,"content":"-- Andreas, 2016-02-11, bug reported by sanzhiyan\n\nmodule Issue610-module-alias where\n\nimport Common.Level\nopen import Common.Equality\n\ndata \u22a5 : Set where\nrecord \u22a4 : Set where\n\ndata A : Set\u2081 where\n set : .Set \u2192 A\n\nmodule M .(x : Set) where\n\n .out : _\n out = x\n\n.ack : A \u2192 Set\nack (set x) = M.out x\n\nhah : set \u22a4 \u2261 set \u22a5\nhah = refl\n\n.moo' : \u22a5\nmoo' = subst (\u03bb x \u2192 x) (cong ack hah) _\n\n-- Expected error:\n-- .(\u22a5) !=< \u22a5 of type Set\n-- when checking that the expression subst (\u03bb x \u2192 x) (cong ack hah) _ has type \u22a5\n\nbaa : .\u22a5 \u2192 \u22a5\nbaa ()\n\nyoink : \u22a5\nyoink = baa moo'\n","avg_line_length":15.1351351351,"max_line_length":80,"alphanum_fraction":0.6035714286} {"size":2735,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module Prelude where\n open import Agda.Primitive using (Level; lzero; lsuc) renaming (_\u2294_ to lmax)\n\n -- empty type\n data \u22a5 : Set where\n\n -- from false, derive whatever\n abort : \u2200 {C : Set} \u2192 \u22a5 \u2192 C\n abort ()\n\n -- unit\n data \u22a4 : Set where\n <> : \u22a4\n\n -- sums\n data _+_ (A B : Set) : Set where\n Inl : A \u2192 A + B\n Inr : B \u2192 A + B\n\n -- pairs\n infixr 1 _,_\n record \u03a3 {l1 l2 : Level} (A : Set l1) (B : A \u2192 Set l2) : Set (lmax l1 l2) where\n constructor _,_\n field\n \u03c01 : A\n \u03c02 : B \u03c01\n open \u03a3 public\n\n -- Sigma types, or dependent pairs, with nice notation.\n syntax \u03a3 A (\\ x -> B) = \u03a3[ x \u2208 A ] B\n\n _\u00d7_ : {l1 : Level} {l2 : Level} \u2192 (Set l1) \u2192 (Set l2) \u2192 Set (lmax l1 l2)\n A \u00d7 B = \u03a3 A \u03bb _ \u2192 B\n\n infixr 1 _\u00d7_\n infixr 1 _+_\n\n -- equality\n data _==_ {l : Level} {A : Set l} (M : A) : A \u2192 Set l where\n refl : M == M\n\n infixr 9 _==_\n\n -- disequality\n _\u2260_ : {l : Level} {A : Set l} \u2192 (a b : A) \u2192 Set l\n a \u2260 b = (a == b) \u2192 \u22a5\n\n {-# BUILTIN EQUALITY _==_ #-}\n\n -- transitivity of equality\n _\u00b7_ : {l : Level} {\u03b1 : Set l} {x y z : \u03b1} \u2192 x == y \u2192 y == z \u2192 x == z\n refl \u00b7 refl = refl\n\n -- symmetry of equality\n ! : {l : Level} {\u03b1 : Set l} {x y : \u03b1} \u2192 x == y \u2192 y == x\n ! refl = refl\n\n -- ap, in the sense of HoTT, that all functions respect equality in their\n -- arguments. named in a slightly non-standard way to avoid naming\n -- clashes with hazelnut constructors.\n ap1 : {l1 l2 : Level} {\u03b1 : Set l1} {\u03b2 : Set l2} {x y : \u03b1} (F : \u03b1 \u2192 \u03b2)\n \u2192 x == y \u2192 F x == F y\n ap1 F refl = refl\n\n -- transport, in the sense of HoTT, that fibrations respect equality\n tr : {l1 l2 : Level} {\u03b1 : Set l1} {x y : \u03b1}\n (B : \u03b1 \u2192 Set l2)\n \u2192 x == y\n \u2192 B x\n \u2192 B y\n tr B refl x\u2081 = x\u2081\n\n -- options\n data Maybe (A : Set) : Set where\n Some : A \u2192 Maybe A\n None : Maybe A\n\n -- the some constructor is injective. perhaps unsurprisingly.\n someinj : {A : Set} {x y : A} \u2192 Some x == Some y \u2192 x == y\n someinj refl = refl\n\n -- some isn't none.\n somenotnone : {A : Set} {x : A} \u2192 Some x == None \u2192 \u22a5\n somenotnone ()\n\n -- function extensionality, used to reason about contexts as finite\n -- functions.\n postulate\n funext : {A : Set} {B : A \u2192 Set} {f g : (x : A) \u2192 (B x)} \u2192\n ((x : A) \u2192 f x == g x) \u2192 f == g\n\n -- non-equality is commutative\n flip : {A : Set} {x y : A} \u2192 (x == y \u2192 \u22a5) \u2192 (y == x \u2192 \u22a5)\n flip neq eq = neq (! eq)\n\n -- two types are said to be equivalent, or isomorphic, if there is a pair\n -- of functions between them where both round-trips are stable up to ==\n _\u2243_ : Set \u2192 Set \u2192 Set\n _\u2243_ A B = \u03a3[ f \u2208 (A \u2192 B) ] \u03a3[ g \u2208 (B \u2192 A) ]\n (((a : A) \u2192 g (f a) == a) \u00d7 (((b : B) \u2192 f (g b) == b)))\n","avg_line_length":27.0792079208,"max_line_length":81,"alphanum_fraction":0.5038391225} {"size":1486,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"------------------------------------------------------------------------\n-- The delay monad, defined coinductively, with a sized type parameter\n------------------------------------------------------------------------\n\n{-# OPTIONS --sized-types #-}\n\nmodule Delay-monad.Sized where\n\nopen import Equality.Propositional\nopen import Prelude\nopen import Prelude.Size\n\nopen import Bijection equality-with-J using (_\u2194_)\n\n-- The delay monad.\n\nmutual\n\n data Delay {a} (A : Size \u2192 Type a) (i : Size) : Type a where\n now : A i \u2192 Delay A i\n later : Delay\u2032 A i \u2192 Delay A i\n\n record Delay\u2032 {a} (A : Size \u2192 Type a) (i : Size) : Type a where\n coinductive\n field\n force : {j : Size< i} \u2192 Delay A j\n\nopen Delay\u2032 public\n\nmodule _ {a} {A : Size \u2192 Type a} where\n\n mutual\n\n -- A non-terminating computation.\n\n never : \u2200 {i} \u2192 Delay A i\n never = later never\u2032\n\n never\u2032 : \u2200 {i} \u2192 Delay\u2032 A i\n force never\u2032 = never\n\n -- Removes a later constructor, if possible.\n\n drop-later : Delay A \u221e \u2192 Delay A \u221e\n drop-later (now x) = now x\n drop-later (later x) = force x\n\n -- An unfolding lemma for Delay.\n\n Delay\u2194 : \u2200 {i} \u2192 Delay A i \u2194 A i \u228e Delay\u2032 A i\n Delay\u2194 = record\n { surjection = record\n { logical-equivalence = record\n { to = \u03bb { (now x) \u2192 inj\u2081 x; (later x) \u2192 inj\u2082 x }\n ; from = [ now , later ]\n }\n ; right-inverse-of = [ (\u03bb _ \u2192 refl) , (\u03bb _ \u2192 refl) ]\n }\n ; left-inverse-of = \u03bb { (now _) \u2192 refl; (later _) \u2192 refl }\n }\n","avg_line_length":24.3606557377,"max_line_length":72,"alphanum_fraction":0.5195154778} {"size":3206,"ext":"agda","lang":"Agda","max_stars_count":1.0,"content":"{-# OPTIONS --without-K --safe #-}\n\nopen import Level\n\nrecord Category (o \u2113 e : Level) : Set (suc (o \u2294 \u2113 \u2294 e)) where\n eta-equality\n infix 4 _\u2248_ _\u21d2_\n infixr 9 _\u2218_\n\n field\n Obj : Set o\n _\u21d2_ : Obj \u2192 Obj \u2192 Set \u2113\n _\u2248_ : \u2200 {A B} \u2192 (A \u21d2 B) \u2192 (A \u21d2 B) \u2192 Set e\n\n _\u2218_ : \u2200 {A B C} \u2192 (B \u21d2 C) \u2192 (A \u21d2 B) \u2192 (A \u21d2 C)\n\n CommutativeSquare : \u2200 {A B C D} \u2192 (f : A \u21d2 B) (g : A \u21d2 C) (h : B \u21d2 D) (i : C \u21d2 D) \u2192 Set _\n CommutativeSquare f g h i = h \u2218 f \u2248 i \u2218 g\n\ninfix 10 _[_,_]\n\n_[_,_] : \u2200 {o \u2113 e} \u2192 (C : Category o \u2113 e) \u2192 (X : Category.Obj C) \u2192 (Y : Category.Obj C) \u2192 Set \u2113\n_[_,_] = Category._\u21d2_\n\nmodule Inner {x\u2081 x\u2082 x\u2083} (CC : Category x\u2081 x\u2082 x\u2083) where\n\n open import Level\n private\n variable\n o \u2113 e o\u2032 \u2113\u2032 e\u2032 o\u2033 \u2113\u2033 e\u2033 : Level\n\n open import Data.Product using (_\u00d7_; \u03a3; _,_; curry\u2032; proj\u2081; proj\u2082; zip; map; <_,_>; swap)\n\n zipWith : \u2200 {a b c p q r s} {A : Set a} {B : Set b} {C : Set c} {P : A \u2192 Set p} {Q : B \u2192 Set q} {R : C \u2192 Set r} {S : (x : C) \u2192 R x \u2192 Set s} (_\u2219_ : A \u2192 B \u2192 C) \u2192 (_\u2218_ : \u2200 {x y} \u2192 P x \u2192 Q y \u2192 R (x \u2219 y)) \u2192 (_*_ : (x : C) \u2192 (y : R x) \u2192 S x y) \u2192 (x : \u03a3 A P) \u2192 (y : \u03a3 B Q) \u2192 S (proj\u2081 x \u2219 proj\u2081 y) (proj\u2082 x \u2218 proj\u2082 y)\n zipWith _\u2219_ _\u2218_ _*_ (a , p) (b , q) = (a \u2219 b) * (p \u2218 q)\n syntax zipWith f g h = f -< h >- g\n\n record Functor (C : Category o \u2113 e) (D : Category o\u2032 \u2113\u2032 e\u2032) : Set (o \u2294 \u2113 \u2294 e \u2294 o\u2032 \u2294 \u2113\u2032 \u2294 e\u2032) where\n eta-equality\n private module C = Category C\n private module D = Category D\n\n field\n F\u2080 : C.Obj \u2192 D.Obj\n F\u2081 : \u2200 {A B} (f : C [ A , B ]) \u2192 D [ F\u2080 A , F\u2080 B ]\n\n Product : (C : Category o \u2113 e) (D : Category o\u2032 \u2113\u2032 e\u2032) \u2192 Category (o \u2294 o\u2032) (\u2113 \u2294 \u2113\u2032) (e \u2294 e\u2032)\n Product C D = record\n { Obj = C.Obj \u00d7 D.Obj\n ; _\u21d2_ = C._\u21d2_ -< _\u00d7_ >- D._\u21d2_\n ; _\u2248_ = C._\u2248_ -< _\u00d7_ >- D._\u2248_\n ; _\u2218_ = zip C._\u2218_ D._\u2218_\n }\n where module C = Category C\n module D = Category D\n\n Bifunctor : Category o \u2113 e \u2192 Category o\u2032 \u2113\u2032 e\u2032 \u2192 Category o\u2033 \u2113\u2033 e\u2033 \u2192 Set _\n Bifunctor C D E = Functor (Product C D) E\n\n private\n module CC = Category CC\n\n open CC\n\n infix 4 _\u2245_\n record _\u2245_ (A B : Obj) : Set (x\u2082) where\n field\n from : A \u21d2 B\n to : B \u21d2 A\n\n private\n variable\n X Y Z W : Obj\n f g h : X \u21d2 Y\n\n record Monoidal : Set (x\u2081 \u2294 x\u2082 \u2294 x\u2083) where\n infixr 10 _\u2297\u2080_ _\u2297\u2081_\n\n field\n \u2297 : Bifunctor CC CC CC\n\n module \u2297 = Functor \u2297\n\n open Functor \u2297\n\n _\u2297\u2080_ : Obj \u2192 Obj \u2192 Obj\n _\u2297\u2080_ = curry\u2032 F\u2080\n\n -- this is also 'curry', but a very-dependent version\n _\u2297\u2081_ : X \u21d2 Y \u2192 Z \u21d2 W \u2192 X \u2297\u2080 Z \u21d2 Y \u2297\u2080 W\n f \u2297\u2081 g = F\u2081 (f , g)\n\n field\n associator : (X \u2297\u2080 Y) \u2297\u2080 Z \u2245 X \u2297\u2080 (Y \u2297\u2080 Z)\n\n module associator {X} {Y} {Z} = _\u2245_ (associator {X} {Y} {Z})\n\n -- for exporting, it makes sense to use the above long names, but for\n -- internal consumption, the traditional (short!) categorical names are more\n -- convenient. However, they are not symmetric, even though the concepts are, so\n -- we'll use \u21d2 and \u21d0 arrows to indicate that\n private\n \u03b1\u21d2 = associator.from\n \u03b1\u21d0 = \u03bb {X} {Y} {Z} \u2192 associator.to {X} {Y} {Z}\n\n field\n assoc-commute-from : CommutativeSquare ((f \u2297\u2081 g) \u2297\u2081 h) \u03b1\u21d2 \u03b1\u21d2 (f \u2297\u2081 (g \u2297\u2081 h))\n assoc-commute-to : CommutativeSquare (f \u2297\u2081 (g \u2297\u2081 h)) \u03b1\u21d0 \u03b1\u21d0 ((f \u2297\u2081 g) \u2297\u2081 h)\n","avg_line_length":29.4128440367,"max_line_length":311,"alphanum_fraction":0.498128509} {"size":659,"ext":"agda","lang":"Agda","max_stars_count":3.0,"content":"module reflnat where\n\n\ndata \u2115 : Set where\n Z : \u2115 \n S : \u2115 -> \u2115 \n\n\n_+_ : \u2115 -> \u2115 -> \u2115\nn + Z = n\nn + S m = S (n + m)\n\ninfixr 10 _+_\n\ninfixr 20 _*_\n_*_ : \u2115 -> \u2115 -> \u2115\nn * Z = Z\nn * S m = n * m + n\n\n\ndata Bool : Set where\n tt : Bool\n ff : Bool\n\ndata \u22a4 : Set where\n true : \u22a4 \n\ndata \u22a5 : Set where\n\n\nAtom : Bool -> Set\nAtom tt = \u22a4 \nAtom ff = \u22a5 \n\n_==Bool_ : \u2115 -> \u2115 -> Bool\nZ ==Bool Z = tt\n(S n) ==Bool (S m) = n ==Bool m\n_ ==Bool _ = ff\n-- Z ==Bool (S _) = ff\n-- (S _) ==Bool Z = ff\n\n\n_==_ : \u2115 -> \u2115 -> Set\nn == m = Atom ( n ==Bool m)\n\n\nRefl : Set\nRefl = (n : \u2115) -> n == n\n\n\nrefl : Refl\nrefl Z = true\nrefl (S n) = refl n\n\n\n\n\n\n\n","avg_line_length":10.9833333333,"max_line_length":32,"alphanum_fraction":0.4324734446} {"size":678,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"-- This file tests that record constructors are used in error\n-- messages, if possible.\n\n-- Andreas, 2016-07-20 Repaired this long disfunctional test case.\n\nmodule RecordConstructorsInErrorMessages where\n\nrecord R : Set\u2081 where\n constructor con\n field\n {A} : Set\n f : A \u2192 A\n {B C} D {E} : Set\n g : B \u2192 C \u2192 E\n\npostulate\n A : Set\n r : R\n\ndata _\u2261_ {A : Set\u2081} (x : A) : A \u2192 Set where\n refl : x \u2261 x\n\nfoo : r \u2261 record\n { A = A\n ; f = \u03bb x \u2192 x\n ; B = A\n ; C = A\n ; D = A\n ; g = \u03bb x _ \u2192 x\n }\nfoo = refl\n\n-- EXPECTED ERROR:\n-- .R.A r != A of type Set\n-- when checking that the expression refl has type\n-- r \u2261 con (\u03bb x \u2192 x) A (\u03bb x _ \u2192 x)\n","avg_line_length":18.3243243243,"max_line_length":66,"alphanum_fraction":0.5471976401} {"size":3641,"ext":"agda","lang":"Agda","max_stars_count":29.0,"content":"module BasicIS4.Metatheory.Gentzen-TarskiOvergluedGentzen where\n\nopen import BasicIS4.Syntax.Gentzen public\nopen import BasicIS4.Semantics.TarskiOvergluedGentzen public\n\n\n-- Internalisation of syntax as syntax representation in a particular model.\n\nmodule _ {{_ : Model}} where\n mutual\n [_] : \u2200 {A \u0393} \u2192 \u0393 \u22a2 A \u2192 \u0393 [\u22a2] A\n [ var i ] = [var] i\n [ lam t ] = [lam] [ t ]\n [ app t u ] = [app] [ t ] [ u ]\n [ multibox ts u ] = [multibox] ([\u22a2]\u22c6\u2192[\u22a2\u22c6] [ ts ]\u22c6) [ u ]\n [ down t ] = [down] [ t ]\n [ pair t u ] = [pair] [ t ] [ u ]\n [ fst t ] = [fst] [ t ]\n [ snd t ] = [snd] [ t ]\n [ unit ] = [unit]\n\n [_]\u22c6 : \u2200 {\u039e \u0393} \u2192 \u0393 \u22a2\u22c6 \u039e \u2192 \u0393 [\u22a2]\u22c6 \u039e\n [_]\u22c6 {\u2205} \u2219 = \u2219\n [_]\u22c6 {\u039e , A} (ts , t) = [ ts ]\u22c6 , [ t ]\n\n\n-- Soundness with respect to all models, or evaluation.\n\nmutual\n eval : \u2200 {A \u0393} \u2192 \u0393 \u22a2 A \u2192 \u0393 \u22a8 A\n eval (var i) \u03b3 = lookup i \u03b3\n eval (lam t) \u03b3 = \u03bb \u03b7 \u2192 let \u03b3\u2032 = mono\u22a9\u22c6 \u03b7 \u03b3\n in [multicut] (reify\u02b3\u22c6 \u03b3\u2032) [ lam t ] \u214b \u03bb a \u2192\n eval t (\u03b3\u2032 , a)\n eval (app t u) \u03b3 = eval t \u03b3 \u27ea$\u27eb eval u \u03b3\n eval (multibox ts u) \u03b3 = \u03bb \u03b7 \u2192 let \u03b3\u2032 = mono\u22a9\u22c6 \u03b7 \u03b3\n in [multicut] (reify\u02b3\u22c6 \u03b3\u2032) [ multibox ts u ] \u214b\n eval u (eval\u22c6 ts \u03b3\u2032)\n eval (down t) \u03b3 = \u27ea\u2193\u27eb (eval t \u03b3)\n eval (pair t u) \u03b3 = eval t \u03b3 , eval u \u03b3\n eval (fst t) \u03b3 = \u03c0\u2081 (eval t \u03b3)\n eval (snd t) \u03b3 = \u03c0\u2082 (eval t \u03b3)\n eval unit \u03b3 = \u2219\n\n eval\u22c6 : \u2200 {\u039e \u0393} \u2192 \u0393 \u22a2\u22c6 \u039e \u2192 \u0393 \u22a8\u22c6 \u039e\n eval\u22c6 {\u2205} \u2219 \u03b3 = \u2219\n eval\u22c6 {\u039e , A} (ts , t) \u03b3 = eval\u22c6 ts \u03b3 , eval t \u03b3\n\n\n-- TODO: Correctness of evaluation with respect to conversion.\n\n\n-- The canonical model.\n\nprivate\n instance\n canon : Model\n canon = record\n { _\u22a9\u1d45_ = \u03bb \u0393 P \u2192 \u0393 \u22a2 \u03b1 P\n ; mono\u22a9\u1d45 = mono\u22a2\n ; _[\u22a2]_ = _\u22a2_\n ; _[\u22a2\u22c6]_ = _\u22a2\u22c6_\n ; mono[\u22a2] = mono\u22a2\n ; [var] = var\n ; [lam] = lam\n ; [app] = app\n ; [multibox] = multibox\n ; [down] = down\n ; [pair] = pair\n ; [fst] = fst\n ; [snd] = snd\n ; [unit] = unit\n ; top[\u22a2\u22c6] = refl\n ; pop[\u22a2\u22c6] = refl\n }\n\n\n-- Soundness and completeness with respect to the canonical model.\n\nmutual\n reflect\u1d9c : \u2200 {A \u0393} \u2192 \u0393 \u22a2 A \u2192 \u0393 \u22a9 A\n reflect\u1d9c {\u03b1 P} t = t \u214b t\n reflect\u1d9c {A \u25bb B} t = \u03bb \u03b7 \u2192 let t\u2032 = mono\u22a2 \u03b7 t\n in t\u2032 \u214b \u03bb a \u2192 reflect\u1d9c (app t\u2032 (reify\u1d9c a))\n reflect\u1d9c {\u25a1 A} t = \u03bb \u03b7 \u2192 let t\u2032 = mono\u22a2 \u03b7 t\n in t\u2032 \u214b reflect\u1d9c (down t\u2032)\n reflect\u1d9c {A \u2227 B} t = reflect\u1d9c (fst t) , reflect\u1d9c (snd t)\n reflect\u1d9c {\u22a4} t = \u2219\n\n reify\u1d9c : \u2200 {A \u0393} \u2192 \u0393 \u22a9 A \u2192 \u0393 \u22a2 A\n reify\u1d9c {\u03b1 P} s = syn s\n reify\u1d9c {A \u25bb B} s = syn (s refl\u2286)\n reify\u1d9c {\u25a1 A} s = syn (s refl\u2286)\n reify\u1d9c {A \u2227 B} s = pair (reify\u1d9c (\u03c0\u2081 s)) (reify\u1d9c (\u03c0\u2082 s))\n reify\u1d9c {\u22a4} s = unit\n\nreflect\u1d9c\u22c6 : \u2200 {\u039e \u0393} \u2192 \u0393 \u22a2\u22c6 \u039e \u2192 \u0393 \u22a9\u22c6 \u039e\nreflect\u1d9c\u22c6 {\u2205} \u2219 = \u2219\nreflect\u1d9c\u22c6 {\u039e , A} (ts , t) = reflect\u1d9c\u22c6 ts , reflect\u1d9c t\n\nreify\u1d9c\u22c6 : \u2200 {\u039e \u0393} \u2192 \u0393 \u22a9\u22c6 \u039e \u2192 \u0393 \u22a2\u22c6 \u039e\nreify\u1d9c\u22c6 {\u2205} \u2219 = \u2219\nreify\u1d9c\u22c6 {\u039e , A} (ts , t) = reify\u1d9c\u22c6 ts , reify\u1d9c t\n\n\n-- Reflexivity and transitivity.\n\nrefl\u22a9\u22c6 : \u2200 {\u0393} \u2192 \u0393 \u22a9\u22c6 \u0393\nrefl\u22a9\u22c6 = reflect\u1d9c\u22c6 refl\u22a2\u22c6\n\ntrans\u22a9\u22c6 : \u2200 {\u0393 \u0393\u2032 \u0393\u2033} \u2192 \u0393 \u22a9\u22c6 \u0393\u2032 \u2192 \u0393\u2032 \u22a9\u22c6 \u0393\u2033 \u2192 \u0393 \u22a9\u22c6 \u0393\u2033\ntrans\u22a9\u22c6 ts us = reflect\u1d9c\u22c6 (trans\u22a2\u22c6 (reify\u1d9c\u22c6 ts) (reify\u1d9c\u22c6 us))\n\n\n-- Completeness with respect to all models, or quotation.\n\nquot : \u2200 {A \u0393} \u2192 \u0393 \u22a8 A \u2192 \u0393 \u22a2 A\nquot s = reify\u1d9c (s refl\u22a9\u22c6)\n\n\n-- Normalisation by evaluation.\n\nnorm : \u2200 {A \u0393} \u2192 \u0393 \u22a2 A \u2192 \u0393 \u22a2 A\nnorm = quot \u2218 eval\n\n\n-- TODO: Correctness of normalisation with respect to conversion.\n","avg_line_length":28.4453125,"max_line_length":81,"alphanum_fraction":0.4391650645} {"size":2531,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"\nmodule Warshall\n (X : Set)\n ((\u2264) : X -> X -> Prop)\n -- and axioms...\n where\n\nid : {A:Set} -> A -> A\nid x = x\n\n(\u2218) : {A B C:Set} -> (B -> C) -> (A -> B) -> A -> C\nf \u2218 g = \\x -> f (g x)\n\n-- Natural numbers --------------------------------------------------------\n\ndata Nat : Set where\n zero : Nat\n suc : Nat -> Nat\n\n(+) : Nat -> Nat -> Nat\nzero + m = m\nsuc n + m = suc (n + m)\n\n-- Finite sets ------------------------------------------------------------\n\ndata Zero : Set where\n\ndata Suc (A:Set) : Set where\n fzero_ : Suc A\n fsuc_ : A -> Suc A\n\nmutual\n\n data Fin (n:Nat) : Set where\n finI : Fin_ n -> Fin n\n\n Fin_ : Nat -> Set\n Fin_ zero = Zero\n Fin_ (suc n) = Suc (Fin n)\n\nfzero : {n:Nat} -> Fin (suc n)\nfzero = finI fzero_\n\nfsuc : {n:Nat} -> Fin n -> Fin (suc n)\nfsuc i = finI (fsuc_ i)\n\nfinE : {n:Nat} -> Fin n -> Fin_ n\nfinE (finI i) = i\n\ninfixr 15 ::\n\n-- Vectors ----------------------------------------------------------------\n\ndata Nil : Set where\n nil_ : Nil\n\ndata Cons (Xs:Set) : Set where\n cons_ : X -> Xs -> Cons Xs\n\nmutual\n\n data Vec (n:Nat) : Set where\n vecI : Vec_ n -> Vec n\n\n Vec_ : Nat -> Set\n Vec_ zero = Nil\n Vec_ (suc n) = Cons (Vec n)\n\nnil : Vec zero\nnil = vecI nil_\n\n(::) : {n:Nat} -> X -> Vec n -> Vec (suc n)\nx :: xs = vecI (cons_ x xs)\n\nvecE : {n:Nat} -> Vec n -> Vec_ n\nvecE (vecI xs) = xs\n\nvec : (n:Nat) -> X -> Vec n\nvec zero _ = nil\nvec (suc n) x = x :: vec n x\n\nmap : {n:Nat} -> (X -> X) -> Vec n -> Vec n\nmap {zero} f (vecI nil_) = nil\nmap {suc n} f (vecI (cons_ x xs)) = f x :: map f xs\n\n(!) : {n:Nat} -> Vec n -> Fin n -> X\n(!) {suc n} (vecI (cons_ x _ )) (finI fzero_) = x\n(!) {suc n} (vecI (cons_ _ xs)) (finI (fsuc_ i)) = xs ! i\n\nupd : {n:Nat} -> Fin n -> X -> Vec n -> Vec n\nupd {suc n} (finI fzero_) x (vecI (cons_ _ xs)) = x :: xs\nupd {suc n} (finI (fsuc_ i)) x (vecI (cons_ y xs)) = y :: upd i x xs\n\ntabulate : {n:Nat} -> (Fin n -> X) -> Vec n\ntabulate {zero} f = nil\ntabulate {suc n} f = f fzero :: tabulate (\\x -> f (fsuc x))\n\npostulate\n (===) : {n:Nat} -> Vec n -> Vec n -> Prop\n\n\nmodule Proof\n (F : {n:Nat} -> Vec n -> Vec n)\n -- and axioms...\n where\n\n stepF : {n:Nat} -> Fin n -> Vec n -> Vec n\n stepF i xs = upd i (F xs ! i) xs\n\n unsafeF' : {n:Nat} -> Nat -> Vec (suc n) -> Vec (suc n)\n unsafeF' zero = id\n unsafeF' (suc m) = unsafeF' m \u2218 stepF fzero\n\n unsafeF : {n:Nat} -> Vec n -> Vec n\n unsafeF {zero} = id\n unsafeF {suc n} = unsafeF' (suc n)\n\n thm : {n:Nat} -> (xs:Vec n) -> F xs === unsafeF xs\n thm = ?\n\n","avg_line_length":20.9173553719,"max_line_length":75,"alphanum_fraction":0.4674041881} {"size":8147,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-\n\nThis file proves a variety of basic results about paths:\n\n- refl, sym, cong and composition of paths. This is used to set up\n equational reasoning.\n\n- Transport, subst and functional extensionality\n\n- J and its computation rule (up to a path)\n\n- \u03a3-types and contractibility of singletons\n\n- Converting PathP to and from a homogeneous path with transp\n\n- Direct definitions of lower h-levels\n\n- Export natural numbers\n\n- Export universe lifting\n\n-}\n{-# OPTIONS --cubical --safe #-}\nmodule Cubical.Foundations.Prelude where\n\nopen import Cubical.Core.Primitives public\n\ninfixr 30 _\u2219_\ninfix 3 _\u220e\ninfixr 2 _\u2261\u27e8_\u27e9_\n\n-- Basic theory about paths. These proofs should typically be\n-- inlined. This module also makes equational reasoning work with\n-- (non-dependent) paths.\n\nprivate\n variable\n \u2113 \u2113' : Level\n A : Type \u2113\n B : A \u2192 Type \u2113\n x y z : A\n\nrefl : x \u2261 x\nrefl {x = x} = \u03bb _ \u2192 x\n\nsym : x \u2261 y \u2192 y \u2261 x\nsym p i = p (~ i)\n\nsymP : {A : I \u2192 Type \u2113} \u2192 {x : A i0} \u2192 {y : A i1} \u2192\n (p : PathP A x y) \u2192 PathP (\u03bb i \u2192 A (~ i)) y x\nsymP p j = p (~ j)\n\ncong : \u2200 (f : (a : A) \u2192 B a) (p : x \u2261 y) \u2192\n PathP (\u03bb i \u2192 B (p i)) (f x) (f y)\ncong f p i = f (p i)\n\ncong\u2082 : \u2200 {C : (a : A) \u2192 (b : B a) \u2192 Type \u2113} \u2192\n (f : (a : A) \u2192 (b : B a) \u2192 C a b) \u2192\n (p : x \u2261 y) \u2192\n {u : B x} {v : B y} (q : PathP (\u03bb i \u2192 B (p i)) u v) \u2192\n PathP (\u03bb i \u2192 C (p i) (q i)) (f x u) (f y v)\ncong\u2082 f p q i = f (p i) (q i)\n\n-- The filler of homogeneous path composition:\n-- compPath-filler p q = PathP (\u03bb i \u2192 x \u2261 q i) p (p \u2219 q)\n\ncompPath-filler : \u2200 {x y z : A} \u2192 x \u2261 y \u2192 y \u2261 z \u2192 I \u2192 I \u2192 A\ncompPath-filler {x = x} p q j i =\n hfill (\u03bb j \u2192 \u03bb { (i = i0) \u2192 x\n ; (i = i1) \u2192 q j }) (inS (p i)) j\n\n_\u2219_ : x \u2261 y \u2192 y \u2261 z \u2192 x \u2261 z\n(p \u2219 q) j = compPath-filler p q i1 j\n\n-- The filler of heterogeneous path composition:\n-- compPathP-filler p q = PathP (\u03bb i \u2192 PathP (\u03bb j \u2192 (compPath-filler (\u03bb i \u2192 A i) B i j)) x (q i)) p (compPathP p q)\n\ncompPathP-filler : {A : I \u2192 Type \u2113} \u2192 {x : A i0} \u2192 {y : A i1} \u2192 {B_i1 : Type \u2113} {B : A i1 \u2261 B_i1} \u2192 {z : B i1} \u2192\n (p : PathP A x y) \u2192 (q : PathP (\u03bb i \u2192 B i) y z) \u2192 \u2200 (i j : I) \u2192 compPath-filler (\u03bb i \u2192 A i) B j i\ncompPathP-filler {A = A} {x = x} {B = B} p q i =\n fill (\u03bb j \u2192 compPath-filler (\u03bb i \u2192 A i) B j i)\n (\u03bb j \u2192 \u03bb { (i = i0) \u2192 x ;\n (i = i1) \u2192 q j }) (inS (p i))\n\ncompPathP : {A : I \u2192 Type \u2113} \u2192 {x : A i0} \u2192 {y : A i1} \u2192 {B_i1 : Type \u2113} {B : (A i1) \u2261 B_i1} \u2192 {z : B i1} \u2192\n (p : PathP A x y) \u2192 (q : PathP (\u03bb i \u2192 B i) y z) \u2192 PathP (\u03bb j \u2192 ((\u03bb i \u2192 A i) \u2219 B) j) x z\ncompPathP p q j = compPathP-filler p q j i1\n\n_\u2261\u27e8_\u27e9_ : (x : A) \u2192 x \u2261 y \u2192 y \u2261 z \u2192 x \u2261 z\n_ \u2261\u27e8 x\u2261y \u27e9 y\u2261z = x\u2261y \u2219 y\u2261z\n\n\n\u2261\u27e8\u27e9-syntax : (x : A) \u2192 x \u2261 y \u2192 y \u2261 z \u2192 x \u2261 z\n\u2261\u27e8\u27e9-syntax = _\u2261\u27e8_\u27e9_\ninfixr 2 \u2261\u27e8\u27e9-syntax\nsyntax \u2261\u27e8\u27e9-syntax x (\u03bb i \u2192 B) y = x \u2261[ i ]\u27e8 B \u27e9 y\n\n_\u220e : (x : A) \u2192 x \u2261 x\n_ \u220e = refl\n\n-- another definition of composition, useful for some proofs\ncompPath'-filler : \u2200 {x y z : A} \u2192 x \u2261 y \u2192 y \u2261 z \u2192 I \u2192 I \u2192 A\ncompPath'-filler {z = z} p q j i =\n hfill (\u03bb j \u2192 \u03bb { (i = i0) \u2192 p (~ j)\n ; (i = i1) \u2192 z }) (inS (q i)) j\n\n_\u25a1_ : x \u2261 y \u2192 y \u2261 z \u2192 x \u2261 z\n(p \u25a1 q) j = compPath'-filler p q i1 j\n\n\u25a1\u2261\u2219 : (p : x \u2261 y) (q : y \u2261 z) \u2192 p \u25a1 q \u2261 p \u2219 q\n\u25a1\u2261\u2219 {x = x} {y = y} {z = z} p q i j = hcomp (\u03bb k \u2192 \\ { (i = i0) \u2192 compPath'-filler p q k j\n ; (i = i1) \u2192 compPath-filler p q k j\n ; (j = i0) \u2192 p ( ~ i \u2227 ~ k)\n ; (j = i1) \u2192 q (k \u2228 ~ i) }) (helper i j)\n where\n helper : PathP (\u03bb i \u2192 p (~ i) \u2261 q (~ i)) q p\n helper i j = hcomp (\u03bb k \u2192 \\ { (i = i0) \u2192 q (k \u2227 j)\n ; (i = i1) \u2192 p (~ k \u2228 j)\n ; (j = i0) \u2192 p (~ i \u2228 ~ k)\n ; (j = i1) \u2192 q (~ i \u2227 k) })\n y\n\n-- Transport, subst and functional extensionality\n\n-- transport is a special case of transp\ntransport : {A B : Type \u2113} \u2192 A \u2261 B \u2192 A \u2192 B\ntransport p a = transp (\u03bb i \u2192 p i) i0 a\n\n-- Transporting in a constant family is the identity function (up to a\n-- path). If we would have regularity this would be definitional.\ntransportRefl : (x : A) \u2192 transport refl x \u2261 x\ntransportRefl {A = A} x i = transp (\u03bb _ \u2192 A) i x\n\n-- We want B to be explicit in subst\nsubst : (B : A \u2192 Type \u2113') (p : x \u2261 y) \u2192 B x \u2192 B y\nsubst B p pa = transport (\u03bb i \u2192 B (p i)) pa\n\nsubstRefl : (px : B x) \u2192 subst B refl px \u2261 px\nsubstRefl px = transportRefl px\n\nfunExt : {f g : (x : A) \u2192 B x} \u2192 ((x : A) \u2192 f x \u2261 g x) \u2192 f \u2261 g\nfunExt p i x = p x i\n\n-- J for paths and its computation rule\n\nmodule _ (P : \u2200 y \u2192 x \u2261 y \u2192 Type \u2113') (d : P x refl) where\n J : (p : x \u2261 y) \u2192 P y p\n J p = transport (\u03bb i \u2192 P (p i) (\u03bb j \u2192 p (i \u2227 j))) d\n\n JRefl : J refl \u2261 d\n JRefl = transportRefl d\n\n-- Contractibility of singletons\n\nsingl : (a : A) \u2192 Type _\nsingl {A = A} a = \u03a3[ x \u2208 A ] (a \u2261 x)\n\ncontrSingl : (p : x \u2261 y) \u2192 Path (singl x) (x , refl) (y , p)\ncontrSingl p i = (p i , \u03bb j \u2192 p (i \u2227 j))\n\n\n-- Converting to and from a PathP\n\nmodule _ {A : I \u2192 Type \u2113} {x : A i0} {y : A i1} where\n toPathP : transp A i0 x \u2261 y \u2192 PathP A x y\n toPathP p i = hcomp (\u03bb j \u2192 \u03bb { (i = i0) \u2192 x\n ; (i = i1) \u2192 p j })\n (transp (\u03bb j \u2192 A (i \u2227 j)) (~ i) x)\n\n fromPathP : PathP A x y \u2192 transp A i0 x \u2261 y\n fromPathP p i = transp (\u03bb j \u2192 A (i \u2228 j)) i (p i)\n\n\n-- Direct definitions of lower h-levels\n\nisContr : Type \u2113 \u2192 Type \u2113\nisContr A = \u03a3[ x \u2208 A ] (\u2200 y \u2192 x \u2261 y)\n\nisProp : Type \u2113 \u2192 Type \u2113\nisProp A = (x y : A) \u2192 x \u2261 y\n\nisSet : Type \u2113 \u2192 Type \u2113\nisSet A = (x y : A) \u2192 isProp (x \u2261 y)\n\nSquare\n : \u2200{w x y z : A}\n \u2192 (p : w \u2261 y) (q : w \u2261 x) (r : y \u2261 z) (s : x \u2261 z)\n \u2192 Set _\nSquare p q r s = PathP (\u03bb i \u2192 p i \u2261 s i) q r\n\nisSet' : Type \u2113 \u2192 Type \u2113\nisSet' A\n = {x y z w : A}\n \u2192 (p : x \u2261 y) (q : z \u2261 w) (r : x \u2261 z) (s : y \u2261 w)\n \u2192 Square r p q s\n\nisGroupoid : Type \u2113 \u2192 Type \u2113\nisGroupoid A = \u2200 a b \u2192 isSet (Path A a b)\n\nCube\n : \u2200{w x y z w' x' y' z' : A}\n \u2192 {p : w \u2261 y} {q : w \u2261 x} {r : y \u2261 z} {s : x \u2261 z}\n \u2192 {p' : w' \u2261 y'} {q' : w' \u2261 x'} {r' : y' \u2261 z'} {s' : x' \u2261 z'}\n \u2192 {a : w \u2261 w'} {b : x \u2261 x'} {c : y \u2261 y'} {d : z \u2261 z'}\n \u2192 (ps : Square a p p' c) (qs : Square a q q' b)\n \u2192 (rs : Square c r r' d) (ss : Square b s s' d)\n \u2192 (f0 : Square p q r s) (f1 : Square p' q' r' s')\n \u2192 Set _\nCube ps qs rs ss f0 f1\n = PathP (\u03bb k \u2192 Square (ps k) (qs k) (rs k) (ss k)) f0 f1\n\nisGroupoid' : Set \u2113 \u2192 Set \u2113\nisGroupoid' A\n = \u2200{w x y z w' x' y' z' : A}\n \u2192 {p : w \u2261 y} {q : w \u2261 x} {r : y \u2261 z} {s : x \u2261 z}\n \u2192 {p' : w' \u2261 y'} {q' : w' \u2261 x'} {r' : y' \u2261 z'} {s' : x' \u2261 z'}\n \u2192 {a : w \u2261 w'} {b : x \u2261 x'} {c : y \u2261 y'} {d : z \u2261 z'}\n \u2192 (fp : Square a p p' c) \u2192 (fq : Square a q q' b)\n \u2192 (fr : Square c r r' d) \u2192 (fs : Square b s s' d)\n \u2192 (f0 : Square p q r s) \u2192 (f1 : Square p' q' r' s')\n \u2192 Cube fp fq fr fs f0 f1\n\nis2Groupoid : Type \u2113 \u2192 Type \u2113\nis2Groupoid A = \u2200 a b \u2192 isGroupoid (Path A a b)\n\n-- Essential consequences of isProp and isContr\nisProp\u2192PathP\n : ((x : A) \u2192 isProp (B x)) \u2192 {a0 a1 : A}\n \u2192 (p : a0 \u2261 a1) (b0 : B a0) (b1 : B a1)\n \u2192 PathP (\u03bb i \u2192 B (p i)) b0 b1\nisProp\u2192PathP P p b0 b1 = toPathP (P _ _ _)\n\nisProp-PathP-I : \u2200 {B : I \u2192 Type \u2113} \u2192 ((i : I) \u2192 isProp (B i))\n \u2192 (b0 : B i0) (b1 : B i1)\n \u2192 PathP (\u03bb i \u2192 B i) b0 b1\nisProp-PathP-I hB b0 b1 = toPathP (hB _ _ _)\n\nisPropIsContr : isProp (isContr A)\nisPropIsContr z0 z1 j =\n ( z0 .snd (z1 .fst) j\n , \u03bb x i \u2192 hcomp (\u03bb k \u2192 \u03bb { (i = i0) \u2192 z0 .snd (z1 .fst) j\n ; (i = i1) \u2192 z0 .snd x (j \u2228 k)\n ; (j = i0) \u2192 z0 .snd x (i \u2227 k)\n ; (j = i1) \u2192 z1 .snd x i })\n (z0 .snd (z1 .snd x i) j))\n\nisContr\u2192isProp : isContr A \u2192 isProp A\nisContr\u2192isProp (x , p) a b i =\n hcomp (\u03bb j \u2192 \u03bb { (i = i0) \u2192 p a j\n ; (i = i1) \u2192 p b j }) x\n\nisProp\u2192isSet : isProp A \u2192 isSet A\nisProp\u2192isSet h a b p q j i =\n hcomp (\u03bb k \u2192 \u03bb { (i = i0) \u2192 h a a k\n ; (i = i1) \u2192 h a b k\n ; (j = i0) \u2192 h a (p i) k\n ; (j = i1) \u2192 h a (q i) k }) a\n\n-- Universe lifting\n\nrecord Lift {i j} (A : Type i) : Type (\u2113-max i j) where\n instance constructor lift\n field\n lower : A\n\nopen Lift public\n","avg_line_length":30.5131086142,"max_line_length":115,"alphanum_fraction":0.4652019148} {"size":539,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"-- Andreas, 2012-09-07\n-- {-# OPTIONS -v tc.polarity:10 -v tc.conv.irr:20 -v tc.conv.elim:25 -v tc.conv.term:10 #-}\nmodule Issue691 where\n\nopen import Common.Equality\n\ndata Bool : Set where\n true false : Bool\n\nassert : (A : Set) \u2192 A \u2192 Bool \u2192 Bool\nassert _ _ true = true\nassert _ _ false = false\n\ng : Bool -> Bool -> Bool\ng x true = true\ng x false = true\n\nunsolved : Bool -> Bool\nunsolved y =\n let X : Bool\n X = _\n in assert (g X y \u2261 g true y) refl X\n-- X should be left unsolved\n\nistrue : (unsolved false) \u2261 true\nistrue = refl\n\n","avg_line_length":19.25,"max_line_length":92,"alphanum_fraction":0.6363636364} {"size":1381,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"-- {-# OPTIONS -v scope:20 #-}\n\nmodule _ (X : Set) where\n\npostulate\n X\u2081 X\u2082 : Set\n\ndata D : Set where\n d : D\n\nmodule Q (x : D) where\n module M1 (z : X\u2081) where\n g = x\n module M2 (y : D) (z : X\u2082) where\n h = y\n open M1 public\n\n-- module Qd = Q d\n\n-- This fails to apply g to d!\nmodule QM2d = Q.M2 d d\n\nmodule QM2p (x : D) = Q.M2 x x\n\ntest-h : X\u2082 \u2192 D\ntest-h = QM2d.h\n\ntest-g\u2081 : X\u2081 \u2192 D\ntest-g\u2081 = QM2d.g\n\ntest-g\u2082 : D \u2192 X\u2081 \u2192 D\ntest-g\u2082 = QM2p.g\n\ndata Nat : Set where\n zero : Nat\n suc : Nat \u2192 Nat\n\npostulate\n Lift : Nat \u2192 Set\n mkLift : \u2200 n \u2192 Lift n\n\nmodule TS (T : Nat) where\n module Lifted (lift : Lift T) where\n postulate f : Nat\n\nrecord Bla (T : Nat) : Set\u2081 where\n\n module TST = TS T\n module LT = TST.Lifted (mkLift T)\n\n Z : Nat\n Z = LT.f\n\npostulate\n A : Set\n\nmodule C (X : Set) where\n postulate cA : X\n\nmodule C\u2032 = C\nmodule C\u2032A = C\u2032 A\n\ndA' : A \u2192 A\ndA' x = C\u2032A.cA\n\npostulate\n B : Set\n\nmodule TermSubst (X : Set) where\n module Lifted (Y : Set) where\n f : Set\n f = Y\n\nrecord TermLemmas (Z : Set) : Set\u2081 where\n module TZ = TermSubst A\n module TZL = TZ.Lifted B\n foo : Set\n foo = TZL.f\n field Y : Set\n\nmodule NatCore where\n module NatT (X Y : Set) where\n Z : Set\n Z = X \u2192 Y\n\nmodule NatTrans (Y : Set) where\n open NatCore public\n\nmodule NT = NatTrans\n\nfoo : Set \u2192 Set\nfoo X = Eta.Z\n module Local where\n module Eta = NT.NatT X X\n","avg_line_length":14.5368421053,"max_line_length":40,"alphanum_fraction":0.5814627082} {"size":2068,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"-- Andreas, 2016-04-14 issue 1796 for rewrite\n\n-- {-# OPTIONS --show-implicit #-}\n-- {-# OPTIONS -v tc.size.solve:100 #-}\n-- {-# OPTIONS -v tc.with.abstract:40 #-}\n\n{-# OPTIONS --sized-types #-}\n\nopen import Common.Size\nopen import Common.Equality\n\ndata Either (A B : Set) : Set where\n left : A \u2192 Either A B\n right : B \u2192 Either A B\n\neither : {A B : Set} \u2192 Either A B \u2192\n \u2200{C : Set} \u2192 (A \u2192 C) \u2192 (B \u2192 C) \u2192 C\neither (left a) l r = l a\neither (right b) l r = r b\n\ndata Nat : Size \u2192 Set where\n zero : \u2200{i} \u2192 Nat (\u2191 i)\n suc : \u2200{i} \u2192 Nat i \u2192 Nat (\u2191 i)\n\nprimrec : \u2200{\u2113} (C : Size \u2192 Set \u2113)\n \u2192 (z : \u2200{i} \u2192 C i)\n \u2192 (s : \u2200{i} \u2192 Nat i \u2192 C i \u2192 C (\u2191 i))\n \u2192 \u2200{i} \u2192 Nat i \u2192 C i\nprimrec C z s zero = z\nprimrec C z s (suc n) = s n (primrec C z s n)\n\ncase : \u2200{i} \u2192 Nat i\n \u2192 \u2200{\u2113} (C : Size \u2192 Set \u2113)\n \u2192 (z : \u2200{i} \u2192 C i)\n \u2192 (s : \u2200{i} \u2192 Nat i \u2192 C (\u2191 i))\n \u2192 C i\ncase n C z s = primrec C z (\u03bb n r \u2192 s n) n\n\ndiff : \u2200{i} \u2192 Nat i \u2192 \u2200{j} \u2192 Nat j \u2192 Either (Nat i) (Nat j)\ndiff = primrec (\u03bb i \u2192 \u2200{j} \u2192 Nat j \u2192 Either (Nat i) (Nat j))\n -- case zero: the second number is bigger and the difference\n right\n -- case suc n:\n (\u03bb{i} n r m \u2192 case m (\u03bb j \u2192 Either (Nat (\u2191 i)) (Nat j))\n -- subcase zero: the first number (suc n) is bigger and the difference\n (left (suc n))\n -- subcase suc m: recurse on (n,m)\n r)\n\ngcd : \u2200{i} \u2192 Nat i \u2192 \u2200{j} \u2192 Nat j \u2192 Nat \u221e\ngcd zero m = m\ngcd (suc n) zero = suc n\ngcd (suc n) (suc m) = either (diff n m)\n (\u03bb n' \u2192 gcd n' (suc m))\n (\u03bb m' \u2192 gcd (suc n) m')\n\ner : \u2200{i} \u2192 Nat i \u2192 Nat \u221e\ner zero = zero\ner (suc n) = suc (er n)\n\ndiff-diag-erase : \u2200{i} (n : Nat i) \u2192 diff (er n) (er n) \u2261 right zero\ndiff-diag-erase zero = refl\ndiff-diag-erase (suc n) = diff-diag-erase n\n\ngcd-diag-erase : \u2200{i} (n : Nat i) \u2192 gcd (er n) (er n) \u2261 er n\ngcd-diag-erase zero = refl\ngcd-diag-erase (suc {i} n)\n rewrite diff-diag-erase n\n -- Before fix: diff-diag-erase {i} n.\n -- The {i} was necessary, otherwise rewrite failed\n -- because an unsolved size var prevented abstraction.\n | gcd-diag-erase n = refl\n","avg_line_length":28.3287671233,"max_line_length":74,"alphanum_fraction":0.5275628627} {"size":450,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"{-# OPTIONS --cubical --safe #-}\n\nopen import Agda.Builtin.Cubical.Path\nopen import Agda.Primitive\n\nprivate\n variable\n a : Level\n A B : Set a\n\nIs-proposition : Set a \u2192 Set a\nIs-proposition A = (x y : A) \u2192 x \u2261 y\n\ndata \u2225_\u2225 (A : Set a) : Set a where\n \u2223_\u2223 : A \u2192 \u2225 A \u2225\n @0 trivial : Is-proposition \u2225 A \u2225\n\nrec : @0 Is-proposition B \u2192 (A \u2192 B) \u2192 \u2225 A \u2225 \u2192 B\nrec p f \u2223 x \u2223 = f x\nrec p f (trivial x y i) = p (rec p f x) (rec p f y) i\n","avg_line_length":21.4285714286,"max_line_length":53,"alphanum_fraction":0.54} {"size":6384,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --cubical --no-import-sorts --safe #-}\n\nmodule Cubical.Algebra.Group.EilenbergMacLane1 where\n\nopen import Cubical.Foundations.Prelude\nopen import Cubical.Foundations.Isomorphism\nopen import Cubical.Foundations.Equiv\nopen import Cubical.Foundations.Equiv.HalfAdjoint\nopen import Cubical.Foundations.GroupoidLaws renaming (assoc to \u2219assoc)\nopen import Cubical.Foundations.Path\nopen import Cubical.Foundations.HLevels\nopen import Cubical.Foundations.Transport\nopen import Cubical.Foundations.Univalence\nopen import Cubical.Foundations.SIP\nopen import Cubical.Data.Unit\nopen import Cubical.Data.Sigma\nopen import Cubical.Relation.Binary.Base\nopen import Cubical.Structures.Axioms\nopen import Cubical.Structures.Auto\nopen import Cubical.Algebra.Group.Base\nopen import Cubical.Algebra.Group.Properties\nopen import Cubical.Homotopy.Connected\nopen import Cubical.HITs.Nullification as Null hiding (rec; elim)\nopen import Cubical.HITs.Truncation.FromNegOne as Trunc renaming (rec to trRec; elim to trElim)\nopen import Cubical.HITs.EilenbergMacLane1\n\nprivate\n variable \u2113 : Level\n\nmodule _ (G : Group {\u2113}) where\n\n open Group G\n\n emloop-id : emloop 0g \u2261 refl\n emloop-id =\n -- emloop 0g \u2261\u27e8 rUnit (emloop 0g) \u27e9\n emloop 0g \u2261\u27e8 rUnit (emloop 0g) \u27e9\n emloop 0g \u2219 refl \u2261\u27e8 cong (emloop 0g \u2219_) (rCancel (emloop 0g) \u207b\u00b9) \u27e9\n emloop 0g \u2219 (emloop 0g \u2219 (emloop 0g) \u207b\u00b9) \u2261\u27e8 \u2219assoc _ _ _ \u27e9\n (emloop 0g \u2219 emloop 0g) \u2219 (emloop 0g) \u207b\u00b9 \u2261\u27e8 cong (_\u2219 emloop 0g \u207b\u00b9) ((emloop-comp G 0g 0g) \u207b\u00b9) \u27e9\n emloop (0g + 0g) \u2219 (emloop 0g) \u207b\u00b9 \u2261\u27e8 cong (\u03bb g \u2192 emloop {G = G} g \u2219 (emloop 0g) \u207b\u00b9) (rid 0g) \u27e9\n emloop 0g \u2219 (emloop 0g) \u207b\u00b9 \u2261\u27e8 rCancel (emloop 0g) \u27e9\n refl \u220e\n\n emloop-inv : (g : Carrier) \u2192 emloop (- g) \u2261 (emloop g) \u207b\u00b9\n emloop-inv g =\n emloop (- g) \u2261\u27e8 rUnit (emloop (- g)) \u27e9\n emloop (- g) \u2219 refl \u2261\u27e8 cong (emloop (- g) \u2219_) (rCancel (emloop g) \u207b\u00b9) \u27e9\n emloop (- g) \u2219 (emloop g \u2219 (emloop g) \u207b\u00b9) \u2261\u27e8 \u2219assoc _ _ _ \u27e9\n (emloop (- g) \u2219 emloop g) \u2219 (emloop g) \u207b\u00b9 \u2261\u27e8 cong (_\u2219 emloop g \u207b\u00b9) ((emloop-comp G (- g) g) \u207b\u00b9) \u27e9\n emloop (- g + g) \u2219 (emloop g) \u207b\u00b9 \u2261\u27e8 cong (\u03bb h \u2192 emloop {G = G} h \u2219 (emloop g) \u207b\u00b9) (invl g) \u27e9\n emloop 0g \u2219 (emloop g) \u207b\u00b9 \u2261\u27e8 cong (_\u2219 (emloop g) \u207b\u00b9) emloop-id \u27e9\n refl \u2219 (emloop g) \u207b\u00b9 \u2261\u27e8 (lUnit ((emloop g) \u207b\u00b9)) \u207b\u00b9 \u27e9\n (emloop g) \u207b\u00b9 \u220e\n\n EM\u2081Groupoid : isGroupoid (EM\u2081 G)\n EM\u2081Groupoid = emsquash\n\n EM\u2081Connected : isConnected 2 (EM\u2081 G)\n EM\u2081Connected = \u2223 embase \u2223 , h\n where\n h : (y : hLevelTrunc 2 (EM\u2081 G)) \u2192 \u2223 embase \u2223 \u2261 y\n h = trElim (\u03bb y \u2192 isOfHLevelSuc 1 (isOfHLevelTrunc 2 \u2223 embase \u2223 y))\n (elimProp G (\u03bb x \u2192 isOfHLevelTrunc 2 \u2223 embase \u2223 \u2223 x \u2223) refl)\n\n {- since we write composition in diagrammatic order,\n and function composition in the other order,\n we need right multiplication here -}\n rightEquiv : (g : Carrier) \u2192 Carrier \u2243 Carrier\n rightEquiv g = isoToEquiv (iso (_+ g) (_+ - g)\n (\u03bb h \u2192 (h + - g) + g \u2261\u27e8 (assoc h (- g) g) \u207b\u00b9 \u27e9\n h + - g + g \u2261\u27e8 cong (h +_) (invl g) \u27e9\n h + 0g \u2261\u27e8 rid h \u27e9 h \u220e)\n \u03bb h \u2192 (h + g) + - g \u2261\u27e8 (assoc h g (- g)) \u207b\u00b9 \u27e9\n h + g + - g \u2261\u27e8 cong (h +_) (invr g) \u27e9\n h + 0g \u2261\u27e8 rid h \u27e9 h \u220e)\n\n compRightEquiv : (g h : Carrier)\n \u2192 compEquiv (rightEquiv g) (rightEquiv h) \u2261 rightEquiv (g + h)\n compRightEquiv g h = equivEq _ _ (funExt (\u03bb x \u2192 (assoc x g h) \u207b\u00b9))\n\n CodesSet : EM\u2081 G \u2192 hSet \u2113\n CodesSet = rec G (isOfHLevelTypeOfHLevel 2) (Carrier , is-set) RE REComp\n where\n RE : (g : Carrier) \u2192 Path (hSet \u2113) (Carrier , is-set) (Carrier , is-set)\n RE g = \u03a3\u2261Prop (\u03bb X \u2192 isPropIsOfHLevel {A = X} 2) (ua (rightEquiv g))\n\n lemma\u2081 : (g h : Carrier) \u2192 Square\n (ua (rightEquiv g)) (ua (rightEquiv (g + h)))\n refl (ua (rightEquiv h))\n lemma\u2081 g h = invEq\n (Square\u2243doubleComp (ua (rightEquiv g)) (ua (rightEquiv (g + h)))\n refl (ua (rightEquiv h)))\n (ua (rightEquiv g) \u2219 ua (rightEquiv h)\n \u2261\u27e8 (uaCompEquiv (rightEquiv g) (rightEquiv h)) \u207b\u00b9 \u27e9\n ua (compEquiv (rightEquiv g) (rightEquiv h))\n \u2261\u27e8 cong ua (compRightEquiv g h) \u27e9\n ua (rightEquiv (g + h)) \u220e)\n\n lemma\u2082 : {A\u2080\u2080 A\u2080\u2081 : hSet \u2113} (p\u2080\u208b : A\u2080\u2080 \u2261 A\u2080\u2081)\n {A\u2081\u2080 A\u2081\u2081 : hSet \u2113} (p\u2081\u208b : A\u2081\u2080 \u2261 A\u2081\u2081)\n (p\u208b\u2080 : A\u2080\u2080 \u2261 A\u2081\u2080) (p\u208b\u2081 : A\u2080\u2081 \u2261 A\u2081\u2081)\n (s : Square (cong fst p\u2080\u208b) (cong fst p\u2081\u208b) (cong fst p\u208b\u2080) (cong fst p\u208b\u2081))\n \u2192 Square p\u2080\u208b p\u2081\u208b p\u208b\u2080 p\u208b\u2081\n fst (lemma\u2082 p\u2080\u208b p\u2081\u208b p\u208b\u2080 p\u208b\u2081 s i j) = s i j\n snd (lemma\u2082 p\u2080\u208b p\u2081\u208b p\u208b\u2080 p\u208b\u2081 s i j) =\n isSet\u2192isSetDep (\u03bb X \u2192 isProp\u2192isSet (isPropIsOfHLevel {A = X} 2))\n (cong fst p\u2080\u208b) (cong fst p\u2081\u208b) (cong fst p\u208b\u2080) (cong fst p\u208b\u2081) s\n (cong snd p\u2080\u208b) (cong snd p\u2081\u208b) (cong snd p\u208b\u2080) (cong snd p\u208b\u2081) i j\n\n REComp : (g h : Carrier) \u2192 Square (RE g) (RE (g + h)) refl (RE h)\n REComp g h = lemma\u2082 (RE g) (RE (g + h)) refl (RE h) (lemma\u2081 g h)\n\n\n Codes : EM\u2081 G \u2192 Type \u2113\n Codes x = CodesSet x .fst\n\n encode : (x : EM\u2081 G) \u2192 embase \u2261 x \u2192 Codes x\n encode x p = subst Codes p 0g\n\n decode : (x : EM\u2081 G) \u2192 Codes x \u2192 embase \u2261 x\n decode = elimSet G (\u03bb x \u2192 isOfHLevel\u03a0 2 (\u03bb c \u2192 EM\u2081Groupoid (embase) x))\n emloop lem\u2082\n where\n module _ (g : Carrier) where\n lem\u2081 : (h : Carrier) \u2192 PathP (\u03bb i \u2192 embase \u2261 emloop g i) (emloop h) (emloop (h + g))\n lem\u2081 h = emcomp h g\n lem\u2082 : PathP (\u03bb i \u2192 Codes (emloop g i) \u2192 embase \u2261 emloop g i) emloop emloop\n lem\u2082 = ua\u2192 {A\u2080 = Carrier} {A\u2081 = Carrier} {e = rightEquiv g} lem\u2081\n\n decode-encode : (x : EM\u2081 G) (p : embase \u2261 x) \u2192 decode x (encode x p) \u2261 p\n decode-encode x p = J (\u03bb y q \u2192 decode y (encode y q) \u2261 q)\n (emloop (transport refl 0g) \u2261\u27e8 cong emloop (transportRefl 0g) \u27e9\n emloop 0g \u2261\u27e8 emloop-id \u27e9 refl \u220e) p\n\n encode-decode : (x : EM\u2081 G) (c : Codes x) \u2192 encode x (decode x c) \u2261 c\n encode-decode = elimProp G (\u03bb x \u2192 isOfHLevel\u03a0 1 (\u03bb c \u2192 CodesSet x .snd _ _))\n \u03bb g \u2192 encode embase (decode embase g) \u2261\u27e8 refl \u27e9\n encode embase (emloop g) \u2261\u27e8 refl \u27e9\n transport (ua (rightEquiv g)) 0g \u2261\u27e8 ua\u03b2 (rightEquiv g) 0g \u27e9\n 0g + g \u2261\u27e8 lid g \u27e9\n g \u220e\n\n \u03a9EM\u2081Iso : Iso (Path (EM\u2081 G) embase embase) Carrier\n Iso.fun \u03a9EM\u2081Iso = encode embase\n Iso.inv \u03a9EM\u2081Iso = emloop\n Iso.rightInv \u03a9EM\u2081Iso = encode-decode embase\n Iso.leftInv \u03a9EM\u2081Iso = decode-encode embase\n\n \u03a9EM\u2081\u2261 : (Path (EM\u2081 G) embase embase) \u2261 Carrier\n \u03a9EM\u2081\u2261 = isoToPath \u03a9EM\u2081Iso\n","avg_line_length":42.0,"max_line_length":101,"alphanum_fraction":0.5825501253} {"size":1706,"ext":"agda","lang":"Agda","max_stars_count":30.0,"content":"{-# OPTIONS --without-K --safe #-}\n\nopen import Definition.Typed.EqualityRelation\n\nmodule Definition.LogicalRelation.Properties.Universe {{eqrel : EqRelSet}} where\nopen EqRelSet {{...}}\n\nopen import Definition.Untyped hiding (_\u2237_)\nopen import Definition.Typed\nopen import Definition.LogicalRelation\nopen import Definition.LogicalRelation.ShapeView\nopen import Definition.LogicalRelation.Irrelevance\n\nopen import Tools.Nat\n\nprivate\n variable\n n : Nat\n \u0393 : Con Term n\n\n-- Helper function for reducible terms of type U for specific type derivations.\nunivEq\u2032 : \u2200 {l A} ([U] : \u0393 \u22a9\u27e8 l \u27e9U) \u2192 \u0393 \u22a9\u27e8 l \u27e9 A \u2237 U \/ U-intr [U] \u2192 \u0393 \u22a9\u27e8 \u2070 \u27e9 A\nunivEq\u2032 (noemb (U\u1d63 .\u2070 0<1 \u22a2\u0393)) (U\u209c A\u2081 d typeA A\u2261A [A]) = [A]\nunivEq\u2032 (emb 0<1 x) [A] = univEq\u2032 x [A]\n\n-- Reducible terms of type U are reducible types.\nunivEq : \u2200 {l A} ([U] : \u0393 \u22a9\u27e8 l \u27e9 U) \u2192 \u0393 \u22a9\u27e8 l \u27e9 A \u2237 U \/ [U] \u2192 \u0393 \u22a9\u27e8 \u2070 \u27e9 A\nunivEq [U] [A] = univEq\u2032 (U-elim [U])\n (irrelevanceTerm [U] (U-intr (U-elim [U])) [A])\n\n-- Helper function for reducible term equality of type U for specific type derivations.\nunivEqEq\u2032 : \u2200 {l l\u2032 A B} ([U] : \u0393 \u22a9\u27e8 l \u27e9U) ([A] : \u0393 \u22a9\u27e8 l\u2032 \u27e9 A)\n \u2192 \u0393 \u22a9\u27e8 l \u27e9 A \u2261 B \u2237 U \/ U-intr [U]\n \u2192 \u0393 \u22a9\u27e8 l\u2032 \u27e9 A \u2261 B \/ [A]\nunivEqEq\u2032 (noemb (U\u1d63 .\u2070 0<1 \u22a2\u0393)) [A]\n (U\u209c\u208c A\u2081 B\u2081 d d\u2032 typeA typeB A\u2261B [t] [u] [t\u2261u]) =\n irrelevanceEq [t] [A] [t\u2261u]\nunivEqEq\u2032 (emb 0<1 x) [A] [A\u2261B] = univEqEq\u2032 x [A] [A\u2261B]\n\n-- Reducible term equality of type U is reducible type equality.\nunivEqEq : \u2200 {l l\u2032 A B} ([U] : \u0393 \u22a9\u27e8 l \u27e9 U) ([A] : \u0393 \u22a9\u27e8 l\u2032 \u27e9 A)\n \u2192 \u0393 \u22a9\u27e8 l \u27e9 A \u2261 B \u2237 U \/ [U]\n \u2192 \u0393 \u22a9\u27e8 l\u2032 \u27e9 A \u2261 B \/ [A]\nunivEqEq [U] [A] [A\u2261B] =\n let [A\u2261B]\u2032 = irrelevanceEqTerm [U] (U-intr (U-elim [U])) [A\u2261B]\n in univEqEq\u2032 (U-elim [U]) [A] [A\u2261B]\u2032\n","avg_line_length":36.2978723404,"max_line_length":87,"alphanum_fraction":0.5644783118} {"size":24693,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-\nJoseph Eremondi\nUtrecht University Capita Selecta\nUU# 4229924\nJuly 22, 2015\n-}\n\nmodule SemiLinRE where\n\nopen import Data.Vec\nopen import Data.Nat\nimport Data.Fin as Fin\n\nopen import Data.List\nimport Data.List.All\nopen import Data.Bool\nopen import Data.Char\n\nopen import Data.Maybe\n\nopen import Data.Product\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality\n\nopen import Relation.Nullary\nopen import Relation.Nullary.Decidable\nopen import Relation.Binary.Core\n\nopen import Category.Monad\n\nopen import Data.Nat.Properties.Simple\n\nopen import Data.Maybe\nopen import Relation.Binary.PropositionalEquality\nopen \u2261-Reasoning\n\nopen import Utils\n\nopen import Function\n\nimport RETypes\n\nopen import Data.Sum\n\nopen import SemiLin\n\nopen import Data.Vec.Equality\nopen import Data.Nat.Properties.Simple\n\n\nmodule VecNatEq = Data.Vec.Equality.DecidableEquality (Relation.Binary.PropositionalEquality.decSetoid Data.Nat._\u225f_)\n\n\n--Find the Parikh vector of a given word\n--Here cmap is the mapping of each character to its position\n--in the Parikh vector\nwordParikh : {n : \u2115} -> (Char -> Fin.Fin n) -> (w : List Char) -> Parikh n\nwordParikh cmap [] = v0\nwordParikh cmap (x \u2237 w) = (basis (cmap x)) +v (wordParikh cmap w)\n\n--Show that the Parikh of concatenating two words\n--Is the sum of their Parikhs\nwordParikhPlus : {n : \u2115} \n -> (cmap : Char -> Fin.Fin n) \n -> (u : List Char) \n -> (v : List Char)\n -> wordParikh cmap (u Data.List.++ v) \u2261 (wordParikh cmap u) +v (wordParikh cmap v)\nwordParikhPlus cmap [] v = sym v0identLeft\nwordParikhPlus {n} cmap (x \u2237 u) v = \n begin\n basis (cmap x) +v wordParikh cmap (u ++l v)\n \u2261\u27e8 cong (\u03bb y \u2192 basis (cmap x) +v y) (wordParikhPlus cmap u v) \u27e9 \n basis (cmap x) +v (wordParikh cmap u +v wordParikh cmap v) \n \u2261\u27e8 sym vAssoc \u27e9 \n ((basis (cmap x) +v wordParikh cmap u) +v wordParikh cmap v \u220e)\n where\n _++l_ = Data.List._++_\n \n\n\n--The algorithm mapping regular expressions to the Parikh set of\n--the language matched by the RE\n--We prove this correct below\nreSemiLin : {n : \u2115} {null? : RETypes.Null?} -> (Char -> Fin.Fin n) -> RETypes.RE null? -> SemiLinSet n \nreSemiLin cmap RETypes.\u03b5 = Data.List.[ v0 , 0 , [] ]\nreSemiLin cmap RETypes.\u2205 = []\nreSemiLin cmap (RETypes.Lit x) = Data.List.[ basis (cmap x ) , 0 , [] ]\nreSemiLin cmap (r1 RETypes.+ r2) = reSemiLin cmap r1 Data.List.++ reSemiLin cmap r2\nreSemiLin cmap (r1 RETypes.\u00b7 r2) = reSemiLin cmap r1 +s reSemiLin cmap r2\nreSemiLin cmap (r RETypes.*) = starSemiLin (reSemiLin cmap r)\n\n\n\n{-\nShow that s* \u2286 s +v s*\nNot implemented due to time restrictions,\nbut should be possible, given that linStarExtend is implemented\nin SemiLin.agda\n-}\nstarExtend \n : {n : \u2115}\n -> (v1 v2 : Parikh n )\n -> ( s ss : SemiLinSet n)\n -> ss \u2261 starSemiLin s\n -> InSemiLin v1 s\n -> InSemiLin v2 ss\n -> InSemiLin (v1 +v v2) (starSemiLin s)\nstarExtend v1 v2 s ss spf inS inSS = {!!}\n\n{-\nShow that s* \u2287 s +v s*\nNot completely implemented due to time restrictions,\nbut should be possible, given that linStarDecomp is implemented\nin SemiLin.agda.\n\nThere are also some hard parts, for example, dealing with the proofs\nthat the returned vectors are non-zero (otherwise, we'd just trivially return v0 and v)\n-}\nstarDecomp\n : {n : \u2115}\n -> (v : Parikh n)\n -> (s ss : SemiLinSet n)\n -> v \u2262 v0\n -> ss \u2261 starSemiLin s\n -> InSemiLin v ss\n -> (\u2203 \u03bb v1 -> \u2203 \u03bb v2 -> v1 +v v2 \u2261 v \u00d7 InSemiLin v1 s \u00d7 InSemiLin v2 ss \u00d7 v1 \u2262 v0 ) \nstarDecomp v s ss vpf spf inSemi = {!!}\n{-\nstarDecomp v sh st .(sh \u2237 st) .((v0 , 0 , []) \u2237 starSum sh st \u2237 []) vnz refl refl (InHead .v .(v0 , 0 , []) .(starSum sh st \u2237 []) x) with emptyCombZero v x | vnz (emptyCombZero v x)\nstarDecomp .v0 sh st .(sh \u2237 st) .((v0 , zero , []) \u2237 [] Data.List.++ starSum sh st \u2237 []) vnz refl refl (InHead .v0 .(v0 , zero , []) .(starSum sh st \u2237 []) x) | refl | ()\nstarDecomp v sh [] .(sh \u2237 []) .((v0 , 0 , []) \u2237 (proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) \u2237 []) vnz refl refl (InTail .v .(v0 , 0 , []) .((proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) \u2237 []) (InHead .v .(proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) .[] starComb)) with linStarDecomp v sh _ vnz {!!} refl starComb\nstarDecomp v sh [] .(sh \u2237 []) .((v0 , zero , []) \u2237 [] Data.List.++ starSum sh [] \u2237 []) vnz refl refl (InTail .v .(v0 , zero , []) .(starSum sh [] \u2237 []) (InHead .v .(proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) .[] starComb)) | inj\u2081 lComb = v , v0 , v0identRight , InHead v sh [] lComb , InHead v0 (v0 , zero , []) _ (v0 , refl) , vnz\nstarDecomp v sh [] .(sh \u2237 []) .((v0 , zero , []) \u2237 [] Data.List.++ starSum sh [] \u2237 []) vnz refl refl (InTail .v .(v0 , zero , []) .(starSum sh [] \u2237 []) (InHead .v .(proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) .[] starComb)) | inj\u2082 (v1 , v2 , sumPf , comb1 , comb2 , zpf ) = v1 , v2 , sumPf , InHead v1 sh [] comb1 , InTail v2 (v0 , zero , []) _ (InHead v2 _ [] comb2) , zpf\nstarDecomp v sh [] .(sh \u2237 []) .((v0 , 0 , []) \u2237 (proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) \u2237 []) vnz refl refl (InTail .v .(v0 , 0 , []) .((proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) \u2237 []) (InTail .v .(proj\u2081 sh , suc (proj\u2081 (proj\u2082 sh)) , proj\u2081 sh \u2237 proj\u2082 (proj\u2082 sh)) .[] ()))\nstarDecomp v sh (x \u2237 st) .(sh \u2237 x \u2237 st) .((v0 , 0 , []) \u2237 (proj\u2081 x +v proj\u2081 (starSum sh st) , suc (proj\u2081 (proj\u2082 x) + proj\u2081 (proj\u2082 (starSum sh st))) , proj\u2081 x \u2237 proj\u2082 (proj\u2082 x) Data.Vec.++ proj\u2082 (proj\u2082 (starSum sh st))) \u2237 []) vnz refl refl (InTail .v .(v0 , 0 , []) .((proj\u2081 x +v proj\u2081 (starSum sh st) , suc (proj\u2081 (proj\u2082 x) + proj\u2081 (proj\u2082 (starSum sh st))) , proj\u2081 x \u2237 proj\u2082 (proj\u2082 x) Data.Vec.++ proj\u2082 (proj\u2082 (starSum sh st))) \u2237 []) inSemi) = {!!} -}\n\n\n\n\n--Stolen from the stdlib\nlistIdentity : {A : Set} -> (x : List A) -> (x Data.List.++ [] ) \u2261 x\nlistIdentity [] = refl\nlistIdentity (x \u2237 xs) = cong (_\u2237_ x) (listIdentity xs)\n\n\n{-\nShow that +s is actually the sum of two sets, that is,\nif v1 is in S1, and v2 is in S2, then v1 +v v2\nis in S1 +s S2\n-}\nsumPreserved : \n {n : \u2115} \n -> (u : Parikh n) \n -> (v : Parikh n)\n -- -> (uv : Parikh n)\n -> (su : SemiLinSet n) \n -> (sv : SemiLinSet n)\n -- -> (suv : SemiLinSet n)\n -- -> (uv \u2261 u +v v)\n -- -> (suv \u2261 su +s sv)\n -> InSemiLin u su\n -> InSemiLin v sv\n -> InSemiLin (u +v v) (su +s sv)\nsumPreserved u v .((ub , um , uvecs) \u2237 st) .((vb , vm , vvecs) \u2237 st\u2081) (InHead .u (ub , um , uvecs) st (uconsts , upf)) (InHead .v (vb , vm , vvecs) st\u2081 (vconsts , vpf))\n rewrite upf | vpf \n = InHead (u +v v) (ub +v vb , um + vm , uvecs Data.Vec.++ vvecs) (Data.List.map (_+l_ (ub , um , uvecs)) st\u2081 Data.List.++\n Data.List.foldr Data.List._++_ []\n (Data.List.map\n (\u03bb z \u2192 z +l (vb , vm , vvecs) \u2237 Data.List.map (_+l_ z) st\u2081) st)) \n ((uconsts Data.Vec.++ vconsts) , trans (combSplit ub vb um vm uvecs vvecs uconsts vconsts) \n (sym (subst (\u03bb x \u2192 u +v v \u2261 x +v applyLinComb vb vm vvecs vconsts) (sym upf) (cong (\u03bb x \u2192 u +v x) (sym vpf)))) )\n\nsumPreserved u v .(sh \u2237 st) .(sh\u2081 \u2237 st\u2081) (InHead .u sh st x) (InTail .v sh\u2081 st\u2081 vIn) = \n let\n subCall1 : InSemiLin (u +v v) ((sh \u2237 []) +s st\u2081)\n subCall1 = sumPreserved u v (sh \u2237 []) ( st\u2081) (InHead u sh [] x) vIn\n \n\n eqTest : (sh \u2237 []) +s ( st\u2081) \u2261 Data.List.map (\u03bb l2 \u2192 sh +l l2) st\u2081\n eqTest = \n begin \n (sh \u2237 []) +s (st\u2081) \n \u2261\u27e8 refl \u27e9 \n Data.List.map (\u03bb l2 \u2192 sh +l l2) ( st\u2081) Data.List.++ [] \n \u2261\u27e8 listIdentity (Data.List.map (_+l_ sh) st\u2081) \u27e9 \n Data.List.map (\u03bb l2 \u2192 sh +l l2) (st\u2081) \n \u2261\u27e8 refl \u27e9 \n (Data.List.map (\u03bb l2 \u2192 sh +l l2) st\u2081 \u220e)\n \n newCall = slExtend (u +v v) (Data.List.map (_+l_ sh) st\u2081) (subst (InSemiLin (u +v v)) eqTest subCall1) (sh +l sh\u2081) -- \n in slConcatRight (u +v v) (Data.List.map (\u03bb l2 \u2192 sh +l l2) (sh\u2081 \u2237 st\u2081)) newCall (Data.List.foldr Data.List._++_ []\n (Data.List.map (\u03bb z \u2192 z +l sh\u2081 \u2237 Data.List.map (_+l_ z) st\u2081) st))\nsumPreserved u v .(sh \u2237 st) sv (InTail .u sh st uIn) vIn = \n (slConcatLeft (u +v v) (st +s sv) (sumPreserved u v st sv uIn vIn) (Data.List.map (\u03bb x \u2192 sh +l x) sv)) \n\n\n--A useful lemma, avoids having to dig into the List monoid instance\nrightCons : {A : Set} -> (l : List A) -> (l Data.List.++ [] \u2261 l)\nrightCons [] = refl\nrightCons (x \u2237 l) rewrite rightCons l = refl\n\n\n\n\n{-\nShow that, if a vector is in the union of two semi-linear sets,\nthen it must be in one of those sets.\nUsed in the proof for Union.\nCalled concat because we represent semi-linear sets as lists,\nso union is just concatenating two semi-linear sets\n-}\ndecomposeConcat \n : {n : \u2115} \n -> (v : Parikh n) \n -> (s1 s2 s3 : SemiLinSet n) \n -> (s3 \u2261 s1 Data.List.++ s2 ) \n -> InSemiLin v s3 \n -> InSemiLin v s1 \u228e InSemiLin v s2\ndecomposeConcat v [] s2 .s2 refl inSemi = inj\u2082 inSemi\ndecomposeConcat v (x \u2237 s1) s2 .(x \u2237 s1 Data.List.++ s2) refl (InHead .v .x .(s1 Data.List.++ s2) x\u2081) = inj\u2081 (InHead v x s1 x\u2081)\ndecomposeConcat v (x \u2237 s1) s2 .(x \u2237 s1 Data.List.++ s2) refl (InTail .v .x .(s1 Data.List.++ s2) inSemi) with decomposeConcat v s1 s2 _ refl inSemi\ndecomposeConcat v (x\u2081 \u2237 s1) s2 .(x\u2081 \u2237 s1 Data.List.++ s2) refl (InTail .v .x\u2081 .(s1 Data.List.++ s2) inSemi) | inj\u2081 x = inj\u2081 (InTail v x\u2081 s1 x)\ndecomposeConcat v (x \u2237 s1) s2 .(x \u2237 s1 Data.List.++ s2) refl (InTail .v .x .(s1 Data.List.++ s2) inSemi) | inj\u2082 y = inj\u2082 y\n\nconcatEq : {n : \u2115} -> (l : LinSet n) -> (s : SemiLinSet n) -> (l \u2237 []) +s s \u2261 (Data.List.map (_+l_ l) s)\nconcatEq l [] = refl\nconcatEq l (x \u2237 s) rewrite concatEq l s | listIdentity (l \u2237 []) = refl \n\n\n{-\nShow that if v is in l1 +l l2, then v = v1 +v v2 for some\nv1 in l1 and v2 in l2.\nThis is the other half of the correcness proof of our sum functions, +l and +s\n-}\ndecomposeLin\n : {n : \u2115} \n -> (v : Parikh n) \n -> (l1 l2 l3 : LinSet n) \n -> (l3 \u2261 l1 +l l2 ) \n -> LinComb v l3 \n -> \u2203 \u03bb v1 \u2192 \u2203 \u03bb v2 -> (v1 +v v2 \u2261 v) \u00d7 (LinComb v1 l1) \u00d7 (LinComb v2 l2 )\ndecomposeLin .(applyLinComb (b1 +v b2) (m1 + m2) (vecs1 Data.Vec.++ vecs2) coeffs) (b1 , m1 , vecs1) (b2 , m2 , vecs2) .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) refl (coeffs , refl) with Data.Vec.splitAt m1 coeffs \ndecomposeLin .(applyLinComb (b1 +v b2) (m1 + m2) (vecs1 Data.Vec.++ vecs2) (coeffs1 Data.Vec.++ coeffs2)) (b1 , m1 , vecs1) (b2 , m2 , vecs2) .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) refl (.(coeffs1 Data.Vec.++ coeffs2) , refl) | coeffs1 , coeffs2 , refl rewrite combSplit b1 b2 m1 m2 vecs1 vecs2 coeffs1 coeffs2 \n = applyLinComb b1 m1 vecs1 coeffs1 , (applyLinComb b2 m2 vecs2 coeffs2 , (refl , ((coeffs1 , refl) , (coeffs2 , refl))))\n\n\n\n\n{-\nShow that our Parikh function is a superset of the actual Parikh image of a Regular Expression.\n\nWe do this by showing that, for every word matching an RE, its Parikh vector\nis in the Parikh Image of the RE\n-}\nreParikhCorrect : \n {n : \u2115} \n -> {null? : RETypes.Null?} \n -> (cmap : Char -> Fin.Fin n) \n -> (r : RETypes.RE null?) \n -> (w : List Char ) \n -> RETypes.REMatch w r\n -> (wordPar : Parikh n)\n -> (wordParikh cmap w \u2261 wordPar)\n -> (langParikh : SemiLinSet n)\n -> (langParikh \u2261 reSemiLin cmap r )\n -> (InSemiLin wordPar langParikh ) \nreParikhCorrect cmap .RETypes.\u03b5 .[] RETypes.EmptyMatch .v0 refl .((v0 , 0 , []) \u2237 []) refl = InHead v0 (v0 , zero , []) [] ([] , refl) \nreParikhCorrect cmap .(RETypes.Lit c) .(c \u2237 []) (RETypes.LitMatch c) .(basis (cmap c) +v v0) refl .((basis (cmap c) , 0 , []) \u2237 []) refl = \n InHead (basis (cmap c) +v v0) (basis (cmap c) , zero , []) [] (subst (\u03bb x \u2192 LinComb x (basis (cmap c) , zero , [])) (sym v0identRight) (v0 , (v0apply (basis (cmap c)) []))) \nreParikhCorrect cmap (r1 RETypes.+ .r2) w (RETypes.LeftPlusMatch r2 match) wordPar wpf langParikh lpf =\n let\n leftParikh = reSemiLin cmap r1\n leftInSemi = reParikhCorrect cmap r1 w match wordPar wpf leftParikh refl\n --Idea: show that langParikh is leftParikh ++ rightParikh\n --And that this means that it must be in the concatentation\n extendToConcat : InSemiLin wordPar ((reSemiLin cmap r1 ) Data.List.++ (reSemiLin cmap r2))\n extendToConcat = slConcatRight wordPar (reSemiLin cmap r1) leftInSemi (reSemiLin cmap r2)\n in subst (\u03bb x \u2192 InSemiLin wordPar x) (sym lpf) extendToConcat\nreParikhCorrect cmap (.r1 RETypes.+ r2) w (RETypes.RightPlusMatch r1 match) wordPar wpf langParikh lpf = let\n rightParikh = reSemiLin cmap r2\n rightInSemi = reParikhCorrect cmap r2 w match wordPar wpf rightParikh refl\n --Idea: show that langParikh is leftParikh ++ rightParikh\n --And that this means that it must be in the concatentation\n extendToConcat : InSemiLin wordPar ((reSemiLin cmap r1 ) Data.List.++ (reSemiLin cmap r2))\n extendToConcat = slConcatLeft wordPar (reSemiLin cmap r2) rightInSemi (reSemiLin cmap r1)\n in subst (\u03bb x \u2192 InSemiLin wordPar x) (sym lpf) extendToConcat\nreParikhCorrect cmap (r1 RETypes.\u00b7 r2) s3 (RETypes.ConcatMatch {s1 = s1} {s2 = s2} {spf = spf} match1 match2) .(wordParikh cmap s3) refl ._ refl rewrite (sym spf) | (wordParikhPlus cmap s1 s2) =\n let\n leftParikh = reSemiLin cmap r1\n leftInSemi : InSemiLin (wordParikh cmap s1) leftParikh\n leftInSemi = reParikhCorrect cmap r1 s1 match1 (wordParikh cmap s1) refl (reSemiLin cmap r1) refl \n\n rightParikh = reSemiLin cmap r2\n rightInSemi : InSemiLin (wordParikh cmap s2) rightParikh\n rightInSemi = reParikhCorrect cmap r2 s2 match2 (wordParikh cmap s2) refl (reSemiLin cmap r2) refl\n\n wordParikhIsPlus : (wordParikh cmap s1) +v (wordParikh cmap s2) \u2261 (wordParikh cmap (s1 Data.List.++ s2 )) \n wordParikhIsPlus = sym (wordParikhPlus cmap s1 s2)\n\n in sumPreserved (wordParikh cmap s1) (wordParikh cmap s2) leftParikh rightParikh leftInSemi rightInSemi\nreParikhCorrect cmap (r RETypes.*) [] RETypes.EmptyStarMatch .v0 refl .(starSemiLin (reSemiLin cmap r)) refl = zeroInStar (reSemiLin cmap r) (starSemiLin (reSemiLin cmap r)) refl\nreParikhCorrect cmap (r RETypes.*) .(s1 Data.List.++ s2 ) (RETypes.StarMatch {s1 = s1} {s2 = s2} {spf = refl} m1 m2) ._ refl .(starSemiLin (reSemiLin cmap r)) refl rewrite wordParikhPlus cmap s1 s2 = \n starExtend (wordParikh cmap s1) (wordParikh cmap s2) (reSemiLin cmap r) _ refl (reParikhCorrect cmap r s1 m1 (wordParikh cmap s1) refl (reSemiLin cmap r) refl) (reParikhCorrect cmap (r RETypes.*) s2 m2 (wordParikh cmap s2) refl (starSemiLin (reSemiLin cmap r)) refl) \n\n\n\n{-\nShow that if v is in s1 +s s2, then v = v1 +v v2 for some\nv1 in s1 and v2 in s2.\nThis is the other half of the correcness proof of our sum functions, +l and +s\n-}\ndecomposeSum \n : {n : \u2115} \n -> (v : Parikh n) \n -> (s1 s2 s3 : SemiLinSet n) \n -> (s3 \u2261 s1 +s s2 ) \n -> InSemiLin v s3 \n -> \u2203 \u03bb (v1 : Parikh n) \u2192 \u2203 \u03bb (v2 : Parikh n) -> (v1 +v v2 \u2261 v) \u00d7 (InSemiLin v1 s1) \u00d7 (InSemiLin v2 s2 )\ndecomposeSum v [] [] .[] refl ()\ndecomposeSum v [] (x \u2237 s2) .[] refl ()\ndecomposeSum v (x \u2237 s1) [] .(Data.List.foldr Data.List._++_ [] (Data.List.map (\u03bb l1 \u2192 []) s1)) refl ()\ndecomposeSum v ((b1 , m1 , vecs1) \u2237 s1) ((b2 , m2 , vecs2) \u2237 s2) ._ refl (InHead .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) ._ lcomb) =\n let\n (v1 , v2 , plusPf , comb1 , comb2 ) = decomposeLin v (b1 , m1 , vecs1) (b2 , m2 , vecs2) (b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) refl lcomb\n in v1 , v2 , plusPf , InHead v1 (b1 , m1 , vecs1) s1 comb1 , InHead v2 (b2 , m2 , vecs2) s2 comb2\ndecomposeSum v ((b1 , m1 , vecs1) \u2237 s1) ((b2 , m2 , vecs2) \u2237 s2) ._ refl (InTail .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) ._ inSemi) with decomposeConcat v (Data.List.map (_+l_ (b1 , m1 , vecs1)) s2) (Data.List.foldr Data.List._++_ []\n (Data.List.map\n (\u03bb z \u2192 z +l (b2 , m2 , vecs2) \u2237 Data.List.map (_+l_ z) s2) s1)) (Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++\n Data.List.foldr Data.List._++_ []\n (Data.List.map\n (\u03bb z \u2192 z +l (b2 , m2 , vecs2) \u2237 Data.List.map (_+l_ z) s2) s1)) refl inSemi\ndecomposeSum v ((b1 , m1 , vecs1) \u2237 s1) ((b2 , m2 , vecs2) \u2237 s2) .((b1 , m1 , vecs1) +l (b2 , m2 , vecs2) \u2237 Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) refl (InTail .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) .(Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) inSemi) | inj\u2081 inSub = \n let\n subCall1 = decomposeSum v ((b1 , m1 , vecs1) \u2237 []) s2 _ refl (subst (\u03bb x \u2192 InSemiLin v x) (sym (concatEq (b1 , m1 , vecs1) s2)) inSub)\n v1 , v2 , pf , xIn , yIn = subCall1\n in v1 , (v2 , (pf , (slCons v1 s1 (b1 , m1 , vecs1) xIn , slExtend v2 s2 yIn (b2 , m2 , vecs2))))\ndecomposeSum v ((b1 , m1 , vecs1) \u2237 s1) ((b2 , m2 , vecs2) \u2237 s2) .((b1 , m1 , vecs1) +l (b2 , m2 , vecs2) \u2237 Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) refl (InTail .v .(b1 +v b2 , m1 + m2 , vecs1 Data.Vec.++ vecs2) .(Data.List.map (_+l_ (b1 , m1 , vecs1)) s2 Data.List.++ Data.List.foldr Data.List._++_ [] (Data.List.map _ s1)) inSemi) | inj\u2082 inSub = \n let \n subCall1 = decomposeSum v s1 ((b2 , m2 , vecs2) \u2237 s2) _ refl inSub \n v1 , v2 , pf , xIn , yIn = subCall1\n in v1 , v2 , pf , slExtend v1 s1 xIn (b1 , m1 , vecs1) , yIn\n\n\n\n\n\n{-\nShow that the generated Parikh image is a subset of the actual Parikh image.\n\nWe do this by showing that, for every vector in the generated Parikh image,\nthere's some word matched by the RE whose Parikh vector is that vector.\n-}\n--We have to convince the compiler that this is terminating\n--Since I didn't have time to implement the proofs of non-zero vectors\n--Which show that we only recurse on strictly smaller vectors in the Star case\n{-# TERMINATING #-}\nreParikhComplete : {n : \u2115} -> {null? : RETypes.Null?}\n -> (cmap : Char -> Fin.Fin n)\n-- -> (imap : Fin.Fin n -> Char)\n-- -> (invPf1 : (x : Char ) -> imap (cmap x) \u2261 x)\n-- -> (invPf2 : (x : Fin.Fin n ) -> cmap (imap x) \u2261 x )\n -> (r : RETypes.RE null?)\n -> (v : Parikh n )\n -> (langParikh : SemiLinSet n)\n -> langParikh \u2261 (reSemiLin cmap r )\n -> (InSemiLin v langParikh )\n -> \u2203 (\u03bb w -> (v \u2261 wordParikh cmap w) \u00d7 (RETypes.REMatch w r) ) \nreParikhComplete cmap RETypes.\u03b5 .v0 .((v0 , 0 , []) \u2237 []) refl (InHead .v0 .(v0 , 0 , []) .[] (combConsts , refl)) = [] , refl , RETypes.EmptyMatch\nreParikhComplete cmap RETypes.\u03b5 v .((v0 , 0 , []) \u2237 []) refl (InTail .v .(v0 , 0 , []) .[] ())\n\n--reParikhComplete cmap RETypes.\u03b5 v .(sh \u2237 st) lpf (InTail .v sh st inSemi) = {!!}\nreParikhComplete cmap RETypes.\u2205 v [] lpf ()\nreParikhComplete cmap RETypes.\u2205 v (h \u2237 t) () inSemi \nreParikhComplete cmap (RETypes.Lit x) langParikh [] inSemi ()\nreParikhComplete cmap (RETypes.Lit x) .(basis (cmap x)) .((basis (cmap x) , 0 , []) \u2237 []) refl (InHead .(basis (cmap x)) .(basis (cmap x) , 0 , []) .[] (consts , refl)) = (x \u2237 []) , (sym v0identRight , RETypes.LitMatch x)\nreParikhComplete cmap (RETypes.Lit x) v .((basis (cmap x) , 0 , []) \u2237 []) refl (InTail .v .(basis (cmap x) , 0 , []) .[] ())\n--reParikhComplete cmap (RETypes.Lit x) v .((basis (cmap x) , 0 , []) \u2237 []) refl (InTail .v .(basis (cmap x) , 0 , []) .[] ())\nreParikhComplete {null? = null?} cmap (r1 RETypes.+ r2) v langParikh lpf inSemi with decomposeConcat v (reSemiLin cmap r1) (reSemiLin cmap r2) langParikh lpf inSemi\n... | inj\u2081 in1 = \n let\n (subw , subPf , subMatch) = reParikhComplete cmap r1 v (reSemiLin cmap r1) refl in1\n in subw , (subPf , (RETypes.LeftPlusMatch r2 subMatch))\n... | inj\u2082 in2 = \n let\n (subw , subPf , subMatch) = reParikhComplete cmap r2 v (reSemiLin cmap r2) refl in2\n in subw , (subPf , (RETypes.RightPlusMatch r1 subMatch))\nreParikhComplete cmap (r1 RETypes.\u00b7 r2) v ._ refl inSemi with decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2) (reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi | reParikhComplete cmap r1 (proj\u2081 (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)\n (reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi)) (reSemiLin cmap r1) refl (proj\u2081 (proj\u2082 (proj\u2082 (proj\u2082 (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)\n (reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi))))) | reParikhComplete cmap r2 (proj\u2081 (proj\u2082 (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)\n (reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi))) (reSemiLin cmap r2) refl (proj\u2082 (proj\u2082 (proj\u2082 (proj\u2082 (decomposeSum v (reSemiLin cmap r1) (reSemiLin cmap r2)\n (reSemiLin cmap r1 +s reSemiLin cmap r2) refl inSemi))))) \nreParikhComplete cmap (r1 RETypes.\u00b7 r2) .(wordParikh cmap w1 +v wordParikh cmap w2) .(Data.List.foldr Data.List._++_ [] (Data.List.map _ (reSemiLin cmap r1))) refl inSemi | .(wordParikh cmap w1) , .(wordParikh cmap w2) , refl , inSemi1 , inSemi2 | w1 , refl , match1 | w2 , refl , match2 = (w1 Data.List.++ w2) , ((sym (wordParikhPlus cmap w1 w2)) , (RETypes.ConcatMatch match1 match2))\n\nreParikhComplete cmap (r RETypes.*) v langParikh lpf inSemi with (reSemiLin cmap r )\nreParikhComplete cmap (r RETypes.*) v .((v0 , 0 , []) \u2237 []) refl (InHead .v .(v0 , 0 , []) .[] x) | [] = [] , ((sym (proj\u2082 x)) , RETypes.EmptyStarMatch)\nreParikhComplete cmap (r RETypes.*) v .((v0 , 0 , []) \u2237 []) refl (InTail .v .(v0 , 0 , []) .[] ()) | []\nreParikhComplete cmap (r RETypes.*) v .((v0 , 0 , []) \u2237 starSum x rsl \u2237 []) refl inSemi | x \u2237 rsl = \n let\n --The first hole is the non-zero proofs that I couldn't work out\n --I'm not totally sure about the second, but I think I just need to apply some associativity to inSemi to get it to fit\n --into the second hole. \n splitVec = starDecomp v (reSemiLin cmap r) _ {!!} refl {!!}\n v1 , v2 , vpf , inS , inSS , _ = splitVec\n subCall1 = reParikhComplete cmap r v1 _ refl inS\n w1 , wpf1 , match = subCall1\n subCall2 = reParikhComplete cmap (r RETypes.*) v2 _ refl inSS\n w2 , wpf2 , match2 = subCall2\n in (w1 Data.List.++ w2) , (trans (sym vpf) (sym (wordParikhPlus cmap w1 w2)) , RETypes.StarMatch match match2)\n\n","avg_line_length":60.2268292683,"max_line_length":590,"alphanum_fraction":0.5539221642} {"size":488,"ext":"agda","lang":"Agda","max_stars_count":6.0,"content":"open import Relation.Binary.Core\n\nmodule TreeSort.Impl1 {A : Set}\n (_\u2264_ : A \u2192 A \u2192 Set)\n (tot\u2264 : Total _\u2264_) where\n\nopen import BTree {A}\nopen import Data.List\nopen import Data.Sum\n\ninsert : A \u2192 BTree \u2192 BTree\ninsert x leaf = node x leaf leaf\ninsert x (node y l r) \n with tot\u2264 x y\n... | inj\u2081 x\u2264y = node y (insert x l) r\n... | inj\u2082 y\u2264x = node y l (insert x r)\n\ntreeSort : List A \u2192 BTree\ntreeSort [] = leaf\ntreeSort (x \u2237 xs) = insert x (treeSort xs)\n\n\n\n\n","avg_line_length":19.52,"max_line_length":43,"alphanum_fraction":0.5860655738} {"size":24698,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module bijection where\n\nopen import Level renaming ( zero to Zero ; suc to Suc )\nopen import Data.Nat\nopen import Data.Maybe\nopen import Data.List hiding ([_] ; sum )\nopen import Data.Nat.Properties\nopen import Relation.Nullary\nopen import Data.Empty\nopen import Data.Unit hiding ( _\u2264_ )\nopen import Relation.Binary.Core hiding (_\u21d4_)\nopen import Relation.Binary.Definitions\nopen import Relation.Binary.PropositionalEquality\n\nopen import logic\nopen import nat\n\n-- record Bijection {n m : Level} (R : Set n) (S : Set m) : Set (n Level.\u2294 m) where\n-- field\n-- fun\u2190 : S \u2192 R\n-- fun\u2192 : R \u2192 S\n-- fiso\u2190 : (x : R) \u2192 fun\u2190 ( fun\u2192 x ) \u2261 x \n-- fiso\u2192 : (x : S ) \u2192 fun\u2192 ( fun\u2190 x ) \u2261 x \n-- \n-- injection : {n m : Level} (R : Set n) (S : Set m) (f : R \u2192 S ) \u2192 Set (n Level.\u2294 m)\n-- injection R S f = (x y : R) \u2192 f x \u2261 f y \u2192 x \u2261 y\n\nopen Bijection \n\nbi-trans : {n m l : Level} (R : Set n) (S : Set m) (T : Set l) \u2192 Bijection R S \u2192 Bijection S T \u2192 Bijection R T\nbi-trans R S T rs st = record { fun\u2190 = \u03bb x \u2192 fun\u2190 rs ( fun\u2190 st x ) ; fun\u2192 = \u03bb x \u2192 fun\u2192 st ( fun\u2192 rs x )\n ; fiso\u2190 = \u03bb x \u2192 trans (cong (\u03bb k \u2192 fun\u2190 rs k) (fiso\u2190 st (fun\u2192 rs x))) ( fiso\u2190 rs x)\n ; fiso\u2192 = \u03bb x \u2192 trans (cong (\u03bb k \u2192 fun\u2192 st k) (fiso\u2192 rs (fun\u2190 st x))) ( fiso\u2192 st x) }\n\nbid : {n : Level} (R : Set n) \u2192 Bijection R R\nbid {n} R = record { fun\u2190 = \u03bb x \u2192 x ; fun\u2192 = \u03bb x \u2192 x ; fiso\u2190 = \u03bb _ \u2192 refl ; fiso\u2192 = \u03bb _ \u2192 refl } \n\nbi-sym : {n m : Level} (R : Set n) (S : Set m) \u2192 Bijection R S \u2192 Bijection S R\nbi-sym R S eq = record { fun\u2190 = fun\u2192 eq ; fun\u2192 = fun\u2190 eq ; fiso\u2190 = fiso\u2192 eq ; fiso\u2192 = fiso\u2190 eq } \n\nopen import Relation.Binary.Structures\n\nbijIsEquivalence : {n : Level } \u2192 IsEquivalence (Bijection {n} {n})\nbijIsEquivalence = record { refl = \u03bb {R} \u2192 bid R ; sym = \u03bb {R} {S} \u2192 bi-sym R S ; trans = \u03bb {R} {S} {T} \u2192 bi-trans R S T }\n\n-- \u00ac A = A \u2192 \u22a5 \n--\n-- famous diagnostic function\n--\n\ndiag : {S : Set } (b : Bijection ( S \u2192 Bool ) S) \u2192 S \u2192 Bool\ndiag b n = not (fun\u2190 b n n)\n\ndiagonal : { S : Set } \u2192 \u00ac Bijection ( S \u2192 Bool ) S\ndiagonal {S} b = diagn1 (fun\u2192 b (\u03bb n \u2192 diag b n) ) refl where\n diagn1 : (n : S ) \u2192 \u00ac (fun\u2192 b (\u03bb n \u2192 diag b n) \u2261 n ) \n diagn1 n dn = \u00act=f (diag b n ) ( begin\n not (diag b n)\n \u2261\u27e8\u27e9\n not (not fun\u2190 b n n)\n \u2261\u27e8 cong (\u03bb k \u2192 not (k n) ) (sym (fiso\u2190 b _)) \u27e9\n not (fun\u2190 b (fun\u2192 b (diag b)) n)\n \u2261\u27e8 cong (\u03bb k \u2192 not (fun\u2190 b k n) ) dn \u27e9\n not (fun\u2190 b n n)\n \u2261\u27e8\u27e9\n diag b n \n \u220e ) where open \u2261-Reasoning\n\nb1 : (b : Bijection ( \u2115 \u2192 Bool ) \u2115) \u2192 \u2115 \nb1 b = fun\u2192 b (diag b)\n\nb-iso : (b : Bijection ( \u2115 \u2192 Bool ) \u2115) \u2192 fun\u2190 b (b1 b) \u2261 (diag b)\nb-iso b = fiso\u2190 b _\n\n--\n-- \u2115 <=> \u2115 + 1\n--\nto1 : {n : Level} {R : Set n} \u2192 Bijection \u2115 R \u2192 Bijection \u2115 (\u22a4 \u2228 R )\nto1 {n} {R} b = record {\n fun\u2190 = to11\n ; fun\u2192 = to12\n ; fiso\u2190 = to13\n ; fiso\u2192 = to14\n } where\n to11 : \u22a4 \u2228 R \u2192 \u2115\n to11 (case1 tt) = 0\n to11 (case2 x) = suc ( fun\u2190 b x )\n to12 : \u2115 \u2192 \u22a4 \u2228 R\n to12 zero = case1 tt\n to12 (suc n) = case2 ( fun\u2192 b n)\n to13 : (x : \u2115) \u2192 to11 (to12 x) \u2261 x\n to13 zero = refl\n to13 (suc x) = cong suc (fiso\u2190 b x)\n to14 : (x : \u22a4 \u2228 R) \u2192 to12 (to11 x) \u2261 x\n to14 (case1 x) = refl\n to14 (case2 x) = cong case2 (fiso\u2192 b x)\n\n\nopen _\u2227_\n\nrecord NN ( i : \u2115) (nxn\u2192n : \u2115 \u2192 \u2115 \u2192 \u2115) (n\u2192nxn : \u2115 \u2192 \u2115 \u2227 \u2115) : Set where\n field\n j k sum stage : \u2115\n nn : j + k \u2261 sum\n ni : i \u2261 j + stage -- not used\n k1 : nxn\u2192n j k \u2261 i\n k0 : n\u2192nxn i \u2261 \u27ea j , k \u27eb \n nn-unique : {j0 k0 : \u2115 } \u2192 nxn\u2192n j0 k0 \u2261 i \u2192 \u27ea j , k \u27eb \u2261 \u27ea j0 , k0 \u27eb \n\ni\u22640\u2192i\u22610 : {i : \u2115 } \u2192 i \u2264 0 \u2192 i \u2261 0\ni\u22640\u2192i\u22610 {0} z\u2264n = refl\n\n\nnxn : Bijection \u2115 (\u2115 \u2227 \u2115)\nnxn = record {\n fun\u2190 = \u03bb p \u2192 nxn\u2192n (proj1 p) (proj2 p)\n ; fun\u2192 = n\u2192nxn \n ; fiso\u2190 = n-id\n ; fiso\u2192 = \u03bb x \u2192 nn-id (proj1 x) (proj2 x)\n } where\n nxn\u2192n : \u2115 \u2192 \u2115 \u2192 \u2115\n nxn\u2192n zero zero = zero\n nxn\u2192n zero (suc j) = j + suc (nxn\u2192n zero j)\n nxn\u2192n (suc i) zero = suc i + suc (nxn\u2192n i zero)\n nxn\u2192n (suc i) (suc j) = suc i + suc j + suc (nxn\u2192n i (suc j))\n n\u2192nxn : \u2115 \u2192 \u2115 \u2227 \u2115\n n\u2192nxn zero = \u27ea 0 , 0 \u27eb\n n\u2192nxn (suc i) with n\u2192nxn i\n ... | \u27ea x , zero \u27eb = \u27ea zero , suc x \u27eb\n ... | \u27ea x , suc y \u27eb = \u27ea suc x , y \u27eb\n\n nxn\u2192n0 : { j k : \u2115 } \u2192 nxn\u2192n j k \u2261 0 \u2192 ( j \u2261 0 ) \u2227 ( k \u2261 0 )\n nxn\u2192n0 {zero} {zero} eq = \u27ea refl , refl \u27eb\n nxn\u2192n0 {zero} {(suc k)} eq = \u22a5-elim ( nat-\u2261< (sym eq) (subst (\u03bb k \u2192 0 < k) (+-comm _ k) (s\u2264s z\u2264n)))\n nxn\u2192n0 {(suc j)} {zero} eq = \u22a5-elim ( nat-\u2261< (sym eq) (s\u2264s z\u2264n) )\n nxn\u2192n0 {(suc j)} {(suc k)} eq = \u22a5-elim ( nat-\u2261< (sym eq) (s\u2264s z\u2264n) )\n\n nid20 : (i : \u2115) \u2192 i + (nxn\u2192n 0 i) \u2261 nxn\u2192n i 0\n nid20 zero = refl -- suc (i + (i + suc (nxn\u2192n 0 i))) \u2261 suc (i + suc (nxn\u2192n i 0))\n nid20 (suc i) = begin\n suc (i + (i + suc (nxn\u2192n 0 i))) \u2261\u27e8 cong (\u03bb k \u2192 suc (i + k)) (sym (+-assoc i 1 (nxn\u2192n 0 i))) \u27e9\n suc (i + ((i + 1) + nxn\u2192n 0 i)) \u2261\u27e8 cong (\u03bb k \u2192 suc (i + (k + nxn\u2192n 0 i))) (+-comm i 1) \u27e9\n suc (i + suc (i + nxn\u2192n 0 i)) \u2261\u27e8 cong ( \u03bb k \u2192 suc (i + suc k)) (nid20 i) \u27e9\n suc (i + suc (nxn\u2192n i 0)) \u220e where open \u2261-Reasoning\n\n nid4 : {i j : \u2115} \u2192 i + 1 + j \u2261 i + suc j\n nid4 {zero} {j} = refl\n nid4 {suc i} {j} = cong suc (nid4 {i} {j} )\n nid5 : {i j k : \u2115} \u2192 i + suc (suc j) + suc k \u2261 i + suc j + suc (suc k )\n nid5 {zero} {j} {k} = begin\n suc (suc j) + suc k \u2261\u27e8 +-assoc 1 (suc j) _ \u27e9\n 1 + (suc j + suc k) \u2261\u27e8 +-comm 1 _ \u27e9\n (suc j + suc k) + 1 \u2261\u27e8 +-assoc (suc j) (suc k) _ \u27e9\n suc j + (suc k + 1) \u2261\u27e8 cong (\u03bb k \u2192 suc j + k ) (+-comm (suc k) 1) \u27e9\n suc j + suc (suc k) \u220e where open \u2261-Reasoning\n nid5 {suc i} {j} {k} = cong suc (nid5 {i} {j} {k} )\n\n -- increment in ths same stage\n nid2 : (i j : \u2115) \u2192 suc (nxn\u2192n i (suc j)) \u2261 nxn\u2192n (suc i) j \n nid2 zero zero = refl\n nid2 zero (suc j) = refl\n nid2 (suc i) zero = begin\n suc (nxn\u2192n (suc i) 1) \u2261\u27e8 refl \u27e9\n suc (suc (i + 1 + suc (nxn\u2192n i 1))) \u2261\u27e8 cong (\u03bb k \u2192 suc (suc k)) nid4 \u27e9\n suc (suc (i + suc (suc (nxn\u2192n i 1)))) \u2261\u27e8 cong (\u03bb k \u2192 suc (suc (i + suc (suc k)))) (nid3 i) \u27e9\n suc (suc (i + suc (suc (i + suc (nxn\u2192n i 0))))) \u2261\u27e8 refl \u27e9\n nxn\u2192n (suc (suc i)) zero \u220e where\n open \u2261-Reasoning\n nid3 : (i : \u2115) \u2192 nxn\u2192n i 1 \u2261 i + suc (nxn\u2192n i 0)\n nid3 zero = refl\n nid3 (suc i) = begin\n suc (i + 1 + suc (nxn\u2192n i 1)) \u2261\u27e8 cong suc nid4 \u27e9\n suc (i + suc (suc (nxn\u2192n i 1))) \u2261\u27e8 cong (\u03bb k \u2192 suc (i + suc (suc k))) (nid3 i) \u27e9\n suc (i + suc (suc (i + suc (nxn\u2192n i 0)))) \u220e\n nid2 (suc i) (suc j) = begin\n suc (nxn\u2192n (suc i) (suc (suc j))) \u2261\u27e8 refl \u27e9\n suc (suc (i + suc (suc j) + suc (nxn\u2192n i (suc (suc j))))) \u2261\u27e8 cong (\u03bb k \u2192 suc (suc (i + suc (suc j) + k))) (nid2 i (suc j)) \u27e9\n suc (suc (i + suc (suc j) + suc (i + suc j + suc (nxn\u2192n i (suc j))))) \u2261\u27e8 cong ( \u03bb k \u2192 suc (suc k)) nid5 \u27e9\n suc (suc (i + suc j + suc (suc (i + suc j + suc (nxn\u2192n i (suc j)))))) \u2261\u27e8 refl \u27e9\n nxn\u2192n (suc (suc i)) (suc j) \u220e where\n open \u2261-Reasoning\n\n -- increment ths stage\n nid00 : (i : \u2115) \u2192 suc (nxn\u2192n i 0) \u2261 nxn\u2192n 0 (suc i) \n nid00 zero = refl\n nid00 (suc i) = begin\n suc (suc (i + suc (nxn\u2192n i 0))) \u2261\u27e8 cong (\u03bb k \u2192 suc (suc (i + k ))) (nid00 i) \u27e9\n suc (suc (i + (nxn\u2192n 0 (suc i)))) \u2261\u27e8 refl \u27e9\n suc (suc (i + (i + suc (nxn\u2192n 0 i)))) \u2261\u27e8 cong suc (sym ( +-assoc 1 i (i + suc (nxn\u2192n 0 i)))) \u27e9\n suc ((1 + i) + (i + suc (nxn\u2192n 0 i))) \u2261\u27e8 cong (\u03bb k \u2192 suc (k + (i + suc (nxn\u2192n 0 i)))) (+-comm 1 i) \u27e9\n suc ((i + 1) + (i + suc (nxn\u2192n 0 i))) \u2261\u27e8 cong suc (+-assoc i 1 (i + suc (nxn\u2192n 0 i))) \u27e9\n suc (i + suc (i + suc (nxn\u2192n 0 i))) \u220e where open \u2261-Reasoning\n\n -----\n --\n -- create the invariant NN for all n\n --\n nn : ( i : \u2115) \u2192 NN i nxn\u2192n n\u2192nxn\n nn zero = record { j = 0 ; k = 0 ; sum = 0 ; stage = 0 ; nn = refl ; ni = refl ; k1 = refl ; k0 = refl\n ; nn-unique = \u03bb {j0} {k0} eq \u2192 cong\u2082 (\u03bb x y \u2192 \u27ea x , y \u27eb) (sym (proj1 (nxn\u2192n0 eq))) (sym (proj2 (nxn\u2192n0 {j0} {k0} eq))) }\n nn (suc i) with NN.k (nn i) | inspect NN.k (nn i) \n ... | zero | record { eq = eq } = record { k = suc (NN.sum (nn i)) ; j = 0 ; sum = suc (NN.sum (nn i)) ; stage = suc (NN.sum (nn i)) + (NN.stage (nn i))\n ; nn = refl\n ; ni = nn01 ; k1 = nn02 ; k0 = nn03 ; nn-unique = nn04 } where\n ---\n --- increment the stage\n ---\n sum = NN.sum (nn i)\n stage = NN.stage (nn i)\n j = NN.j (nn i)\n nn01 : suc i \u2261 0 + (suc sum + stage )\n nn01 = begin\n suc i \u2261\u27e8 cong suc (NN.ni (nn i)) \u27e9\n suc ((NN.j (nn i) ) + stage ) \u2261\u27e8 cong (\u03bb k \u2192 suc (k + stage )) (+-comm 0 _ ) \u27e9\n suc ((NN.j (nn i) + 0 ) + stage ) \u2261\u27e8 cong (\u03bb k \u2192 suc ((NN.j (nn i) + k) + stage )) (sym eq) \u27e9\n suc ((NN.j (nn i) + NN.k (nn i)) + stage ) \u2261\u27e8 cong (\u03bb k \u2192 suc ( k + stage )) (NN.nn (nn i)) \u27e9\n 0 + (suc sum + stage ) \u220e where open \u2261-Reasoning\n nn02 : nxn\u2192n 0 (suc sum) \u2261 suc i\n nn02 = begin\n sum + suc (nxn\u2192n 0 sum) \u2261\u27e8 sym (+-assoc sum 1 (nxn\u2192n 0 sum)) \u27e9\n (sum + 1) + nxn\u2192n 0 sum \u2261\u27e8 cong (\u03bb k \u2192 k + nxn\u2192n 0 sum ) (+-comm sum 1 )\u27e9\n suc (sum + nxn\u2192n 0 sum) \u2261\u27e8 cong suc (nid20 sum ) \u27e9\n suc (nxn\u2192n sum 0) \u2261\u27e8 cong (\u03bb k \u2192 suc (nxn\u2192n k 0 )) (sym (NN.nn (nn i))) \u27e9\n suc (nxn\u2192n (NN.j (nn i) + (NN.k (nn i)) ) 0) \u2261\u27e8 cong\u2082 (\u03bb j k \u2192 suc (nxn\u2192n (NN.j (nn i) + j) k )) eq (sym eq) \u27e9\n suc (nxn\u2192n (NN.j (nn i) + 0 ) (NN.k (nn i))) \u2261\u27e8 cong (\u03bb k \u2192 suc ( nxn\u2192n k (NN.k (nn i)))) (+-comm (NN.j (nn i)) 0) \u27e9\n suc (nxn\u2192n (NN.j (nn i)) (NN.k (nn i))) \u2261\u27e8 cong suc (NN.k1 (nn i) ) \u27e9\n suc i \u220e where open \u2261-Reasoning\n nn03 : n\u2192nxn (suc i) \u2261 \u27ea 0 , suc (NN.sum (nn i)) \u27eb -- k0 : n\u2192nxn i \u2261 \u27ea NN.j (nn i) = sum , NN.k (nn i) = 0 \u27eb\n nn03 with n\u2192nxn i | inspect n\u2192nxn i\n ... | \u27ea x , zero \u27eb | record { eq = eq1 } = begin\n \u27ea zero , suc x \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea zero , suc k \u27eb) (sym (cong proj1 eq1)) \u27e9\n \u27ea zero , suc (proj1 (n\u2192nxn i)) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea zero , suc k \u27eb) (cong proj1 (NN.k0 (nn i))) \u27e9\n \u27ea zero , suc (NN.j (nn i)) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea zero , suc k \u27eb) (+-comm 0 _ ) \u27e9\n \u27ea zero , suc (NN.j (nn i) + 0) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea zero , suc (NN.j (nn i) + k) \u27eb ) (sym eq) \u27e9\n \u27ea zero , suc (NN.j (nn i) + NN.k (nn i)) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea zero , suc k \u27eb ) (NN.nn (nn i)) \u27e9\n \u27ea 0 , suc sum \u27eb \u220e where open \u2261-Reasoning\n ... | \u27ea x , suc y \u27eb | record { eq = eq1 } = \u22a5-elim ( nat-\u2261< (sym (cong proj2 (NN.k0 (nn i)))) (begin\n suc (NN.k (nn i)) \u2261\u27e8 cong suc eq \u27e9\n suc 0 \u2264\u27e8 s\u2264s z\u2264n \u27e9\n suc y \u2261\u27e8 sym (cong proj2 eq1) \u27e9\n proj2 (n\u2192nxn i) \u220e )) where open \u2264-Reasoning\n -- nid2 : (i j : \u2115) \u2192 suc (nxn\u2192n i (suc j)) \u2261 nxn\u2192n (suc i) j \n nn04 : {j0 k0 : \u2115} \u2192 nxn\u2192n j0 k0 \u2261 suc i \u2192 \u27ea 0 , suc (NN.sum (nn i)) \u27eb \u2261 \u27ea j0 , k0 \u27eb\n nn04 {zero} {suc k0} eq1 = cong (\u03bb k \u2192 \u27ea 0 , k \u27eb ) (cong suc (sym nn08)) where -- eq : nxn\u2192n zero (suc k0) \u2261 suc i -- \n nn07 : nxn\u2192n k0 0 \u2261 i\n nn07 = cong pred ( begin\n suc ( nxn\u2192n k0 0 ) \u2261\u27e8 nid00 k0 \u27e9\n nxn\u2192n 0 (suc k0 ) \u2261\u27e8 eq1 \u27e9\n suc i \u220e ) where open \u2261-Reasoning \n nn08 : k0 \u2261 sum \n nn08 = begin\n k0 \u2261\u27e8 cong proj1 (sym (NN.nn-unique (nn i) nn07)) \u27e9\n NN.j (nn i) \u2261\u27e8 +-comm 0 _ \u27e9\n NN.j (nn i) + 0 \u2261\u27e8 cong (\u03bb k \u2192 NN.j (nn i) + k) (sym eq) \u27e9\n NN.j (nn i) + NN.k (nn i) \u2261\u27e8 NN.nn (nn i) \u27e9\n sum \u220e where open \u2261-Reasoning \n nn04 {suc j0} {k0} eq1 = \u22a5-elim ( nat-\u2261< (cong proj2 (nn06 nn05)) (subst (\u03bb k \u2192 k < suc k0) (sym eq) (s\u2264s z\u2264n))) where\n nn05 : nxn\u2192n j0 (suc k0) \u2261 i\n nn05 = begin\n nxn\u2192n j0 (suc k0) \u2261\u27e8 cong pred ( begin \n suc (nxn\u2192n j0 (suc k0)) \u2261\u27e8 nid2 j0 k0 \u27e9\n nxn\u2192n (suc j0) k0 \u2261\u27e8 eq1 \u27e9\n suc i \u220e ) \u27e9\n i \u220e where open \u2261-Reasoning \n nn06 : nxn\u2192n j0 (suc k0) \u2261 i \u2192 \u27ea NN.j (nn i) , NN.k (nn i) \u27eb \u2261 \u27ea j0 , suc k0 \u27eb \n nn06 = NN.nn-unique (nn i)\n ... | suc k | record {eq = eq} = record { k = k ; j = suc (NN.j (nn i)) ; sum = NN.sum (nn i) ; stage = NN.stage (nn i) ; nn = nn10\n ; ni = cong suc (NN.ni (nn i)) ; k1 = nn11 ; k0 = nn12 ; nn-unique = nn13 } where\n ---\n --- increment in a stage\n ---\n nn10 : suc (NN.j (nn i)) + k \u2261 NN.sum (nn i)\n nn10 = begin\n suc (NN.j (nn i)) + k \u2261\u27e8 cong (\u03bb x \u2192 x + k) (+-comm 1 _) \u27e9\n (NN.j (nn i) + 1) + k \u2261\u27e8 +-assoc (NN.j (nn i)) 1 k \u27e9\n NN.j (nn i) + suc k \u2261\u27e8 cong (\u03bb k \u2192 NN.j (nn i) + k) (sym eq) \u27e9\n NN.j (nn i) + NN.k (nn i) \u2261\u27e8 NN.nn (nn i) \u27e9\n NN.sum (nn i) \u220e where open \u2261-Reasoning \n nn11 : nxn\u2192n (suc (NN.j (nn i))) k \u2261 suc i -- nxn\u2192n ( NN.j (nn i)) (NN.k (nn i) \u2261 i\n nn11 = begin\n nxn\u2192n (suc (NN.j (nn i))) k \u2261\u27e8 sym (nid2 (NN.j (nn i)) k) \u27e9\n suc (nxn\u2192n (NN.j (nn i)) (suc k)) \u2261\u27e8 cong (\u03bb k \u2192 suc (nxn\u2192n (NN.j (nn i)) k)) (sym eq) \u27e9\n suc (nxn\u2192n ( NN.j (nn i)) (NN.k (nn i))) \u2261\u27e8 cong suc (NN.k1 (nn i)) \u27e9\n suc i \u220e where open \u2261-Reasoning \n nn18 : zero < NN.k (nn i)\n nn18 = subst (\u03bb k \u2192 0 < k ) ( begin\n suc k \u2261\u27e8 sym eq \u27e9\n NN.k (nn i) \u220e ) (s\u2264s z\u2264n ) where open \u2261-Reasoning \n nn12 : n\u2192nxn (suc i) \u2261 \u27ea suc (NN.j (nn i)) , k \u27eb -- n\u2192nxn i \u2261 \u27ea NN.j (nn i) , NN.k (nn i) \u27eb\n nn12 with n\u2192nxn i | inspect n\u2192nxn i\n ... | \u27ea x , zero \u27eb | record { eq = eq1 } = \u22a5-elim ( nat-\u2261< (sym (cong proj2 eq1))\n (subst (\u03bb k \u2192 0 < k ) ( begin\n suc k \u2261\u27e8 sym eq \u27e9\n NN.k (nn i) \u2261\u27e8 cong proj2 (sym (NN.k0 (nn i)) ) \u27e9\n proj2 (n\u2192nxn i) \u220e ) (s\u2264s z\u2264n )) ) where open \u2261-Reasoning -- eq1 n\u2192nxn i \u2261 \u27ea x , zero \u27eb\n ... | \u27ea x , suc y \u27eb | record { eq = eq1 } = begin -- n\u2192nxn i \u2261 \u27ea x , suc y \u27eb\n \u27ea suc x , y \u27eb \u2261\u27e8 refl \u27e9\n \u27ea suc x , pred (suc y) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea suc (proj1 k) , pred (proj2 k) \u27eb) ( begin\n \u27ea x , suc y \u27eb \u2261\u27e8 sym eq1 \u27e9\n n\u2192nxn i \u2261\u27e8 NN.k0 (nn i) \u27e9\n \u27ea NN.j (nn i) , NN.k (nn i) \u27eb \u220e ) \u27e9\n \u27ea suc (NN.j (nn i)) , pred (NN.k (nn i)) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea suc (NN.j (nn i)) , pred k \u27eb) eq \u27e9\n \u27ea suc (NN.j (nn i)) , k \u27eb \u220e where open \u2261-Reasoning \n nn13 : {j0 k0 : \u2115} \u2192 nxn\u2192n j0 k0 \u2261 suc i \u2192 \u27ea suc (NN.j (nn i)) , k \u27eb \u2261 \u27ea j0 , k0 \u27eb\n nn13 {zero} {suc k0} eq1 = \u22a5-elim ( nat-\u2261< (sym (cong proj2 nn17)) nn18 ) where -- (nxn\u2192n zero (suc k0)) \u2261 suc i\n nn16 : nxn\u2192n k0 zero \u2261 i\n nn16 = cong pred ( subst (\u03bb k \u2192 k \u2261 suc i) (sym ( nid00 k0 )) eq1 )\n nn17 : \u27ea NN.j (nn i) , NN.k (nn i) \u27eb \u2261 \u27ea k0 , zero \u27eb\n nn17 = NN.nn-unique (nn i) nn16\n nn13 {suc j0} {k0} eq1 = begin\n \u27ea suc (NN.j (nn i)) , pred (suc k) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea suc (NN.j (nn i)) , pred k \u27eb ) (sym eq) \u27e9\n \u27ea suc (NN.j (nn i)) , pred (NN.k (nn i)) \u27eb \u2261\u27e8 cong (\u03bb k \u2192 \u27ea suc (proj1 k) , pred (proj2 k) \u27eb) ( begin \n \u27ea NN.j (nn i) , NN.k (nn i) \u27eb \u2261\u27e8 nn15 \u27e9\n \u27ea j0 , suc k0 \u27eb \u220e ) \u27e9\n \u27ea suc j0 , k0 \u27eb \u220e where -- nxn\u2192n (suc j0) k0 \u2261 suc i\n open \u2261-Reasoning\n nn14 : nxn\u2192n j0 (suc k0) \u2261 i\n nn14 = cong pred ( subst (\u03bb k \u2192 k \u2261 suc i) (sym ( nid2 j0 k0 )) eq1 )\n nn15 : \u27ea NN.j (nn i) , NN.k (nn i) \u27eb \u2261 \u27ea j0 , suc k0 \u27eb\n nn15 = NN.nn-unique (nn i) nn14\n\n n-id : (i : \u2115) \u2192 nxn\u2192n (proj1 (n\u2192nxn i)) (proj2 (n\u2192nxn i)) \u2261 i\n n-id i = subst (\u03bb k \u2192 nxn\u2192n (proj1 k) (proj2 k) \u2261 i ) (sym (NN.k0 (nn i))) (NN.k1 (nn i))\n\n nn-id : (j k : \u2115) \u2192 n\u2192nxn (nxn\u2192n j k) \u2261 \u27ea j , k \u27eb\n nn-id j k = begin\n n\u2192nxn (nxn\u2192n j k) \u2261\u27e8 NN.k0 (nn (nxn\u2192n j k)) \u27e9\n \u27ea NN.j (nn (nxn\u2192n j k)) , NN.k (nn (nxn\u2192n j k)) \u27eb \u2261\u27e8 NN.nn-unique (nn (nxn\u2192n j k)) refl \u27e9\n \u27ea j , k \u27eb \u220e where open \u2261-Reasoning\n\n\n-- [] 0\n-- 0 \u2192 1\n-- 1 \u2192 2\n-- 01 \u2192 3\n-- 11 \u2192 4\n-- ...\n\n--\n-- binary invariant\n--\nrecord LB (n : \u2115) (lton : List Bool \u2192 \u2115 ) : Set where\n field\n nlist : List Bool\n isBin : lton nlist \u2261 n\n isUnique : (x : List Bool) \u2192 lton x \u2261 n \u2192 nlist \u2261 x -- we don't need this\n\nlb+1 : List Bool \u2192 List Bool\nlb+1 [] = false \u2237 [] \nlb+1 (false \u2237 t) = true \u2237 t \nlb+1 (true \u2237 t) = false \u2237 lb+1 t\n\nlb-1 : List Bool \u2192 List Bool\nlb-1 [] = []\nlb-1 (true \u2237 t) = false \u2237 t \nlb-1 (false \u2237 t) with lb-1 t\n... | [] = true \u2237 []\n... | x \u2237 t1 = true \u2237 x \u2237 t1\n\nLB\u2115 : Bijection \u2115 ( List Bool ) \nLB\u2115 = record {\n fun\u2190 = \u03bb x \u2192 lton x \n ; fun\u2192 = \u03bb n \u2192 LB.nlist (lb n) \n ; fiso\u2190 = \u03bb n \u2192 LB.isBin (lb n)\n ; fiso\u2192 = \u03bb x \u2192 LB.isUnique (lb (lton x)) x refl\n } where\n lton1 : List Bool \u2192 \u2115\n lton1 [] = 1\n lton1 (true \u2237 t) = suc (lton1 t + lton1 t)\n lton1 (false \u2237 t) = lton1 t + lton1 t\n lton : List Bool \u2192 \u2115\n lton x = pred (lton1 x)\n\n lton1>0 : (x : List Bool ) \u2192 0 < lton1 x \n lton1>0 [] = a0 (true \u2237 x\u2081) = 00 (false \u2237 t) = \u2264-trans (lton1>0 t) x\u2264x+y\n\n 2lton1>0 : (t : List Bool ) \u2192 0 < lton1 t + lton1 t\n 2lton1>0 t = \u2264-trans (lton1>0 t) x\u2264x+y\n\n lb=3 : {x y : \u2115} \u2192 0 < x \u2192 0 < y \u2192 1 \u2264 pred (x + y)\n lb=3 {suc x} {suc y} (s\u2264s 00 : {x : Bool} {y : List Bool } \u2192 0 < lton (x \u2237 y)\n lton-cons>0 {true} {[]} = refl-\u2264s\n lton-cons>0 {true} {x \u2237 y} = \u2264-trans ( lb=3 (lton1>0 (x \u2237 y)) (lton1>0 (x \u2237 y))) px\u2264x\n lton-cons>0 {false} {[]} = refl-\u2264\n lton-cons>0 {false} {x \u2237 y} = lb=3 (lton1>0 (x \u2237 y)) (lton1>0 (x \u2237 y))\n\n lb=0 : {x y : \u2115 } \u2192 pred x < pred y \u2192 suc (x + x \u2238 1) < suc (y + y \u2238 1)\n lb=0 {0} {suc y} lt = s\u2264s (subst (\u03bb k \u2192 0 < k ) (+-comm (suc y) y ) 0 \u00aca \u00acb c = \u22a5-elim (nat-\u2261< (cong suc (sym eq)) (lb=2 {lton1 y} {lton1 x} c))\n lb=1 {x} {y} {false} eq with <-cmp (lton x) (lton y)\n ... | tri< a \u00acb \u00acc = \u22a5-elim (nat-\u2261< (cong suc eq) (lb=0 {lton1 x} {lton1 y} a))\n ... | tri\u2248 \u00aca b \u00acc = b\n ... | tri> \u00aca \u00acb c = \u22a5-elim (nat-\u2261< (cong suc (sym eq)) (lb=0 {lton1 y} {lton1 x} c))\n\n ---\n --- lton is unique in a head\n ---\n lb-tf : {x y : List Bool } \u2192 \u00ac (lton (true \u2237 x) \u2261 lton (false \u2237 y))\n lb-tf {x} {y} eq with <-cmp (lton1 x) (lton1 y)\n ... | tri< a \u00acb \u00acc = \u22a5-elim ( nat-\u2261< eq (lb=01 a)) where\n lb=01 : {x y : \u2115 } \u2192 x < y \u2192 x + x < (y + y \u2238 1)\n lb=01 {x} {y} x \u00aca \u00acb c = \u22a5-elim ( nat-\u2261< (sym eq) (lb=02 c) ) where\n lb=02 : {x y : \u2115 } \u2192 x < y \u2192 x + x \u2238 1 < y + y\n lb=02 {0} {y} lt = \u2264-trans lt x\u2264x+y \n lb=02 {suc x} {y} lt = begin\n suc ( suc x + suc x \u2238 1 ) \u2261\u27e8 refl \u27e9\n suc x + suc x \u2264\u27e8 \u2264-plus {suc x} (0 y) \u27e9\n lton1 y + lton1 y \u2261\u27e8 cong (\u03bb k \u2192 k + k ) (sym b) \u27e9\n lton1 x + lton1 x \u220e )) where open \u2264-Reasoning\n\n ---\n --- lton uniqueness\n ---\n lb=b : (x y : List Bool) \u2192 lton x \u2261 lton y \u2192 x \u2261 y\n lb=b [] [] eq = refl\n lb=b [] (x \u2237 y) eq = \u22a5-elim ( nat-\u2261< eq (lton-cons>0 {x} {y} ))\n lb=b (x \u2237 y) [] eq = \u22a5-elim ( nat-\u2261< (sym eq) (lton-cons>0 {x} {y} ))\n lb=b (true \u2237 x) (false \u2237 y) eq = \u22a5-elim ( lb-tf {x} {y} eq )\n lb=b (false \u2237 x) (true \u2237 y) eq = \u22a5-elim ( lb-tf {y} {x} (sym eq) )\n lb=b (true \u2237 x) (true \u2237 y) eq = cong (\u03bb k \u2192 true \u2237 k ) (lb=b x y (lb=1 {x} {y} {true} eq)) \n lb=b (false \u2237 x) (false \u2237 y) eq = cong (\u03bb k \u2192 false \u2237 k ) (lb=b x y (lb=1 {x} {y} {false} eq)) \n\n lb : (n : \u2115) \u2192 LB n lton\n lb zero = record { nlist = [] ; isBin = refl ; isUnique = lb05 } where\n lb05 : (x : List Bool) \u2192 lton x \u2261 zero \u2192 [] \u2261 x\n lb05 x eq = lb=b [] x (sym eq)\n lb (suc n) with LB.nlist (lb n) | inspect LB.nlist (lb n) \n ... | [] | record { eq = eq } = record { nlist = false \u2237 [] ; isUnique = lb06 ; isBin = lb10 } where\n open \u2261-Reasoning\n lb10 : lton1 (false \u2237 []) \u2238 1 \u2261 suc n\n lb10 = begin\n lton (false \u2237 []) \u2261\u27e8 refl \u27e9 \n suc 0 \u2261\u27e8 refl \u27e9 \n suc (lton []) \u2261\u27e8 cong (\u03bb k \u2192 suc (lton k)) (sym eq) \u27e9 \n suc (lton (LB.nlist (lb n))) \u2261\u27e8 cong suc (LB.isBin (lb n) ) \u27e9 \n suc n \u220e \n lb06 : (x : List Bool) \u2192 pred (lton1 x ) \u2261 suc n \u2192 false \u2237 [] \u2261 x\n lb06 x eq1 = lb=b (false \u2237 []) x (trans lb10 (sym eq1)) -- lton (false \u2237 []) \u2261 lton x\n ... | false \u2237 t | record { eq = eq } = record { nlist = true \u2237 t ; isBin = lb01 ; isUnique = lb09 } where\n lb01 : lton (true \u2237 t) \u2261 suc n\n lb01 = begin\n lton (true \u2237 t) \u2261\u27e8 refl \u27e9 \n lton1 t + lton1 t \u2261\u27e8 sym ( sucprd (2lton1>0 t) ) \u27e9 \n suc (pred (lton1 t + lton1 t )) \u2261\u27e8 refl \u27e9 \n suc (lton (false \u2237 t)) \u2261\u27e8 cong (\u03bb k \u2192 suc (lton k )) (sym eq) \u27e9 \n suc (lton (LB.nlist (lb n))) \u2261\u27e8 cong suc (LB.isBin (lb n)) \u27e9 \n suc n \u220e where open \u2261-Reasoning\n lb09 : (x : List Bool) \u2192 lton1 x \u2238 1 \u2261 suc n \u2192 true \u2237 t \u2261 x\n lb09 x eq1 = lb=b (true \u2237 t) x (trans lb01 (sym eq1) ) -- lton (true \u2237 t) \u2261 lton x\n ... | true \u2237 t | record { eq = eq } = record { nlist = lb+1 (true \u2237 t) ; isBin = lb02 (true \u2237 t) lb03 ; isUnique = lb07 } where\n lb03 : lton (true \u2237 t) \u2261 n\n lb03 = begin\n lton (true \u2237 t) \u2261\u27e8 cong (\u03bb k \u2192 lton k ) (sym eq ) \u27e9 \n lton (LB.nlist (lb n)) \u2261\u27e8 LB.isBin (lb n) \u27e9 \n n \u220e where open \u2261-Reasoning\n\n add11 : (x1 : \u2115 ) \u2192 suc x1 + suc x1 \u2261 suc (suc (x1 + x1))\n add11 zero = refl\n add11 (suc x) = cong (\u03bb k \u2192 suc (suc k)) (trans (+-comm x _) (cong suc (+-comm _ x)))\n\n lb04 : (t : List Bool) \u2192 suc (lton1 t) \u2261 lton1 (lb+1 t) \n lb04 [] = refl\n lb04 (false \u2237 t) = refl\n lb04 (true \u2237 []) = refl\n lb04 (true \u2237 t0 ) = begin\n suc (suc (lton1 t0 + lton1 t0)) \u2261\u27e8 sym (add11 (lton1 t0)) \u27e9 \n suc (lton1 t0) + suc (lton1 t0) \u2261\u27e8 cong (\u03bb k \u2192 k + k ) (lb04 t0 ) \u27e9 \n lton1 (lb+1 t0) + lton1 (lb+1 t0) \u220e where\n open \u2261-Reasoning\n\n lb02 : (t : List Bool) \u2192 lton t \u2261 n \u2192 lton (lb+1 t) \u2261 suc n\n lb02 [] refl = refl\n lb02 t eq1 = begin\n lton (lb+1 t) \u2261\u27e8 refl \u27e9\n pred (lton1 (lb+1 t)) \u2261\u27e8 cong pred (sym (lb04 t)) \u27e9\n pred (suc (lton1 t)) \u2261\u27e8 sym (sucprd (lton1>0 t)) \u27e9\n suc (pred (lton1 t)) \u2261\u27e8 refl \u27e9\n suc (lton t) \u2261\u27e8 cong suc eq1 \u27e9\n suc n \u220e where open \u2261-Reasoning\n\n lb07 : (x : List Bool) \u2192 pred (lton1 x ) \u2261 suc n \u2192 lb+1 (true \u2237 t) \u2261 x\n lb07 x eq1 = lb=b (lb+1 (true \u2237 t)) x (trans ( lb02 (true \u2237 t) lb03 ) (sym eq1)) \n","avg_line_length":48.1442495127,"max_line_length":159,"alphanum_fraction":0.4224228682} {"size":67509,"ext":"agda","lang":"Agda","max_stars_count":5.0,"content":"------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- A bunch of properties about natural number operations\n------------------------------------------------------------------------\n\n-- See README.Data.Nat for some examples showing how this module can be\n-- used.\n\n{-# OPTIONS --without-K --safe #-}\n\nmodule Data.Nat.Properties where\n\nopen import Axiom.UniquenessOfIdentityProofs\nopen import Algebra.Bundles\nopen import Algebra.Morphism\nopen import Algebra.Consequences.Propositional\nopen import Data.Bool.Base using (Bool; false; true; T)\nopen import Data.Bool.Properties using (T?)\nopen import Data.Empty\nopen import Data.Nat.Base\nopen import Data.Product\nopen import Data.Sum.Base as Sum\nopen import Data.Unit using (tt)\nopen import Function.Base\nopen import Function.Injection using (_\u21a3_)\nopen import Level using (0\u2113)\nopen import Relation.Binary\nopen import Relation.Binary.Consequences using (flip-Connex)\nopen import Relation.Binary.PropositionalEquality\nopen import Relation.Nullary hiding (Irrelevant)\nopen import Relation.Nullary.Decidable using (True; via-injection; map\u2032)\nopen import Relation.Nullary.Negation using (contradiction)\n\nopen import Algebra.Definitions {A = \u2115} _\u2261_\n hiding (LeftCancellative; RightCancellative; Cancellative)\nopen import Algebra.Definitions\n using (LeftCancellative; RightCancellative; Cancellative)\nopen import Algebra.Structures {A = \u2115} _\u2261_\n\n------------------------------------------------------------------------\n-- Properties of _\u2261_\n------------------------------------------------------------------------\n\nsuc-injective : \u2200 {m n} \u2192 suc m \u2261 suc n \u2192 m \u2261 n\nsuc-injective refl = refl\n\n\u2261\u1d47\u21d2\u2261 : \u2200 m n \u2192 T (m \u2261\u1d47 n) \u2192 m \u2261 n\n\u2261\u1d47\u21d2\u2261 zero zero _ = refl\n\u2261\u1d47\u21d2\u2261 (suc m) (suc n) eq = cong suc (\u2261\u1d47\u21d2\u2261 m n eq)\n\n\u2261\u21d2\u2261\u1d47 : \u2200 m n \u2192 m \u2261 n \u2192 T (m \u2261\u1d47 n)\n\u2261\u21d2\u2261\u1d47 zero zero eq = _\n\u2261\u21d2\u2261\u1d47 (suc m) (suc n) eq = \u2261\u21d2\u2261\u1d47 m n (suc-injective eq)\n\n-- NB: we use the builtin function `_\u2261\u1d47_` here so that the function\n-- quickly decides whether to return `yes` or `no`. It still takes\n-- a linear amount of time to generate the proof if it is inspected.\n-- We expect the main benefit to be visible in compiled code as the\n-- backend erases proofs.\n\ninfix 4 _\u225f_\n_\u225f_ : Decidable {A = \u2115} _\u2261_\nm \u225f n = map\u2032 (\u2261\u1d47\u21d2\u2261 m n) (\u2261\u21d2\u2261\u1d47 m n) (T? (m \u2261\u1d47 n))\n\n\u2261-irrelevant : Irrelevant {A = \u2115} _\u2261_\n\u2261-irrelevant = Decidable\u21d2UIP.\u2261-irrelevant _\u225f_\n\n\u225f-diag : \u2200 {m n} (eq : m \u2261 n) \u2192 (m \u225f n) \u2261 yes eq\n\u225f-diag = \u2261-\u225f-identity _\u225f_\n\n\u2261-isDecEquivalence : IsDecEquivalence (_\u2261_ {A = \u2115})\n\u2261-isDecEquivalence = record\n { isEquivalence = isEquivalence\n ; _\u225f_ = _\u225f_\n }\n\n\u2261-decSetoid : DecSetoid 0\u2113 0\u2113\n\u2261-decSetoid = record\n { Carrier = \u2115\n ; _\u2248_ = _\u2261_\n ; isDecEquivalence = \u2261-isDecEquivalence\n }\n\n0\u22621+n : \u2200 {n} \u2192 0 \u2262 suc n\n0\u22621+n ()\n\n1+n\u22620 : \u2200 {n} \u2192 suc n \u2262 0\n1+n\u22620 ()\n\n1+n\u2262n : \u2200 {n} \u2192 suc n \u2262 n\n1+n\u2262n {suc n} = 1+n\u2262n \u2218 suc-injective\n\n------------------------------------------------------------------------\n-- Properties of _<\u1d47_\n------------------------------------------------------------------------\n\n<\u1d47\u21d2< : \u2200 m n \u2192 T (m <\u1d47 n) \u2192 m < n\n<\u1d47\u21d2< zero (suc n) m : _\u2270_ \u21d2 _>_\n\u2270\u21d2> {zero} z\u2270n = contradiction z\u2264n z\u2270n\n\u2270\u21d2> {suc m} {zero} _ = s\u2264s z\u2264n\n\u2270\u21d2> {suc m} {suc n} m\u2270n = s\u2264s (\u2270\u21d2> (m\u2270n \u2218 s\u2264s))\n\n\u2270\u21d2\u2265 : _\u2270_ \u21d2 _\u2265_\n\u2270\u21d2\u2265 = <\u21d2\u2264 \u2218 \u2270\u21d2>\n\n\u226e\u21d2\u2265 : _\u226e_ \u21d2 _\u2265_\n\u226e\u21d2\u2265 {_} {zero} _ = z\u2264n\n\u226e\u21d2\u2265 {zero} {suc j} 1\u226ej+1 = contradiction (s\u2264s z\u2264n) 1\u226ej+1\n\u226e\u21d2\u2265 {suc i} {suc j} i+1\u226ej+1 = s\u2264s (\u226e\u21d2\u2265 (i+1\u226ej+1 \u2218 s\u2264s))\n\n\u2264\u2227\u2262\u21d2< : \u2200 {m n} \u2192 m \u2264 n \u2192 m \u2262 n \u2192 m < n\n\u2264\u2227\u2262\u21d2< {_} {zero} z\u2264n m\u2262n = contradiction refl m\u2262n\n\u2264\u2227\u2262\u21d2< {_} {suc n} z\u2264n m\u2262n = s\u2264s z\u2264n\n\u2264\u2227\u2262\u21d2< {_} {suc n} (s\u2264s m\u2264n) 1+m\u22621+n =\n s\u2264s (\u2264\u2227\u2262\u21d2< m\u2264n (1+m\u22621+n \u2218 cong suc))\n\n\u2264-<-connex : Connex _\u2264_ _<_\n\u2264-<-connex m n with m \u2264? n\n... | yes m\u2264n = inj\u2081 m\u2264n\n... | no \u00acm\u2264n = inj\u2082 (\u2270\u21d2> \u00acm\u2264n)\n\n\u2265->-connex : Connex _\u2265_ _>_\n\u2265->-connex = flip \u2264-<-connex\n\n<-\u2264-connex : Connex _<_ _\u2264_\n<-\u2264-connex = flip-Connex \u2264-<-connex\n\n>-\u2265-connex : Connex _>_ _\u2265_\n>-\u2265-connex = flip-Connex \u2265->-connex\n\n------------------------------------------------------------------------\n-- Relational properties of _<_\n\n<-irrefl : Irreflexive _\u2261_ _<_\n<-irrefl refl (s\u2264s n (m\u226en \u2218 <\u21d2<\u1d47) m\u2262n (\u2264\u2227\u2262\u21d2< (\u226e\u21d2\u2265 (m\u226en \u2218 <\u21d2<\u1d47)) (m\u2262n \u2218 sym))\n\ninfix 4 _?_\n\n_?_ : Decidable _>_\n_>?_ = flip _0 : \u2200 {n} \u2192 n \u2262 0 \u2192 n > 0\nn\u22620\u21d2n>0 {zero} 0\u22620 = contradiction refl 0\u22620\nn\u22620\u21d2n>0 {suc n} _ = 0<1+n\n\nm 0 \u2192 m < m + n\nm0 = n>0\nm0 = s\u2264s (m0)\n\nm 0 \u2192 m < n + m\nm0 rewrite +-comm n m = m0\n\nm+n\u226en : \u2200 m n \u2192 m + n \u226e n\nm+n\u226en zero n = n\u226en n\nm+n\u226en (suc m) (suc n) (s\u2264s m+nn\u21d2m\u2238n\u22620 : \u2200 {m n} \u2192 m > n \u2192 m \u2238 n \u2262 0\nm>n\u21d2m\u2238n\u22620 {n = suc n} (s\u2264s m>n) = m>n\u21d2m\u2238n\u22620 m>n\n\n---------------------------------------------------------------\n-- Properties of _\u2238_ and _+_\n\n+-\u2238-comm : \u2200 {m} n {o} \u2192 o \u2264 m \u2192 (m + n) \u2238 o \u2261 (m \u2238 o) + n\n+-\u2238-comm {zero} _ {zero} _ = refl\n+-\u2238-comm {suc m} _ {zero} _ = refl\n+-\u2238-comm {suc m} n {suc o} (s\u2264s o\u2264m) = +-\u2238-comm n o\u2264m\n\n\u2238-+-assoc : \u2200 m n o \u2192 (m \u2238 n) \u2238 o \u2261 m \u2238 (n + o)\n\u2238-+-assoc zero zero o = refl\n\u2238-+-assoc zero (suc n) o = 0\u2238n\u22610 o\n\u2238-+-assoc (suc m) zero o = refl\n\u2238-+-assoc (suc m) (suc n) o = \u2238-+-assoc m n o\n\n+-\u2238-assoc : \u2200 m {n o} \u2192 o \u2264 n \u2192 (m + n) \u2238 o \u2261 m + (n \u2238 o)\n+-\u2238-assoc m (z\u2264n {n = n}) = begin-equality m + n \u220e\n+-\u2238-assoc m (s\u2264s {m = o} {n = n} o\u2264n) = begin-equality\n (m + suc n) \u2238 suc o \u2261\u27e8 cong (_\u2238 suc o) (+-suc m n) \u27e9\n suc (m + n) \u2238 suc o \u2261\u27e8\u27e9\n (m + n) \u2238 o \u2261\u27e8 +-\u2238-assoc m o\u2264n \u27e9\n m + (n \u2238 o) \u220e\n\nm\u2264n+m\u2238n : \u2200 m n \u2192 m \u2264 n + (m \u2238 n)\nm\u2264n+m\u2238n zero n = z\u2264n\nm\u2264n+m\u2238n (suc m) zero = \u2264-refl\nm\u2264n+m\u2238n (suc m) (suc n) = s\u2264s (m\u2264n+m\u2238n m n)\n\nm+n\u2238n\u2261m : \u2200 m n \u2192 m + n \u2238 n \u2261 m\nm+n\u2238n\u2261m m n = begin-equality\n (m + n) \u2238 n \u2261\u27e8 +-\u2238-assoc m (\u2264-refl {x = n}) \u27e9\n m + (n \u2238 n) \u2261\u27e8 cong (m +_) (n\u2238n\u22610 n) \u27e9\n m + 0 \u2261\u27e8 +-identity\u02b3 m \u27e9\n m \u220e\n\nm+n\u2238m\u2261n : \u2200 m n \u2192 m + n \u2238 m \u2261 n\nm+n\u2238m\u2261n m n = trans (cong (_\u2238 m) (+-comm m n)) (m+n\u2238n\u2261m n m)\n\nm+[n\u2238m]\u2261n : \u2200 {m n} \u2192 m \u2264 n \u2192 m + (n \u2238 m) \u2261 n\nm+[n\u2238m]\u2261n {m} {n} m\u2264n = begin-equality\n m + (n \u2238 m) \u2261\u27e8 sym $ +-\u2238-assoc m m\u2264n \u27e9\n (m + n) \u2238 m \u2261\u27e8 cong (_\u2238 m) (+-comm m n) \u27e9\n (n + m) \u2238 m \u2261\u27e8 m+n\u2238n\u2261m n m \u27e9\n n \u220e\n\nm\u2238n+n\u2261m : \u2200 {m n} \u2192 n \u2264 m \u2192 (m \u2238 n) + n \u2261 m\nm\u2238n+n\u2261m {m} {n} n\u2264m = begin-equality\n (m \u2238 n) + n \u2261\u27e8 sym (+-\u2238-comm n n\u2264m) \u27e9\n (m + n) \u2238 n \u2261\u27e8 m+n\u2238n\u2261m m n \u27e9\n m \u220e\n\nm\u2238[m\u2238n]\u2261n : \u2200 {m n} \u2192 n \u2264 m \u2192 m \u2238 (m \u2238 n) \u2261 n\nm\u2238[m\u2238n]\u2261n {m} {_} z\u2264n = n\u2238n\u22610 m\nm\u2238[m\u2238n]\u2261n {suc m} {suc n} (s\u2264s n\u2264m) = begin-equality\n suc m \u2238 (m \u2238 n) \u2261\u27e8 +-\u2238-assoc 1 (m\u2238n\u2264m m n) \u27e9\n suc (m \u2238 (m \u2238 n)) \u2261\u27e8 cong suc (m\u2238[m\u2238n]\u2261n n\u2264m) \u27e9\n suc n \u220e\n\n[m+n]\u2238[m+o]\u2261n\u2238o : \u2200 m n o \u2192 (m + n) \u2238 (m + o) \u2261 n \u2238 o\n[m+n]\u2238[m+o]\u2261n\u2238o zero n o = refl\n[m+n]\u2238[m+o]\u2261n\u2238o (suc m) n o = [m+n]\u2238[m+o]\u2261n\u2238o m n o\n\n------------------------------------------------------------------------\n-- Properties of _\u2238_ and _*_\n\n*-distrib\u02b3-\u2238 : _*_ DistributesOver\u02b3 _\u2238_\n*-distrib\u02b3-\u2238 m zero zero = refl\n*-distrib\u02b3-\u2238 zero zero (suc o) = sym (0\u2238n\u22610 (o * zero))\n*-distrib\u02b3-\u2238 (suc m) zero (suc o) = refl\n*-distrib\u02b3-\u2238 m (suc n) zero = refl\n*-distrib\u02b3-\u2238 m (suc n) (suc o) = begin-equality\n (n \u2238 o) * m \u2261\u27e8 *-distrib\u02b3-\u2238 m n o \u27e9\n n * m \u2238 o * m \u2261\u27e8 sym $ [m+n]\u2238[m+o]\u2261n\u2238o m _ _ \u27e9\n m + n * m \u2238 (m + o * m) \u220e\n\n*-distrib\u02e1-\u2238 : _*_ DistributesOver\u02e1 _\u2238_\n*-distrib\u02e1-\u2238 = comm+distr\u02b3\u21d2distr\u02e1 *-comm *-distrib\u02b3-\u2238\n\n*-distrib-\u2238 : _*_ DistributesOver _\u2238_\n*-distrib-\u2238 = *-distrib\u02e1-\u2238 , *-distrib\u02b3-\u2238\n\neven\u2262odd : \u2200 m n \u2192 2 * m \u2262 suc (2 * n)\neven\u2262odd (suc m) zero eq = contradiction (suc-injective eq) (m+1+n\u22620 m)\neven\u2262odd (suc m) (suc n) eq = even\u2262odd m n (suc-injective (begin-equality\n suc (2 * m) \u2261\u27e8 sym (+-suc m _) \u27e9\n m + suc (m + 0) \u2261\u27e8 suc-injective eq \u27e9\n suc n + suc (n + 0) \u2261\u27e8 cong suc (+-suc n _) \u27e9\n suc (suc (2 * n)) \u220e))\n\n------------------------------------------------------------------------\n-- Properties of _\u2238_ and _\u2293_ and _\u2294_\n\nm\u2293n+n\u2238m\u2261n : \u2200 m n \u2192 (m \u2293 n) + (n \u2238 m) \u2261 n\nm\u2293n+n\u2238m\u2261n zero n = refl\nm\u2293n+n\u2238m\u2261n (suc m) zero = refl\nm\u2293n+n\u2238m\u2261n (suc m) (suc n) = cong suc $ m\u2293n+n\u2238m\u2261n m n\n\n[m\u2238n]\u2293[n\u2238m]\u22610 : \u2200 m n \u2192 (m \u2238 n) \u2293 (n \u2238 m) \u2261 0\n[m\u2238n]\u2293[n\u2238m]\u22610 zero zero = refl\n[m\u2238n]\u2293[n\u2238m]\u22610 zero (suc n) = refl\n[m\u2238n]\u2293[n\u2238m]\u22610 (suc m) zero = refl\n[m\u2238n]\u2293[n\u2238m]\u22610 (suc m) (suc n) = [m\u2238n]\u2293[n\u2238m]\u22610 m n\n\n\u2238-distrib\u02e1-\u2293-\u2294 : \u2200 m n o \u2192 m \u2238 (n \u2293 o) \u2261 (m \u2238 n) \u2294 (m \u2238 o)\n\u2238-distrib\u02e1-\u2293-\u2294 m zero zero = sym (\u2294-idem m)\n\u2238-distrib\u02e1-\u2293-\u2294 zero zero (suc o) = refl\n\u2238-distrib\u02e1-\u2293-\u2294 zero (suc n) zero = refl\n\u2238-distrib\u02e1-\u2293-\u2294 zero (suc n) (suc o) = refl\n\u2238-distrib\u02e1-\u2293-\u2294 (suc m) (suc n) zero = sym (m\u2264n\u21d2m\u2294n\u2261n (\u2264-step (m\u2238n\u2264m m n)))\n\u2238-distrib\u02e1-\u2293-\u2294 (suc m) zero (suc o) = sym (m\u2264n\u21d2n\u2294m\u2261n (\u2264-step (m\u2238n\u2264m m o)))\n\u2238-distrib\u02e1-\u2293-\u2294 (suc m) (suc n) (suc o) = \u2238-distrib\u02e1-\u2293-\u2294 m n o\n\n\u2238-distrib\u02b3-\u2293 : _\u2238_ DistributesOver\u02b3 _\u2293_\n\u2238-distrib\u02b3-\u2293 zero n o = refl\n\u2238-distrib\u02b3-\u2293 (suc m) zero o = refl\n\u2238-distrib\u02b3-\u2293 (suc m) (suc n) zero = sym (\u2293-zero\u02b3 (n \u2238 m))\n\u2238-distrib\u02b3-\u2293 (suc m) (suc n) (suc o) = \u2238-distrib\u02b3-\u2293 m n o\n\n\u2238-distrib\u02e1-\u2294-\u2293 : \u2200 m n o \u2192 m \u2238 (n \u2294 o) \u2261 (m \u2238 n) \u2293 (m \u2238 o)\n\u2238-distrib\u02e1-\u2294-\u2293 m zero zero = sym (\u2293-idem m)\n\u2238-distrib\u02e1-\u2294-\u2293 zero zero o = 0\u2238n\u22610 o\n\u2238-distrib\u02e1-\u2294-\u2293 zero (suc n) o = 0\u2238n\u22610 (suc n \u2294 o)\n\u2238-distrib\u02e1-\u2294-\u2293 (suc m) (suc n) zero = sym (m\u2264n\u21d2m\u2293n\u2261m (\u2264-step (m\u2238n\u2264m m n)))\n\u2238-distrib\u02e1-\u2294-\u2293 (suc m) zero (suc o) = sym (m\u2264n\u21d2n\u2293m\u2261m (\u2264-step (m\u2238n\u2264m m o)))\n\u2238-distrib\u02e1-\u2294-\u2293 (suc m) (suc n) (suc o) = \u2238-distrib\u02e1-\u2294-\u2293 m n o\n\n\u2238-distrib\u02b3-\u2294 : _\u2238_ DistributesOver\u02b3 _\u2294_\n\u2238-distrib\u02b3-\u2294 zero n o = refl\n\u2238-distrib\u02b3-\u2294 (suc m) zero o = refl\n\u2238-distrib\u02b3-\u2294 (suc m) (suc n) zero = sym (\u2294-identity\u02b3 (n \u2238 m))\n\u2238-distrib\u02b3-\u2294 (suc m) (suc n) (suc o) = \u2238-distrib\u02b3-\u2294 m n o\n\n------------------------------------------------------------------------\n-- Properties of \u2223_-_\u2223\n------------------------------------------------------------------------\n\nm\u2261n\u21d2\u2223m-n\u2223\u22610 : \u2200 {m n} \u2192 m \u2261 n \u2192 \u2223 m - n \u2223 \u2261 0\nm\u2261n\u21d2\u2223m-n\u2223\u22610 {zero} refl = refl\nm\u2261n\u21d2\u2223m-n\u2223\u22610 {suc m} refl = m\u2261n\u21d2\u2223m-n\u2223\u22610 {m} refl\n\n\u2223m-n\u2223\u22610\u21d2m\u2261n : \u2200 {m n} \u2192 \u2223 m - n \u2223 \u2261 0 \u2192 m \u2261 n\n\u2223m-n\u2223\u22610\u21d2m\u2261n {zero} {zero} eq = refl\n\u2223m-n\u2223\u22610\u21d2m\u2261n {suc m} {suc n} eq = cong suc (\u2223m-n\u2223\u22610\u21d2m\u2261n eq)\n\nm\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m : \u2200 {m n} \u2192 m \u2264 n \u2192 \u2223 n - m \u2223 \u2261 n \u2238 m\nm\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m {_} {zero} z\u2264n = refl\nm\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m {_} {suc m} z\u2264n = refl\nm\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m {_} {_} (s\u2264s m\u2264n) = m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m m\u2264n\n\n\u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m : \u2200 {m n} \u2192 \u2223 m - n \u2223 \u2261 m \u2238 n \u2192 n \u2264 m\n\u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m {zero} {zero} eq = z\u2264n\n\u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m {suc m} {zero} eq = z\u2264n\n\u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m {suc m} {suc n} eq = s\u2264s (\u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m eq)\n\n\u2223n-n\u2223\u22610 : \u2200 n \u2192 \u2223 n - n \u2223 \u2261 0\n\u2223n-n\u2223\u22610 n = m\u2261n\u21d2\u2223m-n\u2223\u22610 {n} refl\n\n\u2223m-m+n\u2223\u2261n : \u2200 m n \u2192 \u2223 m - m + n \u2223 \u2261 n\n\u2223m-m+n\u2223\u2261n zero n = refl\n\u2223m-m+n\u2223\u2261n (suc m) n = \u2223m-m+n\u2223\u2261n m n\n\n\u2223m+n-m+o\u2223\u2261\u2223n-o| : \u2200 m n o \u2192 \u2223 m + n - m + o \u2223 \u2261 \u2223 n - o \u2223\n\u2223m+n-m+o\u2223\u2261\u2223n-o| zero n o = refl\n\u2223m+n-m+o\u2223\u2261\u2223n-o| (suc m) n o = \u2223m+n-m+o\u2223\u2261\u2223n-o| m n o\n\nm\u2238n\u2264\u2223m-n\u2223 : \u2200 m n \u2192 m \u2238 n \u2264 \u2223 m - n \u2223\nm\u2238n\u2264\u2223m-n\u2223 m n with \u2264-total m n\n... | inj\u2081 m\u2264n = subst (_\u2264 \u2223 m - n \u2223) (sym (m\u2264n\u21d2m\u2238n\u22610 m\u2264n)) z\u2264n\n... | inj\u2082 n\u2264m = subst (m \u2238 n \u2264_) (sym (m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m n\u2264m)) \u2264-refl\n\n\u2223m-n\u2223\u2264m\u2294n : \u2200 m n \u2192 \u2223 m - n \u2223 \u2264 m \u2294 n\n\u2223m-n\u2223\u2264m\u2294n zero m = \u2264-refl\n\u2223m-n\u2223\u2264m\u2294n (suc m) zero = \u2264-refl\n\u2223m-n\u2223\u2264m\u2294n (suc m) (suc n) = \u2264-step (\u2223m-n\u2223\u2264m\u2294n m n)\n\n\u2223-\u2223-identity\u02e1 : LeftIdentity 0 \u2223_-_\u2223\n\u2223-\u2223-identity\u02e1 x = refl\n\n\u2223-\u2223-identity\u02b3 : RightIdentity 0 \u2223_-_\u2223\n\u2223-\u2223-identity\u02b3 zero = refl\n\u2223-\u2223-identity\u02b3 (suc x) = refl\n\n\u2223-\u2223-identity : Identity 0 \u2223_-_\u2223\n\u2223-\u2223-identity = \u2223-\u2223-identity\u02e1 , \u2223-\u2223-identity\u02b3\n\n\u2223-\u2223-comm : Commutative \u2223_-_\u2223\n\u2223-\u2223-comm zero zero = refl\n\u2223-\u2223-comm zero (suc n) = refl\n\u2223-\u2223-comm (suc m) zero = refl\n\u2223-\u2223-comm (suc m) (suc n) = \u2223-\u2223-comm m n\n\n\u2223m-n\u2223\u2261[m\u2238n]\u2228[n\u2238m] : \u2200 m n \u2192 (\u2223 m - n \u2223 \u2261 m \u2238 n) \u228e (\u2223 m - n \u2223 \u2261 n \u2238 m)\n\u2223m-n\u2223\u2261[m\u2238n]\u2228[n\u2238m] m n with \u2264-total m n\n... | inj\u2082 n\u2264m = inj\u2081 $ m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m n\u2264m\n... | inj\u2081 m\u2264n = inj\u2082 $ begin-equality\n \u2223 m - n \u2223 \u2261\u27e8 \u2223-\u2223-comm m n \u27e9\n \u2223 n - m \u2223 \u2261\u27e8 m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m m\u2264n \u27e9\n n \u2238 m \u220e\n\nprivate\n\n *-distrib\u02e1-\u2223-\u2223-aux : \u2200 a m n \u2192 m \u2264 n \u2192 a * \u2223 n - m \u2223 \u2261 \u2223 a * n - a * m \u2223\n *-distrib\u02e1-\u2223-\u2223-aux a m n m\u2264n = begin-equality\n a * \u2223 n - m \u2223 \u2261\u27e8 cong (a *_) (m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m m\u2264n) \u27e9\n a * (n \u2238 m) \u2261\u27e8 *-distrib\u02e1-\u2238 a n m \u27e9\n a * n \u2238 a * m \u2261\u27e8 sym $\u2032 m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m (*-mono\u02b3-\u2264 a m\u2264n) \u27e9\n \u2223 a * n - a * m \u2223 \u220e\n\n*-distrib\u02e1-\u2223-\u2223 : _*_ DistributesOver\u02e1 \u2223_-_\u2223\n*-distrib\u02e1-\u2223-\u2223 a m n with \u2264-total m n\n... | inj\u2081 m\u2264n = begin-equality\n a * \u2223 m - n \u2223 \u2261\u27e8 cong (a *_) (\u2223-\u2223-comm m n) \u27e9\n a * \u2223 n - m \u2223 \u2261\u27e8 *-distrib\u02e1-\u2223-\u2223-aux a m n m\u2264n \u27e9\n \u2223 a * n - a * m \u2223 \u2261\u27e8 \u2223-\u2223-comm (a * n) (a * m) \u27e9\n \u2223 a * m - a * n \u2223 \u220e\n... | inj\u2082 n\u2264m = *-distrib\u02e1-\u2223-\u2223-aux a n m n\u2264m\n\n*-distrib\u02b3-\u2223-\u2223 : _*_ DistributesOver\u02b3 \u2223_-_\u2223\n*-distrib\u02b3-\u2223-\u2223 = comm+distr\u02e1\u21d2distr\u02b3 *-comm *-distrib\u02e1-\u2223-\u2223\n\n*-distrib-\u2223-\u2223 : _*_ DistributesOver \u2223_-_\u2223\n*-distrib-\u2223-\u2223 = *-distrib\u02e1-\u2223-\u2223 , *-distrib\u02b3-\u2223-\u2223\n\nm\u2264n+\u2223n-m\u2223 : \u2200 m n \u2192 m \u2264 n + \u2223 n - m \u2223\nm\u2264n+\u2223n-m\u2223 zero n = z\u2264n\nm\u2264n+\u2223n-m\u2223 (suc m) zero = \u2264-refl\nm\u2264n+\u2223n-m\u2223 (suc m) (suc n) = s\u2264s (m\u2264n+\u2223n-m\u2223 m n)\n\nm\u2264n+\u2223m-n\u2223 : \u2200 m n \u2192 m \u2264 n + \u2223 m - n \u2223\nm\u2264n+\u2223m-n\u2223 m n = subst (m \u2264_) (cong (n +_) (\u2223-\u2223-comm n m)) (m\u2264n+\u2223n-m\u2223 m n)\n\nm\u2264\u2223m-n\u2223+n : \u2200 m n \u2192 m \u2264 \u2223 m - n \u2223 + n\nm\u2264\u2223m-n\u2223+n m n = subst (m \u2264_) (+-comm n _) (m\u2264n+\u2223m-n\u2223 m n)\n\n------------------------------------------------------------------------\n-- Properties of \u230a_\/2\u230b and \u2308_\/2\u2309\n------------------------------------------------------------------------\n\n\u230an\/2\u230b-mono : \u230a_\/2\u230b Preserves _\u2264_ \u27f6 _\u2264_\n\u230an\/2\u230b-mono z\u2264n = z\u2264n\n\u230an\/2\u230b-mono (s\u2264s z\u2264n) = z\u2264n\n\u230an\/2\u230b-mono (s\u2264s (s\u2264s m\u2264n)) = s\u2264s (\u230an\/2\u230b-mono m\u2264n)\n\n\u2308n\/2\u2309-mono : \u2308_\/2\u2309 Preserves _\u2264_ \u27f6 _\u2264_\n\u2308n\/2\u2309-mono m\u2264n = \u230an\/2\u230b-mono (s\u2264s m\u2264n)\n\n\u230an\/2\u230b\u2264\u2308n\/2\u2309 : \u2200 n \u2192 \u230a n \/2\u230b \u2264 \u2308 n \/2\u2309\n\u230an\/2\u230b\u2264\u2308n\/2\u2309 zero = z\u2264n\n\u230an\/2\u230b\u2264\u2308n\/2\u2309 (suc zero) = z\u2264n\n\u230an\/2\u230b\u2264\u2308n\/2\u2309 (suc (suc n)) = s\u2264s (\u230an\/2\u230b\u2264\u2308n\/2\u2309 n)\n\n\u230an\/2\u230b+\u2308n\/2\u2309\u2261n : \u2200 n \u2192 \u230a n \/2\u230b + \u2308 n \/2\u2309 \u2261 n\n\u230an\/2\u230b+\u2308n\/2\u2309\u2261n zero = refl\n\u230an\/2\u230b+\u2308n\/2\u2309\u2261n (suc n) = begin-equality\n \u230a suc n \/2\u230b + suc \u230a n \/2\u230b \u2261\u27e8 +-comm \u230a suc n \/2\u230b (suc \u230a n \/2\u230b) \u27e9\n suc \u230a n \/2\u230b + \u230a suc n \/2\u230b \u2261\u27e8\u27e9\n suc (\u230a n \/2\u230b + \u230a suc n \/2\u230b) \u2261\u27e8 cong suc (\u230an\/2\u230b+\u2308n\/2\u2309\u2261n n) \u27e9\n suc n \u220e\n\n\u230an\/2\u230b\u2264n : \u2200 n \u2192 \u230a n \/2\u230b \u2264 n\n\u230an\/2\u230b\u2264n zero = z\u2264n\n\u230an\/2\u230b\u2264n (suc zero) = z\u2264n\n\u230an\/2\u230b\u2264n (suc (suc n)) = s\u2264s (\u2264-step (\u230an\/2\u230b\u2264n n))\n\n\u230an\/2\u230b\u2032?_\n\n_\u2264\u2032?_ : Decidable _\u2264\u2032_\nm \u2264\u2032? n = map\u2032 \u2264\u21d2\u2264\u2032 \u2264\u2032\u21d2\u2264 (m \u2264? n)\n\n_<\u2032?_ : Decidable _<\u2032_\nm <\u2032? n = suc m \u2264\u2032? n\n\n_\u2265\u2032?_ : Decidable _\u2265\u2032_\n_\u2265\u2032?_ = flip _\u2264\u2032?_\n\n_>\u2032?_ : Decidable _>\u2032_\n_>\u2032?_ = flip _<\u2032?_\n\nm\u2264\u2032m+n : \u2200 m n \u2192 m \u2264\u2032 m + n\nm\u2264\u2032m+n m n = \u2264\u21d2\u2264\u2032 (m\u2264m+n m n)\n\nn\u2264\u2032m+n : \u2200 m n \u2192 n \u2264\u2032 m + n\nn\u2264\u2032m+n zero n = \u2264\u2032-refl\nn\u2264\u2032m+n (suc m) n = \u2264\u2032-step (n\u2264\u2032m+n m n)\n\n\u2308n\/2\u2309\u2264\u2032n : \u2200 n \u2192 \u2308 n \/2\u2309 \u2264\u2032 n\n\u2308n\/2\u2309\u2264\u2032n zero = \u2264\u2032-refl\n\u2308n\/2\u2309\u2264\u2032n (suc zero) = \u2264\u2032-refl\n\u2308n\/2\u2309\u2264\u2032n (suc (suc n)) = s\u2264\u2032s (\u2264\u2032-step (\u2308n\/2\u2309\u2264\u2032n n))\n\n\u230an\/2\u230b\u2264\u2032n : \u2200 n \u2192 \u230a n \/2\u230b \u2264\u2032 n\n\u230an\/2\u230b\u2264\u2032n zero = \u2264\u2032-refl\n\u230an\/2\u230b\u2264\u2032n (suc n) = \u2264\u2032-step (\u2308n\/2\u2309\u2264\u2032n n)\n\n------------------------------------------------------------------------\n-- Properties of _\u2264\u2033_ and _<\u2033_\n------------------------------------------------------------------------\n\nm<\u1d47n\u21d21+m+[n-1+m]\u2261n : \u2200 m n \u2192 T (m <\u1d47 n) \u2192 suc m + (n \u2238 suc m) \u2261 n\nm<\u1d47n\u21d21+m+[n-1+m]\u2261n m n lt = m+[n\u2238m]\u2261n (<\u1d47\u21d2< m n lt)\n\nm<\u1d471+m+n : \u2200 m {n} \u2192 T (m <\u1d47 suc (m + n))\nm<\u1d471+m+n m = <\u21d2<\u1d47 (m\u2264m+n (suc m) _)\n\n<\u1d47\u21d2<\u2033 : \u2200 {m n} \u2192 T (m <\u1d47 n) \u2192 m <\u2033 n\n<\u1d47\u21d2<\u2033 {m} {n} leq = less-than-or-equal (m+[n\u2238m]\u2261n (<\u1d47\u21d2< m n leq))\n\n<\u2033\u21d2<\u1d47 : \u2200 {m n} \u2192 m <\u2033 n \u2192 T (m <\u1d47 n)\n<\u2033\u21d2<\u1d47 {m} (less-than-or-equal refl) = <\u21d2<\u1d47 (m\u2264m+n (suc m) _)\n\n-- equivalence to _\u2264_\n\n\u2264\u2033\u21d2\u2264 : _\u2264\u2033_ \u21d2 _\u2264_\n\u2264\u2033\u21d2\u2264 {zero} (less-than-or-equal refl) = z\u2264n\n\u2264\u2033\u21d2\u2264 {suc m} (less-than-or-equal refl) =\n s\u2264s (\u2264\u2033\u21d2\u2264 (less-than-or-equal refl))\n\n\u2264\u21d2\u2264\u2033 : _\u2264_ \u21d2 _\u2264\u2033_\n\u2264\u21d2\u2264\u2033 = less-than-or-equal \u2218 m+[n\u2238m]\u2261n\n\n-- NB: we use the builtin function `_<\u1d47_ : (m n : \u2115) \u2192 Bool` here so\n-- that the function quickly decides whether to return `yes` or `no`.\n-- It still takes a linear amount of time to generate the proof if it\n-- is inspected. We expect the main benefit to be visible for compiled\n-- code: the backend erases proofs.\n\ninfix 4 _<\u2033?_ _\u2264\u2033?_ _\u2265\u2033?_ _>\u2033?_\n\n_<\u2033?_ : Decidable _<\u2033_\nm <\u2033? n = map\u2032 <\u1d47\u21d2<\u2033 <\u2033\u21d2<\u1d47 (T? (m <\u1d47 n))\n\n_\u2264\u2033?_ : Decidable _\u2264\u2033_\nzero \u2264\u2033? n = yes (less-than-or-equal refl)\nsuc m \u2264\u2033? n = m <\u2033? n\n\n_\u2265\u2033?_ : Decidable _\u2265\u2033_\n_\u2265\u2033?_ = flip _\u2264\u2033?_\n\n_>\u2033?_ : Decidable _>\u2033_\n_>\u2033?_ = flip _<\u2033?_\n\n\u2264\u2033-irrelevant : Irrelevant _\u2264\u2033_\n\u2264\u2033-irrelevant {m} (less-than-or-equal eq\u2081)\n (less-than-or-equal eq\u2082)\n with +-cancel\u02e1-\u2261 m (trans eq\u2081 (sym eq\u2082))\n... | refl = cong less-than-or-equal (\u2261-irrelevant eq\u2081 eq\u2082)\n\n<\u2033-irrelevant : Irrelevant _<\u2033_\n<\u2033-irrelevant = \u2264\u2033-irrelevant\n\n>\u2033-irrelevant : Irrelevant _>\u2033_\n>\u2033-irrelevant = \u2264\u2033-irrelevant\n\n\u2265\u2033-irrelevant : Irrelevant _\u2265\u2033_\n\u2265\u2033-irrelevant = \u2264\u2033-irrelevant\n\n------------------------------------------------------------------------\n-- Properties of _\u2264\u2034_\n------------------------------------------------------------------------\n\n\u2264\u2034\u21d2\u2264\u2033 : \u2200{m n} \u2192 m \u2264\u2034 n \u2192 m \u2264\u2033 n\n\u2264\u2034\u21d2\u2264\u2033 {m = m} \u2264\u2034-refl = less-than-or-equal {k = 0} (+-identity\u02b3 m)\n\u2264\u2034\u21d2\u2264\u2033 {m = m} (\u2264\u2034-step x) = less-than-or-equal (trans (+-suc m _) (_\u2264\u2033_.proof ind)) where\n ind = \u2264\u2034\u21d2\u2264\u2033 x\n\nm\u2264\u2034m+k : \u2200{m n k} \u2192 m + k \u2261 n \u2192 m \u2264\u2034 n\nm\u2264\u2034m+k {m} {k = zero} refl = subst (\u03bb z \u2192 m \u2264\u2034 z) (sym (+-identity\u02b3 m)) (\u2264\u2034-refl {m})\nm\u2264\u2034m+k {m} {k = suc k} proof\n = \u2264\u2034-step (m\u2264\u2034m+k {k = k} (trans (sym (+-suc m _)) proof))\n\n\u2264\u2033\u21d2\u2264\u2034 : \u2200{m n} \u2192 m \u2264\u2033 n \u2192 m \u2264\u2034 n\n\u2264\u2033\u21d2\u2264\u2034 (less-than-or-equal {k} proof) = m\u2264\u2034m+k proof\n\n------------------------------------------------------------------------\n-- Other properties\n------------------------------------------------------------------------\n\n-- If there is an injection from a type to \u2115, then the type has\n-- decidable equality.\n\neq? : \u2200 {a} {A : Set a} \u2192 A \u21a3 \u2115 \u2192 Decidable {A = A} _\u2261_\neq? inj = via-injection inj _\u225f_\n\n\n------------------------------------------------------------------------\n-- DEPRECATED NAMES\n------------------------------------------------------------------------\n-- Please use the new names as continuing support for the old names is\n-- not guaranteed.\n\n-- Version 0.14\n\n_*-mono_ = *-mono-\u2264\n{-# WARNING_ON_USAGE _*-mono_\n\"Warning: _*-mono_ was deprecated in v0.14.\nPlease use *-mono-\u2264 instead.\"\n#-}\n_+-mono_ = +-mono-\u2264\n{-# WARNING_ON_USAGE _+-mono_\n\"Warning: _+-mono_ was deprecated in v0.14.\nPlease use +-mono-\u2264 instead.\"\n#-}\n+-right-identity = +-identity\u02b3\n{-# WARNING_ON_USAGE +-right-identity\n\"Warning: +-right-identity was deprecated in v0.14.\nPlease use +-identity\u02b3 instead.\"\n#-}\n*-right-zero = *-zero\u02b3\n{-# WARNING_ON_USAGE *-right-zero\n\"Warning: *-right-zero was deprecated in v0.14.\nPlease use *-zero\u02b3 instead.\"\n#-}\ndistrib\u02b3-*-+ = *-distrib\u02b3-+\n{-# WARNING_ON_USAGE distrib\u02b3-*-+\n\"Warning: distrib\u02b3-*-+ was deprecated in v0.14.\nPlease use *-distrib\u02b3-+ instead.\"\n#-}\n*-distrib-\u2238\u02b3 = *-distrib\u02b3-\u2238\n{-# WARNING_ON_USAGE *-distrib-\u2238\u02b3\n\"Warning: *-distrib-\u2238\u02b3 was deprecated in v0.14.\nPlease use *-distrib\u02b3-\u2238 instead.\"\n#-}\ncancel-+-left = +-cancel\u02e1-\u2261\n{-# WARNING_ON_USAGE cancel-+-left\n\"Warning: cancel-+-left was deprecated in v0.14.\nPlease use +-cancel\u02e1-\u2261 instead.\"\n#-}\ncancel-+-left-\u2264 = +-cancel\u02e1-\u2264\n{-# WARNING_ON_USAGE cancel-+-left-\u2264\n\"Warning: cancel-+-left-\u2264 was deprecated in v0.14.\nPlease use +-cancel\u02e1-\u2264 instead.\"\n#-}\ncancel-*-right = *-cancel\u02b3-\u2261\n{-# WARNING_ON_USAGE cancel-*-right\n\"Warning: cancel-*-right was deprecated in v0.14.\nPlease use *-cancel\u02b3-\u2261 instead.\"\n#-}\ncancel-*-right-\u2264 = *-cancel\u02b3-\u2264\n{-# WARNING_ON_USAGE cancel-*-right-\u2264\n\"Warning: cancel-*-right-\u2264 was deprecated in v0.14.\nPlease use *-cancel\u02b3-\u2264 instead.\"\n#-}\nstrictTotalOrder = <-strictTotalOrder\n{-# WARNING_ON_USAGE strictTotalOrder\n\"Warning: strictTotalOrder was deprecated in v0.14.\nPlease use <-strictTotalOrder instead.\"\n#-}\nisCommutativeSemiring = *-+-isCommutativeSemiring\n{-# WARNING_ON_USAGE isCommutativeSemiring\n\"Warning: isCommutativeSemiring was deprecated in v0.14.\nPlease use *-+-isCommutativeSemiring instead.\"\n#-}\ncommutativeSemiring = *-+-commutativeSemiring\n{-# WARNING_ON_USAGE commutativeSemiring\n\"Warning: commutativeSemiring was deprecated in v0.14.\nPlease use *-+-commutativeSemiring instead.\"\n#-}\nisDistributiveLattice = \u2293-\u2294-isDistributiveLattice\n{-# WARNING_ON_USAGE isDistributiveLattice\n\"Warning: isDistributiveLattice was deprecated in v0.14.\nPlease use \u2293-\u2294-isDistributiveLattice instead.\"\n#-}\ndistributiveLattice = \u2293-\u2294-distributiveLattice\n{-# WARNING_ON_USAGE distributiveLattice\n\"Warning: distributiveLattice was deprecated in v0.14.\nPlease use \u2293-\u2294-distributiveLattice instead.\"\n#-}\n\u2294-\u2293-0-isSemiringWithoutOne = \u2294-\u2293-isSemiringWithoutOne\n{-# WARNING_ON_USAGE \u2294-\u2293-0-isSemiringWithoutOne\n\"Warning: \u2294-\u2293-0-isSemiringWithoutOne was deprecated in v0.14.\nPlease use \u2294-\u2293-isSemiringWithoutOne instead.\"\n#-}\n\u2294-\u2293-0-isCommutativeSemiringWithoutOne = \u2294-\u2293-isCommutativeSemiringWithoutOne\n{-# WARNING_ON_USAGE \u2294-\u2293-0-isCommutativeSemiringWithoutOne\n\"Warning: \u2294-\u2293-0-isCommutativeSemiringWithoutOne was deprecated in v0.14.\nPlease use \u2294-\u2293-isCommutativeSemiringWithoutOne instead.\"\n#-}\n\u2294-\u2293-0-commutativeSemiringWithoutOne = \u2294-\u2293-commutativeSemiringWithoutOne\n{-# WARNING_ON_USAGE \u2294-\u2293-0-commutativeSemiringWithoutOne\n\"Warning: \u2294-\u2293-0-commutativeSemiringWithoutOne was deprecated in v0.14.\nPlease use \u2294-\u2293-commutativeSemiringWithoutOne instead.\"\n#-}\n\n-- Version 0.15\n\n\u00aci+1+j\u2264i = m+1+n\u2270m\n{-# WARNING_ON_USAGE \u00aci+1+j\u2264i\n\"Warning: \u00aci+1+j\u2264i was deprecated in v0.15.\nPlease use m+1+n\u2270m instead.\"\n#-}\n\u2264-steps = \u2264-steps\u02e1\n{-# WARNING_ON_USAGE \u2264-steps\n\"Warning: \u2264-steps was deprecated in v0.15.\nPlease use \u2264-steps\u02e1 instead.\"\n#-}\n\n-- Version 0.17\n\ni\u2238k\u2238j+j\u2238k\u2261i+j\u2238k : \u2200 i j k \u2192 i \u2238 (k \u2238 j) + (j \u2238 k) \u2261 i + j \u2238 k\ni\u2238k\u2238j+j\u2238k\u2261i+j\u2238k zero j k = cong (_+ (j \u2238 k)) (0\u2238n\u22610 (k \u2238 j))\ni\u2238k\u2238j+j\u2238k\u2261i+j\u2238k (suc i) j zero = cong (\u03bb x \u2192 suc i \u2238 x + j) (0\u2238n\u22610 j)\ni\u2238k\u2238j+j\u2238k\u2261i+j\u2238k (suc i) zero (suc k) = begin-equality\n i \u2238 k + 0 \u2261\u27e8 +-identity\u02b3 _ \u27e9\n i \u2238 k \u2261\u27e8 cong (_\u2238 k) (sym (+-identity\u02b3 _)) \u27e9\n i + 0 \u2238 k \u220e\ni\u2238k\u2238j+j\u2238k\u2261i+j\u2238k (suc i) (suc j) (suc k) = begin-equality\n suc i \u2238 (k \u2238 j) + (j \u2238 k) \u2261\u27e8 i\u2238k\u2238j+j\u2238k\u2261i+j\u2238k (suc i) j k \u27e9\n suc i + j \u2238 k \u2261\u27e8 cong (_\u2238 k) (sym (+-suc i j)) \u27e9\n i + suc j \u2238 k \u220e\n{-# WARNING_ON_USAGE i\u2238k\u2238j+j\u2238k\u2261i+j\u2238k\n\"Warning: i\u2238k\u2238j+j\u2238k\u2261i+j\u2238k was deprecated in v0.17.\"\n#-}\nim\u2261jm+n\u21d2[i\u2238j]m\u2261n : \u2200 i j m n \u2192 i * m \u2261 j * m + n \u2192 (i \u2238 j) * m \u2261 n\nim\u2261jm+n\u21d2[i\u2238j]m\u2261n i j m n eq = begin-equality\n (i \u2238 j) * m \u2261\u27e8 *-distrib\u02b3-\u2238 m i j \u27e9\n (i * m) \u2238 (j * m) \u2261\u27e8 cong (_\u2238 j * m) eq \u27e9\n (j * m + n) \u2238 (j * m) \u2261\u27e8 cong (_\u2238 j * m) (+-comm (j * m) n) \u27e9\n (n + j * m) \u2238 (j * m) \u2261\u27e8 m+n\u2238n\u2261m n (j * m) \u27e9\n n \u220e\n{-# WARNING_ON_USAGE im\u2261jm+n\u21d2[i\u2238j]m\u2261n\n\"Warning: im\u2261jm+n\u21d2[i\u2238j]m\u2261n was deprecated in v0.17.\"\n#-}\n\u2264+\u2262\u21d2< = \u2264\u2227\u2262\u21d2<\n{-# WARNING_ON_USAGE \u2264+\u2262\u21d2<\n\"Warning: \u2264+\u2262\u21d2< was deprecated in v0.17.\nPlease use \u2264\u2227\u2262\u21d2< instead.\"\n#-}\n\n-- Version 1.0\n\n\u2264-irrelevance = \u2264-irrelevant\n{-# WARNING_ON_USAGE \u2264-irrelevance\n\"Warning: \u2264-irrelevance was deprecated in v1.0.\nPlease use \u2264-irrelevant instead.\"\n#-}\n<-irrelevance = <-irrelevant\n{-# WARNING_ON_USAGE <-irrelevance\n\"Warning: <-irrelevance was deprecated in v1.0.\nPlease use <-irrelevant instead.\"\n#-}\n\n-- Version 1.1\n\ni+1+j\u2262i = m+1+n\u2262m\n{-# WARNING_ON_USAGE i+1+j\u2262i\n\"Warning: i+1+j\u2262i was deprecated in v1.1.\nPlease use m+1+n\u2262m instead.\"\n#-}\ni+j\u22610\u21d2i\u22610 = m+n\u22610\u21d2m\u22610\n{-# WARNING_ON_USAGE i+j\u22610\u21d2i\u22610\n\"Warning: i+j\u22610\u21d2i\u22610 was deprecated in v1.1.\nPlease use m+n\u22610\u21d2m\u22610 instead.\"\n#-}\ni+j\u22610\u21d2j\u22610 = m+n\u22610\u21d2n\u22610\n{-# WARNING_ON_USAGE i+j\u22610\u21d2j\u22610\n\"Warning: i+j\u22610\u21d2j\u22610 was deprecated in v1.1.\nPlease use m+n\u22610\u21d2n\u22610 instead.\"\n#-}\ni+1+j\u2270i = m+1+n\u2270m\n{-# WARNING_ON_USAGE i+1+j\u2270i\n\"Warning: i+1+j\u2270i was deprecated in v1.1.\nPlease use m+1+n\u2270m instead.\"\n#-}\ni*j\u22610\u21d2i\u22610\u2228j\u22610 = m*n\u22610\u21d2m\u22610\u2228n\u22610\n{-# WARNING_ON_USAGE i*j\u22610\u21d2i\u22610\u2228j\u22610\n\"Warning: i*j\u22610\u21d2i\u22610\u2228j\u22610 was deprecated in v1.1.\nPlease use m*n\u22610\u21d2m\u22610\u2228n\u22610 instead.\"\n#-}\ni*j\u22611\u21d2i\u22611 = m*n\u22611\u21d2m\u22611\n{-# WARNING_ON_USAGE i*j\u22611\u21d2i\u22611\n\"Warning: i*j\u22611\u21d2i\u22611 was deprecated in v1.1.\nPlease use m*n\u22611\u21d2m\u22611 instead.\"\n#-}\ni*j\u22611\u21d2j\u22611 = m*n\u22611\u21d2n\u22611\n{-# WARNING_ON_USAGE i*j\u22611\u21d2j\u22611\n\"Warning: i*j\u22611\u21d2j\u22611 was deprecated in v1.1.\nPlease use m*n\u22611\u21d2n\u22611 instead.\"\n#-}\ni^j\u22610\u21d2i\u22610 = m^n\u22610\u21d2m\u22610\n{-# WARNING_ON_USAGE i^j\u22610\u21d2i\u22610\n\"Warning: i^j\u22610\u21d2i\u22610 was deprecated in v1.1.\nPlease use m^n\u22610\u21d2m\u22610 instead.\"\n#-}\ni^j\u22611\u21d2j\u22610\u2228i\u22611 = m^n\u22611\u21d2n\u22610\u2228m\u22611\n{-# WARNING_ON_USAGE i^j\u22611\u21d2j\u22610\u2228i\u22611\n\"Warning: i^j\u22611\u21d2j\u22610\u2228i\u22611 was deprecated in v1.1.\nPlease use m^n\u22611\u21d2n\u22610\u2228m\u22611 instead.\"\n#-}\n[i+j]\u2238[i+k]\u2261j\u2238k = [m+n]\u2238[m+o]\u2261n\u2238o\n{-# WARNING_ON_USAGE [i+j]\u2238[i+k]\u2261j\u2238k\n\"Warning: [i+j]\u2238[i+k]\u2261j\u2238k was deprecated in v1.1.\nPlease use [m+n]\u2238[m+o]\u2261n\u2238o instead.\"\n#-}\nm\u22620\u21d2suc[pred[m]]\u2261m = suc[pred[n]]\u2261n\n{-# WARNING_ON_USAGE m\u22620\u21d2suc[pred[m]]\u2261m\n\"Warning: m\u22620\u21d2suc[pred[m]]\u2261m was deprecated in v1.1.\nPlease use suc[pred[n]]\u2261n instead.\"\n#-}\nn\u2261m\u21d2\u2223n-m\u2223\u22610 = m\u2261n\u21d2\u2223m-n\u2223\u22610\n{-# WARNING_ON_USAGE n\u2261m\u21d2\u2223n-m\u2223\u22610\n\"Warning: n\u2261m\u21d2\u2223n-m\u2223\u22610 was deprecated in v1.1.\nPlease use m\u2261n\u21d2\u2223m-n\u2223\u22610 instead.\"\n#-}\n\u2223n-m\u2223\u22610\u21d2n\u2261m = \u2223m-n\u2223\u22610\u21d2m\u2261n\n{-# WARNING_ON_USAGE \u2223n-m\u2223\u22610\u21d2n\u2261m\n\"Warning: \u2223n-m\u2223\u22610\u21d2n\u2261m was deprecated in v1.1.\nPlease use \u2223m-n\u2223\u22610\u21d2m\u2261n instead.\"\n#-}\n\u2223n-m\u2223\u2261n\u2238m\u21d2m\u2264n = \u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m\n{-# WARNING_ON_USAGE \u2223n-m\u2223\u2261n\u2238m\u21d2m\u2264n\n\"Warning: \u2223n-m\u2223\u2261n\u2238m\u21d2m\u2264n was deprecated in v1.1.\nPlease use \u2223m-n\u2223\u2261m\u2238n\u21d2n\u2264m instead.\"\n#-}\n\u2223n-n+m\u2223\u2261m = \u2223m-m+n\u2223\u2261n\n{-# WARNING_ON_USAGE \u2223n-n+m\u2223\u2261m\n\"Warning: \u2223n-n+m\u2223\u2261m was deprecated in v1.1.\nPlease use \u2223m-m+n\u2223\u2261n instead.\"\n#-}\n\u2223n+m-n+o\u2223\u2261\u2223m-o| = \u2223m+n-m+o\u2223\u2261\u2223n-o|\n{-# WARNING_ON_USAGE \u2223n+m-n+o\u2223\u2261\u2223m-o|\n\"Warning: \u2223n+m-n+o\u2223\u2261\u2223m-o| was deprecated in v1.1.\nPlease use \u2223m+n-m+o\u2223\u2261\u2223n-o| instead.\"\n#-}\nn\u2238m\u2264\u2223n-m\u2223 = m\u2238n\u2264\u2223m-n\u2223\n{-# WARNING_ON_USAGE n\u2238m\u2264\u2223n-m\u2223\n\"Warning: n\u2238m\u2264\u2223n-m\u2223 was deprecated in v1.1.\nPlease use m\u2238n\u2264\u2223m-n\u2223 instead.\"\n#-}\n\u2223n-m\u2223\u2264n\u2294m = \u2223m-n\u2223\u2264m\u2294n\n{-# WARNING_ON_USAGE \u2223n-m\u2223\u2264n\u2294m\n\"Warning: \u2223n-m\u2223\u2264n\u2294m was deprecated in v1.1.\nPlease use \u2223m-n\u2223\u2264m\u2294n instead.\"\n#-}\nn\u2264m+n : \u2200 m n \u2192 n \u2264 m + n\nn\u2264m+n m n = subst (n \u2264_) (+-comm n m) (m\u2264m+n n m)\n{-# WARNING_ON_USAGE n\u2264m+n\n\"Warning: n\u2264m+n was deprecated in v1.1.\nPlease use m\u2264n+m instead (note, you will need to switch the argument order).\"\n#-}\nn\u2264m+n\u2238m : \u2200 m n \u2192 n \u2264 m + (n \u2238 m)\nn\u2264m+n\u2238m m zero = z\u2264n\nn\u2264m+n\u2238m zero (suc n) = \u2264-refl\nn\u2264m+n\u2238m (suc m) (suc n) = s\u2264s (n\u2264m+n\u2238m m n)\n{-# WARNING_ON_USAGE n\u2264m+n\u2238m\n\"Warning: n\u2264m+n\u2238m was deprecated in v1.1.\nPlease use m\u2264n+m\u2238n instead (note, you will need to switch the argument order).\"\n#-}\n\u2223n-m\u2223\u2261[n\u2238m]\u2228[m\u2238n] : \u2200 m n \u2192 (\u2223 n - m \u2223 \u2261 n \u2238 m) \u228e (\u2223 n - m \u2223 \u2261 m \u2238 n)\n\u2223n-m\u2223\u2261[n\u2238m]\u2228[m\u2238n] m n with \u2264-total m n\n... | inj\u2081 m\u2264n = inj\u2081 $ m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m m\u2264n\n... | inj\u2082 n\u2264m = inj\u2082 $ begin-equality\n \u2223 n - m \u2223 \u2261\u27e8 \u2223-\u2223-comm n m \u27e9\n \u2223 m - n \u2223 \u2261\u27e8 m\u2264n\u21d2\u2223n-m\u2223\u2261n\u2238m n\u2264m \u27e9\n m \u2238 n \u220e\n{-# WARNING_ON_USAGE \u2223n-m\u2223\u2261[n\u2238m]\u2228[m\u2238n]\n\"Warning: \u2223n-m\u2223\u2261[n\u2238m]\u2228[m\u2238n] was deprecated in v1.1.\nPlease use \u2223m-n\u2223\u2261[m\u2238n]\u2228[n\u2238m] instead (note, you will need to switch the argument order).\"\n#-}\n\n-- Version 1.2\n\n+-*-suc = *-suc\n{-# WARNING_ON_USAGE +-*-suc\n\"Warning: +-*-suc was deprecated in v1.2.\nPlease use *-suc instead.\"\n#-}\n\nn\u2238m\u2264n : \u2200 m n \u2192 n \u2238 m \u2264 n\nn\u2238m\u2264n m n = m\u2238n\u2264m n m\n{-# WARNING_ON_USAGE n\u2238m\u2264n\n\"Warning: n\u2238m\u2264n was deprecated in v1.2.\nPlease use m\u2238n\u2264m instead (note, you will need to switch the argument order).\"\n#-}\n\n-- Version 1.3\n\n\u2200[m\u2264n\u21d2m\u2262o]\u21d2o or \\to\n\n {- To process an Agda file we use C-c C-c from emacs. Once Agda has\n checked the file the type checker also colours the different\n symbols. -}\n\n {- We define addition. Note Agda's syntax for mixfix operations. The\n arguments are represented by _s -}\n\n _+_ : \u2115 \u2192 \u2115 \u2192 \u2115\n zero + n = n\n suc m + n = suc (m + n)\n\n {- Try to evaluate: (suc (suc zero)) + (suc (suc zero))\n by typing in C-c C-n -}\n\n{- Better we import the library definition of \u2115\n This way we can type 2 instead of (suc (suc zero))\n-}\n \n-- open import Data.Nat\n\n{- We define Lists : -}\n\ndata List (A : Set) : Set where\n [] : List A\n _\u2237_ : (a : A) \u2192 (as : List A) \u2192 List A\n\n{- In future we'll use \n open import Data.List -}\n\n{- declare the fixity of \u2237 (type \\::) -}\n\ninfixr 5 _\u2237_\n\n{- Two example lists -}\n\n{-\nl1 : List \u2115\nl1 = 1 \u2237 2 \u2237 3 \u2237 []\n\nl2 : List \u2115\nl2 = 4 \u2237 5 \u2237 []\n-}\n\n{- implementing append (++) -}\n\n_++_ : {A : Set} \u2192 List A \u2192 List A \u2192 List A\n[] ++ bs = bs\n(a \u2237 as) ++ bs = a \u2237 (as ++ bs)\n\n{- Note that Agda checks wether a function is terminating.\n If we type\n (a \u2237 as) ++ bs = (a \u2237 as) ++ bs\n in the 2nd line Agda will complain by coloring the offending \n function calls in red.\n-}\n\n{- What does the following variant of ++ do ? -}\n\n_++'_ : {A : Set} \u2192 List A \u2192 List A \u2192 List A\nas ++' [] = as\nas ++' (b \u2237 bs) = (b \u2237 as) ++' bs\n\n{- Indeed it can be used to define reverse. This way to implement\n reverse is often called fast reverse because it is \"tail recursive\"\n which leads to a more efficient execution than the naive\n implementation. -}\n\nrev : {A : Set} \u2192 List A \u2192 List A\nrev as = [] ++' as\n\n{- We tried to define a function which accesses the nth element of a list:\n\n_!!_ : {A : Set} \u2192 List A \u2192 \u2115 \u2192 A\n[] !! n = {!!}\n(a \u2237 as) !! zero = a\n(a \u2237 as) !! suc n = as !! n\n\n but there is no way to complete the first line (consider what happens\n if A is the empty type! \n-}\n\n{- To fix this we handle errors explicitely, using Maybe -}\n\n-- open import Data.Maybe\n\ndata Maybe (A : Set) : Set where\n just : (x : A) \u2192 Maybe A\n nothing : Maybe A\n\n{- This version of the function can either return an element of the list \n (just a) or an error (nothing).\n-}\n_!!_ : {A : Set} \u2192 List A \u2192 \u2115 \u2192 Maybe A\n[] !! n = nothing\n(a \u2237 as) !! zero = just a\n(a \u2237 as) !! suc n = as !! n\n","avg_line_length":24.2666666667,"max_line_length":74,"alphanum_fraction":0.6085164835} {"size":389,"ext":"agda","lang":"Agda","max_stars_count":24.0,"content":"{-# OPTIONS --without-K --safe #-}\nmodule Cats.Category.Fun.Facts where\n\nopen import Cats.Category.Fun.Facts.Iso public using\n ( \u2248\u2192\u2245 ; \u2245\u2192\u2248 )\nopen import Cats.Category.Fun.Facts.Limit public using\n ( complete )\nopen import Cats.Category.Fun.Facts.Product public using\n ( hasBinaryProducts ; hasFiniteProducts )\nopen import Cats.Category.Fun.Facts.Terminal public using\n ( hasTerminal )\n","avg_line_length":32.4166666667,"max_line_length":57,"alphanum_fraction":0.7455012853} {"size":867,"ext":"agda","lang":"Agda","max_stars_count":39.0,"content":"{-\nThis second-order signature was created from the following second-order syntax description:\n\nsyntax CommGroup | CG\n\ntype\n * : 0-ary\n\nterm\n unit : * | \u03b5 \n add : * * -> * | _\u2295_ l20\n neg : * -> * | \u2296_ r40\n\ntheory\n (\u03b5U\u2295\u1d38) a |> add (unit, a) = a\n (\u03b5U\u2295\u1d3f) a |> add (a, unit) = a\n (\u2295A) a b c |> add (add(a, b), c) = add (a, add(b, c))\n (\u2296N\u2295\u1d38) a |> add (neg (a), a) = unit\n (\u2296N\u2295\u1d3f) a |> add (a, neg (a)) = unit\n (\u2295C) a b |> add(a, b) = add(b, a)\n-}\n\nmodule CommGroup.Signature where\n\nopen import SOAS.Context\n\nopen import SOAS.Common\n\n\nopen import SOAS.Syntax.Signature *T public\nopen import SOAS.Syntax.Build *T public\n\n-- Operator symbols\ndata CG\u2092 : Set where\n unit\u2092 add\u2092 neg\u2092 : CG\u2092\n\n-- Term signature\nCG:Sig : Signature CG\u2092\nCG:Sig = sig \u03bb\n { unit\u2092 \u2192 \u27fc\u2080 *\n ; add\u2092 \u2192 (\u22a2\u2080 *) , (\u22a2\u2080 *) \u27fc\u2082 *\n ; neg\u2092 \u2192 (\u22a2\u2080 *) \u27fc\u2081 *\n }\n\nopen Signature CG:Sig public\n","avg_line_length":18.847826087,"max_line_length":91,"alphanum_fraction":0.5651672434} {"size":4536,"ext":"agda","lang":"Agda","max_stars_count":11.0,"content":"------------------------------------------------------------------------------\n-- The alternating bit protocol (ABP) is correct\n------------------------------------------------------------------------------\n\n{-# OPTIONS --exact-split #-}\n{-# OPTIONS --no-sized-types #-}\n{-# OPTIONS --no-universe-polymorphism #-}\n{-# OPTIONS --without-K #-}\n\n-- This module proves the correctness of the ABP following the\n-- formalization in Dybjer and Sander (1989).\n\nmodule FOTC.Program.ABP.CorrectnessProofI where\n\nopen import FOTC.Base\nopen import FOTC.Base.List\nopen import FOTC.Data.Bool\nopen import FOTC.Data.Bool.PropertiesI\nopen import FOTC.Data.Stream.Type\nopen import FOTC.Data.Stream.Equality.PropertiesI\nopen import FOTC.Program.ABP.ABP\nopen import FOTC.Program.ABP.Lemma1I\nopen import FOTC.Program.ABP.Lemma2I\nopen import FOTC.Program.ABP.Fair.Type\nopen import FOTC.Program.ABP.Terms\nopen import FOTC.Relation.Binary.Bisimilarity.Type\n\n------------------------------------------------------------------------------\n-- Main theorem.\nabpCorrect : \u2200 {b os\u2081 os\u2082 is} \u2192 Bit b \u2192 Fair os\u2081 \u2192 Fair os\u2082 \u2192 Stream is \u2192\n is \u2248 abpTransfer b os\u2081 os\u2082 is\nabpCorrect {b} {os\u2081} {os\u2082} {is} Bb Fos\u2081 Fos\u2082 Sis = \u2248-coind B h\u2081 h\u2082\n where\n h\u2081 : \u2200 {ks ls} \u2192 B ks ls \u2192\n \u2203[ k' ] \u2203[ ks' ] \u2203[ ls' ] ks \u2261 k' \u2237 ks' \u2227 ls \u2261 k' \u2237 ls' \u2227 B ks' ls'\n h\u2081 {ks} {ls} (b , os\u2081 , os\u2082 , as , bs , cs , ds , Sks , Bb , Fos\u2081 , Fos\u2082 , h)\n with Stream-out Sks\n ... | (k' , ks' , ks\u2261k'\u2237ks' , Sks') =\n k' , ks' , ls' , ks\u2261k'\u2237ks' , ls\u2261k'\u2237ls' , Bks'ls'\n where\n S-helper : ks \u2261 k' \u2237 ks' \u2192\n S b ks os\u2081 os\u2082 as bs cs ds ls \u2192\n S b (k' \u2237 ks') os\u2081 os\u2082 as bs cs ds ls\n S-helper h\u2081 h\u2082 = subst (\u03bb t \u2192 S b t os\u2081 os\u2082 as bs cs ds ls) h\u2081 h\u2082\n\n S'-lemma\u2081 : \u2203[ os\u2081' ] \u2203[ os\u2082' ] \u2203[ as' ] \u2203[ bs' ] \u2203[ cs' ] \u2203[ ds' ] \u2203[ ls' ]\n Fair os\u2081'\n \u2227 Fair os\u2082'\n \u2227 S' b k' ks' os\u2081' os\u2082' as' bs' cs' ds' ls'\n \u2227 ls \u2261 k' \u2237 ls'\n S'-lemma\u2081 = lemma\u2081 Bb Fos\u2081 Fos\u2082 (S-helper ks\u2261k'\u2237ks' h)\n\n -- Following Martin Escardo advice (see Agda mailing list, heap\n -- mistery) we use pattern matching instead of \u2203 eliminators to\n -- project the elements of the existentials.\n\n -- 2011-08-25 update: It does not seems strictly necessary because\n -- the Agda issue 415 was fixed.\n\n ls' : D\n ls' with S'-lemma\u2081\n ... | _ , _ , _ , _ , _ , _ , ls' , _ = ls'\n\n ls\u2261k'\u2237ls' : ls \u2261 k' \u2237 ls'\n ls\u2261k'\u2237ls' with S'-lemma\u2081\n ... | _ , _ , _ , _ , _ , _ , _ , _ , _ , _ , prf = prf\n\n S-lemma\u2082 : \u2203[ os\u2081'' ] \u2203[ os\u2082'' ] \u2203[ as'' ] \u2203[ bs'' ] \u2203[ cs'' ] \u2203[ ds'' ]\n Fair os\u2081''\n \u2227 Fair os\u2082''\n \u2227 S (not b) ks' os\u2081'' os\u2082'' as'' bs'' cs'' ds'' ls'\n S-lemma\u2082 with S'-lemma\u2081\n ... | _ , _ , _ , _ , _ , _ , _ , Fos\u2081' , Fos\u2082' , s' , _ =\n lemma\u2082 Bb Fos\u2081' Fos\u2082' s'\n\n Bks'ls' : B ks' ls'\n Bks'ls' with S-lemma\u2082\n ... | os\u2081'' , os\u2082'' , as'' , bs'' , cs'' , ds'' , Fos\u2081'' , Fos\u2082'' , s =\n not b , os\u2081'' , os\u2082'' , as'' , bs'' , cs'' , ds''\n , Sks' , not-Bool Bb , Fos\u2081'' , Fos\u2082'' , s\n\n h\u2082 : B is (abpTransfer b os\u2081 os\u2082 is)\n h\u2082 = b\n , os\u2081\n , os\u2082\n , has aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , hbs aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , hcs aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , hds aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , Sis\n , Bb\n , Fos\u2081\n , Fos\u2082\n , has-eq aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , hbs-eq aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , hcs-eq aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , hds-eq aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is\n , trans (abpTransfer-eq b os\u2081 os\u2082 is)\n (transfer-eq aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 is)\n where\n aux\u2081 aux\u2082 aux\u2083 aux\u2084 aux\u2085 : D\n aux\u2081 = send b\n aux\u2082 = ack b\n aux\u2083 = out b\n aux\u2084 = corrupt os\u2081\n aux\u2085 = corrupt os\u2082\n\n------------------------------------------------------------------------------\n-- abpTransfer produces a Stream.\nabpTransfer-Stream : \u2200 {b os\u2081 os\u2082 is} \u2192\n Bit b \u2192\n Fair os\u2081 \u2192\n Fair os\u2082 \u2192\n Stream is \u2192\n Stream (abpTransfer b os\u2081 os\u2082 is)\nabpTransfer-Stream Bb Fos\u2081 Fos\u2082 Sis = \u2248\u2192Stream\u2082 (abpCorrect Bb Fos\u2081 Fos\u2082 Sis)\n\n------------------------------------------------------------------------------\n-- References\n--\n-- Dybjer, Peter and Sander, Herbert P. (1989). A Functional\n-- Programming Approach to the Specification and Verification of\n-- Concurrent Systems. Formal Aspects of Computing 1, pp. 303\u2013319.\n","avg_line_length":36.5806451613,"max_line_length":80,"alphanum_fraction":0.4914021164} {"size":479,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"-- Andreas, Ulf, 2016-06-01, discussing issue #679\n-- {-# OPTIONS -v tc.with.strip:20 #-}\n\npostulate anything : {A : Set} \u2192 A\n\ndata Ty : Set where\n _=>_ : (a b : Ty) \u2192 Ty\n\n\u27e6_\u27e7 : Ty \u2192 Set\n\u27e6 a => b \u27e7 = \u27e6 a \u27e7 \u2192 \u27e6 b \u27e7\n\neq : (a : Ty) \u2192 \u27e6 a \u27e7 \u2192 \u27e6 a \u27e7 \u2192 Set\neq (a => b) f g = \u2200 {x y : \u27e6 a \u27e7} \u2192 eq a x y \u2192 eq b (f x) (g y)\n\nbad : (a : Ty) (x : \u27e6 a \u27e7) \u2192 eq a x x\nbad (a => b) f h with b\nbad (a => b) f h | _ = anything\n-- ERROR WAS: Too few arguments in with clause!\n-- Should work now.\n","avg_line_length":23.95,"max_line_length":63,"alphanum_fraction":0.4822546973} {"size":586,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"-- 2010-11-21\n-- testing correct implementation of eta for records with higher-order fields\n\nmodule Issue366 where\n\ndata Bool : Set where\n true false : Bool\n\nrecord R (A : Set) : Set where\n constructor r\n field\n unR : A\n\nopen R\n\nfoo : Bool\nfoo = unR (r (unR (r (\u03bb (_ : Bool) \u2192 false))\n true))\n-- before 2010-11-21, an incorrect implementation of eta-contraction\n-- reduced foo to (unR true)\n-- Error message was (due to clause compilation):\n-- Incomplete pattern matching\n\ndata _==_ {A : Set}(a : A) : A -> Set where\n refl : a == a\n\ntest : foo == false\ntest = refl\n\n","avg_line_length":19.5333333333,"max_line_length":77,"alphanum_fraction":0.6501706485} {"size":743,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"-- Andreas, 2016-09-20, issue #2196 reported by mechvel\n-- Test case by Ulf\n\n-- {-# OPTIONS -v tc.lhs.dot:40 #-}\n\ndata _\u2261_ {a} {A : Set a} (x : A) : A \u2192 Set a where\n refl : x \u2261 x\n\nrecord _\u00d7_ (A B : Set) : Set where\n constructor _,_\n field fst : A\n snd : B\nopen _\u00d7_\n\nEqP\u2081 : \u2200 {A B} (p q : A \u00d7 B) \u2192 Set\nEqP\u2081 (x , y) (z , w) = (x \u2261 z) \u00d7 (y \u2261 w)\n\nEqP\u2082 : \u2200 {A B} (p q : A \u00d7 B) \u2192 Set\nEqP\u2082 p q = (fst p \u2261 fst q) \u00d7 (snd p \u2261 snd q)\n\nworks : {A : Set} (p q : A \u00d7 A) \u2192 EqP\u2081 p q \u2192 Set\u2081\nworks (x , y) .(x , y) (refl , refl) = Set\n\ntest : {A : Set} (p q : A \u00d7 A) \u2192 EqP\u2082 p q \u2192 Set\u2081\ntest (x , y) .(x , y) (refl , refl) = Set\n\n-- ERROR WAS:\n-- Failed to infer the value of dotted pattern\n-- when checking that the pattern .(x , y) has type .A \u00d7 .A\n","avg_line_length":24.7666666667,"max_line_length":59,"alphanum_fraction":0.5114401077} {"size":632,"ext":"agda","lang":"Agda","max_stars_count":5.0,"content":"------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- This module is DEPRECATED. Please use\n-- Data.Vec.Relation.Binary.Equality.DecSetoid directly.\n------------------------------------------------------------------------\n\n{-# OPTIONS --without-K --safe #-}\n\nopen import Relation.Binary\n\nmodule Data.Vec.Relation.Equality.DecSetoid\n {a \u2113} (DS : DecSetoid a \u2113) where\n\nopen import Data.Vec.Relation.Binary.Equality.DecSetoid public\n\n{-# WARNING_ON_IMPORT\n\"Data.Vec.Relation.Equality.DecSetoid was deprecated in v1.0.\nUse Data.Vec.Relation.Binary.Equality.DecSetoid instead.\"\n#-}\n","avg_line_length":30.0952380952,"max_line_length":72,"alphanum_fraction":0.5838607595} {"size":464,"ext":"agda","lang":"Agda","max_stars_count":2.0,"content":"\n-- Jesper, 2017-01-24: if we allow a variable to be instantiated with a value\n-- of a supertype, the resulting dot pattern won't be type-correct.\n\nopen import Common.Size\n\ndata D (i : Size) : (j : Size< \u2191 i) \u2192 Set where\n\n c : \u2200 (j : Size< \u2191 i) (k : Size< \u2191 j)\n \u2192 D i j\n \u2192 D j k\n \u2192 D i k\n\nsplit : \u2200 i (j : Size< \u2191 i) \u2192 D i j \u2192 Set\nsplit i j x = {!x!} -- split on x\n\n-- Expected: splitting on x succeeds with\n-- split i .k (c j k x x\u2081) = {!!}\n","avg_line_length":24.4210526316,"max_line_length":77,"alphanum_fraction":0.5495689655} {"size":1810,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module Relations where\n\nopen import Level as Level using (zero)\nopen import Size\nopen import Function\nopen import Relation.Binary\nopen import Relation.Binary.PropositionalEquality as P\nopen \u2261-Reasoning\n\nRelTrans : Set \u2192 Set\u2081\nRelTrans B = Rel B Level.zero \u2192 Rel B Level.zero\n\nMonotone : \u2200{B} \u2192 RelTrans B \u2192 Set\u2081\nMonotone F = \u2200 {R S} \u2192 R \u21d2 S \u2192 F R \u21d2 F S\n\n-- | Useful example of a compatible up-to technique: equivalence closure.\ndata EquivCls {B : Set} (R : Rel B Level.zero) : Rel B Level.zero where\n cls-incl : {a b : B} \u2192 R a b \u2192 EquivCls R a b\n cls-refl : {b : B} \u2192 EquivCls R b b\n cls-sym : {a b : B} \u2192 EquivCls R a b \u2192 EquivCls R b a\n cls-trans : {a b c : B} \u2192 EquivCls R a b \u2192 EquivCls R b c \u2192 EquivCls R a c\n\n-- | The operation of taking the equivalence closure is monotone.\nequivCls-monotone : \u2200{B} \u2192 Monotone {B} EquivCls\nequivCls-monotone R\u2264S (cls-incl xRy) = cls-incl (R\u2264S xRy)\nequivCls-monotone R\u2264S cls-refl = cls-refl\nequivCls-monotone R\u2264S (cls-sym p) = cls-sym (equivCls-monotone R\u2264S p)\nequivCls-monotone R\u2264S (cls-trans p q) =\n cls-trans (equivCls-monotone R\u2264S p) (equivCls-monotone R\u2264S q)\n\n-- | The equivalence closure is indeed a closure operator.\nequivCls-expanding : \u2200{B R} \u2192 R \u21d2 EquivCls {B} R\nequivCls-expanding p = cls-incl p\n\nequivCls-idempotent : \u2200{B R} \u2192 EquivCls (EquivCls R) \u21d2 EquivCls {B} R\nequivCls-idempotent (cls-incl p) = p\nequivCls-idempotent cls-refl = cls-refl\nequivCls-idempotent (cls-sym p) = cls-sym (equivCls-idempotent p)\nequivCls-idempotent (cls-trans p q) =\n cls-trans (equivCls-idempotent p) (equivCls-idempotent q)\n\n-- | Equivalence closure gives indeed equivalence relation\nequivCls-equiv : \u2200{A} \u2192 (R : Rel A _) \u2192 IsEquivalence (EquivCls R)\nequivCls-equiv R = record\n { refl = cls-refl\n ; sym = cls-sym\n ; trans = cls-trans\n }\n","avg_line_length":36.9387755102,"max_line_length":76,"alphanum_fraction":0.6834254144} {"size":90,"ext":"agda","lang":"Agda","max_stars_count":1.0,"content":"{-# OPTIONS --universe-polymorphism #-}\n\nmodule SetInf where\n\nid : \u2200 {A} \u2192 A \u2192 A\nid x = x\n","avg_line_length":12.8571428571,"max_line_length":39,"alphanum_fraction":0.5888888889} {"size":7371,"ext":"agda","lang":"Agda","max_stars_count":12.0,"content":"------------------------------------------------------------------------\n-- Propierties of abstract typing contexts\n------------------------------------------------------------------------\n\n{-# OPTIONS --safe --without-K #-}\n\nmodule Data.Context.Properties where\n\nopen import Data.Fin using (Fin; zero; suc; lift; raise)\nopen import Data.Fin.Substitution.Extra using (Extension)\nopen import Data.Nat using (\u2115; zero; suc; _+_)\nopen import Data.Product using (_\u00d7_; _,_)\nopen import Data.Vec as Vec using (Vec; []; _\u2237_)\nimport Data.Vec.Properties as VecProps\nopen import Function as Fun using (_\u2218_; flip)\nopen import Relation.Binary.PropositionalEquality hiding (subst-\u2218)\nopen \u2261-Reasoning\nopen import Relation.Unary using (Pred)\n\nopen import Data.Context\nopen import Data.Context.WellFormed\n\n\n------------------------------------------------------------------------\n-- Properties of abstract contexts and context extensions.\n\n-- Properties of the `map' functions.\n\nmodule _ {\u2113\u2081 \u2113\u2082} {T\u2081 : Pred \u2115 \u2113\u2081} {T\u2082 : Pred \u2115 \u2113\u2082} where\n\n -- pointwise equality is a congruence w.r.t. map and mapExt.\n\n map-cong : \u2200 {n} {f g : \u2200 {k} \u2192 T\u2081 k \u2192 T\u2082 k} \u2192 (\u2200 {k} \u2192 f {k} \u2257 g {k}) \u2192\n _\u2257_ {A = Ctx T\u2081 n} (map f) (map g)\n map-cong f\u2257g [] = refl\n map-cong f\u2257g (_\u2237_ t \u0393) = cong\u2082 _\u2237_ (f\u2257g t) (map-cong f\u2257g \u0393)\n\n mapExt-cong : \u2200 {k m n} {f g : \u2200 i \u2192 T\u2081 (i + m) \u2192 T\u2082 (i + n)} \u2192\n (\u2200 {i} \u2192 f i \u2257 g i) \u2192\n _\u2257_ {A = CtxExt T\u2081 m k} (mapExt {T\u2082 = T\u2082} f) (mapExt g)\n mapExt-cong f\u2257g [] = refl\n mapExt-cong f\u2257g (_\u2237_ {l} t \u0393) = cong\u2082 _\u2237_ (f\u2257g {l} t) (mapExt-cong f\u2257g \u0393)\n\nmodule _ {\u2113} {T : Pred \u2115 \u2113} where\n\n -- map and mapExt are functorial.\n\n map-id : \u2200 {n} \u2192 _\u2257_ {A = Ctx T n} (map Fun.id) Fun.id\n map-id [] = refl\n map-id (t \u2237 \u0393) = cong (t \u2237_) (map-id \u0393)\n\n mapExt-id : \u2200 {m n} \u2192 _\u2257_ {A = CtxExt T m n} (mapExt \u03bb _ t \u2192 t) Fun.id\n mapExt-id [] = refl\n mapExt-id (t \u2237 \u0393) = cong (t \u2237_) (mapExt-id \u0393)\n\nmodule _ {\u2113\u2081 \u2113\u2082 \u2113\u2083} {T\u2081 : Pred \u2115 \u2113\u2081} {T\u2082 : Pred \u2115 \u2113\u2082} {T\u2083 : Pred \u2115 \u2113\u2083} where\n\n map-\u2218 : \u2200 {n} (f : \u2200 {k} \u2192 T\u2082 k \u2192 T\u2083 k) (g : \u2200 {k} \u2192 T\u2081 k \u2192 T\u2082 k)\n (\u0393 : Ctx T\u2081 n) \u2192 map {T\u2082 = T\u2083} (f \u2218 g) \u0393 \u2261 map {T\u2081 = T\u2082} f (map g \u0393)\n map-\u2218 f g [] = refl\n map-\u2218 f g (t \u2237 \u0393) = cong (_ \u2237_) (map-\u2218 f g \u0393)\n\n mapExt-\u2218 : \u2200 {k l m n}\n (f : \u2200 i \u2192 T\u2082 (i + m) \u2192 T\u2083 (i + n))\n (g : \u2200 i \u2192 T\u2081 (i + l) \u2192 T\u2082 (i + m)) \u2192\n (\u0393 : CtxExt T\u2081 l k) \u2192\n mapExt {T\u2082 = T\u2083} (\u03bb i t \u2192 f i (g i t)) \u0393 \u2261\n mapExt {T\u2081 = T\u2082} f (mapExt g \u0393)\n mapExt-\u2218 f g [] = refl\n mapExt-\u2218 f g (t \u2237 \u0393) = cong (_ \u2237_) (mapExt-\u2218 f g \u0393)\n\n-- Lemmas about operations on contexts that require weakening of\n-- types.\n\nmodule WeakenOpsLemmas {\u2113} {T : Pred \u2115 \u2113} (extension : Extension T) where\n\n -- The underlyig operations.\n open WeakenOps extension\n\n -- Conversion to vector representation commutes with\n -- concatenation.\n\n toVec-++ : \u2200 {m n} (\u0394 : CtxExt T m n) (\u0393 : Ctx T m) \u2192\n toVec (\u0394 ++ \u0393) \u2261 extToVec \u0394 (toVec \u0393)\n toVec-++ [] \u0393 = refl\n toVec-++ (t \u2237 \u0394) \u0393 =\n cong ((_ \u2237_) \u2218 Vec.map weaken) (toVec-++ \u0394 \u0393)\n\n -- Lookup commutes with concatenation.\n\n lookup-++ : \u2200 {m n} (\u0394 : CtxExt T m n) (\u0393 : Ctx T m) x \u2192\n lookup (\u0394 ++ \u0393) x \u2261 extLookup \u0394 (toVec \u0393) x\n lookup-++ \u0394 \u0393 x = cong (flip Vec.lookup x) (toVec-++ \u0394 \u0393)\n\n -- We can skip the first element when looking up others.\n\n lookup-suc : \u2200 {n} t (\u0393 : Ctx T n) x \u2192\n lookup (t \u2237 \u0393) (suc x) \u2261 weaken (lookup \u0393 x)\n lookup-suc t \u0393 x = VecProps.lookup-map x weaken (toVec \u0393)\n\n extLookup-suc : \u2200 {k m n} t (\u0393 : CtxExt T m n) (ts : Vec (T m) k) x \u2192\n extLookup (t \u2237 \u0393) ts (suc x) \u2261 weaken (extLookup \u0393 ts x)\n extLookup-suc t \u0393 ts x = VecProps.lookup-map x weaken (extToVec \u0393 ts)\n\n -- We can skip a spliced-in element when looking up others.\n\n lookup-lift : \u2200 {k m n} (\u0393 : CtxExt T m n) t (ts : Vec (T m) k) x \u2192\n extLookup \u0393 ts x \u2261 extLookup \u0393 (t \u2237 ts) (lift n suc x)\n lookup-lift [] t ts x = refl\n lookup-lift (u \u2237 \u0394) t ts zero = refl\n lookup-lift {n = suc n} (u \u2237 \u0394) t ts (suc x) = begin\n extLookup (u \u2237 \u0394) ts (suc x)\n \u2261\u27e8 extLookup-suc u \u0394 ts x \u27e9\n weaken (extLookup \u0394 ts x)\n \u2261\u27e8 cong weaken (lookup-lift \u0394 t ts x) \u27e9\n weaken (extLookup \u0394 (t \u2237 ts) (lift n suc x))\n \u2261\u27e8 sym (extLookup-suc u \u0394 (t \u2237 ts) (lift n suc x)) \u27e9\n extLookup (u \u2237 \u0394) (t \u2237 ts) (suc (lift n suc x))\n \u220e\n\n -- Lookup in the prefix of a concatenation results in weakening.\n\n lookup-weaken\u22c6 : \u2200 {m} n (\u0394 : CtxExt T m n) (\u0393 : Ctx T m) x \u2192\n lookup (\u0394 ++ \u0393) (raise n x) \u2261 weaken\u22c6 n (lookup \u0393 x)\n lookup-weaken\u22c6 zero [] \u0393 x = refl\n lookup-weaken\u22c6 (suc n) (t \u2237 \u0394) \u0393 x = begin\n lookup (t \u2237 \u0394 ++ \u0393) (suc (raise n x))\n \u2261\u27e8 VecProps.lookup-map (raise n x) weaken (toVec (\u0394 ++ \u0393)) \u27e9\n weaken (lookup (\u0394 ++ \u0393) (raise n x))\n \u2261\u27e8 cong weaken (lookup-weaken\u22c6 n \u0394 \u0393 x) \u27e9\n weaken (weaken\u22c6 n (lookup \u0393 x))\n \u220e\n\n-- Lemmas relating conversions of context extensions to vector\n-- representation with conversions of the underling entries.\n\nmodule ConversionLemmas {T\u2081 T\u2082 : \u2115 \u2192 Set}\n (extension\u2081 : Extension T\u2081)\n (extension\u2082 : Extension T\u2082) where\n private\n module W\u2081 = WeakenOps extension\u2081\n module W\u2082 = WeakenOps extension\u2082\n\n toVec-map : \u2200 {n} (f : \u2200 {k} \u2192 T\u2081 k \u2192 T\u2082 k) (\u0393 : Ctx T\u2081 n) \u2192\n (\u2200 {k} (t : T\u2081 k) \u2192 W\u2082.weaken (f t) \u2261 f (W\u2081.weaken t)) \u2192\n W\u2082.toVec (map f \u0393) \u2261 Vec.map f (W\u2081.toVec \u0393)\n toVec-map f [] _ = refl\n toVec-map f (_\u2237_ t \u0393) hyp = cong\u2082 _\u2237_ (hyp t) (begin\n Vec.map W\u2082.weaken (W\u2082.toVec (map f \u0393))\n \u2261\u27e8 cong (Vec.map W\u2082.weaken) (toVec-map f \u0393 hyp) \u27e9\n (Vec.map W\u2082.weaken (Vec.map f (W\u2081.toVec \u0393)))\n \u2261\u27e8 sym (VecProps.map-\u2218 W\u2082.weaken f (W\u2081.toVec \u0393)) \u27e9\n (Vec.map (W\u2082.weaken \u2218 f) (W\u2081.toVec \u0393))\n \u2261\u27e8 VecProps.map-cong hyp (W\u2081.toVec \u0393) \u27e9\n (Vec.map (f \u2218 W\u2081.weaken) (W\u2081.toVec \u0393))\n \u2261\u27e8 VecProps.map-\u2218 f W\u2081.weaken (W\u2081.toVec \u0393) \u27e9\n (Vec.map f (Vec.map W\u2081.weaken (W\u2081.toVec \u0393)))\n \u220e)\n\n -- Lookup commutes with re-indexing, provided that the reindexing\n -- function commutes with weakening.\n\n lookup-map : \u2200 {n} (f : \u2200 {k} \u2192 T\u2081 k \u2192 T\u2082 k) (\u0393 : Ctx T\u2081 n) x \u2192\n (\u2200 {k} (t : T\u2081 k) \u2192 W\u2082.weaken (f t) \u2261 f (W\u2081.weaken t)) \u2192\n W\u2082.lookup (map f \u0393) x \u2261 f (W\u2081.lookup \u0393 x)\n lookup-map f \u0393 x hyp = begin\n W\u2082.lookup (map f \u0393) x\n \u2261\u27e8 cong (flip Vec.lookup x) (toVec-map f \u0393 hyp) \u27e9\n Vec.lookup (Vec.map f (W\u2081.toVec \u0393)) x\n \u2261\u27e8 VecProps.lookup-map x f (W\u2081.toVec \u0393) \u27e9\n f (W\u2081.lookup \u0393 x)\n \u220e\n\n-- Lemmas about well-formed contexts and context extensions.\n\nmodule ContextFormationLemmas {t \u2113} {T : Pred \u2115 t}\n (_\u22a2_wf : Wf T T \u2113) where\n open ContextFormation _\u22a2_wf\n\n -- Concatenation preserves well-formedness of contexts.\n\n wf-++-wfExt : \u2200 {m n} {\u0394 : CtxExt T m n} {\u0393 : Ctx T m} \u2192\n \u0393 \u22a2 \u0394 wfExt \u2192 \u0393 wf \u2192 \u0394 ++ \u0393 wf\n wf-++-wfExt [] \u0393-wf = \u0393-wf\n wf-++-wfExt (t-wf \u2237 \u0394-wfExt) \u0393-wf = t-wf \u2237 wf-++-wfExt \u0394-wfExt \u0393-wf\n\n -- Splitting of well-formed contexts.\n wf-split : \u2200 {m n} {\u0394 : CtxExt T m n} {\u0393 : Ctx T m} \u2192\n \u0394 ++ \u0393 wf \u2192 \u0393 \u22a2 \u0394 wfExt \u00d7 \u0393 wf\n wf-split {\u0394 = []} \u0393-wf = [] , \u0393-wf\n wf-split {\u0394 = t \u2237 \u0394} (t-wf \u2237 \u0394++\u0393-wf) =\n let \u0394-wfExt , \u0393-wf = wf-split \u0394++\u0393-wf\n in t-wf \u2237 \u0394-wfExt , \u0393-wf\n","avg_line_length":37.9948453608,"max_line_length":78,"alphanum_fraction":0.5213675214} {"size":617,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"{-# OPTIONS --experimental-irrelevance #-}\nmodule ShapeIrrelevantIndexNoBecauseOfRecursion where\n\ndata \u22a5 : Set where\n\nrecord \u22a4 : Set where\n constructor trivial\n\ndata Bool : Set where\n true false : Bool\n\nTrue : Bool \u2192 Set\nTrue false = \u22a5\nTrue true = \u22a4\n\ndata D : ..(b : Bool) \u2192 Set where\n c : {b : Bool} \u2192 True b \u2192 D b\n-- because of the irrelevant index,\n-- D is in essence an existental type D : Set\n-- with constructor c : {b : Bool} \u2192 True b \u2192 D\n\nfromD : {b : Bool} \u2192 D b \u2192 True b\nfromD (c p) = p -- should fail\n\ncast : .(a b : Bool) \u2192 D a \u2192 D b\ncast _ _ x = x\n\nbot : \u22a5\nbot = fromD (cast true false (c trivial))\n","avg_line_length":20.5666666667,"max_line_length":53,"alphanum_fraction":0.6288492707} {"size":4105,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.\n\n Copyright (c) 2020, 2021, Oracle and\/or its affiliates.\n Licensed under the Universal Permissive License v 1.0 as shown at https:\/\/opensource.oracle.com\/licenses\/upl\n-}\n{-# OPTIONS --allow-unsolved-metas #-}\nopen import Optics.All\nopen import LibraBFT.Prelude\nopen import LibraBFT.Lemmas\nopen import LibraBFT.Base.KVMap\nopen import LibraBFT.Base.PKCS\nopen import LibraBFT.Base.Types\nopen import LibraBFT.Impl.Base.Types\nopen import LibraBFT.Impl.Consensus.Types.EpochIndep\nopen import LibraBFT.Impl.NetworkMsg\nopen import LibraBFT.Impl.Util.Crypto\nopen import LibraBFT.Abstract.Types.EpochConfig UID NodeId\nopen WithAbsVote\n\n-- Here we have the abstraction functions that connect\n-- the datatypes defined in LibraBFT.Impl.Consensus.Types\n-- to the abstract records from LibraBFT.Abstract.Records\n-- for a given EpochConfig.\n--\nmodule LibraBFT.Concrete.Records (\ud835\udcd4 : EpochConfig) where\n open import LibraBFT.Impl.Consensus.Types.EpochDep \ud835\udcd4\n open import LibraBFT.Abstract.Abstract UID _\u225fUID_ NodeId \ud835\udcd4 ConcreteVoteEvidence as Abs hiding (bId; qcVotes; Block)\n open EpochConfig \ud835\udcd4\n --------------------------------\n -- Abstracting Blocks and QCs --\n --------------------------------\n\n \u03b1-Block : Block \u2192 Abs.Block\n \u03b1-Block b with \u208bbdBlockType (\u208bbBlockData b)\n ...| NilBlock = record\n { bId = \u208bbId b\n ; bPrevQC = just (b ^\u2219 (bBlockData \u2219 bdQuorumCert \u2219 qcVoteData \u2219 vdParent \u2219 biId))\n ; bRound = b ^\u2219 bBlockData \u2219 bdRound\n }\n ...| Genesis = record\n { bId = b ^\u2219 bId\n ; bPrevQC = nothing\n ; bRound = b ^\u2219 bBlockData \u2219 bdRound\n }\n ...| Proposal cmd \u03b1 = record\n { bId = b ^\u2219 bId\n ; bPrevQC = just (b ^\u2219 bBlockData \u2219 bdQuorumCert \u2219 qcVoteData \u2219 vdParent \u2219 biId)\n ; bRound = b ^\u2219 bBlockData \u2219 bdRound\n }\n\n \u03b1-VoteData-Block : VoteData \u2192 Abs.Block\n \u03b1-VoteData-Block vd = record\n { bId = vd ^\u2219 vdProposed \u2219 biId\n ; bPrevQC = just (vd ^\u2219 vdParent \u2219 biId)\n ; bRound = vd ^\u2219 vdProposed \u2219 biRound\n }\n\n \u03b1-Vote : (qc : QuorumCert)(valid : MetaIsValidQC qc) \u2192 \u2200 {as} \u2192 as \u2208 qcVotes qc \u2192 Abs.Vote\n \u03b1-Vote qc v {as} as\u2208QC = \u03b1-ValidVote (rebuildVote qc as)\n (\u208bivvMember (All-lookup (\u208bivqcMetaVotesValid v) as\u2208QC))\n\n -- Abstraction of votes produce votes that carry evidence\n -- they have been cast.\n \u03b1-Vote-evidence : (qc : QuorumCert)(valid : MetaIsValidQC qc)\n \u2192 \u2200{vs} (prf : vs \u2208 qcVotes qc)\n \u2192 ConcreteVoteEvidence (\u03b1-Vote qc valid prf)\n \u03b1-Vote-evidence qc valid {as} v\u2208qc\n = record { \u208bcveVote = rebuildVote qc as\n ; \u208bcveIsValidVote = All-lookup (\u208bivqcMetaVotesValid valid) v\u2208qc\n ; \u208bcveIsAbs = refl\n }\n\n \u03b1-QC : \u03a3 QuorumCert MetaIsValidQC \u2192 Abs.QC\n \u03b1-QC (qc , valid) = record\n { qCertBlockId = qc ^\u2219 qcVoteData \u2219 vdProposed \u2219 biId\n ; qRound = qc ^\u2219 qcVoteData \u2219 vdProposed \u2219 biRound\n ; qVotes = All-reduce (\u03b1-Vote qc valid) All-self\n ; qVotes-C1 = {! MetaIsValidQC.\u208bivqcMetaIsQuorum valid!}\n ; qVotes-C2 = All-reduce\u207a (\u03b1-Vote qc valid) (\u03bb _ \u2192 refl) All-self\n ; qVotes-C3 = All-reduce\u207a (\u03b1-Vote qc valid) (\u03bb _ \u2192 refl) All-self\n ; qVotes-C4 = All-reduce\u207a (\u03b1-Vote qc valid) (\u03b1-Vote-evidence qc valid) All-self\n }\n\n -- What does it mean for an (abstract) Block or QC to be represented in a NetworkMsg?\n data _\u03b1-\u2208NM_ : Abs.Record \u2192 NetworkMsg \u2192 Set where\n qc\u2208NM : \u2200 {cqc q nm}\n \u2192 (valid : MetaIsValidQC cqc)\n \u2192 cqc QC\u2208NM nm\n \u2192 q \u2261 \u03b1-QC (cqc , valid)\n \u2192 Abs.Q q \u03b1-\u2208NM nm\n b\u2208NM : \u2200 {cb pm nm}\n \u2192 nm \u2261 P pm\n \u2192 pm ^\u2219 pmProposal \u2261 cb\n \u2192 Abs.B (\u03b1-Block cb) \u03b1-\u2208NM nm\n\n -- Our system model contains a message pool, which is a list of NodeId-NetworkMsg pairs. The\n -- following relation expresses that an abstract record r is represented in a given message pool\n -- sm.\n data _\u03b1-Sent_ (r : Abs.Record) (sm : List (NodeId \u00d7 NetworkMsg)) : Set where\n ws : \u2200 {p nm} \u2192 getEpoch nm \u2261 epoch \u2192 (p , nm) \u2208 sm \u2192 r \u03b1-\u2208NM nm \u2192 r \u03b1-Sent sm\n","avg_line_length":40.6435643564,"max_line_length":116,"alphanum_fraction":0.6299634592} {"size":5959,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"\nmodule Equality where\n\n\n-- Equality\n\ndata _\u2261_ {A : Set} (x : A) : A \u2192 Set where\n refl : x \u2261 x\n\ninfix 4 _\u2261_\n\n\n-- Equality is an equivalence relation\n\nsym : \u2200 {A : Set} {x y : A}\n \u2192 x \u2261 y\n -----\n \u2192 y \u2261 x\nsym {A} {x} {.x} refl = refl\n\n\ntrans : \u2200 {A : Set} {x y z : A}\n \u2192 x \u2261 y\n \u2192 y \u2261 z\n -----\n \u2192 x \u2261 z\ntrans {A} {x} {.x} {.x} refl refl = refl\n\n\n-- Congruence and substitution\n\ncong : \u2200 {A B : Set} (f : A \u2192 B) {x y : A}\n \u2192 x \u2261 y\n ---------\n \u2192 f x \u2261 f y\ncong f refl = refl\n\n\ncong\u2082 : \u2200 {A B C : Set} (f : A \u2192 B \u2192 C) {u x : A} {v y : B}\n \u2192 u \u2261 x\n \u2192 v \u2261 y\n -------------\n \u2192 f u v \u2261 f x y\ncong\u2082 f refl refl = refl\n\n\ncong-app : \u2200 {A B : Set} {f g : A \u2192 B}\n \u2192 f \u2261 g\n ---------------------\n \u2192 \u2200 (x : A) \u2192 f x \u2261 g x\ncong-app refl x = refl\n\n\nsubst : \u2200 {A : Set} {x y : A} (P : A \u2192 Set)\n \u2192 x \u2261 y\n ---------\n \u2192 P x \u2192 P y\nsubst P refl px = px\n\n\n\nopen import AuxDefs\n\ndata even : \u2115 \u2192 Set\ndata odd : \u2115 \u2192 Set\n\ndata even where\n\n even-zero : even zero\n\n even-suc : \u2200 {n : \u2115}\n \u2192 odd n\n ------------\n \u2192 even (suc n)\n\ndata odd where\n odd-suc : \u2200 {n : \u2115}\n \u2192 even n\n -----------\n \u2192 odd (suc n)\n\npostulate\n +-comm : \u2200 (m n : \u2115) \u2192 m + n \u2261 n + m\n\n\neven-comm : \u2200 (m n : \u2115)\n \u2192 even (m + n)\n ------------\n \u2192 even (n + m)\neven-comm m n = subst even (+-comm m n)\n\n\n-- Chains of equations\n\nmodule \u2261-Reasoning {A : Set} where\n\n infix 1 begin_\n infixr 2 _\u2261\u27e8\u27e9_ _\u2261\u27e8_\u27e9_\n infix 3 _\u220e\n\n begin_ : \u2200 {x y : A}\n \u2192 x \u2261 y\n -----\n \u2192 x \u2261 y\n begin x\u2261y = x\u2261y\n\n _\u2261\u27e8\u27e9_ : \u2200 (x : A) {y : A}\n \u2192 x \u2261 y\n -----\n \u2192 x \u2261 y\n x \u2261\u27e8\u27e9 x\u2261y = x\u2261y\n\n _\u2261\u27e8_\u27e9_ : \u2200 (x : A) {y z : A}\n \u2192 x \u2261 y\n \u2192 y \u2261 z\n -----\n \u2192 x \u2261 z\n x \u2261\u27e8 x\u2261y \u27e9 y\u2261z = trans x\u2261y y\u2261z\n\n _\u220e : \u2200 (x : A)\n -----\n \u2192 x \u2261 x\n x \u220e = refl\n\nopen \u2261-Reasoning\n\n\ntrans\u2032 : \u2200 {A : Set} {x y z : A}\n \u2192 x \u2261 y\n \u2192 y \u2261 z\n -----\n \u2192 x \u2261 z\ntrans\u2032 {A} {x} {y} {z} x\u2261y y\u2261z = -- begin (x \u2261\u27e8 x\u2261y \u27e9 (y \u2261\u27e8 y\u2261z \u27e9 (z \u220e)))\n begin -- ==>\n x -- trans x\u2261y (trans y\u2261z refl)\n \u2261\u27e8 x\u2261y \u27e9\n y\n \u2261\u27e8 y\u2261z \u27e9\n z\n \u220e\n\n\n-- Chains of equations, another example\n\npostulate\n +-identity : \u2200 (m : \u2115) \u2192 m + zero \u2261 m\n +-suc : \u2200 (m n : \u2115) \u2192 m + suc n \u2261 suc (m + n)\n\n\n+-comm\u2032 : \u2200 (m n : \u2115) \u2192 m + n \u2261 n + m\n+-comm\u2032 m zero =\n begin\n m + zero\n \u2261\u27e8 +-identity m \u27e9\n m\n \u2261\u27e8\u27e9\n zero + m\n \u220e\n+-comm\u2032 m (suc n) =\n begin\n m + suc n\n \u2261\u27e8 +-suc m n \u27e9\n suc (m + n)\n \u2261\u27e8 cong suc (+-comm\u2032 m n) \u27e9\n suc (n + m)\n \u2261\u27e8\u27e9\n suc n + m\n \u220e\n\n{-\n\nExercise \u2264-Reasoning\n\nThe proof of monotonicity from Chapter Relations can be written in a more readable\nform by using an analogue of our notation for \u2261-Reasoning. Define \u2264-Reasoning\nanalogously, and use it to write out an alternative proof that addition is monotonic\nwith regard to inequality. Rewrite all of +-mono\u02e1-\u2264, +-mono\u02b3-\u2264, and +-mono-\u2264.\n\n-}\n\n-- Rewriting\n\n{-\n\ndata even : \u2115 \u2192 Set\ndata odd : \u2115 \u2192 Set\n\ndata even where\n\n even-zero : even zero\n\n even-suc : \u2200 {n : \u2115}\n \u2192 odd n\n ------------\n \u2192 even (suc n)\n\ndata odd where\n odd-suc : \u2200 {n : \u2115}\n \u2192 even n\n -----------\n \u2192 odd (suc n)\n\n-}\n\n\n{-# BUILTIN EQUALITY _\u2261_ #-}\n\n\neven-comm\u2032 : \u2200 (m n : \u2115)\n \u2192 even (m + n)\n ------------\n \u2192 even (n + m)\neven-comm\u2032 m n ev = {!!}\n\n\n-- Multiple rewrites\n\n+-comm\u2033 : \u2200 (m n : \u2115) \u2192 m + n \u2261 n + m\n+-comm\u2033 zero n = {!!}\n+-comm\u2033 (suc m) n = {!!}\n\n\n-- With-abstraction (examples from the Agda docs)\n\ndata List (A : Set) : Set where\n [] : List A\n _\u2237_ : (x : A) \u2192 (xs : List A) \u2192 List A\ninfixr 5 _\u2237_\n\n\nfilter : {A : Set} \u2192 (A \u2192 Bool) \u2192 List A \u2192 List A\nfilter p [] = []\nfilter p (x \u2237 xs) with p x\n... | true = x \u2237 filter p xs\n... | false = filter p xs\n\n\ncompare : \u2115 \u2192 \u2115 \u2192 Comparison\ncompare x y with x < y\n... | false with y < x\n... | false = equal\n... | true = greater\ncompare x y | true = less\n\n\ncompare\u2032 : \u2115 \u2192 \u2115 \u2192 Comparison\ncompare\u2032 x y with x < y | y < x\n... | true | _ = less\n... | _ | true = greater\n... | false | false = equal\n\n\n-- Rewriting expanded\n\neven-comm\u2033 : \u2200 (m n : \u2115)\n \u2192 even (m + n)\n ------------\n \u2192 even (n + m)\neven-comm\u2033 m n ev with m + n | +-comm m n\n... | mn | eq = {!!}\n\n\n-- Leibniz equality\n\n_\u2250_ : \u2200 {A : Set} (x y : A) \u2192 Set\u2081 -- Set : Set\u2081, Set\u2081 : Set\u2082, and so on\n_\u2250_ {A} x y = \u2200 (P : A \u2192 Set) \u2192 P x \u2192 P y\n\n\nrefl-\u2250 : \u2200 {A : Set} {x : A}\n \u2192 x \u2250 x\nrefl-\u2250 P Px = {!!}\n\ntrans-\u2250 : \u2200 {A : Set} {x y z : A}\n \u2192 x \u2250 y\n \u2192 y \u2250 z\n -----\n \u2192 x \u2250 z\ntrans-\u2250 x\u2250y y\u2250z P Px = {!!}\n\n\nsym-\u2250 : \u2200 {A : Set} {x y : A}\n \u2192 x \u2250 y\n -----\n \u2192 y \u2250 x\nsym-\u2250 {A} {x} {y} x\u2250y P = Qy\n where\n Q : A \u2192 Set\n Q z = P z \u2192 P x\n Qx : Q x\n Qx = refl-\u2250 P\n Qy : Q y\n Qy = x\u2250y Q Qx\n\n\n-- subst : \u2200 {A : Set} {x y : A} (P : A \u2192 Set)\n-- \u2192 x \u2261 y\n-- ---------\n-- \u2192 P x \u2192 P y\n\n\n\u2261-implies-\u2250 : \u2200 {A : Set} {x y : A}\n \u2192 x \u2261 y\n -----\n \u2192 x \u2250 y\n\u2261-implies-\u2250 x\u2261y P = subst P x\u2261y\n\n\n\u2250-implies-\u2261 : \u2200 {A : Set} {x y : A}\n \u2192 x \u2250 y\n -----\n \u2192 x \u2261 y\n\u2250-implies-\u2261 {A} {x} {y} x\u2250y = Qy\n where\n Q : A \u2192 Set\n Q z = x \u2261 z\n Qx : Q x\n Qx = refl\n Qy : Q y\n Qy = x\u2250y Q Qx\n\n\n-- Universe polymorphism\n\nopen import Level using (Level; _\u2294_) renaming (zero to lzero; suc to lsuc)\n\n-- lzero : Level\n-- lsuc : Level \u2192 Level\n\n-- Set\u2080 ==> Set lzero\n-- Set\u2081 ==> Set (lsuc lzero)\n-- Set\u2082 ==> Set (lsuc (lsuc lzero))\n\n\n-- Given two levels, returns the larger of the two\n-- _\u2294_ : Level \u2192 Level \u2192 Level\n\n\ndata _\u2261\u2032_ {\u2113 : Level} {A : Set \u2113} (x : A) : A \u2192 Set \u2113 where\n refl\u2032 : x \u2261\u2032 x\n\n\nsym\u2032 : \u2200 {\u2113 : Level} {A : Set \u2113} {x y : A}\n \u2192 x \u2261\u2032 y\n ------\n \u2192 y \u2261\u2032 x\nsym\u2032 refl\u2032 = refl\u2032\n\n\n_\u2250\u2032_ : \u2200 {\u2113 : Level} {A : Set \u2113} (x y : A) \u2192 Set (lsuc \u2113)\n_\u2250\u2032_ {\u2113} {A} x y = \u2200 (P : A \u2192 Set \u2113) \u2192 P x \u2192 P y\n\n\n_\u2218_ : \u2200 {\u2113\u2081 \u2113\u2082 \u2113\u2083 : Level} {A : Set \u2113\u2081} {B : Set \u2113\u2082} {C : Set \u2113\u2083}\n \u2192 (B \u2192 C) \u2192 (A \u2192 B) \u2192 A \u2192 C\n(g \u2218 f) x = g (f x)\n\n","avg_line_length":16.6918767507,"max_line_length":84,"alphanum_fraction":0.4128209431} {"size":6480,"ext":"agda","lang":"Agda","max_stars_count":5.0,"content":"{-# OPTIONS --without-K #-}\nmodule Model.Quantification where\n\nopen import Model.RGraph as RG using (RGraph)\nopen import Model.Size as MS using (_<_ ; \u27e6_\u27e7\u0394 ; \u27e6_\u27e7n ; \u27e6_\u27e7\u03c3)\nopen import Model.Type.Core\nopen import Source.Size.Substitution.Theory\nopen import Source.Size.Substitution.Universe as SS using (Sub\u22a2\u1d64)\nopen import Util.HoTT.Equiv\nopen import Util.HoTT.FunctionalExtensionality\nopen import Util.HoTT.HLevel\nopen import Util.Prelude hiding (_\u2218_)\nopen import Util.Relation.Binary.PropositionalEquality using\n ( \u03a3-\u2261\u207a ; subst-sym-subst ; subst-subst-sym )\n\nimport Source.Size as SS\nimport Source.Type as ST\n\nopen RGraph\nopen RG._\u21d2_\nopen SS.Ctx\nopen SS.Sub\u22a2\u1d64\n\n\nrecord \u27e6\u2200\u27e7\u2032 {\u0394} n (T : \u27e6Type\u27e7 \u27e6 \u0394 \u2219 n \u27e7\u0394) (\u03b4 : Obj \u27e6 \u0394 \u27e7\u0394) : Set where\n no-eta-equality\n field\n arr : \u2200 m (m w a)\n\n f-g : \u2200 v \u2192 f (g v) == v\n f-g v = \u03bb= \u03bb b \u2192 to-transp (apd v (<\u2013-inv-r w b))\n\n g-f : \u2200 u \u2192 g (f u) == u\n g-f u = \u03bb= \u03bb a \u2192 to-transp $ transport (\u03bb p \u2192 u _ == _ [ P \u2193 p ])\n (is-equiv.adj e a)\n (\u2193-ap-in P (\u2013> w)\n (apd u $ <\u2013-inv-l w a))\n\nequiv-\u03a0-r : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n \u2192 (\u2200 x \u2192 B x \u2243 C x) \u2192 \u03a0 A B \u2243 \u03a0 A C\nequiv-\u03a0-r {A = A} {B = B} {C = C} k = equiv f g f-g g-f\n where f : \u03a0 A B \u2192 \u03a0 A C\n f c x = \u2013> (k x) (c x)\n\n g : \u03a0 A C \u2192 \u03a0 A B\n g d x = <\u2013 (k x) (d x)\n\n f-g : \u2200 d \u2192 f (g d) == d\n f-g d = \u03bb= (\u03bb x \u2192 <\u2013-inv-r (k x) (d x))\n\n g-f : \u2200 c \u2192 g (f c) == c\n g-f c = \u03bb= (\u03bb x \u2192 <\u2013-inv-l (k x) (c x))\n\nmodule _ {i\u2080 i\u2081 j\u2080 j\u2081} {A\u2080 : Type i\u2080} {A\u2081 : Type i\u2081}\n {B\u2080 : A\u2080 \u2192 Type j\u2080} {B\u2081 : A\u2081 \u2192 Type j\u2081} where\n equiv-\u03a0 : (u : A\u2080 \u2243 A\u2081) (v : \u2200 a \u2192 B\u2080 (<\u2013 u a) \u2243 B\u2081 a) \u2192 \u03a0 A\u2080 B\u2080 \u2243 \u03a0 A\u2081 B\u2081\n equiv-\u03a0 u v = \u03a0 A\u2080 B\u2080 \u2243\u27e8 equiv-\u03a0-l _ (snd (u \u207b\u00b9)) \u207b\u00b9 \u27e9\n \u03a0 A\u2081 (B\u2080 \u2218 <\u2013 u) \u2243\u27e8 equiv-\u03a0-r v \u27e9\n \u03a0 A\u2081 B\u2081 \u2243\u220e\n\n equiv-\u03a0' : (u : A\u2080 \u2243 A\u2081) (v : \u2200 a \u2192 B\u2080 a \u2243 B\u2081 (\u2013> u a)) \u2192 \u03a0 A\u2080 B\u2080 \u2243 \u03a0 A\u2081 B\u2081\n equiv-\u03a0' u v = \u03a0 A\u2080 B\u2080 \u2243\u27e8 equiv-\u03a0-r v \u27e9\n \u03a0 A\u2080 (B\u2081 \u2218 \u2013> u) \u2243\u27e8 equiv-\u03a0-l _ (snd u) \u27e9\n \u03a0 A\u2081 B\u2081 \u2243\u220e\n\n\n{- Dependent paths in a \u03a0-type -}\nmodule _ {i j k} {A : Type i} {B : A \u2192 Type j} {C : (a : A) \u2192 B a \u2192 Type k}\n where\n\n \u2193-\u03a0-in : {x x' : A} {p : x == x'} {u : \u03a0 (B x) (C x)} {u' : \u03a0 (B x') (C x')}\n \u2192 ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t' [ uncurry C \u2193 pair= p q ])\n \u2192 (u == u' [ (\u03bb x \u2192 \u03a0 (B x) (C x)) \u2193 p ])\n \u2193-\u03a0-in {p = idp} f = \u03bb= (\u03bb x \u2192 f (idp {a = x}))\n\n \u2193-\u03a0-out : {x x' : A} {p : x == x'} {u : \u03a0 (B x) (C x)} {u' : \u03a0 (B x') (C x')}\n \u2192 (u == u' [ (\u03bb x \u2192 \u03a0 (B x) (C x)) \u2193 p ])\n \u2192 ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t' [ uncurry C \u2193 pair= p q ])\n \u2193-\u03a0-out {p = idp} q idp = app= q _\n\n \u2193-\u03a0-\u03b2 : {x x' : A} {p : x == x'} {u : \u03a0 (B x) (C x)} {u' : \u03a0 (B x') (C x')}\n \u2192 (f : {t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t' [ uncurry C \u2193 pair= p q ])\n \u2192 {t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 \u2193-\u03a0-out (\u2193-\u03a0-in f) q == f q\n \u2193-\u03a0-\u03b2 {p = idp} f idp = app=-\u03b2 (\u03bb x \u2192 f (idp {a = x})) _\n\n{- Dependent paths in a \u03a0-type where the codomain is not dependent on anything\n\nRight now, this is defined in terms of the previous one. Maybe it\u2019s a good idea,\nmaybe not.\n-}\nmodule _ {i j k} {A : Type i} {B : A \u2192 Type j} {C : Type k} {x x' : A}\n {p : x == x'} {u : B x \u2192 C} {u' : B x' \u2192 C} where\n\n \u2193-app\u2192cst-in :\n ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t')\n \u2192 (u == u' [ (\u03bb x \u2192 B x \u2192 C) \u2193 p ])\n \u2193-app\u2192cst-in f = \u2193-\u03a0-in (\u03bb q \u2192 \u2193-cst-in (f q))\n\n \u2193-app\u2192cst-out :\n (u == u' [ (\u03bb x \u2192 B x \u2192 C) \u2193 p ])\n \u2192 ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t')\n \u2193-app\u2192cst-out r q = \u2193-cst-out (\u2193-\u03a0-out r q)\n\n \u2193-app\u2192cst-\u03b2 :\n (f : ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t'))\n \u2192 {t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 \u2193-app\u2192cst-out (\u2193-app\u2192cst-in f) q == f q\n \u2193-app\u2192cst-\u03b2 f q =\n \u2193-app\u2192cst-out (\u2193-app\u2192cst-in f) q\n =\u27e8 idp \u27e9\n \u2193-cst-out (\u2193-\u03a0-out (\u2193-\u03a0-in (\u03bb qq \u2192 \u2193-cst-in (f qq))) q)\n =\u27e8 \u2193-\u03a0-\u03b2 (\u03bb qq \u2192 \u2193-cst-in (f qq)) q |in-ctx\n \u2193-cst-out \u27e9\n \u2193-cst-out (\u2193-cst-in {p = pair= p q} (f q))\n =\u27e8 \u2193-cst-\u03b2 (pair= p q) (f q) \u27e9\n f q \u220e\n\n{- Dependent paths in an arrow type -}\nmodule _ {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n {x x' : A} {p : x == x'} {u : B x \u2192 C x} {u' : B x' \u2192 C x'} where\n\n \u2193-\u2192-in :\n ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t' [ C \u2193 p ])\n \u2192 (u == u' [ (\u03bb x \u2192 B x \u2192 C x) \u2193 p ])\n \u2193-\u2192-in f = \u2193-\u03a0-in (\u03bb q \u2192 \u2193-cst2-in p q (f q))\n\n \u2193-\u2192-out :\n (u == u' [ (\u03bb x \u2192 B x \u2192 C x) \u2193 p ])\n \u2192 ({t : B x} {t' : B x'} (q : t == t' [ B \u2193 p ])\n \u2192 u t == u' t' [ C \u2193 p ])\n \u2193-\u2192-out r q = \u2193-cst2-out p q (\u2193-\u03a0-out r q)\n\n-- Dependent paths in a \u03a0-type where the domain is constant\nmodule _ {i j k} {A : Type i} {B : Type j} {C : A \u2192 B \u2192 Type k} where\n\n \u2193-cst\u2192app-in : {x x' : A} {p : x == x'}\n {u : (b : B) \u2192 C x b} {u' : (b : B) \u2192 C x' b}\n \u2192 ((b : B) \u2192 u b == u' b [ (\u03bb x \u2192 C x b) \u2193 p ])\n \u2192 (u == u' [ (\u03bb x \u2192 (b : B) \u2192 C x b) \u2193 p ])\n \u2193-cst\u2192app-in {p = idp} f = \u03bb= f\n\n \u2193-cst\u2192app-out : {x x' : A} {p : x == x'}\n {u : (b : B) \u2192 C x b} {u' : (b : B) \u2192 C x' b}\n \u2192 (u == u' [ (\u03bb x \u2192 (b : B) \u2192 C x b) \u2193 p ])\n \u2192 ((b : B) \u2192 u b == u' b [ (\u03bb x \u2192 C x b) \u2193 p ])\n \u2193-cst\u2192app-out {p = idp} q = app= q\n\nsplit-ap2 : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : Type k} (f : \u03a3 A B \u2192 C)\n {x y : A} (p : x == y)\n {u : B x} {v : B y} (q : u == v [ B \u2193 p ])\n \u2192 ap f (pair= p q) == \u2193-app\u2192cst-out (apd (curry f) p) q\nsplit-ap2 f idp idp = idp\n\n{-\nInteraction of [apd] with function composition.\nThe basic idea is that [apd (g \u2218 f) p == apd g (apd f p)] but the version here\nis well-typed. Note that we assume a propositional equality [r] between\n[apd f p] and [q].\n-}\napd-\u2218 : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : (a : A) \u2192 B a \u2192 Type k}\n (g : {a : A} \u2192 \u03a0 (B a) (C a)) (f : \u03a0 A B) {x y : A} (p : x == y)\n {q : f x == f y [ B \u2193 p ]} (r : apd f p == q)\n \u2192 apd (g \u2218 f) p == \u2193-apd-out C r (apd\u2193 g q)\napd-\u2218 g f idp idp = idp\n\n{- When [g] is nondependent, it\u2019s much simpler -}\napd-\u2218' : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n (g : {a : A} \u2192 B a \u2192 C a) (f : \u03a0 A B) {x y : A} (p : x == y)\n \u2192 apd (g \u2218 f) p == ap\u2193 g (apd f p)\napd-\u2218' g f idp = idp\n\n\u2218'-apd : \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k}\n (g : {a : A} \u2192 B a \u2192 C a) (f : \u03a0 A B) {x y : A} (p : x == y)\n \u2192 ap\u2193 g (apd f p) == apd (g \u2218 f) p\n\u2218'-apd g f idp = idp\n\n\n{- 2-dimensional coherence conditions -}\n\n-- postulate\n-- lhs :\n-- \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k} {f g : \u03a0 A B}\n-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}\n-- (k : (u \u25c3 apd g p) == (apd f p \u25b9 v))\n-- (h : {a : A} \u2192 B a \u2192 C a)\n-- \u2192 ap h u \u25c3 apd (h \u2218 g) p == ap\u2193 h (u \u25c3 apd g p)\n\n-- rhs :\n-- \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k} {f g : \u03a0 A B}\n-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}\n-- (k : (u \u25c3 apd g p) == (apd f p \u25b9 v))\n-- (h : {a : A} \u2192 B a \u2192 C a)\n-- \u2192 ap\u2193 h (apd f p \u25b9 v) == apd (h \u2218 f) p \u25b9 ap h v\n\n -- ap\u2193-\u2193-=-in :\n -- \u2200 {i j k} {A : Type i} {B : A \u2192 Type j} {C : A \u2192 Type k} {f g : \u03a0 A B}\n -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}\n -- (k : (u \u25c3 apd g p) == (apd f p \u25b9 v))\n -- (h : {a : A} \u2192 B a \u2192 C a)\n -- \u2192 ap\u2193 (\u03bb {a} \u2192 ap (h {a = a})) (\u2193-=-in {p = p} {u = u} {v = v} k)\n -- == \u2193-=-in (lhs {f = f} {g = g} k h \u2219 ap (ap\u2193 (\u03bb {a} \u2192 h {a = a})) k \n -- \u2219 rhs {f = f} {g = g} k h)\n\n{-\nCommutation of [ap\u2193 (ap h)] and [\u2193-swap!]. This is \"just\" J, but it\u2019s not as\neasy as it seems.\n-}\n\nmodule Ap\u2193-swap! {i j k \u2113} {A : Type i} {B : Type j} {C : Type k}\n {D : Type \u2113} (h : C \u2192 D) (f : A \u2192 C) (g : B \u2192 C)\n {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}\n (r : f a == g b') (s : f a' == g b)\n (t : r == s \u2219 ap g q [ (\u03bb x \u2192 f x == g b') \u2193 p ])\n where\n\n lhs : ap h (ap f p \u2219' s) == ap (h \u2218 f) p \u2219' ap h s\n lhs = ap-\u2219' h (ap f p) s \u2219 (ap (\u03bb u \u2192 u \u2219' ap h s) (\u2218-ap h f p))\n\n rhs : ap h (s \u2219 ap g q) == ap h s \u2219 ap (h \u2218 g) q\n rhs = ap-\u2219 h s (ap g q) \u2219 (ap (\u03bb u \u2192 ap h s \u2219 u) (\u2218-ap h g q))\n\n \u03b2 : ap\u2193 (ap h) (\u2193-swap! f g r s t) ==\n lhs \u25c3 \u2193-swap! (h \u2218 f) (h \u2218 g) (ap h r) (ap h s) (ap\u2193 (ap h) t \u25b9 rhs)\n \u03b2 with a | a' | p | b | b' | q | r | s | t\n \u03b2 | a | .a | idp | b | .b | idp | r | s | t = coh r s t where\n\n T : {x x' : C} (r s : x == x') (t : r == s \u2219 idp) \u2192 Type _\n T r s t =\n ap (ap h) (\u2219'-unit-l s \u2219 ! (\u2219-unit-r s) \u2219 ! t) ==\n (ap-\u2219' h idp s \u2219 idp)\n \u2219\n (\u2219'-unit-l (ap h s) \u2219\n ! (\u2219-unit-r (ap h s)) \u2219\n !\n (ap (ap h) t \u2219'\n (ap-\u2219 h s idp \u2219 idp)))\n\n coh' : {x x' : C} {r s : x == x'} (t : r == s) \u2192 T r s (t \u2219 ! (\u2219-unit-r s))\n coh' {r = idp} {s = .idp} idp = idp\n\n coh : {x x' : C} (r s : x == x') (t : r == s \u2219 idp) \u2192 T r s t\n coh r s t = transport (\u03bb t \u2192 T r s t) (coh2 t (\u2219-unit-r s)) (coh' (t \u2219 \u2219-unit-r s)) where\n\n coh2 : \u2200 {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) \u2192 (p \u2219 q) \u2219 ! q == p\n coh2 idp idp = idp\n\n\n-- module _ {i j k} {A : Type i} {B B' : Type j} {C : Type k} (f : A \u2192 C) (g' : B' \u2192 B) (g : B \u2192 C) where\n\n-- abc : {a a' : A} {p : a == a'} {c c' : B'} {q' : c == c'} {q : g' c == g' c'}\n-- (r : f a == g (g' c')) (s : f a' == g (g' c))\n-- (t : q == ap g' q')\n-- (\u03b1 : r == s \u2219 ap g q [ (\u03bb x \u2192 f x == g (g' c')) \u2193 p ])\n-- \u2192 {!(\u2193-swap! f g r s \u03b1 \u25b9 ?) \u2219'2\u1d48 ?!} == \u2193-swap! f (g \u2218 g') {p = p} {q = q'} r s (\u03b1 \u25b9 ap (\u03bb u \u2192 s \u2219 u) (ap (ap g) t \u2219 \u2218-ap g g' q')) \n-- abc = {!!}\n\n{- Functoriality of application and function extensionality -}\n\n\u2219-app= : \u2200 {i j} {A : Type i} {B : A \u2192 Type j} {f g h : \u03a0 A B}\n (\u03b1 : f == g) (\u03b2 : g == h) \n \u2192 \u03b1 \u2219 \u03b2 == \u03bb= (\u03bb x \u2192 app= \u03b1 x \u2219 app= \u03b2 x)\n\u2219-app= idp \u03b2 = \u03bb=-\u03b7 \u03b2\n\n\u2219-\u03bb= : \u2200 {i j} {A : Type i} {B : A \u2192 Type j} {f g h : \u03a0 A B}\n (\u03b1 : (x : A) \u2192 f x == g x) (\u03b2 : (x : A) \u2192 g x == h x) \n \u2192 \u03bb= \u03b1 \u2219 \u03bb= \u03b2 == \u03bb= (\u03bb x \u2192 \u03b1 x \u2219 \u03b2 x)\n\u2219-\u03bb= \u03b1 \u03b2 = \u2219-app= (\u03bb= \u03b1) (\u03bb= \u03b2)\n \u2219 ap \u03bb= (\u03bb= (\u03bb x \u2192 ap (\u03bb w \u2192 w \u2219 app= (\u03bb= \u03b2) x) (app=-\u03b2 \u03b1 x)\n \u2219 ap (\u03bb w \u2192 \u03b1 x \u2219 w) (app=-\u03b2 \u03b2 x)))\n","avg_line_length":36.3209459459,"max_line_length":139,"alphanum_fraction":0.3657334201} {"size":5222,"ext":"agda","lang":"Agda","max_stars_count":39.0,"content":"\n-- The category of contexts and renamings\nmodule SOAS.ContextMaps.CategoryOfRenamings {T : Set} where\n\nopen import SOAS.Common\nopen import SOAS.Context {T}\nopen import SOAS.Variable\nopen import SOAS.ContextMaps.Combinators (\u2110 {T})\n\nopen import Categories.Functor.Bifunctor\nopen import Categories.Object.Initial\nopen import Categories.Object.Coproduct\nopen import Categories.Category.Cocartesian\n\nimport Categories.Morphism\n\n\n-- The category of contexts and renamings, defined as the Lawvere theory\n-- associated with the clone of variables. In elementary terms it has\n-- contexts \u0393, \u0394 as objects, and renamings \u0393 \u219d \u0394 \u225c \u0393 ~[ \u2110 \u2192 \u2110 ]\u219d \u0394 as arrows.\n\ud835\udd3d : Category 0\u2113 0\u2113 0\u2113\n\ud835\udd3d = categoryHelper (record\n { Obj = Ctx\n ; _\u21d2_ = _\u219d_\n ; _\u2248_ = \u03bb {\u0393} \u03c1\u2081 \u03c1\u2082 \u2192 \u2200{\u03b1 : T}{v : \u2110 \u03b1 \u0393} \u2192 \u03c1\u2081 v \u2261 \u03c1\u2082 v\n ; id = \u03bb x \u2192 x\n ; _\u2218_ = \u03bb \u03f1 \u03c1 v \u2192 \u03f1 (\u03c1 v)\n ; assoc = refl\n ; identity\u02e1 = refl\n ; identity\u02b3 = refl\n ; equiv = record { refl = refl ; sym = \u03bb p \u2192 sym p ; trans = \u03bb p q \u2192 trans p q }\n ; \u2218-resp-\u2248 = \u03bb{ {f = \u03c1\u2081} p\u2081 p\u2082 \u2192 trans (cong \u03c1\u2081 p\u2082) p\u2081 }\n })\n\nmodule \ud835\udd3d = Category \ud835\udd3d using (op) renaming ( _\u2218_ to _\u2218\u1d63_\n ; _\u2248_ to _\u2248\u1d63_\n ; id to id\u1d63\n ; \u2218-resp-\u2248 to \u2218-resp-\u2248\u1d63 )\nopen \ud835\udd3d public\n\nid\u2032\u1d63 : (\u0393 : Ctx) \u2192 \u0393 \u219d \u0393\nid\u2032\u1d63 \u0393 = id\u1d63 {\u0393}\n\n-- Category of context is co-Cartesian, given by the empty initial context and\n-- context concatenation as the monoidal product.\n\ud835\udd3d:Cocartesian : Cocartesian \ud835\udd3d\n\ud835\udd3d:Cocartesian = record\n { initial = record\n { \u22a5 = \u2205\n ; \u22a5-is-initial = record { ! = \u03bb{()} ; !-unique = \u03bb{ f {_} {()}} }\n }\n ; coproducts = record { coproduct = \u03bb {\u0393}{\u0394} \u2192 record\n { A+B = \u0393 \u2214 \u0394\n ; i\u2081 = expand\u02b3 \u0394\n ; i\u2082 = expand\u02e1 \u0393\n ; [_,_] = copair\n ; inject\u2081 = \u03bb{ {\u0398}{\u03c1}{\u03f1} \u2192 i\u2081-commute \u03c1 \u03f1 _ }\n ; inject\u2082 = \u03bb{ {\u0398}{\u03c1}{\u03f1} \u2192 i\u2082-commute \u03c1 \u03f1 _ }\n ; unique = \u03bb{ p\u2081 p\u2082 \u2192 unique {\u0393}{\u0394} _ _ _ p\u2081 p\u2082 _ }\n } }\n }\n where\n\n in\u2081 : (\u0393 \u0394 : Ctx) \u2192 \u0393 \u219d \u0393 \u2214 \u0394\n in\u2081 (\u03b1 \u2219 \u0393) \u0394 new = new\n in\u2081 (\u03b1 \u2219 \u0393) \u0394 (old v) = old (in\u2081 \u0393 \u0394 v)\n\n in\u2082 : (\u0393 \u0394 : Ctx) \u2192 \u0394 \u219d \u0393 \u2214 \u0394\n in\u2082 \u2205 \u0394 v = v\n in\u2082 (\u03b1 \u2219 \u0393) \u0394 v = old (in\u2082 \u0393 \u0394 v)\n\n i\u2081-commute : {\u0393 \u0394 \u0398 : Ctx}{\u03b1 : T}(\u03c1 : \u0393 \u219d \u0398)(\u03f1 : \u0394 \u219d \u0398)(v : \u2110 \u03b1 \u0393)\n \u2192 copair \u03c1 \u03f1 (expand\u02b3 \u0394 v) \u2261 \u03c1 v\n i\u2081-commute \u03c1 \u03f1 new = refl\n i\u2081-commute \u03c1 \u03f1 (old v) = i\u2081-commute (\u03c1 \u2218 old) \u03f1 v\n\n i\u2082-commute : {\u0393 \u0394 \u0398 : Ctx}{\u03b1 : T}(\u03c1 : \u0393 \u219d \u0398)(\u03f1 : \u0394 \u219d \u0398)(v : \u2110 \u03b1 \u0394)\n \u2192 copair \u03c1 \u03f1 (expand\u02e1 \u0393 v) \u2261 \u03f1 v\n i\u2082-commute {\u2205} \u03c1 \u03f1 v = refl\n i\u2082-commute {\u03b1 \u2219 \u0393} \u03c1 \u03f1 v = i\u2082-commute (\u03c1 \u2218 old) \u03f1 v\n\n unique : {\u0393 \u0394 \u0398 : Ctx}{\u03b1 : T}(\u03c1 : \u0393 \u219d \u0398)(\u03f1 : \u0394 \u219d \u0398)(\u03c0 : \u0393 \u2214 \u0394 \u219d \u0398)\n \u2192 (\u03c0 \u2218\u1d63 expand\u02b3 \u0394 \u2248\u1d63 \u03c1)\n \u2192 (\u03c0 \u2218\u1d63 expand\u02e1 \u0393 \u2248\u1d63 \u03f1)\n \u2192 (v : \u2110 \u03b1 (\u0393 \u2214 \u0394)) \u2192 copair \u03c1 \u03f1 v \u2261 \u03c0 v\n unique {\u2205} \u03c1 \u03f1 \u03c0 p\u2081 p\u2082 v = sym p\u2082\n unique {\u03b1 \u2219 \u0393} \u03c1 \u03f1 \u03c0 p\u2081 p\u2082 new = sym p\u2081\n unique {\u03b1 \u2219 \u0393} \u03c1 \u03f1 \u03c0 p\u2081 p\u2082 (old v) = unique (\u03c1 \u2218 old) \u03f1 (\u03c0 \u2218 old) p\u2081 p\u2082 v\n\n\nmodule \ud835\udd3d:Co = Cocartesian \ud835\udd3d:Cocartesian\nmodule \u2214 = BinaryCoproducts (Cocartesian.coproducts \ud835\udd3d:Cocartesian)\n\n-- | Special operations coming from the coproduct structure\n\n-- Concatenation is a bifunctor\n\u2214:Bifunctor : Bifunctor \ud835\udd3d \ud835\udd3d \ud835\udd3d\n\u2214:Bifunctor = \ud835\udd3d:Co.-+-\n\n-- Left context concatenation functor \u0393 \u2214 (-) : \ud835\udd3d \u27f6 \ud835\udd3d, for any context \u0393\n_\u2214F\u2013 : Ctx \u2192 Functor \ud835\udd3d \ud835\udd3d\n\u0393 \u2214F\u2013 = \u0393 \u2214.+-\n\n-- Right context concatenation functor (-) \u2214 \u0394 : \ud835\udd3d \u27f6 \ud835\udd3d, for any context \u0394\n\u2013\u2214F_ : Ctx \u2192 Functor \ud835\udd3d \ud835\udd3d\n\u2013\u2214F \u0394 = \u2214.-+ \u0394\n\n-- Functorial mapping and injections\n_\u2223\u2214\u2223_ : {\u0393\u2081 \u0393\u2082 \u0394\u2081 \u0394\u2082 : Ctx}(\u03c1 : \u0393\u2081 \u219d \u0393\u2082)(\u03f1 : \u0394\u2081 \u219d \u0394\u2082) \u2192 (\u0393\u2081 \u2214 \u0394\u2081) \u219d (\u0393\u2082 \u2214 \u0394\u2082)\n_\u2223\u2214\u2223_ = \u2214._+\u2081_\n\n_\u2223\u2214_ : {\u0393\u2081 \u0393\u2082 : Ctx}(\u03c1 : \u0393\u2081 \u219d \u0393\u2082)(\u0394 : Ctx) \u2192 (\u0393\u2081 \u2214 \u0394) \u219d (\u0393\u2082 \u2214 \u0394)\n\u03c1 \u2223\u2214 \u0394 = \u03c1 \u2223\u2214\u2223 id\u2032\u1d63 \u0394\n\n_\u2214\u2223_ : {\u0394\u2081 \u0394\u2082 : Ctx}(\u0393 : Ctx)(\u03f1 : \u0394\u2081 \u219d \u0394\u2082) \u2192 (\u0393 \u2214 \u0394\u2081) \u219d (\u0393 \u2214 \u0394\u2082)\n\u0393 \u2214\u2223 \u03f1 = id\u2032\u1d63 \u0393 \u2223\u2214\u2223 \u03f1\n\ninl : (\u0393 {\u0394} : Ctx) \u2192 \u0393 \u219d \u0393 \u2214 \u0394\ninl \u0393 {\u0394} v = \u2214.i\u2081 {\u0393}{\u0394} v\n\ninr : (\u0393 {\u0394} : Ctx) \u2192 \u0394 \u219d \u0393 \u2214 \u0394\ninr \u0393 {\u0394} v = \u2214.i\u2082 {\u0393}{\u0394} v\n\n\n-- Left context concatenation represents weakening a variable in \u0393 by an\n-- arbitrary new context \u0398 to get a variable in context (\u0398 \u2214 \u0393).\nmodule Concat\u02e1 \u0393 = Functor (\u0393 \u2214F\u2013)\n using () renaming ( F\u2081 to _\u2214\u1d63_\n ; identity to \u2214identity\n ; homomorphism to \u2214homomorphism\n ; F-resp-\u2248 to \u2214F-resp-\u2248)\nopen Concat\u02e1 public\n\n-- Context extension represents weakening by a single type, and it's a special\n-- case of context concatenation with a singleton context.\nmodule Ext \u03c4 = Functor (\u230a \u03c4 \u230b \u2214F\u2013)\n using () renaming ( F\u2081 to _\u2219\u1d63_\n ; identity to \u2219identity\n ; homomorphism to \u2219homomorphism\n ; F-resp-\u2248 to \u2219F-resp-\u2248)\nopen Ext public\n\n-- The two coincide (since add is a special case of copair)\n-- but not definitionally: \u2219\u1d63 is the parallel sum of id : \u230a \u03c4 \u230b \u219d \u230a \u03c4 \u230b and \u03c1 : \u0393 \u219d \u0394\n-- (i.e. the copairing of expand\u02b3 \u230a \u03c4 \u230b \u0394 : \u230a \u03c4 \u230b \u219d \u03c4 \u2219 \u0394 and old \u2218 \u03c1 : \u0393 \u219d \u03c4 \u2219 \u0394)\n-- while lift\u1d63 is the copairing of new : \u230a \u03c4 \u230b \u219d \u03c4 \u2219 \u0394 and old \u2218 \u03c1 : \u0393 \u219d \u03c4 \u2219 \u0394\n\u2219\u1d63-as-add : {\u03b1 \u03c4 : T}{\u0393 \u0394 : Ctx} \u2192 (\u03c1 : \u0393 \u219d \u0394)(v : \u2110 \u03b1 (\u03c4 \u2219 \u0393))\n \u2192 add new (old \u2218 \u03c1) v \u2261 (\u03c4 \u2219\u1d63 \u03c1) v\n\u2219\u1d63-as-add \u03c1 new = refl\n\u2219\u1d63-as-add \u03c1 (old v) = refl\n\n-- Making this a definitional equality simplifies things significantly\n\n-- Right context concatenation is possible but rarely needed.\nmodule Concat\u02b3 \u0394 = Functor (\u2013\u2214F \u0394 )\n","avg_line_length":33.4743589744,"max_line_length":85,"alphanum_fraction":0.5402144772} {"size":14346,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --type-in-type #-}\n{-# OPTIONS --no-termination-check #-}\n\n-- In this post we'll consider how to define and generalize fixed-point combinators for families of\n-- mutually recursive functions. Both in the lazy and strict settings.\n\nmodule FixN where\n\nopen import Function\nopen import Relation.Binary.PropositionalEquality\nopen import Data.Nat.Base\nopen import Data.Bool.Base\n\n-- This module is parameterized by `even` and `odd` functions and defines the `Test` type\n-- which is used below for testing particular `even` and `odd`.\nmodule Test (even : \u2115 -> Bool) (odd : \u2115 -> Bool) where\n open import Data.List.Base\n open import Data.Product using (_,\u2032_)\n\n Test : Set\n Test =\n ( map even (0 \u2237 1 \u2237 2 \u2237 3 \u2237 4 \u2237 5 \u2237 [])\n ,\u2032 map odd (0 \u2237 1 \u2237 2 \u2237 3 \u2237 4 \u2237 5 \u2237 [])\n )\n \u2261 ( true \u2237 false \u2237 true \u2237 false \u2237 true \u2237 false \u2237 []\n ,\u2032 false \u2237 true \u2237 false \u2237 true \u2237 false \u2237 true \u2237 []\n )\n\n-- Brings `Test : (\u2115 -> Bool) -> (\u2115 -> Bool) -> Set` in scope.\nopen Test\n\nmodule Classic where\n open import Data.Product\n\n -- We can use the most straightforward fixed-point operator in order to get mutual recursion.\n {-# TERMINATING #-}\n fix : {A : Set} -> (A -> A) -> A\n fix f = f (fix f)\n\n -- We instantiate `fix` to be defined over a pair of functions. I.e. a generic fixed-point\n -- combinator for a family of two mutually recursive functions has this type signature:\n -- `\u2200 {A B} -> (A \u00d7 B -> A \u00d7 B) -> A \u00d7 B` which is an instance of `\u2200 {A} -> (A -> A) -> A`.\n\n -- Here is the even-and-odd example.\n -- `even` is denoted as the first element of the resulting tuple, `odd` is the second.\n evenAndOdd : (\u2115 -> Bool) \u00d7 (\u2115 -> Bool)\n evenAndOdd = fix $ \u03bb p ->\n -- `even` returns `true` on `0` and calls `odd` on `suc`\n (\u03bb { 0 -> true ; (suc n) -> proj\u2082 p n })\n -- `odd` returns `false` on `0` and calls `even` on `suc`\n , (\u03bb { 0 -> false ; (suc n) -> proj\u2081 p n })\n\n even : \u2115 -> Bool\n even = proj\u2081 evenAndOdd\n\n odd : \u2115 -> Bool\n odd = proj\u2082 evenAndOdd\n\n test : Test even odd\n test = refl\n\n -- And that's all.\n\n -- This Approach\n\n -- 1. relies on laziness\n -- 2. relies on tuples\n -- 3. allows to encode a family of arbitrary number of mutually recursive functions\n -- of possibly distinct types\n\n -- There is one pitfall, though, if we write this in Haskell:\n\n -- evenAndOdd :: ((Int -> Bool), (Int -> Bool))\n -- evenAndOdd = fix $ \\(even, odd) ->\n -- ( (\\n -> n == 0 || odd (n - 1))\n -- , (\\n -> n \/= 0 && even (n - 1))\n -- )\n\n -- we'll get an infinite loop, because matching over tuples is strict in Haskell (in Agda it's lazy)\n -- which means that in order to return a tuple, you must first compute it to whnf, which is a loop.\n -- This is what the author of [1] stumpled upon. The fix is simple, though: just use lazy matching\n -- (aka irrefutable pattern) like this:\n\n -- evenAndOdd = fix $ \\(~(even, odd)) -> ...\n\n -- In general, that's a good approach for a lazy language, but Plutus Core is a strict one (so far),\n -- so we need something else. Besides, we can do some pretty cool generalizations, so let's do them.\n\nmodule PartlyUncurried2 where\n open import Data.Product\n\n -- It is clear that we can transform\n\n -- \u2200 {A B} -> (A \u00d7 B -> A \u00d7 B) -> A \u00d7 B\n\n -- into\n\n -- \u2200 {A B R} -> (A \u00d7 B -> A \u00d7 B) -> (A -> B -> R) -> R\n\n -- by Church-encoding `A \u00d7 B` into `\u2200 {R} -> (A -> B -> R) -> R`.\n -- However in our case we can also transform\n\n -- A \u00d7 B -> A \u00d7 B\n\n -- into\n\n -- \u2200 {Q} -> (A -> B -> Q) -> A -> B -> Q\n\n -- Ignoring the former transformation right now, but performing the latter we get the following:\n\n fix2 : \u2200 {A B} -> (\u2200 {Q} -> (A -> B -> Q) -> A -> B -> Q) -> A \u00d7 B\n fix2 f = f (\u03bb x y -> x) (proj\u2081 (fix2 f)) (proj\u2082 (fix2 f))\n , f (\u03bb x y -> y) (proj\u2081 (fix2 f)) (proj\u2082 (fix2 f))\n\n -- `f` is what was of the `A \u00d7 B -> A \u00d7 B` type previously, but now instead of receiving a tuple\n -- and defining a tuple, `f` receives a selector and two values of types `A` and `B`. The values\n -- represent the functions being defined, while the selector is needed in order to select one of\n -- these functions.\n\n -- Consider the example:\n\n evenAndOdd : (\u2115 -> Bool) \u00d7 (\u2115 -> Bool)\n evenAndOdd = fix2 $ \u03bb select even odd -> select\n (\u03bb { 0 -> true ; (suc n) -> odd n })\n (\u03bb { 0 -> false ; (suc n) -> even n })\n\n -- `select` is only instantiated to either `\u03bb x y -> x` or `\u03bb x y -> y` which allow us\n -- to select the branch we want to go in. When defining the `even` function, we want to go in\n -- the first branch and thus instantiate `select` with `\u03bb x y -> x`. When defining `odd`,\n -- we want the second branch and thus instantiate `select` with `\u03bb x y -> y`.\n -- All these instantiations happen in the `fix2` function itself.\n\n -- It is instructive to inline `fix2` and `select` along with the particular selectors. We get:\n\n evenAndOdd-inlined : (\u2115 -> Bool) \u00d7 (\u2115 -> Bool)\n evenAndOdd-inlined = defineEven (proj\u2081 evenAndOdd-inlined) (proj\u2082 evenAndOdd-inlined)\n , defineOdd (proj\u2081 evenAndOdd-inlined) (proj\u2082 evenAndOdd-inlined)\n where\n defineEven : (\u2115 -> Bool) -> (\u2115 -> Bool) -> \u2115 -> Bool\n defineEven even odd = \u03bb { 0 -> true ; (suc n) -> odd n }\n\n defineOdd : (\u2115 -> Bool) -> (\u2115 -> Bool) -> \u2115 -> Bool\n defineOdd even odd = \u03bb { 0 -> false ; (suc n) -> even n }\n\n -- I.e. each definition is parameterized by both functions and this is just the same fixed point\n -- of a tuple of functions that we've seen before.\n\n test : Test (proj\u2081 evenAndOdd) (proj\u2082 evenAndOdd)\n test = refl\n\n test-inlined : Test (proj\u2081 evenAndOdd-inlined) (proj\u2082 evenAndOdd-inlined)\n test-inlined = refl\n\nmodule Uncurried where\n -- We can now do another twist and turn `A \u00d7 B` into `\u2200 {R} -> (A -> B -> R) -> R` which finally\n -- allows us to get rid of tuples:\n\n fix2 : {A B R : Set} -> (\u2200 {Q} -> (A -> B -> Q) -> A -> B -> Q) -> (A -> B -> R) -> R\n fix2 f k = k (fix2 f (f \u03bb x y -> x)) (fix2 f (f \u03bb x y -> y))\n\n -- `k` is the continuation that represents a Church-encoded tuple returned as the result.\n -- But... if `k` is just another way to construct a tuple, how are we not keeping `f` outside of\n -- recursion? Previously it was `fix f = f (fix f)` or\n\n -- fix2 f = f (\u03bb x y -> x) (proj\u2081 (fix2 f)) (proj\u2082 (fix2 f))\n -- , f (\u03bb x y -> y) (proj\u2081 (fix2 f)) (proj\u2082 (fix2 f))\n\n -- i.e. `f` is always an outermost call and recursive calls are somewhere inside. But in the\n -- definition above `f` is inside the recursive call. How is that? Watch the hands:\n\n -- fix2 f k [1]\n -- = k (fix2 f (f \u03bb x y -> x)) (fix2 f (f \u03bb x y -> y)) [2]\n -- ~ k (fix2 f (f (\u03bb x y -> x))) (fix2 f (f (\u03bb x y -> y))) [3]\n -- ~ k (f (\u03bb x y -> x) (fix2 f (f \u03bb x y -> x)) (fix2 f (f \u03bb x y -> y)))\n -- (f (\u03bb x y -> y) (fix2 f (f \u03bb x y -> y)) (fix2 f (f \u03bb x y -> y)))\n\n -- [1] unfold the definition of `fix2`\n -- [2] add parens around selectors for clarity\n -- [3] unfold the definition of `fix` in both the arguments of `k`\n\n -- The result is very similar to the one from the previous section\n -- (quoted in the snippet several lines above).\n\n -- And the test:\n\n evenAndOdd : \u2200 {R} -> ((\u2115 -> Bool) -> (\u2115 -> Bool) -> R) -> R\n evenAndOdd = fix2 $ \u03bb select even odd -> select\n (\u03bb { 0 -> true ; (suc n) -> odd n })\n (\u03bb { 0 -> false ; (suc n) -> even n })\n\n test : Test (evenAndOdd \u03bb x y -> x) (evenAndOdd \u03bb x y -> y)\n test = refl\n\n -- It is straighforward to define a fixed-point combinator for a family of three mutually\n -- recursive functions:\n\n fix3 : {A B C R : Set} -> (\u2200 {Q} -> (A -> B -> C -> Q) -> A -> B -> C -> Q) -> (A -> B -> C -> R) -> R\n fix3 f k = k (fix3 f (f \u03bb x y z -> x)) (fix3 f (f \u03bb x y z -> y)) (fix3 f (f \u03bb x y z -> z))\n\n -- The pattern is clear and we can abstract it.\n\nmodule UncurriedGeneral where\n -- The type signatures of the fixed point combinators from the above\n\n -- \u2200 {A B} -> (\u2200 {Q} -> (A -> B -> Q) -> A -> B -> Q) -> \u2200 {R} -> (A -> B -> R) -> R\n -- \u2200 {A B C} -> (\u2200 {Q} -> (A -> B -> C -> Q) -> A -> B -> C -> Q) -> \u2200 {R} -> (A -> B -> C -> R) -> R\n\n -- (`\u2200 {R}` is moved slightly righter than what it was previously, because it helps readability below)\n -- can be generalized to\n\n -- \u2200 {F} -> (\u2200 {Q} -> F Q -> F Q) -> \u2200 {R} -> F R -> R\n\n -- with `F` being `\u03bb X -> A -> B -> X` in the first case and `\u03bb X -> A -> B -> C -> X` in the second.\n -- That's fact (1).\n\n -- Now let's look at the definitions. There we see\n\n -- fix2 f k = k (fix2 f (f \u03bb x y -> x)) (fix2 f (f \u03bb x y -> y))\n -- fix3 f k = k (fix3 f (f \u03bb x y z -> x)) (fix3 f (f \u03bb x y z -> y)) (fix3 f (f \u03bb x y z -> z))\n\n -- i.e. each recursive call is parameterized by the `f` that never changes, but also by\n -- the `f` applied to a selector and selectors do change. Thus the\n\n -- \u03bb selector -> fix2 f (f selector)\n -- \u03bb selector -> fix3 f (f selector)\n\n -- parts can be abstracted into something like\n\n -- \u03bb selector -> fixSome f (f selector)\n\n -- where `fixSome` can be both `fix2` and `fix3` depending on what you instantiate it with.\n -- Then we only need combinators that duplicate the recursive case an appropriate number of times\n -- (2 for `fix2` and 3 for `fix3`) and supply a selector to each of the duplicates. That's fact (2).\n -- And those combinators have to be of the same type, so we can pass them to the generic\n -- fixed-point combinator we're deriving.\n\n -- To infer the type of those combinators we start by looking at the types of\n\n -- \u03bb selector -> fix2 f (f selector)\n -- \u03bb selector -> fix3 f (f selector)\n\n -- which are\n\n -- \u2200 {Q} -> (A -> B -> Q) -> Q\n -- \u2200 {Q} -> (A -> B -> C -> Q) -> Q\n\n -- correspondingly. I.e. the unifying type of\n\n -- \u03bb selector -> fixSome f (f selector)\n\n -- is `\u2200 {Q} -> F Q -> Q`.\n\n -- Therefore, the combinators receive something of type `\u2200 {Q} -> F Q -> Q` and return something of\n -- type `\u2200 {R} -> F R -> R` (the same type, just alpha-converted for convenience), because that's\n -- what `fix2` and `fix3` and thus the generic fixed-point combinator return.\n -- I.e. the whole unifying type of those combinators is\n\n -- (\u2200 {R} -> (\u2200 {Q} -> F Q -> Q) -> F R -> R)\n\n -- That's fact (3).\n\n -- Assembling everything together, we arrive at\n\n fixBy : {F : Set -> Set}\n -> ((\u2200 {Q} -> F Q -> Q) -> \u2200 {R} -> F R -> R) -- by fact (3)\n -> (\u2200 {Q} -> F Q -> F Q) -> \u2200 {R} -> F R -> R -- by fact (1)\n fixBy by f = by (fixBy by f \u2218 f) -- by fact (2)\n\n -- Let's now implement particular `by`s:\n\n by2 : {A B : Set} -> (\u2200 {Q} -> (A -> B -> Q) -> Q) -> {R : Set} -> (A -> B -> R) -> R\n by2 r k = k (r \u03bb x y -> x) (r \u03bb x y -> y)\n\n by3 : {A B C : Set} -> (\u2200 {Q} -> (A -> B -> C -> Q) -> Q) -> {R : Set} -> (A -> B -> C -> R) -> R\n by3 r k = k (r \u03bb x y z -> x) (r \u03bb x y z -> y) (r \u03bb x y z -> z)\n\n -- and fixed-points combinators from the previous section in terms of what we derived in this one:\n\n fix2 : \u2200 {A B} -> (\u2200 {Q} -> (A -> B -> Q) -> A -> B -> Q) -> \u2200 {R} -> (A -> B -> R) -> R\n fix2 = fixBy by2\n\n fix3 : \u2200 {A B C} -> (\u2200 {Q} -> (A -> B -> C -> Q) -> A -> B -> C -> Q) -> \u2200 {R} -> (A -> B -> C -> R) -> R\n fix3 = fixBy by3\n\n -- That's it. One `fixBy` to rule them all. The final test:\n\n evenAndOdd : \u2200 {R} -> ((\u2115 -> Bool) -> (\u2115 -> Bool) -> R) -> R\n evenAndOdd = fix2 $ \u03bb select even odd -> select\n (\u03bb { 0 -> true ; (suc n) -> odd n })\n (\u03bb { 0 -> false ; (suc n) -> even n })\n\n test : Test (evenAndOdd \u03bb x y -> x) (evenAndOdd \u03bb x y -> y)\n test = refl\n\nmodule LazinessStrictness where\n open UncurriedGeneral using (fixBy)\n\n -- So what about strictness? `fixBy` is generic enough to allow both lazy and strict derivatives.\n -- The version of strict `fix2` looks like this in Haskell:\n\n -- apply :: (a -> b) -> a -> b\n -- apply = ($!)\n\n -- fix2\n -- :: ((a1 -> b1) -> (a2 -> b2) -> a1 -> b1)\n -- -> ((a1 -> b1) -> (a2 -> b2) -> a2 -> b2)\n -- -> ((a1 -> b1) -> (a2 -> b2) -> r) -> r\n -- fix2 f g k = k\n -- (\\x1 -> f `apply` fix2 f g (\\x y -> x) `apply` fix2 f g (\\x y -> y) `apply` x1)\n -- (\\x2 -> g `apply` fix2 f g (\\x y -> x) `apply` fix2 f g (\\x y -> y) `apply` x2)\n\n -- This is just like the Z combinator is of type `((a -> b) -> a -> b) -> a -> b`, so that it can\n -- be used to get fixed points of functions in a strict language where the Y combinator loops forever.\n\n -- The version of `fix2` that works in a strict language can be defined as follows:\n\n by2' : {A\u2081 B\u2081 A\u2082 B\u2082 : Set}\n -> (\u2200 {Q} -> ((A\u2081 -> B\u2081) -> (A\u2082 -> B\u2082) -> Q) -> Q)\n -> {R : Set} -> ((A\u2081 -> B\u2081) -> (A\u2082 -> B\u2082) -> R) -> R\n by2' r k = k (\u03bb x\u2081 -> r \u03bb f\u2081 f\u2082 -> f\u2081 x\u2081) (\u03bb x\u2082 -> r \u03bb f\u2081 f\u2082 -> f\u2082 x\u2082)\n\n fix2' : {A\u2081 B\u2081 A\u2082 B\u2082 : Set}\n -> (\u2200 {Q} -> ((A\u2081 -> B\u2081) -> (A\u2082 -> B\u2082) -> Q) -> (A\u2081 -> B\u2081) -> (A\u2082 -> B\u2082) -> Q)\n -> {R : Set} -> ((A\u2081 -> B\u2081) -> (A\u2082 -> B\u2082) -> R) -> R\n fix2' = fixBy by2'\n\n -- The difference is that in\n\n by2 : {A B : Set} -> (\u2200 {Q} -> (A -> B -> Q) -> Q) -> {R : Set} -> (A -> B -> R) -> R\n by2 r k = k (r \u03bb x y -> x) (r \u03bb x y -> y)\n\n -- both calls to `r` are forced before `k` returns, while in `by2'` additional lambdas that bind\n -- `x\u2081` and `x\u2082` block the recursive calls from being forced, so `k` at some point can decide not to\n -- recurse anymore (i.e. not to force recursive calls) and return a result instead.\n\nmodule ComputeUncurriedGeneral where\n -- You might wonder whether we can define a single `fixN` which receives a natural number and\n -- computes the appropriate fixed-point combinator of mutually recursive functions. E.g.\n\n -- fixN 2 ~> fix2\n -- fixN 3 ~> fix3\n\n -- So that we do not even need to specify `by2` and `by3` by ourselves. Yes we can do that, see [2]\n -- (the naming is slightly different there).\n\n -- Moreover, we can assign a type to `fixN` in pure System F\u03c9, see [3].\n\nmodule References where\n -- [1] \"Mutual Recursion in Final Encoding\", Andreas Herrmann\n -- https:\/\/aherrmann.github.io\/programming\/2016\/05\/28\/mutual-recursion-in-final-encoding\/\n\n -- [2] https:\/\/gist.github.com\/effectfully\/b3185437da14322c775f4a7691b6fe1f#file-mutualfixgenericcompute-agda\n\n -- [3] https:\/\/gist.github.com\/effectfully\/b3185437da14322c775f4a7691b6fe1f#file-mutualfixgenericcomputenondep-agda\n","avg_line_length":40.4112676056,"max_line_length":117,"alphanum_fraction":0.5591802593} {"size":3623,"ext":"agda","lang":"Agda","max_stars_count":98.0,"content":"{-# OPTIONS --universe-polymorphism #-}\nmodule Categories.Bicategory.Helpers where\n\n-- quite a bit of the code below is taken from Categories.2-Category\nopen import Data.Nat using (_+_)\nopen import Function using (flip)\nopen import Data.Product using (_,_; curry)\n\nopen import Categories.Category\nopen import Categories.Categories using (Categories)\nimport Categories.Functor\nopen import Categories.Terminal using (OneC; One; unit)\nopen import Categories.Object.Terminal using (module Terminal)\nopen import Categories.Bifunctor hiding (identity\u02e1; identity\u02b3; assoc) renaming (id to idF; _\u2261_ to _\u2261F_; _\u2218_ to _\u2218F_)\nopen import Categories.NaturalIsomorphism\nopen import Categories.NaturalTransformation using (NaturalTransformation) renaming (_\u2261_ to _\u2261\u207f_; id to id\u207f)\nopen import Categories.Product using (Product; assoc\u02b3; \u03c0\u02e1; \u03c0\u02b3)\n\nmodule BicategoryHelperFunctors {o \u2113 t e} (Obj : Set o) (_\u21d2_ : (A B : Obj) \u2192 Category \u2113 t e)\n (\u2014\u2297\u2014 : {A B C : Obj} \u2192 Bifunctor (B \u21d2 C) (A \u21d2 B) (A \u21d2 C)) \n (id : {A : Obj} \u2192 Functor {\u2113} {t} {e} OneC (A \u21d2 A)) where\n\n open Terminal (One {\u2113} {t} {e})\n\n _\u2218_ : {A B C : Obj} {L R : Category \u2113 t e} \u2192 Functor L (B \u21d2 C) \u2192 Functor R (A \u21d2 B) \u2192 Bifunctor L R (A \u21d2 C)\n _\u2218_ {A} {B} {C} F G = reduce-\u00d7 {D\u2081 = B \u21d2 C} {D\u2082 = A \u21d2 B} \u2014\u2297\u2014 F G\n\n -- convenience!\n module _\u21d2_ (A B : Obj) = Category (A \u21d2 B)\n open _\u21d2_ public using () renaming (Obj to _\u21d2\u2081_)\n\n private module imp\u21d2 {X Y : Obj} = Category (X \u21d2 Y)\n open imp\u21d2 public using () renaming (_\u21d2_ to _\u21d2\u2082_; id to id\u2082; _\u2218_ to _\u2022_; _\u2261_ to _\u2261\u2082_)\n\n id\u2081 : \u2200 {A} \u2192 A \u21d2\u2081 A\n id\u2081 {A} = Functor.F\u2080 (id {A}) unit\n\n id\u2081\u2082 : \u2200 {A} \u2192 id\u2081 {A} \u21d2\u2082 id\u2081 {A}\n id\u2081\u2082 {A} = id\u2082 {A = id\u2081 {A}}\n\n infixr 9 _\u2218\u2081_\n _\u2218\u2081_ : \u2200 {A B C} \u2192 B \u21d2\u2081 C \u2192 A \u21d2\u2081 B \u2192 A \u21d2\u2081 C\n _\u2218\u2081_ = curry (Functor.F\u2080 \u2014\u2297\u2014)\n\n -- horizontal composition\n infixr 9 _\u2218\u2082_\n _\u2218\u2082_ : \u2200 {A B C} {g g\u2032 : B \u21d2\u2081 C} {f f\u2032 : A \u21d2\u2081 B} (\u03b2 : g \u21d2\u2082 g\u2032) (\u03b1 : f \u21d2\u2082 f\u2032) \u2192 (g \u2218\u2081 f) \u21d2\u2082 (g\u2032 \u2218\u2081 f\u2032)\n _\u2218\u2082_ = curry (Functor.F\u2081 \u2014\u2297\u2014)\n\n -- left whiskering\n infixl 9 _\u25c3_\n _\u25c3_ : \u2200 {A B C} {g g\u2032 : B \u21d2\u2081 C} \u2192 g \u21d2\u2082 g\u2032 \u2192 (f : A \u21d2\u2081 B) \u2192 (g \u2218\u2081 f) \u21d2\u2082 (g\u2032 \u2218\u2081 f)\n \u03b2 \u25c3 f = \u03b2 \u2218\u2082 id\u2082\n\n -- right whiskering\n infixr 9 _\u25b9_\n _\u25b9_ : \u2200 {A B C} (g : B \u21d2\u2081 C) \u2192 {f f\u2032 : A \u21d2\u2081 B} \u2192 f \u21d2\u2082 f\u2032 \u2192 (g \u2218\u2081 f) \u21d2\u2082 (g \u2218\u2081 f\u2032)\n g \u25b9 \u03b1 = id\u2082 \u2218\u2082 \u03b1\n\n module Coherence\n (identity\u02e1 : {A B : Obj} \u2192 NaturalIsomorphism (id \u2218 idF {C = A \u21d2 B}) (\u03c0\u02b3 {C = \u22a4} {A \u21d2 B}))\n (identity\u02b3 : {A B : Obj} \u2192 NaturalIsomorphism (idF {C = A \u21d2 B} \u2218 id) (\u03c0\u02e1 {C = A \u21d2 B}))\n (assoc : {A B C D : Obj} \u2192 NaturalIsomorphism (idF \u2218 \u2014\u2297\u2014) ((\u2014\u2297\u2014 \u2218 idF) \u2218F assoc\u02b3 (C \u21d2 D) (B \u21d2 C) (A \u21d2 B)) ) where\n\n open Categories.NaturalTransformation.NaturalTransformation\n\n -- left\/right are inverted between in certain situations!\n -- private so as to not clash with the ones in Bicategory itself\n private\n \u03c1\u1d64 : {A B : Obj} (f : A \u21d2\u2081 B) \u2192 (id\u2081 \u2218\u2081 f) \u21d2\u2082 f\n \u03c1\u1d64 f = \u03b7 (NaturalIsomorphism.F\u21d2G identity\u02e1) (unit , f)\n\n \u03bb\u1d64 : {A B : Obj} (f : A \u21d2\u2081 B) \u2192 (f \u2218\u2081 id\u2081) \u21d2\u2082 f\n \u03bb\u1d64 f = \u03b7 (NaturalIsomorphism.F\u21d2G identity\u02b3) (f , unit)\n\n \u03b1 : {A B C D : Obj} (f : A \u21d2\u2081 B) (g : B \u21d2\u2081 C) (h : C \u21d2\u2081 D) \u2192\n (h \u2218\u2081 (g \u2218\u2081 f)) \u21d2\u2082 ((h \u2218\u2081 g) \u2218\u2081 f)\n \u03b1 f g h = \u03b7 (NaturalIsomorphism.F\u21d2G assoc) (h , g , f)\n\n -- Triangle identity. Look how closely it matches with the one on\n -- http:\/\/ncatlab.org\/nlab\/show\/bicategory\n Triangle : {A B C : Obj} (f : A \u21d2\u2081 B) (g : B \u21d2\u2081 C) \u2192 Set e\n Triangle f g = (g \u25b9 \u03c1\u1d64 f) \u2261\u2082 ((\u03bb\u1d64 g \u25c3 f) \u2022 (\u03b1 f id\u2081 g))\n\n -- Pentagon identity. Ditto.\n Pentagon : {A B C D E : Obj} (f : A \u21d2\u2081 B) (g : B \u21d2\u2081 C) (h : C \u21d2\u2081 D) (i : D \u21d2\u2081 E) \u2192 Set e\n Pentagon f g h i = ((\u03b1 g h i \u25c3 f) \u2022 (\u03b1 f (h \u2218\u2081 g) i)) \u2022 (i \u25b9 \u03b1 f g h) \u2261\u2082 (\u03b1 f g (i \u2218\u2081 h) \u2022 \u03b1 (g \u2218\u2081 f) h i)\n","avg_line_length":41.1704545455,"max_line_length":120,"alphanum_fraction":0.5578250069} {"size":1022,"ext":"agda","lang":"Agda","max_stars_count":3.0,"content":"\ndata Dec (A : Set) : Set where\n yes : A \u2192 Dec A\n no : Dec A\n\nrecord \u22a4 : Set where constructor tt\n\ndata _\u2261_ {A : Set}(x : A) : A \u2192 Set where\n refl : x \u2261 x\n\nsubst : \u2200 {A}(P : A \u2192 Set){x y} \u2192 x \u2261 y \u2192 P x \u2192 P y\nsubst P refl px = px\n\ncong : \u2200 {A B}(f : A \u2192 B){x y} \u2192 x \u2261 y \u2192 f x \u2261 f y\ncong f refl = refl\n\npostulate _\u225f_ : (n n' : \u22a4) \u2192 Dec (n \u2261 n')\n\nrecord _\u00d7_ A B : Set where\n constructor _,_\n field proj\u2081 : A\n proj\u2082 : B\n\nopen _\u00d7_\n\ndata Maybe : Set where\n nothing : Maybe\n\ndata Blah (a : Maybe \u00d7 \u22a4) : Set where\n blah : {b : Maybe \u00d7 \u22a4} \u2192 Blah b \u2192 Blah a\n\nupdate : {A : Set} \u2192 \u22a4 \u2192 A \u2192 A\nupdate n m with n \u225f n\nupdate n m | yes p = m\nupdate n m | no = m\n\nlem-upd : \u2200 {A} n (m : A) \u2192 update n m \u2261 m\nlem-upd n m with n \u225f n\n... | yes p = refl\n... | no = refl\n\nbug : {x : Maybe \u00d7 \u22a4} \u2192 proj\u2081 x \u2261 nothing \u2192 Blah x\nbug ia = blah (bug (subst {\u22a4}\n (\u03bb _ \u2192 proj\u2081 {B = \u22a4}\n (update tt (nothing , tt)) \u2261 nothing)\n refl (cong proj\u2081 (lem-upd _ _))))\n","avg_line_length":21.7446808511,"max_line_length":72,"alphanum_fraction":0.4765166341} {"size":1951,"ext":"agda","lang":"Agda","max_stars_count":6.0,"content":"{-# OPTIONS --cubical --safe --postfix-projections #-}\n\nmodule Data.Nat.Order where\n\nopen import Prelude\nopen import Data.Nat.Properties\nopen import Relation.Binary\n\n<-trans : Transitive _<_\n<-trans {zero} {suc y} {suc z} x : \u2200 x y \u2192 \u00ac (x \u2264 y) \u2192 y < x\n\u2115-\u2270\u21d2> x y x\u2270y with y <\u1d2e x\n... | false = x\u2270y tt\n... | true = tt\n\n\u2115-\u226e\u21d2\u2265 : \u2200 x y \u2192 \u00ac (x < y) \u2192 y \u2264 x\n\u2115-\u226e\u21d2\u2265 x y x\u226ey with x <\u1d2e y\n... | false = tt\n... | true = x\u226ey tt\n\ntotalOrder : TotalOrder \u2115 \u2113zero \u2113zero\ntotalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder._<_ = _<_\ntotalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder.trans {x} {y} {z} = <-trans {x} {y} {z}\ntotalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.strictPreorder .StrictPreorder.irrefl {x} = <-irrefl {x = x}\ntotalOrder .TotalOrder.strictPartialOrder .StrictPartialOrder.conn = <-conn\ntotalOrder .TotalOrder.partialOrder .PartialOrder.preorder .Preorder._\u2264_ = _\u2264_\ntotalOrder .TotalOrder.partialOrder .PartialOrder.preorder .Preorder.refl {x} = \u2264-refl x\ntotalOrder .TotalOrder.partialOrder .PartialOrder.preorder .Preorder.trans {x} {y} {z} = \u2264-trans x y z\ntotalOrder .TotalOrder.partialOrder .PartialOrder.antisym = \u2264-antisym\ntotalOrder .TotalOrder._ {x} {y} = \u2115-\u2270\u21d2> x y\ntotalOrder .TotalOrder.\u226e\u21d2\u2265 {x} {y} = \u2115-\u226e\u21d2\u2265 x y\n","avg_line_length":38.2549019608,"max_line_length":132,"alphanum_fraction":0.6514607893} {"size":1883,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --copatterns #-}\n{-# OPTIONS -v tc.constr.findInScope:15 #-}\n\n-- One-place functors (decorations) on Set\n\nmodule Control.Bug-Loop where\n\nopen import Function using (id; _\u2218_)\nopen import Relation.Binary.PropositionalEquality\nopen \u2261-Reasoning\n\nopen import Control.Functor\n\nopen IsFunctor {{...}}\n\nrecord IsDecoration (D : Set \u2192 Set) : Set\u2081 where\n field\n traverse : \u2200 {F} {{ functor : IsFunctor F }} {A B} \u2192\n\n (A \u2192 F B) \u2192 D A \u2192 F (D B)\n\n traverse-id : \u2200 {A} \u2192\n\n traverse {F = \u03bb A \u2192 A} {A = A} id \u2261 id\n\n traverse-\u2218 :\n \u2200 {F G} {{ funcF : IsFunctor F}} {{ funcG : IsFunctor G}} \u2192\n \u2200 {A B C} {f : A \u2192 F B} {g : B \u2192 G C} \u2192\n\n traverse ((map g) \u2218 f) \u2261 map {{funcF}} (traverse g) \u2218 traverse f\n\n isFunctor : IsFunctor D\n isFunctor = record\n { ops = record { map = traverse }\n ; laws = record { map-id = traverse-id\n ; map-\u2218 = traverse-\u2218\n }\n }\n\nopen IsDecoration\n\nidIsDecoration : IsDecoration (\u03bb A \u2192 A)\ntraverse idIsDecoration f = f\ntraverse-id idIsDecoration = refl\ntraverse-\u2218 idIsDecoration = refl\n\ncompIsDecoration : \u2200 {D E} \u2192 IsDecoration D \u2192 IsDecoration E \u2192 IsDecoration (\u03bb A \u2192 D (E A))\ntraverse (compIsDecoration d e) f = traverse d (traverse e f)\ntraverse-id (compIsDecoration d e) = begin\n traverse d (traverse e id)\n \u2261\u27e8 cong (traverse d) (traverse-id e) \u27e9\n traverse d id\n \u2261\u27e8 traverse-id d \u27e9\n id\n \u220e\ntraverse-\u2218 (compIsDecoration d e) {{funcF = funcF}} {{funcG = funcG}} {f = f} {g = g} = begin\n traverse (compIsDecoration d e) (map g \u2218 f)\n \u2261\u27e8\u27e9\n traverse d (traverse e (map g \u2218 f))\n \u2261\u27e8 cong (traverse d) (traverse-\u2218 e) \u27e9\n traverse d (map (traverse e g) \u2218 traverse e f)\n \u2261\u27e8 traverse-\u2218 d \u27e9\n map (traverse d (traverse e g)) \u2218 traverse d (traverse e f)\n \u2261\u27e8\u27e9\n map (traverse (compIsDecoration d e) g) \u2218 traverse (compIsDecoration d e) f\n \u220e\n","avg_line_length":28.1044776119,"max_line_length":93,"alphanum_fraction":0.5894848646} {"size":158,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"{-# OPTIONS --universe-polymorphism #-}\nmodule Issue204 where\n\nopen import Issue204.Dependency\n\npostulate\n \u2113 : Level\n r : R \u2113\n d : D \u2113\n\nopen R r\n\nopen M d\n","avg_line_length":11.2857142857,"max_line_length":39,"alphanum_fraction":0.6772151899} {"size":3062,"ext":"agda","lang":"Agda","max_stars_count":1.0,"content":"------------------------------------------------------------------------\n-- The Agda standard library\n--\n-- Decorated star-lists\n------------------------------------------------------------------------\n\nmodule Data.Star.Decoration where\n\nopen import Data.Star\nopen import Relation.Binary\nopen import Function\nopen import Data.Unit\nopen import Level\n\n-- A predicate on relation \"edges\" (think of the relation as a graph).\n\nEdgePred : {I : Set} \u2192 Rel I zero \u2192 Set\u2081\nEdgePred T = \u2200 {i j} \u2192 T i j \u2192 Set\n\ndata NonEmptyEdgePred {I : Set}\n (T : Rel I zero) (P : EdgePred T) : Set where\n nonEmptyEdgePred : \u2200 {i j} {x : T i j}\n (p : P x) \u2192 NonEmptyEdgePred T P\n\n-- Decorating an edge with more information.\n\ndata DecoratedWith {I : Set} {T : Rel I zero} (P : EdgePred T)\n : Rel (NonEmpty (Star T)) zero where\n \u21a6 : \u2200 {i j k} {x : T i j} {xs : Star T j k}\n (p : P x) \u2192 DecoratedWith P (nonEmpty (x \u25c5 xs)) (nonEmpty xs)\n\nedge : \u2200 {I} {T : Rel I zero} {P : EdgePred T} {i j} \u2192\n DecoratedWith {T = T} P i j \u2192 NonEmpty T\nedge (\u21a6 {x = x} p) = nonEmpty x\n\ndecoration : \u2200 {I} {T : Rel I zero} {P : EdgePred T} {i j} \u2192\n (d : DecoratedWith {T = T} P i j) \u2192\n P (NonEmpty.proof (edge d))\ndecoration (\u21a6 p) = p\n\n-- Star-lists decorated with extra information. All P xs means that\n-- all edges in xs satisfy P.\n\nAll : \u2200 {I} {T : Rel I zero} \u2192 EdgePred T \u2192 EdgePred (Star T)\nAll P {j = j} xs =\n Star (DecoratedWith P) (nonEmpty xs) (nonEmpty {y = j} \u03b5)\n\n-- We can map over decorated vectors.\n\ngmapAll : \u2200 {I} {T : Rel I zero} {P : EdgePred T}\n {J} {U : Rel J zero} {Q : EdgePred U}\n {i j} {xs : Star T i j}\n (f : I \u2192 J) (g : T =[ f ]\u21d2 U) \u2192\n (\u2200 {i j} {x : T i j} \u2192 P x \u2192 Q (g x)) \u2192\n All P xs \u2192 All {T = U} Q (gmap f g xs)\ngmapAll f g h \u03b5 = \u03b5\ngmapAll f g h (\u21a6 x \u25c5 xs) = \u21a6 (h x) \u25c5 gmapAll f g h xs\n\n-- Since we don't automatically have gmap id id xs \u2261 xs it is easier\n-- to implement mapAll in terms of map than in terms of gmapAll.\n\nmapAll : \u2200 {I} {T : Rel I zero} {P Q : EdgePred T} {i j} {xs : Star T i j} \u2192\n (\u2200 {i j} {x : T i j} \u2192 P x \u2192 Q x) \u2192\n All P xs \u2192 All Q xs\nmapAll {P = P} {Q} f ps = map F ps\n where\n F : DecoratedWith P \u21d2 DecoratedWith Q\n F (\u21a6 x) = \u21a6 (f x)\n\n-- We can decorate star-lists with universally true predicates.\n\ndecorate : \u2200 {I} {T : Rel I zero} {P : EdgePred T} {i j} \u2192\n (\u2200 {i j} (x : T i j) \u2192 P x) \u2192\n (xs : Star T i j) \u2192 All P xs\ndecorate f \u03b5 = \u03b5\ndecorate f (x \u25c5 xs) = \u21a6 (f x) \u25c5 decorate f xs\n\n-- We can append Alls. Unfortunately _\u25c5\u25c5_ does not quite work.\n\ninfixr 5 _\u25c5\u25c5\u25c5_ _\u25bb\u25bb\u25bb_\n\n_\u25c5\u25c5\u25c5_ : \u2200 {I} {T : Rel I zero} {P : EdgePred T}\n {i j k} {xs : Star T i j} {ys : Star T j k} \u2192\n All P xs \u2192 All P ys \u2192 All P (xs \u25c5\u25c5 ys)\n\u03b5 \u25c5\u25c5\u25c5 ys = ys\n(\u21a6 x \u25c5 xs) \u25c5\u25c5\u25c5 ys = \u21a6 x \u25c5 xs \u25c5\u25c5\u25c5 ys\n\n_\u25bb\u25bb\u25bb_ : \u2200 {I} {T : Rel I zero} {P : EdgePred T}\n {i j k} {xs : Star T j k} {ys : Star T i j} \u2192\n All P xs \u2192 All P ys \u2192 All P (xs \u25bb\u25bb ys)\n_\u25bb\u25bb\u25bb_ = flip _\u25c5\u25c5\u25c5_\n","avg_line_length":33.2826086957,"max_line_length":76,"alphanum_fraction":0.5003265839} {"size":3080,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"{-# OPTIONS --without-K #-}\n\nmodule Data.ByteString where\n\nimport Data.ByteString.Primitive as Prim\nimport Data.ByteString.Utf8 as Utf8\n\nopen import Data.Word8 using (Word8)\nopen import Data.Nat using (\u2115)\nopen import Data.Colist using (Colist)\nopen import Data.List using (List)\nopen import Data.String using (String)\nopen import Data.Bool using (Bool; true; false)\nopen import Data.Product using (_\u00d7_)\nopen import Data.Tuple using (Pair\u2192\u00d7)\n\nopen import Relation.Nullary using (yes; no)\nopen import Relation.Nullary.Decidable using (\u230a_\u230b)\nopen import Relation.Binary using (Decidable)\nopen import Relation.Binary.PropositionalEquality as PropEq using (_\u2261_)\nopen import Relation.Binary.PropositionalEquality.TrustMe using (trustMe)\n\n\ndata ByteStringKind : Set where\n Lazy Strict : ByteStringKind\n\nByteString : ByteStringKind \u2192 Set\nByteString Lazy = Prim.ByteStringLazy\nByteString Strict = Prim.ByteStringStrict\n\nempty : \u2200 {k} \u2192 ByteString k\nempty {Lazy} = Prim.emptyLazy\nempty {Strict} = Prim.emptyStrict\n\nnull : \u2200 {k} \u2192 ByteString k \u2192 Bool\nnull {Lazy} = Prim.nullLazy\nnull {Strict} = Prim.nullStrict\n\nlength : \u2200 {k} \u2192 ByteString k \u2192 \u2115\nlength {Lazy} bs = Prim.int64To\u2115 (Prim.lengthLazy bs)\nlength {Strict} bs = Prim.IntTo\u2115 (Prim.lengthStrict bs)\n\nunsafeHead : \u2200 {k} \u2192 ByteString k \u2192 Word8\nunsafeHead {Lazy} = Prim.headLazy\nunsafeHead {Strict} = Prim.headStrict\n\nunsafeTail : \u2200 {k} \u2192 ByteString k \u2192 ByteString k\nunsafeTail {Lazy} = Prim.tailLazy\nunsafeTail {Strict} = Prim.tailStrict\n\nunsafeIndex : \u2200 {k} \u2192 ByteString k \u2192 \u2115 \u2192 Word8\nunsafeIndex {Lazy} bs ix = Prim.indexLazy bs (Prim.\u2115ToInt64 ix)\nunsafeIndex {Strict} bs ix = Prim.indexStrict bs (Prim.\u2115ToInt ix)\n\nunsafeSplitAt : \u2200 {k} \u2192 \u2115 \u2192 ByteString k \u2192 (ByteString k) \u00d7 (ByteString k)\nunsafeSplitAt {Lazy} ix bs = Pair\u2192\u00d7 (Prim.splitAtLazy (Prim.\u2115ToInt64 ix) bs)\nunsafeSplitAt {Strict} ix bs = Pair\u2192\u00d7 (Prim.splitAtStrict (Prim.\u2115ToInt ix) bs)\n\nByteStringRep : ByteStringKind \u2192 Set\nByteStringRep Lazy = Colist Word8\nByteStringRep Strict = List Word8\n\nunpack : \u2200 {k} \u2192 ByteString k \u2192 ByteStringRep k\nunpack {Lazy} = Prim.Colist\u2190Lazy\nunpack {Strict} = Prim.List\u2190Strict\n\npack : \u2200 {k} \u2192 ByteStringRep k \u2192 ByteString k\npack {Lazy} = Prim.Colist\u2192Lazy\npack {Strict} = Prim.List\u2192Strict\n\n\ninfix 4 _\u225f_\n\n_\u225f_ : \u2200 {k} \u2192 Decidable {A = ByteString k} _\u2261_\n_\u225f_ {Lazy} s\u2081 s\u2082 with Prim.lazy\u225flazy s\u2081 s\u2082\n... | true = yes trustMe\n... | false = no whatever\n where postulate whatever : _\n_\u225f_ {Strict} s\u2081 s\u2082 with Prim.strict\u225fstrict s\u2081 s\u2082\n... | true = yes trustMe\n... | false = no whatever\n where postulate whatever : _\n\n-- behind _==_ is the same idea as in Data.String\ninfix 4 _==_\n\n_==_ : \u2200 {k} \u2192 ByteString k \u2192 ByteString k \u2192 Bool\n_==_ {k} s\u2081 s\u2082 = \u230a s\u2081 \u225f s\u2082 \u230b\n\n_++_ : ByteString Lazy \u2192 ByteString Lazy \u2192 ByteString Lazy\n_++_ = Prim.appendLazy\n\nfromChunks : List (ByteString Strict) \u2192 ByteString Lazy\nfromChunks = Prim.fromChunks\n\ntoChunks : ByteString Lazy \u2192 List (ByteString Strict)\ntoChunks = Prim.toChunks\n\ntoLazy : ByteString Strict \u2192 ByteString Lazy\ntoLazy = Prim.toLazy\n\ntoStrict : ByteString Lazy \u2192 ByteString Strict\ntoStrict = Prim.toStrict\n\n","avg_line_length":29.3333333333,"max_line_length":78,"alphanum_fraction":0.7279220779} {"size":4710,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"module StreamEnc where\n\nopen import Data.Unit hiding (_\u2264_)\nopen import Data.Nat\nopen import Data.Product\nopen import Data.Sum\nopen import Relation.Binary.PropositionalEquality as P\nopen \u2261-Reasoning\n\n\u2264-step : \u2200{k n} \u2192 k \u2264 n \u2192 k \u2264 suc n\n\u2264-step z\u2264n = z\u2264n\n\u2264-step (s\u2264s p) = s\u2264s (\u2264-step p)\n\npred-\u2264 : \u2200{k n} \u2192 suc k \u2264 n \u2192 k \u2264 n\npred-\u2264 (s\u2264s p) = \u2264-step p\n\nStr : Set \u2192 Set\nStr A = \u2115 \u2192 A\n\nhd : \u2200{A} \u2192 Str A \u2192 A\nhd s = s 0\n\ntl : \u2200{A} \u2192 Str A \u2192 Str A\ntl s n = s (suc n)\n\n_\u03c9 : \u2200{A} \u2192 A \u2192 Str A\n(a \u03c9) n = a\n\n_\u2237_ : \u2200{A} \u2192 A \u2192 Str A \u2192 Str A\n(a \u2237 s) 0 = a\n(a \u2237 s) (suc n) = s n\n\nmodule Mealy (A B : Set) where\n\n M : Set \u2192 Set\n M X = A \u2192 B \u00d7 X\n\n M\u2081 : {X Y : Set} \u2192 (X \u2192 Y) \u2192 M X \u2192 M Y\n M\u2081 f g a =\n let (b , x) = g a\n in (b , f x)\n\n \ud835\udcdc : Set\n \ud835\udcdc = Str A \u2192 Str B\n\n d : \ud835\udcdc \u2192 M \ud835\udcdc\n d f a = (f (a \u03c9) 0 , (\u03bb s n \u2192 f (a \u2237 s) (suc n)))\n\n corec : \u2200{X} \u2192 (c : X \u2192 M X) \u2192 X \u2192 \ud835\udcdc\n corec c x s zero = proj\u2081 (c x (hd s))\n corec c x s (suc n) = corec c (proj\u2082 (c x (hd s))) (tl s) n\n\n compute' : \u2200{X} (c : X \u2192 M X) (x : X) \u2192\n \u2200 a \u2192 d (corec c x) a \u2261 M\u2081 (corec c) (c x) a\n compute' c x a =\n begin\n d (corec c x) a\n \u2261\u27e8 refl \u27e9\n ((corec c x) (a \u03c9) 0 , \u03bb s n \u2192 (corec c x) (a \u2237 s) (suc n))\n \u2261\u27e8 refl \u27e9\n (proj\u2081 (c x (hd (a \u03c9)))\n , \u03bb s n \u2192 corec c (proj\u2082 (c x (hd (a \u2237 s)))) (tl (a \u2237 s)) n)\n \u2261\u27e8 refl \u27e9\n (proj\u2081 (c x a) , \u03bb s n \u2192 corec c (proj\u2082 (c x a)) (\u03bb n \u2192 s n) n)\n \u2261\u27e8 refl \u27e9\n (proj\u2081 (c x a) , \u03bb s n \u2192 corec c (proj\u2082 (c x a)) s n)\n \u2261\u27e8 refl \u27e9\n (proj\u2081 (c x a) , \u03bb s \u2192 corec c (proj\u2082 (c x a)) s)\n \u2261\u27e8 refl \u27e9\n (proj\u2081 (c x a) , corec c (proj\u2082 (c x a)))\n \u2261\u27e8 refl \u27e9\n M\u2081 (corec c) (c x) a\n \u220e\n\n compute : \u2200{X} (c : X \u2192 M X) (x : X) \u2192\n d (corec c x) \u2261 M\u2081 (corec c) (c x)\n compute c x =\n begin\n d (corec c x)\n \u2261\u27e8 refl \u27e9\n (\u03bb a \u2192 d (corec c x) a)\n \u2261\u27e8 refl \u27e9 -- Same as in compute'\n (\u03bb a \u2192 M\u2081 (corec c) (c x) a)\n \u2261\u27e8 refl \u27e9\n M\u2081 (corec c) (c x)\n \u220e\n\nmodule MealyT (A B : Set) (a\u2080 : A) where\n\n M : Set \u2192 Set\n M X = \u22a4 \u228e (A \u2192 B \u00d7 X)\n\n M\u2081 : {X Y : Set} \u2192 (X \u2192 Y) \u2192 M X \u2192 M Y\n M\u2081 f (inj\u2081 x) = inj\u2081 x\n M\u2081 f (inj\u2082 g) =\n inj\u2082 (\u03bb a \u2192\n let (b , x) = g a\n in (b , f x))\n\n Mono : (Str A \u2192 Str (\u22a4 \u228e B)) \u2192 Set\n -- Mono f = \u2200 n \u2192 (\u2203 \u03bb s \u2192 \u2203 \u03bb b \u2192 f s n \u2261 inj\u2082 b) \u2192\n -- \u2200 s \u2192 \u2200 k \u2192 k \u2264 n \u2192 (\u2203 \u03bb b \u2192 f s k \u2261 inj\u2082 b)\n Mono f = \u2200 n \u2192 \u2200 s\u2081 b\u2081 \u2192 f s\u2081 n \u2261 inj\u2082 b\u2081 \u2192\n \u2200 s \u2192 \u2200 k \u2192 k \u2264 n \u2192 (\u2203 \u03bb b \u2192 f s k \u2261 inj\u2082 b)\n\n \ud835\udcdc\u2081 : Set\n \ud835\udcdc\u2081 = Str A \u2192 Str (\u22a4 \u228e B)\n\n \ud835\udcdc : Set\n \ud835\udcdc = \u03a3[ f \u2208 \ud835\udcdc\u2081 ] (Mono f)\n\n d : \ud835\udcdc \u2192 M \ud835\udcdc\n d (f , m) = F (f (a\u2080 \u03c9) 0) refl\n where\n F : (u : \u22a4 \u228e B) \u2192 (f (a\u2080 \u03c9) 0) \u2261 u \u2192 M \ud835\udcdc\n F (inj\u2081 tt) _ = inj\u2081 tt\n F (inj\u2082 b) p = inj\u2082 (\u03bb a \u2192\n let (b' , p') = m 0 (a\u2080 \u03c9) b p (a \u03c9) 0 z\u2264n\n f' = \u03bb s n \u2192 f (a \u2237 s) (suc n)\n m' : Mono f'\n m' = \u03bb {n s\u2081 b\u2081 p\u2081 s k k\u2264n \u2192\n m (suc n) (a \u2237 s\u2081) b\u2081 p\u2081 (a \u2237 s) (suc k) (s\u2264s k\u2264n)}\n in b' , f' , m')\n\n corec\u2081 : \u2200{X} \u2192 (c : X \u2192 M X) \u2192 X \u2192 \ud835\udcdc\u2081\n corec\u2081 c x s n with c x\n corec\u2081 c x s n | inj\u2081 tt = inj\u2081 tt\n corec\u2081 c x s zero | inj\u2082 g = inj\u2082 (proj\u2081 (g (hd s)))\n corec\u2081 c x s (suc n) | inj\u2082 g = corec\u2081 c (proj\u2082 (g (hd s))) (tl s) n\n\n corec\u2082 : \u2200{X} \u2192 (c : X \u2192 M X) (x : X) \u2192 Mono (corec\u2081 c x)\n corec\u2082 c x n s\u2081 b\u2081 p\u2081 s k k\u2264n with c x\n corec\u2082 c x n s\u2081 b\u2081 () s k k\u2264n | inj\u2081 tt\n corec\u2082 c x n s\u2081 b\u2081 p\u2081 s zero k\u2264n | inj\u2082 g = (proj\u2081 (g (hd s)) , refl)\n corec\u2082 c x n s\u2081 b\u2081 p\u2081 s (suc k) sk\u2264n | inj\u2082 g = {!!}\n -- corec\u2082 c\n -- (proj\u2082 (g (hd s)))\n -- n\n -- (tl s)\n -- (proj\u2081 (g (hd s)))\n -- {!!}\n -- (tl s) k (pred-\u2264 sk\u2264n)\n\n -- compute' : \u2200{X} (c : X \u2192 M X) (x : X) \u2192\n -- \u2200 a \u2192 d (corec c x) a \u2261 M\u2081 (corec c) (c x) a\n -- compute' c x a =\n -- begin\n -- d (corec c x) a\n -- \u2261\u27e8 refl \u27e9\n -- ((corec c x) (a \u03c9) 0 , \u03bb s n \u2192 (corec c x) (a \u2237 s) (suc n))\n -- \u2261\u27e8 refl \u27e9\n -- (proj\u2081 (c x (hd (a \u03c9)))\n -- , \u03bb s n \u2192 corec c (proj\u2082 (c x (hd (a \u2237 s)))) (tl (a \u2237 s)) n)\n -- \u2261\u27e8 refl \u27e9\n -- (proj\u2081 (c x a) , \u03bb s n \u2192 corec c (proj\u2082 (c x a)) (\u03bb n \u2192 s n) n)\n -- \u2261\u27e8 refl \u27e9\n -- (proj\u2081 (c x a) , \u03bb s n \u2192 corec c (proj\u2082 (c x a)) s n)\n -- \u2261\u27e8 refl \u27e9\n -- (proj\u2081 (c x a) , \u03bb s \u2192 corec c (proj\u2082 (c x a)) s)\n -- \u2261\u27e8 refl \u27e9\n -- (proj\u2081 (c x a) , corec c (proj\u2082 (c x a)))\n -- \u2261\u27e8 refl \u27e9\n -- M\u2081 (corec c) (c x) a\n -- \u220e\n\n -- compute : \u2200{X} (c : X \u2192 M X) (x : X) \u2192\n -- d (corec c x) \u2261 M\u2081 (corec c) (c x)\n -- compute c x =\n -- begin\n -- d (corec c x)\n -- \u2261\u27e8 refl \u27e9\n -- (\u03bb a \u2192 d (corec c x) a)\n -- \u2261\u27e8 refl \u27e9 -- Same as in compute'\n -- (\u03bb a \u2192 M\u2081 (corec c) (c x) a)\n -- \u2261\u27e8 refl \u27e9\n -- M\u2081 (corec c) (c x)\n -- \u220e\n","avg_line_length":26.4606741573,"max_line_length":73,"alphanum_fraction":0.395329087} {"size":418,"ext":"agda","lang":"Agda","max_stars_count":1989.0,"content":"{-# OPTIONS --experimental-irrelevance #-}\n\n-- Andreas, 2015-05-18 Irrelevant module parameters\n-- should not be resurrected in module body.\n\npostulate\n A : Set\n\nmodule M .(a : A) where\n\n bad : (..(_ : A) -> Set) -> Set\n bad f = f a\n -- SHOULD FAIL: variable a is declared irrelevant,\n -- so it cannot be used here.\n\n-- This fails of course:\n-- fail : .(a : A) -> (..(_ : A) -> Set) -> Set\n-- fail a f = f a\n","avg_line_length":22.0,"max_line_length":54,"alphanum_fraction":0.5909090909} {"size":95,"ext":"agda","lang":"Agda","max_stars_count":null,"content":"-- This combination should not be allowed:\n\n{-# OPTIONS --guardedness --sized-types --safe #-}\n","avg_line_length":23.75,"max_line_length":50,"alphanum_fraction":0.6842105263} {"size":624,"ext":"agda","lang":"Agda","max_stars_count":10.0,"content":"------------------------------------------------------------------------\n-- INCREMENTAL \u03bb-CALCULUS\n--\n-- Overloading \u27e6_\u27e7 notation\n--\n-- This module defines a general mechanism for overloading the\n-- \u27e6_\u27e7 notation, using Agda\u2019s instance arguments.\n------------------------------------------------------------------------\n\nmodule Base.Denotation.Notation where\n\nopen import Level\n\nrecord Meaning (Syntax : Set) {\u2113 : Level} : Set (suc \u2113) where\n constructor\n meaning\n field\n {Semantics} : Set \u2113\n \u27e8_\u27e9\u27e6_\u27e7 : Syntax \u2192 Semantics\n\nopen Meaning {{...}} public\n renaming (\u27e8_\u27e9\u27e6_\u27e7 to \u27e6_\u27e7)\n\nopen Meaning public\n using (\u27e8_\u27e9\u27e6_\u27e7)\n","avg_line_length":24.0,"max_line_length":72,"alphanum_fraction":0.516025641}