Search is not available for this dataset
text
string | meta
dict |
---|---|
module x10-747Lists-hc where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong)
open Eq.≡-Reasoning
open import Data.Bool using (Bool; true; false; T; _∧_; _∨_; not)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _≤_; s≤s; z≤n)
open import Data.Nat.Properties using (+-assoc; +-identityˡ; +-identityʳ; *-assoc; *-identityˡ; *-identityʳ)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (_×_; ∃; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_∘_)
open import Level using (Level)
open import Data.Empty using (⊥)
------------------------------------------------------------------------------
-- Copied from 747Isomorphism.
infix 0 _≃_
record _≃_ (A B : Set) : Set where
constructor mk-≃ -- This has been added, not in PLFA
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_
------------------------------------------------------------------------------
-- Polymorphic lists (parameterized version).
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
infixr 5 _∷_
-- example
_ : List ℕ
_ = 0 ∷ 1 ∷ 2 ∷ []
-- equivalent indexed version
data List' : Set → Set where
[]' : ∀ {A : Set} → List' A
_∷'_ : ∀ {A : Set} → A → List' A → List' A
-- using implicit arguments in above example (why?)
_ : List ℕ
_ = _∷_ {ℕ} 0 (_∷_ {ℕ} 1 (_∷_ {ℕ} 2 ([] {ℕ})))
-- tell Agda to use Haskell lists internally
{-# BUILTIN LIST List #-}
-- useful syntax
pattern [_] z = z ∷ []
pattern [_,_] y z = y ∷ z ∷ []
pattern [_,_,_] x y z = x ∷ y ∷ z ∷ []
pattern [_,_,_,_] w x y z = w ∷ x ∷ y ∷ z ∷ []
pattern [_,_,_,_,_] v w x y z = v ∷ w ∷ x ∷ y ∷ z ∷ []
pattern [_,_,_,_,_,_] u v w x y z = u ∷ v ∷ w ∷ x ∷ y ∷ z ∷ []
-- append for lists
infixr 5 _++_
_++_ : ∀ {A : Set} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
_ : [ 0 , 2 , 4 ] ++ [ 3 , 5 ] ≡ [ 0 , 2 , 4 , 3 , 5 ]
_ = refl
-- associativity of append
++-assoc : ∀ {A : Set} → (xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
++-assoc [] ys zs = refl
++-assoc (x ∷ xs) ys zs rewrite ++-assoc xs ys zs = refl
-- left/right identities for append
++-identityˡ : ∀ {A : Set} → (xs : List A) → [] ++ xs ≡ xs
++-identityˡ xs = refl
++-identityʳ : ∀ {A : Set} → (xs : List A) → xs ++ [] ≡ xs
++-identityʳ [] = refl
++-identityʳ (x ∷ xs) rewrite ++-identityʳ xs = refl
-- length of a list
length : ∀ {A : Set} → List A → ℕ
length [] = zero
length (x ∷ xs) = suc (length xs)
_ : length [ 0 , 1 , 2 ] ≡ 3
_ = refl
-- reasoning about length.
length-++ : ∀ {A : Set} → (xs ys : List A) → length (xs ++ ys) ≡ length xs + length ys
length-++ [] ys = refl
length-++ (x ∷ xs) ys rewrite length-++ xs ys = refl
-- quadratic time reverse using structural recursion
reverse : ∀ {A : Set} → List A → List A
reverse [] = []
reverse (x ∷ xs) = reverse xs ++ [ x ]
_ : reverse [ 0 , 1 , 2 ] ≡ [ 2 , 1 , 0 ]
_ = refl
-- 747/PLFA exercise: RevCommApp (1 point)
-- reverse commutes with ++
-- https://gist.github.com/pedrominicz/012e842362f6c65361722ed1aaf10178
-- The key to this one is NOT splitting ys.
reverse-++-commute : ∀ {A : Set}
→ (xs ys : List A)
→ reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-++-commute [] ys rewrite ++-identityʳ (reverse ys) = refl
reverse-++-commute (x ∷ xs) ys
-- reverse ((x ∷ xs) ++ ys) ≡ reverse ys ++ reverse (x ∷ xs)
-- reverse (xs ++ ys) ++ [ x ] ≡ reverse ys ++ reverse xs ++ [ x ]
rewrite
reverse-++-commute xs ys
-- (reverse ys ++ reverse xs) ++ [ x ] ≡ reverse ys ++ reverse xs ++ [ x ]
| ++-assoc (reverse ys) (reverse xs) [ x ]
-- reverse ys ++ reverse xs ++ [ x ] ≡ reverse ys ++ reverse xs ++ [ x ]
= refl
-- NOT USED
snoc : {A : Set} → List A → A → List A
snoc [] x = x ∷ []
snoc (y ∷ l) x = y ∷ (snoc l x)
-- NOT USED
snoc≡app : {A : Set} → (l : List A) → (a : A) → snoc l a ≡ l ++ [ a ]
snoc≡app [] a = refl
snoc≡app (x ∷ l) a rewrite (snoc≡app l a) = refl
-- NOT USED
reverse-snoc : ∀ {A : Set} → (xs : List A) → List A
reverse-snoc [] = []
reverse-snoc (x ∷ xs) = snoc (reverse-snoc xs) x
_ : reverse-snoc [ 0 , 1 , 2 ] ≡ [ 2 , 1 , 0 ]
_ = refl
-- NOT USED
reverse≡reverse-snoc : ∀ {A : Set} → (xs : List A) → reverse xs ≡ reverse-snoc xs
reverse≡reverse-snoc [] = refl
reverse≡reverse-snoc (x ∷ xs) -- reverse (x ∷ xs) ≡ reverse-snoc (x ∷ xs)
-- reverse xs ++ [ x ] ≡ snoc (reverse-snoc xs) x
rewrite
reverse≡reverse-snoc xs -- reverse-snoc xs ++ [ x ] ≡ snoc (reverse-snoc xs) x
| snoc≡app (reverse-snoc xs) x -- reverse-snoc xs ++ [ x ] ≡ reverse-snoc xs ++ [ x ]
= refl
-- 747/PLFA exercise: RevInvol (1 point)
-- Reverse is its own inverse.
reverse-involutive : ∀ {A : Set} → (xs : List A) → reverse (reverse xs) ≡ xs
reverse-involutive [] = refl
reverse-involutive (x ∷ xs) -- reverse (reverse (x ∷ xs)) ≡ x ∷ xs
-- reverse (reverse xs ++ [ x ]) ≡ x ∷ xs
rewrite
(reverse-++-commute (reverse xs) [ x ]) -- x ∷ reverse (reverse xs) ≡ x ∷ xs
| reverse-involutive xs -- x ∷ xs ≡ x ∷ xs
= refl
-- towards more efficient linear time reverse
-- generalization of reverse
shunt : ∀ {A : Set} → List A → List A → List A
shunt [] ys = ys
shunt (x ∷ xs) ys = shunt xs (x ∷ ys)
-- explanation of what shunt is doing
shunt-reverse : ∀ {A : Set} → (xs ys : List A) → shunt xs ys ≡ reverse xs ++ ys
shunt-reverse [] ys = refl
shunt-reverse (x ∷ xs) [] -- shunt (x ∷ xs) [] ≡ reverse (x ∷ xs) ++ []
-- shunt xs [ x ] ≡ (reverse xs ++ [ x ]) ++ []
rewrite
++-identityʳ (reverse xs ++ [ x ])
-- shunt xs [ x ] ≡ reverse xs ++ [ x ]
| shunt-reverse xs [ x ] -- reverse xs ++ [ x ] ≡ reverse xs ++ [ x ]
= refl
shunt-reverse (x ∷ xs) (y ∷ ys)
-- shunt (x ∷ xs) (y ∷ ys) ≡ reverse (x ∷ xs) ++ y ∷ ys
-- shunt xs (x ∷ y ∷ ys) ≡ (reverse xs ++ [ x ]) ++ y ∷ ys
rewrite
shunt-reverse xs (x ∷ y ∷ ys)
-- reverse xs ++ x ∷ y ∷ ys ≡ (reverse xs ++ [ x ]) ++ y ∷ ys
| ++-assoc (reverse xs) [ x ] (y ∷ ys)
-- reverse xs ++ x ∷ y ∷ ys ≡ reverse xs ++ x ∷ y ∷ ys
= refl
-- linear reverse is a special case of shunt
reverse' : ∀ {A : Set} → List A → List A
reverse' xs = shunt xs []
_ : reverse' [ 0 , 1 , 2 ] ≡ [ 2 , 1 , 0 ]
_ = refl
-- prove quadratic and linear reverse are equivalent
reverses : ∀ {A : Set} → (xs : List A) → reverse' xs ≡ reverse xs
reverses [] = refl
reverses (x ∷ xs) -- reverse' (x ∷ xs) ≡ reverse (x ∷ xs)
-- reverse' (x ∷ xs) ≡ reverse xs ++ [ x ]
rewrite shunt-reverse xs [ x ] -- reverse xs ++ [ x ] ≡ reverse xs ++ [ x ]
= refl
-- common higher-order list functions
map : ∀ {A B : Set} → (A → B) → List A → List B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
_ : map suc [ 0 , 1 , 2 ] ≡ [ 1 , 2 , 3 ]
_ = refl
-- 747/PLFA exercise: MapCompose (1 point)
-- The map of a composition is the composition of maps.
-- Changed from PLFA: some arguments made explicit, uses pointwise equality.
map-compose : ∀ {A B C : Set} (f : A → B) (g : B → C) (xs : List A)
→ map (g ∘ f) xs ≡ (map g ∘ map f) xs
map-compose f g [] = refl
map-compose f g (x ∷ xs) -- map (g ∘ f) (x ∷ xs) ≡ (map g ∘ map f) (x ∷ xs)
-- (g ∘ f) x ∷ map (g ∘ f) xs ≡ (map g ∘ map f) (x ∷ xs)
rewrite
map-compose f g xs -- g (f x) ∷ map g (map f xs) ≡ g (f x) ∷ map g (map f xs)
= refl
-- 747/PLFA exercise: MapAppendComm (1 point)
-- The map of an append is the append of maps.
-- Changed from PLFA: some arguments made explicit.
map-++-commute : ∀ {A B : Set} (f : A → B) (xs ys : List A)
→ map f (xs ++ ys) ≡ map f xs ++ map f ys
map-++-commute f [] ys = refl
map-++-commute f (x ∷ xs) ys -- map f ((x ∷ xs) ++ ys) ≡ map f (x ∷ xs) ++ map f ys
-- f x ∷ map f (xs ++ ys) ≡ f x ∷ map f xs ++ map f ys
rewrite
map-++-commute f xs ys -- f x ∷ map f xs ++ map f ys ≡ f x ∷ map f xs ++ map f ys
= refl
------------------------------------------------------------------------------
-- PLFA exercise: map over trees
-- trees with leaves of type A and internal nodes of type B
data Tree (A B : Set) : Set where
leaf : A → Tree A B
node : Tree A B → B → Tree A B → Tree A B
map-Tree : ∀ {A B C D : Set} → (A → C) → (B → D) → Tree A B → Tree C D
map-Tree f g (leaf a) = leaf (f a)
map-Tree f g (node tl b tr) = node (map-Tree f g tl) (g b) (map-Tree f g tr)
------------------------------------------------------------------------------
-- Fold-right: put operator ⊗ between each list element (and supplied final element).
-- ⊗ is considered right-associative.
-- Fold-right is universal for structural recursion on one argument.
foldr : ∀ {A B : Set} → (A → B → B) → B → List A → B
foldr _⊗_ e [] = e
foldr _⊗_ e (x ∷ xs) = x ⊗ foldr _⊗_ e xs
_ : foldr _+_ 0 [ 1 , 2 , 3 , 4 ] ≡ 10
_ = refl
-- Summing a list using foldr.
sum : List ℕ → ℕ
sum = foldr _+_ 0
_ : sum [ 1 , 2 , 3 , 4 ] ≡ 10
_ = refl
-- PLFA exercise: use foldr to define product on lists of naturals
product : List ℕ → ℕ
product = foldr _*_ 1
_ : product [ 1 , 2 , 3 , 4 ] ≡ 24
_ = refl
-- 747/PLFA exercise: FoldrOverAppend (1 point)
-- prove foldr over an append can be expressed as foldrs over each list.
foldr-++ : ∀ {A B : Set} (_⊗_ : A → B → B) (b : B) (xs ys : List A) →
foldr _⊗_ b (xs ++ ys) ≡ foldr _⊗_ (foldr _⊗_ b ys) xs
foldr-++ _⊗_ b [] ys = refl
foldr-++ _⊗_ b (x ∷ xs) ys
-- foldr _⊗_ b ((x ∷ xs) ++ ys) ≡ foldr _⊗_ (foldr _⊗_ b ys) (x ∷ xs)
-- (x ⊗ foldr _⊗_ b (xs ++ ys)) ≡ (x ⊗ foldr _⊗_ (foldr _⊗_ b ys) xs)
rewrite foldr-++ _⊗_ b xs ys
-- (x ⊗ foldr _⊗_ (foldr _⊗_ b ys) xs) ≡ (x ⊗ foldr _⊗_ (foldr _⊗_ b ys) xs)
= refl
-- 747/PLFA exercise: MapIsFoldr (1 point)
-- Show that map can be expressed as a fold.
-- Changed from PLFA: some arguments made explicit, uses pointwise equality.
map-is-foldr : ∀ {A B : Set} (f : A → B) (xs : List A)
→ map f xs ≡ foldr (λ x rs → f x ∷ rs) [] xs
map-is-foldr f [] = refl
map-is-foldr f (x ∷ xs) rewrite map-is-foldr f xs = refl
-- PLFA exercise: write a fold for trees
fold-Tree : ∀ {A B C : Set} → (A → C) → (C → B → C → C) → Tree A B → C
fold-Tree f g (leaf a) = f a
fold-Tree f g (node tl b tr) = g (fold-Tree f g tl) b (fold-Tree f g tr)
-- PLFA exercise: the downFrom function computes a countdown list
-- Prove an equality about its sum
downFrom : ℕ → List ℕ
downFrom zero = []
downFrom (suc n) = n ∷ downFrom n
_ : downFrom 4 ≡ [ 3 , 2 , 1 , 0 ]
_ = refl
_ : sum (downFrom 4) ≡ 6
_ = refl
{- TODO
sum-downFrom : ∀ (n : ℕ) → sum (downFrom n) * 2 ≡ n * (n ∸ 1)
sum-downFrom n = {!!}
-}
------------------------------------------------------------------------------
-- 'Monoid' : set with
-- - an associative operator
-- - an element which is the left and right identity
record IsMonoid (A : Set) : Set where
field
id : A
_⊗_ : A → A → A
assoc : ∀ (x y z : A) → (x ⊗ y) ⊗ z ≡ x ⊗ (y ⊗ z)
identityˡ : ∀ (x : A) → id ⊗ x ≡ x
identityʳ : ∀ (x : A) → x ⊗ id ≡ x
-- The following open command is different from PLFA; it uses instance arguments,
-- which work like typeclasses in Haskell (allow overloading, which is cleaner).
open IsMonoid {{ ...}} public
-- These pragmas make displays of goal and context look nicer.
{-# DISPLAY IsMonoid.id _ = id #-}
{-# DISPLAY IsMonoid._⊗_ _ = _⊗_ #-}
-- instances of Monoid
instance
+-monoid : IsMonoid ℕ
IsMonoid.id +-monoid = 0
IsMonoid._⊗_ +-monoid = _+_
IsMonoid.assoc +-monoid = +-assoc
IsMonoid.identityˡ +-monoid = +-identityˡ
IsMonoid.identityʳ +-monoid = +-identityʳ
*-monoid : IsMonoid ℕ
IsMonoid.id *-monoid = 1
IsMonoid._⊗_ *-monoid = _*_
IsMonoid.assoc *-monoid = *-assoc
IsMonoid.identityˡ *-monoid = *-identityˡ
IsMonoid.identityʳ *-monoid = *-identityʳ
++-monoid : ∀ {A : Set} → IsMonoid (List A)
IsMonoid.id ++-monoid = []
IsMonoid._⊗_ ++-monoid = _++_
IsMonoid.assoc ++-monoid = ++-assoc
IsMonoid.identityˡ ++-monoid = ++-identityˡ
IsMonoid.identityʳ ++-monoid = ++-identityʳ
-- property of foldr over a monoid
foldr-monoid : ∀ {A : Set} → {{m : IsMonoid A}} →
∀ (xs : List A) (y : A)
→ foldr _⊗_ y xs ≡ (foldr _⊗_ id xs) ⊗ y
foldr-monoid {A} ⦃ m ⦄ [] y
rewrite identityˡ y = refl
foldr-monoid {A} ⦃ m ⦄ (x ∷ xs) y
with foldr-monoid xs y
... | xxx
rewrite
xxx
| sym (assoc x (foldr _⊗_ id xs) y)
= refl
foldr-monoid-++ : ∀ {A : Set} → {{m : IsMonoid A}} →
∀ (xs ys : List A)
→ foldr _⊗_ id (xs ++ ys) ≡ foldr _⊗_ id xs ⊗ foldr _⊗_ id ys
foldr-monoid-++ {A} ⦃ m ⦄ [] ys
rewrite
sym (foldr-monoid {A} {{m}} [] (foldr _⊗_ id ys))
= refl
foldr-monoid-++ {A} ⦃ m ⦄ (x ∷ xs) ys
rewrite
foldr-monoid-++ {A} {{m}} xs ys
| assoc x (foldr _⊗_ id xs) (foldr _⊗_ id ys)
= refl
-- 747/PLFA exercise: Foldl (1 point)
-- Define foldl, which associates left instead of right, e.g.
-- foldr _⊗_ e [ x , y , z ] = x ⊗ (y ⊗ (z ⊗ e))
-- foldl _⊗_ e [ x , y , z ] = ((e ⊗ x) ⊗ y) ⊗ z
foldl : ∀ {A B : Set} → (B → A → B) → B → List A → B
foldl _⊗_ e [] = e
foldl _⊗_ e (x ∷ xs) = foldl _⊗_ (e ⊗ x) xs
sum-foldl : foldl _+_ 0 [ 4 , 3 , 2 , 1 ] ≡ 10
sum-foldl = refl
monus-foldl : foldl _∸_ 20 [ 4 , 3 , 2 ] ≡ 11
monus-foldl = refl
monus-foldr : foldr _∸_ 20 [ 4 , 3 , 2 ] ≡ 1
monus-foldr = refl
-- 747/PLFA exercise: FoldrMonFoldl (2 points)
-- Show that foldr and foldl compute the same value on a monoid
-- when the base case is the identity.
-- Hint: generalize to when the base case is an arbitrary value.
foldl-r-mon-helper : ∀ {A : Set} {{m : IsMonoid A}}
→ ∀ (xs : List A) (y : A)
→ foldl _⊗_ y xs ≡ y ⊗ foldl _⊗_ id xs
foldl-r-mon-helper [] y rewrite identityʳ y = refl
foldl-r-mon-helper (x ∷ xs) y -- foldl _⊗_ y (x ∷ xs) ≡ (y ⊗ foldl _⊗_ id (x ∷ xs))
-- foldl _⊗_ (y ⊗ x) xs ≡ (y ⊗ foldl _⊗_ (id ⊗ x) xs)
rewrite
identityˡ x -- foldl _⊗_ (y ⊗ x) xs ≡ (y ⊗ foldl _⊗_ x xs)
| foldl-r-mon-helper xs (y ⊗ x) -- ((y ⊗ x) ⊗ foldl _⊗_ id xs) ≡ (y ⊗ foldl _⊗_ x xs)
| assoc y x (foldl _⊗_ id xs) -- (y ⊗ (x ⊗ foldl _⊗_ id xs)) ≡ (y ⊗ foldl _⊗_ x xs)
| foldl-r-mon-helper xs x -- (y ⊗ (x ⊗ foldl _⊗_ id xs)) ≡ (y ⊗ (x ⊗ foldl _⊗_ id xs))
= refl
foldl-r-mon : ∀ {A : Set} → {{m : IsMonoid A}}
→ ∀ (xs : List A) → foldl _⊗_ id xs ≡ foldr _⊗_ id xs
foldl-r-mon [] = refl
foldl-r-mon (x ∷ xs)
-- foldl _⊗_ id (x ∷ xs) ≡ foldr _⊗_ id (x ∷ xs)
-- foldl _⊗_ (id ⊗ x) xs ≡ (x ⊗ foldr _⊗_ id xs)
rewrite
identityˡ x -- foldl _⊗_ x xs ≡ (x ⊗ foldr _⊗_ id xs)
| foldl-r-mon-helper xs x -- (x ⊗ foldl _⊗_ id xs) ≡ (x ⊗ foldr _⊗_ id xs)
| foldl-r-mon xs -- (x ⊗ foldr _⊗_ id xs) ≡ (x ⊗ foldr _⊗_ id xs)
= refl
------------------------------------------------------------------------------
-- Inductively-defined predicates over lists
-- All P xs means P x holds for every element of xs
data All {A : Set} (P : A → Set) : List A → Set where
[] : All P []
_∷_ : ∀ {x : A} {xs : List A} → P x → All P xs → All P (x ∷ xs)
_ : All (_≤ 2) [ 0 , 1 , 2 ]
_ = z≤n ∷ s≤s z≤n ∷ s≤s (s≤s z≤n) ∷ []
-- Any P xs means P x holds for some element of xs
data Any {A : Set} (P : A → Set) : List A → Set where
here : ∀ {x : A} {xs : List A} → P x → Any P (x ∷ xs)
there : ∀ {x : A} {xs : List A} → Any P xs → Any P (x ∷ xs)
-- membership in list as application of Any
infix 4 _∈_ _∉_
_∈_ : ∀ {A : Set} (x : A) (xs : List A) → Set
x ∈ xs = Any (x ≡_) xs
_∉_ : ∀ {A : Set} (x : A) (xs : List A) → Set
x ∉ xs = ¬ (x ∈ xs)
_ : 0 ∈ [ 0 , 1 , 0 , 2 ]
_ = here refl
_ : 0 ∈ [ 1 , 2 , 0 ]
_ = there (there (here refl))
not-in : 3 ∉ [ 0 , 1 , 0 , 2 ]
not-in (here ())
not-in (there (here ()))
not-in (there (there (here ())))
not-in (there (there (there (here ()))))
-- The development in PLFA, repeated with our notation.
All-++-⇔ : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ All P (xs ++ ys) ⇔ (All P xs × All P ys)
to (All-++-⇔ xs ys) = to' xs ys
where
to' : ∀ {A : Set} {P : A → Set} (xs ys : List A)
→ All P (xs ++ ys) → (All P xs × All P ys)
to' [] ys = λ All-P-ys → ⟨ [] , All-P-ys ⟩
to' (x ∷ xs) ys (Px ∷ All-P-xs++ys) with to' xs ys All-P-xs++ys
... | ⟨ All-P-xs , All-PP-ys ⟩ = ⟨ Px ∷ All-P-xs , All-PP-ys ⟩
from (All-++-⇔ xs ys) = from' xs ys
where
from' : ∀ { A : Set} {P : A → Set} (xs ys : List A)
→ All P xs × All P ys → All P (xs ++ ys)
from' [] ys = λ { ⟨ All-P-[] , All-P-ys ⟩ → All-P-ys }
from' (x ∷ xs) ys = λ { ⟨ Px ∷ All-P-xs , All-P-ys ⟩ → Px ∷ from' xs ys ⟨ All-P-xs , All-P-ys ⟩ }
-- PLFA exercise: state and prove Any-++-⇔
Any-++-⇔ : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ Any P (xs ++ ys) ⇔ (Any P xs ⊎ Any P ys)
to (Any-++-⇔ xs ys) = to' xs ys
where
to' : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ Any P (xs ++ ys)
→ (Any P xs ⊎ Any P ys)
to' [] ys = λ Any-P-ys → inj₂ Any-P-ys
to' (x ∷ xs) ys (here Px ) = inj₁ (here Px)
to' (x ∷ xs) ys (there Any-P-xs++ys) with to' xs ys Any-P-xs++ys
... | inj₁ Any-P-xs = inj₁ (there Any-P-xs)
... | inj₂ Any-P-ys = inj₂ Any-P-ys
from (Any-++-⇔ xs ys) = from' xs ys
where
from' : ∀ {A : Set} {P : A → Set}
→ (xs ys : List A)
→ (Any P xs ⊎ Any P ys)
→ Any P (xs ++ ys)
from' [] ys (inj₂ Any-P-ys) = Any-P-ys
from' (x ∷ xs) ys (inj₂ Any-P-ys) = there (from' xs ys (inj₂ Any-P-ys))
from' (x ∷ xs) ys (inj₁ (here Px)) = here Px
from' (x ∷ xs) ys (inj₁ (there Any-P-xs)) = there (from' xs ys (inj₁ Any-P-xs))
-- use Any-++-⇔ to demonstrate an equivalence relating ∈ and _++_ TODO
-- PLFA exercise: Show that the equivalence All-++-⇔ can be extended to an isomorphism.
-- PLFA exercise: Here is a universe-polymorphic version of composition,
-- and a version of DeMorgan's law for Any and All expressed using it.
_∘'_ : ∀ {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃}
→ (B → C) → (A → B) → A → C
(g ∘' f) x = g (f x)
¬Any≃All¬ : ∀ {A : Set} (P : A → Set) (xs : List A)
→ (¬_ ∘' Any P) xs ≃ All (¬_ ∘' P) xs
to (¬Any≃All¬ _ []) ¬_∘'AnyPxs = []
to (¬Any≃All¬ P (_ ∷ xs)) ¬_∘'AnyPxs with to (¬Any≃All¬ P xs)
... | AnyPxs→⊥→Allλx₁→Px₁→⊥xs
= (λ Px → ¬ here Px ∘'AnyPxs) ∷ AnyPxs→⊥→Allλx₁→Px₁→⊥xs (λ AnyPxs → ¬ there AnyPxs ∘'AnyPxs)
from (¬Any≃All¬ _ []) All¬_∘'Pxs ()
from (¬Any≃All¬ P (x ∷ xs)) All¬_∘'Pxs (here Px) with from (¬Any≃All¬ P xs)
... | All-λx₁→Px₁→⊥-xs→AnyPxs→⊥
= All-λx₁→Px₁→⊥-xs→AnyPxs→⊥ {!!} {!!}
from (¬Any≃All¬ _ (x ∷ xs)) All¬_∘'Pxs (there AnyPxs) = {!!}
from∘to (¬Any≃All¬ P xs) = {!!}
to∘from (¬Any≃All¬ P xs) = {!!}
{-
-- Can we prove the following? If not, explain why.
-- ¬All≃Any¬ : ∀ {A : Set} (P : A → Set) (xs : List A)
-- → (¬_ ∘' All P) xs ≃ Any (¬_ ∘' P) xs
-- End of PLFA exercise
-- Decidability of All
-- A Boolean analogue of All
all : ∀ {A : Set} → (A → Bool) → List A → Bool
all p = foldr _∧_ true ∘ map p
-- A Dec analogue of All
-- A definition of a predicate being decidable
Decidable : ∀ {A : Set} → (A → Set) → Set
Decidable {A} P = ∀ (x : A) → Dec (P x)
All? : ∀ {A : Set} {P : A → Set} → Decidable P → Decidable (All P)
All? P? [] = yes []
All? P? (x ∷ xs) with P? x | All? P? xs
All? P? (x ∷ xs) | yes p | yes p₁ = yes (p ∷ p₁)
All? P? (x ∷ xs) | yes p | no ¬p = no (λ { (x ∷ x₁) → ¬p x₁})
All? P? (x ∷ xs) | no ¬p | _ = no (λ { (x ∷ x₁) → ¬p x})
-- PLFA exercise: repeat above for Any
-- PLFA exercises: All-∀ and Any-∃
-- You will need the stronger version of extensionality
-- (for dependent function types) given in PLFA Isomorphism.
-- PLFA exercise: a version of 'filter' for decidable predicates
-- filter? : ∀ {A : Set} {P : A → Set}
-- → (P? : Decidable P) → List A → ∃[ ys ]( All P ys )
-- filter? P? xs = {!!}
-}
| {
"alphanum_fraction": 0.4997401125,
"avg_line_length": 34.9224422442,
"ext": "agda",
"hexsha": "50def15eb7b9ce4a8a4f5ba5182839ccf5895ea2",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x10-747Lists-hc.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x10-747Lists-hc.agda",
"max_line_length": 108,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x10-747Lists-hc.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 8272,
"size": 21163
} |
postulate
A : Set
P : A → Set
Q : ∀{a} → P a → Set
variable -- WORKS if replaced by postulate
a : A
module _ (p : P a) (let q = p) where
postulate r : Q q
-- Panic: unbound variable q (id: 18@787003719158301342)
-- when checking that the expression q has type P _a_12
| {
"alphanum_fraction": 0.6302816901,
"avg_line_length": 17.75,
"ext": "agda",
"hexsha": "ac3b923661510a1f66767023a533c13350b53175",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3470.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3470.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3470.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 104,
"size": 284
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Level
open import Relation.Unary using (Pred)
open import Data.Product hiding (swap; curry)
open import Data.List
open import Data.List.Relation.Unary.All as All
open import Data.List.Relation.Unary.Any
open import Data.List.Membership.Propositional
open import Data.List.Prefix
open import Function as Fun using (case_of_)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
import Experiments.Category as Cat
module Experiments.StrongMonad
(Type : Set)
(Val : Type → Cat.MP₀ (⊑-preorder {A = Type}))
(funext : ∀ {a b} → Extensionality a b) where
open import Relation.Binary.PropositionalEquality.Extensionality funext
open Cat (⊑-preorder {A = Type})
open Product
World = List Type
Store : World → Set
Store Σ = All (λ a → Val a · Σ) Σ
import Relation.Binary.HeterogeneousEquality as H
module HR = H.≅-Reasoning
mcong : ∀ {Σₛ Σ Σ' ℓ}{P : MP ℓ}
{μ : Store Σ}{μ' : Store Σ'}{p : Σ ⊒ Σₛ}{p' : Σ' ⊒ Σₛ}{q : P · Σ}{q' : P · Σ'} →
Σ ≡ Σ' → p H.≅ p' → μ H.≅ μ' → q H.≅ q' → (Σ , p , μ , q) ≡ (Σ' , p' , μ' , q')
mcong refl H.refl H.refl H.refl = refl
-- The monad takes monotone predicates over worlds
-- to monotone functions over stores in these worlds.
M : ∀ {ℓ} → MP ℓ → MP ℓ
M P = mp (λ Σ → ∀ Σ₁ → (ext : Σ ⊑ Σ₁) → (μ : Store Σ₁) → ∃ λ Σ₂ → Σ₂ ⊒ Σ₁ × Store Σ₂ × P · Σ₂)
record {
monotone = λ w₀ f Σ w₁ μ → f Σ (⊑-trans w₀ w₁) μ ;
monotone-refl = λ f → funext³ (λ Σ₁ _ μ → cong (λ u → f Σ₁ u μ) ⊑-trans-refl) ;
monotone-trans = λ f w₀ w₁ → funext³ (λ Σ₁ w₂ μ → cong (λ u → f Σ₁ u μ) (sym ⊑-trans-assoc))
}
-- η is the natural transformation between the identity functor and the functor M
η : ∀ {p}(P : MP p) → P ⇒ M P
η P =
mk⇒
(λ p Σ ext μ → Σ , ⊑-refl , μ , MP.monotone P ext p)
(λ c~c' {p} → begin
(λ z ext μ → z , ⊑-refl , μ , MP.monotone P ext (MP.monotone P c~c' p))
≡⟨ funext³ (λ z ext μ → cong (λ u → z , ⊑-refl , μ , u) (sym (MP.monotone-trans P p c~c' ext))) ⟩
(λ z ext μ → z , ⊑-refl , μ , MP.monotone P (⊑-trans c~c' ext) p)
≡⟨ refl ⟩
MP.monotone (M P) c~c' (λ z ext μ → z , ⊑-refl , μ , MP.monotone P ext p)
∎)
μ : ∀ {p}(P : MP p) → M (M P) ⇒ M P
μ P = mk⇒
(λ pc Σ₁ ext μ →
case pc Σ₁ ext μ of λ{
(Σ₂ , ext₁ , μ₁ , f) →
case f Σ₂ ⊑-refl μ₁ of λ{
(Σ₃ , ext₂ , μ₂ , v) → Σ₃ , ⊑-trans ext₁ ext₂ , μ₂ , v
}
})
(λ c~c' → refl)
fmap : ∀ {p q}{P : MP p}{Q : MP q} → (P ⇒ Q) → M P ⇒ M Q
fmap F = mk⇒
(λ x Σ₁ ext μ → case x Σ₁ ext μ of λ{
(Σ₂ , ext₁ , μ₁ , v) → Σ₂ , ext₁ , μ₁ , apply F v
})
(λ c~c' → refl)
bind : ∀ {p q}{P : MP p}(Q : MP q) → (P ⇒ M Q) → M P ⇒ M Q
bind Q F = μ Q ∘ fmap F
open Exponential (sym ⊑-trans-assoc) ⊑-trans-refl ⊑-trans-refl'
module Coherence where
-- We prove that η is the component of a natural transformation between the functors
-- 𝕀 and M where 𝕀 is the identity functor.
η-natural : ∀ {p q}(P : MP p)(Q : MP q)(F : P ⇒ Q) → η Q ∘ F ⇒≡ (fmap F) ∘ η P
η-natural P Q F p =
begin
apply (η Q ∘ F) p
≡⟨ refl ⟩
apply (η Q) (apply F p)
≡⟨ refl ⟩
(λ Σ ext μ → Σ , ⊑-refl , μ , MP.monotone Q ext (apply F p))
≡⟨ funext³ (λ Σ ext μ → cong (λ u → Σ , ⊑-refl , μ , u) (sym (monotone-comm F ext))) ⟩
(λ Σ ext μ → Σ , ⊑-refl , μ , apply F (MP.monotone P ext p))
≡⟨ refl ⟩
apply (fmap F) (λ Σ ext μ → Σ , ⊑-refl , μ , MP.monotone P ext p)
≡⟨ refl ⟩
apply (fmap F) (apply (η P) p)
≡⟨ refl ⟩
apply (fmap F ∘ η P) p
∎
-- We prove that μ is the component of a natural transformation between
-- the functors M² and M.
μ-natural : ∀ {p q}(P : MP p)(Q : MP q)(F : P ⇒ Q) → μ Q ∘ (fmap (fmap F)) ⇒≡ (fmap F) ∘ μ P
μ-natural P Q F = λ p → refl
-- from these facts we can prove the monad laws
left-id : ∀ {p}{P : MP p} → μ P ∘ fmap (η P) ⇒≡ id (M P)
left-id {P = P} p = funext³
λ Σ₁ ext μ₁ → mcong {P = P} refl (lem refl) H.refl (H.≡-to-≅ (MP.monotone-refl P _))
where
lem : ∀ {Σ Σ' Σ'' : World}{xs : Σ'' ⊒ Σ'}{ys : Σ'' ⊒ Σ} → Σ ≡ Σ' → ⊑-trans xs ⊑-refl H.≅ ys
lem {xs = xs}{ys} refl with ⊑-unique xs ys
... | refl = H.≡-to-≅ ⊑-trans-refl'
right-id : ∀ {p}{P : MP p} → μ P ∘ (η (M P)) ⇒≡ id (M P)
right-id {P = P} p = funext³ λ Σ₁ ext μ₁ →
let f = (λ{(Σ₃ , ext₂ , μ₂ , v) → Σ₃ , ⊑-trans ⊑-refl ext₂ , μ₂ , v}) in
trans
(cong f (cong (λ u → p Σ₁ u μ₁) ⊑-trans-refl'))
(mcong {P = P} refl (H.≡-to-≅ ⊑-trans-refl) H.refl H.refl )
-- if we have a (M³ P) then it doesn't matter if we join
-- the outer or inner ones first.
assoc : ∀ {p}{P : MP p} → μ P ∘ (fmap (μ P)) ⇒≡ μ P ∘ μ (M P)
assoc {P = P} p = funext³ λ Σ₁ ext μ → mcong {P = P} refl (H.≡-to-≅ ⊑-trans-assoc) H.refl H.refl
-- fmap makes M a functor
fmap-id : ∀ {ℓ}{P : MP ℓ} → fmap (id P) ⇒≡ id (M P)
fmap-id = λ p → refl
fmap-∘ : ∀ {ℓ₁ ℓ₂ ℓ₃}{P : MP ℓ₁}{Q : MP ℓ₂}{R : MP ℓ₃}(F : P ⇒ Q)(G : Q ⇒ R) →
fmap (G ∘ F) ⇒≡ fmap G ∘ fmap F
fmap-∘ F G = λ p → refl
module Strong where
-- tensorial strength
ts : ∀ {p q}(P : MP p)(Q : MP q) → P ⊗ M Q ⇒ M (P ⊗ Q)
ts P Q = mk⇒
(λ x Σ₁ ext μ →
case (proj₂ x) Σ₁ ext μ of λ{
(_ , ext₁ , μ₁ , v ) → _ , ext₁ , μ₁ , (MP.monotone P (⊑-trans ext ext₁) (proj₁ x)) , v
}
)
(λ c~c' →
funext³ λ Σ₁ ext μ₁ →
mcong {P = (P ⊗ Q)} refl H.refl H.refl (
H.cong₂ {A = P · _}{B = λ _ → Q · _} (λ u v → u , v)
(H.≡-to-≅ (begin
MP.monotone P (⊑-trans ext _) _
≡⟨ (MP.monotone-trans P _ _ _) ⟩
MP.monotone P _ (MP.monotone P ext (MP.monotone P c~c' _))
≡⟨ cong (λ x → MP.monotone P _ x) (sym ((MP.monotone-trans P _ _ _))) ⟩
MP.monotone P _ (MP.monotone P (⊑-trans c~c' ext) _)
≡⟨ sym ((MP.monotone-trans P _ _ _)) ⟩
MP.monotone P (⊑-trans (⊑-trans c~c' ext) _) _
∎))
H.refl
))
ts' : ∀ {p q}(P : MP p)(Q : MP q) → M P ⊗ Q ⇒ M (P ⊗ Q)
ts' P Q = fmap (swap Q P) ∘ ts Q P ∘ swap _ _
diagram₁ : ∀ {ℓ}{P : MP ℓ} → fmap {P = ⊤ ⊗ P} (π₂ {P = ⊤}) ∘ ts ⊤ P ⇒≡ π₂ {P = ⊤}
diagram₁ = λ p → refl
diagram₂ : ∀ {ℓ₁ ℓ₂ ℓ₃}{A : MP ℓ₁}{B : MP ℓ₂}{C : MP ℓ₃} →
fmap (comm A B C) ∘ ts (A ⊗ B) C ⇒≡ ts A (B ⊗ C) ∘ xmap (id A) (ts B C) ∘ comm A B (M C)
diagram₂ = λ p → refl
diagram₃ : ∀ {ℓ₁ ℓ₂}(A : MP ℓ₁)(B : MP ℓ₂) →
η (A ⊗ B) ⇒≡ ts A B ∘ xmap (id A) (η B)
diagram₃ A B (a , b) = funext³ λ Σ ext r → mcong {P = A ⊗ B} refl H.refl H.refl
(H.≡-to-≅
(cong₂ _,_
(cong₂
(λ ext a → MP.monotone A ext a)
(trans (sym ⊑-trans-refl') (cong (λ r → ⊑-trans ext r) refl))
refl
)
(cong (λ x → x) refl)))
diagram₄ : ∀ {ℓ₁ ℓ₂}{A : MP ℓ₁}{B : MP ℓ₂} →
ts A B ∘ xmap (id A) (μ B) ⇒≡ μ (A ⊗ B) ∘ fmap (ts A B) ∘ ts A (M B)
diagram₄ {A = A}{B} p@(l , r) =
funext³ λ Σ₁ ext μ' →
mcong {P = A ⊗ B} refl H.refl H.refl (
H.cong (Fun.flip _,_ _)
(H.≡-to-≅ (
trans
(cong (λ u → MP.monotone A u l) ⊑-trans-assoc)
(trans
(MP.monotone-trans A l (⊑-trans ext _) _)
(cong
(λ u → MP.monotone A u (MP.monotone A (⊑-trans _ _) l))
(sym ⊑-trans-refl))))))
-- internal fmap
fmap' : ∀ {p q}{P : MP p}{Q : MP q} → (Q ^ P) ⇒ (M Q) ^ (M P)
fmap' {P = P}{Q} = curry (fmap ε ∘ ts (Q ^ P) P)
-- internal bind
bind' : ∀ {p q}{P : MP p}(Q : MP q) → (M P ⊗ (M Q ^ P)) ⇒ M Q
bind' {P = P} Q =
μ Q
∘ fmap (ε ∘ swap P (M Q ^ P))
∘ ts' P (M Q ^ P)
| {
"alphanum_fraction": 0.4945914245,
"avg_line_length": 36.0234741784,
"ext": "agda",
"hexsha": "908c05d36e9cc7775baf00f01c60fdda01268e6c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/Experiments/StrongMonad.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/Experiments/StrongMonad.agda",
"max_line_length": 105,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/Experiments/StrongMonad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 3397,
"size": 7673
} |
{-# OPTIONS --allow-unsolved-metas #-}
module Issue242 where
postulate Y : Set
module Inner (X : Set) where
module M (A : Set) where
postulate R : Set
module R (r : R) where
postulate C : Set
open module MX = M Y
module M' (r : R) where
open module Rr = R r
c : C
c = {!!}
| {
"alphanum_fraction": 0.5705128205,
"avg_line_length": 14.8571428571,
"ext": "agda",
"hexsha": "3a9eb6fa82fb6426940de265b7e7aa903cb02445",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue242.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue242.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue242.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 102,
"size": 312
} |
{-# OPTIONS --sized-types #-}
module SizedTypesLoopDueInadmissibility where
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {size ^}
suc : {size : Size} -> Nat {size} -> Nat {size ^}
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A -> Maybe A
shift_case : {i : Size} -> Maybe (Nat {i ^}) -> Maybe (Nat {i})
shift_case nothing = nothing
shift_case (just zero) = nothing
shift_case (just (suc x)) = just x
shift : {i : Size} -> (Nat -> Maybe (Nat {i ^})) ->
(Nat -> Maybe (Nat {i}))
shift f n = shift_case (f (suc n))
inc : Nat -> Maybe Nat
inc n = just (suc n)
-- the type of the following recursive function should be rejected!!
-- it is inadmissible (see Abel, RAIRO 2004 or CSL 2006)
loop : {i : Size} -> Nat {i} -> (Nat -> Maybe (Nat {i})) -> Set
loop (suc n) f = loop n (shift f)
loop zero f with (f zero)
... | nothing = Nat
... | (just zero) = Nat
... | (just (suc y)) = loop y (shift f)
{-
mutual
loop : {i : Size} -> Nat {i} -> (Nat -> Maybe (Nat {i})) -> Set
loop .{i ^} (suc {i} n) f = loop {i} n (shift {i} f)
loop .{i ^} (zero {i}) f = loop_case {i ^} (f zero) f
loop_case : {i : Size} -> Maybe (Nat {i}) -> (Nat -> Maybe (Nat {i})) -> Set
loop_case nothing f = Nat
loop_case (just zero) f = Nat
loop_case (just (suc y)) f = loop y (shift f)
-}
diverge = loop zero inc
| {
"alphanum_fraction": 0.5589403974,
"avg_line_length": 26.4912280702,
"ext": "agda",
"hexsha": "4680235655e12c1a261d2299d3a0da813e07b6fc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/bugs/SizedTypesLoopDueInadmissibility.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/bugs/SizedTypesLoopDueInadmissibility.agda",
"max_line_length": 78,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/bugs/SizedTypesLoopDueInadmissibility.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 521,
"size": 1510
} |
------------------------------------------------------------------------
-- Some definitions related to and properties of booleans
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Bool
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (id; _∘_; swap)
open import Bijection eq as Bijection using (_↔_)
open Derived-definitions-and-properties eq
open import Equality.Decision-procedures eq
open import Equivalence eq using (_≃_; ↔⇒≃; lift-equality)
open import Function-universe eq
open import H-level eq
open import H-level.Closure eq
-- The not function is involutive.
not-involutive : (b : Bool) → not (not b) ≡ b
not-involutive true = refl _
not-involutive false = refl _
-- Bool is isomorphic to Fin 2.
Bool↔Fin2 : Bool ↔ Fin 2
Bool↔Fin2 =
⊤ ⊎ ⊤ ↝⟨ inverse $ id ⊎-cong ⊎-right-identity ⟩□
⊤ ⊎ ⊤ ⊎ ⊥ □
-- A non-trivial automorphism on Bool.
swap : Bool ↔ Bool
swap = record
{ surjection = record
{ logical-equivalence = record
{ to = not
; from = not
}
; right-inverse-of = not-involutive
}
; left-inverse-of = not-involutive
}
private
non-trivial : _↔_.to swap ≢ id
non-trivial not≡id = Bool.true≢false (cong (_$ false) not≡id)
-- Equality rearrangement lemmas.
not≡⇒≢ : (b₁ b₂ : Bool) → not b₁ ≡ b₂ → b₁ ≢ b₂
not≡⇒≢ true true f≡t _ = Bool.true≢false (sym f≡t)
not≡⇒≢ true false _ t≡f = Bool.true≢false t≡f
not≡⇒≢ false true _ f≡t = Bool.true≢false (sym f≡t)
not≡⇒≢ false false t≡f _ = Bool.true≢false t≡f
≢⇒not≡ : (b₁ b₂ : Bool) → b₁ ≢ b₂ → not b₁ ≡ b₂
≢⇒not≡ true true t≢t = ⊥-elim (t≢t (refl _))
≢⇒not≡ true false _ = refl _
≢⇒not≡ false true _ = refl _
≢⇒not≡ false false f≢f = ⊥-elim (f≢f (refl _))
not≡↔≡not : {b₁ b₂ : Bool} → not b₁ ≡ b₂ ↔ b₁ ≡ not b₂
not≡↔≡not {true} {true} =
false ≡ true ↝⟨ inverse $ Bijection.⊥↔uninhabited (Bool.true≢false ∘ sym) ⟩
⊥₀ ↝⟨ Bijection.⊥↔uninhabited Bool.true≢false ⟩□
true ≡ false □
not≡↔≡not {true} {false} =
false ≡ false ↝⟨ inverse Bijection.≡↔inj₂≡inj₂ ⟩
tt ≡ tt ↝⟨ Bijection.≡↔inj₁≡inj₁ ⟩□
true ≡ true □
not≡↔≡not {false} {true} =
true ≡ true ↝⟨ inverse Bijection.≡↔inj₁≡inj₁ ⟩
tt ≡ tt ↝⟨ Bijection.≡↔inj₂≡inj₂ ⟩□
false ≡ false □
not≡↔≡not {false} {false} =
true ≡ false ↝⟨ inverse $ Bijection.⊥↔uninhabited Bool.true≢false ⟩
⊥₀ ↝⟨ Bijection.⊥↔uninhabited (Bool.true≢false ∘ sym) ⟩□
false ≡ true □
-- Some lemmas related to T.
T↔≡true : {b : Bool} → T b ↔ b ≡ true
T↔≡true {false} = $⟨ Bool.true≢false ⟩
true ≢ false ↝⟨ (_∘ sym) ⟩
false ≢ true ↝⟨ Bijection.⊥↔uninhabited ⟩□
⊥ ↔ false ≡ true □
T↔≡true {true} = $⟨ refl true ⟩
true ≡ true ↝⟨ propositional⇒inhabited⇒contractible Bool-set ⟩
Contractible (true ≡ true) ↝⟨ _⇔_.to contractible⇔↔⊤ ⟩
true ≡ true ↔ ⊤ ↝⟨ inverse ⟩□
⊤ ↔ true ≡ true □
T-not↔≡false : ∀ {b} → T (not b) ↔ b ≡ false
T-not↔≡false {b} =
T (not b) ↝⟨ T↔≡true ⟩
not b ≡ true ↝⟨ not≡↔≡not ⟩□
b ≡ false □
T-not⇔¬T :
(b : Bool) → T (not b) ⇔ ¬ T b
T-not⇔¬T true =
⊥ ↔⟨ Bijection.⊥↔uninhabited (_$ _) ⟩
(⊤ → ⊥) □
T-not⇔¬T false =
⊤ ↝⟨ record { to = λ _ → id } ⟩□
¬ ⊥ □
T-not↔¬T : (b : Bool) → T (not b) ↝[ lzero ∣ lzero ] ¬ T b
T-not↔¬T true _ =
⊥ ↔⟨ Bijection.⊥↔uninhabited (_$ _) ⟩
(⊤ → ⊥) □
T-not↔¬T false ext =
⊤ ↝⟨ inverse-ext? ¬⊥↔⊤ ext ⟩□
¬ ⊥ □
¬T⇔≡false : ∀ {b} → ¬ T b ⇔ b ≡ false
¬T⇔≡false {b} =
¬ T b ↝⟨ inverse $ T-not⇔¬T b ⟩
T (not b) ↔⟨ T-not↔≡false ⟩□
b ≡ false □
¬T↔≡false : ∀ {b} → ¬ T b ↝[ lzero ∣ lzero ] b ≡ false
¬T↔≡false {b = b} ext =
¬ T b ↝⟨ inverse-ext? (T-not↔¬T b) ext ⟩
T (not b) ↔⟨ T-not↔≡false ⟩□
b ≡ false □
T-∧↔T×T : ∀ b₁ {b₂} → T (b₁ ∧ b₂) ↔ T b₁ × T b₂
T-∧↔T×T true {b₂} =
T b₂ ↝⟨ inverse ×-left-identity ⟩□
⊤ × T b₂ □
T-∧↔T×T false {b₂} =
⊥ ↝⟨ inverse ×-left-zero ⟩□
⊥ × T b₂ □
T-∨⇔T⊎T : ∀ b₁ {b₂} → T (b₁ ∨ b₂) ⇔ T b₁ ⊎ T b₂
T-∨⇔T⊎T true = record { to = inj₁ }
T-∨⇔T⊎T false {b₂} =
T b₂ ↔⟨ inverse ⊎-left-identity ⟩□
⊥ ⊎ T b₂ □
-- Bool ≃ Bool is isomorphic to Bool (assuming extensionality).
[Bool≃Bool]↔Bool₁ : Extensionality lzero lzero →
(Bool ≃ Bool) ↔ Bool
[Bool≃Bool]↔Bool₁ ext = record
{ surjection = record
{ logical-equivalence = record
{ to = λ eq → _≃_.to eq true
; from = if_then id else ↔⇒≃ swap
}
; right-inverse-of = λ { true → refl _; false → refl _ }
}
; left-inverse-of = λ eq →
lift-equality ext (apply-ext ext (lemma₂ eq))
}
where
lemma₁ : ∀ b → _≃_.to (if b then id else ↔⇒≃ swap) false ≡ not b
lemma₁ true = refl _
lemma₁ false = refl _
lemma₂ : ∀ eq b →
_≃_.to (if _≃_.to eq true then id else ↔⇒≃ swap) b ≡
_≃_.to eq b
lemma₂ eq true with _≃_.to eq true
... | true = refl _
... | false = refl _
lemma₂ eq false =
_≃_.to (if _≃_.to eq true then id else ↔⇒≃ swap) false ≡⟨ lemma₁ (_≃_.to eq true) ⟩
not (_≃_.to eq true) ≡⟨ ≢⇒not≡ _ _ (Bool.true≢false ∘ _≃_.injective eq) ⟩∎
_≃_.to eq false ∎
-- Another proof showing that Bool ≃ Bool is isomorphic to Bool
-- (assuming extensionality).
[Bool≃Bool]↔Bool₂ : Extensionality lzero lzero →
(Bool ≃ Bool) ↔ Bool
[Bool≃Bool]↔Bool₂ ext = record
{ surjection = record
{ logical-equivalence = record
{ to = λ eq → _≃_.to eq false
; from = if_then ↔⇒≃ swap else id
}
; right-inverse-of = λ { true → refl _; false → refl _ }
}
; left-inverse-of = λ eq →
lift-equality ext (apply-ext ext (lemma₂ eq))
}
where
lemma₁ : ∀ b → _≃_.to (if b then ↔⇒≃ swap else id) true ≡ not b
lemma₁ true = refl _
lemma₁ false = refl _
lemma₂ : ∀ eq b →
_≃_.to (if _≃_.to eq false then ↔⇒≃ swap else id) b ≡
_≃_.to eq b
lemma₂ eq false with _≃_.to eq false
... | true = refl _
... | false = refl _
lemma₂ eq true =
_≃_.to (if _≃_.to eq false then ↔⇒≃ swap else id) true ≡⟨ lemma₁ (_≃_.to eq false) ⟩
not (_≃_.to eq false) ≡⟨ ≢⇒not≡ _ _ (Bool.true≢false ∘ sym ∘ _≃_.injective eq) ⟩∎
_≃_.to eq true ∎
private
-- The two proofs are not equal.
distinct : {ext : Extensionality lzero lzero} →
[Bool≃Bool]↔Bool₁ ext ≢ [Bool≃Bool]↔Bool₂ ext
distinct =
Bool.true≢false ∘ cong (λ iso → _≃_.to (_↔_.from iso true) true)
| {
"alphanum_fraction": 0.5249076127,
"avg_line_length": 30.75,
"ext": "agda",
"hexsha": "90b41573a25bb4787ad985d03986f8dbfa3b89f1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Bool.agda",
"max_line_length": 119,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 2903,
"size": 6765
} |
postulate
A : Set
open import Agda.Builtin.Equality
foo : (f : A → A → A) (@0 g : @0 A → @0 A → A)
→ @0 _≡_ {A = @0 A → @0 A → A} g (\ x y → f y x)
→ @0 A → @0 A → A
foo f g refl = g
-- In the goal, `C-c C-n g` gives
-- λ (@0 x) (@0 y) → f y x
-- which is only well-typed in an erased context.
bad : (f : A → A → A) → @0 A → @0 A → A
bad f = foo f (\ x y → f y x) refl
| {
"alphanum_fraction": 0.4601542416,
"avg_line_length": 22.8823529412,
"ext": "agda",
"hexsha": "1f13280b1d61cd6b1fe95c9d9ff63eb2df957e19",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue4986a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4986a.agda",
"max_line_length": 52,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4986a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 172,
"size": 389
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Sum.Base where
open import Cubical.Core.Everything
private
variable
ℓ ℓ' : Level
A B C D : Type ℓ
data _⊎_ (A : Type ℓ)(B : Type ℓ') : Type (ℓ-max ℓ ℓ') where
inl : A → A ⊎ B
inr : B → A ⊎ B
elim-⊎ : {C : A ⊎ B → Type ℓ} → ((a : A) → C (inl a)) → ((b : B) → C (inr b))
→ (x : A ⊎ B) → C x
elim-⊎ f _ (inl x) = f x
elim-⊎ _ g (inr y) = g y
map-⊎ : (A → C) → (B → D) → A ⊎ B → C ⊎ D
map-⊎ f _ (inl x) = inl (f x)
map-⊎ _ g (inr y) = inr (g y)
| {
"alphanum_fraction": 0.4760076775,
"avg_line_length": 22.652173913,
"ext": "agda",
"hexsha": "1d1f25799c68247df75d6352405790149776c4df",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/Sum/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/Sum/Base.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/Sum/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 261,
"size": 521
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Sn.Properties where
open import Cubical.Data.Int hiding (_+_)
open import Cubical.Data.Bool
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.HITs.S1
open import Cubical.HITs.S3
open import Cubical.Data.Nat
open import Cubical.Data.Prod
open import Cubical.HITs.Sn.Base
open import Cubical.HITs.Susp
open import Cubical.Data.Unit
open import Cubical.HITs.Join
open import Cubical.HITs.Pushout
open import Cubical.HITs.SmashProduct
open import Cubical.HITs.PropositionalTruncation
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : Type ℓ'
--- Some silly lemmas on S1 ---
isGroupoidS1 : isGroupoid (S₊ 1)
isGroupoidS1 = isGroupoidS¹
isConnectedS1 : (x : S₊ 1) → ∥ base ≡ x ∥
isConnectedS1 = isConnectedS¹
| {
"alphanum_fraction": 0.7949167397,
"avg_line_length": 27.1666666667,
"ext": "agda",
"hexsha": "98964ffa71616d54ef6fd319950fb209a5dfefd7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "69d358f6be7842f77105634712821eda22d9c044",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "aljungstrom/cubical",
"max_forks_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/cubical",
"max_issues_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/cubical",
"max_stars_repo_path": "Cubical/HITs/Sn/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 341,
"size": 1141
} |
{-# OPTIONS --cubical --safe #-}
module _ where
open import Agda.Primitive
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Glue
open import Agda.Builtin.Bool
-- If primGlue does not reduce away we should report an error for
-- patterns of other types.
--
-- In the future we might want to allow the constructor glue itself as
-- a pattern.
test : ∀ φ → primGlue {ℓ' = lzero} Bool {φ = φ} ? ? → Bool
test _ true = ?
test _ false = ?
| {
"alphanum_fraction": 0.7076923077,
"avg_line_length": 25.2777777778,
"ext": "agda",
"hexsha": "748be73f810a52f322df5990a6546663ddfe543e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue3620.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue3620.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue3620.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 130,
"size": 455
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Values for caching evaluation of MTerm
------------------------------------------------------------------------
import Parametric.Syntax.Type as Type
import Parametric.Syntax.MType as MType
import Parametric.Denotation.Value as Value
import Parametric.Denotation.MValue as MValue
module Parametric.Denotation.CachingMValue
(Base : Type.Structure)
(⟦_⟧Base : Value.Structure Base)
where
open import Base.Data.DependentList
open import Base.Denotation.Notation
open Type.Structure Base
open MType.Structure Base
open Value.Structure Base ⟦_⟧Base
open MValue.Structure Base ⟦_⟧Base
open import Data.Product hiding (map)
open import Data.Sum hiding (map)
open import Data.Unit
open import Level
open import Function hiding (const)
Structure : Set
Structure = Base → Type
module Structure (ΔBase : Structure) where
{-# TERMINATING #-}
⟦_⟧ValTypeHidCache : (τ : ValType) → Set
⟦_⟧CompTypeHidCache : (τ : CompType) → Set
⟦ U c ⟧ValTypeHidCache = ⟦ c ⟧CompTypeHidCache
⟦ B ι ⟧ValTypeHidCache = ⟦ base ι ⟧
⟦ vUnit ⟧ValTypeHidCache = ⊤
⟦ τ₁ v× τ₂ ⟧ValTypeHidCache = ⟦ τ₁ ⟧ValTypeHidCache × ⟦ τ₂ ⟧ValTypeHidCache
⟦ τ₁ v+ τ₂ ⟧ValTypeHidCache = ⟦ τ₁ ⟧ValTypeHidCache ⊎ ⟦ τ₂ ⟧ValTypeHidCache
--
-- XXX The termination checker isn't happy with it, and it may be right ─ if
-- you keep substituting τ₁ = U (F τ), you can make the cache arbitrarily big.
-- I think we don't do that unless we are caching a non-terminating
-- computation to begin with, but I'm not entirely sure.
--
-- However, the termination checker can't prove that the function is
-- terminating because it's not structurally recursive, but one call of the
-- function will produce another call of the function stuck on a neutral term:
-- So the computation will have terminated, just in an unusual way!
--
-- Anyway, I need not mechanize this part of the proof for my goals.
--
-- XXX: This line is the only change, up to now, for the caching semantics,
-- the rest is copied. Inheritance would handle this precisely; without
-- inheritance, we might want to use one of the standard encodings of related
-- features (delegation?).
⟦ F τ ⟧CompTypeHidCache = (Σ[ τ₁ ∈ ValType ] ⟦ τ ⟧ValTypeHidCache × ⟦ τ₁ ⟧ValTypeHidCache )
⟦ σ ⇛ τ ⟧CompTypeHidCache = ⟦ σ ⟧ValTypeHidCache → ⟦ τ ⟧CompTypeHidCache
⟦_⟧ValCtxHidCache : (Γ : ValContext) → Set
⟦_⟧ValCtxHidCache = DependentList ⟦_⟧ValTypeHidCache
{-# TERMINATING #-}
⟦_⟧ΔValType : ValType → Set
⟦_⟧ΔCompType : CompType → Set
⟦_⟧ΔCompType (F τ) = Σ[ τ₁ ∈ ValType ] (⟦ τ₁ ⟧ValTypeHidCache → ⟦ τ ⟧ΔValType × ⟦ τ₁ ⟧ValTypeHidCache)
⟦_⟧ΔCompType (σ ⇛ τ) = ⟦ σ ⟧ΔValType → ⟦ τ ⟧ΔCompType
⟦_⟧ΔValType (U c) = ⟦ c ⟧ΔCompType
⟦_⟧ΔValType (B ι) = ⟦ ΔBase ι ⟧
⟦_⟧ΔValType vUnit = ⊤
⟦_⟧ΔValType (τ₁ v× τ₂) = ⟦_⟧ΔValType τ₁ × ⟦_⟧ΔValType τ₂
⟦_⟧ΔValType (τ₁ v+ τ₂) = (⟦_⟧ΔValType τ₁ ⊎ ⟦_⟧ΔValType τ₂) ⊎ (⟦ τ₁ ⟧ ⊎ ⟦ τ₂ ⟧)
open import Data.Product
open import Level
-- -- Needed to allow storing functions in cache:
-- record _↝_↝_ {a b} (S : Set a) c (T : Set b) : Set (a ⊔ b ⊔ suc c) where
-- field
-- cache : Set c
-- fun : S → (T × cache)
-- record _↝′_↝′_ {a b} (dS : Set a) c (dT : Set b) : Set (a ⊔ b ⊔ suc c) where
-- field
-- cache : Set c
-- fun : dS → cache → (dT × cache)
-- -- -- For simplicity, but won't work:
-- --
-- -- record _↝_ {a b} (S : Set a) (T : Set b) : Set (a ⊔ b ⊔ suc zero) where
-- -- field
-- -- cache : Set
-- -- fun : S → (T × cache)
-- -- record _↝′_ (da : Set₁) (db : Set₁) : Set₁ where
-- -- field
-- -- cache : Set
-- -- dfun : da → cache → (db × cache)
-- fooo : (a b : Set₁) → Set₁
-- fooo a b = a ↝ zero ↝ (b ↝ zero ↝ b)
-- dfooo : (da db : Set₁) → Set₁
-- dfooo da db = da ↝′ zero ↝′ (db ↝′ zero ↝′ db)
-- Since caches can contain caches, including function caches, we can't use the
-- above. The existentials must store object-language codes of some sort. For
-- extra fun, the resulting code is not typeable with simple types, so we can't
-- use codes for simple types but must store, say, function bodies.
| {
"alphanum_fraction": 0.6353643967,
"avg_line_length": 36.3913043478,
"ext": "agda",
"hexsha": "0818c82cbc200b8f3a257790edc63740a955339e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Parametric/Denotation/CachingMValue.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Parametric/Denotation/CachingMValue.agda",
"max_line_length": 104,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Parametric/Denotation/CachingMValue.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 1489,
"size": 4185
} |
open import Relation.Binary.Core
module PLRTree.Insert.Properties {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.Sum
open import PLRTree {A}
open import PLRTree.Compound {A}
open import PLRTree.Insert _≤_ tot≤
lemma-insert-compound : (x : A)(t : PLRTree) → Compound (insert x t)
lemma-insert-compound x leaf = compound
lemma-insert-compound x (node perfect y l r)
with tot≤ x y | l | r
... | inj₁ x≤y | leaf | leaf = compound
... | inj₁ x≤y | leaf | node _ _ _ _ = compound
... | inj₁ x≤y | node _ _ _ _ | leaf = compound
... | inj₁ x≤y | node _ _ _ _ | node _ _ _ _ = compound
... | inj₂ y≤x | leaf | leaf = compound
... | inj₂ y≤x | leaf | node _ _ _ _ = compound
... | inj₂ y≤x | node _ _ _ _ | leaf = compound
... | inj₂ y≤x | node _ _ _ _ | node _ _ _ _ = compound
lemma-insert-compound x (node left y l _)
with tot≤ x y
... | inj₁ x≤y
with insert y l | lemma-insert-compound y l
... | node perfect _ _ _ | compound = compound
... | node left _ _ _ | compound = compound
... | node right _ _ _ | compound = compound
lemma-insert-compound x (node left y l _) | inj₂ y≤x
with insert x l | lemma-insert-compound x l
... | node perfect _ _ _ | compound = compound
... | node left _ _ _ | compound = compound
... | node right _ _ _ | compound = compound
lemma-insert-compound x (node right y _ r)
with tot≤ x y
... | inj₁ x≤y
with insert y r | lemma-insert-compound y r
... | node perfect _ _ _ | compound = compound
... | node left _ _ _ | compound = compound
... | node right _ _ _ | compound = compound
lemma-insert-compound x (node right y _ r) | inj₂ y≤x
with insert x r | lemma-insert-compound x r
... | node perfect _ _ _ | compound = compound
... | node left _ _ _ | compound = compound
... | node right _ _ _ | compound = compound
| {
"alphanum_fraction": 0.6153017241,
"avg_line_length": 37.8775510204,
"ext": "agda",
"hexsha": "7899a02677972d28bfb6846d1d1c137edfe8f275",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/PLRTree/Insert/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/PLRTree/Insert/Properties.agda",
"max_line_length": 68,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/PLRTree/Insert/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 585,
"size": 1856
} |
-- Placeholder
| {
"alphanum_fraction": 0.7333333333,
"avg_line_length": 7.5,
"ext": "agda",
"hexsha": "285876d3dc8b889feb680848d7132454d82d7543",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/FileThatDoesNotExist.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/FileThatDoesNotExist.agda",
"max_line_length": 14,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/FileThatDoesNotExist.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 3,
"size": 15
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Homotopy.WedgeConnectivity where
open import Cubical.Foundations.Everything
open import Cubical.Data.HomotopyGroup
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.HITs.Nullification
open import Cubical.HITs.Susp
open import Cubical.HITs.Truncation as Trunc
open import Cubical.Homotopy.Connected
module WedgeConnectivity {ℓ ℓ' ℓ''} (n m : ℕ)
(A : Pointed ℓ) (connA : isConnected (suc n) (typ A))
(B : Pointed ℓ') (connB : isConnected (suc m) (typ B))
(P : typ A → typ B → TypeOfHLevel ℓ'' (n + m))
(f : (a : typ A) → P a (pt B) .fst)
(g : (b : typ B) → P (pt A) b .fst)
(p : f (pt A) ≡ g (pt B))
where
private
Q : typ A → TypeOfHLevel _ n
Q a =
( (Σ[ k ∈ ((b : typ B) → P a b .fst) ] k (pt B) ≡ f a)
, isOfHLevelRetract n
(λ {(h , q) → h , funExt λ _ → q})
(λ {(h , q) → h , funExt⁻ q _})
(λ _ → refl)
(isOfHLevelPrecomposeConnected n m (P a) (λ _ → pt B)
(isConnectedPoint m connB (pt B)) (λ _ → f a))
)
main : isContr (fiber (λ s _ → s (pt A)) (λ _ → g , p ⁻¹))
main =
elim.isEquivPrecompose (λ _ → pt A) n Q
(isConnectedPoint n connA (pt A))
.equiv-proof (λ _ → g , p ⁻¹)
extension : ∀ a b → P a b .fst
extension a b = main .fst .fst a .fst b
left : ∀ a → extension a (pt B) ≡ f a
left a = main .fst .fst a .snd
right : ∀ b → extension (pt A) b ≡ g b
right = funExt⁻ (cong fst (funExt⁻ (main .fst .snd) _))
-- TODO: left (pt A) ⁻¹ ∙ right (pt B) ≡ p
| {
"alphanum_fraction": 0.56875,
"avg_line_length": 31.3725490196,
"ext": "agda",
"hexsha": "a39faec633900c6f4ea475f0c81df6db48dd2d0f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Homotopy/WedgeConnectivity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Homotopy/WedgeConnectivity.agda",
"max_line_length": 63,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Homotopy/WedgeConnectivity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 605,
"size": 1600
} |
{-# OPTIONS --without-K #-}
-- most of this is subsumed by crypto-agda Search code
open import Type hiding (★)
open import Data.Nat.NP hiding (_==_) renaming (_<=_ to _ℕ<=_)
open import Data.Bits
open import Data.Bit hiding (_==_)
open import Data.Bool.Properties using (not-involutive)
import Data.Vec.NP as V
open V hiding (rewire; rewireTbl; sum) renaming (map to vmap; swap to vswap)
import Relation.Binary.PropositionalEquality.NP as ≡
open ≡
open import Function.NP hiding (_→⟨_⟩_)
open import Algebra.FunctionProperties.NP
module Data.Bits.Search where
module Search {i} {I : ★ i} (`1 : I) (`2*_ : I → I)
{a} {A : I → ★ a} (_∙_ : ∀ {m} → A m → A m → A (`2* m)) where
`2^_ : ℕ → I
`2^_ = fold `1 `2*_
search : ∀ {n} → (Bits n → A `1) → A (`2^ n)
search {zero} f = f []
search {suc n} f = search (f ∘ 0∷_) ∙ search (f ∘ 1∷_)
searchBit : (Bit → A `1) → A (`2* `1)
searchBit f = f 0b ∙ f 1b
-- search-ext
search-≗ : ∀ {n} (f g : Bits n → A `1) → f ≗ g → search f ≡ search g
search-≗ {zero} f g f≗g = f≗g []
search-≗ {suc n} f g f≗g
rewrite search-≗ (f ∘ 0∷_) (g ∘ 0∷_) (f≗g ∘ 0∷_)
| search-≗ (f ∘ 1∷_) (g ∘ 1∷_) (f≗g ∘ 1∷_) = refl
module Comm (∙-comm : ∀ {m} (x y : A m) → x ∙ y ≡ y ∙ x) where
{- This pad bit vector allows to specify which bit do we negate in the vector. -}
search-comm : ∀ {n} (pad : Bits n) (f : Bits n → A `1) → search f ≡ search (f ∘ _⊕_ pad)
search-comm {zero} pad f = refl
search-comm {suc n} (b ∷ pad) f
rewrite search-comm pad (f ∘ 0∷_)
| search-comm pad (f ∘ 1∷_)
with b
... | true = ∙-comm (search (f ∘ 0∷_ ∘ _⊕_ pad)) _
... | false = refl
open Comm public
module SimpleSearch {a} {A : ★ a} (_∙_ : A → A → A) where
open Search 1 2*_ {A = const A} _∙_ public
module SearchUnit ε (ε∙ε : ε ∙ ε ≡ ε) where
search-constε≡ε : ∀ n → search {n = n} (const ε) ≡ ε
search-constε≡ε zero = refl
search-constε≡ε (suc n) rewrite search-constε≡ε n = ε∙ε
searchBit-search : ∀ n (f : Bits (suc n) → A) → searchBit (λ b → search (f ∘ _∷_ b)) ≡ search f
searchBit-search n f = refl
search-≗₂ : ∀ {m n} (f g : Bits m → Bits n → A) → f ≗₂ g
→ search (search ∘ f) ≡ search (search ∘ g)
search-≗₂ f g f≗g = search-≗ (search ∘ f) (search ∘ g) (λ xs →
search-≗ (f xs) (g xs) (λ ys →
f≗g xs ys))
search-+ : ∀ {m n} (f : Bits (m + n) → A) →
search {m + n} f
≡ search {m} (λ xs → search {n} (λ ys → f (xs ++ ys)))
search-+ {zero} f = refl
search-+ {suc m} f rewrite search-+ {m} (f ∘ 0∷_)
| search-+ {m} (f ∘ 1∷_) = refl
module SearchInterchange (∙-interchange : Interchange _≡_ _∙_ _∙_) where
search-dist : ∀ {n} (f₀ f₁ : Bits n → A) → search (λ x → f₀ x ∙ f₁ x) ≡ search f₀ ∙ search f₁
search-dist {zero} _ _ = refl
search-dist {suc n} f₀ f₁
rewrite search-dist (f₀ ∘ 0∷_) (f₁ ∘ 0∷_)
| search-dist (f₀ ∘ 1∷_) (f₁ ∘ 1∷_)
= ∙-interchange _ _ _ _
search-searchBit : ∀ {n} (f : Bits (suc n) → A) →
search (λ xs → searchBit (λ b → f (b ∷ xs))) ≡ search f
search-searchBit f = search-dist (f ∘ 0∷_) (f ∘ 1∷_)
search-search : ∀ {m n} (f : Bits (m + n) → A) →
search {m} (λ xs → search {n} (λ ys → f (xs ++ ys)))
≡ search {n} (λ ys → search {m} (λ xs → f (xs ++ ys)))
search-search {zero} f = refl
search-search {suc m} {n} f
rewrite search-search {m} {n} (f ∘ 0∷_)
| search-search {m} {n} (f ∘ 1∷_)
| search-searchBit {n} (λ { (b ∷ ys) → search {m} (λ xs → f (b ∷ xs ++ ys)) })
= refl
{- -- It might also be done by using search-dist twice and commutativity of addition.
-- However, this also affect 'f' and makes this proof actually longer.
search-search {m} {n} f =
search {m} (λ xs → search {n} (λ ys → f (xs ++ ys)))
≡⟨ {!!} ⟩
search {m + n} f
≡⟨ {!!} ⟩
search {n + m} (f ∘ vswap n)
≡⟨ {!!} ⟩
search {n} (λ ys → search {m} (λ xs → f (vswap n (ys ++ xs))))
≡⟨ {!!} ⟩
search {n} (λ ys → search {m} (λ xs → f (xs ++ ys)))
∎
where open ≡-Reasoning
-}
search-swap : ∀ {m n} (f : Bits (m + n) → A) → search {n + m} (f ∘ vswap n) ≡ search {m + n} f
search-swap {m} {n} f =
search {n + m} (f ∘ vswap n)
≡⟨ search-+ {n} {m} (f ∘ vswap n) ⟩
search {n} (λ ys → search {m} (λ xs → f (vswap n (ys ++ xs))))
≡⟨ search-≗₂ {n} {m}
(λ ys → f ∘ vswap n ∘ _++_ ys)
(λ ys → f ∘ flip _++_ ys)
(λ ys xs → cong f (swap-++ n ys xs)) ⟩
search {n} (λ ys → search {m} (λ xs → f (xs ++ ys)))
≡⟨ sym (search-search {m} {n} f) ⟩
search {m} (λ xs → search {n} (λ ys → f (xs ++ ys)))
≡⟨ sym (search-+ {m} {n} f) ⟩
search {m + n} f
∎ where open ≡-Reasoning
search-0↔1 : ∀ {n} (f : Bits n → A) → search {n} (f ∘ 0↔1) ≡ search {n} f
search-0↔1 {zero} _ = refl
search-0↔1 {suc zero} _ = refl
search-0↔1 {suc (suc n)} _ = ∙-interchange _ _ _ _
module Bij (∙-comm : Commutative _≡_ _∙_)
(∙-interchange : Interchange _≡_ _∙_ _∙_) where
open SearchInterchange ∙-interchange using (search-0↔1)
open import Data.Bits.OperationSyntax hiding (_∙_)
search-bij : ∀ {n} f (g : Bits n → A) → search (g ∘ eval f) ≡ search g
search-bij `id _ = refl
search-bij `0↔1 f = search-0↔1 f
search-bij (f `⁏ g) h
rewrite search-bij f (h ∘ eval g)
| search-bij g h
= refl
search-bij {suc n} (`id `∷ f) g
rewrite search-bij (f 0b) (g ∘ 0∷_)
| search-bij (f 1b) (g ∘ 1∷_)
= refl
search-bij {suc n} (`notᴮ `∷ f) g
rewrite search-bij (f 1b) (g ∘ 0∷_)
| search-bij (f 0b) (g ∘ 1∷_)
= ∙-comm _ _
|de-morgan| : ∀ {n} (f g : Bits n → Bit) → f |∨| g ≗ not ∘ ((not ∘ f) |∧| (not ∘ g))
|de-morgan| f g x with f x
... | true = refl
... | false = sym (not-involutive _)
open SimpleSearch
search-de-morgan : ∀ {n} op (f g : Bits n → Bit) →
search op (f |∨| g) ≡ search op (not ∘ ((not ∘ f) |∧| (not ∘ g)))
search-de-morgan op f g = search-≗ op _ _ (|de-morgan| f g)
search-hom :
∀ {n a b}
{A : ★ a} {B : ★ b}
(_+_ : A → A → A)
(_*_ : B → B → B)
(f : A → B)
(p : Bits n → A)
(hom : ∀ x y → f (x + y) ≡ f x * f y)
→ f (search _+_ p) ≡ search _*_ (f ∘ p)
search-hom {zero} _ _ _ _ _ = refl
search-hom {suc n} _+_ _*_ f p hom =
trans (hom _ _)
(cong₂ _*_ (search-hom _+_ _*_ f (p ∘ 0∷_) hom)
(search-hom _+_ _*_ f (p ∘ 1∷_) hom))
| {
"alphanum_fraction": 0.4413347686,
"avg_line_length": 41.5195530726,
"ext": "agda",
"hexsha": "58f3c2e23f8be82de847c8c2fb750f777f33f1d3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Experimental/DataBitsSearch.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Experimental/DataBitsSearch.agda",
"max_line_length": 102,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Experimental/DataBitsSearch.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 2756,
"size": 7432
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Category.Functor
open import Data.Maybe
open import Function
open import Level
open import Relation.Binary.PropositionalEquality
module Optics.Functorial where
Lens' : (F : Set → Set) → RawFunctor F → Set → Set → Set
Lens' F _ S A = (A → F A) → S → F S
data Lens (S A : Set) : Set₁ where
lens : ((F : Set → Set)(rf : RawFunctor F) → Lens' F rf S A)
→ Lens S A
private
cf : {A : Set} → RawFunctor {Level.zero} (const A)
cf = record { _<$>_ = λ x x₁ → x₁ }
if : RawFunctor {Level.zero} id
if = record { _<$>_ = λ x x₁ → x x₁ }
-- We can make lenses relatively painlessly without requiring reflection
-- by providing getter and setter functions
mkLens' : ∀ {A B : Set}
→ (B → A)
→ (B → A → B)
→ Lens B A
mkLens' {A} {B} get set =
lens (λ F rf f b → Category.Functor.RawFunctor._<$>_
{F = F} rf
{A = A}
{B = B}
(set b)
(f (get b)))
-- Getter:
-- this is typed as ^\.
_^∙_ : ∀{S A} → S → Lens S A → A
_^∙_ {_} {A} s (lens p) = p (const A) cf id s
-- Setter:
set : ∀{S A} → Lens S A → A → S → S
set (lens p) a s = p id if (const a) s
infixr 4 _∙~_
_∙~_ = set
-- _|>_ is renamed to _&_ by Util.Prelude
set? : ∀{S A} → Lens S (Maybe A) → A → S → S
set? l a s = s |> l ∙~ just a
infixr 4 _?~_
_?~_ = set?
-- Modifier:
over : ∀{S A} → Lens S A → (A → A) → S → S
over (lens p) f s = p id if f s
infixr 4 _%~_
_%~_ = over
-- Composition
infixr 30 _∙_
_∙_ : ∀{S A B} → Lens S A → Lens A B → Lens S B
(lens p) ∙ (lens q) = lens (λ F rf x x₁ → p F rf (q F rf x) x₁)
-- Relation between the same field of two states This most general form allows us to specify a
-- Lens S A, a function A → B, and a relation between two B's, and holds iff the relation holds
-- between the values yielded by applying the Lens to two S's and then applying the function to
-- the results; more specific variants are provided below
_[_]L_f=_at_ : ∀ {ℓ} {S A B : Set} → S → (B → B → Set ℓ) → S → (A → B) → Lens S A → Set ℓ
s₁ [ _~_ ]L s₂ f= f at l = f (s₁ ^∙ l) ~ f (s₂ ^∙ l)
_[_]L_at_ : ∀ {ℓ} {S A} → S → (A → A → Set ℓ) → S → Lens S A → Set ℓ
s₁ [ _~_ ]L s₂ at l = _[_]L_f=_at_ s₁ _~_ s₂ id l
infix 4 _≡L_f=_at_
_≡L_f=_at_ : ∀ {S A B : Set} → (s₁ s₂ : S) → (A → B) → Lens S A → Set
s₁ ≡L s₂ f= f at l = _[_]L_f=_at_ s₁ _≡_ s₂ f l
infix 4 _≡L_at_
_≡L_at_ : ∀ {S A} → (s₁ s₂ : S) → Lens S A → Set
s₁ ≡L s₂ at l = _[_]L_f=_at_ s₁ _≡_ s₂ id l
| {
"alphanum_fraction": 0.5400770039,
"avg_line_length": 30.7204301075,
"ext": "agda",
"hexsha": "1948d78d3d75ef95a7e58544b7f29f14f73ea431",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/Optics/Functorial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/Optics/Functorial.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/Optics/Functorial.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1096,
"size": 2857
} |
-- Andreas, 2015-05-28
open import Common.Size
fix : ∀ {C : Size → Set} → (∀ i → (∀ (j : Size< i) → C j) → C i) → ∀ i → C i
fix t i = t i λ (j : Size< i) → fix t j
-- Expected error:
-- Possibly empty type of sizes (Size< i)
-- when checking that the expression λ (j : Size< i) → fix t j has
-- type (j : Size< i) → .C j
| {
"alphanum_fraction": 0.5462962963,
"avg_line_length": 29.4545454545,
"ext": "agda",
"hexsha": "08402b9ab9d8e94c8780237d5c18057a0bdff4c3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1523c.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1523c.agda",
"max_line_length": 76,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1523c.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 124,
"size": 324
} |
module Main where
open import Category.Functor
open import Category.Monad
open import Data.Unit
open import Data.Container.Indexed
open import Data.Maybe
open import Data.Product
open import IO.Primitive hiding (_>>=_)
open import Signature
open import Sodium
open import Model
open import View
------------------------------------------------------------------------
postulate
eEvent : Event VtyEvent
bMode : Behaviour Mode
eCommand : Event (∃ (Command Hårss))
eCommand = filterJust (snapshot (λ v m → forget (vtyToCmd v m))
eEvent bMode)
where
forget : ∀ {m} → Maybe (Command Hårss m) → Maybe (∃ (Command Hårss))
forget nothing = nothing
forget (just c) = just (_ , c)
eResponse : Event (∃₂ λ m (c : Command Hårss m) → Response Hårss c)
eResponse = executeAsyncIO (snapshot
(λ c m → fmap (forget c) (cmdToResp (proj₂ c) m)) eCommand bModel)
where
forget : (c : ∃ (Command Hårss)) → Response Hårss (proj₂ c) →
∃₂ λ m (c : Command Hårss m) → Response Hårss c
forget (m , c) r = m , (c , r)
postulate
fmap : ∀ {A B} → (A → B) → IO A → IO B
bModel : Behaviour Model
bModel : Reactive (Behaviour Model)
bModel = accum initialModel (update <$> eResponse)
where
open RawFunctor eventFunctor
update : (∃₂ λ m (c : Command Hårss m) →
(Response Hårss c)) → Model → Model
update (._ , moveP d , _) m = moveModel d m
update (._ , promptP p , _) m = setMode (input p) m
update (._ , putCharP c , _) m = addCharToBuffer c m
update (._ , doneP , (s , search)) m = searchModel s m
update (._ , doneP , (s , addFeed)) m = addFeedToModel s m
update (._ , fetchP , f) m = setCurrentFeed m f
update (._ , searchNextP , s) m = searchNextModel s m
setup : Reactive (IO ⊤)
setup =
bModel >>= λ m →
listen (updates m) view
where
open RawMonad reactiveMonad
| {
"alphanum_fraction": 0.6067297581,
"avg_line_length": 30.1904761905,
"ext": "agda",
"hexsha": "ab176f2c009040f14b175e22511e89669b1e2211",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "stevana/haarss",
"max_forks_repo_path": "prototype/command-response/Main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "stevana/haarss",
"max_issues_repo_path": "prototype/command-response/Main.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "stevana/haarss",
"max_stars_repo_path": "prototype/command-response/Main.agda",
"max_stars_repo_stars_event_max_datetime": "2015-07-30T11:43:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T11:43:26.000Z",
"num_tokens": 578,
"size": 1902
} |
{-# OPTIONS --without-K --safe #-}
module Data.Binary.Operations.Multiplication where
open import Data.Binary.Definitions
open import Data.Binary.Operations.Addition
mul : 𝔹⁺ → 𝔹⁺ → 𝔹⁺
mul 1ᵇ ys = ys
mul (O ∷ xs) ys = O ∷ (mul xs ys)
mul (I ∷ xs) ys = add O (O ∷ mul ys xs) ys
_*_ : 𝔹 → 𝔹 → 𝔹
0ᵇ * ys = 0ᵇ
(0< _) * 0ᵇ = 0ᵇ
(0< xs) * (0< ys) = 0< mul xs ys
{-# INLINE _*_ #-}
| {
"alphanum_fraction": 0.5921052632,
"avg_line_length": 21.1111111111,
"ext": "agda",
"hexsha": "f554b8e2d2d517c35e2b6276853292bac2b162c1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Binary/Operations/Multiplication.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-binary",
"max_issues_repo_path": "Data/Binary/Operations/Multiplication.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Binary/Operations/Multiplication.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 173,
"size": 380
} |
{-# OPTIONS --without-K #-}
open import Base
module Homotopy.Cover.Def {i} (A : Set i) where
record covering : Set (suc i) where
constructor cov[_,_]
field
fiber : A → Set i
fiber-is-set : ∀ a → is-set (fiber a)
open import Homotopy.Truncation
open import Homotopy.Connected
open import Homotopy.PathTruncation
-- In terms of connectedness
is-universal : covering → Set i
is-universal cov[ fiber , _ ] = is-connected ⟨1⟩ $ Σ A fiber
-- In terms of connectedness
universal-covering : Set (suc i)
universal-covering = Σ covering is-universal
tracing : ∀ cov → let open covering cov in
∀ {a₁ a₂} → fiber a₁ → a₁ ≡₀ a₂ → fiber a₂
tracing cov[ fiber , fiber-is-set ] y =
π₀-extend-nondep
⦃ fiber-is-set _ ⦄
(λ p → transport fiber p y)
compose-tracing : ∀ cov → let open covering cov in
∀ {a₁ a₂ a₃} y (p₁ : a₁ ≡₀ a₂) (p₂ : a₂ ≡₀ a₃)
→ tracing cov (tracing cov y p₁) p₂ ≡ tracing cov y (p₁ ∘₀ p₂)
compose-tracing cov y = let open covering cov in
π₀-extend
⦃ λ _ → Π-is-set λ _ → ≡-is-set $ fiber-is-set _ ⦄
(λ p₁ → π₀-extend
⦃ λ _ → ≡-is-set $ fiber-is-set _ ⦄
(λ p₂ → compose-trans fiber p₂ p₁ y))
covering-eq : ∀ {co₁ co₂ : covering}
→ covering.fiber co₁ ≡ covering.fiber co₂
→ co₁ ≡ co₂
covering-eq {cov[ _ , set₁ ]} {cov[ ._ , set₂ ]} refl =
ap (λ set → cov[ _ , set ])
(prop-has-all-paths (Π-is-prop λ _ → is-set-is-prop) _ _)
| {
"alphanum_fraction": 0.6336917563,
"avg_line_length": 29.0625,
"ext": "agda",
"hexsha": "77d582ee4ee9fb0e0b43cf096c2e8f3b38ffca48",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Homotopy/Cover/Def.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Homotopy/Cover/Def.agda",
"max_line_length": 64,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Homotopy/Cover/Def.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 508,
"size": 1395
} |
{-# OPTIONS --prop --without-K --rewriting #-}
open import Calf.CostMonoid
module Calf.Types.Eq where
open import Calf.Prelude
open import Calf.Metalanguage
open import Calf.PhaseDistinction
open import Relation.Binary.PropositionalEquality
postulate
eq : (A : tp pos) → val A → val A → tp pos
eq/intro : ∀ {A v1 v2} → v1 ≡ v2 → val (eq A v1 v2)
eq/ref : ∀ {A v1 v2} → cmp (F (eq A v1 v2)) → v1 ≡ v2
eq/uni : ∀ {A v1 v2} → (p q : cmp (F (eq A v1 v2))) →
(u : ext) → p ≡ q
| {
"alphanum_fraction": 0.6257668712,
"avg_line_length": 25.7368421053,
"ext": "agda",
"hexsha": "00f151124c520308389a14234e4177bd79ebecc2",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/Types/Eq.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/Types/Eq.agda",
"max_line_length": 55,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/Types/Eq.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 188,
"size": 489
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Primality
------------------------------------------------------------------------
module Data.Nat.Primality where
open import Data.Empty
open import Data.Fin as Fin hiding (_+_)
open import Data.Fin.Dec
open import Data.Nat
open import Data.Nat.Divisibility
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Nullary.Negation
open import Relation.Unary
-- Definition of primality.
Prime : ℕ → Set
Prime 0 = ⊥
Prime 1 = ⊥
Prime (suc (suc n)) = (i : Fin n) → ¬ (2 + Fin.toℕ i ∣ 2 + n)
-- Decision procedure for primality.
prime? : Decidable Prime
prime? 0 = no λ()
prime? 1 = no λ()
prime? (suc (suc n)) = all? λ _ → ¬? (_ ∣? _)
private
-- Example: 2 is prime.
2-is-prime : Prime 2
2-is-prime = from-yes (prime? 2)
| {
"alphanum_fraction": 0.5406283857,
"avg_line_length": 23.6666666667,
"ext": "agda",
"hexsha": "b632f9e8e76422b5349c5fa28b2b25bb79bf1b3f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Nat/Primality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Nat/Primality.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Nat/Primality.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 247,
"size": 923
} |
module Rev {A : Set} where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; sym; trans; cong; cong₂; _≢_)
open Eq.≡-Reasoning
open import Data.Empty using (⊥; ⊥-elim)
open import Data.List
using (List; []; _∷_; _++_; map; foldr; replicate; length; _∷ʳ_)
-- renaming (reverse to rev)
open import Data.List.Properties
using (++-assoc; ++-identityʳ)
-- renaming (unfold-reverse to revʳ;
-- reverse-++-commute to rev-++;
-- reverse-involutive to rev-inv)
open import Data.List.All using (All; []; _∷_)
open import Data.List.All.Properties
renaming (++⁺ to _++All_)
pattern [_] x = x ∷ []
pattern [_,_] x y = x ∷ y ∷ []
pattern [_,_,_] x y z = x ∷ y ∷ z ∷ []
pattern [_,_,_,_] x y z w = x ∷ y ∷ z ∷ w ∷ []
rev : List A → List A
rev [] = []
rev (x ∷ xs) = rev xs ++ [ x ]
rev-++ : ∀ xs ys → rev (xs ++ ys) ≡ rev ys ++ rev xs
rev-++ [] ys =
begin
rev ([] ++ ys)
≡⟨ sym (++-identityʳ (rev ys)) ⟩
rev ys ++ rev []
∎
rev-++ (x ∷ xs) ys =
begin
rev (x ∷ xs ++ ys)
≡⟨⟩
rev (xs ++ ys) ++ [ x ]
≡⟨ cong (_++ [ x ]) (rev-++ xs ys) ⟩
(rev ys ++ rev xs) ++ [ x ]
≡⟨ ++-assoc (rev ys) (rev xs) [ x ] ⟩
rev ys ++ (rev xs ++ [ x ])
≡⟨⟩
rev ys ++ (rev (x ∷ xs))
∎
rev-inv : ∀ xs → rev (rev xs) ≡ xs
rev-inv [] =
begin
rev (rev [])
≡⟨⟩
[]
∎
rev-inv (x ∷ xs) =
begin
rev (rev (x ∷ xs))
≡⟨⟩
rev (rev xs ++ [ x ])
≡⟨ rev-++ (rev xs) [ x ] ⟩
rev [ x ] ++ rev (rev xs)
≡⟨ cong (rev [ x ] ++_) (rev-inv xs) ⟩
rev [ x ] ++ xs
≡⟨⟩
x ∷ xs
∎
revAll : ∀ (P : A → Set) → ∀ {xs} → All P xs → All P (rev xs)
revAll P [] = []
revAll P (Px ∷ Pxs) = revAll P Pxs ++All [ Px ]
| {
"alphanum_fraction": 0.4795152914,
"avg_line_length": 24.0694444444,
"ext": "agda",
"hexsha": "88889804fd26968edf5fceff5868ce9007391d8f",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "manikdv/plfa.github.io",
"max_forks_repo_path": "extra/extra/Rev.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "manikdv/plfa.github.io",
"max_issues_repo_path": "extra/extra/Rev.agda",
"max_line_length": 66,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "manikdv/plfa.github.io",
"max_stars_repo_path": "extra/extra/Rev.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 701,
"size": 1733
} |
-- Andreas, 2021-04-10, issue #5288
-- De Bruijn index problem in treeless compiler
-- {-# OPTIONS -v tc.cc:20 #-}
-- {-# OPTIONS -v treeless:40 #-}
-- {-# OPTIONS -v treeless.convert.lambdas:40 #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.IO
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
f : Nat → Nat → Nat
f _ zero = 0
f m = λ _ → m -- this catch-all was wrongly compiled
postulate
printNat : Nat → IO ⊤
{-# COMPILE GHC printNat = print #-}
{-# COMPILE JS printNat = function (x) { return function(cb) { process.stdout.write(x + "\n"); cb(0); }; } #-}
test : Nat
test = f 123 1
prf : test ≡ 123
prf = refl
main = printNat test
-- Should print 123
| {
"alphanum_fraction": 0.6457142857,
"avg_line_length": 21.875,
"ext": "agda",
"hexsha": "644d697b11bc261a542d85fe8317b438a1d1298a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue5288.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue5288.agda",
"max_line_length": 111,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue5288.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 224,
"size": 700
} |
-- Andreas, 2012-09-17
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.with.type:15 -v syntax.reify.con:30 #-}
module ReifyConstructorParametersForWith where
import Common.Level
module M {i} {I : Set i} where
data D : Set i where
c : {i : I} → D -- danger of confusion for c {i = ...}
data P : D → Set i where
p : {x : I} → P (c {x})
Pc : (x : I) → Set i
Pc x = P (c {x})
works : ∀ (x : I) → Pc x → Pc x
works x y with Set
... | _ = y
module N (x : I) where
bla : Pc x → Pc x
bla y with Set
... | _ = y
open M
test : ∀ {i}{I : Set i}(x : I) → Pc x → Pc x
test x y with Set
... | _ = y
-- If reification does not reify constructor parameters
-- for generating the with type, it confuses constructor
-- parameter {i} with constructor argument {i}.
| {
"alphanum_fraction": 0.5669586984,
"avg_line_length": 21.0263157895,
"ext": "agda",
"hexsha": "0a6d315a0a4301fdf6b6f14549930c546b9d1799",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/ReifyConstructorParametersForWith.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/ReifyConstructorParametersForWith.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/ReifyConstructorParametersForWith.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 275,
"size": 799
} |
module slots.defs where
open import slots.imports
record config
: Set where
field
n : ℕ -- reel count
m : ℕ -- fruit count
Win/Bet = ℕ -- win per 1 bet
Fruit = Fin m
ReelNo = Fin n
Reel = List Fruit
Reels = Vec Reel n
WinLine = Vec Win/Bet n
WinTable = Vec WinLine m
Line = Vec Fruit n
record game (cfg : config) : Set where
open config cfg
field
reels : Reels
winTable : WinTable
| {
"alphanum_fraction": 0.6355140187,
"avg_line_length": 15.2857142857,
"ext": "agda",
"hexsha": "842463ca071065199bfe2aed7b6ec6bce3ab9169",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "86d777ade14f63032c46bd168b76ac60d6bdf9b9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/slots-agda",
"max_forks_repo_path": "src/slots/defs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86d777ade14f63032c46bd168b76ac60d6bdf9b9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "semenov-vladyslav/slots-agda",
"max_issues_repo_path": "src/slots/defs.agda",
"max_line_length": 38,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "86d777ade14f63032c46bd168b76ac60d6bdf9b9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/slots-agda",
"max_stars_repo_path": "src/slots/defs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 140,
"size": 428
} |
{-# OPTIONS --without-K #-}
open import HoTT
module cohomology.WithCoefficients where
→Ω-group-structure : ∀ {i j} (X : Ptd i) (Y : Ptd j)
→ GroupStructure (fst (X ⊙→ ⊙Ω Y))
→Ω-group-structure X Y = record {
ident = ((λ _ → idp) , idp);
inv = λ F → ((! ∘ fst F) , ap ! (snd F));
comp = λ F G →
((λ x → fst F x ∙ fst G x), ap2 _∙_ (snd F) (snd G));
unitl = λ G → pair= idp (ap2-idp-l _∙_ {x = idp} (snd G) ∙ ap-idf (snd G));
unitr = λ F → ⊙λ=
(∙-unit-r ∘ fst F)
(ap2-idp-r _∙_ (snd F) ∙ unitr-lemma (snd F));
assoc = λ F G H → ⊙λ=
(λ x → ∙-assoc (fst F x) (fst G x) (fst H x))
(! (∙-unit-r _) ∙ assoc-lemma (snd F) (snd G) (snd H));
invl = λ F → ⊙λ=
(!-inv-l ∘ fst F)
(invl-lemma (snd F) ∙ ! (∙-unit-r _));
invr = λ F → ⊙λ=
(!-inv-r ∘ fst F)
(invr-lemma (snd F) ∙ ! (∙-unit-r _))}
where
unitr-lemma : ∀ {i} {A : Type i} {x : A} {p : x == x} (α : p == idp)
→ ap (λ r → r ∙ idp) α == ∙-unit-r p ∙ α
unitr-lemma idp = idp
assoc-lemma : ∀ {i} {A : Type i} {w x y z : A}
{p₁ p₂ : w == x} {q₁ q₂ : x == y} {r₁ r₂ : y == z}
(α : p₁ == p₂) (β : q₁ == q₂) (γ : r₁ == r₂)
→ ap2 _∙_ (ap2 _∙_ α β) γ ∙ ∙-assoc p₂ q₂ r₂ ==
∙-assoc p₁ q₁ r₁ ∙ ap2 _∙_ α (ap2 _∙_ β γ)
assoc-lemma idp idp idp = ! (∙-unit-r _)
invl-lemma : ∀ {i} {A : Type i} {x : A} {p : x == x} (α : p == idp)
→ ap2 _∙_ (ap ! α) α == !-inv-l p
invl-lemma idp = idp
invr-lemma : ∀ {i} {A : Type i} {x : A} {p : x == x} (α : p == idp)
→ ap2 _∙_ α (ap ! α) == !-inv-r p
invr-lemma idp = idp
→Ω-Group : ∀ {i j} (X : Ptd i) (Y : Ptd j) → Group (lmax i j)
→Ω-Group X Y = Trunc-Group (→Ω-group-structure X Y)
{- Pointed maps out of bool -}
Bool⊙→-out : ∀ {i} {X : Ptd i}
→ fst (⊙Lift {j = i} ⊙Bool ⊙→ X) → fst X
Bool⊙→-out (h , _) = h (lift false)
Bool⊙→-equiv : ∀ {i} (X : Ptd i)
→ fst (⊙Lift {j = i} ⊙Bool ⊙→ X) ≃ fst X
Bool⊙→-equiv {i} X = equiv Bool⊙→-out g f-g g-f
where
g : fst X → fst (⊙Lift {j = i} ⊙Bool ⊙→ X)
g x = ((λ {(lift b) → if b then snd X else x}) , idp)
f-g : ∀ x → Bool⊙→-out (g x) == x
f-g x = idp
g-f : ∀ H → g (Bool⊙→-out H) == H
g-f (h , hpt) = pair=
(λ= lemma)
(↓-app=cst-in $
idp
=⟨ ! (!-inv-l hpt) ⟩
! hpt ∙ hpt
=⟨ ! (app=-β lemma (lift true)) |in-ctx (λ w → w ∙ hpt) ⟩
app= (λ= lemma) (lift true) ∙ hpt ∎)
where lemma : ∀ b → fst (g (h (lift false))) b == h b
lemma (lift true) = ! hpt
lemma (lift false) = idp
abstract
Bool⊙→-path : ∀ {i} (X : Ptd i)
→ fst (⊙Lift {j = i} ⊙Bool ⊙→ X) == fst X
Bool⊙→-path X = ua (Bool⊙→-equiv X)
abstract
Bool⊙→Ω-is-π₁ : ∀ {i} (X : Ptd i)
→ →Ω-Group (⊙Lift {j = i} ⊙Bool) X == π 1 (ℕ-S≠O _) X
Bool⊙→Ω-is-π₁ {i} X =
group-ua
(record {
f = Trunc-fmap Bool⊙→-out;
pres-comp = Trunc-elim {i = i}
(λ _ → Π-level {j = i} (λ _ → =-preserves-level _ Trunc-level))
(λ g₁ → Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ g₂ → idp))} ,
is-equiv-Trunc ⟨0⟩ _ (snd (Bool⊙→-equiv (⊙Ω X))))
| {
"alphanum_fraction": 0.4582253886,
"avg_line_length": 31.5102040816,
"ext": "agda",
"hexsha": "759324856fd8fdb1b2d54d3efa86192012e615ab",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "cohomology/WithCoefficients.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "danbornside/HoTT-Agda",
"max_issues_repo_path": "cohomology/WithCoefficients.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "cohomology/WithCoefficients.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1471,
"size": 3088
} |
postulate P : Set -> Set
test : (B : Set) -> P B -> P B
test = λ p p -> {!!}
postulate A : Set
test₂ : Set → A
test₂ A = {!!}
| {
"alphanum_fraction": 0.488372093,
"avg_line_length": 12.9,
"ext": "agda",
"hexsha": "1f82707069322162fa205ec8ce1d12ddd06ef114",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue572.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue572.agda",
"max_line_length": 30,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue572.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 49,
"size": 129
} |
module Haskell.RangedSetsProp.BoundariesProperties where
open import Haskell.RangedSetsProp.library
open import Agda.Builtin.Equality
open import Agda.Builtin.Bool
open import Haskell.Prim
open import Haskell.Prim.Ord
open import Haskell.Prim.Bool
open import Haskell.Prim.Maybe
open import Haskell.Prim.Enum
open import Haskell.Prim.Eq
open import Haskell.Prim.List
open import Haskell.Prim.Integer
open import Haskell.Prim.Double
open import Haskell.RangedSets.Boundaries
prop_no_boundary_smaller : {{ o : Ord a }} -> {{ dio : DiscreteOrdered a}} -> (r1 : Boundary a) -> (r1 < BoundaryBelowAll) ≡ false
prop_no_boundary_smaller BoundaryBelowAll = refl
prop_no_boundary_smaller BoundaryAboveAll = refl
prop_no_boundary_smaller (BoundaryAbove x) = refl
prop_no_boundary_smaller (BoundaryBelow x) = refl
prop_no_boundary_greater : {{ o : Ord a }} -> {{ dio : DiscreteOrdered a}} -> (r1 : Boundary a) -> (r1 > BoundaryAboveAll) ≡ false
prop_no_boundary_greater BoundaryBelowAll = refl
prop_no_boundary_greater BoundaryAboveAll = refl
prop_no_boundary_greater (BoundaryAbove x) = refl
prop_no_boundary_greater (BoundaryBelow x) = refl
BoundaryBelowAllSmaller : ⦃ o : Ord a ⦄ → ⦃ dio : DiscreteOrdered a ⦄ → (b : Boundary a)
→ (BoundaryBelowAll <= b) ≡ true
BoundaryBelowAllSmaller BoundaryBelowAll = refl
BoundaryBelowAllSmaller BoundaryAboveAll = refl
BoundaryBelowAllSmaller (BoundaryBelow _) = refl
BoundaryBelowAllSmaller (BoundaryAbove _) = refl
postulate
prop_max_sym : {{ o : Ord a }} -> {{ dio : DiscreteOrdered a}} -> (r1 : Boundary a) -> (r2 : Boundary a) -> max r1 r2 ≡ max r2 r1
prop_min_sym : {{ o : Ord a }} -> {{ dio : DiscreteOrdered a}} -> (r1 : Boundary a) -> (r2 : Boundary a) -> min r1 r2 ≡ min r2 r1
-- prop_max_sym : {{ o : Ord a }} -> {{ dio : DiscreteOrdered a}} -> (r1 : Boundary a) -> (r2 : Boundary a) -> max r1 r2 ≡ max r2 r1
-- prop_max_sym {{o}} {{dio}} r1 r2 =
-- begin
-- max r1 r2
-- =⟨⟩
-- if (compare x y == GT) then x else y
-- =⟨⟩
-- if (compare y x == GT) then y else x
-- =⟨⟩
-- max r2 r1
-- end | {
"alphanum_fraction": 0.6888160973,
"avg_line_length": 40.320754717,
"ext": "agda",
"hexsha": "6a478321edff0c17049862a3e85cc412b73e6419",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ioanasv/agda2hs",
"max_forks_repo_path": "lib/Haskell/RangedSetsProp/BoundariesProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ioanasv/agda2hs",
"max_issues_repo_path": "lib/Haskell/RangedSetsProp/BoundariesProperties.agda",
"max_line_length": 133,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ioanasv/agda2hs",
"max_stars_repo_path": "lib/Haskell/RangedSetsProp/BoundariesProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:41:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:41:34.000Z",
"num_tokens": 628,
"size": 2137
} |
{- Type class for natural transformations. -}
module CategoryTheory.NatTrans where
open import CategoryTheory.Categories
open import CategoryTheory.Functor
open import Relation.Binary using (IsEquivalence)
infixr 25 _⟹_
-- Natural transformation between two functors
record _⟹_ {n} {ℂ 𝔻 : Category n} (F : Functor ℂ 𝔻) (G : Functor ℂ 𝔻) : Set (lsuc n) where
private module ℂ = Category ℂ
private module 𝔻 = Category 𝔻
private module F = Functor F
private module G = Functor G
field
-- || Definitions
-- One component of the natural transformations.
at : ∀(A : ℂ.obj) -> (F.omap A) 𝔻.~> (G.omap A)
-- || Laws
-- Naturality condition
nat-cond : ∀{A B : ℂ.obj} {f : A ℂ.~> B}
-> (G.fmap f 𝔻.∘ at A) 𝔻.≈ (at B 𝔻.∘ F.fmap f)
-- Identity natural transformation
ιd : ∀ {n} {ℂ 𝔻 : Category n} -> (F : Functor ℂ 𝔻) -> F ⟹ F
ιd {n} {ℂ} {𝔻} F = record
{ at = λ A -> F.fmap ℂ.id
; nat-cond = λ {A} {B} {f} ->
begin
F.fmap f ∘ F.fmap ℂ.id
≈⟨ ≈-cong-right (F.fmap-id) ⟩
F.fmap f ∘ id
≈⟨ id-comm ⟩
id ∘ F.fmap f
≈⟨ ≈-cong-left (F.fmap-id [sym]) ⟩
F.fmap ℂ.id ∘ F.fmap f
∎
}
where
private module F = Functor F
private module ℂ = Category ℂ
open Category 𝔻
-- Vertical composition of natural transformations
_⊚_ : ∀ {n} {ℂ 𝔻 : Category n} -> {F G H : Functor ℂ 𝔻}
-> (G ⟹ H) -> (F ⟹ G) -> (F ⟹ H)
_⊚_ {n} {ℂ} {𝔻} {F} {G} {H} φ ψ = record
{ at = λ A -> (φ.at A) ∘ (ψ.at A)
; nat-cond = λ {A} {B} {f} ->
begin
H.fmap f ∘ (φ.at A ∘ ψ.at A)
≈⟨ ∘-assoc [sym] ⟩
(H.fmap f ∘ φ.at A) ∘ ψ.at A
≈⟨ ≈-cong-left (φ.nat-cond) ≈> ∘-assoc ⟩
φ.at B ∘ (G.fmap f ∘ ψ.at A)
≈⟨ ≈-cong-right (ψ.nat-cond) ≈> (∘-assoc [sym])⟩
(φ.at B ∘ ψ.at B) ∘ F.fmap f
∎
}
where
open Category 𝔻
private module F = Functor F
private module G = Functor G
private module H = Functor H
private module φ = _⟹_ φ
private module ψ = _⟹_ ψ
open import Relation.Binary using (IsEquivalence)
-- Horizontal composition of natural tranformations
_✦_ : ∀ {n} {ℂ 𝔻 𝔼 : Category n} {F F′ : Functor ℂ 𝔻} {G G′ : Functor 𝔻 𝔼}
-> (G ⟹ G′) -> (F ⟹ F′) -> (G ◯ F ⟹ G′ ◯ F′)
_✦_ {n} {ℂ} {𝔻} {𝔼} {F} {F′} {G} {G′} ψ φ = record
{ at = λ A → G′.fmap (φ.at A) ∘ ψ.at (F.omap A)
; nat-cond = λ {A} {B} {f} →
begin
Functor.fmap (G′ ◯ F′) f ∘ (G′.fmap (φ.at A) ∘ ψ.at (F.omap A))
≈⟨ ∘-assoc [sym] ≈> ≈-cong-left (G′.fmap-∘ [sym]) ⟩
G′.fmap (F′.fmap f 𝔻.∘ φ.at A) ∘ ψ.at (F.omap A)
≈⟨ ≈-cong-left (G′.fmap-cong (φ.nat-cond)) ⟩
G′.fmap (φ.at B 𝔻.∘ F.fmap f) ∘ ψ.at (F.omap A)
≈⟨ ≈-cong-left (G′.fmap-∘) ≈> ∘-assoc ⟩
G′.fmap (φ.at B) ∘ (Functor.fmap (G′ ◯ F) f ∘ ψ.at (F.omap A))
≈⟨ ≈-cong-right (ψ.nat-cond) ≈> ∘-assoc [sym] ⟩
(G′.fmap (φ.at B) ∘ ψ.at (F.omap B)) ∘ Functor.fmap (G ◯ F) f
∎
}
where
private module 𝔻 = Category 𝔻
open Category 𝔼
private module F = Functor F
private module G = Functor G
private module F′ = Functor F′
private module G′ = Functor G′
private module φ = _⟹_ φ
private module ψ = _⟹_ ψ
-- Natural isomorphism between two functors
record _⟺_ {n} {ℂ 𝔻 : Category n} (F : Functor ℂ 𝔻) (G : Functor ℂ 𝔻) : Set (lsuc n) where
private module ℂ = Category ℂ
private module 𝔻 = Category 𝔻
private module F = Functor F
private module G = Functor G
field
-- || Definitions
-- NT from F to G
to : F ⟹ G
-- NT from G to F
from : G ⟹ F
private module to = _⟹_ to
private module from = _⟹_ from
field
-- || Isomorphism laws
iso1 : ∀{A : ℂ.obj} -> (from.at A) 𝔻.∘ (to.at A) 𝔻.≈ 𝔻.id
iso2 : ∀{A : ℂ.obj} -> (to.at A) 𝔻.∘ (from.at A) 𝔻.≈ 𝔻.id
-- Natural isomorphism is an equivalence
⟺-equiv : ∀ {n} {ℂ 𝔻 : Category n} -> IsEquivalence (_⟺_ {n} {ℂ} {𝔻})
⟺-equiv {n} {ℂ} {𝔻} = record
{ refl = λ {F} -> record
{ to = ιd F
; from = ιd F
; iso1 = λ {A} -> refl-iso-proof {A} {F}
; iso2 = λ {A} -> refl-iso-proof {A} {F} }
; sym = λ {F} {G} F⟺G -> record
{ to = _⟺_.from F⟺G
; from = _⟺_.to F⟺G
; iso1 = _⟺_.iso2 F⟺G
; iso2 = _⟺_.iso1 F⟺G }
; trans = λ {F} {G} {H} F⟺G G⟺H -> record
{ to = (_⟺_.to G⟺H) ⊚ (_⟺_.to F⟺G)
; from = (_⟺_.from F⟺G) ⊚ (_⟺_.from G⟺H)
; iso1 = λ {A} →
begin
at (from F⟺G ⊚ from G⟺H) A ∘ at (to G⟺H ⊚ to F⟺G) A
≈⟨ ∘-assoc [sym] ≈> ≈-cong-left (∘-assoc) ⟩
(at (from F⟺G) A ∘ (at (from G⟺H) A ∘ at (to G⟺H) A)) ∘ at (to F⟺G) A
≈⟨ ≈-cong-left (≈-cong-right (iso1 G⟺H)) ⟩
(at (from F⟺G) A ∘ id) ∘ at (to F⟺G) A
≈⟨ ≈-cong-left (id-right) ⟩
at (from F⟺G) A ∘ at (to F⟺G) A
≈⟨ iso1 F⟺G ⟩
id
∎
; iso2 = λ {A} →
begin
at (to G⟺H ⊚ to F⟺G) A ∘ at (from F⟺G ⊚ from G⟺H) A
≈⟨ (∘-assoc [sym]) ≈> ≈-cong-left (∘-assoc) ⟩
(at (to G⟺H) A ∘ (at (to F⟺G) A ∘ at (from F⟺G) A)) ∘ at (from G⟺H) A
≈⟨ ≈-cong-left (≈-cong-right (iso2 F⟺G)) ⟩
(at (to G⟺H) A ∘ id) ∘ at (from G⟺H) A
≈⟨ ≈-cong-left (id-right) ⟩
at (to G⟺H) A ∘ at (from G⟺H) A
≈⟨ iso2 G⟺H ⟩
id
∎
}
}
where
private module ℂ = Category ℂ
open Category 𝔻
open _⟹_
open _⟺_
refl-iso-proof : {A : ℂ.obj} {F : Functor ℂ 𝔻}
-> _⟹_.at (ιd F) A ∘ _⟹_.at (ιd F) A ≈ id
refl-iso-proof {A} {F} =
begin
_⟹_.at (ιd F) A ∘ _⟹_.at (ιd F) A
≈⟨ ≈-cong-left (Functor.fmap-id F) ⟩
id ∘ _⟹_.at (ιd F) A
≈⟨ ≈-cong-right (Functor.fmap-id F) ⟩
id ∘ id
≈⟨ id-left ⟩
id
∎
| {
"alphanum_fraction": 0.444778006,
"avg_line_length": 34.7747252747,
"ext": "agda",
"hexsha": "b5ff5a4f1a6b1b3b55a0c729a2285043dc959943",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/CategoryTheory/NatTrans.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/CategoryTheory/NatTrans.agda",
"max_line_length": 91,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/CategoryTheory/NatTrans.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 2662,
"size": 6329
} |
-- Andreas, AIM XXIII, Issue 1944
-- {-# OPTIONS -v tc.proj.amb:30 #-}
-- Non-overloaded
record Wrap (A : Set) : Set where
field wrapped : A
open Wrap
-- Overloaded
record Sg (A : Set) : Set where
field head : A
open Sg
record Sg' (A : Set) : Set where
field head : A
open Sg'
-- ov/ov
works : ∀ {A : Set} (w : Sg (Sg' A)) → Sg A
head (works w) = head (head w)
-- ov/nov
test : ∀ {A : Set} (w : Wrap (Sg' A)) → Sg A
head (test w) = head (wrapped w)
-- WAS: failed because of a missing `reduce`
| {
"alphanum_fraction": 0.5851272016,
"avg_line_length": 15.96875,
"ext": "agda",
"hexsha": "2664cce648b8f4f5aefbeb4dc986a1971110c75a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1944-nested.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1944-nested.agda",
"max_line_length": 44,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1944-nested.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 189,
"size": 511
} |
module SizedIO.coIOIO where
open import Size
mutual
data coIO² (i : Size) (j : Size)
(Cin : Set ) (Rin : Cin → Set)
(Cext : Set) (Rext : Cext → Set)
(A : Set) : Set where
return : A → coIO² i j Cin Rin Cext Rext A
dof : (i' : Size< i) →
(c : Cin) → (Rin c → coIO² i' j Cin Rin Cext Rext A)
→ coIO² i j Cin Rin Cext Rext A
do∞ : (c : Cext)
→ (Rext c → coIO²∞ j Cin Rin Cext Rext A)
→ coIO² i j Cin Rin Cext Rext A
record coIO²∞ (j : Size) (Cin : Set ) (Rin : Cin → Set)
(Cext : Set) (Rext : Cext → Set)
(A : Set) : Set where
coinductive
field
force : (j' : Size< j)
→ coIO² ∞ j' Cin Rin Cext Rext A
open coIO²∞ public
| {
"alphanum_fraction": 0.4525810324,
"avg_line_length": 29.75,
"ext": "agda",
"hexsha": "f81eab9a9962f88ebbc1a5235c65f1620bbe4d6d",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "src/SizedIO/coIOIO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "src/SizedIO/coIOIO.agda",
"max_line_length": 66,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "src/SizedIO/coIOIO.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 291,
"size": 833
} |
-- Andreas, 2012-02-24 example by Ramana Kumar
{-# OPTIONS --sized-types #-}
-- {-# OPTIONS --show-implicit -v tc.size.solve:20 -v tc.conv.size:15 #-}
module SizeInconsistentMeta4 where
open import Data.Nat using (ℕ;zero;suc) renaming (_<_ to _N<_)
open import Data.Product using (_,_;_×_)
open import Data.Product.Relation.Binary.Lex.Strict using (×-Lex; ×-transitive)
open import Data.List using (List)
open import Data.List.Relation.Binary.Lex.Strict using (Lex-<) renaming (<-transitive to Lex<-trans)
open import Relation.Binary using (Rel;_Respects₂_;Transitive;IsEquivalence)
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
open import Level using (0ℓ)
open import Size using (Size;↑_)
-- keeping the definition of Vec for the positivity check
infixr 5 _∷_
data Vec {a} (A : Set a) : ℕ → Set a where
[] : Vec A zero
_∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n)
{- produces different error
data Lex-< {A : _} (_≈_ _<_ : Rel A Level.zero) : Rel (List A) Level.zero where
postulate
Lex<-trans : ∀ {P _≈_ _<_} →
IsEquivalence _≈_ → _<_ Respects₂ _≈_ → Transitive _<_ →
Transitive (Lex-< _≈_ _<_)
-}
postulate
N<-trans : Transitive _N<_
-- Vec : ∀ {a} (A : Set a) → ℕ → Set a
Vec→List : ∀ {a n} {A : Set a} → Vec A n → List A
data Type : Size → Set where
TyApp : {z : Size} (n : ℕ) → (as : Vec (Type z) n) → Type (↑ z)
<-transf : ∀ {z} → Rel (Type z) 0ℓ → Rel (ℕ × List (Type z)) 0ℓ
<-transf _<_ = ×-Lex _≡_ _N<_ (Lex-< _≡_ _<_)
infix 4 _<_
data _<_ : {z : Size} → Rel (Type z) 0ℓ where
TyApp<TyApp : ∀ {z} {n₁} {as₁} {n₂} {as₂} →
<-transf (_<_ {z}) (n₁ , Vec→List as₁) (n₂ , Vec→List as₂) →
_<_ {↑ z} (TyApp n₁ as₁) (TyApp n₂ as₂)
<-trans : ∀ {z} → Transitive (_<_ {z})
<-trans (TyApp<TyApp p) (TyApp<TyApp q) =
TyApp<TyApp (×-transitive {_<₂_ = Lex-< _≡_ _<_}
PropEq.isEquivalence
(PropEq.resp₂ _N<_)
N<-trans
(Lex<-trans PropEq.isEquivalence (PropEq.resp₂ _<_) <-trans)
p q)
| {
"alphanum_fraction": 0.595581172,
"avg_line_length": 36.5263157895,
"ext": "agda",
"hexsha": "3906499be099b7aaa45304f9fc694b1597b71bc5",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/LibSucceed/SizeInconsistentMeta4.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/LibSucceed/SizeInconsistentMeta4.agda",
"max_line_length": 100,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/LibSucceed/SizeInconsistentMeta4.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 747,
"size": 2082
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Globe where
import Level
open import Relation.Binary using (IsEquivalence; module IsEquivalence)
open import Relation.Binary.PropositionalEquality using (isEquivalence)
open import Data.Nat using (ℕ; zero; suc; _<_; _≤_; z≤n; s≤s)
open import Data.Nat.Properties using (<-trans)
open import Categories.Support.PropositionalEquality
open import Categories.Category
-- the stdlib doesn't have this
private
≤-unique : ∀ {m n} {x y : m ≤ n} → x ≣ y
≤-unique {x = z≤n} {z≤n} = ≣-refl
≤-unique {x = s≤s m≤n} {s≤s m≤n'} = ≣-cong s≤s ≤-unique
data GlobeHom : (m n : ℕ) → Set where
I : {place : ℕ} → GlobeHom place place
σ : {m n : ℕ} (n<m : n < m) → GlobeHom n m
τ : {m n : ℕ} (n<m : n < m) → GlobeHom n m
infixl 7 _⊚_
_⊚_ : ∀ {l m n} → GlobeHom m n → GlobeHom l m → GlobeHom l n
I ⊚ y = y
x ⊚ I = x
σ n<m ⊚ σ m<l = σ (<-trans m<l n<m)
σ n<m ⊚ τ m<l = τ (<-trans m<l n<m)
τ n<m ⊚ σ m<l = σ (<-trans m<l n<m)
τ n<m ⊚ τ m<l = τ (<-trans m<l n<m)
Globe : Category Level.zero Level.zero Level.zero
Globe = record
{ Obj = ℕ
; _⇒_ = GlobeHom
; _≡_ = _≣_
; id = I
; _∘_ = _⊚_
; assoc = λ {_} {_} {_} {_} {f} {g} {h} → assoc {f = f} {g} {h}
; identityˡ = λ {A} {B} {f} → ≣-refl
; identityʳ = identityʳ
; equiv = isEquivalence
; ∘-resp-≡ = ∘-resp-≡
}
where
assoc : ∀ {A B C D} {f : GlobeHom A B} {g : GlobeHom B C} {h : GlobeHom C D} → (h ⊚ g) ⊚ f ≣ h ⊚ (g ⊚ f)
assoc {f = I} {I} {I} = ≣-refl
assoc {f = I} {I} {σ _} = ≣-refl
assoc {f = I} {I} {τ _} = ≣-refl
assoc {f = I} {σ _} {I} = ≣-refl
assoc {f = I} {σ _} {σ _} = ≣-refl
assoc {f = I} {σ _} {τ _} = ≣-refl
assoc {f = I} {τ _} {I} = ≣-refl
assoc {f = I} {τ _} {σ _} = ≣-refl
assoc {f = I} {τ _} {τ _} = ≣-refl
assoc {f = σ _} {I} {I} = ≣-refl
assoc {f = σ _} {I} {σ _} = ≣-refl
assoc {f = σ _} {I} {τ _} = ≣-refl
assoc {f = σ _} {σ _} {I} = ≣-refl
assoc {f = σ _} {σ _} {σ _} = ≣-cong σ ≤-unique
assoc {f = σ _} {σ _} {τ _} = ≣-cong σ ≤-unique
assoc {f = σ _} {τ _} {I} = ≣-refl
assoc {f = σ _} {τ _} {σ _} = ≣-cong σ ≤-unique
assoc {f = σ _} {τ _} {τ _} = ≣-cong σ ≤-unique
assoc {f = τ n<m} {I} {I} = ≣-refl
assoc {f = τ n<m} {I} {σ _} = ≣-refl
assoc {f = τ n<m} {I} {τ _} = ≣-refl
assoc {f = τ n<m} {σ _} {I} = ≣-refl
assoc {f = τ n<m} {σ _} {σ _} = ≣-cong τ ≤-unique
assoc {f = τ n<m} {σ _} {τ _} = ≣-cong τ ≤-unique
assoc {f = τ n<m} {τ _} {I} = ≣-refl
assoc {f = τ n<m} {τ _} {σ _} = ≣-cong τ ≤-unique
assoc {f = τ n<m} {τ _} {τ _} = ≣-cong τ ≤-unique
-- this is necessary because Agda lies...
identityʳ : ∀ {A B} {f : GlobeHom A B} → f ⊚ I ≣ f
identityʳ {f = I} = ≣-refl
identityʳ {f = σ _} = ≣-refl
identityʳ {f = τ _} = ≣-refl
∘-resp-≡ : ∀ {A B C} {f h : GlobeHom B C} {g i : GlobeHom A B} → f ≣ h → g ≣ i → f ⊚ g ≣ h ⊚ i
∘-resp-≡ ≣-refl ≣-refl = ≣-refl
infixl 30 _σ′
infixl 30 _τ′
data GlobeHom′ : (m n : ℕ) → Set where
I : ∀ {place : ℕ} → GlobeHom′ place place
_σ′ : ∀ {n m : ℕ} → GlobeHom′ (suc n) m → GlobeHom′ n m
_τ′ : ∀ {n m : ℕ} → GlobeHom′ (suc n) m → GlobeHom′ n m
data GlobeEq′ : {m n : ℕ} → GlobeHom′ m n → GlobeHom′ m n → Set where
both-I : ∀ {m} → GlobeEq′ {m} {m} I I
both-σ : ∀ {m n x y} → GlobeEq′ {m} {n} (x σ′) (y σ′)
both-τ : ∀ {m n x y} → GlobeEq′ {m} {n} (x τ′) (y τ′)
GlobeEquiv : ∀ {m n} → IsEquivalence (GlobeEq′ {m} {n})
GlobeEquiv = record { refl = refl; sym = sym; trans = trans }
where
refl : ∀ {m n} {x : GlobeHom′ m n} → GlobeEq′ x x
refl {x = I} = both-I
refl {x = y σ′} = both-σ
refl {x = y τ′} = both-τ
sym : ∀ {m n} {x y : GlobeHom′ m n} → GlobeEq′ x y → GlobeEq′ y x
sym both-I = both-I
sym both-σ = both-σ
sym both-τ = both-τ
trans : ∀ {m n} {x y z : GlobeHom′ m n} → GlobeEq′ x y → GlobeEq′ y z → GlobeEq′ x z
trans both-I y∼z = y∼z
trans both-σ both-σ = both-σ
trans both-τ both-τ = both-τ
infixl 7 _⊚′_
_⊚′_ : ∀ {l m n} → GlobeHom′ m n → GlobeHom′ l m → GlobeHom′ l n
x ⊚′ I = x
x ⊚′ y σ′ = (x ⊚′ y) σ′
x ⊚′ y τ′ = (x ⊚′ y) τ′
Globe′ : Category Level.zero Level.zero Level.zero
Globe′ = record
{ Obj = ℕ
; _⇒_ = GlobeHom′
; _≡_ = GlobeEq′
; id = I
; _∘_ = _⊚′_
; assoc = λ {_ _ _ _ f g h} → assoc {f = f} {g} {h}
; identityˡ = identityˡ
; identityʳ = identityʳ
; equiv = GlobeEquiv
; ∘-resp-≡ = ∘-resp-≡
}
where
assoc : ∀ {A B C D} {f : GlobeHom′ A B} {g : GlobeHom′ B C} {h : GlobeHom′ C D} → GlobeEq′ ((h ⊚′ g) ⊚′ f) (h ⊚′ (g ⊚′ f))
assoc {f = I} = refl
where open IsEquivalence GlobeEquiv
assoc {f = y σ′} = both-σ
assoc {f = y τ′} = both-τ
identityˡ : ∀ {A B} {f : GlobeHom′ A B} → GlobeEq′ (I ⊚′ f) f
identityˡ {f = I} = both-I
identityˡ {f = y σ′} = both-σ
identityˡ {f = y τ′} = both-τ
identityʳ : ∀ {A B} {f : GlobeHom′ A B} → GlobeEq′ (f ⊚′ I) f
identityʳ = IsEquivalence.refl GlobeEquiv
∘-resp-≡ : ∀ {A B C} {f h : GlobeHom′ B C} {g i : GlobeHom′ A B} → GlobeEq′ f h → GlobeEq′ g i → GlobeEq′ (f ⊚′ g) (h ⊚′ i)
∘-resp-≡ f∼h both-I = f∼h
∘-resp-≡ f∼h both-σ = both-σ
∘-resp-≡ f∼h both-τ = both-τ
-- Fix this
{-
data ReflexiveGlobeHom : (m n : ℕ) → Set where
plain : ∀ {m n} → GlobeHom m n → ReflexiveGlobeHom m n
ι : ∀ {m n} → ReflexiveGlobeHom m n → ReflexiveGlobeHom m (suc n)
stripped : ∀ {m n} → (cons : n < m → GlobeHom n m) → n < suc m → GlobeHom n m
stripped cons n<Sm with <-unsucʳ n<Sm
stripped cons n<Sm | inl ≣-refl = I
stripped cons n<Sm | inr n<m = cons n<m
_⊚ʳ_ : ∀ {l m n} → ReflexiveGlobeHom m n → ReflexiveGlobeHom l m → ReflexiveGlobeHom l n
ι x ⊚ʳ y = ι (x ⊚ʳ y)
plain x ⊚ʳ plain y = plain (x ⊚ y)
plain I ⊚ʳ ι y = ι y
plain (σ _) ⊚ʳ ι y = (plain (stripped σ n<m)) ⊚ʳ y
plain (τ n<m) ⊚ʳ ι y = (plain (stripped τ n<m)) ⊚ʳ y
-}
| {
"alphanum_fraction": 0.5247991617,
"avg_line_length": 33.485380117,
"ext": "agda",
"hexsha": "c86a76cf9e51a402c154cd8e420d0637271d434d",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Globe.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Globe.agda",
"max_line_length": 125,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Globe.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 2776,
"size": 5726
} |
primitive
abstract
postulate
private
mutual
macro
variable
instance
record F : Set where
field
| {
"alphanum_fraction": 0.7619047619,
"avg_line_length": 5.5263157895,
"ext": "agda",
"hexsha": "b87c3f67400f17ddfdf9fc82e78f887c70f9570a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/empty.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/empty.agda",
"max_line_length": 20,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/empty.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 27,
"size": 105
} |
open import Common.Level
-- Note that this is level-polymorphic
record ⊤ {a} : Set a where
constructor tt
data ⊥ {a} : Set a where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
lzero' : ℕ → Level
lzero' zero = lzero
lzero' (suc n) = lzero ⊔ (lzero' n)
IsZero : (x : ℕ) → Set (lsuc (lzero' x))
IsZero zero = ⊤
IsZero (suc _) = ⊥
test : IsZero (suc _)
test = tt
| {
"alphanum_fraction": 0.6010781671,
"avg_line_length": 15.4583333333,
"ext": "agda",
"hexsha": "6877cdb4b24faae77872232177ae5085183a1fa2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue1213.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue1213.agda",
"max_line_length": 40,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1213.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 146,
"size": 371
} |
open import Level using (_⊔_)
open import Data.Maybe using (Maybe; nothing; just)
open import Data.List.Any as A hiding (map)
open import Relation.Binary.PropositionalEquality.Core as PropEq
open import Relation.Binary
open import Prelude hiding (map)
open Eq {{...}}
module RW.Data.PMap (A : Set){{eqA : Eq A}} where
private
_≟_ : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)
a₁ ≟ a₂ = Eq.cmp eqA a₁ a₂
-- Naive Partial Map representation
to_ : ∀{b} → Set b → Set b
to B = List (A × B)
to_default : ∀{b} → Set b → Set b
to B default = B × List (A × B)
onDef : ∀{b c}{B : Set b}{C : Set c}
→ (m : to B → C) → to B default → C
onDef f (_ , m) = f m
onDef' : ∀{b}{B : Set b}
→ (m : to B → to B) → to B default → to B default
onDef' f (def , m) = def , f m
empty : ∀{b}{B : Set b}
→ to B
empty = []
-- Membership
_∈_ : ∀{b}{B : Set b}
→ A → (to B) → Set _
a ∈ m = A.Any ((_≡_ a) ∘ p1) m
_∉_ : ∀{b}{B : Set b}
→ A → (to B) → Set _
a ∉ m = (a ∈ m) → ⊥
-- Decidable membership
dec∈ : ∀{b}{B : Set b}
→ (a : A) → (m : to B) → Dec (a ∈ m)
dec∈ a [] = no (λ ())
dec∈ a (x ∷ m) with a ≟ (p1 x)
...| yes a≡x = yes (here a≡x)
...| no a≢x with dec∈ a m
...| yes a∈m = yes (there a∈m)
...| no a∉m = no (a∉m ∘ tail a≢x)
-- Look up
lkup : ∀{b}{B : Set b} → A → (to B) → Maybe B
lkup k [] = nothing
lkup k ((h , r) ∷ ts)
with k ≟ h
...| yes _ = just r
...| no _ = lkup k ts
-- Look up in a map with a default value
lkupDef : ∀{b}{B : Set b} → A → to B default → B
lkupDef a (b , m) = maybe id b (lkup a m)
-- Total version
lkup' : ∀{b}{B : Set b}
→ (a : A) → (m : to B) → a ∈ m → B
lkup' a (m ∷ _) (here px) = p2 m
lkup' a (_ ∷ ms) (there prf) = lkup' a ms prf
-- Insertion / Removal
alter : ∀{b}{B : Set b}
→ (Maybe B → Maybe B) → A → (to B) → (to B)
alter f a [] with f nothing
...| just b = (a , b) ∷ []
...| nothing = []
alter f a (x ∷ m) with a ≟ p1 x
...| no _ = x ∷ alter f a m
...| yes _ with f $ just (p2 x)
...| nothing = m
...| just b = (a , b) ∷ m
alterPrf : ∀{b}{B : Set b}
→ B → (a : A) → (m : to B) → Σ (to B) (_∈_ a)
alterPrf b a m with dec∈ a m
...| yes a∈m = m , a∈m
...| no a∉m = (a , b) ∷ m , here refl
insert : ∀{b}{B : Set b}
→ A → B → (to B) → (to B)
insert a b m = alter (const $ just b) a m
delete : ∀{b}{B : Set b}
→ A → (to B) → (to B)
delete a m = alter (const nothing) a m
-- Map
map : ∀{b}{B B′ : Set b} → (B → B′) → (to B) → (to B′)
map f [] = []
map f ((a , b) ∷ m) = (a , f b) ∷ map f m
| {
"alphanum_fraction": 0.4609848485,
"avg_line_length": 25.6310679612,
"ext": "agda",
"hexsha": "d475d868eed8c5862e0cdfb538e412dd0315345c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "VictorCMiraldo/agda-rw",
"max_forks_repo_path": "RW/Data/PMap.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "VictorCMiraldo/agda-rw",
"max_issues_repo_path": "RW/Data/PMap.agda",
"max_line_length": 64,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "VictorCMiraldo/agda-rw",
"max_stars_repo_path": "RW/Data/PMap.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z",
"num_tokens": 1146,
"size": 2640
} |
{-# OPTIONS --universe-polymorphism #-}
open import Level
module Categories.Categories.Products (o ℓ e : Level) where
open import Categories.Category
open import Categories.Categories
import Categories.Object.Products
open Categories.Object.Products (Categories o ℓ e)
open import Categories.Product
import Categories.Product.Projections
import Categories.Product.Properties
open import Categories.Terminal
private
import Categories.Object.Product
open Categories.Object.Product (Categories o ℓ e)
renaming (Product to ProductObject)
product :
{A B : Category o ℓ e}
→ ProductObject A B
product {A}{B} = record
{ A×B = Product A B
; π₁ = ∏₁
; π₂ = ∏₂
; ⟨_,_⟩ = _※_
; commute₁ = λ {C}{f}{g} → ※-commute₁ {A = C}{f}{g}
; commute₂ = λ {C}{f}{g} → ※-commute₂ {A = C}{f}{g}
; universal = λ {C}{f}{g}{i} → ※-universal {A = C}{f}{g}{i}
} where
open Categories.Product.Projections A B
open Categories.Product.Properties A B
products : Products
products = record
{ terminal = One {o}{ℓ}{e}
; binary = record
{ product = λ {A}{B} → product {A}{B}
}
}
| {
"alphanum_fraction": 0.5915267786,
"avg_line_length": 26.6170212766,
"ext": "agda",
"hexsha": "84206342b5c6be808149c0ce0851a01170ddcb68",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Categories/Products.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Categories/Products.agda",
"max_line_length": 67,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Categories/Products.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 339,
"size": 1251
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core using (Category)
open import Categories.Functor.Bifunctor using (Bifunctor)
module Categories.Diagram.Cowedge {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Bifunctor (Category.op C) C D) where
private
module C = Category C
module D = Category D
open D
open HomReasoning
open Equiv
variable
A : Obj
open import Level
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation.Dinatural
open Functor F
record Cowedge : Set (levelOfTerm F) where
field
E : Obj
dinatural : DinaturalTransformation F (const E)
module dinatural = DinaturalTransformation dinatural
Cowedge-∘ : (W : Cowedge) → Cowedge.E W ⇒ A → Cowedge
Cowedge-∘ {A = A} W f = record
{ E = A
; dinatural = extranaturalˡ (λ X → f ∘ dinatural.α X)
(assoc ○ ∘-resp-≈ʳ (extranatural-commˡ dinatural) ○ sym-assoc)
}
where open Cowedge W
record Cowedge-Morphism (W₁ W₂ : Cowedge) : Set (levelOfTerm F) where
private
module W₁ = Cowedge W₁
module W₂ = Cowedge W₂
open DinaturalTransformation
field
u : W₁.E ⇒ W₂.E
commute : ∀ {C} → u ∘ W₁.dinatural.α C ≈ W₂.dinatural.α C
Cowedge-id : ∀ {W} → Cowedge-Morphism W W
Cowedge-id {W} = record { u = D.id ; commute = D.identityˡ }
Cowedge-Morphism-∘ : {A B C : Cowedge} → Cowedge-Morphism B C → Cowedge-Morphism A B → Cowedge-Morphism A C
Cowedge-Morphism-∘ M N = record { u = u M ∘ u N ; commute = assoc ○ (∘-resp-≈ʳ (commute N) ○ commute M) }
where
open Cowedge-Morphism
open HomReasoning
| {
"alphanum_fraction": 0.6670644391,
"avg_line_length": 28.8965517241,
"ext": "agda",
"hexsha": "786a7840ff8e03175d0561148c8a1aa725904ccd",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Cowedge.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Cowedge.agda",
"max_line_length": 107,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Cowedge.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 554,
"size": 1676
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.KVMap as Map hiding (empty)
open import Util.Prelude
module LibraBFT.Impl.Types.OnChainConfig.ValidatorSet where
new : List ValidatorInfo → ValidatorSet
new = ValidatorSet∙new ConsensusScheme∙new
empty : ValidatorSet
empty = new []
obmFromVV : ValidatorVerifier → ValidatorSet
obmFromVV vv0 = record -- ValidatorSet
{ _vsScheme = ConsensusScheme∙new -- TODO
; _vsPayload = fmap go (Map.toList (vv0 ^∙ vvAddressToValidatorInfo))
}
where
go : (Author × ValidatorConsensusInfo) → ValidatorInfo
go (address , ValidatorConsensusInfo∙new pk vp) =
record -- ValidatorInfo
{ _viAccountAddress = address
; _viConsensusVotingPower = vp
; _viConfig = record -- ValidatorConfig
{ _vcConsensusPublicKey = pk
; _vcValidatorNetworkAddress = address ^∙ aAuthorName } }
obmGetValidatorInfo : AuthorName → ValidatorSet → Either ErrLog ValidatorInfo
obmGetValidatorInfo name vs =
case List-filter (λ vi → vi ^∙ viAccountAddress ∙ aAuthorName ≟ name) (vs ^∙ vsPayload) of λ where
(vi ∷ []) → pure vi
_ → Left fakeErr -- ["ValidatorSet", "obmGetValidatorInfo", "TODO better err msg"]
| {
"alphanum_fraction": 0.7123015873,
"avg_line_length": 37.8,
"ext": "agda",
"hexsha": "39b16c47487944411df07d9a9eb5cd8975c8cd84",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Types/OnChainConfig/ValidatorSet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Types/OnChainConfig/ValidatorSet.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Types/OnChainConfig/ValidatorSet.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 409,
"size": 1512
} |
{-# OPTIONS --without-K #-}
module function.isomorphism.univalence where
open import equality.core
open import function.core
open import function.isomorphism.core
open import hott.equivalence.alternative
open import hott.univalence
≅⇒≡ : ∀ {i}{X Y : Set i}
→ X ≅ Y → X ≡ Y
≅⇒≡ = ≈⇒≡ ∘ ≅⇒≈
| {
"alphanum_fraction": 0.6858108108,
"avg_line_length": 22.7692307692,
"ext": "agda",
"hexsha": "48b4e432c5d7ab64e6c1e1567e642f4fb56347ef",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/function/isomorphism/univalence.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/function/isomorphism/univalence.agda",
"max_line_length": 44,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "function/isomorphism/univalence.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 103,
"size": 296
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.DStructures.Structures.Category where
open import Cubical.Foundations.Prelude
open import Cubical.DStructures.Base
open import Cubical.DStructures.Meta.Properties
open import Cubical.Categories.Category renaming (isUnivalent to isUnivalentCat)
private
variable
ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓ≅A ℓB ℓ≅B ℓ≅ᴰ : Level
-- every univalent 1-precategory gives a URGStr
Cat→𝒮 : (𝒞 : Precategory ℓ ℓ') → (uni : isUnivalentCat 𝒞) → URGStr (𝒞 .ob) ℓ'
Cat→𝒮 𝒞 uni
= urgstr (CatIso {𝒞 = 𝒞}) idCatIso λ x y → isUnivalentCat.univ uni x y
| {
"alphanum_fraction": 0.73,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "ec928962d6dab9fb806643079b0858ff8da7d4cf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/DStructures/Structures/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/DStructures/Structures/Category.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/DStructures/Structures/Category.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 227,
"size": 600
} |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Setoids.Subset
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Sets.EquivalenceRelations
open import Rings.Orders.Total.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Definition
open import Fields.Fields
open import Groups.Definition
open import Sequences
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Semirings.Definition
open import Functions.Definition
open import Fields.Orders.Total.Definition
module Fields.Orders.Limits.Definition {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {_} {c} A} {R : Ring S _+_ _*_} {pOrder : SetoidPartialOrder S _<_} {F : Field R} {pRing : PartiallyOrderedRing R pOrder} (oF : TotallyOrderedField F pRing) where
open Ring R
open TotallyOrderedField oF
open TotallyOrderedRing oRing
open PartiallyOrderedRing pRing
open import Rings.Orders.Total.Lemmas oRing
open import Rings.Orders.Total.AbsoluteValue oRing
open import Rings.Orders.Partial.Lemmas pRing
open SetoidTotalOrder total
open SetoidPartialOrder pOrder
open Group additiveGroup
open import Groups.Lemmas additiveGroup
open Setoid S
open Equivalence eq
open Field F
open import Fields.CauchyCompletion.Definition (TotallyOrderedField.oRing oF) F
_~>_ : Sequence A → A → Set (a ⊔ c)
x ~> c = (ε : A) → (0R < ε) → Sg ℕ (λ N → (n : ℕ) → (N <N n) → abs ((index x n) + inverse c) < ε)
1/2 : A
1/2 with allInvertible (1R + 1R) (orderedImpliesCharNot2 nontrivial)
... | a , _ = a
abstract
1/2is1/2 : (1/2 * (1R + 1R)) ∼ 1R
1/2is1/2 with allInvertible (1R + 1R) (orderedImpliesCharNot2 nontrivial)
... | a , pr = pr
0<1/2 : 0R < 1/2
0<1/2 = halvePositive 1/2 (<WellDefined reflexive (symmetric (transitive (transitive (+WellDefined (symmetric (transitive *Commutative identIsIdent)) (symmetric (transitive *Commutative identIsIdent))) (symmetric *DistributesOver+)) 1/2is1/2)) (0<1 nontrivial))
halfHalves : {a : A} → (1/2 * (a + a)) ∼ a
halfHalves {a} = transitive (*WellDefined reflexive (+WellDefined (symmetric identIsIdent) (symmetric identIsIdent))) (transitive (*WellDefined reflexive (symmetric *DistributesOver+')) (transitive *Associative (transitive (*WellDefined 1/2is1/2 reflexive) identIsIdent)))
abstract
bothNearImpliesNear : {t r s : A} (e : A) .(0<e : 0R < e) → (abs (r + inverse t) < e) → (abs (s + inverse t) < e) → abs (r + inverse s) < (e + e)
bothNearImpliesNear {t} {r} {s} e 0<e rNearT sNearT = u
where
pr : ((abs (r + inverse t)) + (abs (s + inverse t))) < (e + e)
pr = ringAddInequalities rNearT sNearT
t' : (abs (r + inverse t) + abs (t + inverse s)) < (e + e)
t' = <WellDefined (+WellDefined reflexive (transitive (absNegation _) (absWellDefined _ _ (transitive invContravariant (+WellDefined (invTwice _) reflexive))))) reflexive pr
u : abs (r + inverse s) < (e + e)
u with triangleInequality (r + inverse t) (t + inverse s)
... | inl t'' = <Transitive (<WellDefined (absWellDefined _ _ (transitive +Associative (+WellDefined (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invLeft) identRight)) reflexive))) reflexive t'') t'
... | inr eq = <WellDefined (transitive (symmetric eq) (absWellDefined _ _ (transitive +Associative (+WellDefined (transitive (symmetric +Associative) (transitive (+WellDefined reflexive invLeft) identRight)) reflexive)))) reflexive t'
private
limitsUniqueLemma : (x : Sequence A) {r s : A} (xr : x ~> r) (xs : x ~> s) (r<s : r < s) → False
limitsUniqueLemma x {r} {s} xr xs r<s = irreflexive (<WellDefined reflexive (symmetric prE) u')
where
e : A
e = 1/2 * (s + inverse r)
prE : (s + inverse r) ∼ (e + e)
prE = transitive (symmetric halfHalves) *DistributesOver+
0<e : 0R < e
0<e = orderRespectsMultiplication 0<1/2 (moveInequality r<s)
abstract
N1 : ℕ
N1 with xs e 0<e
... | x , _ = x
N1prop : (n : ℕ) → (N1 <N n) → abs (index x n + inverse s) < e
N1prop with xs e 0<e
... | x , pr = pr
N2 : ℕ
N2 with xr e 0<e
... | x , _ = x
N2prop : (n : ℕ) → (N2 <N n) → abs (index x n + inverse r) < e
N2prop with xr e 0<e
... | x , pr = pr
good : ℕ
good = succ (N1 +N N2)
N1Good : abs (index x good + inverse s) < e
N1Good = N1prop good (le N2 (applyEquality succ (Semiring.commutative ℕSemiring N2 N1)))
N2Good : abs (index x good + inverse r) < e
N2Good = N2prop good (le N1 refl)
t : ((abs (index x good + inverse s)) + (abs (index x good + inverse r))) < (e + e)
t = ringAddInequalities N1Good N2Good
t' : ((abs (index x good + inverse s)) + (abs (r + inverse (index x good)))) < (e + e)
t' = <WellDefined (+WellDefined reflexive (transitive (absNegation _) (absWellDefined _ _ (transitive invContravariant (+WellDefined (invTwice _) reflexive))))) reflexive t
u : abs (inverse s + r) < (e + e)
u with triangleInequality (index x good + inverse s) (r + inverse (index x good))
... | inl t'' = <Transitive (<WellDefined (absWellDefined _ _ (transitive groupIsAbelian (transitive +Associative (transitive (+WellDefined (symmetric +Associative) reflexive) (transitive (+WellDefined (transitive (+WellDefined reflexive invLeft) identRight) reflexive) groupIsAbelian))))) reflexive t'') t'
... | inr eq = <WellDefined (transitive (symmetric eq) (absWellDefined _ _ (transitive groupIsAbelian (transitive +Associative (transitive (+WellDefined (symmetric +Associative) reflexive) (transitive (+WellDefined (transitive (+WellDefined reflexive invLeft) identRight) reflexive) groupIsAbelian)))))) reflexive t'
u' : (s + inverse r) < (e + e)
u' = <WellDefined (transitive (absNegation _) (transitive (absWellDefined _ _ (transitive invContravariant (transitive groupIsAbelian (+WellDefined (invTwice _) reflexive)))) (symmetric (greaterZeroImpliesEqualAbs (moveInequality r<s))))) reflexive u
limitsAreUnique : (x : Sequence A) → {r s : A} → (x ~> r) → (x ~> s) → r ∼ s
limitsAreUnique x {r} {s} xr xs with totality r s
limitsAreUnique x {r} {s} xr xs | inl (inl r<s) = exFalso (limitsUniqueLemma x xr xs r<s)
limitsAreUnique x {r} {s} xr xs | inl (inr s<r) = exFalso (limitsUniqueLemma x xs xr s<r)
limitsAreUnique x {r} {s} xr xs | inr r=s = r=s
constantSequenceConverges : (a : A) → constSequence a ~> a
constantSequenceConverges a e 0<e = 0 , λ n _ → <WellDefined (symmetric (transitive (absWellDefined _ _ (transitive (+WellDefined (identityOfIndiscernablesRight _∼_ reflexive (indexAndConst a n)) reflexive) invRight)) absZeroIsZero)) reflexive 0<e
| {
"alphanum_fraction": 0.6749818709,
"avg_line_length": 57.4583333333,
"ext": "agda",
"hexsha": "c6de8b30e68591f6fe8e407204a8a207e779debf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/Orders/Limits/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/Orders/Limits/Definition.agda",
"max_line_length": 322,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/Orders/Limits/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 2260,
"size": 6895
} |
module FStream.Clocked where
open import Library
open import FStream.Core
mutual
record ClSF {i : Size} {ℓ₁ ℓ₂} {Cl : Set ℓ₂} (C : Container ℓ₁) (cl : FStream C Cl) (A B : Set ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
inductive
field
inFCl : A → ⟦ C ⟧ (ClSF' {i} C cl A B)
record ClSF' {i : Size} {ℓ₁ ℓ₂} {Cl : Set ℓ₂} (C : Container ℓ₁) (cl : FStream C Cl) (A B : Set ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
coinductive
field
head : B
tail : {j : Size< i} → ClSF {j} C cl A B
open FStream public
open FStream' public
_>>>_ : ∀ {i : Size} {ℓ₁ ℓ₂} {a b c Cl : Set ℓ₂} {C : Container ℓ₁} {cl : FStream C Cl} → ClSF {i} C cl a b → ClSF {i} C cl b c → ClSF {i} C cl a c
_>>>_ = {!!}
-- runClock : ∀ {i : Size} {ℓ₁ ℓ₂} {Cl B : Set ℓ₂} {C : Container ℓ₁} → (cl : FStream C Cl) → ClSF {i} C cl A B → FStream {i} C A -> FStream {i} C B
runClock : ∀ {i : Size} {ℓ₁ ℓ₂} {A B Cl : Set ℓ₂} {C : Container ℓ₁} → (cl : FStream C Cl) → ClSF {i} C cl A B → FStream {i} C A -> FStream {i} C B
runClock = {!!}
| {
"alphanum_fraction": 0.5525793651,
"avg_line_length": 40.32,
"ext": "agda",
"hexsha": "5f21abbea22dd6db9bdcd9d81f6b520f120cf4f8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "zimbatm/condatis",
"max_forks_repo_path": "FStream/Clocked.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "zimbatm/condatis",
"max_issues_repo_path": "FStream/Clocked.agda",
"max_line_length": 149,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Aerate/condatis",
"max_stars_repo_path": "FStream/Clocked.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z",
"num_tokens": 456,
"size": 1008
} |
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
postulate
A : Set
a b c : A
f g : A → A
rew₁ : f a ≡ b
rew₂ : ∀ {x} → f (g x) ≡ c
rew₃ : g a ≡ a
{-# REWRITE rew₁ #-}
{-# REWRITE rew₂ #-}
{-# REWRITE rew₃ #-}
works : (x : A) → f (g x) ≡ c
works x = refl
works' : f (g a) ≡ c
works' = works a
fails : f (g a) ≡ c
fails = refl
| {
"alphanum_fraction": 0.5550239234,
"avg_line_length": 15.4814814815,
"ext": "agda",
"hexsha": "8629cb6abe20dff1036089f8f07915e8aa849a44",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/ConfluenceNestedOverlap.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/ConfluenceNestedOverlap.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/ConfluenceNestedOverlap.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 167,
"size": 418
} |
module Mendler (F : Set → Set) where
open import Data.Product using (_×_)
Alg : Set → Set₁
Alg X = ∀ (R : Set) → (R → X) → F R → X
test : Set → Set
test A = A × A
test′ : ∀ (R : Set) → Set
test′ A = A × A
| {
"alphanum_fraction": 0.5336538462,
"avg_line_length": 17.3333333333,
"ext": "agda",
"hexsha": "47fceaed16ebdf1eb5264d5f9dcaf21bbb2ef0dd",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "manikdv/plfa.github.io",
"max_forks_repo_path": "extra/extra/Mendler.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "manikdv/plfa.github.io",
"max_issues_repo_path": "extra/extra/Mendler.agda",
"max_line_length": 39,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "manikdv/plfa.github.io",
"max_stars_repo_path": "extra/extra/Mendler.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 82,
"size": 208
} |
--{-# OPTIONS -vtc:50 #-}
{-# OPTIONS --double-check #-}
open import Agda.Primitive
postulate Id : (l : Level) (A : Set l) → A → A → Set l
postulate w/e : (l : Level) (A : Set l) → A
data Box l (A : Set l) : Set l where
box : A → Box l A
unbox : (l : Level) (A : Set l) → Box l A → A
unbox l A (box x) = x
record R l (A : Set l) : Set l where
--no-eta-equality
-- ^ works if eta is disabled
field
boxed : Box l A
refl : Id l A (w/e l A) (w/e l A)
postulate
El : (l : Level) (A : Set l) → A → A
trans : (l : Level) (A : Set l) (x : A) → Id l A (w/e l A) (w/e l A) → Id l A (w/e l A) (w/e l A) → Id l A (w/e l A) (w/e l A)
cong : (l : Level) (A : Set l) (f : A → A) (x y : A) → Id l A x y → Id l A (f x) (f y)
module _ (l : Level) (BADNESS : Set) (A : Set l) (r : R l A) where
open R r
x = w/e l A
p = trans l A (unbox l A boxed) refl refl
lemma = El l
(Id l (Id l A x x) p p)
(cong l _ (λ p → trans l A (unbox l A boxed) p _) refl refl (w/e l (Id l (Id l A x x) refl refl)))
-- ^ works if definition of lemma is removed
test = λ _ → unbox _ _ boxed
| {
"alphanum_fraction": 0.5080071174,
"avg_line_length": 26.7619047619,
"ext": "agda",
"hexsha": "39474b0e0b7eb93a72acf328c6303c8420bcee65",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue4283.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue4283.agda",
"max_line_length": 128,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4283.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 456,
"size": 1124
} |
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-}
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base -- Rel
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
open import Function.Base using (_$_)
open import Cubical.Data.Nat hiding (min)
open import Cubical.Data.Nat.Order
-- open import Cubical.Data.Nat.Properties -- using (+-suc; injSuc; snotz; +-comm; +-assoc; +-zero; inj-m+)
open import MoreNatProperties
module Enumeration
{ℓ}
{A : Type ℓ}
(f : A → ℕ)
(f⁻¹ : ℕ → A)
(isRetraction : ∀ x → f⁻¹ (f x) ≡ x)
where
_≤'_ : Rel A A ℓ-zero
a ≤' b = (f a) ≤ (f b)
min' : A → A → A
min' a b = f⁻¹ (min (f a) (f b))
max' : A → A → A
max' a b = f⁻¹ (max (f a) (f b))
max'-sym : ∀ a b → max' a b ≡ max' b a
max'-sym a b with f a ≟ f b | f b ≟ f a
... | lt x | lt y = ⊥-elim {A = λ _ → f⁻¹ (f b) ≡ f⁻¹ (f a)} $ <-asymʷ _ _ x y
... | lt x | eq y = refl
... | lt x | gt y = refl
... | eq x | lt y = refl
... | eq x | eq y = cong f⁻¹ x
... | eq x | gt y = cong f⁻¹ x
... | gt x | lt y = refl
... | gt x | eq y = sym (cong f⁻¹ y)
... | gt x | gt y = ⊥-elim {A = λ _ → f⁻¹ (f a) ≡ f⁻¹ (f b)} $ <-asymʷ _ _ x y
max'-implies-≤'₁ : ∀ a b → a ≤' max' a b
max'-implies-≤'₁ a b with (f a) ≟ (f b)
... | lt (x , p) = suc x , sym (+-suc _ _) ∙ p ∙ cong f (sym (isRetraction b))
... | eq x = 0 , sym (cong f (isRetraction a) ∙ refl {x = f a})
... | gt x = 0 , sym (cong f (isRetraction a) ∙ refl {x = f a})
max-implies-≤' : ∀ a b → (a ≤' max' a b) × (b ≤' max' a b)
max-implies-≤' a b = max'-implies-≤'₁ a b , transport (λ i → b ≤' max'-sym b a i) (max'-implies-≤'₁ b a)
min'-sym : ∀ a b → min' a b ≡ min' b a
min'-sym a b with f a ≟ f b | f b ≟ f a
... | lt x | lt y = ⊥-elim {A = λ _ → f⁻¹ (f a) ≡ f⁻¹ (f b)} $ <-asymʷ _ _ x y
... | lt x | eq y = sym (cong f⁻¹ y)
... | lt x | gt y = refl
... | eq x | lt y = cong f⁻¹ x
... | eq x | eq y = cong f⁻¹ x
... | eq x | gt y = refl
... | gt x | lt y = refl
... | gt x | eq y = refl
... | gt x | gt y = ⊥-elim {A = λ _ → f⁻¹ (f b) ≡ f⁻¹ (f a)} $ <-asymʷ _ _ x y
min'-implies-≤'₁ : ∀ a b → min' a b ≤' a
min'-implies-≤'₁ a b with (f a) ≟ (f b)
... | lt x = 0 , cong f (isRetraction a) ∙ refl {x = f a}
... | eq x = 0 , cong f (isRetraction a) ∙ refl {x = f a}
... | gt (x , p) = suc x , (λ i → suc (x + cong f (sym (isRetraction b)) (~ i))) ∙ sym (+-suc _ _) ∙ p
min-implies-≤' : ∀ a b → (min' a b ≤' a) × (min' a b ≤' b)
min-implies-≤' a b = min'-implies-≤'₁ a b , transport (λ i → min'-sym b a i ≤' b) (min'-implies-≤'₁ b a)
| {
"alphanum_fraction": 0.5145380935,
"avg_line_length": 36.2266666667,
"ext": "agda",
"hexsha": "5c8bc8e4dd027352670d4bd30c8669491af3392b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Enumeration.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Enumeration.agda",
"max_line_length": 107,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Enumeration.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 1220,
"size": 2717
} |
module InterpretationEqualityExceptAtVariableName where
open import OscarPrelude
open import VariableName
open import FunctionName
open import PredicateName
open import Elements
open import Interpretation
record _≞_/_ (𝓘 : Interpretation) (I : Interpretation) (𝑥 : VariableName) : Set
where
field
μEquality : {𝑥′ : VariableName} → 𝑥′ ≢ 𝑥 → μ⟦ 𝓘 ⟧ 𝑥 ≡ μ⟦ I ⟧ 𝑥′
𝑓Equality : (𝑓 : FunctionName) (μs : Elements) → 𝑓⟦ 𝓘 ⟧ 𝑓 μs ≡ 𝑓⟦ I ⟧ 𝑓 μs
𝑃Equality : (𝑃 : PredicateName) → (μs : Elements) → 𝑃⟦ 𝓘 ⟧ 𝑃 μs ≡ 𝑃⟦ I ⟧ 𝑃 μs
| {
"alphanum_fraction": 0.6842105263,
"avg_line_length": 31.2941176471,
"ext": "agda",
"hexsha": "ae12cf759acb70bb9156d78311dff1adca1e5c4b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/InterpretationEqualityExceptAtVariableName.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/InterpretationEqualityExceptAtVariableName.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/InterpretationEqualityExceptAtVariableName.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 226,
"size": 532
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Structures.InftyMagma where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.FunExtEquiv
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
private
variable
ℓ ℓ' ℓ'' : Level
-- ∞-Magmas with SNS
∞-magma-structure : Type ℓ → Type ℓ
∞-magma-structure X = X → X → X
∞-Magma : Type (ℓ-suc ℓ)
∞-Magma {ℓ} = TypeWithStr ℓ ∞-magma-structure
∞-magma-iso : StrIso ∞-magma-structure ℓ
∞-magma-iso (X , _·_) (Y , _∗_) f =
(x x' : X) → equivFun f (x · x') ≡ equivFun f x ∗ equivFun f x'
∞-magma-is-SNS : SNS {ℓ} ∞-magma-structure ∞-magma-iso
∞-magma-is-SNS f = SNS-≡→SNS-PathP ∞-magma-iso (λ _ _ → funExt₂Equiv) f
| {
"alphanum_fraction": 0.6743243243,
"avg_line_length": 26.4285714286,
"ext": "agda",
"hexsha": "c442dadeb514feee83a2a5b3bcb8f1f79b0b6197",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/Structures/InftyMagma.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/Structures/InftyMagma.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/Structures/InftyMagma.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 312,
"size": 740
} |
module 060-commutative-group where
-- We need groups.
open import 050-group
record CommutativeGroup
{M : Set}
(_==_ : M -> M -> Set)
(_*_ : M -> M -> M)
(id : M)
(invert : M -> M)
: Set1 where
field
group : Group _==_ _*_ id invert
comm : ∀ {r s} -> (r * s) == (s * r)
open Group group public
-- Nothing proven here yet.
| {
"alphanum_fraction": 0.552407932,
"avg_line_length": 16.0454545455,
"ext": "agda",
"hexsha": "aa4195bca8fd133ef6a9d7b1feb72e9595391758",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mcmtroffaes/agda-proofs",
"max_forks_repo_path": "060-commutative-group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mcmtroffaes/agda-proofs",
"max_issues_repo_path": "060-commutative-group.agda",
"max_line_length": 40,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mcmtroffaes/agda-proofs",
"max_stars_repo_path": "060-commutative-group.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z",
"num_tokens": 121,
"size": 353
} |
{-# OPTIONS --without-K #-}
module Explore.BinTree where
open import Level.NP
open import Type hiding (★)
open import Data.Tree.Binary
open import Data.Zero
open import Data.One
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality.NP
open import HoTT
open Equivalences
open import Type.Identities
open import Function
open import Function.Extensionality
open import Explore.Core
open import Explore.Properties
open import Explore.Zero
open import Explore.Sum
open import Explore.Isomorphism
fromBinTree : ∀ {m} {a} {A : ★ a} → BinTree A → Explore m A
fromBinTree empty = empty-explore
fromBinTree (leaf x) = point-explore x
fromBinTree (fork ℓ r) = merge-explore (fromBinTree ℓ) (fromBinTree r)
fromBinTree-ind : ∀ {m p a} {A : ★ a} (t : BinTree A) → ExploreInd p (fromBinTree {m} t)
fromBinTree-ind empty = empty-explore-ind
fromBinTree-ind (leaf x) = point-explore-ind x
fromBinTree-ind (fork ℓ r) = merge-explore-ind (fromBinTree-ind ℓ)
(fromBinTree-ind r)
AnyP≡ΣfromBinTree : ∀ {a p}{A : ★ a}{P : A → ★ p}(xs : BinTree A) → Any P xs ≡ Σᵉ (fromBinTree xs) P
AnyP≡ΣfromBinTree empty = idp
AnyP≡ΣfromBinTree (leaf x) = idp
AnyP≡ΣfromBinTree (fork xs xs₁) = ⊎= (AnyP≡ΣfromBinTree xs) (AnyP≡ΣfromBinTree xs₁)
module _ {{_ : UA}}{{_ : FunExt}}{A : ★ ₀} where
exploreΣ∈ : ∀ {m} xs → Explore m (Σ A λ x → Any (_≡_ x) xs)
exploreΣ∈ empty = explore-iso (coe-equiv (Lift≡id ∙ ! ×𝟘-snd ∙ ×= idp (! Lift≡id))) Lift𝟘ᵉ
exploreΣ∈ (leaf x) = point-explore (x , idp)
exploreΣ∈ (fork xs xs₁) = explore-iso (coe-equiv (! Σ⊎-split)) (exploreΣ∈ xs ⊎ᵉ exploreΣ∈ xs₁)
Σᵉ-adq-exploreΣ∈ : ∀ {m} xs → Adequate-Σ {m} (Σᵉ (exploreΣ∈ xs))
Σᵉ-adq-exploreΣ∈ empty = Σ-iso-ok (coe-equiv (Lift≡id ∙ ! ×𝟘-snd ∙ ×= idp (! Lift≡id)))
{Aᵉ = Lift𝟘ᵉ} ΣᵉLift𝟘-ok
Σᵉ-adq-exploreΣ∈ (leaf x₁) F = ! Σ𝟙-snd ∙ Σ-fst≃ (≃-sym (Σx≡≃𝟙 x₁)) F
Σᵉ-adq-exploreΣ∈ (fork xs xs₁) = Σ-iso-ok (coe-equiv (! Σ⊎-split)) {Aᵉ = exploreΣ∈ xs ⊎ᵉ exploreΣ∈ xs₁}
(Σᵉ⊎-ok {eᴬ = exploreΣ∈ xs}{eᴮ = exploreΣ∈ xs₁} (Σᵉ-adq-exploreΣ∈ xs) (Σᵉ-adq-exploreΣ∈ xs₁))
module _ {{_ : UA}}{{_ : FunExt}}{A : ★ ₀}{P : A → ★ _}(explore-P : ∀ {m} x → Explore m (P x)) where
open import Explore.Zero
open import Explore.Sum
open import Explore.Isomorphism
exploreAny : ∀ {m} xs → Explore m (Any P xs)
exploreAny empty = Lift𝟘ᵉ
exploreAny (leaf x) = explore-P x
exploreAny (fork xs xs₁) = exploreAny xs ⊎ᵉ exploreAny xs₁
module _ (Σᵉ-adq-explore-P : ∀ {m} x → Adequate-Σ {m} (Σᵉ (explore-P x))) where
Σᵉ-adq-exploreAny : ∀ {m} xs → Adequate-Σ {m} (Σᵉ (exploreAny xs))
Σᵉ-adq-exploreAny empty F = ! Σ𝟘-lift∘fst ∙ Σ-fst= (! Lift≡id) _
Σᵉ-adq-exploreAny (leaf x₁) F = Σᵉ-adq-explore-P x₁ F
Σᵉ-adq-exploreAny (fork xs xs₁) F = ⊎= (Σᵉ-adq-exploreAny xs _) (Σᵉ-adq-exploreAny xs₁ _) ∙ ! dist-⊎-Σ
exploreΣᵉ : ∀ {m} xs → Explore m (Σᵉ (fromBinTree xs) P)
exploreΣᵉ {m} xs = fromBinTree-ind xs (λ e → Explore m (Σᵉ e P)) Lift𝟘ᵉ _⊎ᵉ_ explore-P
module _ (Σᵉ-adq-explore-P : ∀ {m} x → Adequate-Σ {m} (Σᵉ (explore-P x))) where
Σᵉ-adq-exploreΣᵉ : ∀ {m} xs → Adequate-Σ {m} (Σᵉ (exploreΣᵉ xs))
Σᵉ-adq-exploreΣᵉ empty F = ! Σ𝟘-lift∘fst ∙ Σ-fst= (! Lift≡id) _
Σᵉ-adq-exploreΣᵉ (leaf x₁) F = Σᵉ-adq-explore-P x₁ F
Σᵉ-adq-exploreΣᵉ (fork xs xs₁) F = ⊎= (Σᵉ-adq-exploreΣᵉ xs _) (Σᵉ-adq-exploreΣᵉ xs₁ _) ∙ ! dist-⊎-Σ
data Path {a}{A : ★_ a} : BinTree A → ★_ a where
leaf : (x : A) → Path (leaf x)
left : {t u : BinTree A} (p : Path t) → Path (fork t u)
right : {t u : BinTree A} (p : Path u) → Path (fork t u)
path : ∀ {a}{A : ★ a} → BinTree A → ★₀
path empty = 𝟘
path (leaf x) = 𝟙
path (fork t u) = path t ⊎ path u
path' : ∀{a}{A : ★ a} → BinTree A → ★₀
path' t = fromBinTree t 𝟘 _⊎_ (const 𝟙)
-- -}
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.618116315,
"avg_line_length": 39.2525252525,
"ext": "agda",
"hexsha": "a1aaa18cc396400b37fa1cdcf5163bb142ab6b79",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/BinTree.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/BinTree.agda",
"max_line_length": 108,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/BinTree.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 1765,
"size": 3886
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Groups.Definition
open import Groups.Abelian.Definition
open import Setoids.Setoids
open import Rings.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Modules.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+R_ : A → A → A} {_*_ : A → A → A} (R : Ring S _+R_ _*_) {m n : _} {M : Set m} {T : Setoid {m} {n} M} {_+_ : M → M → M} {G' : Group T _+_} (G : AbelianGroup G') (_·_ : A → M → M) where
record Module : Set (a ⊔ b ⊔ m ⊔ n) where
field
dotWellDefined : {r s : A} {t u : M} → Setoid._∼_ S r s → Setoid._∼_ T t u → Setoid._∼_ T (r · t) (s · u)
dotDistributesLeft : {r : A} {x y : M} → Setoid._∼_ T (r · (x + y)) ((r · x) + (r · y))
dotDistributesRight : {r s : A} {x : M} → Setoid._∼_ T ((r +R s) · x) ((r · x) + (s · x))
dotAssociative : {r s : A} {x : M} → Setoid._∼_ T ((r * s) · x) (r · (s · x))
dotIdentity : {x : M} → Setoid._∼_ T ((Ring.1R R) · x) x
| {
"alphanum_fraction": 0.5385395538,
"avg_line_length": 51.8947368421,
"ext": "agda",
"hexsha": "2323a297c88f440dac644e59c4e2e730789995be",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Modules/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Modules/Definition.agda",
"max_line_length": 257,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Modules/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 423,
"size": 986
} |
{-# OPTIONS --safe --without-K #-}
open import Level using (_⊔_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; trans; subst₂)
open import Function using (_∘_)
open import Relation.Nullary.Negation using (contradiction)
module PiCalculus.Utils where
module ListInv {a} {A : Set a} where
open import Data.List as List using (List; []; _∷_; [_]; _++_)
import Data.List.Properties as Listₚ
import Data.List.Membership.Propositional.Properties as ∈ₚ
import Data.List.Relation.Unary.Any.Properties as Anyₚ
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.List.Membership.Propositional using (_∈_; _∉_)
open import Data.List.Relation.Binary.Equality.Propositional {A = A} using (_≋_; []; _∷_; ≋⇒≡; ≡⇒≋; ≋-refl)
inv-++ˡ' : ∀ lx ly {rx ry} s → s ∉ lx → s ∉ ly → lx ++ [ s ] ++ rx ≋ ly ++ [ s ] ++ ry → lx ≋ ly
inv-++ˡ' [] [] s ∉lx ∉ly eq = []
inv-++ˡ' [] (x ∷ ly) .x ∉lx ∉ly (refl ∷ eq) = contradiction (here refl) ∉ly
inv-++ˡ' (x ∷ lx) [] .x ∉lx ∉ly (refl ∷ eq) = contradiction (here refl) ∉lx
inv-++ˡ' (x ∷ lx) (.x ∷ ly) s ∉lx ∉ly (refl ∷ eq)
rewrite ≋⇒≡ (inv-++ˡ' lx ly s (∉lx ∘ there) (∉ly ∘ there) eq) = ≋-refl
inv-++ˡ : ∀ lx ly {rx ry} s → s ∉ lx → s ∉ ly → lx ++ [ s ] ++ rx ≡ ly ++ [ s ] ++ ry → lx ≡ ly
inv-++ˡ lx ly s ∉lx ∉ly = ≋⇒≡ ∘ inv-++ˡ' lx ly s ∉lx ∉ly ∘ ≡⇒≋
inv-++ʳ : ∀ lx ly {rx ry} s → s ∉ rx → s ∉ ry → lx ++ [ s ] ++ rx ≡ ly ++ [ s ] ++ ry → rx ≡ ry
inv-++ʳ lx ly {rx} {ry} s ∉rx ∉ry
= Listₚ.reverse-injective
∘ inv-++ˡ (List.reverse rx) (List.reverse ry) s (∉rx ∘ Anyₚ.reverse⁻) (∉ry ∘ Anyₚ.reverse⁻)
∘ subst₂ _≡_ (do-reverse lx _) (do-reverse ly _)
∘ cong List.reverse
where do-reverse : ∀ (lx rx : List A) {s}
→ List.reverse (lx ++ [ s ] ++ rx) ≡ List.reverse rx ++ [ s ] ++ List.reverse lx
do-reverse lx rx {s} = trans (Listₚ.reverse-++-commute lx _)
(trans (cong (_++ List.reverse lx) (Listₚ.unfold-reverse s rx))
(Listₚ.++-assoc (List.reverse rx) _ _))
| {
"alphanum_fraction": 0.5520833333,
"avg_line_length": 51.512195122,
"ext": "agda",
"hexsha": "0b80e4c416d56691f7c308b956144d4c1c27152d",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/Utils.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/Utils.agda",
"max_line_length": 109,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/Utils.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 808,
"size": 2112
} |
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
data ⊤ : Set where tt : ⊤
id : ⊤ → ⊤
id tt = tt
data Foo : ⊤ → Set where
foo : {x : ⊤} → Foo (id x)
test : {x : Σ ⊤ Foo} → Set
test {x₁ , x₂} = {!x₂!}
| {
"alphanum_fraction": 0.4866920152,
"avg_line_length": 14.6111111111,
"ext": "agda",
"hexsha": "eb2a29714609ef94911083b0387fb2721512163e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue1006.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1006.agda",
"max_line_length": 44,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1006.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 117,
"size": 263
} |
module Issue639 where
postulate A : Set
| {
"alphanum_fraction": 0.7804878049,
"avg_line_length": 10.25,
"ext": "agda",
"hexsha": "bb7f75214095842b30fca5b775558349ec034be9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue639.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue639.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue639.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 11,
"size": 41
} |
{-# OPTIONS --enable-prop #-}
data _≡P_ {A : Set} (x : A) : A → Prop where
refl : x ≡P x
J-P : {A : Set} (x : A) (P : (y : A) → x ≡P y → Set)
→ P x refl → (y : A) (e : x ≡P y) → P y e
J-P x P p .x refl = p
| {
"alphanum_fraction": 0.4205607477,
"avg_line_length": 23.7777777778,
"ext": "agda",
"hexsha": "ae1ed31848b14ee0dc2a26f9d3fc683a1419ef5b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/eagda",
"max_forks_repo_path": "test/Fail/Prop-EqNoEliminator.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "asr/eagda",
"max_issues_repo_path": "test/Fail/Prop-EqNoEliminator.agda",
"max_line_length": 52,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/eagda",
"max_stars_repo_path": "test/Fail/Prop-EqNoEliminator.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 103,
"size": 214
} |
module DuplicateConstructors where
data D : Set where
c : D
c : D
f : D -> D
f c = c
| {
"alphanum_fraction": 0.597826087,
"avg_line_length": 9.2,
"ext": "agda",
"hexsha": "460680c0fd14bd4cf7e719ec1bd463d5829cf37f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/DuplicateConstructors.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/DuplicateConstructors.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/DuplicateConstructors.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 34,
"size": 92
} |
-- Home to all functions creating, modifying or removing ScopeEnv or ScopeState
module ScopeState where
open import Data.List using (List) renaming ([] to emptyList ; map to listMap ; _∷_ to _cons_)
open import Data.String renaming (_++_ to _then_)
open import Data.Bool
open import Data.Nat
open import Data.Fin renaming (zero to fzero ; suc to fsuc) hiding (_+_)
open import Relation.Binary.PropositionalEquality
open import Data.Maybe renaming (map to maybemap) hiding (monad)
open import ParseTree
open import Data.List.Properties
open import Data.Vec hiding (_>>=_) renaming (lookup to veclookup)
open import Category.Monad.State
open import Data.Product hiding (map)
open import Data.Sum hiding (map)
open import Data.Empty
open import Relation.Nullary
open import Category.Monad
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality.TrustMe
open import Data.Unit
open import AgdaHelperFunctions
open import Data.Nat.Show
import IO.Primitive as Prim
open import ParseTreeOperations
data ScopeType : Set where
funcDef : ScopeType
moduleDef : (name : Identifier) -> ScopeType
addFuncToModule : ScopeType
addVariableToType : ScopeType
topLevel : ScopeType
data Scope (maxVars : ℕ) (maxScopes : ℕ): Set where
mkScope : (scopeType : ScopeType) ->
(enclosing : Maybe (Fin maxScopes)) -> -- Nothing if this is the top scope
(declaredVars : List (Fin maxVars)) -> -- the list of variables declared in this scope
Scope maxVars maxScopes
getType : {m n : ℕ} -> Scope m n -> ScopeType
getType (mkScope scopeType enclosing declaredVars) = scopeType
--appendToDeclared : {m n : ℕ} -> Fin m -> Scope m n -> Scope m n
--appendToDeclared what (mkScope scopeType enclosing declaredVars) =
-- mkScope scopeType enclosing (what cons declaredVars)
getDeclared : {m n : ℕ} -> Scope m n -> List (Fin m)
getDeclared (mkScope scopeType enclosing declaredVars) = declaredVars
data ScopeEnv : Set where
env : {numVars : ℕ} ->
(vars : Vec String numVars) ->
(maxScopes : ℕ) ->
(scopes : Vec (Scope numVars maxScopes) maxScopes ) ->
(current : Fin maxScopes) ->
ScopeEnv
ScopeState : Set -> Set
ScopeState = StateT (ScopeEnv) (λ x -> Prim.IO (String ⊎ x))
--open RawMonadState (StateTMonadState ScopeEnv {M = IOStringError} EitherOverIO) public
liftIO : {a : Set} -> Prim.IO a -> ScopeState a
liftIO action e = do
a <- action
return (inj₂ (a , e))
where open RawMonad IOMonad
runScopeState : {a : Set} -> ScopeState a -> ScopeEnv -> Prim.IO (String ⊎ a)
runScopeState s e = do
inj₂ ( result , e) <- s e
where inj₁ e -> return $ inj₁ e
return $ inj₂ result
where open RawMonad IOMonad -- brings return and bind for the Prim.IO monad into scope
fail : {a : Set} -> String -> ScopeState a
fail message = λ x -> Prim.return $ inj₁ message
-- Try an action and return an error message on failure rather than
-- propagating the failure. All state changes are rolled back.
try : {a : Set} -> ScopeState a -> ScopeState (String ⊎ a)
try st environment = do
inj₂ (x , newEnv) <- st environment
where inj₁ error -> return $ inj₂ $ inj₁ error , environment
return $ inj₂ $ inj₂ x , newEnv
where open RawMonad IOMonad
open RawMonadState (StateTMonadState ScopeEnv (SumMonadT IOMonad String)) public
newEnv : ScopeEnv
newEnv = env [] 1 ((mkScope topLevel nothing emptyList) ∷ []) fzero
-- Variable adding
newRaise : {n : ℕ} -> Fin n -> Fin (1 + n)
newRaise fzero = fzero
newRaise (fsuc f) = fsuc (newRaise f)
raiseScopeType : {n m : ℕ} -> Scope n m -> Scope (1 + n) m
raiseScopeType (mkScope t s declared) = mkScope t s (listMap newRaise declared)
raiseType : {n m : ℕ} -> (x : Scope n m) -> getType x ≡ getType (raiseScopeType x)
raiseType (mkScope scopeType enclosing declaredVars) = refl
mapRaiseType : {n m o : ℕ} -> (x : Vec (Scope n m) o) -> (curr : Fin o)
-> getType (veclookup curr x) ≡ getType (veclookup curr (map raiseScopeType x))
mapRaiseType (x ∷ xs) fzero with veclookup fzero (x ∷ xs)
... | c = raiseType c
mapRaiseType (x ∷ xs) (fsuc curr) = mapRaiseType xs curr
addVarToScope : {n m : ℕ} -> (Scope n m) -> (what : Fin (1 + n))
-> (Scope (1 + n) m)
addVarToScope (mkScope scopeType enclosing declaredVars) what =
mkScope scopeType enclosing (what cons (listMap newRaise declaredVars))
addVar : {n m numScopes : ℕ}(xs : Vec (Scope n m) numScopes) ->
(atPos : Fin numScopes) -> (what : Fin (1 + n)) ->
Vec (Scope (1 + n) m) numScopes
addVar (x ∷ xs) fzero what = addVarToScope x what ∷ map raiseScopeType xs
addVar (x ∷ xs) (fsuc atPos) what = raiseScopeType x ∷ addVar xs atPos what
addExistingVarToScope : {n m : ℕ} -> (Scope n m) -> (what : Fin n)
-> (Scope n m)
addExistingVarToScope (mkScope scopeType enclosing declaredVars) what =
mkScope scopeType enclosing (what cons declaredVars)
addExistingVar : {n m numScopes : ℕ}(xs : Vec (Scope n m) numScopes) ->
(atPos : Fin numScopes) -> (what : Fin n) ->
Vec (Scope n m) numScopes
addExistingVar [] () what
addExistingVar (x ∷ xs) fzero what = (addExistingVarToScope x what) ∷ xs
addExistingVar (x ∷ xs) (fsuc atPos) what = x ∷ addExistingVar xs atPos what
-- returns input identifier with id and scope id filled in
addIdentifier : Identifier -> ScopeState Identifier
addIdentifier (identifier name isInRange scope declaration {b}{c} {c2}) = do
env {numVars} vars maxScopes scopes current <- get
let newScopes = (addVar scopes current (fromℕ numVars))
put (env (vars ∷ʳ name) maxScopes
newScopes
current)
return (identifier name isInRange (toℕ current) numVars {b}{c} {c2})
raiseEnclosingScope : {maxVars maxScopes : ℕ} -> Scope maxVars maxScopes
-> Scope maxVars (1 + maxScopes)
raiseEnclosingScope (mkScope scopeType enclosing declaredVars) =
mkScope scopeType (maybemap newRaise enclosing) declaredVars
addScope : (b : ScopeType) -> ScopeState ℕ
addScope scopeType = do
env vars maxScopes scopes current <- get
let newScopes = map raiseEnclosingScope scopes ∷ʳ
mkScope scopeType
(just (newRaise current)) emptyList
put (env vars (1 + maxScopes)
newScopes
(fromℕ maxScopes)
)
return maxScopes
castCurrent : {n m : ℕ} -> {A : Set} -> Vec A n -> Fin m -> ScopeState (Fin n)
castCurrent [] x = fail "Something went wrong with scope saving"
castCurrent (x ∷ vec) fzero = return fzero
castCurrent (x ∷ vec) (fsuc f) = do
r <- castCurrent vec f
return (fsuc r)
saveAndReturnToScope : {A : Set} -> ScopeState A -> ScopeState A
saveAndReturnToScope ss = do
env vars maxScopes scopes current <- get
c <- ss
env vars₁ maxScopes₁ scopes₁ current₁ <- get
newCurr <- castCurrent scopes₁ current
let newEnv = env vars₁ maxScopes₁ scopes₁ newCurr
put newEnv
return c
setScope : (n : ℕ) -> ScopeState ℕ
setScope n (env vars maxScopes scopes current) with suc n Data.Nat.≤? maxScopes
setScope n (env vars maxScopes scopes current) | yes p = return n (env vars maxScopes scopes (fromℕ≤ p)) --inj₂ (n , (env vars maxScopes scopes (fromℕ≤ p)))
setScope n e | no ¬p = Prim.return $ inj₁ "Tried to set scope to invalid value" --inj₁ "Tried to set scope to invalid value"
filter : {A : Set} -> (A -> Bool) -> List A -> List A
filter f emptyList = emptyList
filter f (x cons l) = if (f x) then (x cons (filter f l)) else filter f l
-- this is the lookup function from Schäfer's algorithm
-- TODO: Simple dummy function, does not sufficiently reflect real
-- scoping rules
-- TODO: Agda does not understand that this terminates because
-- the fact that the enclosing scope must be farther to the front of
-- the scopes list is not encoded in the type yet
-- returns the declaration id the input string
{-# TERMINATING #-}
lookup : String -> ScopeState ℕ
lookup s = saveAndReturnToScope (do
env vars maxScopes scopes current <- get
mkScope scopeType enclosing decl <- return (veclookup current scopes)
emptyList <- return ( filter (λ x -> veclookup x vars == s) decl)
where x cons xs -> return (toℕ x)
just n <- return enclosing
where _ -> fail $ "There is no enclosing scope while looking up: " then s
setScope (toℕ n)
lookup s)
-- fill in the declaration and scope information in an identifier
-- given that the name has already been declared
fillInIdentifier : Identifier -> ScopeState Identifier
fillInIdentifier (identifier name isInRange scope declaration {b}{c} {c2}) = do
x <- saveAndReturnToScope (lookup name)
suc n <- return x
where zero -> fail ("Identifier not found in file: " then name)
env vars maxScopes scopes current <- get
return (identifier name isInRange (toℕ current) (suc n) {b}{c} {c2})
-- at the place where something is declared, you can only use simple names.
-- TODO: Actually, this should be adequately bounded by the current scope. But how to implement?
access : Identifier -> ScopeState Identifier
access (identifier name isInRange scope declaration {b}{c} {c2}) = do
env {numVars} vars maxScopes scopes current <- get
yes p <- return (suc declaration Data.Nat.≤? numVars)
where _ -> fail "Parse tree scoping has produced a nonsense declaration"
let newName = veclookup (fromℕ≤ p) vars
anything <- setScope scope
identifier n r s d <- fillInIdentifier (identifier newName isInRange scope declaration {b}{c} {c2})
yes x <- return (d Data.Nat.≟ declaration)
where no y -> fail "Could not perform name change because this would change the meaning of the code"
return (identifier n r s d {b}{c} {c2})
mapState : {A B : Set} -> (A -> ScopeState B) -> List A -> ScopeState (List B)
mapState f emptyList = return emptyList
mapState f (x cons list) = do
x1 <- f x
xs <- mapState f list
return (x1 cons xs)
addContentReferenceToModuleTop : TypeSignature -> ScopeState ℕ
addContentReferenceToModuleTop (typeSignature (identifier name isInRange scope 0) funcType) = fail "Trying to add signature which has not been scoped"
addContentReferenceToModuleTop (typeSignature (identifier name isInRange scope declaration) funcType) = do
env {numVars } vars maxScopes scopes current <- get
yes p <- return (suc declaration Data.Nat.≤? numVars)
where _ -> fail "Found messed-up scoping"
let newScopes = addExistingVar scopes current (fromℕ≤ p)
return declaration
_after_ : {A B C : Set} -> (B -> ScopeState C) -> (A -> ScopeState B) -> A -> ScopeState C
_after_ f g x = do
prelim <- g x
f prelim
getNameForId : ℕ -> ScopeState String
getNameForId n = do
env {numVars } vars maxScopes scopes current <- get
yes p <- return (suc n Data.Nat.≤? numVars)
where _ -> fail "Can't get name for this invalid identifier"
let r = veclookup (fromℕ≤ p) vars
return r
replaceName : {A : Set} -> {n : ℕ} -> Fin n -> A -> Vec A n -> Vec A n
replaceName fzero a (x ∷ list) = a ∷ list
replaceName (fsuc n) a (x ∷ list) = x ∷ replaceName n a list
replaceID : ℕ -> String -> ScopeState String
replaceID which newName = do
env {numVars} vars maxScopes scopes current <- get
yes p <- return (suc which Data.Nat.≤? numVars)
where _ -> fail "Can't rename this invalid identifier"
let newList = replaceName (fromℕ≤ p) newName vars
put (env {numVars } newList maxScopes scopes current)
return newName
currentScopeTypeIsFuncDef : ScopeState Bool
currentScopeTypeIsFuncDef = do
env {numVars } vars maxScopes scopes current <- get
mkScope funcDef enclosing declaredVars <- return (veclookup current scopes)
where _ -> fail "This is not the scope type you expected"
return true
isNameInUse : String -> ScopeState Bool
isNameInUse s = do
env vars maxScopes scopes current <- get
return $ Data.List.any (λ x -> x == s) (Data.Vec.toList vars)
-- terminates because vars is not infinite.
{-# TERMINATING #-}
makeUniqueName : ℕ -> ScopeState String
makeUniqueName n = do
let proposedName = Data.String.concat $ "renameMe" Data.List.∷ (Data.Nat.Show.show n) Data.List.∷ emptyList
b <- isNameInUse proposedName
if b
then makeUniqueName $ suc n
else return proposedName
getUniqueIdentifierWithInScope : Bool -> ScopeState Identifier
getUniqueIdentifierWithInScope b = do
name <- makeUniqueName 0
id <- addIdentifier $ identifier name (λ _ -> before) 0 0 {b}{emptyList} {emptyList}
return id
getUniqueIdentifier : ScopeState Identifier
getUniqueIdentifier = getUniqueIdentifierWithInScope true
| {
"alphanum_fraction": 0.7032683948,
"avg_line_length": 40.2006472492,
"ext": "agda",
"hexsha": "d9465136f710684bf72da91d4b918141f58da01a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/ScopeState.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/ScopeState.agda",
"max_line_length": 156,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/ScopeState.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 3544,
"size": 12422
} |
{-
Copyright 2019 Lisandra Silva
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}
open import Prelude
open import Relation.Binary.HeterogeneousEquality
using (_≅_)
renaming (cong to ≅-cong; refl to ≅-refl)
open import StateMachineModel
module Examples.SMCounter where
data MyEvent : Set where
inc : MyEvent
inc2 : MyEvent
data MyEnabled : MyEvent → ℕ → Set where
tt : ∀ {e} {n} → MyEnabled e n
MyEventSet : EventSet {Event = MyEvent}
MyEventSet inc = ⊤
MyEventSet inc2 = ⊤
MyAction : {preSt : ℕ} {ev : MyEvent} → MyEnabled ev preSt → ℕ
MyAction {preSt} {inc} enEv = suc preSt
MyAction {preSt} {inc2} enEv = suc (suc preSt)
data MyWeakFairness : EventSet → Set where
w0 : MyWeakFairness MyEventSet
-- Another way of modelling the WeakFairness
MyWeakFairness2 : EventSet {Event = MyEvent} → Set
MyWeakFairness2 MyEventSet = ⊤
MyStateMachine : StateMachine ℕ MyEvent
MyStateMachine = record { initial = 2 ≡_
; enabled = MyEnabled
; action = MyAction }
mySystem : System ℕ MyEvent
mySystem = record { stateMachine = MyStateMachine
; weakFairness = MyWeakFairness }
myInvariant : Invariant MyStateMachine (2 ≤_)
myInvariant (init x) = ≤-reflexive x
myInvariant (step {ps} {inc} rs enEv) = ≤-stepsˡ 1 (myInvariant rs)
myInvariant (step {ps} {inc2} rs enEv) = ≤-stepsˡ 2 (myInvariant rs)
open LeadsTo ℕ MyEvent mySystem
-- A state equals to n leads to a state equals to (1 + n) or equals to (2 + n)
progressDumb : ∀ {n : ℕ} → (n ≡_) l-t ((1 + n ≡_) ∪ (2 + n ≡_))
progressDumb = viaEvSet MyEventSet w0
( λ { inc ⊤ → hoare λ { refl enEv → inj₁ refl}
; inc2 ⊤ → hoare λ { refl enEv → inj₂ refl} })
( λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt)} )
λ rs n≡s → inc , tt , tt
n<m+n : ∀ {n m} → 0 < m → n < m + n
n<m+n {zero} {suc m} x = s≤s z≤n
n<m+n {suc n} {suc m} x = s≤s (m≤n+m (suc n) m)
progress-< : ∀ n → (n ≡_) l-t (n <_)
progress-< n = viaTrans
progressDumb
(viaInv (λ { rs (inj₁ refl) → s≤s ≤-refl
; rs (inj₂ refl) → s≤s (m≤n+m n 1)}))
{- A predicate on states, parameterized by m (target). The d parameter is the
"distance" from the target m from state s.
QUESTION : We are generalizing Z to be of a given type, however in myWFR
we are using it knowing that is ℕ because we apply _≡_ and _+_
-}
F : ∀ {m} → ℕ → Z → Set
F {m} d s = m ≡ d + s
wfr-1 : ∀ {m} → (s : Z) → (m ≤ s) ⊎ ∃[ x ] F {m} x s
wfr-1 {m} s with m ≤? s
... | yes yy = inj₁ yy
... | no s<m = inj₂ (m ∸ s , sym (m∸n+n≡m (≰⇒≥ s<m)) )
progress-1st : ∀ {n m} → (n ≡_) l-t ( (m ≤_) ∪ [∃ x ∶ F {m} x ] )
progress-1st {n} {m} = viaInv (λ {s} rs n≡s → wfr-1 s)
-- A state which distance to m is 0 (if we are in the state m)
-- leads to a state greater than m
progress-d0 : ∀ {m} → F {m} 0 l-t ( (m ≤_) ∪ [∃ x ⇒ _< 0 ∶ F {m} x ] )
progress-d0 {m} = viaInv (λ { {s} rs refl → inj₁ ≤-refl })
progress-d1 : ∀ {m} → F {m} 1 l-t ((m ≤_) ∪ [∃ x ⇒ _< 1 ∶ F {m} x ] )
progress-d1 {m} =
viaEvSet
MyEventSet
w0
(λ { inc ⊤ → hoare (λ { refl _ → inj₁ ≤-refl })
; inc2 ⊤ → hoare (λ { refl _ → inj₁ (≤-step ≤-refl) })
})
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt)
})
λ _ _ → inc , tt , tt
progress-d2 : ∀ {m w} → F {m} (2 + w) l-t ( (m ≤_) ∪ [∃ x ⇒ _< (2 + w) ∶ F {m} x ] )
progress-d2 {m} {w} =
viaEvSet
MyEventSet
w0
(λ { inc ⊤ → hoare λ { {ps} refl _
→ inj₂ (suc w , ≤-refl , cong suc (sym (+-suc w ps)) )}
; inc2 ⊤ → hoare λ { {ps} refl _
→ inj₂ (w , ≤-step ≤-refl , sym (trans (+-suc w (suc ps))
(cong suc (+-suc w ps)))) }
})
(λ { inc ⊥ → ⊥-elim (⊥ tt)
; inc2 ⊥ → ⊥-elim (⊥ tt) })
λ _ _ → inc , tt , tt
progress-2nd : ∀ {m w}
→ F {m} w
l-t
((m ≤_) ∪ [∃ x ⇒ _< w ∶ F {m} x ] )
progress-2nd {m} {zero} = progress-d0
progress-2nd {m} {suc zero} = progress-d1
progress-2nd {m} {suc (suc w)} = progress-d2
-- A state equals to n leads to a state greater or equal to m, ∀ m.
-- In other words, from n we can go to every possible state m steps
-- away from n
progress : ∀ {n m : ℕ} → (n ≡_) l-t (m ≤_)
progress {n} {m} = viaWFR (F {m})
progress-1st
λ w → progress-2nd
| {
"alphanum_fraction": 0.5171889839,
"avg_line_length": 31.5269461078,
"ext": "agda",
"hexsha": "776aa489bbe5402c79dbc7305155179365108f45",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "lisandrasilva/agda-liveness",
"max_forks_repo_path": "src/Examples/SMCounter.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "lisandrasilva/agda-liveness",
"max_issues_repo_path": "src/Examples/SMCounter.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "lisandrasilva/agda-liveness",
"max_stars_repo_path": "src/Examples/SMCounter.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1856,
"size": 5265
} |
module Prelude.Strict where
open import Prelude.Equality
open import Agda.Builtin.Strict
force : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) → (∀ x → B x) → B x
force x f = primForce x f
force′ : ∀ {a b} {A : Set a} {B : A → Set b} → (x : A) → (∀ y → x ≡ y → B y) → B x
force′ x k = (force x λ y → k y) refl
forceLemma = primForceLemma
{-# INLINE force #-}
{-# DISPLAY primForce = force #-}
{-# DISPLAY primForceLemma = forceLemma #-}
seq : ∀ {a b} {A : Set a} {B : Set b} → A → B → B
seq x y = force x (λ _ → y)
{-# INLINE seq #-}
infixr 0 _$!_
_$!_ : ∀ {a b} {A : Set a} {B : A → Set b} → (∀ x → B x) → ∀ x → B x
f $! x = force x f
{-# INLINE _$!_ #-}
| {
"alphanum_fraction": 0.5104477612,
"avg_line_length": 22.3333333333,
"ext": "agda",
"hexsha": "f69efe7cc71a2940946fd324a0961460e6f927ec",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Prelude/Strict.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "t-more/agda-prelude",
"max_issues_repo_path": "src/Prelude/Strict.agda",
"max_line_length": 82,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Prelude/Strict.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 259,
"size": 670
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Graph where
open import Cubical.Data.Graph.Base public
open import Cubical.Data.Graph.Examples public
| {
"alphanum_fraction": 0.7701149425,
"avg_line_length": 29,
"ext": "agda",
"hexsha": "f6abd9cb0788fd46c055eb1a38e956a17de66212",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Graph.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/Graph.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Graph.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 40,
"size": 174
} |
------------------------------------------------------------------------
-- The partiality monad's monad instance
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module Partiality-monad.Inductive.Monad where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
import Monad
open import Prelude hiding (⊥)
open import Bijection equality-with-J using (_↔_)
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
as Trunc hiding (_>>=′_)
open import Nat equality-with-J as Nat
open import Univalence-axiom equality-with-J
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Alternative-order
open import Partiality-monad.Inductive.Eliminators
open import Partiality-monad.Inductive.Monotone
open import Partiality-monad.Inductive.Omega-continuous
open [_⊥→_⊥]
------------------------------------------------------------------------
-- The monad instance
-- Functions of type A → B ⊥ can be lifted to /ω-continuous/ functions
-- from A ⊥ to B ⊥.
private
=<<-args : ∀ {a b} {A : Type a} {B : Type b}
(f : A → B ⊥) → Arguments-nd b b A
=<<-args {B = B} f = record
{ P = B ⊥
; Q = _⊑_
; pe = never
; po = f
; pl = λ _ → ⨆
; pa = λ _ _ → antisymmetry
; ps = ⊥-is-set
; qr = λ _ → ⊑-refl
; qt = λ _ _ _ _ _ → ⊑-trans
; qe = λ _ → never⊑
; qu = λ _ → upper-bound
; ql = λ _ _ _ → least-upper-bound
; qp = λ _ _ → ⊑-propositional
}
infix 50 _∗ _∗-inc_
_∗ : ∀ {a b} {A : Type a} {B : Type b} →
(A → B ⊥) → [ A ⊥→ B ⊥]
f ∗ = record
{ monotone-function = record
{ function = ⊥-rec-nd (=<<-args f)
; monotone = ⊑-rec-nd (=<<-args f)
}
; ω-continuous = λ s →
⊥-rec-nd (=<<-args f) (⨆ s) ≡⟨ ⊥-rec-nd-⨆ (=<<-args f) s ⟩∎
⨆ (inc-rec-nd (=<<-args f) s) ∎
}
_∗-inc_ : ∀ {a b} {A : Type a} {B : Type b} →
(A → B ⊥) → Increasing-sequence A → Increasing-sequence B
_∗-inc_ f = inc-rec-nd (=<<-args f)
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ : ∀ {a b} {A : Type a} {B : Type b} →
A ⊥ → (A → B ⊥) → B ⊥
x >>=′ f = function (f ∗) x
-- Join.
join : ∀ {a} {A : Type a} → A ⊥ ⊥ → A ⊥
join x = x >>=′ id
-- "Computation" rules for bind.
never->>= : ∀ {a b} {A : Type a} {B : Type b} {f : A → B ⊥} →
never >>=′ f ≡ never
never->>= = ⊥-rec-nd-never (=<<-args _)
now->>= : ∀ {a b} {A : Type a} {B : Type b} {f : A → B ⊥} {x} →
now x >>=′ f ≡ f x
now->>= = ⊥-rec-nd-now (=<<-args _) _
⨆->>= : ∀ {a b} {A : Type a} {B : Type b} {f : A → B ⊥} {s} →
⨆ s >>=′ f ≡ ⨆ (f ∗-inc s)
⨆->>= = ⊥-rec-nd-⨆ (=<<-args _) _
-- Bind is monotone.
infixl 5 _>>=-mono_
_>>=-mono_ :
∀ {a b} {A : Type a} {B : Type b} {x y : A ⊥} {f g : A → B ⊥} →
x ⊑ y → (∀ z → f z ⊑ g z) → x >>=′ f ⊑ y >>=′ g
_>>=-mono_ {x = x} {y} {f} {g} x⊑y f⊑g =
x >>=′ f ⊑⟨ monotone (f ∗) x⊑y ⟩
y >>=′ f ⊑⟨ ⊥-rec-⊥ (record
{ P = λ y → y >>=′ f ⊑ y >>=′ g
; pe = never >>=′ f ≡⟨ never->>= ⟩⊑
never ⊑⟨ never⊑ _ ⟩■
never >>=′ g ■
; po = λ x →
now x >>=′ f ≡⟨ now->>= ⟩⊑
f x ⊑⟨ f⊑g x ⟩
g x ≡⟨ sym now->>= ⟩⊑
now x >>=′ g ■
; pl = λ s ih →
⨆ s >>=′ f ≡⟨ ⨆->>= ⟩⊑
⨆ (f ∗-inc s) ⊑⟨ ⨆-mono ih ⟩
⨆ (g ∗-inc s) ≡⟨ sym ⨆->>= ⟩⊑
⨆ s >>=′ g ■
; pp = λ _ → ⊑-propositional
})
y ⟩
y >>=′ g ■
-- Instances of the monad laws with extra universe polymorphism.
module Monad-laws where
left-identity : ∀ {a b} {A : Type a} {B : Type b} x (f : A → B ⊥) →
now x >>=′ f ≡ f x
left-identity _ _ = now->>=
right-identity : ∀ {a} {A : Type a} (x : A ⊥) →
x >>=′ now ≡ x
right-identity = ⊥-rec-⊥
(record
{ pe = never >>=′ now ≡⟨ never->>= ⟩∎
never ∎
; po = λ x →
now x >>=′ now ≡⟨ now->>= ⟩∎
now x ∎
; pl = λ s hyp →
⨆ s >>=′ now ≡⟨ ⨆->>= ⟩
⨆ (now ∗-inc s) ≡⟨ cong ⨆ (_↔_.to equality-characterisation-increasing λ n →
s [ n ] >>=′ now ≡⟨ hyp n ⟩∎
s [ n ] ∎) ⟩∎
⨆ s ∎
; pp = λ _ → ⊥-is-set
})
associativity : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(x : A ⊥) (f : A → B ⊥) (g : B → C ⊥) →
x >>=′ (λ x → f x >>=′ g) ≡ x >>=′ f >>=′ g
associativity x f g = ⊥-rec-⊥
(record
{ pe = (never >>=′ λ x → f x >>=′ g) ≡⟨ never->>= ⟩
never ≡⟨ sym never->>= ⟩
never >>=′ g ≡⟨ cong (_>>=′ g) $ sym never->>= ⟩∎
never >>=′ f >>=′ g ∎
; po = λ x →
(now x >>=′ λ x → f x >>=′ g) ≡⟨ now->>= ⟩
f x >>=′ g ≡⟨ cong (_>>=′ g) $ sym now->>= ⟩∎
now x >>=′ f >>=′ g ∎
; pl = λ s hyp →
(⨆ s >>=′ λ x → f x >>=′ g) ≡⟨ ⨆->>= ⟩
⨆ ((λ x → f x >>=′ g) ∗-inc s) ≡⟨ cong ⨆ (_↔_.to equality-characterisation-increasing λ n →
s [ n ] >>=′ (λ x → f x >>=′ g) ≡⟨ hyp n ⟩∎
s [ n ] >>=′ f >>=′ g ∎) ⟩
⨆ (g ∗-inc (f ∗-inc s)) ≡⟨ sym ⨆->>= ⟩
⨆ (f ∗-inc s) >>=′ g ≡⟨ cong (_>>=′ g) (sym ⨆->>=) ⟩∎
⨆ s >>=′ f >>=′ g ∎
; pp = λ _ → ⊥-is-set
})
x
open Monad equality-with-J hiding (map; map-id; map-∘)
instance
-- The partiality monad's monad instance.
partiality-raw-monad : ∀ {ℓ} → Raw-monad (_⊥ {a = ℓ})
Raw-monad.return partiality-raw-monad = now
Raw-monad._>>=_ partiality-raw-monad = _>>=′_
partiality-monad : ∀ {ℓ} → Monad (_⊥ {a = ℓ})
Monad.raw-monad partiality-monad = partiality-raw-monad
Monad.left-identity partiality-monad = Monad-laws.left-identity
Monad.right-identity partiality-monad = Monad-laws.right-identity
Monad.associativity partiality-monad = Monad-laws.associativity
------------------------------------------------------------------------
-- _⊥ is a functor
map : ∀ {a b} {A : Type a} {B : Type b} →
(A → B) → [ A ⊥→ B ⊥]
map f = (return ∘ f) ∗
map-id : ∀ {a} {A : Type a} →
map (id {A = A}) ≡ idω
map-id =
return ∗ ≡⟨ _↔_.to equality-characterisation-continuous (λ x →
x >>= return ≡⟨ right-identity x ⟩∎
x ∎) ⟩∎
idω ∎
map-∘ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
(f : B → C) (g : A → B) →
map (f ∘ g) ≡ map f ∘ω map g
map-∘ f g =
(now ∘ f ∘ g) ∗ ≡⟨ _↔_.to equality-characterisation-continuous (λ x →
x >>=′ (now ∘ f ∘ g) ≡⟨ cong (x >>=′_) (⟨ext⟩ λ _ → sym now->>=) ⟩
x >>=′ (λ x → now (g x) >>=′ (now ∘ f)) ≡⟨ Monad-laws.associativity x (now ∘ g) (now ∘ f) ⟩∎
x >>=′ (now ∘ g) >>=′ (now ∘ f) ∎) ⟩∎
(now ∘ f) ∗ ∘ω (now ∘ g) ∗ ∎
------------------------------------------------------------------------
-- Some properties
-- A kind of inversion lemma for _⇓_.
>>=-⇓ :
∀ {a b} {A : Type a} {B : Type b}
{x : A ⊥} {f : A → B ⊥} {y} →
(x >>=′ f ⇓ y) ≃ ∥ ∃ (λ z → x ⇓ z × f z ⇓ y) ∥
>>=-⇓ {x = x} {f} {y} = ⊥-rec-⊥
(record
{ P = λ x → (x >>=′ f ⇓ y) ≃ ∥ ∃ (λ z → x ⇓ z × f z ⇓ y) ∥
; pe = never >>=′ f ⇓ y ↝⟨ ≡⇒↝ _ (cong (_⇓ y) never->>=) ⟩
never ⇓ y ↝⟨ never⇓≃⊥ ⟩
Prelude.⊥ ↔⟨ inverse (not-inhabited⇒∥∥↔⊥ id) ⟩
∥ Prelude.⊥ ∥ ↔⟨ ∥∥-cong (inverse ×-right-zero) ⟩
∥ ∃ (λ z → ⊥₀) ∥ ↔⟨ ∥∥-cong (∃-cong (λ _ → inverse ×-left-zero)) ⟩
∥ ∃ (λ z → Prelude.⊥ × f z ⇓ y) ∥ ↝⟨ ∥∥-cong (∃-cong (λ _ → inverse never⇓≃⊥ ×-cong F.id)) ⟩□
∥ ∃ (λ z → never ⇓ z × f z ⇓ y) ∥ □
; po = λ x →
now x >>=′ f ⇓ y ↝⟨ ≡⇒↝ _ (cong (_⇓ y) now->>=) ⟩
f x ⇓ y ↔⟨ inverse (∥∥↔ ⊥-is-set) ⟩
∥ f x ⇓ y ∥ ↔⟨ ∥∥-cong (inverse $ drop-⊤-left-Σ $
_⇔_.to contractible⇔↔⊤ (other-singleton-contractible _)) ⟩
∥ ∃ (λ (p : ∃ (λ z → x ≡ z)) → f (proj₁ p) ⇓ y) ∥ ↔⟨ ∥∥-cong (inverse Σ-assoc) ⟩
∥ ∃ (λ z → x ≡ z × f z ⇓ y) ∥ ↔⟨ inverse $ Trunc.flatten′
(λ F → ∃ (λ _ → F (_ ≡ _) × _))
(λ f → Σ-map id (Σ-map f id))
(λ { (x , y , z) → ∥∥-map ((x ,_) ∘ (_, z)) y }) ⟩
∥ ∃ (λ z → ∥ x ≡ z ∥ × f z ⇓ y) ∥ ↝⟨ ∥∥-cong (∃-cong λ _ → inverse now≡now≃∥≡∥ ×-cong F.id) ⟩□
∥ ∃ (λ z → now x ⇓ z × f z ⇓ y) ∥ □
; pl = λ s ih →
⨆ s >>=′ f ⇓ y ↝⟨ ≡⇒↝ _ (cong (_⇓ y) ⨆->>=) ⟩
⨆ (f ∗-inc s) ⇓ y ↝⟨ ⨆⇓≃∥∃⇓∥ ⟩
∥ (∃ λ n → s [ n ] >>=′ f ⇓ y) ∥ ↝⟨ ∥∥-cong (∃-cong ih) ⟩
∥ (∃ λ n → ∥ ∃ (λ z → s [ n ] ⇓ z × f z ⇓ y) ∥) ∥ ↔⟨ Trunc.flatten′ (λ F → ∃ λ _ → F (∃ λ _ → _ × _))
(λ f → Σ-map id f)
(uncurry λ x → ∥∥-map (x ,_)) ⟩
∥ (∃ λ n → ∃ λ z → s [ n ] ⇓ z × f z ⇓ y) ∥ ↔⟨ ∥∥-cong ∃-comm ⟩
∥ (∃ λ z → ∃ λ n → s [ n ] ⇓ z × f z ⇓ y) ∥ ↔⟨ ∥∥-cong (∃-cong λ _ → Σ-assoc) ⟩
∥ (∃ λ z → (∃ λ n → s [ n ] ⇓ z) × f z ⇓ y) ∥ ↔⟨ inverse $ Trunc.flatten′
(λ F → (∃ λ _ → F (∃ λ _ → _ ⇓ _) × _))
(λ f → Σ-map id (Σ-map f id))
(λ { (x , y , z) → ∥∥-map ((x ,_) ∘ (_, z)) y }) ⟩
∥ (∃ λ z → ∥ (∃ λ n → s [ n ] ⇓ z) ∥ × f z ⇓ y) ∥ ↝⟨ ∥∥-cong (∃-cong λ _ → inverse ⨆⇓≃∥∃⇓∥ ×-cong F.id) ⟩□
∥ ∃ (λ z → ⨆ s ⇓ z × f z ⇓ y) ∥ □
; pp = λ _ → Eq.right-closure ext 0 truncation-is-proposition
})
x
-- □ is closed, in a certain sense, under bind.
□->>= :
∀ {a b p q}
{A : Type a} {B : Type b} {P : A → Type p} {Q : B → Type q}
{x : A ⊥} {f : A → B ⊥} →
(∀ x → Is-proposition (Q x)) →
□ P x → (∀ {x} → P x → □ Q (f x)) → □ Q (x >>=′ f)
□->>= {Q = Q} {x} {f} Q-prop □-x □-f y =
x >>=′ f ⇓ y ↔⟨ >>=-⇓ ⟩
∥ (∃ λ z → x ⇓ z × f z ⇓ y) ∥ ↝⟨ Trunc.rec (Q-prop y) (λ { (z , x⇓z , fz⇓y) → □-f (□-x z x⇓z) y fz⇓y }) ⟩□
Q y □
-- ◇ is closed, in a certain sense, under bind.
◇->>= :
∀ {a b p q}
{A : Type a} {B : Type b} {P : A → Type p} {Q : B → Type q}
{x : A ⊥} {f : A → B ⊥} →
◇ P x → (∀ {x} → P x → ◇ Q (f x)) → ◇ Q (x >>=′ f)
◇->>= {x = x} {f} ◇-x ◇-f = Trunc.rec
truncation-is-proposition
(λ { (y , x⇓y , Py) →
∥∥-map (λ { (z , fy⇓z , Qz) →
z
, (x >>=′ f ≡⟨ cong (_>>=′ f) x⇓y ⟩
now y >>=′ f ≡⟨ now->>= ⟩
f y ≡⟨ fy⇓z ⟩∎
now z ∎)
, Qz
})
(◇-f Py)
})
◇-x
-- Certain nested occurrences of ⨆ can be replaced by a single one.
⨆>>=⨆≡⨆>>= :
∀ {a b} {A : Type a} {B : Type b} →
∀ (s : Increasing-sequence A) (f : A → Increasing-sequence B)
{inc₁ inc₂} →
⨆ ((λ n → s [ n ] >>=′ ⨆ ∘ f) , inc₁) ≡
⨆ ((λ n → s [ n ] >>=′ λ y → f y [ n ]) , inc₂)
⨆>>=⨆≡⨆>>= s f = antisymmetry
(least-upper-bound _ _ λ n →
_≃_.to ≼≃⊑ $ λ z →
s [ n ] >>=′ ⨆ ∘ f ⇓ z ↔⟨ >>=-⇓ ⟩
∥ (∃ λ y → s [ n ] ⇓ y × ⨆ (f y) ⇓ z) ∥ ↔⟨ ∥∥-cong (∃-cong λ _ → F.id ×-cong ⨆⇓≃∥∃⇓∥) ⟩
∥ (∃ λ y → s [ n ] ⇓ y × ∥ (∃ λ m → f y [ m ] ⇓ z) ∥) ∥ ↔⟨ Trunc.flatten′
(λ F → ∃ λ _ → _ × F (∃ λ _ → _ ⇓ _))
(λ f → Σ-map id (Σ-map id f))
(λ { (y , p , q) → ∥∥-map ((y ,_) ∘ (p ,_)) q }) ⟩
∥ (∃ λ y → s [ n ] ⇓ y × ∃ λ m → f y [ m ] ⇓ z) ∥ ↔⟨ ∥∥-cong (∃-cong λ _ → ∃-comm) ⟩
∥ (∃ λ y → ∃ λ m → s [ n ] ⇓ y × f y [ m ] ⇓ z) ∥ ↝⟨ ∥∥-map (Σ-map id lemma) ⟩
∥ (∃ λ y → ∃ λ m → s [ m ] ⇓ y × f y [ m ] ⇓ z) ∥ ↔⟨ ∥∥-cong ∃-comm ⟩
∥ (∃ λ m → ∃ λ y → s [ m ] ⇓ y × f y [ m ] ⇓ z) ∥ ↔⟨ inverse $ Trunc.flatten′
(λ F → ∃ λ _ → F (∃ λ _ → _ × _))
(λ f → Σ-map id f)
(λ { (m , p) → ∥∥-map (m ,_) p }) ⟩
∥ (∃ λ m → ∥ (∃ λ y → s [ m ] ⇓ y × f y [ m ] ⇓ z) ∥) ∥ ↔⟨ ∥∥-cong (∃-cong λ _ → inverse $ >>=-⇓) ⟩
∥ (∃ λ m → (s [ m ] >>=′ λ y → f y [ m ]) ⇓ z) ∥ ↔⟨ inverse ⨆⇓≃∥∃⇓∥ ⟩□
⨆ ((λ m → s [ m ] >>=′ λ y → f y [ m ]) , _) ⇓ z □)
(⨆-mono λ n →
(s [ n ] >>=′ λ y → f y [ n ]) ⊑⟨ ⊑-refl (s [ n ]) >>=-mono (λ y → upper-bound (f y) n) ⟩■
(s [ n ] >>=′ ⨆ ∘ f) ■)
where
lemma :
∀ {n y z} →
(∃ λ m → s [ n ] ⇓ y × f y [ m ] ⇓ z) →
(∃ λ m → s [ m ] ⇓ y × f y [ m ] ⇓ z)
lemma {n} (m , p , q) with Nat.total m n
... | inj₁ m≤n = n
, p
, _≃_.from ≼≃⊑ (later-larger (f _) m≤n) _ q
... | inj₂ n≤m = m
, _≃_.from ≼≃⊑ (later-larger s n≤m) _ p
, q
| {
"alphanum_fraction": 0.3227300593,
"avg_line_length": 40.4435261708,
"ext": "agda",
"hexsha": "5ae4eac126e0badb0c52743ada20cc9e88cf8e42",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Inductive/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Inductive/Monad.agda",
"max_line_length": 128,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Inductive/Monad.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 5877,
"size": 14681
} |
postulate
F : Set₂ → Set₃
G : Set₁ → Set₂
H : Set₀ → Set₁
infix 1 F
infix 2 G
infix 3 H
syntax F x = ! x
syntax G x = # x
syntax H x = ! x
ok₁ : Set₀ → Set₂
ok₁ X = # ! X
ok₂ : Set₁ → Set₃
ok₂ X = ! # X
| {
"alphanum_fraction": 0.4813278008,
"avg_line_length": 12.6842105263,
"ext": "agda",
"hexsha": "f9028e70808995fe8a797d923532793c561e51ca",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1436-6.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1436-6.agda",
"max_line_length": 19,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1436-6.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 113,
"size": 241
} |
{-# OPTIONS --cubical #-}
module n2o.N2O where
open import proto.Base
open import proto.Core
open import proto.IO
open import n2o.Network.WebSocket
open import n2o.Network.Socket
open import n2o.Network.Core
open import n2o.Network.Internal
-- open import Infinity.Proto
postulate
terminationCheck : IO ⊤
{-# FOREIGN GHC
import Control.Concurrent (threadDelay)
terminationCheck :: IO ()
terminationCheck = do
putStrLn "sapere aude"
threadDelay 1000000
terminationCheck #-}
{-# COMPILE GHC terminationCheck = terminationCheck #-}
data Example : Set where
Greet : Example
-- index Init = do
-- updateText "system" "What is your name?"
-- wire record { id_ = "send" , postback = Just Greet, source = "name" ∷ [] }
-- index (Message Greet) = do
-- Just name ← get "name"
-- updateText "system" ("Hello, " <> jsEscape name)
index : Event Example → IO ⊤
index ev = putStrLn "Unknown event" -- TODO : monoids
about : Event Example → IO ⊤
about ev = putStrLn "Unknown event"
-- route : Context N2OProto Example → Context N2OProto Example
-- route c with (unpack (Request.reqPath (Context.cxRequest c)))
-- ... | "/ws/samples/static/index.html" = about
-- ... | "/ws/samples/static/about.html" = about
-- ... | _ = about
-- router : Context N2OProto Example → Context N2OProto Example
-- router c = record c { handler = mkHandler route }
-- protocols :
-- cx : Cx Example
-- cx = mkCx h r m p a d
-- where h = ?
-- r = ?
-- m = route ∷ []
-- p = []
-- a = ?
-- d = ?
main : IO ⊤
main = do
-- sock ← socket AF_INET Stream (+ 0)
hPutStrLn stdout "asd"
-- protoRun 0 protos
terminationCheck
putStrLn "[*] Done"
-- main : IO ⊤
-- main = getLine >>= λ s → putStrLn s
| {
"alphanum_fraction": 0.6252091467,
"avg_line_length": 23.5921052632,
"ext": "agda",
"hexsha": "8ae374bc7c2e04ed9fad0b025c71452faacc6eae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d7903dfffcd66ae174eed9347afe008f892b2491",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "o4/n2o",
"max_forks_repo_path": "n2o/N2O.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d7903dfffcd66ae174eed9347afe008f892b2491",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "o4/n2o",
"max_issues_repo_path": "n2o/N2O.agda",
"max_line_length": 79,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "d7903dfffcd66ae174eed9347afe008f892b2491",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "o4/n2o",
"max_stars_repo_path": "n2o/N2O.agda",
"max_stars_repo_stars_event_max_datetime": "2019-01-02T06:37:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-30T11:37:10.000Z",
"num_tokens": 493,
"size": 1793
} |
module Syntax where
data S
(A₁ : Set)
(A₂ : A₁ → Set)
: Set
where
_,_
: (x₁ : A₁)
→ A₂ x₁
→ S A₁ A₂
syntax S A₁ (λ x → A₂)
= x ∈ A₁ × A₂
module M where
data S'
(A₁ : Set)
(A₂ : A₁ → Set)
: Set
where
_,'_
: (x₁ : A₁)
→ A₂ x₁
→ S' A₁ A₂
syntax S' A₁ (λ x → A₂)
= x ∈' A₁ ×' A₂
open M
using (S')
postulate
p1
: {A₁ : Set}
→ {A₂ : A₁ → Set}
→ x₁ ∈ A₁ × A₂ x₁
→ A₁
p1'
: {A₁ : Set}
→ {A₂ : A₁ → Set}
→ x₁ ∈' A₁ ×' A₂ x₁
→ A₁
| {
"alphanum_fraction": 0.3901098901,
"avg_line_length": 10.92,
"ext": "agda",
"hexsha": "443f086397812ede983d00ee9f9bcce4d0ff755b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msuperdock/agda-unused",
"max_forks_repo_path": "data/declaration/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "msuperdock/agda-unused",
"max_issues_repo_path": "data/declaration/Syntax.agda",
"max_line_length": 25,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msuperdock/agda-unused",
"max_stars_repo_path": "data/declaration/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z",
"num_tokens": 260,
"size": 546
} |
-- Andreas, Issue 1944, Bengtfest Marsstrand 2016-04-28
-- A reason why issue 1098 (automatic opening of record modules)
-- cannot easily be fixed
data Bool : Set where
true false : Bool
if_then_else_ : ∀{A : Set} → Bool → A → A → A
if true then t else e = t
if false then t else e = e
record Testable (A : Set) : Set where
field
test : A -> Bool
open Testable {{...}}
open Testable -- overloading projection `test`
mytest : ∀{A} → Testable A → A → Bool
mytest dict = test dict -- Should work.
t : ∀{A}{{_ : Testable A}} → A → A
t = λ x → if test x then x else x
-- This may fail when test is overloaded.
| {
"alphanum_fraction": 0.6479099678,
"avg_line_length": 24.88,
"ext": "agda",
"hexsha": "a0917c5fab9fd354caf7eeb0a40febc8c1f96e9d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1944-instance.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1944-instance.agda",
"max_line_length": 64,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1944-instance.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 199,
"size": 622
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Functors on indexed sets (predicates)
------------------------------------------------------------------------
-- Note that currently the functor laws are not included here.
{-# OPTIONS --without-K --safe #-}
module Category.Functor.Predicate where
open import Function
open import Level
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (PT)
record RawPFunctor {i j ℓ₁ ℓ₂} {I : Set i} {J : Set j}
(F : PT I J ℓ₁ ℓ₂) : Set (i ⊔ j ⊔ suc ℓ₁ ⊔ suc ℓ₂)
where
infixl 4 _<$>_ _<$_
field
_<$>_ : ∀ {P Q} → P ⊆ Q → F P ⊆ F Q
_<$_ : ∀ {P Q} → (∀ {i} → P i) → F Q ⊆ F P
x <$ y = const x <$> y
| {
"alphanum_fraction": 0.4749679076,
"avg_line_length": 27.8214285714,
"ext": "agda",
"hexsha": "ffcc337da9785fedeb7ad1e7ae85c1e08abdccaa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Category/Functor/Predicate.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Category/Functor/Predicate.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Category/Functor/Predicate.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 215,
"size": 779
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Monad.Duality {o ℓ e} (C : Category o ℓ e) where
open import Categories.Functor
open import Categories.NaturalTransformation
open import Categories.Monad
open import Categories.Comonad
private
module C = Category C
open C
open HomReasoning
coMonad⇒Comonad : Monad C.op → Comonad C
coMonad⇒Comonad M = record
{ F = Functor.op F
; ε = NaturalTransformation.op η
; δ = NaturalTransformation.op μ
; assoc = M.sym-assoc
; sym-assoc = M.assoc
; identityˡ = M.identityˡ
; identityʳ = M.identityʳ
}
where module M = Monad M
open M using (F; η; μ)
Comonad⇒coMonad : Comonad C → Monad C.op
Comonad⇒coMonad M = record
{ F = Functor.op F
; η = NaturalTransformation.op ε
; μ = NaturalTransformation.op δ
; assoc = M.sym-assoc
; sym-assoc = M.assoc
; identityˡ = M.identityˡ
; identityʳ = M.identityʳ
}
where module M = Comonad M
open M using (F; ε; δ)
| {
"alphanum_fraction": 0.6304549675,
"avg_line_length": 25.6428571429,
"ext": "agda",
"hexsha": "0e7c889f8b27b7979f9afa08c9ccea83aab3b6b7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Monad/Duality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Monad/Duality.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Monad/Duality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 329,
"size": 1077
} |
open import Reflection
open import Reflection.Term
open import Reflection.Universe
open import Reflection.Annotated
open import Agda.Builtin.Reflection using (withReconstructed; dontReduceDefs; onlyReduceDefs)
open import Relation.Nullary
open import Data.String as S
open import Data.Maybe hiding (_>>=_)
open import Data.Unit
open import Function
open import Data.List as L
open import Data.Vec as V using (Vec; []; _∷_)
open import Data.Nat
open import Data.Product
open import Data.Bool
-- Get a reference to the local term such as where-function or
-- with- or rewrite- by its name.
get-defn : String → AnnotationFun (λ _ → Maybe Name)
get-defn n ⟨term⟩ (def f x) with showName f S.≟ n
... | yes _ = just f
... | no _ = nothing
get-defn n u t = defaultAnn nothing _<∣>_ u t
do-get-defn : String → ∀ {u} → (t : ⟦ u ⟧) → Annotated (λ _ → Maybe Name) t
do-get-defn n = annotate (get-defn n)
to-pat-lam : Definition → TC (Maybe Term)
to-pat-lam (function cs) = return $ just (pat-lam cs [])
to-pat-lam _ = return $ nothing
tel-norm : Names → Telescope → Telescope → TC Telescope
tel-norm base-funs [] ctx = return []
tel-norm base-funs ((v , arg i x) ∷ tel) ctx = do
x ← dontReduceDefs base-funs
$ inContext (reverse $ L.map proj₂ ctx)
$ withReconstructed
$ normalise x
--$ reduce x
let p = (v , arg i x)
tel ← tel-norm base-funs tel (ctx L.++ [ p ])
return $! p ∷ tel
pat-lam-norm : Term → Names → TC Term
pat-lam-norm (pat-lam cs args) base-funs = do
cs ← hlpr cs
return $ pat-lam cs args
where
hlpr : List Clause → TC $ List Clause
hlpr [] = return []
hlpr (clause tel ps t ∷ l) = do
--gctx ← getContext
-- Try normalising telescope
tel ← tel-norm base-funs tel []
let ctx = reverse $ L.map proj₂ tel
t ← dontReduceDefs base-funs
$ inContext ctx --(gctx L.++ ctx)
$ withReconstructed
$ normalise t
--$ reduce t
l ← hlpr l
return $! clause tel ps t ∷ l
hlpr (absurd-clause tel ps ∷ l) = do
l ← hlpr l
return $! absurd-clause tel ps ∷ l
pat-lam-norm t _ = return t
get-term : (f : Name) (base-funs : List Name) → TC Term
get-term t bf = do
td ← withReconstructed $ dontReduceDefs bf $ getDefinition t
just te ← to-pat-lam td where _ → typeError [ strErr $ "get-term: " S.++ showName t S.++ " is not a function" ]
te ← pat-lam-norm te bf
return te
get-ty : (f : Name) (base-funs : List Name) → TC Term
get-ty t bf = do
ty ← getType t
withReconstructed $ dontReduceDefs bf $ normalise ty
-- A helper function to get a term or a type (first parameter true/false) using
-- the chain of names so that we could traverse into helper functions. For example
-- assume that `f` has `with-x` in its body which in turn has `rewrite-y` which we
-- want to obtain. Then we should call frefln as follows:
--
-- frefln true ("with-x" ∷ "rewrite-y" ∷ []) (base-funs) (quote f)
frefln-h : Bool → (name-chain : List String) (base-funs : Names) → Name → TC Term
frefln-h true [] bf t = get-term t bf
frefln-h false [] bf t = get-ty t bf
frefln-h te/ty (x ∷ ns) bf t = do
xt ← get-term t bf
case (ann $ do-get-defn x {⟨term⟩} xt) of λ where
(nothing) → typeError [ strErr $ "frefln: cannot find name `" S.++ x S.++ "` in term " S.++ showName t ]
(just f') → frefln-h te/ty ns bf f'
macro
frefl : Name → List Name → Term → TC ⊤
frefl n bf a = frefln-h true [] bf n >>= quoteTC >>= unify a
fty : Name → List Name → Term → TC ⊤
fty n bf a = frefln-h false [] bf n >>= quoteTC >>= unify a
frefln : Name → List Name → List String → Term → TC ⊤
frefln n bf ns a = frefln-h true ns bf n >>= quoteTC >>= unify a
ftyn : Name → List Name → List String → Term → TC ⊤
ftyn n bf ns a = frefln-h false ns bf n >>= quoteTC >>= unify a
{-
-- For debugging purposes.
frefl : Name → List Name → Term → TC ⊤
frefl f base-funs a = do
ty ← getType f
ty ← withReconstructed $ dontReduceDefs base-funs $ normalise ty
te ← withReconstructed $ getDefinition f >>= λ where
(function cs) → return $ pat-lam cs []
_ → return unknown
te ← pat-lam-norm te base-funs
q ← quoteTC te
unify a q
fty : Name → List Name → Term → TC ⊤
fty f base-funs a = do
ty ← getType f
ty ← withReconstructed $ dontReduceDefs base-funs $ normalise ty
q ← quoteTC ty
unify a q
-- XXX We can generalise this to List of names, then the local function can be
-- at arbitrary depth.
frefl2 : Name → String → Term → TC ⊤
frefl2 f na a = do
td ← withReconstructed $ getDefinition f
just te ← to-pat-lam td where _ → typeError [ strErr "ERROR₁" ]
te ← pat-lam-norm te []
--te ← normalise te
case (ann $ do-get-defn na {⟨term⟩} te) of λ where
(nothing) → typeError [ strErr "ERROR₁" ]
(just f') → do
td' ← withReconstructed $ getDefinition f
just te ← to-pat-lam td' where _ → typeError [ strErr "ERROR₃" ]
quoteTC te >>= unify a
fty2 : Name → String → Term → TC ⊤
fty2 f na a = do
td ← withReconstructed $ getDefinition f
just te ← to-pat-lam td where _ → typeError [ strErr "ERROR₁" ]
te ← pat-lam-norm te []
--te ← normalise te
case (ann $ do-get-defn na {⟨term⟩} te) of λ where
(nothing) → typeError [ strErr "ERROR₁" ]
(just f') → do
ty ← getType f'
ty ← withReconstructed $ normalise ty
quoteTC ty >>= unify a
-}
| {
"alphanum_fraction": 0.610951526,
"avg_line_length": 34.3827160494,
"ext": "agda",
"hexsha": "cd36cf9dd2db4d2a0d4aa896407bc1a579214c6c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "ReflHelper.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "ashinkarov/agda-extractor",
"max_issues_repo_path": "ReflHelper.agda",
"max_line_length": 116,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "ReflHelper.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 1753,
"size": 5570
} |
------------------------------------------------------------------------------
-- The relation of divisibility on partial natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.Divisibility.By0 where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
infix 4 _∣_
------------------------------------------------------------------------------
-- The relation of divisibility (the symbol is '\mid' not '|')
--
-- (See documentation in FOTC.Data.Nat.Divisibility.By0)
--
-- In our definition 0∣0, which is used to prove properties of the gcd
-- as it is in GHC ≥ 7.2.1, where gcd 0 0 = 0 (see
-- http://hackage.haskell.org/trac/ghc/ticket/3304).
-- Note that @k@ should be a total natural number.
_∣_ : D → D → Set
m ∣ n = ∃[ k ] N k ∧ n ≡ k * m
| {
"alphanum_fraction": 0.479757085,
"avg_line_length": 34.0689655172,
"ext": "agda",
"hexsha": "9c7d68e463ef41cc3de5bce8c1f9fb87e126778d",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Data/Nat/Divisibility/By0.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Data/Nat/Divisibility/By0.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Data/Nat/Divisibility/By0.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 234,
"size": 988
} |
module FFI.IO where
import Lvl
open import Data
open import String
open import Type
postulate IO : ∀{a} → Type{a} → Type{a}
{-# BUILTIN IO IO #-}
{-# FOREIGN GHC type AgdaIO a b = IO b #-}
{-# COMPILE GHC IO = type AgdaIO #-}
{-# FOREIGN GHC import qualified Data.Text.IO #-}
postulate printStr : String → IO(Unit{Lvl.𝟎})
{-# COMPILE GHC printStr = Data.Text.IO.putStr #-}
postulate printStrLn : String → IO(Unit{Lvl.𝟎})
{-# COMPILE GHC printStrLn = Data.Text.IO.putStrLn #-}
| {
"alphanum_fraction": 0.6666666667,
"avg_line_length": 24.3,
"ext": "agda",
"hexsha": "9e6294b4ea3fdabbc9b8e7b399455d96c073f59d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "FFI/IO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "FFI/IO.agda",
"max_line_length": 54,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "FFI/IO.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 140,
"size": 486
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
-- [Subtype] is defined in lib.NType.
module lib.types.Subtype where
infix 40 _⊆_
_⊆_ : ∀ {i j₁ j₂} {A : Type i} → SubtypeProp A j₁ → SubtypeProp A j₂
→ Type (lmax i (lmax j₁ j₂))
P₁ ⊆ P₂ = ∀ a → SubtypeProp.prop P₁ a → SubtypeProp.prop P₂ a
infix 80 _∘sub_
_∘sub_ : ∀ {i j k} {A : Type i} {B : Type j}
→ SubtypeProp B k → (A → B) → SubtypeProp A k
P ∘sub f = SubtypeProp.prop P ∘ f , level where
abstract level = SubtypeProp.level P ∘ f
{- Dependent paths in a Σ-type -}
module _ {i j k} {A : Type i} {B : A → Type j} (subB : (a : A) → SubtypeProp (B a) k)
where
↓-Subtype-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'}
{s : SubtypeProp.prop (subB x) r} {s' : SubtypeProp.prop (subB x') r'}
(q : r == r' [ B ↓ p ])
→ (r , s) == (r' , s') [ (λ x → Subtype (subB x)) ↓ p ]
↓-Subtype-in {p = idp} q = Subtype=-out (subB _) q
| {
"alphanum_fraction": 0.5650793651,
"avg_line_length": 31.5,
"ext": "agda",
"hexsha": "04307bf6ed48f8b4b4dceb4c1c1acf06dcdea730",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Subtype.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Subtype.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Subtype.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 394,
"size": 945
} |
module _ where
module A where
postulate
Nat : Set
suc : Nat → Nat
open A
syntax suc x = ⟦ x ⟧
-- Error WAS:
-- Names out of scope in fixity declarations: suc
-- Error SHOULD BE something like:
-- Name 'suc' not declared in same scope as its syntax declaration.
| {
"alphanum_fraction": 0.6775362319,
"avg_line_length": 16.2352941176,
"ext": "agda",
"hexsha": "a52fc561217864fc1dfd39a4fac89a8f57afbee5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue1204.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue1204.agda",
"max_line_length": 67,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue1204.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 76,
"size": 276
} |
{-# OPTIONS --sized-types --show-implicit #-}
-- {-# OPTIONS -v tc.size.solve:60 #-}
module Issue300 where
open import Common.Size
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {↑ size}
suc : {size : Size} -> Nat {size} -> Nat {↑ size}
-- Size meta used in a different context than the one created in
A : Set1
A = (Id : {i : Size} -> Nat {_} -> Set)
(k : Size)(m : Nat {↑ k}) -> Id {k} m
->
(j : Size)(n : Nat {j}) -> Id {j} n
-- should solve _ with ↑ i
| {
"alphanum_fraction": 0.5463709677,
"avg_line_length": 26.1052631579,
"ext": "agda",
"hexsha": "3c840876691f343cc5249cd0e4b321c2d85c7082",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue300.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue300.agda",
"max_line_length": 64,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue300.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 165,
"size": 496
} |
module sn-calculus-compatconf.base where
open import sn-calculus
open import utility renaming (_U̬_ to _∪_)
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
using (Can ; Canₛ ; Canₛₕ ; Canₖ ; module CodeSet)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ;
Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.Context.Properties
using (unplug ; unplugc ; plug ; plugc ; ⟦⟧e-to-⟦⟧c)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning)
open import Data.Bool
using (Bool ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _∷_ ; [] ; _++_ ; map)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function using (_∘_ ; id ; _∋_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open EvaluationContext1
open _≐_⟦_⟧e
open Context1
open _≐_⟦_⟧c
open ListSet Data.Nat._≟_
data two-roads-diverged : EvaluationContext → Context → Set where
divout-disjoint : ∀ {C₁ C} → two-roads-diverged [] (C₁ ∷ C)
divpar-split₁ : ∀ {E C p q} → two-roads-diverged (epar₁ q ∷ E) (ceval (epar₂ p) ∷ C)
divpar-split₂ : ∀ {E C p q} → two-roads-diverged (epar₂ p ∷ E) (ceval (epar₁ q) ∷ C)
divseq-split : ∀ {E C p q} → two-roads-diverged (eseq q ∷ E) (cseq₂ p ∷ C)
divloop-splitˢ : ∀ {E C p q} → two-roads-diverged (eloopˢ q ∷ E) (cloopˢ₂ p ∷ C)
divin : ∀ {E₁ E C} → two-roads-diverged E C → two-roads-diverged (E₁ ∷ E) (ceval E₁ ∷ C)
data context-prefix : EvaluationContext → Context → Set where
ecsame : ∀ {E} → context-prefix E (map ceval E)
ecin-lift : ∀ {E E₁ E'} → context-prefix (E ++ (E₁ ∷ E')) (map ceval E)
ecsplit : ∀ {E C} → (div : two-roads-diverged E C) → context-prefix E C
get-context-prefix : ∀ {E C p q r} →
p ≐ E ⟦ q ⟧e → p ≐ C ⟦ r ⟧c →
context-prefix E C
get-context-prefix {[]} {[]} dehole p≐C⟦r⟧ = ecsame
get-context-prefix {[]} {C₁ ∷ C} dehole p≐C⟦r⟧ = ecsplit divout-disjoint
get-context-prefix {E₁ ∷ E} p≐E⟦q⟧ dchole = ecin-lift
get-context-prefix (depar₁ p≐E⟦q⟧) (dcpar₂ p≐C⟦r⟧) = ecsplit divpar-split₁
get-context-prefix (depar₂ p≐E⟦q⟧) (dcpar₁ p≐C⟦r⟧) = ecsplit divpar-split₂
get-context-prefix (deseq p≐E⟦q⟧) (dcseq₂ p≐C⟦r⟧) = ecsplit divseq-split
get-context-prefix (deloopˢ p≐E⟦q⟧) (dcloopˢ₂ p≐C⟦r⟧) = ecsplit divloop-splitˢ
get-context-prefix (depar₁ p≐E⟦q⟧) (dcpar₁ p≐C⟦r⟧)
with get-context-prefix p≐E⟦q⟧ p≐C⟦r⟧
... | ecsame = ecsame
... | ecin-lift = ecin-lift
... | ecsplit div = ecsplit (divin div)
get-context-prefix (depar₂ p≐E⟦q⟧) (dcpar₂ p≐C⟦r⟧)
with get-context-prefix p≐E⟦q⟧ p≐C⟦r⟧
... | ecsame = ecsame
... | ecin-lift = ecin-lift
... | ecsplit div = ecsplit (divin div)
get-context-prefix (deloopˢ p≐E⟦q⟧) (dcloopˢ₁ p≐C⟦r⟧)
with get-context-prefix p≐E⟦q⟧ p≐C⟦r⟧
... | ecsame = ecsame
... | ecin-lift = ecin-lift
... | ecsplit div = ecsplit (divin div)
get-context-prefix (deseq p≐E⟦q⟧) (dcseq₁ p≐C⟦r⟧)
with get-context-prefix p≐E⟦q⟧ p≐C⟦r⟧
... | ecsame = ecsame
... | ecin-lift = ecin-lift
... | ecsplit div = ecsplit (divin div)
get-context-prefix (desuspend p≐E⟦q⟧) (dcsuspend p≐C⟦r⟧)
with get-context-prefix p≐E⟦q⟧ p≐C⟦r⟧
... | ecsame = ecsame
... | ecin-lift = ecin-lift
... | ecsplit div = ecsplit (divin div)
-- didn't directly pattern match on p≐C⟦r⟧ in order to get complete pattern matching coverage
get-context-prefix (detrap p≐E⟦q⟧) p≐trap[C⟦r⟧] with p≐trap[C⟦r⟧]
... | dchole = ecin-lift
... | dctrap p≐C⟦r⟧ with get-context-prefix p≐E⟦q⟧ p≐C⟦r⟧
... | ecsame = ecsame
... | ecin-lift = ecin-lift
... | ecsplit div = ecsplit (divin div)
| {
"alphanum_fraction": 0.6450295979,
"avg_line_length": 40.4876033058,
"ext": "agda",
"hexsha": "8c213fe201b66ff5ad6edb61c2b59b5644133033",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-compatconf/base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-compatconf/base.agda",
"max_line_length": 97,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-compatconf/base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 1908,
"size": 4899
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
import LibraBFT.Impl.OBM.Genesis as Genesis
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.Impl.OBM.Util
import LibraBFT.Impl.Types.OnChainConfig.ValidatorSet as ValidatorSet
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.Impl.OBM.Util
import LibraBFT.Impl.Types.OnChainConfig.ValidatorSet as ValidatorSet
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import Util.PKCS
open import Util.Prelude
module LibraBFT.Impl.IO.OBM.GenKeyFile where
------------------------------------------------------------------------------
EndpointAddress = Author
AddressToSkAndPkAssocList = List (EndpointAddress × (SK × PK))
------------------------------------------------------------------------------
genKeys : {-Crypto.SystemDRG →-} ℕ → List (SK × PK)
mkAuthors : {-Crypto.SystemDRG →-} U64 → List EndpointAddress
→ Either ErrLog AddressToSkAndPkAssocList
mkValidatorSignersAndVerifierAndProposerElection
: U64 → AddressToSkAndPkAssocList
→ Either ErrLog (List ValidatorSigner × ValidatorVerifier × ProposerElection)
------------------------------------------------------------------------------
NfLiwsVssVvPe =
(U64 × LedgerInfoWithSignatures × List ValidatorSigner × ValidatorVerifier × ProposerElection)
NfLiwsVsVvPe =
(U64 × LedgerInfoWithSignatures × ValidatorSigner × ValidatorVerifier × ProposerElection)
create'
: U64 → List EndpointAddress {-→ SystemDRG-}
→ Either ErrLog
( U64 × AddressToSkAndPkAssocList
× List ValidatorSigner × ValidatorVerifier × ProposerElection × LedgerInfoWithSignatures )
create' numFailures addresses {-drg-} = do
authors ← mkAuthors {-drg-} numFailures addresses
(s , vv , pe) ← mkValidatorSignersAndVerifierAndProposerElection numFailures authors
case Genesis.obmMkGenesisLedgerInfoWithSignatures s (ValidatorSet.obmFromVV vv) of λ where
(Left err) → Left err
(Right liws) → pure (numFailures , authors , s , vv , pe , liws)
abstract
create = create'
create≡ : create ≡ create'
create≡ = refl
mkAuthors {-drg-} numFailures0 addresses0 = do
addrs <- checkAddresses
checkBftAndRun numFailures0 addrs f
where
f : ℕ → List EndpointAddress → AddressToSkAndPkAssocList
f _numFailures addresses = zip addresses (genKeys {-drg-} (length addresses))
checkAddresses : Either ErrLog (List EndpointAddress)
checkAddresses = pure addresses0
postulate -- Valid assumption: secret and public keys for each NodeId
mkSK : NodeId → SK
mkPK : NodeId → PK
genKeys zero = []
genKeys x@(suc n) = (mkSK x , mkPK x) ∷ genKeys n
mkValidatorSignersAndVerifierAndProposerElection numFaults ks = do
-- IMPL-DIFF: Agda Author type does NOT contain a PK
let allAuthors = fmap fst ks
validatorVerifier ← ValidatorVerifier.initValidatorVerifier numFaults ks
let authorKeyPairs = fmap (λ (a , (sk , _)) → (a , sk)) ks
validatorSigners = foldl' go [] authorKeyPairs
pure (validatorSigners , validatorVerifier , ProposerElection∙new allAuthors)
where
go : List ValidatorSigner → (Author × SK) → List ValidatorSigner
go acc (author , sk) = ValidatorSigner∙new author sk ∷ acc
| {
"alphanum_fraction": 0.6963795941,
"avg_line_length": 42.3953488372,
"ext": "agda",
"hexsha": "85b3032266acc547c1379015b04cbda54359c438",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/IO/OBM/GenKeyFile.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/IO/OBM/GenKeyFile.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/IO/OBM/GenKeyFile.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 970,
"size": 3646
} |
-- A simple word counter
open import Coinduction using ( ♯_ )
open import Data.Char.Classifier using ( isSpace )
open import Data.Bool using ( Bool ; true ; false )
open import Data.Natural using ( Natural ; show )
open import System.IO using ( Command )
open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ; _⟫_ ; _⟨&⟩_ )
open import System.IO.Transducers.List using ( length )
open import System.IO.Transducers.Bytes using ( bytes )
open import System.IO.Transducers.IO using ( run )
open import System.IO.Transducers.UTF8 using ( split ; encode )
open import System.IO.Transducers.Session using ( ⟨_⟩ ; _&_ ; Bytes ; Strings )
module System.IO.Examples.WC where
words : Bytes ⇒ ⟨ Natural ⟩
words = split isSpace ⟫ inp (♯ length { Bytes })
-- TODO: this isn't exactly lovely user syntax.
report : ⟨ Natural ⟩ & ⟨ Natural ⟩ ⇒ Strings
report =
(inp (♯ λ #bytes →
(out true
(out (show #bytes)
(out true
(out " "
(inp (♯ λ #words →
(out true
(out (show #words)
(out true
(out "\n"
(out false done)))))))))))))
wc : Bytes ⇒ Bytes
wc = bytes ⟨&⟩ words ⟫ report ⟫ inp (♯ encode)
main : Command
main = run wc
| {
"alphanum_fraction": 0.664644714,
"avg_line_length": 28.1463414634,
"ext": "agda",
"hexsha": "3c1030f528c60e6d326196df9b837b939a6c4e0b",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Examples/WC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Examples/WC.agda",
"max_line_length": 85,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Examples/WC.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 333,
"size": 1154
} |
module _ where
data D (@erased A : Set) : Set
-- The modality should not be repeated here
data D (@erased A) where
mkD : D A
| {
"alphanum_fraction": 0.6615384615,
"avg_line_length": 14.4444444444,
"ext": "agda",
"hexsha": "acdd562c716e20ba9896ff63c10ae130a8e639ec",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1886-modality.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue1886-modality.agda",
"max_line_length": 43,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1886-modality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 43,
"size": 130
} |
{-# OPTIONS --guardedness #-}
module Class.Monad.IO where
open import Class.Monad
open import IO
open import Level
record MonadIO {a} (M : Set a → Set a) {{_ : Monad M}} : Set (suc a) where
field
liftIO : ∀ {A} → IO A → M A
open MonadIO {{...}} public
| {
"alphanum_fraction": 0.6259541985,
"avg_line_length": 18.7142857143,
"ext": "agda",
"hexsha": "abd607fc7196af3b940595da746c0e7552965870",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Class/Monad/IO.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Class/Monad/IO.agda",
"max_line_length": 74,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Class/Monad/IO.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 81,
"size": 262
} |
open import FRP.JS.Float using ( ℝ ) renaming ( _/?_ to _/?r_ )
open import FRP.JS.Int using ( ℤ ; _-_ ) renaming ( float to floatz ; show to showz )
open import FRP.JS.Primitive using ( String )
open import FRP.JS.Bool using ( Bool ; _∨_ ; not )
open import FRP.JS.True using ( True )
open import FRP.JS.Maybe using ( Maybe )
module FRP.JS.Nat where
infixr 4 _≤_ _<_ _≟_ _≠_
infixl 6 _+_ _∸_
infixl 7 _*_ _/_ _/?_
open import FRP.JS.Primitive public using ( ℕ ; zero ; suc )
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
{-# BUILTIN NATPLUS _+_ #-}
{-# COMPILED_JS _+_ function (x) { return function (y) { return x+y; }; } #-}
_∸_ : ℕ → ℕ → ℕ
zero ∸ n = zero
suc m ∸ zero = suc m
suc m ∸ suc n = m ∸ n
{-# BUILTIN NATMINUS _∸_ #-}
{-# COMPILED_JS _∸_ function (x) { return function (y) { return Math.max(0,x-y); }; } #-}
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + m * n
{-# BUILTIN NATTIMES _*_ #-}
{-# COMPILED_JS _*_ function (x) { return function (y) { return x*y; }; } #-}
private
primitive
primNatEquality : ℕ → ℕ → Bool
primNatLess : ℕ → ℕ → Bool
primNatToInteger : ℕ → ℤ
primFloatDiv : ℝ → ℝ → ℝ
_≟_ = primNatEquality
_<_ = primNatLess
+_ = primNatToInteger
{-# COMPILED_JS _≟_ function (x) { return function (y) { return x === y; }; } #-}
{-# COMPILED_JS _<_ function (x) { return function (y) { return x < y; }; } #-}
{-# COMPILED_JS +_ function (x) { return x; } #-}
float : ℕ → ℝ
float x = floatz (+ x)
show : ℕ → String
show x = showz (+ x)
-_ : ℕ → ℤ
-_ x = (+ 0) - (+ x)
_≤_ : ℕ → ℕ → Bool
x ≤ y = not (y < x)
_≠_ : ℕ → ℕ → Bool
x ≠ y = not (x ≟ y)
_/_ : (x y : ℕ) → {y≠0 : True (y ≠ 0)} → ℝ
x / y = primFloatDiv (float x) (float y)
_/?_ : ℕ → ℕ → Maybe ℝ
x /? y = (float x) /?r (float y)
{-# COMPILED_JS float function (x) { return x; } #-}
{-# COMPILED_JS show function (x) { return x.toString(); } #-}
{-# COMPILED_JS -_ function (x) { return -x; } #-}
{-# COMPILED_JS _≤_ function (x) { return function (y) { return x <= y; }; } #-}
{-# COMPILED_JS _≠_ function (x) { return function (y) { return x !== y; }; } #-}
{-# COMPILED_JS _/_ function(x) { return function(y) { return function() { return x / y; }; }; } #-}
{-# COMPILED_JS _/?_ function(x) { return function(y) { if (y === 0) { return null; } else { return x / y; } }; } #-}
| {
"alphanum_fraction": 0.56640625,
"avg_line_length": 28.4444444444,
"ext": "agda",
"hexsha": "753acae46fc3300353821258957b4f1e64695b9e",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "src/agda/FRP/JS/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "src/agda/FRP/JS/Nat.agda",
"max_line_length": 118,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 855,
"size": 2304
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category.Core
open import Categories.Object.Zero
-- Normal Mono and Epimorphisms
-- https://ncatlab.org/nlab/show/normal+monomorphism
module Categories.Morphism.Normal {o ℓ e} (𝒞 : Category o ℓ e) (𝒞-Zero : Zero 𝒞) where
open import Level
open import Categories.Object.Kernel 𝒞-Zero
open import Categories.Object.Kernel.Properties 𝒞-Zero
open import Categories.Morphism 𝒞
open Category 𝒞
record IsNormalMonomorphism {A K : Obj} (k : K ⇒ A) : Set (o ⊔ ℓ ⊔ e) where
field
{B} : Obj
arr : A ⇒ B
isKernel : IsKernel k arr
open IsKernel isKernel public
mono : Mono k
mono = Kernel-Mono (IsKernel⇒Kernel isKernel)
record NormalMonomorphism (K A : Obj) : Set (o ⊔ ℓ ⊔ e) where
field
mor : K ⇒ A
isNormalMonomorphism : IsNormalMonomorphism mor
open IsNormalMonomorphism isNormalMonomorphism public
| {
"alphanum_fraction": 0.7202247191,
"avg_line_length": 25.4285714286,
"ext": "agda",
"hexsha": "37c5fcfc18d398e85bd315be37b6a9c5f13aea56",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Morphism/Normal.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Morphism/Normal.agda",
"max_line_length": 86,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Morphism/Normal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 278,
"size": 890
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.PKCS
import LibraBFT.Impl.Types.LedgerInfoWithSignatures as LedgerInfoWithSignatures
open import LibraBFT.ImplShared.Consensus.Types
module LibraBFT.Impl.Types.CryptoProxies where
addToLi : AccountAddress → Signature → LedgerInfoWithSignatures → LedgerInfoWithSignatures
addToLi = LedgerInfoWithSignatures.addSignature
| {
"alphanum_fraction": 0.8187919463,
"avg_line_length": 37.25,
"ext": "agda",
"hexsha": "0964b02dc31146941f5a160e8c8b04854a9b478b",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z",
"max_forks_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "oracle/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Types/CryptoProxies.agda",
"max_issues_count": 72,
"max_issues_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "oracle/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Types/CryptoProxies.agda",
"max_line_length": 111,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "oracle/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Types/CryptoProxies.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z",
"num_tokens": 154,
"size": 596
} |
module TerminationNoArgs where
loop : Set
loop = loop
| {
"alphanum_fraction": 0.7818181818,
"avg_line_length": 11,
"ext": "agda",
"hexsha": "a44fc117968c28d79565d95132b7d570fc869d91",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/TerminationNoArgs.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/TerminationNoArgs.agda",
"max_line_length": 30,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/TerminationNoArgs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 15,
"size": 55
} |
module lib.libraryDec where
-- old version of Dec
--
open import Data.Empty
open import Level
open import Relation.Nullary using ( ¬_ )
data Dec {p} (P : Set p) : Set p where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
| {
"alphanum_fraction": 0.6137339056,
"avg_line_length": 17.9230769231,
"ext": "agda",
"hexsha": "32db726b76e219bc6eee6f54c25da6ce276a5eec",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "src/lib/libraryDec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "src/lib/libraryDec.agda",
"max_line_length": 41,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "src/lib/libraryDec.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 77,
"size": 233
} |
module UselessPrivateImportAs where
private
import Common.Prelude as P
| {
"alphanum_fraction": 0.8378378378,
"avg_line_length": 14.8,
"ext": "agda",
"hexsha": "f20048ec783a8016980c126c5e9949ba9afa5d88",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/UselessPrivateImportAs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/UselessPrivateImportAs.agda",
"max_line_length": 35,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/UselessPrivateImportAs.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 18,
"size": 74
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Automatic solver for equations over product and sum types
--
-- See examples at the bottom of the file for how to use this solver
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function.Related.TypeIsomorphisms.Solver where
open import Algebra using (CommutativeSemiring)
import Algebra.Solver.Ring.NaturalCoefficients.Default
open import Data.Empty using (⊥)
open import Data.Product using (_×_)
open import Data.Sum using (_⊎_)
open import Data.Unit using (⊤)
open import Level using (Level; Lift)
open import Function.Inverse as Inv using (_↔_)
open import Function.Related as Related
open import Function.Related.TypeIsomorphisms
------------------------------------------------------------------------
-- The solver
module ×-⊎-Solver (k : Symmetric-kind) {ℓ} =
Algebra.Solver.Ring.NaturalCoefficients.Default
(×-⊎-commutativeSemiring k ℓ)
------------------------------------------------------------------------
-- Tests
private
-- A test of the solver above.
test : {ℓ : Level} (A B C : Set ℓ) →
(Lift ℓ ⊤ × A × (B ⊎ C)) ↔ (A × B ⊎ C × (Lift ℓ ⊥ ⊎ A))
test = solve 3 (λ A B C → con 1 :* (A :* (B :+ C)) :=
A :* B :+ C :* (con 0 :+ A))
Inv.id
where open ×-⊎-Solver bijection
| {
"alphanum_fraction": 0.5191637631,
"avg_line_length": 32.6136363636,
"ext": "agda",
"hexsha": "709dbe1697a21e3df20ea99935950ca6ca50873c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Function/Related/TypeIsomorphisms/Solver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Function/Related/TypeIsomorphisms/Solver.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Function/Related/TypeIsomorphisms/Solver.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 353,
"size": 1435
} |
module Sized.ConsoleExample where
open import SizedIO.Base
open import SizedIO.Console hiding (main)
open import NativeIO
myProgram : ∀{i} → IOConsole i Unit
force myProgram = do' getLine λ line →
do (putStrLn line) λ _ →
do (putStrLn line) λ _ →
myProgram
main : NativeIO Unit
main = translateIOConsole myProgram
| {
"alphanum_fraction": 0.6075,
"avg_line_length": 23.5294117647,
"ext": "agda",
"hexsha": "65f8eb5ef543438de5bbd91ef7bda56c0291a8a1",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/Sized/ConsoleExample.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/Sized/ConsoleExample.agda",
"max_line_length": 49,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/Sized/ConsoleExample.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 105,
"size": 400
} |
module Calculator where
open import Human.Humanity hiding (_==_)
open import Human.Nat public hiding (_==_)
open import Human.Char public
open import Human.Equality public
--------- Data ---------
-- Generic proof to proof "Or" operation. Proof that one of the arguments must be true
data Either (A B : Set) : Set where
fst : A -> Either A B
snd : B -> Either A B
-- Declaring a set of operations
data Operation : Set where
add sub mul : Operation
-- It's used to identify which number will be updated, the one on the right or left
data Side : Set where
right left : Side
-- Can be a number, an operation symbol or execution command
data Event : Set where
clr : Event -- base case
num : Side -> Nat -> Event -- a digit
ope : Operation -> Event -- operator
data State : Set where
state : Operation → Nat → Nat → State
--------- Auxiliar properties ---------
-- Proof of commutativity of addition. Proof by beala
x+0 : (a : Nat) → (a + 0) == a
x+0 zero = refl
x+0 (suc a) rewrite x+0 a = refl
-- Agda knows that 0 * a == 0, now we are telling that "a * 0 == 0 * a"
a*0 : (a : Nat) -> (a * 0) == 0
a*0 zero = refl
a*0 (suc a) rewrite (a*0 a) = refl -- does that 0 * a == 0
-- Proof that 1 is identity element of multiply over nats. Proof by beala
a*1 : (a : Nat) -> (a * 1) == a
a*1 zero = refl
a*1 (suc a) rewrite a*1 a | a*0 a | x+0 a = refl
-- Tells Agda that 1 * a == a
1*a : (a : Nat) -> (1 * a) == a
1*a zero = refl
1*a (suc a) rewrite 1*a a = refl
--------- Calculator ---------
-- Initial state
init : State
init = (state add 0 0)
-- Calculates the operation related to a state
result : State -> Nat
result (state add a b) = (a + b)
result (state sub a b) = (a - b)
result (state mul a b) = (a * b)
-- Get the current State, an Event and update to a new State
updateState : State -> Event -> State
-- clear
updateState s clr = init
-- "num operation": update the numbers values
updateState (state op m n) (num right x) = (state op m x)
updateState (state op m n) (num left x) = (state op x n)
-- execute an operation
updateState (state op m n) (ope e) = (state e m n)
--------- Testing Calculator ---------
testUpState0 : State -- add a number on the left
testUpState0 = (updateState init (num left 1))
testUpState1 : State -- add a number on the right
testUpState1 = (updateState testUpState0 (num right 1))
testUpState2 : State -- executes an operation on both numbers
testUpState2 = (updateState testUpState1 (ope add))
-- A type of test as is usually done in other programming languages. Given some input what do I expect as result?
testUpStateResult : (result (updateState testUpState1 (ope add))) == 2
testUpStateResult = refl
testUpState0a : State -- add a number on the left
testUpState0a = (updateState init (num left 3))
testUpState1a : State -- add a number on the right
testUpState1a = (updateState testUpState0a (num right 5))
testUpState2a : State -- executes an operation on both numbers
testUpState2a = (updateState testUpState1a (ope mul))
testUpState0b : State
testUpState0b = (updateState testUpState2a (clr))
--------- Theorems ---------
-- Proofs that the result showing up an operation will always do that operation --
theorem-0 : (s : State) -> (a b : Nat) -> (result (state add a b)) == (a + b)
theorem-0 s a b = refl
theorem-1 : (s : State) -> (a b : Nat) -> (result (state sub a b)) == (a - b)
theorem-1 s a b = refl
theorem-2 : (s : State) -> (a b : Nat) -> (result (state mul a b)) == (a * b)
theorem-2 s a b = refl
-- Given a and b and a proof that one of them is 0, then the result of multiplicating a and b must be 0
theorem-3 : ∀ (a b : Nat) -> Either (a == 0) (b == 0) -> (a * b) == 0
theorem-3 .0 b (fst refl) = refl -- Agda knows that 0 * n == 0 (refl)
theorem-3 a .0 (snd refl) = (a*0 a) -- then we proof that n * 0 is also 0
-- if a == 1: (mul a b) == b
-- if b == 1: (mul a b) == a
-- if a == 1 OR b == 1: Either ((mul a b) == b) ((mul a b) == a)
-- Given a and b and a proof that one of them is 1,
-- then the result of multiplicating a and b must be the number that is not 1
theorem-4 : ∀ (a b : Nat) -> Either (a == 1) (b == 1) -> Either ((a * b) == b) ((a * b) == a)
theorem-4 .1 b (fst refl) = fst (1*a b) -- A proof that 1 * b == b
theorem-4 a .1 (snd refl) = snd (a*1 a) -- A proof that b * 1 == b
-- Proof that update state works as expected
update-theorem : ∀ (x y : Nat) → (s : State) → (result (updateState (updateState (updateState s (num left x)) (ope add)) (num right y))) == (x + y)
update-theorem x y (state op m n) = refl
-- TODO --
-- -- Evaluates several expressions. E.g. (2 + 3) * 5
-- data Expression : Set where
-- num : Nat -> Expression
-- add : Expression -> Expression -> Expression
-- sub : Expression -> Expression -> Expression
----- VIEW? -----
-- main : Program
-- main _ = do
--
-- print "-- Calculator --"
-- -- Receives a number, an operation symbol and a execution command
--
-- let result = exe-operation 2 3 add
-- print (show result)
-- let result2 = (primNatToChar (exe-operation 2 3 add))
-- print (primShowChar result2)
-- for i from 0 to 10 do:
-- print ("i: " ++ show i)
--
-- if (2 == 2)
-- (then: print "foo")
-- (else: print "bar")
--
-- let num =
-- init 0.0
-- for i from 0 to 1000000 do:
-- λ result → result f+ 1.0
-- print (primShowFloat num)
| {
"alphanum_fraction": 0.6165246388,
"avg_line_length": 31.9408284024,
"ext": "agda",
"hexsha": "315e93c25ba479dc507ff5583212a82fb3c360a9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MaisaMilena/AgdaCalculator",
"max_forks_repo_path": "src/Calculator.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MaisaMilena/AgdaCalculator",
"max_issues_repo_path": "src/Calculator.agda",
"max_line_length": 147,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MaisaMilena/AgdaCalculator",
"max_stars_repo_path": "src/Calculator.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-29T02:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-29T02:30:10.000Z",
"num_tokens": 1732,
"size": 5398
} |
open import level
open import bool
open import bool-thms
open import eq
open import eq-reasoning
open import sum
open import nat
data Lgc : Set where
ttrue : Lgc
ffalse : Lgc
aand : Lgc → Lgc → Lgc
oor : Lgc → Lgc → Lgc
nnot : Lgc → Lgc
check_ : Lgc → 𝔹
check ttrue = tt
check ffalse = ff
check (aand c1 c2) = (check c1) && (check c2)
check (oor c1 c2) = (check c1) || (check c2)
check (nnot c) = ~(check c)
data _isTrue : Lgc → Set
data _isFalse : Lgc → Set
data _isTrue where
c-tt :
-----------
ttrue isTrue
c-and : ∀ {c1 c2 : Lgc}
→ c1 isTrue
→ c2 isTrue
-----------------
→ (aand c1 c2) isTrue
c-or₁ : ∀ {c1 c2 : Lgc}
→ c1 isTrue
---------------
→ (oor c1 c2) isTrue
c-or₂ : ∀ {c1 c2 : Lgc}
→ c2 isTrue
----------------
→ (oor c1 c2) isTrue
c-not : ∀ {c : Lgc}
→ c isFalse
-------------
→ (nnot c) isTrue
data _isFalse where
~c-ff :
--------------
ffalse isFalse
~c-or : ∀ {c1 c2 : Lgc}
→ c1 isFalse
→ c2 isFalse
---------------------
→ (oor c1 c2) isFalse
~c-and₁ : ∀ {c1 c2 : Lgc}
→ c1 isFalse
----------------------
→ (aand c1 c2) isFalse
~c-and₂ : ∀ {c1 c2 : Lgc}
→ c2 isFalse
-----------------
→ (aand c1 c2) isFalse
~c-not : ∀ {c : Lgc}
→ c isTrue
-------------
→ (nnot c) isFalse
c-thm : ∀ {c : Lgc} → c isTrue → (check c ≡ tt)
~c-thm : ∀ {c : Lgc} → c isFalse → (check c ≡ ff)
c-thm (c-tt) =
begin
check ttrue
≡⟨ refl ⟩
tt
∎
c-thm (c-and{c1}{c2} dat1 dat2) =
begin
check (aand c1 c2)
≡⟨ refl ⟩
(check c1) && (check c2)
≡⟨ congf2{f = _&&_}{f' = _&&_} refl (c-thm dat1) (c-thm dat2) ⟩
tt && tt
≡⟨ refl ⟩
tt
∎
c-thm (c-or₁{c1}{c2} dat1) =
begin
check (oor c1 c2)
≡⟨ refl ⟩
(check c1) || (check c2)
≡⟨ congf2{f = _||_}{f' = _||_} refl (c-thm dat1) refl ⟩
tt || (check c2)
≡⟨ refl ⟩
tt
∎
c-thm (c-or₂{c1}{c2} dat2) =
begin
check (oor c1 c2)
≡⟨ refl ⟩
(check c1) || (check c2)
≡⟨ congf2{f = _||_}{f' = _||_} refl refl (c-thm dat2) ⟩
(check c1) || tt
≡⟨ ||-tt (check c1)⟩
tt
∎
c-thm (c-not{c} dat) =
begin
check (nnot c)
≡⟨ refl ⟩
~ (check c)
≡⟨ congf{f = ~_}{f' = ~_} refl (~c-thm dat) ⟩
~ ff
≡⟨ refl ⟩
tt
∎
~c-thm (~c-ff) =
begin
check ffalse
≡⟨ refl ⟩
ff
∎
~c-thm (~c-or{c1}{c2} dat1 dat2) =
begin
check (oor c1 c2)
≡⟨ refl ⟩
(check c1) || (check c2)
≡⟨ congf2{f = _||_}{f' = _||_} refl (~c-thm dat1) (~c-thm dat2) ⟩
ff || ff
≡⟨ refl ⟩
ff
∎
~c-thm (~c-and₁{c1}{c2} dat1) =
begin
check (aand c1 c2)
≡⟨ refl ⟩
(check c1) && (check c2)
≡⟨ congf2{f = _&&_}{f' = _&&_} refl (~c-thm dat1) refl ⟩
ff && (check c2)
≡⟨ refl ⟩
ff
∎
~c-thm (~c-and₂{c1}{c2} dat2) =
begin
check (aand c1 c2)
≡⟨ refl ⟩
(check c1) && (check c2)
≡⟨ congf2{f = _&&_}{f' = _&&_} refl refl (~c-thm dat2) ⟩
(check c1) && ff
≡⟨ &&-ff (check c1)⟩
ff
∎
~c-thm (~c-not{c} dat) =
begin
check (nnot c)
≡⟨ refl ⟩
~ (check c)
≡⟨ congf{f = ~_}{f' = ~_} refl (c-thm dat) ⟩
~ tt
≡⟨ refl ⟩
ff
∎
| {
"alphanum_fraction": 0.4454573078,
"avg_line_length": 18.2833333333,
"ext": "agda",
"hexsha": "95083d5300eed67eea7743f188551be873adfead",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JimFixGroupResearch/imper-ial",
"max_forks_repo_path": "cond-chck-holds.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JimFixGroupResearch/imper-ial",
"max_issues_repo_path": "cond-chck-holds.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "80d9411b2869614cae488cd4a6272894146c9f3c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JimFixGroupResearch/imper-ial",
"max_stars_repo_path": "cond-chck-holds.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1508,
"size": 3291
} |
{-# OPTIONS --without-K --safe #-}
-- Verbatim dual of Categories.Category.Construction.Kleisli
module Categories.Category.Construction.CoKleisli where
open import Level
open import Categories.Category
open import Categories.Functor using (Functor; module Functor)
open import Categories.NaturalTransformation hiding (id)
open import Categories.Comonad
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
CoKleisli : {𝒞 : Category o ℓ e} → Comonad 𝒞 → Category o ℓ e
CoKleisli {𝒞 = 𝒞} M =
record
{ Obj = Obj
; _⇒_ = λ A B → (F₀ A ⇒ B)
; _≈_ = _≈_
; _∘_ = λ f g → f ∘ F₁ g ∘ δ.η _
; id = ε.η _
; assoc = assoc′
; sym-assoc = sym assoc′
; identityˡ = identityˡ′
; identityʳ = identityʳ′
; identity² = identity²′
; equiv = equiv
; ∘-resp-≈ = λ f≈h g≈i → ∘-resp-≈ f≈h (∘-resp-≈ (F≈ g≈i) refl)
}
where
module M = Comonad M
open M using (ε; δ; F)
open Functor F
open Category 𝒞
open HomReasoning
open Equiv
open MR 𝒞
-- useful lemma
trihom : {X Y Z W : Obj} {f : X ⇒ Y} {g : Y ⇒ Z} {h : Z ⇒ W} → F₁ (h ∘ g ∘ f) ≈ F₁ h ∘ F₁ g ∘ F₁ f
trihom {X} {Y} {Z} {W} {f} {g} {h} = begin
F₁ (h ∘ g ∘ f) ≈⟨ homomorphism ⟩
F₁ h ∘ F₁ (g ∘ f) ≈⟨ refl⟩∘⟨ homomorphism ⟩
F₁ h ∘ F₁ g ∘ F₁ f ∎
-- shorthands to make the proofs nicer
F≈ = F-resp-≈
assoc′ : {A B C D : Obj} {f : F₀ A ⇒ B} {g : F₀ B ⇒ C} {h : F₀ C ⇒ D} → (h ∘ F₁ g ∘ δ.η B) ∘ F₁ f ∘ δ.η A ≈ h ∘ F₁ (g ∘ F₁ f ∘ δ.η A) ∘ δ.η A
assoc′ {A} {B} {C} {D} {f} {g} {h} =
begin
(h ∘ F₁ g ∘ δ.η B) ∘ (F₁ f ∘ δ.η A) ≈⟨ assoc²' ⟩
h ∘ (F₁ g ∘ (δ.η B ∘ (F₁ f ∘ δ.η A))) ≈⟨ ((refl⟩∘⟨ (refl⟩∘⟨ sym assoc))) ⟩
h ∘ (F₁ g ∘ ((δ.η B ∘ F₁ f) ∘ δ.η A)) ≈⟨ ((refl⟩∘⟨ (refl⟩∘⟨ pushˡ (δ.commute f)))) ⟩
h ∘ (F₁ g ∘ (F₁ (F₁ f) ∘ (δ.η (F₀ A) ∘ δ.η A))) ≈⟨ refl⟩∘⟨ (refl⟩∘⟨ pushʳ (Comonad.assoc M)) ⟩
h ∘ (F₁ g ∘ ((F₁ (F₁ f) ∘ F₁ (δ.η A)) ∘ δ.η A)) ≈⟨ pull-center (sym trihom) ⟩
h ∘ (F₁ (g ∘ (F₁ f ∘ δ.η A)) ∘ δ.η A)
∎
identityˡ′ : ∀ {A B : Obj} {f : F₀ A ⇒ B} → ε.η B ∘ F₁ f ∘ δ.η A ≈ f
identityˡ′ {A} {B} {f} =
begin
ε.η B ∘ F₁ f ∘ δ.η A ≈⟨ pullˡ (ε.commute f) ⟩
(f ∘ ε.η (F₀ A)) ∘ δ.η A ≈⟨ trans (pullʳ (Comonad.identityʳ M)) identityʳ ⟩
f
∎
identityʳ′ : ∀ {A B : Obj} {f : F₀ A ⇒ B} → f ∘ F₁ (ε.η A) ∘ δ.η A ≈ f
identityʳ′ {A} {B} {f} = elimʳ (Comonad.identityˡ M)
identity²′ : {A : Obj} → ε.η A ∘ F₁ (ε.η A) ∘ δ.η A ≈ ε.η A
identity²′ = elimʳ (Comonad.identityˡ M) | {
"alphanum_fraction": 0.4996102884,
"avg_line_length": 34.2133333333,
"ext": "agda",
"hexsha": "ba29c71bf5f25789f97ed16422fa1b8372226a96",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/CoKleisli.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/CoKleisli.agda",
"max_line_length": 143,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/CoKleisli.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-22T03:54:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-21T17:07:19.000Z",
"num_tokens": 1263,
"size": 2566
} |
import Data.Integer as Integer
open Integer using (ℤ)
module NumberTheory.ModularArithmetic (m : ℤ) where
open import Algebra.Structures
open Integer hiding (+_; _-_) -- using (_+_; _*_; -_; +0)
open import Data.Integer.GCD
open import Data.Integer.Properties hiding (*-1-isMonoid; *-1-isCommutativeMonoid; +-*-isCommutativeRing)
open import Data.Integer.Tactic.RingSolver
open import Data.Product
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
_≈_ : Rel ℤ _
x ≈ y = ∃ λ k → k * m + x ≡ y
refl : Reflexive _≈_
refl {x} = +0 , (begin
+0 * m + x
≡⟨ ≡.cong (_+ x) (*-zeroˡ m) ⟩
+0 + x
≡⟨ +-identityˡ x ⟩
x
∎)
where
open ≡.≡-Reasoning
sym : Symmetric _≈_
sym {x} {y} (k , p) = (- k) , (begin
- k * m + y
≡˘⟨ ≡.cong₂ _+_ (neg-distribˡ-* k m) (neg-involutive y) ⟩
- (k * m) + - - y
≡˘⟨ neg-distrib-+ (k * m) (- y) ⟩
- (k * m + - y)
≡⟨ ≡.cong -_ (begin
k * m + - y
≡˘⟨ +-identityʳ _ ⟩
k * m + - y + +0
≡˘⟨ ≡.cong (k * m + - y +_) (+-inverseʳ x) ⟩
k * m + - y + (x + - x)
≡˘⟨ +-assoc (k * m + - y) x (- x) ⟩
k * m + - y + x + - x
≡⟨ ≡.cong (_+ - x) (begin
k * m + - y + x
≡⟨ +-assoc (k * m) (- y) x ⟩
k * m + (- y + x)
≡⟨ ≡.cong (k * m +_) (+-comm (- y) x) ⟩
k * m + (x + - y)
≡˘⟨ +-assoc (k * m) x (- y) ⟩
k * m + x + - y
≡⟨ ≡.cong (_+ - y) p ⟩
y + - y
≡⟨ +-inverseʳ y ⟩
+0
∎) ⟩
+0 + - x
≡⟨ +-identityˡ (- x) ⟩
- x
∎) ⟩
- - x
≡⟨ neg-involutive x ⟩
x
∎)
where
open ≡.≡-Reasoning
trans : Transitive _≈_
trans {x} {y} {z} (j , p) (k , q) = k + j , (begin
(k + j) * m + x
≡⟨ ≡.cong (_+ x) (*-distribʳ-+ (m) k j) ⟩
k * m + j * m + x
≡⟨ +-assoc (k * m) (j * m) x ⟩
k * m + (j * m + x)
≡⟨ ≡.cong (_+_ (k * m)) p ⟩
k * m + y
≡⟨ q ⟩
z
∎)
where
open ≡.≡-Reasoning
≈-isEquivalence : IsEquivalence _≈_
≈-isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
open IsEquivalence ≈-isEquivalence public using (reflexive)
setoid : Setoid _ _
setoid = record { isEquivalence = ≈-isEquivalence }
open import Algebra.Definitions _≈_
+-cong : Congruent₂ _+_
+-cong {x} {y} {u} {v} (j , p) (k , q) = j + k , (begin
(j + k) * m + (x + u)
≡⟨ ≡.cong (_+ (x + u)) (*-distribʳ-+ m j k) ⟩
j * m + k * m + (x + u)
≡˘⟨ +-assoc (j * m + k * m) x u ⟩
j * m + k * m + x + u
≡⟨ ≡.cong (_+ u) (begin
j * m + k * m + x
≡⟨ +-assoc (j * m) (k * m) x ⟩
j * m + (k * m + x)
≡⟨ ≡.cong (j * m +_) (+-comm (k * m) x) ⟩
j * m + (x + k * m)
≡˘⟨ +-assoc (j * m) x (k * m) ⟩
j * m + x + k * m
∎) ⟩
j * m + x + k * m + u
≡⟨ +-assoc (j * m + x) (k * m) u ⟩
j * m + x + (k * m + u)
≡⟨ ≡.cong₂ _+_ p q ⟩
y + v
∎)
where
open ≡.≡-Reasoning
*-cong : Congruent₂ _*_
*-cong {x} {y} {u} {v} (j , p) (k , q) = j * m * k + j * u + x * k , (begin
(j * m * k + j * u + x * k) * m + x * u
≡⟨ ≡.cong (_+ x * u) (begin
(j * m * k + j * u + x * k) * m
≡⟨ *-distribʳ-+ m (j * m * k + j * u) (x * k) ⟩
(j * m * k + j * u) * m + (x * k) * m
≡⟨ ≡.cong₂ _+_ (*-distribʳ-+ m (j * m * k) (j * u)) (*-assoc x k m) ⟩
j * m * k * m + j * u * m + x * (k * m)
≡⟨ ≡.cong (_+ x * (k * m)) (begin
j * m * k * m + (j * u) * m
≡⟨ ≡.cong (_+ j * u * m) (*-assoc (j * m) k m) ⟩
j * m * (k * m) + j * u * m
≡⟨ ≡.cong (j * m * (k * m) +_) (begin
j * u * m
≡⟨ *-assoc j u m ⟩
j * (u * m)
≡⟨ ≡.cong (j *_) (*-comm u m) ⟩
j * (m * u)
≡˘⟨ *-assoc j m u ⟩
j * m * u
∎) ⟩
(j * m) * (k * m) + (j * m) * u
∎) ⟩
j * m * (k * m) + j * m * u + x * (k * m)
∎) ⟩
(j * m) * (k * m) + (j * m) * u + x * (k * m) + x * u
≡⟨ +-assoc ((j * m) * (k * m) + (j * m) * u) (x * (k * m)) (x * u) ⟩
(j * m) * (k * m) + (j * m) * u + (x * (k * m) + x * u)
≡˘⟨ ≡.cong₂ _+_ (*-distribˡ-+ (j * m) (k * m) u) (*-distribˡ-+ x (k * m) u) ⟩
(j * m) * (k * m + u) + x * (k * m + u)
≡˘⟨ *-distribʳ-+ (k * m + u) (j * m) x ⟩
(j * m + x) * (k * m + u)
≡⟨ ≡.cong₂ _*_ p q ⟩
y * v
∎)
where
open ≡.≡-Reasoning
neg-cong : Congruent₁ -_
neg-cong {x} {y} (k , p) = - k , (begin
- k * m + - x
≡˘⟨ ≡.cong (_+ - x) (neg-distribˡ-* k m) ⟩
- (k * m) + - x
≡˘⟨ neg-distrib-+ (k * m) x ⟩
- (k * m + x)
≡⟨ ≡.cong -_ p ⟩
- y
∎)
where
open ≡.≡-Reasoning
+-0-isAbelianGroup : IsAbelianGroup _≈_ _+_ +0 -_
+-0-isAbelianGroup = record
{ isGroup = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≈-isEquivalence
; ∙-cong = +-cong
}
; assoc = λ x y z → reflexive (+-assoc x y z)
}
; identity = (λ x → reflexive (+-identityˡ x)) , λ x → reflexive (+-identityʳ x)
}
; inverse = (λ x → reflexive (+-inverseˡ x)) , λ x → reflexive(+-inverseʳ x)
; ⁻¹-cong = neg-cong
}
; comm = λ x y → reflexive (+-comm x y)
}
*-1-isCommutativeMonoid : IsCommutativeMonoid _≈_ _*_ (Integer.+ 1)
*-1-isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = ≈-isEquivalence
; ∙-cong = *-cong
}
; assoc = λ x y z → reflexive (*-assoc x y z)
}
; identity = (λ x → reflexive (*-identityˡ x)) , λ x → reflexive (*-identityʳ x )
}
; comm = λ x y → reflexive (*-comm x y)
}
open IsCommutativeMonoid *-1-isCommutativeMonoid using () renaming (isMonoid to *-1-isMonoid)
+-*-isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ +0 (Integer.+ 1)
+-*-isCommutativeRing = record
{ isRing = record
{ +-isAbelianGroup = +-0-isAbelianGroup
; *-isMonoid = *-1-isMonoid
; distrib = (λ x y z → reflexive (*-distribˡ-+ x y z)) , λ x y z → reflexive (*-distribʳ-+ x y z)
; zero = (λ x → reflexive (*-zeroˡ x)) , λ x → reflexive (*-zeroʳ x)
}
; *-comm = λ x y → reflexive (*-comm x y)
}
| {
"alphanum_fraction": 0.4233635774,
"avg_line_length": 27.8018018018,
"ext": "agda",
"hexsha": "0b5318cab5dae8e5c4faf160a80379bec15b3971",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8c3a4235a16f66a94267aada287bd8ee7d054ead",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/antlion",
"max_forks_repo_path": "src/NumberTheory/ModularArithmetic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c3a4235a16f66a94267aada287bd8ee7d054ead",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/antlion",
"max_issues_repo_path": "src/NumberTheory/ModularArithmetic.agda",
"max_line_length": 105,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8c3a4235a16f66a94267aada287bd8ee7d054ead",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/antlion",
"max_stars_repo_path": "src/NumberTheory/ModularArithmetic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2884,
"size": 6172
} |
{-# OPTIONS -v tc.lhs.unify:80 #-}
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
postulate
A : Set
a : A
record Foo : Set where
constructor foo
field anA : A
test : (f : A → A) (x : Foo) → foo (f a) ≡ x → A
test f .(foo (f a)) refl = a
| {
"alphanum_fraction": 0.5212355212,
"avg_line_length": 17.2666666667,
"ext": "agda",
"hexsha": "3648c91a12c5bd3a05c81f291699f3f039a182c9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1809.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1809.agda",
"max_line_length": 48,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1809.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 110,
"size": 259
} |
module Highlighting where
Set-one : Set₂
Set-one = Set₁
record R (A : Set) : Set-one where
constructor con
field X : Set
F : Set → Set → Set
F A B = B
field P : F A X → Set
-- highlighting of non-terminating definition
Q : F A X → Set
Q = Q
postulate P : _
open import Highlighting.M
data D (A : Set) : Set-one where
d : let X = D in X A
postulate _+_ _×_ : Set → Set → Set
infixl 4 _×_ _+_
-- Issue #2140: the operators should be highlighted also in the
-- fixity declaration.
| {
"alphanum_fraction": 0.6340508806,
"avg_line_length": 15.96875,
"ext": "agda",
"hexsha": "c54372827314c06ff97ce104d13cb1090188eb74",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/interaction/Highlighting.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/interaction/Highlighting.agda",
"max_line_length": 65,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/interaction/Highlighting.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 170,
"size": 511
} |
------------------------------------------------------------------------
-- Integers, defined using a quotient type
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Integer.Quotient
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Prelude as P hiding (suc; _*_; _^_) renaming (_+_ to _⊕_)
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Equality.Path.Isomorphisms.Univalence eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Equivalence-relation equality-with-J
open import Erased.Cubical eq
open import Function-universe equality-with-J hiding (id; _∘_)
open import Group equality-with-J as G using (Group; Abelian; _≃ᴳ_)
open import Group.Cyclic eq as C using (Generated-by; Cyclic)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq using (∣_∣)
import Integer equality-with-J as Data
import Nat equality-with-J as Nat
open import Quotient eq as Q hiding (elim; rec)
open import Univalence-axiom equality-with-J
private
variable
m m₁ m₂ n n₁ n₂ : ℕ
a : Level
A : Type a
i j p q : A
------------------------------------------------------------------------
-- The relation used to define the integers.
-- Two pairs of natural numbers are related if they have the same
-- difference.
Same-difference : ℕ × ℕ → ℕ × ℕ → Type
Same-difference (m₁ , n₁) (m₂ , n₂) = m₁ ⊕ n₂ ≡ n₁ ⊕ m₂
-- The relation is pointwise propositional.
Same-difference-propositional :
Is-proposition (Same-difference p q)
Same-difference-propositional = ℕ-set
-- The relation is an equivalence relation.
Same-difference-is-equivalence-relation :
Is-equivalence-relation Same-difference
Same-difference-is-equivalence-relation = record
{ reflexive = λ { {m , n} →
m ⊕ n ≡⟨ Nat.+-comm m ⟩∎
n ⊕ m ∎
}
; symmetric = λ { {m₁ , n₁} {m₂ , n₂} hyp →
m₂ ⊕ n₁ ≡⟨ Nat.+-comm m₂ ⟩
n₁ ⊕ m₂ ≡⟨ sym hyp ⟩
m₁ ⊕ n₂ ≡⟨ Nat.+-comm m₁ ⟩∎
n₂ ⊕ m₁ ∎
}
; transitive = λ { {m₁ , n₁} {m₂ , n₂} {m₃ , n₃} hyp₁ hyp₂ →
Nat.+-cancellativeʳ (
m₁ ⊕ n₃ ⊕ m₂ ≡⟨ sym $ Nat.+-assoc m₁ ⟩
m₁ ⊕ (n₃ ⊕ m₂) ≡⟨ cong (m₁ ⊕_) $ Nat.+-comm n₃ ⟩
m₁ ⊕ (m₂ ⊕ n₃) ≡⟨ cong (m₁ ⊕_) hyp₂ ⟩
m₁ ⊕ (n₂ ⊕ m₃) ≡⟨ Nat.+-assoc m₁ ⟩
m₁ ⊕ n₂ ⊕ m₃ ≡⟨ cong (_⊕ m₃) hyp₁ ⟩
n₁ ⊕ m₂ ⊕ m₃ ≡⟨ sym $ Nat.+-assoc n₁ ⟩
n₁ ⊕ (m₂ ⊕ m₃) ≡⟨ cong (n₁ ⊕_) $ Nat.+-comm m₂ ⟩
n₁ ⊕ (m₃ ⊕ m₂) ≡⟨ Nat.+-assoc n₁ ⟩∎
n₁ ⊕ m₃ ⊕ m₂ ∎)
}
}
-- It is decidable whether the relation holds.
Same-difference-decidable : ∀ p → Dec (Same-difference p q)
Same-difference-decidable _ = _ Nat.≟ _
------------------------------------------------------------------------
-- Integers
-- Integers.
ℤ : Type
ℤ = (ℕ × ℕ) / Same-difference
-- The integers form a set.
ℤ-set : Is-set ℤ
ℤ-set = /-is-set
-- Turns natural numbers into the corresponding integers.
infix 8 +_
+_ : ℕ → ℤ
+ n = [ (n , 0) ]
-- Turns natural numbers into the corresponding negative integers.
-[_] : ℕ → ℤ
-[ n ] = [ (0 , n) ]
------------------------------------------------------------------------
-- A lemma
-- Increasing both sides of a pair by one does not affect the value of
-- the corresponding integer.
[]≡[suc,suc] : _≡_ {A = ℤ} [ (m , n) ] [ (P.suc m , P.suc n) ]
[]≡[suc,suc] {m = m} {n = n} = []-respects-relation
(m ⊕ P.suc n ≡⟨ sym $ Nat.suc+≡+suc m ⟩
P.suc m ⊕ n ≡⟨ Nat.+-comm (P.suc m) ⟩∎
n ⊕ P.suc m ∎)
------------------------------------------------------------------------
-- A one-to-one correspondence between two definitions of integers
-- There is a bijection between this variant of integers and the one
-- in Integer.
ℤ↔ℤ : ℤ ↔ Data.ℤ
ℤ↔ℤ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
to-lemma₁ : m₁ ⊕ P.suc n₂ ≡ m₂ →
(Data.+ m₁) ≡ Data.+ m₂ +-[1+ n₂ ]
to-lemma₁ {m₁ = m₁} {n₂ = n₂} {m₂ = zero} hyp =
⊥-elim $
Nat.0≢+
(zero ≡⟨ sym hyp ⟩
m₁ ⊕ P.suc n₂ ≡⟨ sym $ Nat.suc+≡+suc m₁ ⟩∎
P.suc (m₁ ⊕ n₂) ∎)
to-lemma₁ {m₁ = m₁} {n₂ = zero} {m₂ = P.suc m₂} hyp =
cong (Data.+_) $
Nat.cancel-suc
(P.suc m₁ ≡⟨ Nat.+-comm 1 ⟩
m₁ ⊕ 1 ≡⟨ hyp ⟩∎
P.suc m₂ ∎)
to-lemma₁ {m₁ = m₁} {n₂ = P.suc n₂} {m₂ = P.suc m₂} hyp =
to-lemma₁ $
Nat.cancel-suc
(P.suc (m₁ ⊕ P.suc n₂) ≡⟨ Nat.suc+≡+suc m₁ ⟩
m₁ ⊕ P.suc (P.suc n₂) ≡⟨ hyp ⟩∎
P.suc m₂ ∎)
to-lemma₂ : m₁ ⊕ zero ≡ P.suc n₁ ⊕ m₂ →
Data.+ m₁ +-[1+ n₁ ] ≡ Data.+ m₂
to-lemma₂ {m₁ = zero} hyp =
⊥-elim $ Nat.0≢+ hyp
to-lemma₂ {m₁ = P.suc m₁} {n₁ = zero} {m₂ = m₂} hyp =
cong (Data.+_) $
Nat.cancel-suc
(P.suc m₁ ≡⟨ sym Nat.+-right-identity ⟩
P.suc m₁ ⊕ 0 ≡⟨ hyp ⟩∎
P.suc m₂ ∎)
to-lemma₂ {m₁ = P.suc m₁} {n₁ = P.suc n₁} hyp =
to-lemma₂ (Nat.cancel-suc hyp)
to-lemma₃ :
∀ m₁ n₁ m₂ n₂ →
m₁ ⊕ P.suc n₂ ≡ P.suc n₁ ⊕ m₂ →
Data.+ m₁ +-[1+ n₁ ] ≡ Data.+ m₂ +-[1+ n₂ ]
to-lemma₃ (P.suc m₁) (P.suc n₁) m₂ n₂ hyp =
to-lemma₃ m₁ n₁ m₂ n₂ (Nat.cancel-suc hyp)
to-lemma₃ m₁ n₁ (P.suc m₂) (P.suc n₂) hyp =
to-lemma₃ m₁ n₁ m₂ n₂ $
Nat.cancel-suc
(P.suc (m₁ ⊕ P.suc n₂) ≡⟨ Nat.suc+≡+suc m₁ ⟩
m₁ ⊕ P.suc (P.suc n₂) ≡⟨ hyp ⟩
P.suc n₁ ⊕ P.suc m₂ ≡⟨ cong P.suc $ sym $ Nat.suc+≡+suc n₁ ⟩∎
P.suc (P.suc n₁ ⊕ m₂) ∎)
to-lemma₃ zero n₁ zero n₂ hyp =
cong Data.-[1+_] $
Nat.cancel-suc
(P.suc n₁ ≡⟨ sym Nat.+-right-identity ⟩
P.suc n₁ ⊕ 0 ≡⟨ sym hyp ⟩∎
P.suc n₂ ∎)
to-lemma₃ (P.suc m₁) zero (P.suc m₂) zero hyp =
cong (Data.+_) $
Nat.cancel-suc $
(P.suc m₁ ≡⟨ Nat.+-comm 1 ⟩
m₁ ⊕ 1 ≡⟨ Nat.cancel-suc hyp ⟩∎
P.suc m₂ ∎)
to-lemma₃ (P.suc m₁) zero zero n₂ hyp =
⊥-elim $ Nat.0≢+
(0 ≡⟨ sym $ Nat.cancel-suc hyp ⟩
m₁ ⊕ P.suc n₂ ≡⟨ sym $ Nat.suc+≡+suc m₁ ⟩∎
P.suc (m₁ ⊕ n₂) ∎)
to-lemma₃ zero n₁ (P.suc m₂) zero hyp =
⊥-elim $ Nat.0≢+
(0 ≡⟨ Nat.cancel-suc hyp ⟩
n₁ ⊕ P.suc m₂ ≡⟨ sym $ Nat.suc+≡+suc n₁ ⟩∎
P.suc (n₁ ⊕ m₂) ∎)
to-lemma :
∀ m₁ n₁ m₂ n₂ →
Same-difference (m₁ , n₁) (m₂ , n₂) →
Data.+ m₁ Data.- Data.+ n₁ ≡
Data.+ m₂ Data.- Data.+ n₂
to-lemma m₁ zero m₂ zero hyp =
Data.+ (m₁ ⊕ 0) ≡⟨ cong Data.+_ hyp ⟩
Data.+ m₂ ≡⟨ cong Data.+_ (sym Nat.+-right-identity) ⟩∎
Data.+ (m₂ ⊕ 0) ∎
to-lemma m₁ zero m₂ (P.suc n₂) hyp =
Data.+ (m₁ ⊕ 0) ≡⟨ cong Data.+_ Nat.+-right-identity ⟩
Data.+ m₁ ≡⟨ to-lemma₁ hyp ⟩∎
Data.+ m₂ +-[1+ n₂ ] ∎
to-lemma m₁ (P.suc n₁) m₂ zero hyp =
Data.+ m₁ +-[1+ n₁ ] ≡⟨ to-lemma₂ hyp ⟩
Data.+ m₂ ≡⟨ cong Data.+_ (sym Nat.+-right-identity) ⟩∎
Data.+ (m₂ ⊕ 0) ∎
to-lemma m₁ (P.suc n₁) m₂ (P.suc n₂) hyp =
Data.+ m₁ +-[1+ n₁ ] ≡⟨ to-lemma₃ _ _ _ _ hyp ⟩∎
Data.+ m₂ +-[1+ n₂ ] ∎
to : ℤ → Data.ℤ
to = Q.rec λ where
.[]ʳ (m , n) → Data.+ m Data.- Data.+ n
.[]-respects-relationʳ {x = m₁ , n₁} {y = m₂ , n₂} →
to-lemma m₁ n₁ m₂ n₂
.is-setʳ → Data.ℤ-set
from : Data.ℤ → ℤ
from (Data.+ n) = + n
from Data.-[1+ n ] = [ (0 , P.suc n) ]
to∘from : ∀ i → to (from i) ≡ i
to∘from (Data.+ n) =
to (from (Data.+ n)) ≡⟨⟩
Data.+ (n ⊕ 0) ≡⟨ cong Data.+_ Nat.+-right-identity ⟩∎
Data.+ n ∎
to∘from Data.-[1+ n ] =
to (from Data.-[1+ n ]) ≡⟨⟩
Data.-[1+ n ] ∎
from-+_+-[1+_] :
∀ m n → from (Data.+ m +-[1+ n ]) ≡ [ (m , P.suc n) ]
from-+ zero +-[1+ n ] = refl _
from-+ P.suc m +-[1+ zero ] = []≡[suc,suc]
from-+ P.suc m +-[1+ P.suc n ] =
from (Data.+ P.suc m +-[1+ P.suc n ]) ≡⟨⟩
from (Data.+ m +-[1+ n ]) ≡⟨ from-+ m +-[1+ n ] ⟩
[ (m , P.suc n) ] ≡⟨ []≡[suc,suc] ⟩∎
[ (P.suc m , P.suc (P.suc n)) ] ∎
from∘to : ∀ i → from (to i) ≡ i
from∘to = Q.elim-prop λ where
.[]ʳ (m , zero) →
from (to (+ m)) ≡⟨⟩
+ (m ⊕ 0) ≡⟨ cong +_ Nat.+-right-identity ⟩∎
+ m ∎
.[]ʳ (m , P.suc n) →
from (to [ (m , P.suc n) ]) ≡⟨⟩
from (Data.+ m +-[1+ n ]) ≡⟨ from-+ m +-[1+ n ] ⟩∎
[ (m , P.suc n) ] ∎
.is-propositionʳ _ → ℤ-set
-- The bijection is homomorphic with respect to +_/Data.+_.
ℤ↔ℤ-+ : _↔_.to ℤ↔ℤ (+ n) ≡ Data.+ n
ℤ↔ℤ-+ {n = n} =
Data.+ (n ⊕ 0) ≡⟨ cong Data.+_ Nat.+-right-identity ⟩∎
Data.+ n ∎
-- The bijection is homomorphic with respect to -[_]/Data.-[_].
ℤ↔ℤ--[] : _↔_.to ℤ↔ℤ -[ n ] ≡ Data.-[ n ]
ℤ↔ℤ--[] {n = zero} = Data.+ 0 ∎
ℤ↔ℤ--[] {n = P.suc n} = Data.-[1+ n ] ∎
------------------------------------------------------------------------
-- An eliminator and a recursor with poor computational behaviour
module _ where
private
-- An eliminator for integers. This eliminator is not exported,
-- because it is basically just the eliminator for quotients.
elim :
(P : ℤ → Type p) →
(∀ i → Is-set (P i)) →
(f : ∀ m n → P [ (m , n) ]) →
(∀ {p q} (s : Same-difference p q) →
subst P ([]-respects-relation s) (uncurry f p) ≡ uncurry f q) →
∀ i → P i
elim _ P-set f resp = Q.elim λ where
.[]ʳ → uncurry f
.[]-respects-relationʳ → resp
.is-setʳ → P-set
-- The following computation rule holds by definition.
elim-[] :
(P : ℤ → Type p) →
(P-set : ∀ i → Is-set (P i)) →
(f : ∀ m n → P [ (m , n) ]) →
(resp : ∀ {p q} (s : Same-difference p q) →
subst P ([]-respects-relation s) (uncurry f p) ≡
uncurry f q) →
elim P P-set f resp [ (m , n) ] ≡ f m n
elim-[] _ _ _ _ = refl _
private
-- A helper function used in the implementation of elim.
elim′ :
(P : ℤ → Type p) →
(∀ n → P (_↔_.from ℤ↔ℤ (Data.+ n))) →
(∀ n → P (_↔_.from ℤ↔ℤ Data.-[1+ n ])) →
∀ i → P (_↔_.from ℤ↔ℤ i)
elim′ _ p n (Data.+ m) = p m
elim′ _ p n Data.-[1+ m ] = n m
-- An eliminator for integers.
--
-- Note that the motive does not have to be a family of sets, and
-- that the function does not need to respect the relation
-- Same-difference.
elim :
(P : ℤ → Type p) →
(∀ m n → P [ (m , n) ]) →
∀ i → P i
elim P f i = $⟨ elim′ P (λ n → f n 0) (λ n → f 0 (P.suc n)) (_↔_.to ℤ↔ℤ i) ⟩
P (_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ i)) ↝⟨ subst P (_↔_.left-inverse-of ℤ↔ℤ i) ⟩□
P i □
mutual
-- A "computation" rule for elim.
--
-- Here the function is required to respect Same-difference. Note that
-- this "computation" rule does not (at the time of writing) in
-- general hold by definition.
elim-[] :
{P : ℤ → Type p}
(f : ∀ m n → P [ (m , n) ]) →
(∀ {p q} (s : Same-difference p q) →
subst P ([]-respects-relation s) (uncurry f p) ≡ uncurry f q) →
elim P f [ (m , n) ] ≡ f m n
elim-[] f hyp = elim-[]′ f (λ _ _ → hyp _)
-- A variant of the computation rule in which the requirement to
-- respect Same-difference has been replaced by a more specific
-- condition.
elim-[]′ :
{P : ℤ → Type p}
(f : ∀ m n → P [ (m , n) ]) →
(∀ m n → subst P []≡[suc,suc] (f m n) ≡ f (P.suc m) (P.suc n)) →
elim P f [ (m , n) ] ≡ f m n
elim-[]′ {m = m} {n = zero} {P = P} f hyp =
elim P f [ (m , 0) ] ≡⟨⟩
subst P (cong +_ Nat.+-right-identity) (f (m ⊕ 0) 0) ≡⟨ sym $ subst-∘ _ _ _ ⟩
subst (P ∘ +_) Nat.+-right-identity (f (m ⊕ 0) 0) ≡⟨ elim¹ (λ eq → subst (P ∘ +_) eq (f _ _) ≡ f _ _) (subst-refl _ _) _ ⟩∎
f m 0 ∎
elim-[]′ {m = m} {n = P.suc n} {P = P} f hyp =
elim P f [ (m , P.suc n) ] ≡⟨⟩
subst P (_↔_.left-inverse-of ℤ↔ℤ [ (m , P.suc n) ]) $
elim′ P (λ n → f n 0) (λ n → f 0 (P.suc n)) (Data.+ m +-[1+ n ]) ≡⟨ lemma m n ⟩∎
f m (P.suc n) ∎
where
lemma :
∀ m n →
subst P (_↔_.left-inverse-of ℤ↔ℤ [ (m , P.suc n) ])
(elim′ P (λ n → f n 0) (λ n → f 0 (P.suc n))
(Data.+ m +-[1+ n ])) ≡
f m (P.suc n)
lemma zero n =
subst P (refl _) (f 0 (P.suc n)) ≡⟨ subst-refl _ _ ⟩∎
f 0 (P.suc n) ∎
lemma (P.suc m) zero =
subst P []≡[suc,suc] (f m 0) ≡⟨ hyp _ _ ⟩∎
f (P.suc m) 1 ∎
lemma (P.suc m) (P.suc n) =
subst P
(trans (_↔_.left-inverse-of ℤ↔ℤ [ (m , P.suc n) ])
[]≡[suc,suc])
(elim′ P (λ n → f n 0) (λ n → f 0 (P.suc n))
(Data.+ m +-[1+ n ])) ≡⟨ sym $ subst-subst _ _ _ _ ⟩
subst P []≡[suc,suc]
(subst P (_↔_.left-inverse-of ℤ↔ℤ [ (m , P.suc n) ])
(elim′ P (λ n → f n 0) (λ n → f 0 (P.suc n))
(Data.+ m +-[1+ n ]))) ≡⟨ cong (subst P ([]-respects-relation _)) $
lemma m n ⟩
subst P []≡[suc,suc] (f m (P.suc n)) ≡⟨ hyp _ _ ⟩∎
f (P.suc m) (P.suc (P.suc n)) ∎
private
-- A helper function used in the implementation of rec.
rec′ : (ℕ → A) → (ℕ → A) → Data.ℤ → A
rec′ p n (Data.+ m) = p m
rec′ p n Data.-[1+ m ] = n m
-- A recursor for integers.
rec : (ℕ → ℕ → A) → ℤ → A
rec {A = A} f =
ℤ ↔⟨ ℤ↔ℤ ⟩
Data.ℤ ↝⟨ rec′ (λ n → f n 0) (λ n → f 0 (P.suc n)) ⟩□
A □
-- The recursor could have been defined in terms of the eliminator.
--
-- The recursor is not defined in terms of the eliminator in this way
-- because (in at least some cases) this would lead to different
-- computational behaviour.
rec≡elim : (f : ℕ → ℕ → A) → rec f i ≡ elim (const _) f i
rec≡elim {i = i} f =
rec f i ≡⟨⟩
rec′ (λ n → f n 0) (λ n → f 0 (P.suc n)) (_↔_.to ℤ↔ℤ i) ≡⟨ lemma (_↔_.to ℤ↔ℤ i) ⟩
elim′ (const _) (λ n → f n 0) (λ n → f 0 (P.suc n)) (_↔_.to ℤ↔ℤ i) ≡⟨ sym $ subst-const _ ⟩
subst (const _) (_↔_.left-inverse-of ℤ↔ℤ i) $
elim′ (const _) (λ n → f n 0) (λ n → f 0 (P.suc n)) (_↔_.to ℤ↔ℤ i) ≡⟨⟩
elim (const _) f i ∎
where
lemma :
∀ i →
rec′ (λ n → f n 0) (λ n → f 0 (P.suc n)) i ≡
elim′ (const _) (λ n → f n 0) (λ n → f 0 (P.suc n)) i
lemma (Data.+ _) = refl _
lemma Data.-[1+ _ ] = refl _
-- A "computation" rule for rec.
--
-- Note that this "computation" rule does not (at the time of writing)
-- in general hold by definition.
rec-[] :
(f : ℕ → ℕ → A) →
(∀ {p q} → Same-difference p q → uncurry f p ≡ uncurry f q) →
rec f [ (m , n) ] ≡ f m n
rec-[] {m = m} {n = n} f hyp =
rec f [ (m , n) ] ≡⟨ rec≡elim f ⟩
elim (const _) f [ (m , n) ] ≡⟨ elim-[] f (λ {p q} s →
subst (const _) ([]-respects-relation s) (uncurry f p) ≡⟨ subst-const _ ⟩
uncurry f p ≡⟨ hyp s ⟩∎
uncurry f q ∎) ⟩∎
f m n ∎
------------------------------------------------------------------------
-- Negation, addition and subtraction
-- A helper function that can be used to define unary operators on
-- integers.
unary-operator :
(f : ℕ × ℕ → ℕ × ℕ) →
(∀ {i j} →
Same-difference i j →
Same-difference (f i) (f j)) →
ℤ → ℤ
unary-operator f resp = Q.rec λ where
.[]ʳ i → [ f i ]
.[]-respects-relationʳ s → []-respects-relation (resp s)
.is-setʳ → ℤ-set
private
-- A computation rule for unary-operator.
--
-- The function is not defined using the recursor above, but rather
-- the quotient eliminator, to ensure that this computation rule
-- holds by definition.
unary-operator-[] :
(f : ℕ × ℕ → ℕ × ℕ) →
(resp : ∀ {i j} →
Same-difference i j →
Same-difference (f i) (f j)) →
∀ i → unary-operator f resp [ i ] ≡ [ f i ]
unary-operator-[] _ _ _ = refl _
-- A helper function that can be used to define binary operators on
-- integers.
binary-operator :
(f : ℕ × ℕ → ℕ × ℕ → ℕ × ℕ) →
(∀ {i₁ i₂ j₁ j₂} →
Same-difference i₁ i₂ →
Same-difference j₁ j₂ →
Same-difference (f i₁ j₁) (f i₂ j₂)) →
ℤ → ℤ → ℤ
binary-operator f resp = Q.rec λ where
.[]ʳ i → Q.rec λ where
.[]ʳ j → [ f i j ]
.[]-respects-relationʳ s →
[]-respects-relation (resp (Nat.+-comm (proj₁ i)) s)
.is-setʳ → ℤ-set
.[]-respects-relationʳ s → ⟨ext⟩ $ Q.elim-prop λ where
.[]ʳ i → []-respects-relation (resp s (Nat.+-comm (proj₁ i)))
.is-propositionʳ _ → +⇒≡ {n = 1} ℤ-set
.is-setʳ →
Π-closure ext 2 λ _ →
ℤ-set
private
-- A computation rule for binary-operator.
--
-- The function is not defined using the recursor above, but rather
-- the quotient eliminator, to ensure that this computation rule
-- holds by definition.
binary-operator-[] :
(f : ℕ × ℕ → ℕ × ℕ → ℕ × ℕ) →
(resp : ∀ {i₁ i₂ j₁ j₂} →
Same-difference i₁ i₂ →
Same-difference j₁ j₂ →
Same-difference (f i₁ j₁) (f i₂ j₂)) →
∀ i j → binary-operator f resp [ i ] [ j ] ≡ [ f i j ]
binary-operator-[] _ _ _ _ = refl _
-- Negation.
infix 8 -_
-_ : ℤ → ℤ
-_ = unary-operator swap sym
-- Addition.
infixl 6 _+_
_+_ : ℤ → ℤ → ℤ
_+_ = binary-operator
(Σ-zip _⊕_ _⊕_)
(λ { {k₁ , k₂} {ℓ₁ , ℓ₂} {m₁ , m₂} {n₁ , n₂} hyp₁ hyp₂ →
(k₁ ⊕ m₁) ⊕ (ℓ₂ ⊕ n₂) ≡⟨ lemma k₁ ⟩
(k₁ ⊕ ℓ₂) ⊕ (m₁ ⊕ n₂) ≡⟨ cong₂ _⊕_ hyp₁ hyp₂ ⟩
(k₂ ⊕ ℓ₁) ⊕ (m₂ ⊕ n₁) ≡⟨ lemma k₂ ⟩∎
(k₂ ⊕ m₂) ⊕ (ℓ₁ ⊕ n₁) ∎
})
where
lemma : ∀ _ {_ _ _} → _
lemma a {b} {c} {d} =
(a ⊕ b) ⊕ (c ⊕ d) ≡⟨ sym $ Nat.+-assoc a ⟩
a ⊕ (b ⊕ (c ⊕ d)) ≡⟨ cong (a ⊕_) $ Nat.+-assoc b ⟩
a ⊕ ((b ⊕ c) ⊕ d) ≡⟨ cong ((a ⊕_) ∘ (_⊕ d)) $ Nat.+-comm b ⟩
a ⊕ ((c ⊕ b) ⊕ d) ≡⟨ cong (a ⊕_) $ sym $ Nat.+-assoc c ⟩
a ⊕ (c ⊕ (b ⊕ d)) ≡⟨ Nat.+-assoc a ⟩∎
(a ⊕ c) ⊕ (b ⊕ d) ∎
-- Subtraction.
infixl 6 _-_
_-_ : ℤ → ℤ → ℤ
i - j = i + - j
-- The implementation of negation given here matches the one in
-- Integer.
-₁≡-₁ : ∀ i → - (_↔_.from ℤ↔ℤ i) ≡ _↔_.from ℤ↔ℤ (Data.- i)
-₁≡-₁ (Data.+ zero) = -[ 0 ] ∎
-₁≡-₁ (Data.+ (P.suc n)) = -[ P.suc n ] ∎
-₁≡-₁ Data.-[1+ n ] = + P.suc n ∎
-- A lemma used in the implementation of +≡+.
++-[1+]≡++-[1+] : + m + -[ P.suc n ] ≡ _↔_.from ℤ↔ℤ (Data.+ m +-[1+ n ])
++-[1+]≡++-[1+] {m = zero} {n = n} = refl _
++-[1+]≡++-[1+] {m = P.suc m} {n = zero} =
[ (P.suc (m ⊕ 0) , 1) ] ≡⟨ cong (Q.[_] ∘ (_, 1) ∘ P.suc) Nat.+-right-identity ⟩
[ (P.suc m , 1) ] ≡⟨ sym []≡[suc,suc] ⟩∎
[ (m , 0) ] ∎
++-[1+]≡++-[1+] {m = P.suc m} {n = P.suc n} =
+ P.suc m + -[ P.suc (P.suc n) ] ≡⟨ sym []≡[suc,suc] ⟩
+ m + -[ P.suc n ] ≡⟨ ++-[1+]≡++-[1+] ⟩
_↔_.from ℤ↔ℤ (Data.+ m +-[1+ n ]) ≡⟨⟩
_↔_.from ℤ↔ℤ (Data.+ P.suc m +-[1+ P.suc n ]) ∎
-- The implementation of addition given here matches the one in
-- Integer.
+≡+ :
∀ i →
(_↔_.from ℤ↔ℤ i) + (_↔_.from ℤ↔ℤ j) ≡ _↔_.from ℤ↔ℤ (i Data.+ j)
+≡+ {j = Data.+ n} (Data.+ m) = + (m ⊕ n) ∎
+≡+ {j = Data.-[1+ n ]} (Data.+ m) = ++-[1+]≡++-[1+]
+≡+ {j = Data.+ n} Data.-[1+ m ] =
-[ P.suc m ] + + n ≡⟨ []-respects-relation (
n ⊕ P.suc m ≡⟨ Nat.+-comm n ⟩
P.suc m ⊕ n ≡⟨ sym $ cong₂ _⊕_ (Nat.+-right-identity {n = P.suc m}) Nat.+-right-identity ⟩∎
P.suc m ⊕ 0 ⊕ (n ⊕ 0) ∎) ⟩
+ n + -[ P.suc m ] ≡⟨ ++-[1+]≡++-[1+] ⟩∎
_↔_.from ℤ↔ℤ (Data.+ n +-[1+ m ]) ∎
+≡+ {j = Data.-[1+ n ]} Data.-[1+ m ] =
-[ P.suc m ⊕ P.suc n ] ≡⟨ cong (-[_] ∘ P.suc) $ sym $ Nat.suc+≡+suc _ ⟩∎
-[ P.suc (P.suc (m ⊕ n)) ] ∎
-- The implementation of subtraction given here matches the one in
-- Integer.
-≡- :
∀ i j →
(_↔_.from ℤ↔ℤ i) - (_↔_.from ℤ↔ℤ j) ≡ _↔_.from ℤ↔ℤ (i Data.- j)
-≡- i j =
(_↔_.from ℤ↔ℤ i) - (_↔_.from ℤ↔ℤ j) ≡⟨⟩
(_↔_.from ℤ↔ℤ i) + - (_↔_.from ℤ↔ℤ j) ≡⟨ cong (λ j → _↔_.from ℤ↔ℤ i + j) $ -₁≡-₁ j ⟩
_↔_.from ℤ↔ℤ i + _↔_.from ℤ↔ℤ (Data.- j) ≡⟨ +≡+ i ⟩
_↔_.from ℤ↔ℤ (i Data.+ Data.- j) ≡⟨⟩
_↔_.from ℤ↔ℤ (i Data.- j) ∎
------------------------------------------------------------------------
-- Some lemmas related to equality
-- The Same-difference relation is pointwise equivalent to equality
-- under [_] (assuming propositional extensionality).
Same-difference≃[]≡[] :
Propositional-extensionality lzero →
Same-difference i j ≃ ([ i ] ≡ [ j ])
Same-difference≃[]≡[] prop-ext =
related≃[equal]
prop-ext
Same-difference-is-equivalence-relation
(λ {p} → Same-difference-propositional {p = p})
-- Non-negative integers are not equal to negative integers.
+≢-[1+] : + m ≢ -[ P.suc n ]
+≢-[1+] {m = m} {n = n} =
Stable-¬
[ + m ≡ -[ P.suc n ] ↔⟨⟩
[ (m , 0) ] ≡ [ (0 , P.suc n) ] ↔⟨ inverse $ Same-difference≃[]≡[] prop-ext ⟩
Same-difference (m , 0) (0 , P.suc n) ↔⟨⟩
m ⊕ P.suc n ≡ 0 ↝⟨ trans (Nat.suc+≡+suc m) ⟩
P.suc (m ⊕ n) ≡ 0 ↝⟨ Nat.0≢+ ∘ sym ⟩□
⊥ □
]
-- Non-positive integers are not equal to positive integers.
+[1+]≢- : + P.suc m ≢ -[ n ]
+[1+]≢- {m = m} {n = n} =
Stable-¬
[ + P.suc m ≡ -[ n ] ↔⟨⟩
[ (P.suc m , 0) ] ≡ [ (0 , n) ] ↔⟨ inverse $ Same-difference≃[]≡[] prop-ext ⟩
Same-difference (P.suc m , 0) (0 , n) ↔⟨⟩
P.suc m ⊕ n ≡ 0 ↝⟨ Nat.0≢+ ∘ sym ⟩□
⊥ □
]
-- The +_ "constructor" is cancellative (assuming propositional
-- extensionality).
+-cancellative :
Propositional-extensionality lzero →
+ m ≡ + n → m ≡ n
+-cancellative {m = m} {n = n} prop-ext =
+ m ≡ + n ↔⟨⟩
[ (m , 0) ] ≡ [ (n , 0) ] ↔⟨ inverse $ Same-difference≃[]≡[] prop-ext ⟩
m ⊕ 0 ≡ 0 ⊕ n ↝⟨ trans (sym Nat.+-right-identity) ⟩□
m ≡ n □
-- The -[_] "constructor" is cancellative (assuming propositional
-- extensionality).
-[]-cancellative :
Propositional-extensionality lzero →
-[ m ] ≡ -[ n ] → m ≡ n
-[]-cancellative {m = m} {n = n} prop-ext =
-[ m ] ≡ -[ n ] ↝⟨ cong (-_) ⟩
+ m ≡ + n ↝⟨ +-cancellative prop-ext ⟩□
m ≡ n □
-- Equality of integers is decidable (assuming propositional
-- extensionality).
infix 4 [_]_≟_
[_]_≟_ :
Propositional-extensionality lzero →
Decidable-equality ℤ
[_]_≟_ prop-ext = Q.elim-prop λ where
.[]ʳ i → Q.elim-prop λ where
.[]ʳ _ →
⊎-map (_≃_.to $ Same-difference≃[]≡[] prop-ext)
(_∘ _≃_.from (Same-difference≃[]≡[] prop-ext))
(Same-difference-decidable i)
.is-propositionʳ _ →
Dec-closure-propositional ext ℤ-set
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Dec-closure-propositional ext ℤ-set
-- Erased equality of integers is decidable.
infix 4 _≟_
_≟_ : Decidable-erased-equality ℤ
_≟_ = Q.elim-prop λ where
.[]ʳ i → Q.elim-prop λ where
.[]ʳ _ →
Dec-Erased-map
(from-equivalence $ Same-difference≃[]≡[] prop-ext) $
Dec→Dec-Erased $
Same-difference-decidable i
.is-propositionʳ _ →
Is-proposition-Dec-Erased ext ℤ-set
.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Is-proposition-Dec-Erased ext ℤ-set
------------------------------------------------------------------------
-- The successor and predecessor functions
-- The successor function.
suc : ℤ → ℤ
suc = Q.rec λ where
.[]ʳ (m , n) → [ (P.suc m , n) ]
.[]-respects-relationʳ {x = m₁ , m₂} {y = n₁ , n₂} hyp →
[]-respects-relation
(P.suc (m₁ ⊕ n₂) ≡⟨ cong P.suc hyp ⟩
P.suc (m₂ ⊕ n₁) ≡⟨ Nat.suc+≡+suc _ ⟩∎
m₂ ⊕ P.suc n₁ ∎ )
.is-setʳ → ℤ-set
-- The function suc adds one to its input.
suc≡1+ : ∀ i → suc i ≡ + 1 + i
suc≡1+ = elim _ λ _ _ → refl _
-- The predecessor function.
pred : ℤ → ℤ
pred = Q.rec λ where
.[]ʳ (m , n) → [ (m , P.suc n) ]
.[]-respects-relationʳ {x = m₁ , m₂} {y = n₁ , n₂} hyp →
[]-respects-relation
(m₁ ⊕ P.suc n₂ ≡⟨ sym $ Nat.suc+≡+suc _ ⟩
P.suc (m₁ ⊕ n₂) ≡⟨ cong P.suc hyp ⟩∎
P.suc (m₂ ⊕ n₁) ∎)
.is-setʳ → ℤ-set
-- The function pred subtracts one from its input.
pred≡-1+ : ∀ i → pred i ≡ -[ 1 ] + i
pred≡-1+ = elim _ λ _ _ → refl _
-- An equivalence between ℤ and ℤ corresponding to the successor
-- function.
successor : ℤ ≃ ℤ
successor = Eq.↔→≃
suc
pred
(elim _ λ m _ → []-respects-relation (cong P.suc (Nat.+-comm m)))
(elim _ λ m _ → []-respects-relation (cong P.suc (Nat.+-comm m)))
------------------------------------------------------------------------
-- Positive, negative
-- The property of being positive.
Positive : ℤ → Type
Positive = Data.Positive ∘ _↔_.to ℤ↔ℤ
-- Positive is propositional.
Positive-propositional : ∀ i → Is-proposition (Positive i)
Positive-propositional _ = Data.Positive-propositional
-- The property of being negative.
Negative : ℤ → Type
Negative = Data.Negative ∘ _↔_.to ℤ↔ℤ
-- Negative is propositional.
Negative-propositional : ∀ i → Is-proposition (Negative i)
Negative-propositional _ = Data.Negative-propositional
-- No integer is both positive and negative.
¬+- : ∀ i → Positive i → Negative i → ⊥₀
¬+- _ = Data.¬+-
-- No integer is both positive and equal to zero.
¬+0 : Positive i → i ≡ + 0 → ⊥₀
¬+0 pos ≡0 = Data.¬+0 pos (_↔_.from-to ℤ↔ℤ (sym ≡0))
-- No integer is both negative and equal to zero.
¬-0 : Negative i → i ≡ + 0 → ⊥₀
¬-0 neg ≡0 = Data.¬-0 neg (_↔_.from-to ℤ↔ℤ (sym ≡0))
-- One can decide if an integer is negative, zero or positive.
-⊎0⊎+ : ∀ i → Negative i ⊎ i ≡ + 0 ⊎ Positive i
-⊎0⊎+ i =
⊎-map id (⊎-map (sym ∘ _↔_.to-from ℤ↔ℤ) id)
(Data.-⊎0⊎+ $ _↔_.to ℤ↔ℤ i)
-- If i and j are positive, then i + j is positive.
>0→>0→+>0 : ∀ i j → Positive i → Positive j → Positive (i + j)
>0→>0→+>0 i j i+ j+ = $⟨ Data.>0→>0→+>0 (_↔_.to ℤ↔ℤ i) (_↔_.to ℤ↔ℤ j) i+ j+ ⟩
Data.Positive (_↔_.to ℤ↔ℤ i Data.+ _↔_.to ℤ↔ℤ j) ↝⟨ subst Data.Positive $
sym $ _↔_.from-to ℤ↔ℤ $ sym $ +≡+ (_↔_.to ℤ↔ℤ i) ⟩
Data.Positive (_↔_.to ℤ↔ℤ (_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ i) +
_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ j))) ↔⟨⟩
Positive (_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ i) + _↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ j)) ↝⟨ subst Positive $
cong₂ _+_
(_↔_.left-inverse-of ℤ↔ℤ i)
(_↔_.left-inverse-of ℤ↔ℤ j) ⟩□
Positive (i + j) □
-- If i and j are negative, then i + j is negative.
<0→<0→+<0 : ∀ i j → Negative i → Negative j → Negative (i + j)
<0→<0→+<0 i j i- j- = $⟨ Data.<0→<0→+<0 (_↔_.to ℤ↔ℤ i) (_↔_.to ℤ↔ℤ j) i- j- ⟩
Data.Negative (_↔_.to ℤ↔ℤ i Data.+ _↔_.to ℤ↔ℤ j) ↝⟨ subst Data.Negative $
sym $ _↔_.from-to ℤ↔ℤ $ sym $ +≡+ (_↔_.to ℤ↔ℤ i) ⟩
Data.Negative (_↔_.to ℤ↔ℤ (_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ i) +
_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ j))) ↔⟨⟩
Negative (_↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ i) + _↔_.from ℤ↔ℤ (_↔_.to ℤ↔ℤ j)) ↝⟨ subst Negative $
cong₂ _+_
(_↔_.left-inverse-of ℤ↔ℤ i)
(_↔_.left-inverse-of ℤ↔ℤ j) ⟩□
Negative (i + j) □
------------------------------------------------------------------------
-- The group of integers
-- The group of integers.
ℤ-group : Group lzero
ℤ-group .Group.Carrier = ℤ
ℤ-group .Group.Carrier-is-set = ℤ-set
ℤ-group .Group._∘_ = _+_
ℤ-group .Group.id = + 0
ℤ-group .Group._⁻¹ = -_
ℤ-group .Group.assoc =
elim _ λ m₁ n₁ → elim _ λ _ _ → elim _ λ _ _ →
cong [_] $ cong₂ _,_
(Nat.+-assoc m₁)
(Nat.+-assoc n₁)
ℤ-group .Group.left-identity =
elim _ λ _ _ → refl _
ℤ-group .Group.right-identity =
elim _ λ _ _ →
cong [_] $ cong₂ _,_
Nat.+-right-identity
Nat.+-right-identity
ℤ-group .Group.left-inverse =
elim _ λ _ n →
[]-respects-relation (cong (_⊕ 0) $ Nat.+-comm n)
ℤ-group .Group.right-inverse =
elim _ λ m _ →
[]-respects-relation (cong (_⊕ 0) $ Nat.+-comm m)
-- ℤ-group is isomorphic to Data.ℤ-group.
ℤ≃ᴳℤ : ℤ-group ≃ᴳ Data.ℤ-group
ℤ≃ᴳℤ = G.≃ᴳ-sym λ where
.G.Homomorphic.related → Eq.↔⇒≃ (inverse ℤ↔ℤ)
.G.Homomorphic.homomorphic i _ → sym (+≡+ i)
-- ℤ-group is equal to Data.ℤ-group (assuming univalence).
ℤ≡ℤ :
Univalence lzero →
ℤ-group ≡ Data.ℤ-group
ℤ≡ℤ univ = _≃_.to (G.≃ᴳ≃≡ ext univ) ℤ≃ᴳℤ
-- The group of integers is generated by + 1.
ℤ-generated-by-1 : Generated-by ℤ-group (+ 1)
ℤ-generated-by-1 =
C.≃ᴳ→Generated-by→Generated-by
(G.≃ᴳ-sym ℤ≃ᴳℤ)
C.ℤ-generated-by-1
-- The group of integers is cyclic.
ℤ-cyclic : Cyclic ℤ-group
ℤ-cyclic = ∣ _ , ℤ-generated-by-1 ∣
-- The group of integers is abelian.
ℤ-abelian : Abelian ℤ-group
ℤ-abelian = C.Cyclic→Abelian ℤ-group ℤ-cyclic
-- The direct product of the group of integers and the group of
-- integers is not cyclic.
ℤ×ℤ-not-cyclic : ¬ Cyclic (ℤ-group G.× ℤ-group)
ℤ×ℤ-not-cyclic =
Cyclic (ℤ-group G.× ℤ-group) ↝⟨ C.≃ᴳ→Cyclic→Cyclic (G.↝-× ℤ≃ᴳℤ ℤ≃ᴳℤ) ⟩
Cyclic (Data.ℤ-group G.× Data.ℤ-group) ↝⟨ C.ℤ×ℤ-not-cyclic ⟩□
⊥ □
-- The group of integers is not isomorphic to the direct product of
-- the group of integers and the group of integers.
ℤ≄ᴳℤ×ℤ : ¬ ℤ-group ≃ᴳ (ℤ-group G.× ℤ-group)
ℤ≄ᴳℤ×ℤ =
ℤ-group ≃ᴳ (ℤ-group G.× ℤ-group) ↝⟨ G.↝ᴳ-trans (G.≃ᴳ-sym ℤ≃ᴳℤ) ∘ flip G.↝ᴳ-trans (G.↝-× ℤ≃ᴳℤ ℤ≃ᴳℤ) ⟩
Data.ℤ-group ≃ᴳ (Data.ℤ-group G.× Data.ℤ-group) ↝⟨ C.ℤ≄ᴳℤ×ℤ ⟩□
⊥ □
-- The group of integers is not equal to the direct product of the
-- group of integers and the group of integers.
ℤ≢ℤ×ℤ : ℤ-group ≢ (ℤ-group G.× ℤ-group)
ℤ≢ℤ×ℤ =
ℤ-group ≡ (ℤ-group G.× ℤ-group) ↝⟨ flip (subst (ℤ-group ≃ᴳ_)) G.↝ᴳ-refl ⟩
ℤ-group ≃ᴳ (ℤ-group G.× ℤ-group) ↝⟨ ℤ≄ᴳℤ×ℤ ⟩□
⊥ □
| {
"alphanum_fraction": 0.4627105811,
"avg_line_length": 32.7797311272,
"ext": "agda",
"hexsha": "0df4e05c45fb4b1cc9cb926b2f3cdf7f09fbc890",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Integer/Quotient.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Integer/Quotient.agda",
"max_line_length": 131,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Integer/Quotient.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 12712,
"size": 31698
} |
-- Reported by guillaume.brunerie, Sep 18, 2013
-- Andreas, 2013-10-27 issue submitted by Guilliaume Brunerie
{-# OPTIONS --copatterns #-}
module Issue907 where
-- Globular types as a coinductive record
record Glob : Set1 where
coinductive
field
Ob : Set
Hom : (a b : Ob) → Glob
open Glob public
Glob-corec : {A : Set1} (Ob* : A → Set)
(Hom* : (x : A) (a b : Ob* x) → A) → (A → Glob)
Ob (Glob-corec Ob* Hom* x) = Ob* x
Hom (Glob-corec Ob* Hom* x) a b = Glob-corec Ob* Hom* (Hom* x a b)
-- For the second equation to type-check,
-- we need to reduce with the first equation!
| {
"alphanum_fraction": 0.6333333333,
"avg_line_length": 25,
"ext": "agda",
"hexsha": "4500edff360802492227edd74fc16e72c293e838",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue907.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue907.agda",
"max_line_length": 66,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue907.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 209,
"size": 600
} |
module Oscar.Category.CategoryAction where
open import Oscar.Category.Action
open import Oscar.Category.Category
open import Oscar.Category.SemigroupoidAction
open import Oscar.Category.Setoid
open import Oscar.Level
module _ {𝔊𝔬 𝔊𝔪 𝔊𝔮} (category : Category 𝔊𝔬 𝔊𝔪 𝔊𝔮) where
open Category category
module _ {𝔄𝔬 𝔄𝔮} (action : Action ⋆ 𝔄𝔬 𝔄𝔮) where
open Action action
record IsCategoryAction
(_◂_ : ∀ {x y} → x ↦ y → ↥ x → ↥ y)
: Set (𝔊𝔬 ⊔ 𝔊𝔪 ⊔ 𝔊𝔮 ⊔ 𝔄𝔬 ⊔ 𝔄𝔮) where
field ⦃ isSemigroupoidAction ⦄ : IsSemigroupoidAction semigroupoid action _◂_
field identity : ∀ {x} → (s : ↥ x) → ε ◂ s ≋ s
open IsCategoryAction ⦃ … ⦄ public
record CategoryAction 𝔊𝔬 𝔊𝔪 𝔊𝔮 𝔄𝔬 𝔄𝔮 : Set (lsuc (𝔊𝔬 ⊔ 𝔊𝔪 ⊔ 𝔊𝔮 ⊔ 𝔄𝔬 ⊔ 𝔄𝔮)) where
constructor [_/_]
field category : Category 𝔊𝔬 𝔊𝔪 𝔊𝔮
open Category category public
field action : Action ⋆ 𝔄𝔬 𝔄𝔮
open Action action public
field _◂_ : ∀ {x y} → x ↦ y → ↥ x → ↥ y
field ⦃ isCategoryAction ⦄ : IsCategoryAction category action _◂_
semgroupoidAction : SemigroupoidAction _ _ _ _ _
SemigroupoidAction.semigroupoid semgroupoidAction = semigroupoid
SemigroupoidAction.action semgroupoidAction = action
SemigroupoidAction._◂_ semgroupoidAction = _◂_
| {
"alphanum_fraction": 0.7040650407,
"avg_line_length": 31.5384615385,
"ext": "agda",
"hexsha": "fcc96a7ad7f9366d0b9be158e0a6baad39862552",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Category/CategoryAction.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Category/CategoryAction.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Category/CategoryAction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 519,
"size": 1230
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Morphisms between algebraic structures
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Algebra.Morphism where
open import Relation.Binary
open import Algebra
open import Algebra.FunctionProperties
import Algebra.Properties.Group as GroupP
open import Function
open import Level
import Relation.Binary.Reasoning.Setoid as EqR
------------------------------------------------------------------------
-- Basic definitions
module Definitions {f t ℓ}
(From : Set f) (To : Set t) (_≈_ : Rel To ℓ) where
Morphism : Set _
Morphism = From → To
Homomorphic₀ : Morphism → From → To → Set _
Homomorphic₀ ⟦_⟧ ∙ ∘ = ⟦ ∙ ⟧ ≈ ∘
Homomorphic₁ : Morphism → Fun₁ From → Op₁ To → Set _
Homomorphic₁ ⟦_⟧ ∙_ ∘_ = ∀ x → ⟦ ∙ x ⟧ ≈ (∘ ⟦ x ⟧)
Homomorphic₂ : Morphism → Fun₂ From → Op₂ To → Set _
Homomorphic₂ ⟦_⟧ _∙_ _∘_ =
∀ x y → ⟦ x ∙ y ⟧ ≈ (⟦ x ⟧ ∘ ⟦ y ⟧)
------------------------------------------------------------------------
-- Structure homomorphisms
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : Semigroup c₁ ℓ₁)
(To : Semigroup c₂ ℓ₂) where
private
module F = Semigroup From
module T = Semigroup To
open Definitions F.Carrier T.Carrier T._≈_
record IsSemigroupMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
⟦⟧-cong : ⟦_⟧ Preserves F._≈_ ⟶ T._≈_
∙-homo : Homomorphic₂ ⟦_⟧ F._∙_ T._∙_
syntax IsSemigroupMorphism From To F = F Is From -Semigroup⟶ To
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : Monoid c₁ ℓ₁)
(To : Monoid c₂ ℓ₂) where
private
module F = Monoid From
module T = Monoid To
open Definitions F.Carrier T.Carrier T._≈_
record IsMonoidMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
sm-homo : IsSemigroupMorphism F.semigroup T.semigroup ⟦_⟧
ε-homo : Homomorphic₀ ⟦_⟧ F.ε T.ε
open IsSemigroupMorphism sm-homo public
syntax IsMonoidMorphism From To F = F Is From -Monoid⟶ To
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : CommutativeMonoid c₁ ℓ₁)
(To : CommutativeMonoid c₂ ℓ₂) where
private
module F = CommutativeMonoid From
module T = CommutativeMonoid To
open Definitions F.Carrier T.Carrier T._≈_
record IsCommutativeMonoidMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
mn-homo : IsMonoidMorphism F.monoid T.monoid ⟦_⟧
open IsMonoidMorphism mn-homo public
syntax IsCommutativeMonoidMorphism From To F = F Is From -CommutativeMonoid⟶ To
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : IdempotentCommutativeMonoid c₁ ℓ₁)
(To : IdempotentCommutativeMonoid c₂ ℓ₂) where
private
module F = IdempotentCommutativeMonoid From
module T = IdempotentCommutativeMonoid To
open Definitions F.Carrier T.Carrier T._≈_
record IsIdempotentCommutativeMonoidMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
mn-homo : IsMonoidMorphism F.monoid T.monoid ⟦_⟧
open IsMonoidMorphism mn-homo public
isCommutativeMonoidMorphism :
IsCommutativeMonoidMorphism F.commutativeMonoid T.commutativeMonoid ⟦_⟧
isCommutativeMonoidMorphism = record { mn-homo = mn-homo }
syntax IsIdempotentCommutativeMonoidMorphism From To F = F Is From -IdempotentCommutativeMonoid⟶ To
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : Group c₁ ℓ₁)
(To : Group c₂ ℓ₂) where
private
module F = Group From
module T = Group To
open Definitions F.Carrier T.Carrier T._≈_
record IsGroupMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
mn-homo : IsMonoidMorphism F.monoid T.monoid ⟦_⟧
open IsMonoidMorphism mn-homo public
⁻¹-homo : Homomorphic₁ ⟦_⟧ F._⁻¹ T._⁻¹
⁻¹-homo x = let open EqR T.setoid in T.uniqueˡ-⁻¹ ⟦ x F.⁻¹ ⟧ ⟦ x ⟧ $ begin
⟦ x F.⁻¹ ⟧ T.∙ ⟦ x ⟧ ≈⟨ T.sym (∙-homo (x F.⁻¹) x) ⟩
⟦ x F.⁻¹ F.∙ x ⟧ ≈⟨ ⟦⟧-cong (F.inverseˡ x) ⟩
⟦ F.ε ⟧ ≈⟨ ε-homo ⟩
T.ε ∎
syntax IsGroupMorphism From To F = F Is From -Group⟶ To
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : AbelianGroup c₁ ℓ₁)
(To : AbelianGroup c₂ ℓ₂) where
private
module F = AbelianGroup From
module T = AbelianGroup To
open Definitions F.Carrier T.Carrier T._≈_
record IsAbelianGroupMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
gp-homo : IsGroupMorphism F.group T.group ⟦_⟧
open IsGroupMorphism gp-homo public
syntax IsAbelianGroupMorphism From To F = F Is From -AbelianGroup⟶ To
module _ {c₁ ℓ₁ c₂ ℓ₂}
(From : Ring c₁ ℓ₁)
(To : Ring c₂ ℓ₂) where
private
module F = Ring From
module T = Ring To
open Definitions F.Carrier T.Carrier T._≈_
record IsRingMorphism (⟦_⟧ : Morphism) :
Set (c₁ ⊔ ℓ₁ ⊔ c₂ ⊔ ℓ₂) where
field
+-abgp-homo : ⟦_⟧ Is F.+-abelianGroup -AbelianGroup⟶ T.+-abelianGroup
*-mn-homo : ⟦_⟧ Is F.*-monoid -Monoid⟶ T.*-monoid
syntax IsRingMorphism From To F = F Is From -Ring⟶ To
| {
"alphanum_fraction": 0.598285603,
"avg_line_length": 29.3314285714,
"ext": "agda",
"hexsha": "c866460d403082201ea137b08d6e3a7cc28e5b11",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Morphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Morphism.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Morphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1856,
"size": 5133
} |
module Function.Equals.Proofs where
import Lvl
open import Data
import Functional
import Function.Equals
open import Logic.Predicate
open import Logic.Propositional
open import Structure.Setoid
open import Structure.Function
import Structure.Operator.Names as Names
open import Structure.Operator.Properties
open import Structure.Operator
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Syntax.Transitivity
open import Syntax.Type
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓₑ ℓᵤ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ : Lvl.Level
module Dependent where
open Functional using (id)
open import Functional.Dependent
open Function.Equals.Dependent
module _ {A : Type{ℓ₁}} {B : A → Type{ℓ₂}} ⦃ equiv-B : ∀{a} → Equiv{ℓₑ₂}(B(a)) ⦄ where
[⊜]-identityₗ : Identityₗ {T₂ = (a : A) → B(a)} (_∘_)(id)
_⊜_.proof (Identityₗ.proof [⊜]-identityₗ) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity equiv-B ⦄
module _ {A : Type{ℓ₁}} {B : Type{ℓ₂}} {C : B → Type{ℓ₂}} ⦃ equiv-C : ∀{b} → Equiv{ℓₑ₃}(C(b)) ⦄ where
[⊜][∘]ₗ-function-raw : ∀{f₁ f₂ : (b : B) → C(b)}{g : A → B} → (f₁ ⊜ f₂) → ((f₁ ∘ g) ⊜ (f₂ ∘ g))
[⊜][∘]ₗ-function-raw {g = g} (intro feq) = intro(\{x} → feq{g(x)})
module _ {A : Type{ℓ₁}} {B : A → Type{ℓ₂}} {C : (a : A) → B(a) → Type{ℓ₃}} ⦃ equiv-C : ∀{a}{b} → Equiv{ℓₑ₃}(C(a)(b)) ⦄ where
[⊜][∘ₛ]ₗ-function-raw : ∀{f₁ f₂ : (a : A) → (b : B(a)) → C(a)(b)}{g : (a : A) → B(a)} → (f₁ ⊜ f₂) → ((f₁ ∘ₛ g) ⊜ (f₂ ∘ₛ g))
[⊜][∘ₛ]ₗ-function-raw {g = g} (intro feq) = intro(\{x} → _⊜_.proof (feq{x}) {g(x)})
-- module _ {A : Type{ℓ₁}} {B : Type{ℓ₂}} {C : B → Type{ℓ₃}} ⦃ _ : Equiv(B) ⦄ ⦃ equiv-C : ∀{b} → Equiv(C(b)) ⦄ {f₁ f₂ : (b : B) → C(b)} ⦃ _ : Function(f₂) ⦄ where (TODO: Requires Function to be able to take a dependent function)
-- [⊜][∘]-binaryOperator-raw : (f₁ ⊜ f₂) → ∀{g₁ g₂ : A → B} → (g₁ ⊜ g₂) → (f₁ ∘ g₁ ⊜ f₂ ∘ g₂)
-- [⊜][∘]-binaryOperator-raw feq (intro geq) = [⊜][∘]ₗ-function-raw feq 🝖 (intro(congruence₁(f₂) (geq)))
open Functional
open Function.Equals
private variable A B C D A₁ A₂ B₁ B₂ : Type{ℓ}
-- TODO: Rename all these so that they mention (_∘_)
module _ ⦃ _ : let _ = A in Equiv{ℓₑ₂}(B) ⦄ where
[⊜]-identityₗ : Identityₗ {T₂ = A → B} (_∘_)(id)
_⊜_.proof(Identityₗ.proof([⊜]-identityₗ)) = reflexivity(_≡_)
[⊜]-identityᵣ : Identityᵣ {T₁ = A → B} (_∘_)(id)
_⊜_.proof(Identityᵣ.proof([⊜]-identityᵣ)) = reflexivity(_≡_)
module _ ⦃ _ : Equiv{ℓₑ}(A) ⦄ where
[⊜]-identity : Identity {T = A → A} (_∘_)(id)
[⊜]-identity = intro ⦃ left = [⊜]-identityₗ ⦄ ⦃ right = [⊜]-identityᵣ ⦄
module _ ⦃ _ : let _ = A ; _ = B ; _ = C ; _ = D in Equiv{ℓₑ₄}(D) ⦄ where
[⊜]-associativity : Names.AssociativityPattern {T₁ = C → D} {T₂ = B → C} {T₃ = A → B} (_∘_)(_∘_)(_∘_)(_∘_)
_⊜_.proof ([⊜]-associativity {f} {g} {h}) {x} = reflexivity(_≡_)
module _ ⦃ _ : Equiv{ℓₑ₁}(Empty{ℓₑ}) ⦄ where
[⊜]-emptyₗ : ∀{f g : A → Empty{ℓₑ}} → (f ⊜ g)
[⊜]-emptyₗ {f = f} = intro(\{x} → empty(f(x)))
module _ ⦃ _ : Equiv{ℓₑ}(A) ⦄ where
[⊜]-emptyᵣ : ∀{f g : Empty{ℓₑ} → A} → (f ⊜ g)
[⊜]-emptyᵣ = intro(\{})
module _ ⦃ _ : Equiv{ℓₑ}(Unit{ℓᵤ}) ⦄ where
[⊜]-unitₗ : ∀{f g : A → Unit{ℓᵤ}} → (f ⊜ g)
[⊜]-unitₗ = intro(reflexivity(_≡_))
module _ ⦃ _ : let _ = A ; _ = B ; _ = C in Equiv{ℓₑ₃}(C) ⦄ where
[⊜][∘]ₗ-function-raw : ∀{f₁ f₂ : B → C}{g : A → B} → (f₁ ⊜ f₂) → ((f₁ ∘ g) ⊜ (f₂ ∘ g))
[⊜][∘]ₗ-function-raw {g = g} (intro feq) = intro(\{x} → feq{g(x)})
module _ ⦃ _ : let _ = A in Equiv{ℓₑ₂}(B) ⦄ ⦃ _ : Equiv{ℓₑ₃}(C) ⦄ {f₁ f₂ : B → C} ⦃ func₂ : Function(f₂) ⦄ {g₁ g₂ : A → B} where
[⊜][∘]-binaryOperator-raw : (f₁ ⊜ f₂) → (g₁ ⊜ g₂) → (f₁ ∘ g₁ ⊜ f₂ ∘ g₂)
[⊜][∘]-binaryOperator-raw feq (intro geq) = [⊜][∘]ₗ-function-raw feq 🝖 (intro(congruence₁(f₂) (geq)))
module _ ⦃ _ : let _ = A in Equiv{ℓₑ₂}(B) ⦄ ⦃ _ : Equiv{ℓₑ₃}(C) ⦄ ⦃ function : ∀{f : B → C} → Function(f) ⦄ where
instance
[⊜][∘]-binaryOperator : BinaryOperator(_∘_ {X = A}{Y = B}{Z = C})
BinaryOperator.congruence [⊜][∘]-binaryOperator = [⊜][∘]-binaryOperator-raw
module _ ⦃ _ : let _ = A in Equiv{ℓₑ₂}(B) ⦄ where
[⊜]-abstract : ∀{a b : B} → (a ≡ b) → ((x ↦ a) ⊜ ((x ↦ b) :of: (A → B)))
[⊜]-abstract {a} {b} x = intro x
[⊜]-apply : ∀{f g : A → B} → (f ⊜ g) → (∀{x} → (f(x) ≡ g(x)))
[⊜]-apply (intro proof) = proof
-- TODO: Is this correct?
-- [⊜]-not-all : ∀{ℓ₁ ℓ₂}{T₁ : Type{ℓ₁}}{T₂ : Type{ℓ₂}} → (∀{f g : T₁ → T₂} → (f ⊜ g)) → IsEmpty(T₁)
-- [⊜]-not-all{_}{_} {_} {_}{_} = intro(\{})
{- TODO: What assumptions? Unprovable?
module _
{ℓ} -- {ℓ₁}{ℓ₂}{ℓ₃}{ℓ₄}
{A : Type{ℓ}} ⦃ _ : Equiv(A) ⦄
{B : Type{ℓ}} ⦃ _ : Equiv(B) ⦄
{C : Type{ℓ}} ⦃ eq-c : Equiv(C) ⦄
{D : Type{ℓ}} ⦃ eq-d : Equiv(D) ⦄
{f : (A → B) → (C → D)}
⦃ fn : ∀{ab} → Function {T₁ = C} ⦃ eq-c ⦄ {T₂ = D} ⦃ eq-d ⦄ (f(ab)) ⦄
where
instance
[⊜]-function : Function {T₁ = A → B} ⦃ [⊜]-equiv ⦄ {T₂ = C → D} ⦃ [⊜]-equiv ⦄ (f)
_⊜_.proof (Function.congruence ([⊜]-function) {g} {h} (intro eq)) {x} = {!!}
-}
| {
"alphanum_fraction": 0.5386468581,
"avg_line_length": 43.3130434783,
"ext": "agda",
"hexsha": "be5e46febca696923d3b57af86fa9a80608df749",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Function/Equals/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Function/Equals/Proofs.agda",
"max_line_length": 230,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Function/Equals/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 2514,
"size": 4981
} |
{-# OPTIONS --safe #-}
module Definition.Conversion.Conversion where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.RedSteps
open import Definition.Typed.Properties
open import Definition.Conversion
open import Definition.Conversion.Stability
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.Equality
open import Definition.Typed.Consequences.Reduction
open import Tools.Product
import Tools.PropositionalEquality as PE
mutual
-- Conversion of algorithmic equality.
convConv↑Term : ∀ {t u A B Γ Δ l}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ A ≡ B ^ [ ! , l ]
→ Γ ⊢ t [conv↑] u ∷ A ^ l
→ Δ ⊢ t [conv↑] u ∷ B ^ l
convConv↑Term Γ≡Δ A≡B ([↑]ₜ B₁ t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u) =
let _ , ⊢B = syntacticEq A≡B
B′ , whnfB′ , D′ = whNorm ⊢B
B₁≡B′ = trans (sym (subset* D)) (trans A≡B (subset* (red D′)))
in [↑]ₜ B′ t′ u′ (stabilityRed* Γ≡Δ (red D′))
(stabilityRed*Term Γ≡Δ (conv* d B₁≡B′))
(stabilityRed*Term Γ≡Δ (conv* d′ B₁≡B′)) whnfB′ whnft′ whnfu′
(convConv↓Term Γ≡Δ B₁≡B′ whnfB′ t<>u)
-- Conversion of algorithmic equality with terms and types in WHNF.
convConv↓Term : ∀ {t u A B Γ Δ l}
→ ⊢ Γ ≡ Δ
→ Γ ⊢ A ≡ B ^ [ ! , l ]
→ Whnf B
→ Γ ⊢ t [conv↓] u ∷ A ^ l
→ Δ ⊢ t [conv↓] u ∷ B ^ l
convConv↓Term Γ≡Δ A≡B whnfB (ℕ-ins x) rewrite ℕ≡A A≡B whnfB =
ℕ-ins (stability~↓! Γ≡Δ x)
convConv↓Term Γ≡Δ A≡B whnfB (ne x) rewrite U≡A-whnf A≡B whnfB = ne (stability~↓! Γ≡Δ x)
convConv↓Term Γ≡Δ A≡B whnfB (ne-ins t u x x₁) with ne≡A x A≡B whnfB
convConv↓Term Γ≡Δ A≡B whnfB (ne-ins t u x x₁) | B , neB , PE.refl =
ne-ins (stabilityTerm Γ≡Δ (conv t A≡B)) (stabilityTerm Γ≡Δ (conv u A≡B))
neB (stability~↓! Γ≡Δ x₁)
convConv↓Term Γ≡Δ A≡B whnfB (zero-refl x) rewrite ℕ≡A A≡B whnfB =
let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ
in zero-refl ⊢Δ
convConv↓Term Γ≡Δ A≡B whnfB (suc-cong x) rewrite ℕ≡A A≡B whnfB =
suc-cong (stabilityConv↑Term Γ≡Δ x)
convConv↓Term Γ≡Δ A≡B whnfB (η-eq l< l<' x x₁ x₂ y y₁ x₃) with Π≡A A≡B whnfB
convConv↓Term Γ≡Δ A≡B whnfB (η-eq l< l<' x x₁ x₂ y y₁ x₃) | F′ , G′ , PE.refl =
let F≡F′ , rF≡rF′ , _ , _ , G≡G′ = injectivity A≡B
⊢F , ⊢F′ = syntacticEq F≡F′
in η-eq l< l<'
(stability Γ≡Δ ⊢F′) (stabilityTerm Γ≡Δ (conv x₁ A≡B))
(stabilityTerm Γ≡Δ (conv x₂ A≡B)) y y₁
(convConv↑Term (Γ≡Δ ∙ F≡F′) G≡G′ x₃)
convConv↓Term Γ≡Δ A≡B whnfB (U-refl x x₁) rewrite U≡A-whnf A≡B whnfB =
let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in U-refl x ⊢Δ
convConv↓Term Γ≡Δ A≡B whnfB (ℕ-refl x) rewrite U≡A-whnf A≡B whnfB =
let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in ℕ-refl ⊢Δ
convConv↓Term Γ≡Δ A≡B whnfB (Empty-refl x _) rewrite U≡A-whnf A≡B whnfB =
let _ , ⊢Δ , _ = contextConvSubst Γ≡Δ in Empty-refl x ⊢Δ
convConv↓Term Γ≡Δ A≡B whnfB (Π-cong lΠ rF lF lG l< l<' x x₁ x₂) rewrite U≡A-whnf A≡B whnfB =
Π-cong lΠ rF lF lG l< l<' (stability Γ≡Δ x) (stabilityConv↑Term Γ≡Δ x₁) (stabilityConv↑Term (Γ≡Δ ∙ refl x) x₂)
convConv↓Term Γ≡Δ A≡B whnfB (∃-cong lΠ x x₁ x₂) rewrite U≡A-whnf A≡B whnfB =
∃-cong lΠ (stability Γ≡Δ x) (stabilityConv↑Term Γ≡Δ x₁) (stabilityConv↑Term (Γ≡Δ ∙ refl x) x₂)
-- Conversion of algorithmic equality with the same context.
convConvTerm : ∀ {t u A B Γ l}
→ Γ ⊢ t [conv↑] u ∷ A ^ l
→ Γ ⊢ A ≡ B ^ [ ! , l ]
→ Γ ⊢ t [conv↑] u ∷ B ^ l
convConvTerm t<>u A≡B = convConv↑Term (reflConEq (wfEq A≡B)) A≡B t<>u
conv~↑% : ∀ {t u A B Γ l}
-- → ⊢ Γ ≡ Δ
→ Γ ⊢ t ~ u ↑% A ^ l
→ Γ ⊢ A ≡ B ^ [ % , l ]
→ Γ ⊢ t ~ u ↑% B ^ l
conv~↑% (%~↑ ⊢k ⊢l) e = %~↑ (conv ⊢k e) (conv ⊢l e)
--(stabilityTerm ⊢Γ≡Δ (conv ⊢k e)) (stabilityTerm ⊢Γ≡Δ (conv ⊢l e))
convConvTerm%! : ∀ {t u A B Γ r l}
→ Γ ⊢ t [genconv↑] u ∷ A ^ [ r , l ]
→ Γ ⊢ A ≡ B ^ [ r , l ]
→ Γ ⊢ t [genconv↑] u ∷ B ^ [ r , l ]
convConvTerm%! {r = !} = convConvTerm
convConvTerm%! {r = %} = conv~↑%
| {
"alphanum_fraction": 0.5542708825,
"avg_line_length": 43.2448979592,
"ext": "agda",
"hexsha": "b2ea2d0597a1adfa3326693506c078edf5b8ea4d",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Conversion/Conversion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Conversion/Conversion.agda",
"max_line_length": 114,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Conversion/Conversion.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 1882,
"size": 4238
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.