Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --universe-polymorphism #-}
module Data.BitVector.Properties where
open import Algebra using (CommutativeRing)
open import Data.Bool using (_∧_; _∨_; _xor_)
renaming (Bool to Bit; false to 0#; true to 1#)
open import Data.Nat using (ℕ) renaming (zero to Nzero; suc to Nsuc)
open import Data.Product using (_,_)
open import Data.Vec hiding (last)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Data.BitVector
last-cons : ∀ {n} x (xs : BitVector (Nsuc n)) → last (x ∷ xs) ≡ last xs
last-cons _ (x ∷ xs) = refl
last-snoc : ∀ {n} (xs : BitVector n) x → last (snoc xs x) ≡ x
last-snoc [] _ = refl
last-snoc (y ∷ []) _ = refl
last-snoc (y ∷ y′ ∷ ys) x rewrite last-cons y′ (snoc ys x) = last-snoc ys x
droplast-snoc : ∀ {n} (xs : BitVector n) x → droplast (snoc xs x) ≡ xs
droplast-snoc [] _ = refl
droplast-snoc (y ∷ ys) x rewrite droplast-snoc ys x = refl
droplast-snoc-last : ∀ {n} (x : BitVector (Nsuc n)) → snoc (droplast x) (last x) ≡ x
droplast-snoc-last (x ∷ []) = refl
droplast-snoc-last (x ∷ x′ ∷ xs) rewrite droplast-snoc-last (x′ ∷ xs) = refl
rotate∘unrotate≡id : ∀ {n} (x : BitVector n) → rotate (unrotate x) ≡ x
rotate∘unrotate≡id [] = refl
rotate∘unrotate≡id (x ∷ []) = refl
rotate∘unrotate≡id (x ∷ x′ ∷ xs) rewrite last-cons x′ (snoc xs x)
| last-snoc xs x
| droplast-snoc xs x = refl
unrotate∘rotate≡id : ∀ {n} (x : BitVector n) → unrotate (rotate x) ≡ x
unrotate∘rotate≡id [] = refl
unrotate∘rotate≡id (x ∷ xs) = droplast-snoc-last (x ∷ xs)
private
module P {n : ℕ} where
import Algebra.FunctionProperties as FP; open FP (_≡_ {A = BitVector n}) public
open P
+-identityˡ : ∀ {n} → LeftIdentity (zero n) _+_
+-identityˡ [] = refl
+-identityˡ (1# ∷ xs) rewrite +-identityˡ xs = refl
+-identityˡ (0# ∷ xs) rewrite +-identityˡ xs = refl
+-identityʳ : ∀ {n} → RightIdentity (zero n) _+_
+-identityʳ [] = refl
+-identityʳ (1# ∷ xs) rewrite +-identityʳ xs = refl
+-identityʳ (0# ∷ xs) rewrite +-identityʳ xs = refl
add-carry : ∀ {n} c₁ c₂ (x y z : BitVector n) → add′ c₁ x (add′ c₂ y z) ≡ add′ c₂ x (add′ c₁ y z)
add-carry c₁ c₂ [] [] [] = refl
add-carry 0# 0# (0# ∷ xs) (y ∷ ys) (z ∷ zs) = refl
add-carry 0# 0# (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) = refl
add-carry 0# 0# (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) = refl
add-carry 0# 0# (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) = refl
add-carry 0# 0# (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) = refl
add-carry 0# 1# (0# ∷ xs) (0# ∷ ys) (0# ∷ zs) = refl
add-carry 0# 1# (0# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-carry 0# 1# xs ys zs = refl
add-carry 0# 1# (0# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-carry 0# 1# xs ys zs = refl
add-carry 0# 1# (0# ∷ xs) (1# ∷ ys) (1# ∷ zs) = refl
add-carry 0# 1# (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) = refl
add-carry 0# 1# (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-carry 0# 1# xs ys zs = refl
add-carry 0# 1# (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-carry 0# 1# xs ys zs = refl
add-carry 0# 1# (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) = refl
add-carry 1# 0# (0# ∷ xs) (0# ∷ ys) (0# ∷ zs) = refl
add-carry 1# 0# (0# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-carry 1# 0# xs ys zs = refl
add-carry 1# 0# (0# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-carry 1# 0# xs ys zs = refl
add-carry 1# 0# (0# ∷ xs) (1# ∷ ys) (1# ∷ zs) = refl
add-carry 1# 0# (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) = refl
add-carry 1# 0# (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-carry 1# 0# xs ys zs = refl
add-carry 1# 0# (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-carry 1# 0# xs ys zs = refl
add-carry 1# 0# (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) = refl
add-carry 1# 1# (0# ∷ xs) (y ∷ ys) (z ∷ zs) = refl
add-carry 1# 1# (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) = refl
add-carry 1# 1# (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) = refl
add-carry 1# 1# (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) = refl
add-carry 1# 1# (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) = refl
add-assoc : ∀ {n} c₁ c₂ (x y z : BitVector n) → add′ c₁ (add′ c₂ x y) z ≡ add′ c₁ x (add′ c₂ y z)
add-assoc c₁ c₂ [] [] [] = refl
add-assoc c₁ 1# (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite add-assoc 1# 1# xs ys zs = refl
add-assoc c₁ 1# (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-assoc c₁ 1# xs ys zs = refl
add-assoc c₁ 1# (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-assoc c₁ 1# xs ys zs = refl
add-assoc c₁ 1# (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 1# xs ys zs
| add-carry 0# 1# xs ys zs = refl
add-assoc c₁ 1# (0# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite add-assoc c₁ 1# xs ys zs = refl
add-assoc c₁ 1# (0# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 1# xs ys zs = refl
add-assoc c₁ 1# (0# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-assoc 1# 0# xs ys zs
| add-carry 1# 0# xs ys zs = refl
add-assoc c₁ 1# (0# ∷ xs) (0# ∷ ys) (0# ∷ zs) rewrite add-assoc c₁ 0# xs ys zs = refl
add-assoc c₁ 0# (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite add-assoc c₁ 1# xs ys zs = refl
add-assoc c₁ 0# (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 1# xs ys zs
| add-carry 0# 1# xs ys zs = refl
add-assoc c₁ 0# (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-assoc 1# 0# xs ys zs = refl
add-assoc c₁ 0# (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) rewrite add-assoc c₁ 0# xs ys zs = refl
add-assoc c₁ 0# (0# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite add-assoc 1# 0# xs ys zs
| add-carry 1# 0# xs ys zs = refl
add-assoc c₁ 0# (0# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-assoc c₁ 0# xs ys zs = refl
add-assoc c₁ 0# (0# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-assoc c₁ 0# xs ys zs = refl
add-assoc c₁ 0# (0# ∷ xs) (0# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 0# xs ys zs = refl
+-assoc : ∀ {n} → Associative {n} _+_
+-assoc [] [] [] = refl
+-assoc (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite add-assoc 0# 1# xs ys zs = refl
+-assoc (1# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 1# xs ys zs
| add-carry 0# 1# xs ys zs = refl
+-assoc (1# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-assoc 1# 0# xs ys zs = refl
+-assoc (1# ∷ xs) (0# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 0# xs ys zs = refl
+-assoc (0# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite add-assoc 1# 0# xs ys zs
| add-carry 1# 0# xs ys zs = refl
+-assoc (0# ∷ xs) (1# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 0# xs ys zs = refl
+-assoc (0# ∷ xs) (0# ∷ ys) (1# ∷ zs) rewrite add-assoc 0# 0# xs ys zs = refl
+-assoc (0# ∷ xs) (0# ∷ ys) (0# ∷ zs) rewrite add-assoc 0# 0# xs ys zs = refl
add-comm : ∀ {n} c (x y : BitVector n) → add′ c x y ≡ add′ c y x
add-comm c [] [] = refl
add-comm c (1# ∷ xs) (1# ∷ ys) rewrite add-comm 1# xs ys = refl
add-comm c (1# ∷ xs) (0# ∷ ys) rewrite add-comm c xs ys = refl
add-comm c (0# ∷ xs) (1# ∷ ys) rewrite add-comm c xs ys = refl
add-comm c (0# ∷ xs) (0# ∷ ys) rewrite add-comm 0# xs ys = refl
+-comm : ∀ {n} → Commutative {n} _+_
+-comm = add-comm 0#
add-inverse : ∀ {n} xs → add′ 1# (zero n + bitwise-negation xs) xs ≡ zero n
add-inverse [] = refl
add-inverse (1# ∷ xs) rewrite add-inverse xs = refl
add-inverse (0# ∷ xs) rewrite add-inverse xs = refl
inverseˡ : ∀ {n} → LeftInverse (zero n) -_ _+_
inverseˡ [] = refl
inverseˡ (1# ∷ xs) rewrite add-inverse xs = refl
inverseˡ (0# ∷ xs) rewrite add-assoc 0# 1# (zero _) (bitwise-negation xs) xs
| add-carry 0# 1# (zero _) (bitwise-negation xs) xs
| sym (add-assoc 1# 0# (zero _) (bitwise-negation xs) xs)
| add-inverse xs = refl
inverseʳ : ∀ {n} → RightInverse (zero n) -_ _+_
inverseʳ x = trans (+-comm x (- x)) (inverseˡ x)
*-zeroˡ : ∀ {n} → LeftZero (zero n) _*_
*-zeroˡ [] = refl
*-zeroˡ {Nsuc n} x rewrite *-zeroˡ (droplast x) = refl
2*_ : ∀ {n} → Op₁ {0} (BitVector n)
2* x = droplast (0# ∷ x)
1+2*_ : ∀ {n} → Op₁ {0} (BitVector n)
1+2* x = droplast (1# ∷ x)
_+2*_ : ∀ {n} → Bit → BitVector n → BitVector n
b +2* x = droplast (b ∷ x)
*-identityˡ : ∀ {n} → LeftIdentity (one n) _*_
*-identityˡ [] = refl
*-identityˡ (0# ∷ xs) rewrite *-zeroˡ ( 2* xs) | +-identityʳ xs = refl
*-identityˡ (1# ∷ xs) rewrite *-zeroˡ (1+2* xs) | +-identityʳ xs = refl
*-comm : ∀ {n} → Commutative {n} _*_
*-comm [] [] = refl
*-comm {Nsuc n} x y = *-comm1 x y
where
*-comm1 : ∀ {n} → Commutative {Nsuc n} _*_
*-comm1 (0# ∷ []) (0# ∷ []) = refl
*-comm1 (0# ∷ []) (1# ∷ []) = refl
*-comm1 (1# ∷ []) (0# ∷ []) = refl
*-comm1 (1# ∷ []) (1# ∷ []) = refl
*-comm1 {Nsuc _} (0# ∷ xs) (0# ∷ ys) rewrite *-comm1 xs (2* ys)
| *-comm1 ys (2* xs)
| *-comm (droplast ys) (droplast xs) = refl
*-comm1 {Nsuc _} (0# ∷ xs) (1# ∷ ys) rewrite *-comm1 xs (1+2* ys)
| *-comm1 ys (2* xs)
| *-comm (droplast ys) (droplast xs) = refl
*-comm1 {Nsuc _} (1# ∷ xs) (0# ∷ ys) rewrite *-comm1 xs (2* ys)
| *-comm1 ys (1+2* xs)
| *-comm (droplast ys) (droplast xs) = refl
*-comm1 {Nsuc _} (1# ∷ xs) (1# ∷ ys) rewrite *-comm1 xs (1+2* ys)
| *-comm1 ys (1+2* xs)
| *-comm (droplast ys) (droplast xs)
| sym (+-assoc ys xs (0# ∷ droplast xs * droplast ys))
| +-comm ys xs
| +-assoc xs ys (0# ∷ droplast xs * droplast ys) = refl
droplast-distrib-+ : ∀ {n} (x y : BitVector (Nsuc n))
→ droplast (x + y) ≡ droplast x + droplast y
droplast-distrib-+ {Nzero} _ _ = refl
droplast-distrib-+ {Nsuc _} (0# ∷ xs) (0# ∷ ys) rewrite droplast-distrib-+ xs ys = refl
droplast-distrib-+ {Nsuc _} (0# ∷ xs) (1# ∷ ys) rewrite droplast-distrib-+ xs ys = refl
droplast-distrib-+ {Nsuc _} (1# ∷ xs) (0# ∷ ys) rewrite droplast-distrib-+ xs ys = refl
droplast-distrib-+ {Nsuc _} (1# ∷ xs) (1# ∷ ys) rewrite droplast-distrib-+ xs ys
= cong (_∷_ 0#) (lemma xs ys)
where
lemma : ∀ {n} (xs ys : BitVector (Nsuc n))
→ droplast (add′ 1# xs ys) ≡ add′ 1# (droplast xs) (droplast ys)
lemma {Nzero} _ _ = refl
lemma {Nsuc _} (0# ∷ xs) (0# ∷ ys) rewrite droplast-distrib-+ xs ys = refl
lemma {Nsuc _} (0# ∷ xs) (1# ∷ ys) rewrite lemma xs ys = refl
lemma {Nsuc _} (1# ∷ xs) (0# ∷ ys) rewrite lemma xs ys = refl
lemma {Nsuc _} (1# ∷ xs) (1# ∷ ys) rewrite lemma xs ys = refl
droplast-distrib-* : ∀ {n} (x y : BitVector (Nsuc n))
→ droplast (x * y) ≡ droplast x * droplast y
droplast-distrib-* {Nzero} _ _ = refl
droplast-distrib-* {Nsuc _} (0# ∷ xs) (y ∷ ys)
rewrite droplast-distrib-* xs (y +2* ys) = refl
droplast-distrib-* {Nsuc _} (1# ∷ xs) (0# ∷ ys)
rewrite droplast-distrib-+ ys (xs * (2* ys))
| droplast-distrib-* xs (2* ys) = refl
droplast-distrib-* {Nsuc _} (1# ∷ xs) (1# ∷ ys)
rewrite droplast-distrib-+ ys (xs * (1+2* ys))
| droplast-distrib-* xs (1+2* ys) = refl
extract-carry : ∀ {n} (xs ys : BitVector n) → add′ 1# xs ys ≡ one _ + (xs + ys)
extract-carry [] [] = refl
extract-carry (0# ∷ xs) (0# ∷ ys) rewrite +-identityˡ (xs + ys) = refl
extract-carry (0# ∷ xs) (1# ∷ ys) rewrite add-carry 1# 0# (zero _) xs ys
| +-identityˡ (add′ 1# xs ys) = refl
extract-carry (1# ∷ xs) (0# ∷ ys) rewrite add-carry 1# 0# (zero _) xs ys
| +-identityˡ (add′ 1# xs ys) = refl
extract-carry (1# ∷ xs) (1# ∷ ys) rewrite +-identityˡ (add′ 1# xs ys) = refl
shift-to-add : ∀ c {n} (x : BitVector n) → c +2* x ≡ add′ c x x
shift-to-add _ [] = refl
shift-to-add c (0# ∷ xs) rewrite shift-to-add 0# xs = refl
shift-to-add c (1# ∷ xs) rewrite shift-to-add 1# xs = refl
*-distribʳ : ∀ {n} → (_*_ {n}) DistributesOverʳ _+_
*-distribʳ [] [] [] = refl
*-distribʳ {Nsuc n} xs ys zs = *-distribʳ1 xs ys zs
where
lemma : ∀ {n} c (xs ys zs : BitVector n)
→ add′ 1# ys zs * c +2* xs
≡ add′ c (xs + (ys * c +2* xs)) (xs + (zs * c +2* xs))
lemma c xs ys zs rewrite
extract-carry ys zs
| *-distribʳ (c +2* xs) (one _) (ys + zs)
| *-identityˡ (c +2* xs)
| *-distribʳ (c +2* xs) ys zs
| shift-to-add c xs
| *-comm ys (add′ c xs xs)
| *-comm zs (add′ c xs xs)
| +-comm (add′ c xs xs) (add′ c xs xs * ys + add′ c xs xs * zs)
| add-carry 0# c (add′ c xs xs * ys + add′ c xs xs * zs) xs xs
| add-assoc c 0# (add′ c xs xs * ys) (add′ c xs xs * zs) (xs + xs)
| sym (+-assoc (add′ c xs xs * zs) xs xs)
| +-comm (add′ c xs xs * zs) xs
| +-comm (xs + add′ c xs xs * zs) xs
| sym (add-assoc c 0# (add′ c xs xs * ys) xs (xs + add′ c xs xs * zs))
| +-comm (add′ c xs xs * ys) xs
= refl
*-distribʳ1 : ∀ {n} → (_*_ {Nsuc n}) DistributesOverʳ _+_
*-distribʳ1 xs (0# ∷ ys) (0# ∷ zs) rewrite *-distribʳ (droplast xs) ys zs = refl
*-distribʳ1 (0# ∷ xs) (0# ∷ ys) (1# ∷ zs)
rewrite *-distribʳ (2* xs) ys zs
| sym (+-assoc xs (ys * 2* xs) (zs * 2* xs))
| +-comm xs (ys * 2* xs)
| +-assoc (ys * 2* xs) xs (zs * 2* xs) = refl
*-distribʳ1 (1# ∷ xs) (0# ∷ ys) (1# ∷ zs)
rewrite *-distribʳ (1+2* xs) ys zs
| sym (+-assoc xs (ys * 1+2* xs) (zs * 1+2* xs))
| +-comm xs (ys * 1+2* xs)
| +-assoc (ys * 1+2* xs) xs (zs * 1+2* xs) = refl
*-distribʳ1 (0# ∷ xs) (1# ∷ ys) (0# ∷ zs)
rewrite *-distribʳ (2* xs) ys zs
| +-assoc xs (ys * 2* xs) (zs * 2* xs) = refl
*-distribʳ1 (1# ∷ xs) (1# ∷ ys) (0# ∷ zs)
rewrite *-distribʳ (1+2* xs) ys zs
| +-assoc xs (ys * 1+2* xs) (zs * 1+2* xs) = refl
*-distribʳ1 (0# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite lemma 0# xs ys zs = refl
*-distribʳ1 (1# ∷ xs) (1# ∷ ys) (1# ∷ zs) rewrite lemma 1# xs ys zs = refl
*-assoc : ∀ {n} → Associative {n} _*_
*-assoc [] [] [] = refl
*-assoc {Nsuc n} x y z = *-assoc1 x y z
where
*-assoc1 : ∀ {n} → Associative {Nsuc n} _*_
*-assoc1 (0# ∷ xs) ys zs rewrite *-assoc xs (droplast ys) (droplast zs)
| droplast-distrib-* ys zs = refl
*-assoc1 (1# ∷ xs) ys zs rewrite *-distribʳ zs ys (0# ∷ xs * droplast ys)
| *-assoc xs (droplast ys) (droplast zs)
| droplast-distrib-* ys zs = refl
*-identityʳ : ∀ {n} → RightIdentity (one n) _*_
*-identityʳ x rewrite *-comm x (one _) = *-identityˡ x
*-distribˡ : ∀ {n} → (_*_ {n}) DistributesOverˡ _+_
*-distribˡ x y z rewrite *-comm x (y + z)
| *-distribʳ x y z
| *-comm x y
| *-comm x z = refl
module Properties (n : ℕ) where
open import Algebra.Structures
+-isSemigroup : IsSemigroup {A = BitVector n} _≡_ _+_
+-isSemigroup = record
{ isEquivalence = isEquivalence; assoc = +-assoc; ∙-cong = cong₂ _+_ }
+-isMonoid : IsMonoid _≡_ _+_ (zero n)
+-isMonoid = record
{ isSemigroup = +-isSemigroup; identity = +-identityˡ , +-identityʳ }
+-isGroup : IsGroup _≡_ _+_ (zero n) -_
+-isGroup = record
{ isMonoid = +-isMonoid; inverse = inverseˡ , inverseʳ; ⁻¹-cong = cong -_ }
+-isAbelianGroup : IsAbelianGroup _≡_ _+_ (zero n) -_
+-isAbelianGroup = record { isGroup = +-isGroup; comm = +-comm }
*-isSemigroup : IsSemigroup {A = BitVector n} _≡_ _*_
*-isSemigroup = record
{ isEquivalence = isEquivalence; assoc = *-assoc; ∙-cong = cong₂ _*_ }
*-isMonoid : IsMonoid _≡_ _*_ (one n)
*-isMonoid = record
{ isSemigroup = *-isSemigroup; identity = *-identityˡ , *-identityʳ }
isRing : IsRing _≡_ _+_ _*_ -_ (zero n) (one n)
isRing = record { +-isAbelianGroup = +-isAbelianGroup;
*-isMonoid = *-isMonoid;
distrib = *-distribˡ , *-distribʳ }
isCommutativeRing : IsCommutativeRing _≡_ _+_ _*_ -_ (zero n) (one n)
isCommutativeRing = record { isRing = isRing; *-comm = *-comm }
commutativeRing : ∀ n → CommutativeRing _ _
commutativeRing n = record
{ Carrier = BitVector n;
_≈_ = _≡_; _+_ = _+_; _*_ = _*_; -_ = -_;
0# = zero n; 1# = one n;
isCommutativeRing = Properties.isCommutativeRing n }
| {
"alphanum_fraction": 0.4540680994,
"avg_line_length": 52.78,
"ext": "agda",
"hexsha": "6079084d1aeebbfc62501cca4a761cb5f21e7dbb",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-11-12T01:40:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-25T00:15:43.000Z",
"max_forks_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "copumpkin/bitvector",
"max_forks_repo_path": "Data/BitVector/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_issues_repo_issues_event_max_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "copumpkin/bitvector",
"max_issues_repo_path": "Data/BitVector/Properties.agda",
"max_line_length": 101,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/bitvector",
"max_stars_repo_path": "Data/BitVector/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-12T01:41:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T07:19:55.000Z",
"num_tokens": 7043,
"size": 18473
} |
open import Signature
import Logic
module Model (Σ Δ : Sig) (V : Set) (Φ : Logic.Program Σ Δ V) where
open import Function
open import Data.Empty renaming (⊥ to Ø)
open import Data.Sum
open import Data.Product renaming (Σ to ∐)
open import Relation.Unary
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Logic Σ Δ V
open import Terms Σ
-- | I-ary relations over A
Rel : Set → Set → Set₁
Rel I A = (I → A) → Set
_⊆ᵣ_ : ∀{I A} → Rel I A → Rel I A → Set
R₁ ⊆ᵣ R₂ = ∀{t} → R₁ t → R₂ t
PredInterpret : Set₁
PredInterpret = (Q : ∥ Δ ∥) → Rel (ar Δ Q) (T∞ Ø)
_⊑ᵢ_ : PredInterpret → PredInterpret → Set
I₁ ⊑ᵢ I₂ = ∀ {Q} → I₁ Q ⊆ᵣ I₂ Q
liftApp∞ : ∀ {V W} {I : Set} → Subst∞ V W → (I → T∞ V) → (I → T∞ W)
liftApp∞ σ f i = app∞ σ (f i)
_≡[_]_ : T∞ Ø → Subst∞ V Ø → T V → Set
t ≡[ σ ] s = t ~ app∞ σ (χ s)
{-
_⊨[_]_ : PredInterpret → Subst∞ V Ø → Formula → Set
I ⊨[ σ ] (inj₁ (Q , ts)) = liftApp∞ σ (χ ∘ ts) ∈ I Q
I ⊨[ σ ] (inj₂ _) = Ø
-}
_⊨[_]_ : PredInterpret → Subst∞ V Ø → Formula → Set
I ⊨[ σ ] (Q , ts) = liftApp∞ σ (χ ∘ ts) ∈ I Q
⟦_⟧ : dom Φ → PredInterpret → PredInterpret
⟦ C ⟧ I = F (get Φ C)
where
-- | Forward closure for inductive clauses is given by
-- F(h ⊢μ Q'(t))(I)(Q)
-- = {t[σ] | σ : V → Ø ∧ Q ≡ Q' ∧ ∀ P(s) ∈ h. s[σ] ∈ I(P)}.
-- The backwards closure for coinductive clauses is, on the other hand,
-- given by
-- F(h ⊢ν P(s))(I)(Q) = {t[σ] | σ : V → Ø ∧ Q(t) ∈ h ∧ s ∈ I(Q)}
F : Clause → PredInterpret
F (h ⊢[ ind ] (Q' , pat)) Q ts =
∐ (Q' ≡ Q) (λ p →
∃ (λ σ →
∀ i → ts (subst _ p i) ≡[ σ ] pat i
× (∀ j → I ⊨[ σ ] get h j)))
F (h ⊢[ coind ] φ) Q ts =
∃ (λ j →
∐ (proj₁ (get h j) ≡ Q) (λ p →
∃ (λ σ →
∀ i → ts (subst _ p i) ≡[ σ ] proj₂ (get h j) i
× I ⊨[ σ ] φ)))
FormInterpret : PredInterpret → Formula → Pred (Subst∞ V Ø) _
FormInterpret I (Q , ts) σ = (λ i → app∞ σ (χ (ts i))) ∈ I Q
B : (Formula → Pred (Subst∞ V Ø) _) → (Formula → Pred (Subst∞ V Ø) _)
B D F = {!!}
record ModelData : Set₁ where
field
preds : PredInterpret
| {
"alphanum_fraction": 0.5183946488,
"avg_line_length": 27.5394736842,
"ext": "agda",
"hexsha": "89ee76043d0ca011d84721ba92fcca10b859c6ff",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "LP/Model.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "LP/Model.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "LP/Model.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 911,
"size": 2093
} |
------------------------------------------------------------------------
-- Parsing of mixfix operators
------------------------------------------------------------------------
-- This module defines a grammar for the precedence graph g.
open import RecursiveDescent.Hybrid.Mixfix.Expr
module RecursiveDescent.Hybrid.Mixfix (g : PrecedenceGraph) where
import Data.Vec as Vec
import Data.List as List
open List using (List; []; _∷_; foldr; foldl)
import Data.Vec1 as Vec1
open Vec1 using (Vec₁)
open import Data.Product renaming (_,_ to pair)
open import Data.Product.Record using (_,_)
open import Data.Bool
open import Data.Unit
open import Data.Nat
open import Data.Function hiding (_⟨_⟩_)
import Data.String as String
open import RecursiveDescent.Hybrid.Mixfix.Fixity
open import RecursiveDescent.Index
open import RecursiveDescent.Hybrid
open import RecursiveDescent.Hybrid.Simple
open import RecursiveDescent.Hybrid.Lib
open Token String.decSetoid
-- Note that, even though grammar below is not recursive, these
-- functions are (mutually). Fortunately the recursion is structural,
-- though. Note also that the reason for not using the implementation
--
-- grammar (nodes ts) = choiceMap (\t -> ! node t) ts
--
-- is that this would lead to a definition of node-corners which
-- was not structurally recursive.
nodes-corners : PrecedenceGraph -> Corners
nodes-corners [] = _
nodes-corners (p ∷ ps) = _
node-corners : PrecedenceTree -> Corners
node-corners (precedence ops ps) = _
-- Nonterminals.
data NT : ParserType where
-- Expressions.
expr : NT _ Expr
-- Expressions corresponding to zero or more nodes in the precedence
-- graph: operator applications where the outermost operator has one
-- of the precedences ps. The graph g is used for internal
-- expressions.
nodes : (ps : PrecedenceGraph) -> NT (false , nodes-corners ps) Expr
-- Expressions corresponding to one node in the precedence graph:
-- operator applications where the outermost operator has
-- precedence p. The graph g is used for internal expressions.
node : (p : PrecedenceTree) -> NT (false , node-corners p) Expr
-- The parser type used in this module.
P : Index -> Set -> Set1
P = Parser NamePart NT
-- A vector containing parsers recognising the name parts of the
-- operator.
nameParts : forall {fix arity} -> Operator fix arity ->
Vec₁ (P _ NamePart) (1 + arity)
nameParts (operator ns) = Vec1.map₀₁ sym ns
-- Internal parts (all name parts plus internal expressions) of
-- operators of the given precedence and fixity.
internal : forall {fix}
(ops : List (∃ (Operator fix))) -> P _ (Internal fix)
internal =
choiceMap (\op' -> let op = proj₂ op' in
_∙_ op <$> (! expr between nameParts op))
-- The grammar.
grammar : Grammar NamePart NT
grammar expr = ! nodes g
grammar (nodes []) = fail
grammar (nodes (p ∷ ps)) = ! node p ∣ ! nodes ps
grammar (node (precedence ops ps)) =
⟪_⟫ <$> ⟦ closed ⟧
∣ _⟨_⟩_ <$> ↑ ⊛ ⟦ infx non ⟧ ⊛ ↑
∣ flip (foldr _$_) <$> preRight + ⊛ ↑
∣ foldl (flip _$_) <$> ↑ ⊛ postLeft +
where
-- ⟦ fix ⟧ parses the internal parts of operators with the
-- current precedence level and fixity fix.
⟦_⟧ = \(fix : Fixity) -> internal (ops fix)
-- Operator applications where the outermost operator binds
-- tighter than the current precedence level.
↑ = ! nodes ps
-- Right associative and prefix operators.
preRight = ⟪_⟩_ <$> ⟦ prefx ⟧
∣ _⟨_⟩_ <$> ↑ ⊛ ⟦ infx right ⟧
-- Left associative and postfix operators.
postLeft = flip _⟨_⟫ <$> ⟦ postfx ⟧
∣ (\op e₂ e₁ -> e₁ ⟨ op ⟩ e₂) <$> ⟦ infx left ⟧ ⊛ ↑
-- An expression parser.
parseExpr : List NamePart -> List Expr
parseExpr = parse-complete (! expr) grammar
| {
"alphanum_fraction": 0.645236251,
"avg_line_length": 33.1025641026,
"ext": "agda",
"hexsha": "13274579864116f9ea5869dcd359cc4cd88ed587",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/RecursiveDescent/Hybrid/Mixfix.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 1008,
"size": 3873
} |
module Refactoring where
open import ParseTree hiding (after)
open import Data.List
open import Data.String hiding (_++_)
open import Data.Sum hiding (map)
open import Data.Product
open import ScopeParseTree
open import MatchUpNames
open import ScopeState
open import Data.Nat
open import InterpretCommand
open import Data.Maybe
open import Data.Vec using (toList ; lookup ; Vec)
open import Data.Fin
open import AgdaHelperFunctions
open import PushArgument renaming (pushArgument to push)
open import IO.Primitive using (IO)
open import Typing
open import Data.Bool
open import ExtractFunction using (extract)
open import ExplicitImplicitConversion
doNothing : List ParseTree -> List ParseTree
doNothing x = x
{-# COMPILE GHC doNothing as doNothing #-}
scopeList : ScopeState (List ParseTree)
scopeList = do
env {numVars} vars maxScopes scopes current <- get
let decl = Data.Vec.map getDeclared scopes
let scopeDec = Data.Vec.map ( λ x -> Data.List.map (λ y -> Data.Vec.lookup y vars) x) decl
fail $ Data.String.concat $ Data.List.map concatSpace $ Data.Vec.toList scopeDec
where concatSpace : List String -> String
concatSpace l = (Data.String.concat l) Data.String.++ "\n"
varList : ScopeState (List ParseTree)
varList = do
env vars maxScopes scopes current <- get
fail $ Data.String.concat $ Data.Vec.toList vars
scopeOnly : List ParseTree -> IO (String ⊎ List ParseTree)
scopeOnly program = runScopeState (matchUpNames after scopeParseTreeList $ program) newEnv
{-# COMPILE GHC scopeOnly as scopeOnly #-}
checkCommand' : List ParseTree -> ℕ -> ScopeState String
checkCommand' list n = do
let afterScoping = scopeOnly list
newList <- scopeParseTreeList list
just decl <- return $ getDeclarationIDForPoint newList n
where nothing -> fail "Cursor is not in renameable instance"
getNameForId decl
checkCommand : List ParseTree -> ℕ -> IO (String ⊎ String)
checkCommand list n = runScopeState (checkCommand' list n ) newEnv
{-# COMPILE GHC checkCommand as checkCommand #-}
rename' : List ParseTree -> ℕ -> String -> ScopeState (List ParseTree)
rename' program point newName = do
scoped <- scopeParseTreeList program
just decl <- return $ getDeclarationIDForPoint scoped point
where nothing -> fail "Cursor is not in renameable instance"
noerror <- replaceID decl newName
matchUpNames scoped
rename : List ParseTree -> ℕ -> String -> IO (String ⊎ List ParseTree)
rename program point newName = runScopeState (rename' program point newName) newEnv
{-# COMPILE GHC rename as rename #-}
pushArgument' : List ParseTree -> ℕ -> ScopeState (List ParseTree)
pushArgument' program point = do
scoped <- scopeParseTreeList program
funcID , argNumber <- getFuncIdAndArgNumber scoped point
push scoped funcID argNumber
pushArgument : List ParseTree -> ℕ -> IO (String ⊎ List ParseTree)
pushArgument program point = runScopeState (pushArgument' program point) newEnv
{-# COMPILE GHC pushArgument as pushArgument #-}
changeExplicitness' : List ParseTree -> ℕ -> ScopeState (List ParseTree)
changeExplicitness' program point = do
scoped <- scopeParseTreeList program
funcID , argNumber <- getFuncIdAndArgNumber scoped point
convert scoped funcID argNumber
toggleExplicitness : List ParseTree -> ℕ -> IO (String ⊎ List ParseTree)
toggleExplicitness program point = runScopeState (changeExplicitness' program point) newEnv
{-# COMPILE GHC toggleExplicitness as toggleExplicitness #-}
extractFunction : List ParseTree -> ℕ -> ℕ -> String -> IO (String ⊎ List ParseTree)
extractFunction program startPoint endPoint filename = runScopeState (extract program startPoint endPoint filename) newEnv
{-# COMPILE GHC extractFunction as extractFunction #-}
| {
"alphanum_fraction": 0.7612140747,
"avg_line_length": 36.5,
"ext": "agda",
"hexsha": "97617ab200b7500e3d8340ad31d9f822c837c74f",
"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/Refactoring.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/Refactoring.agda",
"max_line_length": 122,
"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/Refactoring.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": 891,
"size": 3723
} |
{-# OPTIONS --safe --warning=error --with-K #-}
open import Sets.EquivalenceRelations
open import Groups.Definition
open import Orders
open import Rings.Definition
open import Numbers.Integers.Integers
open import Numbers.Integers.Multiplication
open import Setoids.Setoids
open import LogicalFormulae
open import Sets.FinSet
open import Functions
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Order
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.WithK
open import Numbers.Modulo.Definition
open import Numbers.Modulo.Addition
open import Numbers.Modulo.Group
open import Rings.Examples.Examples
open import Numbers.Primes.PrimeNumbers
open import Groups.Lemmas
open import Groups.Homomorphisms.Definition
open import Groups.Homomorphisms.Lemmas
open import Groups.Isomorphisms.Definition
open import Groups.Cyclic.Definition
open import Groups.QuotientGroup.Definition
open import Groups.Subgroups.Definition
open import Groups.Subgroups.Normal.Definition
module Groups.Examples.Examples where
trivialGroup : Group (reflSetoid (FinSet 1)) λ _ _ → fzero
Group.+WellDefined trivialGroup _ _ = refl
Group.0G trivialGroup = fzero
Group.inverse trivialGroup _ = fzero
Group.+Associative trivialGroup = refl
Group.identRight trivialGroup {fzero} = refl
Group.identRight trivialGroup {fsucc ()}
Group.identLeft trivialGroup {fzero} = refl
Group.identLeft trivialGroup {fsucc ()}
Group.invLeft trivialGroup = refl
Group.invRight trivialGroup = refl
elementPowZ : (n : ℕ) → (elementPower ℤGroup (nonneg 1) (nonneg n)) ≡ nonneg n
elementPowZ zero = refl
elementPowZ (succ n) rewrite elementPowZ n = refl
ℤCyclic : CyclicGroup ℤGroup
CyclicGroup.generator ℤCyclic = nonneg 1
CyclicGroup.cyclic ℤCyclic {nonneg x} = (nonneg x , elementPowZ x)
CyclicGroup.cyclic ℤCyclic {negSucc x} = (negSucc x , ans)
where
ans : (Group.inverse ℤGroup ((nonneg 1) +Z elementPower ℤGroup (nonneg 1) (nonneg x))) ≡ negSucc x
ans rewrite elementPowZ x = refl
elementPowZn : (n : ℕ) → {pr : 0 <N succ (succ n)} → (power : ℕ) → (powerLess : power <N succ (succ n)) → {p : 1 <N succ (succ n)} → elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = p }) (nonneg power) ≡ record { x = power ; xLess = powerLess }
elementPowZn n zero powerLess = equalityZn _ _ refl
elementPowZn n {pr} (succ power) powerLess {p} with TotalOrder.totality ℕTotalOrder (ℤn.x (elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = p }) (nonneg power))) (succ n)
elementPowZn n {pr} (succ power) powerLess {p} | inl (inl x) = equalityZn _ _ (applyEquality succ v)
where
t : elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = succPreservesInequality (succIsPositive n) }) (nonneg power) ≡ record { x = power ; xLess = PartialOrder.<Transitive (TotalOrder.order ℕTotalOrder) (a<SuccA power) powerLess }
t = elementPowZn n {pr} power (PartialOrder.<Transitive (TotalOrder.order ℕTotalOrder) (a<SuccA power) powerLess) {succPreservesInequality (succIsPositive n)}
u : elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = p }) (nonneg power) ≡ record { x = power ; xLess = PartialOrder.<Transitive (TotalOrder.order ℕTotalOrder) (a<SuccA power) powerLess }
u rewrite <NRefl p (succPreservesInequality (succIsPositive n)) = t
v : ℤn.x (elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = p }) (nonneg power)) ≡ power
v rewrite u = refl
elementPowZn n {pr} (succ power) powerLess {p} | inl (inr x) with elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = p }) (nonneg power)
elementPowZn n {pr} (succ power) powerLess {p} | inl (inr x) | record { x = x' ; xLess = xLess } = exFalso (noIntegersBetweenXAndSuccX _ x xLess)
elementPowZn n {pr} (succ power) powerLess {p} | inr x with inspect (elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = p }) (nonneg power))
elementPowZn n {pr} (succ power) powerLess {p} | inr x | record { x = x' ; xLess = p' } with≡ inspected rewrite elementPowZn n {pr} power (PartialOrder.<Transitive (TotalOrder.order ℕTotalOrder) (a<SuccA power) powerLess) {p} | x = exFalso (PartialOrder.irreflexive (TotalOrder.order ℕTotalOrder) powerLess)
ℤnCyclic : (n : ℕ) → (pr : 0 <N n) → CyclicGroup (ℤnGroup n pr)
ℤnCyclic zero ()
CyclicGroup.generator (ℤnCyclic (succ zero) pr) = record { x = 0 ; xLess = pr }
CyclicGroup.cyclic (ℤnCyclic (succ zero) pr) {record { x = zero ; xLess = xLess }} rewrite <NRefl xLess (succIsPositive 0) | <NRefl pr (succIsPositive 0) = (nonneg 0 , refl)
CyclicGroup.cyclic (ℤnCyclic (succ zero) _) {record { x = succ x ; xLess = xLess }} = exFalso (zeroNeverGreater (canRemoveSuccFrom<N xLess))
ℤnCyclic (succ (succ n)) pr = record { generator = record { x = 1 ; xLess = succPreservesInequality (succIsPositive n) } ; cyclic = λ {x} → ans x }
where
ans : (z : ℤn (succ (succ n)) pr) → Sg ℤ (λ i → (elementPower (ℤnGroup (succ (succ n)) pr) (record { x = 1 ; xLess = succPreservesInequality (succIsPositive n) }) i) ≡ z)
ans record { x = x ; xLess = xLess } = nonneg x , elementPowZn n x xLess
multiplyByNHom : (n : ℕ) → GroupHom ℤGroup ℤGroup (λ i → i *Z nonneg n)
GroupHom.groupHom (multiplyByNHom n) {x} {y} = lemma1
where
open Setoid (reflSetoid ℤ)
open Group ℤGroup
lemma : nonneg n *Z (x +Z y) ≡ (nonneg n) *Z x +Z nonneg n *Z y
lemma = Ring.*DistributesOver+ ℤRing {nonneg n} {x} {y}
lemma1 : (x +Z y) *Z nonneg n ≡ x *Z nonneg n +Z y *Z nonneg n
lemma1 rewrite Ring.*Commutative ℤRing {x +Z y} {nonneg n} | Ring.*Commutative ℤRing {x} {nonneg n} | Ring.*Commutative ℤRing {y} {nonneg n} = lemma
GroupHom.wellDefined (multiplyByNHom n) {x} {.x} refl = refl
modNExampleGroupHom : (n : ℕ) → (pr : 0 <N n) → GroupHom ℤGroup (ℤnGroup n pr) (mod n pr)
GroupHom.groupHom (modNExampleGroupHom n 0<n) {x} {y} = {!!}
GroupHom.wellDefined (modNExampleGroupHom n 0<n) {x} {.x} refl = refl
intoZn : {n : ℕ} → {pr : 0 <N n} → (x : ℕ) → (x<n : x <N n) → mod n pr (nonneg x) ≡ record { x = x ; xLess = x<n }
intoZn {zero} {()}
intoZn {succ n} {0<n} x x<n with divisionAlg (succ n) x
intoZn {succ n} {0<n} x x<n | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl y ; quotSmall = quotSmall } = equalityZn _ _ (modIsUnique (record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl y ; quotSmall = quotSmall }) (record { quot = 0 ; rem = x ; pr = ans ; remIsSmall = inl x<n ; quotSmall = inl (succIsPositive n)}))
where
ans : n *N 0 +N x ≡ x
ans rewrite multiplicationNIsCommutative n 0 = refl
intoZn {succ n} {0<n} x x<n | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
quotientZn : (n : ℕ) → (pr : 0 <N n) → GroupIso (quotientGroupByHom ℤGroup (modNExampleGroupHom n pr)) (ℤnGroup n pr) (mod n pr)
GroupHom.groupHom (GroupIso.groupHom (quotientZn n pr)) = GroupHom.groupHom (modNExampleGroupHom n pr)
GroupHom.wellDefined (GroupIso.groupHom (quotientZn n pr)) {x} {y} x~y = need
where
given : mod n pr (x +Z (Group.inverse ℤGroup y)) ≡ record { x = 0 ; xLess = pr }
given = x~y
given' : (mod n pr x) +n (mod n pr (Group.inverse ℤGroup y)) ≡ record { x = 0 ; xLess = pr }
given' = transitivity (equalityCommutative (GroupHom.groupHom (modNExampleGroupHom n pr))) given
given'' : (mod n pr x) +n Group.inverse (ℤnGroup n pr) (mod n pr y) ≡ record { x = 0 ; xLess = pr}
given'' = transitivity (applyEquality (λ i → mod n pr x +n i) (equalityCommutative (homRespectsInverse (modNExampleGroupHom n pr)))) given'
need : mod n pr x ≡ mod n pr y
need = transferToRight (ℤnGroup n pr) given''
SetoidInjection.wellDefined (SetoidBijection.inj (GroupIso.bij (quotientZn n pr))) {x} {y} x=y = {!!}
SetoidSurjection.wellDefined (SetoidBijection.surj (GroupIso.bij (quotientZn n pr))) {x} {y} = SetoidInjection.wellDefined (SetoidBijection.inj (GroupIso.bij (quotientZn n pr))) {x} {y}
SetoidInjection.injective (SetoidBijection.inj (GroupIso.bij (quotientZn n pr))) {x} {y} fx~fy = need
where
given : mod n pr x +n Group.inverse (ℤnGroup n pr) (mod n pr y) ≡ record { x = 0 ; xLess = pr }
given = transferToRight'' (ℤnGroup n pr) fx~fy
given' : mod n pr (x +Z (Group.inverse ℤGroup y)) ≡ record { x = 0 ; xLess = pr }
given' = identityOfIndiscernablesLeft _≡_ given (equalityCommutative (transitivity (GroupHom.groupHom (modNExampleGroupHom n pr) {x}) (applyEquality (λ i → mod n pr x +n i) (homRespectsInverse (modNExampleGroupHom n pr)))))
need' : (mod n pr x) +n (mod n pr (Group.inverse ℤGroup y)) ≡ record { x = 0 ; xLess = pr }
need' rewrite equalityCommutative (GroupHom.groupHom (modNExampleGroupHom n pr) {x} {Group.inverse ℤGroup y}) = given'
need : mod n pr (x +Z (Group.inverse ℤGroup y)) ≡ record { x = 0 ; xLess = pr}
need = identityOfIndiscernablesLeft _≡_ need' (equalityCommutative (GroupHom.groupHom (modNExampleGroupHom n pr)))
SetoidSurjection.surjective (SetoidBijection.surj (GroupIso.bij (quotientZn n pr))) {record { x = x ; xLess = xLess }} = nonneg x , intoZn x xLess
trivialGroupHom : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) → GroupHom trivialGroup G (λ _ → Group.0G G)
GroupHom.groupHom (trivialGroupHom {S = S} G) = symmetric identRight
where
open Setoid S
open Group G
open Equivalence eq
GroupHom.wellDefined (trivialGroupHom {S = S} G) _ = Equivalence.reflexive (Setoid.eq S)
| {
"alphanum_fraction": 0.6938211209,
"avg_line_length": 67.1642857143,
"ext": "agda",
"hexsha": "e25229d75a9b5ccbc4ce73111a22fbe91287f0de",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/Examples/Examples.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Examples/Examples.agda",
"max_line_length": 344,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/Examples/Examples.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": 3242,
"size": 9403
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Monoidal.Cartesian where
open import Data.Product using (proj₁; proj₂) renaming (_×_ to _×₀_)
open import Data.Fin using (zero)
open import Categories.Category
open import Categories.Monoidal
open import Categories.Object.BinaryProducts
open import Categories.Object.Products
open import Categories.Object.Products.Properties
renaming (module Properties to ProductProperties)
open import Categories.Object.Terminal
open import Categories.Bifunctor using (Bifunctor)
import Categories.Morphisms
open import Categories.Square
import Categories.Monoidal.Cartesian.Pentagon as Pentagon
Cartesian : ∀ {o ℓ e} (C : Category o ℓ e) → Products C → Monoidal C
Cartesian C Ps = record
{ ⊗ = ⊗
; id = ⊤
; identityˡ = record
{ F⇒G = record
{ η = λ X → π₂
; commute = λ f → commute₂
}
; F⇐G = record
{ η = λ X → ⟨ ! , id ⟩
; commute = λ f → unitˡ-natural
}
; iso = λ X → _≅_.iso unitˡ
}
; identityʳ = record
{ F⇒G = record
{ η = λ X → π₁
; commute = λ f → commute₁
}
; F⇐G = record
{ η = λ X → ⟨ id , ! ⟩
; commute = λ f → unitʳ-natural
}
; iso = λ X → _≅_.iso unitʳ
}
; assoc = record
{ F⇒G = record
{ η = λ X → assocˡ
; commute = λ f → assocˡ∘⁂
}
; F⇐G = record
{ η = λ X → assocʳ
; commute = λ f → assocʳ∘⁂
}
; iso = λ X → record
{ isoˡ = Iso.isoʳ (_≅_.iso ×-assoc)
; isoʳ = Iso.isoˡ (_≅_.iso ×-assoc)
}
}
; triangle = λ {X} → triangle {X}
; pentagon = pentagon
}
where
open Categories.Morphisms C
open Category C
open Products Ps renaming (terminal to T₀; binary to P₀)
open ProductProperties C Ps
open Terminal T₀ using (⊤; !; !-unique; !-unique₂)
open BinaryProducts P₀
open Pentagon.Law C P₀ using (pentagon)
⊗ : Bifunctor C C C
⊗ = record
{ F₀ = λ p → proj₁ p × proj₂ p
; F₁ = λ x → proj₁ x ⁂ proj₂ x
; identity = identity
; homomorphism = Equiv.sym ⁂∘⁂
; F-resp-≡ = λ {A B F G} x → F-resp-≡ {A} {B} {F} {G} x
}
where
.identity : ∀ {A : Obj ×₀ Obj} → (id {proj₁ A} ⁂ id {proj₂ A}) ≡ id
identity = universal (id-comm {f = π₁}) (id-comm {f = π₂})
.F-resp-≡ : ∀ {A B F G} F≡G → _
F-resp-≡ {F = F} {G} x = ⟨⟩-cong₂ (∘-resp-≡ˡ (proj₁ x)) (∘-resp-≡ˡ (proj₂ x))
-- The implicit x is actually used implicitly by the rest of the expression, so don't take it out,
-- or Agda will complain about something referring to something to which it has no access.
-- The connection between the mentioned x and the rest of the type is given by the caller way up
-- there, so if that were not using these the triangle and pentagon laws would be yellow.
.triangle : ∀ {x} → first π₁ ≡ second π₂ ∘ assocˡ
triangle =
begin
first π₁
↓⟨ ⟨⟩-congʳ identityˡ ⟩
⟨ π₁ ∘ π₁ , π₂ ⟩
↑⟨ ⟨⟩-congʳ commute₂ ⟩
⟨ π₁ ∘ π₁ , π₂ ∘ ⟨ π₂ ∘ π₁ , π₂ ⟩ ⟩
↑⟨ second∘⟨⟩ ⟩
second π₂ ∘ assocˡ
∎
where
open HomReasoning
open Equiv
| {
"alphanum_fraction": 0.5886755613,
"avg_line_length": 29.2666666667,
"ext": "agda",
"hexsha": "918fa2142596d8d3d7b3aa73e70335db6d292d33",
"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/Monoidal/Cartesian.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/Monoidal/Cartesian.agda",
"max_line_length": 100,
"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/Monoidal/Cartesian.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": 1101,
"size": 3073
} |
{-# OPTIONS --sized-types #-}
open import Relation.Binary.Core
module Heapsort.Impl1.Correctness.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import BBHeap _≤_ hiding (forget ; flatten)
open import BBHeap.Heapify _≤_ tot≤ trans≤
open import BBHeap.Insert _≤_ tot≤ trans≤
open import BBHeap.Subtyping _≤_ trans≤
open import BHeap _≤_ hiding (forget) renaming (flatten to flatten')
open import BHeap.Order _≤_
open import BHeap.Order.Properties _≤_
open import BHeap.Properties _≤_
open import Bound.Lower A
open import Bound.Lower.Order _≤_
open import Data.List
open import Data.Nat renaming (_≤_ to _≤ₙ_)
open import Data.Sum
open import Heapsort.Impl1 _≤_ tot≤ trans≤
open import List.Permutation.Base A
open import List.Permutation.Base.Equivalence A
open import List.Permutation.Base.Concatenation A
open import OList _≤_
open import Order.Total _≤_ tot≤
open import Relation.Binary
open DecTotalOrder decTotalOrder hiding (refl)
lemma-flatten-flatten' : {b : Bound}(h : BHeap b)(accₕ : Acc h) → forget (flatten h accₕ) ∼ flatten' h
lemma-flatten-flatten' lf _ = ∼[]
lemma-flatten-flatten' (nd b≤x l r) (acc rs) = ∼x /head /head (trans∼ (lemma-flatten-flatten' (merge tot≤ l r) (rs (merge tot≤ l r) (lemma-merge≤′ tot≤ b≤x l r))) (lemma-merge∼ tot≤ l r))
lemma-flatten'-flatten : {b : Bound}(h : BHeap b)(accₕ : Acc h) → (flatten' h) ∼ (forget (flatten h accₕ))
lemma-flatten'-flatten h tₕ = sym∼ (lemma-flatten-flatten' h tₕ)
lemma-subtyping≡ : {b b' : Bound}(b'≤b : LeB b' b)(h : BBHeap b) → (flatten' (relax (subtyping b'≤b h))) ≡ flatten' (relax h)
lemma-subtyping≡ b'≤b leaf = refl
lemma-subtyping≡ b'≤b (left {l = l} {r = r} b≤x l⋘r) rewrite lemma-subtyping≡ b≤x l | lemma-subtyping≡ b≤x r = refl
lemma-subtyping≡ b'≤b (right {l = l} {r = r} b≤x l⋙r) rewrite lemma-subtyping≡ b≤x l | lemma-subtyping≡ b≤x r = refl
lemma-insert∼ : {b : Bound}{x : A}(b≤x : LeB b (val x))(h : BBHeap b) → (x ∷ flatten' (relax h)) ∼ (flatten' (relax (insert b≤x h)))
lemma-insert∼ b≤x leaf = refl∼
lemma-insert∼ {x = x} b≤x (left {x = y} {l = l} {r = r} b≤y l⋘r)
with tot≤ x y
... | inj₁ x≤y
with lemma-insert⋘ (lexy refl≤) l⋘r
... | inj₁ lᵢ⋘r
rewrite lemma-subtyping≡ {val y} {val x} (lexy x≤y) (insert {val y} {y} (lexy refl≤) l)
| lemma-subtyping≡ {val y} {val x} (lexy x≤y) r
= ∼x /head /head (lemma++∼r (lemma-insert∼ (lexy refl≤) l))
... | inj₂ lᵢ⋗r
rewrite lemma-subtyping≡ {val y} {val x} (lexy x≤y) (insert {val y} {y} (lexy refl≤) l)
| lemma-subtyping≡ {val y} {val x} (lexy x≤y) r
= ∼x /head /head (lemma++∼r (lemma-insert∼ (lexy refl≤) l))
lemma-insert∼ {x = x} b≤x (left {x = y} {l = l} {r = r} b≤y l⋘r) | inj₂ y≤x
with lemma-insert⋘ (lexy y≤x) l⋘r
... | inj₁ lᵢ⋘r = ∼x (/tail /head) /head (lemma++∼r (lemma-insert∼ (lexy y≤x) l))
... | inj₂ lᵢ⋗r = ∼x (/tail /head) /head (lemma++∼r (lemma-insert∼ (lexy y≤x) l))
lemma-insert∼ {x = x} b≤x (right {x = y} {l = l} {r = r} b≤y l⋙r)
with tot≤ x y
... | inj₁ x≤y
with lemma-insert⋙ (lexy refl≤) l⋙r
... | inj₁ l⋙rᵢ
rewrite lemma-subtyping≡ {val y} {val x} (lexy x≤y) (insert {val y} {y} (lexy refl≤) r)
| lemma-subtyping≡ {val y} {val x} (lexy x≤y) l
= ∼x /head /head (trans∼ (∼x /head (lemma++/ {xs = flatten' (relax l)}) refl∼) (lemma++∼l {xs = flatten' (relax l)} (lemma-insert∼ (lexy refl≤) r)))
... | inj₂ l≃rᵢ
rewrite lemma-subtyping≡ {val y} {val x} (lexy x≤y) (insert {val y} {y} (lexy refl≤) r)
| lemma-subtyping≡ {val y} {val x} (lexy x≤y) l
= ∼x /head /head (trans∼ (∼x /head (lemma++/ {xs = flatten' (relax l)}) refl∼) (lemma++∼l {xs = flatten' (relax l)} (lemma-insert∼ (lexy refl≤) r)))
lemma-insert∼ {x = x} b≤x (right {x = y} {l = l} {r = r} b≤y l⋙r) | inj₂ y≤x
with lemma-insert⋙ (lexy y≤x) l⋙r
... | inj₁ l⋙rᵢ = ∼x (/tail /head) /head (trans∼ (∼x /head (lemma++/ {xs = flatten' (relax l)}) refl∼) (lemma++∼l {xs = flatten' (relax l)} (lemma-insert∼ (lexy y≤x) r)))
... | inj₂ l≃rᵢ = ∼x (/tail /head) /head (trans∼ (∼x /head (lemma++/ {xs = flatten' (relax l)}) refl∼) (lemma++∼l {xs = flatten' (relax l)} (lemma-insert∼ (lexy y≤x) r)))
theorem-heapsort∼ : (xs : List A) → xs ∼ forget (heapsort xs)
theorem-heapsort∼ [] = ∼[]
theorem-heapsort∼ (x ∷ xs) = trans∼ (trans∼ (∼x /head /head (trans∼ (theorem-heapsort∼ xs) (lemma-flatten-flatten' h' accₕ'))) (lemma-insert∼ lebx h)) (lemma-flatten'-flatten (hᵢ) accₕᵢ)
where h = heapify xs
h' = relax h
accₕ' = ≺-wf h'
hᵢ = relax (insert lebx h)
accₕᵢ = ≺-wf hᵢ
| {
"alphanum_fraction": 0.5755573906,
"avg_line_length": 55.6781609195,
"ext": "agda",
"hexsha": "6607af6cb281f34ab9bbedc137b6465b46f758c8",
"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/Heapsort/Impl1/Correctness/Permutation.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/Heapsort/Impl1/Correctness/Permutation.agda",
"max_line_length": 187,
"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/Heapsort/Impl1/Correctness/Permutation.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": 2004,
"size": 4844
} |
open import Common.Prelude
open import Common.Equality
test : "foo" ≡ "bar" → Set₁
test refl = Set
| {
"alphanum_fraction": 0.72,
"avg_line_length": 16.6666666667,
"ext": "agda",
"hexsha": "f6358fa0762c52c7bdbf3d12859da254628bd61b",
"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/LiteralConflict.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/LiteralConflict.agda",
"max_line_length": 27,
"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/LiteralConflict.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 31,
"size": 100
} |
-- 2012-02-22
module CorrectPrintingOfVariablesInSortCheckingForData where
data Bool : Set where
true false : Bool
if_then_else_ : {A : Set2} → Bool → A → A → A
if true then a else b = a
if false then a else b = b
data foo : (y : Bool) → if y then Set else Set
data foo where
bar : foo true
-- This should print
-- if y then Set else Set != Set of type Set₁
-- and not
-- if @0 then ... | {
"alphanum_fraction": 0.6550868486,
"avg_line_length": 21.2105263158,
"ext": "agda",
"hexsha": "66fdfc5c6dfef93be8154ddec99f563c5b6ed4f5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/CorrectPrintingOfVariablesInSortCheckingForData.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/CorrectPrintingOfVariablesInSortCheckingForData.agda",
"max_line_length": 60,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/CorrectPrintingOfVariablesInSortCheckingForData.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 128,
"size": 403
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Semiring -- for length
open import Lists.Definition
open import Lists.Fold.Fold
module Lists.Length where
length : {a : _} {A : Set a} (l : List A) → ℕ
length [] = zero
length (x :: l) = succ (length l)
length' : {a : _} {A : Set a} → (l : List A) → ℕ
length' = fold (λ _ → succ) 0
length=length' : {a : _} {A : Set a} (l : List A) → length l ≡ length' l
length=length' [] = refl
length=length' (x :: l) = applyEquality succ (length=length' l)
| {
"alphanum_fraction": 0.6337522442,
"avg_line_length": 27.85,
"ext": "agda",
"hexsha": "d770c9aad3d0d663795f4b6470ea26687c4a6bb5",
"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": "Lists/Length.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": "Lists/Length.agda",
"max_line_length": 72,
"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": "Lists/Length.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": 181,
"size": 557
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Bifunctor where
-- Bifunctor, aka a Functor from C × D to E
open import Level
open import Categories.Category
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.Category.Product
private
variable
o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ : Level
C D D₁ D₂ E E₁ E₂ : Category o ℓ e
Bifunctor : Category o ℓ e → Category o′ ℓ′ e′ → Category o″ ℓ″ e″ → Set _
Bifunctor C D E = Functor (Product C D) E
overlap-× : ∀ (H : Bifunctor D₁ D₂ C) (F : Functor E D₁) (G : Functor E D₂) → Functor E C
overlap-× H F G = H ∘F (F ※ G)
reduce-× : ∀ (H : Bifunctor D₁ D₂ C) (F : Functor E₁ D₁) (G : Functor E₂ D₂) → Bifunctor E₁ E₂ C
reduce-× H F G = H ∘F (F ⁂ G)
flip-bifunctor : Bifunctor C D E → Bifunctor D C E
flip-bifunctor b = b ∘F Swap
appˡ : Bifunctor C D E → Category.Obj C → Functor D E
appˡ F c = F ∘F constˡ c
appʳ : Bifunctor C D E → Category.Obj D → Functor C E
appʳ F d = F ∘F constʳ d
| {
"alphanum_fraction": 0.6623376623,
"avg_line_length": 29.4411764706,
"ext": "agda",
"hexsha": "abe71a2bc51aa0e42d7e8a9dcfa1a4070f4192a4",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Bifunctor.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Bifunctor.agda",
"max_line_length": 96,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Bifunctor.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": 384,
"size": 1001
} |
{-# OPTIONS --without-K #-}
module Agda.Builtin.Sigma where
open import Agda.Primitive
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
fst : A
snd : B fst
open Σ public
infixr 4 _,_
{-# BUILTIN SIGMA Σ #-}
| {
"alphanum_fraction": 0.601532567,
"avg_line_length": 14.5,
"ext": "agda",
"hexsha": "51f8ad7f3b6603f1089165728252ded06f7f4b3e",
"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": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bennn/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Sigma.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"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": "bennn/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Sigma.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bennn/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Sigma.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 91,
"size": 261
} |
------------------------------------------------------------------------
-- Code for converting Vec₁ n A → B to and from n-ary functions
------------------------------------------------------------------------
-- I want universe polymorphism.
module Data.Vec.N-ary1 where
open import Data.Nat
open import Data.Vec1
open import Relation.Binary.PropositionalEquality1
------------------------------------------------------------------------
-- N-ary functions
N-ary : ℕ → Set₁ → Set₁ → Set₁
N-ary zero A B = B
N-ary (suc n) A B = A → N-ary n A B
------------------------------------------------------------------------
-- Conversion
curryⁿ : ∀ {n A B} → (Vec₁ A n → B) → N-ary n A B
curryⁿ {zero} f = f []
curryⁿ {suc n} f = λ x → curryⁿ (λ xs → f (x ∷ xs))
_$ⁿ_ : ∀ {n A B} → N-ary n A B → (Vec₁ A n → B)
f $ⁿ [] = f
f $ⁿ (x ∷ xs) = f x $ⁿ xs
------------------------------------------------------------------------
-- N-ary function equality
Eq : ∀ {A B} n → (B → B → Set₁) → (f g : N-ary n A B) → Set₁
Eq zero _∼_ f g = f ∼ g
Eq (suc n) _∼_ f g = ∀ x → Eq n _∼_ (f x) (g x)
------------------------------------------------------------------------
-- Some lemmas
-- The two functions are inverses.
left-inverse : ∀ {n A B} (f : Vec₁ A n → B) →
∀ xs → curryⁿ f $ⁿ xs ≡₁ f xs
left-inverse f [] = refl
left-inverse f (x ∷ xs) = left-inverse (λ xs → f (x ∷ xs)) xs
data Lift {A : Set₁} (R : A → A → Set) x y : Set₁ where
lift : R x y → Lift R x y
right-inverse : ∀ {A B} n (f : N-ary n A B) →
Eq n (Lift _≡₁_) (curryⁿ (_$ⁿ_ {n} f)) f
right-inverse zero f = lift refl
right-inverse (suc n) f = λ x → right-inverse n (f x)
-- Conversion preserves equality.
curryⁿ-pres : ∀ {n A B _∼_} (f g : Vec₁ A n → B) →
(∀ xs → f xs ∼ g xs) →
Eq n _∼_ (curryⁿ f) (curryⁿ g)
curryⁿ-pres {zero} f g hyp = hyp []
curryⁿ-pres {suc n} f g hyp = λ x →
curryⁿ-pres (λ xs → f (x ∷ xs)) (λ xs → g (x ∷ xs))
(λ xs → hyp (x ∷ xs))
curryⁿ-pres⁻¹ : ∀ {n A B _∼_} (f g : Vec₁ A n → B) →
Eq n _∼_ (curryⁿ f) (curryⁿ g) →
∀ xs → f xs ∼ g xs
curryⁿ-pres⁻¹ f g hyp [] = hyp
curryⁿ-pres⁻¹ f g hyp (x ∷ xs) =
curryⁿ-pres⁻¹ (λ xs → f (x ∷ xs)) (λ xs → g (x ∷ xs)) (hyp x) xs
appⁿ-pres : ∀ {n A B _∼_} (f g : N-ary n A B) →
Eq n _∼_ f g →
(xs : Vec₁ A n) → (f $ⁿ xs) ∼ (g $ⁿ xs)
appⁿ-pres f g hyp [] = hyp
appⁿ-pres f g hyp (x ∷ xs) = appⁿ-pres (f x) (g x) (hyp x) xs
appⁿ-pres⁻¹ : ∀ {n A B _∼_} (f g : N-ary n A B) →
((xs : Vec₁ A n) → (f $ⁿ xs) ∼ (g $ⁿ xs)) →
Eq n _∼_ f g
appⁿ-pres⁻¹ {zero} f g hyp = hyp []
appⁿ-pres⁻¹ {suc n} f g hyp = λ x →
appⁿ-pres⁻¹ (f x) (g x) (λ xs → hyp (x ∷ xs))
| {
"alphanum_fraction": 0.420331651,
"avg_line_length": 32.6352941176,
"ext": "agda",
"hexsha": "1f24a645bbb2d456852ab7ccda8737d83b424baa",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Vec/N-ary1.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Vec/N-ary1.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Vec/N-ary1.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 1048,
"size": 2774
} |
{-# OPTIONS --without-K --safe #-}
module PlainPi where
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
open import Relation.Binary.PropositionalEquality
infixr 70 _×ᵤ_
infixr 60 _+ᵤ_
infixr 50 _⊚_
------------------------------------------------------------------------------
-- Pi
data 𝕌 : Set
⟦_⟧ : (A : 𝕌) → Set
data _⟷_ : 𝕌 → 𝕌 → Set
eval : {A B : 𝕌} → (A ⟷ B) → ⟦ A ⟧ → ⟦ B ⟧
data 𝕌 where
𝟘 : 𝕌
𝟙 : 𝕌
_+ᵤ_ : 𝕌 → 𝕌 → 𝕌
_×ᵤ_ : 𝕌 → 𝕌 → 𝕌
⟦ 𝟘 ⟧ = ⊥
⟦ 𝟙 ⟧ = ⊤
⟦ t₁ +ᵤ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ t₁ ×ᵤ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
data _⟷_ where
unite₊l : {t : 𝕌} → 𝟘 +ᵤ t ⟷ t
uniti₊l : {t : 𝕌} → t ⟷ 𝟘 +ᵤ t
unite₊r : {t : 𝕌} → t +ᵤ 𝟘 ⟷ t
uniti₊r : {t : 𝕌} → t ⟷ t +ᵤ 𝟘
swap₊ : {t₁ t₂ : 𝕌} → t₁ +ᵤ t₂ ⟷ t₂ +ᵤ t₁
assocl₊ : {t₁ t₂ t₃ : 𝕌} → t₁ +ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ +ᵤ t₂) +ᵤ t₃
assocr₊ : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) +ᵤ t₃ ⟷ t₁ +ᵤ (t₂ +ᵤ t₃)
unite⋆l : {t : 𝕌} → 𝟙 ×ᵤ t ⟷ t
uniti⋆l : {t : 𝕌} → t ⟷ 𝟙 ×ᵤ t
unite⋆r : {t : 𝕌} → t ×ᵤ 𝟙 ⟷ t
uniti⋆r : {t : 𝕌} → t ⟷ t ×ᵤ 𝟙
swap⋆ : {t₁ t₂ : 𝕌} → t₁ ×ᵤ t₂ ⟷ t₂ ×ᵤ t₁
assocl⋆ : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) ×ᵤ t₃
assocr⋆ : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₂) ×ᵤ t₃ ⟷ t₁ ×ᵤ (t₂ ×ᵤ t₃)
absorbr : {t : 𝕌} → 𝟘 ×ᵤ t ⟷ 𝟘
absorbl : {t : 𝕌} → t ×ᵤ 𝟘 ⟷ 𝟘
factorzr : {t : 𝕌} → 𝟘 ⟷ t ×ᵤ 𝟘
factorzl : {t : 𝕌} → 𝟘 ⟷ 𝟘 ×ᵤ t
dist : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) ×ᵤ t₃ ⟷ (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃)
factor : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) ⟷ (t₁ +ᵤ t₂) ×ᵤ t₃
distl : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ +ᵤ t₃) ⟷ (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃)
factorl : {t₁ t₂ t₃ : 𝕌 } → (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) ⟷ t₁ ×ᵤ (t₂ +ᵤ t₃)
id⟷ : {t : 𝕌} → t ⟷ t
_⊚_ : {t₁ t₂ t₃ : 𝕌} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ +ᵤ t₂ ⟷ t₃ +ᵤ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (t₁ ×ᵤ t₂ ⟷ t₃ ×ᵤ t₄)
eval unite₊l (inj₂ v) = v
eval uniti₊l v = inj₂ v
eval unite₊r (inj₁ v) = v
eval uniti₊r v = inj₁ v
eval swap₊ (inj₁ v) = inj₂ v
eval swap₊ (inj₂ v) = inj₁ v
eval assocl₊ (inj₁ v) = inj₁ (inj₁ v)
eval assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
eval assocl₊ (inj₂ (inj₂ v)) = inj₂ v
eval assocr₊ (inj₁ (inj₁ v)) = inj₁ v
eval assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
eval assocr₊ (inj₂ v) = inj₂ (inj₂ v)
eval unite⋆l (tt , v) = v
eval uniti⋆l v = (tt , v)
eval unite⋆r (v , tt) = v
eval uniti⋆r v = (v , tt)
eval swap⋆ (v₁ , v₂) = (v₂ , v₁)
eval assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
eval assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
eval absorbl ()
eval absorbr ()
eval factorzl ()
eval factorzr ()
eval dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
eval dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
eval factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
eval factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
eval distl (v , inj₁ v₁) = inj₁ (v , v₁)
eval distl (v , inj₂ v₂) = inj₂ (v , v₂)
eval factorl (inj₁ (v , v₁)) = (v , inj₁ v₁)
eval factorl (inj₂ (v , v₂)) = (v , inj₂ v₂)
eval id⟷ v = v
eval (c₁ ⊚ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₁ v) = inj₁ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₂ v) = inj₂ (eval c₂ v)
eval (c₁ ⊗ c₂) (v₁ , v₂) = (eval c₁ v₁ , eval c₂ v₂)
| {
"alphanum_fraction": 0.4795821462,
"avg_line_length": 32.2346938776,
"ext": "agda",
"hexsha": "6589a2e144c3fd7bb0922286f07048f5d57d9e99",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "fracGC/PlainPi.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "fracGC/PlainPi.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "fracGC/PlainPi.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 2015,
"size": 3159
} |
{-# OPTIONS --erased-cubical --safe #-}
module Transformation where
open import Data.Integer using (ℤ; +_; _-_; -_)
open import Data.List using (List; _∷_; []; map; reverse)
open import Data.Product using (_,_)
open import Note using (Note; tone; rest)
open import Pitch using (Pitch; transposePitch)
open import Interval using (PitchPair)
retrograde : List Note → List Note
retrograde = reverse
-- Create a list of intervals between all adjacent tones, ignoring rests.
intervals : List Note → List ℤ
intervals [] = []
intervals (rest _ ∷ ns) = intervals ns
intervals (tone d p ∷ ns) = intervals' p ns where
intervals' : Pitch → List Note → List ℤ
intervals' p [] = []
intervals' p (rest d ∷ ns) = intervals' p ns
intervals' p (tone d q ∷ ns) = (+ q) - (+ p) ∷ intervals' q ns
inversion : List Note → List Note
inversion [] = []
inversion (rest d ∷ ns) = rest d ∷ inversion ns
inversion xs@(tone d p ∷ ns) = tone d p ∷ inversion' p is ns where
is : List ℤ
is = map (-_) (intervals xs)
inversion' : Pitch → List ℤ → List Note → List Note
inversion' p [] ns = ns
inversion' _ (_ ∷ _) [] = []
inversion' p is@(_ ∷ _) (rest d ∷ ns) = rest d ∷ inversion' p is ns
inversion' p (i ∷ is) (tone d _ ∷ ns) = let q = transposePitch i p in (tone d q) ∷ inversion' q is ns
| {
"alphanum_fraction": 0.5893108298,
"avg_line_length": 37.4210526316,
"ext": "agda",
"hexsha": "62b6e0cff300d34e554045c48cca0d6b3aab642a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Transformation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Transformation.agda",
"max_line_length": 105,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Transformation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 417,
"size": 1422
} |
------------------------------------------------------------------------------
-- Properties of the divisibility relation
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.Divisibility.By0.PropertiesATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Divisibility.By0
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.PropertiesATP
------------------------------------------------------------------------------
-- Any positive number divides 0.
postulate S∣0 : ∀ n → succ₁ n ∣ zero
{-# ATP prove S∣0 #-}
-- 0 divides 0.
postulate 0∣0 : zero ∣ zero
{-# ATP prove 0∣0 #-}
-- The divisibility relation is reflexive.
postulate ∣-refl : ∀ {n} → N n → n ∣ n
{-# ATP prove ∣-refl *-leftIdentity #-}
-- If x divides y and z then x divides y ∸ z.
postulate
x∣y→x∣z→x∣y∸z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * m →
o ≡ k' * m →
n ∸ o ≡ (k ∸ k') * m
{-# ATP prove x∣y→x∣z→x∣y∸z-helper *∸-leftDistributive #-}
x∣y→x∣z→x∣y∸z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n ∸ o
x∣y→x∣z→x∣y∸z Nm Nn No (k , Nk , h₁) (k' , Nk' , h₂) =
k ∸ k' , ∸-N Nk Nk' , x∣y→x∣z→x∣y∸z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and z then x divides y + z.
postulate
x∣y→x∣z→x∣y+z-helper : ∀ {m n o k k'} → N m → N k → N k' →
n ≡ k * m →
o ≡ k' * m →
n + o ≡ (k + k') * m
{-# ATP prove x∣y→x∣z→x∣y+z-helper *+-leftDistributive #-}
x∣y→x∣z→x∣y+z : ∀ {m n o} → N m → N n → N o → m ∣ n → m ∣ o → m ∣ n + o
x∣y→x∣z→x∣y+z Nm Nn No (k , Nk , h₁) (k' , Nk' , h₂) =
k + k' , +-N Nk Nk' , x∣y→x∣z→x∣y+z-helper Nm Nk Nk' h₁ h₂
-- If x divides y and y is positive, then x ≤ y.
postulate x∣S→x≤S-helper₁ : ∀ {m n} → succ₁ n ≡ zero * m → ⊥
{-# ATP prove x∣S→x≤S-helper₁ #-}
-- Nice proof by the ATPa.
postulate x∣S→x≤S-helper₂ : ∀ {m n o} → N m → N n → N o →
succ₁ n ≡ succ₁ o * m →
m ≤ succ₁ n
{-# ATP prove x∣S→x≤S-helper₂ x≤x+y *-N #-}
x∣S→x≤S : ∀ {m n} → N m → N n → m ∣ (succ₁ n) → m ≤ succ₁ n
x∣S→x≤S Nm Nn (.zero , nzero , Sn≡0*m) = ⊥-elim (x∣S→x≤S-helper₁ Sn≡0*m)
x∣S→x≤S Nm Nn (.(succ₁ k) , nsucc {k} Nk , Sn≡Sk*m) =
x∣S→x≤S-helper₂ Nm Nn Nk Sn≡Sk*m
| {
"alphanum_fraction": 0.4574303406,
"avg_line_length": 36.9142857143,
"ext": "agda",
"hexsha": "52f42a50820fd5b658651104504b683bfadec24a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/Nat/Divisibility/By0/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Nat/Divisibility/By0/PropertiesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/Nat/Divisibility/By0/PropertiesATP.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": 1036,
"size": 2584
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
--(Binary) product of objects and morphisms
module Categories.Object.Product {o ℓ e} (C : Category o ℓ e) where
open import Categories.Object.Product.Core C public
open import Categories.Object.Product.Morphisms C public
| {
"alphanum_fraction": 0.7663230241,
"avg_line_length": 29.1,
"ext": "agda",
"hexsha": "fe095f1d80476a08b995b36bbdb10c9f18fdc675",
"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/Object/Product.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/Object/Product.agda",
"max_line_length": 67,
"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/Object/Product.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": 65,
"size": 291
} |
module examplesPaperJFP.finn where
open import Data.Nat
data Fin : ℕ → Set where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} (i : Fin n) → Fin (suc n)
mutual
data Even : ℕ → Set where
0p : Even 0
sucp : {n : ℕ} → Odd n → Even (suc n)
data Odd : ℕ → Set where
sucp : {n : ℕ} → Even n → Odd (suc n)
| {
"alphanum_fraction": 0.5176470588,
"avg_line_length": 21.25,
"ext": "agda",
"hexsha": "5e0a4e41e59fa5d3c777f979ec98aa3c1a310a4f",
"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/examplesPaperJFP/finn.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/examplesPaperJFP/finn.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/examplesPaperJFP/finn.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": 143,
"size": 340
} |
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module CombiningProofs.WhereTranslation where
open import FOTC.Base
open import FOTC.Data.Nat
-- See Issue https://github.com/asr/apia/issues/81 .
+-rightIdentityA : D → Set
+-rightIdentityA i = i + zero ≡ i
{-# ATP definition +-rightIdentityA #-}
+-rightIdentity : ∀ {n} → N n → n + zero ≡ n
+-rightIdentity Nn = N-ind +-rightIdentityA A0 is Nn
where
postulate A0 : +-rightIdentityA zero
{-# ATP prove A0 #-}
postulate is : ∀ {i} → +-rightIdentityA i → +-rightIdentityA (succ₁ i)
{-# ATP prove is #-}
A' : ∀ {n} → (Nn : N n) → D → Set
A' Nn i = i + zero ≡ i
-- {-# ATP definition A' #-}
postulate A0' : ∀ {n} → (Nn : N n) → A' Nn zero
-- {-# ATP prove A0' #-}
postulate is' : ∀ {n} → (Nn : N n) → ∀ {i} → A' Nn i → A' Nn (succ₁ i)
-- {-# ATP prove is' #-}
| {
"alphanum_fraction": 0.5628299894,
"avg_line_length": 27.8529411765,
"ext": "agda",
"hexsha": "e1f8b8b0c1e62bb7ec48ff4273654c3a6968a4a0",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/thesis/report/CombiningProofs/WhereTranslation.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/thesis/report/CombiningProofs/WhereTranslation.agda",
"max_line_length": 72,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/thesis/report/CombiningProofs/WhereTranslation.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": 315,
"size": 947
} |
-- (Pre)abelian categories
{-# OPTIONS --safe #-}
module Cubical.Categories.Abelian.Base where
open import Cubical.Categories.Additive.Base
open import Cubical.Categories.Category.Base
open import Cubical.Categories.Morphism
open import Cubical.Data.Sigma.Base
open import Cubical.Foundations.Prelude
private
variable
ℓ ℓ' : Level
-- (Co)kernels
module _ (C : PreaddCategory ℓ ℓ') where
open PreaddCategory C
module _ {x y : ob} (f : Hom[ x , y ]) where
-- Kernels
record IsKernel {k : ob} (ker : Hom[ k , x ]) : Type (ℓ-max ℓ ℓ') where
field
ker⋆f : ker ⋆ f ≡ 0h
univ : ∀ (w : ob) (t : Hom[ w , x ])
→ (t ⋆ f ≡ 0h) → ∃![ u ∈ Hom[ w , k ] ] (u ⋆ ker ≡ t)
record Kernel : Type (ℓ-max ℓ ℓ') where
constructor kernel
field
k : ob
ker : Hom[ k , x ]
isKer : IsKernel ker
open IsKernel isKer public
-- Cokernels
record IsCokernel {c : ob} (coker : Hom[ y , c ]) : Type (ℓ-max ℓ ℓ') where
field
f⋆coker : f ⋆ coker ≡ 0h
univ : ∀ (w : ob) (t : Hom[ y , w ])
→ (f ⋆ t ≡ 0h) → ∃![ u ∈ Hom[ c , w ] ] (coker ⋆ u ≡ t)
record Cokernel : Type (ℓ-max ℓ ℓ') where
field
c : ob
coker : Hom[ y , c ]
isCoker : IsCokernel coker
open IsCokernel isCoker public
-- Preabelian categories
record PreabCategoryStr (C : AdditiveCategory ℓ ℓ') : Type (ℓ-max ℓ ℓ') where
open AdditiveCategory C
field
hasKernels : {x y : ob} → (f : Hom[ x , y ]) → Kernel preaddcat f
hasCokernels : {x y : ob} → (f : Hom[ x , y ]) → Cokernel preaddcat f
-- Convenient ker/coker functions
ker = λ {x y} (f : Hom[ x , y ]) → hasKernels f .Kernel.ker
coker = λ {x y} (f : Hom[ x , y ]) → hasCokernels f .Cokernel.coker
record PreAbCategory (ℓ ℓ' : Level) : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
additive : AdditiveCategory ℓ ℓ'
preAbStr : PreabCategoryStr additive
open AdditiveCategory additive public
open PreabCategoryStr preAbStr public
-- Abelian categories
record AbelianCategoryStr (C : PreAbCategory ℓ ℓ') : Type (ℓ-max ℓ ℓ') where
open PreAbCategory C
private
_=ker_ : ∀ {k x y} → Hom[ k , x ] → Hom[ x , y ] → Type (ℓ-max ℓ ℓ')
m =ker f = IsKernel preaddcat f m
_=coker_ : ∀ {c x y} → Hom[ y , c ] → Hom[ x , y ] → Type (ℓ-max ℓ ℓ')
e =coker f = IsCokernel preaddcat f e
field
monNormal : {x y : ob} → (m : Hom[ x , y ]) → isMonic cat m
→ Σ[ z ∈ ob ] Σ[ f ∈ Hom[ y , z ] ] (m =ker f)
epiNormal : {x y : ob} → (e : Hom[ x , y ]) → isEpic cat e
→ Σ[ w ∈ ob ] Σ[ f ∈ Hom[ w , x ] ] (e =coker f)
record AbelianCategory (ℓ ℓ' : Level): Type (ℓ-suc (ℓ-max ℓ ℓ')) where
field
preAb : PreAbCategory ℓ ℓ'
abelianStr : AbelianCategoryStr preAb
open PreAbCategory preAb public
open AbelianCategoryStr abelianStr public
| {
"alphanum_fraction": 0.5815578065,
"avg_line_length": 27.7961165049,
"ext": "agda",
"hexsha": "effa51a4f23b373e8d76c052df3d04ea6c92a2ca",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Categories/Abelian/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Categories/Abelian/Base.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Categories/Abelian/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1062,
"size": 2863
} |
module Prelude.Eq where
open import Prelude.Level
infix 4 _==_
data _==_ {l : Level}{A : Set l} (x : A) : A → Set l where
refl : x == x
cong : {A : Set}{B : Set}{x y : A}(f : A → B) → x == y → f x == f y
cong f refl = refl
{-# BUILTIN EQUALITY _==_ #-}
| {
"alphanum_fraction": 0.5285171103,
"avg_line_length": 16.4375,
"ext": "agda",
"hexsha": "4055bc492c585724649056843cd4c117d1a5a2c4",
"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": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/epic/Prelude/Eq.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/epic/Prelude/Eq.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/epic/Prelude/Eq.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 103,
"size": 263
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Group
open import lib.types.Sigma
open import lib.types.Truncation
module lib.groups.SubgroupProp where
record SubgroupProp {i} (G : Group i) j : Type (lmax i (lsucc j)) where
private
module G = Group G
field
prop : G.El → Type j
level : ∀ g → is-prop (prop g)
-- In theory being inhabited implies that the identity is included,
-- but in practice let's just prove the identity case.
ident : prop G.ident
diff : ∀ {g₁ g₂} → prop g₁ → prop g₂ → prop (G.diff g₁ g₂)
subEl-prop : SubtypeProp G.El j
subEl-prop = prop , level
SubEl = Subtype subEl-prop
abstract
{-
ident : prop G.ident
ident = transport prop (G.inv-r (fst inhab)) (diff (snd inhab) (snd inhab))
-}
inv : ∀ {g} → prop g → prop (G.inv g)
inv pg = transport prop (G.unit-l _) (diff ident pg)
comp : ∀ {g₁ g₂} → prop g₁ → prop g₂ → prop (G.comp g₁ g₂)
comp {g₁} {g₂} pg₁ pg₂ =
transport prop (ap (G.comp g₁) (G.inv-inv g₂)) (diff pg₁ (inv pg₂))
is-fullᴳ : ∀ {i j} {G : Group i} → SubgroupProp G j → Type (lmax i j)
is-fullᴳ P = ∀ g → SubgroupProp.prop P g
-- Normal subgroups
is-normal : ∀ {i j} {G : Group i} → SubgroupProp G j → Type (lmax i j)
is-normal {G = G} P = ∀ g₁ {g₂} → P.prop g₂ → P.prop (Group.conj G g₁ g₂)
where module P = SubgroupProp P
NormalSubgroupProp : ∀ {i} (G : Group i) j → Type (lmax i (lsucc j))
NormalSubgroupProp {i} G j = Σ (SubgroupProp G j) is-normal
module NormalSubgroupProp {i j} {G : Group i} (normal-prop : NormalSubgroupProp G j) where
private
module G = Group G
propᴳ : SubgroupProp G j
propᴳ = fst normal-prop
open SubgroupProp propᴳ public
conj : is-normal propᴳ
conj = snd normal-prop
abstract
comm : ∀ g₁ g₂ → prop (G.comp g₁ g₂) → prop (G.comp g₂ g₁)
comm g₁ g₂ pg₁g₂ = transport prop
( ap (λ g → G.comp g (G.inv g₂)) (! (G.assoc g₂ g₁ g₂))
∙ G.assoc (G.comp g₂ g₁) g₂ (G.inv g₂)
∙ ap (G.comp (G.comp g₂ g₁)) (G.inv-r g₂)
∙ G.unit-r (G.comp g₂ g₁))
(conj g₂ pg₁g₂)
{- So far this is not used.
unconj : ∀ g₁ g₂ → prop (G.conj g₁ g₂) → prop g₂
unconj g₁ g₂ pg₁g₂ = transport prop path (conj (G.inv g₁) pg₁g₂) where
path : G.conj (G.inv g₁) (G.conj g₁ g₂) == g₂
path = ! (G.conj-comp-l (G.inv g₁) g₁ g₂) ∙ ap (λ g → G.conj g g₂) (G.inv-l g₁) ∙ G.conj-unit-l g₂
-}
abstract
comm-is-normal : ∀ {i j} {G : Group i} (P : SubgroupProp G j)
→ (∀ g₁ g₂ → SubgroupProp.prop P (Group.comp G g₁ g₂)
→ SubgroupProp.prop P (Group.comp G g₂ g₁))
→ is-normal P
comm-is-normal {G = G} P P-comm g₁ {g₂} Pg₂ =
transport! P.prop (G.assoc g₁ g₂ (G.inv g₁)) $
P-comm (G.diff g₂ g₁) g₁ $
transport! P.prop
( G.assoc g₂ (G.inv g₁) g₁
∙ ap (G.comp g₂) (G.inv-l g₁)
∙ G.unit-r g₂)
Pg₂
where module G = Group G
module P = SubgroupProp P
sub-abelian-is-normal : ∀ {i j} {G : Group i}
→ (G-is-abelian : is-abelian G)
→ (P : SubgroupProp G j)
→ is-normal P
sub-abelian-is-normal {G = G} G-is-abelian P =
comm-is-normal P λ g₁ g₂ Pg₁g₂ → transport P.prop (G.comm g₁ g₂) Pg₁g₂
where module G = AbGroup (G , G-is-abelian)
module P = SubgroupProp P
sub-abelian-normal : ∀ {i j} {G : Group i}
→ (G-is-abelian : is-abelian G)
→ SubgroupProp G j
→ NormalSubgroupProp G j
sub-abelian-normal G-is-abelian P = P , sub-abelian-is-normal G-is-abelian P
{- Subgroups of subgroups -}
infix 40 _⊆ᴳ_
_⊆ᴳ_ : ∀ {i j k} {G : Group i}
→ SubgroupProp G j → SubgroupProp G k → Type (lmax i (lmax j k))
P ⊆ᴳ Q = ∀ g → P.prop g → Q.prop g
where module P = SubgroupProp P
module Q = SubgroupProp Q
{- triviality -}
trivial-propᴳ : ∀ {i} (G : Group i) → SubgroupProp G i
trivial-propᴳ {i} G = record {M} where
module G = Group G
module M where
prop : G.El → Type i
prop g = g == G.ident
ident : prop G.ident
ident = idp
level : ∀ g → is-prop (prop g)
level g = G.El-level g G.ident
abstract
diff : {g₁ g₂ : G.El} → prop g₁ → prop g₂ → prop (G.diff g₁ g₂)
diff g₁=id g₂=id = ap2 G.comp g₁=id (ap G.inv g₂=id ∙ G.inv-ident)
∙ G.unit-r G.ident
is-trivial-propᴳ : ∀ {i j} {G : Group i} → SubgroupProp G j → Type (lmax i j)
is-trivial-propᴳ {G = G} P = P ⊆ᴳ trivial-propᴳ G
| {
"alphanum_fraction": 0.5940460081,
"avg_line_length": 31.8992805755,
"ext": "agda",
"hexsha": "bc529037f100c3132eddf0355173e2e99dcd3f82",
"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/groups/SubgroupProp.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/groups/SubgroupProp.agda",
"max_line_length": 104,
"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/groups/SubgroupProp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1639,
"size": 4434
} |
{-# OPTIONS --safe #-}
open import Generics.Prelude
open import Generics.Telescope
open import Generics.Desc
open import Generics.Mu
module Generics.Mu.Fold
{P I n} {D : DataDesc P I n}
{c} (X : ⟦ P , I ⟧xtel → Set c)
(alg : ∀ {pi} → ⟦ D ⟧Data X pi → X pi) where
private
variable
p : ⟦ P ⟧tel tt
V : ExTele P
i : ⟦ I ⟧tel p
v : ⟦ V ⟧tel p
fold : μ D (p , i) → X (p , i)
foldIndArg : (C : ConDesc P V I)
(x : ⟦ C ⟧IndArgω (μ D) (p , v))
→ ⟦ C ⟧IndArg X (p , v)
foldIndArg (var _) x = fold x
foldIndArg (π ia _ C) x = fun< ia > λ s → foldIndArg C (x s)
foldIndArg (A ⊗ B) (xa , xb) = foldIndArg A xa , foldIndArg B xb
foldCon : (C : ConDesc P V I)
(x : ⟦ C ⟧Conω (μ D) (p , v , i))
→ ⟦ C ⟧Con X (p , v , i)
foldCon (var _) (liftω refl) = refl
foldCon (π _ _ C) (s , x) = (s , foldCon C x)
foldCon (A ⊗ B) (xa , xb) = foldIndArg A xa , foldCon B xb
fold ⟨ k , x ⟩ = alg (k , foldCon (lookupCon D k) x)
| {
"alphanum_fraction": 0.5318930041,
"avg_line_length": 26.2702702703,
"ext": "agda",
"hexsha": "ca0619e7095323b1f40490765cbefce269b9b93a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Mu/Fold.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Mu/Fold.agda",
"max_line_length": 64,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Mu/Fold.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 404,
"size": 972
} |
{-# OPTIONS --safe #-}
module Cubical.Data.SumFin.Properties where
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Unit
import Cubical.Data.Fin as Fin
open import Cubical.Data.Nat
open import Cubical.Data.SumFin.Base as SumFin
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
private
variable
ℓ : Level
k : ℕ
SumFin→Fin : Fin k → Fin.Fin k
SumFin→Fin = SumFin.elim (λ {k} _ → Fin.Fin k) Fin.fzero Fin.fsuc
Fin→SumFin : Fin.Fin k → Fin k
Fin→SumFin = Fin.elim (λ {k} _ → Fin k) fzero fsuc
Fin→SumFin-fsuc : (fk : Fin.Fin k) → Fin→SumFin (Fin.fsuc fk) ≡ fsuc (Fin→SumFin fk)
Fin→SumFin-fsuc = Fin.elim-fsuc (λ {k} _ → Fin k) fzero fsuc
SumFin→Fin→SumFin : (fk : Fin k) → Fin→SumFin (SumFin→Fin fk) ≡ fk
SumFin→Fin→SumFin = SumFin.elim (λ fk → Fin→SumFin (SumFin→Fin fk) ≡ fk)
refl λ {k} {fk} eq →
Fin→SumFin (Fin.fsuc (SumFin→Fin fk)) ≡⟨ Fin→SumFin-fsuc (SumFin→Fin fk) ⟩
fsuc (Fin→SumFin (SumFin→Fin fk)) ≡⟨ cong fsuc eq ⟩
fsuc fk ∎
Fin→SumFin→Fin : (fk : Fin.Fin k) → SumFin→Fin (Fin→SumFin fk) ≡ fk
Fin→SumFin→Fin = Fin.elim (λ fk → SumFin→Fin (Fin→SumFin fk) ≡ fk)
refl λ {k} {fk} eq →
SumFin→Fin (Fin→SumFin (Fin.fsuc fk)) ≡⟨ cong SumFin→Fin (Fin→SumFin-fsuc fk) ⟩
Fin.fsuc (SumFin→Fin (Fin→SumFin fk)) ≡⟨ cong Fin.fsuc eq ⟩
Fin.fsuc fk ∎
SumFin≃Fin : ∀ k → Fin k ≃ Fin.Fin k
SumFin≃Fin _ =
isoToEquiv (iso SumFin→Fin Fin→SumFin Fin→SumFin→Fin SumFin→Fin→SumFin)
SumFin≡Fin : ∀ k → Fin k ≡ Fin.Fin k
SumFin≡Fin k = ua (SumFin≃Fin k)
-- Closure properties of SumFin under type constructors
private
_⋆_ = compEquiv
infixr 30 _⋆_
SumFin⊎≃ : (m n : ℕ) → (Fin m ⊎ Fin n) ≃ (Fin (m + n))
SumFin⊎≃ 0 n = ⊎-swap-≃ ⋆ ⊎-⊥-≃
SumFin⊎≃ (suc m) n = ⊎-assoc-≃ ⋆ ⊎-equiv (idEquiv ⊤) (SumFin⊎≃ m n)
SumFinΣ≃ : (n : ℕ)(f : Fin n → ℕ) → (Σ (Fin n) (λ x → Fin (f x))) ≃ (Fin (totalSum f))
SumFinΣ≃ 0 f = ΣEmpty _
SumFinΣ≃ (suc n) f =
Σ⊎≃
⋆ ⊎-equiv (ΣUnit (λ tt → Fin (f (inl tt)))) (SumFinΣ≃ n (λ x → f (inr x)))
⋆ SumFin⊎≃ (f (inl tt)) (totalSum (λ x → f (inr x)))
SumFin×≃ : (m n : ℕ) → (Fin m × Fin n) ≃ (Fin (m · n))
SumFin×≃ m n = SumFinΣ≃ m (λ _ → n) ⋆ pathToEquiv (λ i → Fin (totalSumConst {m = m} n i))
SumFinΠ≃ : (n : ℕ)(f : Fin n → ℕ) → ((x : Fin n) → Fin (f x)) ≃ (Fin (totalProd f))
SumFinΠ≃ 0 f = isContr→≃Unit (isContrΠ⊥) ⋆ invEquiv (⊎-⊥-≃)
SumFinΠ≃ (suc n) f =
Π⊎≃
⋆ Σ-cong-equiv (ΠUnit (λ tt → Fin (f (inl tt)))) (λ _ → SumFinΠ≃ n (λ x → f (inr x)))
⋆ SumFin×≃ (f (inl tt)) (totalProd (λ x → f (inr x)))
isNotZero : ℕ → ℕ
isNotZero 0 = 0
isNotZero (suc n) = 1
SumFin∥∥≃ : (n : ℕ) → ∥ Fin n ∥ ≃ Fin (isNotZero n)
SumFin∥∥≃ 0 = propTruncIdempotent≃ (isProp⊥)
SumFin∥∥≃ (suc n) =
isContr→≃Unit (inhProp→isContr ∣ inl tt ∣ isPropPropTrunc)
⋆ isContr→≃Unit (isContrUnit) ⋆ invEquiv (⊎-⊥-≃)
| {
"alphanum_fraction": 0.6071768815,
"avg_line_length": 33.8602150538,
"ext": "agda",
"hexsha": "76df5fc8a3084da102cb734ec3cde2b1879db898",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Data/SumFin/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Data/SumFin/Properties.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Data/SumFin/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 1389,
"size": 3149
} |
module Basic.Compiler.Code where
open import Basic.AST
open import Basic.BigStep
open import Utils.Decidable
open import Utils.Monoid
open import Data.Fin using (Fin; #_)
open import Data.Vec hiding (_∷ʳ_; _++_; [_])
open import Data.Nat
open import Data.Bool renaming (not to notBool; if_then_else_ to ifBool_then_else)
open import Data.List hiding ([_])
open import Data.List.Properties
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Product
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Data.Empty
open import Algebra
import Level as L
private
module LM {a A} = Algebra.Monoid (Data.List.monoid {a} A)
{-
Chapter 3.1 and 3.2.
Semantics of an abstract machine and specification of the translation from
While syntax to the abstract machine syntax.
-}
{-
Definition of the stack and the AM
We follow the book closely here.
"nat-inj" and "bool-inj" just establish injectivity of context entry
constructors.
That we have to prove them is something of a limitation of the current Agda.
In contrast, Coq derives injectivity of constructors automatically.
-}
data StackEntry : Set where
nat : ℕ → StackEntry
bool : Bool → StackEntry
nat-inj : ∀ {n m} → (StackEntry ∋ nat n) ≡ nat m → n ≡ m
nat-inj refl = refl
bool-inj : ∀ {b b'} → (StackEntry ∋ bool b) ≡ bool b' → b ≡ b'
bool-inj refl = refl
Stack : Set
Stack = List StackEntry
mutual
data Inst (n : ℕ) : Set where
PUSH : ℕ → Inst n
FETCH STORE : Fin n → Inst n
ADD MUL SUB TRUE FALSE EQ LTE LT AND NOT NOOP : Inst n
BRANCH LOOP : Code n → Code n → Inst n
Code : ℕ → Set
Code = List ∘ Inst
-- Semantics
------------------------------------------------------------
data ⟨_,_,_⟩▷⟨_,_,_⟩ {n} : Code n → Stack → State n → Code n → Stack → State n → Set where
PUSH :
∀ n {c e s}
→ --------------------------------------------
⟨ PUSH n ∷ c , e , s ⟩▷⟨ c , nat n ∷ e , s ⟩
ADD :
∀ a b {c e s}
→ ---------------------------------------------------------------
⟨ ADD ∷ c , nat a ∷ nat b ∷ e , s ⟩▷⟨ c , nat (a + b) ∷ e , s ⟩
MUL :
∀ a b {c e s}
→ ----------------------------------------------------------------
⟨ MUL ∷ c , nat a ∷ nat b ∷ e , s ⟩▷⟨ c , nat (a * b) ∷ e , s ⟩
SUB :
∀ a b {c e s}
→ ----------------------------------------------------------------
⟨ SUB ∷ c , nat a ∷ nat b ∷ e , s ⟩▷⟨ c , nat (a ∸ b) ∷ e , s ⟩
TRUE :
∀ {c e s}
→ -----------------------------------------------
⟨ TRUE ∷ c , e , s ⟩▷⟨ c , bool true ∷ e , s ⟩
FALSE :
∀ {c e s}
→ ------------------------------------------------
⟨ FALSE ∷ c , e , s ⟩▷⟨ c , bool false ∷ e , s ⟩
EQ :
∀ a b {c e s}
→ -------------------------------------------------------------------
⟨ EQ ∷ c , nat a ∷ nat b ∷ e , s ⟩▷⟨ c , bool ⌊ a ≡⁇ b ⌋ ∷ e , s ⟩
LT :
∀ a b {c e s}
→ -------------------------------------------------------------------
⟨ LT ∷ c , nat a ∷ nat b ∷ e , s ⟩▷⟨ c , bool ⌊ a <⁇ b ⌋ ∷ e , s ⟩
LTE :
∀ a b {c e s}
→ --------------------------------------------------------------------
⟨ LTE ∷ c , nat a ∷ nat b ∷ e , s ⟩▷⟨ c , bool ⌊ a ≤⁇ b ⌋ ∷ e , s ⟩
AND :
∀ a b {c e s}
→ -------------------------------------------------------------------
⟨ AND ∷ c , bool a ∷ bool b ∷ e , s ⟩▷⟨ c , bool (a ∧ b) ∷ e , s ⟩
NOT :
∀ b {c e s}
→ -----------------------------------------------------------
⟨ NOT ∷ c , bool b ∷ e , s ⟩▷⟨ c , bool (notBool b) ∷ e , s ⟩
FETCH :
∀ x {c e s}
→ ---------------------------------------------------------
⟨ FETCH x ∷ c , e , s ⟩▷⟨ c , nat (lookup x s) ∷ e , s ⟩
STORE :
∀ x {n c e s}
→ ------------------------------------------------------
⟨ STORE x ∷ c , nat n ∷ e , s ⟩▷⟨ c , e , s [ x ]≔ n ⟩
BRANCH :
∀ {c₁ c₂ c t e s} → let c' = (ifBool t then c₁ else c₂) <> c in
--------------------------------------------------------------
⟨ BRANCH c₁ c₂ ∷ c , bool t ∷ e , s ⟩▷⟨ c' , e , s ⟩
NOOP :
∀ {c e s}
→ ------------------------------------
⟨ NOOP ∷ c , e , s ⟩▷⟨ c , e , s ⟩
LOOP :
∀ {c₁ c₂ c e s} → let c' = c₁ <> BRANCH (c₂ ∷ʳ LOOP c₁ c₂ ) (NOOP ∷ []) ∷ c in
-----------------------------------------------------------------------------------
⟨ LOOP c₁ c₂ ∷ c , e , s ⟩▷⟨ c' , e , s ⟩
-- Computation sequences
------------------------------------------------------------
infixr 5 _∷_
data ⟨_,_,_⟩▷*⟨_,_,_⟩ {n} : Code n → Stack → State n → Code n → Stack → State n → Set where
done :
∀ {e s}
→ ---------------------------------
⟨ [] , e , s ⟩▷*⟨ [] , e , s ⟩
{- We define "being stuck" explicitly as a configuration from which no transitions exist -}
stuck :
∀ {c cs e s} → (∀ c' e' s' → ¬ ⟨ c ∷ cs , e , s ⟩▷⟨ c' , e' , s' ⟩)
→ ------------------------------------------------------------
⟨ c ∷ cs , e , s ⟩▷*⟨ c ∷ cs , e , s ⟩
_∷_ :
∀ {c e s c' e' s' c'' e'' s''} →
⟨ c , e , s ⟩▷⟨ c' , e' , s' ⟩ → ⟨ c' , e' , s' ⟩▷*⟨ c'' , e'' , s'' ⟩
→ ------------------------------------------------------------------------
⟨ c , e , s ⟩▷*⟨ c'' , e'' , s'' ⟩
{- We will need the length of computation sequences for the compiler correctness proof -}
▷*-length : ∀ {n}{c c' e e'}{s s' : State n} → ⟨ c , e , s ⟩▷*⟨ c' , e' , s' ⟩ → ℕ
▷*-length done = 0
▷*-length (stuck x) = 0
▷*-length (x ∷ p) = suc (▷*-length p)
-- Determinism (exercise 3.6)
------------------------------------------------------------
▷-deterministic :
∀ {n}{c c' c'' e e' e''}{s s' s'' : State n}
→ ⟨ c , e , s ⟩▷⟨ c' , e' , s' ⟩ → ⟨ c , e , s ⟩▷⟨ c'' , e'' , s'' ⟩
→ (c' ≡ c'') × (e' ≡ e'') × (s' ≡ s'')
▷-deterministic (PUSH n₁) (PUSH .n₁) = refl , refl , refl
▷-deterministic (ADD a b) (ADD .a .b) = refl , refl , refl
▷-deterministic (MUL a b) (MUL .a .b) = refl , refl , refl
▷-deterministic (SUB a b) (SUB .a .b) = refl , refl , refl
▷-deterministic TRUE TRUE = refl , refl , refl
▷-deterministic FALSE FALSE = refl , refl , refl
▷-deterministic (EQ a b) (EQ .a .b) = refl , refl , refl
▷-deterministic (LT a b) (LT .a .b) = refl , refl , refl
▷-deterministic (LTE a b) (LTE .a .b) = refl , refl , refl
▷-deterministic (AND a b) (AND .a .b) = refl , refl , refl
▷-deterministic (NOT b) (NOT .b) = refl , refl , refl
▷-deterministic (FETCH x) (FETCH .x) = refl , refl , refl
▷-deterministic (STORE x) (STORE .x) = refl , refl , refl
▷-deterministic BRANCH BRANCH = refl , refl , refl
▷-deterministic NOOP NOOP = refl , refl , refl
▷-deterministic LOOP LOOP = refl , refl , refl
▷*-deterministic :
∀ {n}{c c' c'' e e' e''}{s s' s'' : State n}
→ ⟨ c , e , s ⟩▷*⟨ c' , e' , s' ⟩ → ⟨ c , e , s ⟩▷*⟨ c'' , e'' , s'' ⟩
→ (c' ≡ c'') × (e' ≡ e'') × (s' ≡ s'')
▷*-deterministic done done = refl , refl , refl
▷*-deterministic done (() ∷ p2)
▷*-deterministic (stuck x) (stuck x₁) = refl , refl , refl
▷*-deterministic (stuck x) (x₁ ∷ p2) = ⊥-elim (x _ _ _ x₁)
▷*-deterministic (() ∷ p1) done
▷*-deterministic (x ∷ p1) (stuck x₁) = ⊥-elim (x₁ _ _ _ x)
▷*-deterministic (x ∷ p1) (x₁ ∷ p2) with ▷-deterministic x x₁
... | eq1 , eq2 , eq3 rewrite eq1 | eq2 | eq3 = ▷*-deterministic p1 p2
-- Compilation (chapter 3.2)
------------------------------------------------------------
𝓒⟦_⟧ᵉ : ∀ {n t} → Exp n t → Code n
𝓒⟦ lit x ⟧ᵉ = PUSH x ∷ []
𝓒⟦ add a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ ADD
𝓒⟦ mul a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ MUL
𝓒⟦ sub a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ SUB
𝓒⟦ var x ⟧ᵉ = FETCH x ∷ []
𝓒⟦ tt ⟧ᵉ = TRUE ∷ []
𝓒⟦ ff ⟧ᵉ = FALSE ∷ []
𝓒⟦ eq a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ EQ
𝓒⟦ lte a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ LTE
𝓒⟦ lt a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ LT
𝓒⟦ Exp.and a b ⟧ᵉ = 𝓒⟦ b ⟧ᵉ <> 𝓒⟦ a ⟧ᵉ ∷ʳ AND
𝓒⟦ not e ⟧ᵉ = 𝓒⟦ e ⟧ᵉ ∷ʳ NOT
𝓒⟦_⟧ˢ : ∀ {n} → St n → Code n
𝓒⟦ x := e ⟧ˢ = 𝓒⟦ e ⟧ᵉ ∷ʳ STORE x
𝓒⟦ skip ⟧ˢ = NOOP ∷ []
𝓒⟦ s₁ , s₂ ⟧ˢ = 𝓒⟦ s₁ ⟧ˢ <> 𝓒⟦ s₂ ⟧ˢ
𝓒⟦ if b then st₁ else st₂ ⟧ˢ = 𝓒⟦ b ⟧ᵉ ∷ʳ BRANCH 𝓒⟦ st₁ ⟧ˢ 𝓒⟦ st₂ ⟧ˢ
𝓒⟦ while b do st ⟧ˢ = LOOP 𝓒⟦ b ⟧ᵉ 𝓒⟦ st ⟧ˢ ∷ []
------------------------------------------------------------
{-
Some additional lemmas needed to the compiler correctness proofs.
-}
{- A weaker variant of exercise 3.4 -}
weaken-step-code :
∀ {n}{c c' c'' e e'}{s s' : State n}
→ ⟨ c , e , s ⟩▷⟨ c' , e' , s' ⟩
→ ⟨ c <> c'' , e , s ⟩▷⟨ c' <> c'' , e' , s' ⟩
weaken-step-code (PUSH n₁) = PUSH n₁
weaken-step-code (ADD a b) = ADD a b
weaken-step-code (MUL a b) = MUL a b
weaken-step-code (SUB a b) = SUB a b
weaken-step-code TRUE = TRUE
weaken-step-code FALSE = FALSE
weaken-step-code (EQ a b) = EQ a b
weaken-step-code (LT a b) = LT a b
weaken-step-code (LTE a b) = LTE a b
weaken-step-code (AND a b) = AND a b
weaken-step-code (NOT b) = NOT b
weaken-step-code (FETCH x) = FETCH x
weaken-step-code (STORE x) = STORE x
weaken-step-code {c'' = c''}(BRANCH {c₁}{c₂}{c}{t})
rewrite LM.assoc (ifBool t then c₁ else c₂) c c'' = BRANCH
weaken-step-code {c'' = c''}(LOOP {c₁}{c₂}{c})
rewrite LM.assoc c₁ (BRANCH (c₂ ∷ʳ LOOP c₁ c₂) (NOOP ∷ []) ∷ c) c'' = LOOP
weaken-step-code NOOP = NOOP
{-
This lemma is not in the book, but it's very convenient to use in the following
proofs. It's just the analogue of Basic.SmallStep.append for the computation
sequences here.
-}
infixr 5 _▷*<>_
_▷*<>_ :
∀ {n c c' e e' e''}{s s' s'' : State n}
→ ⟨ c , e , s ⟩▷*⟨ [] , e' , s' ⟩
→ ⟨ c' , e' , s' ⟩▷*⟨ [] , e'' , s'' ⟩
→ ⟨ c <> c' , e , s ⟩▷*⟨ [] , e'' , s'' ⟩
_▷*<>_ done p2 = p2
_▷*<>_ (step ∷ p1) p2 = weaken-step-code step ∷ p1 ▷*<> p2
{- Lemma 3.18 -}
𝓒-Exp-nat :
∀ {n e}{s : State n} exp -> ⟨ 𝓒⟦ exp ⟧ᵉ , e , s ⟩▷*⟨ [] , nat (⟦ exp ⟧ᵉ s) ∷ e , s ⟩
𝓒-Exp-nat (lit x) = PUSH x ∷ done
𝓒-Exp-nat (add a b) = (𝓒-Exp-nat b ▷*<> 𝓒-Exp-nat a) ▷*<> (ADD _ _ ∷ done)
𝓒-Exp-nat (mul a b) = (𝓒-Exp-nat b ▷*<> 𝓒-Exp-nat a) ▷*<> (MUL _ _ ∷ done)
𝓒-Exp-nat (sub a b) = (𝓒-Exp-nat b ▷*<> 𝓒-Exp-nat a) ▷*<> (SUB _ _ ∷ done)
𝓒-Exp-nat (var x) = FETCH x ∷ done
{- Lemma 3.19 -}
𝓒-Exp-bool :
∀ {n e}{s : State n} exp -> ⟨ 𝓒⟦ exp ⟧ᵉ , e , s ⟩▷*⟨ [] , bool (⟦ exp ⟧ᵉ s) ∷ e , s ⟩
𝓒-Exp-bool tt = TRUE ∷ done
𝓒-Exp-bool ff = FALSE ∷ done
𝓒-Exp-bool (eq a b) = (𝓒-Exp-nat b ▷*<> 𝓒-Exp-nat a) ▷*<> EQ _ _ ∷ done
𝓒-Exp-bool (lte a b) = (𝓒-Exp-nat b ▷*<> 𝓒-Exp-nat a) ▷*<> LTE _ _ ∷ done
𝓒-Exp-bool (lt a b) = (𝓒-Exp-nat b ▷*<> 𝓒-Exp-nat a) ▷*<> LT _ _ ∷ done
𝓒-Exp-bool (Exp.and a b) = (𝓒-Exp-bool b ▷*<> 𝓒-Exp-bool a) ▷*<> AND _ _ ∷ done
𝓒-Exp-bool (not e) = 𝓒-Exp-bool e ▷*<> NOT _ ∷ done
{-
A "smart constructor" that gets rid of the trailing (++[]) at the end of the branch.
This is not mentioned in the book, because it (rightfully) assumes that appendding an
empty list to the end of a list results in the same list, while here we have to make
this property explicit
-}
BRANCH-[] :
∀ {n c₁ c₂ e t}{s : State n} → let c' = ifBool t then c₁ else c₂ in
⟨ BRANCH c₁ c₂ ∷ [] , bool t ∷ e , s ⟩▷⟨ c' , e , s ⟩
BRANCH-[] {n}{c₁}{c₂}{e}{t}{s} =
subst
(λ b → ⟨ BRANCH c₁ c₂ ∷ [] , bool t ∷ e , s ⟩▷⟨ b , e , s ⟩)
(proj₂ LM.identity (ifBool t then c₁ else c₂))
BRANCH
| {
"alphanum_fraction": 0.4249217494,
"avg_line_length": 35.2865671642,
"ext": "agda",
"hexsha": "67d817ecee41974723f03f3167f95bbef604ebc8",
"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": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_forks_repo_path": "Basic/Compiler/Code.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"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": "AndrasKovacs/SemanticsWithApplications",
"max_issues_repo_path": "Basic/Compiler/Code.agda",
"max_line_length": 96,
"max_stars_count": 8,
"max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_stars_repo_path": "Basic/Compiler/Code.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z",
"num_tokens": 4683,
"size": 11821
} |
module ListNat where
data Nat : Set where
zero : Nat
succ : Nat -> Nat
data List (a : Set) : Set where
[] : List a
_::_ : a -> List a -> List a
infixr 30 _::_
[1,0,2] = one :: zero :: succ one :: []
where one = succ zero
| {
"alphanum_fraction": 0.5137254902,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "487234d4074d282352511166bae85680c66264b2",
"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": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/ListNat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"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": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/ListNat.agda",
"max_line_length": 41,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/ListNat.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 88,
"size": 255
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Subtype where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
private
variable
ℓ ℓ' : Level
-- The type of Subtypes of a type
Subtype : {ℓ : Level} → (ℓ' : Level) → Type ℓ → Type (ℓ-max ℓ (ℓ-suc ℓ'))
Subtype ℓ' A = A → (hProp ℓ')
-- Coercion from Subtype to Type
Subtype→Type : {ℓ ℓ' : Level} {A : Type ℓ} (B : Subtype ℓ' A) → Type (ℓ-max ℓ ℓ')
Subtype→Type {A = A} B = Σ[ a ∈ A ] (fst (B a))
-- if A has Level n > 0 then so do all of its subtypes -}
subtypePreservesHLevel : {ℓ ℓ' : Level} {A : Type ℓ} {n : ℕ₊₁} (p : isOfHLevel (ℕ₊₁→ℕ n) A) (B : Subtype ℓ' A) → isOfHLevel (ℕ₊₁→ℕ n) (Subtype→Type B)
subtypePreservesHLevel {n = one} p B = isPropΣ p λ a → snd (B a)
subtypePreservesHLevel {n = 1+ (suc n)} p B = isOfHLevelΣ (suc (suc n)) p λ a → isProp→isOfHLevelSuc (suc n) (snd (B a))
-- if two terms x and y of the original type A are equal by q, and p and p' witness that x , y are in
-- the subtype then p ≡ p' over q
subtypeWitnessIrrelevance : {A : Type ℓ} (B : Subtype ℓ' A) {xp yp : Subtype→Type B} (q : fst xp ≡ fst yp) → xp ≡ yp
subtypeWitnessIrrelevance B q = Σ≡Prop (λ a → B a .snd) q
| {
"alphanum_fraction": 0.6525037936,
"avg_line_length": 39.9393939394,
"ext": "agda",
"hexsha": "1f003feb6e9fc44605122ef17e604c8e44ef6004",
"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/Structures/Subtype.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/Structures/Subtype.agda",
"max_line_length": 150,
"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/Structures/Subtype.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 520,
"size": 1318
} |
{-# OPTIONS --without-K #-}
module higher.circle.properties where
open import sum
open import equality
open import function.isomorphism
open import sets.empty
open import sets.bool
open import hott.equivalence
open import hott.univalence
open import higher.circle.core
non-simply-connected : ¬ (loop ≡ refl)
non-simply-connected loop-trivial = inv-non-trivial inv-trivial
where
not-iso : Bool ≅' Bool
not-iso = iso not not H H , γ
where
H : (x : Bool) → not (not x) ≡ x
H true = refl
H false = refl
γ : (x : Bool) → ap not (H x) ≡ H (not x)
γ true = refl
γ false = refl
abstract
not-is-equiv : weak-equiv not
not-is-equiv = proj₂ (≅'⇒≈ not-iso)
not-equiv : Bool ≈ Bool
not-equiv = not , not-is-equiv
inv : Bool ≡ Bool
inv = ≈⇒≡ not-equiv
inv-non-trivial : ¬ (inv ≡ refl)
inv-non-trivial q = distinct absurd
where
open ≡-Reasoning
distinct : false ≡ true → ⊥
distinct ()
absurd : false ≡ true
absurd = begin
false
≡⟨ refl ⟩
not true
≡⟨ ap (λ g → g true)
(sym (uni-coherence not-equiv)) ⟩
coerce inv true
≡⟨ ap (λ z → coerce z true) q ⟩
coerce refl true
≡⟨ refl ⟩
true
∎
f : S¹ → Set
f = elim Bool inv
f' : base ≡ base → Bool ≡ Bool
f' p = ap f p
β₂ : f' loop ≡ inv
β₂ = β-loop Bool inv
inv-trivial : inv ≡ refl
inv-trivial = begin
inv
≡⟨ sym β₂ ⟩
f' loop
≡⟨ ap f' loop-trivial ⟩
refl
∎
where
open ≡-Reasoning
| {
"alphanum_fraction": 0.5228215768,
"avg_line_length": 21.6282051282,
"ext": "agda",
"hexsha": "684024335d13e59b8a7ad9e84a40327dd019535c",
"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/higher/circle/properties.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/higher/circle/properties.agda",
"max_line_length": 63,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/higher/circle/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 524,
"size": 1687
} |
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures
1 : Set1
1 = Set
| {
"alphanum_fraction": 0.7222222222,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "e189046cb8307400865701738ae108446f3ca0d6",
"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/Issue1609.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/Issue1609.agda",
"max_line_length": 71,
"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/Issue1609.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 28,
"size": 90
} |
{-# OPTIONS --without-K #-}
module Model.Quantification where
open import Model.RGraph as RG using (RGraph)
open import Model.Size as MS using (_<_ ; ⟦_⟧Δ ; ⟦_⟧n ; ⟦_⟧σ)
open import Model.Type.Core
open import Source.Size.Substitution.Theory
open import Source.Size.Substitution.Universe as SS using (Sub⊢ᵤ)
open import Util.HoTT.Equiv
open import Util.HoTT.FunctionalExtensionality
open import Util.HoTT.HLevel
open import Util.Prelude hiding (_∘_)
open import Util.Relation.Binary.PropositionalEquality using
( Σ-≡⁺ ; subst-sym-subst ; subst-subst-sym )
import Source.Size as SS
import Source.Type as ST
open RGraph
open RG._⇒_
open SS.Ctx
open SS.Sub⊢ᵤ
record ⟦∀⟧′ {Δ} n (T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ) (δ : Obj ⟦ Δ ⟧Δ) : Set where
no-eta-equality
field
arr : ∀ m (m<n : m < ⟦ n ⟧n .fobj δ) → Obj T (δ , m , m<n)
param : ∀ m m<n m′ m′<n → eq T _ (arr m m<n) (arr m′ m′<n)
open ⟦∀⟧′ public
⟦∀⟧′Canon : ∀ {Δ} n (T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ) (δ : Obj ⟦ Δ ⟧Δ) → Set
⟦∀⟧′Canon n T δ
= Σ[ f ∈ (∀ m (m<n : m < ⟦ n ⟧n .fobj δ) → Obj T (δ , m , m<n)) ]
(∀ m m<n m′ m′<n → eq T _ (f m m<n) (f m′ m′<n))
⟦∀⟧′≅⟦∀⟧′Canon : ∀ {Δ n T δ} → ⟦∀⟧′ {Δ} n T δ ≅ ⟦∀⟧′Canon n T δ
⟦∀⟧′≅⟦∀⟧′Canon = record
{ forth = λ { record { arr = x ; param = y } → x , y }
; isIso = record
{ back = λ x → record { arr = proj₁ x ; param = proj₂ x }
; back∘forth = λ { record {} → refl }
; forth∘back = λ _ → refl
}
}
abstract
⟦∀⟧′Canon-IsSet : ∀ {Δ n T δ} → IsSet (⟦∀⟧′Canon {Δ} n T δ)
⟦∀⟧′Canon-IsSet {T = T} = Σ-IsSet
(∀-IsSet λ m → ∀-IsSet λ m<n → λ _ _ → T .Obj-IsSet _ _)
(λ f → IsOfHLevel-suc 1 (∀-IsProp λ m → ∀-IsProp λ m<n → ∀-IsProp λ m′
→ ∀-IsProp λ m′<n → T .eq-IsProp))
⟦∀⟧′-IsSet : ∀ {Δ n T δ} → IsSet (⟦∀⟧′ {Δ} n T δ)
⟦∀⟧′-IsSet {Δ} {n} {T} {δ}
= ≅-pres-IsOfHLevel 2 (≅-sym ⟦∀⟧′≅⟦∀⟧′Canon) (⟦∀⟧′Canon-IsSet {Δ} {n} {T} {δ})
⟦∀⟧′-≡⁺ : ∀ {Δ n T δ} (f g : ⟦∀⟧′ {Δ} n T δ)
→ (∀ m m<n → f .arr m m<n ≡ g .arr m m<n)
→ f ≡ g
⟦∀⟧′-≡⁺ {T = T} record{} record{} f≈g = ≅-Injective ⟦∀⟧′≅⟦∀⟧′Canon (Σ-≡⁺
( (funext λ m → funext λ m<n → f≈g m m<n)
, funext λ m → funext λ m<n → funext λ m′ → funext λ m<n′ → T .eq-IsProp _ _))
⟦∀⟧′-resp-≈⟦Type⟧ : ∀ {Δ n T U}
→ T ≈⟦Type⟧ U
→ ∀ {δ} → ⟦∀⟧′ {Δ} n T δ ≅ ⟦∀⟧′ n U δ
⟦∀⟧′-resp-≈⟦Type⟧ T≈U = record
{ forth = λ f → record
{ arr = λ m m<n → T≈U .forth .fobj (f .arr m m<n)
; param = λ m m<n m′ m′<n → T≈U .forth .feq _ (f .param m m<n m′ m′<n)
}
; isIso = record
{ back = λ f → record
{ arr = λ m m<n → T≈U .back .fobj (f .arr m m<n)
; param = λ m m<n m′ m′<n → T≈U .back .feq _ (f .param m m<n m′ m′<n)
}
; back∘forth = λ x → ⟦∀⟧′-≡⁺ _ _ λ m m<n → T≈U .back-forth .≈⁻ _ _
; forth∘back = λ x → ⟦∀⟧′-≡⁺ _ _ λ m m<n → T≈U .forth-back .≈⁻ _ _
}
}
⟦∀⟧ : ∀ {Δ} n (T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ) → ⟦Type⟧ ⟦ Δ ⟧Δ
⟦∀⟧ n T = record
{ ObjHSet = λ δ → HLevel⁺ (⟦∀⟧′ n T δ) ⟦∀⟧′-IsSet
; eqHProp = λ _ f g → ∀-HProp _ λ m → ∀-HProp _ λ m<n → ∀-HProp _ λ m′
→ ∀-HProp _ λ m′<n → T .eqHProp _ (f .arr m m<n) (g .arr m′ m′<n)
; eq-refl = λ f → f .param
}
⟦∀⟧-resp-≈⟦Type⟧ : ∀ {Δ} n {T U : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ}
→ T ≈⟦Type⟧ U
→ ⟦∀⟧ n T ≈⟦Type⟧ ⟦∀⟧ n U
⟦∀⟧-resp-≈⟦Type⟧ n T≈U = record
{ forth = record
{ fobj = ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .forth
; feq = λ δ≈δ′ x≈y a a₁ a₂ a₃ → T≈U .forth .feq _ (x≈y a a₁ a₂ a₃)
}
; back = record
{ fobj = ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .back
; feq = λ δ≈δ′ x≈y a a₁ a₂ a₃ → T≈U .back .feq _ (x≈y a a₁ a₂ a₃)
}
; back-forth = ≈⁺ λ δ x → ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .back∘forth _
; forth-back = ≈⁺ λ δ x → ⟦∀⟧′-resp-≈⟦Type⟧ T≈U .forth∘back _
}
absₛ : ∀ {Δ n} {Γ : ⟦Type⟧ ⟦ Δ ⟧Δ} {T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ}
→ subT ⟦ SS.Wk ⟧σ Γ ⇒ T
→ Γ ⇒ ⟦∀⟧ n T
absₛ {Δ} {n} {Γ} {T} f = record
{ fobj = λ {δ} x → record
{ arr = λ m m<n → f .fobj x
; param = λ m m<n m′ m′<n → f .feq _ (Γ .eq-refl x)
}
; feq = λ _ x≈y m m′ m<nγ m′<nγ′ → f .feq _ x≈y
}
appₛ : ∀ {Δ n m} {Γ : ⟦Type⟧ ⟦ Δ ⟧Δ} {T : ⟦Type⟧ ⟦ Δ ∙ n ⟧Δ}
→ (m<n : m SS.< n)
→ Γ ⇒ ⟦∀⟧ n T
→ Γ ⇒ subT ⟦ SS.Sing m<n ⟧σ T
appₛ {m = m} {T = T} m<n f = record
{ fobj = λ {δ} x → f .fobj x .arr (⟦ m ⟧n .fobj δ) (MS.⟦<⟧ m<n)
; feq = λ δ≈δ′ {x y} x≈y → f .feq _ x≈y _ _ _ _
}
subT-⟦∀⟧ : ∀ {Δ Ω n σ} (⊢σ : σ ∶ Δ ⇒ᵤ Ω) (T : ⟦Type⟧ ⟦ Ω ∙ n ⟧Δ)
→ ⟦∀⟧ (n [ σ ]ᵤ)
(subT (⟦_⟧σ {Ω = Ω ∙ n} (Lift ⊢σ refl)) T)
≈⟦Type⟧ subT ⟦ ⊢σ ⟧σ (⟦∀⟧ n T)
subT-⟦∀⟧ {Δ} {Ω} {n} {σ} ⊢σ T = record
{ forth = record
{ fobj = λ {γ} f → record
{ arr = λ m m<n
→ transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(f .arr m (subst (m <_) (sym (MS.⟦sub⟧ ⊢σ n)) m<n))
; param = λ m m<n m′ m′<n
→ transportObj-resp-eq T _ _ (f .param _ _ _ _)
}
; feq = λ γ≈γ′ f≈g a a₁ a₂ a₃ → transportObj-resp-eq T _ _ (f≈g _ _ _ _)
}
; back = record
{ fobj = λ {γ} f → record
{ arr = λ m m<n
→ transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(f .arr m (subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n))
; param = λ m m<n m′ m′<n
→ transportObj-resp-eq T _ _ (f .param _ _ _ _)
}
; feq = λ γ≈γ′ f≈g a a₁ a₂ a₃ → transportObj-resp-eq T _ _ (f≈g _ _ _ _)
}
; back-forth = ≈⁺ λ γ f → ⟦∀⟧′-≡⁺ _ _ λ m m<n
→ trans
(transportObj∘transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl))
(trans
(cong
(λ p → transportObj T
(trans
(MS.⟦Δ∙n⟧-≡⁺ Ω n
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) p)
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n)
refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n)
(subst (m <_) (MS.⟦sub⟧ ⊢σ n) m<n)
refl refl))
(f .arr m p))
(subst-sym-subst (MS.⟦sub⟧ ⊢σ n)))
(transportObj-refl T _))
; forth-back = ≈⁺ λ γ f → ⟦∀⟧′-≡⁺ _ _ λ m m<n
→ trans
(transportObj∘transportObj T
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n _ _ refl refl))
(trans
(cong
(λ p → transportObj T
(trans
(MS.⟦Δ∙n⟧-≡⁺ Ω n p p refl refl)
(MS.⟦Δ∙n⟧-≡⁺ Ω n p m<n refl refl))
(f .arr m p))
(subst-subst-sym (MS.⟦sub⟧ ⊢σ n)))
(transportObj-refl T _))
}
| {
"alphanum_fraction": 0.4393518519,
"avg_line_length": 32.2388059701,
"ext": "agda",
"hexsha": "0e2b477eeeea3c2689cbeaa9783f05a40bac8151",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis-code",
"max_forks_repo_path": "src/Model/Quantification.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/msc-thesis-code",
"max_issues_repo_path": "src/Model/Quantification.agda",
"max_line_length": 82,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis-code",
"max_stars_repo_path": "src/Model/Quantification.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z",
"num_tokens": 3363,
"size": 6480
} |
module Tactic.Nat.Subtract.Refute where
open import Prelude
open import Builtin.Reflection
open import Tactic.Reflection.Quote
open import Tactic.Reflection.Substitute
open import Tactic.Reflection
open import Control.Monad.State
open import Tactic.Nat.Reflect
open import Tactic.Nat.NF
open import Tactic.Nat.Exp
open import Tactic.Nat.Auto
open import Tactic.Nat.Auto.Lemmas
open import Tactic.Nat.Simpl.Lemmas
open import Tactic.Nat.Simpl
open import Tactic.Nat.Reflect
open import Tactic.Nat.Subtract.Exp
open import Tactic.Nat.Subtract.Reflect
open import Tactic.Nat.Subtract.Lemmas
open import Tactic.Nat.Less.Lemmas
data Impossible : Set where
invalidEquation : ⊤
invalidEquation = _
private
0≠suc : ∀ n → 0 ≡ Nat.suc n → ⊥
0≠suc n ()
n≮0 : {n : Nat} → n < 0 → ⊥
n≮0 (diff k ())
lem-refute : ∀ n nf ρ → 0 ≡ ⟦ (suc n , []) ∷ nf ⟧ns (atomEnvS ρ) → ⊥
lem-refute n nf ρ eq = erase-⊥ $ 0≠suc (n + ⟦ nf ⟧n (atomEnvS ρ)) $
eq ⟨≡⟩ ns-sound ((suc n , []) ∷ nf) (atomEnvS ρ) ⟨≡⟩ auto
refutation-proof : ∀ {a} {A : Set a} eqn ρ → Maybe (⟦ eqn ⟧eqn ρ → A)
refutation-proof (a :≡ b) ρ with cancel (normSub a) (normSub b) | complicateSubEq a b ρ
refutation-proof (a :≡ b) ρ | [] , (suc n , []) ∷ v | compl = just λ eq → ⊥-elim $ lem-refute n v ρ (compl eq)
refutation-proof (a :≡ b) ρ | (suc n , []) ∷ v , [] | compl = just λ eq → ⊥-elim $ lem-refute n v ρ (sym (compl eq))
refutation-proof (a :≡ b) ρ | _ , _ | _ = nothing
refutation-proof (a :< b) ρ with cancel (normSub a) (normSub b) | complicateSubLess a b ρ
refutation-proof (a :< b) ρ | v , [] | compl = just λ eq → ⊥-elim $ erase-⊥ $ n≮0 (compl eq)
refutation-proof (a :< b) ρ | _ , _ | _ = nothing
-- Some trickery to make tactics call be erased
get-absurd-proof : ∀ {a} {A : Set a} (prf : Maybe (A → ⊥)) → QED {x = prf} → A → ⊥
get-absurd-proof = get-proof
get-refute-proof : ∀ {a b} {A : Set a} {B : Set b} (prf : Maybe (A → ⊥)) → QED {x = prf} → A → B
get-refute-proof eq x y = ⊥-elim (get-absurd-proof eq x y)
{-# INLINE get-refute-proof #-}
refutesub-tactic : Term → TC Term
refutesub-tactic prf =
inferNormalisedType prf >>= λ a →
caseM termToSubEqn a of λ
{ nothing → pure $ failedProof (quote invalidEquation) a
; (just (eqn , Γ)) → pure $
applyTerm (safe
(getProof (quote cantProve) a $
def (quote refutation-proof)
$ vArg (` eqn)
∷ vArg (quotedEnv Γ)
∷ []) _) (vArg prf ∷ [])
}
| {
"alphanum_fraction": 0.6285362854,
"avg_line_length": 33.875,
"ext": "agda",
"hexsha": "094950c5c0f14d612ee2e497a30086d728b81642",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Subtract/Refute.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Subtract/Refute.agda",
"max_line_length": 116,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Subtract/Refute.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 913,
"size": 2439
} |
{-# OPTIONS --allow-unsolved-metas #-}
module simple where
module Nat where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
module N = Nat
z = N._+_ (N.suc N.zero) (N.suc N.zero)
zz = Nat._+_ (Nat.suc Nat.zero) (Nat.suc Nat.zero)
module List (A : Set) where
infixr 15 _::_ _++_
data List : Set where
nil : List
_::_ : A -> List -> List
_++_ : List -> List -> List
nil ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
module TestList where
open Nat
module ListNat = List Nat
open ListNat using (_++_; _::_; nil)
zzz = (zero :: nil) ++ (suc zero :: nil)
module EvenOdd where
mutual
data Even : Set where
evenZero : Even
evenSuc : Odd -> Even
data Odd : Set where
oddSuc : Even -> Odd
module Monad where
data Monad (m : Set -> Set) : Set1 where
monad : ({a : Set} -> a -> m a) ->
({a b : Set} -> m a -> (a -> m b) -> m b) ->
Monad m
return : {m : Set -> Set} -> {a : Set} -> Monad m -> a -> m a
return (monad ret _) x = ret x
module Stack where
abstract
data Stack (A : Set) : Set where
snil : Stack A
scons : A -> Stack A -> Stack A
module Ops where
abstract
empty : {A : Set} -> Stack A
empty = snil
push : {A : Set} -> A -> Stack A -> Stack A
push x s = scons x s
unit : {A : Set} -> A -> Stack A
unit x = push x empty
module TestStack where
open Stack using (Stack)
open Stack.Ops
open Nat
zzzz : Stack Nat
zzzz = push zero (unit (suc zero))
module TestIdentity where
postulate
A : Set
idA : A -> A
F : Set -> Set
H : (A B : Set) -> Set
id0 : (A : Set) -> A -> A
idH : {A : Set} -> A -> A
fa : F A
a : A
test1 = id0 (F A) fa
test2 = idH fa
test3 = id0 _ fa
test4 = idH {! foo bar !}
-- test5 = id id -- we can't do this (on purpose)!
id = \{A : Set}(x : A) -> x
test = id a
module prop where
postulate
_\/_ : Set -> Set -> Set
inl : {P Q : Set} -> P -> P \/ Q
inr : {P Q : Set} -> Q -> P \/ Q
orE : {P Q R : Set} -> P \/ Q -> (P -> R) -> (Q -> R) -> R
False : Set
_==>_ : Set -> Set -> Set
impI : {P Q : Set} -> (P -> Q) -> P ==> Q
impE : {P Q : Set} -> P ==> Q -> P -> Q
Not = \(P : Set) -> P ==> False
notnotEM = \(P : Set) ->
impI (\ (nEM : Not (P \/ Not P)) ->
impE nEM (
inr (
impI (\ p ->
impE nEM (inl p)
)
)
)
)
module Tests where
infix 5 _==_
postulate
_==_ : {A : Set} -> A -> A -> Set
refl : {A : Set} -> {x : A} -> x == x
open TestList.ListNat
open Nat
test1 : TestList.zzz == zero :: suc zero :: nil
test1 = refl
| {
"alphanum_fraction": 0.4640614096,
"avg_line_length": 19.4965986395,
"ext": "agda",
"hexsha": "8f93e27030f6ac10da8b42b3dd524eaf5b89b130",
"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/simple.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/simple.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/Succeed/simple.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": 1005,
"size": 2866
} |
module Numeral.Natural.LinearSearch where
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.List
import Data.List.Functions as List
open import Data.List.Relation.Membership using (_∈_)
open import Data.List.Relation.Membership.Proofs
open import Data.List.Relation.Quantification
open import Data.List.Relation.Quantification.Proofs
open import Data.List.Sorting
open import Functional
open import Logic.Propositional
open import Numeral.Finite
import Numeral.Finite.LinearSearch as 𝕟
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Relation.Order
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function
private variable a b n i j : ℕ
private variable f : ℕ → Bool
{-
findBoundedMin : ℕ → ℕ → (ℕ → Bool) → Option(ℕ)
findBoundedMin a b f = Option.map 𝕟-to-ℕ (𝕟.findMin{b −₀ a}(f ∘ (_+ a) ∘ 𝕟-to-ℕ))
findBoundedMin-None-correctness : (a < b) → (findBoundedMin a b f ≡ None) ↔ (∀{i} → (a ≤ i) → (i < b) → IsFalse(f(i)))
findBoundedMin-None-correctness{a}{b}{f} ab
with [↔]-intro l r ← 𝕟.findMin-None-correctness{b −₀ a}{f ∘ (_+ a) ∘ 𝕟-to-ℕ}
= [↔]-intro (\p → congruence₁(Option.map 𝕟-to-ℕ) (l (\{i} → p ([≤]-of-[+]ᵣ {𝕟-to-ℕ i}) {![<]-with-[+]-weak ([∨]-introₗ ([∧]-intro ? ?))!}))) (\p{i} ai ib → {!r ? {?}!})
-}
findBoundedAll : ℕ → ℕ → (ℕ → Bool) → List(ℕ)
findBoundedAll a b f = List.map ((_+ a) ∘ 𝕟-to-ℕ) (𝕟.findAll{b −₀ a} (f ∘ (_+ a) ∘ 𝕟-to-ℕ))
findBoundedAll-correctness : AllElements(IsTrue ∘ f)(findBoundedAll a b f)
findBoundedAll-correctness {f} {a} {b} with 𝕟.findAll{b −₀ a} (f ∘ (_+ a) ∘ 𝕟-to-ℕ) | 𝕟.findAll-correctness{b −₀ a}{f ∘ (_+ a) ∘ 𝕟-to-ℕ}
... | ∅ | ∅ = ∅
... | _ ⊰ _ | p ⊰ ps = p ⊰ AllElements-mapᵣ ((_+ a) ∘ 𝕟-to-ℕ) id ps
postulate findBoundedAll-completeness : IsTrue(f(i)) → (a ≤ i) → (i < b) → (i ∈ findBoundedAll a b f)
-- findBoundedAll-completeness {f}{i}{a}{b} ai ib fi = {![∈]-map {f = 𝕟-to-ℕ} (𝕟.findAll-completeness{b −₀ a}{f ∘ (_+ a) ∘ 𝕟-to-ℕ}{ℕ-to-𝕟 (i −₀ a) ⦃ ? ⦄} ?)!}
postulate findBoundedAll-emptyness : (∀{i} → (a ≤ i) → (i < b) → IsFalse(f(i))) ↔ (findBoundedAll a b f ≡ ∅)
postulate findBoundedAll-sorted : Sorted(_≤?_)(findBoundedAll a b f)
postulate findBoundedAll-membership : (i ∈ findBoundedAll a b f) ↔ ((a ≤ i) ∧ (i < b) ∧ IsTrue(f(i)))
| {
"alphanum_fraction": 0.6506329114,
"avg_line_length": 43.8888888889,
"ext": "agda",
"hexsha": "3d7ae9d208b14f15a1346d65bf3cff1ebda6153e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/LinearSearch.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/LinearSearch.agda",
"max_line_length": 170,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/LinearSearch.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": 938,
"size": 2370
} |
{-# OPTIONS --allow-unsolved-metas #-}
record R : Set₁ where
field
A : Set
f : A → A
record Double {a} (A : Set a) : Set a where
field
double : A → A
open Double {{...}}
-- Type error (incomplete patterns in Patterns.Match)
doubleR : Double R
R.A (double {{doubleR}} x) = R.A x
R.f (double {{doubleR}} x) z = R.f x (R.f x z)
-- Internal error (incomplete patterns in Reduce.Fast)
doubleR₁ : Double R
R.A (double {{doubleR₁}} x) = R.A x
R.f (double {{doubleR₁}} x) z = {!R.f x (R.f x z)!}
| {
"alphanum_fraction": 0.5945419103,
"avg_line_length": 22.3043478261,
"ext": "agda",
"hexsha": "c261d73e20ec7c17fed2358f9d98ba74de788d57",
"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/Issue2265.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/Issue2265.agda",
"max_line_length": 54,
"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/Issue2265.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 177,
"size": 513
} |
{-
This files contains:
- Facts about constructions on finite sets, especially when they preserve finiteness.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet.Constructors where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_)
open import Cubical.Foundations.Univalence
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.Data.Nat
open import Cubical.Data.Unit
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.Fin.LehmerCode as LehmerCode
open import Cubical.Data.SumFin
open import Cubical.Data.FinSet.Base
open import Cubical.Data.FinSet.Properties
open import Cubical.Data.FinSet.FiniteChoice
open import Cubical.Relation.Nullary
open import Cubical.Functions.Fibration
open import Cubical.Functions.Embedding
open import Cubical.Functions.Surjection
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
module _
(X : Type ℓ)(p : isFinOrd X) where
isFinOrd∥∥ : isFinOrd ∥ X ∥
isFinOrd∥∥ = _ , propTrunc≃ (p .snd) ⋆ SumFin∥∥≃ _
isFinOrd≃ : isFinOrd (X ≃ X)
isFinOrd≃ = _ , equivComp (p .snd) (p .snd) ⋆ SumFin≃≃ _
module _
(X : Type ℓ )(p : isFinOrd X)
(Y : Type ℓ')(q : isFinOrd Y) where
isFinOrd⊎ : isFinOrd (X ⊎ Y)
isFinOrd⊎ = _ , ⊎-equiv (p .snd) (q .snd) ⋆ SumFin⊎≃ _ _
isFinOrd× : isFinOrd (X × Y)
isFinOrd× = _ , Σ-cong-equiv (p .snd) (λ _ → q .snd) ⋆ SumFin×≃ _ _
module _
(X : Type ℓ )(p : isFinOrd X)
(Y : X → Type ℓ')(q : (x : X) → isFinOrd (Y x)) where
private
e = p .snd
f : (x : X) → ℕ
f x = q x .fst
isFinOrdΣ : isFinOrd (Σ X Y)
isFinOrdΣ = _ ,
Σ-cong-equiv {B' = λ x → Y (invEq e x)} e (transpFamily p)
⋆ Σ-cong-equiv-snd (λ x → q (invEq e x) .snd)
⋆ SumFinΣ≃ _ _
isFinOrdΠ : isFinOrd ((x : X) → Y x)
isFinOrdΠ = _ ,
equivΠ {B' = λ x → Y (invEq e x)} e (transpFamily p)
⋆ equivΠCod (λ x → q (invEq e x) .snd)
⋆ SumFinΠ≃ _ _
-- closedness under several type constructors
module _
(X : FinSet ℓ)
(Y : X .fst → FinSet ℓ') where
isFinSetΣ : isFinSet (Σ (X .fst) (λ x → Y x .fst))
isFinSetΣ = rec2 isPropIsFinSet
(λ p q → isFinOrd→isFinSet (isFinOrdΣ (X .fst) (_ , p) (λ x → Y x .fst) q))
(X .snd .snd) (choice X (λ x → isFinOrd (Y x .fst)) (λ x → isFinSet→isFinSet' (Y x .snd)))
isFinSetΠ : isFinSet ((x : X .fst) → Y x .fst)
isFinSetΠ = rec2 isPropIsFinSet
(λ p q → isFinOrd→isFinSet (isFinOrdΠ (X .fst) (_ , p) (λ x → Y x .fst) q))
(X .snd .snd) (choice X (λ x → isFinOrd (Y x .fst)) (λ x → isFinSet→isFinSet' (Y x .snd)))
module _
(X : FinSet ℓ)
(Y : X .fst → FinSet ℓ')
(Z : (x : X .fst) → Y x .fst → FinSet ℓ'') where
isFinSetΠ2 : isFinSet ((x : X .fst) → (y : Y x .fst) → Z x y .fst)
isFinSetΠ2 = isFinSetΠ X (λ x → _ , isFinSetΠ (Y x) (Z x))
module _
(X : FinSet ℓ)
(Y : X .fst → FinSet ℓ')
(Z : (x : X .fst) → Y x .fst → FinSet ℓ'')
(W : (x : X .fst) → (y : Y x .fst) → Z x y .fst → FinSet ℓ''') where
isFinSetΠ3 : isFinSet ((x : X .fst) → (y : Y x .fst) → (z : Z x y .fst) → W x y z .fst)
isFinSetΠ3 = isFinSetΠ X (λ x → _ , isFinSetΠ2 (Y x) (Z x) (W x))
module _
(X : FinSet ℓ) where
isFinSet≡ : (a b : X .fst) → isFinSet (a ≡ b)
isFinSet≡ a b = isDecProp→isFinSet (isFinSet→isSet (X .snd) a b) (isFinSet→Discrete (X .snd) a b)
isFinSet∥∥ : isFinSet ∥ X .fst ∥
isFinSet∥∥ = Prop.rec isPropIsFinSet (λ p → isFinOrd→isFinSet (isFinOrd∥∥ (X .fst) (_ , p))) (X .snd .snd)
isFinSetIsContr : isFinSet (isContr (X .fst))
isFinSetIsContr = isFinSetΣ X (λ x → _ , (isFinSetΠ X (λ y → _ , isFinSet≡ x y)))
isFinSetIsProp : isFinSet (isProp (X .fst))
isFinSetIsProp = isFinSetΠ2 X (λ _ → X) (λ x x' → _ , isFinSet≡ x x')
module _
(X : FinSet ℓ )
(Y : FinSet ℓ')
(f : X .fst → Y .fst) where
isFinSetFiber : (y : Y .fst) → isFinSet (fiber f y)
isFinSetFiber y = isFinSetΣ X (λ x → _ , isFinSet≡ Y (f x) y)
isFinSetIsEquiv : isFinSet (isEquiv f)
isFinSetIsEquiv =
EquivPresIsFinSet
(invEquiv (isEquiv≃isEquiv' f))
(isFinSetΠ Y (λ y → _ , isFinSetIsContr (_ , isFinSetFiber y)))
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
isFinSet⊎ : isFinSet (X .fst ⊎ Y .fst)
isFinSet⊎ = card X + card Y ,
map2 (λ p q → isFinOrd⊎ (X .fst) (_ , p) (Y .fst) (_ , q) .snd) (X .snd .snd) (Y .snd .snd)
isFinSet× : isFinSet (X .fst × Y .fst)
isFinSet× = card X · card Y ,
map2 (λ p q → isFinOrd× (X .fst) (_ , p) (Y .fst) (_ , q) .snd) (X .snd .snd) (Y .snd .snd)
isFinSet→ : isFinSet (X .fst → Y .fst)
isFinSet→ = isFinSetΠ X (λ _ → Y)
isFinSet≃ : isFinSet (X .fst ≃ Y .fst)
isFinSet≃ = isFinSetΣ (_ , isFinSet→) (λ f → _ , isFinSetIsEquiv X Y f)
module _
(X Y : FinSet ℓ ) where
isFinSetType≡ : isFinSet (X .fst ≡ Y .fst)
isFinSetType≡ = EquivPresIsFinSet (invEquiv univalence) (isFinSet≃ X Y)
module _
(X : FinSet ℓ) where
isFinSetAut : isFinSet (X .fst ≃ X .fst)
isFinSetAut = LehmerCode.factorial (card X) ,
Prop.map (λ p → isFinOrd≃ (X .fst) (card X , p) .snd) (X .snd .snd)
isFinSetTypeAut : isFinSet (X .fst ≡ X .fst)
isFinSetTypeAut = EquivPresIsFinSet (invEquiv univalence) isFinSetAut
module _
(X : FinSet ℓ) where
isFinSet¬ : isFinSet (¬ (X .fst))
isFinSet¬ = isFinSet→ X (Fin 0 , isFinSetFin)
module _
(X : FinSet ℓ) where
isFinSetNonEmpty : isFinSet (NonEmpty (X .fst))
isFinSetNonEmpty = isFinSet¬ (_ , isFinSet¬ X)
module _
(X : FinSet ℓ )
(Y : FinSet ℓ')
(f : X .fst → Y .fst) where
isFinSetIsEmbedding : isFinSet (isEmbedding f)
isFinSetIsEmbedding =
isFinSetΠ2 X (λ _ → X)
(λ a b → _ , isFinSetIsEquiv (_ , isFinSet≡ X a b) (_ , isFinSet≡ Y (f a) (f b)) (cong f))
isFinSetIsSurjection : isFinSet (isSurjection f)
isFinSetIsSurjection =
isFinSetΠ Y (λ y → _ , isFinSet∥∥ (_ , isFinSetFiber X Y f y))
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
isFinSet↪ : isFinSet (X .fst ↪ Y .fst)
isFinSet↪ = isFinSetΣ (_ , isFinSet→ X Y) (λ f → _ , isFinSetIsEmbedding X Y f)
isFinSet↠ : isFinSet (X .fst ↠ Y .fst)
isFinSet↠ = isFinSetΣ (_ , isFinSet→ X Y) (λ f → _ , isFinSetIsSurjection X Y f)
-- a criterion of being finite set
module _
(X : Type ℓ)(Y : FinSet ℓ')
(f : X → Y .fst)
(h : (y : Y .fst) → isFinSet (fiber f y)) where
isFinSetTotal : isFinSet X
isFinSetTotal = EquivPresIsFinSet (invEquiv (totalEquiv f)) (isFinSetΣ Y (λ y → _ , h y))
-- a criterion of fibers being finite sets, more general than the previous result
module _
(X : FinSet ℓ)
(Y : Type ℓ')(h : Discrete Y)
(f : X. fst → Y) where
isFinSetFiberDisc : (y : Y) → isFinSet (fiber f y)
isFinSetFiberDisc y = isFinSetΣ X (λ x → _ , isDecProp→isFinSet (Discrete→isSet h _ _) (h (f x) y))
| {
"alphanum_fraction": 0.6183340679,
"avg_line_length": 29.3405172414,
"ext": "agda",
"hexsha": "332138f50a35a66c583e00cf1c076148bbb1e029",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Data/FinSet/Constructors.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Data/FinSet/Constructors.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Data/FinSet/Constructors.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2858,
"size": 6807
} |
module Prelude.Int where
open import Prelude.Unit
open import Prelude.Empty
open import Prelude.Nat
open import Prelude.Number
open import Prelude.String
open import Prelude.Semiring
open import Prelude.Equality
open import Prelude.Equality.Inspect
open import Prelude.Equality.Unsafe using (eraseEquality)
open import Prelude.Ord
open import Prelude.Decidable
open import Prelude.Function
open import Prelude.Nat.Properties
open import Prelude.Int.Properties
open import Prelude.Int.Core public
open import Agda.Builtin.Int public
private
subInt-cancel-r : (a b c : Int) → a - b ≡ c → c + b ≡ a
subInt-cancel-r a b c refl =
addInt-assoc a (negate b) b ʳ⟨≡⟩
a +_ $≡ (addInt-commute (negate b) b ⟨≡⟩ subInt-equal b _ refl) ⟨≡⟩
addInt-zero-r a
lem-equal : (a b : Int) → a - b ≡ 0 → a ≡ b
lem-equal a b eq = subInt-cancel-r a b 0 eq ʳ⟨≡⟩ addInt-zero-l b
lem-less : (a b c : Int) → a - b ≡ c → negate c + a ≡ b
lem-less a b c eq = subInt-cancel-r b a (negate c) (negate-subInt a b ʳ⟨≡⟩ negate $≡ eq)
-- Eq --
instance
EqInt : Eq Int
Eq._==_ EqInt = eqInt
where
eqInt : (a b : Int) → Dec (a ≡ b)
eqInt a b with inspect (a - b)
eqInt a b | pos zero with≡ eq = yes (lem-equal a b eq)
eqInt a b | pos (suc n) with≡ eq = no λ a=b → case subInt-equal _ _ a=b ʳ⟨≡⟩ eq of λ ()
eqInt a b | negsuc n with≡ eq = no λ a=b → case subInt-equal _ _ a=b ʳ⟨≡⟩ eq of λ ()
-- Ord --
data LessInt (a b : Int) : Set where
diff : (k : Nat) (eq : b ≡ pos (suc k) + a) → LessInt a b
compareInt : (a b : Int) → Comparison LessInt a b
compareInt a b with inspect (a - b)
compareInt a b | pos zero with≡ eq = equal (eraseEquality (lem-equal a b eq))
compareInt a b | c@(pos (suc k)) with≡ eq = greater (diff k (eraseEquality (sym (subInt-cancel-r a b c eq))))
compareInt a b | c@(negsuc k) with≡ eq = less (diff k (eraseEquality (sym (lem-less a b c eq))))
{-# INLINE compareInt #-}
private
from-eq : ∀ x y → x ≡ y → LessInt x (1 + y)
from-eq x y eq = diff 0 (eraseEquality (1 +_ $≡ sym eq))
from-lt : ∀ x y → LessInt x y → LessInt x (1 + y)
from-lt (pos n) _ (diff k eq) = diff (suc k) (eraseEquality (1 +_ $≡ eq))
from-lt (negsuc n) _ (diff k eq) = diff (suc k) (eraseEquality (
1 +_ $≡ eq ⟨≡⟩ addInt-pos 1 (suc k -NZ suc n) ⟨≡⟩ʳ
-NZ-suc-l (suc k) (suc n)))
from-leq : ∀ x y → LessInt x (1 + y) → LessEq LessInt x y
from-leq x y (diff zero eq) = equal (eraseEquality (addInt-inj₂ 1 x y (sym eq)))
from-leq x y (diff (suc k) eq) =
less (diff k (eraseEquality (sucInt-inj y (_+_ (pos (suc k)) x)
(addInt-pos 1 y ʳ⟨≡⟩ eq ⟨≡⟩ addInt-sucInt-l (pos (suc k)) x))))
instance
OrdInt : Ord Int
Ord._<_ OrdInt = _
Ord._≤_ OrdInt a b = LessInt a (1 + b)
Ord.compare OrdInt = compareInt
Ord.eq-to-leq OrdInt = from-eq _ _
Ord.lt-to-leq OrdInt = from-lt _ _
Ord.leq-to-lteq OrdInt = from-leq _ _
-- Ord/Laws --
private
lessInt-antirefl : (a : Int) → a < a → ⊥
lessInt-antirefl a (diff k eq) = case addInt-inj₁ 0 (pos (suc k)) a (addInt-zero-l a ⟨≡⟩ eq) of λ ()
lessInt-antisym : (a b : Int) → a < b → b < a → ⊥
lessInt-antisym a b (diff k refl) (diff j eq) =
case addInt-inj₁ 0 (pos (suc j) + pos (suc k)) a
(addInt-zero-l a ⟨≡⟩ eq ⟨≡⟩ addInt-assoc (pos (suc j)) (pos (suc k)) a)
of λ ()
lessInt-trans : {a b c : Int} → a < b → b < c → a < c
lessInt-trans {a} (diff k eq) (diff j eq₁) = diff (j + suc k) (eraseEquality $
case eq of λ where
refl → case eq₁ of λ where
refl → addInt-assoc (pos (suc j)) (pos (suc k)) a)
instance
OrdIntLaws : Ord/Laws Int
Ord/Laws.super OrdIntLaws = it
less-antirefl {{OrdIntLaws}} = lessInt-antirefl _
less-trans {{OrdIntLaws}} = lessInt-trans
| {
"alphanum_fraction": 0.6002624672,
"avg_line_length": 35.2777777778,
"ext": "agda",
"hexsha": "3571d6f842e57bd5b128b27646312fb3cbf43a22",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Prelude/Int.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Prelude/Int.agda",
"max_line_length": 109,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Prelude/Int.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": 1422,
"size": 3810
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Lattice where
open import Cubical.Algebra.Lattice.Base public
open import Cubical.Algebra.Lattice.Properties public
| {
"alphanum_fraction": 0.8036809816,
"avg_line_length": 27.1666666667,
"ext": "agda",
"hexsha": "2abec7db01686ce5bed4c913ad1c24c5c2b91fbf",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Algebra/Lattice.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Algebra/Lattice.agda",
"max_line_length": 53,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Algebra/Lattice.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 36,
"size": 163
} |
{-# OPTIONS --without-K #-}
module algebra.semigroup.morphism where
open import level
open import algebra.semigroup.core
open import equality.core
open import hott.level
module _ {i}{j}
{X : Set i}⦃ sX : IsSemigroup X ⦄
{Y : Set j}⦃ sY : IsSemigroup Y ⦄ where
open IsSemigroup ⦃ ... ⦄
IsSemigroupMorphism : (X → Y) → Set (i ⊔ j)
IsSemigroupMorphism f = (x₁ x₂ : X) → f (x₁ * x₂) ≡ f x₁ * f x₂
is-semigroup-morphism-level : (f : X → Y) → h 1 (IsSemigroupMorphism f)
is-semigroup-morphism-level f = Π-level λ x₁ → Π-level λ x₂ → is-set _ _
| {
"alphanum_fraction": 0.6374781086,
"avg_line_length": 30.0526315789,
"ext": "agda",
"hexsha": "cca55b69ac8296cdd79b579ca33e400fe92c8dec",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/algebra/semigroup/morphism.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/algebra/semigroup/morphism.agda",
"max_line_length": 74,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/algebra/semigroup/morphism.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 208,
"size": 571
} |
{-# OPTIONS --safe #-}
{-
Constructions of "sets" in the cumulative hierarchy. Including:
- the empty set
- unions
- ω
- replacement
- separation
-}
module Cubical.HITs.CumulativeHierarchy.Constructions where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Structure
open import Cubical.Functions.Embedding
open import Cubical.Functions.Logic as L
open import Cubical.Data.Sum hiding (elim)
open import Cubical.Data.Sigma
open import Cubical.Data.Nat hiding (elim)
open import Cubical.Data.Sum as ⊎ using (_⊎_)
open import Cubical.Data.Bool
open import Cubical.Data.Unit
open import Cubical.Data.Empty as E hiding (elim)
open import Cubical.HITs.PropositionalTruncation as P hiding (elim; elim2)
open import Cubical.HITs.CumulativeHierarchy.Base
open import Cubical.HITs.CumulativeHierarchy.Properties
import Cubical.HITs.PropositionalTruncation.Monad as PropMonad
private
variable
ℓ ℓ' : Level
------------
-- Structures for building specific sets by giving encodings and decodings for their membership
-----------
record SetStructure ℓ : Type (ℓ-suc ℓ) where
field
X : Type ℓ
ix : X → V ℓ
resSet : V ℓ
resSet = sett X ix
record SetPackage ℓ ℓ' : Type (ℓ-max (ℓ-suc ℓ) (ℓ-suc ℓ')) where
field
structure : SetStructure ℓ
open SetStructure structure hiding (resSet)
open SetStructure structure using (resSet) public
field
∈-rep : V ℓ → hProp ℓ'
unpack : (x : X) → ⟨ ∈-rep (ix x) ⟩
repack : {y : V ℓ} → ⟨ ∈-rep y ⟩ → ∥ fiber ix y ∥₁
open PropMonad
classification : ⟨ ∀[ y ] (y ∈ₛ resSet ⇔ ∈-rep y) ⟩
classification y = intoClassifier , fromClassifier where
intoClassifier : ⟨ y ∈ₛ resSet ⟩ → ⟨ ∈-rep y ⟩
intoClassifier (yi , yr) = proof (∈-rep y) by do
(x , ix) ← ∈∈ₛ {b = resSet} .snd (yi , yr)
return (subst (fst ∘ ∈-rep) ix (unpack x))
fromClassifier : ⟨ ∈-rep y ⟩ → ⟨ y ∈ₛ resSet ⟩
fromClassifier yr = ∈∈ₛ {b = resSet} .fst (repack {y = y} yr)
------------
-- Specific constructions
-----------
open SetPackage using (structure; ∈-rep; unpack; repack)
module EmptySet where
EmptyStructure : SetStructure ℓ
SetStructure.X EmptyStructure = Lift E.⊥
SetStructure.ix EmptyStructure ()
EmptyPackage : SetPackage ℓ ℓ-zero
structure EmptyPackage = EmptyStructure
∈-rep EmptyPackage _ = L.⊥
unpack EmptyPackage ()
repack EmptyPackage ()
∅ : V ℓ
∅ = SetStructure.resSet EmptyStructure
∅-empty : ⟨ ∀[ b ∶ V ℓ ] ¬ (b ∈ₛ ∅) ⟩
∅-empty b = SetPackage.classification EmptyPackage b .fst
open EmptySet using (∅; ∅-empty) public
module UnionSet (S : V ℓ) where
UnionStructure : SetStructure ℓ
SetStructure.X UnionStructure = Σ[ r ∈ ⟪ S ⟫ ] ⟪ ⟪ S ⟫↪ r ⟫
SetStructure.ix UnionStructure (r , i) = ⟪ ⟪ S ⟫↪ r ⟫↪ i
UNION : V ℓ
UNION = SetStructure.resSet UnionStructure
UnionPackage : SetPackage _ (ℓ-suc ℓ)
structure UnionPackage = UnionStructure
∈-rep UnionPackage y = ∃[ v ] (v ∈ₛ S) ⊓ (y ∈ₛ v)
unpack UnionPackage (vi , yi) = ∣ ⟪ S ⟫↪ vi , ∈ₛ⟪ S ⟫↪ vi , ∈ₛ⟪ ⟪ S ⟫↪ vi ⟫↪ yi ∣₁
repack UnionPackage {y = y} = P.rec squash₁ go where
go : Σ[ v ∈ V _ ] ⟨ v ∈ₛ S ⟩ ⊓′ ⟨ y ∈ₛ v ⟩ → ∥ fiber _ y ∥₁
go (v , (vi , vS) , xv) = ∣ repFiber≃fiber _ _ .fst ((vi , key .fst) , key .snd) ∣₁ where
path : v ≡ ⟪ S ⟫↪ vi
path = sym (equivFun identityPrinciple vS)
key : Σ[ i ∈ ⟪ ⟪ S ⟫↪ vi ⟫ ] ⟪ ⟪ S ⟫↪ vi ⟫↪ i ≊ y
key = subst (λ v → Σ[ ix ∈ ⟪ v ⟫ ] ⟪ v ⟫↪ ix ≊ y) path xv
union-ax : ⟨ ∀[ u ] (u ∈ₛ UNION ⇔ (∃[ v ] (v ∈ₛ S) ⊓ (u ∈ₛ v))) ⟩
union-ax = classification where
open SetPackage UnionPackage using (classification)
open UnionSet renaming (UNION to infixr 9 ⋃_) using (union-ax) public
module PairingSet (a b : V ℓ) where
PairingStructure : SetStructure ℓ
SetStructure.X PairingStructure = Lift Bool
SetStructure.ix PairingStructure (lift false) = a
SetStructure.ix PairingStructure (lift true) = b
open PropMonad
PairingPackage : SetPackage _ (ℓ-suc ℓ)
structure PairingPackage = PairingStructure
∈-rep PairingPackage d = (d ≡ₕ a) ⊔ (d ≡ₕ b)
unpack PairingPackage (lift false) = L.inl refl
unpack PairingPackage (lift true) = L.inr refl
repack PairingPackage {y = y} = _>>= λ where
(_⊎_.inl ya) → ∣ lift false , sym ya ∣₁
(_⊎_.inr yb) → ∣ lift true , sym yb ∣₁
PAIR : V ℓ
PAIR = SetStructure.resSet PairingStructure
pairing-ax : ⟨ ∀[ d ] (d ∈ₛ PAIR ⇔ (d ≡ₕ a) ⊔ (d ≡ₕ b)) ⟩
pairing-ax = classification where
open SetPackage PairingPackage using (classification)
-- pairing TODO: notation?
open PairingSet renaming (PAIR to infix 12 ⁅_,_⁆) using (pairing-ax) public
module SingletonSet (a : V ℓ) where
SingletonStructure : SetStructure ℓ
SetStructure.X SingletonStructure = Lift Unit
SetStructure.ix SingletonStructure (lift tt) = a
SingletonPackage : SetPackage _ (ℓ-suc ℓ)
structure SingletonPackage = SingletonStructure
∈-rep SingletonPackage d = d ≡ₕ a
unpack SingletonPackage _ = refl
repack SingletonPackage ya = ∣ lift tt , sym ya ∣₁
SINGL : V ℓ
SINGL = SetStructure.resSet SingletonStructure
open SingletonSet renaming (SINGL to infix 10 ⁅_⁆s) public
-- small unions
_∪_ : (a b : V ℓ) → V ℓ
a ∪ b = ⋃ ⁅ a , b ⁆
module InfinitySet {ℓ} where
sucV : V ℓ → V ℓ
sucV N = N ∪ ⁅ N ⁆s
#_ : ℕ → V ℓ
# zero = ∅
# suc n = sucV (# n)
ωStructure : SetStructure ℓ
SetStructure.X ωStructure = Lift ℕ
SetStructure.ix ωStructure = #_ ∘ lower
ω : V ℓ
ω = SetStructure.resSet ωStructure
open PropMonad
ωPackage : SetPackage _ (ℓ-suc ℓ)
structure ωPackage = ωStructure
∈-rep ωPackage d = (d ≡ₕ ∅) ⊔ (∃[ v ] (d ≡ₕ sucV v) ⊓ (v ∈ₛ ω))
unpack ωPackage (lift zero) = L.inl refl
unpack ωPackage (lift (suc n)) = L.inr ∣ # n , refl , ∈∈ₛ {b = ω} .fst ∣ lift n , refl ∣₁ ∣₁
repack ωPackage {y = y} = ⊔-elim (y ≡ₕ ∅) ∥ _ ∥ₚ (λ _ → ∥ fiber _ y ∥ₚ)
(λ e → ∣ lift zero , sym e ∣₁)
(λ m → do (v , yv , vr) ← m
(lift n , eq) ← ∈∈ₛ {b = ω} .snd vr
∣ lift (suc n) , sym (subst (λ v → y ≡ (v ∪ ⁅ v ⁆s)) (sym eq) yv) ∣₁
)
infinity-ax : ⟨ ∀[ y ] (y ∈ₛ ω ⇔ (y ≡ₕ ∅) ⊔ (∃[ v ] (y ≡ₕ sucV v) ⊓ (v ∈ₛ ω))) ⟩
infinity-ax = classification where
open SetPackage ωPackage using (classification)
ω-empty : ⟨ ∅ ∈ₛ ω ⟩
ω-empty = infinity-ax ∅ .snd (L.inl refl)
ω-next : ⟨ ∀[ x ∶ V ℓ ] x ∈ₛ ω ⇒ sucV x ∈ₛ ω ⟩
ω-next x x∈ω = infinity-ax (sucV x) .snd (L.inr ∣ x , refl , x∈ω ∣₁)
#-in-ω : ∀ n → ⟨ # n ∈ₛ ω ⟩
#-in-ω zero = ω-empty
#-in-ω (suc n) = ω-next (# n) (#-in-ω n)
open InfinitySet using (ω; ω-empty; ω-next; infinity-ax) public
module ReplacementSet (r : V ℓ → V ℓ) (a : V ℓ) where
ReplacementStructure : SetStructure ℓ
SetStructure.X ReplacementStructure = ⟪ a ⟫
SetStructure.ix ReplacementStructure = r ∘ ⟪ a ⟫↪
REPLACED : V ℓ
REPLACED = SetStructure.resSet ReplacementStructure
open PropMonad
ReplacementPackage : SetPackage _ (ℓ-suc ℓ)
structure ReplacementPackage = ReplacementStructure
∈-rep ReplacementPackage y = ∃[ z ] (z ∈ₛ a) ⊓ (y ≡ₕ r z)
unpack ReplacementPackage ⟪a⟫ = ∣ ⟪ a ⟫↪ ⟪a⟫ , (∈ₛ⟪ a ⟫↪ ⟪a⟫) , refl ∣₁
repack ReplacementPackage {y = y} m = do
(z , (a , za) , yr) ← m
∣ a , cong r (equivFun identityPrinciple za) ∙ sym yr ∣₁
replacement-ax : ⟨ ∀[ y ] (y ∈ₛ REPLACED ⇔ (∃[ z ] (z ∈ₛ a) ⊓ (y ≡ₕ r z))) ⟩
replacement-ax y = classification y where
open SetPackage ReplacementPackage using (classification)
open ReplacementSet renaming (REPLACED to infix 12 ⁅_∣_⁆) using (replacement-ax) public
module SeparationSet (a : V ℓ) (ϕ : V ℓ → hProp ℓ) where
SeparationStructure : SetStructure ℓ
SetStructure.X SeparationStructure = Σ[ x ∈ ⟪ a ⟫ ] ⟨ ϕ (⟪ a ⟫↪ x) ⟩
SetStructure.ix SeparationStructure = ⟪ a ⟫↪ ∘ fst
SeparationPackage : SetPackage _ ℓ
structure SeparationPackage = SeparationStructure
∈-rep SeparationPackage y = (y ∈ₛ a) ⊓ ϕ y
unpack SeparationPackage (⟪a⟫ , phi) = (∈ₛ⟪ a ⟫↪ ⟪a⟫) , phi
repack SeparationPackage ((⟪a⟫ , ya) , phi) =
∣ (⟪a⟫ , subst (fst ∘ ϕ) (sym (equivFun identityPrinciple ya)) phi)
, equivFun identityPrinciple ya ∣₁
SEPAREE : V ℓ
SEPAREE = SetStructure.resSet SeparationStructure
separation-ax : ⟨ ∀[ y ] (y ∈ₛ SEPAREE ⇔ (y ∈ₛ a) ⊓ ϕ y) ⟩
separation-ax y = classification y .fst , classification y .snd where
open SetPackage SeparationPackage using (classification)
open SeparationSet renaming (SEPAREE to infix 12 ⁅_∶_⁆) using (separation-ax) public
module Examples where
open InfinitySet
the1 : V ℓ-zero
the1 = # 1
1-ok? : ∥ Bool ∥₁
1-ok? = do
prf ← infinity-ax the1 .fst (#-in-ω 1)
case prf of λ { (⊎.inl _) → ∣ false ∣₁ ; (⊎.inr _) → ∣ true ∣₁ }
where
open PropMonad
test : 1-ok? ≡ ∣ true ∣₁
test = refl
| {
"alphanum_fraction": 0.63875,
"avg_line_length": 33.7164750958,
"ext": "agda",
"hexsha": "03336f5c7ae2a4497838751f1e92acea892a6d8a",
"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": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/HITs/CumulativeHierarchy/Constructions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"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": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/HITs/CumulativeHierarchy/Constructions.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/HITs/CumulativeHierarchy/Constructions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 3316,
"size": 8800
} |
module A1 where
open import Data.Empty using (⊥)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; subst)
open import Data.Unit using (⊤; tt)
open import Data.Bool using (Bool; false; true; _xor_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; Σ; Σ-syntax)
open import Data.Nat using (ℕ; suc; _+_; _*_)
open import Data.List using (List; []; _++_)
open import Data.Vec using (Vec; []; _∷_) renaming (_++_ to _++V_)
------------------------------------------------------------------------------
-- Ch. 1
-- Theme: for each type, recursion principle and induction principle
------------------------------------------------------------------------------
-- Sec. 1.9
-- ℕ
recℕ : ∀ {ℓ} → (C : Set ℓ) → C → (ℕ → C → C) → ℕ → C
recℕ C z f 0 = z
recℕ C z f (suc n) = f n (recℕ C z f n)
indℕ : ∀ {ℓ} → (C : ℕ → Set ℓ) → C 0 → ((n : ℕ) → C n → C (suc n)) → (n : ℕ) → C n
indℕ C z f 0 = z
indℕ C z f (suc n) = f n (indℕ C z f n)
-- Many examples in L.agda
------------------------------------------------------------------------------
-- Sec. 1.7
-- Empty type
-- Ex falso quodlibet
rec⊥ : ∀ {ℓ} → (C : Set ℓ) → ⊥ → C
rec⊥ C ()
ind⊥ : ∀ {ℓ} → (C : ⊥ → Set ℓ) → (v : ⊥) → C v
ind⊥ C ()
-- Examples
⊥→1≡2 : ⊥ → (1 ≡ 2)
⊥→1≡2 = rec⊥ (1 ≡ 2)
⊥→⊤≡⊥ : ⊥ → ⊤
⊥→⊤≡⊥ = rec⊥ ⊤
⊥→⊤≡⊥' : ⊥ → ⊤
⊥→⊤≡⊥' = ind⊥ (λ v → ⊤)
------------------------------------------------------------------------------
-- Sec. 1.5
-- Unit type
rec⊤ : ∀ {ℓ} → (C : Set ℓ) → C → ⊤ → C
rec⊤ C c tt = c
ind⊤ : ∀ {ℓ} → (C : ⊤ → Set ℓ) → C tt → (u : ⊤) → C u
ind⊤ C c tt = c
-- Example
singleton⊤ : (u : ⊤) → (u ≡ tt)
singleton⊤ = ind⊤ (λ u → u ≡ tt) refl
------------------------------------------------------------------------------
-- Sec. 1.8
-- Booleans
recBool : ∀ {ℓ} → (C : Set ℓ) → C → C → Bool → C
recBool C el th false = el
recBool C el th true = th
indBool : ∀ {ℓ} → (C : Bool → Set ℓ) → C false → C true → (b : Bool) → C b
indBool C el th false = el
indBool C el th true = th
-- Example
bool2 : (b : Bool) → (b ≡ false) ⊎ (b ≡ true)
bool2 = indBool
(λ b → (b ≡ false) ⊎ (b ≡ true))
(inj₁ refl)
(inj₂ refl)
------------------------------------------------------------------------------
-- Sec. 1.5
-- Product types
rec× : ∀ {ℓ₁ ℓ₂ ℓ₃} → {A : Set ℓ₁} {B : Set ℓ₂} →
(C : Set ℓ₃) → (A → B → C) → A × B → C
rec× C g (a , b) = g a b
ind× : ∀ {ℓ₁ ℓ₂ ℓ₃} → {A : Set ℓ₁} {B : Set ℓ₂} → (C : A × B → Set ℓ₃) →
((a : A) → (b : B) → C (a , b)) → (p : A × B) → C p
ind× C g ( a , b ) = g a b
-- Examples
fst : {A B : Set} → A × B → A
fst {A} {B} = rec× A (λ a b → a)
snd : {A B : Set} → A × B → B
snd {A} {B} = rec× B (λ a b → b)
surj-pair : ∀ {A B} → (p : A × B) → (fst p , snd p) ≡ p
surj-pair = ind×
(λ p → (fst p , snd p) ≡ p)
(λ a b → refl)
-- IMPORTANT:
--
-- TO PROVE ANY PROPERTY OF SOMETHING OF TYPE A × B, IT IS SUFFICIENT
-- TO PROVE IT FOR CANONICAL VALUES OF THAT TYPE, i.e. FOR (a , b)
--
_Product_ : (A : Set) → (B : Set) → Set
A Product B = (z : Bool) → recBool Set A B z
pair : {A B : Set} → A → B → A Product B
pair {A} {B} a b = indBool (λ z → recBool Set A B z) a b
------------------------------------------------------------------------------
-- Sigma types (dependent pair type)
recΣ : ∀ {ℓ₁ ℓ₂ ℓ₃} → {A : Set ℓ₁} {B : A → Set ℓ₂} → (C : Set ℓ₃) →
((a : A) → B a → C) → Σ A B → C
recΣ C g (a , b) = g a b
indΣ : ∀ {ℓ₁ ℓ₂ ℓ₃} → {A : Set ℓ₁} {B : A → Set ℓ₂} → (C : Σ A B → Set ℓ₃) →
((a : A) → (b : B a) → C (a , b)) → (p : Σ A B) → C p
indΣ C g ( a , b ) = g a b
-- Examples
dfst : {A : Set} {B : A → Set} → Σ A B → A
dfst {A} {B} = recΣ A (λ a b → a)
dsnd : {A : Set} {B : A → Set} → (p : Σ A B) → B (dfst p)
dsnd {A} {B} = indΣ
(λ p → B (dfst p))
(λ a b → b)
ac : {A B : Set} {R : A → B → Set} →
((x : A) → (Σ[ y ∈ B ] (R x y))) →
(Σ[ f ∈ (A → B) ] ((x : A) → R x (f x)))
ac g = (λ x → dfst (g x)) , (λ x → dsnd (g x))
{-- In English :-)
If for all x, exists y, such that x R y, then
exists f such that for all x, x R f(x)
... this is one type-theoretic "axiom of choice"
--}
Magma : Set₁
Magma = Σ[ A ∈ Set ] (A → A → A)
m₁ m₂ m₃ m₄ m₅ : Magma
m₁ = (ℕ , _+_)
m₂ = (ℕ , _*_)
m₃ = (Bool , _xor_)
m₄ = (List Bool , _++_)
m₅ = (⊥ , λ ())
PointedMagma : Set₁
PointedMagma = Σ[ A ∈ Set ] ((A → A → A) × A)
pm₁ pm₂ pm₃ pm₄ : PointedMagma
pm₁ = (ℕ , _+_ , 0)
pm₂ = (ℕ , _*_ , 1)
pm₃ = (Bool , _xor_ , false)
pm₄ = (List Bool , _++_ , [])
------------------------------------------------------------------------------
-- Sum types (coproducts)
rec⊎ : ∀ {ℓ₁ ℓ₂ ℓ₃} → {A : Set ℓ₁} {B : Set ℓ₂} →
(C : Set ℓ₃) → (A → C) → (B → C) → (A ⊎ B → C)
rec⊎ C f g (inj₁ a) = f a
rec⊎ C f g (inj₂ b) = g b
ind⊎ : ∀ {ℓ₁ ℓ₂ ℓ₃} → {A : Set ℓ₁} {B : Set ℓ₂} → (C : A ⊎ B → Set ℓ₃) →
((a : A) → C (inj₁ a)) → ((b : B) → C (inj₂ b)) → ((x : A ⊎ B) → C x)
ind⊎ C f g (inj₁ a) = f a
ind⊎ C f g (inj₂ b) = g b
-- Examples
_Union_ : (A : Set) → (B : Set) → Set
A Union B = Σ[ b ∈ Bool ] (recBool Set A B b)
inLeft : {A B : Set} → A → A Union B
inLeft a = (false , a)
inRight : {A B : Set} → B → A Union B
inRight b = (true , b)
------------------------------------------------------------------------------
-- Induction principle for vectors
indVec : {A : Set} → (C : {n : ℕ} → Vec A n → Set) →
C [] →
({m : ℕ} → (x : A) → (xs : Vec A m) → C xs → C (x ∷ xs)) →
({n : ℕ} → (xs : Vec A n) → C xs)
indVec C cnil ccons [] = cnil
indVec C cnil ccons (x ∷ xs) = ccons x xs (indVec C cnil ccons xs)
-- Example
[]++v≡v : ∀ {A n} → (v : Vec A n) → [] ++V v ≡ v
[]++v≡v {A} {n} = indVec
(λ v → [] ++V v ≡ v)
refl
(λ x xs p → refl)
postulate
n+0≡n : ∀ {n} → n + 0 ≡ n
v++[]≡v : ∀ {n} {A : Set} → (v : Vec A n) →
(subst (λ n -> Vec A n) n+0≡n (v ++V [])) ≡ v
v++[]≡v {A} {n} = {!!}
------------------------------------------------------------------------------
-- Obvious omission from list of types
-- No induction principle for functions
------------------------------------------------------------------------------
-- Propositions as types
¬ : Set → Set
¬ A = A → ⊥
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.3910034602,
"avg_line_length": 26.2727272727,
"ext": "agda",
"hexsha": "5ccc1ef58bbaccb560fe7f84a36025601eb6fe41",
"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": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andmkent/misc-HoTT",
"max_forks_repo_path": "A1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"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": "andmkent/misc-HoTT",
"max_issues_repo_path": "A1.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "b05c58ffdaed99932ca2acc632deca8d14742b04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andmkent/misc-HoTT",
"max_stars_repo_path": "A1.agda",
"max_stars_repo_stars_event_max_datetime": "2016-01-26T18:17:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-01-26T18:17:16.000Z",
"num_tokens": 2609,
"size": 6358
} |
module x02-842Induction-hc where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_)
-- associativity
_ : (3 + 4) + 5 ≡ 3 + (4 + 5)
_ =
begin
(3 + 4) + 5 ≡⟨⟩
7 + 5 ≡⟨⟩
12 ≡⟨⟩
3 + 9 ≡⟨⟩
3 + (4 + 5)
∎
+-identityᴸ : ∀ (m : ℕ) → zero + m ≡ m
+-identityᴸ m = refl -- via def/eq
+-identityʳ : ∀ (m : ℕ) → m + zero ≡ m
+-identityʳ zero = refl
+-identityʳ (suc m) -- suc m + zero ≡ suc m
-- suc (m + zero) ≡ suc m
rewrite +-identityʳ m -- suc m ≡ suc m
= refl
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc zero n p = refl
+-assoc (suc m) n p -- suc m + n + p ≡ suc m + (n + p)
-- suc (m + n + p) ≡ suc (m + (n + p))
rewrite +-assoc m n p -- suc (m + (n + p)) ≡ suc (m + (n + p))
= refl
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc zero n = refl
+-suc (suc m) n -- suc (m + suc n) ≡ suc (suc (m + n))
rewrite +-suc m n -- suc (suc (m + n)) ≡ suc (suc (m + n))
= refl
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm zero n -- zero + n ≡ n + zero
-- n ≡ n + zero
rewrite +-identityʳ n -- n ≡ n
= refl
+-comm (suc m) zero -- suc m + zero ≡ zero + suc m
-- suc (m + zero) ≡ suc m
rewrite +-identityʳ m -- suc m ≡ suc m
= refl
+-comm (suc m) (suc n) -- suc m + suc n ≡ suc n + suc m
-- suc (m + suc n) ≡ suc (n + suc m)
rewrite
+-suc m n -- suc (suc (m + n)) ≡ suc (n + suc m)
| +-suc n m -- suc (suc (m + n)) ≡ suc (suc (n + m))
| +-comm m n -- suc (suc (n + m)) ≡ suc (suc (n + m))
= refl
-- without using induction/recursion
+-swap : ∀ (m n p : ℕ) → (m + n) + p ≡ n + (m + p)
+-swap zero n p = refl
+-swap (suc m) n p -- suc m + n + p ≡ n + (suc m + p)
-- suc (m + n + p) ≡ n + suc (m + p)
rewrite
+-suc n (m + p) -- suc (m + n + p) ≡ suc (n + (m + p))
| +-comm m n -- suc (n + m + p) ≡ suc (n + (m + p))
| +-assoc n m p -- suc (n + (m + p)) ≡ suc (n + (m + p))
= refl
-- addition distributes over multiplication
*-+-rdistrib : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p
*-+-rdistrib zero n p = refl
*-+-rdistrib (suc m) n p -- (suc m + n) * p ≡ suc m * p + n * p
-- p + (m + n) * p ≡ p + m * p + n * p
rewrite
*-+-rdistrib m n p -- p + (m * p + n * p) ≡ p + m * p + n * p
| +-assoc p (m * p) (n * p) -- p + (m * p + n * p) ≡ p + (m * p + n * p)
= refl
*-assoc : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
*-assoc zero n p = refl
*-assoc (suc m) n p -- suc m * n * p ≡ suc m * (n * p)
-- (n + m * n) * p ≡ n * p + m * (n * p)
rewrite
*-+-rdistrib n (m * n) p -- n * p + m * n * p ≡ n * p + m * (n * p)
| *-assoc m n p -- n * p + m * (n * p) ≡ n * p + m * (n * p)
= refl
*0 : ∀ (n : ℕ) → n * zero ≡ zero
*0 zero = refl
*0 (suc n) = *0 n
*-suc : ∀ (m n : ℕ) → m * suc n ≡ m + (m * n)
*-suc zero n = refl
*-suc (suc m) n -- suc m * suc n ≡ suc m + suc m * n
-- suc (n + m * suc n) ≡ suc (m + (n + m * n))
rewrite
*-suc m n -- suc (n + (m + m * n)) ≡ suc (m + (n + m * n))
| sym (+-assoc n m (m * n)) -- suc (n + m + m * n) ≡ suc (m + (n + m * n))
| +-comm n m -- suc (m + n + m * n) ≡ suc (m + (n + m * n))
| +-assoc m n (m * n) -- suc (m + (n + m * n)) ≡ suc (m + (n + m * n))
= refl
*-comm : ∀ (m n : ℕ) → m * n ≡ n * m
*-comm zero n rewrite *0 n = refl
*-comm (suc m) n -- suc m * n ≡ n * suc m
-- n + m * n ≡ n * suc m
rewrite
*-suc n m -- n + m * n ≡ n + n * m
| *-comm m n -- n + n * m ≡ n + n * m
= refl
0∸n≡0 : ∀ (m : ℕ) → zero ∸ m ≡ zero
0∸n≡0 zero = refl
0∸n≡0 (suc m) rewrite 0∸n≡0 m = refl
-- form of associativity for monus
∸-+-assoc : ∀ (m n p : ℕ) → m ∸ n ∸ p ≡ m ∸ (n + p)
∸-+-assoc zero n p -- zero ∸ n ∸ p ≡ zero ∸ (n + p)
rewrite
0∸n≡0 n -- 0 ∸ p ≡ 0 ∸ (n + p)
| 0∸n≡0 p -- 0 ≡ 0 ∸ (n + p)
| 0∸n≡0 (n + p) -- 0 ≡ 0
= refl
∸-+-assoc m zero p -- m ∸ p ≡ m ∸ p
= refl
∸-+-assoc m n zero -- m ∸ n ≡ m ∸ (n + zero)
rewrite +-identityʳ n -- m ∸ n ≡ m ∸ n
= refl
∸-+-assoc (suc m) (suc n) p -- m ∸ n ∸ p ≡ m ∸ (n + p)
rewrite ∸-+-assoc m n p -- m ∸ (n + p) ≡ m ∸ (n + p)
= refl
------------------------------------------------------------------------------
-- properties of binary representation
-- BEGIN copied from 842Naturals
data Bin-ℕ : Set where
bits : Bin-ℕ
_x0 : Bin-ℕ → Bin-ℕ
_x1 : Bin-ℕ → Bin-ℕ
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc n) = suc (suc (dbl n))
inc : Bin-ℕ → Bin-ℕ
inc bits = bits x1
inc (m x0) = m x1
inc (m x1) = inc m x0
tob : ℕ → Bin-ℕ
tob zero = bits
tob (suc m) = inc (tob m)
fromb : Bin-ℕ → ℕ
fromb bits = 0
fromb (n x0) = dbl (fromb n)
fromb (n x1) = suc (dbl (fromb n))
_bin-+_ : Bin-ℕ → Bin-ℕ → Bin-ℕ
bl bin-+ bits = bl
bits bin-+ br = br
(bl x0) bin-+ (br x0) = (bl bin-+ br) x0
(bl x0) bin-+ (br x1) = (bl bin-+ br) x1
(bl x1) bin-+ (br x0) = (bl bin-+ br) x1
(bl x1) bin-+ (br x1) = inc ((bl bin-+ br) x1)
-- END copied from 842Naturals
dblb : Bin-ℕ → Bin-ℕ
dblb b = b x0
_ : dblb (tob 3) ≡ tob 6
_ = refl
_ : dblb (tob 7) ≡ tob 14
_ = refl
_ : dblb (tob 9) ≡ tob 18
_ = refl
from∘inc : ∀ (b : Bin-ℕ) → fromb (inc b) ≡ suc (fromb b)
from∘inc bits = refl
from∘inc (b x0) = refl
from∘inc (b x1) -- fromb (inc (b x1)) ≡ suc (fromb (b x1))
-- dbl (fromb (inc b)) ≡ suc (suc (dbl (fromb b)))
rewrite from∘inc b -- suc (suc (dbl (fromb b))) ≡ suc (suc (dbl (fromb b)))
= refl
from∘tob : ∀ (m : ℕ) → fromb (tob m) ≡ m
from∘tob zero = refl
from∘tob (suc m) -- fromb (tob (suc m)) ≡ suc m
-- fromb (inc (tob m)) ≡ suc m
rewrite
from∘inc (tob m) -- suc (fromb (tob m)) ≡ suc m
| from∘tob m -- suc m ≡ suc m
= refl
-- The property ∀ (m : Bin-ℕ) → tob (fromb m) ≡ m cannot be proved.
-- Because there are two representations of zero.
-- The following restriction can be proved:
to/from-corr : ∀ (b : Bin-ℕ) (n : ℕ) → b ≡ tob n → fromb b ≡ n -- TODO
to/from-corr b n b≡tn = {!!}
dblb∘inc : ∀ (b : Bin-ℕ) → dblb (inc b) ≡ inc (inc (dblb b))
dblb∘inc bits = refl
dblb∘inc (b x0) -- dblb (inc (b x0)) ≡ inc (inc (dblb (b x0)))
-- dblb (b x1) ≡ ((b x1) x0)
rewrite dblb∘inc b -- ((b x1) x0) ≡ ((b x1) x0)
= refl
dblb∘inc (b x1) -- dblb (inc (b x1)) ≡ inc (inc (dblb (b x1)))
-- dblb (inc b x0) ≡ ((inc b x0) x0)
rewrite dblb∘inc b -- ((inc b x0) x0) ≡ ((inc b x0) x0)
= refl
{-
-- more BIN properties to prove
-- not sure this can be proved because of multiple representations of zero
to∘dbl : ∀ (m : ℕ) → tob (dbl m) ≡ dblb (tob m) -- TODO -- not sure if provable because of zero
to∘dbl zero -- tob (dbl zero) ≡ dblb (tob zero)
-- bits ≡ dblb bits
= {!!}
to∘dbl (suc m) -- tob (dbl (suc m)) ≡ dblb (tob (suc m))
-- inc (inc (tob (dbl m))) ≡ dblb (inc (tob m))
rewrite to∘dbl m -- (inc (tob m) x0) ≡ (inc (tob m) x0)
= refl
from∘dblb : ∀ (b : Bin-ℕ) → fromb (dblb b) ≡ dbl (fromb b)
from∘dblb b = refl
-- bit version of second case for unary addition: suc m + n = suc (m + n)
-- useful in the next proof
-- hint: use induction on both parameters
bin-+-linc : ∀ (b1 b2 : Bin-ℕ) → (inc b1) bin-+ b2 ≡ inc (b1 bin-+ b2) -- TODO
bin-+-linc b1 bits = refl
bin-+-linc bits (b2 x0) = {!!}
bin-+-linc bits (b2 x1) = {!!}
bin-+-linc (b1 x0) b2 = {!!}
bin-+-linc (b1 x1) b2 = {!!}
-- 842 exercise: PlusUnaryBinary (2 points)
-- This theorem relates unary and binary addition.
to∘+ : ∀ (m n : ℕ) → tob (m + n) ≡ tob m bin-+ tob n -- TODO
to∘+ m n = {!!}
-}
{-
The follwing theorems can be found in:
import Data.Nat.Properties using (+-assoc; +-identityʳ; +-suc; +-comm)
-- Unicode
∀ U+2200 FOR ALL (\forall, \all)
ʳ U+02B3 MODIFIER LETTER SMALL R (\^r)
′ U+2032 PRIME (\')
″ U+2033 DOUBLE PRIME (\')
‴ U+2034 TRIPLE PRIME (\')
⁗ U+2057 QUADRUPLE PRIME (\')
-}
| {
"alphanum_fraction": 0.4083936007,
"avg_line_length": 34.5681818182,
"ext": "agda",
"hexsha": "eaaeb35b5843e1d808ebc04fe0280cbb1242674e",
"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/x02-842Induction-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/x02-842Induction-hc.agda",
"max_line_length": 95,
"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/x02-842Induction-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": 3769,
"size": 9126
} |
-- Instance arguments in records.
module Issue509 where
-- The instance version of _
⋯ : {A : Set} {{ x : A }} → A
⋯ {{ x }} = x
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
record T (n : ℕ) : Set where
field
nextPrime : ℕ
T₁ : T (suc zero)
T₁ = record { nextPrime = suc (suc zero) }
T₂ : T (suc (suc zero))
T₂ = record { nextPrime = suc (suc (suc zero)) }
data Param : ℕ → Set where
param : ∀ n → Param (suc n)
record R : Set where
constructor r
field
{impl} : ℕ
{{ inst }} : T impl
p : Param impl
s : ℕ
-- The inst field should be an instance meta here
testA : R
testA = record { p = param zero; s = suc (suc zero) }
-- So, pretty much this:
testB : R
testB = record { impl = _; inst = ⋯; p = param zero; s = suc (suc zero) }
-- Or using the construcor
testC : R
testC = r { _ } {{ ⋯ }} (param zero) (suc (suc zero))
-- Omitting the fields also works when using the constructor (of course)
testD : R
testD = r (param zero) (suc (suc zero))
-- Note that {{ _ }} means explicitly giving the instance argument and saying
-- it should be an ordinary meta. Going the other way would be {⋯}.
| {
"alphanum_fraction": 0.6072695035,
"avg_line_length": 22.1176470588,
"ext": "agda",
"hexsha": "689d69978a7f8c7594b4a3c49cba4f99f7113b92",
"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/Issue509.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/Issue509.agda",
"max_line_length": 77,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue509.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 379,
"size": 1128
} |
{-# OPTIONS --without-K --exact-split --rewriting #-}
open import lib.Basics
open import lib.NConnected
open import Graphs.Definition
open import Coequalizers.Definition
{- We will consider two properties of graphs: if they are trees and if they are connected,
both are defined in terms of the geometric realisation (coequalizer). -}
module Graphs.Properties where
{- A graph is a tree if its coequalizer is contractible. -}
is-tree : {i j : ULevel} {E : Type i} {V : Type j} ( gph : Graph E V ) → Type (lmax i j)
is-tree gph = is-contr (Coeq gph)
{- A graph is connected if its coequalizer is connected. -}
gph-is-connected : {i j : ULevel} {E : Type i} {V : Type j} (gph : Graph E V) → Type (lmax i j)
gph-is-connected gph = is-connected 0 (Coeq gph)
| {
"alphanum_fraction": 0.7017082786,
"avg_line_length": 38.05,
"ext": "agda",
"hexsha": "cb373bbc3115c87b123d89fd702b30889277fe8f",
"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": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Graphs/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"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": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Graphs/Properties.agda",
"max_line_length": 95,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Graphs/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 225,
"size": 761
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Integers, basic types and operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Integer.Base where
open import Data.Nat.Base as ℕ
using (ℕ) renaming (_+_ to _ℕ+_; _*_ to _ℕ*_)
open import Data.Sign as Sign using (Sign) renaming (_*_ to _S*_)
open import Function
open import Relation.Nullary using (¬_)
open import Relation.Binary using (Rel)
open import Relation.Binary.PropositionalEquality using (_≡_)
infix 8 -_
infixl 7 _*_ _⊓_
infixl 6 _+_ _-_ _⊖_ _⊔_
infix 4 _≤_ _≥_ _<_ _>_ _≰_ _≱_ _≮_ _≯_
------------------------------------------------------------------------
-- The types
open import Agda.Builtin.Int public
using ()
renaming
( Int to ℤ
; pos to +_ -- "+ n" stands for "n"
; negsuc to -[1+_] -- "-[1+ n ]" stands for "- (1 + n)"
)
------------------------------------------------------------------------
-- Conversions
-- Absolute value.
∣_∣ : ℤ → ℕ
∣ + n ∣ = n
∣ -[1+ n ] ∣ = ℕ.suc n
-- Gives the sign. For zero the sign is arbitrarily chosen to be +.
sign : ℤ → Sign
sign (+ _) = Sign.+
sign -[1+ _ ] = Sign.-
------------------------------------------------------------------------
-- A view of integers as sign + absolute value
infix 5 _◂_ _◃_
_◃_ : Sign → ℕ → ℤ
_ ◃ ℕ.zero = + ℕ.zero
Sign.+ ◃ n = + n
Sign.- ◃ ℕ.suc n = -[1+ n ]
data SignAbs : ℤ → Set where
_◂_ : (s : Sign) (n : ℕ) → SignAbs (s ◃ n)
signAbs : ∀ i → SignAbs i
signAbs (+ ℕ.zero) = Sign.+ ◂ ℕ.zero
signAbs (+ (ℕ.suc n)) = Sign.+ ◂ ℕ.suc n
signAbs (-[1+ n ]) = Sign.- ◂ ℕ.suc n
------------------------------------------------------------------------
-- Arithmetic
-- Negation.
-_ : ℤ → ℤ
- (+ ℕ.suc n) = -[1+ n ]
- (+ ℕ.zero) = + ℕ.zero
- -[1+ n ] = + ℕ.suc n
-- Subtraction of natural numbers.
_⊖_ : ℕ → ℕ → ℤ
m ⊖ ℕ.zero = + m
ℕ.zero ⊖ ℕ.suc n = -[1+ n ]
ℕ.suc m ⊖ ℕ.suc n = m ⊖ n
-- Addition.
_+_ : ℤ → ℤ → ℤ
-[1+ m ] + -[1+ n ] = -[1+ ℕ.suc (m ℕ+ n) ]
-[1+ m ] + + n = n ⊖ ℕ.suc m
+ m + -[1+ n ] = m ⊖ ℕ.suc n
+ m + + n = + (m ℕ+ n)
-- Subtraction.
_-_ : ℤ → ℤ → ℤ
i - j = i + (- j)
-- Successor.
suc : ℤ → ℤ
suc i = (+ 1) + i
-- Predecessor.
pred : ℤ → ℤ
pred i = (- + 1) + i
-- Multiplication.
_*_ : ℤ → ℤ → ℤ
i * j = sign i S* sign j ◃ ∣ i ∣ ℕ* ∣ j ∣
-- Maximum.
_⊔_ : ℤ → ℤ → ℤ
-[1+ m ] ⊔ -[1+ n ] = -[1+ ℕ._⊓_ m n ]
-[1+ m ] ⊔ + n = + n
+ m ⊔ -[1+ n ] = + m
+ m ⊔ + n = + (ℕ._⊔_ m n)
-- Minimum.
_⊓_ : ℤ → ℤ → ℤ
-[1+ m ] ⊓ -[1+ n ] = -[1+ ℕ._⊔_ m n ]
-[1+ m ] ⊓ + n = -[1+ m ]
+ m ⊓ -[1+ n ] = -[1+ n ]
+ m ⊓ + n = + (ℕ._⊓_ m n)
------------------------------------------------------------------------
-- Ordering
data _≤_ : ℤ → ℤ → Set where
-≤+ : ∀ {m n} → -[1+ m ] ≤ + n
-≤- : ∀ {m n} → (n≤m : n ℕ.≤ m) → -[1+ m ] ≤ -[1+ n ]
+≤+ : ∀ {m n} → (m≤n : m ℕ.≤ n) → + m ≤ + n
_≥_ : Rel ℤ _
x ≥ y = y ≤ x
_<_ : Rel ℤ _
x < y = suc x ≤ y
_>_ : Rel ℤ _
x > y = y < x
_≰_ : Rel ℤ _
x ≰ y = ¬ (x ≤ y)
_≱_ : Rel ℤ _
x ≱ y = ¬ (x ≥ y)
_≮_ : Rel ℤ _
x ≮ y = ¬ (x < y)
_≯_ : Rel ℤ _
x ≯ y = ¬ (x > y)
| {
"alphanum_fraction": 0.3853267571,
"avg_line_length": 20.6624203822,
"ext": "agda",
"hexsha": "4490e7bfe2ce27d44effc9a4dfbe2ffe9ad95816",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Integer/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Integer/Base.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Integer/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1307,
"size": 3244
} |
module DeBruijnExSubst where
open import Prelude -- using (_∘_) -- composition, identity
open import Data.Maybe
open import Logic.Identity renaming (subst to subst≡)
import Logic.ChainReasoning
module Chain = Logic.ChainReasoning.Poly.Homogenous _≡_ (\x -> refl) (\x y z -> trans)
open Chain
open import DeBruijn
-- untyped de Bruijn terms
data LamE (A : Set) : Set where
varE : A -> LamE A
appE : LamE A -> LamE A -> LamE A
absE : LamE (Maybe A) -> LamE A
flatE : LamE (LamE A) -> LamE A
-- functoriality of LamE
lamE : {A B : Set} -> (A -> B) -> LamE A -> LamE B
lamE f (varE a) = varE (f a)
lamE f (appE t1 t2) = appE (lamE f t1) (lamE f t2)
lamE f (absE r) = absE (lamE (fmap f) r)
lamE f (flatE r) = flatE (lamE (lamE f) r)
{- from TCS 05 paper
eval' : {A B : Set} -> (A -> B) -> LamE A -> Lam B
eval' f (varE a) = var (f a)
eval' f (appE t1 t2) = app (eval' f t1) (eval' f t2)
eval' f (absE r) = abs (eval' (fmap f) r)
eval' f (flatE r) = subst id (eval' (eval' f) r)
eval : {A : Set} -> LamE A -> Lam A
eval = eval' id
-}
eval : {A : Set} -> LamE A -> Lam A
eval (varE a) = var a
eval (appE t1 t2) = app (eval t1) (eval t2)
eval (absE r) = abs (eval r)
eval (flatE r) = subst eval (eval r)
evalNAT : {A B : Set}(f : A -> B) -> (t : LamE A) ->
eval (lamE f t) ≡ lam f (eval t)
evalNAT f (varE a) = refl
evalNAT f (appE t1 t2) =
chain> eval (lamE f (appE t1 t2))
=== eval (appE (lamE f t1) (lamE f t2))
by refl
=== app (eval (lamE f t1)) (eval (lamE f t2))
by refl
=== app (lam f (eval t1)) (eval (lamE f t2))
by cong (\ x -> app x (eval (lamE f t2))) (evalNAT f t1)
=== app (lam f (eval t1)) (lam f (eval t2))
by cong (\ x -> app (lam f (eval t1)) x) (evalNAT f t2)
=== lam f (app (eval t1) (eval t2))
by refl
=== lam f (eval (appE t1 t2))
by refl
evalNAT f (absE r) =
chain> eval (lamE f (absE r))
=== eval (absE (lamE (fmap f) r)) by refl
=== abs (eval (lamE (fmap f) r)) by refl
=== abs (lam (fmap f) (eval r)) by cong abs (evalNAT (fmap f) r)
=== lam f (abs (eval r)) by refl
=== lam f (eval (absE r)) by refl
evalNAT f (flatE r) =
chain> eval (lamE f (flatE r))
=== eval (flatE (lamE (lamE f) r))
by refl
=== subst eval (eval (lamE (lamE f) r))
by refl
=== subst eval (lam (lamE f) (eval r))
by cong (subst eval) (evalNAT (lamE f) r)
=== subst (eval ∘ lamE f) (eval r)
by substLaw1 (lamE f) eval (eval r)
=== subst (lam f ∘ eval) (eval r)
by substExt _ _ (evalNAT f) (eval r)
=== lam f (subst eval (eval r))
by substLaw2 f eval (eval r)
=== lam f (eval (flatE r))
by refl
evalNATcor : {A : Set}(ee : LamE (LamE A)) ->
subst id (eval (lamE eval ee)) ≡ eval (flatE ee)
evalNATcor ee =
chain> subst id (eval (lamE eval ee))
=== subst id (lam eval (eval ee)) by cong (subst id) (evalNAT eval ee)
=== subst eval (eval ee) by substLaw1 eval id (eval ee)
=== eval (flatE ee) by refl | {
"alphanum_fraction": 0.5372848948,
"avg_line_length": 34.8666666667,
"ext": "agda",
"hexsha": "1c9685761194addcba6e963d9983de929a574621",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/NestedDataTypes/DeBruijnExSubst.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/NestedDataTypes/DeBruijnExSubst.agda",
"max_line_length": 86,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/NestedDataTypes/DeBruijnExSubst.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 1202,
"size": 3138
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Sets.EquivalenceRelations
open import LogicalFormulae
open import Orders.Total.Definition
open import Orders.Partial.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Setoids.Orders.Partial.Definition where
record SetoidPartialOrder {a b c : _} {A : Set a} (S : Setoid {a} {b} A) (_<_ : Rel {a} {c} A) : Set (a ⊔ b ⊔ c) where
open Setoid S
field
<WellDefined : {a b c d : A} → (a ∼ b) → (c ∼ d) → a < c → b < d
irreflexive : {x : A} → (x < x) → False
<Transitive : {a b c : A} → (a < b) → (b < c) → (a < c)
_<=_ : Rel {a} {b ⊔ c} A
a <= b = (a < b) || (a ∼ b)
<=Transitive : {a b c : A} → (a <= b) → (b <= c) → (a <= c)
<=Transitive (inl a<b) (inl b<c) = inl (<Transitive a<b b<c)
<=Transitive (inl a<b) (inr b=c) = inl (<WellDefined (Equivalence.reflexive eq) b=c a<b)
<=Transitive (inr a=b) (inl b<c) = inl (<WellDefined (Equivalence.symmetric eq a=b) (Equivalence.reflexive eq) b<c)
<=Transitive (inr a=b) (inr b=c) = inr (Equivalence.transitive eq a=b b=c)
partialOrderToSetoidPartialOrder : {a b : _} {A : Set a} (P : PartialOrder {a} A {b}) → SetoidPartialOrder (reflSetoid A) (PartialOrder._<_ P)
SetoidPartialOrder.<WellDefined (partialOrderToSetoidPartialOrder P) a=b c=d a<c rewrite a=b | c=d = a<c
SetoidPartialOrder.irreflexive (partialOrderToSetoidPartialOrder P) = PartialOrder.irreflexive P
SetoidPartialOrder.<Transitive (partialOrderToSetoidPartialOrder P) = PartialOrder.<Transitive P
| {
"alphanum_fraction": 0.6601636249,
"avg_line_length": 49.65625,
"ext": "agda",
"hexsha": "4a7750658ab26edf112dd926f681e5e30ed0f828",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Setoids/Orders/Partial/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Setoids/Orders/Partial/Definition.agda",
"max_line_length": 142,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Setoids/Orders/Partial/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": 570,
"size": 1589
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Nat.Lower where
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Data.Bool
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Nat.Base
open import Cubical.Data.Nat.Properties
open import Cubical.Data.Sigma
open import Cubical.Data.Sum
open import Cubical.Data.Unit
open import Cubical.Relation.Nullary
isMonotone : (ℕ → Bool) → Type
isMonotone f = ∀ n → f n ≥ f (suc n)
isPropIsMonotone : ∀ f → isProp (isMonotone f)
isPropIsMonotone f = isPropΠ λ n → isProp≥ (f n) (f (suc n))
isPropDepIsMonotone : isPropDep isMonotone
isPropDepIsMonotone = isOfHLevel→isOfHLevelDep 1 isPropIsMonotone {_}
Monotone : Type
Monotone = Σ _ isMonotone
isSetMonotone : isSet Monotone
isSetMonotone = isSetΣ (isSet→ isSetBool) (isProp→isSet ∘ isPropIsMonotone)
private
variable
ℓ : Level
m n : Monotone
private
mz : ℕ → Bool
mz _ = false
ms : (ℕ → Bool) → (ℕ → Bool)
ms _ zero = true
ms f (suc m) = f m
msm : ∀{f} → isMonotone f → isMonotone (ms f)
msm _ zero = _
msm mf (suc m) = mf m
mp : (ℕ → Bool) → (ℕ → Bool)
mp f k = f (suc k)
ms-mp : ∀ f → f 0 ≡ true → ms (mp f) ≡ f
ms-mp f p i 0 = p (~ i)
ms-mp f p i (suc k) = f (suc k)
mz-lemma : ∀ f → isMonotone f → f 0 ≡ false → ∀ k → false ≡ f k
mz-lemma f _ p zero = sym p
mz-lemma f mf p (suc k)
with f 1
| inspect f 1
| subst (_≥ f 1) p (mf 0)
... | false | [ q ]ᵢ | _ = mz-lemma (mp f) (mf ∘ suc) q k
msuc : Monotone → Monotone
msuc m .fst = ms (fst m)
msuc m .snd = msm (snd m)
mpred : Monotone → Monotone
mpred f .fst k = f .fst (suc k)
mpred f .snd k = f .snd (suc k)
data MView : (ℕ → Bool) → Type where
mzv : MView mz
msv : ∀ n → MView (ms n)
mview : ∀ f → isMonotone f → MView f
mview f mf with f 0 | inspect f 0
... | true | [ p ]ᵢ = subst MView (ms-mp f p) (msv (mp f))
... | false | [ p ]ᵢ = subst MView (funExt (mz-lemma f mf p)) mzv
∞ : Monotone
∞ .fst _ = true
∞ .snd _ = _
Detached : (ℕ → Bool) → Type
Detached p = Σ[ n ∈ ℕ ] Bool→Type (p n)
Lower : Monotone → Type
Lower m = Detached (fst m)
Detached-ext
: ∀{p : ℕ → Bool} (k l : Detached p) → k .fst ≡ l .fst → k ≡ l
Detached-ext {p} (k , q) (l , r) s
= ΣPathP (s , isPropDep∘ p isPropDep-Bool→Type q r s)
Lower∞≃ℕ : Lower ∞ ≃ ℕ
Lower∞≃ℕ = isoToEquiv λ where
.fun → fst
.inv n → n , _
.rightInv _ → refl
.leftInv _ → refl
where open Iso
private
apart : ℕ → ℕ → Type
apart zero zero = ⊥
apart (suc m) (suc n) = apart m n
apart _ _ = Unit
≢→apart : (i j : ℕ) → ¬ i ≡ j → apart i j
≢→apart zero zero ¬p = ¬p refl
≢→apart (suc i) (suc j) ¬p = ≢→apart i j (¬p ∘ cong suc)
≢→apart zero (suc _) _ = _
≢→apart (suc _) zero _ = _
apart→≢ : (i j : ℕ) → apart i j → ¬ i ≡ j
apart→≢ (suc _) zero _ = snotz
apart→≢ zero (suc _) _ = znots
apart→≢ (suc i) (suc j) i#j = apart→≢ i j i#j ∘ cong predℕ
isPropApart : ∀ i j → isProp (apart i j)
isPropApart 0 0 = isProp⊥
isPropApart (suc i) (suc j) = isPropApart i j
isPropApart 0 (suc _) = isPropUnit
isPropApart (suc _) 0 = isPropUnit
_#_ : ∀{P : ℕ → Type ℓ} → Σ ℕ P → Σ ℕ P → Type
u # v = apart (fst u) (fst v)
_#?_ : ∀{P : ℕ → Type ℓ} → (u v : Σ ℕ P) → (u # v) ⊎ (fst u ≡ fst v)
u #? v = decide (fst u) (fst v) where
decide : (m n : ℕ) → apart m n ⊎ (m ≡ n)
decide zero zero = inr refl
decide zero (suc _) = inl _
decide (suc _) zero = inl _
decide (suc m) (suc n) = map (idfun _) (cong suc) (decide m n)
#→≢ : ∀{P : ℕ → Type ℓ} (u v : Σ ℕ P) → u # v → ¬ u ≡ v
#→≢ u v d = apart→≢ (fst u) (fst v) d ∘ cong fst
isProp# : ∀{P : ℕ → Type ℓ} (u v : Σ ℕ P) → isProp (u # v)
isProp# u v = isPropApart (fst u) (fst v)
isProp#Depᵣ : ∀{P : ℕ → Type ℓ} (v : Σ ℕ P) → isPropDep (λ u → u # v)
isProp#Depᵣ v = isOfHLevel→isOfHLevelDep 1 (λ u → isProp# u v) {_} {_}
≢→# : ∀{p} (u v : Detached p) → ¬ u ≡ v → u # v
≢→# u v ¬p = ≢→apart (fst u) (fst v) (¬p ∘ Detached-ext u v)
dzero : ∀{f} → Detached (ms f)
dzero = zero , _
dsuc : ∀{f} → Detached f → Detached (ms f)
dsuc (l , p) = suc l , p
module Untangle
{α β}
(f : Detached (ms α) → Detached (ms β))
(g : Detached (ms β) → Detached (ms α))
(rinv : section f g)
(linv : retract f g)
where
default : ∀{γ} → (v d : Detached (ms γ)) → v # d → Detached γ
default (suc l , p) _ _ = l , p
default (0 , _) (suc l , p) _ = l , p
#-f : ∀ u v → u # v → f u # f v
#-f u v u#v with f u #? f v
... | inl fu#fv = fu#fv
... | inr fu≡fv = Empty.rec (#→≢ u v u#v u≡v)
where
u≡v : u ≡ v
u≡v = sym (linv u)
∙∙ cong g (Detached-ext (f u) (f v) fu≡fv)
∙∙ linv v
#-g : ∀ u v → u # v → g u # g v
#-g u v u#v with g u #? g v
... | inl gu#gv = gu#gv
... | inr gu≡gv = Empty.rec (#→≢ u v u#v u≡v)
where
u≡v : u ≡ v
u≡v = sym (rinv u)
∙∙ cong f (Detached-ext (g u) (g v) gu≡gv)
∙∙ rinv v
f- : Detached α → Detached β
f- v = default (f (dsuc v)) (f dzero) (#-f (dsuc v) dzero _)
g- : Detached β → Detached α
g- v = default (g (dsuc v)) (g dzero) (#-g (dsuc v) dzero _)
g-f-z : ∀ v u → g dzero ≡ dsuc v → g (dsuc u) ≡ dzero → g- u ≡ v
g-f-z v u r s with g (dsuc u) | g dzero | #-g (dsuc u) dzero _
... | zero , _ | suc k , q | #gf
= Detached-ext (k , q) v (cong (predℕ ∘ fst) r)
... | w@(suc k , _) | _ | #gf = Empty.rec (snotz (cong fst s))
g-f-s : ∀ v u → g (dsuc u) ≡ dsuc v → g- u ≡ v
g-f-s v u r with g (dsuc u) | #-g (dsuc u) dzero _
... | suc k , q | #gf = Detached-ext (k , q) v (cong (predℕ ∘ fst) r)
... | zero , _ | #gf = Empty.rec (znots (cong fst r))
g-f- : ∀(v : Detached α) → g- (f- v) ≡ v
g-f- v with f (dsuc v) | linv (dsuc v) | #-f (dsuc v) dzero _
g-f- v | suc j , p | r | #f = g-f-s v (j , p) r
... | zero , _ | r | #f with f dzero | linv dzero
... | suc j , p | s = g-f-z v (j , p) r s
f-g-z : ∀ v u → f dzero ≡ dsuc v → f (dsuc u) ≡ dzero → f- u ≡ v
f-g-z v u r s with f (dsuc u) | f dzero | #-f (dsuc u) dzero _
... | zero , _ | suc k , q | #fg
= Detached-ext (k , q) v (cong (predℕ ∘ fst) r)
... | (suc _ , _) | _ | _ = Empty.rec (snotz (cong fst s))
f-g-s : ∀ v u → f (dsuc u) ≡ dsuc v → f- u ≡ v
f-g-s v u r with f (dsuc u) | #-f (dsuc u) dzero _
... | suc k , q | _ = Detached-ext (k , q) v (cong (predℕ ∘ fst) r)
... | zero , _ | _ = Empty.rec (znots (cong fst r))
f-g- : ∀ v → f- (g- v) ≡ v
f-g- v with g (dsuc v) | rinv (dsuc v) | #-g (dsuc v) dzero _
... | suc j , q | r | _ = f-g-s v (j , q) r
... | zero , _ | r | _ with g dzero | rinv dzero
... | suc k , q | s = f-g-z v (k , q) r s
open Iso
iso- : Iso (Detached α) (Detached β)
iso- .fun = f-
iso- .inv = g-
iso- .rightInv = f-g-
iso- .leftInv = g-f-
iso-pred
: ∀{α β}
→ Iso (Detached (ms α)) (Detached (ms β))
→ Iso (Detached α) (Detached β)
iso-pred i = Untangle.iso- fun inv rightInv leftInv
where open Iso i
isInjectiveLower : Lower m ≡ Lower n → m ≡ n
isInjectiveLower {m} {n} P =
curry ΣPathP
(lemma (m .fst) (n .fst) (m .snd) (n .snd) (pathToIso P))
(isPropDepIsMonotone (m .snd) (n .snd) _)
where
lemma
: ∀ α β → isMonotone α → isMonotone β
→ Iso (Detached α) (Detached β)
→ α ≡ β
lemma α β mα mβ I i k with mview α mα | mview β mβ
... | mzv | mzv = mz k
lemma α β mα mβ I i 0 | msv _ | msv _
= true
lemma α β mα mβ I i (suc k) | msv α' | msv β'
= lemma α' β' (mα ∘ suc) (mβ ∘ suc) (iso-pred I) i k
lemma α β mα mβ I i k | mzv | msv β'
= Empty.rec {A = α k ≡ β k} (Iso.inv I dzero .snd) i
lemma α β mα mβ I i k | msv _ | mzv
= Empty.rec {A = α k ≡ β k} (Iso.fun I dzero .snd) i
| {
"alphanum_fraction": 0.5440578974,
"avg_line_length": 29.2788104089,
"ext": "agda",
"hexsha": "abb8a88aa086d91df48c8cd59cc162f5b4533ffe",
"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": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/Nat/Lower.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"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": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/Nat/Lower.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/Nat/Lower.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 3499,
"size": 7876
} |
------------------------------------------------------------------------
-- An observation about weak bisimilarity
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Delay-monad.Bisimilarity.Observation where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Prelude.Size
open import Function-universe equality-with-J as F hiding (_∘_)
open import H-level.Closure equality-with-J
------------------------------------------------------------------------
-- The D type
mutual
-- A mixed inductive-coinductive type.
data D (i : Size) : Type where
-- Output a boolean and continue. Note that this constructor is
-- inductive.
put : Bool → D i → D i
-- Wait. The intention is that finite delay should not be
-- "observable" (as captured by weak bisimilarity).
later : D′ i → D i
record D′ (i : Size) : Type where
coinductive
field
force : {j : Size< i} → D j
open D′ public
private
variable
b b′ : Bool
n : ℕ
i : Size
x y z : D ∞
x′ y′ : D′ ∞
-- Making put inductive is a bit strange, because one can construct a
-- coinductive variant of it by using later.
put′ : Bool → D′ i → D i
put′ b x = later λ { .force → put b (x .force) }
------------------------------------------------------------------------
-- Weak bisimilarity
-- The output relation: x [ n ]≡ b means that x can output at least n
-- times, and the n-th output is b.
data _[_]≡_ : D ∞ → ℕ → Bool → Type where
put-zero : put b x [ zero ]≡ b
put-suc : x [ n ]≡ b → put b′ x [ suc n ]≡ b
later : x′ .force [ n ]≡ b → later x′ [ n ]≡ b
-- The output relation is propositional.
[]≡-propositional : Is-proposition (x [ n ]≡ b)
[]≡-propositional {b = true} put-zero put-zero = refl
[]≡-propositional {b = false} put-zero put-zero = refl
[]≡-propositional (put-suc p) (put-suc q) =
cong put-suc ([]≡-propositional p q)
[]≡-propositional (later p) (later q) =
cong later ([]≡-propositional p q)
-- Weak bisimilarity. Two computations are weakly bisimilar if the
-- output relation cannot distinguish between them.
_≈_ : D ∞ → D ∞ → Type
x ≈ y = ∀ {n b} → x [ n ]≡ b ⇔ y [ n ]≡ b
-- Weak bisimilarity is propositional (assuming extensionality).
≈-propositional :
Extensionality lzero lzero →
Is-proposition (x ≈ y)
≈-propositional ext =
implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
⇔-closure ext 1 []≡-propositional []≡-propositional
-- The put constructor and the function put′ are closely related.
put≈put′ : put b (x′ .force) ≈ put′ b x′
put≈put′ ._⇔_.to q = later q
put≈put′ ._⇔_.from (later q) = q
-- Weak bisimilarity is an equivalence relation.
reflexive-≈ : x ≈ x
reflexive-≈ = F.id
symmetric-≈ : x ≈ y → y ≈ x
symmetric-≈ x≈y = F.inverse x≈y
transitive-≈ : x ≈ y → y ≈ z → x ≈ z
transitive-≈ x≈y y≈z = y≈z F.∘ x≈y
-- The later constructor can be removed to the left and to the right.
laterˡ⁻¹ : later x′ ≈ y → x′ .force ≈ y
laterˡ⁻¹ p ._⇔_.to q = _⇔_.to p (later q)
laterˡ⁻¹ p ._⇔_.from q with _⇔_.from p q
… | later q′ = q′
laterʳ⁻¹ : x ≈ later y′ → x ≈ y′ .force
laterʳ⁻¹ = symmetric-≈ ∘ laterˡ⁻¹ ∘ symmetric-≈
later⁻¹ : later x′ ≈ later y′ → x′ .force ≈ y′ .force
later⁻¹ = laterˡ⁻¹ ∘ laterʳ⁻¹
-- The put constructor can be removed if it is removed on both sides
-- at the same time.
put⁻¹ : put b x ≈ put b′ y → x ≈ y
put⁻¹ p ._⇔_.to q with _⇔_.to p (put-suc q)
… | put-suc q′ = q′
put⁻¹ p ._⇔_.from q with _⇔_.from p (put-suc q)
… | put-suc q′ = q′
------------------------------------------------------------------------
-- Not weak bisimilarity
module Not-weak-bisimilarity where
mutual
infix 4 [_]_≈_ [_]_≈′_
-- After having seen the definition of weak bisimilarity in
-- Delay-monad.Bisimilarity one might believe that weak
-- bisimilarity for D can be defined in the following way:
data [_]_≈_ (i : Size) : D ∞ → D ∞ → Type where
put : [ i ] x ≈ y → [ i ] put b x ≈ put b y
later : [ i ] x′ .force ≈′ y′ .force → [ i ] later x′ ≈ later y′
laterˡ : [ i ] x′ .force ≈ y → [ i ] later x′ ≈ y
laterʳ : [ i ] x ≈ y′ .force → [ i ] x ≈ later y′
record [_]_≈′_ (i : Size) (x y : D ∞) : Type where
coinductive
field
force : {j : Size< i} → [ j ] x ≈ y
open [_]_≈′_ public
-- The relation [ i ]_≈_ is reflexive and symmetric.
reflexive-[]≈ : [ i ] x ≈ x
reflexive-[]≈ {x = put _ _} = put reflexive-[]≈
reflexive-[]≈ {x = later _} = later λ { .force → reflexive-[]≈ }
symmetric-[]≈ : [ i ] x ≈ y → [ i ] y ≈ x
symmetric-[]≈ (put p) = put (symmetric-[]≈ p)
symmetric-[]≈ (later p) = later λ { .force →
symmetric-[]≈ (p .force) }
symmetric-[]≈ (laterˡ p) = laterʳ (symmetric-[]≈ p)
symmetric-[]≈ (laterʳ p) = laterˡ (symmetric-[]≈ p)
-- However, the relation [ ∞ ]_≈_ is not transitive.
¬-transitive-≈ :
¬ (∀ {x y z} → [ ∞ ] x ≈ y → [ ∞ ] y ≈ z → [ ∞ ] x ≈ z)
¬-transitive-≈ trans = x≉z x≈z
where
x̲ : D i
x̲ = later λ { .force → put true (put true x̲) }
y̲ : D i
y̲ = later λ { .force → put true y̲ }
z̲ : D i
z̲ = put true (later λ { .force → put true z̲ })
x≈y : [ i ] x̲ ≈ y̲
x≈y = later λ { .force → put (laterʳ (put x≈y)) }
y≈z : [ i ] y̲ ≈ z̲
y≈z = laterˡ (put (later λ { .force → put y≈z }))
x≉z : ¬ [ ∞ ] x̲ ≈ z̲
x≉z (laterˡ (put (laterʳ (put p)))) = x≉z p
x≈z : [ ∞ ] x̲ ≈ z̲
x≈z = trans x≈y y≈z
-- Thus the two relations _≈_ and [ ∞ ]_≈_ are not pointwise
-- logically equivalent.
¬≈⇔[]≈ : ¬ (∀ {x y} → x ≈ y ⇔ [ ∞ ] x ≈ y)
¬≈⇔[]≈ =
(∀ {x y} → x ≈ y ⇔ [ ∞ ] x ≈ y) ↝⟨ (λ hyp x≈y y≈z → _⇔_.to hyp (transitive-≈ (_⇔_.from hyp x≈y) (_⇔_.from hyp y≈z))) ⟩
(∀ {x y z} → [ ∞ ] x ≈ y → [ ∞ ] y ≈ z → [ ∞ ] x ≈ z) ↝⟨ ¬-transitive-≈ ⟩□
⊥ □
-- The relation [ ∞ ]_≈_ is contained in _≈_.
[]≈→≈ : [ ∞ ] x ≈ y → x ≈ y
[]≈→≈ = λ p → record { to = ≈→→ p; from = ≈→→ (symmetric-[]≈ p) }
where
≈→→ : [ ∞ ] x ≈ y → x [ n ]≡ b → y [ n ]≡ b
≈→→ (put p) put-zero = put-zero
≈→→ (put p) (put-suc q) = put-suc (≈→→ p q)
≈→→ (later p) (later q) = later (≈→→ (p .force) q)
≈→→ (laterˡ p) (later q) = ≈→→ p q
≈→→ (laterʳ p) q = later (≈→→ p q)
-- The relation _≈_ is not contained in [ ∞ ]_≈_.
¬≈→[]≈ : ¬ (∀ {x y} → x ≈ y → [ ∞ ] x ≈ y)
¬≈→[]≈ =
(∀ {x y} → x ≈ y → [ ∞ ] x ≈ y) ↝⟨ (λ hyp → record { to = hyp; from = []≈→≈ }) ⟩
(∀ {x y} → x ≈ y ⇔ [ ∞ ] x ≈ y) ↝⟨ ¬≈⇔[]≈ ⟩□
⊥ □
------------------------------------------------------------------------
-- An alternative definition of weak bisimilarity
mutual
infix 4 [_]_≈_ [_]_≈′_
-- The problem with Not-weak-bisimilarity.[_]_≈_ is that its put
-- constructor is inductive. The put constructor of D is inductive,
-- but as noted above (put′, put≈put′) this is a bit strange, and it
-- might make more sense to make put coinductive.
--
-- The following definition of weak bisimilarity uses a coinductive
-- put constructor.
data [_]_≈_ (i : Size) : D ∞ → D ∞ → Type where
put : [ i ] x ≈′ y → [ i ] put b x ≈ put b y
later : [ i ] x′ .force ≈′ y′ .force → [ i ] later x′ ≈ later y′
laterˡ : [ i ] x′ .force ≈ y → [ i ] later x′ ≈ y
laterʳ : [ i ] x ≈ y′ .force → [ i ] x ≈ later y′
record [_]_≈′_ (i : Size) (x y : D ∞) : Type where
coinductive
field
force : {j : Size< i} → [ j ] x ≈ y
open [_]_≈′_ public
-- The relation [ ∞ ]_≈_ is not propositional.
¬-≈[]-propositional : ¬ (∀ {x y} → Is-proposition ([ ∞ ] x ≈ y))
¬-≈[]-propositional =
(∀ {x y} → Is-proposition ([ ∞ ] x ≈ y)) ↝⟨ (λ prop → prop _ _) ⟩
proof₁ ≡ proof₂ ↝⟨ (λ ()) ⟩□
⊥ □
where
never : D i
never = later λ { .force → never }
proof₁ : ∀ {i} → [ i ] never ≈ never
proof₁ = later λ { .force → proof₁ }
proof₂ : ∀ {i} → [ i ] never ≈ never
proof₂ = laterˡ proof₁
-- The relation [ i ]_≈_ is reflexive and symmetric.
reflexive-[]≈ : [ i ] x ≈ x
reflexive-[]≈ {x = put _ _} = put λ { .force → reflexive-[]≈ }
reflexive-[]≈ {x = later _} = later λ { .force → reflexive-[]≈ }
symmetric-[]≈ : [ i ] x ≈ y → [ i ] y ≈ x
symmetric-[]≈ (put p) = put λ { .force → symmetric-[]≈ (p .force) }
symmetric-[]≈ (later p) = later λ { .force → symmetric-[]≈ (p .force) }
symmetric-[]≈ (laterˡ p) = laterʳ (symmetric-[]≈ p)
symmetric-[]≈ (laterʳ p) = laterˡ (symmetric-[]≈ p)
-- The two relations _≈_ and [ ∞ ]_≈_ are pointwise logically
-- equivalent.
≈⇔[]≈ : x ≈ y ⇔ [ ∞ ] x ≈ y
≈⇔[]≈ = record
{ to = to _ _
; from = λ p → record { to = from p; from = from (symmetric-[]≈ p) }
}
where
from : [ ∞ ] x ≈ y → x [ n ]≡ b → y [ n ]≡ b
from (put p) put-zero = put-zero
from (put p) (put-suc q) = put-suc (from (p .force) q)
from (later p) (later q) = later (from (p .force) q)
from (laterˡ p) (later q) = from p q
from (laterʳ p) q = later (from p q)
mutual
to : ∀ x y → x ≈ y → [ i ] x ≈ y
to (put b x) y p = symmetric-[]≈ (to′ (symmetric-≈ p)
(_⇔_.to p put-zero))
to x (put b y) p = to′ p (_⇔_.from p put-zero)
to (later x) (later y) p = later λ { .force → to _ _ (later⁻¹ p) }
to′ : x ≈ put b y → x [ zero ]≡ b → [ i ] x ≈ put b y
to′ p put-zero = put λ { .force → to _ _ (put⁻¹ p) }
to′ p (later q) = laterˡ (to′ (laterˡ⁻¹ p) q)
-- The relation [ ∞ ]_≈_ is transitive.
transitive-[]≈ : [ ∞ ] x ≈ y → [ ∞ ] y ≈ z → [ ∞ ] x ≈ z
transitive-[]≈ p q =
_⇔_.to ≈⇔[]≈ (transitive-≈ (_⇔_.from ≈⇔[]≈ p) (_⇔_.from ≈⇔[]≈ q))
| {
"alphanum_fraction": 0.4915970615,
"avg_line_length": 31.546031746,
"ext": "agda",
"hexsha": "066aeba8e3817ad1165f521418254bb3ccbfc2c9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Bisimilarity/Observation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Bisimilarity/Observation.agda",
"max_line_length": 145,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Bisimilarity/Observation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3969,
"size": 9937
} |
open import FRP.JS.String using ( String )
open import FRP.JS.Time using ( Time )
module FRP.JS.Date where
postulate
Date : Set
fromTime : Time → Date
toTime : Date → Time
toString : Date → String
toUTCString : Date → String
{-# COMPILED_JS fromTime require("agda-frp-time").date #-}
{-# COMPILED_JS toTime function(d) { return d.getTime(); } #-}
{-# COMPILED_JS toString function(d) { return d.toString(); } #-}
{-# COMPILED_JS toUTCString function(d) { return d.toUTCString(); } #-}
| {
"alphanum_fraction": 0.6773547094,
"avg_line_length": 27.7222222222,
"ext": "agda",
"hexsha": "bcfc7efb8e804d02dd5b81f5d77105cf8d1c84fb",
"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/Date.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/Date.agda",
"max_line_length": 71,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/Date.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": 140,
"size": 499
} |
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym)
module AKS.Nat.Combinatorial where
open import AKS.Nat.Base using (ℕ; _+_; _∸_; _*_; _≤_)
open ℕ
open import AKS.Nat.Properties using (*-identityʳ)
open import AKS.Nat.Properties using (0≤n; ≤-refl; m≤m+n; *-mono-≤; module ≤-Reasoning)
open import AKS.Nat.Properties using (<-irrefl; *-mono-<)
open import AKS.Nat.Divisibility using (_/_)
open ≤-Reasoning
_C_ : ℕ → ℕ → ℕ
n C zero = 1
zero C suc k = 0
suc n C suc k = n C k + n C (suc k)
_! : ℕ → ℕ
zero ! = 1
suc n ! = suc n * n !
1≤n! : ∀ n → 1 ≤ n !
1≤n! zero = ≤-refl
1≤n! (suc n) = begin
1 ≤⟨ 1≤n! n ⟩
n ! ≤⟨ m≤m+n ⟩
n ! + n * n ! ≡⟨ refl ⟩
(1 + n) ! ∎
n≤n! : ∀ n → n ≤ n !
n≤n! zero = 0≤n
n≤n! (suc n) = begin
suc n ≡⟨ sym (*-identityʳ (suc n)) ⟩
suc n * 1 ≤⟨ *-mono-≤ (≤-refl {suc n}) (1≤n! n) ⟩
(1 + n) ! ∎
_C′_ : ℕ → ℕ → ℕ
n C′ k = (n ! / (k ! * (n ∸ k) !)) {≢⇒¬≟ den≢0}
where
den≢0 : k ! * (n ∸ k) ! ≢ 0
den≢0 den≡0 = <-irrefl (sym den≡0) (*-mono-< (1≤n! k) (1≤n! (n ∸ k)))
nC′0≡1 : ∀ {n} → n C′ 0 ≡ 1
nC′0≡1 {n} = lemma num≡dem
where
num≡dem : n ! ≡ (0 ! * (n ∸ 0) !)
num≡dem = sym (+-identityʳ (n !))
lemma : ∀ {num dem} .{dem≢0} → num ≡ dem → (num / dem) {dem≢0} ≡ 1
lemma {num} {_} {dem≢0} refl = n/n≡1 num {dem≢0}
-- 0C′n≡0 : ∀ {k} → 0 C′ k ≡ 0
-- 0C′n≡0 {k} = {!0/n≡0 (k ! * (0 ∸ k) !) {?}!}
-- lem : ∀ {n k} → n C k ≡ n C′ k
-- lem {n} {zero} = sym (nC′0≡1 {n})
-- lem {zero} {suc k} = {!refl!}
-- lem {suc n} {suc k} with lem {n} {k} | lem {n} {suc k}
-- ... | p₁ | p₂ = {!!}
| {
"alphanum_fraction": 0.4856046065,
"avg_line_length": 26.05,
"ext": "agda",
"hexsha": "e8fa8d881fb5767d4ec9effdf9e31727d94eb613",
"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": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Nat/Combinatorial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"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": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Nat/Combinatorial.agda",
"max_line_length": 87,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Nat/Combinatorial.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 836,
"size": 1563
} |
{-# OPTIONS --without-K #-}
module Lecture6 where
import Lecture5
open Lecture5 public
-- Section 6.1 Contractible types
is-contr : {i : Level} → UU i → UU i
is-contr A = Sigma A (λ a → (x : A) → Id a x)
center : {i : Level} {A : UU i} → is-contr A → A
center (dpair c C) = c
-- We make sure that the contraction is coherent in a straightforward way
contraction : {i : Level} {A : UU i} (H : is-contr A) →
(const A A (center H) ~ id)
contraction (dpair c C) x = concat _ (inv (C c)) (C x)
coh-contraction : {i : Level} {A : UU i} (H : is-contr A) →
Id (contraction H (center H)) refl
coh-contraction (dpair c C) = left-inv (C c)
ev-pt : {i j : Level} (A : UU i) (a : A) (B : A → UU j) → ((x : A) → B x) → B a
ev-pt A a B f = f a
sing-ind-is-contr : {i j : Level} (A : UU i) (H : is-contr A) (B : A → UU j) →
B (center H) → (x : A) → B x
sing-ind-is-contr A H B b x = tr B (contraction H x) b
sing-comp-is-contr : {i j : Level} (A : UU i) (H : is-contr A) (B : A → UU j) →
(((ev-pt A (center H) B) ∘ (sing-ind-is-contr A H B)) ~ id)
sing-comp-is-contr A H B b =
ap (λ (ω : Id (center H) (center H)) → tr B ω b) (coh-contraction H)
is-sing-is-contr : {i j : Level} (A : UU i) (H : is-contr A) (B : A → UU j) →
sec (ev-pt A (center H) B)
is-sing-is-contr A H B =
dpair (sing-ind-is-contr A H B) (sing-comp-is-contr A H B)
is-sing : {i : Level} (A : UU i) → A → UU (lsuc i)
is-sing {i} A a = (B : A → UU i) → sec (ev-pt A a B)
is-contr-is-sing : {i : Level} (A : UU i) (a : A) →
is-sing A a → is-contr A
is-contr-is-sing A a S = dpair a (pr1 (S (λ y → Id a y)) refl)
is-sing-unit : is-sing unit star
is-sing-unit B = dpair ind-unit (λ b → refl)
is-contr-unit : is-contr unit
is-contr-unit = is-contr-is-sing unit star (is-sing-unit)
is-sing-total-path : {i : Level} (A : UU i) (a : A) →
is-sing (Σ A (λ x → Id a x)) (dpair a refl)
is-sing-total-path A a B = dpair (ind-Σ ∘ (ind-Id _)) (λ b → refl)
is-contr-total-path : {i : Level} (A : UU i) (a : A) →
is-contr (Σ A (λ x → Id a x))
is-contr-total-path A a = is-contr-is-sing _ _ (is-sing-total-path A a)
-- Section 6.2 Contractible maps
fib : {i j : Level} {A : UU i} {B : UU j} (f : A → B) (b : B) → UU (i ⊔ j)
fib f b = Σ _ (λ x → Id (f x) b)
is-contr-map : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-contr-map f = (y : _) → is-contr (fib f y)
-- Our goal is to show that contractible maps are equivalences.
-- First we construct the inverse of a contractible map.
inv-is-contr-map : {i j : Level} {A : UU i} {B : UU j} {f : A → B} →
is-contr-map f → B → A
inv-is-contr-map H y = pr1 (center (H y))
-- Then we show that the inverse is a section.
issec-is-contr-map : {i j : Level} {A : UU i} {B : UU j} {f : A → B}
(H : is-contr-map f) → (f ∘ (inv-is-contr-map H)) ~ id
issec-is-contr-map H y = pr2 (center (H y))
-- Then we show that the inverse is also a retraction.
isretr-is-contr-map : {i j : Level} {A : UU i} {B : UU j} {f : A → B}
(H : is-contr-map f) → ((inv-is-contr-map H) ∘ f) ~ id
isretr-is-contr-map {_} {_} {A} {B} {f} H x =
ap {_} {_} {fib f (f x)} {A} pr1
{dpair (inv-is-contr-map H (f x)) (issec-is-contr-map H (f x))}
{dpair x refl}
( concat (center (H (f x)))
(inv (contraction (H (f x))
(dpair (inv-is-contr-map H (f x)) (issec-is-contr-map H (f x)))))
(contraction (H (f x)) (dpair x refl)))
-- Finally we put it all together to show that contractible maps are equivalences.
is-equiv-is-contr-map : {i j : Level} {A : UU i} {B : UU j} {f : A → B} →
is-contr-map f → is-equiv f
is-equiv-is-contr-map H =
pair
(dpair (inv-is-contr-map H) (issec-is-contr-map H))
(dpair (inv-is-contr-map H) (isretr-is-contr-map H))
-- Section 6.3 Equivalences are contractible maps
htpy-nat : {i j : Level} {A : UU i} {B : UU j} {f g : A → B} (H : f ~ g)
{x y : A} (p : Id x y) →
Id (concat _ (H x) (ap g p)) (concat _ (ap f p) (H y))
htpy-nat H refl = right-unit (H _)
-- Should left-unwhisk and right-unwhisk be moved to Lecture 4? That's where they most naturally fit.
left-unwhisk : {i : Level} {A : UU i} {x y z : A} (p : Id x y) {q r : Id y z} →
Id (concat _ p q) (concat _ p r) → Id q r
left-unwhisk refl s = concat _ (inv (left-unit _)) (concat _ s (left-unit _))
right-unwhisk : {i : Level} {A : UU i} {x y z : A} {p q : Id x y}
(r : Id y z) → Id (concat _ p r) (concat _ q r) → Id p q
right-unwhisk refl s = concat _ (inv (right-unit _)) (concat _ s (right-unit _))
htpy-red : {i : Level} {A : UU i} {f : A → A} (H : f ~ id) →
(x : A) → Id (H (f x)) (ap f (H x))
htpy-red {_} {A} {f} H x = right-unwhisk (H x)
(concat (concat (f x) (H (f x)) (ap id (H x)))
(ap (concat (f x) (H (f x))) (inv (ap-id (H x)))) (htpy-nat H (H x)))
center-is-invertible : {i j : Level} {A : UU i} {B : UU j} {f : A → B} →
is-invertible f → (y : B) → fib f y
center-is-invertible {i} {j} {A} {B} {f}
(dpair g (dpair issec isretr)) y =
(dpair (g y)
(concat _
(inv (ap (f ∘ g) (issec y)))
(concat _ (ap f (isretr (g y))) (issec y))))
mv-left : {i : Level} {A : UU i} {x y z : A}
(p : Id x y) {q : Id y z} {r : Id x z} →
Id (concat _ p q) r → Id q (concat _ (inv p) r)
mv-left refl s = s
square : {i : Level} {A : UU i} {x y1 y2 z : A}
(p1 : Id x y1) (q1 : Id y1 z) (p2 : Id x y2) (q2 : Id y2 z) → UU i
square p q p' q' = Id (concat _ p q) (concat _ p' q')
sq-left-whisk : {i : Level} {A : UU i} {x y1 y2 z : A} {p1 p1' : Id x y1}
(s : Id p1 p1') {q1 : Id y1 z} {p2 : Id x y2} {q2 : Id y2 z} →
square p1 q1 p2 q2 → square p1' q1 p2 q2
sq-left-whisk refl sq = sq
sq-top-whisk : {i : Level} {A : UU i} {x y1 y2 z : A}
{p1 : Id x y1} {q1 : Id y1 z}
{p2 p2' : Id x y2} (s : Id p2 p2') {q2 : Id y2 z} →
square p1 q1 p2 q2 → square p1 q1 p2' q2
sq-top-whisk refl sq = sq
contraction-is-invertible : {i j : Level} {A : UU i} {B : UU j} {f : A → B} →
(I : is-invertible f) → (y : B) → (t : fib f y) →
Id (center-is-invertible I y) t
contraction-is-invertible {i} {j} {A} {B} {f}
(dpair g (dpair issec isretr)) y (dpair x refl) =
eq-pair (dpair
(isretr x)
(concat _
(tr-fib (isretr x) (f x)
(pr2 (center-is-invertible
(dpair g (dpair issec isretr))
(f x))))
(inv (mv-left (ap f (isretr x))
(concat _ (right-unit (ap f (isretr x)))
(mv-left (ap (f ∘ g) (issec y))
(sq-left-whisk {_} {_} {f(g(f(g(f x))))} {f(g(f x))} {f(g(f x))} {f x}
{issec (f(g(f x)))} {ap (f ∘ g) (issec (f x))}
(htpy-red issec (f x)) {ap f (isretr x)} {ap f (isretr (g (f x)))}
{issec (f x)}
(sq-top-whisk {_} {_} {f(g(f(g(f x))))} {f(g(f x))} {f(g(f x))} {f x}
{issec (f(g(f x)))} {_} {_} {_}
(concat _ (ap-comp f (g ∘ f) (isretr x))
(inv (ap (ap f) (htpy-red isretr x))))
(htpy-nat (htpy-right-whisk issec f) (isretr x))))))))))
is-contr-map-is-invertible : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-invertible f → is-contr-map f
is-contr-map-is-invertible {i} {j} {A} {B} {f} I y =
dpair (center-is-invertible I y) (contraction-is-invertible I y)
is-contr-map-is-equiv : {i j : Level} {A : UU i} {B : UU j} {f : A → B} → is-equiv f → is-contr-map f
is-contr-map-is-equiv = is-contr-map-is-invertible ∘ is-invertible-is-equiv
is-contr-total-path' : {i : Level} (A : UU i) (a : A) →
is-contr (Σ A (λ x → Id x a))
is-contr-total-path' A a = is-contr-map-is-equiv (is-equiv-id _) a
-- Exercises
-- Exercise 6.1
is-prop-is-contr : {i : Level} {A : UU i} → is-contr A → (x y : A) → is-contr (Id x y)
is-prop-is-contr {i} {A} C =
sing-ind-is-contr A C
(λ x → ((y : A) → is-contr (Id x y)))
(λ y → dpair
(contraction C y)
(ind-Id
(λ z (p : Id (center C) z) → Id (contraction C z) p)
(coh-contraction C)
y))
-- Exercise 6.2
is-contr-retract-of : {i j : Level} {A : UU i} (B : UU j) → A retract-of B → is-contr B → is-contr A
is-contr-retract-of B (dpair i (dpair r isretr)) C =
dpair
(r (center C))
(λ x → concat (r (i x)) (ap r (contraction C (i x))) (isretr x))
-- Exercise 6.3
is-equiv-const-is-contr : {i : Level} {A : UU i} → is-contr A → is-equiv (const A unit star)
is-equiv-const-is-contr {i} {A} H = pair (dpair (ind-unit (center H)) (ind-unit refl)) (dpair (const unit A (center H)) (contraction H))
is-contr-is-equiv-const : {i : Level} {A : UU i} → is-equiv (const A unit star) → is-contr A
is-contr-is-equiv-const (dpair (dpair g issec) (dpair h isretr)) = dpair (h star) isretr
is-contr-is-equiv : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → is-equiv f → is-contr B → is-contr A
is-contr-is-equiv f Ef C =
is-contr-is-equiv-const
(is-equiv-comp (λ x → refl) Ef (is-equiv-const-is-contr C))
is-contr-is-equiv' : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → is-equiv f → is-contr A → is-contr B
is-contr-is-equiv' f Ef C = is-contr-is-equiv (inv-is-equiv Ef) (is-equiv-inv-is-equiv Ef) C
is-equiv-is-contr : {i j : Level} {A : UU i} {B : UU j} (f : A → B) →
is-contr A → is-contr B → is-equiv f
is-equiv-is-contr {i} {j} {A} {B} f CA CB =
pair
(dpair
(const B A (center CA))
(sing-ind-is-contr B CB _ (inv (contraction CB (f (center CA))))))
(dpair (const B A (center CA)) (contraction CA))
| {
"alphanum_fraction": 0.5440797941,
"avg_line_length": 39.8461538462,
"ext": "agda",
"hexsha": "b8e1e1e4675cfa3b6f82468f2bccb9180d80eaae",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2018-06-25T15:05:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-02-22T19:58:46.000Z",
"max_forks_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "glangmead/hott_cmu80818",
"max_forks_repo_path": "Lecture6.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b",
"max_issues_repo_issues_event_max_datetime": "2018-03-25T14:44:31.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-22T21:01:16.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "glangmead/hott_cmu80818",
"max_issues_repo_path": "Lecture6.agda",
"max_line_length": 136,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "af64d808630f4f1498a75201b6ca4d74d662516b",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "glangmead/hott_cmu80818",
"max_stars_repo_path": "Lecture6.agda",
"max_stars_repo_stars_event_max_datetime": "2018-09-04T02:52:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-03T20:32:19.000Z",
"num_tokens": 3851,
"size": 9324
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Construct.DirectProduct
module Construct.DirectProduct where
open import Algebra
import Algebra.Construct.DirectProduct as DirectProduct
open import Data.Product
open import Data.Product.Relation.Binary.Pointwise.NonDependent
open import Level using (Level; _⊔_)
private
variable
a b ℓ₁ ℓ₂ : Level
------------------------------------------------------------------------
-- Raw bundles
rawQuasigroup : RawQuasigroup a ℓ₁ → RawQuasigroup b ℓ₂ → RawQuasigroup (a ⊔ b) (ℓ₁ ⊔ ℓ₂)
rawQuasigroup M N = record
{ Carrier = M.Carrier × N.Carrier
; _≈_ = Pointwise M._≈_ N._≈_
; _∙_ = zip M._∙_ N._∙_
; _\\_ = zip M._\\_ N._\\_
; _//_ = zip M._//_ N._//_
} where module M = RawQuasigroup M; module N = RawQuasigroup N
rawLoop : RawLoop a ℓ₁ → RawLoop b ℓ₂ → RawLoop (a ⊔ b) (ℓ₁ ⊔ ℓ₂)
rawLoop M N = record
{ Carrier = M.Carrier × N.Carrier
; _≈_ = Pointwise M._≈_ N._≈_
; _∙_ = zip M._∙_ N._∙_
; _\\_ = zip M._\\_ N._\\_
; _//_ = zip M._//_ N._//_
; ε = M.ε , N.ε
} where module M = RawLoop M; module N = RawLoop N
------------------------------------------------------------------------
-- Bundles
unitalMagma : UnitalMagma a ℓ₁ → UnitalMagma b ℓ₂ → UnitalMagma (a ⊔ b) (ℓ₁ ⊔ ℓ₂)
unitalMagma M N = record
{ ε = M.ε , N.ε
; isUnitalMagma = record
{ isMagma = Magma.isMagma (magma M.magma N.magma)
; identity = (M.identityˡ , N.identityˡ <*>_)
, (M.identityʳ , N.identityʳ <*>_)
}
} where module M = UnitalMagma M; module N = UnitalMagma N
invertibleMagma : InvertibleMagma a ℓ₁ → InvertibleMagma b ℓ₂ → InvertibleMagma (a ⊔ b) (ℓ₁ ⊔ ℓ₂)
invertibleMagma M N = record
{ _⁻¹ = map M._⁻¹ N._⁻¹
; isInvertibleMagma = record
{ isMagma = Magma.isMagma (magma M.magma N.magma)
; inverse = (λ x → (M.inverseˡ , N.inverseˡ) <*> x)
, (λ x → (M.inverseʳ , N.inverseʳ) <*> x)
}
} where module M = InvertibleMagma M; module N = InvertibleMagma N
invertibleUnitalMagma : InvertibleUnitalMagma a ℓ₁ → InvertibleUnitalMagma b ℓ₂ → InvertibleUnitalMagma (a ⊔ b) (ℓ₁ ⊔ ℓ₂)
invertibleUnitalMagma M N = record
{ ε = M.ε , N.ε
; isInvertibleUnitalMagma = record
{ isInvertibleMagma = InvertibleMagma.isInvertibleMagma (invertibleMagma M.invertibleMagma N.invertibleMagma)
; identity = (M.identityˡ , N.identityˡ <*>_)
, (M.identityʳ , N.identityʳ <*>_)
}
} where module M = InvertibleUnitalMagma M; module N = InvertibleUnitalMagma N
| {
"alphanum_fraction": 0.6073401736,
"avg_line_length": 35.1944444444,
"ext": "agda",
"hexsha": "4ac62a0f6e0418ab4f6297b33f7df6484a3727fb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Construct/DirectProduct.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Construct/DirectProduct.agda",
"max_line_length": 121,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Construct/DirectProduct.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 912,
"size": 2534
} |
{-# OPTIONS --without-K #-}
open import Base
module Homotopy.PullbackDef where
record pullback-diag (i : Level) : Set (suc i) where
constructor diag_,_,_,_,_
field
A : Set i
B : Set i
C : Set i
f : A → C
g : B → C
pullback-diag-raw-eq : ∀ {i} {A A' : Set i} (p : A ≡ A')
{B B' : Set i} (q : B ≡ B') {C C' : Set i} (r : C ≡ C')
{f : A → C} {f' : A' → C'} (s : f' ◯ (transport _ p) ≡ transport _ r ◯ f)
{g : B → C} {g' : B' → C'} (t : transport _ r ◯ g ≡ g' ◯ (transport _ q))
→ (diag A , B , C , f , g) ≡ (diag A' , B' , C' , f' , g')
pullback-diag-raw-eq refl refl refl refl refl = refl
pullback-diag-eq : ∀ {i} {A A' : Set i} (p : A ≃ A')
{B B' : Set i} (q : B ≃ B') {C C' : Set i} (r : C ≃ C')
{f : A → C} {f' : A' → C'} (s : (a : A) → f' ((π₁ p) a) ≡ (π₁ r) (f a))
{g : B → C} {g' : B' → C'} (t : (b : B) → (π₁ r) (g b) ≡ g' ((π₁ q) b))
→ (diag A , B , C , f , g) ≡ (diag A' , B' , C' , f' , g')
pullback-diag-eq p q r {f} {f'} s {g} {g'} t = pullback-diag-raw-eq
(eq-to-path p)
(eq-to-path q)
(eq-to-path r)
(funext (λ a → ap f' (trans-id-eq-to-path p a)
∘ (s a ∘ ! (trans-id-eq-to-path r (f a)))))
(funext (λ b → trans-id-eq-to-path r (g b)
∘ (t b ∘ ap g' (! (trans-id-eq-to-path q b)))))
module Pullback {i} (D : pullback-diag i) where
open pullback-diag D
record pullback : Set i where
constructor _,_,_
field
a : A
b : B
h : f a ≡ g b
pullback-eq : {a a' : A} (p : a ≡ a') {b b' : B} (q : b ≡ b')
{h : f a ≡ g b} {h' : f a' ≡ g b'} (r : h ∘ ap g q ≡ ap f p ∘ h')
→ (a , b , h) ≡ (a' , b' , h')
pullback-eq refl refl r =
ap (λ u → _ , _ , u) (! (refl-right-unit _) ∘ r)
open Pullback public
| {
"alphanum_fraction": 0.4455899198,
"avg_line_length": 31.7454545455,
"ext": "agda",
"hexsha": "baf7eeb89bf027fcb9c470315a8891cd9a7e8806",
"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/PullbackDef.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/PullbackDef.agda",
"max_line_length": 75,
"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/PullbackDef.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": 784,
"size": 1746
} |
-- Module shadowing using generated modules for records and datatypes
module Issue260b where
module R where
record R : Set where
| {
"alphanum_fraction": 0.8076923077,
"avg_line_length": 21.6666666667,
"ext": "agda",
"hexsha": "71f9ba92842292bab5a1b836efa69ddac233d350",
"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/Issue260b.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/Issue260b.agda",
"max_line_length": 69,
"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/Issue260b.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": 29,
"size": 130
} |
module UniDB.Subst.StarPrime where
open import UniDB.Subst.Core
open import UniDB.Morph.StarPrime
open import UniDB.Morph.Depth
module _
{T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
{Ξ : MOR} {{lkTΞ : Lk T Ξ}}
where
mutual
instance
iLkStar* : Lk T (Star* Ξ)
lk {{iLkStar*}} refl i = vr i
lk {{iLkStar*}} (incl ξ) i = lk ξ i
iLkStar₁ : Lk T (Star+ Ξ)
lk {{iLkStar₁}} (step ξs ξ) i = ap {T} (depth ξ 0) (lk ξs i)
| {
"alphanum_fraction": 0.5684210526,
"avg_line_length": 22.619047619,
"ext": "agda",
"hexsha": "3aaa3d6b9c8b0384afc51ef8f90f53088d619a19",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Subst/StarPrime.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Subst/StarPrime.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Subst/StarPrime.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 204,
"size": 475
} |
-- Basic intuitionistic propositional calculus, without ∨ or ⊥.
-- Hilbert-style formalisation of syntax.
-- Nested terms.
module BasicIPC.Syntax.Hilbert where
open import BasicIPC.Syntax.Common public
-- Derivations.
infix 3 _⊢_
data _⊢_ (Γ : Cx Ty) : Ty → Set where
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
ci : ∀ {A} → Γ ⊢ A ▻ A
ck : ∀ {A B} → Γ ⊢ A ▻ B ▻ A
cs : ∀ {A B C} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cpair : ∀ {A B} → Γ ⊢ A ▻ B ▻ A ∧ B
cfst : ∀ {A B} → Γ ⊢ A ∧ B ▻ A
csnd : ∀ {A B} → Γ ⊢ A ∧ B ▻ B
unit : Γ ⊢ ⊤
infix 3 _⊢⋆_
_⊢⋆_ : Cx Ty → Cx Ty → Set
Γ ⊢⋆ ∅ = 𝟙
Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A
-- Monotonicity with respect to context inclusion.
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η ci = ci
mono⊢ η ck = ck
mono⊢ η cs = cs
mono⊢ η cpair = cpair
mono⊢ η cfst = cfst
mono⊢ η csnd = csnd
mono⊢ η unit = unit
mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Shorthand for variables.
v₀ : ∀ {A Γ} → Γ , A ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ} → Γ , A , B ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ} → Γ , A , B , C ⊢ A
v₂ = var i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem.
lam : ∀ {A B Γ} → Γ , A ⊢ B → Γ ⊢ A ▻ B
lam (var top) = ci
lam (var (pop i)) = app ck (var i)
lam (app t u) = app (app cs (lam t)) (lam u)
lam ci = app ck ci
lam ck = app ck ck
lam cs = app ck cs
lam cpair = app ck cpair
lam cfst = app ck cfst
lam csnd = app ck csnd
lam unit = app ck unit
lam⋆ : ∀ {Ξ Γ A} → Γ ⧺ Ξ ⊢ A → Γ ⊢ Ξ ▻⋯▻ A
lam⋆ {∅} = I
lam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam
lam⋆₀ : ∀ {Γ A} → Γ ⊢ A → ∅ ⊢ Γ ▻⋯▻ A
lam⋆₀ {∅} = I
lam⋆₀ {Γ , B} = lam⋆₀ ∘ lam
-- Detachment theorem.
det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
det⋆ : ∀ {Ξ Γ A} → Γ ⊢ Ξ ▻⋯▻ A → Γ ⧺ Ξ ⊢ A
det⋆ {∅} = I
det⋆ {Ξ , B} = det ∘ det⋆ {Ξ}
det⋆₀ : ∀ {Γ A} → ∅ ⊢ Γ ▻⋯▻ A → Γ ⊢ A
det⋆₀ {∅} = I
det⋆₀ {Γ , B} = det ∘ det⋆₀
-- Cut and multicut.
cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut t u = app (lam u) t
multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in functional form.
pair : ∀ {A B Γ} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
pair t u = app (app cpair t) u
fst : ∀ {A B Γ} → Γ ⊢ A ∧ B → Γ ⊢ A
fst t = app cfst t
snd : ∀ {A B Γ} → Γ ⊢ A ∧ B → Γ ⊢ B
snd t = app csnd t
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
-- Convertibility.
data _⋙_ {Γ : Cx Ty} : ∀ {A} → Γ ⊢ A → Γ ⊢ A → Set where
refl⋙ : ∀ {A} → {t : Γ ⊢ A}
→ t ⋙ t
trans⋙ : ∀ {A} → {t t′ t″ : Γ ⊢ A}
→ t ⋙ t′ → t′ ⋙ t″
→ t ⋙ t″
sym⋙ : ∀ {A} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ t′ ⋙ t
congapp⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ▻ B} → {u u′ : Γ ⊢ A}
→ t ⋙ t′ → u ⋙ u′
→ app t u ⋙ app t′ u′
congi⋙ : ∀ {A} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ app ci t ⋙ app ci t′
congk⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ app (app ck t) u ⋙ app (app ck t′) u′
congs⋙ : ∀ {A B C} → {t t′ : Γ ⊢ A ▻ B ▻ C} → {u u′ : Γ ⊢ A ▻ B} → {v v′ : Γ ⊢ A}
→ t ⋙ t′ → u ⋙ u′ → v ⋙ v′
→ app (app (app cs t) u) v ⋙ app (app (app cs t′) u′) v′
congpair⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ app (app cpair t) u ⋙ app (app cpair t′) u′
congfst⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ app cfst t ⋙ app cfst t′
congsnd⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ app csnd t ⋙ app csnd t′
-- TODO: Verify this.
beta▻ₖ⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ app (app ck t) u ⋙ t
-- TODO: Verify this.
beta▻ₛ⋙ : ∀ {A B C} → {t : Γ ⊢ A ▻ B ▻ C} → {u : Γ ⊢ A ▻ B} → {v : Γ ⊢ A}
→ app (app (app cs t) u) v ⋙ app (app t v) (app u v)
-- TODO: What about eta for ▻?
beta∧₁⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ app cfst (app (app cpair t) u) ⋙ t
beta∧₂⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ app csnd (app (app cpair t) u) ⋙ u
eta∧⋙ : ∀ {A B} → {t : Γ ⊢ A ∧ B}
→ t ⋙ app (app cpair (app cfst t)) (app csnd t)
eta⊤⋙ : ∀ {t : Γ ⊢ ⊤} → t ⋙ unit
| {
"alphanum_fraction": 0.3829027872,
"avg_line_length": 25.9207048458,
"ext": "agda",
"hexsha": "cf2a2c51ce779fb8264480e5309495758b1f10f8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicIPC/Syntax/Hilbert.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicIPC/Syntax/Hilbert.agda",
"max_line_length": 86,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicIPC/Syntax/Hilbert.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 2958,
"size": 5884
} |
------------------------------------------------------------------------
-- Small parser combinator library used by Mixfix.Acyclic.Grammar
------------------------------------------------------------------------
-- Note that while Mixfix.Acyclic.Lib and Mixfix.Cyclic.Lib may appear
-- to be very similar, there are some important differences:
--
-- • Mixfix.Cyclic.Lib._⊛∞_ accepts delayed parsers,
-- Mixfix.Acyclic.Lib._⊛_ does not.
--
-- • There is a translation from the parsers in Mixfix.Acyclic.Lib to
-- the /simplified/ parsers in
-- StructurallyRecursiveDescentParsing.Simplified; no such
-- translation is defined for the parsers in Mixfix.Cyclic.Lib. Note
-- that the depth-first backend in
-- StructurallyRecursiveDescentParsing.DepthFirst only handles
-- simplified parsers.
module Mixfix.Acyclic.Lib where
open import Algebra
open import Codata.Musical.Notation
open import Data.Bool using (Bool; true; false)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.List using (List; []; _∷_; _++_)
open import Data.List.NonEmpty using (List⁺; _∷_; [_]; _∷⁺_; _⁺∷ʳ_)
import Data.List.Properties
private module LM {A : Set} = Monoid (Data.List.Properties.++-monoid A)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Product
import Data.String.Properties as String
open import Relation.Binary
open DecSetoid String.≡-decSetoid using (_≟_)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; cong)
import StructurallyRecursiveDescentParsing.Simplified as Simplified
open Simplified hiding (⟦_⟧)
open import StructurallyRecursiveDescentParsing.Simplified.Semantics
as Sem hiding (cast∈; sound; complete)
open import Mixfix.Operator using (NamePart)
------------------------------------------------------------------------
-- Programs
-- Agda's termination checker only accepts corecursive definitions if
-- they are /syntactically/ guarded by constructors. The following
-- small language of "parser programs" reifies a selection of parser
-- combinators as /constructors/. These constructors are then used in
-- Mixfix.Acyclic.Grammar in order to ensure that Agda accepts the
-- grammars defined there.
infix 55 _+
infixl 50 _⊛_ _<$>_
infixl 5 _∣_
infixr 5 _∥_
data ParserProg : Set → Set1 where
fail : ∀ {R} → ParserProg R
_∣_ : ∀ {R}
(p₁ : ParserProg R)
(p₂ : ParserProg R) →
ParserProg R
_⊛_ : ∀ {R₁ R₂}
(p₁ : ParserProg (R₁ → R₂))
(p₂ : ParserProg R₁) →
ParserProg R₂
_<$>_ : ∀ {R₁ R₂} (f : R₁ → R₂)
(p : ParserProg R₁) →
ParserProg R₂
_+ : ∀ {R} (p : ParserProg R) →
ParserProg (List⁺ R)
_between_ : ∀ {R n}
(p : ∞ (ParserProg R)) (toks : Vec NamePart (1 + n)) →
ParserProg (Vec R n)
_∥_ : ∀ {I i} {R : I → Set}
(p₁ : ParserProg (R i))
(p₂ : ParserProg (∃ R)) →
ParserProg (∃ R)
-- Parses a given token.
tok : NamePart → Parser NamePart false NamePart
tok tok = token !>>= λ tok′ → ♯ ok tok′
module TheToken where
okIndex : NamePart → Bool
okIndex tok′ with tok ≟ tok′
... | yes _ = true
... | no _ = false
ok : (tok′ : NamePart) → Parser NamePart (okIndex tok′) NamePart
ok tok′ with tok ≟ tok′
... | yes _ = return tok′
... | no _ = fail
-- Interprets the parser programs as parsers.
private
infix 10 ♯′_
♯′_ : {A : Set₁} → A → ∞ A
♯′ x = ♯ x
⟦_⟧ : ∀ {R} → ParserProg R → Parser NamePart false R
⟦ fail ⟧ = fail
⟦ p₁ ∣ p₂ ⟧ = ⟦ p₁ ⟧ ∣ ⟦ p₂ ⟧
⟦ p₁ ⊛ p₂ ⟧ = ⟦ p₁ ⟧ !>>= λ f → ♯ ⟦ f <$> p₂ ⟧
⟦ f <$> p ⟧ = ⟦ p ⟧ !>>= λ x → ♯′ return (f x)
⟦ p + ⟧ = ⟦ p ⟧ !>>= λ x → ♯
(⟦ _∷⁺_ x <$> p + ⟧ ∣ return [ x ])
⟦ p between (t ∷ []) ⟧ = tok t !>>= λ _ → ♯′ return []
⟦ p between (t ∷ t′ ∷ ts) ⟧ = tok t !>>= λ _ → ♯
⟦ _∷_ <$> ♭ p ⊛ (p between (t′ ∷ ts)) ⟧
⟦ p₁ ∥ p₂ ⟧ = (⟦ p₁ ⟧ !>>= λ x → ♯′ return (-, x)) ∣
⟦ p₂ ⟧
------------------------------------------------------------------------
-- Semantics of the programs
module Semantics where
-- This definition may seem unnecessary: why not simply define
--
-- x ∈⟦ p ⟧· s = x ∈ ⟦ p ⟧ · s?
--
-- One reason is that it is hard for Agda to infer the value of p
-- from ⟦ p ⟧ (note that ⟦_⟧ is a function which evaluates). By
-- using the definition below this problem is avoided. A more
-- important reason may be that the definition below ensures that
-- the details of ⟦_⟧ do not need to be understood.
infix 60 <$>_
infixl 50 _⊛_
infix 4 _∈⟦_⟧·_
data _∈⟦_⟧·_ : ∀ {R} → R → ParserProg R → List NamePart → Set₁ where
∣ˡ : ∀ {R x s}
{p₁ : ParserProg R} {p₂ : ParserProg R}
(x∈p₁ : x ∈⟦ p₁ ⟧· s) → x ∈⟦ p₁ ∣ p₂ ⟧· s
∣ʳ : ∀ {R x s}
{p₁ : ParserProg R} {p₂ : ParserProg R}
(x∈p₂ : x ∈⟦ p₂ ⟧· s) → x ∈⟦ p₁ ∣ p₂ ⟧· s
_⊛_ : ∀ {s₁ s₂ R₁ R₂ f x}
{p₁ : ParserProg (R₁ → R₂)}
{p₂ : ParserProg R₁}
(f∈p₁ : f ∈⟦ p₁ ⟧· s₁)
(x∈p₂ : x ∈⟦ p₂ ⟧· s₂) →
f x ∈⟦ p₁ ⊛ p₂ ⟧· s₁ ++ s₂
<$>_ : ∀ {s R₁ R₂ x} {f : R₁ → R₂} {p : ParserProg R₁}
(x∈p : x ∈⟦ p ⟧· s) → f x ∈⟦ f <$> p ⟧· s
+-[] : ∀ {R x s} {p : ParserProg R}
(x∈p : x ∈⟦ p ⟧· s) → [ x ] ∈⟦ p + ⟧· s
+-∷ : ∀ {R x s₁ s₂ xs} {p : ParserProg R}
(x∈p : x ∈⟦ p ⟧· s₁) (xs∈p : xs ∈⟦ p + ⟧· s₂) →
x ∷⁺ xs ∈⟦ p + ⟧· s₁ ++ s₂
between-[] : ∀ {R t} {p : ∞ (ParserProg R)} →
[] ∈⟦ p between (t ∷ []) ⟧· t ∷ []
between-∷ : ∀ {R n t x xs s₁ s₂}
{p : ∞ (ParserProg R)} {ts : Vec NamePart (suc n)}
(x∈p : x ∈⟦ ♭ p ⟧· s₁)
(xs∈⋯ : xs ∈⟦ p between ts ⟧· s₂) →
x ∷ xs ∈⟦ p between (t ∷ ts) ⟧· t ∷ s₁ ++ s₂
∥ˡ : ∀ {I i} {R : I → Set} {x s}
{p₁ : ParserProg (R i)}
{p₂ : ParserProg (∃ R)}
(x∈p₁ : x ∈⟦ p₁ ⟧· s) → (-, x) ∈⟦ p₁ ∥ p₂ ⟧· s
∥ʳ : ∀ {I i} {R : I → Set} {x s}
{p₁ : ParserProg (R i)}
{p₂ : ParserProg (∃ R)}
(x∈p₂ : x ∈⟦ p₂ ⟧· s) → x ∈⟦ p₁ ∥ p₂ ⟧· s
-- The semantics is correct. (Note that this proof only establishes
-- language equivalence, not parser equivalence; see
-- TotalParserCombinators.Semantics.)
private
drop-[] : ∀ {R s x} {p : Parser NamePart false R} →
x ∈ p · s ++ [] → x ∈ p · s
drop-[] = Sem.cast∈ refl refl (proj₂ LM.identity _)
add-[] : ∀ {R s x} {p : ParserProg R} →
x ∈⟦ p ⟧· s → x ∈⟦ p ⟧· s ++ []
add-[] {s = s} x∈p rewrite proj₂ LM.identity s = x∈p
⊛-complete : ∀ {s₁ s₂ R₁ R₂ f x}
(p₁ : ParserProg (R₁ → R₂)) {p₂ : ParserProg R₁} →
f ∈ ⟦ p₁ ⟧ · s₁ → x ∈ ⟦ p₂ ⟧ · s₂ →
f x ∈ ⟦ p₁ ⊛ p₂ ⟧ · s₁ ++ s₂
⊛-complete _ f∈p₁ x∈p₂ = f∈p₁ !>>= drop-[] (x∈p₂ !>>= return)
tok-sound : ∀ {t t′ s} →
t′ ∈ tok t · s →
t ≡ t′ × s ≡ t′ ∷ []
tok-sound {t} (_!>>=_ {x = t″} token t′∈) with t ≟ t″
tok-sound (token !>>= return) | yes t≈t″ = (t≈t″ , refl)
tok-sound (token !>>= ()) | no t≉t″
tok-complete : ∀ {t} → t ∈ tok t · t ∷ []
tok-complete {t} = token !>>= ok-lemma
where
ok-lemma : t ∈ TheToken.ok t t · []
ok-lemma with t ≟ t
... | yes refl = return
... | no t≢t with t≢t refl
... | ()
sound : ∀ {R x s} {p : ParserProg R} →
x ∈⟦ p ⟧· s → x ∈ ⟦ p ⟧ · s
sound (∣ˡ x∈p₁) = ∣ˡ (sound x∈p₁)
sound (∣ʳ x∈p₂) = ∣ʳ false (sound x∈p₂)
sound (_⊛_ {p₁ = p₁} f∈p₁ x∈p₂) = ⊛-complete p₁ (sound f∈p₁) (sound x∈p₂)
sound (<$> x∈p) = drop-[] (sound x∈p !>>= return)
sound (+-[] x∈p) = drop-[] (sound x∈p !>>= ∣ʳ false return)
sound (+-∷ x∈p xs∈p) = sound x∈p !>>= ∣ˡ (drop-[] (sound xs∈p !>>= return))
sound (∥ˡ x∈p₁) = drop-[] (∣ˡ {x = (-, _)} (sound x∈p₁ !>>= return))
sound (∥ʳ x∈p₂) = ∣ʳ false (sound x∈p₂)
sound between-[] = tok-complete !>>= return
sound (between-∷ {s₁ = s₁} {p = p} {ts = _ ∷ _} x∈p xs∈⋯) =
tok-complete !>>=
⊛-complete (_ <$> ♭ p) (drop-[] {s = s₁} (sound x∈p !>>= return)) (sound xs∈⋯)
complete : ∀ {R x s} (p : ParserProg R) →
x ∈ ⟦ p ⟧ · s → x ∈⟦ p ⟧· s
complete fail ()
complete (p₁ ∣ p₂) (∣ˡ x∈p₁) = ∣ˡ (complete p₁ x∈p₁)
complete (p₁ ∣ p₂) (∣ʳ .false x∈p₂) = ∣ʳ (complete p₂ x∈p₂)
complete (p₁ ⊛ p₂) (f∈p₁ !>>= (y∈p₂ !>>= return)) =
complete p₁ f∈p₁ ⊛ add-[] (complete p₂ y∈p₂)
complete (f <$> p) (x∈p !>>= return) = add-[] (<$> complete p x∈p)
complete (p +) (x∈p !>>= ∣ˡ (xs∈p+ !>>= return)) = +-∷ (complete p x∈p) (add-[] (complete (p +) xs∈p+))
complete (p +) (x∈p !>>= ∣ʳ .false return) = add-[] (+-[] (complete p x∈p))
complete (p between (t ∷ [])) (t∈ !>>= return) with tok-sound t∈
... | (refl , refl) = between-[]
complete (p between (t ∷ t′ ∷ ts))
(t∈ !>>= (x∈p !>>= return !>>= (xs∈ !>>= return))) with tok-sound t∈
... | (refl , refl) =
between-∷ (add-[] (complete (♭ p) x∈p))
(add-[] (complete (p between (t′ ∷ ts)) xs∈))
complete (p₁ ∥ p₂) (∣ˡ (x∈p₁ !>>= return)) = add-[] (∥ˡ (complete p₁ x∈p₁))
complete (p₁ ∥ p₂) (∣ʳ .false x∈p₂) = ∥ʳ (complete p₂ x∈p₂)
------------------------------------------------------------------------
-- A variant of the semantics
-- The alternative semantics defined below may be slightly harder to
-- understand, but it is (language) equivalent to the one above, and
-- it simplifies the proof in Mixfix.Acyclic.Show.
module Semantics-⊕ where
infix 60 <$>_
infixl 50 _⊛_
infix 4 _⊕_∈⟦_⟧·_
data _⊕_∈⟦_⟧·_ : ∀ {R} →
R → List NamePart → ParserProg R → List NamePart → Set1 where
∣ˡ : ∀ {R x s s₁}
{p₁ : ParserProg R} {p₂ : ParserProg R}
(x∈p₁ : x ⊕ s₁ ∈⟦ p₁ ⟧· s) → x ⊕ s₁ ∈⟦ p₁ ∣ p₂ ⟧· s
∣ʳ : ∀ {R x s s₁}
{p₁ : ParserProg R} {p₂ : ParserProg R}
(x∈p₂ : x ⊕ s₁ ∈⟦ p₂ ⟧· s) → x ⊕ s₁ ∈⟦ p₁ ∣ p₂ ⟧· s
_⊛_ : ∀ {s s₁ s₂ R₁ R₂ f x}
{p₁ : ParserProg (R₁ → R₂)} {p₂ : ParserProg R₁}
(f∈p₁ : f ⊕ s₁ ∈⟦ p₁ ⟧· s) (x∈p₂ : x ⊕ s₂ ∈⟦ p₂ ⟧· s₁) →
f x ⊕ s₂ ∈⟦ p₁ ⊛ p₂ ⟧· s
<$>_ : ∀ {s s′ R₁ R₂ x} {f : R₁ → R₂} {p : ParserProg R₁}
(x∈p : x ⊕ s′ ∈⟦ p ⟧· s) → f x ⊕ s′ ∈⟦ f <$> p ⟧· s
+-[] : ∀ {R x s s₁} {p : ParserProg R}
(x∈p : x ⊕ s₁ ∈⟦ p ⟧· s) → [ x ] ⊕ s₁ ∈⟦ p + ⟧· s
+-∷ : ∀ {R x s s₁ s₂ xs} {p : ParserProg R}
(x∈p : x ⊕ s₁ ∈⟦ p ⟧· s) (xs∈p : xs ⊕ s₂ ∈⟦ p + ⟧· s₁) →
x ∷⁺ xs ⊕ s₂ ∈⟦ p + ⟧· s
between-[] : ∀ {R t s} {p : ∞ (ParserProg R)} →
[] ⊕ s ∈⟦ p between (t ∷ []) ⟧· t ∷ s
between-∷ : ∀ {R n t x xs s s₁ s₂}
{p : ∞ (ParserProg R)} {ts : Vec NamePart (suc n)}
(x∈p : x ⊕ s₁ ∈⟦ ♭ p ⟧· s)
(xs∈⋯ : xs ⊕ s₂ ∈⟦ p between ts ⟧· s₁) →
x ∷ xs ⊕ s₂ ∈⟦ p between (t ∷ ts) ⟧· t ∷ s
∥ˡ : ∀ {I i} {R : I → Set} {x s s′}
{p₁ : ParserProg (R i)}
{p₂ : ParserProg (∃ R)}
(x∈p₁ : x ⊕ s′ ∈⟦ p₁ ⟧· s) →
(-, x) ⊕ s′ ∈⟦ p₁ ∥ p₂ ⟧· s
∥ʳ : ∀ {I i} {R : I → Set} {s s′ i′} {x : R i′}
{p₁ : ParserProg (R i)}
{p₂ : ParserProg (∃ R)}
(x∈p₂ : (-, x) ⊕ s′ ∈⟦ p₂ ⟧· s) →
(-, x) ⊕ s′ ∈⟦ p₁ ∥ p₂ ⟧· s
-- The semantics is correct.
⊛-complete : ∀ {s s₁ s₂ R₁ R₂ f x}
(p₁ : ParserProg (R₁ → R₂)) {p₂ : ParserProg R₁} →
f ⊕ s₁ ∈ ⟦ p₁ ⟧ · s → x ⊕ s₂ ∈ ⟦ p₂ ⟧ · s₁ →
f x ⊕ s₂ ∈ ⟦ p₁ ⊛ p₂ ⟧ · s
⊛-complete _ f∈p₁ x∈p₂ = f∈p₁ !>>= (x∈p₂ !>>= return)
tok-sound : ∀ {t t′ s₁ s} →
t′ ⊕ s₁ ∈ tok t · s →
t ≡ t′ × s ≡ t′ ∷ s₁
tok-sound ∈ with Sem.⊕-sound′ ∈
tok-sound ∈ | (s , refl , ∈′) with Semantics.tok-sound ∈′
tok-sound {t} ∈ | (.(t ∷ []) , refl , ∈′) | (refl , refl) = (refl , refl)
tok-complete : ∀ {t s} → t ⊕ s ∈ tok t · t ∷ s
tok-complete = Sem.⊕-complete′ (_ , refl , Semantics.tok-complete)
sound : ∀ {R x s s′} {p : ParserProg R} →
x ⊕ s′ ∈⟦ p ⟧· s → x ⊕ s′ ∈ ⟦ p ⟧ · s
sound (∣ˡ x∈p₁) = ∣ˡ (sound x∈p₁)
sound (∣ʳ x∈p₂) = ∣ʳ false (sound x∈p₂)
sound (_⊛_ {p₁ = p₁} f∈p₁ x∈p₂) = ⊛-complete p₁ (sound f∈p₁) (sound x∈p₂)
sound (<$> x∈p) = sound x∈p !>>= return
sound (+-[] x∈p) = sound x∈p !>>= ∣ʳ false return
sound (+-∷ x∈p xs∈p) = sound x∈p !>>= ∣ˡ (sound xs∈p !>>= return)
sound (∥ˡ x∈p₁) = ∣ˡ (sound x∈p₁ !>>= return)
sound (∥ʳ x∈p₂) = ∣ʳ false (sound x∈p₂)
sound between-[] = tok-complete !>>= return
sound (between-∷ {p = p} {ts = _ ∷ _} x∈p xs∈⋯) =
tok-complete !>>=
⊛-complete (_ <$> ♭ p) (sound x∈p !>>= return) (sound xs∈⋯)
complete : ∀ {R x s s′} (p : ParserProg R) →
x ⊕ s′ ∈ ⟦ p ⟧ · s → x ⊕ s′ ∈⟦ p ⟧· s
complete fail ()
complete (p₁ ∣ p₂) (∣ˡ x∈p₁) = ∣ˡ (complete p₁ x∈p₁)
complete (p₁ ∣ p₂) (∣ʳ .false x∈p₂) = ∣ʳ (complete p₂ x∈p₂)
complete (p₁ ⊛ p₂) (f∈p₁ !>>= (y∈p₂ !>>= return)) =
complete p₁ f∈p₁ ⊛ complete p₂ y∈p₂
complete (f <$> p) (x∈p !>>= return) = <$> complete p x∈p
complete (p +) (x∈p !>>= ∣ˡ (xs∈p+ !>>= return)) = +-∷ (complete p x∈p) (complete (p +) xs∈p+)
complete (p +) (x∈p !>>= ∣ʳ .false return) = +-[] (complete p x∈p)
complete (p between (t ∷ [])) (t∈ !>>= return) with tok-sound t∈
... | (refl , refl) = between-[]
complete (p between (t ∷ t′ ∷ ts))
(t∈ !>>= (x∈p !>>= return !>>= (xs∈ !>>= return))) with tok-sound t∈
... | (refl , refl) =
between-∷ (complete (♭ p) x∈p) (complete (p between (t′ ∷ ts)) xs∈)
complete (p₁ ∥ p₂) (∣ˡ (x∈p₁ !>>= return)) = ∥ˡ (complete p₁ x∈p₁)
complete (p₁ ∥ p₂) (∣ʳ .false x∈p₂) = ∥ʳ (complete p₂ x∈p₂)
-- Some lemmas.
+-∷ʳ : ∀ {R x s s₁ s₂ xs} {p : ParserProg R} →
xs ⊕ s₁ ∈⟦ p + ⟧· s → x ⊕ s₂ ∈⟦ p ⟧· s₁ →
xs ⁺∷ʳ x ⊕ s₂ ∈⟦ p + ⟧· s
+-∷ʳ {xs = _ ∷ ._} (+-[] x∈p) y∈p = +-∷ x∈p (+-[] y∈p)
+-∷ʳ {xs = _ ∷ ._} (+-∷ x∈p xs∈p) y∈p = +-∷ x∈p (+-∷ʳ xs∈p y∈p)
cast∈ : ∀ {R x₁ x₂ s s′} {p : ParserProg R} →
x₁ ≡ x₂ → x₁ ⊕ s′ ∈⟦ p ⟧· s → x₂ ⊕ s′ ∈⟦ p ⟧· s
cast∈ refl x∈p = x∈p
| {
"alphanum_fraction": 0.4403535588,
"avg_line_length": 40.7777777778,
"ext": "agda",
"hexsha": "84b99073ad1cbe080205c9572392d73be7162c21",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "Mixfix/Acyclic/Lib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "Mixfix/Acyclic/Lib.agda",
"max_line_length": 105,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "Mixfix/Acyclic/Lib.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 6139,
"size": 15047
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A Categorical view of the Sum type (Left-biased)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Level
module Data.Sum.Categorical.Left {a} (A : Set a) (b : Level) where
open import Data.Sum
open import Category.Functor
open import Category.Applicative
open import Category.Monad
import Function.Identity.Categorical as Id
open import Function
-- To minimize the universe level of the RawFunctor, we require that elements of
-- B are "lifted" to a copy of B at a higher universe level (a ⊔ b). See the
-- examples for how this is done.
------------------------------------------------------------------------
-- Left-biased monad instance for _⊎_
Sumₗ : Set (a ⊔ b) → Set (a ⊔ b)
Sumₗ B = A ⊎ B
functor : RawFunctor Sumₗ
functor = record { _<$>_ = map₂ }
applicative : RawApplicative Sumₗ
applicative = record
{ pure = inj₂
; _⊛_ = [ const ∘ inj₁ , map₂ ]′
}
-- The monad instance also requires some mucking about with universe levels.
monadT : RawMonadT (_∘′ Sumₗ)
monadT M = record
{ return = M.pure ∘ inj₂
; _>>=_ = λ ma f → ma M.>>= [ M.pure ∘′ inj₁ , f ]′
} where module M = RawMonad M
monad : RawMonad Sumₗ
monad = monadT Id.monad
------------------------------------------------------------------------
-- Get access to other monadic functions
module _ {F} (App : RawApplicative {a ⊔ b} F) where
open RawApplicative App
sequenceA : ∀ {A} → Sumₗ (F A) → F (Sumₗ A)
sequenceA (inj₁ a) = pure (inj₁ a)
sequenceA (inj₂ x) = inj₂ <$> x
mapA : ∀ {A B} → (A → F B) → Sumₗ A → F (Sumₗ B)
mapA f = sequenceA ∘ map₂ f
forA : ∀ {A B} → Sumₗ A → (A → F B) → F (Sumₗ B)
forA = flip mapA
module _ {M} (Mon : RawMonad {a ⊔ b} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM : ∀ {A} → Sumₗ (M A) → M (Sumₗ A)
sequenceM = sequenceA App
mapM : ∀ {A B} → (A → M B) → Sumₗ A → M (Sumₗ B)
mapM = mapA App
forM : ∀ {A B} → Sumₗ A → (A → M B) → M (Sumₗ B)
forM = forA App
| {
"alphanum_fraction": 0.5472589792,
"avg_line_length": 26.7848101266,
"ext": "agda",
"hexsha": "2bd7f2b11b73c6346c231c906abd4bdb6a1f7ddb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Categorical/Left.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Categorical/Left.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Sum/Categorical/Left.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 679,
"size": 2116
} |
{-# REWRITE #-}
| {
"alphanum_fraction": 0.4375,
"avg_line_length": 8,
"ext": "agda",
"hexsha": "5b21f0f1aaf284c00e0e74ee577cc8320f0d401b",
"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/Issue2592/A.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/Issue2592/A.agda",
"max_line_length": 15,
"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/Issue2592/A.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": 4,
"size": 16
} |
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}
module SAT-solver where
import 14-univalence
open 14-univalence public
{- The literates are atomic propositions or negations thereof. We simply use
the natural numbers to encode the atomic propositions, and we use the
booleans to tell whether it should be negated or not. -}
Literate = ℕ × bool
neg-Literate : Literate → Literate
neg-Literate (pair n b) = pair n (neg-𝟚 b)
zero-true-Literate : Literate
zero-true-Literate = pair zero-ℕ true
truth-value-Literate : (ℕ → bool) → Literate → bool
truth-value-Literate f (pair n true) = f n
truth-value-Literate f (pair n false) = neg-𝟚 (f n)
bool-Eq-ℕ : ℕ → ℕ → bool
bool-Eq-ℕ zero-ℕ zero-ℕ = true
bool-Eq-ℕ zero-ℕ (succ-ℕ n) = false
bool-Eq-ℕ (succ-ℕ m) zero-ℕ = false
bool-Eq-ℕ (succ-ℕ m) (succ-ℕ n) = bool-Eq-ℕ m n
bool-Eq-𝟚 : bool → bool → bool
bool-Eq-𝟚 true true = true
bool-Eq-𝟚 true false = false
bool-Eq-𝟚 false true = false
bool-Eq-𝟚 false false = true
bool-Eq-Literate : Literate → Literate → bool
bool-Eq-Literate (pair m x) (pair n y) =
conjunction-𝟚 (bool-Eq-ℕ m n) (bool-Eq-𝟚 x y)
{- Clauses are finite disjunctions of literates. We simply encode them using
lists of literates. -}
Clause = list Literate
clause-Literate : Literate → Clause
clause-Literate l = cons l nil
is-literate-Clause : Clause → UU lzero
is-literate-Clause c = Σ Literate (λ l → Id (clause-Literate l) c)
zero-true-Clause = clause-Literate zero-true-Literate
truth-value-Clause : (ℕ → bool) → Clause → bool
truth-value-Clause f nil = false
truth-value-Clause f (cons l c) =
disjunction-𝟚 (truth-value-Literate f l) (truth-value-Clause f c)
contains-Clause : Literate → Clause → bool
contains-Clause l nil = false
contains-Clause l (cons l' c) =
disjunction-𝟚 (bool-Eq-Literate l l') (contains-Clause l c)
if-then-else : {l : Level} {A : UU l} → bool → A → A → A
if-then-else true x y = x
if-then-else false x y = y
if-then-else-dep :
{l1 l2 : Level} {A : UU l1} (B : A → UU l2)
(b : bool) {x y : A} (u : Id b true → B x) (v : Id b false → B y) →
B (if-then-else b x y)
if-then-else-dep B true u v = u refl
if-then-else-dep B false u v = v refl
{- We write a function that simplifies a clause in the following way:
* simplified clauses do not contain any literate more than once.
* if a simplified clause contains a literate and its negation, then it is
of the form l ∨ ¬l. -}
simplify-Clause : Clause → Clause
simplify-Clause nil = nil
simplify-Clause (cons l c) =
if-then-else
( contains-Clause (neg-Literate l) c)
( cons l (cons (neg-Literate l) nil))
( if-then-else
( contains-Clause l c)
( simplify-Clause c)
( cons l (simplify-Clause c)))
is-satisfiable-Clause : Clause → UU lzero
is-satisfiable-Clause c = Σ (ℕ → bool) (λ f → Id (truth-value-Clause f c) true)
{- We show that any non-empty disjunctive clause is satisfiable. -}
right-true-law-disjunction-𝟚 : (b : bool) → Id (disjunction-𝟚 b true) true
right-true-law-disjunction-𝟚 true = refl
right-true-law-disjunction-𝟚 false = refl
left-true-law-disjunction-𝟚 : (b : bool) → Id (disjunction-𝟚 true b) true
left-true-law-disjunction-𝟚 true = refl
left-true-law-disjunction-𝟚 false = refl
is-satisfiable-cons-Clause :
( l : Literate) (c : Clause) → is-satisfiable-Clause (cons l c)
is-satisfiable-cons-Clause (pair n true) c =
pair
( const ℕ bool true)
( left-true-law-disjunction-𝟚 (truth-value-Clause (const ℕ bool true) c))
is-satisfiable-cons-Clause (pair n false) c =
pair
( const ℕ bool false)
( left-true-law-disjunction-𝟚 (truth-value-Clause (const ℕ bool false) c))
{- Formulas in conjunctive normal form are finite conjunctions of clauses, as
defined above. Therefore we encode them as lists of clauses. -}
CNF = list Clause
truth-value-CNF : (ℕ → bool) → CNF → bool
truth-value-CNF f nil = true
truth-value-CNF f (cons c φ) =
conjunction-𝟚 (truth-value-Clause f c) (truth-value-CNF f φ)
{- A formula φ is in conjunctive normal form is said to be satisfiable if there
is a map ℕ → bool which evaluates φ to true. -}
is-satisfiable-CNF : CNF → UU lzero
is-satisfiable-CNF φ = Σ (ℕ → bool) (λ f → Id (truth-value-CNF f φ) true)
contains-CNF : (l : Literate) (φ : CNF) → bool
contains-CNF l nil = false
contains-CNF l (cons c φ) =
disjunction-𝟚 (contains-Clause l c) (contains-CNF l φ)
contains
simplify-CNF : CNF → CNF
simplify-CNF nil = nil
simplify-CNF (cons c φ) = cons (simplify-Clause c) (simplify-CNF φ)
| {
"alphanum_fraction": 0.6858093126,
"avg_line_length": 31.9858156028,
"ext": "agda",
"hexsha": "56f84368a2d37da7c64c4c88351587fbabc4ccfb",
"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": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tmoux/HoTT-Intro",
"max_forks_repo_path": "Agda/SAT-solver.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "tmoux/HoTT-Intro",
"max_issues_repo_path": "Agda/SAT-solver.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tmoux/HoTT-Intro",
"max_stars_repo_path": "Agda/SAT-solver.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1501,
"size": 4510
} |
open import Data.Product using ( _,_ )
open import Data.Unit using ( ⊤ ; tt )
open import FRP.LTL.ISet.Core using ( ISet ; [_] ; _,_ )
module FRP.LTL.ISet.Unit where
T : ISet
T = [ (λ i → ⊤) , (λ i j i~j t → (tt , tt)) , (λ i j i⊑j t → tt) ]
| {
"alphanum_fraction": 0.5714285714,
"avg_line_length": 24.5,
"ext": "agda",
"hexsha": "ce7ebfa4feed4920f429d8e48a3f652e3ddcefda",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z",
"max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-frp-ltl",
"max_forks_repo_path": "src/FRP/LTL/ISet/Unit.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-frp-ltl",
"max_issues_repo_path": "src/FRP/LTL/ISet/Unit.agda",
"max_line_length": 66,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-frp-ltl",
"max_stars_repo_path": "src/FRP/LTL/ISet/Unit.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z",
"num_tokens": 95,
"size": 245
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Extensional pointwise lifting of relations to vectors
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Relation.Binary.Pointwise.Extensional where
open import Data.Fin using (zero; suc)
open import Data.Nat using (zero; suc)
open import Data.Vec as Vec hiding ([_]; head; tail; map)
open import Data.Vec.Relation.Binary.Pointwise.Inductive as Inductive
using ([]; _∷_)
renaming (Pointwise to IPointwise)
open import Level using (_⊔_)
open import Function using (_∘_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence as Equiv
using (_⇔_; ⇔-setoid; equivalence; module Equivalence)
open import Level using (_⊔_) renaming (zero to ℓ₀)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Binary.Construct.Closure.Transitive as Plus
hiding (equivalent; map)
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
record Pointwise {a b ℓ} {A : Set a} {B : Set b} (_∼_ : REL A B ℓ)
{n} (xs : Vec A n) (ys : Vec B n) : Set (a ⊔ b ⊔ ℓ)
where
constructor ext
field app : ∀ i → lookup xs i ∼ lookup ys i
------------------------------------------------------------------------
-- Operations
head : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ}
{n x y xs} {ys : Vec B n} →
Pointwise _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
head (ext app) = app zero
tail : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ}
{n x y xs} {ys : Vec B n} →
Pointwise _∼_ (x ∷ xs) (y ∷ ys) → Pointwise _∼_ xs ys
tail (ext app) = ext (app ∘ suc)
map : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ _∼′_ : REL A B ℓ} {n} →
_∼_ ⇒ _∼′_ → Pointwise _∼_ ⇒ Pointwise _∼′_ {n}
map ∼⇒∼′ xs∼ys = ext (∼⇒∼′ ∘ Pointwise.app xs∼ys)
gmap : ∀ {a b ℓ} {A : Set a} {B : Set b}
{_∼_ : Rel A ℓ} {_∼′_ : Rel B ℓ} {f : A → B} {n} →
_∼_ =[ f ]⇒ _∼′_ →
Pointwise _∼_ =[ Vec.map {n = n} f ]⇒ Pointwise _∼′_
gmap {_} ∼⇒∼′ {[]} {[]} xs∼ys = ext λ()
gmap {_∼′_ = _∼′_} ∼⇒∼′ {x ∷ xs} {y ∷ ys} xs∼ys = ext λ
{ zero → ∼⇒∼′ (head xs∼ys)
; (suc i) → Pointwise.app (gmap {_∼′_ = _∼′_} ∼⇒∼′ (tail xs∼ys)) i
}
------------------------------------------------------------------------
-- The inductive and extensional definitions are equivalent.
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
extensional⇒inductive : ∀ {n} {xs : Vec A n} {ys : Vec B n} →
Pointwise _∼_ xs ys → IPointwise _∼_ xs ys
extensional⇒inductive {zero} {[]} {[]} xs∼ys = []
extensional⇒inductive {suc n} {x ∷ xs} {y ∷ ys} xs∼ys =
(head xs∼ys) ∷ extensional⇒inductive (tail xs∼ys)
inductive⇒extensional : ∀ {n} {xs : Vec A n} {ys : Vec B n} →
IPointwise _∼_ xs ys → Pointwise _∼_ xs ys
inductive⇒extensional [] = ext λ()
inductive⇒extensional (x∼y ∷ xs∼ys) = ext λ
{ zero → x∼y
; (suc i) → Pointwise.app (inductive⇒extensional xs∼ys) i
}
equivalent : ∀ {n} {xs : Vec A n} {ys : Vec B n} →
Pointwise _∼_ xs ys ⇔ IPointwise _∼_ xs ys
equivalent = equivalence extensional⇒inductive inductive⇒extensional
------------------------------------------------------------------------
-- Relational properties
refl : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} →
∀ {n} → Reflexive _∼_ → Reflexive (Pointwise _∼_ {n = n})
refl ∼-rfl = ext (λ _ → ∼-rfl)
sym : ∀ {a b ℓ} {A : Set a} {B : Set b} {P : REL A B ℓ} {Q : REL B A ℓ}
{n} → Sym P Q → Sym (Pointwise P) (Pointwise Q {n = n})
sym sm xs∼ys = ext λ i → sm (Pointwise.app xs∼ys i)
trans : ∀ {a b c ℓ} {A : Set a} {B : Set b} {C : Set c}
{P : REL A B ℓ} {Q : REL B C ℓ} {R : REL A C ℓ} {n} →
Trans P Q R →
Trans (Pointwise P) (Pointwise Q) (Pointwise R {n = n})
trans trns xs∼ys ys∼zs = ext λ i →
trns (Pointwise.app xs∼ys i) (Pointwise.app ys∼zs i)
decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} →
Decidable _∼_ → ∀ {n} → Decidable (Pointwise _∼_ {n = n})
decidable dec xs ys = Dec.map
(Setoid.sym (⇔-setoid _) equivalent)
(Inductive.decidable dec xs ys)
isEquivalence : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} →
∀ {n} → IsEquivalence _∼_ →
IsEquivalence (Pointwise _∼_ {n = n})
isEquivalence equiv = record
{ refl = refl Eq.refl
; sym = sym Eq.sym
; trans = trans Eq.trans
} where module Eq = IsEquivalence equiv
isDecEquivalence : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} →
∀ {n} → IsDecEquivalence _∼_ →
IsDecEquivalence (Pointwise _∼_ {n = n})
isDecEquivalence decEquiv = record
{ isEquivalence = isEquivalence DecEq.isEquivalence
; _≟_ = decidable DecEq._≟_
} where module DecEq = IsDecEquivalence decEquiv
------------------------------------------------------------------------
-- Pointwise _≡_ is equivalent to _≡_.
module _ {a} {A : Set a} where
Pointwise-≡⇒≡ : ∀ {n} {xs ys : Vec A n} →
Pointwise _≡_ xs ys → xs ≡ ys
Pointwise-≡⇒≡ {zero} {[]} {[]} (ext app) = P.refl
Pointwise-≡⇒≡ {suc n} {x ∷ xs} {y ∷ ys} xs∼ys =
P.cong₂ _∷_ (head xs∼ys) (Pointwise-≡⇒≡ (tail xs∼ys))
≡⇒Pointwise-≡ : ∀ {n} {xs ys : Vec A n} →
xs ≡ ys → Pointwise _≡_ xs ys
≡⇒Pointwise-≡ P.refl = refl P.refl
Pointwise-≡↔≡ : ∀ {n} {xs ys : Vec A n} →
Pointwise _≡_ xs ys ⇔ xs ≡ ys
Pointwise-≡↔≡ {ℓ} {A} =
Equiv.equivalence Pointwise-≡⇒≡ ≡⇒Pointwise-≡
------------------------------------------------------------------------
-- Pointwise and Plus commute when the underlying relation is
-- reflexive.
module _ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} where
⁺∙⇒∙⁺ : ∀ {n} {xs ys : Vec A n} →
Plus (Pointwise _∼_) xs ys → Pointwise (Plus _∼_) xs ys
⁺∙⇒∙⁺ [ ρ≈ρ′ ] = ext (λ x → [ Pointwise.app ρ≈ρ′ x ])
⁺∙⇒∙⁺ (ρ ∼⁺⟨ ρ≈ρ′ ⟩ ρ′≈ρ″) = ext (λ x →
_ ∼⁺⟨ Pointwise.app (⁺∙⇒∙⁺ ρ≈ρ′ ) x ⟩
Pointwise.app (⁺∙⇒∙⁺ ρ′≈ρ″) x)
∙⁺⇒⁺∙ : ∀ {n} {xs ys : Vec A n} → Reflexive _∼_ →
Pointwise (Plus _∼_) xs ys → Plus (Pointwise _∼_) xs ys
∙⁺⇒⁺∙ rfl =
Plus.map (_⟨$⟩_ (Equivalence.from equivalent)) ∘
helper ∘
_⟨$⟩_ (Equivalence.to equivalent)
where
helper : ∀ {n} {xs ys : Vec A n} →
IPointwise (Plus _∼_) xs ys → Plus (IPointwise _∼_) xs ys
helper [] = [ [] ]
helper (_∷_ {x = x} {y = y} {xs = xs} {ys = ys} x∼y xs∼ys) =
x ∷ xs ∼⁺⟨ Plus.map (_∷ Inductive.refl rfl) x∼y ⟩
y ∷ xs ∼⁺⟨ Plus.map (rfl ∷_) (helper xs∼ys) ⟩∎
y ∷ ys ∎
-- ∙⁺⇒⁺∙ cannot be defined if the requirement of reflexivity
-- is dropped.
private
module Counterexample where
data D : Set where
i j x y z : D
data _R_ : Rel D ℓ₀ where
iRj : i R j
xRy : x R y
yRz : y R z
xR⁺z : x [ _R_ ]⁺ z
xR⁺z =
x ∼⁺⟨ [ xRy ] ⟩
y ∼⁺⟨ [ yRz ] ⟩∎
z ∎
ix : Vec D 2
ix = i ∷ x ∷ []
jz : Vec D 2
jz = j ∷ z ∷ []
ix∙⁺jz : IPointwise (Plus _R_) ix jz
ix∙⁺jz = [ iRj ] ∷ xR⁺z ∷ []
¬ix⁺∙jz : ¬ Plus′ (IPointwise _R_) ix jz
¬ix⁺∙jz [ iRj ∷ () ∷ [] ]
¬ix⁺∙jz ((iRj ∷ xRy ∷ []) ∷ [ () ∷ yRz ∷ [] ])
¬ix⁺∙jz ((iRj ∷ xRy ∷ []) ∷ (() ∷ yRz ∷ []) ∷ _)
counterexample :
¬ (∀ {n} {xs ys : Vec D n} →
Pointwise (Plus _R_) xs ys →
Plus (Pointwise _R_) xs ys)
counterexample ∙⁺⇒⁺∙ =
¬ix⁺∙jz (Equivalence.to Plus.equivalent ⟨$⟩
Plus.map (_⟨$⟩_ (Equivalence.to equivalent))
(∙⁺⇒⁺∙ (Equivalence.from equivalent ⟨$⟩ ix∙⁺jz)))
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
Pointwise-≡ = Pointwise-≡↔≡
{-# WARNING_ON_USAGE Pointwise-≡
"Warning: Pointwise-≡ was deprecated in v0.15.
Please use Pointwise-≡↔≡ instead."
#-}
| {
"alphanum_fraction": 0.4940759741,
"avg_line_length": 35.5956521739,
"ext": "agda",
"hexsha": "da9f1c527dba0b6a29ee6f7696f37221ab721fdb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Pointwise/Extensional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Pointwise/Extensional.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Relation/Binary/Pointwise/Extensional.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3209,
"size": 8187
} |
module IPC.Metatheory.Hilbert-BasicTarski where
open import IPC.Syntax.Hilbert public
open import IPC.Semantics.BasicTarski public
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (app t u) γ = (eval t γ) (eval u γ)
eval ci γ = I
eval ck γ = K
eval cs γ = S
eval cpair γ = _,_
eval cfst γ = π₁
eval csnd γ = π₂
eval unit γ = ∙
eval cboom γ = elim𝟘
eval cinl γ = ι₁
eval cinr γ = ι₂
eval ccase γ = elim⊎
-- Correctness of evaluation with respect to conversion.
eval✓ : ∀ {{_ : Model}} {A Γ} {t t′ : Γ ⊢ A} → t ⋙ t′ → eval t ≡ eval t′
eval✓ refl⋙ = refl
eval✓ (trans⋙ p q) = trans (eval✓ p) (eval✓ q)
eval✓ (sym⋙ p) = sym (eval✓ p)
eval✓ (congapp⋙ {A} {B} p q) = cong² (_⟦$⟧_ {A} {B}) (eval✓ p) (eval✓ q)
eval✓ (congi⋙ p) = cong I (eval✓ p)
eval✓ (congk⋙ p q) = cong² K (eval✓ p) (eval✓ q)
eval✓ (congs⋙ {A} {B} {C} p q r) = cong³ (⟦S⟧ {A} {B} {C}) (eval✓ p) (eval✓ q) (eval✓ r)
eval✓ (congpair⋙ {A} {B} p q) = cong² (_⟦,⟧_ {A} {B}) (eval✓ p) (eval✓ q)
eval✓ (congfst⋙ {A} {B} p) = cong (⟦π₁⟧ {A} {B}) (eval✓ p)
eval✓ (congsnd⋙ {A} {B} p) = cong (⟦π₂⟧ {A} {B}) (eval✓ p)
eval✓ (congboom⋙ {C} p) = cong (⟦elim𝟘⟧ {C}) (eval✓ p)
eval✓ (conginl⋙ {A} {B} p) = cong (⟦ι₁⟧ {A} {B}) (eval✓ p)
eval✓ (conginr⋙ {A} {B} p) = cong (⟦ι₂⟧ {A} {B}) (eval✓ p)
eval✓ (congcase⋙ {A} {B} {C} p q r) = cong³ (⟦celim⊎⟧ {A} {B} {C}) (eval✓ p) (eval✓ q) (eval✓ r)
eval✓ beta▻ₖ⋙ = refl
eval✓ beta▻ₛ⋙ = refl
eval✓ beta∧₁⋙ = refl
eval✓ beta∧₂⋙ = refl
eval✓ eta∧⋙ = refl
eval✓ eta⊤⋙ = refl
eval✓ beta∨₁⋙ = refl
eval✓ beta∨₂⋙ = refl
| {
"alphanum_fraction": 0.4485368315,
"avg_line_length": 39.64,
"ext": "agda",
"hexsha": "d36f621ee15dd4060ce18ccd625b6482a22d98f4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "IPC/Metatheory/Hilbert-BasicTarski.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "IPC/Metatheory/Hilbert-BasicTarski.agda",
"max_line_length": 96,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "IPC/Metatheory/Hilbert-BasicTarski.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 878,
"size": 1982
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Groups.Abelian.Definition
open import Groups.FiniteGroups.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Setoids.Setoids
open import Sets.FinSet.Definition
open import Sets.FinSet.Lemmas
open import Functions
open import Semirings.Definition
open import Numbers.Modulo.Definition
open import Numbers.Modulo.Addition
open import Orders.Total.Definition
open import Numbers.Modulo.ModuloFunction
open import Numbers.Integers.Definition
open import Numbers.Modulo.Group
open import Modules.Definition
open import Numbers.Integers.RingStructure.Ring
module Numbers.Modulo.ZModule {n : ℕ} (pr : 0 <N n) where
timesNat : ℕ → ℤn n pr → ℤn n pr
timesNat 0 b = record { x = 0 ; xLess = pr }
timesNat (succ x) b = _+n_ pr b (timesNat x b)
times : ℤ → ℤn n pr → ℤn n pr
times (nonneg x) b = timesNat x b
times (negSucc x) b = Group.inverse (ℤnGroup n pr) (timesNat (succ x) b)
dotDistributesLeft : (r : ℤ) → (x y : ℤn n pr) → times r ((_ +n x) y) ≡ (_ +n times r x) (times r y)
dotDistributesLeft (nonneg zero) x y = equalityCommutative (Group.identRight (ℤnGroup n pr))
dotDistributesLeft (nonneg (succ r)) x y rewrite dotDistributesLeft (nonneg r) x y = equalityZn (transitivity (equalityCommutative (modExtracts pr _ _)) (transitivity (applyEquality (mod n pr) (transitivity (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring (ℤn.x x) _ _)) (applyEquality (ℤn.x x +N_) (transitivity (Semiring.commutative ℕSemiring (ℤn.x y) _) (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring _ (ℤn.x (timesNat r y)) (ℤn.x y))) (applyEquality (ℤn.x (timesNat r x) +N_) (Semiring.commutative ℕSemiring (ℤn.x (timesNat r y)) (ℤn.x y))))))) (Semiring.+Associative ℕSemiring (ℤn.x x) _ _))) (modExtracts pr _ _)))
dotDistributesLeft (negSucc r) x y = {!!}
ZnZModule : Module ℤRing (ℤnAbGroup n pr) times
Module.dotWellDefined (ZnZModule) refl refl = refl
Module.dotDistributesLeft (ZnZModule) {r} {x} {y} = dotDistributesLeft r x y
Module.dotDistributesRight (ZnZModule) = {!!}
Module.dotAssociative (ZnZModule) = {!!}
Module.dotIdentity (ZnZModule) {record { x = x ; xLess = xLess }} = {!!}
| {
"alphanum_fraction": 0.7483815278,
"avg_line_length": 51.4888888889,
"ext": "agda",
"hexsha": "5915c027213ad78ff6485cfd7eba73b8f2349382",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Modulo/ZModule.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Modulo/ZModule.agda",
"max_line_length": 660,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Modulo/ZModule.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": 747,
"size": 2317
} |
------------------------------------------------------------------------------
-- Group theory properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module GroupTheory.PropertiesATP where
open import GroupTheory.Base
------------------------------------------------------------------------------
postulate leftCancellation : ∀ {a b c} → a · b ≡ a · c → b ≡ c
{-# ATP prove leftCancellation #-}
postulate rightIdentity : ∀ a → a · ε ≡ a
{-# ATP prove rightIdentity #-}
postulate rightInverse : ∀ a → a · a ⁻¹ ≡ ε
{-# ATP prove rightInverse #-}
postulate rightCancellation : ∀ {a b c} → b · a ≡ c · a → b ≡ c
{-# ATP prove rightCancellation #-}
postulate y≡x⁻¹[xy] : ∀ a b → b ≡ a ⁻¹ · (a · b)
{-# ATP prove y≡x⁻¹[xy] #-}
postulate x≡[xy]y⁻¹ : ∀ a b → a ≡ (a · b) · b ⁻¹
{-# ATP prove x≡[xy]y⁻¹ #-}
postulate rightIdentityUnique : ∀ r → (∀ a → a · r ≡ a) → r ≡ ε
{-# ATP prove rightIdentityUnique #-}
-- A more appropiate version to be used in the proofs.
postulate rightIdentityUnique' : ∀ a r → a · r ≡ a → r ≡ ε
{-# ATP prove rightIdentityUnique' #-}
postulate leftIdentityUnique : ∀ l → (∀ a → l · a ≡ a) → l ≡ ε
{-# ATP prove leftIdentityUnique #-}
-- A more appropiate version to be used in the proofs.
postulate leftIdentityUnique' : ∀ a l → l · a ≡ a → l ≡ ε
{-# ATP prove leftIdentityUnique' #-}
postulate
rightInverseUnique : ∀ {a} → ∃[ r ] (a · r ≡ ε) ∧ (∀ r' → a · r' ≡ ε → r ≡ r')
{-# ATP prove rightInverseUnique #-}
-- A more appropiate version to be used in the proofs.
postulate rightInverseUnique' : ∀ {a r} → a · r ≡ ε → a ⁻¹ ≡ r
{-# ATP prove rightInverseUnique' #-}
postulate
leftInverseUnique : ∀ {a} → ∃[ l ] (l · a ≡ ε) ∧ (∀ l' → l' · a ≡ ε → l ≡ l')
{-# ATP prove leftInverseUnique #-}
-- A more appropiate version to be used in the proofs.
postulate leftInverseUnique' : ∀ {a l} → l · a ≡ ε → a ⁻¹ ≡ l
{-# ATP prove leftInverseUnique' #-}
postulate ⁻¹-involutive : ∀ a → a ⁻¹ ⁻¹ ≡ a
{-# ATP prove ⁻¹-involutive #-}
postulate identityInverse : ε ⁻¹ ≡ ε
{-# ATP prove identityInverse #-}
postulate inverseDistributive : ∀ a b → (a · b) ⁻¹ ≡ b ⁻¹ · a ⁻¹
{-# ATP prove inverseDistributive #-}
-- The equation xa = b has an unique solution.
postulate
xa≡b-uniqueSolution : ∀ a b → ∃[ x ] (x · a ≡ b) ∧ (∀ x' → x' · a ≡ b → x ≡ x')
{-# ATP prove xa≡b-uniqueSolution #-}
-- The equation ax = b has an unique solution.
postulate
ax≡b-uniqueSolution : ∀ a b → ∃[ x ] (a · x ≡ b) ∧ (∀ x' → a · x' ≡ b → x ≡ x')
{-# ATP prove ax≡b-uniqueSolution #-}
-- If the square of every element is the identity, the system is
-- commutative. From: TPTP 6.4.0 problem GRP/GRP001-2.p.
postulate x²≡ε→comm : (∀ a → a · a ≡ ε) → ∀ {b c d} → b · c ≡ d → c · b ≡ d
{-# ATP prove x²≡ε→comm #-}
| {
"alphanum_fraction": 0.5384090133,
"avg_line_length": 33.6666666667,
"ext": "agda",
"hexsha": "a1b0b94f2c188784bd9bea34c7e109c38f49d218",
"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/GroupTheory/PropertiesATP.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/GroupTheory/PropertiesATP.agda",
"max_line_length": 81,
"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/GroupTheory/PropertiesATP.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": 941,
"size": 2929
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Ring.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary.Poset
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Ring.Base
open import Cubical.HITs.PropositionalTruncation
private
variable
ℓ ℓ' ℓ'' ℓ''' ℓ'''' : Level
{-
some basic calculations (used for example in QuotientRing.agda),
that should become obsolete or subject to change once we have a
ring solver (see https://github.com/agda/cubical/issues/297)
-}
module RingTheory (R' : Ring ℓ) where
open RingStr (snd R')
private R = ⟨ R' ⟩
implicitInverse : (x y : R)
→ x + y ≡ 0r
→ y ≡ - x
implicitInverse x y p =
y ≡⟨ sym (+Lid y) ⟩
0r + y ≡⟨ cong (λ u → u + y) (sym (+Linv x)) ⟩
(- x + x) + y ≡⟨ sym (+Assoc _ _ _) ⟩
(- x) + (x + y) ≡⟨ cong (λ u → (- x) + u) p ⟩
(- x) + 0r ≡⟨ +Rid _ ⟩
- x ∎
equalByDifference : (x y : R)
→ x - y ≡ 0r
→ x ≡ y
equalByDifference x y p =
x ≡⟨ sym (+Rid _) ⟩
x + 0r ≡⟨ cong (λ u → x + u) (sym (+Linv y)) ⟩
x + ((- y) + y) ≡⟨ +Assoc _ _ _ ⟩
(x - y) + y ≡⟨ cong (λ u → u + y) p ⟩
0r + y ≡⟨ +Lid _ ⟩
y ∎
0Selfinverse : - 0r ≡ 0r
0Selfinverse = sym (implicitInverse _ _ (+Rid 0r))
0Idempotent : 0r + 0r ≡ 0r
0Idempotent = +Lid 0r
+Idempotency→0 : (x : R) → x ≡ x + x → x ≡ 0r
+Idempotency→0 x p =
x ≡⟨ sym (+Rid x) ⟩
x + 0r ≡⟨ cong (λ u → x + u) (sym (+Rinv _)) ⟩
x + (x + (- x)) ≡⟨ +Assoc _ _ _ ⟩
(x + x) + (- x) ≡⟨ cong (λ u → u + (- x)) (sym p) ⟩
x + (- x) ≡⟨ +Rinv _ ⟩
0r ∎
-Idempotent : (x : R) → -(- x) ≡ x
-Idempotent x = - (- x) ≡⟨ sym (implicitInverse (- x) x (+Linv _)) ⟩
x ∎
0RightAnnihilates : (x : R) → x · 0r ≡ 0r
0RightAnnihilates x =
let x·0-is-idempotent : x · 0r ≡ x · 0r + x · 0r
x·0-is-idempotent =
x · 0r ≡⟨ cong (λ u → x · u) (sym 0Idempotent) ⟩
x · (0r + 0r) ≡⟨ ·Rdist+ _ _ _ ⟩
(x · 0r) + (x · 0r) ∎
in (+Idempotency→0 _ x·0-is-idempotent)
0LeftAnnihilates : (x : R) → 0r · x ≡ 0r
0LeftAnnihilates x =
let 0·x-is-idempotent : 0r · x ≡ 0r · x + 0r · x
0·x-is-idempotent =
0r · x ≡⟨ cong (λ u → u · x) (sym 0Idempotent) ⟩
(0r + 0r) · x ≡⟨ ·Ldist+ _ _ _ ⟩
(0r · x) + (0r · x) ∎
in +Idempotency→0 _ 0·x-is-idempotent
-DistR· : (x y : R) → x · (- y) ≡ - (x · y)
-DistR· x y = implicitInverse (x · y) (x · (- y))
(x · y + x · (- y) ≡⟨ sym (·Rdist+ _ _ _) ⟩
x · (y + (- y)) ≡⟨ cong (λ u → x · u) (+Rinv y) ⟩
x · 0r ≡⟨ 0RightAnnihilates x ⟩
0r ∎)
-DistL· : (x y : R) → (- x) · y ≡ - (x · y)
-DistL· x y = implicitInverse (x · y) ((- x) · y)
(x · y + (- x) · y ≡⟨ sym (·Ldist+ _ _ _) ⟩
(x - x) · y ≡⟨ cong (λ u → u · y) (+Rinv x) ⟩
0r · y ≡⟨ 0LeftAnnihilates y ⟩
0r ∎)
-Swap· : (x y : R) → (- x) · y ≡ x · (- y)
-Swap· _ _ = -DistL· _ _ ∙ sym (-DistR· _ _)
-IsMult-1 : (x : R) → - x ≡ (- 1r) · x
-IsMult-1 _ = sym (·Lid _) ∙ sym (-Swap· _ _)
-Dist : (x y : R) → (- x) + (- y) ≡ - (x + y)
-Dist x y =
implicitInverse _ _
((x + y) + ((- x) + (- y)) ≡⟨ sym (+Assoc _ _ _) ⟩
x + (y + ((- x) + (- y))) ≡⟨ cong
(λ u → x + (y + u))
(+Comm _ _) ⟩
x + (y + ((- y) + (- x))) ≡⟨ cong (λ u → x + u) (+Assoc _ _ _) ⟩
x + ((y + (- y)) + (- x)) ≡⟨ cong (λ u → x + (u + (- x)))
(+Rinv _) ⟩
x + (0r + (- x)) ≡⟨ cong (λ u → x + u) (+Lid _) ⟩
x + (- x) ≡⟨ +Rinv _ ⟩
0r ∎)
translatedDifference : (x a b : R) → a - b ≡ (x + a) - (x + b)
translatedDifference x a b =
a - b ≡⟨ cong (λ u → a + u)
(sym (+Lid _)) ⟩
(a + (0r + (- b))) ≡⟨ cong (λ u → a + (u + (- b)))
(sym (+Rinv _)) ⟩
(a + ((x + (- x)) + (- b))) ≡⟨ cong (λ u → a + u)
(sym (+Assoc _ _ _)) ⟩
(a + (x + ((- x) + (- b)))) ≡⟨ (+Assoc _ _ _) ⟩
((a + x) + ((- x) + (- b))) ≡⟨ cong (λ u → u + ((- x) + (- b)))
(+Comm _ _) ⟩
((x + a) + ((- x) + (- b))) ≡⟨ cong (λ u → (x + a) + u)
(-Dist _ _) ⟩
((x + a) - (x + b)) ∎
+Assoc-comm1 : (x y z : R) → x + (y + z) ≡ y + (x + z)
+Assoc-comm1 x y z = +Assoc x y z ∙∙ cong (λ x → x + z) (+Comm x y) ∙∙ sym (+Assoc y x z)
+Assoc-comm2 : (x y z : R) → x + (y + z) ≡ z + (y + x)
+Assoc-comm2 x y z = +Assoc-comm1 x y z ∙∙ cong (λ x → y + x) (+Comm x z) ∙∙ +Assoc-comm1 y z x
+ShufflePairs : (a b c d : R)
→ (a + b) + (c + d) ≡ (a + c) + (b + d)
+ShufflePairs a b c d =
(a + b) + (c + d) ≡⟨ +Assoc _ _ _ ⟩
((a + b) + c) + d ≡⟨ cong (λ u → u + d) (sym (+Assoc _ _ _)) ⟩
(a + (b + c)) + d ≡⟨ cong (λ u → (a + u) + d) (+Comm _ _) ⟩
(a + (c + b)) + d ≡⟨ cong (λ u → u + d) (+Assoc _ _ _) ⟩
((a + c) + b) + d ≡⟨ sym (+Assoc _ _ _) ⟩
(a + c) + (b + d) ∎
·-assoc2 : (x y z w : R) → (x · y) · (z · w) ≡ x · (y · z) · w
·-assoc2 x y z w = ·Assoc (x · y) z w ∙ cong (_· w) (sym (·Assoc x y z))
module RingHoms where
open IsRingHom
idRingHom : (R : Ring ℓ) → RingHom R R
fst (idRingHom R) = idfun (fst R)
snd (idRingHom R) = makeIsRingHom refl (λ _ _ → refl) (λ _ _ → refl)
compIsRingHom : {A : Ring ℓ} {B : Ring ℓ'} {C : Ring ℓ''}
{g : ⟨ B ⟩ → ⟨ C ⟩} {f : ⟨ A ⟩ → ⟨ B ⟩}
→ IsRingHom (B .snd) g (C .snd)
→ IsRingHom (A .snd) f (B .snd)
→ IsRingHom (A .snd) (g ∘ f) (C .snd)
compIsRingHom {g = g} {f} gh fh .pres0 = cong g (fh .pres0) ∙ gh .pres0
compIsRingHom {g = g} {f} gh fh .pres1 = cong g (fh .pres1) ∙ gh .pres1
compIsRingHom {g = g} {f} gh fh .pres+ x y = cong g (fh .pres+ x y) ∙ gh .pres+ (f x) (f y)
compIsRingHom {g = g} {f} gh fh .pres· x y = cong g (fh .pres· x y) ∙ gh .pres· (f x) (f y)
compIsRingHom {g = g} {f} gh fh .pres- x = cong g (fh .pres- x) ∙ gh .pres- (f x)
compRingHom : {R : Ring ℓ} {S : Ring ℓ'} {T : Ring ℓ''}
→ RingHom R S → RingHom S T → RingHom R T
fst (compRingHom f g) x = g .fst (f .fst x)
snd (compRingHom f g) = compIsRingHom (g .snd) (f .snd)
syntax compRingHom f g = g ∘r f
compIdRingHom : {R S : Ring ℓ} (φ : RingHom R S) → compRingHom (idRingHom R) φ ≡ φ
compIdRingHom φ = RingHom≡ refl
idCompRingHom : {R S : Ring ℓ} (φ : RingHom R S) → compRingHom φ (idRingHom S) ≡ φ
idCompRingHom φ = RingHom≡ refl
compAssocRingHom : {R S T U : Ring ℓ} (φ : RingHom R S) (ψ : RingHom S T) (χ : RingHom T U) →
compRingHom (compRingHom φ ψ) χ ≡ compRingHom φ (compRingHom ψ χ)
compAssocRingHom _ _ _ = RingHom≡ refl
module RingEquivs where
open RingStr
open IsRingHom
open RingHoms
compIsRingEquiv : {A : Ring ℓ} {B : Ring ℓ'} {C : Ring ℓ''}
{g : ⟨ B ⟩ ≃ ⟨ C ⟩} {f : ⟨ A ⟩ ≃ ⟨ B ⟩}
→ IsRingEquiv (B .snd) g (C .snd)
→ IsRingEquiv (A .snd) f (B .snd)
→ IsRingEquiv (A .snd) (compEquiv f g) (C .snd)
compIsRingEquiv {g = g} {f} gh fh = compIsRingHom {g = g .fst} {f .fst} gh fh
compRingEquiv : {A : Ring ℓ} {B : Ring ℓ'} {C : Ring ℓ''}
→ RingEquiv A B → RingEquiv B C → RingEquiv A C
fst (compRingEquiv f g) = compEquiv (f .fst) (g .fst)
snd (compRingEquiv f g) = compIsRingEquiv {g = g .fst} {f = f .fst} (g .snd) (f .snd)
isRingHomInv : {A : Ring ℓ} → {B : Ring ℓ'} → (e : RingEquiv A B) → IsRingHom (snd B) (invEq (fst e)) (snd A)
isRingHomInv {A = A} {B = B} e = makeIsRingHom
((cong g (sym (pres1 fcrh))) ∙ retEq et (1r (snd A)))
(λ x y → g (snd B ._+_ x y) ≡⟨ cong g (sym (cong₂ (snd B ._+_) (secEq et x) (secEq et y))) ⟩
g (snd B ._+_ (f (g x)) (f (g y))) ≡⟨ cong g (sym (pres+ fcrh (g x) (g y))) ⟩
g (f (snd A ._+_ (g x) (g y))) ≡⟨ retEq et (snd A ._+_ (g x) (g y)) ⟩
snd A ._+_ (g x) (g y) ∎)
(λ x y → g (snd B ._·_ x y) ≡⟨ cong g (sym (cong₂ (snd B ._·_) (secEq et x) (secEq et y))) ⟩
g (snd B ._·_ (f (g x)) (f (g y))) ≡⟨ cong g (sym (pres· fcrh (g x) (g y))) ⟩
g (f (snd A ._·_ (g x) (g y))) ≡⟨ retEq et (snd A ._·_ (g x) (g y)) ⟩
snd A ._·_ (g x) (g y) ∎)
where
et = fst e
f = fst et
fcrh = snd e
g = invEq et
invEquivRing : {A : Ring ℓ} → {B : Ring ℓ'} → RingEquiv A B → RingEquiv B A
fst (invEquivRing e) = invEquiv (fst e)
snd (invEquivRing e) = isRingHomInv e
module RingHomTheory {R S : Ring ℓ} (φ : RingHom R S) where
open RingTheory ⦃...⦄
open RingStr ⦃...⦄
open IsRingHom (φ .snd)
private
instance
_ = R
_ = S
_ = snd R
_ = snd S
f = fst φ
ker≡0→inj : ({x : ⟨ R ⟩} → f x ≡ 0r → x ≡ 0r)
→ ({x y : ⟨ R ⟩} → f x ≡ f y → x ≡ y)
ker≡0→inj ker≡0 {x} {y} p = equalByDifference _ _ (ker≡0 path)
where
path : f (x - y) ≡ 0r
path = f (x - y) ≡⟨ pres+ _ _ ⟩
f x + f (- y) ≡⟨ cong (f x +_) (pres- _) ⟩
f x - f y ≡⟨ cong (_- f y) p ⟩
f y - f y ≡⟨ +Rinv _ ⟩
0r ∎
-- the Ring version of uaCompEquiv
module RingUAFunctoriality where
open RingStr
open RingEquivs
Ring≡ : (A B : Ring ℓ) → (
Σ[ p ∈ ⟨ A ⟩ ≡ ⟨ B ⟩ ]
Σ[ q0 ∈ PathP (λ i → p i) (0r (snd A)) (0r (snd B)) ]
Σ[ q1 ∈ PathP (λ i → p i) (1r (snd A)) (1r (snd B)) ]
Σ[ r+ ∈ PathP (λ i → p i → p i → p i) (_+_ (snd A)) (_+_ (snd B)) ]
Σ[ r· ∈ PathP (λ i → p i → p i → p i) (_·_ (snd A)) (_·_ (snd B)) ]
Σ[ s ∈ PathP (λ i → p i → p i) (-_ (snd A)) (-_ (snd B)) ]
PathP (λ i → IsRing (q0 i) (q1 i) (r+ i) (r· i) (s i)) (isRing (snd A)) (isRing (snd B)))
≃ (A ≡ B)
Ring≡ A B = isoToEquiv theIso
where
open Iso
theIso : Iso _ _
fun theIso (p , q0 , q1 , r+ , r· , s , t) i = p i
, ringstr (q0 i) (q1 i) (r+ i) (r· i) (s i) (t i)
inv theIso x = cong ⟨_⟩ x , cong (0r ∘ snd) x , cong (1r ∘ snd) x
, cong (_+_ ∘ snd) x , cong (_·_ ∘ snd) x , cong (-_ ∘ snd) x , cong (isRing ∘ snd) x
rightInv theIso _ = refl
leftInv theIso _ = refl
caracRing≡ : {A B : Ring ℓ} (p q : A ≡ B) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracRing≡ {A = A} {B = B} p q P =
sym (transportTransport⁻ (ua (Ring≡ A B)) p)
∙∙ cong (transport (ua (Ring≡ A B))) helper
∙∙ transportTransport⁻ (ua (Ring≡ A B)) q
where
helper : transport (sym (ua (Ring≡ A B))) p ≡ transport (sym (ua (Ring≡ A B))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd B)) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsRing _ _ _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaCompRingEquiv : {A B C : Ring ℓ} (f : RingEquiv A B) (g : RingEquiv B C)
→ uaRing (compRingEquiv f g) ≡ uaRing f ∙ uaRing g
uaCompRingEquiv f g = caracRing≡ _ _ (
cong ⟨_⟩ (uaRing (compRingEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
cong ⟨_⟩ (uaRing f) ∙ cong ⟨_⟩ (uaRing g)
≡⟨ sym (cong-∙ ⟨_⟩ (uaRing f) (uaRing g)) ⟩
cong ⟨_⟩ (uaRing f ∙ uaRing g) ∎)
open RingEquivs
open RingUAFunctoriality
recPT→Ring : {A : Type ℓ'} (𝓕 : A → Ring ℓ)
→ (σ : ∀ x y → RingEquiv (𝓕 x) (𝓕 y))
→ (∀ x y z → σ x z ≡ compRingEquiv (σ x y) (σ y z))
------------------------------------------------------
→ ∥ A ∥ → Ring ℓ
recPT→Ring 𝓕 σ compCoh = rec→Gpd isGroupoidRing 𝓕
(3-ConstantCompChar 𝓕 (λ x y → uaRing (σ x y))
λ x y z → sym ( cong uaRing (compCoh x y z)
∙ uaCompRingEquiv (σ x y) (σ y z)))
| {
"alphanum_fraction": 0.4329202779,
"avg_line_length": 41.9249249249,
"ext": "agda",
"hexsha": "a66b40cf16b0f824f81ad56e44d36832ae5d5417",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/Ring/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/Ring/Properties.agda",
"max_line_length": 133,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/Ring/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5531,
"size": 13961
} |
module SystemF.Everything where
open import SystemF.Syntax public
open import SystemF.WellTyped public
open import SystemF.Substitutions.Lemmas public
open import SystemF.Substitutions public
open import SystemF.NormalForm public
open TypeLemmas public hiding (var)
| {
"alphanum_fraction": 0.8576779026,
"avg_line_length": 29.6666666667,
"ext": "agda",
"hexsha": "fcb8410f67ca0d6d3a36cea4ad8b5443c7ce92e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/SystemF/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/SystemF/Everything.agda",
"max_line_length": 47,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/SystemF/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 61,
"size": 267
} |
data Nat : Set where
zero : Nat
suc : Nat → Nat
test : ∀{N M : Nat} → Nat → Nat → Nat
test N M = {!.N N .M!}
| {
"alphanum_fraction": 0.5087719298,
"avg_line_length": 16.2857142857,
"ext": "agda",
"hexsha": "06f83433c237edf265a52384f6f40afe5e58d592",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/interaction/SplitOnHidden.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/interaction/SplitOnHidden.agda",
"max_line_length": 37,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/interaction/SplitOnHidden.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 46,
"size": 114
} |
module nodcap.NF.Show where
open import Data.String using (String)
open import nodcap.Base
open import nodcap.NF.Typing
import nodcap.Show as S
showTerm : {Γ : Environment} → ⊢ⁿᶠ Γ → String
showTerm {Γ} x = S.showTerm (fromNF x)
| {
"alphanum_fraction": 0.735042735,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "ca7575c06026778799e419538f037ffe955498b4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pepijnkokke/nodcap",
"max_forks_repo_path": "src/cpnd1/nodcap/NF/Show.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"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": "pepijnkokke/nodcap",
"max_issues_repo_path": "src/cpnd1/nodcap/NF/Show.agda",
"max_line_length": 45,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/nodcap",
"max_stars_repo_path": "src/cpnd1/nodcap/NF/Show.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z",
"num_tokens": 77,
"size": 234
} |
{-# OPTIONS --without-K --safe #-}
-- This module shows that D<: typing is undecidable.
module DsubTermUndec where
open import Data.List as List
open import Data.List.All as All
open import Data.Nat as ℕ
open import Data.Maybe as Maybe
open import Data.Product
open import Data.Sum
open import Data.Empty renaming (⊥ to False)
open import Data.Vec as Vec renaming (_∷_ to _‼_ ; [] to nil) hiding (_++_)
open import Function
open import Data.Maybe.Properties as Maybeₚ
open import Data.Nat.Properties as ℕₚ
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality as ≡
open import DsubDef
open import DsubFull
open import DsubReduced
open import Dsub renaming (_⊢_<:_ to _⊢′_<:_)
open import Utils
open import DsubEquivSimpler
module DifferentProof where
open import FsubMinus
open FsubMinus.FsubMinus hiding (_↑_)
open FsubMinusToDsubR
open Undecidability′
F<:⇒typing′ : ∀ {Γ S U} →
Γ ⊢F S <: U →
⟪ Γ ⟫ ⊢ val ⟨A= ⟦ S ⟧ ⟩ ∶ ⟨A: ⊥ ⋯ ⟦ U ⟧ ⟩
F<:⇒typing′ S<:U = <∶ ⟨A⟩-I (bnd ⊥<: (<:′⇒<: $ F<:⇒D<: S<:U))
bnd<:⇒F<:′ : ∀ {Γ S U} →
⟪ Γ ⟫ ⊢″ ⟨A: ⟦ S ⟧ ⋯ ⟦ S ⟧ ⟩ <: ⟨A: ⊥ ⋯ ⟦ U ⟧ ⟩ →
Γ ⊢F S <: U
bnd<:⇒F<:′ {Γ} {S} {U} bnd<: = helper
where open DsubInvProperties contraInvertible
cΓ = ⟪⟫-contraEnv Γ
helper : Γ ⊢F S <: U
helper with ⟨A:⟩<:⟨A:⟩ (<:⇒<:ᵢ (<:″⇒<: bnd<:) cΓ) cΓ
... | _ , S<:U = D<:⇒F<: $ <:ᵢ⇒<: S<:U
typing⇒F<:′ : ∀ {Γ S U} →
⟪ Γ ⟫ ⊢ val ⟨A= ⟦ S ⟧ ⟩ ∶ ⟨A: ⊥ ⋯ ⟦ U ⟧ ⟩ →
Γ ⊢F S <: U
typing⇒F<:′ typ = bnd<:⇒F<:′ $ <:⇒<:″ $ <:⇒<:′ (helper typ refl refl)
where helper : ∀ {Γ Γ′ S S′ T} →
Γ′ ⊢ val ⟨A= S′ ⟩ ∶ T →
Γ′ ≡ ⟪ Γ ⟫ → S′ ≡ ⟦ S ⟧ →
⟪ Γ ⟫ ⊢ ⟨A: ⟦ S ⟧ ⋯ ⟦ S ⟧ ⟩ <: T
helper ⟨A⟩-I eqΓ refl = refl
helper (<∶ typ x) refl eqS = tran _ (helper typ refl eqS) x
| {
"alphanum_fraction": 0.5140809012,
"avg_line_length": 32.55,
"ext": "agda",
"hexsha": "26a0de32b98eef4118f3ebb2e32ccb94e1e05551",
"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": "48214a55ebb484fd06307df4320813d4a002535b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "HuStmpHrrr/popl20-artifact",
"max_forks_repo_path": "agda/DsubTermUndec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"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": "HuStmpHrrr/popl20-artifact",
"max_issues_repo_path": "agda/DsubTermUndec.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "HuStmpHrrr/popl20-artifact",
"max_stars_repo_path": "agda/DsubTermUndec.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z",
"num_tokens": 817,
"size": 1953
} |
{-# OPTIONS --warning=error --safe --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Numbers.Integers.Integers
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Subtraction
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Order
open import Numbers.Naturals.Exponentiation
open import Numbers.Primes.PrimeNumbers
open import Maybe
open import Semirings.Definition
open import Numbers.Naturals.EuclideanAlgorithm
open import Sequences
open import Vectors
module LectureNotes.NumbersAndSets.Examples1 where
open Semiring ℕSemiring
open import Semirings.Solver ℕSemiring multiplicationNIsCommutative
private
abstract
q1Lemma1 : {q r : ℕ} → 3 *N succ q +N r ≡ succ (succ (succ (3 *N q +N r)))
q1Lemma1 {q} {r} rewrite sumZeroRight q | commutative q (succ q) | commutative q (succ (succ (q +N q))) | +Associative q q q = refl
q1Lemma : {n : ℕ} → (2 <N n) → ((3 ∣ n) || (3 ∣ (n +N 2))) || (3 ∣ (n +N 4))
q1Lemma {zero} ()
q1Lemma {succ zero} (le zero ())
q1Lemma {succ zero} (le (succ x) ())
q1Lemma {succ (succ zero)} (le (succ x) proof) rewrite Semiring.commutative ℕSemiring x 2 = exFalso (naughtE (equalityCommutative (succInjective (succInjective proof))))
q1Lemma {succ (succ (succ zero))} 2<n = inl (inl (aDivA 3))
q1Lemma {succ (succ (succ (succ zero)))} 2<n = inl (inr (divides (record { quot = 2 ; rem = zero ; pr = refl ; remIsSmall = inl (le 2 refl) ; quotSmall = inl (le 2 refl)}) refl))
q1Lemma {succ (succ (succ (succ (succ zero))))} 2<n = inr (divides (record { quot = 3 ; rem = zero ; pr = refl ; remIsSmall = inl (le 2 refl) ; quotSmall = inl (le 2 refl)}) refl)
q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n with q1Lemma {succ (succ (succ n))} (le n (applyEquality succ (Semiring.commutative ℕSemiring n 2)))
q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n | inl (inl (divides record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } x)) = inl (inl (divides (record { quot = succ quot ; rem = rem ; pr = transitivity (q1Lemma1 {quot} {rem}) (applyEquality (λ x → succ (succ (succ x))) pr) ; remIsSmall = remIsSmall ; quotSmall = inl (le 2 refl) }) x))
q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n | inl (inr (divides record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } x)) = inl (inr (divides record { quot = succ quot ; rem = rem ; pr = transitivity (q1Lemma1 {quot} {rem}) (applyEquality (λ x → succ (succ (succ x))) pr) ; remIsSmall = remIsSmall ; quotSmall = inl (le 2 refl) } x))
q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n | inr (divides record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } x) = inr (divides record { quot = succ quot ; rem = rem ; pr = transitivity (q1Lemma1 {quot} {rem}) (applyEquality (λ x → succ (succ (succ x))) pr) ; remIsSmall = remIsSmall ; quotSmall = inl (le 2 refl) } x)
q1 : {n : ℕ} → Prime n → Prime (n +N 2) → Prime (n +N 4) → n ≡ 3
q1 {succ zero} record { p>1 = (le zero ()) ; pr = pr } pN+2 pN+4
q1 {succ zero} record { p>1 = (le (succ x) ()) ; pr = pr } pN+2 pN+4
q1 {succ (succ zero)} pN record { p>1 = p>1 ; pr = pr } pN+4 with pr {2} (divides (record { quot = 2 ; rem = zero ; pr = refl ; remIsSmall = inl (le 1 refl) ; quotSmall = inl (le 1 refl)}) refl) (le 1 refl) (le 1 refl)
q1 {succ (succ zero)} pN record { p>1 = p>1 ; pr = pr } pN+4 | ()
q1 {succ (succ (succ n))} pN pN+2 pN+4 with q1Lemma {succ (succ (succ n))} (le n (applyEquality succ (commutative n 2)))
q1 {succ (succ (succ n))} pN pN+2 pN+4 | inl (inl 3|n) = equalityCommutative (primeDivPrimeImpliesEqual threeIsPrime pN 3|n)
q1 {succ (succ (succ n))} pN pN+2 pN+4 | inl (inr 3|n+2) with primeDivPrimeImpliesEqual threeIsPrime pN+2 3|n+2
... | bl rewrite commutative n 2 = exFalso (naughtE (succInjective (succInjective (succInjective bl))))
q1 {succ (succ (succ n))} pN pN+2 pN+4 | inr 3|n+4 with primeDivPrimeImpliesEqual threeIsPrime pN+4 3|n+4
... | bl rewrite commutative n 4 = exFalso (naughtE (succInjective (succInjective (succInjective bl))))
q3Differences : ℕ → ℕ
q3Differences a = 2 *N a
q3Seq : (start : ℕ) → ℕ → ℕ
q3Seq start zero = start
q3Seq start (succ n) = q3Differences (succ n) +N q3Seq start n
q3SeqFirst : take 5 (funcToSequence (q3Seq 41)) ≡ 41 ,- 43 ,- 47 ,- 53 ,- 61 ,- []
q3SeqFirst = refl
q3N : (start : ℕ) (a : ℕ) → q3Seq start a ≡ start +N (a +N (a *N a))
q3N start zero = equalityCommutative (sumZeroRight start)
q3N start (succ a) rewrite q3N start a | sumZeroRight a =
from (succ (plus (plus (const a) (succ (const a))) (plus (const start) (plus (const a) (times (const a) (const a))))))
to (plus (const start) (succ (plus (const a) (succ (plus (const a) (times (const a) (succ (const a))))))))
by applyEquality (λ i → succ (succ i)) (transitivity (+Associative (a +N a) start _) (transitivity (transitivity (applyEquality (_+N (a +N a *N a)) (commutative (a +N a) start)) (equalityCommutative (+Associative start _ _))) (applyEquality (start +N_) (equalityCommutative (+Associative a a (a +N a *N a))))))
q3NDivision : (start : ℕ) → start ∣ (q3Seq start start)
q3NDivision 0 = aDivA 0
q3NDivision (succ start) rewrite q3N (succ start) (succ start) = dividesBothImpliesDividesSum {succ start} {succ start} (aDivA (succ start)) (dividesBothImpliesDividesSum {succ start} {succ start} (aDivA (succ start)) (divides (record { quot = succ start ; rem = 0 ; pr = sumZeroRight _ ; remIsSmall = inl (succIsPositive start) ; quotSmall = inl (succIsPositive start) }) refl))
q3 : (start : ℕ) → ((n : ℕ) → Prime (q3Seq start n)) → False
q3 zero a with a 2
... | record { p>1 = p>1 ; pr = pr } with pr {2} (divides (record { quot = 3 ; rem = 0 ; pr = refl ; remIsSmall = inl (le 1 refl) ; quotSmall = inl (le 1 refl) }) refl) (le 3 refl) (succIsPositive 1)
... | ()
q3 (succ zero) a with a 0
... | record { p>1 = le zero () ; pr = pr }
... | record { p>1 = le (succ x) () ; pr = pr }
q3 (succ (succ start)) a with q3NDivision (succ (succ start))
... | r with a (succ (succ start))
... | s = compositeImpliesNotPrime (succ (succ start)) _ (succPreservesInequality (succIsPositive start)) (le (succ (succ start) +N ((start +N succ start) +N q3Seq (succ (succ start)) start)) (applyEquality (λ i → succ (succ i)) (from (succ (plus (plus (const start) (plus (plus (const start) (succ (const start))) (const (q3Seq (succ (succ start)) start)))) (succ (succ (const start))))) to plus (plus (const start) (succ (succ (plus (const start) zero)))) (succ (plus (plus (const start) (succ (plus (const start) zero))) (const (q3Seq (succ (succ start)) start)))) by applyEquality (λ i → succ (succ (succ (succ i)))) (transitivity (commutative _ start) (+Associative start start _))))) r s
q3' : ((n : ℕ) → Prime (q3Seq 41 n)) → False
q3' = q3 41
q6 : {n : ℕ} → 3 ∣ (n *N n) → 3 ∣ n
q6 {n} 3|n^2 with primesArePrime {3} {n} {n} threeIsPrime 3|n^2
q6 {n} 3|n^2 | inl x = x
q6 {n} 3|n^2 | inr x = x
_*q10_ : {a : ℕ} → {b : ℕ} → (0 <N a) → (0 <N b) → ℕ
*q10Pos : {a : ℕ} → {b : ℕ} → (0<a : 0 <N a) → (0<b : 0 <N b) → 0 <N (_*q10_ 0<a 0<b)
_*q10_ {succ zero} {succ b} 0<a 0<b = succ (succ b)
_*q10_ {succ (succ a)} {succ zero} 0<a 0<b = _*q10_ {succ a} {2} (le a (applyEquality succ (sumZeroRight a))) (le 1 refl)
_*q10_ {succ (succ a)} {succ (succ b)} 0<a 0<b = _*q10_ {succ a} {_*q10_ {succ (succ a)} {succ b} 0<a (le b (applyEquality succ (sumZeroRight b)))} (le a (applyEquality succ (sumZeroRight a))) (*q10Pos 0<a (le b (applyEquality succ (sumZeroRight b))))
*q10Pos {succ zero} {succ b} 0<a 0<b = le (succ b) (applyEquality (λ i → succ (succ i)) (sumZeroRight b))
*q10Pos {succ (succ a)} {succ zero} 0<a 0<b = *q10Pos (le a (applyEquality succ (sumZeroRight a))) (le 1 refl)
*q10Pos {succ (succ a)} {succ (succ b)} 0<a 0<b = *q10Pos (le a (applyEquality succ (sumZeroRight a))) (*q10Pos 0<a (le b (applyEquality succ (sumZeroRight b))))
| {
"alphanum_fraction": 0.6453944908,
"avg_line_length": 81.8673469388,
"ext": "agda",
"hexsha": "419293a8856d5918ffa79373db7a71e11d03baad",
"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": "LectureNotes/NumbersAndSets/Examples1.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": "LectureNotes/NumbersAndSets/Examples1.agda",
"max_line_length": 693,
"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": "LectureNotes/NumbersAndSets/Examples1.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": 2976,
"size": 8023
} |
{-
This second-order signature was created from the following second-order syntax description:
syntax Monoid | M
type
* : 0-ary
term
unit : * | ε
add : * * -> * | _⊕_ l20
theory
(εU⊕ᴸ) a |> add (unit, a) = a
(εU⊕ᴿ) a |> add (a, unit) = a
(⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))
-}
module Monoid.Signature where
open import SOAS.Context
open import SOAS.Common
open import SOAS.Syntax.Signature *T public
open import SOAS.Syntax.Build *T public
-- Operator symbols
data Mₒ : Set where
unitₒ addₒ : Mₒ
-- Term signature
M:Sig : Signature Mₒ
M:Sig = sig λ
{ unitₒ → ⟼₀ *
; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
}
open Signature M:Sig public
| {
"alphanum_fraction": 0.6096491228,
"avg_line_length": 16.6829268293,
"ext": "agda",
"hexsha": "4e3f5bfd55d65e62c09cf80586d0f514dc3c5d16",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Monoid/Signature.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Monoid/Signature.agda",
"max_line_length": 91,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Monoid/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 269,
"size": 684
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import Level using (0ℓ)
-- This module incldes various Agda lemmas that are independent of the project's domain
module LibraBFT.Lemmas where
cong₃ : ∀{a b c d}{A : Set a}{B : Set b}{C : Set c}{D : Set d}
→ (f : A → B → C → D) → ∀{x y u v m n} → x ≡ y → u ≡ v → m ≡ n
→ f x u m ≡ f y v n
cong₃ f refl refl refl = refl
≡-pi : ∀{a}{A : Set a}{x y : A}(p q : x ≡ y) → p ≡ q
≡-pi refl refl = refl
Unit-pi : {u1 u2 : Unit}
→ u1 ≡ u2
Unit-pi {unit} {unit} = refl
++-inj : ∀{a}{A : Set a}{m n o p : List A}
→ length m ≡ length n → m ++ o ≡ n ++ p
→ m ≡ n × o ≡ p
++-inj {m = []} {x ∷ n} () hip
++-inj {m = x ∷ m} {[]} () hip
++-inj {m = []} {[]} lhip hip
= refl , hip
++-inj {m = m ∷ ms} {n ∷ ns} lhip hip
with ++-inj {m = ms} {ns} (suc-injective lhip) (proj₂ (∷-injective hip))
...| (mn , op) rewrite proj₁ (∷-injective hip)
= cong (n ∷_) mn , op
++-abs : ∀{a}{A : Set a}{n : List A}(m : List A)
→ 1 ≤ length m → [] ≡ m ++ n → ⊥
++-abs [] ()
++-abs (x ∷ m) imp ()
data All-vec {ℓ} {A : Set ℓ} (P : A → Set ℓ) : ∀ {n} → Vec {ℓ} A n → Set (Level.suc ℓ) where
[] : All-vec P []
_∷_ : ∀ {x n} {xs : Vec A n} (px : P x) (pxs : All-vec P xs) → All-vec P (x ∷ xs)
≤-unstep : ∀{m n} → suc m ≤ n → m ≤ n
≤-unstep (s≤s ss) = ≤-step ss
≡⇒≤ : ∀{m n} → m ≡ n → m ≤ n
≡⇒≤ refl = ≤-refl
∈-cong : ∀{a b}{A : Set a}{B : Set b}{x : A}{l : List A}
→ (f : A → B) → x ∈ l → f x ∈ List-map f l
∈-cong f (here px) = here (cong f px)
∈-cong f (there hyp) = there (∈-cong f hyp)
All-self : ∀{a}{A : Set a}{xs : List A} → All (_∈ xs) xs
All-self = All-tabulate (λ x → x)
All-reduce⁺
: ∀{a b}{A : Set a}{B : Set b}{Q : A → Set}{P : B → Set}
→ { xs : List A }
→ (f : ∀{x} → Q x → B)
→ (∀{x} → (prf : Q x) → P (f prf))
→ (all : All Q xs)
→ All P (All-reduce f all)
All-reduce⁺ f hyp [] = []
All-reduce⁺ f hyp (ax ∷ axs) = (hyp ax) ∷ All-reduce⁺ f hyp axs
All-reduce⁻
: ∀{a b}{A : Set a}{B : Set b}
{Q : A → Set}
→ { xs : List A }
→ ∀ {vdq}
→ (f : ∀{x} → Q x → B)
→ (all : All Q xs)
→ vdq ∈ All-reduce f all
→ ∃[ v ] ∃[ v∈xs ] (vdq ≡ f {v} v∈xs)
All-reduce⁻ {Q = Q} {(h ∷ _)} {vdq} f (px ∷ pxs) (here refl) = h , px , refl
All-reduce⁻ {Q = Q} {(_ ∷ t)} {vdq} f (px ∷ pxs) (there vdq∈) = All-reduce⁻ {xs = t} f pxs vdq∈
List-index : ∀ {A : Set} → (_≟A_ : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)) → A → (l : List A) → Maybe (Fin (length l))
List-index _≟A_ x l with break (_≟A x) l
...| not≡ , _ with length not≡ <? length l
...| no _ = nothing
...| yes found = just ( fromℕ< {length not≡} {length l} found)
nats : ℕ → List ℕ
nats 0 = []
nats (suc n) = (nats n) ++ (n ∷ [])
_ : nats 4 ≡ 0 ∷ 1 ∷ 2 ∷ 3 ∷ []
_ = refl
_ : Maybe-map toℕ (List-index _≟_ 2 (nats 4)) ≡ just 2
_ = refl
_ : Maybe-map toℕ (List-index _≟_ 4 (nats 4)) ≡ nothing
_ = refl
allDistinct : ∀ {A : Set} → List A → Set
allDistinct l = ∀ (i j : Σ ℕ (_< length l)) →
proj₁ i ≡ proj₁ j
⊎ List-lookup l (fromℕ< (proj₂ i)) ≢ List-lookup l (fromℕ< (proj₂ j))
postulate -- TODO-1: currently unused; prove it, if needed
allDistinct? : ∀ {A : Set} → {≟A : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)} → (l : List A) → Dec (allDistinct l)
-- Extends an arbitrary relation to work on the head of
-- the supplied list, if any.
data OnHead {A : Set}(P : A → A → Set) (x : A) : List A → Set where
[] : OnHead P x []
on-∷ : ∀{y ys} → P x y → OnHead P x (y ∷ ys)
-- Establishes that a list is sorted according to the supplied
-- relation.
data IsSorted {A : Set}(_<_ : A → A → Set) : List A → Set where
[] : IsSorted _<_ []
_∷_ : ∀{x xs} → OnHead _<_ x xs → IsSorted _<_ xs → IsSorted _<_ (x ∷ xs)
OnHead-prop : ∀{A}(P : A → A → Set)(x : A)(l : List A)
→ Irrelevant P
→ isPropositional (OnHead P x l)
OnHead-prop P x [] hyp [] [] = refl
OnHead-prop P x (x₁ ∷ l) hyp (on-∷ x₂) (on-∷ x₃) = cong on-∷ (hyp x₂ x₃)
IsSorted-prop : ∀{A}(_<_ : A → A → Set)(l : List A)
→ Irrelevant _<_
→ isPropositional (IsSorted _<_ l)
IsSorted-prop _<_ [] hyp [] [] = refl
IsSorted-prop _<_ (x ∷ l) hyp (x₁ ∷ a) (x₂ ∷ b)
= cong₂ _∷_ (OnHead-prop _<_ x l hyp x₁ x₂)
(IsSorted-prop _<_ l hyp a b)
IsSorted-map⁻ : {A : Set}{_≤_ : A → A → Set}
→ {B : Set}(f : B → A)(l : List B)
→ IsSorted (λ x y → f x ≤ f y) l
→ IsSorted _≤_ (List-map f l)
IsSorted-map⁻ f .[] [] = []
IsSorted-map⁻ f .(_ ∷ []) (x ∷ []) = [] ∷ []
IsSorted-map⁻ f .(_ ∷ _ ∷ _) (on-∷ x ∷ (x₁ ∷ is)) = (on-∷ x) ∷ IsSorted-map⁻ f _ (x₁ ∷ is)
transOnHead : ∀ {A} {l : List A} {y x : A} {_<_ : A → A → Set}
→ Transitive _<_
→ OnHead _<_ y l
→ x < y
→ OnHead _<_ x l
transOnHead _ [] _ = []
transOnHead trans (on-∷ y<f) x<y = on-∷ (trans x<y y<f)
++-OnHead : ∀ {A} {xs ys : List A} {y : A} {_<_ : A → A → Set}
→ OnHead _<_ y xs
→ OnHead _<_ y ys
→ OnHead _<_ y (xs ++ ys)
++-OnHead [] y<y₁ = y<y₁
++-OnHead (on-∷ y<x) _ = on-∷ y<x
h∉t : ∀ {A} {t : List A} {h : A} {_<_ : A → A → Set}
→ Irreflexive _<_ _≡_ → Transitive _<_
→ IsSorted _<_ (h ∷ t)
→ h ∉ t
h∉t irfl trans (on-∷ h< ∷ sxs) (here refl) = ⊥-elim (irfl h< refl)
h∉t irfl trans (on-∷ h< ∷ (x₁< ∷ sxs)) (there h∈t)
= h∉t irfl trans ((transOnHead trans x₁< h<) ∷ sxs) h∈t
≤-head : ∀ {A} {l : List A} {x y : A} {_<_ : A → A → Set} {_≤_ : A → A → Set}
→ Reflexive _≤_ → Trans _<_ _≤_ _≤_
→ y ∈ (x ∷ l) → IsSorted _<_ (x ∷ l)
→ _≤_ x y
≤-head ref≤ trans (here refl) _ = ref≤
≤-head ref≤ trans (there y∈) (on-∷ x<x₁ ∷ sl) = trans x<x₁ (≤-head ref≤ trans y∈ sl)
-- TODO-1 : Better name and/or replace with library property
Any-sym : ∀ {a b}{A : Set a}{B : Set b}{tgt : B}{l : List A}{f : A → B}
→ Any (λ x → tgt ≡ f x) l
→ Any (λ x → f x ≡ tgt) l
Any-sym (here x) = here (sym x)
Any-sym (there x) = there (Any-sym x)
Any-lookup-correct : ∀ {a b}{A : Set a}{B : Set b}{tgt : B}{l : List A}{f : A → B}
→ (p : Any (λ x → f x ≡ tgt) l)
→ Any-lookup p ∈ l
Any-lookup-correct (here px) = here refl
Any-lookup-correct (there p) = there (Any-lookup-correct p)
Any-lookup-correctP : ∀ {a}{A : Set a}{l : List A}{P : A → Set}
→ (p : Any P l)
→ Any-lookup p ∈ l
Any-lookup-correctP (here px) = here refl
Any-lookup-correctP (there p) = there (Any-lookup-correctP p)
Any-witness : ∀ {a b} {A : Set a} {l : List A} {P : A → Set b}
→ (p : Any P l) → P (Any-lookup p)
Any-witness (here px) = px
Any-witness (there x) = Any-witness x
-- TODO-1: there is probably a library property for this.
∈⇒Any : ∀ {A : Set}{x : A}
→ {xs : List A}
→ x ∈ xs
→ Any (_≡ x) xs
∈⇒Any {x = x} (here refl) = here refl
∈⇒Any {x = x} {h ∷ t} (there xxxx) = there (∈⇒Any {xs = t} xxxx)
false≢true : false ≢ true
false≢true ()
witness : {A : Set}{P : A → Set}{x : A}{xs : List A}
→ x ∈ xs → All P xs → P x
witness x y = All-lookup y x
maybe-⊥ : ∀{a}{A : Set a}{x : A}{y : Maybe A}
→ y ≡ just x
→ y ≡ nothing
→ ⊥
maybe-⊥ () refl
Maybe-map-cool : ∀ {S S₁ : Set} {f : S → S₁} {x : Maybe S} {z}
→ Maybe-map f x ≡ just z
→ x ≢ nothing
Maybe-map-cool {x = nothing} ()
Maybe-map-cool {x = just y} prf = λ x → ⊥-elim (maybe-⊥ (sym x) refl)
Maybe-map-cool-1 : ∀ {S S₁ : Set} {f : S → S₁} {x : Maybe S} {z}
→ Maybe-map f x ≡ just z
→ Σ S (λ x' → f x' ≡ z)
Maybe-map-cool-1 {x = nothing} ()
Maybe-map-cool-1 {x = just y} {z = z} refl = y , refl
Maybe-map-cool-2 : ∀ {S S₁ : Set} {f : S → S₁} {x : S} {z}
→ f x ≡ z
→ Maybe-map f (just x) ≡ just z
Maybe-map-cool-2 {S}{S₁}{f}{x}{z} prf rewrite prf = refl
T⇒true : ∀ {a : Bool} → T a → a ≡ true
T⇒true {true} _ = refl
isJust : ∀ {A : Set}{aMB : Maybe A}{a : A}
→ aMB ≡ just a
→ Is-just aMB
isJust refl = just tt
to-witness-isJust-≡ : ∀ {A : Set}{aMB : Maybe A}{a prf}
→ to-witness (isJust {aMB = aMB} {a} prf) ≡ a
to-witness-isJust-≡ {aMB = just a'} {a} {prf}
with to-witness-lemma (isJust {aMB = just a'} {a} prf) refl
...| xxx = just-injective (trans (sym xxx) prf)
deMorgan : ∀ {A B : Set} → (¬ A) ⊎ (¬ B) → ¬ (A × B)
deMorgan (inj₁ ¬a) = λ a×b → ¬a (proj₁ a×b)
deMorgan (inj₂ ¬b) = λ a×b → ¬b (proj₂ a×b)
¬subst : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {P : A → Set ℓ₂}
→ {x y : A}
→ ¬ (P x)
→ y ≡ x
→ ¬ (P y)
¬subst px refl = px
∸-suc-≤ : ∀ (x w : ℕ) → suc x ∸ w ≤ suc (x ∸ w)
∸-suc-≤ x zero = ≤-refl
∸-suc-≤ zero (suc w) rewrite 0∸n≡0 w = z≤n
∸-suc-≤ (suc x) (suc w) = ∸-suc-≤ x w
m∸n≤o⇒m∸o≤n : ∀ (x z w : ℕ) → x ∸ z ≤ w → x ∸ w ≤ z
m∸n≤o⇒m∸o≤n x zero w p≤ rewrite m≤n⇒m∸n≡0 p≤ = z≤n
m∸n≤o⇒m∸o≤n zero (suc z) w p≤ rewrite 0∸n≡0 w = z≤n
m∸n≤o⇒m∸o≤n (suc x) (suc z) w p≤ = ≤-trans (∸-suc-≤ x w) (s≤s (m∸n≤o⇒m∸o≤n x z w p≤))
tail-⊆ : ∀ {A : Set} {x} {xs ys : List A}
→ (x ∷ xs) ⊆List ys
→ xs ⊆List ys
tail-⊆ xxs⊆ys x∈xs = xxs⊆ys (there x∈xs)
allDistinctTail : ∀ {A : Set} {x} {xs : List A}
→ allDistinct (x ∷ xs)
→ allDistinct xs
allDistinctTail allDist (i , i<l) (j , j<l)
with allDist (suc i , s≤s i<l) (suc j , s≤s j<l)
...| inj₁ 1+i≡1+j = inj₁ (cong pred 1+i≡1+j)
...| inj₂ lookup≢ = inj₂ lookup≢
∈-Any-Index-elim : ∀ {A : Set} {x y} {ys : List A} (x∈ys : x ∈ ys)
→ x ≢ y → y ∈ ys
→ y ∈ ys ─ Any-index x∈ys
∈-Any-Index-elim (here refl) x≢y (here refl) = ⊥-elim (x≢y refl)
∈-Any-Index-elim (here refl) _ (there y∈ys) = y∈ys
∈-Any-Index-elim (there _) _ (here refl) = here refl
∈-Any-Index-elim (there x∈ys) x≢y (there y∈ys) = there (∈-Any-Index-elim x∈ys x≢y y∈ys)
∉∧⊆List⇒∉ : ∀ {A : Set} {x} {xs ys : List A}
→ x ∉ xs → ys ⊆List xs
→ x ∉ ys
∉∧⊆List⇒∉ x∉xs ys∈xs x∈ys = ⊥-elim (x∉xs (ys∈xs x∈ys))
allDistinctʳʳ : ∀ {A : Set} {x x₁ : A} {xs : List A}
→ allDistinct (x ∷ x₁ ∷ xs)
→ allDistinct (x ∷ xs)
allDistinctʳʳ _ (zero , _) (zero , _) = inj₁ refl
allDistinctʳʳ allDist (zero , i<l) (suc j , j<l)
with allDist (0 , s≤s z≤n) (suc (suc j) , s≤s j<l)
...| inj₂ x≢lookup
= inj₂ λ x≡lkpxs → ⊥-elim (x≢lookup x≡lkpxs)
allDistinctʳʳ allDist (suc i , i<l) (zero , j<l)
with allDist (suc (suc i) , s≤s i<l) (0 , s≤s z≤n)
...| inj₂ x≢lookup
= inj₂ λ x≡lkpxs → ⊥-elim (x≢lookup x≡lkpxs)
allDistinctʳʳ allDist (suc i , i<l) (suc j , j<l)
with allDist (2 + i , (s≤s i<l)) (2 + j , s≤s j<l)
...| inj₁ si≡sj = inj₁ (cong pred si≡sj)
...| inj₂ lookup≡ = inj₂ lookup≡
allDistinct⇒∉ : ∀ {A : Set} {x} {xs : List A}
→ allDistinct (x ∷ xs)
→ x ∉ xs
allDistinct⇒∉ allDist (here x≡x₁)
with allDist (0 , s≤s z≤n) (1 , s≤s (s≤s z≤n))
... | inj₂ x≢x₁ = ⊥-elim (x≢x₁ x≡x₁)
allDistinct⇒∉ allDist (there x∈xs)
= allDistinct⇒∉ (allDistinctʳʳ allDist) x∈xs
sumListMap : ∀ {A : Set} {x} {xs : List A} (f : A → ℕ) → (x∈xs : x ∈ xs)
→ f-sum f xs ≡ f x + f-sum f (xs ─ Any-index x∈xs)
sumListMap _ (here refl) = refl
sumListMap {_} {x} {x₁ ∷ xs} f (there x∈xs)
rewrite sumListMap f x∈xs
| sym (+-assoc (f x) (f x₁) (f-sum f (xs ─ Any-index x∈xs)))
| +-comm (f x) (f x₁)
| +-assoc (f x₁) (f x) (f-sum f (xs ─ Any-index x∈xs)) = refl
lookup⇒Any : ∀ {A : Set} {xs : List A} {P : A → Set} (i : Fin (length xs))
→ P (List-lookup xs i) → Any P xs
lookup⇒Any {_} {_ ∷ _} zero px = here px
lookup⇒Any {_} {_ ∷ _} (suc i) px = there (lookup⇒Any i px)
x∉→AllDistinct : ∀ {A : Set} {x} {xs : List A}
→ allDistinct xs
→ x ∉ xs
→ allDistinct (x ∷ xs)
x∉→AllDistinct _ _ (0 , _) (0 , _) = inj₁ refl
x∉→AllDistinct _ x∉xs (0 , _) (suc j , j<l)
= inj₂ (λ x≡lkp → x∉xs (lookup⇒Any (fromℕ< (≤-pred j<l)) x≡lkp))
x∉→AllDistinct _ x∉xs (suc i , i<l) (0 , _)
= inj₂ (λ x≡lkp → x∉xs (lookup⇒Any (fromℕ< (≤-pred i<l)) (sym x≡lkp)))
x∉→AllDistinct allDist x∉xs (suc i , i<l) (suc j , j<l)
with allDist (i , (≤-pred i<l)) (j , (≤-pred j<l))
...| inj₁ i≡j = inj₁ (cong suc i≡j)
...| inj₂ lkup≢ = inj₂ lkup≢
module DecLemmas {A : Set} (_≟D_ : Decidable {A = A} (_≡_)) where
_∈?_ : ∀ (x : A) → (xs : List A) → Dec (Any (x ≡_) xs)
x ∈? xs = Any-any (x ≟D_) xs
y∉xs⇒Allxs≢y : ∀ {xs : List A} {x y}
→ y ∉ (x ∷ xs)
→ x ≢ y × y ∉ xs
y∉xs⇒Allxs≢y {xs} {x} {y} y∉
with y ∈? xs
...| yes y∈xs = ⊥-elim (y∉ (there y∈xs))
...| no y∉xs
with x ≟D y
...| yes x≡y = ⊥-elim (y∉ (here (sym x≡y)))
...| no x≢y = x≢y , y∉xs
⊆List-Elim : ∀ {x} {xs ys : List A} (x∈ys : x ∈ ys)
→ x ∉ xs → xs ⊆List ys
→ xs ⊆List ys ─ Any-index x∈ys
⊆List-Elim (here refl) x∉xs xs∈ys x₂∈xs
with xs∈ys x₂∈xs
...| here refl = ⊥-elim (x∉xs x₂∈xs)
...| there x∈xs = x∈xs
⊆List-Elim (there x∈ys) x∉xs xs∈ys x₂∈xxs
with x₂∈xxs
...| there x₂∈xs
= ⊆List-Elim (there x∈ys) (proj₂ (y∉xs⇒Allxs≢y x∉xs)) (tail-⊆ xs∈ys) x₂∈xs
...| here refl
with xs∈ys x₂∈xxs
...| here refl = here refl
...| there x₂∈ys
= there (∈-Any-Index-elim x∈ys (≢-sym (proj₁ (y∉xs⇒Allxs≢y x∉xs))) x₂∈ys)
sum-⊆-≤ : ∀ {ys} (xs : List A) (f : A → ℕ)
→ allDistinct xs
→ xs ⊆List ys
→ f-sum f xs ≤ f-sum f ys
sum-⊆-≤ [] _ _ _ = z≤n
sum-⊆-≤ (x ∷ xs) f dxs xs⊆ys
rewrite sumListMap f (xs⊆ys (here refl))
= let x∉xs = allDistinct⇒∉ dxs
xs⊆ysT = tail-⊆ xs⊆ys
xs⊆ys-x = ⊆List-Elim (xs⊆ys (here refl)) x∉xs xs⊆ysT
disTail = allDistinctTail dxs
in +-monoʳ-≤ (f x) (sum-⊆-≤ xs f disTail xs⊆ys-x)
intersect : List A → List A → List A
intersect xs [] = []
intersect xs (y ∷ ys)
with y ∈? xs
...| yes _ = y ∷ intersect xs ys
...| no _ = intersect xs ys
union : List A → List A → List A
union xs [] = xs
union xs (y ∷ ys)
with y ∈? xs
...| yes _ = union xs ys
...| no _ = y ∷ union xs ys
∈-intersect : ∀ (xs ys : List A) {α}
→ α ∈ intersect xs ys
→ α ∈ xs × α ∈ ys
∈-intersect xs (y ∷ ys) α∈int
with y ∈? xs | α∈int
...| no y∉xs | α∈ = ×-map₂ there (∈-intersect xs ys α∈)
...| yes y∈xs | here refl = y∈xs , here refl
...| yes y∈xs | there α∈ = ×-map₂ there (∈-intersect xs ys α∈)
x∉⇒x∉intersect : ∀ {x} {xs ys : List A}
→ x ∉ xs ⊎ x ∉ ys
→ x ∉ intersect xs ys
x∉⇒x∉intersect {x} {xs} {ys} x∉ x∈int
= contraposition (∈-intersect xs ys) (deMorgan x∉) x∈int
intersectDistinct : ∀ (xs ys : List A)
→ allDistinct xs → allDistinct ys
→ allDistinct (intersect xs ys)
intersectDistinct xs (y ∷ ys) dxs dys
with y ∈? xs
...| yes y∈xs = let distTail = allDistinctTail dys
intDTail = intersectDistinct xs ys dxs distTail
y∉intTail = x∉⇒x∉intersect (inj₂ (allDistinct⇒∉ dys))
in x∉→AllDistinct intDTail y∉intTail
...| no y∉xs = intersectDistinct xs ys dxs (allDistinctTail dys)
x∉⇒x∉union : ∀ {x} {xs ys : List A}
→ x ∉ xs × x ∉ ys
→ x ∉ union xs ys
x∉⇒x∉union {_} {_} {[]} (x∉xs , _) x∈∪ = ⊥-elim (x∉xs x∈∪)
x∉⇒x∉union {x} {xs} {y ∷ ys} (x∉xs , x∉ys) x∈union
with y ∈? xs | x∈union
...| yes y∈xs | x∈∪
= ⊥-elim (x∉⇒x∉union (x∉xs , (proj₂ (y∉xs⇒Allxs≢y x∉ys))) x∈∪)
...| no y∉xs | here refl
= ⊥-elim (proj₁ (y∉xs⇒Allxs≢y x∉ys) refl)
...| no y∉xs | there x∈∪
= ⊥-elim (x∉⇒x∉union (x∉xs , (proj₂ (y∉xs⇒Allxs≢y x∉ys))) x∈∪)
unionDistinct : ∀ (xs ys : List A)
→ allDistinct xs → allDistinct ys
→ allDistinct (union xs ys)
unionDistinct xs [] dxs dys = dxs
unionDistinct xs (y ∷ ys) dxs dys
with y ∈? xs
...| yes y∈xs = unionDistinct xs ys dxs (allDistinctTail dys)
...| no y∉xs = let distTail = allDistinctTail dys
uniDTail = unionDistinct xs ys dxs distTail
y∉intTail = x∉⇒x∉union (y∉xs , allDistinct⇒∉ dys)
in x∉→AllDistinct uniDTail y∉intTail
sumIntersect≤ : ∀ (xs ys : List A) (f : A → ℕ)
→ f-sum f (intersect xs ys) ≤ f-sum f (xs ++ ys)
sumIntersect≤ _ [] _ = z≤n
sumIntersect≤ xs (y ∷ ys) f
with y ∈? xs
...| yes y∈xs rewrite map-++-commute f xs (y ∷ ys)
| sum-++-commute (List-map f xs) (List-map f (y ∷ ys))
| sym (+-assoc (f-sum f xs) (f y) (f-sum f ys))
| +-comm (f-sum f xs) (f y)
| +-assoc (f y) (f-sum f xs) (f-sum f ys)
| sym (sum-++-commute (List-map f xs) (List-map f ys))
| sym (map-++-commute f xs ys)
= +-monoʳ-≤ (f y) (sumIntersect≤ xs ys f)
...| no y∉xs rewrite map-++-commute f xs (y ∷ ys)
| sum-++-commute (List-map f xs) (List-map f (y ∷ ys))
| +-comm (f y) (f-sum f ys)
| sym (+-assoc (f-sum f xs) (f-sum f ys) (f y))
| sym (sum-++-commute (List-map f xs) (List-map f ys))
| sym (map-++-commute f xs ys)
= ≤-stepsʳ (f y) (sumIntersect≤ xs ys f)
| {
"alphanum_fraction": 0.4728523099,
"avg_line_length": 37.33126294,
"ext": "agda",
"hexsha": "4e46b3a6ba5ffde39fd34151e06639028c537ed3",
"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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Lemmas.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"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": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Lemmas.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7804,
"size": 18031
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
module Haskell.Modules.Eq where
open import Haskell.Modules.ToBool
------------------------------------------------------------------------------
open import Data.Bool hiding (_≟_; not)
open import Data.List as DL
open import Data.Maybe using (Maybe; just; nothing)
import Data.Nat as DN
open import Function using (_$_; _∘_)
import Relation.Binary.PropositionalEquality as PE using (_≡_; refl)
import Relation.Nullary as RN
record Eq {a} (A : Set a) : Set a where
infix 4 _≟_ _==_ _/=_
field
_≟_ : (a b : A) → RN.Dec (a PE.≡ b)
_==_ : A → A → Bool
a == b = toBool $ a ≟ b
_/=_ : A → A → Bool
a /= b = not (a == b)
open Eq ⦃ ... ⦄ public
import Data.List.Relation.Unary.Any as Any using (any)
elem : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → A → DL.List A → Bool
elem x = toBool ∘ Any.any (x ≟_)
instance
Eq-Nat : Eq DN.ℕ
Eq._≟_ Eq-Nat = DN._≟_
Eq-Maybe : ∀ {a} {A : Set a} ⦃ _ : Eq A ⦄ → Eq (Maybe A)
Eq._≟_ Eq-Maybe nothing nothing = RN.yes PE.refl
Eq._≟_ Eq-Maybe (just _) nothing = RN.no λ ()
Eq._≟_ Eq-Maybe nothing (just _) = RN.no λ ()
Eq._≟_ Eq-Maybe (just a) (just b)
with a ≟ b
... | RN.no proof = RN.no λ where PE.refl → proof PE.refl
... | RN.yes PE.refl = RN.yes PE.refl
| {
"alphanum_fraction": 0.5575221239,
"avg_line_length": 32.2857142857,
"ext": "agda",
"hexsha": "4d8824685a5bd83a2547f19d78a0620c10f8d129",
"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/Haskell/Modules/Eq.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/Haskell/Modules/Eq.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/Haskell/Modules/Eq.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 517,
"size": 1582
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Cat.Facts.Exponential where
open import Data.Product using (_,_)
open import Level using (_⊔_)
open import Relation.Binary using (IsEquivalence)
open import Cats.Bifunctor using
(Bifunctor ; Bifunctor→Functor₁ ; transposeBifunctor₁ ; transposeBifunctor₁-resp)
open import Cats.Category
open import Cats.Category.Cat as Cat′ using
(Cat ; Functor ; _∘_ ; _≈_) renaming
(id to Id)
open import Cats.Category.Cat.Facts.Product using (hasBinaryProducts ; ⟨_×_⟩)
open import Cats.Category.Fun using (_↝_ ; Trans ; ≈-intro ; ≈-elim)
open import Cats.Category.Fun.Facts.Iso using (≈→≅)
open import Cats.Category.Product.Binary using (_×_)
open import Cats.Trans.Iso as NatIso using (NatIso)
open import Cats.Util.Conv
import Cats.Category.Base as Base
import Cats.Category.Constructions.Unique as Unique
import Cats.Category.Constructions.Iso as Iso
open Functor
open Trans
open Iso.Iso
private
module Cat≈ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
= IsEquivalence (Cat′.equiv {C = C} {D})
module Fun {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
= Category (C ↝ D)
module _ {lo la l≈ lo′ la′ l≈′}
{B : Category lo la l≈} {C : Category lo′ la′ l≈′}
where
private
module B = Category B
module C = Category C
Eval : Bifunctor (B ↝ C) B C
Eval = record
{ fobj = λ where
(F , x) → fobj F x
; fmap = λ where
{F , a} {G , b} (θ , f) → fmap G f C.∘ component θ a
; fmap-resp = λ where
{F , a} {G , b} {θ , f} {ι , g} (θ≈ι , f≈g) →
C.∘-resp (fmap-resp G f≈g) (≈-elim θ≈ι)
; fmap-id = λ { {F , b} → C.≈.trans (C.∘-resp-l (fmap-id F)) C.id-l }
; fmap-∘ = λ where
{F , a} {G , b} {H , c} {θ , f} {ι , g} →
begin
(fmap H f C.∘ component θ b) C.∘ (fmap G g C.∘ component ι a)
≈⟨ C.∘-resp-l (C.≈.sym (natural θ)) ⟩
(component θ c C.∘ fmap G f) C.∘ (fmap G g C.∘ component ι a)
≈⟨ C.assoc ⟩
component θ c C.∘ fmap G f C.∘ (fmap G g C.∘ component ι a)
≈⟨ C.∘-resp-r C.unassoc ⟩
component θ c C.∘ (fmap G f C.∘ fmap G g) C.∘ component ι a
≈⟨ C.∘-resp-r (C.∘-resp-l (fmap-∘ G)) ⟩
component θ c C.∘ fmap G (f B.∘ g) C.∘ component ι a
≈⟨ C.unassoc ⟩
(component θ c C.∘ fmap G (f B.∘ g)) C.∘ component ι a
≈⟨ C.∘-resp-l (natural θ) ⟩
(fmap H (f B.∘ g) C.∘ component θ a) C.∘ component ι a
≈⟨ C.assoc ⟩
fmap H (f B.∘ g) C.∘ component θ a C.∘ component ι a
∎
}
where
open C.≈-Reasoning
module _ {lo la l≈ lo′ la′ l≈′ lo″ la″ l≈″}
{B : Category lo la l≈} {C : Category lo′ la′ l≈′} {D : Category lo″ la″ l≈″}
where
private
module B = Category B
module C = Category C
module D = Category D
Curry : Bifunctor B C D → Functor B (C ↝ D)
Curry F = transposeBifunctor₁ F
Curry-resp : ∀ {F G} → F ≈ G → Curry F ≈ Curry G
Curry-resp = transposeBifunctor₁-resp
Curry-correct : ∀ {F} → Eval ∘ ⟨ Curry F × Id ⟩ ≈ F
Curry-correct {F} = record
{ iso = D.≅.refl
; forth-natural = λ where
{a , a′} {b , b′} {f , f′} →
begin
D.id D.∘ fmap F (B.id , f′) D.∘ fmap F (f , C.id)
≈⟨ D.≈.trans D.id-l (fmap-∘ F) ⟩
fmap F (B.id B.∘ f , f′ C.∘ C.id)
≈⟨ fmap-resp F (B.id-l , C.id-r) ⟩
fmap F (f , f′)
≈⟨ D.≈.sym D.id-r ⟩
fmap F (f , f′) D.∘ D.id
∎
}
where
open D.≈-Reasoning
Curry-unique : ∀ {F Curry′}
→ Eval ∘ ⟨ Curry′ × Id ⟩ ≈ F
→ Curry′ ≈ Curry F
Curry-unique {F} {Curry′} eq@record { iso = iso ; forth-natural = fnat } = record
{ iso = λ {x} →
let open Fun.≅-Reasoning in
Fun.≅.sym (
begin
fobj (Curry F) x
≈⟨ NatIso.iso (Curry-resp (Cat≈.sym eq)) ⟩
fobj (Curry (Eval ∘ ⟨ Curry′ × Id ⟩)) x
≈⟨ ≈→≅ (lem x) ⟩
fobj Curry′ x
∎
)
; forth-natural = λ {a} {b} {f} → ≈-intro λ {x} →
-- TODO We need a simplification tactic.
let open D.≈-Reasoning in
triangle (forth iso D.∘ component (fmap Curry′ f) x)
( begin
((forth iso D.∘
(fmap (fobj Curry′ b) C.id D.∘ component (fmap Curry′ B.id) x) D.∘ D.id) D.∘
D.id D.∘ D.id) D.∘
component (fmap Curry′ f) x
≈⟨ D.∘-resp-l (D.≈.trans (D.∘-resp-r D.id-l) (D.≈.trans D.id-r
(D.≈.trans (D.∘-resp-r (D.≈.trans D.id-r (D.≈.trans
(D.∘-resp (fmap-id (fobj Curry′ b))
(≈-elim (fmap-id Curry′))) D.id-l))) D.id-r))) ⟩
forth iso D.∘ component (fmap Curry′ f) x
∎
)
( begin
fmap F (f , C.id) D.∘
(forth iso D.∘ (fmap (fobj Curry′ a) C.id D.∘ component (fmap Curry′ B.id) x) D.∘ D.id) D.∘
D.id D.∘ D.id
≈⟨ D.∘-resp-r (D.≈.trans (D.∘-resp-r D.id-r) (D.≈.trans D.id-r
(D.≈.trans (D.∘-resp-r (D.≈.trans D.id-r (D.≈.trans
(D.∘-resp-l (fmap-id (fobj Curry′ a)))
(D.≈.trans D.id-l (≈-elim (fmap-id Curry′)))))) D.id-r))) ⟩
fmap F (f , C.id) D.∘ forth iso
≈⟨ D.≈.sym fnat ⟩
forth iso D.∘ fmap (fobj Curry′ b) C.id D.∘ component (fmap Curry′ f) x
≈⟨ D.∘-resp-r (D.≈.trans (D.∘-resp-l (fmap-id (fobj Curry′ b))) D.id-l) ⟩
forth iso D.∘ component (fmap Curry′ f) x
∎
)
}
where
lem : ∀ x
→ NatIso (Bifunctor→Functor₁ (Eval ∘ ⟨ Curry′ × Id ⟩) x) (fobj Curry′ x)
lem x = record
{ iso = D.≅.refl
; forth-natural = D.≈.trans D.id-l (D.∘-resp-r (≈-elim (fmap-id Curry′)))
}
-- We get the following lemmas for free from HasExponentials, but only when
-- all the categories are at the same (single) level.
Uncurry : Functor B (C ↝ D) → Bifunctor B C D
Uncurry F = Eval ∘ ⟨ F × Id ⟩
Curry∘Uncurry : {F : Functor B (C ↝ D)}
→ Curry (Uncurry F) ≈ F
Curry∘Uncurry {F} = Cat≈.sym (Curry-unique {Curry′ = F} Cat≈.refl)
Uncurry∘Curry : {F : Bifunctor B C D}
→ Uncurry (Curry F) ≈ F
Uncurry∘Curry {F} = Curry-correct {F = F}
instance
hasExponentials : ∀ {l} → HasExponentials (Cat l l l)
hasExponentials {l} = record
{ _↝′_ = λ B C → record
{ Cᴮ = B ↝ C
; eval = Eval
; curry′ = λ {A} F → record
{ arr = Curry F
; prop = Curry-correct {B = A} {B} {C} {F}
; unique = λ {g} eq → Cat≈.sym (Curry-unique eq)
}
}
}
| {
"alphanum_fraction": 0.4898938491,
"avg_line_length": 33.2222222222,
"ext": "agda",
"hexsha": "45dec570f6ea106eb6b2df7d7881c1302cf30151",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Cat/Facts/Exponential.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Cat/Facts/Exponential.agda",
"max_line_length": 105,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Cat/Facts/Exponential.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 2666,
"size": 6877
} |
module OlderBasicILP.Indirect.Translation where
open import OlderBasicILP.Indirect public
import OlderBasicILP.Indirect.Hilbert.Sequential as HS
import OlderBasicILP.Indirect.Hilbert.Nested as HN
import OlderBasicILP.Indirect.Gentzen as G
open HS using () renaming (_⊢×_ to HS⟨_⊢×_⟩ ; _⊢_ to HS⟨_⊢_⟩) public
open HN using () renaming (_⊢_ to HN⟨_⊢_⟩ ; _⊢⋆_ to HN⟨_⊢⋆_⟩) public
open G using () renaming (_⊢_ to G⟨_⊢_⟩ ; _⊢⋆_ to G⟨_⊢⋆_⟩) public
-- Translation from sequential Hilbert-style to nested.
hs→hnᵀᵐ : HS.Tm → HN.Tm
hs→hnᵀᵐ TS = aux TS 0
where
aux : HS.Tm → ℕ → HN.Tm
aux HS.NIL zero = {!!}
aux (HS.VAR I TS) zero = HN.VAR I
aux (HS.MP I J TS) zero = HN.APP (aux TS I) (aux TS J)
aux (HS.CI TS) zero = HN.CI
aux (HS.CK TS) zero = HN.CK
aux (HS.CS TS) zero = HN.CS
aux (HS.NEC SS TS) zero = HN.BOX (aux SS 0)
aux (HS.CDIST TS) zero = HN.CDIST
aux (HS.CUP TS) zero = HN.CUP
aux (HS.CDOWN TS) zero = HN.CDOWN
aux (HS.CPAIR TS) zero = HN.CPAIR
aux (HS.CFST TS) zero = HN.CFST
aux (HS.CSND TS) zero = HN.CSND
aux (HS.UNIT TS) zero = HN.UNIT
aux HS.NIL (suc K) = {!!}
aux (HS.VAR I TS) (suc K) = aux TS K
aux (HS.MP I J TS) (suc K) = aux TS K
aux (HS.CI TS) (suc K) = aux TS K
aux (HS.CK TS) (suc K) = aux TS K
aux (HS.CS TS) (suc K) = aux TS K
aux (HS.NEC SS TS) (suc K) = aux TS K
aux (HS.CDIST TS) (suc K) = aux TS K
aux (HS.CUP TS) (suc K) = aux TS K
aux (HS.CDOWN TS) (suc K) = aux TS K
aux (HS.CPAIR TS) (suc K) = aux TS K
aux (HS.CFST TS) (suc K) = aux TS K
aux (HS.CSND TS) (suc K) = aux TS K
aux (HS.UNIT TS) (suc K) = aux TS K
hs→hnᵀʸ : Ty HS.Tm → Ty HN.Tm
hs→hnᵀʸ (α P) = α P
hs→hnᵀʸ (A ▻ B) = hs→hnᵀʸ A ▻ hs→hnᵀʸ B
hs→hnᵀʸ (T ⦂ A) = hs→hnᵀᵐ T ⦂ hs→hnᵀʸ A
hs→hnᵀʸ (A ∧ B) = hs→hnᵀʸ A ∧ hs→hnᵀʸ B
hs→hnᵀʸ ⊤ = ⊤
hs→hnᵀʸ⋆ : Cx (Ty HS.Tm) → Cx (Ty HN.Tm)
hs→hnᵀʸ⋆ ∅ = ∅
hs→hnᵀʸ⋆ (Γ , A) = hs→hnᵀʸ⋆ Γ , hs→hnᵀʸ A
hs→hnᴵˣ : ∀ {A Γ} → A ∈ Γ → hs→hnᵀʸ A ∈ hs→hnᵀʸ⋆ Γ
hs→hnᴵˣ top = top
hs→hnᴵˣ (pop i) = pop (hs→hnᴵˣ i)
hs→hn : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → HN⟨ hs→hnᵀʸ⋆ Γ ⊢ hs→hnᵀʸ A ⟩
hs→hn (Ξ , ts) = aux ts top
where
aux : ∀ {A Γ Ξ} → HS⟨ Γ ⊢× Ξ ⟩ → A ∈ Ξ → HN⟨ hs→hnᵀʸ⋆ Γ ⊢ hs→hnᵀʸ A ⟩
aux (HS.var i ts) top = HN.var (hs→hnᴵˣ i)
aux (HS.mp i j ts) top = HN.app (aux ts i) (aux ts j)
aux (HS.ci ts) top = HN.ci
aux (HS.ck ts) top = HN.ck
aux (HS.cs ts) top = HN.cs
aux (HS.nec ss ts) top = {!HN.box (aux ss top)!}
aux (HS.cdist ts) top = {!HN.cdist!}
aux (HS.cup ts) top = {!HN.cup!}
aux (HS.cdown ts) top = HN.cdown
aux (HS.cpair ts) top = HN.cpair
aux (HS.cfst ts) top = HN.cfst
aux (HS.csnd ts) top = HN.csnd
aux (HS.unit ts) top = HN.unit
aux (HS.var i ts) (pop k) = aux ts k
aux (HS.mp i j ts) (pop k) = aux ts k
aux (HS.ci ts) (pop k) = aux ts k
aux (HS.ck ts) (pop k) = aux ts k
aux (HS.cs ts) (pop k) = aux ts k
aux (HS.nec ss ts) (pop k) = aux ts k
aux (HS.cdist ts) (pop k) = aux ts k
aux (HS.cup ts) (pop k) = aux ts k
aux (HS.cdown ts) (pop k) = aux ts k
aux (HS.cpair ts) (pop k) = aux ts k
aux (HS.cfst ts) (pop k) = aux ts k
aux (HS.csnd ts) (pop k) = aux ts k
aux (HS.unit ts) (pop k) = aux ts k
-- Translation from nested Hilbert-style to sequential.
hn→hsᵀᵐ : HN.Tm → HS.Tm
hn→hsᵀᵐ (HN.VAR I) = HS.VAR I HS.NIL
hn→hsᵀᵐ (HN.APP T U) = HS.APP (hn→hsᵀᵐ T) (hn→hsᵀᵐ U)
hn→hsᵀᵐ HN.CI = HS.CI HS.NIL
hn→hsᵀᵐ HN.CK = HS.CK HS.NIL
hn→hsᵀᵐ HN.CS = HS.CS HS.NIL
hn→hsᵀᵐ (HN.BOX T) = HS.BOX (hn→hsᵀᵐ T)
hn→hsᵀᵐ HN.CDIST = HS.CDIST HS.NIL
hn→hsᵀᵐ HN.CUP = HS.CUP HS.NIL
hn→hsᵀᵐ HN.CDOWN = HS.CDOWN HS.NIL
hn→hsᵀᵐ HN.CPAIR = HS.CPAIR HS.NIL
hn→hsᵀᵐ HN.CFST = HS.CFST HS.NIL
hn→hsᵀᵐ HN.CSND = HS.CSND HS.NIL
hn→hsᵀᵐ HN.UNIT = HS.UNIT HS.NIL
hn→hsᵀʸ : Ty HN.Tm → Ty HS.Tm
hn→hsᵀʸ (α P) = α P
hn→hsᵀʸ (A ▻ B) = hn→hsᵀʸ A ▻ hn→hsᵀʸ B
hn→hsᵀʸ (T ⦂ A) = hn→hsᵀᵐ T ⦂ hn→hsᵀʸ A
hn→hsᵀʸ (A ∧ B) = hn→hsᵀʸ A ∧ hn→hsᵀʸ B
hn→hsᵀʸ ⊤ = ⊤
hn→hsᵀʸ⋆ : Cx (Ty HN.Tm) → Cx (Ty HS.Tm)
hn→hsᵀʸ⋆ ∅ = ∅
hn→hsᵀʸ⋆ (Γ , A) = hn→hsᵀʸ⋆ Γ , hn→hsᵀʸ A
hn→hsᴵˣ : ∀ {A Γ} → A ∈ Γ → hn→hsᵀʸ A ∈ hn→hsᵀʸ⋆ Γ
hn→hsᴵˣ top = top
hn→hsᴵˣ (pop i) = pop (hn→hsᴵˣ i)
hn→hs : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → HS⟨ hn→hsᵀʸ⋆ Γ ⊢ hn→hsᵀʸ A ⟩
hn→hs (HN.var i) = ∅ , HS.var (hn→hsᴵˣ i) HS.nil
hn→hs (HN.app t u) = HS.app (hn→hs t) (hn→hs u)
hn→hs HN.ci = ∅ , HS.ci HS.nil
hn→hs HN.ck = ∅ , HS.ck HS.nil
hn→hs HN.cs = ∅ , HS.cs HS.nil
hn→hs (HN.box t) = {!HS.box (hn→hs t)!}
hn→hs HN.cdist = ∅ , HS.cdist HS.nil
hn→hs HN.cup = ∅ , HS.cup HS.nil
hn→hs HN.cdown = ∅ , HS.cdown HS.nil
hn→hs HN.cpair = ∅ , HS.cpair HS.nil
hn→hs HN.cfst = ∅ , HS.cfst HS.nil
hn→hs HN.csnd = ∅ , HS.csnd HS.nil
hn→hs HN.unit = ∅ , HS.unit HS.nil
-- Deduction theorem for sequential Hilbert-style.
hs→hn→hsᵀᵐ : ∀ {TS} → hn→hsᵀᵐ (hs→hnᵀᵐ TS) ≡ TS
hs→hn→hsᵀᵐ {HS.NIL} = {!refl!}
hs→hn→hsᵀᵐ {HS.VAR I TS} = cong² HS.VAR refl {!!}
hs→hn→hsᵀᵐ {HS.MP I J TS} = {!!}
hs→hn→hsᵀᵐ {HS.CI TS} = {!!}
hs→hn→hsᵀᵐ {HS.CK TS} = {!!}
hs→hn→hsᵀᵐ {HS.CS TS} = {!!}
hs→hn→hsᵀᵐ {HS.NEC SS TS} = {!!}
hs→hn→hsᵀᵐ {HS.CDIST TS} = {!!}
hs→hn→hsᵀᵐ {HS.CUP TS} = {!!}
hs→hn→hsᵀᵐ {HS.CDOWN TS} = {!!}
hs→hn→hsᵀᵐ {HS.CPAIR TS} = {!!}
hs→hn→hsᵀᵐ {HS.CFST TS} = {!!}
hs→hn→hsᵀᵐ {HS.CSND TS} = {!!}
hs→hn→hsᵀᵐ {HS.UNIT TS} = {!!}
hs→hn→hsᵀʸ : ∀ {A} → hn→hsᵀʸ (hs→hnᵀʸ A) ≡ A
hs→hn→hsᵀʸ {α P} = refl
hs→hn→hsᵀʸ {A ▻ B} = cong² _▻_ hs→hn→hsᵀʸ hs→hn→hsᵀʸ
hs→hn→hsᵀʸ {T ⦂ A} = cong² _⦂_ hs→hn→hsᵀᵐ hs→hn→hsᵀʸ
hs→hn→hsᵀʸ {A ∧ B} = cong² _∧_ hs→hn→hsᵀʸ hs→hn→hsᵀʸ
hs→hn→hsᵀʸ {⊤} = refl
-- hs-lam : ∀ {A B Γ} → HS⟨ Γ , A ⊢ B ⟩ → HS⟨ Γ ⊢ A ▻ B ⟩
-- hs-lam t = {!hn→hs (HN.lam (hs→hn t))!}
-- hn→hs ∘ HN.lam ∘ hs→hn
-- Translation from nested Hilbert-style to Gentzen-style.
hn→gᵀᵐ : HN.Tm → G.Tm
hn→gᵀᵐ (HN.VAR I) = G.VAR I
hn→gᵀᵐ (HN.APP T U) = G.APP (hn→gᵀᵐ T) (hn→gᵀᵐ U)
hn→gᵀᵐ HN.CI = G.CI
hn→gᵀᵐ HN.CK = G.CK
hn→gᵀᵐ HN.CS = G.CS
hn→gᵀᵐ (HN.BOX T) = G.BOX (hn→gᵀᵐ T)
hn→gᵀᵐ HN.CDIST = G.CDIST
hn→gᵀᵐ HN.CUP = G.CUP
hn→gᵀᵐ HN.CDOWN = G.CDOWN
hn→gᵀᵐ HN.CPAIR = G.CPAIR
hn→gᵀᵐ HN.CFST = G.CFST
hn→gᵀᵐ HN.CSND = G.CSND
hn→gᵀᵐ HN.UNIT = G.UNIT
hn→gᵀʸ : Ty HN.Tm → Ty G.Tm
hn→gᵀʸ (α P) = α P
hn→gᵀʸ (A ▻ B) = hn→gᵀʸ A ▻ hn→gᵀʸ B
hn→gᵀʸ (T ⦂ A) = hn→gᵀᵐ T ⦂ hn→gᵀʸ A
hn→gᵀʸ (A ∧ B) = hn→gᵀʸ A ∧ hn→gᵀʸ B
hn→gᵀʸ ⊤ = ⊤
hn→gᵀʸ⋆ : Cx (Ty HN.Tm) → Cx (Ty G.Tm)
hn→gᵀʸ⋆ ∅ = ∅
hn→gᵀʸ⋆ (Γ , A) = hn→gᵀʸ⋆ Γ , hn→gᵀʸ A
hn→gᴵˣ : ∀ {A Γ} → A ∈ Γ → hn→gᵀʸ A ∈ hn→gᵀʸ⋆ Γ
hn→gᴵˣ top = top
hn→gᴵˣ (pop i) = pop (hn→gᴵˣ i)
hn→g : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → G⟨ hn→gᵀʸ⋆ Γ ⊢ hn→gᵀʸ A ⟩
hn→g (HN.var i) = G.var (hn→gᴵˣ i)
hn→g (HN.app t u) = G.app (hn→g t) (hn→g u)
hn→g HN.ci = G.ci
hn→g HN.ck = G.ck
hn→g HN.cs = G.cs
hn→g (HN.box t) = {!G.box (hn→g t)!}
hn→g HN.cdist = {!G.cdist!}
hn→g HN.cup = {!G.cup!}
hn→g HN.cdown = G.cdown
hn→g HN.cpair = G.cpair
hn→g HN.cfst = G.cfst
hn→g HN.csnd = G.csnd
hn→g HN.unit = G.unit
-- Translation from sequential Hilbert-style to Gentzen-style.
hs→gᵀʸ : Ty HS.Tm → Ty G.Tm
hs→gᵀʸ = hn→gᵀʸ ∘ hs→hnᵀʸ
hs→gᵀʸ⋆ : Cx (Ty HS.Tm) → Cx (Ty G.Tm)
hs→gᵀʸ⋆ = hn→gᵀʸ⋆ ∘ hs→hnᵀʸ⋆
hs→g : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → G⟨ hs→gᵀʸ⋆ Γ ⊢ hs→gᵀʸ A ⟩
hs→g = hn→g ∘ hs→hn
-- Translation from Gentzen-style to Hilbert-style.
mutual
g→hnᵀᵐ : G.Tm → HN.Tm
g→hnᵀᵐ (G.VAR I) = HN.VAR I
g→hnᵀᵐ (G.LAM T) = HN.LAM (g→hnᵀᵐ T)
g→hnᵀᵐ (G.APP T U) = HN.APP (g→hnᵀᵐ T) (g→hnᵀᵐ U)
g→hnᵀᵐ (G.MULTIBOX TS U) = HN.MULTIBOX (g→hnᵀᵐ⋆ TS) (g→hnᵀᵐ U)
g→hnᵀᵐ (G.DOWN T) = HN.DOWN (g→hnᵀᵐ T)
g→hnᵀᵐ (G.PAIR T U) = HN.PAIR (g→hnᵀᵐ T) (g→hnᵀᵐ U)
g→hnᵀᵐ (G.FST T) = HN.FST (g→hnᵀᵐ T)
g→hnᵀᵐ (G.SND T) = HN.SND (g→hnᵀᵐ T)
g→hnᵀᵐ G.UNIT = HN.UNIT
g→hnᵀᵐ⋆ : Cx G.Tm → Cx HN.Tm
g→hnᵀᵐ⋆ ∅ = ∅
g→hnᵀᵐ⋆ (TS , T) = g→hnᵀᵐ⋆ TS , g→hnᵀᵐ T
g→hnᵀʸ : Ty G.Tm → Ty HN.Tm
g→hnᵀʸ (α P) = α P
g→hnᵀʸ (A ▻ B) = g→hnᵀʸ A ▻ g→hnᵀʸ B
g→hnᵀʸ (T ⦂ A) = g→hnᵀᵐ T ⦂ g→hnᵀʸ A
g→hnᵀʸ (A ∧ B) = g→hnᵀʸ A ∧ g→hnᵀʸ B
g→hnᵀʸ ⊤ = ⊤
g→hnᵀʸ⋆ : Cx (Ty G.Tm) → Cx (Ty HN.Tm)
g→hnᵀʸ⋆ ∅ = ∅
g→hnᵀʸ⋆ (Γ , A) = g→hnᵀʸ⋆ Γ , g→hnᵀʸ A
g→hnᴵˣ : ∀ {A Γ} → A ∈ Γ → g→hnᵀʸ A ∈ g→hnᵀʸ⋆ Γ
g→hnᴵˣ top = top
g→hnᴵˣ (pop i) = pop (g→hnᴵˣ i)
mutual
g→hn : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HN⟨ g→hnᵀʸ⋆ Γ ⊢ g→hnᵀʸ A ⟩
g→hn (G.var i) = HN.var (g→hnᴵˣ i)
g→hn (G.lam t) = HN.lam (g→hn t)
g→hn (G.app t u) = HN.app (g→hn t) (g→hn u)
g→hn (G.multibox ts u) = {!HN.multibox (g→hn⋆ ts) (g→hn u)!}
g→hn (G.down t) = HN.down (g→hn t)
g→hn (G.pair t u) = HN.pair (g→hn t) (g→hn u)
g→hn (G.fst t) = HN.fst (g→hn t)
g→hn (G.snd t) = HN.snd (g→hn t)
g→hn G.unit = HN.unit
g→hn⋆ : ∀ {Ξ Γ} → G⟨ Γ ⊢⋆ Ξ ⟩ → HN⟨ g→hnᵀʸ⋆ Γ ⊢⋆ g→hnᵀʸ⋆ Ξ ⟩
g→hn⋆ {∅} ∙ = ∙
g→hn⋆ {Ξ , A} (ts , t) = g→hn⋆ ts , g→hn t
-- Translation from Gentzen-style to sequential Hilbert-style.
g→hsᵀʸ : Ty G.Tm → Ty HS.Tm
g→hsᵀʸ = hn→hsᵀʸ ∘ g→hnᵀʸ
g→hsᵀʸ⋆ : Cx (Ty G.Tm) → Cx (Ty HS.Tm)
g→hsᵀʸ⋆ = hn→hsᵀʸ⋆ ∘ g→hnᵀʸ⋆
g→hs : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HS⟨ g→hsᵀʸ⋆ Γ ⊢ g→hsᵀʸ A ⟩
g→hs = hn→hs ∘ g→hn
| {
"alphanum_fraction": 0.5150975047,
"avg_line_length": 32.4421768707,
"ext": "agda",
"hexsha": "f635d4179e03a3f722930ca6cb982b75a5951aee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "OlderBasicILP/Indirect/Translation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "OlderBasicILP/Indirect/Translation.agda",
"max_line_length": 73,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "OlderBasicILP/Indirect/Translation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 5745,
"size": 9538
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
data _≅_ {A : Set} (x : A) : {B : Set} → B → Set where
refl : x ≅ x
test₁ : (A : Set) (x y : A) (z : Nat) → x ≡ y → x ≅ (suc z) → y ≅ 1 → Nat
test₁ A (suc z) (suc zero) .z refl refl refl = {!!}
test₂ : (A : Set) (x y : A) (z : Nat) → x ≡ y → x ≅ 1 → y ≅ (suc z) → Nat
test₂ A (suc zero) (suc z) .z refl refl refl = {!!}
| {
"alphanum_fraction": 0.5257009346,
"avg_line_length": 30.5714285714,
"ext": "agda",
"hexsha": "91d5023b295c8175b462f138fc3403f14f1ccd91",
"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/Issue2856.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/Issue2856.agda",
"max_line_length": 73,
"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/Issue2856.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": 428
} |
open import Nat
open import Prelude
open import List
open import contexts
open import unions
module core where
-- types
data typ : Set where
_==>_ : typ → typ → typ
⟨⟩ : typ
⟨_×_⟩ : typ → typ → typ
D[_] : Nat → typ
-- arrow type constructors bind very tightly
infixr 25 _==>_
-- type contexts, hole contexts, and datatype environments
tctx = typ ctx
hctx = (tctx ∧ typ) ctx
denv = Σ[ dctx ∈ tctx ctx ]
∀{d1 d2 cctx1 cctx2 c} →
d1 ≠ d2 →
(d1 , cctx1) ∈ dctx →
(d2 , cctx2) ∈ dctx →
c # cctx1 ∨ c # cctx2
-- simple values
data val : Set where
⟨⟩ : val
⟨_,_⟩ : val → val → val
C[_]_ : Nat → val → val
-- examples
data ex : Set where
⟨⟩ : ex
⟨_,_⟩ : ex → ex → ex
C[_]_ : Nat → ex → ex
_↦_ : val → ex → ex
¿¿ : ex
-- simple value typing
data _⊢_::ⱽ_ : denv → val → typ → Set where
VTUnit : ∀{Σ'} → Σ' ⊢ ⟨⟩ ::ⱽ ⟨⟩
VTPair : ∀{Σ' v1 v2 τ1 τ2} →
Σ' ⊢ v1 ::ⱽ τ1 →
Σ' ⊢ v2 ::ⱽ τ2 →
Σ' ⊢ ⟨ v1 , v2 ⟩ ::ⱽ ⟨ τ1 × τ2 ⟩
VTCtor : ∀{Σ' d cctx c v τ} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Σ' ⊢ v ::ⱽ τ →
Σ' ⊢ C[ c ] v ::ⱽ D[ d ]
-- example typing
data _,_⊢_:·_ : hctx → denv → ex → typ → Set where
XTUnit : ∀{Δ Σ'} → Δ , Σ' ⊢ ⟨⟩ :· ⟨⟩
XTPair : ∀{Δ Σ' ex1 ex2 τ1 τ2} →
Δ , Σ' ⊢ ex1 :· τ1 →
Δ , Σ' ⊢ ex2 :· τ2 →
Δ , Σ' ⊢ ⟨ ex1 , ex2 ⟩ :· ⟨ τ1 × τ2 ⟩
XTCtor : ∀{Δ Σ' d cctx c ex τ} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Δ , Σ' ⊢ ex :· τ →
Δ , Σ' ⊢ C[ c ] ex :· D[ d ]
XTTop : ∀{Δ Σ' τ} → Δ , Σ' ⊢ ¿¿ :· τ
XTInOut : ∀{Δ Σ' v ex τ1 τ2} →
Σ' ⊢ v ::ⱽ τ1 →
Δ , Σ' ⊢ ex :· τ2 →
Δ , Σ' ⊢ v ↦ ex :· τ1 ==> τ2
-- the two possible prj indices
data prj-idx : Set where
P1 : prj-idx
P2 : prj-idx
prj : {A : Set} → prj-idx → A → A → A
prj P1 a1 a2 = a1
prj P2 a1 a2 = a2
mutual
record rule : Set where
inductive
constructor |C_=>_
field
parm : Nat
branch : exp
-- Expressions
data exp : Set where
fix_⦇·λ_=>_·⦈ : Nat → Nat → exp → exp
_∘_ : exp → exp → exp
X[_] : Nat → exp
⟨⟩ : exp
⟨_,_⟩ : exp → exp → exp
prj[_]_ : prj-idx → exp → exp
C[_]_ : Nat → exp → exp
case_of⦃·_·⦄ : exp → rule ctx → exp
??[_] : Nat → exp
PBE:assert : exp → exp → exp
-- u is fresh in e
data hole-name-new : (e : exp) → (u : Nat) → Set where
HNNFix : ∀{x f e u} → hole-name-new e u → hole-name-new (fix f ⦇·λ x => e ·⦈) u
HNNVar : ∀{x u} → hole-name-new (X[ x ]) u
HNNAp : ∀{e1 e2 u} → hole-name-new e1 u → hole-name-new e2 u → hole-name-new (e1 ∘ e2) u
HNNUnit : ∀{u} → hole-name-new ⟨⟩ u
HNNPair : ∀{e1 e2 u} → hole-name-new e1 u → hole-name-new e2 u → hole-name-new ⟨ e1 , e2 ⟩ u
HNNPrj : ∀{e i u} → hole-name-new e u → hole-name-new (prj[ i ] e) u
HNNCtor : ∀{c e u} → hole-name-new e u → hole-name-new (C[ c ] e) u
HNNCase : ∀{e rules u} →
hole-name-new e u →
(∀{c rule} → (c , rule) ∈ rules → hole-name-new (rule.branch rule) u) →
hole-name-new (case e of⦃· rules ·⦄) u
HNNHole : ∀{u' u} → u' ≠ u → hole-name-new (??[ u' ]) u
HNNAsrt : ∀{e1 e2 u} → hole-name-new e1 u → hole-name-new e2 u → hole-name-new (PBE:assert e1 e2) u
-- e1 and e2 do not have any hole names in common
data holes-disjoint : (e1 : exp) → (e2 : exp) → Set where
HDFix : ∀{x f e e'} → holes-disjoint e e' → holes-disjoint (fix f ⦇·λ x => e ·⦈) e'
HDVar : ∀{x e'} → holes-disjoint (X[ x ]) e'
HDAp : ∀{e1 e2 e'} → holes-disjoint e1 e' → holes-disjoint e2 e' → holes-disjoint (e1 ∘ e2) e'
HDUnit : ∀{e'} → holes-disjoint ⟨⟩ e'
HDPair : ∀{e1 e2 e'} → holes-disjoint e1 e' → holes-disjoint e2 e' → holes-disjoint ⟨ e1 , e2 ⟩ e'
HDPrj : ∀{i e e'} → holes-disjoint e e' → holes-disjoint (prj[ i ] e) e'
HDCtor : ∀{c e e'} → holes-disjoint e e' → holes-disjoint (C[ c ] e) e'
HDCase : ∀{e rules e'} →
holes-disjoint e e' →
(∀{c rule} → (c , rule) ∈ rules → holes-disjoint (rule.branch rule) e') →
holes-disjoint (case e of⦃· rules ·⦄) e'
HDHole : ∀{u e'} → hole-name-new e' u → holes-disjoint (??[ u ]) e'
HDAsrt : ∀{e1 e2 e'} → holes-disjoint e1 e' → holes-disjoint e2 e' → holes-disjoint (PBE:assert e1 e2) e'
-- e ecomplete iff e contains no holes
data _ecomplete : exp → Set where
ECFix : ∀{f x e} → e ecomplete → fix f ⦇·λ x => e ·⦈ ecomplete
ECVar : ∀{x} → X[ x ] ecomplete
ECAp : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → (e1 ∘ e2) ecomplete
ECUnit : ⟨⟩ ecomplete
ECPair : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → ⟨ e1 , e2 ⟩ ecomplete
ECPrj : ∀{i e} → e ecomplete → (prj[ i ] e) ecomplete
ECCtor : ∀{c e} → e ecomplete → (C[ c ] e) ecomplete
ECCase : ∀{e rules} →
e ecomplete →
(∀{c rule} → (c , rule) ∈ rules → (rule.branch rule) ecomplete) →
case e of⦃· rules ·⦄ ecomplete
ECAsrt : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → (PBE:assert e1 e2) ecomplete
-- type assignment for expressions
data _,_,_⊢_::_ : hctx → denv → tctx → exp → typ → Set where
TFix : ∀{Δ Σ' Γ f x e τ1 τ2} →
Δ , Σ' , (Γ ,, (f , τ1 ==> τ2) ,, (x , τ1)) ⊢ e :: τ2 →
Δ , Σ' , Γ ⊢ fix f ⦇·λ x => e ·⦈ :: τ1 ==> τ2
TVar : ∀{Δ Σ' Γ x τ} → (x , τ) ∈ Γ → Δ , Σ' , Γ ⊢ X[ x ] :: τ
THole : ∀{Δ Σ' Γ u τ} → (u , (Γ , τ)) ∈ Δ → Δ , Σ' , Γ ⊢ ??[ u ] :: τ
TUnit : ∀{Δ Σ' Γ} → Δ , Σ' , Γ ⊢ ⟨⟩ :: ⟨⟩
TPair : ∀{Δ Σ' Γ e1 e2 τ1 τ2} →
holes-disjoint e1 e2 →
Δ , Σ' , Γ ⊢ e1 :: τ1 →
Δ , Σ' , Γ ⊢ e2 :: τ2 →
Δ , Σ' , Γ ⊢ ⟨ e1 , e2 ⟩ :: ⟨ τ1 × τ2 ⟩
TCtor : ∀{Δ Σ' Γ d cctx c e τ} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Δ , Σ' , Γ ⊢ e :: τ →
Δ , Σ' , Γ ⊢ C[ c ] e :: D[ d ]
TApp : ∀{Δ Σ' Γ f arg τ1 τ2} →
holes-disjoint f arg →
Δ , Σ' , Γ ⊢ f :: τ1 ==> τ2 →
Δ , Σ' , Γ ⊢ arg :: τ1 →
Δ , Σ' , Γ ⊢ f ∘ arg :: τ2
TPrj : ∀{Δ Σ' Γ i e τ1 τ2} →
Δ , Σ' , Γ ⊢ e :: ⟨ τ1 × τ2 ⟩ →
Δ , Σ' , Γ ⊢ prj[ i ] e :: prj i τ1 τ2
TCase : ∀{Δ Σ' Γ d cctx e rules τ} →
(d , cctx) ∈ π1 Σ' →
Δ , Σ' , Γ ⊢ e :: D[ d ] →
-- There must be a rule for each constructor, i.e. case exhuastiveness
(∀{c} → dom cctx c → dom rules c) →
(∀{c xc ec} →
(c , |C xc => ec) ∈ rules →
holes-disjoint ec e ∧
(∀{c' xc' ec'} → (c' , |C xc' => ec') ∈ rules → c ≠ c' → holes-disjoint ec ec') ∧
-- The constructor of each rule must be of the right datatype, and the branch must type-check
Σ[ τc ∈ typ ] (
(c , τc) ∈ cctx ∧
Δ , Σ' , (Γ ,, (xc , τc)) ⊢ ec :: τ)) →
Δ , Σ' , Γ ⊢ case e of⦃· rules ·⦄ :: τ
TAssert : ∀{Δ Σ' Γ e1 e2 τ} →
holes-disjoint e1 e2 →
Δ , Σ' , Γ ⊢ e1 :: τ →
Δ , Σ' , Γ ⊢ e2 :: τ →
Δ , Σ' , Γ ⊢ PBE:assert e1 e2 :: ⟨⟩
mutual
env : Set
env = result ctx
-- results - evaluation takes expressions to results, but results aren't necessarily final
data result : Set where
[_]fix_⦇·λ_=>_·⦈ : env → Nat → Nat → exp → result
⟨⟩ : result
⟨_,_⟩ : result → result → result
C[_]_ : Nat → result → result
[_]??[_] : env → Nat → result
_∘_ : result → result → result
prj[_]_ : prj-idx → result → result
[_]case_of⦃·_·⦄ : env → result → rule ctx → result
C⁻¹[_]_ : Nat → result → result
mutual
data _env-final : env → Set where
EFNone : ∅ env-final
EFInd : ∀{E x r} → E env-final → r final → (E ,, (x , r)) env-final
-- final results are those that cannot be evaluated further
data _final : result → Set where
FDet : ∀{r} → r det → r final
FIndet : ∀{r} → r indet → r final
-- final results that can be eliminated (or in the case of ⟨⟩, that don't need to be)
data _det : result → Set where
DFix : ∀{E f x e} → E env-final → [ E ]fix f ⦇·λ x => e ·⦈ det
DUnit : ⟨⟩ det
DPair : ∀{r1 r2} → r1 final → r2 final → ⟨ r1 , r2 ⟩ det
DCtor : ∀{c r} → r final → (C[ c ] r) det
-- indeterminate results are incomplete and cannot be further reduced except by resumption
data _indet : result → Set where
IDHole : ∀{E u} → E env-final → [ E ]??[ u ] indet
IDApp : ∀{r1 r2} → r1 indet → r2 final → (r1 ∘ r2) indet
IDPrj : ∀{i r} → r indet → (prj[ i ] r) indet
IDCase : ∀{E r rules} → E env-final → r indet → [ E ]case r of⦃· rules ·⦄ indet
mutual
-- type assignment for environments
data _,_,_⊢_ : hctx → denv → tctx → env → Set where
EnvId : ∀{Δ Σ'} → Δ , Σ' , ∅ ⊢ ∅
EnvInd : ∀{Δ Σ' Γ E x τx rx} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' ⊢ rx ·: τx →
Δ , Σ' , (Γ ,, (x , τx)) ⊢ (E ,, (x , rx))
-- type assignment for results
data _,_⊢_·:_ : hctx → denv → result → typ → Set where
RTFix : ∀{Δ Σ' Γ E f x e τ} →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' , Γ ⊢ fix f ⦇·λ x => e ·⦈ :: τ →
Δ , Σ' ⊢ [ E ]fix f ⦇·λ x => e ·⦈ ·: τ
RTHole : ∀{Δ Σ' Γ E u τ} →
(u , (Γ , τ)) ∈ Δ →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' ⊢ [ E ]??[ u ] ·: τ
RTUnit : ∀{Δ Σ'} → Δ , Σ' ⊢ ⟨⟩ ·: ⟨⟩
RTPair : ∀{Δ Σ' r1 r2 τ1 τ2} →
Δ , Σ' ⊢ r1 ·: τ1 →
Δ , Σ' ⊢ r2 ·: τ2 →
Δ , Σ' ⊢ ⟨ r1 , r2 ⟩ ·: ⟨ τ1 × τ2 ⟩
RTCtor : ∀{Δ Σ' d cctx c r τ} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Δ , Σ' ⊢ r ·: τ →
Δ , Σ' ⊢ C[ c ] r ·: D[ d ]
RTApp : ∀{Δ Σ' f arg τ1 τ2} →
Δ , Σ' ⊢ f ·: τ1 ==> τ2 →
Δ , Σ' ⊢ arg ·: τ1 →
Δ , Σ' ⊢ f ∘ arg ·: τ2
RTPrj : ∀{Δ Σ' i r τ1 τ2} →
Δ , Σ' ⊢ r ·: ⟨ τ1 × τ2 ⟩ →
Δ , Σ' ⊢ prj[ i ] r ·: prj i τ1 τ2
RTCase : ∀{Δ Σ' Γ E d cctx r rules τ} →
(d , cctx) ∈ π1 Σ' →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' ⊢ r ·: D[ d ] →
-- There must be a rule for each constructor, i.e. case exhaustiveness
(∀{c} → dom cctx c → dom rules c) →
(∀{c xc ec} →
(c , |C xc => ec) ∈ rules →
-- The constructor of each rule must be of the right datatype, and the branch must type-check
Σ[ τc ∈ typ ] (
(c , τc) ∈ cctx ∧
Δ , Σ' , (Γ ,, (xc , τc)) ⊢ ec :: τ)) →
Δ , Σ' ⊢ [ E ]case r of⦃· rules ·⦄ ·: τ
RTUnwrapCtor : ∀{Δ Σ' d cctx c r τ} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Δ , Σ' ⊢ r ·: D[ d ] →
Δ , Σ' ⊢ C⁻¹[ c ] r ·: τ
excon = env ∧ ex
excons = List excon
assertions = List (result ∧ val)
hole-fillings = exp ctx
constraints = hole-fillings ∧ excons ctx
record goal : Set where
inductive
constructor _⊢??[_]:_⊨_
field
g-tctx : tctx
g-id : Nat
g-typ : typ
g-excons : excons
goals = List goal
-- value-to-example coercion
⌊_⌋ : val → ex
⌊ ⟨⟩ ⌋ = ⟨⟩
⌊ ⟨ v1 , v2 ⟩ ⌋ = ⟨ ⌊ v1 ⌋ , ⌊ v2 ⌋ ⟩
⌊ C[ c ] v ⌋ = C[ c ] ⌊ v ⌋
-- result-to-value coercion
data ⌈_⌉:=_ : result → val → Set where
CoerceUnit : ⌈ ⟨⟩ ⌉:= ⟨⟩
CoercePair : ∀{r1 r2 v1 v2} →
⌈ r1 ⌉:= v1 →
⌈ r2 ⌉:= v2 →
⌈ ⟨ r1 , r2 ⟩ ⌉:= ⟨ v1 , v2 ⟩
CoerceCtor : ∀{c r v} →
⌈ r ⌉:= v →
⌈ C[ c ] r ⌉:= C[ c ] v
-- excons typing
data _,_⊢_::ˣ_,_ : hctx → denv → excons → tctx → typ → Set where
TXNil : ∀{Δ Σ' Γ τ} → Δ , Σ' ⊢ [] ::ˣ Γ , τ
TXInd : ∀{Δ Σ' X E ex Γ τ} →
Δ , Σ' ⊢ X ::ˣ Γ , τ →
Δ , Σ' , Γ ⊢ E →
Δ , Σ' ⊢ ex :· τ →
Δ , Σ' ⊢ ((E , ex) :: X) ::ˣ Γ , τ
-- type assignment for hole fillings
data _,_⊢ᴴ_ : hctx → denv → hole-fillings → Set where
TFNil : ∀{Δ Σ'} → Δ , Σ' ⊢ᴴ ∅
TFInd : ∀{Δ Σ' F u Γ τ e} →
(u , Γ , τ) ∈ Δ →
Δ , Σ' ⊢ᴴ F →
Δ , Σ' , Γ ⊢ e :: τ →
Δ , Σ' ⊢ᴴ (F ,, (u , e))
{- TODO - we have to decide between this version and the one prior
_,_⊢ₕ_ : hctx → denv → hole-fillings → Set
Δ , Σ' ⊢ₕ F = ∀{u e} →
(u , e) ∈ F →
Σ[ Γ ∈ tctx ] Σ[ τ ∈ typ ] (
(u , Γ , τ) ∈ Δ ∧
Δ , Σ' , Γ ⊢ e :: τ)
-}
-- these are used to determine the "order" in which result consistency rules are checked
not-both-pair : (r r' : result) → Set
not-both-pair r r' = (∀{r1 r2} → r ≠ ⟨ r1 , r2 ⟩) ∨ (∀{r1 r2} → r' ≠ ⟨ r1 , r2 ⟩)
not-both-ctor : (r r' : result) → Set
not-both-ctor r r' = (∀{c r''} → r ≠ (C[ c ] r'')) ∨ (∀{c r''} → r' ≠ (C[ c ] r''))
-- result consistency
data _≡⌊_⌋_ : result → assertions → result → Set where
RCRefl : ∀{r} → r ≡⌊ [] ⌋ r
RCPair : ∀{r1 r2 r'1 r'2 A1 A2} →
(_==_ {A = result} ⟨ r1 , r2 ⟩ ⟨ r'1 , r'2 ⟩ → ⊥) →
r1 ≡⌊ A1 ⌋ r'1 →
r2 ≡⌊ A2 ⌋ r'2 →
⟨ r1 , r2 ⟩ ≡⌊ A1 ++ A2 ⌋ ⟨ r'1 , r'2 ⟩
RCCtor : ∀{c r r' A} →
(_==_ {A = result} (C[ c ] r) (C[ c ] r') → ⊥) →
r ≡⌊ A ⌋ r' →
(C[ c ] r) ≡⌊ A ⌋ (C[ c ] r')
RCAssert1 : ∀{r1 r2 v2 A} →
r1 ≠ r2 →
not-both-pair r1 r2 →
not-both-ctor r1 r2 →
⌈ r2 ⌉:= v2 →
A == (r1 , v2) :: [] →
r1 ≡⌊ A ⌋ r2
RCAssert2 : ∀{r1 r2 v1 A} →
r1 ≠ r2 →
not-both-pair r1 r2 →
not-both-ctor r1 r2 →
⌈ r1 ⌉:= v1 →
A == (r2 , v1) :: [] →
r1 ≡⌊ A ⌋ r2
-- Generic result consistency failure - this goes through if results are not consistent
data _≢_ : result → result → Set where
RCFPair1 : ∀{r1 r2 r'1 r'2} →
r1 ≢ r'1 →
⟨ r1 , r2 ⟩ ≢ ⟨ r'1 , r'2 ⟩
RCFPair2 : ∀{r1 r2 r'1 r'2} →
r2 ≢ r'2 →
⟨ r1 , r2 ⟩ ≢ ⟨ r'1 , r'2 ⟩
RCFCtorMM : ∀{c c' r r'} →
c ≠ c' →
(C[ c ] r) ≢ (C[ c' ] r')
RCFCtor : ∀{c r r'} →
r ≢ r' →
(C[ c ] r) ≢ (C[ c ] r')
RCFNoCoerce : ∀{r r'} →
r ≠ r' →
not-both-pair r r' →
not-both-ctor r r' →
(∀{v} → ⌈ r ⌉:= v → ⊥) →
(∀{v} → ⌈ r' ⌉:= v → ⊥) →
r ≢ r'
-- Various judgments accept "fuel", which defines whether or not they can recurse indefinitely,
-- and, if not, then the numerical limit. The limit is not on the recursion depth, but rather
-- on the number of "beta reductions", interpreted a bit loosely to include case evaluations.
-- - If ⌊ ⛽ ⌋ is ∞, then there is no beta reduction limit,
-- but the judgment will not be satisfied unless evaluation eventually terminates.
-- - If ⌊ ⛽ ⌋ is ⛽⟨ n ⟩, then the beta reduction limit is at most n,
-- but if the limit is reached, then "success" judgments will not go through,
-- but "failure" judgments will be satisfied automatically.
data Fuel : Set where
∞ : Fuel
⛽⟨_⟩ : Nat → Fuel
-- fuel depletion
data _⛽⇓_ : Fuel → Fuel → Set where
CF∞ : ∞ ⛽⇓ ∞
CF⛽ : ∀{n} → ⛽⟨ 1+ n ⟩ ⛽⇓ ⛽⟨ n ⟩
-- TODO we need a theorem that h-constraints cannot generate spurious hole names.
-- generally, all the steps from an exp to an something with holes should not contain hole names
-- not in the original exp, and the process as a whole should also not produce spurious names
-- this realization probably means there are other important theorems that have been missed
-- NOTE the core theorem in completeness.agda will do the trick for evaluation itself
-- TODO we should have theorems that constrain where don't cares and such can be found.
-- Don't cares should only be generated in backprop and should not appear anywhere else.
-- Generic big step evaluation
data _⊢_⌊_⌋⇒_⊣_ : env → exp → Fuel → result → assertions → Set where
EUnit : ∀{E ⛽} → E ⊢ ⟨⟩ ⌊ ⛽ ⌋⇒ ⟨⟩ ⊣ []
EPair : ∀{E ⛽ e1 e2 r1 r2 A1 A2} →
E ⊢ e1 ⌊ ⛽ ⌋⇒ r1 ⊣ A1 →
E ⊢ e2 ⌊ ⛽ ⌋⇒ r2 ⊣ A2 →
E ⊢ ⟨ e1 , e2 ⟩ ⌊ ⛽ ⌋⇒ ⟨ r1 , r2 ⟩ ⊣ A1 ++ A2
ECtor : ∀{E ⛽ c e r A} →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
E ⊢ C[ c ] e ⌊ ⛽ ⌋⇒ (C[ c ] r) ⊣ A
EFix : ∀{E ⛽ f x e} → E ⊢ fix f ⦇·λ x => e ·⦈ ⌊ ⛽ ⌋⇒ [ E ]fix f ⦇·λ x => e ·⦈ ⊣ []
EVar : ∀{E ⛽ x r} → (x , r) ∈ E → E ⊢ X[ x ] ⌊ ⛽ ⌋⇒ r ⊣ []
EHole : ∀{E ⛽ u} → E ⊢ ??[ u ] ⌊ ⛽ ⌋⇒ [ E ]??[ u ] ⊣ []
EAppFix : ∀{E ⛽ ⛽↓ e1 e2 Ef f x ef r1 A1 r2 A2 r A} →
⛽ ⛽⇓ ⛽↓ →
E ⊢ e1 ⌊ ⛽ ⌋⇒ r1 ⊣ A1 →
r1 == [ Ef ]fix f ⦇·λ x => ef ·⦈ →
E ⊢ e2 ⌊ ⛽ ⌋⇒ r2 ⊣ A2 →
(Ef ,, (f , r1) ,, (x , r2)) ⊢ ef ⌊ ⛽↓ ⌋⇒ r ⊣ A →
E ⊢ e1 ∘ e2 ⌊ ⛽ ⌋⇒ r ⊣ A1 ++ A2 ++ A
EAppIndet : ∀{E ⛽ e1 e2 r1 A1 r2 A2} →
E ⊢ e1 ⌊ ⛽ ⌋⇒ r1 ⊣ A1 →
(∀{Ef f x ef} → r1 ≠ [ Ef ]fix f ⦇·λ x => ef ·⦈) →
E ⊢ e2 ⌊ ⛽ ⌋⇒ r2 ⊣ A2 →
E ⊢ e1 ∘ e2 ⌊ ⛽ ⌋⇒ (r1 ∘ r2) ⊣ A1 ++ A2
EPrj : ∀{E ⛽ i e r1 r2 A} →
E ⊢ e ⌊ ⛽ ⌋⇒ ⟨ r1 , r2 ⟩ ⊣ A →
E ⊢ prj[ i ] e ⌊ ⛽ ⌋⇒ prj i r1 r2 ⊣ A
EPrjIndet : ∀{E ⛽ i e r A} →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
(∀{r1 r2} → r ≠ ⟨ r1 , r2 ⟩) →
E ⊢ prj[ i ] e ⌊ ⛽ ⌋⇒ prj[ i ] r ⊣ A
ECase : ∀{E ⛽ ⛽↓ e rules c xc ec r A' rc A} →
⛽ ⛽⇓ ⛽↓ →
(c , |C xc => ec) ∈ rules →
E ⊢ e ⌊ ⛽ ⌋⇒ (C[ c ] r) ⊣ A →
(E ,, (xc , r)) ⊢ ec ⌊ ⛽↓ ⌋⇒ rc ⊣ A' →
E ⊢ case e of⦃· rules ·⦄ ⌊ ⛽ ⌋⇒ rc ⊣ A ++ A'
ECaseIndet : ∀{E ⛽ e rules r A} →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
(∀{c rc} → r ≠ (C[ c ] rc)) →
E ⊢ case e of⦃· rules ·⦄ ⌊ ⛽ ⌋⇒ [ E ]case r of⦃· rules ·⦄ ⊣ A
EAssert : ∀{E ⛽ e1 r1 A1 e2 r2 A2 A3} →
E ⊢ e1 ⌊ ⛽ ⌋⇒ r1 ⊣ A1 →
E ⊢ e2 ⌊ ⛽ ⌋⇒ r2 ⊣ A2 →
r1 ≡⌊ A3 ⌋ r2 →
E ⊢ PBE:assert e1 e2 ⌊ ⛽ ⌋⇒ ⟨⟩ ⊣ A1 ++ A2 ++ A3
-- Generic evaluation failure - this goes through if evaluation would fail due to failure
-- of some assertion that occurs during evaluation, or if the fuel runs out.
data _⊢_⌊_⌋⇒∅ : env → exp → Fuel → Set where
EFPair1 : ∀{E ⛽ e1 e2} →
E ⊢ e1 ⌊ ⛽ ⌋⇒∅ →
E ⊢ ⟨ e1 , e2 ⟩ ⌊ ⛽ ⌋⇒∅
EFPair2 : ∀{E ⛽ e1 e2} →
E ⊢ e2 ⌊ ⛽ ⌋⇒∅ →
E ⊢ ⟨ e1 , e2 ⟩ ⌊ ⛽ ⌋⇒∅
EFCtor : ∀{E ⛽ c e} →
E ⊢ e ⌊ ⛽ ⌋⇒∅ →
E ⊢ C[ c ] e ⌊ ⛽ ⌋⇒∅
EFAppFun : ∀{E ⛽ e1 e2} →
E ⊢ e1 ⌊ ⛽ ⌋⇒∅ →
E ⊢ e1 ∘ e2 ⌊ ⛽ ⌋⇒∅
EFAppArg : ∀{E ⛽ e1 e2} →
E ⊢ e2 ⌊ ⛽ ⌋⇒∅ →
E ⊢ e1 ∘ e2 ⌊ ⛽ ⌋⇒∅
EFAppEval : ∀{E ⛽ ⛽↓ e1 e2 Ef f x ef r1 A1 r2 A2} →
⛽ ⛽⇓ ⛽↓ →
E ⊢ e1 ⌊ ⛽ ⌋⇒ r1 ⊣ A1 →
r1 == [ Ef ]fix f ⦇·λ x => ef ·⦈ →
E ⊢ e2 ⌊ ⛽ ⌋⇒ r2 ⊣ A2 →
(Ef ,, (f , r1) ,, (x , r2)) ⊢ ef ⌊ ⛽↓ ⌋⇒∅ →
E ⊢ e1 ∘ e2 ⌊ ⛽ ⌋⇒∅
EFPrj : ∀{E ⛽ i e} →
E ⊢ e ⌊ ⛽ ⌋⇒∅ →
E ⊢ prj[ i ] e ⌊ ⛽ ⌋⇒∅
EFCaseScrut : ∀{E ⛽ e rules} →
E ⊢ e ⌊ ⛽ ⌋⇒∅ →
E ⊢ case e of⦃· rules ·⦄ ⌊ ⛽ ⌋⇒∅
EFCaseRule : ∀{E ⛽ ⛽↓ e rules c xc ec r A} →
⛽ ⛽⇓ ⛽↓ →
(c , |C xc => ec) ∈ rules →
E ⊢ e ⌊ ⛽ ⌋⇒ (C[ c ] r) ⊣ A →
(E ,, (xc , r)) ⊢ ec ⌊ ⛽↓ ⌋⇒∅ →
E ⊢ case e of⦃· rules ·⦄ ⌊ ⛽ ⌋⇒∅
EFAssert1 : ∀{E ⛽ e1 e2} →
E ⊢ e1 ⌊ ⛽ ⌋⇒∅ →
E ⊢ PBE:assert e1 e2 ⌊ ⛽ ⌋⇒∅
EFAssert2 : ∀{E ⛽ e1 e2} →
E ⊢ e2 ⌊ ⛽ ⌋⇒∅ →
E ⊢ PBE:assert e1 e2 ⌊ ⛽ ⌋⇒∅
EFAssert : ∀{E ⛽ e1 r1 A1 e2 r2 A2} →
E ⊢ e1 ⌊ ⛽ ⌋⇒ r1 ⊣ A1 →
E ⊢ e2 ⌊ ⛽ ⌋⇒ r2 ⊣ A2 →
r1 ≢ r2 →
E ⊢ PBE:assert e1 e2 ⌊ ⛽ ⌋⇒∅
EFLimit : ∀{E e} → E ⊢ e ⌊ ⛽⟨ 0 ⟩ ⌋⇒∅
-- resumption
mutual
data _⊢_⌊_⌋:⇨_:=_ : hole-fillings → env → Fuel → env → assertions → Set where
RENil : ∀{⛽ F} → F ⊢ ∅ ⌊ ⛽ ⌋:⇨ ∅ := []
REInd : ∀{⛽ F E E' x r r' A A'} →
F ⊢ E ⌊ ⛽ ⌋:⇨ E' := A →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A' →
F ⊢ E ,, (x , r) ⌊ ⛽ ⌋:⇨ (E' ,, (x , r')) := A ++ A'
data _⊢_⌊_⌋⇨_:=_ : hole-fillings → result → Fuel → result → assertions → Set where
RHoleResume : ∀{⛽ F E u r r' e A A'} →
(u , e) ∈ F →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A' →
F ⊢ [ E ]??[ u ] ⌊ ⛽ ⌋⇨ r' := A ++ A'
RHoleIndet : ∀{⛽ F E E' u A} →
u # F →
F ⊢ E ⌊ ⛽ ⌋:⇨ E' := A →
F ⊢ [ E ]??[ u ] ⌊ ⛽ ⌋⇨ [ E' ]??[ u ] := A
RUnit : ∀{⛽ F} → F ⊢ ⟨⟩ ⌊ ⛽ ⌋⇨ ⟨⟩ := []
RPair : ∀{⛽ F r1 r2 r1' r2' A1 A2} →
F ⊢ r1 ⌊ ⛽ ⌋⇨ r1' := A1 →
F ⊢ r2 ⌊ ⛽ ⌋⇨ r2' := A2 →
F ⊢ ⟨ r1 , r2 ⟩ ⌊ ⛽ ⌋⇨ ⟨ r1' , r2' ⟩ := A1 ++ A2
RCtor : ∀{⛽ F c r r' A} →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A →
F ⊢ C[ c ] r ⌊ ⛽ ⌋⇨ (C[ c ] r') := A
RApp : ∀{⛽ ⛽↓ F r1 r2 r r' Ef f x ef r1' r2' A1 A2 Af A'} →
⛽ ⛽⇓ ⛽↓ →
F ⊢ r1 ⌊ ⛽ ⌋⇨ r1' := A1 →
r1' == [ Ef ]fix f ⦇·λ x => ef ·⦈ →
F ⊢ r2 ⌊ ⛽ ⌋⇨ r2' := A2 →
(Ef ,, (f , r1') ,, (x , r2')) ⊢ ef ⌊ ⛽↓ ⌋⇒ r ⊣ Af →
F ⊢ r ⌊ ⛽↓ ⌋⇨ r' := A' →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨ r' := A1 ++ A2 ++ Af ++ A'
RAppIndet : ∀{⛽ F r1 r2 r1' r2' A1 A2} →
F ⊢ r1 ⌊ ⛽ ⌋⇨ r1' := A1 →
(∀{Ef f x ef} → r1' ≠ [ Ef ]fix f ⦇·λ x => ef ·⦈) →
F ⊢ r2 ⌊ ⛽ ⌋⇨ r2' := A2 →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨ (r1' ∘ r2') := A1 ++ A2
RFix : ∀{⛽ F E E' f x e A} →
F ⊢ E ⌊ ⛽ ⌋:⇨ E' := A →
F ⊢ [ E ]fix f ⦇·λ x => e ·⦈ ⌊ ⛽ ⌋⇨ [ E' ]fix f ⦇·λ x => e ·⦈ := A
RPrj : ∀{⛽ F i r r1 r2 A} →
F ⊢ r ⌊ ⛽ ⌋⇨ ⟨ r1 , r2 ⟩ := A →
F ⊢ prj[ i ] r ⌊ ⛽ ⌋⇨ prj i r1 r2 := A
RPrjIndet : ∀{⛽ F i r r' A} →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A →
(∀{r1 r2} → r' ≠ ⟨ r1 , r2 ⟩) →
F ⊢ prj[ i ] r ⌊ ⛽ ⌋⇨ prj[ i ] r' := A
RCase : ∀{⛽ F E r rules c xc ec r' rc A A'} →
(c , |C xc => ec) ∈ rules →
F ⊢ r ⌊ ⛽ ⌋⇨ (C[ c ] r') := A →
F ⊢ [ E ]fix xc ⦇·λ xc => ec ·⦈ ∘ (C⁻¹[ c ] r) ⌊ ⛽ ⌋⇨ rc := A' →
F ⊢ [ E ]case r of⦃· rules ·⦄ ⌊ ⛽ ⌋⇨ rc := A ++ A'
RCaseIndet : ∀{⛽ F E E' r rules r' A A'} →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A →
(∀{c rc} → r' ≠ (C[ c ] rc)) →
F ⊢ E ⌊ ⛽ ⌋:⇨ E' := A' →
F ⊢ [ E ]case r of⦃· rules ·⦄ ⌊ ⛽ ⌋⇨ [ E' ]case r' of⦃· rules ·⦄ := A ++ A'
RUnwrapCtor : ∀{⛽ F r c rc A} →
F ⊢ r ⌊ ⛽ ⌋⇨ C[ c ] rc := A →
F ⊢ C⁻¹[ c ] r ⌊ ⛽ ⌋⇨ rc := A
RUnwrapIndet : ∀{⛽ F c r r' A} →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A →
(∀{rc} → r' ≠ (C[ c ] rc)) →
F ⊢ C⁻¹[ c ] r ⌊ ⛽ ⌋⇨ C⁻¹[ c ] r' := A
-- Generic resumption failure - this goes through if resumption would fail due to failure
-- of some evaluation that occurs during resumption.
mutual
data _⊢_⌊_⌋:⇨∅ : hole-fillings → env → Fuel → Set where
RFERes : ∀{⛽ F E x r} →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ (E ,, (x , r)) ⌊ ⛽ ⌋:⇨∅
RFEEnv : ∀{⛽ F E x r} →
F ⊢ E ⌊ ⛽ ⌋:⇨∅ →
F ⊢ (E ,, (x , r)) ⌊ ⛽ ⌋:⇨∅
{- TODO we must choose between this approach and the one prior
RFE : ∀{⛽ F E x r} →
(x , r) ∈ E →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ E ⌊ ⛽ ⌋:⇨∅
-}
data _⊢_⌊_⌋⇨∅ : hole-fillings → result → Fuel → Set where
RFHoleEval : ∀{⛽ F E u e} →
(u , e) ∈ F →
E ⊢ e ⌊ ⛽ ⌋⇒∅ →
F ⊢ [ E ]??[ u ] ⌊ ⛽ ⌋⇨∅
RFHoleRes : ∀{⛽ F E u e r A} →
(u , e) ∈ F →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ [ E ]??[ u ] ⌊ ⛽ ⌋⇨∅
RFHoleIndet : ∀{⛽ F E u} →
u # F →
F ⊢ E ⌊ ⛽ ⌋:⇨∅ →
F ⊢ [ E ]??[ u ] ⌊ ⛽ ⌋⇨∅
RFPair1 : ∀{⛽ F r1 r2} →
F ⊢ r1 ⌊ ⛽ ⌋⇨∅ →
F ⊢ ⟨ r1 , r2 ⟩ ⌊ ⛽ ⌋⇨∅
RFPair2 : ∀{⛽ F r1 r2} →
F ⊢ r2 ⌊ ⛽ ⌋⇨∅ →
F ⊢ ⟨ r1 , r2 ⟩ ⌊ ⛽ ⌋⇨∅
RFCtor : ∀{⛽ F c r} →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ C[ c ] r ⌊ ⛽ ⌋⇨∅
RFAppFun : ∀{⛽ F r1 r2} →
F ⊢ r1 ⌊ ⛽ ⌋⇨∅ →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨∅
RFAppArg : ∀{⛽ F r1 r2} →
F ⊢ r2 ⌊ ⛽ ⌋⇨∅ →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨∅
RFAppEval : ∀{⛽ ⛽↓ F r1 r2 Ef f x ef r1' r2' A1 A2} →
⛽ ⛽⇓ ⛽↓ →
F ⊢ r1 ⌊ ⛽ ⌋⇨ r1' := A1 →
r1' == [ Ef ]fix f ⦇·λ x => ef ·⦈ →
F ⊢ r2 ⌊ ⛽ ⌋⇨ r2' := A2 →
(Ef ,, (f , r1') ,, (x , r2')) ⊢ ef ⌊ ⛽↓ ⌋⇒∅ →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨∅
RFAppRes : ∀{⛽ ⛽↓ F r1 r2 Ef f x ef r1' r2' r A1 A2 Af} →
⛽ ⛽⇓ ⛽↓ →
F ⊢ r1 ⌊ ⛽ ⌋⇨ r1' := A1 →
r1' == [ Ef ]fix f ⦇·λ x => ef ·⦈ →
F ⊢ r2 ⌊ ⛽ ⌋⇨ r2' := A2 →
(Ef ,, (f , r1') ,, (x , r2')) ⊢ ef ⌊ ⛽↓ ⌋⇒ r ⊣ Af →
F ⊢ r ⌊ ⛽↓ ⌋⇨∅ →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨∅
RFFix : ∀{⛽ F E f x e} →
F ⊢ E ⌊ ⛽ ⌋:⇨∅ →
F ⊢ [ E ]fix f ⦇·λ x => e ·⦈ ⌊ ⛽ ⌋⇨∅
RFPrj : ∀{⛽ F i r} →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ prj[ i ] r ⌊ ⛽ ⌋⇨∅
RFCaseScrut : ∀{⛽ F E r rules} →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ [ E ]case r of⦃· rules ·⦄ ⌊ ⛽ ⌋⇨∅
RFCase : ∀{⛽ F E r rules c xc ec r' A} →
(c , |C xc => ec) ∈ rules →
F ⊢ r ⌊ ⛽ ⌋⇨ (C[ c ] r') := A →
F ⊢ [ E ]fix xc ⦇·λ xc => ec ·⦈ ∘ (C⁻¹[ c ] r) ⌊ ⛽ ⌋⇨∅ →
F ⊢ [ E ]case r of⦃· rules ·⦄ ⌊ ⛽ ⌋⇨∅
RFCaseIndet : ∀{⛽ F E r rules r' A} →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A →
(∀{c rc} → r' ≠ (C[ c ] rc)) →
F ⊢ E ⌊ ⛽ ⌋:⇨∅ →
F ⊢ [ E ]case r of⦃· rules ·⦄ ⌊ ⛽ ⌋⇨∅
RFUnwrapCtor : ∀{⛽ F c r} →
F ⊢ r ⌊ ⛽ ⌋⇨∅ →
F ⊢ C⁻¹[ c ] r ⌊ ⛽ ⌋⇨∅
RFLimit : ∀{F r} → F ⊢ r ⌊ ⛽⟨ 0 ⟩ ⌋⇨∅
data Filter_:=_ : excons → excons → Set where
FilterNil : Filter [] := []
FilterYes : ∀{X X' E ex} →
Filter X := X' →
ex ≠ ¿¿ →
Filter (E , ex) :: X := ((E , ex) :: X')
FilterNo : ∀{X X' E} →
Filter X := X' →
Filter (E , ¿¿) :: X := X'
-- Assertion Satisfaction and Simplification
data _⌊_⌋⊨ᴬ_ : hole-fillings → Fuel → assertions → Set where
SANil : ∀{⛽ F} → F ⌊ ⛽ ⌋⊨ᴬ []
SAInd : ∀{⛽ F r v r' A A'} →
F ⌊ ⛽ ⌋⊨ᴬ A →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A' →
F ⌊ ⛽ ⌋⊨ᴬ A' →
⌈ r' ⌉:= v →
F ⌊ ⛽ ⌋⊨ᴬ ((r , v) :: A)
-- Example Satisfaction (of Results)
data _⊢_⌊_⌋⊨ᴿ_ : hole-fillings → result → Fuel → ex → Set where
XSTop : ∀{⛽ F r} → F ⊢ r ⌊ ⛽ ⌋⊨ᴿ ¿¿
XSUnit : ∀{⛽ F} → F ⊢ ⟨⟩ ⌊ ⛽ ⌋⊨ᴿ ⟨⟩
XSPair : ∀{⛽ F r1 r2 ex1 ex2} →
F ⊢ r1 ⌊ ⛽ ⌋⊨ᴿ ex1 →
F ⊢ r2 ⌊ ⛽ ⌋⊨ᴿ ex2 →
F ⊢ ⟨ r1 , r2 ⟩ ⌊ ⛽ ⌋⊨ᴿ ⟨ ex1 , ex2 ⟩
XSCtor : ∀{⛽ F r c ex} →
F ⊢ r ⌊ ⛽ ⌋⊨ᴿ ex →
F ⊢ C[ c ] r ⌊ ⛽ ⌋⊨ᴿ (C[ c ] ex)
XSInOut : ∀{⛽ F r1 r2 v2 ex r A} →
⌈ r2 ⌉:= v2 →
F ⊢ r1 ∘ r2 ⌊ ⛽ ⌋⇨ r := A →
F ⊢ r ⌊ ⛽ ⌋⊨ᴿ ex →
F ⌊ ⛽ ⌋⊨ᴬ A →
F ⊢ r1 ⌊ ⛽ ⌋⊨ᴿ (v2 ↦ ex)
-- Example Satisfaction (of Expressions)
data _⊢_⌊_⌋⊨ᴱ_ : hole-fillings → exp → Fuel → excons → Set where
SatNil : ∀{⛽ F e} → F ⊢ e ⌊ ⛽ ⌋⊨ᴱ []
SatTop : ∀{⛽ F e E X} →
F ⊢ e ⌊ ⛽ ⌋⊨ᴱ X →
F ⊢ e ⌊ ⛽ ⌋⊨ᴱ ((E , ¿¿) :: X)
SatInd : ∀{⛽ F e E ex X r r' A A'} →
ex ≠ ¿¿ →
F ⊢ e ⌊ ⛽ ⌋⊨ᴱ X →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A' →
F ⊢ r' ⌊ ⛽ ⌋⊨ᴿ ex →
F ⌊ ⛽ ⌋⊨ᴬ A ++ A' →
F ⊢ e ⌊ ⛽ ⌋⊨ᴱ ((E , ex) :: X)
data _⌊_⌋⊨ᵁ_ : hole-fillings → Fuel → excons ctx → Set where
CSNil : ∀{⛽ F} → F ⌊ ⛽ ⌋⊨ᵁ ∅
CSInd : ∀{⛽ F U u X} →
F ⌊ ⛽ ⌋⊨ᵁ U →
F ⊢ ??[ u ] ⌊ ⛽ ⌋⊨ᴱ X →
F ⌊ ⛽ ⌋⊨ᵁ (U ,, (u , X))
-- Constraint Satisfaction
_⌊_⌋⊨ᴷ_ : hole-fillings → Fuel → constraints → Set
F ⌊ ⛽ ⌋⊨ᴷ (F0 , U) =
(∀{u e} → (u , e) ∈ F0 → (u , e) ∈ F) ∧
F ⌊ ⛽ ⌋⊨ᵁ U
-- constraints merge
_⊕_:=_ : constraints → constraints → constraints → Set
(F1 , U1) ⊕ (F2 , U2) := (F' , U') = F1 ≈ F2 ∧ F1 ∪ F2 == F' ∧ U1 ⊎ U2 == U'
mutual
-- example unevaluation
data _,_,_⊢_⇐⌊_⌋_:=_ : hctx → denv → hole-fillings → result → Fuel → ex → constraints → Set where
UTop : ∀{⛽ Δ Σ' F r} → Δ , Σ' , F ⊢ r ⇐⌊ ⛽ ⌋ ¿¿ := (∅ , ∅)
UHole : ∀{⛽ Δ Σ' F E u ex} →
ex ≠ ¿¿ →
Δ , Σ' , F ⊢ [ E ]??[ u ] ⇐⌊ ⛽ ⌋ ex := (∅ , ■ (u , (E , ex) :: []))
UUnit : ∀{⛽ Δ Σ' F} → Δ , Σ' , F ⊢ ⟨⟩ ⇐⌊ ⛽ ⌋ ⟨⟩ := (∅ , ∅)
UCtor : ∀{⛽ Δ Σ' F c r ex K} →
Δ , Σ' , F ⊢ r ⇐⌊ ⛽ ⌋ ex := K →
Δ , Σ' , F ⊢ C[ c ] r ⇐⌊ ⛽ ⌋ C[ c ] ex := K
UPair : ∀{⛽ Δ Σ' F r1 r2 ex1 ex2 K1 K2 K'} →
Δ , Σ' , F ⊢ r1 ⇐⌊ ⛽ ⌋ ex1 := K1 →
Δ , Σ' , F ⊢ r2 ⇐⌊ ⛽ ⌋ ex2 := K2 →
K1 ⊕ K2 := K' →
Δ , Σ' , F ⊢ ⟨ r1 , r2 ⟩ ⇐⌊ ⛽ ⌋ ⟨ ex1 , ex2 ⟩ := K'
UFix : ∀{⛽ ⛽↓ Δ Σ' F E f x e rf v r ex K} →
⛽ ⛽⇓ ⛽↓ →
rf == [ E ]fix f ⦇·λ x => e ·⦈ →
⌈ r ⌉:= v →
Δ , Σ' , F ⊢ e ⌊ ⛽ ⌋⇌ ((E ,, (f , rf) ,, (x , r)) , ex) :: [] := K →
Δ , Σ' , F ⊢ rf ⇐⌊ ⛽ ⌋ v ↦ ex := K
UApp : ∀{⛽ Δ Σ' F r1 r2 ex v2 K} →
ex ≠ ¿¿ →
⌈ r2 ⌉:= v2 →
Δ , Σ' , F ⊢ r1 ⇐⌊ ⛽ ⌋ v2 ↦ ex := K →
Δ , Σ' , F ⊢ r1 ∘ r2 ⇐⌊ ⛽ ⌋ ex := K
UPrj1 : ∀{⛽ Δ Σ' F r ex K} →
ex ≠ ¿¿ →
Δ , Σ' , F ⊢ r ⇐⌊ ⛽ ⌋ ⟨ ex , ¿¿ ⟩ := K →
Δ , Σ' , F ⊢ prj[ P1 ] r ⇐⌊ ⛽ ⌋ ex := K
UPrj2 : ∀{⛽ Δ Σ' F r ex K} →
ex ≠ ¿¿ →
Δ , Σ' , F ⊢ r ⇐⌊ ⛽ ⌋ ⟨ ¿¿ , ex ⟩ := K →
Δ , Σ' , F ⊢ prj[ P2 ] r ⇐⌊ ⛽ ⌋ ex := K
UCase : ∀{⛽ ⛽↓ Δ Σ' F E r rules ex c xc ec K1 K2 K'} →
ex ≠ ¿¿ →
⛽ ⛽⇓ ⛽↓ →
(c , |C xc => ec) ∈ rules →
Δ , Σ' , F ⊢ r ⇐⌊ ⛽ ⌋ C[ c ] ¿¿ := K1 →
Δ , Σ' , F ⊢ ec ⌊ ⛽↓ ⌋⇌ ((E ,, (xc , C⁻¹[ c ] r)) , ex) :: [] := K2 →
K1 ⊕ K2 := K' →
Δ , Σ' , F ⊢ [ E ]case r of⦃· rules ·⦄ ⇐⌊ ⛽ ⌋ ex := K'
UCaseGuess : ∀{⛽ ⛽↓ Δ Σ' F F' E r rules ex c xc ec r' A K K' Kₘ₁ Kₘ₂} →
ex ≠ ¿¿ →
⛽ ⛽⇓ ⛽↓ →
(c , |C xc => ec) ∈ rules →
Δ , Σ' ⊢ᴴ F' →
F ## F' →
F ∪ F' ⊢ r ⌊ ⛽ ⌋⇨ C[ c ] r' := A →
Δ , Σ' ⊢Simplify A ⌊ ⛽ ⌋:= K →
Δ , Σ' , F ∪ F' ⊢ ec ⌊ ⛽↓ ⌋⇌ ((E ,, (xc , r')) , ex) :: [] := K' →
K ⊕ K' := Kₘ₁ →
(F' , ∅) ⊕ Kₘ₁ := Kₘ₂ →
Δ , Σ' , F ⊢ [ E ]case r of⦃· rules ·⦄ ⇐⌊ ⛽ ⌋ ex := Kₘ₂
UUnwrapCtor : ∀{⛽ Δ Σ' F c r ex K} →
ex ≠ ¿¿ →
Δ , Σ' , F ⊢ r ⇐⌊ ⛽ ⌋ C[ c ] ex := K →
Δ , Σ' , F ⊢ C⁻¹[ c ] r ⇐⌊ ⛽ ⌋ ex := K
-- Assertion Simplification
data _,_⊢Simplify_⌊_⌋:=_ : hctx → denv → assertions → Fuel → constraints → Set where
SNil : ∀{⛽ Δ Σ'} → Δ , Σ' ⊢Simplify [] ⌊ ⛽ ⌋:= (∅ , ∅)
SInd : ∀{⛽ Δ Σ' r v A K K' K''} →
Δ , Σ' ⊢Simplify A ⌊ ⛽ ⌋:= K →
r final →
Δ , Σ' , ∅ ⊢ r ⇐⌊ ⛽ ⌋ ⌊ v ⌋ := K' →
K ⊕ K' := K'' →
Δ , Σ' ⊢Simplify (r , v) :: A ⌊ ⛽ ⌋:= K''
-- Live Bidirectional Example Checking
data _,_,_⊢_⌊_⌋⇌_:=_ : hctx → denv → hole-fillings → exp → Fuel → excons → constraints → Set where
ChkNil : ∀{⛽ Δ Σ' F e} → Δ , Σ' , F ⊢ e ⌊ ⛽ ⌋⇌ [] := (∅ , ∅)
ChkInd : ∀{⛽ Δ Σ' F e E ex X r r' A A' K K' K'' Kₘ₁ Kₘ₂} →
Δ , Σ' , F ⊢ e ⌊ ⛽ ⌋⇌ X := K →
E ⊢ e ⌊ ⛽ ⌋⇒ r ⊣ A →
F ⊢ r ⌊ ⛽ ⌋⇨ r' := A' →
Δ , Σ' , F ⊢ r' ⇐⌊ ⛽ ⌋ ex := K' →
Δ , Σ' ⊢Simplify A ++ A' ⌊ ⛽ ⌋:= K'' →
K' ⊕ K'' := Kₘ₁ →
K ⊕ Kₘ₁ := Kₘ₂ →
Δ , Σ' , F ⊢ e ⌊ ⛽ ⌋⇌ ((E , ex) :: X) := Kₘ₂
-- TODO theorems for all the things, including resumption, synthesis, solve, satisfaction, consistency, Group, and Filter
-- Type-Directed Guessing
data _⊢⦇_⊢●:_⦈:=ᴳ_ : denv → tctx → typ → exp → Set where
GUnit : ∀{Σ' Γ} → Σ' ⊢⦇ Γ ⊢●: ⟨⟩ ⦈:=ᴳ ⟨⟩
GPair : ∀{Σ' Γ τ1 τ2 e1 e2} →
Σ' ⊢⦇ Γ ⊢●: τ1 ⦈:=ᴳ e1 →
Σ' ⊢⦇ Γ ⊢●: τ2 ⦈:=ᴳ e2 →
Σ' ⊢⦇ Γ ⊢●: ⟨ τ1 × τ2 ⟩ ⦈:=ᴳ ⟨ e1 , e2 ⟩
GCtor : ∀{Σ' Γ d cctx c τ e} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Σ' ⊢⦇ Γ ⊢●: τ ⦈:=ᴳ e →
Σ' ⊢⦇ Γ ⊢●: D[ d ] ⦈:=ᴳ (C[ c ] e)
GFix : ∀{Σ' Γ τ1 τ2 f x e} →
Σ' ⊢⦇ Γ ,, (f , τ1 ==> τ2) ,, (x , τ1) ⊢●: τ2 ⦈:=ᴳ e →
Σ' ⊢⦇ Γ ⊢●: τ1 ==> τ2 ⦈:=ᴳ fix f ⦇·λ x => e ·⦈
GCase : ∀{Σ' Γ τ e rules d cctx} →
(d , cctx) ∈ π1 Σ' →
(∀{c} → dom cctx c → dom rules c) →
(∀{c} → dom rules c → dom cctx c) →
Σ' ⊢⦇ Γ ⊢●: D[ d ] ⦈:=ᴳ e →
(∀{c x-c e-c τ-c} →
(c , |C x-c => e-c) ∈ rules →
(c , τ-c) ∈ cctx →
Σ' ⊢⦇ Γ ,, (x-c , τ-c) ⊢●: τ ⦈:=ᴳ e-c) →
Σ' ⊢⦇ Γ ⊢●: τ ⦈:=ᴳ case e of⦃· rules ·⦄
GVar : ∀{Σ' Γ τ x} →
(x , τ) ∈ Γ →
Σ' ⊢⦇ Γ ⊢●: τ ⦈:=ᴳ X[ x ]
GApp : ∀{Σ' Γ τ e1 e2 τ'} →
Σ' ⊢⦇ Γ ⊢●: τ' ==> τ ⦈:=ᴳ e1 →
Σ' ⊢⦇ Γ ⊢●: τ' ⦈:=ᴳ e2 →
Σ' ⊢⦇ Γ ⊢●: τ ⦈:=ᴳ (e1 ∘ e2)
GPrj : ∀{Σ' Γ τ1 τ2 i e} →
Σ' ⊢⦇ Γ ⊢●: ⟨ τ1 × τ2 ⟩ ⦈:=ᴳ e →
Σ' ⊢⦇ Γ ⊢●: prj i τ1 τ2 ⦈:=ᴳ (prj[ i ] e)
-- TODO theorem that if u # Δ , then u is new in a type-checked exp or result
-- TODO theorem that any hole in the exp produced by refinement is in the goals
-- Type-and-Example-Directed Refinement
data _⊢⦇_⊢●:_⊨_⦈:=ᴿ_⊣_ : denv → tctx → typ → excons → exp → goals → Set where
RefUnit : ∀{Σ' Γ X Xf} →
Filter X := Xf →
(∀{i E ex} → Xf ⟦ i ⟧ == Some (E , ex) → ex == ⟨⟩) →
Σ' ⊢⦇ Γ ⊢●: ⟨⟩ ⊨ X ⦈:=ᴿ ⟨⟩ ⊣ []
RefPair : ∀{Σ' Γ τ1 τ2 X u1 u2 G1 G2} {E-ex1-ex2s : List (env ∧ ex ∧ ex)} →
Filter X := map (λ {(E , ex1 , ex2) → E , ⟨ ex1 , ex2 ⟩}) E-ex1-ex2s →
G1 == Γ ⊢??[ u1 ]: τ1 ⊨ map (λ {(E , ex1 , ex2) → E , ex1}) E-ex1-ex2s →
G2 == Γ ⊢??[ u2 ]: τ2 ⊨ map (λ {(E , ex1 , ex2) → E , ex2}) E-ex1-ex2s →
Σ' ⊢⦇ Γ ⊢●: ⟨ τ1 × τ2 ⟩ ⊨ X ⦈:=ᴿ ⟨ ??[ u1 ] , ??[ u2 ] ⟩ ⊣ (G1 :: (G2 :: []))
RefCtor : ∀{Σ' Γ X X' d cctx c τ u G} →
(d , cctx) ∈ π1 Σ' →
(c , τ) ∈ cctx →
Filter X := map (λ {(E , ex) → E , C[ c ] ex}) X' →
G == Γ ⊢??[ u ]: τ ⊨ X' →
Σ' ⊢⦇ Γ ⊢●: D[ d ] ⊨ X ⦈:=ᴿ C[ c ] ??[ u ] ⊣ (G :: [])
RefFix : ∀{Σ' Γ X τ1 τ2 f x u X' G} {E-in-inᶜ-outs : List (env ∧ val ∧ result ∧ ex)} →
(∀{i E-i v-i r-i ex-i} →
E-in-inᶜ-outs ⟦ i ⟧ == Some (E-i , v-i , r-i , ex-i) →
⌈ r-i ⌉:= v-i) →
Filter X := map (λ {(E , in' , _ , out) → E , in' ↦ out}) E-in-inᶜ-outs →
X' == map (λ {(E , _ , in' , out) → (E ,, (f , [ E ]fix f ⦇·λ x => ??[ u ] ·⦈) ,, (x , in')) , out}) E-in-inᶜ-outs →
G == (Γ ,, (f , τ1 ==> τ2) ,, (x , τ1)) ⊢??[ u ]: τ2 ⊨ X' →
Σ' ⊢⦇ Γ ⊢●: τ1 ==> τ2 ⊨ X ⦈:=ᴿ fix f ⦇·λ x => ??[ u ] ·⦈ ⊣ (G :: [])
-- Type-and-Example-Directed Branching
data _⊢⦇_⊢●:_⊨_⦈⌊_⌋:=ᴮ_⊣_ : denv → tctx → typ → excons → Fuel → exp → goals → Set where
BCase : ∀{⛽ Σ' Γ X Xf τ e rules d cctx x τ+u+X⁺-ctx Gs} →
Filter X := Xf →
-- choose one fresh variable name that will be used for all cases
x # Γ →
-- τ+u+X⁺-ctx is just cctx extended with hole names and excons
cctx == ctxmap π1 τ+u+X⁺-ctx →
-- the rules can be defined from x and the hole names in τ+u+X⁺-ctx
rules == ctxmap (λ {(τ-c , u-c , X⁺-c) → |C x => ??[ u-c ]}) τ+u+X⁺-ctx →
-- the following premises appear in the paper
(d , cctx) ∈ π1 Σ' →
Σ' ⊢⦇ Γ ⊢●: D[ d ] ⦈:=ᴳ e →
Gs == map
(λ {(τ-c , u-c , X⁺-c) →
-- this corresponds to the goal definition in the paper
(Γ ,, (x , τ-c)) ⊢??[ u-c ]: τ ⊨
-- this corresponds to the definition of each X_i in the paper
map (λ {(E , ex , r) → (E ,, (x , r)) , ex}) X⁺-c})
(ctx⇒values τ+u+X⁺-ctx) →
-- the following premise checks that every X⁺-c obeys the rules in the paper premise
(∀{c τ-c u-c X⁺-c} →
(c , τ-c , u-c , X⁺-c) ∈ τ+u+X⁺-ctx →
-- for each excon (extended with a result r-j) of X⁺-c, ...
(∀{j E-j ex-j r-j} →
X⁺-c ⟦ j ⟧ == Some (E-j , ex-j , r-j) →
-- the excon is an element of Filter X, and ...
Σ[ k ∈ Nat ] (Xf ⟦ k ⟧ == Some (E-j , ex-j)) ∧
-- the scrutinee e will evaluate to constructor c applied to the specified argument r-j
E-j ⊢ e ⌊ ⛽ ⌋⇒ C[ c ] r-j ⊣ [])) →
-- the last premise in the paper - every excon in Filter X is an element of some X⁺-c for some c
(∀{k E-k ex-k} →
Xf ⟦ k ⟧ == Some (E-k , ex-k) →
Σ[ c ∈ Nat ] Σ[ τ-c ∈ typ ] Σ[ u-c ∈ Nat ] Σ[ X⁺-c ∈ List (env ∧ ex ∧ result)] Σ[ j ∈ Nat ] Σ[ r-j ∈ result ] (
(c , τ-c , u-c , X⁺-c) ∈ τ+u+X⁺-ctx ∧
X⁺-c ⟦ j ⟧ == Some (E-k , ex-k , r-j))) →
Σ' ⊢⦇ Γ ⊢●: τ ⊨ X ⦈⌊ ⛽ ⌋:=ᴮ case e of⦃· rules ·⦄ ⊣ Gs
-- Hole Filling
data _,_,_⊢⦇_⊢??[_]:_⊨_⦈⌊_⌋:=_,_ : hctx → denv → hole-fillings → tctx → Nat → typ → excons → Fuel → constraints → hctx → Set where
HFRefBranch : ∀{⛽ Δ Σ' F Γ u τ X e Gs K Δ'} →
-- this premise ensures that all holes are fresh
(∀{i j g-i g-j} →
Gs ⟦ i ⟧ == Some g-i →
Gs ⟦ j ⟧ == Some g-j →
goal.g-id g-i # Δ ∧
goal.g-id g-i ≠ u ∧
(i ≠ j → goal.g-id g-i ≠ goal.g-id g-j)) →
(Σ' ⊢⦇ Γ ⊢●: τ ⊨ X ⦈:=ᴿ e ⊣ Gs ∨
Σ' ⊢⦇ Γ ⊢●: τ ⊨ X ⦈⌊ ⛽ ⌋:=ᴮ e ⊣ Gs) →
K == (■ (u , e) , list⇒ctx (map (λ {(_ ⊢??[ u' ]: _ ⊨ X') → u' , X'}) Gs)) →
Δ' == list⇒ctx (map (λ {(Γ' ⊢??[ u' ]: τ' ⊨ _) → u' , Γ' , τ'}) Gs) →
Δ , Σ' , F ⊢⦇ Γ ⊢??[ u ]: τ ⊨ X ⦈⌊ ⛽ ⌋:= K , Δ'
HFGuessChk : ∀{⛽ Δ Σ' F Γ u τ X e K K'} →
Σ' ⊢⦇ Γ ⊢●: τ ⦈:=ᴳ e →
Δ , Σ' , (F ,, (u , e)) ⊢ e ⌊ ⛽ ⌋⇌ X := K →
(■ (u , e) , ∅) ⊕ K := K' →
Δ , Σ' , F ⊢⦇ Γ ⊢??[ u ]: τ ⊨ X ⦈⌊ ⛽ ⌋:= K' , ∅
HFDefer : ∀{⛽ Δ Σ' F Γ u τ X} →
X ≠ [] →
Filter X := [] →
Δ , Σ' , F ⊢⦇ Γ ⊢??[ u ]: τ ⊨ X ⦈⌊ ⛽ ⌋:= (■ (u , ??[ u ]) , ∅) , ∅
{- TODO - later, we need to fix this stuff up too
data _,_IterSolve_,_⌊_⌋:=_,_ : hctx → denv → hole-fillings → excons ctx → Fuel → hole-fillings → hctx → Set where
ISFin : ∀{⛽ Δ Σ' F-0 U F' Δ' u+F+Δs} →
(∀{u} → dom U u → dom Δ u) →
∥ u+F+Δs ∥ == 1+ ∥ U ∥ →
Σ[ u-0 ∈ Nat ] (u+F+Δs ⟦ 0 ⟧ == Some (u-0 , F-0 , Δ)) →
(∀{u W} →
(u , W) ∈ U →
Σ[ i ∈ Nat ] Σ[ F-i ∈ hole-fillings ] Σ[ Δ-i ∈ hctx ] (
1+ i < ∥ u+F+Δs ∥ ∧ u+F+Δs ⟦ i ⟧ == Some (u , F-i , Δ-i))) →
(∀{i u-i u-i+1 W-i F-i F-i+1 Δ-i Δ-i+1 Γ-i τ-i} →
1+ i < ∥ u+F+Δs ∥ →
u+F+Δs ⟦ i ⟧ == Some (u-i , F-i , Δ-i) →
u+F+Δs ⟦ 1+ i ⟧ == Some (u-i+1 , F-i+1 , Δ-i+1) →
(u-i , W-i) ∈ U →
(u-i , Γ-i , τ-i) ∈ Δ →
Σ[ F'-i ∈ hole-fillings ] Σ[ Δ'-i ∈ hctx ] (
(Δ-i , Σ' , F-i ⊢⦇ Γ-i ⊢??[ u-i ]: τ-i ⊨ W-i ⦈⌊ ⛽ ⌋:= (F'-i , ∅) , Δ'-i) ∧
F-i+1 == F-i ∪ F'-i ∧
Δ-i+1 == Δ-i ∪ Δ'-i)) →
Σ[ u-n ∈ Nat ] (u+F+Δs ⟦ ∥ U ∥ ⟧ == Some (u-n , F' , Δ')) →
Δ , Σ' IterSolve F-0 , U ⌊ ⛽ ⌋:= F' , Δ'
ISInd : ∀{⛽ Δ Σ' F-0 U F' Δ' u+F+U+Δs U' Δ-n F-n} →
(∀{u} → dom U u → dom Δ u) →
∥ u+F+U+Δs ∥ == 1+ ∥ U ∥ →
Σ[ u-0 ∈ Nat ] (u+F+U+Δs ⟦ 0 ⟧ == Some (u-0 , F-0 , ∅ , Δ)) →
(∀{u W} →
(u , W) ∈ U →
Σ[ i ∈ Nat ] Σ[ F-i ∈ hole-fillings ] Σ[ U-i ∈ excons ctx ] Σ[ Δ-i ∈ hctx ] (
1+ i < ∥ u+F+U+Δs ∥ ∧ u+F+U+Δs ⟦ i ⟧ == Some (u , F-i , U-i , Δ-i))) →
(∀{i u-i u-i+1 W-i F-i F-i+1 U-i U-i+1 Δ-i Δ-i+1 Γ-i τ-i} →
1+ i < ∥ u+F+U+Δs ∥ →
u+F+U+Δs ⟦ i ⟧ == Some (u-i , F-i , U-i , Δ-i) →
u+F+U+Δs ⟦ 1+ i ⟧ == Some (u-i+1 , F-i+1 , U-i+1 , Δ-i+1) →
(u-i , W-i) ∈ U →
(u-i , Γ-i , τ-i) ∈ Δ →
Σ[ F'-i ∈ hole-fillings ] Σ[ Δ'-i ∈ hctx ] (
(Δ-i , Σ' , F-i ⊢⦇ Γ-i ⊢??[ u-i ]: τ-i ⊨ W-i ⦈⌊ ⛽ ⌋:= (F'-i , U-i+1) , Δ'-i) ∧
F-i+1 == F-i ∪ F'-i ∧
Δ-i+1 == Δ-i ∪ Δ'-i)) →
U' == foldl _∪_ ∅ (map (π1 ⊙ (π2 ⊙ π2)) u+F+U+Δs) →
U' ≠ ∅ →
Σ[ u-n ∈ Nat ] Σ[ U-n ∈ excons ctx ] (u+F+U+Δs ⟦ ∥ U ∥ ⟧ == Some (u-n , F-n , U-n , Δ-n)) →
Δ-n , Σ' IterSolve F-n , U' ⌊ ⛽ ⌋:= F' , Δ' →
Δ , Σ' IterSolve F-0 , U ⌊ ⛽ ⌋:= F' , Δ'
data _,_Solve_⌊_⌋:=_ : hctx → denv → constraints → Fuel → hole-fillings → Set where
Solve : ∀{⛽ Δ Σ' F0 U F Δ'} →
Δ , Σ' IterSolve F0 , U ⌊ ⛽ ⌋:= F , Δ' →
Δ , Σ' Solve (F0 , U) ⌊ ⛽ ⌋:= F
-}
{- TODO
-- those external expressions without holes
data _ecomplete : hexp → Set where
ECConst : c ecomplete
ECAsc : ∀{τ e} → τ tcomplete → e ecomplete → (e ·: τ) ecomplete
ECVar : ∀{x} → (X x) ecomplete
ECLam1 : ∀{x e} → e ecomplete → (·λ x e) ecomplete
ECLam2 : ∀{x e τ} → e ecomplete → τ tcomplete → (·λ x [ τ ] e) ecomplete
ECAp : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → (e1 ∘ e2) ecomplete
ECFst : ∀{e} → e ecomplete → (fst e) ecomplete
ECSnd : ∀{e} → e ecomplete → (snd e) ecomplete
ECPair : ∀{e1 e2} → e1 ecomplete → e2 ecomplete → ⟨ e1 , e2 ⟩ ecomplete
-- those internal expressions without holes
data _dcomplete : ihexp → Set where
DCVar : ∀{x} → (X x) dcomplete
DCConst : c dcomplete
DCLam : ∀{x τ d} → d dcomplete → τ tcomplete → (·λ x [ τ ] d) dcomplete
DCAp : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → (d1 ∘ d2) dcomplete
DCCast : ∀{d τ1 τ2} → d dcomplete → τ1 tcomplete → τ2 tcomplete → (d ⟨ τ1 ⇒ τ2 ⟩) dcomplete
DCFst : ∀{d} → d dcomplete → (fst d) dcomplete
DCSnd : ∀{d} → d dcomplete → (snd d) dcomplete
DCPair : ∀{d1 d2} → d1 dcomplete → d2 dcomplete → ⟨ d1 , d2 ⟩ dcomplete
mutual
-- substitution typing
data _,_⊢_:s:_ : hctx → tctx → env → tctx → Set where
STAId : ∀{Γ Γ' Δ} →
((x : Nat) (τ : htyp) → (x , τ) ∈ Γ' → (x , τ) ∈ Γ) →
Δ , Γ ⊢ Id Γ' :s: Γ'
STASubst : ∀{Γ Δ σ y Γ' d τ } →
Δ , Γ ,, (y , τ) ⊢ σ :s: Γ' →
Δ , Γ ⊢ d :: τ →
Δ , Γ ⊢ Subst d y σ :s: Γ'
-- type assignment
data _,_⊢_::_ : (Δ : hctx) (Γ : tctx) (d : ihexp) (τ : htyp) → Set where
TAConst : ∀{Δ Γ} → Δ , Γ ⊢ c :: b
TAVar : ∀{Δ Γ x τ} → (x , τ) ∈ Γ → Δ , Γ ⊢ X x :: τ
TALam : ∀{ Δ Γ x τ1 d τ2} →
x # Γ →
Δ , (Γ ,, (x , τ1)) ⊢ d :: τ2 →
Δ , Γ ⊢ ·λ x [ τ1 ] d :: (τ1 ==> τ2)
TAAp : ∀{ Δ Γ d1 d2 τ1 τ} →
Δ , Γ ⊢ d1 :: τ1 ==> τ →
Δ , Γ ⊢ d2 :: τ1 →
Δ , Γ ⊢ d1 ∘ d2 :: τ
TAEHole : ∀{ Δ Γ σ u Γ' τ} →
(u , (Γ' , τ)) ∈ Δ →
Δ , Γ ⊢ σ :s: Γ' →
Δ , Γ ⊢ ⦇⦈⟨ u , σ ⟩ :: τ
TANEHole : ∀ { Δ Γ d τ' Γ' u σ τ } →
(u , (Γ' , τ)) ∈ Δ →
Δ , Γ ⊢ d :: τ' →
Δ , Γ ⊢ σ :s: Γ' →
Δ , Γ ⊢ ⦇⌜ d ⌟⦈⟨ u , σ ⟩ :: τ
TACast : ∀{ Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 →
τ1 ~ τ2 →
Δ , Γ ⊢ d ⟨ τ1 ⇒ τ2 ⟩ :: τ2
TAFailedCast : ∀{Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 →
τ1 ground →
τ2 ground →
τ1 ≠ τ2 →
Δ , Γ ⊢ d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩ :: τ2
TAFst : ∀{Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 ⊗ τ2 →
Δ , Γ ⊢ fst d :: τ1
TASnd : ∀{Δ Γ d τ1 τ2} →
Δ , Γ ⊢ d :: τ1 ⊗ τ2 →
Δ , Γ ⊢ snd d :: τ2
TAPair : ∀{Δ Γ d1 d2 τ1 τ2} →
Δ , Γ ⊢ d1 :: τ1 →
Δ , Γ ⊢ d2 :: τ2 →
Δ , Γ ⊢ ⟨ d1 , d2 ⟩ :: τ1 ⊗ τ2
-- substitution
[_/_]_ : ihexp → Nat → ihexp → ihexp
[ d / y ] c = c
[ d / y ] X x
with natEQ x y
[ d / y ] X .y | Inl refl = d
[ d / y ] X x | Inr neq = X x
[ d / y ] (·λ x [ x₁ ] d')
with natEQ x y
[ d / y ] (·λ .y [ τ ] d') | Inl refl = ·λ y [ τ ] d'
[ d / y ] (·λ x [ τ ] d') | Inr x₁ = ·λ x [ τ ] ( [ d / y ] d')
[ d / y ] ⦇⦈⟨ u , σ ⟩ = ⦇⦈⟨ u , Subst d y σ ⟩
[ d / y ] ⦇⌜ d' ⌟⦈⟨ u , σ ⟩ = ⦇⌜ [ d / y ] d' ⌟⦈⟨ u , Subst d y σ ⟩
[ d / y ] (d1 ∘ d2) = ([ d / y ] d1) ∘ ([ d / y ] d2)
[ d / y ] (d' ⟨ τ1 ⇒ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒ τ2 ⟩
[ d / y ] (d' ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩ ) = ([ d / y ] d') ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩
[ d / y ] ⟨ d1 , d2 ⟩ = ⟨ [ d / y ] d1 , [ d / y ] d2 ⟩
[ d / y ] (fst d') = fst ([ d / y ] d')
[ d / y ] (snd d') = snd ([ d / y ] d')
-- applying an environment to an expression
apply-env : env → ihexp → ihexp
apply-env (Id Γ) d = d
apply-env (Subst d y σ) d' = [ d / y ] ( apply-env σ d')
-- freshness
mutual
-- ... with respect to a hole context
data envfresh : Nat → env → Set where
EFId : ∀{x Γ} → x # Γ → envfresh x (Id Γ)
EFSubst : ∀{x d σ y} → fresh x d
→ envfresh x σ
→ x ≠ y
→ envfresh x (Subst d y σ)
-- ... for inernal expressions
data fresh : Nat → ihexp → Set where
FConst : ∀{x} → fresh x c
FVar : ∀{x y} → x ≠ y → fresh x (X y)
FLam : ∀{x y τ d} → x ≠ y → fresh x d → fresh x (·λ y [ τ ] d)
FHole : ∀{x u σ} → envfresh x σ → fresh x (⦇⦈⟨ u , σ ⟩)
FNEHole : ∀{x d u σ} → envfresh x σ → fresh x d → fresh x (⦇⌜ d ⌟⦈⟨ u , σ ⟩)
FAp : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x (d1 ∘ d2)
FCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒ τ2 ⟩)
FFailedCast : ∀{x d τ1 τ2} → fresh x d → fresh x (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
FFst : ∀{x d} → fresh x d → fresh x (fst d)
FSnd : ∀{x d} → fresh x d → fresh x (snd d)
FPair : ∀{x d1 d2} → fresh x d1 → fresh x d2 → fresh x ⟨ d1 , d2 ⟩
-- ... for external expressions
data freshh : Nat → hexp → Set where
FRHConst : ∀{x} → freshh x c
FRHAsc : ∀{x e τ} → freshh x e → freshh x (e ·: τ)
FRHVar : ∀{x y} → x ≠ y → freshh x (X y)
FRHLam1 : ∀{x y e} → x ≠ y → freshh x e → freshh x (·λ y e)
FRHLam2 : ∀{x τ e y} → x ≠ y → freshh x e → freshh x (·λ y [ τ ] e)
FRHEHole : ∀{x u} → freshh x (⦇⦈[ u ])
FRHNEHole : ∀{x u e} → freshh x e → freshh x (⦇⌜ e ⌟⦈[ u ])
FRHAp : ∀{x e1 e2} → freshh x e1 → freshh x e2 → freshh x (e1 ∘ e2)
FRHFst : ∀{x e} → freshh x e → freshh x (fst e)
FRHSnd : ∀{x e} → freshh x e → freshh x (snd e)
FRHPair : ∀{x e1 e2} → freshh x e1 → freshh x e2 → freshh x ⟨ e1 , e2 ⟩
-- with respect to all bindings in a context
freshΓ : {A : Set} → (Γ : A ctx) → (e : hexp) → Set
freshΓ {A} Γ e = (x : Nat) → dom Γ x → freshh x e
-- x is not used in a binding site in d
mutual
data unbound-in-σ : Nat → env → Set where
UBσId : ∀{x Γ} → unbound-in-σ x (Id Γ)
UBσSubst : ∀{x d y σ} → unbound-in x d
→ unbound-in-σ x σ
→ x ≠ y
→ unbound-in-σ x (Subst d y σ)
data unbound-in : (x : Nat) (d : ihexp) → Set where
UBConst : ∀{x} → unbound-in x c
UBVar : ∀{x y} → unbound-in x (X y)
UBLam2 : ∀{x d y τ} → x ≠ y
→ unbound-in x d
→ unbound-in x (·λ_[_]_ y τ d)
UBHole : ∀{x u σ} → unbound-in-σ x σ
→ unbound-in x (⦇⦈⟨ u , σ ⟩)
UBNEHole : ∀{x u σ d }
→ unbound-in-σ x σ
→ unbound-in x d
→ unbound-in x (⦇⌜ d ⌟⦈⟨ u , σ ⟩)
UBAp : ∀{ x d1 d2 } →
unbound-in x d1 →
unbound-in x d2 →
unbound-in x (d1 ∘ d2)
UBCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒ τ2 ⟩)
UBFailedCast : ∀{x d τ1 τ2} → unbound-in x d → unbound-in x (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
UBFst : ∀{x d} → unbound-in x d → unbound-in x (fst d)
UBSnd : ∀{x d} → unbound-in x d → unbound-in x (snd d)
UBPair : ∀{x d1 d2} → unbound-in x d1 → unbound-in x d2 → unbound-in x ⟨ d1 , d2 ⟩
mutual
data binders-disjoint-σ : env → ihexp → Set where
BDσId : ∀{Γ d} → binders-disjoint-σ (Id Γ) d
BDσSubst : ∀{d1 d2 y σ} → binders-disjoint d1 d2
→ binders-disjoint-σ σ d2
→ binders-disjoint-σ (Subst d1 y σ) d2
-- two terms that do not share any binders
data binders-disjoint : (d1 : ihexp) → (d2 : ihexp) → Set where
BDConst : ∀{d} → binders-disjoint c d
BDVar : ∀{x d} → binders-disjoint (X x) d
BDLam : ∀{x τ d1 d2} → binders-disjoint d1 d2
→ unbound-in x d2
→ binders-disjoint (·λ_[_]_ x τ d1) d2
BDHole : ∀{u σ d2} → binders-disjoint-σ σ d2
→ binders-disjoint (⦇⦈⟨ u , σ ⟩) d2
BDNEHole : ∀{u σ d1 d2} → binders-disjoint-σ σ d2
→ binders-disjoint d1 d2
→ binders-disjoint (⦇⌜ d1 ⌟⦈⟨ u , σ ⟩) d2
BDAp : ∀{d1 d2 d3} → binders-disjoint d1 d3
→ binders-disjoint d2 d3
→ binders-disjoint (d1 ∘ d2) d3
BDCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒ τ2 ⟩) d2
BDFailedCast : ∀{d1 d2 τ1 τ2} → binders-disjoint d1 d2 → binders-disjoint (d1 ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩) d2
BDFst : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint (fst d1) d2
BDSnd : ∀{d1 d2} → binders-disjoint d1 d2 → binders-disjoint (snd d1) d2
BDPair : ∀{d1 d2 d3} →
binders-disjoint d1 d3 →
binders-disjoint d2 d3 →
binders-disjoint ⟨ d1 , d2 ⟩ d3
mutual
-- each term has to be binders unique, and they have to be pairwise
-- disjoint with the collection of bound vars
data binders-unique-σ : env → Set where
BUσId : ∀{Γ} → binders-unique-σ (Id Γ)
BUσSubst : ∀{d y σ} → binders-unique d
→ binders-unique-σ σ
→ binders-disjoint-σ σ d
→ binders-unique-σ (Subst d y σ)
-- all the variable names in the term are unique
data binders-unique : ihexp → Set where
BUHole : binders-unique c
BUVar : ∀{x} → binders-unique (X x)
BULam : {x : Nat} {τ : htyp} {d : ihexp} → binders-unique d
→ unbound-in x d
→ binders-unique (·λ_[_]_ x τ d)
BUEHole : ∀{u σ} → binders-unique-σ σ
→ binders-unique (⦇⦈⟨ u , σ ⟩)
BUNEHole : ∀{u σ d} → binders-unique d
→ binders-unique-σ σ
→ binders-unique (⦇⌜ d ⌟⦈⟨ u , σ ⟩)
BUAp : ∀{d1 d2} → binders-unique d1
→ binders-unique d2
→ binders-disjoint d1 d2
→ binders-unique (d1 ∘ d2)
BUCast : ∀{d τ1 τ2} → binders-unique d
→ binders-unique (d ⟨ τ1 ⇒ τ2 ⟩)
BUFailedCast : ∀{d τ1 τ2} → binders-unique d
→ binders-unique (d ⟨ τ1 ⇒⦇⦈⇏ τ2 ⟩)
BUFst : ∀{d} →
binders-unique d →
binders-unique (fst d)
BUSnd : ∀{d} →
binders-unique d →
binders-unique (snd d)
BUPair : ∀{d1 d2} →
binders-unique d1 →
binders-unique d2 →
binders-disjoint d1 d2 →
binders-unique ⟨ d1 , d2 ⟩
-}
| {
"alphanum_fraction": 0.3473978815,
"avg_line_length": 44.4169944925,
"ext": "agda",
"hexsha": "006eaeb2968087ebc7a4f153d5e77a80864a9f6b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnat-myth-",
"max_forks_repo_path": "core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnat-myth-",
"max_issues_repo_path": "core.agda",
"max_line_length": 132,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a8f9299090d95f4ef1a6c2f15954c2981c0ee25c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnat-myth-",
"max_stars_repo_path": "core.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-19T23:42:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-19T23:42:31.000Z",
"num_tokens": 25319,
"size": 56454
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
module ClassicalLogic.ClassicalFive where
em = {A : Set} → (A || (A → False))
dne = {A : Set} → ((A → False) → False) → A
peirce = {A B : Set} → ((A → B) → A) → A
iad = {A B : Set} → (A → B) → ((A → False) || B)
dem = {A B : Set} → (((A → False) && (B → False)) → False) → A || B
emToDne : em → dne
emToDne em {A} pr with em {A}
emToDne em {A} pr | inl x = x
emToDne em {A} pr | inr x = exFalso (pr x)
dneToPeirce : dne → peirce
dneToPeirce dne {A} {B} aba = dne (λ z → z (aba (λ a → dne (λ _ → z a))))
peirceToIad : peirce → iad
peirceToIad peirce {A} {B} aToB = peirce (λ z → inl (λ x → z (inr (aToB x))))
iadToDem : iad → dem
iadToDem iad {A} {B} x with iad {A} {A} (λ i → i)
iadToDem iad {A} {B} x | inl notA with iad {B} {B} (λ i → i)
iadToDem iad {A} {B} x | inl notA | inl notB = exFalso (x (notA ,, notB))
iadToDem iad {A} {B} x | inl notA | inr b = inr b
iadToDem iad {A} {B} x | inr a = inl a
demToEm : dem → em
demToEm dem {A} = dem (λ z → _&&_.snd z (_&&_.fst z))
| {
"alphanum_fraction": 0.5535714286,
"avg_line_length": 31.2941176471,
"ext": "agda",
"hexsha": "b685a6654909833a632a821c6808a128e6ca6a26",
"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": "ClassicalLogic/ClassicalFive.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": "ClassicalLogic/ClassicalFive.agda",
"max_line_length": 77,
"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": "ClassicalLogic/ClassicalFive.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": 486,
"size": 1064
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open import LibraBFT.Concrete.Records as LCR
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Util.Crypto
open import Optics.All
open import Util.KVMap
open import Util.Lemmas
open import Util.PKCS
open import Util.Prelude
open import Yasm.Base
open EpochConfig
-- This module contains placeholders for the future analog of the
-- corresponding VotesOnce property. Defining the implementation
-- obligation and proving that it is an invariant of an implementation
-- is a substantial undertaking. We are working first on proving the
-- simpler VotesOnce property to settle down the structural aspects
-- before tackling the harder semantic issues.
module LibraBFT.Concrete.Properties.PreferredRound (iiah : SystemInitAndHandlers ℓ-RoundManager ConcSysParms) (𝓔 : EpochConfig) where
open LibraBFT.ImplShared.Consensus.Types.EpochDep.WithEC
import LibraBFT.Abstract.Records UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔) as Abs
import LibraBFT.Abstract.Records.Extends UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔) as Ext
open import LibraBFT.Abstract.RecordChain UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔)
open import LibraBFT.Abstract.System UID _≟UID_ NodeId 𝓔 (ConcreteVoteEvidence 𝓔)
open import LibraBFT.Concrete.Intermediate 𝓔 (ConcreteVoteEvidence 𝓔)
open import LibraBFT.Concrete.Obligations.PreferredRound 𝓔 (ConcreteVoteEvidence 𝓔)
open SystemTypeParameters ConcSysParms
open SystemInitAndHandlers iiah
open ParamsWithInitAndHandlers iiah
open import LibraBFT.ImplShared.Util.HashCollisions iiah
open import LibraBFT.Concrete.Properties.Common iiah 𝓔
open import Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms iiah PeerCanSignForPK PeerCanSignForPK-stable
open PerEpoch 𝓔
open WithAbsVote 𝓔
open LCR.WithEC 𝓔
open PerState
open PerReachableState
open IntermediateSystemState
open All-InSys-props
Block-RC-AllInSys : Abs.Vote → SystemState → Set
Block-RC-AllInSys vabs st = ∃[ b ] ( Abs.bId b ≡ abs-vBlockUID vabs
× Σ (RecordChain (Abs.B b)) (All-InSys (InSys (intSystemState st))))
ImplObligation-RC : Set (ℓ+1 ℓ-RoundManager)
ImplObligation-RC =
∀{pid s' outs pk}{pre : SystemState}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ ∀{v m} → Meta-Honest-PK pk
-- For signed every vote v of every outputted message
→ v ⊂Msg m → send m ∈ outs
→ (sig : WithVerSig pk v)
→ 0 < v ^∙ vRound
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre))
→ let post = StepPeer-post {pre = pre} (step-honest sps)
in (pcs4 : PeerCanSignForPK post v pid pk)
→ ∃[ mbr ] ( getPubKey 𝓔 mbr ≡ pk
× Block-RC-AllInSys (α-ValidVote 𝓔 v mbr) post)
-- For PreferredRound, we have two implementation obligations, one for when v is sent by the
-- step and v' has been sent before, and one for when both are sent by the step.
ImplObligation₁ : Set (ℓ+1 ℓ-RoundManager)
ImplObligation₁ =
∀{pid pid' s' outs pk}{pre : SystemState}
→ (r : ReachableSystemState pre)
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ let post = StepPeer-post {pre = pre} (step-honest sps) in
∀{mbr v vabs m v' v'abs m'}
→ Meta-Honest-PK pk
-- For signed every vote v of every outputted message
→ v' ⊂Msg m' → send m' ∈ outs
→ (sig' : WithVerSig pk v') → ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig'))
-- If v is really new and valid
→ ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre))
→ PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v' pid pk
-- And if there exists another v' that has been sent before
→ v ⊂Msg m → (pid' , m) ∈ (msgPool pre)
→ (sig : WithVerSig pk v) → ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig))
-- If v and v' share the same epoch
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
-- and v is for a smaller round
→ v ^∙ vRound < v' ^∙ vRound
-- and vabs* are the abstract Votes for v and v'
→ α-ValidVote 𝓔 v mbr ≡ vabs
→ α-ValidVote 𝓔 v' mbr ≡ v'abs
→ (c2 : Cand-3-chain-vote (intSystemState post) vabs)
-- then the round of the block that v' votes for is at least the round of
-- the grandparent of the block that v votes for (i.e., the preferred round rule)
→ Σ (VoteParentData (intSystemState post) v'abs)
(λ vp → Cand-3-chain-head-round (intSystemState post) c2 ≤ Abs.round (vpParent vp))
⊎ (VoteForRound∈ pk (v' ^∙ vRound) (v' ^∙ vEpoch) (v' ^∙ vProposedId) (msgPool pre))
-- Similarly in case the same step sends both v and v'
ImplObligation₂ : Set (ℓ+1 ℓ-RoundManager)
ImplObligation₂ =
∀{pid s' outs pk}{pre : SystemState}
→ (r : ReachableSystemState pre)
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ let post = StepPeer-post {pre = pre} (step-honest sps) in
∀{mbr v vabs m v' v'abs m'}
→ Meta-Honest-PK pk
-- For every vote v represented in a message output by the call
→ v ⊂Msg m → send m ∈ outs
→ (sig : WithVerSig pk v) → ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig))
-- If v is really new and valid
→ ¬ (MsgWithSig∈ pk (ver-signature sig) (msgPool pre))
→ PeerCanSignForPK post v pid pk
-- And if there exists another v' that is also new and valid
→ v' ⊂Msg m' → send m' ∈ outs
→ (sig' : WithVerSig pk v') → ¬ (∈BootstrapInfo bootstrapInfo (ver-signature sig'))
→ ¬ (MsgWithSig∈ pk (ver-signature sig') (msgPool pre))
→ PeerCanSignForPK (StepPeer-post {pre = pre} (step-honest sps)) v' pid pk
-- If v and v' share the same epoch and round
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ v ^∙ vRound < v' ^∙ vRound
→ α-ValidVote 𝓔 v mbr ≡ vabs
→ α-ValidVote 𝓔 v' mbr ≡ v'abs
→ (c2 : Cand-3-chain-vote (intSystemState post) vabs)
→ Σ (VoteParentData (intSystemState post) v'abs)
(λ vp → Cand-3-chain-head-round (intSystemState post) c2 ≤ Abs.round (vpParent vp))
module _ where
open InSys iiah
stepPreservesVoteParentData : ∀ {st0 st1 v}
→ Step st0 st1
→ (vpd : VoteParentData (intSystemState st0) v)
→ Σ (VoteParentData (intSystemState st1) v)
λ vpd' → vpParent vpd' ≡ vpParent vpd
stepPreservesVoteParentData {st0} {st1} theStep vpd
with vpd
...| (record { vpV4B = vpV4B
; vpBlock∈sys = vpBlock∈sys
; vpParent = vpParent
; vpParent∈sys = vpParent∈sys
; vpExt = vpExt
; vpMaybeBlock = vpMaybeBlock
}) = (record
{ vpV4B = vpV4B
; vpBlock∈sys = stable theStep vpBlock∈sys
; vpParent = vpParent
; vpParent∈sys = stable theStep vpParent∈sys
; vpExt = vpExt
; vpMaybeBlock = transp-vpmb vpMaybeBlock
}) , refl
where transp-vpmb : ∀ {r}
→ VoteParentData-BlockExt (intSystemState st0) r
→ VoteParentData-BlockExt (intSystemState st1) r
transp-vpmb vpParent≡I = vpParent≡I
transp-vpmb (vpParent≡Q x x₁) = vpParent≡Q x (stable theStep x₁)
module Proof
(sps-corr : StepPeerState-AllValidParts) -- Bring in newMsg⊎msgSentB4
(Impl-bsvr : ImplObl-bootstrapVotesRound≡0)
(Impl-nvr≢0 : ImplObl-NewVoteRound≢0)
(Impl-∈BI? : (sig : Signature) → Dec (∈BootstrapInfo bootstrapInfo sig))
(Impl-RC : ImplObligation-RC)
(Impl-IRO : IncreasingRoundObligation)
(Impl-PR1 : ImplObligation₁)
(Impl-PR2 : ImplObligation₂)
where
module _ {st : SystemState}(r : ReachableSystemState st) (𝓔-∈sys : EpochConfig∈Sys st 𝓔) where
open Structural sps-corr
open ConcreteCommonProperties st r sps-corr Impl-bsvr Impl-nvr≢0
α-ValidVote-trans : ∀ {pk mbr vabs pool} (v : Vote)
→ α-ValidVote 𝓔 v mbr ≡ vabs
→ (vfr : VoteForRound∈ pk (v ^∙ vRound) (v ^∙ vEpoch)
(v ^∙ vProposedId) pool)
→ α-ValidVote 𝓔 (msgVote vfr) mbr ≡ vabs
α-ValidVote-trans v₁ refl vfr
with msgRound≡ vfr | msgEpoch≡ vfr | msgBId≡ vfr
...| refl | refl | refl = refl
0<rnd⇒¬BootStrap : ∀ {pk rnd bid pool}
→ (v4r : VoteForRound∈ pk rnd (epoch 𝓔) bid pool)
→ 0 < rnd
→ ¬ (∈BootstrapInfo bootstrapInfo (ver-signature $ msgSigned v4r))
0<rnd⇒¬BootStrap v4r 0<r rewrite sym (msgRound≡ v4r) = ⊥-elim ∘ (<⇒≢ 0<r) ∘ sym ∘ Impl-bsvr (msgSigned v4r)
-- To prove this, we observe that cheaters can't introduce a VoteForRound∈ for an honest PK. We
-- will also require an additional implementation obligation. It may simply be that Votes sent
-- satisy IsValidVote, but the question is where do we maintain evidence that such a RecordChain
-- exists for any Block we may vote for?
voteForRound-RC : ∀ {pk vabs}{st : SystemState}
→ Meta-Honest-PK pk
→ ReachableSystemState st
→ (v4r : VoteForRound∈ pk (abs-vRound vabs) (epoch 𝓔) (abs-vBlockUID vabs) (msgPool st))
→ 0 < abs-vRound vabs
→ Block-RC-AllInSys vabs st
voteForRound-RC-mws : ∀ {pk vabs pre pid st' outs}
→ Meta-Honest-PK pk
→ ReachableSystemState pre
→ (sp : StepPeer pre pid st' outs)
→ (v4r : VoteForRound∈ pk (abs-vRound vabs) (epoch 𝓔) (abs-vBlockUID vabs) (msgPool $ StepPeer-post sp))
→ MsgWithSig∈ pk (ver-signature $ msgSigned v4r) (msgPool pre)
→ 0 < abs-vRound vabs
→ Block-RC-AllInSys vabs (StepPeer-post sp)
voteForRound-RC-mws {pk} {vabs} {pre} hpk preReach sps v4r mwsb4 0<r
with sameSig⇒sameVoteData (msgSigned mwsb4) (msgSigned v4r) (msgSameSig mwsb4)
...| inj₁ hb = ⊥-elim $ meta-no-collision preReach hb -- TODO-2: refine sameSig⇒samevotedata to
-- enable tying collision to specific state
-- so we can use meta-no-collision-in-sys
...| inj₂ svd
with msgSentB4⇒VoteRound∈ (msgSigned v4r) mwsb4'
where
mwsb4' : _
mwsb4' rewrite
trans (cong (_^∙ vdProposed ∙ biEpoch) $ sym svd) (msgEpoch≡ v4r) |
msgBId≡ v4r |
msgSameSig mwsb4 = mwsb4
...| v4r' , refl
with voteForRound-RC {pk} {vabs} hpk preReach v4r'' 0<r
where
v4r'' : VoteForRound∈ pk (abs-vRound vabs) (epoch 𝓔) (abs-vBlockUID vabs) (msgPool pre)
v4r'' rewrite sym (msgEpoch≡ v4r) | sym (msgRound≡ v4r) | sym (msgBId≡ v4r) = v4r'
...| b , refl , rc , ais = b , refl , rc , InSys.ais-stable iiah (step-peer sps) rc ais
voteForRound-RC {pk} {vabs} {st} hpk (step-s preReach (step-peer (step-honest sps))) v4r 0<r
with newMsg⊎msgSentB4 {sndr = msgSender v4r} preReach sps hpk (msgSigned v4r)
(0<rnd⇒¬BootStrap v4r 0<r)
(msg⊆ v4r)
(msg∈pool v4r)
...| inj₂ mwsb4 = voteForRound-RC-mws {vabs = vabs} hpk preReach (step-honest sps) v4r mwsb4 0<r
...| inj₁ (send∈outs , pcs4 , ¬sentb4) rewrite sym (msgRound≡ v4r)
with Impl-RC preReach sps hpk (msg⊆ v4r) send∈outs (msgSigned v4r) 0<r ¬sentb4 pcs4
...| mbr , refl , b , bid≡ , rc∈sys = b , (trans bid≡ $ msgBId≡ v4r) , rc∈sys
voteForRound-RC {pk} {vabs} {st} hpk (step-s {pre = pre} preReach (step-peer (step-cheat {pid} x))) v4r 0<r
with VoteRound∈⇒msgSent v4r
...| msgb4 , refl , refl
with ¬cheatForgeNew {st = pre} (step-cheat x) refl unit hpk msgb4
(0<rnd⇒¬BootStrap v4r 0<r)
...| mwsb4 = voteForRound-RC-mws {vabs = vabs} hpk preReach (step-cheat x) v4r mwsb4 0<r
open _α-Sent_
open _BlockDataInjectivityProps_
Abs2ImplCollision : ∀ {ab1 ab2 : Abs.Block}{post}
→ (rPost : ReachableSystemState post)
→ InSys (intSystemState post) (Abs.B ab1)
→ InSys (intSystemState post) (Abs.B ab2)
→ ab1 ≢ ab2
→ Abs.bId ab1 ≡ Abs.bId ab2
→ HashCollisionFound rPost
Abs2ImplCollision rPost (ws ep≡1 m1∈pool (b∈NM {cb1} {pm1} refl refl bidcorr1))
(ws ep≡2 m2∈pool (b∈NM {cb2} {pm2} refl refl bidcorr2)) neq absIds≡ =
msgmsgHC {r = rPost} (inP m1∈pool (inPM (inB {b = cb1}))) (inP m2∈pool (inPM (inB {b = cb2}))) hashes≡ bsls≢
where
-- TODO-2: Some of the properties should be factored out for reuse, maybe into Common?
bIds≡ : _
bIds≡ = trans (trans (α-Block-bid≡ cb1) absIds≡) (sym (α-Block-bid≡ cb2))
hashes≡ : _
hashes≡ = trans (trans bidcorr1 bIds≡) (sym bidcorr2)
rnds≡ : ∀ {cb1 cb2} → (cb1 ^∙ bBlockData) BlockDataInjectivityProps (cb2 ^∙ bBlockData)
→ Abs.bRound (α-Block cb1) ≡ Abs.bRound (α-Block cb2)
rnds≡ {cb1} {cb2} injprops = trans (sym (α-Block-rnd≡ cb1)) (trans (bdInjRound injprops) (α-Block-rnd≡ cb2))
propBlock : ∀ {cb pm} → pm ^∙ pmProposal ≡ cb
→ cb ^∙ bId ≡ pm ^∙ pmProposal ∙ bId
propBlock refl = refl
prevQCs≡ : ∀ {cb1 cb2}
→ (cb1 ^∙ bBlockData) BlockDataInjectivityProps (cb2 ^∙ bBlockData)
→ Abs.bPrevQC (α-Block cb1) ≡ Abs.bPrevQC (α-Block cb2)
prevQCs≡ {cb1} {cb2} injprops
with cb1 ^∙ bBlockData ∙ bdBlockType | inspect
(cb1 ^∙_) (bBlockData ∙ bdBlockType)
...| Genesis | [ R ] rewrite R = sym (α-Block-prevqc≡-Gen {cb2} (bdInjBTGen injprops R))
...| Proposal _ _ | [ R ] rewrite R | bdInjVD injprops = sym (α-Block-prevqc≡-Prop {cb2} (trans (sym $ bdInjBTProp injprops R) R))
...| NilBlock | [ R ] rewrite R | bdInjBTNil injprops R | bdInjVD injprops = refl
bsls≢ : _
bsls≢ _
with hashBD-inj hashes≡
...| injprops = neq (Abs.Block-η
(rnds≡ {cb1} {cb2} injprops)
absIds≡
(prevQCs≡ {cb1} {cb2} injprops))
Cand-3-chain-vote-b4 : ∀ {pk vabs}{pre : SystemState}{pid st' outs sp}
→ Meta-Honest-PK pk
→ ReachableSystemState pre
→ let post = StepPeer-post {pid}{st'}{outs}{pre} sp in
(c2 : Cand-3-chain-vote (intSystemState post) vabs)
→ (v4r : VoteForRound∈ pk (abs-vRound vabs) (epoch 𝓔) (abs-vBlockUID vabs) (msgPool pre))
→ Σ (Cand-3-chain-vote (intSystemState pre) vabs)
λ c2' → Cand-3-chain-head-round (intSystemState post) c2
≡ Cand-3-chain-head-round (intSystemState pre ) c2'
Cand-3-chain-vote-b4 {pk} {vabs} {pre} {pid} {st'} {outs} {sp} pkH r
c3@(mkCand3chainvote (mkVE veBlock refl refl) c3Blk∈sys₁ qc₁ qc←b₁ rc₁ rc∈sys₁ n₁ is-2chain₁) v4r
with v-cand-3-chain⇒0<roundv (intSystemState $ StepPeer-post {pid}{st'}{outs}{pre} sp)
...| 0<r
with voteForRound-RC {vabs = vabs} pkH r v4r (0<r c3)
...| b , refl , rcb , ais
with veBlock Abs.≟Block b
...| no neq = ⊥-elim (meta-no-collision-in-sys postR hcf)
where
post = StepPeer-post sp
theStep = step-peer sp
postR = step-s r theStep
hcf = Abs2ImplCollision postR c3Blk∈sys₁ (InSys.stable iiah theStep (ais here)) neq refl
...| yes refl
with RecordChain-irrelevant rcb (step rc₁ qc←b₁)
...| inj₁ (((b1 , b2) , neq , absIds≡) , b1∈rcb , b2∈rc1ext) = ⊥-elim (meta-no-collision-in-sys postR (hcf b2∈rc1ext))
where
post = StepPeer-post sp
theStep = step-peer sp
postR = step-s r theStep
inSys1 = InSys.stable iiah theStep $ ais b1∈rcb
inSys2 : _ → _
inSys2 here = c3Blk∈sys₁
inSys2 (there .qc←b₁ b2∈rc1ext) = rc∈sys₁ b2∈rc1ext
hcf : _ → _
hcf b2∈rc1ext = Abs2ImplCollision postR inSys1 (inSys2 b2∈rc1ext) neq absIds≡
...| inj₂ (eq-step {r₀ = .(Abs.B b)} {r₁ = .(Abs.B b)} rc0 rc1 b≈b
ext0@(Ext.I←B _ prevNothing)
ext1@(Ext.Q←B _ prevJust)
rcrest≈) = absurd just _ ≡ nothing case trans prevJust prevNothing of λ ()
...| inj₂ (eq-step {r₀ = .(Abs.B b)} {r₁ = .(Abs.B b)} rc0 rc1 b≈b
ext0@(Ext.Q←B {qc0} {.b} _ _)
ext1@(Ext.Q←B {qc1} {.b} _ _) rcrest≈) = newc3 , rnds≡
where
newc3 = mkCand3chainvote (mkVE b refl refl)
(ais here)
qc0
ext0
rc0
(ais ∘ (_∈RC-simple_.there ext0))
n₁
(transp-𝕂-chain (≈RC-sym rcrest≈) is-2chain₁)
rnds≡ = cong Abs.bRound $ kchainBlock-≈RC is-2chain₁ (suc zero) (≈RC-sym rcrest≈)
PreferredRoundProof :
∀ {pk round₁ round₂ bId₁ bId₂ v₁abs v₂abs mbr} {st : SystemState}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (v₁ : VoteForRound∈ pk round₁ (epoch 𝓔) bId₁ (msgPool st))
→ (v₂ : VoteForRound∈ pk round₂ (epoch 𝓔) bId₂ (msgPool st))
→ round₁ < round₂
→ α-ValidVote 𝓔 (msgVote v₁) mbr ≡ v₁abs
→ α-ValidVote 𝓔 (msgVote v₂) mbr ≡ v₂abs
→ (c3 : Cand-3-chain-vote (intSystemState st) v₁abs)
→ Σ (VoteParentData (intSystemState st) v₂abs)
(λ vp → Cand-3-chain-head-round (intSystemState st) c3 ≤ Abs.round (vpParent vp))
PreferredRoundProof {pk}{round₁}{round₂}{bId₁}{bId₂}{v₁abs}{v₂abs}{mbr}{st = post}
step@(step-s {pre = pre} r theStep) pkH v₁ v₂ r₁<r₂ refl refl c3
with msgRound≡ v₁ | msgEpoch≡ v₁ | msgBId≡ v₁
| msgRound≡ v₂ | msgEpoch≡ v₂ | msgBId≡ v₂
...| refl | refl | refl | refl | refl | refl
with Impl-∈BI? (_vSignature (msgVote v₁)) | Impl-∈BI? (_vSignature (msgVote v₂))
...| yes init₁ | yes init₂ = let r₁≡0 = Impl-bsvr (msgSigned v₁) init₁
r₂≡0 = Impl-bsvr (msgSigned v₂) init₂
in ⊥-elim (<⇒≢ r₁<r₂ (trans r₁≡0 (sym r₂≡0)))
...| yes init₁ | no ¬init₂ = let 0≡rv = sym (Impl-bsvr (msgSigned v₁) init₁)
0<rv = v-cand-3-chain⇒0<roundv (intSystemState post) c3
in ⊥-elim (<⇒≢ 0<rv 0≡rv)
...| no ¬init₁ | yes init₂ = let 0≡r₂ = sym (Impl-bsvr (msgSigned v₂) init₂)
r₁ = msgVote v₁ ^∙ vRound
in ⊥-elim (<⇒≱ r₁<r₂ (subst (r₁ ≥_) 0≡r₂ z≤n))
...| no ¬init₁ | no ¬init₂
with theStep
...| step-peer {pid} {st'} {outs} cheat@(step-cheat c) = vpdPres
where
m₁sb4 = ¬cheatForgeNewSig r cheat unit pkH (msgSigned v₁) (msg⊆ v₁) (msg∈pool v₁) ¬init₁
m₂sb4 = ¬cheatForgeNewSig r cheat unit pkH (msgSigned v₂) (msg⊆ v₂) (msg∈pool v₂) ¬init₂
v₁sb4 = msgSentB4⇒VoteRound∈ (msgSigned v₁) m₁sb4
v₂sb4 = msgSentB4⇒VoteRound∈ (msgSigned v₂) m₂sb4
v₁abs' = α-ValidVote-trans {pk} {mbr} {pool = msgPool pre} (msgVote v₁) refl (proj₁ v₁sb4)
v₂abs' = α-ValidVote-trans {pk} {mbr} {pool = msgPool pre} (msgVote v₂) refl (proj₁ v₂sb4)
vpdPres : Σ (VoteParentData (intSystemState post) v₂abs)
(λ vp → Cand-3-chain-head-round (intSystemState post) c3 ≤ Abs.round (vpParent vp))
vpdPres
with Cand-3-chain-vote-b4 {sp = step-cheat c} pkH r c3 (proj₁ v₁sb4)
...| c2' , c2'rnd≡
with PreferredRoundProof r pkH (proj₁ v₁sb4) (proj₁ v₂sb4) r₁<r₂ v₁abs' v₂abs' c2'
...| vpd , rnd≤
with stepPreservesVoteParentData theStep vpd
...| res , rnds≡ rewrite sym rnds≡ = res , ≤-trans (≤-reflexive c2'rnd≡) rnd≤
...| step-peer (step-honest stP)
with ⊎-map₂ (msgSentB4⇒VoteRound∈ (msgSigned v₁))
(newMsg⊎msgSentB4 r stP pkH (msgSigned v₁) ¬init₁ (msg⊆ v₁) (msg∈pool v₁))
| ⊎-map₂ (msgSentB4⇒VoteRound∈ (msgSigned v₂))
(newMsg⊎msgSentB4 r stP pkH (msgSigned v₂) ¬init₂ (msg⊆ v₂) (msg∈pool v₂))
...| inj₂ (v₁sb4 , refl) | inj₂ (v₂sb4 , refl)
= vpdPres
where
v₁abs' = α-ValidVote-trans (msgVote v₁) refl v₁sb4
v₂abs' = α-ValidVote-trans (msgVote v₂) refl v₂sb4
vpdPres : _
vpdPres
with Cand-3-chain-vote-b4 {sp = step-honest stP} pkH r c3 v₁sb4
...| c2' , c2'rnd≡
with PreferredRoundProof r pkH v₁sb4 v₂sb4 r₁<r₂ v₁abs' v₂abs' c2'
...| vpd , rnd≤
with stepPreservesVoteParentData theStep vpd
...| res , pars≡ rewrite sym pars≡ = res , ≤-trans (≤-reflexive c2'rnd≡) rnd≤
...| inj₁ (m₁∈outs , v₁pk , newV₁) | inj₁ (m₂∈outs , v₂pk , newV₂) =
Impl-PR2 r stP pkH (msg⊆ v₁) m₁∈outs (msgSigned v₁) ¬init₁ newV₁ v₁pk (msg⊆ v₂)
m₂∈outs (msgSigned v₂) ¬init₂ newV₂ v₂pk refl r₁<r₂ refl refl c3
...| inj₁ (m₁∈outs , v₁pk , v₁New) | inj₂ (v₂sb4 , refl) = help
where
round≡ = trans (msgRound≡ v₂sb4) (msgRound≡ v₂)
¬bootstrapV₂ = ¬Bootstrap∧Round≡⇒¬Bootstrap step pkH v₂ ¬init₂ (msgSigned v₂sb4) round≡
epoch≡ = sym (msgEpoch≡ v₂sb4)
implir0 : _
implir0 = Impl-IRO r stP pkH (msg⊆ v₁) m₁∈outs (msgSigned v₁) ¬init₁ v₁New v₁pk (msg⊆ v₂sb4)
(msg∈pool v₂sb4) (msgSigned v₂sb4) ¬bootstrapV₂ epoch≡
help : _
help = either (λ r₂<r₁ → ⊥-elim (<⇒≯ r₁<r₂ (<-transʳ (≡⇒≤ (sym round≡)) r₂<r₁)))
(λ v₁sb4 → let v₁abs = α-ValidVote-trans (msgVote v₁) refl v₁sb4
v₂abs = α-ValidVote-trans (msgVote v₂) refl v₂sb4
c2'p = Cand-3-chain-vote-b4 {sp = step-honest stP} pkH r c3 v₁sb4
prp = PreferredRoundProof r pkH v₁sb4 v₂sb4 r₁<r₂ v₁abs v₂abs (proj₁ c2'p)
vpd' = stepPreservesVoteParentData theStep (proj₁ prp)
in (proj₁ vpd') , (≤-trans (≤-reflexive (proj₂ c2'p)) (proj₂ prp)))
implir0
...| inj₂ (v₁sb4 , refl) | inj₁ (m₂∈outs , v₂pk , v₂New) = help
where
rv₁<r₂ = <-transʳ (≡⇒≤ (msgRound≡ v₁sb4)) r₁<r₂
round≡ = trans (msgRound≡ v₁sb4) (msgRound≡ v₁)
¬bootstrapV₁ = ¬Bootstrap∧Round≡⇒¬Bootstrap step pkH v₁ ¬init₁ (msgSigned v₁sb4) round≡
v₁abs' = α-ValidVote-trans (msgVote v₁) refl v₁sb4
c2'p = Cand-3-chain-vote-b4 {sp = step-honest stP} pkH r c3 v₁sb4
implir1 : _
implir1 = Impl-PR1 r stP pkH (msg⊆ v₂) m₂∈outs (msgSigned v₂) ¬init₂ v₂New v₂pk
(msg⊆ v₁sb4) (msg∈pool v₁sb4) (msgSigned v₁sb4) ¬bootstrapV₁
(msgEpoch≡ v₁sb4) rv₁<r₂ v₁abs' refl c3
help : _
help = either id
(λ v₂sb4 → let v₂abs' = α-ValidVote-trans (msgVote v₂) refl v₂sb4
prp = PreferredRoundProof r pkH v₁sb4 v₂sb4 r₁<r₂ v₁abs' v₂abs' (proj₁ c2'p)
vpd' = stepPreservesVoteParentData theStep (proj₁ prp)
in (proj₁ vpd') , (≤-trans (≤-reflexive (proj₂ c2'p)) (proj₂ prp)))
implir1
prr : Type (intSystemState st)
prr honα refl sv refl sv' c2 round<
with vmsg≈v (vmFor sv) | vmsg≈v (vmFor sv')
...| refl | refl
= let v₁ = mkVoteForRound∈ (nm (vmFor sv)) (cv ((vmFor sv))) (cv∈nm (vmFor sv))
(vmSender sv) (nmSentByAuth sv) (vmsgSigned (vmFor sv))
(vmsgEpoch (vmFor sv)) refl refl
v₂ = mkVoteForRound∈ (nm (vmFor sv')) (cv (vmFor sv')) (cv∈nm (vmFor sv'))
(vmSender sv') (nmSentByAuth sv') (vmsgSigned (vmFor sv'))
(vmsgEpoch (vmFor sv')) refl refl
in PreferredRoundProof r honα v₁ v₂ round< refl refl c2
| {
"alphanum_fraction": 0.5693907062,
"avg_line_length": 53.5292887029,
"ext": "agda",
"hexsha": "167782ff7f6674e5333ee98093fc1f28435b5975",
"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/Concrete/Properties/PreferredRound.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/Concrete/Properties/PreferredRound.agda",
"max_line_length": 137,
"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/Concrete/Properties/PreferredRound.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8644,
"size": 25587
} |
module NativeInt where
open import Data.Integer.Base hiding (_+_)
postulate
Int : Set
toInt : ℤ -> Int
fromInt : Int -> ℤ
{-# COMPILE GHC Int = type Int #-}
{-# COMPILE GHC toInt fromInteger #-}
{-# COMPILE GHC fromInt toInteger #-}
| {
"alphanum_fraction": 0.6611570248,
"avg_line_length": 18.6153846154,
"ext": "agda",
"hexsha": "ca1569aef679399f3ab653b54d8a58cf98d87a41",
"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/NativeInt.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/NativeInt.agda",
"max_line_length": 42,
"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/NativeInt.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": 67,
"size": 242
} |
module Numeral.Natural.Oper.FlooredDivision.Proofs.DivisibilityWithRemainder where
open import Data
open import Functional
open import Numeral.Finite
import Numeral.Finite.Proofs as 𝕟
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.FlooredDivision.Proofs
open import Numeral.Natural.Relation.DivisibilityWithRemainder hiding (base₀ ; base₊ ; step)
open import Numeral.Natural.Relation.DivisibilityWithRemainder.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Syntax.Transitivity
-- The quotient of the divisibility relation is given by the floored division operation.
[⌊/⌋][∣ᵣₑₘ]-quotient-equality : ∀{x y r}{p : (𝐒(y) ∣ᵣₑₘ x)(r)} → ((x ⌊/⌋ 𝐒(y)) ≡ [∣ᵣₑₘ]-quotient p)
[⌊/⌋][∣ᵣₑₘ]-quotient-equality {𝟎} {_} {𝟎} {DivRem𝟎} = [≡]-intro
[⌊/⌋][∣ᵣₑₘ]-quotient-equality {𝐒 .(𝕟-to-ℕ r)} {𝐒 y} {𝐒 r} {DivRem𝟎} =
([ 0 , 𝐒(y) ] (𝕟-to-ℕ r) div y) 🝖[ _≡_ ]-[ inddiv-smaller(𝕟.bounded{y}{r}) ]
𝟎 🝖-end
[⌊/⌋][∣ᵣₑₘ]-quotient-equality {𝐒 x} {𝟎} {𝟎} {DivRem𝐒 p} = [≡]-with(𝐒) $
([ 0 , 0 ] x div 0) 🝖[ _≡_ ]-[ [⌊/⌋]-of-1ᵣ ]
x 🝖[ _≡_ ]-[ [∣ᵣₑₘ]-quotient-of-1 p ]-sym
[∣ᵣₑₘ]-quotient p 🝖-end
{-# CATCHALL #-}
[⌊/⌋][∣ᵣₑₘ]-quotient-equality {𝐒 .(x + y)} {y} {r} {DivRem𝐒 {x = x} p} =
([ 0 , (y) ] (𝐒(x) + y) div y) 🝖[ _≡_ ]-[ inddiv-step-denominator{0}{(y)}{𝐒(x)}{y} ]
([ 0 , (y) ] 𝐒(x) div 𝟎) 🝖[ _≡_ ]-[]
𝐒([ 0 , y ] x div y) 🝖[ _≡_ ]-[ [≡]-with(𝐒) ([⌊/⌋][∣ᵣₑₘ]-quotient-equality {p = p}) ]
𝐒([∣ᵣₑₘ]-quotient p) 🝖-end
| {
"alphanum_fraction": 0.59609518,
"avg_line_length": 49.6666666667,
"ext": "agda",
"hexsha": "aa32c5745387c77f61c76ea29cfa556ef1c88ec3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Oper/FlooredDivision/Proofs/DivisibilityWithRemainder.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Oper/FlooredDivision/Proofs/DivisibilityWithRemainder.agda",
"max_line_length": 99,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Oper/FlooredDivision/Proofs/DivisibilityWithRemainder.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": 816,
"size": 1639
} |
module Miscellaneous.HeterogenousId where
import Lvl
open import Logic
open import Logic.Propositional
open import Functional
open import Type
-- TODO: Will this work for getting function extensionality? Probably not?
data IdFn {ℓ} : ∀{T : Type{ℓ}} → T → T → Stmt{Lvl.𝐒(ℓ)} where
IdFn-intro : ∀{T}{x : T} → (IdFn x x)
IdFn-func : ∀{A B : Type{ℓ}}{f g : A → B} → (∀{x : A} → IdFn(f(x))(g(x))) → (IdFn f g)
| {
"alphanum_fraction": 0.6418269231,
"avg_line_length": 32,
"ext": "agda",
"hexsha": "3eb47b7b26b1d7204e6a2c6e5a42115e59cbd2b2",
"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": "Miscellaneous/HeterogenousId.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": "Miscellaneous/HeterogenousId.agda",
"max_line_length": 88,
"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": "Miscellaneous/HeterogenousId.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": 152,
"size": 416
} |
-- The part up to "data D" could be replaced by "open import
-- Common.Prelude", but at the time of writing that seems to slow down
-- the test by something like a factor of two or three (for the GHC
-- backend, on one system).
open import Agda.Builtin.IO
open import Agda.Builtin.String
open import Agda.Builtin.Unit
postulate
putStr : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text.IO #-}
{-# COMPILE GHC putStr = Data.Text.IO.putStr #-}
{-# COMPILE JS putStr =
function (x) {
return function(cb) {
process.stdout.write(x); cb(0); }; } #-}
data D : Set where
@0 c : D
f : @0 D → String
f c = "Success\n"
main : IO ⊤
main = putStr (f c)
| {
"alphanum_fraction": 0.6568047337,
"avg_line_length": 24.1428571429,
"ext": "agda",
"hexsha": "0f90995e301e7308aa236a46a5f9edd0017b6213",
"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/Issue4638.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/Issue4638.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/Compiler/simple/Issue4638.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": 191,
"size": 676
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Function setoids and related constructions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function.Equality where
import Function as Fun
open import Level
open import Relation.Binary using (Setoid)
open import Relation.Binary.Indexed.Heterogeneous
using (IndexedSetoid; _=[_]⇒_)
import Relation.Binary.Indexed.Heterogeneous.Construct.Trivial
as Trivial
------------------------------------------------------------------------
-- Functions which preserve equality
record Π {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂)
(To : IndexedSetoid (Setoid.Carrier From) t₁ t₂) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
infixl 5 _⟨$⟩_
field
_⟨$⟩_ : (x : Setoid.Carrier From) → IndexedSetoid.Carrier To x
cong : Setoid._≈_ From =[ _⟨$⟩_ ]⇒ IndexedSetoid._≈_ To
open Π public
infixr 0 _⟶_
_⟶_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Set _
From ⟶ To = Π From (Trivial.indexedSetoid To)
------------------------------------------------------------------------
-- Identity and composition.
id : ∀ {a₁ a₂} {A : Setoid a₁ a₂} → A ⟶ A
id = record { _⟨$⟩_ = Fun.id; cong = Fun.id }
infixr 9 _∘_
_∘_ : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
{b₁ b₂} {B : Setoid b₁ b₂}
{c₁ c₂} {C : Setoid c₁ c₂} →
B ⟶ C → A ⟶ B → A ⟶ C
f ∘ g = record
{ _⟨$⟩_ = Fun._∘_ (_⟨$⟩_ f) (_⟨$⟩_ g)
; cong = Fun._∘_ (cong f) (cong g)
}
-- Constant equality-preserving function.
const : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
{b₁ b₂} {B : Setoid b₁ b₂} →
Setoid.Carrier B → A ⟶ B
const {B = B} b = record
{ _⟨$⟩_ = Fun.const b
; cong = Fun.const (Setoid.refl B)
}
------------------------------------------------------------------------
-- Function setoids
-- Dependent.
setoid : ∀ {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂) →
IndexedSetoid (Setoid.Carrier From) t₁ t₂ →
Setoid _ _
setoid From To = record
{ Carrier = Π From To
; _≈_ = λ f g → ∀ {x y} → x ≈₁ y → f ⟨$⟩ x ≈₂ g ⟨$⟩ y
; isEquivalence = record
{ refl = λ {f} → cong f
; sym = λ f∼g x∼y → To.sym (f∼g (From.sym x∼y))
; trans = λ f∼g g∼h x∼y → To.trans (f∼g From.refl) (g∼h x∼y)
}
}
where
open module From = Setoid From using () renaming (_≈_ to _≈₁_)
open module To = IndexedSetoid To using () renaming (_≈_ to _≈₂_)
-- Non-dependent.
infixr 0 _⇨_
_⇨_ : ∀ {f₁ f₂ t₁ t₂} → Setoid f₁ f₂ → Setoid t₁ t₂ → Setoid _ _
From ⇨ To = setoid From (Trivial.indexedSetoid To)
-- A variant of setoid which uses the propositional equality setoid
-- for the domain, and a more convenient definition of _≈_.
≡-setoid : ∀ {f t₁ t₂} (From : Set f) → IndexedSetoid From t₁ t₂ → Setoid _ _
≡-setoid From To = record
{ Carrier = (x : From) → Carrier x
; _≈_ = λ f g → ∀ x → f x ≈ g x
; isEquivalence = record
{ refl = λ {f} x → refl
; sym = λ f∼g x → sym (f∼g x)
; trans = λ f∼g g∼h x → trans (f∼g x) (g∼h x)
}
} where open IndexedSetoid To
-- Parameter swapping function.
flip : ∀ {a₁ a₂} {A : Setoid a₁ a₂}
{b₁ b₂} {B : Setoid b₁ b₂}
{c₁ c₂} {C : Setoid c₁ c₂} →
A ⟶ B ⇨ C → B ⟶ A ⇨ C
flip {B = B} f = record
{ _⟨$⟩_ = λ b → record
{ _⟨$⟩_ = λ a → f ⟨$⟩ a ⟨$⟩ b
; cong = λ a₁≈a₂ → cong f a₁≈a₂ (Setoid.refl B) }
; cong = λ b₁≈b₂ a₁≈a₂ → cong f a₁≈a₂ b₁≈b₂
}
| {
"alphanum_fraction": 0.5076215128,
"avg_line_length": 28.975,
"ext": "agda",
"hexsha": "4f6242415d5d83576f4b376f0a833544398dda11",
"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/Equality.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/Equality.agda",
"max_line_length": 77,
"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/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1297,
"size": 3477
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Prelude hiding (⊤)
module Control.Monad.Free.State {ℓ} (S : Type ℓ) (isSetS : isSet S) where
open import Control.Monad.Free.Quotiented
open import Data.Unit.UniversePolymorphic
open import Algebra
open import Data.List
open import Data.List.Syntax
data StateF (A : Type ℓ) : Type ℓ where
getF : (k : S → A) → StateF A
putF : (s : S) (k : A) → StateF A
module Laws where
open RawMonadSyntax
put : S → Syntax StateF ⊤
put x = lift (putF x _)
get : Syntax StateF S
get = lift (getF id)
law₁ law₂ law₃ law₄ : Law StateF
law₁ .Γ = S × S
law₁ .ν = ⊤
law₁ .eqn (u , u′) .lhs = do put u
put u′
law₁ .eqn (u , u′) .rhs = put u′
law₂ .Γ = S
law₂ .ν = S
law₂ .eqn u .lhs = do put u
u′ ← get
return u′
law₂ .eqn u .rhs = do put u
return u
law₃ .Γ = ⊤
law₃ .ν = S × S
law₃ .eqn _ .lhs = do s ← get
s′ ← get
return (s , s′)
law₃ .eqn _ .rhs = do s ← get
return (s , s)
law₄ .Γ = ⊤
law₄ .ν = ⊤
law₄ .eqn _ .lhs = do s ← get
put s
law₄ .eqn _ .rhs = return tt
StateLaws : Theory StateF
StateLaws = [ law₁ , law₂ , law₃ , law₄ ]
open Laws using (StateLaws)
State : Type ℓ → Type _
State = Free StateF StateLaws
get : State S
get = lift (getF id)
put : S → State ⊤
put x = lift (putF x _)
state-alg : Φ[ StateF ⋆ A / StateLaws ] ⇒ (S → A × S)
state-alg .fst (liftF (getF k)) s = k s , s
state-alg .fst (liftF (putF s₂ k)) s₁ = k , s₂
state-alg .fst (returnF x) s = x , s
state-alg .fst (bindF _ P⟨xs⟩ _ P⟨∘k⟩) s = uncurry P⟨∘k⟩ (P⟨xs⟩ s)
state-alg .snd .c->>=idˡ f Pf x = refl
state-alg .snd .c->>=idʳ x Px = refl
state-alg .snd .c->>=assoc xs Pxs f Pf g Pg = refl
state-alg .snd .c-quot (0 , p) γ = refl
state-alg .snd .c-quot (1 , p) γ = refl
state-alg .snd .c-quot (2 , p) γ = refl
state-alg .snd .c-quot (3 , p) γ = refl
runState : State A → S → A × S
runState = ⟦ state-alg ⟧
open FreeMonadSyntax
fromState : (S → A × S) → State A
fromState k = do
s₁ ← get
let x , s₂ = k s₁
put s₂
return x
open import HITs.PropositionalTruncation
open import Relation.Binary.Equivalence.PropHIT
open import Path.Reasoning
state-state : isSet A → State A ⇔ (S → A × S)
state-state _ .fun = runState
state-state _ .inv = fromState
state-state _ .rightInv _ = refl
state-state isSetA .leftInv xs = ⟦ lemma ⟧ xs
where
dup : S → S × S
dup x = x , x
lemma : Ψ[ xs ⦂ StateF ⋆ * / StateLaws ] ⇒ (fromState (runState xs) ≡ xs)
lemma .snd = prop-coh λ _ → uip _ _
lemma .fst (liftF (getF k)) =
fromState (runState (lift (getF k))) ≡⟨ {!!} ⟩
lift (getF k) ∎
lemma .fst (liftF (putF s k)) =
fromState (runState (lift (putF s k))) ≡⟨ {!!} ⟩
lift (putF s k) ∎
lemma .fst (returnF x) =
fromState (runState (return x)) ≡⟨⟩
fromState (λ s → x , s) ≡⟨⟩
(get >>= λ s → put s >> return x) ≡˘⟨ >>=-assoc get put (const (return x)) ⟩
((get >>= put) >> return x) ≡⟨ cong (_>> return x) (quot (3 , _) tt) ⟩
(return tt >> return x) ≡⟨ >>=-idˡ (const (return x)) tt ⟩
return x ∎
lemma .fst (bindF xs P⟨xs⟩ k P⟨∘k⟩) =
fromState (runState (xs >>= k)) ≡⟨⟩
fromState (λ s → uncurry (runState ∘ k) (runState xs s)) ≡⟨⟩
(get >>= λ s₁ → let x , s₂ = uncurry (runState ∘ k) (runState xs s₁) in put s₂ >> return x) ≡⟨⟩
(get >>= λ s₁ → let x , s₂ = runState xs s₁ ; y , s₃ = runState (k x) s₂ in put s₃ >> return y) ≡⟨ {!!} ⟩
(fromState (runState xs) >>= (fromState ∘ runState ∘ k)) ≡⟨ cong₂ Free._>>=_ P⟨xs⟩ (funExt P⟨∘k⟩) ⟩
(xs >>= k) ∎
functorState : Functor ℓ ℓ
functorState .Functor.𝐹 = StateF
functorState .Functor.map f (getF k) = getF (f ∘ k)
functorState .Functor.map f (putF s k) = putF s (f k)
functorState .Functor.map-id i (getF k) = getF k
functorState .Functor.map-id i (putF s k) = putF s k
functorState .Functor.map-comp f g i (getF k) = getF (f ∘ g ∘ k)
functorState .Functor.map-comp f g i (putF s k) = putF s (f (g k))
-- runState′ : isSet A → State A → S → A × S
-- runState′ isSetA = cata functorState (isSetState isSetA) _,_ ϕ ℒ
-- where
-- ϕ : StateF (S → A × S) → S → A × S
-- ϕ (getF k) s = k s s
-- ϕ (putF s₂ k) s₁ = k s₂
-- ℒ : InTheory functorState {𝒯 = StateLaws} (isSetState isSetA) ϕ
-- ℒ (0 , p) f iss e = refl
-- ℒ (1 , p) f iss e = refl
-- ℒ (2 , p) f iss e = refl
-- ℒ (3 , p) f iss e = refl
-- -- open import Data.Nat using (_∸_)
-- -- example : State ℕ ℕ
-- -- example = do
-- -- x ← get
-- -- put (suc x)
-- -- put x
-- -- return (x ∸ 1)
-- -- res : ℕ × ℕ
-- -- res = runState example 5
| {
"alphanum_fraction": 0.5536471586,
"avg_line_length": 28.0714285714,
"ext": "agda",
"hexsha": "7085f9895f8a0ff55d13f26a65d1e9c6d8bbd995",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Control/Monad/Free/State.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Control/Monad/Free/State.agda",
"max_line_length": 109,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Control/Monad/Free/State.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 1915,
"size": 4716
} |
module my-list where
open import level
open import bool
open import eq
open import maybe
open import nat
open import nat-thms
open import product-thms
open import product
data 𝕃 {ℓ} (A : Set ℓ) : Set ℓ where
[] : 𝕃 A
_::_ : (x : A) (xs : 𝕃 A) → 𝕃 A
{-# BUILTIN LIST 𝕃 #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
length : ∀{ℓ}{A : Set ℓ} → 𝕃 A → ℕ
length [] = 0
length (x :: x₁) = suc (length x₁)
_++_ : ∀ {ℓ}{A : Set ℓ} → 𝕃 A → 𝕃 A → 𝕃 A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
map : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → (A → B) → 𝕃 A → 𝕃 B
map f [] = []
map f (x :: xs) = f x :: map f xs
filter : ∀{ℓ}{A : Set ℓ} → (A → 𝔹) → 𝕃 A → 𝕃 A
filter p [] = []
filter p (x :: xs) = let r = filter p xs in
if p x then x :: r else r
-- remove all elements equal to the given one
remove : ∀{ℓ}{A : Set ℓ}(eq : A → A → 𝔹)(a : A)(l : 𝕃 A) → 𝕃 A
remove eq a l = filter (λ x → ~ (eq a x)) l
nth : ∀{ℓ}{A : Set ℓ} → ℕ → 𝕃 A → maybe A
nth _ [] = nothing
nth 0 (x :: xs) = just x
nth (suc n) (x :: xs) = nth n xs
reverse-helper : ∀ {ℓ}{A : Set ℓ} → 𝕃 A → 𝕃 A → 𝕃 A
reverse-helper h [] = h
reverse-helper h (x :: xs) = reverse-helper (x :: h) xs
reverse : ∀ {ℓ}{A : Set ℓ} → 𝕃 A → 𝕃 A
reverse l = reverse-helper [] l
length-++ : ∀{ℓ}{A : Set ℓ}(l1 l2 : 𝕃 A) →
length (l1 ++ l2) ≡ (length l1) + (length l2)
length-++ [] l2 = refl
length-++ (x :: l1) l2 rewrite length-++ l1 l2 = refl
++-assoc : ∀{ℓ}{A : Set ℓ} (l1 l2 l3 : 𝕃 A) →
(l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3)
++-assoc [] l2 l3 = refl
++-assoc (x :: l1) l2 l3 rewrite ++-assoc l1 l2 l3 = refl
length-filter : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l : 𝕃 A) →
length (filter p l) ≤ length l ≡ tt
length-filter p [] = refl
length-filter p (x :: l) with p x
... | tt = length-filter p l
... | ff = ≤-trans{length (filter p l)}
(length-filter p l) (≤-suc (length l))
filter-idem : ∀{ℓ}{A : Set ℓ}(p : A → 𝔹)(l : 𝕃 A) →
(filter p (filter p l)) ≡ (filter p l)
filter-idem p [] = refl
filter-idem p (x :: l) with keep (p x)
... | tt , p'
rewrite p' | p' | filter-idem p l = refl
... | ff , p' rewrite p' = filter-idem p l
length-reverse-helper : ∀{ℓ}{A : Set ℓ}(h l : 𝕃 A) →
length (reverse-helper h l) ≡ length h + length l
length-reverse-helper h [] = sym (+0 (length h))
length-reverse-helper h (x :: l)
rewrite length-reverse-helper (x :: h) l =
sym (+suc (length h) (length l))
| {
"alphanum_fraction": 0.4854028805,
"avg_line_length": 30.2235294118,
"ext": "agda",
"hexsha": "b46900a9a5bc6f21c5fe3dc7c29d92c88f197c9d",
"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": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "logicshan/IAL",
"max_forks_repo_path": "my-list.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"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": "logicshan/IAL",
"max_issues_repo_path": "my-list.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "logicshan/IAL",
"max_stars_repo_path": "my-list.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1026,
"size": 2569
} |
open import Agda.Builtin.Nat
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
it : ∀ {a} {A : Set a} {{_ : A}} → A
it {{p}} = p
f : (a {b} {{c}} : Nat) → Nat
f = λ a {b} → it
g : (a b@(c , d) (e , f) : Σ Nat (λ _ → Nat)) → Nat
g = λ a b@(c , d) x@(e , _) → f (fst a) {d} {{e}}
h : ∀ {a} (b@(c , d) : Σ Nat (λ _ → Nat)) → Nat
h {a} b = g a b b
i : ∀ a b → Nat
i a b = h {a} b
{-
j : ∀ x → let (m , n) = x in m ≡ n
j x = {!!}
-}
data P (a {b} {{v}} c : Σ Nat (λ _ → Nat)) : Set where
CON : a ≡ it → P a c
uncurry :
{A : Set} {B : A → Set} {C : ∀ a → B a → Set} →
((a : A) (b : B a) → C a b) →
((a , b) : Σ A B) → C a b
uncurry f = λ (a , b) → f a b
equal× : {A B : Set} (p q : Σ A (λ _ → B)) → Set
equal× = λ (a , b) (c , d) → Σ (a ≡ c) (λ _ → b ≡ d)
record WRAP : Set where
constructor TTTTT
field wrapped : Nat
id : WRAP → WRAP
id = λ x (let (TTTTT n) = x) → let (TTTTT n) = x in x
id' : WRAP → WRAP
id' = λ x@(TTTTT n) → x
id'' : WRAP → WRAP
id'' = λ (TTTTT n) → TTTTT n
shadowing : (p@(m , p) m@(r , s) : Σ Nat (λ _ → Nat)) →
Σ (Σ Nat (p ≡_)) (λ _ → Σ _ (m ≡_))
shadowing = λ (_ , p) m → (p , refl) , (m , refl)
shadowing' : (x@(m , p) p@(r , s) : Σ Nat (λ _ → Nat)) → x ≡ p → m ≡ r
shadowing' _ _ refl = refl
| {
"alphanum_fraction": 0.4443561208,
"avg_line_length": 22.4642857143,
"ext": "agda",
"hexsha": "cf4a81d691b26377fa867a107e260416d73f2e5c",
"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/AsInTele.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/AsInTele.agda",
"max_line_length": 70,
"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/AsInTele.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": 618,
"size": 1258
} |
{-
This module converts between the path types and the inductively
defined equality types.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.Equality where
open import Cubical.Foundations.Prelude public
hiding ( _≡_ ; _≡⟨_⟩_ ; _∎ ; isPropIsContr)
renaming ( refl to reflPath
; transport to transportPath
; J to JPath
; JRefl to JPathRefl
; sym to symPath
; _∙_ to compPath
; cong to congPath
; subst to substPath
; funExt to funExtPath
; isContr to isContrPath
; isProp to isPropPath )
open import Cubical.Foundations.Equiv
renaming ( fiber to fiberPath
; isEquiv to isEquivPath
; _≃_ to EquivPath
; equivFun to equivFunPath
; isPropIsEquiv to isPropIsEquivPath )
hiding ( equivCtr
; equivIsEquiv )
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence hiding (univalence)
open import Cubical.HITs.PropositionalTruncation public
renaming (rec to recPropTruncPath
; elim to elimPropTruncPath )
open import Cubical.HITs.S1 as S1
renaming (loop to loopPath)
hiding (helix ; winding ; ΩS¹ ; encode ; intLoop ; decode ; decodeEncode)
open import Cubical.Data.Nat
open import Cubical.Data.Int
-- Import the builtin equality type defined as an inductive family
open import Agda.Builtin.Equality public
private
variable
ℓ ℓ' : Level
A B : Type ℓ
x y z : A
infix 3 _∎
infixr 2 _≡⟨_⟩_
ap : (f : A → B) {x y : A} → x ≡ y → f x ≡ f y
ap f refl = refl
_∙_ : {x y z : A} → x ≡ y → y ≡ z → x ≡ z
refl ∙ q = q
_≡⟨_⟩_ : (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ p ⟩ q = p ∙ q
_∎ : (x : A) → x ≡ x
_ ∎ = refl
transport : ∀ (C : A → Type ℓ') {x y : A} → x ≡ y → C x → C y
transport C refl b = b
sym : {x y : A} → x ≡ y → y ≡ x
sym refl = refl
apd : {C : A → Type ℓ} (f : (x : A) → C x) {x y : A} (p : x ≡ y) → transport C p (f x) ≡ f y
apd f refl = refl
congPathd : {C : A → Type ℓ} (f : (x : A) → C x) {x y : A} (p : Path A x y) → Path (C y) (substPath C p (f x)) (f y)
congPathd f p = fromPathP (congPath f p)
-- Equality between Path and equality
eqToPath : {x y : A} → x ≡ y → Path A x y
eqToPath refl = reflPath
pathToEq : {x y : A} → Path A x y → x ≡ y
pathToEq {x = x} = JPath (λ y _ → x ≡ y) refl
eqToPath-pathToEq : {x y : A} → (p : Path A x y) → Path _ (eqToPath (pathToEq p)) p
eqToPath-pathToEq p =
JPath (λ _ h → Path _ (eqToPath (pathToEq h)) h)
(congPath eqToPath (transportRefl refl)) p
pathToEq-eqToPath : {x y : A} → (p : x ≡ y) → Path _ (pathToEq (eqToPath p)) p
pathToEq-eqToPath refl = transportRefl refl
PathIsoEq : {x y : A} → Iso (Path A x y) (x ≡ y)
PathIsoEq = iso pathToEq eqToPath pathToEq-eqToPath eqToPath-pathToEq
PathPathEq : {x y : A} → Path _ (Path A x y) (x ≡ y)
PathPathEq = isoToPath PathIsoEq
Path≡Eq : {x y : A} → (Path A x y) ≡ (x ≡ y)
Path≡Eq = pathToEq PathPathEq
-- We get funext by going back and forth between Path and Eq
funExt : {B : A → Type ℓ} {f g : (x : A) → B x} → ((x : A) → f x ≡ g x) → f ≡ g
funExt p = pathToEq (λ i x → eqToPath (p x) i)
-- Some lemmas relating the definitions for Path and ≡
substPath≡transport' : (C : A → Type ℓ) {x y : A} (b : C x) (p : x ≡ y) → substPath C (eqToPath p) b ≡ transport C p b
substPath≡transport' C b refl = pathToEq (transportRefl b)
substPath≡transport : (C : A → Type ℓ) {x y : A} (b : C x) (p : Path _ x y) → substPath C p b ≡ transport C (pathToEq p) b
substPath≡transport C b p = ap (λ x → substPath C x b) (pathToEq (symPath (eqToPath-pathToEq p)))
∙ substPath≡transport' C b (pathToEq p)
congPath≡ap : {x y : A} → (f : A → B) (p : x ≡ y) → congPath f (eqToPath p) ≡ eqToPath (ap f p)
congPath≡ap f refl = refl
ap≡congPath : {x y : A} → (f : A → B) (p : Path A x y) → ap f (pathToEq p) ≡ pathToEq (congPath f p)
ap≡congPath {x = x} f p = JPath (λ _ q → ap f (pathToEq q) ≡ pathToEq (congPath f q)) rem p
where
rem : ap f (transp (λ i → x ≡ x) i0 refl) ≡ transp (λ i → f x ≡ f x) i0 refl
rem = pathToEq (compPath (λ i → ap f (transportRefl refl i)) (symPath (transportRefl refl)))
-- Equivalences expressed using ≡ everywhere
fiber : ∀ {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ')
fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
record isEquiv {A : Type ℓ} {B : Type ℓ'} (f : A → B) : Type (ℓ-max ℓ ℓ') where
field
equiv-proof : (y : B) → isContr (fiber f y)
open isEquiv public
infix 4 _≃_
_≃_ : ∀ (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ')
A ≃ B = Σ[ f ∈ (A → B) ] (isEquiv f)
equivFun : A ≃ B → A → B
equivFun e = e .fst
equivIsEquiv : (e : A ≃ B) → isEquiv (equivFun e)
equivIsEquiv e = e .snd
equivCtr : (e : A ≃ B) (y : B) → fiber (equivFun e) y
equivCtr e y = e .snd .equiv-proof y .fst
-- Functions for going between the various definitions. This could
-- also be achieved by making lines in the universe and transporting
-- back and forth along them.
fiberPathToFiber : {f : A → B} {y : B} → fiberPath f y → fiber f y
fiberPathToFiber (x , p) = (x , pathToEq p)
fiberToFiberPath : {f : A → B} {y : B} → fiber f y → fiberPath f y
fiberToFiberPath (x , p) = (x , eqToPath p)
fiberToFiber : {f : A → B} {y : B} (p : fiber f y) → Path _ (fiberPathToFiber (fiberToFiberPath p)) p
fiberToFiber (x , p) i = x , pathToEq-eqToPath p i
fiberPathToFiberPath : {f : A → B} {y : B} (p : fiberPath f y) → Path _ (fiberToFiberPath (fiberPathToFiber p)) p
fiberPathToFiberPath (x , p) i = x , eqToPath-pathToEq p i
isContrPathToIsContr : isContrPath A → isContr A
isContrPathToIsContr (ctr , p) = (ctr , λ y → pathToEq (p y))
isContrToIsContrPath : isContr A → isContrPath A
isContrToIsContrPath (ctr , p) = (ctr , λ y → eqToPath (p y))
isPropPathToIsProp : isPropPath A → isProp A
isPropPathToIsProp H x y = pathToEq (H x y)
isPropToIsPropPath : isProp A → isPropPath A
isPropToIsPropPath H x y = eqToPath (H x y)
-- Specialized helper lemmas for going back and forth between
-- isContrPath and isContr:
helper1 : {A B : Type ℓ} (f : A → B) (g : B → A) (h : ∀ y → Path _ (f (g y)) y)
→ isContrPath A → isContr B
helper1 f g h (x , p) =
(f x , λ y → pathToEq (λ i → hcomp (λ j → λ { (i = i0) → f x
; (i = i1) → h y j })
(f (p (g y) i))))
helper2 : {A B : Type ℓ} (f : A → B) (g : B → A) (h : ∀ y → Path _ (g (f y)) y)
→ isContr B → isContrPath A
helper2 {A = A} f g h (x , p) = (g x , λ y → eqToPath (ap g (p (f y)) ∙ pathToEq (h y)))
-- This proof is essentially the one for proving that isContr with
-- Path is a proposition, but as we are working with ≡ we have to
-- insert a lof of conversion functions.
-- TODO: prove this directly following the HoTT proof?
isPropIsContr : (p1 p2 : isContr A) → Path (isContr A) p1 p2
isPropIsContr (a0 , p0) (a1 , p1) j =
( eqToPath (p0 a1) j ,
hcomp (λ i → λ { (j = i0) → λ x → pathToEq-eqToPath (p0 x) i
; (j = i1) → λ x → pathToEq-eqToPath (p1 x) i })
(λ x → pathToEq (λ i → hcomp (λ k → λ { (i = i0) → eqToPath (p0 a1) j
; (i = i1) → eqToPath (p0 x) (j ∨ k)
; (j = i0) → eqToPath (p0 x) (i ∧ k)
; (j = i1) → eqToPath (p1 x) i })
(eqToPath (p0 (eqToPath (p1 x) i)) j))))
-- We now prove that isEquiv is a proposition
isPropIsEquiv : {A B : Type ℓ} {f : A → B} (h1 h2 : isEquiv f) → Path _ h1 h2
equiv-proof (isPropIsEquiv h1 h2 i) y = isPropIsContr (h1 .equiv-proof y) (h2 .equiv-proof y) i
equivToEquivPath : A ≃ B → EquivPath A B
equivToEquivPath (f , p) =
(f , λ { .equiv-proof y → helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y) })
-- Go from a Path equivalence to an ≡ equivalence
equivPathToEquiv : EquivPath A B → A ≃ B
equivPathToEquiv (f , p) =
(f , λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (p .equiv-proof y) })
equivToEquiv : {A B : Type ℓ} (p : A ≃ B) → Path _ (equivPathToEquiv (equivToEquivPath p)) p
equivToEquiv (f , p) i =
(f , isPropIsEquiv (λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber
(helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y)) }) p i)
equivPathToEquivPath : {A B : Type ℓ} (p : EquivPath A B) → Path _ (equivToEquivPath (equivPathToEquiv p)) p
equivPathToEquivPath (f , p) i =
( f , isPropIsEquivPath f (equivToEquivPath (equivPathToEquiv (f , p)) .snd) p i )
equivPath≡Equiv : {A B : Type ℓ} → Path _ (EquivPath A B) (A ≃ B)
equivPath≡Equiv {ℓ} = isoToPath (iso (equivPathToEquiv {ℓ}) equivToEquivPath equivToEquiv equivPathToEquivPath)
path≡Eq : {A B : Type ℓ} → Path _ (Path _ A B) (A ≡ B)
path≡Eq = isoToPath (iso pathToEq eqToPath pathToEq-eqToPath eqToPath-pathToEq)
-- Univalence formulated using ≡ everywhere
univalenceEq : (A ≡ B) ≃ (A ≃ B)
univalenceEq {A = A} {B = B} = equivPathToEquiv rem
where
rem0 : Path _ (Lift (EquivPath A B)) (Lift (A ≃ B))
rem0 = congPath Lift equivPath≡Equiv
rem1 : Path _ (A ≡ B) (Lift (A ≃ B))
rem1 i = hcomp (λ j → λ { (i = i0) → path≡Eq {A = A} {B = B} j
; (i = i1) → rem0 j })
(univalencePath {A = A} {B = B} i)
rem : EquivPath (A ≡ B) (A ≃ B)
rem = compEquiv (eqweqmap rem1) (invEquiv LiftEquiv)
-- Propositional truncation using ≡ with paths under the hood
∥∥-isProp : ∀ (x y : ∥ A ∥₁) → x ≡ y
∥∥-isProp x y = pathToEq (squash₁ x y)
∥∥-recursion : ∀ {A : Type ℓ} {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥₁ → P
∥∥-recursion Pprop = recPropTruncPath (isPropToIsPropPath Pprop)
∥∥-induction : ∀ {A : Type ℓ} {P : ∥ A ∥₁ → Type ℓ} → ((a : ∥ A ∥₁) → isProp (P a)) →
((x : A) → P ∣ x ∣₁) → (a : ∥ A ∥₁) → P a
∥∥-induction Pprop = elimPropTruncPath (λ a → isPropToIsPropPath (Pprop a))
-- The circle using ≡
loop : base ≡ base
loop = pathToEq loopPath
S¹-rec : {A : Type ℓ} (b : A) (l : b ≡ b) → S¹ → A
S¹-rec b l = S1.rec b (eqToPath l)
S¹-recβ : (b : A) (l : b ≡ b) → ap (S¹-rec b l) loop ≡ l
S¹-recβ b l =
ap (S¹-rec b l) loop ≡⟨ ap≡congPath (S¹-rec b l) loopPath ⟩
pathToEq (congPath (S¹-rec b l) loopPath) ≡⟨ refl ⟩
pathToEq (eqToPath l) ≡⟨ pathToEq (pathToEq-eqToPath l) ⟩
l ∎
-- TODO: see https://github.com/agda/cubical/pull/309#discussion_r424664465
-- S¹-elimβ : (C : S¹ → Type ℓ) (b : C base) (l : transport C loop b ≡ b) → apd (S¹-elim C b l) loop ≡ l
-- S¹-elimβ C b l =
-- apd (S¹-elim C b l) (pathToEq loopPath) ≡⟨ {!!} ⟩
-- {!!} ≡⟨ {!!} ⟩
-- l ∎
-- We now compute some winding numbers to check that everything computes as expected
Cover : S¹ → Type₀
Cover = S¹-rec ℤ (pathToEq sucPathℤ)
ΩS¹ : Type₀
ΩS¹ = base ≡ base
encode : {x : S¹} → base ≡ x → Cover x
encode p = transport Cover p (pos zero)
winding : ΩS¹ → ℤ
winding = encode {base}
loop^ : ℤ → ΩS¹
loop^ (pos zero) = refl
loop^ (pos (suc n)) = loop^ (pos n) ∙ loop
loop^ (negsuc zero) = sym loop
loop^ (negsuc (suc n)) = loop^ (negsuc n) ∙ sym loop
private
test-winding-refl : winding refl ≡ pos 0
test-winding-refl = refl
-- These should type check if things would compute:
-- test-winding-loop : winding loop ≡ pos 1
-- test-winding-loop = refl
-- test-winding-pos5 : winding (loop^ (pos 2)) ≡ pos 2
-- test-winding-pos5 = refl
-- test-winding-neg5 : winding (loop^ (negsuc 2)) ≡ negsuc 2
-- test-winding-neg5 = refl
| {
"alphanum_fraction": 0.5878050855,
"avg_line_length": 35.8506097561,
"ext": "agda",
"hexsha": "4e8609af5ec0ff9d6dcb3665501729e4c2a6e3df",
"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": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"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": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/Equality.agda",
"max_line_length": 136,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 4562,
"size": 11759
} |
-- Andreas, issue #2482, reported by Guillaume Allais
-- Internal error because of wrong value for
-- number of parameters for data type.
-- {-# OPTIONS -v tc.data.sort:50 #-}
-- {-# OPTIONS -v tc.term.con:50 #-}
data D {b} (B : Set b) : Set b
-- This used to falsely compute the number of parameters to 1
data D B where
c : B → D B
-- ... leading to a violated invariant when applying the constructor.
test : ∀ {B : Set} (b : B) → D B
test b = c b
-- n = npars = conPars (c)
-- n' = npars' = getNumberOfParameters (D)
-- should be the same
| {
"alphanum_fraction": 0.6358695652,
"avg_line_length": 24,
"ext": "agda",
"hexsha": "90fcdaf104fb0896b825aca08d1ecece74418b02",
"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/Issue2482.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/Issue2482.agda",
"max_line_length": 69,
"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/Issue2482.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": 552
} |
module UniDB.Morph.Sub where
open import UniDB.Spec
open import UniDB.Morph.Depth
--------------------------------------------------------------------------------
data Single (T : STX) : MOR where
single : {γ : Dom} (t : T γ) → Single T (suc γ) γ
instance
iLkSingle : {T : STX} {{vrT : Vr T}} → Lk T (Single T)
lk {{iLkSingle {T}}} (single t) zero = t
lk {{iLkSingle {T}}} (single t) (suc i) = vr {T} i
iBetaSingle : {T : STX} → Beta T (Single T)
beta {{iBetaSingle}} = single
--------------------------------------------------------------------------------
data Sub (T : STX) : MOR where
sub : {γ₁ γ₂ : Dom} (ξ : Depth (Single T) γ₁ γ₂) → Sub T γ₁ γ₂
module _ {T : STX} where
instance
iLkSub : {{vrT : Vr T}} {{wkT : Wk T}} → Lk T (Sub T)
lk {{iLkSub}} (sub ξ) = lk {T} {Depth (Single T)} ξ
iUpSub : Up (Sub T)
_↑₁ {{iUpSub}} (sub ζ) = sub (ζ ↑₁)
_↑_ {{iUpSub}} ξ 0 = ξ
_↑_ {{iUpSub}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpSub}} ξ = refl
↑-suc {{iUpSub}} ξ δ = refl
iBetaSub : Beta T (Sub T)
beta {{iBetaSub}} t = sub (beta {T} {Depth (Single T)} t)
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4250614251,
"avg_line_length": 29.7804878049,
"ext": "agda",
"hexsha": "396b67cf9a8a2d0eacb972062a0c2f3c856a57c5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Morph/Sub.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Morph/Sub.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Morph/Sub.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 429,
"size": 1221
} |
-- Andreas, 2022-06-14, issue #4725 reported by nad
-- The termination checker needs to recognize
-- dotted variable and record patterns as patterns
-- for this example to pass.
-- These should be harmless even with --cubical
-- (dotted constructor patterns are not, see #4606).
-- Keep fingers crossed.
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Sigma
mutual
data D : Set where
d : S → D
S : Set
S = Σ D λ x → R x
fst′ : S → D
fst′ s = fst s
data R : D → Set where
r : ∀ x → R (fst′ x) → R (d x)
module _
(P : D → Set)
(Q : ∀ x → P x → R x → Set)
(p : ∀ s (p : P (fst s)) → Q (fst s) p (snd s) → P (d s))
(q : ∀ s rs (ps : P (fst s)) (qs : Q (fst s) ps (snd s)) →
Q (fst s) ps rs → Q (d s) (p s ps qs) (r s rs))
where
mutual
f : (x : D) → P x
f (d (x , r₁)) = p (x , r₁) (f x) (g x r₁)
g : (x : D) (x⊑y : R x) → Q x (f x) x⊑y
g (d (x , r₁)) (r .(x , r₁) r₂) =
q (x , r₁) r₂ (f x) (g x r₁) (g (fst′ (x , r₁)) r₂)
-- Should termination check.
| {
"alphanum_fraction": 0.5107421875,
"avg_line_length": 22.2608695652,
"ext": "agda",
"hexsha": "f2309ff6854b1a9c7420045e71780b14fe5ae43a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue4725.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue4725.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue4725.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 417,
"size": 1024
} |
module examplesPaperJFP.safeFibStackMachineObjectOriented where
open import Data.Nat
open import Data.List
open import Data.Vec
open import Data.Sum
open import Data.Fin renaming (_+_ to _+f_)
open import Data.Product
open import examplesPaperJFP.StatefulObject
open import examplesPaperJFP.StackBisim
open import examplesPaperJFP.triangleRightOperator
{- Object based version of safe stack
it is essentially the last part of safeFibStackMachine.agda
with the names simplified -}
{- the state is what we are computing right now:
fib n menas we need to compute fib n
val k means we have computed the value k
-}
data FibState : Set where
fib : ℕ → FibState
val : ℕ → FibState
data FibStackEl : Set where
_+• : ℕ → FibStackEl
•+fib_ : ℕ → FibStackEl
FibStack : ℕ → Set
FibStack = Objectˢ (StackInterfaceˢ FibStackEl)
FibStackmachine : Set
FibStackmachine = Σ[ n ∈ ℕ ] (FibState × FibStack n)
reduce : FibStackmachine → FibStackmachine ⊎ ℕ
reduce (n , fib 0 , stack) = inj₁ (n , val 1 , stack)
reduce (n , fib 1 , stack) = inj₁ (n , val 1 , stack)
reduce (n , fib (suc (suc m)) , stack) =
objectMethod stack (push (•+fib m)) ▹ λ { (_ , stack₁) →
inj₁ ( suc n , fib (suc m) , stack₁) }
reduce (0 , val k , stack) = inj₂ k
reduce (suc n , val k , stack) =
objectMethod stack pop ▹ λ { (k′ +• , stack₁) →
inj₁ (n , val (k′ + k) , stack₁)
; (•+fib m , stack₁) →
objectMethod stack₁ (push (k +•)) ▹ λ { (_ , stack₂) →
inj₁ (suc n , fib m , stack₂) }}
iter : (m : ℕ) → FibStackmachine → FibStackmachine ⊎ ℕ
iter 0 s = inj₁ s
iter (suc n) s with reduce s
... | inj₁ s′ = iter n s′
... | inj₂ m = inj₂ m
computeFib : ℕ → ℕ → FibStackmachine ⊎ ℕ
computeFib n m = iter n (0 , fib m , stack [])
fibO0 : FibStackmachine ⊎ ℕ
fibO0 = computeFib 2 0
-- evaluates to inj₂ 1
fibO1 : FibStackmachine ⊎ ℕ
fibO1 = computeFib 2 1
-- evaluates to inj₂ 1
fibO2 : FibStackmachine ⊎ ℕ
fibO2 = computeFib 10 2
-- evaluates to inj₂ 2
fibO3 : FibStackmachine ⊎ ℕ
fibO3 = computeFib 14 3
-- evaluates to inj₂ 3
fibO4 : FibStackmachine ⊎ ℕ
fibO4 = computeFib 30 4
-- evaluates to inj₂ 5
fibO5 : FibStackmachine ⊎ ℕ
fibO5 = computeFib 30 5
-- evaluates to inj₂ 8
{-# TERMINATING #-}
computeFibRec : FibStackmachine → ℕ
computeFibRec s with reduce s
... | inj₁ s′ = computeFibRec s′
... | inj₂ k = k
fibUsingStack : ℕ → ℕ
fibUsingStack m = computeFibRec (0 , fib m , stack [])
test : List ℕ
test = fibUsingStack 0 ∷ fibUsingStack 1 ∷ fibUsingStack 2 ∷ fibUsingStack 3 ∷ fibUsingStack 4 ∷ fibUsingStack 5 ∷ fibUsingStack 6 ∷ []
testExpected : List ℕ
testExpected = 1 ∷ 1 ∷ 2 ∷ 3 ∷ 5 ∷ 8 ∷ 13 ∷ []
| {
"alphanum_fraction": 0.606132879,
"avg_line_length": 27.6886792453,
"ext": "agda",
"hexsha": "16bda22826dd3c8092fa971b018b4bbe11d5a2fd",
"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/examplesPaperJFP/safeFibStackMachineObjectOriented.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/examplesPaperJFP/safeFibStackMachineObjectOriented.agda",
"max_line_length": 136,
"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/examplesPaperJFP/safeFibStackMachineObjectOriented.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": 1037,
"size": 2935
} |
-- Andreas, 2021-09-06, issue #5545,
-- regression introduced by #5522 (fix for #5291).
--
-- Note: this test requires that there is no newline at the end of file.
-- So, it violates the whitespace requirement of fix-whitespace,
-- and needs to be an exception in the configuration of fix-whitespace.
{-# OPTIONS --allow-unsolved-metas #-}
-- No newline at end of file triggered "Unterminated {!" error.
_ : Set
_ = {! !} | {
"alphanum_fraction": 0.7004716981,
"avg_line_length": 32.6153846154,
"ext": "agda",
"hexsha": "d11c1be61f1663ab5c0c9ea69cee3689bec29fed",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue5545.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue5545.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue5545.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": 111,
"size": 424
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
import Data.Vec.Relation.Unary.All as Vec-All
import Data.Fin as Fin
-- This module defines the EpochConfigs available in the system, along
-- with a function to add a new EpochConfig and some properties that
-- facilitate proofs across state transitions that add an EpochConfig.
module LibraBFT.Yasm.AvailableEpochs
(NodeId : Set)
(ℓ-EC : Level)
(EpochConfig : Set ℓ-EC)
(epochId : EpochConfig → ℕ)
(authorsN : EpochConfig → ℕ)
where
open import LibraBFT.Yasm.Base ℓ-EC EpochConfig epochId authorsN
fin-lower-toℕ : ∀{e}(i : Fin (suc e))(prf : e ≢ toℕ i) → toℕ (Fin.lower₁ i prf) ≡ toℕ i
fin-lower-toℕ {zero} zero prf = ⊥-elim (prf refl)
fin-lower-toℕ {suc e} zero prf = refl
fin-lower-toℕ {suc e} (suc i) prf = cong suc (fin-lower-toℕ i (prf ∘ cong suc))
toℕ-correct : ∀{n}(i : Fin n) → toℕ i < n
toℕ-correct zero = s≤s z≤n
toℕ-correct (suc i) = s≤s (toℕ-correct i)
toℕ-inject₁-≡ : ∀{n}(i : Fin n) → toℕ i ≡ toℕ (Fin.inject₁ i)
toℕ-inject₁-≡ zero = refl
toℕ-inject₁-≡ (suc i) = cong suc (toℕ-inject₁-≡ i)
lower₁-inject₁-id : ∀{n}(i : Fin n)(prf : n ≢ toℕ (Fin.inject₁ i)) → Fin.lower₁ (Fin.inject₁ i) prf ≡ i
lower₁-inject₁-id zero prf = refl
lower₁-inject₁-id (suc i) prf = cong suc (lower₁-inject₁-id i (prf ∘ cong suc))
fromℕ-≤-step-natural : ∀{n m}(prf : n < m) → fromℕ< (≤-step prf) ≡ Fin.inject₁ (fromℕ< prf)
fromℕ-≤-step-natural (s≤s z≤n) = refl
fromℕ-≤-step-natural (s≤s (s≤s prf)) = cong suc (fromℕ-≤-step-natural (s≤s prf))
Vec-All-lookup∘tabulate : ∀{n}{A : Set}{v : Vec A n}{ℓ : Level}{P : A → Set ℓ}
→ (f : (x : Fin n) → P (Vec-lookup v x))(i : Fin n)
→ Vec-All.lookup {P = P} i (Vec-All.tabulate {xs = v} f) ≡ f i
Vec-All-lookup∘tabulate {v = v₀ ∷ vs} f zero = refl
Vec-All-lookup∘tabulate {v = v₀ ∷ vs} f (suc i) = Vec-All-lookup∘tabulate (f ∘ suc) i
subst-elim : {A : Set}{ℓ : Level}(P : A → Set ℓ){a₀ a₁ : A}
→ (prf : a₀ ≡ a₁)(x : P a₁)
→ subst P prf (subst P (sym prf) x) ≡ x
subst-elim _ refl x = refl
-- Available epochs consist of a vector of EpochConfigs with
-- the correct epoch ids.
AvailableEpochs : ℕ → Set ℓ-EC
AvailableEpochs = Vec-All (EpochConfigFor ∘ toℕ) ∘ Vec-allFin
lookup : ∀{e} → AvailableEpochs e → (ix : Fin e) → EpochConfigFor (toℕ ix)
lookup 𝓔s ix = subst EpochConfigFor (cong toℕ (Vec-lookup∘tabulate id ix)) (Vec-All-lookup ix 𝓔s)
lookup' : ∀{e} → AvailableEpochs e → Fin e → EpochConfig
lookup' 𝓔s ix = EpochConfigFor.epochConfig (lookup 𝓔s ix)
lookup'' : ∀{e m} → AvailableEpochs e → m < e → EpochConfig
lookup'' 𝓔s ix = lookup' 𝓔s (fromℕ< ix)
lookup-𝓔s-injective : ∀ {e m1 m2} → (𝓔s : AvailableEpochs e)
→ (p1 : m1 < e) → (p2 : m2 < e) → m1 ≡ m2
→ lookup'' 𝓔s p1 ≡ lookup'' 𝓔s p2
lookup-𝓔s-injective {e} 𝓔s p1 p2 refl = cong (lookup'' 𝓔s) (<-irrelevant p1 p2)
-- The /transpose/ of append is defined by the semantics of a lookup
-- over an append; the /append/ function below is defined by tabulating this
-- monster.
appendᵀ : ∀{e} → EpochConfigFor e → AvailableEpochs e → (i : Fin (suc e)) → EpochConfigFor (toℕ i)
appendᵀ {e} ecf al i with e ≟ℕ toℕ i
...| yes e≡i = subst EpochConfigFor e≡i ecf
...| no prf = subst EpochConfigFor
(trans (cong toℕ (Vec-lookup∘tabulate id (Fin.lower₁ i prf)))
(fin-lower-toℕ i prf))
(Vec-All-lookup (Fin.lower₁ i prf) al)
-- Append is defined by tabulating appendᵀ
append : ∀{e} → EpochConfigFor e → AvailableEpochs e → AvailableEpochs (suc e)
append {e} ecf al = Vec-All.tabulate
(λ i → subst (EpochConfigFor) (sym (cong toℕ (Vec-lookup∘tabulate id i))) (appendᵀ ecf al i))
lookup-append-lemma
: ∀{e}(𝓔s : AvailableEpochs e)(𝓔 : EpochConfigFor e)(ix : Fin (suc e))
→ lookup (append 𝓔 𝓔s) ix ≡ appendᵀ 𝓔 𝓔s ix
lookup-append-lemma al ecf ix
rewrite Vec-All-lookup∘tabulate
{v = zero ∷ Vec-tabulate suc}
{P = EpochConfigFor ∘ toℕ}
(λ i → subst EpochConfigFor (sym (cong toℕ (Vec-lookup∘tabulate id i))) (appendᵀ ecf al i)) ix
= subst-elim EpochConfigFor (cong toℕ (Vec-lookup∘tabulate id ix)) (appendᵀ ecf al ix)
-- Ok, let's bring in the big guns
import Relation.Binary.HeterogeneousEquality as HE
append-inject₁-lemma
: ∀{e}(𝓔s : AvailableEpochs e)(𝓔 : EpochConfigFor e)(ix : Fin e)
→ appendᵀ 𝓔 𝓔s (Fin.inject₁ ix)
≅ lookup 𝓔s ix
append-inject₁-lemma {e} 𝓔s 𝓔 ix
with e ≟ℕ (toℕ (Fin.inject₁ ix))
...| yes abs = ⊥-elim (<⇒≢ (toℕ-correct ix) (trans (toℕ-inject₁-≡ ix) (sym abs)))
...| no prf = HE.trans (HE.≡-subst-removable EpochConfigFor
(trans (cong toℕ (Vec-lookup∘tabulate id (Fin.lower₁ (Fin-inject₁ ix) prf)))
(fin-lower-toℕ (Fin.inject₁ ix) prf))
(Vec-All-lookup (Fin.lower₁ (Fin.inject₁ ix) prf) 𝓔s))
(HE.trans (≅-cong (λ P → Vec-All-lookup P 𝓔s) (HE.≡-to-≅ (lower₁-inject₁-id ix prf)))
(HE.sym (HE.≡-subst-removable EpochConfigFor
(cong toℕ (Vec-lookup∘tabulate id ix))
(Vec-All-lookup ix 𝓔s))))
lookup''-≤-step-lemma
: ∀{e m}(𝓔s : AvailableEpochs e)(𝓔 : EpochConfigFor e)(prf : m < e)
→ lookup'' (append 𝓔 𝓔s) (≤-step prf) ≡ lookup'' 𝓔s prf
lookup''-≤-step-lemma al ecf prf
rewrite fromℕ-≤-step-natural prf
| lookup-append-lemma al ecf (Fin.inject₁ (fromℕ< prf))
= ECF-cong (append-inject₁-lemma al ecf (fromℕ< prf))
(sym (toℕ-inject₁-≡ (fromℕ< prf)))
where
ECF-cong : ∀{e e'}{ef : EpochConfigFor e}{ef' : EpochConfigFor e'}
→ ef ≅ ef' → e ≡ e'
→ EpochConfigFor.epochConfig ef ≡ EpochConfigFor.epochConfig ef'
ECF-cong {e} {e'} {ef} {ef'} HE.refl refl = refl
| {
"alphanum_fraction": 0.6021921341,
"avg_line_length": 46.6466165414,
"ext": "agda",
"hexsha": "22d5661f29f47946a06ebae8bba755c7e0082fb6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Yasm/AvailableEpochs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Yasm/AvailableEpochs.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Yasm/AvailableEpochs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2327,
"size": 6204
} |
module ZTF where
infixr 40 _◎_
open import Data.Integer
open import Data.Product
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------------
-- Zero totalized fields
data B : Set where
ZERO : B
ONE : B
PLUS : B → B → B
TIMES : B → B → B
RECIP : B → B
NEG : B → B
normalizeB : B → ℤ × ℤ
normalizeB ZERO = (+ 0 , + 1)
normalizeB ONE = (+ 1 , + 1)
normalizeB (PLUS b₁ b₂) with normalizeB b₁ | normalizeB b₂
... | (n1 , d1) | (n2 , d2) = (n1 * d2 + n2 * d1 , d1 * d2)
normalizeB (TIMES b₁ b₂) with normalizeB b₁ | normalizeB b₂
... | (n1 , d1) | (n2 , d2) = (n1 * n2 , d1 * d2)
normalizeB (RECIP b) with normalizeB b
... | (n , d) = (d , n)
normalizeB (NEG b) with normalizeB b
... | (n , d) = (- n , d)
b1 : ℤ × ℤ
b1 = normalizeB (
RECIP (PLUS
(TIMES (PLUS ONE ONE) (PLUS ONE (PLUS ONE ONE)))
(NEG (TIMES (PLUS ONE ONE) (PLUS ONE (PLUS ONE ONE))))))
helper : ℤ × ℤ → B
helper (+ 0 , _) = ZERO
helper (_ , + 0) = ZERO
helper _ = ONE
ztf : B → B
ztf b = helper (normalizeB b)
rlem : {b : B} → normalizeB b ≡ swap (normalizeB (RECIP b))
rlem = refl
{--
helperlem : {z₁ z₂ : ℤ} → helper (z₁ , z₂) ≡ helper (z₂ , z₁)
helperlem {+ 0} {_} = refl
helperlem {_} {+ 0} = refl
helperlem {_} {_} = refl
--}
data X : Set where
P0 : X
P1 : X
P2 : X
helperX : X × X → B
helperX (P0 , P0) = ZERO
helperX (_ , _) = ZERO
--helperX (P0 , _) = ZERO
--helperX (_ , P0) = ZERO
--helperX _ = ONE
helperlemX : {a b : X} → helperX (a , b) ≡ helperX (b , a)
helperlemX {P0} {P0} = refl
helperlemX {P1} {P0} = refl
helperlemX {P2} {P0} = refl
helperlemX {_} {P1} = refl
helperlemX {_} {P2} = refl
blemX : {b : B} → b ≡ b
blemX = refl
{--
helperlemX : ∀ a b → helperX (a , b) ≡ helperX (b , a)
helperlemX {P0} {P0} = refl
helperlemX {P0} {P1} = refl
helperlemX {P0} {P2} = refl
helperlemX {P1} {P0} = refl
helperlemX {P1} {P1} = refl
helperlemX {P1} {P2} = refl
helperlemX {P2} {P0} = refl
helperlemX {P2} {P1} = refl
helperlemX {P2} {P2} = refl
rlem2 : (b : B) → ztf b ≡ ztf (RECIP b)
rlem2 b = refl
with normalizeB b | normalizeB (RECIP b)
... | (n , + 0) | .(+ 0 , n) = refl
... | (+ 0 , d) | .(d , + 0) = refl
... | (n , d) | .(d , n) = refl
--}
data _⟷_ : B → B → Set₁ where
unite₊ : {b : B} → PLUS ZERO b ⟷ b
uniti₊ : {b : B} → b ⟷ PLUS ZERO b
swap₊ : {b₁ b₂ : B} → PLUS b₁ b₂ ⟷ PLUS b₂ b₁
assocl₊ : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷ PLUS (PLUS b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷ PLUS b₁ (PLUS b₂ b₃)
unitez⋆ : { b : B } → TIMES (ztf b) b ⟷ b
unitiz⋆ : { b : B } → b ⟷ TIMES (ztf b) b
-- subsumed by above
-- unite⋆ : { b : B } → TIMES ONE b ⟷ b
-- uniti⋆ : { b : B } → b ⟷ TIMES ONE b
-- distZ : { b : B } → TIMES ZERO b ⟷ ZERO
-- factorZ : { b : B } → ZERO ⟷ TIMES ZERO b
swap⋆ : {b₁ b₂ : B} → TIMES b₁ b₂ ⟷ TIMES b₂ b₁
assocl⋆ : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷ TIMES (TIMES b₁ b₂) b₃
assocr⋆ : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷ TIMES b₁ (TIMES b₂ b₃)
dist : { b₁ b₂ b₃ : B } →
TIMES (PLUS b₁ b₂) b₃ ⟷ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
factor : { b₁ b₂ b₃ : B } →
PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷ TIMES (PLUS b₁ b₂) b₃
id⟷ : {b : B } → b ⟷ b
op : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)
_◎_ : { b₁ b₂ b₃ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS b₁ b₂ ⟷ PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B } →
(b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES b₁ b₂ ⟷ TIMES b₃ b₄)
η⋆ : {b : B} → ztf b ⟷ TIMES (RECIP b) b
ε⋆ : {b : B} → TIMES (RECIP b) b ⟷ ztf b
η₊ : {b : B} → ZERO ⟷ PLUS (NEG b) b
ε₊ : {b : B} → PLUS (NEG b) b ⟷ ZERO
------------------------------------------------------------------------------
-- Examples
_⇒⋆_ : B → B → B
b₁ ⇒⋆ b₂ = TIMES (RECIP b₁) b₂
_⇒₊_ : B → B → B
b₁ ⇒₊ b₂ = PLUS (NEG b₁) b₂
name : {b₁ b₂ : B} → (b₁ ⟷ b₂) → (ztf b₁ ⟷ (b₁ ⇒⋆ b₂))
name c = η⋆ ◎ (id⟷ ⊗ c)
{--
doubleDiv : { b : B } → b ⟷ RECIP (RECIP b)
doubleDiv = unitiz⋆ ◎
(η⋆ ⊗ id⟷) ◎
assocr⋆ ◎
(id⟷ ⊗ ε⋆) ◎
swap⋆ ◎
unitez⋆
--}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4713463751,
"avg_line_length": 27.5,
"ext": "agda",
"hexsha": "9552c33844166db1fbfebea3a3c10aadfdd2ff0f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "agda/ZTF.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "agda/ZTF.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "agda/ZTF.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 1996,
"size": 4345
} |
------------------------------------------------------------------------
-- The unit type (in Set₁)
------------------------------------------------------------------------
module Data.Unit1 where
record ⊤₁ : Set₁ where
| {
"alphanum_fraction": 0.2387387387,
"avg_line_length": 27.75,
"ext": "agda",
"hexsha": "dcc3a5f2104d29a2a2174d1569cbdd9d5f17d566",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Unit1.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Unit1.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Unit1.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 28,
"size": 222
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pi
open import lib.types.Paths
open import lib.types.Sigma
module lib.types.Flattening {i j k}
(A : Type i) (B : Type j) (f g : B → A)
(C : A → Type k) (D : (b : B) → C (f b) ≃ C (g b)) where
{- The base HIT -}
import lib.types.Generic1HIT as Generic1HIT
module W = Generic1HIT A B f g
open W public using (cc; pp)
renaming (T to W)
module P = W.RecType C D
open P public -- using (↓-pp-in; ↓-pp-out; ↓-pp-β)
renaming (f to P)
{- The flattened HIT -}
At : Type _
At = Σ A C
Bt : Type _
Bt = Σ B (C ∘ f)
ft : Bt → At
ft (b , d) = (f b , d)
gt : Bt → At
gt (b , d) = (g b , –> (D b) d)
module Wt = Generic1HIT At Bt ft gt
open Wt public using ()
renaming (T to Wt)
cct = curry Wt.cc
ppt = curry Wt.pp
private
{- Flattening -}
module _ where
paths-flatten :
(b : B) → (cct (f b) == cct (g b) [ (λ w → (P w → Wt)) ↓ pp b ])
paths-flatten b =
↓-app→cst-in (λ q → ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))
module FlattenCurried = W.Elim cct paths-flatten
flatten-curried : (w : W) → (P w → Wt)
flatten-curried = W.Elim.f cct paths-flatten
flatten : Σ W P → Wt
flatten (w , x) = flatten-curried w x
{- Unflattening -}
unflatten-cc : (ac : At) → Σ W P
unflatten-cc (a , c) = (cc a , c)
unflatten-pp : (bd : Bt) → unflatten-cc (ft bd) == unflatten-cc (gt bd)
unflatten-pp (b , d) = pair= (pp b) (↓-pp-in idp)
module Unflatten = Wt.Rec unflatten-cc unflatten-pp
unflatten : Wt → Σ W P
unflatten = Unflatten.f
{- First composition -}
flatten-unflatten : (w : Wt) → flatten (unflatten w) == w
flatten-unflatten = Wt.elim
(λ _ → idp)
(λ bd → let (b , d) = bd in
↓-∘=idf-in flatten unflatten
(ap flatten (ap unflatten (ppt b d))
=⟨ Unflatten.pp-β bd |in-ctx ap flatten ⟩
ap flatten (pair= (pp b) (↓-pp-in idp))
=⟨ split-ap2 flatten (pp b) (↓-pp-in idp) ⟩
↓-app→cst-out (apd flatten-curried (pp b)) (↓-pp-in idp)
=⟨ FlattenCurried.pp-β b
|in-ctx (λ u → ↓-app→cst-out u (↓-pp-in idp)) ⟩
↓-app→cst-out (paths-flatten b) (↓-pp-in idp)
=⟨ idp ⟩
↓-app→cst-out (↓-app→cst-in
(λ q → ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))) (↓-pp-in idp)
=⟨ ↓-app→cst-β (λ q → ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))
(↓-pp-in idp) ⟩
ppt b d ∙' ap (cct (g b)) (↓-pp-out (↓-pp-in idp))
=⟨ ↓-pp-β idp |in-ctx (λ u → ppt b d ∙' ap (cct (g b)) u) ⟩
ppt b d ∎))
{- Second composition -}
unflatten-flatten-curried : (w : W) (x : P w)
→ unflatten (flatten-curried w x) == (w , x)
unflatten-flatten-curried = W.elim
(λ a x → idp)
(λ b → ↓-Π-in
(λ q → ↓-∘=idf-in unflatten flatten
(ap unflatten (ap flatten (pair= (pp b) q))
=⟨ split-ap2 flatten (pp b) q |in-ctx ap unflatten ⟩
ap unflatten (↓-app→cst-out (apd flatten-curried (pp b)) q)
=⟨ FlattenCurried.pp-β b
|in-ctx (λ u → ap unflatten (↓-app→cst-out u q)) ⟩
ap unflatten (↓-app→cst-out (paths-flatten b) q)
=⟨ idp ⟩
ap unflatten (↓-app→cst-out (↓-app→cst-in (λ qq → ppt b _ ∙' ap (cct (g b)) (↓-pp-out qq))) q)
=⟨ ↓-app→cst-β (λ qq → ppt b _ ∙' ap (cct (g b)) (↓-pp-out qq)) q |in-ctx ap unflatten ⟩
ap unflatten (ppt b _ ∙' ap (cct (g b)) (↓-pp-out q))
=⟨ ap-∙' unflatten (ppt b _) (ap (cct (g b)) (↓-pp-out q)) ⟩
ap unflatten (ppt b _) ∙' ap unflatten (ap (cct (g b)) (↓-pp-out q))
=⟨ Unflatten.pp-β (b , _) |in-ctx (λ u → u ∙' ap unflatten (ap (cct (g b)) (↓-pp-out q))) ⟩
pair= (pp b) (↓-pp-in idp) ∙' ap unflatten (ap (cct (g b)) (↓-pp-out q))
=⟨ ∘-ap unflatten (cct (g b)) (↓-pp-out q) |in-ctx (λ u → (pair= (pp b) (↓-pp-in idp) ∙' u)) ⟩
pair= (pp b) (↓-pp-in idp) ∙' ap (unflatten ∘ cct (g b)) (↓-pp-out q)
=⟨ idp ⟩
pair= (pp b) (↓-pp-in idp) ∙' ap (λ x → (cc (g b), x)) (↓-pp-out q)
=⟨ ap-cst,id P (↓-pp-out q) |in-ctx (λ u → pair= (pp b) (↓-pp-in idp) ∙' u) ⟩
pair= (pp b) (↓-pp-in idp) ∙' pair= idp (↓-pp-out q)
=⟨ Σ-∙' (↓-pp-in idp) (↓-pp-out q) ⟩
pair= (pp b) (↓-pp-in idp ∙'ᵈ ↓-pp-out q)
=⟨ to-transp-weird q (coe-pp-β _ _) |in-ctx pair= (pp b) ⟩
pair= (pp b) q ∎)))
unflatten-flatten : (wx : Σ W P) → unflatten (flatten wx) == wx
unflatten-flatten (w , x) = unflatten-flatten-curried w x
{- The equivalence -}
abstract
flattening-equiv : Σ W P ≃ Wt
flattening-equiv = equiv flatten unflatten flatten-unflatten unflatten-flatten
| {
"alphanum_fraction": 0.5010416667,
"avg_line_length": 34.0425531915,
"ext": "agda",
"hexsha": "a4db40cef5956e7bb3cc32546f3903afbc423dbd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/types/Flattening.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/types/Flattening.agda",
"max_line_length": 111,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/Flattening.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1904,
"size": 4800
} |
{-
Definition of what it means to be a notion of relational structure
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.RelationalStructure where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as Trunc
open import Cubical.HITs.SetQuotients
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.ZigZag.Base
open BinaryRelation
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
-- A notion of structured relation for a structure S assigns a relation on S X and S Y to every relation on X
-- and Y. We require the output to be proposition-valued when the input is proposition-valued.
StrRel : (S : Type ℓ → Type ℓ') (ℓ'' : Level) → Type (ℓ-max (ℓ-suc (ℓ-max ℓ ℓ'')) ℓ')
StrRel {ℓ = ℓ} S ℓ'' = ∀ {A B} (R : Rel A B ℓ) → Rel (S A) (S B) ℓ''
-- Given a type A and relation R, a quotient structure is a structure on the set quotient A/R such that
-- the graph of [_] : A → A/R is a structured relation
InducedQuotientStr : (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'')
(A : TypeWithStr ℓ S) (R : Rel (typ A) (typ A) ℓ)
→ Type (ℓ-max ℓ' ℓ'')
InducedQuotientStr S ρ A R =
Σ[ s ∈ S (typ A / R) ] ρ (graphRel [_]) (A .snd) s
-- A structured equivalence relation R on a structured type A should induce a structure on A/R
InducesQuotientStr : (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'') → Type _
InducesQuotientStr {ℓ = ℓ} S ρ =
(A : TypeWithStr ℓ S) (R : EquivPropRel (typ A) ℓ)
→ ρ (R .fst .fst) (A .snd) (A .snd)
→ ∃![ s ∈ S (typ A / R .fst .fst) ] ρ (graphRel [_]) (A .snd) s
-- The inverse of a structured relation should be structured
isSymmetricStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _
isSymmetricStrRel {ℓ = ℓ} {S = S} ρ =
{X Y : Type ℓ} (R : PropRel X Y ℓ)
{sx : S X} {sy : S Y}
→ ρ (R .fst) sx sy
→ ρ (invPropRel R .fst) sy sx
-- The composite of structured relations should be structured
isTransitiveStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _
isTransitiveStrRel {ℓ = ℓ} {S = S} ρ =
{X Y Z : Type ℓ}
(R₀ : PropRel X Y ℓ) (R₁ : PropRel Y Z ℓ)
{sx : S X} {sy : S Y} {sz : S Z}
→ ρ (R₀ .fst) sx sy
→ ρ (R₁ .fst) sy sz
→ ρ (compPropRel R₀ R₁ .fst) sx sz
-- The type of structures on a prop-valued relation should be a prop
preservesPropsStrRel : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'') → Type _
preservesPropsStrRel {ℓ = ℓ} {S = S} ρ =
{X Y : Type ℓ} {R : Rel X Y ℓ}
→ (∀ x y → isProp (R x y))
→ (sx : S X) (sy : S Y)
→ isProp (ρ R sx sy)
record SuitableStrRel (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'') : Type (ℓ-max (ℓ-max (ℓ-suc ℓ) ℓ') ℓ'')
where
field
quo : InducesQuotientStr S ρ
symmetric : isSymmetricStrRel ρ
transitive : isTransitiveStrRel ρ
prop : preservesPropsStrRel ρ
open SuitableStrRel
-- We can also ask for a notion of structured relations to agree with some notion of structured equivalences.
StrRelMatchesEquiv : {S : Type ℓ → Type ℓ'}
→ StrRel S ℓ'' → StrEquiv S ℓ''' → Type _
StrRelMatchesEquiv {S = S} ρ ι =
(A B : TypeWithStr _ S) (e : typ A ≃ typ B) →
ρ (graphRel (e .fst)) (A .snd) (B .snd) ≃ ι A B e
-- Given a suitable notion of structured relation, if we have a structured quasi equivalence relation R
-- between structured types A and B, we get induced structures on the quotients A/(R ∙ R⁻¹) and B/(R⁻¹ ∙ R),
-- and the induced equivalence e : A/(R ∙ R⁻¹) ≃ B/(R⁻¹ ∙ R) is structured with respect to those quotient
-- structures.
quotientPropRel : ∀ {ℓ} {A : Type ℓ} (R : Rel A A ℓ) → PropRel A (A / R) ℓ
quotientPropRel R .fst a t = [ a ] ≡ t
quotientPropRel R .snd _ _ = squash/ _ _
record QERDescends (S : Type ℓ → Type ℓ') (ρ : StrRel S ℓ'')
(A B : TypeWithStr ℓ S) (R : QuasiEquivRel (typ A) (typ B) ℓ) : Type (ℓ-max ℓ' ℓ'')
where
private
module E = QER→Equiv R
field
quoᴸ : InducedQuotientStr S ρ A E.Rᴸ
quoᴿ : InducedQuotientStr S ρ B E.Rᴿ
rel : ρ (graphRel (E.Thm .fst)) (quoᴸ .fst) (quoᴿ .fst)
open QERDescends
open isQuasiEquivRel
structuredQER→structuredEquiv : {S : Type ℓ → Type ℓ'} (ρ : StrRel S ℓ'')
(θ : SuitableStrRel S ρ)
(A B : TypeWithStr ℓ S) (R : QuasiEquivRel (typ A) (typ B) ℓ)
→ ρ (R .fst .fst) (A .snd) (B .snd)
→ QERDescends S ρ A B R
structuredQER→structuredEquiv ρ θ (X , s) (Y , t) R r .quoᴸ =
θ .quo (X , s) (QER→EquivRel R)
(subst (λ R' → ρ R' s s) correction
(θ .transitive (R .fst) (invPropRel (R .fst)) r (θ .symmetric (R .fst) r)))
.fst
where
correction : compPropRel (R .fst) (invPropRel (R .fst)) .fst ≡ QER→EquivRel R .fst .fst
correction =
funExt₂ λ x₀ x₁ →
(hPropExt squash (R .fst .snd _ _)
(Trunc.rec (R .fst .snd _ _) (λ {(y , r , r') → R .snd .zigzag r r' (R .snd .fwdRel _)}))
(λ r → ∣ _ , r , R .snd .fwdRel _ ∣))
structuredQER→structuredEquiv ρ θ (X , s) (Y , t) R r .quoᴿ =
θ .quo (Y , t) (QER→EquivRel (invQER R))
(subst (λ R' → ρ R' t t) correction
(θ .transitive (invPropRel (R .fst)) (R .fst) (θ .symmetric (R .fst) r) r))
.fst
where
correction : compPropRel (invPropRel (R .fst)) (R .fst) .fst ≡ QER→EquivRel (invQER R) .fst .fst
correction =
funExt₂ λ y₀ y₁ →
(hPropExt squash (R .fst .snd _ _)
(Trunc.rec (R .fst .snd _ _) (λ {(x , r , r') → R .snd .zigzag (R .snd .bwdRel _) r' r}))
(λ r → ∣ _ , r , R .snd .bwdRel _ ∣))
structuredQER→structuredEquiv ρ θ (X , s) (Y , t) R r .rel =
subst (λ R' → ρ R' (quol .fst) (quor .fst)) correction
(θ .transitive (compPropRel (invPropRel (quotientPropRel E.Rᴸ)) (R .fst)) (quotientPropRel E.Rᴿ)
(θ .transitive (invPropRel (quotientPropRel E.Rᴸ)) (R .fst)
(θ .symmetric (quotientPropRel E.Rᴸ) (quol .snd))
r)
(quor .snd))
where
module E = QER→Equiv R
quol = structuredQER→structuredEquiv ρ θ (X , s) (Y , t) R r .quoᴸ
quor = structuredQER→structuredEquiv ρ θ (X , s) (Y , t) R r .quoᴿ
[R] = compPropRel (compPropRel (invPropRel (quotientPropRel E.Rᴸ)) (R .fst)) (quotientPropRel E.Rᴿ)
correction : [R] .fst ≡ graphRel (E.Thm .fst)
correction =
funExt₂ λ qx qy →
(hPropExt squash (squash/ _ _)
(Trunc.rec (squash/ _ _)
(λ {(y , qr , py) →
Trunc.rec
(squash/ _ _)
(λ {(x , px , r) →
cong (E.Thm .fst) (sym px)
∙ eq/ (R .snd .fwd x) y (R .snd .zigzag (R .snd .bwdRel y) r (R .snd .fwdRel x))
∙ py})
qr}))
(elimProp
{B = λ qx →
E.Thm .fst qx ≡ qy → [R] .fst qx qy}
(λ _ → isPropΠ λ _ → squash)
(λ x p → ∣ _ , ∣ _ , refl , R .snd .fwdRel x ∣ , p ∣)
qx))
| {
"alphanum_fraction": 0.6057034774,
"avg_line_length": 39.0511363636,
"ext": "agda",
"hexsha": "938bbce4f453588e6709449ba5ebede73b9490da",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Foundations/RelationalStructure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Foundations/RelationalStructure.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Foundations/RelationalStructure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2684,
"size": 6873
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Relation.Nullary where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty
private
variable
ℓ : Level
A : Type ℓ
-- Negation
infix 3 ¬_
¬_ : Type ℓ → Type ℓ
¬ A = A → ⊥
isProp¬ : (A : Type ℓ) → isProp (¬ A)
isProp¬ A p q i x = isProp⊥ (p x) (q x) i
-- Decidable types (inspired by standard library)
data Dec (P : Type ℓ) : Type ℓ where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
Stable : Type ℓ → Type ℓ
Stable A = ¬ ¬ A → A
Discrete : Type ℓ → Type ℓ
Discrete A = (x y : A) → Dec (x ≡ y)
Stable¬ : Stable (¬ A)
Stable¬ ¬¬¬a a = ¬¬¬a ¬¬a
where
¬¬a = λ ¬a → ¬a a
fromYes : A → Dec A → A
fromYes _ (yes a) = a
fromYes a (no _) = a
discreteDec : (Adis : Discrete A) → Discrete (Dec A)
discreteDec Adis (yes p) (yes p') = decideYes (Adis p p') -- TODO: monad would simply stuff
where
decideYes : Dec (p ≡ p') → Dec (yes p ≡ yes p')
decideYes (yes eq) = yes (cong yes eq)
decideYes (no ¬eq) = no λ eq → ¬eq (cong (fromYes p) eq)
discreteDec Adis (yes p) (no ¬p) = ⊥-elim (¬p p)
discreteDec Adis (no ¬p) (yes p) = ⊥-elim (¬p p)
discreteDec {A = A} Adis (no ¬p) (no ¬p') = yes (cong no (isProp¬ A ¬p ¬p'))
isPropDec : (Aprop : isProp A) → isProp (Dec A)
isPropDec Aprop (yes a) (yes a') = cong yes (Aprop a a')
isPropDec Aprop (yes a) (no ¬a) = ⊥-elim (¬a a)
isPropDec Aprop (no ¬a) (yes a) = ⊥-elim (¬a a)
isPropDec {A = A} Aprop (no ¬a) (no ¬a') = cong no (isProp¬ A ¬a ¬a')
mapDec : ∀ {B : Type ℓ} → (A → B) → (¬ A → ¬ B) → Dec A → Dec B
mapDec f _ (yes p) = yes (f p)
mapDec _ f (no ¬p) = no (f ¬p)
| {
"alphanum_fraction": 0.5734138973,
"avg_line_length": 26.2698412698,
"ext": "agda",
"hexsha": "8aa27eb4305a85f3895dd5cadc8e4abadc71cb24",
"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": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/Relation/Nullary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"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": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/Relation/Nullary.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/Relation/Nullary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 692,
"size": 1655
} |
Subsets and Splits