Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K --exact-split #-}
module 08-contractible-types where
import 07-equivalences
open 07-equivalences public
-- Section 6.1 Contractible types
is-contr :
{i : Level} → UU i → UU i
is-contr A = Σ A (λ a → (x : A) → Id a x)
abstract
center :
{i : Level} {A : UU i} → is-contr A → A
center (pair c is-contr-A) = c
-- We make sure that the contraction is coherent in a straightforward way
contraction :
{i : Level} {A : UU i} (is-contr-A : is-contr A) →
(const A A (center is-contr-A) ~ id)
contraction (pair c C) x = (inv (C c)) ∙ (C x)
coh-contraction :
{i : Level} {A : UU i} (is-contr-A : is-contr A) →
Id (contraction is-contr-A (center is-contr-A)) refl
coh-contraction (pair c C) = left-inv (C c)
-- We show that contractible types satisfy an induction principle akin to the induction principle of the unit type: singleton induction. This can be helpful to give short proofs of many facts.
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
abstract
sing-ind-is-contr :
{i j : Level} (A : UU i) (is-contr-A : is-contr A) (B : A → UU j) →
(a : A) → B a → (x : A) → B x
sing-ind-is-contr A is-contr-A B a b x =
tr B ((inv (contraction is-contr-A a)) ∙ (contraction is-contr-A x)) b
sing-comp-is-contr :
{i j : Level} (A : UU i) (is-contr-A : is-contr A) (B : A → UU j) (a : A) →
((ev-pt A a B) ∘ (sing-ind-is-contr A is-contr-A B a)) ~ id
sing-comp-is-contr A is-contr-A B a b =
ap (λ ω → tr B ω b) (left-inv (contraction is-contr-A a))
sec-ev-pt-is-contr :
{i j : Level} (A : UU i) (is-contr-A : is-contr A) (B : A → UU j) (a : A) →
sec (ev-pt A a B)
sec-ev-pt-is-contr A is-contr-A B a =
pair
( sing-ind-is-contr A is-contr-A B a)
( sing-comp-is-contr A is-contr-A B a)
abstract
is-sing-is-contr :
{i j : Level} (A : UU i) (is-contr-A : is-contr A) (B : A → UU j) →
( a : A) → sec (ev-pt A a B)
is-sing-is-contr A is-contr-A B a =
pair
( sing-ind-is-contr A is-contr-A B a)
( sing-comp-is-contr A is-contr-A B a)
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)
abstract
is-contr-sing-ind :
{i : Level} (A : UU i) (a : A) →
((P : A → UU i) → P a → (x : A) → P x) → is-contr A
is-contr-sing-ind A a S = pair a (S (λ x → Id a x) refl)
abstract
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 = is-contr-sing-ind A a (λ P → pr1 (S P))
abstract
is-sing-unit : is-sing unit star
is-sing-unit B = pair ind-unit (λ b → refl)
is-contr-unit : is-contr unit
is-contr-unit = is-contr-is-sing unit star (is-sing-unit)
abstract
is-sing-total-path :
{i : Level} (A : UU i) (a : A) →
is-sing (Σ A (λ x → Id a x)) (pair a refl)
is-sing-total-path A a B = pair (ind-Σ ∘ (ind-Id a _)) (λ b → refl)
abstract
is-contr-total-path :
{i : Level} {A : UU i} (a : A) → is-contr (Σ A (λ x → Id a x))
is-contr-total-path {A = A} a = is-contr-is-sing _ _ (is-sing-total-path A a)
-- Section 6.2 Contractible maps
-- We first introduce the notion of a fiber of a map.
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)
fib' :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (b : B) → UU (i ⊔ j)
fib' f b = Σ _ (λ x → Id b (f x))
-- A map is said to be contractible if its fibers are contractible in the usual sense.
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 is-contr-f y = pr1 (center (is-contr-f 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}
(is-contr-f : is-contr-map f) → (f ∘ (inv-is-contr-map is-contr-f)) ~ id
issec-is-contr-map is-contr-f y = pr2 (center (is-contr-f 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}
(is-contr-f : is-contr-map f) → ((inv-is-contr-map is-contr-f) ∘ f) ~ id
isretr-is-contr-map {_} {_} {A} {B} {f} is-contr-f x =
ap ( pr1 {B = λ z → Id (f z) (f x)})
( ( inv
( contraction
( is-contr-f (f x))
( pair
( inv-is-contr-map is-contr-f (f x))
( issec-is-contr-map is-contr-f (f x))))) ∙
( contraction (is-contr-f (f x)) (pair x refl)))
-- Finally we put it all together to show that contractible maps are equivalences.
abstract
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 is-contr-f =
is-equiv-has-inverse
( inv-is-contr-map is-contr-f)
( issec-is-contr-map is-contr-f)
( isretr-is-contr-map is-contr-f)
-- Section 6.3 Equivalences are contractible maps
-- The goal in this section is to show that all equivalences are contractible maps. This theorem is much harder than anything we've seen so far, but many future results will depend on it.
-- We characterize the identity types of fibers
Eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
fib f y → fib f y → UU (i ⊔ j)
Eq-fib f y s t =
Σ (Id (pr1 s) (pr1 t)) (λ α → Id ((ap f α) ∙ (pr2 t)) (pr2 s))
reflexive-Eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
(s : fib f y) → Eq-fib f y s s
reflexive-Eq-fib f y s = pair refl refl
Eq-fib-eq :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
{s t : fib f y} → (Id s t) → Eq-fib f y s t
Eq-fib-eq f y {s} refl = reflexive-Eq-fib f y s
eq-Eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
{s t : fib f y} → Eq-fib f y s t → Id s t
eq-Eq-fib f y {pair x p} {pair .x .p} (pair refl refl) = refl
issec-eq-Eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
{s t : fib f y} → ((Eq-fib-eq f y {s} {t}) ∘ (eq-Eq-fib f y {s} {t})) ~ id
issec-eq-Eq-fib f y {pair x p} {pair .x .p} (pair refl refl) = refl
isretr-eq-Eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
{s t : fib f y} → ((eq-Eq-fib f y {s} {t}) ∘ (Eq-fib-eq f y {s} {t})) ~ id
isretr-eq-Eq-fib f y {pair x p} {.(pair x p)} refl = refl
abstract
is-equiv-Eq-fib-eq :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
{s t : fib f y} → is-equiv (Eq-fib-eq f y {s} {t})
is-equiv-Eq-fib-eq f y {s} {t} =
is-equiv-has-inverse
( eq-Eq-fib f y)
( issec-eq-Eq-fib f y)
( isretr-eq-Eq-fib f y)
abstract
is-equiv-eq-Eq-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) (y : B) →
{s t : fib f y} → is-equiv (eq-Eq-fib f y {s} {t})
is-equiv-eq-Eq-fib f y {s} {t} =
is-equiv-has-inverse
( Eq-fib-eq f y)
( isretr-eq-Eq-fib f y)
( issec-eq-Eq-fib f y)
-- Next, we improve the homotopy G : f ∘ g ~ id if f comes equipped with the
-- structure has-inverse f.
inv-has-inverse :
{i j : Level} {A : UU i} {B : UU j} {f : A → B} →
has-inverse f → B → A
inv-has-inverse inv-f = pr1 inv-f
issec-inv-has-inverse :
{i j : Level} {A : UU i} {B : UU j} {f : A → B} →
(inv-f : has-inverse f) → (f ∘ (inv-has-inverse inv-f)) ~ id
issec-inv-has-inverse {f = f} (pair g (pair G H)) y =
(inv (G (f (g y)))) ∙ (ap f (H (g y)) ∙ (G y))
isretr-inv-has-inverse :
{i j : Level} {A : UU i} {B : UU j} {f : A → B} →
(inv-f : has-inverse f) → ((inv-has-inverse inv-f) ∘ f) ~ id
isretr-inv-has-inverse inv-f = pr2 (pr2 inv-f)
-- Before we start we will develop some of the ingredients of the construction.
-- We will need the naturality of homotopies.
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 ((H x) ∙ (ap g p)) ((ap f p) ∙ (H y))
htpy-nat H refl = right-unit
-- We will also need to undo concatenation on the left and right. One might notice that, in the terminology of Lecture 9, we almost show here that concat p and concat' q are embeddings.
left-unwhisk :
{i : Level} {A : UU i} {x y z : A} (p : Id x y) {q r : Id y z} →
Id (p ∙ q) (p ∙ r) → Id q r
left-unwhisk refl s = (inv left-unit) ∙ (s ∙ left-unit)
right-unwhisk :
{i : Level} {A : UU i} {x y z : A} {p q : Id x y}
(r : Id y z) → Id (p ∙ r) (q ∙ r) → Id p q
right-unwhisk refl s = (inv right-unit) ∙ (s ∙ right-unit)
-- We will also need to compute with homotopies to the identity function.
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)
( ( ap (concat (H (f x)) x) (inv (ap-id (H x)))) ∙
( htpy-nat H (H x)))
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 (p ∙ q) (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 : Id x y2) {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 p1 q1 p2 refl q2 sq = sq
coherence-inv-has-inverse :
{i j : Level} {A : UU i} {B : UU j} {f : A → B} →
(inv-f : has-inverse f) →
(f ·l (isretr-inv-has-inverse inv-f)) ~ ((issec-inv-has-inverse inv-f) ·r f)
coherence-inv-has-inverse {f = f} (pair g (pair G H)) x =
inv-con
( G (f (g (f x))))
( ap f (H x))
( (ap f (H (g (f x)))) ∙ (G (f x)))
( sq-top-whisk
( G (f (g (f x))))
( ap f (H x))
( (ap (f ∘ (g ∘ f)) (H x)))
( (ap-comp f (g ∘ f) (H x)) ∙ (inv (ap (ap f) (htpy-red H x))))
( G (f x))
( htpy-nat (htpy-right-whisk G f) (H x)))
-- Now the proof that equivalences are contractible maps really begins. Note that we have already shown that any equivalence has an inverse. Our strategy is therefore to first show that maps with inverses are contractible, and then deduce the claim about equivalences.
abstract
center-has-inverse :
{i j : Level} {A : UU i} {B : UU j} {f : A → B} →
has-inverse f → (y : B) → fib f y
center-has-inverse {i} {j} {A} {B} {f} inv-f y =
pair
( inv-has-inverse inv-f y)
( issec-inv-has-inverse inv-f y)
contraction-has-inverse :
{i j : Level} {A : UU i} {B : UU j} {f : A → B} →
(I : has-inverse f) → (y : B) → (t : fib f y) →
Id (center-has-inverse I y) t
contraction-has-inverse {i} {j} {A} {B} {f}
( pair g (pair G H)) y (pair x refl) =
eq-Eq-fib f y (pair
( H x)
( ( right-unit) ∙
( coherence-inv-has-inverse (pair g (pair G H)) x)))
is-contr-map-has-inverse : {i j : Level} {A : UU i} {B : UU j} {f : A → B} →
has-inverse f → is-contr-map f
is-contr-map-has-inverse inv-f y =
pair
( center-has-inverse inv-f y)
( contraction-has-inverse inv-f 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-has-inverse ∘ has-inverse-is-equiv
abstract
is-contr-total-path' :
{i : Level} {A : UU i} (a : A) → is-contr (Σ A (λ x → Id x a))
is-contr-total-path' a = is-contr-map-is-equiv (is-equiv-id _) a
-- Exercises
-- Exercise 6.1
-- In this exercise we are asked to show that the identity types of a contractible type are again contractible. In the terminology of Lecture 8: we are showing that contractible types are propositions.
abstract
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} is-contr-A =
sing-ind-is-contr A is-contr-A
( λ x → ((y : A) → is-contr (Id x y)))
( center is-contr-A)
( λ y → pair
( contraction is-contr-A y)
( ind-Id
( center is-contr-A)
( λ z (p : Id (center is-contr-A) z) →
Id (contraction is-contr-A z) p)
( coh-contraction is-contr-A)
( y)))
abstract
is-prop-is-contr' : {i : Level} {A : UU i} → is-contr A →
(x y : A) → Id x y
is-prop-is-contr' is-contr-A x y =
center (is-prop-is-contr is-contr-A x y)
-- Exercise 6.2
-- In this exercise we are showing that contractible types are closed under retracts.
abstract
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 (pair i (pair r isretr)) is-contr-B =
pair
( r (center is-contr-B))
( λ x → (ap r (contraction is-contr-B (i x))) ∙ (isretr x))
-- Exercise 6.3
-- In this exercise we are showing that a type is contractible if and only if the constant map to the unit type is an equivalence. This can be used to derive a '3-for-2 property' for contractible types, which may come in handy sometimes.
abstract
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} is-contr-A =
pair
( pair (ind-unit (center is-contr-A)) (ind-unit refl))
( pair (const unit A (center is-contr-A)) (contraction is-contr-A))
abstract
is-contr-is-equiv-const :
{i : Level} {A : UU i} → is-equiv (const A unit star) → is-contr A
is-contr-is-equiv-const (pair (pair g issec) (pair h isretr)) =
pair (h star) isretr
abstract
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 B f is-equiv-f is-contr-B =
is-contr-is-equiv-const
( is-equiv-comp'
( const B unit star)
( f)
( is-equiv-f)
( is-equiv-const-is-contr is-contr-B))
abstract
is-contr-equiv :
{i j : Level} {A : UU i} (B : UU j) (e : A ≃ B) → is-contr B → is-contr A
is-contr-equiv B (pair e is-equiv-e) is-contr-B =
is-contr-is-equiv B e is-equiv-e is-contr-B
abstract
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' A f is-equiv-f is-contr-A =
is-contr-is-equiv A
( inv-is-equiv is-equiv-f)
( is-equiv-inv-is-equiv is-equiv-f)
( is-contr-A)
abstract
is-contr-equiv' :
{i j : Level} (A : UU i) {B : UU j} (e : A ≃ B) → is-contr A → is-contr B
is-contr-equiv' A (pair e is-equiv-e) is-contr-A =
is-contr-is-equiv' A e is-equiv-e is-contr-A
abstract
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 is-contr-A is-contr-B =
is-equiv-has-inverse
( const B A (center is-contr-A))
( sing-ind-is-contr B is-contr-B _ _
( inv (contraction is-contr-B (f (center is-contr-A)))))
( contraction is-contr-A)
equiv-is-contr :
{i j : Level} {A : UU i} {B : UU j} →
is-contr A → is-contr B → A ≃ B
equiv-is-contr is-contr-A is-contr-B =
pair
( λ a → center is-contr-B)
( is-equiv-is-contr _ is-contr-A is-contr-B)
-- Exercise 6.4
-- In this exercise we will show that if the base type in a Σ-type is contractible, then the Σ-type is equivalent to the fiber at the center of contraction. This can be seen as a left unit law for Σ-types. We will derive a right unit law for Σ-types in Lecture 7 (not because it is unduable here, but it is useful to have some knowledge of fiberwise equivalences).
left-unit-law-Σ-map :
{i j : Level} {C : UU i} (B : C → UU j)
(is-contr-C : is-contr C) → B (center is-contr-C) → Σ C B
left-unit-law-Σ-map B is-contr-C y = pair (center is-contr-C) y
left-unit-law-Σ-map-conv :
{i j : Level} {C : UU i} (B : C → UU j)
(is-contr-C : is-contr C) → Σ C B → B (center is-contr-C)
left-unit-law-Σ-map-conv B is-contr-C =
ind-Σ
( sing-ind-is-contr _ is-contr-C
( λ x → B x → B (center is-contr-C))
( center is-contr-C)
( id))
left-inverse-left-unit-law-Σ-map-conv :
{i j : Level} {C : UU i} (B : C → UU j) (is-contr-C : is-contr C) →
( ( left-unit-law-Σ-map-conv B is-contr-C) ∘
( left-unit-law-Σ-map B is-contr-C)) ~ id
left-inverse-left-unit-law-Σ-map-conv B is-contr-C y =
ap
( λ (f : B (center is-contr-C) → B (center is-contr-C)) → f y)
( sing-comp-is-contr _ is-contr-C
( λ x → B x → B (center is-contr-C))
( center is-contr-C)
( id))
right-inverse-left-unit-law-Σ-map-conv :
{i j : Level} {C : UU i} (B : C → UU j) (is-contr-C : is-contr C) →
( ( left-unit-law-Σ-map B is-contr-C) ∘
( left-unit-law-Σ-map-conv B is-contr-C)) ~ id
right-inverse-left-unit-law-Σ-map-conv B is-contr-C =
ind-Σ
( sing-ind-is-contr _ is-contr-C
( λ x → (y : B x) →
Id ( ( ( left-unit-law-Σ-map B is-contr-C) ∘
( left-unit-law-Σ-map-conv B is-contr-C))
( pair x y))
( id (pair x y))) (center is-contr-C)
( λ y → ap
( left-unit-law-Σ-map B is-contr-C)
( ap
( λ f → f y)
( sing-comp-is-contr _ is-contr-C
( λ x → B x → B (center is-contr-C)) (center is-contr-C) id))))
abstract
is-equiv-left-unit-law-Σ-map :
{i j : Level} {C : UU i} (B : C → UU j) (is-contr-C : is-contr C) →
is-equiv (left-unit-law-Σ-map B is-contr-C)
is-equiv-left-unit-law-Σ-map B is-contr-C =
is-equiv-has-inverse
( left-unit-law-Σ-map-conv B is-contr-C)
( right-inverse-left-unit-law-Σ-map-conv B is-contr-C)
( left-inverse-left-unit-law-Σ-map-conv B is-contr-C)
abstract
is-equiv-left-unit-law-Σ-map-conv :
{i j : Level} {C : UU i} (B : C → UU j) (is-contr-C : is-contr C) →
is-equiv (left-unit-law-Σ-map-conv B is-contr-C)
is-equiv-left-unit-law-Σ-map-conv B is-contr-C =
is-equiv-has-inverse
( left-unit-law-Σ-map B is-contr-C)
( left-inverse-left-unit-law-Σ-map-conv B is-contr-C)
( right-inverse-left-unit-law-Σ-map-conv B is-contr-C)
left-unit-law-Σ : {i j : Level} {C : UU i} (B : C → UU j)
(is-contr-C : is-contr C) → B (center is-contr-C) ≃ Σ C B
left-unit-law-Σ B is-contr-C =
pair
( left-unit-law-Σ-map B is-contr-C)
( is-equiv-left-unit-law-Σ-map B is-contr-C)
left-unit-law-Σ-map-gen :
{l1 l2 : Level} {A : UU l1} (B : A → UU l2) →
is-contr A → (x : A) → B x → Σ A B
left-unit-law-Σ-map-gen B is-contr-A x y = pair x y
abstract
is-equiv-left-unit-law-Σ-map-gen :
{l1 l2 : Level} {A : UU l1} (B : A → UU l2) →
(is-contr-A : is-contr A) →
(x : A) → is-equiv (left-unit-law-Σ-map-gen B is-contr-A x)
is-equiv-left-unit-law-Σ-map-gen B is-contr-A x =
is-equiv-comp
( left-unit-law-Σ-map-gen B is-contr-A x)
( left-unit-law-Σ-map B is-contr-A)
( tr B (inv (contraction is-contr-A x)))
( λ y → eq-pair (inv (contraction is-contr-A x)) refl)
( is-equiv-tr B (inv (contraction is-contr-A x)))
( is-equiv-left-unit-law-Σ-map B is-contr-A)
left-unit-law-Σ-gen :
{l1 l2 : Level} {A : UU l1} (B : A → UU l2) →
(is-contr-A : is-contr A) →
(x : A) → B x ≃ Σ A B
left-unit-law-Σ-gen B is-contr-A x =
pair
( left-unit-law-Σ-map-gen B is-contr-A x)
( is-equiv-left-unit-law-Σ-map-gen B is-contr-A x)
-- Exercise 6.6
-- In this exercise we show that the domain of a map is equivalent to the total space of its fibers.
Σ-fib-to-domain :
{i j : Level} {A : UU i} {B : UU j} (f : A → B ) → (Σ B (fib f)) → A
Σ-fib-to-domain f t = pr1 (pr2 t)
triangle-Σ-fib-to-domain :
{i j : Level} {A : UU i} {B : UU j} (f : A → B ) →
pr1 ~ (f ∘ (Σ-fib-to-domain f))
triangle-Σ-fib-to-domain f t = inv (pr2 (pr2 t))
domain-to-Σ-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B) → A → Σ B (fib f)
domain-to-Σ-fib f x = pair (f x) (pair x refl)
left-inverse-domain-to-Σ-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B ) →
((domain-to-Σ-fib f) ∘ (Σ-fib-to-domain f)) ~ id
left-inverse-domain-to-Σ-fib f (pair .(f x) (pair x refl)) = refl
right-inverse-domain-to-Σ-fib :
{i j : Level} {A : UU i} {B : UU j} (f : A → B ) →
((Σ-fib-to-domain f) ∘ (domain-to-Σ-fib f)) ~ id
right-inverse-domain-to-Σ-fib f x = refl
abstract
is-equiv-Σ-fib-to-domain :
{i j : Level} {A : UU i} {B : UU j} (f : A → B ) →
is-equiv (Σ-fib-to-domain f)
is-equiv-Σ-fib-to-domain f =
is-equiv-has-inverse
( domain-to-Σ-fib f)
( right-inverse-domain-to-Σ-fib f)
( left-inverse-domain-to-Σ-fib f)
equiv-Σ-fib-to-domain :
{i j : Level} {A : UU i} {B : UU j} (f : A → B ) → Σ B (fib f) ≃ A
equiv-Σ-fib-to-domain f =
pair (Σ-fib-to-domain f) (is-equiv-Σ-fib-to-domain f)
-- Exercise 6.7
-- In this exercise we show that if a cartesian product is contractible, then so are its factors. We make use of the fact that contractible types are closed under retracts, just because that is a useful property to practice with. Other proofs are possible too.
abstract
is-contr-left-factor-prod :
{i j : Level} (A : UU i) (B : UU j) → is-contr (A × B) → is-contr A
is-contr-left-factor-prod A B is-contr-AB =
is-contr-retract-of
( A × B)
( pair
( λ x → pair x (pr2 (center is-contr-AB)))
( pair pr1 (λ x → refl)))
( is-contr-AB)
abstract
is-contr-right-factor-prod :
{i j : Level} (A : UU i) (B : UU j) → is-contr (A × B) → is-contr B
is-contr-right-factor-prod A B is-contr-AB =
is-contr-left-factor-prod B A
( is-contr-equiv
( A × B)
( equiv-swap-prod B A)
( is-contr-AB))
abstract
is-contr-prod :
{i j : Level} {A : UU i} {B : UU j} →
is-contr A → is-contr B → is-contr (A × B)
is-contr-prod {A = A} {B = B} is-contr-A is-contr-B =
is-contr-equiv' B
( left-unit-law-Σ (λ x → B) is-contr-A)
( is-contr-B)
-- Exercise 6.8
-- Given any family B over A, there is a map from the fiber of the projection map (pr1 : Σ A B → A) to the type (B a), i.e. the fiber of B at a. In this exercise we define this map, and show that it is an equivalence, for every a : A.
fib-fam-fib-pr1 :
{i j : Level} {A : UU i} (B : A → UU j)
(a : A) → fib (pr1 {B = B}) a → B a
fib-fam-fib-pr1 B a (pair (pair x y) p) = tr B p y
fib-pr1-fib-fam :
{i j : Level} {A : UU i} (B : A → UU j)
(a : A) → B a → fib (pr1 {B = B}) a
fib-pr1-fib-fam B a b = pair (pair a b) refl
left-inverse-fib-pr1-fib-fam :
{i j : Level} {A : UU i} (B : A → UU j) (a : A) →
((fib-pr1-fib-fam B a) ∘ (fib-fam-fib-pr1 B a)) ~ id
left-inverse-fib-pr1-fib-fam B a (pair (pair .a y) refl) = refl
right-inverse-fib-pr1-fib-fam :
{i j : Level} {A : UU i} (B : A → UU j) (a : A) →
((fib-fam-fib-pr1 B a) ∘ (fib-pr1-fib-fam B a)) ~ id
right-inverse-fib-pr1-fib-fam B a b = refl
abstract
is-equiv-fib-fam-fib-pr1 :
{i j : Level} {A : UU i} (B : A → UU j) (a : A) →
is-equiv (fib-fam-fib-pr1 B a)
is-equiv-fib-fam-fib-pr1 B a =
is-equiv-has-inverse
( fib-pr1-fib-fam B a)
( right-inverse-fib-pr1-fib-fam B a)
( left-inverse-fib-pr1-fib-fam B a)
equiv-fib-fam-fib-pr1 :
{i j : Level} {A : UU i} (B : A → UU j) (a : A) →
fib (pr1 {B = B}) a ≃ B a
equiv-fib-fam-fib-pr1 B a =
pair (fib-fam-fib-pr1 B a) (is-equiv-fib-fam-fib-pr1 B a)
abstract
is-equiv-fib-pr1-fib-fam :
{i j : Level} {A : UU i} (B : A → UU j) (a : A) →
is-equiv (fib-pr1-fib-fam B a)
is-equiv-fib-pr1-fib-fam B a =
is-equiv-has-inverse
( fib-fam-fib-pr1 B a)
( left-inverse-fib-pr1-fib-fam B a)
( right-inverse-fib-pr1-fib-fam B a)
equiv-fib-pr1-fib-fam :
{i j : Level} {A : UU i} (B : A → UU j) (a : A) →
B a ≃ fib (pr1 {B = B}) a
equiv-fib-pr1-fib-fam B a =
pair (fib-pr1-fib-fam B a) (is-equiv-fib-pr1-fib-fam B a)
abstract
is-equiv-pr1-is-contr :
{i j : Level} {A : UU i} (B : A → UU j) →
((a : A) → is-contr (B a)) → is-equiv (pr1 {B = B})
is-equiv-pr1-is-contr B is-contr-B =
is-equiv-is-contr-map
( λ x → is-contr-equiv
( B x)
( equiv-fib-fam-fib-pr1 B x)
( is-contr-B x))
equiv-pr1 :
{i j : Level} {A : UU i} {B : A → UU j} →
((a : A) → is-contr (B a)) → (Σ A B) ≃ A
equiv-pr1 is-contr-B = pair pr1 (is-equiv-pr1-is-contr _ is-contr-B)
abstract
is-contr-is-equiv-pr1 :
{i j : Level} {A : UU i} (B : A → UU j) →
(is-equiv (pr1 {B = B})) → ((a : A) → is-contr (B a))
is-contr-is-equiv-pr1 B is-equiv-pr1-B a =
is-contr-equiv'
( fib pr1 a)
( equiv-fib-fam-fib-pr1 B a)
( is-contr-map-is-equiv is-equiv-pr1-B a)
right-unit-law-Σ :
{i j : Level} {A : UU i} (B : A → UU j) →
((a : A) → is-contr (B a)) → (Σ A B) ≃ A
right-unit-law-Σ B is-contr-B =
pair pr1 (is-equiv-pr1-is-contr B is-contr-B)
| {
"alphanum_fraction": 0.559623431,
"avg_line_length": 34.9592123769,
"ext": "agda",
"hexsha": "6de47ddf417ab28cef076e06c121acd6db42e38e",
"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": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "hemangandhi/HoTT-Intro",
"max_forks_repo_path": "Agda/08-contractible-types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"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": "hemangandhi/HoTT-Intro",
"max_issues_repo_path": "Agda/08-contractible-types.agda",
"max_line_length": 364,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "hemangandhi/HoTT-Intro",
"max_stars_repo_path": "Agda/08-contractible-types.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9749,
"size": 24856
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A bunch of properties about natural number operations
------------------------------------------------------------------------
-- See README.Nat for some examples showing how this module can be
-- used.
module Data.Nat.Properties where
open import Data.Nat as Nat
open ≤-Reasoning
renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≡⟨_⟩'_)
open import Relation.Binary
open DecTotalOrder Nat.decTotalOrder using () renaming (refl to ≤-refl)
open import Function
open import Algebra
open import Algebra.Structures
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; sym; cong; cong₂)
open PropEq.≡-Reasoning
import Algebra.FunctionProperties as P; open P (_≡_ {A = ℕ})
open import Data.Product
open import Data.Sum
------------------------------------------------------------------------
-- basic lemmas about (ℕ, +, *, 0, 1):
open import Data.Nat.Properties.Simple
-- (ℕ, +, *, 0, 1) is a commutative semiring
isCommutativeSemiring : IsCommutativeSemiring _≡_ _+_ _*_ 0 1
isCommutativeSemiring = record
{ +-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = PropEq.isEquivalence
; assoc = +-assoc
; ∙-cong = cong₂ _+_
}
; identityˡ = λ _ → refl
; comm = +-comm
}
; *-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = PropEq.isEquivalence
; assoc = *-assoc
; ∙-cong = cong₂ _*_
}
; identityˡ = +-right-identity
; comm = *-comm
}
; distribʳ = distribʳ-*-+
; zeroˡ = λ _ → refl
}
commutativeSemiring : CommutativeSemiring _ _
commutativeSemiring = record
{ _+_ = _+_
; _*_ = _*_
; 0# = 0
; 1# = 1
; isCommutativeSemiring = isCommutativeSemiring
}
import Algebra.RingSolver.Simple as Solver
import Algebra.RingSolver.AlmostCommutativeRing as ACR
module SemiringSolver =
Solver (ACR.fromCommutativeSemiring commutativeSemiring) _≟_
------------------------------------------------------------------------
-- (ℕ, ⊔, ⊓, 0) is a commutative semiring without one
private
⊔-assoc : Associative _⊔_
⊔-assoc zero _ _ = refl
⊔-assoc (suc m) zero o = refl
⊔-assoc (suc m) (suc n) zero = refl
⊔-assoc (suc m) (suc n) (suc o) = cong suc $ ⊔-assoc m n o
⊔-identity : Identity 0 _⊔_
⊔-identity = (λ _ → refl) , n⊔0≡n
where
n⊔0≡n : RightIdentity 0 _⊔_
n⊔0≡n zero = refl
n⊔0≡n (suc n) = refl
⊔-comm : Commutative _⊔_
⊔-comm zero n = sym $ proj₂ ⊔-identity n
⊔-comm (suc m) zero = refl
⊔-comm (suc m) (suc n) =
begin
suc m ⊔ suc n
≡⟨ refl ⟩
suc (m ⊔ n)
≡⟨ cong suc (⊔-comm m n) ⟩
suc (n ⊔ m)
≡⟨ refl ⟩
suc n ⊔ suc m
∎
⊓-assoc : Associative _⊓_
⊓-assoc zero _ _ = refl
⊓-assoc (suc m) zero o = refl
⊓-assoc (suc m) (suc n) zero = refl
⊓-assoc (suc m) (suc n) (suc o) = cong suc $ ⊓-assoc m n o
⊓-zero : Zero 0 _⊓_
⊓-zero = (λ _ → refl) , n⊓0≡0
where
n⊓0≡0 : RightZero 0 _⊓_
n⊓0≡0 zero = refl
n⊓0≡0 (suc n) = refl
⊓-comm : Commutative _⊓_
⊓-comm zero n = sym $ proj₂ ⊓-zero n
⊓-comm (suc m) zero = refl
⊓-comm (suc m) (suc n) =
begin
suc m ⊓ suc n
≡⟨ refl ⟩
suc (m ⊓ n)
≡⟨ cong suc (⊓-comm m n) ⟩
suc (n ⊓ m)
≡⟨ refl ⟩
suc n ⊓ suc m
∎
distrib-⊓-⊔ : _⊓_ DistributesOver _⊔_
distrib-⊓-⊔ = (distribˡ-⊓-⊔ , distribʳ-⊓-⊔)
where
distribʳ-⊓-⊔ : _⊓_ DistributesOverʳ _⊔_
distribʳ-⊓-⊔ (suc m) (suc n) (suc o) = cong suc $ distribʳ-⊓-⊔ m n o
distribʳ-⊓-⊔ (suc m) (suc n) zero = cong suc $ refl
distribʳ-⊓-⊔ (suc m) zero o = refl
distribʳ-⊓-⊔ zero n o = begin
(n ⊔ o) ⊓ 0 ≡⟨ ⊓-comm (n ⊔ o) 0 ⟩
0 ⊓ (n ⊔ o) ≡⟨ refl ⟩
0 ⊓ n ⊔ 0 ⊓ o ≡⟨ ⊓-comm 0 n ⟨ cong₂ _⊔_ ⟩ ⊓-comm 0 o ⟩
n ⊓ 0 ⊔ o ⊓ 0 ∎
distribˡ-⊓-⊔ : _⊓_ DistributesOverˡ _⊔_
distribˡ-⊓-⊔ m n o = begin
m ⊓ (n ⊔ o) ≡⟨ ⊓-comm m _ ⟩
(n ⊔ o) ⊓ m ≡⟨ distribʳ-⊓-⊔ m n o ⟩
n ⊓ m ⊔ o ⊓ m ≡⟨ ⊓-comm n m ⟨ cong₂ _⊔_ ⟩ ⊓-comm o m ⟩
m ⊓ n ⊔ m ⊓ o ∎
⊔-⊓-0-isCommutativeSemiringWithoutOne
: IsCommutativeSemiringWithoutOne _≡_ _⊔_ _⊓_ 0
⊔-⊓-0-isCommutativeSemiringWithoutOne = record
{ isSemiringWithoutOne = record
{ +-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = PropEq.isEquivalence
; assoc = ⊔-assoc
; ∙-cong = cong₂ _⊔_
}
; identityˡ = proj₁ ⊔-identity
; comm = ⊔-comm
}
; *-isSemigroup = record
{ isEquivalence = PropEq.isEquivalence
; assoc = ⊓-assoc
; ∙-cong = cong₂ _⊓_
}
; distrib = distrib-⊓-⊔
; zero = ⊓-zero
}
; *-comm = ⊓-comm
}
⊔-⊓-0-commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne _ _
⊔-⊓-0-commutativeSemiringWithoutOne = record
{ _+_ = _⊔_
; _*_ = _⊓_
; 0# = 0
; isCommutativeSemiringWithoutOne =
⊔-⊓-0-isCommutativeSemiringWithoutOne
}
------------------------------------------------------------------------
-- (ℕ, ⊓, ⊔) is a lattice
private
absorptive-⊓-⊔ : Absorptive _⊓_ _⊔_
absorptive-⊓-⊔ = abs-⊓-⊔ , abs-⊔-⊓
where
abs-⊔-⊓ : _⊔_ Absorbs _⊓_
abs-⊔-⊓ zero n = refl
abs-⊔-⊓ (suc m) zero = refl
abs-⊔-⊓ (suc m) (suc n) = cong suc $ abs-⊔-⊓ m n
abs-⊓-⊔ : _⊓_ Absorbs _⊔_
abs-⊓-⊔ zero n = refl
abs-⊓-⊔ (suc m) (suc n) = cong suc $ abs-⊓-⊔ m n
abs-⊓-⊔ (suc m) zero = cong suc $
begin
m ⊓ m
≡⟨ cong (_⊓_ m) $ sym $ proj₂ ⊔-identity m ⟩
m ⊓ (m ⊔ 0)
≡⟨ abs-⊓-⊔ m zero ⟩
m
∎
isDistributiveLattice : IsDistributiveLattice _≡_ _⊓_ _⊔_
isDistributiveLattice = record
{ isLattice = record
{ isEquivalence = PropEq.isEquivalence
; ∨-comm = ⊓-comm
; ∨-assoc = ⊓-assoc
; ∨-cong = cong₂ _⊓_
; ∧-comm = ⊔-comm
; ∧-assoc = ⊔-assoc
; ∧-cong = cong₂ _⊔_
; absorptive = absorptive-⊓-⊔
}
; ∨-∧-distribʳ = proj₂ distrib-⊓-⊔
}
distributiveLattice : DistributiveLattice _ _
distributiveLattice = record
{ _∨_ = _⊓_
; _∧_ = _⊔_
; isDistributiveLattice = isDistributiveLattice
}
------------------------------------------------------------------------
-- Converting between ≤ and ≤′
≤-step : ∀ {m n} → m ≤ n → m ≤ 1 + n
≤-step z≤n = z≤n
≤-step (s≤s m≤n) = s≤s (≤-step m≤n)
≤′⇒≤ : _≤′_ ⇒ _≤_
≤′⇒≤ ≤′-refl = ≤-refl
≤′⇒≤ (≤′-step m≤′n) = ≤-step (≤′⇒≤ m≤′n)
z≤′n : ∀ {n} → zero ≤′ n
z≤′n {zero} = ≤′-refl
z≤′n {suc n} = ≤′-step z≤′n
s≤′s : ∀ {m n} → m ≤′ n → suc m ≤′ suc n
s≤′s ≤′-refl = ≤′-refl
s≤′s (≤′-step m≤′n) = ≤′-step (s≤′s m≤′n)
≤⇒≤′ : _≤_ ⇒ _≤′_
≤⇒≤′ z≤n = z≤′n
≤⇒≤′ (s≤s m≤n) = s≤′s (≤⇒≤′ m≤n)
------------------------------------------------------------------------
-- Various order-related properties
≤-steps : ∀ {m n} k → m ≤ n → m ≤ k + n
≤-steps zero m≤n = m≤n
≤-steps (suc k) m≤n = ≤-step (≤-steps k m≤n)
m≤m+n : ∀ m n → m ≤ m + n
m≤m+n zero n = z≤n
m≤m+n (suc m) n = s≤s (m≤m+n m n)
m≤′m+n : ∀ m n → m ≤′ m + n
m≤′m+n m n = ≤⇒≤′ (m≤m+n m n)
n≤′m+n : ∀ m n → n ≤′ m + n
n≤′m+n zero n = ≤′-refl
n≤′m+n (suc m) n = ≤′-step (n≤′m+n m n)
n≤m+n : ∀ m n → n ≤ m + n
n≤m+n m n = ≤′⇒≤ (n≤′m+n m n)
n≤1+n : ∀ n → n ≤ 1 + n
n≤1+n _ = ≤-step ≤-refl
1+n≰n : ∀ {n} → ¬ 1 + n ≤ n
1+n≰n (s≤s le) = 1+n≰n le
≤pred⇒≤ : ∀ m n → m ≤ pred n → m ≤ n
≤pred⇒≤ m zero le = le
≤pred⇒≤ m (suc n) le = ≤-step le
≤⇒pred≤ : ∀ m n → m ≤ n → pred m ≤ n
≤⇒pred≤ zero n le = le
≤⇒pred≤ (suc m) n le = start
m ≤⟨ n≤1+n m ⟩
suc m ≤⟨ le ⟩
n □
¬i+1+j≤i : ∀ i {j} → ¬ i + suc j ≤ i
¬i+1+j≤i zero ()
¬i+1+j≤i (suc i) le = ¬i+1+j≤i i (≤-pred le)
n∸m≤n : ∀ m n → n ∸ m ≤ n
n∸m≤n zero n = ≤-refl
n∸m≤n (suc m) zero = ≤-refl
n∸m≤n (suc m) (suc n) = start
n ∸ m ≤⟨ n∸m≤n m n ⟩
n ≤⟨ n≤1+n n ⟩
suc n □
n≤m+n∸m : ∀ m n → n ≤ m + (n ∸ m)
n≤m+n∸m m zero = z≤n
n≤m+n∸m zero (suc n) = ≤-refl
n≤m+n∸m (suc m) (suc n) = s≤s (n≤m+n∸m m n)
m⊓n≤m : ∀ m n → m ⊓ n ≤ m
m⊓n≤m zero _ = z≤n
m⊓n≤m (suc m) zero = z≤n
m⊓n≤m (suc m) (suc n) = s≤s $ m⊓n≤m m n
m≤m⊔n : ∀ m n → m ≤ m ⊔ n
m≤m⊔n zero _ = z≤n
m≤m⊔n (suc m) zero = ≤-refl
m≤m⊔n (suc m) (suc n) = s≤s $ m≤m⊔n m n
⌈n/2⌉≤′n : ∀ n → ⌈ n /2⌉ ≤′ n
⌈n/2⌉≤′n zero = ≤′-refl
⌈n/2⌉≤′n (suc zero) = ≤′-refl
⌈n/2⌉≤′n (suc (suc n)) = s≤′s (≤′-step (⌈n/2⌉≤′n n))
⌊n/2⌋≤′n : ∀ n → ⌊ n /2⌋ ≤′ n
⌊n/2⌋≤′n zero = ≤′-refl
⌊n/2⌋≤′n (suc n) = ≤′-step (⌈n/2⌉≤′n n)
<-trans : Transitive _<_
<-trans {i} {j} {k} i<j j<k = start
1 + i ≤⟨ i<j ⟩
j ≤⟨ n≤1+n j ⟩
1 + j ≤⟨ j<k ⟩
k □
≰⇒> : _≰_ ⇒ _>_
≰⇒> {zero} z≰n with z≰n z≤n
... | ()
≰⇒> {suc m} {zero} _ = s≤s z≤n
≰⇒> {suc m} {suc n} m≰n = s≤s (≰⇒> (m≰n ∘ s≤s))
------------------------------------------------------------------------
-- (ℕ, _≡_, _<_) is a strict total order
m≢1+m+n : ∀ m {n} → m ≢ suc (m + n)
m≢1+m+n zero ()
m≢1+m+n (suc m) eq = m≢1+m+n m (cong pred eq)
strictTotalOrder : StrictTotalOrder _ _ _
strictTotalOrder = record
{ Carrier = ℕ
; _≈_ = _≡_
; _<_ = _<_
; isStrictTotalOrder = record
{ isEquivalence = PropEq.isEquivalence
; trans = <-trans
; compare = cmp
; <-resp-≈ = PropEq.resp₂ _<_
}
}
where
2+m+n≰m : ∀ {m n} → ¬ 2 + (m + n) ≤ m
2+m+n≰m (s≤s le) = 2+m+n≰m le
cmp : Trichotomous _≡_ _<_
cmp m n with compare m n
cmp .m .(suc (m + k)) | less m k = tri< (m≤m+n (suc m) k) (m≢1+m+n _) 2+m+n≰m
cmp .n .n | equal n = tri≈ 1+n≰n refl 1+n≰n
cmp .(suc (n + k)) .n | greater n k = tri> 2+m+n≰m (m≢1+m+n _ ∘ sym) (m≤m+n (suc n) k)
------------------------------------------------------------------------
-- Miscellaneous other properties
0∸n≡0 : LeftZero zero _∸_
0∸n≡0 zero = refl
0∸n≡0 (suc _) = refl
n∸n≡0 : ∀ n → n ∸ n ≡ 0
n∸n≡0 zero = refl
n∸n≡0 (suc n) = n∸n≡0 n
∸-+-assoc : ∀ m n o → (m ∸ n) ∸ o ≡ m ∸ (n + o)
∸-+-assoc m n zero = cong (_∸_ m) (sym $ +-right-identity n)
∸-+-assoc zero zero (suc o) = refl
∸-+-assoc zero (suc n) (suc o) = refl
∸-+-assoc (suc m) zero (suc o) = refl
∸-+-assoc (suc m) (suc n) (suc o) = ∸-+-assoc m n (suc o)
+-∸-assoc : ∀ m {n o} → o ≤ n → (m + n) ∸ o ≡ m + (n ∸ o)
+-∸-assoc m (z≤n {n = n}) = begin m + n ∎
+-∸-assoc m (s≤s {m = o} {n = n} o≤n) = begin
(m + suc n) ∸ suc o ≡⟨ cong (λ n → n ∸ suc o) (+-suc m n) ⟩
suc (m + n) ∸ suc o ≡⟨ refl ⟩
(m + n) ∸ o ≡⟨ +-∸-assoc m o≤n ⟩
m + (n ∸ o) ∎
m+n∸n≡m : ∀ m n → (m + n) ∸ n ≡ m
m+n∸n≡m m n = begin
(m + n) ∸ n ≡⟨ +-∸-assoc m (≤-refl {x = n}) ⟩
m + (n ∸ n) ≡⟨ cong (_+_ m) (n∸n≡0 n) ⟩
m + 0 ≡⟨ +-right-identity m ⟩
m ∎
m+n∸m≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n
m+n∸m≡n {m} {n} m≤n = begin
m + (n ∸ m) ≡⟨ sym $ +-∸-assoc m m≤n ⟩
(m + n) ∸ m ≡⟨ cong (λ n → n ∸ m) (+-comm m n) ⟩
(n + m) ∸ m ≡⟨ m+n∸n≡m n m ⟩
n ∎
m⊓n+n∸m≡n : ∀ m n → (m ⊓ n) + (n ∸ m) ≡ n
m⊓n+n∸m≡n zero n = refl
m⊓n+n∸m≡n (suc m) zero = refl
m⊓n+n∸m≡n (suc m) (suc n) = cong suc $ m⊓n+n∸m≡n m n
[m∸n]⊓[n∸m]≡0 : ∀ m n → (m ∸ n) ⊓ (n ∸ m) ≡ 0
[m∸n]⊓[n∸m]≡0 zero zero = refl
[m∸n]⊓[n∸m]≡0 zero (suc n) = refl
[m∸n]⊓[n∸m]≡0 (suc m) zero = refl
[m∸n]⊓[n∸m]≡0 (suc m) (suc n) = [m∸n]⊓[n∸m]≡0 m n
[i+j]∸[i+k]≡j∸k : ∀ i j k → (i + j) ∸ (i + k) ≡ j ∸ k
[i+j]∸[i+k]≡j∸k zero j k = refl
[i+j]∸[i+k]≡j∸k (suc i) j k = [i+j]∸[i+k]≡j∸k i j k
-- TODO: Can this proof be simplified? An automatic solver which can
-- handle ∸ would be nice...
i∸k∸j+j∸k≡i+j∸k : ∀ i j k → i ∸ (k ∸ j) + (j ∸ k) ≡ i + j ∸ k
i∸k∸j+j∸k≡i+j∸k zero j k = begin
0 ∸ (k ∸ j) + (j ∸ k)
≡⟨ cong (λ x → x + (j ∸ k)) (0∸n≡0 (k ∸ j)) ⟩
0 + (j ∸ k)
≡⟨ refl ⟩
j ∸ k
∎
i∸k∸j+j∸k≡i+j∸k (suc i) j zero = begin
suc i ∸ (0 ∸ j) + j
≡⟨ cong (λ x → suc i ∸ x + j) (0∸n≡0 j) ⟩
suc i ∸ 0 + j
≡⟨ refl ⟩
suc (i + j)
∎
i∸k∸j+j∸k≡i+j∸k (suc i) zero (suc k) = begin
i ∸ k + 0
≡⟨ +-right-identity _ ⟩
i ∸ k
≡⟨ cong (λ x → x ∸ k) (sym (+-right-identity _)) ⟩
i + 0 ∸ k
∎
i∸k∸j+j∸k≡i+j∸k (suc i) (suc j) (suc k) = begin
suc i ∸ (k ∸ j) + (j ∸ k)
≡⟨ i∸k∸j+j∸k≡i+j∸k (suc i) j k ⟩
suc i + j ∸ k
≡⟨ cong (λ x → x ∸ k)
(sym (+-suc i j)) ⟩
i + suc j ∸ k
∎
i+j≡0⇒i≡0 : ∀ i {j} → i + j ≡ 0 → i ≡ 0
i+j≡0⇒i≡0 zero eq = refl
i+j≡0⇒i≡0 (suc i) ()
i+j≡0⇒j≡0 : ∀ i {j} → i + j ≡ 0 → j ≡ 0
i+j≡0⇒j≡0 i {j} i+j≡0 = i+j≡0⇒i≡0 j $ begin
j + i
≡⟨ +-comm j i ⟩
i + j
≡⟨ i+j≡0 ⟩
0
∎
i*j≡0⇒i≡0∨j≡0 : ∀ i {j} → i * j ≡ 0 → i ≡ 0 ⊎ j ≡ 0
i*j≡0⇒i≡0∨j≡0 zero {j} eq = inj₁ refl
i*j≡0⇒i≡0∨j≡0 (suc i) {zero} eq = inj₂ refl
i*j≡0⇒i≡0∨j≡0 (suc i) {suc j} ()
i*j≡1⇒i≡1 : ∀ i j → i * j ≡ 1 → i ≡ 1
i*j≡1⇒i≡1 (suc zero) j _ = refl
i*j≡1⇒i≡1 zero j ()
i*j≡1⇒i≡1 (suc (suc i)) (suc (suc j)) ()
i*j≡1⇒i≡1 (suc (suc i)) (suc zero) ()
i*j≡1⇒i≡1 (suc (suc i)) zero eq with begin
0 ≡⟨ *-comm 0 i ⟩
i * 0 ≡⟨ eq ⟩
1 ∎
... | ()
i*j≡1⇒j≡1 : ∀ i j → i * j ≡ 1 → j ≡ 1
i*j≡1⇒j≡1 i j eq = i*j≡1⇒i≡1 j i (begin
j * i ≡⟨ *-comm j i ⟩
i * j ≡⟨ eq ⟩
1 ∎)
cancel-+-left : ∀ i {j k} → i + j ≡ i + k → j ≡ k
cancel-+-left zero eq = eq
cancel-+-left (suc i) eq = cancel-+-left i (cong pred eq)
cancel-+-left-≤ : ∀ i {j k} → i + j ≤ i + k → j ≤ k
cancel-+-left-≤ zero le = le
cancel-+-left-≤ (suc i) (s≤s le) = cancel-+-left-≤ i le
cancel-*-right : ∀ i j {k} → i * suc k ≡ j * suc k → i ≡ j
cancel-*-right zero zero eq = refl
cancel-*-right zero (suc j) ()
cancel-*-right (suc i) zero ()
cancel-*-right (suc i) (suc j) {k} eq =
cong suc (cancel-*-right i j (cancel-+-left (suc k) eq))
cancel-*-right-≤ : ∀ i j k → i * suc k ≤ j * suc k → i ≤ j
cancel-*-right-≤ zero _ _ _ = z≤n
cancel-*-right-≤ (suc i) zero _ ()
cancel-*-right-≤ (suc i) (suc j) k le =
s≤s (cancel-*-right-≤ i j k (cancel-+-left-≤ (suc k) le))
*-distrib-∸ʳ : _*_ DistributesOverʳ _∸_
*-distrib-∸ʳ i zero k = begin
(0 ∸ k) * i ≡⟨ cong₂ _*_ (0∸n≡0 k) refl ⟩
0 ≡⟨ sym $ 0∸n≡0 (k * i) ⟩
0 ∸ k * i ∎
*-distrib-∸ʳ i (suc j) zero = begin i + j * i ∎
*-distrib-∸ʳ i (suc j) (suc k) = begin
(j ∸ k) * i ≡⟨ *-distrib-∸ʳ i j k ⟩
j * i ∸ k * i ≡⟨ sym $ [i+j]∸[i+k]≡j∸k i _ _ ⟩
i + j * i ∸ (i + k * i) ∎
im≡jm+n⇒[i∸j]m≡n
: ∀ i j m n →
i * m ≡ j * m + n → (i ∸ j) * m ≡ n
im≡jm+n⇒[i∸j]m≡n i j m n eq = begin
(i ∸ j) * m ≡⟨ *-distrib-∸ʳ m i j ⟩
(i * m) ∸ (j * m) ≡⟨ cong₂ _∸_ eq (refl {x = j * m}) ⟩
(j * m + n) ∸ (j * m) ≡⟨ cong₂ _∸_ (+-comm (j * m) n) (refl {x = j * m}) ⟩
(n + j * m) ∸ (j * m) ≡⟨ m+n∸n≡m n (j * m) ⟩
n ∎
i+1+j≢i : ∀ i {j} → i + suc j ≢ i
i+1+j≢i i eq = ¬i+1+j≤i i (reflexive eq)
where open DecTotalOrder decTotalOrder
⌊n/2⌋-mono : ⌊_/2⌋ Preserves _≤_ ⟶ _≤_
⌊n/2⌋-mono z≤n = z≤n
⌊n/2⌋-mono (s≤s z≤n) = z≤n
⌊n/2⌋-mono (s≤s (s≤s m≤n)) = s≤s (⌊n/2⌋-mono m≤n)
⌈n/2⌉-mono : ⌈_/2⌉ Preserves _≤_ ⟶ _≤_
⌈n/2⌉-mono m≤n = ⌊n/2⌋-mono (s≤s m≤n)
pred-mono : pred Preserves _≤_ ⟶ _≤_
pred-mono z≤n = z≤n
pred-mono (s≤s le) = le
_+-mono_ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
_+-mono_ {zero} {m₂} {n₁} {n₂} z≤n n₁≤n₂ = start
n₁ ≤⟨ n₁≤n₂ ⟩
n₂ ≤⟨ n≤m+n m₂ n₂ ⟩
m₂ + n₂ □
s≤s m₁≤m₂ +-mono n₁≤n₂ = s≤s (m₁≤m₂ +-mono n₁≤n₂)
_*-mono_ : _*_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
z≤n *-mono n₁≤n₂ = z≤n
s≤s m₁≤m₂ *-mono n₁≤n₂ = n₁≤n₂ +-mono (m₁≤m₂ *-mono n₁≤n₂)
∸-mono : _∸_ Preserves₂ _≤_ ⟶ _≥_ ⟶ _≤_
∸-mono z≤n (s≤s n₁≥n₂) = z≤n
∸-mono (s≤s m₁≤m₂) (s≤s n₁≥n₂) = ∸-mono m₁≤m₂ n₁≥n₂
∸-mono {m₁} {m₂} m₁≤m₂ (z≤n {n = n₁}) = start
m₁ ∸ n₁ ≤⟨ n∸m≤n n₁ m₁ ⟩
m₁ ≤⟨ m₁≤m₂ ⟩
m₂ □
| {
"alphanum_fraction": 0.4329983754,
"avg_line_length": 29.1561403509,
"ext": "agda",
"hexsha": "ccd5f258143213af6dc09540bc5411c3f7822225",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Nat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Nat/Properties.agda",
"max_line_length": 88,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Nat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 8595,
"size": 16619
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Lists.Lists
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Semirings.Definition
open import Orders.Total.Definition
module Numbers.BinaryNaturals.Definition where
data Bit : Set where
zero : Bit
one : Bit
BinNat : Set
BinNat = List Bit
::Inj : {xs ys : BinNat} {i : Bit} → i :: xs ≡ i :: ys → xs ≡ ys
::Inj {i = zero} refl = refl
::Inj {i = one} refl = refl
nonEmptyNotEmpty : {a : _} {A : Set a} {l1 : List A} {i : A} → i :: l1 ≡ [] → False
nonEmptyNotEmpty {l1 = l1} {i} ()
-- TODO - maybe we should do the floating-point style of assuming there's a leading bit and not storing it.
-- That way, everything is already canonical.
canonical : BinNat → BinNat
canonical [] = []
canonical (zero :: n) with canonical n
canonical (zero :: n) | [] = []
canonical (zero :: n) | x :: bl = zero :: x :: bl
canonical (one :: n) = one :: canonical n
Canonicalised : Set
Canonicalised = Sg BinNat (λ i → canonical i ≡ i)
binNatToN : BinNat → ℕ
binNatToN [] = 0
binNatToN (zero :: b) = 2 *N binNatToN b
binNatToN (one :: b) = 1 +N (2 *N binNatToN b)
incr : BinNat → BinNat
incr [] = one :: []
incr (zero :: n) = one :: n
incr (one :: n) = zero :: (incr n)
incrNonzero : (x : BinNat) → canonical (incr x) ≡ [] → False
incrPreservesCanonical : (x : BinNat) → (canonical x ≡ x) → canonical (incr x) ≡ incr x
incrPreservesCanonical [] pr = refl
incrPreservesCanonical (zero :: xs) pr with canonical xs
incrPreservesCanonical (zero :: xs) pr | x :: t = applyEquality (one ::_) (::Inj pr)
incrPreservesCanonical (one :: xs) pr with inspect (canonical (incr xs))
incrPreservesCanonical (one :: xs) pr | [] with≡ x = exFalso (incrNonzero xs x)
incrPreservesCanonical (one :: xs) pr | (x₁ :: y) with≡ x rewrite x = applyEquality (zero ::_) (transitivity (equalityCommutative x) (incrPreservesCanonical xs (::Inj pr)))
incrPreservesCanonical' : (x : BinNat) → canonical (incr x) ≡ incr (canonical x)
incrC : Canonicalised → Canonicalised
incrC (a , b) = incr a , incrPreservesCanonical a b
NToBinNat : ℕ → BinNat
NToBinNat zero = []
NToBinNat (succ n) with NToBinNat n
NToBinNat (succ n) | t = incr t
NToBinNatC : ℕ → Canonicalised
NToBinNatC zero = [] , refl
NToBinNatC (succ n) = incrC (NToBinNatC n)
incrInj : {x y : BinNat} → incr x ≡ incr y → canonical x ≡ canonical y
incrNonzero' : (x : BinNat) → (incr x) ≡ [] → False
incrNonzero' (zero :: xs) ()
incrNonzero' (one :: xs) ()
canonicalRespectsIncr' : {x y : BinNat} → canonical (incr x) ≡ canonical (incr y) → canonical x ≡ canonical y
binNatToNSucc : (n : BinNat) → binNatToN (incr n) ≡ succ (binNatToN n)
NToBinNatSucc : (n : ℕ) → incr (NToBinNat n) ≡ NToBinNat (succ n)
binNatToNZero : (x : BinNat) → binNatToN x ≡ 0 → canonical x ≡ []
binNatToNZero' : (x : BinNat) → canonical x ≡ [] → binNatToN x ≡ 0
NToBinNatZero : (n : ℕ) → NToBinNat n ≡ [] → n ≡ 0
NToBinNatZero zero pr = refl
NToBinNatZero (succ n) pr with NToBinNat n
NToBinNatZero (succ n) pr | zero :: bl = exFalso (nonEmptyNotEmpty pr)
NToBinNatZero (succ n) pr | one :: bl = exFalso (nonEmptyNotEmpty pr)
canonicalAscends : {i : Bit} → (a : BinNat) → 0 <N binNatToN a → i :: canonical a ≡ canonical (i :: a)
canonicalAscends' : {i : Bit} → (a : BinNat) → (canonical a ≡ [] → False) → i :: canonical a ≡ canonical (i :: a)
canonicalAscends' {i} a pr = canonicalAscends {i} a (t a pr)
where
t : (a : BinNat) → (canonical a ≡ [] → False) → 0 <N binNatToN a
t a pr with TotalOrder.totality ℕTotalOrder 0 (binNatToN a)
t a pr | inl (inl x) = x
t a pr | inr x = exFalso (pr (binNatToNZero a (equalityCommutative x)))
canonicalIdempotent : (a : BinNat) → canonical a ≡ canonical (canonical a)
canonicalIdempotent [] = refl
canonicalIdempotent (zero :: a) with inspect (canonical a)
canonicalIdempotent (zero :: a) | [] with≡ y rewrite y = refl
canonicalIdempotent (zero :: a) | (x :: bl) with≡ y = transitivity (equalityCommutative (canonicalAscends' {zero} a λ p → contr p y)) (transitivity (applyEquality (zero ::_) (canonicalIdempotent a)) (equalityCommutative v))
where
contr : {a : _} {A : Set a} {l1 l2 : List A} → {x : A} → l1 ≡ [] → l1 ≡ x :: l2 → False
contr {l1 = []} p1 ()
contr {l1 = x :: l1} () p2
u : canonical (canonical (zero :: a)) ≡ canonical (zero :: canonical a)
u = applyEquality canonical (equalityCommutative (canonicalAscends' {zero} a λ p → contr p y))
v : canonical (canonical (zero :: a)) ≡ zero :: canonical (canonical a)
v = transitivity u (equalityCommutative (canonicalAscends' {zero} (canonical a) λ p → contr (transitivity (canonicalIdempotent a) p) y))
canonicalIdempotent (one :: a) rewrite equalityCommutative (canonicalIdempotent a) = refl
canonicalAscends'' : {i : Bit} → (a : BinNat) → canonical (i :: canonical a) ≡ canonical (i :: a)
binNatToNInj : (x y : BinNat) → binNatToN x ≡ binNatToN y → canonical x ≡ canonical y
NToBinNatInj : (x y : ℕ) → canonical (NToBinNat x) ≡ canonical (NToBinNat y) → x ≡ y
NToBinNatIsCanonical : (x : ℕ) → NToBinNat x ≡ canonical (NToBinNat x)
NToBinNatIsCanonical zero = refl
NToBinNatIsCanonical (succ x) with NToBinNatC x
NToBinNatIsCanonical (succ x) | a , b = equalityCommutative (incrPreservesCanonical (NToBinNat x) (equalityCommutative (NToBinNatIsCanonical x)))
contr' : {a : _} {A : Set a} {l1 l2 : List A} → {x : A} → l1 ≡ [] → l1 ≡ x :: l2 → False
contr' {l1 = []} p1 ()
contr' {l1 = x :: l1} () p2
binNatToNIsCanonical : (x : BinNat) → binNatToN (canonical x) ≡ binNatToN x
binNatToNIsCanonical [] = refl
binNatToNIsCanonical (zero :: x) with inspect (canonical x)
binNatToNIsCanonical (zero :: x) | [] with≡ t rewrite t | binNatToNZero' x t = refl
binNatToNIsCanonical (zero :: x) | (x₁ :: bl) with≡ t rewrite (equalityCommutative (canonicalAscends' {zero} x λ p → contr' p t)) | binNatToNIsCanonical x = refl
binNatToNIsCanonical (one :: x) rewrite binNatToNIsCanonical x = refl
-- The following two theorems demonstrate that Canonicalised is isomorphic to ℕ
nToN : (x : ℕ) → binNatToN (NToBinNat x) ≡ x
binToBin : (x : BinNat) → NToBinNat (binNatToN x) ≡ canonical x
binToBin x = transitivity (NToBinNatIsCanonical (binNatToN x)) (binNatToNInj (NToBinNat (binNatToN x)) x (nToN (binNatToN x)))
doubleIsBitShift' : (a : ℕ) → NToBinNat (2 *N succ a) ≡ zero :: NToBinNat (succ a)
doubleIsBitShift' zero = refl
doubleIsBitShift' (succ a) with doubleIsBitShift' a
... | bl rewrite Semiring.commutative ℕSemiring a (succ (succ (a +N 0))) | Semiring.commutative ℕSemiring (succ (a +N 0)) a | Semiring.commutative ℕSemiring a (succ (a +N 0)) | Semiring.commutative ℕSemiring (a +N 0) a | bl = refl
doubleIsBitShift : (a : ℕ) → (0 <N a) → NToBinNat (2 *N a) ≡ zero :: NToBinNat a
doubleIsBitShift zero ()
doubleIsBitShift (succ a) _ = doubleIsBitShift' a
canonicalDescends : {a : Bit} (as : BinNat) → (prA : a :: as ≡ canonical (a :: as)) → as ≡ canonical as
canonicalDescends {zero} as pr with canonical as
canonicalDescends {zero} as pr | x :: bl = ::Inj pr
canonicalDescends {one} as pr = ::Inj pr
--- Proofs
parity : (a b : ℕ) → succ (2 *N a) ≡ 2 *N b → False
doubleInj : (a b : ℕ) → (2 *N a) ≡ (2 *N b) → a ≡ b
incrNonzeroTwice : (x : BinNat) → canonical (incr (incr x)) ≡ one :: [] → False
incrNonzeroTwice (zero :: xs) pr with canonical (incr xs)
incrNonzeroTwice (zero :: xs) () | []
incrNonzeroTwice (zero :: xs) () | x :: bl
incrNonzeroTwice (one :: xs) pr = exFalso (incrNonzero xs (::Inj pr))
canonicalRespectsIncr' {[]} {[]} pr = refl
canonicalRespectsIncr' {[]} {zero :: y} pr with canonical y
canonicalRespectsIncr' {[]} {zero :: y} pr | [] = refl
canonicalRespectsIncr' {[]} {one :: y} pr with canonical (incr y)
canonicalRespectsIncr' {[]} {one :: y} () | []
canonicalRespectsIncr' {[]} {one :: y} () | x :: bl
canonicalRespectsIncr' {zero :: xs} {y} pr with canonical xs
canonicalRespectsIncr' {zero :: xs} {[]} pr | [] = refl
canonicalRespectsIncr' {zero :: xs} {zero :: y} pr | [] with canonical y
canonicalRespectsIncr' {zero :: xs} {zero :: y} pr | [] | [] = refl
canonicalRespectsIncr' {zero :: xs} {one :: y} pr | [] with canonical (incr y)
canonicalRespectsIncr' {zero :: xs} {one :: y} () | [] | []
canonicalRespectsIncr' {zero :: xs} {one :: y} () | [] | x :: bl
canonicalRespectsIncr' {zero :: xs} {zero :: ys} pr | x :: bl with canonical ys
canonicalRespectsIncr' {zero :: xs} {zero :: ys} pr | x :: bl | x₁ :: th = applyEquality (zero ::_) (::Inj pr)
canonicalRespectsIncr' {zero :: xs} {one :: ys} pr | x :: bl with canonical (incr ys)
canonicalRespectsIncr' {zero :: xs} {one :: ys} () | x :: bl | []
canonicalRespectsIncr' {zero :: xs} {one :: ys} () | x :: bl | x₁ :: th
canonicalRespectsIncr' {one :: xs} {[]} pr with canonical (incr xs)
canonicalRespectsIncr' {one :: xs} {[]} () | []
canonicalRespectsIncr' {one :: xs} {[]} () | x :: bl
canonicalRespectsIncr' {one :: xs} {zero :: ys} pr with canonical ys
canonicalRespectsIncr' {one :: xs} {zero :: ys} pr | [] with canonical (incr xs)
canonicalRespectsIncr' {one :: xs} {zero :: ys} () | [] | []
canonicalRespectsIncr' {one :: xs} {zero :: ys} () | [] | x :: t
canonicalRespectsIncr' {one :: xs} {zero :: ys} pr | x :: bl with canonical (incr xs)
canonicalRespectsIncr' {one :: xs} {zero :: ys} () | x :: bl | []
canonicalRespectsIncr' {one :: xs} {zero :: ys} () | x :: bl | x₁ :: t
canonicalRespectsIncr' {one :: xs} {one :: ys} pr with inspect (canonical (incr xs))
canonicalRespectsIncr' {one :: xs} {one :: ys} pr | [] with≡ x = exFalso (incrNonzero xs x)
canonicalRespectsIncr' {one :: xs} {one :: ys} pr | (x+1 :: x+1s) with≡ bad rewrite bad = applyEquality (one ::_) ans
where
ans : canonical xs ≡ canonical ys
ans with inspect (canonical (incr ys))
ans | [] with≡ x = exFalso (incrNonzero ys x)
ans | (x₁ :: y) with≡ x rewrite x = canonicalRespectsIncr' {xs} {ys} (transitivity bad (transitivity (::Inj pr) (equalityCommutative x)))
binNatToNInj[] : (y : BinNat) → 0 ≡ binNatToN y → [] ≡ canonical y
binNatToNInj[] [] pr = refl
binNatToNInj[] (zero :: y) pr with productZeroImpliesOperandZero {2} {binNatToN y} (equalityCommutative pr)
binNatToNInj[] (zero :: y) pr | inr x with inspect (canonical y)
binNatToNInj[] (zero :: y) pr | inr x | [] with≡ canYPr rewrite canYPr = refl
binNatToNInj[] (zero :: ys) pr | inr x | (y :: canY) with≡ canYPr with binNatToNZero ys x
... | r with canonical ys
binNatToNInj[] (zero :: ys) pr | inr x | (y :: canY) with≡ canYPr | r | [] = refl
binNatToNInj[] (zero :: ys) pr | inr x | (y :: canY) with≡ canYPr | () | x₁ :: t
binNatToNInj [] y pr = binNatToNInj[] y pr
binNatToNInj (zero :: xs) [] pr = equalityCommutative (binNatToNInj[] (zero :: xs) (equalityCommutative pr))
binNatToNInj (zero :: xs) (zero :: ys) pr with doubleInj (binNatToN xs) (binNatToN ys) pr
... | x=y with binNatToNInj xs ys x=y
... | t with canonical xs
binNatToNInj (zero :: xs) (zero :: ys) pr | x=y | t | [] with canonical ys
binNatToNInj (zero :: xs) (zero :: ys) pr | x=y | t | [] | [] = refl
binNatToNInj (zero :: xs) (zero :: ys) pr | x=y | t | x :: cxs with canonical ys
binNatToNInj (zero :: xs) (zero :: ys) pr | x=y | t | x :: cxs | x₁ :: cys = applyEquality (zero ::_) t
binNatToNInj (zero :: xs) (one :: ys) pr = exFalso (parity (binNatToN ys) (binNatToN xs) (equalityCommutative pr))
binNatToNInj (one :: xs) (zero :: ys) pr = exFalso (parity (binNatToN xs) (binNatToN ys) pr)
binNatToNInj (one :: xs) (one :: ys) pr = applyEquality (one ::_) (binNatToNInj xs ys (doubleInj (binNatToN xs) (binNatToN ys) (succInjective pr)))
NToBinNatInj zero zero pr = refl
NToBinNatInj zero (succ y) pr with NToBinNat y
NToBinNatInj zero (succ y) pr | bl = exFalso (incrNonzero bl (equalityCommutative pr))
NToBinNatInj (succ x) zero pr with NToBinNat x
... | bl = exFalso (incrNonzero bl pr)
NToBinNatInj (succ x) (succ y) pr with inspect (NToBinNat x)
NToBinNatInj (succ zero) (succ zero) pr | [] with≡ nToBinXPr = refl
NToBinNatInj (succ zero) (succ (succ y)) pr | [] with≡ nToBinXPr with NToBinNat y
NToBinNatInj (succ zero) (succ (succ y)) pr | [] with≡ nToBinXPr | y' = exFalso (incrNonzeroTwice y' (equalityCommutative pr))
NToBinNatInj (succ (succ x)) (succ y) pr | [] with≡ nToBinXPr with NToBinNat x
NToBinNatInj (succ (succ x)) (succ y) pr | [] with≡ nToBinXPr | t = exFalso (incrNonzero' t nToBinXPr)
NToBinNatInj (succ x) (succ y) pr | (x₁ :: nToBinX) with≡ nToBinXPr with NToBinNatInj x y (canonicalRespectsIncr' {NToBinNat x} {NToBinNat y} pr)
NToBinNatInj (succ x) (succ .x) pr | (x₁ :: nToBinX) with≡ nToBinXPr | refl = refl
incrInj {[]} {[]} pr = refl
incrInj {[]} {zero :: ys} pr rewrite equalityCommutative (::Inj pr) = refl
incrInj {zero :: xs} {[]} pr rewrite ::Inj pr = refl
incrInj {zero :: xs} {zero :: .xs} refl = refl
incrInj {one :: xs} {one :: ys} pr = applyEquality (one ::_) (incrInj {xs} {ys} (l (incr xs) (incr ys) pr))
where
l : (a : BinNat) → (b : BinNat) → zero :: a ≡ zero :: b → a ≡ b
l a .a refl = refl
doubleInj zero zero pr = refl
doubleInj (succ a) (succ b) pr = applyEquality succ (doubleInj a b u)
where
t : a +N a ≡ b +N b
t rewrite Semiring.commutative ℕSemiring (succ a) 0 | Semiring.commutative ℕSemiring (succ b) 0 | Semiring.commutative ℕSemiring a (succ a) | Semiring.commutative ℕSemiring b (succ b) = succInjective (succInjective pr)
u : a +N (a +N zero) ≡ b +N (b +N zero)
u rewrite Semiring.commutative ℕSemiring a 0 | Semiring.commutative ℕSemiring b 0 = t
binNatToNZero [] pr = refl
binNatToNZero (zero :: xs) pr with inspect (canonical xs)
binNatToNZero (zero :: xs) pr | [] with≡ x rewrite x = refl
binNatToNZero (zero :: xs) pr | (x₁ :: y) with≡ x with productZeroImpliesOperandZero {2} {binNatToN xs} pr
binNatToNZero (zero :: xs) pr | (x₁ :: y) with≡ x | inr pr' with binNatToNZero xs pr'
... | bl with canonical xs
binNatToNZero (zero :: xs) pr | (x₁ :: y) with≡ x | inr pr' | bl | [] = refl
binNatToNZero (zero :: xs) pr | (x₁ :: y) with≡ x | inr pr' | () | x₂ :: t
binNatToNSucc [] = refl
binNatToNSucc (zero :: n) = refl
binNatToNSucc (one :: n) rewrite Semiring.commutative ℕSemiring (binNatToN n) zero | Semiring.commutative ℕSemiring (binNatToN (incr n)) 0 | binNatToNSucc n = applyEquality succ (Semiring.commutative ℕSemiring (binNatToN n) (succ (binNatToN n)))
incrNonzero (one :: xs) pr with inspect (canonical (incr xs))
incrNonzero (one :: xs) pr | [] with≡ x = incrNonzero xs x
incrNonzero (one :: xs) pr | (y :: ys) with≡ x with canonical (incr xs)
incrNonzero (one :: xs) pr | (y :: ys) with≡ () | []
incrNonzero (one :: xs) () | (.x₁ :: .th) with≡ refl | x₁ :: th
nToN zero = refl
nToN (succ x) with inspect (NToBinNat x)
nToN (succ x) | [] with≡ pr = ans
where
t : x ≡ zero
t = NToBinNatInj x 0 (applyEquality canonical pr)
ans : binNatToN (incr (NToBinNat x)) ≡ succ x
ans rewrite t | pr = refl
nToN (succ x) | (bit :: xs) with≡ pr = transitivity (binNatToNSucc (NToBinNat x)) (applyEquality succ (nToN x))
parity zero (succ b) pr rewrite Semiring.commutative ℕSemiring b (succ (b +N 0)) = bad pr
where
bad : (1 ≡ succ (succ ((b +N 0) +N b))) → False
bad ()
parity (succ a) (succ b) pr rewrite Semiring.commutative ℕSemiring b (succ (b +N 0)) | Semiring.commutative ℕSemiring a (succ (a +N 0)) | Semiring.commutative ℕSemiring (a +N 0) a | Semiring.commutative ℕSemiring (b +N 0) b = parity a b (succInjective (succInjective pr))
binNatToNZero' [] pr = refl
binNatToNZero' (zero :: xs) pr with inspect (canonical xs)
binNatToNZero' (zero :: xs) pr | [] with≡ p2 = ans
where
t : binNatToN xs ≡ 0
t = binNatToNZero' xs p2
ans : 2 *N binNatToN xs ≡ 0
ans rewrite t = refl
binNatToNZero' (zero :: xs) pr | (y :: ys) with≡ p rewrite p = exFalso (bad pr)
where
bad : zero :: y :: ys ≡ [] → False
bad ()
binNatToNZero' (one :: xs) ()
canonicalAscends {zero} a 0<a with inspect (canonical a)
canonicalAscends {zero} (zero :: a) 0<a | [] with≡ x = exFalso (contr'' (binNatToN a) t v)
where
u : binNatToN (zero :: a) ≡ 0
u = binNatToNZero' (zero :: a) x
v : binNatToN a ≡ 0
v with inspect (binNatToN a)
v | zero with≡ x = x
v | succ a' with≡ x with inspect (binNatToN (zero :: a))
v | succ a' with≡ x | zero with≡ pr2 rewrite pr2 = exFalso (TotalOrder.irreflexive ℕTotalOrder 0<a)
v | succ a' with≡ x | succ y with≡ pr2 rewrite u = exFalso (TotalOrder.irreflexive ℕTotalOrder 0<a)
t : 0 <N binNatToN a
t with binNatToN a
t | succ bl rewrite Semiring.commutative ℕSemiring (succ bl) 0 = succIsPositive bl
contr'' : (x : ℕ) → (0 <N x) → (x ≡ 0) → False
contr'' x 0<x x=0 rewrite x=0 = TotalOrder.irreflexive ℕTotalOrder 0<x
canonicalAscends {zero} a 0<a | (x₁ :: y) with≡ x rewrite x = refl
canonicalAscends {one} a 0<a = refl
canonicalAscends'' {i} a with inspect (canonical a)
canonicalAscends'' {zero} a | [] with≡ x rewrite x = refl
canonicalAscends'' {one} a | [] with≡ x rewrite x = refl
canonicalAscends'' {i} a | (x₁ :: y) with≡ x = transitivity (applyEquality canonical (canonicalAscends' {i} a λ p → contr p x)) (equalityCommutative (canonicalIdempotent (i :: a)))
where
contr : {a : _} {A : Set a} {l1 l2 : List A} → {x : A} → l1 ≡ [] → l1 ≡ x :: l2 → False
contr {l1 = []} p1 ()
contr {l1 = x :: l1} () p2
incrPreservesCanonical' [] = refl
incrPreservesCanonical' (zero :: xs) with inspect (canonical xs)
incrPreservesCanonical' (zero :: xs) | [] with≡ x rewrite x = refl
incrPreservesCanonical' (zero :: xs) | (x₁ :: y) with≡ x rewrite x = refl
incrPreservesCanonical' (one :: xs) with inspect (canonical (incr xs))
... | [] with≡ pr = exFalso (incrNonzero xs pr)
... | (_ :: _) with≡ pr rewrite pr = applyEquality (zero ::_) (transitivity (equalityCommutative pr) (incrPreservesCanonical' xs))
NToBinNatSucc zero = refl
NToBinNatSucc (succ n) with NToBinNat n
... | [] = refl
... | a :: as = refl
| {
"alphanum_fraction": 0.6511445682,
"avg_line_length": 50.7585227273,
"ext": "agda",
"hexsha": "3758b1f870bbff50e795a6ad7514a01385c486c3",
"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/BinaryNaturals/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": "Numbers/BinaryNaturals/Definition.agda",
"max_line_length": 271,
"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/BinaryNaturals/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": 6450,
"size": 17867
} |
module Id where
{-
postulate x : Set
postulate y : Set
postulate _p_ : Set -> Set -> Set
e : Set
e = x p y
-}
{-
id2 : (A : Set0) -> (_ : A) -> A
id2 = \ (C : Set) (z : C) -> z
-}
{-
id : (A : Set) -> A -> A
id = \ A x -> x
-}
{-
idImp : {A : Set} -> A -> A
idImp = \ {A} x -> x
-}
id : {A : Set} -> A -> A
id x = x
idd = id id
| {
"alphanum_fraction": 0.4179104478,
"avg_line_length": 10.8064516129,
"ext": "agda",
"hexsha": "3371e775a930a39e8056d1455347ea3223e65868",
"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/Id.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/Id.agda",
"max_line_length": 33,
"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/Id.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": 154,
"size": 335
} |
module deriveUtil where
open import Level renaming ( suc to succ ; zero to Zero )
open import Data.Nat
open import Data.Fin
open import Data.List
open import regex
open import automaton
open import nfa
open import logic
open NAutomaton
open Automaton
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import Relation.Nullary
open Bool
data alpha2 : Set where
a : alpha2
b : alpha2
a-eq? : (x y : alpha2) → Dec (x ≡ y)
a-eq? a a = yes refl
a-eq? b b = yes refl
a-eq? a b = no (λ ())
a-eq? b a = no (λ ())
open Regex
open import finiteSet
fin-a : FiniteSet alpha2
fin-a = record {
finite = finite0
; Q←F = Q←F0
; F←Q = F←Q0
; finiso→ = finiso→0
; finiso← = finiso←0
} where
finite0 : ℕ
finite0 = 2
Q←F0 : Fin finite0 → alpha2
Q←F0 zero = a
Q←F0 (suc zero) = b
F←Q0 : alpha2 → Fin finite0
F←Q0 a = # 0
F←Q0 b = # 1
finiso→0 : (q : alpha2) → Q←F0 ( F←Q0 q ) ≡ q
finiso→0 a = refl
finiso→0 b = refl
finiso←0 : (f : Fin finite0 ) → F←Q0 ( Q←F0 f ) ≡ f
finiso←0 zero = refl
finiso←0 (suc zero) = refl
open import derive alpha2 fin-a a-eq?
test11 = regex→automaton ( < a > & < b > )
test12 = accept test11 record { state = < a > & < b > ; is-derived = unit } ( a ∷ b ∷ [] )
test13 = accept test11 record { state = < a > & < b > ; is-derived = unit } ( a ∷ a ∷ [] )
test14 = regex-match ( ( < a > & < b > ) * ) ( a ∷ b ∷ a ∷ a ∷ [] )
test15 = regex-derive ( ( < a > & < b > ) * ∷ [] )
test16 = regex-derive test15
test17 : regex-derive test16 ≡ test16
test17 = refl
| {
"alphanum_fraction": 0.578782172,
"avg_line_length": 22.7571428571,
"ext": "agda",
"hexsha": "23621f6e4d1a6eed7aa690d0c0084c8e1992797a",
"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": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/deriveUtil.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"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": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/deriveUtil.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/deriveUtil.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 597,
"size": 1593
} |
{-# OPTIONS --without-K #-}
module higher.interval where
open import Relation.Binary.PropositionalEquality
open import equality-groupoid
postulate
I : Set
zero : I
one : I
path : zero ≡ one
module DepElim (B : I → Set)
(x : B zero)
(y : B one)
(p : subst B path x ≡ y) where
postulate
elim : (t : I) → B t
β-zero : elim zero ≡ x
β-one : elim one ≡ y
β-path : ap (subst B path) (sym β-zero)
· lem-naturality elim path
· β-one
≡ p
module Elim {X : Set}
(x y : X)
(p : x ≡ y) where
open DepElim (λ _ → X) x y p
postulate
elim' : I → X
β-zero' : elim zero ≡ x
β-one' : elim one ≡ y
β-path' : sym (β-zero') · ap elim path · β-one' ≡ p | {
"alphanum_fraction": 0.5038167939,
"avg_line_length": 20.1538461538,
"ext": "agda",
"hexsha": "536ad0662e5134853fc801192986ba525b154761",
"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/interval.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/interval.agda",
"max_line_length": 55,
"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/interval.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": 254,
"size": 786
} |
-- Jesper, 2019-09-12: The fix of #3541 introduced a regression: the
-- index of the equality type is treated as a positive argument.
data _≡_ (A : Set) : Set → Set where
refl : A ≡ A
postulate X : Set
data D : Set where
c : X ≡ D → D
| {
"alphanum_fraction": 0.646090535,
"avg_line_length": 20.25,
"ext": "agda",
"hexsha": "f0b91c0d0efaf24d8d7d773417acc8b9a3ed33f4",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/EqualityNotPositive.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "strake/agda",
"max_issues_repo_path": "test/Fail/EqualityNotPositive.agda",
"max_line_length": 68,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "strake/agda",
"max_stars_repo_path": "test/Fail/EqualityNotPositive.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 84,
"size": 243
} |
-- Andreas, 2017-07-26, issue #2331.
-- Andrea found a counterexample against the "usable decrease" feature:
open import Agda.Builtin.Size
data D (i : Size) : Set where
c : (j : Size< i) → D i
mutual
test : (i : Size) → D i → Set
test i (c j) = (k : Size< j) (l : Size< k) → helper i j k (c l)
helper : (i : Size) (j : Size< i) (k : Size< j) → D k → Set
helper i j k d = test k d
-- Should not termination check.
| {
"alphanum_fraction": 0.5874125874,
"avg_line_length": 25.2352941176,
"ext": "agda",
"hexsha": "1f88c4175b68fe591531ed882262798170465f50",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2331.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2331.agda",
"max_line_length": 71,
"max_stars_count": 2,
"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/Issue2331.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 157,
"size": 429
} |
module ConstructorHeadedDivergenceIn2-2-10 where
data ⊤ : Set where
tt : ⊤
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
data _×_ (A B : Set) : Set where
_,_ : A → B → A × B
{- Brandon Moore reports (July 2011)
In 2.2.10 the following code seems to cause typechecking
to diverge.
-}
f : ℕ → Set
f zero = ⊤
f (suc n) = ℕ × f n
enum : (n : ℕ) → f n
enum zero = tt
enum (suc n) = n , enum n
n : ℕ
n = _
test : f n
test = enum (suc n)
{-
This typechecks quickly if the definition
of test is changed to
test = enum n
I think the problem is that the body has type ℕ × f n,
and unifying it with the expected type f n invokes the
constructor-headed function specialization to resolve
n to suc n', and the process repeats.
Brandon
-}
-- Andreas, 2011-07-28 This bug is not reproducible in the darcs
-- version.
--
-- This file should fail with unresolved metas. | {
"alphanum_fraction": 0.6697459584,
"avg_line_length": 18.0416666667,
"ext": "agda",
"hexsha": "94e6b58bcfa257c2e5a2e9f28605c49c818ad918",
"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/ConstructorHeadedDivergenceIn2-2-10.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/ConstructorHeadedDivergenceIn2-2-10.agda",
"max_line_length": 64,
"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/ConstructorHeadedDivergenceIn2-2-10.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": 281,
"size": 866
} |
{-# OPTIONS --allow-unsolved-metas #-}
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
infix 0 _≡_
{-# BUILTIN EQUALITY _≡_ #-}
data Sigma {l} (A : Set l) (B : A -> Set l) : Set l where
_**_ : (a : A) -> B a -> Sigma A B
sym : ∀ {a} {A : Set a} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {a} {A : Set a} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl eq = eq
subst : ∀ {a b} {x y : Set a} → (P : Set a → Set b) → x ≡ y → P x ≡ P y
subst P refl = refl
cong : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y
cong f refl = refl
fst : ∀ {l} -> {A : Set l}{B : A -> Set l} -> Sigma A B -> A
fst (x ** _) = x
snd : ∀ {l} -> {A : Set l}{B : A -> Set l} -> (sum : Sigma A B) -> B (fst sum)
snd (x ** y) = y
record Group {l} (G : Set l) (_op_ : G -> G -> G) : Set l where
field
assoc : {a b c : G} -> ((a op b) op c) ≡ (a op (b op c))
id : {a : G} -> Sigma G (\e -> e op a ≡ a)
inv : {a : G} -> Sigma G (\a^-1 -> (a^-1 op a) ≡ (fst (id {a})))
e : {a : G} -> G
e {a} = fst (id {a})
_^-1 : G -> G
x ^-1 = fst (inv {x})
a^-1-op-a==e : {a : G} -> ((a ^-1) op a) ≡ e {a}
a^-1-op-a==e {a} with inv {a}
... | (_ ** p) = p
id-lem-right : {a : G} -> (e {a} op a) ≡ a
id-lem-right {a} = snd (id {a})
id-lem-left : {a : G} -> (a op e {a}) ≡ a
id-lem-left {a} rewrite id-lem-right {a} = {!!}
-- In Agda 2.4.2.5 the error was:
-- Function does not accept argument {r = _}
-- when checking that {r = a} is a valid argument to a function of
-- type {a : G} → G
| {
"alphanum_fraction": 0.4349775785,
"avg_line_length": 28.3818181818,
"ext": "agda",
"hexsha": "830142a7e7dea96b9b32d9926b7c0dfc8c5268b0",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1934.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1934.agda",
"max_line_length": 80,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1934.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": 702,
"size": 1561
} |
module plfa.part1.Naturals where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
seven = suc (suc (suc (suc (suc (suc (suc zero))))))
{-# BUILTIN NATURAL ℕ #-}
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
_+_ : ℕ → ℕ → ℕ
zero + n = n
(suc m) + n = suc (m + n)
_ : 2 + 3 ≡ 5
_ =
begin
2 + 3
≡⟨⟩ -- is shorthand for
(suc (suc zero)) + (suc (suc (suc zero)))
≡⟨⟩ -- inductive case
suc ((suc zero) + (suc (suc (suc zero))))
≡⟨⟩ -- inductive case
suc (suc (zero + (suc (suc (suc zero)))))
≡⟨⟩ -- base case
suc (suc (suc (suc (suc zero))))
≡⟨⟩ -- is longhand for
5
∎
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
_̂_ : ℕ → ℕ → ℕ
n ̂ zero = 1
n ̂ (suc m) = n * (n ̂ m)
_ : 3 ̂ 4 ≡ 81
_ =
begin
3 ̂ 4
≡⟨⟩
81
∎
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
| {
"alphanum_fraction": 0.4786235662,
"avg_line_length": 17.4363636364,
"ext": "agda",
"hexsha": "8dc5e7fd843bee4768b8df42816faeafbdd5eba1",
"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": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sym-cereal/proofs",
"max_forks_repo_path": "plfa/part1/Naturals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"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": "sym-cereal/proofs",
"max_issues_repo_path": "plfa/part1/Naturals.agda",
"max_line_length": 52,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "275ecc582b3a6a1da1af387251c6b4d74d9a5203",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UnsoundWitch/proofs",
"max_stars_repo_path": "plfa/part1/Naturals.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T10:58:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-03T03:29:40.000Z",
"num_tokens": 463,
"size": 959
} |
open import Categories
open import Monads
module Monads.Kleisli.Functors {a b}{C : Cat {a}{b}}(M : Monad C) where
open import Library
open import Functors
open import Monads.Kleisli M
open Cat C
open Fun
open Monad M
KlL : Fun C Kl
KlL = record{
OMap = id;
HMap = comp η;
fid = idr;
fcomp = λ{_}{_}{_}{f}{g} →
proof
comp η (comp f g)
≅⟨ sym ass ⟩
comp (comp η f) g
≅⟨ cong (λ f → comp f g) (sym law2) ⟩
comp (comp (bind (comp η f)) η) g
≅⟨ ass ⟩
comp (bind (comp η f)) (comp η g)
∎}
KlR : Fun Kl C
KlR = record{
OMap = T;
HMap = bind;
fid = law1;
fcomp = law3}
| {
"alphanum_fraction": 0.5698412698,
"avg_line_length": 17.5,
"ext": "agda",
"hexsha": "0773c8c5d940ec6ab115d5468714ce2b54261a0b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Monads/Kleisli/Functors.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Monads/Kleisli/Functors.agda",
"max_line_length": 71,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Monads/Kleisli/Functors.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 266,
"size": 630
} |
mutual
Loop : Set
Loop = {!!}
-- Should not solve ?0 := Loop → Loop
solve : Loop → Loop → Loop
solve x = x
| {
"alphanum_fraction": 0.5378151261,
"avg_line_length": 13.2222222222,
"ext": "agda",
"hexsha": "5124aef8ed39dfee6cda2ea0b8023665694808f8",
"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/Issue2710.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/Issue2710.agda",
"max_line_length": 39,
"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/Issue2710.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": 41,
"size": 119
} |
{-# OPTIONS --prop --without-K --rewriting #-}
module Calf.Types.Unit where
open import Calf.Prelude
open import Calf.Metalanguage
open import Data.Unit public using (⊤) renaming (tt to triv)
unit : tp pos
unit = U (meta ⊤)
| {
"alphanum_fraction": 0.7074235808,
"avg_line_length": 17.6153846154,
"ext": "agda",
"hexsha": "f71a07d5388221de144a91be6bddb1c5dad065d0",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/Types/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/Types/Unit.agda",
"max_line_length": 60,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/Types/Unit.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 64,
"size": 229
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Group
open import lib.types.List
open import lib.types.Pi
open import lib.types.SetQuotient
open import lib.types.Word
open import lib.groups.GeneratedGroup
open import lib.groups.Homomorphism
module lib.groups.GeneratedAbelianGroup {i} {m} where
module GeneratedAbelianGroup (A : Type i) (R : Rel (Word A) m) where
data AbGroupRel : Word A → Word A → Type (lmax i m) where
agr-commutes : ∀ l₁ l₂ → AbGroupRel (l₁ ++ l₂) (l₂ ++ l₁)
agr-rel : ∀ {l₁ l₂} → R l₁ l₂ → AbGroupRel l₁ l₂
private
module Gen = GeneratedGroup A AbGroupRel
open Gen hiding (module HomomorphismEquiv; rel-holds) public
agr-reverse : (w : Word A) → QuotWordRel (reverse w) w
agr-reverse nil = qwr-refl idp
agr-reverse (x :: w) =
reverse w ++ (x :: nil)
qwr⟨ qwr-rel (agr-commutes (reverse w) (x :: nil)) ⟩
x :: reverse w
qwr⟨ qwr-cong-r (x :: nil) (agr-reverse w) ⟩
x :: w qwr∎
GenAbGroup : AbGroup (lmax i m)
GenAbGroup = grp , grp-is-abelian
where
grp : Group (lmax i m)
grp = GenGroup
module grp = Group grp
grp-is-abelian : is-abelian grp
grp-is-abelian =
QuotWord-elim {P = λ a → ∀ b → grp.comp a b == grp.comp b a}
(λ la →
QuotWord-elim {P = λ b → grp.comp qw[ la ] b == grp.comp b qw[ la ]}
(λ lb → quot-rel (qwr-rel (agr-commutes la lb)))
(λ _ → prop-has-all-paths-↓))
(λ _ → prop-has-all-paths-↓ {{Π-level ⟨⟩}})
rel-holds : ∀ {w₁} {w₂} (r : R w₁ w₂) → qw[ w₁ ] == qw[ w₂ ]
rel-holds r = Gen.rel-holds (agr-rel r)
module GenAbGroup = AbGroup GenAbGroup
{- Universal Properties -}
module HomomorphismEquiv {j} (G : AbGroup j) where
private
module G = AbGroup G
module R-RFs = RelationRespectingFunctions A R G.grp
module AbGroupRel-RFs = RelationRespectingFunctions A AbGroupRel G.grp
open R-RFs public
private
legal-functions-equiv : R-RFs.RelationRespectingFunction
≃ AbGroupRel-RFs.RelationRespectingFunction
legal-functions-equiv =
equiv to from
(λ lf → AbGroupRel-RFs.RelationRespectingFunction= idp)
(λ lf → R-RFs.RelationRespectingFunction= idp)
where
to : R-RFs.RelationRespectingFunction → AbGroupRel-RFs.RelationRespectingFunction
to (R-RFs.rel-res-fun f respects-R) =
AbGroupRel-RFs.rel-res-fun f respects-AbGroupRel
where
respects-AbGroupRel : AbGroupRel-RFs.respects-rel f
respects-AbGroupRel (agr-commutes l₁ l₂) =
Word-extendᴳ G.grp f (l₁ ++ l₂)
=⟨ Word-extendᴳ-++ G.grp f l₁ l₂ ⟩
G.comp (Word-extendᴳ G.grp f l₁) (Word-extendᴳ G.grp f l₂)
=⟨ G.comm (Word-extendᴳ G.grp f l₁) (Word-extendᴳ G.grp f l₂) ⟩
G.comp (Word-extendᴳ G.grp f l₂) (Word-extendᴳ G.grp f l₁)
=⟨ ! (Word-extendᴳ-++ G.grp f l₂ l₁) ⟩
Word-extendᴳ G.grp f (l₂ ++ l₁) =∎
respects-AbGroupRel (agr-rel r) = respects-R r
from : AbGroupRel-RFs.RelationRespectingFunction → R-RFs.RelationRespectingFunction
from (AbGroupRel-RFs.rel-res-fun f respects-AbGroupRel) =
R-RFs.rel-res-fun f respects-R
where
respects-R : R-RFs.respects-rel f
respects-R r = respects-AbGroupRel (agr-rel r)
extend-equiv : R-RFs.RelationRespectingFunction ≃ (GenAbGroup.grp →ᴳ G.grp)
extend-equiv =
Gen.HomomorphismEquiv.extend-equiv G.grp ∘e legal-functions-equiv
extend : R-RFs.RelationRespectingFunction → (GenAbGroup.grp →ᴳ G.grp)
extend = –> extend-equiv
| {
"alphanum_fraction": 0.623987034,
"avg_line_length": 37.3939393939,
"ext": "agda",
"hexsha": "8a816821c32daf4698960173cecb06140cba8385",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/groups/GeneratedAbelianGroup.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/groups/GeneratedAbelianGroup.agda",
"max_line_length": 91,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/groups/GeneratedAbelianGroup.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": 1185,
"size": 3702
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Modalities.Everything where
open import Cubical.Modalities.Modality public
| {
"alphanum_fraction": 0.7822580645,
"avg_line_length": 24.8,
"ext": "agda",
"hexsha": "f835e615dc7d7b831746fce9964e5286726119b1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Modalities/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Modalities/Everything.agda",
"max_line_length": 46,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Modalities/Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 31,
"size": 124
} |
{-
This second-order signature was created from the following second-order syntax description:
syntax PCF
type
N : 0-ary
_↣_ : 2-ary | r30
B : 0-ary
term
app : α ↣ β α -> β | _$_ l20
lam : α.β -> α ↣ β | ƛ_ r10
tr : B
fl : B
ze : N
su : N -> N
pr : N -> N
iz : N -> B | 0?
if : B α α -> α
fix : α.α -> α
theory
(ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]
(ƛη) f : α ↣ β |> lam (x. app(f, x)) = f
(zz) |> iz (ze) = tr
(zs) n : N |> iz (su (n)) = fl
(ps) n : N |> pr (su (n)) = n
(ift) t f : α |> if (tr, t, f) = t
(iff) t f : α |> if (fl, t, f) = f
(fix) t : α.α |> fix (x.t[x]) = t[fix (x.t[x])]
-}
module PCF.Signature where
open import SOAS.Context
-- Type declaration
data PCFT : Set where
N : PCFT
_↣_ : PCFT → PCFT → PCFT
B : PCFT
infixr 30 _↣_
open import SOAS.Syntax.Signature PCFT public
open import SOAS.Syntax.Build PCFT public
-- Operator symbols
data PCFₒ : Set where
appₒ lamₒ : {α β : PCFT} → PCFₒ
trₒ flₒ zeₒ suₒ prₒ izₒ : PCFₒ
ifₒ fixₒ : {α : PCFT} → PCFₒ
-- Term signature
PCF:Sig : Signature PCFₒ
PCF:Sig = sig λ
{ (appₒ {α}{β}) → (⊢₀ α ↣ β) , (⊢₀ α) ⟼₂ β
; (lamₒ {α}{β}) → (α ⊢₁ β) ⟼₁ α ↣ β
; trₒ → ⟼₀ B
; flₒ → ⟼₀ B
; zeₒ → ⟼₀ N
; suₒ → (⊢₀ N) ⟼₁ N
; prₒ → (⊢₀ N) ⟼₁ N
; izₒ → (⊢₀ N) ⟼₁ B
; (ifₒ {α}) → (⊢₀ B) , (⊢₀ α) , (⊢₀ α) ⟼₃ α
; (fixₒ {α}) → (α ⊢₁ α) ⟼₁ α
}
open Signature PCF:Sig public
| {
"alphanum_fraction": 0.4620418848,
"avg_line_length": 21.5211267606,
"ext": "agda",
"hexsha": "641b7ede447f2fcbb1d109f679170fef2761bc90",
"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/PCF/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/PCF/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/PCF/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": 767,
"size": 1528
} |
module ShouldBeEmpty where
data Zero : Set where
data One : Set where
one : One
ok : Zero -> One
ok ()
bad : One -> One
bad ()
| {
"alphanum_fraction": 0.6268656716,
"avg_line_length": 9.5714285714,
"ext": "agda",
"hexsha": "e0b809086da7db462a10e3f0a313beaf251063de",
"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/ShouldBeEmpty.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/ShouldBeEmpty.agda",
"max_line_length": 26,
"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/ShouldBeEmpty.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 40,
"size": 134
} |
{- 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 LibraBFT.Impl.NetworkMsg
open import LibraBFT.Concrete.System.Parameters
-- This module collects the implementation obligations for our (fake/simple, for now)
-- "implementation" into the structure required by Concrete.Properties.
open import LibraBFT.Impl.Handle.Properties
import LibraBFT.Impl.Properties.VotesOnce as VO
import LibraBFT.Impl.Properties.PreferredRound as PR
open import LibraBFT.Concrete.Obligations
open import LibraBFT.Concrete.System
module LibraBFT.Impl.Properties where
theImplObligations : ImplObligations
theImplObligations = record { sps-cor = impl-sps-avp
; vo₁ = VO.vo₁
; vo₂ = VO.vo₂
; pr₁ = PR.pr₁ }
| {
"alphanum_fraction": 0.7102983638,
"avg_line_length": 43.2916666667,
"ext": "agda",
"hexsha": "b883978f40f438183378f0ac7b7c807e71d77fe6",
"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/Impl/Properties.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/Impl/Properties.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/Impl/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 265,
"size": 1039
} |
{-# OPTIONS --without-K #-}
module Transport where
open import GroupoidStructure
open import PathOperations
open import Types
tr-post : ∀ {a} {A : Set a} (a : A) {x y : A}
(p : x ≡ y) (q : a ≡ x) →
tr (λ x → a ≡ x) p q ≡ q · p
tr-post a = J
(λ x _ p → (q : a ≡ x) → tr (λ x → a ≡ x) p q ≡ q · p)
(λ _ q → p·id q ⁻¹)
_ _
tr-pre : ∀ {a} {A : Set a} (a : A) {x y : A}
(p : x ≡ y) (q : x ≡ a) →
tr (λ x → x ≡ a) p q ≡ p ⁻¹ · q
tr-pre a = J
(λ x _ p → (q : x ≡ a) → tr (λ x → x ≡ a) p q ≡ p ⁻¹ · q)
(λ _ q → id·p q ⁻¹)
_ _
tr-both : ∀ {a} {A : Set a} (a : A) {x y : A}
(p : x ≡ y) (q : x ≡ x) →
tr (λ x → x ≡ x) p q ≡ p ⁻¹ · q · p
tr-both a = J
(λ x _ p → (q : x ≡ x) → tr (λ x → x ≡ x) p q ≡ p ⁻¹ · q · p)
(λ _ q → p·id q ⁻¹ · id·p (q · refl) ⁻¹)
_ _
tr-∘ : ∀ {a b p} {A : Set a} {B : Set b} {P : B → Set p}
(f : A → B) {x y : A} (p : x ≡ y) (u : P (f x)) →
tr (P ∘ f) p u ≡ tr P (ap f p) u
tr-∘ {P = P} f = J
(λ x _ p → (u : P (f x)) → tr (P ∘ f) p u ≡ tr P (ap f p) u)
(λ _ _ → refl) _ _
| {
"alphanum_fraction": 0.3916423712,
"avg_line_length": 27.0789473684,
"ext": "agda",
"hexsha": "e3b0929995e9b52f74cb0999eaccb7545e5dbb56",
"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": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/Transport.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"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": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/Transport.agda",
"max_line_length": 63,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/Transport.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 555,
"size": 1029
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Homogeneously-indexed binary relations
------------------------------------------------------------------------
-- The contents of this module should be accessed via
-- `Relation.Binary.Indexed.Homogeneous`.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Indexed.Homogeneous.Core
module Relation.Binary.Indexed.Homogeneous.Structures
{i a ℓ} {I : Set i}
(A : I → Set a) -- The underlying indexed sets
(_≈ᵢ_ : IRel A ℓ) -- The underlying indexed equality relation
where
open import Data.Product using (_,_)
open import Function using (_⟨_⟩_)
open import Level using (Level; _⊔_; suc)
open import Relation.Binary as B using (_⇒_)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Binary.Indexed.Homogeneous.Definitions
------------------------------------------------------------------------
-- Equivalences
-- Indexed structures are laid out in a similar manner as to those
-- in Relation.Binary. The main difference is each structure also
-- contains proofs for the lifted version of the relation.
record IsIndexedEquivalence : Set (i ⊔ a ⊔ ℓ) where
field
reflᵢ : Reflexive A _≈ᵢ_
symᵢ : Symmetric A _≈ᵢ_
transᵢ : Transitive A _≈ᵢ_
reflexiveᵢ : ∀ {i} → _≡_ ⟨ _⇒_ ⟩ _≈ᵢ_ {i}
reflexiveᵢ P.refl = reflᵢ
-- Lift properties
reflexive : _≡_ ⇒ (Lift A _≈ᵢ_)
reflexive P.refl i = reflᵢ
refl : B.Reflexive (Lift A _≈ᵢ_)
refl i = reflᵢ
sym : B.Symmetric (Lift A _≈ᵢ_)
sym x≈y i = symᵢ (x≈y i)
trans : B.Transitive (Lift A _≈ᵢ_)
trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i)
isEquivalence : B.IsEquivalence (Lift A _≈ᵢ_)
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
record IsIndexedDecEquivalence : Set (i ⊔ a ⊔ ℓ) where
infix 4 _≟ᵢ_
field
_≟ᵢ_ : Decidable A _≈ᵢ_
isEquivalenceᵢ : IsIndexedEquivalence
open IsIndexedEquivalence isEquivalenceᵢ public
------------------------------------------------------------------------
-- Preorders
record IsIndexedPreorder {ℓ₂} (_∼ᵢ_ : IRel A ℓ₂)
: Set (i ⊔ a ⊔ ℓ ⊔ ℓ₂) where
field
isEquivalenceᵢ : IsIndexedEquivalence
reflexiveᵢ : _≈ᵢ_ ⇒[ A ] _∼ᵢ_
transᵢ : Transitive A _∼ᵢ_
module Eq = IsIndexedEquivalence isEquivalenceᵢ
reflᵢ : Reflexive A _∼ᵢ_
reflᵢ = reflexiveᵢ Eq.reflᵢ
∼ᵢ-respˡ-≈ᵢ : Respectsˡ A _∼ᵢ_ _≈ᵢ_
∼ᵢ-respˡ-≈ᵢ x≈y x∼z = transᵢ (reflexiveᵢ (Eq.symᵢ x≈y)) x∼z
∼ᵢ-respʳ-≈ᵢ : Respectsʳ A _∼ᵢ_ _≈ᵢ_
∼ᵢ-respʳ-≈ᵢ x≈y z∼x = transᵢ z∼x (reflexiveᵢ x≈y)
∼ᵢ-resp-≈ᵢ : Respects₂ A _∼ᵢ_ _≈ᵢ_
∼ᵢ-resp-≈ᵢ = ∼ᵢ-respʳ-≈ᵢ , ∼ᵢ-respˡ-≈ᵢ
-- Lifted properties
reflexive : Lift A _≈ᵢ_ B.⇒ Lift A _∼ᵢ_
reflexive x≈y i = reflexiveᵢ (x≈y i)
refl : B.Reflexive (Lift A _∼ᵢ_)
refl i = reflᵢ
trans : B.Transitive (Lift A _∼ᵢ_)
trans x≈y y≈z i = transᵢ (x≈y i) (y≈z i)
∼-respˡ-≈ : (Lift A _∼ᵢ_) B.Respectsˡ (Lift A _≈ᵢ_)
∼-respˡ-≈ x≈y x∼z i = ∼ᵢ-respˡ-≈ᵢ (x≈y i) (x∼z i)
∼-respʳ-≈ : (Lift A _∼ᵢ_) B.Respectsʳ (Lift A _≈ᵢ_)
∼-respʳ-≈ x≈y z∼x i = ∼ᵢ-respʳ-≈ᵢ (x≈y i) (z∼x i)
∼-resp-≈ : (Lift A _∼ᵢ_) B.Respects₂ (Lift A _≈ᵢ_)
∼-resp-≈ = ∼-respʳ-≈ , ∼-respˡ-≈
isPreorder : B.IsPreorder (Lift A _≈ᵢ_) (Lift A _∼ᵢ_)
isPreorder = record
{ isEquivalence = Eq.isEquivalence
; reflexive = reflexive
; trans = trans
}
------------------------------------------------------------------------
-- Partial orders
record IsIndexedPartialOrder {ℓ₂} (_≤ᵢ_ : IRel A ℓ₂)
: Set (i ⊔ a ⊔ ℓ ⊔ ℓ₂) where
field
isPreorderᵢ : IsIndexedPreorder _≤ᵢ_
antisymᵢ : Antisymmetric A _≈ᵢ_ _≤ᵢ_
open IsIndexedPreorder isPreorderᵢ public
renaming
( ∼ᵢ-respˡ-≈ᵢ to ≤ᵢ-respˡ-≈ᵢ
; ∼ᵢ-respʳ-≈ᵢ to ≤ᵢ-respʳ-≈ᵢ
; ∼ᵢ-resp-≈ᵢ to ≤ᵢ-resp-≈ᵢ
; ∼-respˡ-≈ to ≤-respˡ-≈
; ∼-respʳ-≈ to ≤-respʳ-≈
; ∼-resp-≈ to ≤-resp-≈
)
antisym : B.Antisymmetric (Lift A _≈ᵢ_) (Lift A _≤ᵢ_)
antisym x≤y y≤x i = antisymᵢ (x≤y i) (y≤x i)
isPartialOrder : B.IsPartialOrder (Lift A _≈ᵢ_) (Lift A _≤ᵢ_)
isPartialOrder = record
{ isPreorder = isPreorder
; antisym = antisym
}
| {
"alphanum_fraction": 0.5721987811,
"avg_line_length": 27.8823529412,
"ext": "agda",
"hexsha": "cc43931143a136460367408553a91bfdf01edbfc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous/Structures.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 1883,
"size": 4266
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NConnected
open import lib.types.Empty
open import lib.types.Nat
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.TLevel
open import lib.types.Truncation
module lib.types.LoopSpace where
{- loop space -}
module _ {i} where
⊙Ω : Ptd i → Ptd i
⊙Ω ⊙[ A , a ] = ⊙[ (a == a) , idp ]
Ω : Ptd i → Type i
Ω = de⊙ ∘ ⊙Ω
module _ {i} {X : Ptd i} where
Ω-! : Ω X → Ω X
Ω-! = !
Ω-∙ : Ω X → Ω X → Ω X
Ω-∙ = _∙_
{- pointed versions of functions on paths -}
⊙Ω-∙ : ∀ {i} {X : Ptd i} → ⊙Ω X ⊙× ⊙Ω X ⊙→ ⊙Ω X
⊙Ω-∙ = (uncurry Ω-∙ , idp)
⊙Ω-fmap : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → ⊙Ω X ⊙→ ⊙Ω Y
⊙Ω-fmap (f , idp) = ap f , idp
Ω-fmap : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → (Ω X → Ω Y)
Ω-fmap F = fst (⊙Ω-fmap F)
Ω-fmap-β : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p : Ω X)
→ Ω-fmap F p == ! (snd F) ∙ ap (fst F) p ∙' snd F
Ω-fmap-β (_ , idp) _ = idp
Ω-isemap : ∀ {i j} {X : Ptd i} {Y : Ptd j}
(F : X ⊙→ Y) → is-equiv (fst F) → is-equiv (Ω-fmap F)
Ω-isemap (f , idp) e = ap-is-equiv e _ _
Ω-emap : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ (X ⊙≃ Y) → (Ω X ≃ Ω Y)
Ω-emap (F , F-is-equiv) = Ω-fmap F , Ω-isemap F F-is-equiv
⊙Ω-emap : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ (X ⊙≃ Y) → (⊙Ω X ⊙≃ ⊙Ω Y)
⊙Ω-emap (F , F-is-equiv) = ⊙Ω-fmap F , Ω-isemap F F-is-equiv
⊙Ω-fmap2 : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ X ⊙× Y ⊙→ Z → ⊙Ω X ⊙× ⊙Ω Y ⊙→ ⊙Ω Z
⊙Ω-fmap2 (f , idp) = (λ{(p , q) → ap2 (curry f) p q}) , idp
⊙Ω-fmap-∘ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : Y ⊙→ Z) (f : X ⊙→ Y)
→ ⊙Ω-fmap (g ⊙∘ f) == ⊙Ω-fmap g ⊙∘ ⊙Ω-fmap f
⊙Ω-fmap-∘ (g , idp) (f , idp) = ⊙λ=' (λ p → ap-∘ g f p) idp
⊙Ω-csmap : ∀ {i₀ i₁ j₀ j₁} {X₀ : Ptd i₀} {X₁ : Ptd i₁}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}
{hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}
→ ⊙CommSquare f g hX hY
→ ⊙CommSquare (⊙Ω-fmap f) (⊙Ω-fmap g) (⊙Ω-fmap hX) (⊙Ω-fmap hY)
⊙Ω-csmap {f = f} {g} {hX} {hY} (⊙comm-sqr cs) = ⊙comm-sqr $ ⊙app= $
⊙Ω-fmap hY ⊙∘ ⊙Ω-fmap f
=⟨ ! $ ⊙Ω-fmap-∘ hY f ⟩
⊙Ω-fmap (hY ⊙∘ f)
=⟨ ap ⊙Ω-fmap $ ⊙λ= cs ⟩
⊙Ω-fmap (g ⊙∘ hX)
=⟨ ⊙Ω-fmap-∘ g hX ⟩
⊙Ω-fmap g ⊙∘ ⊙Ω-fmap hX
=∎
⊙Ω-csemap : ∀ {i₀ i₁ j₀ j₁} {X₀ : Ptd i₀} {X₁ : Ptd i₁}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}
{hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}
→ ⊙CommSquareEquiv f g hX hY
→ ⊙CommSquareEquiv (⊙Ω-fmap f) (⊙Ω-fmap g) (⊙Ω-fmap hX) (⊙Ω-fmap hY)
⊙Ω-csemap {f = f} {g} {hX} {hY} (⊙comm-sqr cs , hX-ise , hY-ise) =
(⊙comm-sqr $ ⊙app= $
⊙Ω-fmap hY ⊙∘ ⊙Ω-fmap f
=⟨ ! $ ⊙Ω-fmap-∘ hY f ⟩
⊙Ω-fmap (hY ⊙∘ f)
=⟨ ap ⊙Ω-fmap $ ⊙λ= cs ⟩
⊙Ω-fmap (g ⊙∘ hX)
=⟨ ⊙Ω-fmap-∘ g hX ⟩
⊙Ω-fmap g ⊙∘ ⊙Ω-fmap hX
=∎) ,
Ω-isemap hX hX-ise , Ω-isemap hY hY-ise
⊙Ω-fmap-idf : ∀ {i} {X : Ptd i} → ⊙Ω-fmap (⊙idf X) == ⊙idf _
⊙Ω-fmap-idf = ⊙λ=' ap-idf idp
⊙Ω-fmap2-fst : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ ⊙Ω-fmap2 {X = X} {Y = Y} ⊙fst == ⊙fst
⊙Ω-fmap2-fst = ⊙λ=' (uncurry ap2-fst) idp
⊙Ω-fmap2-snd : ∀ {i j} {X : Ptd i} {Y : Ptd j}
→ ⊙Ω-fmap2 {X = X} {Y = Y} ⊙snd == ⊙snd
⊙Ω-fmap2-snd = ⊙λ=' (uncurry ap2-snd) idp
⊙Ω-fmap-fmap2 : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(G : Z ⊙→ W) (F : X ⊙× Y ⊙→ Z)
→ ⊙Ω-fmap G ⊙∘ ⊙Ω-fmap2 F == ⊙Ω-fmap2 (G ⊙∘ F)
⊙Ω-fmap-fmap2 (g , idp) (f , idp) =
⊙λ=' (uncurry (ap-ap2 g (curry f))) idp
⊙Ω-fmap2-fmap : ∀ {i j k l m}
{X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}
(G : (U ⊙× V) ⊙→ Z) (F₁ : X ⊙→ U) (F₂ : Y ⊙→ V)
→ ⊙Ω-fmap2 G ⊙∘ ⊙×-fmap (⊙Ω-fmap F₁) (⊙Ω-fmap F₂) == ⊙Ω-fmap2 (G ⊙∘ ⊙×-fmap F₁ F₂)
⊙Ω-fmap2-fmap (g , idp) (f₁ , idp) (f₂ , idp) =
⊙λ=' (λ {(p , q) → ap2-ap-l (curry g) f₁ p (ap f₂ q)
∙ ap2-ap-r (λ x v → g (f₁ x , v)) f₂ p q})
idp
⊙Ω-fmap2-diag : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙× X ⊙→ Y)
→ ⊙Ω-fmap2 F ⊙∘ ⊙diag == ⊙Ω-fmap (F ⊙∘ ⊙diag)
⊙Ω-fmap2-diag (f , idp) = ⊙λ=' (ap2-diag (curry f)) idp
{- iterated loop spaces. [Ω^] and [Ω^'] iterates [Ω] from different sides:
[Ω^ (S n) X = Ω (Ω^ n X)] and [Ω^' (S n) X = Ω^' n (Ω X)]. -}
module _ {i} where
⊙Ω^ : (n : ℕ) → Ptd i → Ptd i
⊙Ω^ O X = X
⊙Ω^ (S n) X = ⊙Ω (⊙Ω^ n X)
Ω^ : (n : ℕ) → Ptd i → Type i
Ω^ n X = de⊙ (⊙Ω^ n X)
⊙Ω^' : (n : ℕ) → Ptd i → Ptd i
⊙Ω^' O X = X
⊙Ω^' (S n) X = (⊙Ω^' n (⊙Ω X))
Ω^' : (n : ℕ) → Ptd i → Type i
Ω^' n X = de⊙ (⊙Ω^' n X)
{- [⊙Ω^-fmap] and [⊙Ω^-fmap2] for higher loop spaces -}
⊙Ω^-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → ⊙Ω^ n X ⊙→ ⊙Ω^ n Y
⊙Ω^-fmap O F = F
⊙Ω^-fmap (S n) F = ⊙Ω-fmap (⊙Ω^-fmap n F)
Ω^-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → (de⊙ (⊙Ω^ n X) → de⊙ (⊙Ω^ n Y))
Ω^-fmap n F = fst (⊙Ω^-fmap n F)
⊙Ω^-csmap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}
{hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}
→ ⊙CommSquare f g hX hY
→ ⊙CommSquare (⊙Ω^-fmap n f) (⊙Ω^-fmap n g) (⊙Ω^-fmap n hX) (⊙Ω^-fmap n hY)
⊙Ω^-csmap O cs = cs
⊙Ω^-csmap (S n) cs = ⊙Ω-csmap (⊙Ω^-csmap n cs)
⊙Ω^'-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → ⊙Ω^' n X ⊙→ ⊙Ω^' n Y
⊙Ω^'-fmap O F = F
⊙Ω^'-fmap (S n) F = ⊙Ω^'-fmap n (⊙Ω-fmap F)
⊙Ω^'-csmap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}
{hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}
→ ⊙CommSquare f g hX hY
→ ⊙CommSquare (⊙Ω^'-fmap n f) (⊙Ω^'-fmap n g) (⊙Ω^'-fmap n hX) (⊙Ω^'-fmap n hY)
⊙Ω^'-csmap O cs = cs
⊙Ω^'-csmap (S n) cs = ⊙Ω^'-csmap n (⊙Ω-csmap cs)
Ω^'-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ X ⊙→ Y → (de⊙ (⊙Ω^' n X) → de⊙ (⊙Ω^' n Y))
Ω^'-fmap n F = fst (⊙Ω^'-fmap n F)
⊙Ω^-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ ((X ⊙× Y) ⊙→ Z)
→ ((⊙Ω^ n X ⊙× ⊙Ω^ n Y) ⊙→ ⊙Ω^ n Z)
⊙Ω^-fmap2 O F = F
⊙Ω^-fmap2 (S n) F = ⊙Ω-fmap2 (⊙Ω^-fmap2 n F)
Ω^-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ ((X ⊙× Y) ⊙→ Z)
→ ((Ω^ n X) × (Ω^ n Y) → Ω^ n Z)
Ω^-fmap2 n F = fst (⊙Ω^-fmap2 n F)
⊙Ω^'-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ ((X ⊙× Y) ⊙→ Z)
→ ((⊙Ω^' n X ⊙× ⊙Ω^' n Y) ⊙→ ⊙Ω^' n Z)
⊙Ω^'-fmap2 O F = F
⊙Ω^'-fmap2 (S n) F = ⊙Ω^'-fmap2 n (⊙Ω-fmap2 F)
Ω^'-fmap2 : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
→ ((X ⊙× Y) ⊙→ Z)
→ ((Ω^' n X) × (Ω^' n Y) → Ω^' n Z)
Ω^'-fmap2 n F = fst (⊙Ω^'-fmap2 n F)
⊙Ω^-fmap-∘ : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : Y ⊙→ Z) (f : X ⊙→ Y)
→ ⊙Ω^-fmap n (g ⊙∘ f) == ⊙Ω^-fmap n g ⊙∘ ⊙Ω^-fmap n f
⊙Ω^-fmap-∘ O _ _ = idp
⊙Ω^-fmap-∘ (S n) g f = ap ⊙Ω-fmap (⊙Ω^-fmap-∘ n g f)
∙ ⊙Ω-fmap-∘ (⊙Ω^-fmap n g) (⊙Ω^-fmap n f)
⊙Ω^-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → ⊙Ω^-fmap n (⊙idf X) == ⊙idf _
⊙Ω^-fmap-idf O = idp
⊙Ω^-fmap-idf (S n) = ap ⊙Ω-fmap (⊙Ω^-fmap-idf n) ∙ ⊙Ω-fmap-idf
Ω^-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^-fmap n (⊙idf X) == idf _
Ω^-fmap-idf n = fst= $ ⊙Ω^-fmap-idf n
⊙Ω^'-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → ⊙Ω^'-fmap n (⊙idf X) == ⊙idf _
⊙Ω^'-fmap-idf O = idp
⊙Ω^'-fmap-idf (S n) = ap (⊙Ω^'-fmap n) ⊙Ω-fmap-idf ∙ ⊙Ω^'-fmap-idf n
Ω^'-fmap-idf : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^'-fmap n (⊙idf X) == idf _
Ω^'-fmap-idf n = fst= $ ⊙Ω^'-fmap-idf n
⊙Ω^-fmap-fmap2 : ∀ {i j k l} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(G : Z ⊙→ W) (F : (X ⊙× Y) ⊙→ Z)
→ ⊙Ω^-fmap n G ⊙∘ ⊙Ω^-fmap2 n F == ⊙Ω^-fmap2 n (G ⊙∘ F)
⊙Ω^-fmap-fmap2 O G F = idp
⊙Ω^-fmap-fmap2 (S n) G F = ⊙Ω-fmap-fmap2 (⊙Ω^-fmap n G) (⊙Ω^-fmap2 n F) ∙ ap ⊙Ω-fmap2 (⊙Ω^-fmap-fmap2 n G F)
Ω^-fmap-fmap2 : ∀ {i j k l} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l}
(G : Z ⊙→ W) (F : (X ⊙× Y) ⊙→ Z)
→ Ω^-fmap n G ∘ Ω^-fmap2 n F == Ω^-fmap2 n (G ⊙∘ F)
Ω^-fmap-fmap2 n G F = fst= $ ⊙Ω^-fmap-fmap2 n G F
⊙Ω^-fmap2-fst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ ⊙Ω^-fmap2 n {X} {Y} ⊙fst == ⊙fst
⊙Ω^-fmap2-fst O = idp
⊙Ω^-fmap2-fst (S n) = ap ⊙Ω-fmap2 (⊙Ω^-fmap2-fst n) ∙ ⊙Ω-fmap2-fst
Ω^-fmap2-fst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ Ω^-fmap2 n {X} {Y} ⊙fst == fst
Ω^-fmap2-fst n = fst= $ ⊙Ω^-fmap2-fst n
⊙Ω^-fmap2-snd : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ ⊙Ω^-fmap2 n {X} {Y} ⊙snd == ⊙snd
⊙Ω^-fmap2-snd O = idp
⊙Ω^-fmap2-snd (S n) = ap ⊙Ω-fmap2 (⊙Ω^-fmap2-snd n) ∙ ⊙Ω-fmap2-snd
Ω^-fmap2-snd : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ Ω^-fmap2 n {X} {Y} ⊙snd == snd
Ω^-fmap2-snd n = fst= $ ⊙Ω^-fmap2-snd n
⊙Ω^-fmap2-fmap : ∀ {i j k l m} (n : ℕ)
{X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}
(G : (U ⊙× V) ⊙→ Z) (F₁ : X ⊙→ U) (F₂ : Y ⊙→ V)
→ ⊙Ω^-fmap2 n G ⊙∘ ⊙×-fmap (⊙Ω^-fmap n F₁) (⊙Ω^-fmap n F₂) == ⊙Ω^-fmap2 n (G ⊙∘ ⊙×-fmap F₁ F₂)
⊙Ω^-fmap2-fmap O G F₁ F₂ = idp
⊙Ω^-fmap2-fmap (S n) G F₁ F₂ =
⊙Ω-fmap2-fmap (⊙Ω^-fmap2 n G) (⊙Ω^-fmap n F₁) (⊙Ω^-fmap n F₂) ∙ ap ⊙Ω-fmap2 (⊙Ω^-fmap2-fmap n G F₁ F₂)
Ω^-fmap2-fmap : ∀ {i j k l m} (n : ℕ)
{X : Ptd i} {Y : Ptd j} {U : Ptd k} {V : Ptd l} {Z : Ptd m}
(G : (U ⊙× V) ⊙→ Z) (F₁ : X ⊙→ U) (F₂ : Y ⊙→ V)
→ Ω^-fmap2 n G ∘ ×-fmap (Ω^-fmap n F₁) (Ω^-fmap n F₂) == Ω^-fmap2 n (G ⊙∘ ⊙×-fmap F₁ F₂)
Ω^-fmap2-fmap n G F₁ F₂ = fst= $ ⊙Ω^-fmap2-fmap n G F₁ F₂
⊙Ω^-fmap2-diag : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} (F : X ⊙× X ⊙→ Y)
→ ⊙Ω^-fmap2 n F ⊙∘ ⊙diag == ⊙Ω^-fmap n (F ⊙∘ ⊙diag)
⊙Ω^-fmap2-diag O F = idp
⊙Ω^-fmap2-diag (S n) F = ⊙Ω-fmap2-diag (⊙Ω^-fmap2 n F) ∙ ap ⊙Ω-fmap (⊙Ω^-fmap2-diag n F)
Ω^-fmap2-diag : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} (F : X ⊙× X ⊙→ Y)
→ Ω^-fmap2 n F ∘ diag == Ω^-fmap n (F ⊙∘ ⊙diag)
Ω^-fmap2-diag n F = fst= $ ⊙Ω^-fmap2-diag n F
{- for n ≥ 1, we have a group structure on the loop space -}
module _ {i} (n : ℕ) {X : Ptd i} where
Ω^S-! : Ω^ (S n) X → Ω^ (S n) X
Ω^S-! = Ω-!
Ω^S-∙ : Ω^ (S n) X → Ω^ (S n) X → Ω^ (S n) X
Ω^S-∙ = Ω-∙
module _ {i} where
Ω^'S-! : (n : ℕ) {X : Ptd i} → Ω^' (S n) X → Ω^' (S n) X
Ω^'S-! O = Ω-!
Ω^'S-! (S n) {X} = Ω^'S-! n {⊙Ω X}
Ω^'S-∙ : (n : ℕ) {X : Ptd i} → Ω^' (S n) X → Ω^' (S n) X → Ω^' (S n) X
Ω^'S-∙ O = Ω-∙
Ω^'S-∙ (S n) {X} = Ω^'S-∙ n {⊙Ω X}
idp^ : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^ n X
idp^ n {X} = pt (⊙Ω^ n X)
idp^' : ∀ {i} (n : ℕ) {X : Ptd i} → Ω^' n X
idp^' n {X} = pt (⊙Ω^' n X)
module _ {i} (n : ℕ) {X : Ptd i} where
{- Prove these as lemmas now
- so we don't have to deal with the n = O case later -}
Ω^S-∙-unit-l : (q : Ω^ (S n) X)
→ (Ω^S-∙ n (idp^ (S n)) q) == q
Ω^S-∙-unit-l _ = idp
Ω^S-∙-unit-r : (q : Ω^ (S n) X)
→ (Ω^S-∙ n q (idp^ (S n))) == q
Ω^S-∙-unit-r = ∙-unit-r
Ω^S-∙-assoc : (p q r : Ω^ (S n) X)
→ Ω^S-∙ n (Ω^S-∙ n p q) r == Ω^S-∙ n p (Ω^S-∙ n q r)
Ω^S-∙-assoc = ∙-assoc
Ω^S-!-inv-l : (p : Ω^ (S n) X)
→ Ω^S-∙ n (Ω^S-! n p) p == idp^ (S n)
Ω^S-!-inv-l = !-inv-l
Ω^S-!-inv-r : (p : Ω^ (S n) X)
→ Ω^S-∙ n p (Ω^S-! n p) == idp^ (S n)
Ω^S-!-inv-r = !-inv-r
module _ {i} where
Ω^'S-∙-unit-l : (n : ℕ) {X : Ptd i} (q : Ω^' (S n) X)
→ (Ω^'S-∙ n (idp^' (S n)) q) == q
Ω^'S-∙-unit-l O _ = idp
Ω^'S-∙-unit-l (S n) = Ω^'S-∙-unit-l n
Ω^'S-∙-unit-r : (n : ℕ) {X : Ptd i} (q : Ω^' (S n) X)
→ (Ω^'S-∙ n q (idp^' (S n))) == q
Ω^'S-∙-unit-r O = ∙-unit-r
Ω^'S-∙-unit-r (S n) = Ω^'S-∙-unit-r n
Ω^'S-∙-assoc : (n : ℕ) {X : Ptd i} (p q r : Ω^' (S n) X)
→ Ω^'S-∙ n (Ω^'S-∙ n p q) r == Ω^'S-∙ n p (Ω^'S-∙ n q r)
Ω^'S-∙-assoc O = ∙-assoc
Ω^'S-∙-assoc (S n) = Ω^'S-∙-assoc n
Ω^'S-!-inv-l : (n : ℕ) {X : Ptd i} (p : Ω^' (S n) X)
→ Ω^'S-∙ n (Ω^'S-! n p) p == idp^' (S n)
Ω^'S-!-inv-l O = !-inv-l
Ω^'S-!-inv-l (S n) = Ω^'S-!-inv-l n
Ω^'S-!-inv-r : (n : ℕ) {X : Ptd i} (p : Ω^' (S n) X)
→ Ω^'S-∙ n p (Ω^'S-! n p) == idp^' (S n)
Ω^'S-!-inv-r O = !-inv-r
Ω^'S-!-inv-r (S n) = Ω^'S-!-inv-r n
module _ where
Ω-fmap-∙ : ∀ {i j} {X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p q : Ω X)
→ Ω-fmap F (p ∙ q) == Ω-fmap F p ∙ Ω-fmap F q
Ω-fmap-∙ (f , idp) p q = ap-∙ f p q
Ω^S-fmap-∙ : ∀ {i j} (n : ℕ)
{X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p q : Ω^ (S n) X)
→ Ω^-fmap (S n) F (Ω^S-∙ n p q)
== Ω^S-∙ n (Ω^-fmap (S n) F p) (Ω^-fmap (S n) F q)
Ω^S-fmap-∙ n F = Ω-fmap-∙ (⊙Ω^-fmap n F)
Ω^'S-fmap-∙ : ∀ {i j} (n : ℕ)
{X : Ptd i} {Y : Ptd j} (F : X ⊙→ Y) (p q : Ω^' (S n) X)
→ Ω^'-fmap (S n) F (Ω^'S-∙ n p q)
== Ω^'S-∙ n (Ω^'-fmap (S n) F p) (Ω^'-fmap (S n) F q)
Ω^'S-fmap-∙ O = Ω-fmap-∙
Ω^'S-fmap-∙ (S n) F = Ω^'S-fmap-∙ n (⊙Ω-fmap F)
{- [Ω^] preserves (pointed) equivalences -}
module _ {i j} {X : Ptd i} {Y : Ptd j} where
Ω^-isemap : (n : ℕ) (F : X ⊙→ Y) (e : is-equiv (fst F))
→ is-equiv (Ω^-fmap n F)
Ω^-isemap O F e = e
Ω^-isemap (S n) F e = Ω-isemap (⊙Ω^-fmap n F) (Ω^-isemap n F e)
⊙Ω^-isemap = Ω^-isemap
Ω^-emap : (n : ℕ) → X ⊙≃ Y → Ω^ n X ≃ Ω^ n Y
Ω^-emap n (F , e) = Ω^-fmap n F , Ω^-isemap n F e
⊙Ω^-emap : (n : ℕ) → X ⊙≃ Y → ⊙Ω^ n X ⊙≃ ⊙Ω^ n Y
⊙Ω^-emap n (F , e) = ⊙Ω^-fmap n F , ⊙Ω^-isemap n F e
⊙Ω^-csemap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}
{hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}
→ ⊙CommSquareEquiv f g hX hY
→ ⊙CommSquareEquiv (⊙Ω^-fmap n f) (⊙Ω^-fmap n g) (⊙Ω^-fmap n hX) (⊙Ω^-fmap n hY)
⊙Ω^-csemap n {hX = hX} {hY} (cs , hX-ise , hY-ise) = ⊙Ω^-csmap n cs , Ω^-isemap n hX hX-ise , Ω^-isemap n hY hY-ise
{- [Ω^'] preserves (pointed) equivalences too -}
module _ {i j} where
Ω^'-isemap : {X : Ptd i} {Y : Ptd j} (n : ℕ) (F : X ⊙→ Y) (e : is-equiv (fst F))
→ is-equiv (Ω^'-fmap n F)
Ω^'-isemap O F e = e
Ω^'-isemap (S n) F e = Ω^'-isemap n (⊙Ω-fmap F) (Ω-isemap F e)
⊙Ω^'-isemap = Ω^'-isemap
Ω^'-emap : {X : Ptd i} {Y : Ptd j} (n : ℕ) → X ⊙≃ Y → Ω^' n X ≃ Ω^' n Y
Ω^'-emap n (F , e) = Ω^'-fmap n F , Ω^'-isemap n F e
⊙Ω^'-emap : {X : Ptd i} {Y : Ptd j} (n : ℕ) → X ⊙≃ Y → ⊙Ω^' n X ⊙≃ ⊙Ω^' n Y
⊙Ω^'-emap n (F , e) = ⊙Ω^'-fmap n F , ⊙Ω^'-isemap n F e
⊙Ω^'-csemap : ∀ {i₀ i₁ j₀ j₁} (n : ℕ) {X₀ : Ptd i₀} {X₁ : Ptd i₁}
{Y₀ : Ptd j₀} {Y₁ : Ptd j₁} {f : X₀ ⊙→ Y₀} {g : X₁ ⊙→ Y₁}
{hX : X₀ ⊙→ X₁} {hY : Y₀ ⊙→ Y₁}
→ ⊙CommSquareEquiv f g hX hY
→ ⊙CommSquareEquiv (⊙Ω^'-fmap n f) (⊙Ω^'-fmap n g) (⊙Ω^'-fmap n hX) (⊙Ω^'-fmap n hY)
⊙Ω^'-csemap n {hX = hX} {hY} (cs , hX-ise , hY-ise) = ⊙Ω^'-csmap n cs , Ω^'-isemap n hX hX-ise , Ω^'-isemap n hY hY-ise
Ω^-level : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i)
→ (has-level (⟨ n ⟩₋₂ +2+ m) (de⊙ X) → has-level m (Ω^ n X))
Ω^-level m O X pX = pX
Ω^-level m (S n) X pX =
has-level-apply (Ω^-level (S m) n X
(transport (λ k → has-level k (de⊙ X)) (! (+2+-βr ⟨ n ⟩₋₂ m)) pX))
(idp^ n) (idp^ n)
{- As for the levels of [Ω^'], these special cases can avoid
trailing constants, and it seems we only need the following
two special cases. -}
Ω^'-is-set : ∀ {i} (n : ℕ) (X : Ptd i)
→ (has-level ⟨ n ⟩ (de⊙ X) → is-set (Ω^' n X))
Ω^'-is-set O X pX = pX
Ω^'-is-set (S n) X pX = Ω^'-is-set n (⊙Ω X) (has-level-apply pX (pt X) (pt X))
Ω^'-is-prop : ∀ {i} (n : ℕ) (X : Ptd i)
→ (has-level ⟨ n ⟩₋₁ (de⊙ X) → is-prop (Ω^' n X))
Ω^'-is-prop O X pX = pX
Ω^'-is-prop (S n) X pX = Ω^'-is-prop n (⊙Ω X) (has-level-apply pX (pt X) (pt X))
Ω^-conn : ∀ {i} (m : ℕ₋₂) (n : ℕ) (X : Ptd i)
→ (is-connected (⟨ n ⟩₋₂ +2+ m) (de⊙ X)) → is-connected m (Ω^ n X)
Ω^-conn m O X pX = pX
Ω^-conn m (S n) X pX =
path-conn $ Ω^-conn (S m) n X $
transport (λ k → is-connected k (de⊙ X)) (! (+2+-βr ⟨ n ⟩₋₂ m)) pX
{- Eckmann-Hilton argument -}
module _ {i} {X : Ptd i} where
Ω-fmap2-∙ : (α β : Ω^ 2 X) → ap2 _∙_ α β == Ω^S-∙ 1 α β
Ω-fmap2-∙ α β = ap2-out _∙_ α β ∙ ap2 _∙_ (lemma α) (ap-idf β)
where
lemma : ∀ {i} {A : Type i} {x y : A} {p q : x == y} (α : p == q)
→ ap (λ r → r ∙ idp) α == ∙-unit-r p ∙ α ∙' ! (∙-unit-r q)
lemma {p = idp} idp = idp
⊙Ω-fmap2-∙ : ⊙Ω-fmap2 (⊙Ω-∙ {X = X}) == ⊙Ω-∙
⊙Ω-fmap2-∙ = ⊙λ=' (uncurry Ω-fmap2-∙) idp
Ω^2-∙-comm : (α β : Ω^ 2 X) → Ω^S-∙ 1 α β == Ω^S-∙ 1 β α
Ω^2-∙-comm α β = ! (⋆2=Ω^S-∙ α β) ∙ ⋆2=⋆'2 α β ∙ ⋆'2=Ω^S-∙ α β
where
⋆2=Ω^S-∙ : (α β : Ω^ 2 X) → α ⋆2 β == Ω^S-∙ 1 α β
⋆2=Ω^S-∙ α β = ap (λ π → π ∙ β) (∙-unit-r α)
⋆'2=Ω^S-∙ : (α β : Ω^ 2 X) → α ⋆'2 β == Ω^S-∙ 1 β α
⋆'2=Ω^S-∙ α β = ap (λ π → β ∙ π) (∙-unit-r α)
{- NOT USED and DUPLICATE of [Ω^S-Trunc-preiso] in lib.groups.HomotopyGroup.
XXX Should be an equivalence.
{- Pushing truncation through loop space -}
module _ {i} where
Trunc-Ω^-conv : (m : ℕ₋₂) (n : ℕ) (X : Ptd i)
→ ⊙Trunc m (⊙Ω^ n X) == ⊙Ω^ n (⊙Trunc (⟨ n ⟩₋₂ +2+ m) X)
Trunc-Ω^-conv m O X = idp
Trunc-Ω^-conv m (S n) X =
⊙Trunc m (⊙Ω^ (S n) X)
=⟨ ! (pair= (Trunc=-path [ _ ] [ _ ]) (↓-idf-ua-in _ idp)) ⟩
⊙Ω (⊙Trunc (S m) (⊙Ω^ n X))
=⟨ ap ⊙Ω (Trunc-Ω^-conv (S m) n X) ⟩
⊙Ω^ (S n) (⊙Trunc (⟨ n ⟩₋₂ +2+ S m) X)
=⟨ +2+-βr ⟨ n ⟩₋₂ m |in-ctx (λ k → ⊙Ω^ (S n) (⊙Trunc k X)) ⟩
⊙Ω^ (S n) (⊙Trunc (S ⟨ n ⟩₋₂ +2+ m) X) =∎
Ω-Trunc-econv : (m : ℕ₋₂) (X : Ptd i)
→ Ω (⊙Trunc (S m) X) ≃ Trunc m (Ω X)
Ω-Trunc-econv m X = Trunc=-equiv [ pt X ] [ pt X ]
-}
{- Our definition of [Ω^] builds up loops from the outside,
- but this is equivalent to building up from the inside -}
module _ {i} where
⊙Ω^-Ω-split : (n : ℕ) (X : Ptd i)
→ (⊙Ω^ (S n) X ⊙→ ⊙Ω^ n (⊙Ω X))
⊙Ω^-Ω-split O _ = (idf _ , idp)
⊙Ω^-Ω-split (S n) X = ⊙Ω-fmap (⊙Ω^-Ω-split n X)
Ω^-Ω-split : (n : ℕ) (X : Ptd i)
→ (Ω^ (S n) X → Ω^ n (⊙Ω X))
Ω^-Ω-split n X = fst (⊙Ω^-Ω-split n X)
Ω^S-Ω-split-∙ : (n : ℕ)
(X : Ptd i) (p q : Ω^ (S (S n)) X)
→ Ω^-Ω-split (S n) X (Ω^S-∙ (S n) p q)
== Ω^S-∙ n (Ω^-Ω-split (S n) X p) (Ω^-Ω-split (S n) X q)
Ω^S-Ω-split-∙ n X p q =
Ω^S-fmap-∙ 0 (⊙Ω^-Ω-split n X) p q
Ω^-Ω-split-is-equiv : (n : ℕ) (X : Ptd i)
→ is-equiv (Ω^-Ω-split n X)
Ω^-Ω-split-is-equiv O X = is-eq (idf _) (idf _) (λ _ → idp) (λ _ → idp)
Ω^-Ω-split-is-equiv (S n) X =
⊙Ω^-isemap 1 (⊙Ω^-Ω-split n X) (Ω^-Ω-split-is-equiv n X)
Ω^-Ω-split-equiv : (n : ℕ) (X : Ptd i) → Ω^ (S n) X ≃ Ω^ n (⊙Ω X)
Ω^-Ω-split-equiv n X = _ , Ω^-Ω-split-is-equiv n X
module _ {i j} (X : Ptd i) (Y : Ptd j) where
Ω-× : Ω (X ⊙× Y) ≃ Ω X × Ω Y
Ω-× = equiv
(λ p → fst×= p , snd×= p)
(λ p → pair×= (fst p) (snd p))
(λ p → pair×= (fst×=-β (fst p) (snd p)) (snd×=-β (fst p) (snd p)))
(! ∘ pair×=-η)
⊙Ω-× : ⊙Ω (X ⊙× Y) ⊙≃ ⊙Ω X ⊙× ⊙Ω Y
⊙Ω-× = ≃-to-⊙≃ Ω-× idp
Ω-×-∙ : ∀ (p q : Ω (X ⊙× Y))
→ –> Ω-× (p ∙ q) == (fst (–> Ω-× p) ∙ fst (–> Ω-× q) , snd (–> Ω-× p) ∙ snd (–> Ω-× q))
Ω-×-∙ p q = pair×= (Ω-fmap-∙ ⊙fst p q) (Ω-fmap-∙ ⊙snd p q)
module _ {i j} where
⊙Ω^-× : ∀ (n : ℕ) (X : Ptd i) (Y : Ptd j)
→ ⊙Ω^ n (X ⊙× Y) ⊙≃ ⊙Ω^ n X ⊙× ⊙Ω^ n Y
⊙Ω^-× O _ _ = ⊙ide _
⊙Ω^-× (S n) X Y = ⊙Ω-× (⊙Ω^ n X) (⊙Ω^ n Y) ⊙∘e ⊙Ω-emap (⊙Ω^-× n X Y)
⊙Ω^'-× : ∀ (n : ℕ) (X : Ptd i) (Y : Ptd j)
→ ⊙Ω^' n (X ⊙× Y) ⊙≃ ⊙Ω^' n X ⊙× ⊙Ω^' n Y
⊙Ω^'-× O _ _ = ⊙ide _
⊙Ω^'-× (S n) X Y = ⊙Ω^'-× n (⊙Ω X) (⊙Ω Y) ⊙∘e ⊙Ω^'-emap n (⊙Ω-× X Y)
| {
"alphanum_fraction": 0.4348333687,
"avg_line_length": 34.0144404332,
"ext": "agda",
"hexsha": "e00a140c46c58d29d367c2faceb7db48143cacef",
"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": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/LoopSpace.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"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": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/LoopSpace.agda",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/LoopSpace.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11870,
"size": 18844
} |
-- Step-indexed logical relations based on relational big-step semantics
-- for ILC-based incremental computation.
-- Goal: prove the fundamental lemma for a ternary logical relation (change
-- validity) across t1, dt and t2. The fundamnetal lemma relates t, derive t and
-- t. That is, we relate a term evaluated relative to an original environment,
-- its derivative evaluated relative to a valid environment change, and the
-- original term evaluated relative to an updated environment.
--
-- Missing goal: here ⊕ isn't defined and wouldn't yet agree with change
-- validity.
--
-- This development is strongly inspired by "Imperative self-adjusting
-- computation" (ISAC below), POPL'08, including the choice of using ANF syntax
-- to simplify some step-indexing proofs.
--
-- In fact, this development is typed, hence some parts of the model are closer
-- to Ahmed (ESOP 2006), "Step-Indexed Syntactic Logical Relations for Recursive
-- and Quantified Types". But for many relevant aspects, the two papers are
-- very similar. In fact, I first defined similar logical relations
-- without types, but they require a trickier recursion scheme for well-founded
-- recursion, and I failed to do any proof in that setting.
--
-- The original inspiration came from Dargaye and Leroy (2010), "A verified
-- framework for higher-order uncurrying optimizations", but we ended up looking
-- at their source.
--
-- The main insight from the ISAC paper missing from the other one is how to
-- step-index a big-step semantics correctly: just ensure that the steps in the
-- big-step semantics agree with the ones in the small-step semantics. *Then*
-- everything just works with big-step semantics. Quite a few other details are
-- fiddly, but those are the same in small-step semantics.
--
-- The crucial novelty here is that we relate two computations on different
-- inputs. So we only conclude their results are related if both terminate; the
-- relation for computations does not prove that if the first computation
-- terminates, then the second terminates as well.
--
-- Instead, e1, de and e2 are related at k steps if, whenever e1 terminates in j
-- < k steps and e2 terminates with any step count, then de terminates (with any
-- step count) and their results are related at k - j steps.
--
-- Even when e1 terminates in j steps implies that e2 terminates, e2 gets no
-- bound. Similarly, we do not bound in how many steps de terminates, since on
-- big inputs it might take long.
module Thesis.SIRelBigStep.README where
-- Base language
import Thesis.SIRelBigStep.Lang
-- Which comprises:
import Thesis.SIRelBigStep.Types
import Thesis.SIRelBigStep.Syntax
-- Denotational semantics:
import Thesis.SIRelBigStep.DenSem
-- Big-step operations semantics:
import Thesis.SIRelBigStep.OpSem
-- Show these two semantics are equivalent:
import Thesis.SIRelBigStep.SemEquiv
-- It follows that the big-step semantics is deterministic.
-- To show that the big-step semantics is total, give a proof of (CBV) strong
-- normalization for this calculus, using a unary logical relation.
-- This is just TAPL Ch. 12, adapted to our environment-based big-step
-- semantics.
import Thesis.SIRelBigStep.Normalization
-- Change language
import Thesis.SIRelBigStep.DLang
-- Which comprises:
import Thesis.SIRelBigStep.DSyntax
-- The operational semantics also defines ⊕:
import Thesis.SIRelBigStep.DOpSem
-- Differentiation:
import Thesis.SIRelBigStep.DLangDerive
-- Small extra arithmetic lemmas for step-indexes.
import Thesis.SIRelBigStep.ArithExtra
-- Step-indexed logical relations for validity, their monotonicity and agreement with ⊕
import Thesis.SIRelBigStep.IlcSILR
-- Prove the fundamental property
import Thesis.SIRelBigStep.FundamentalProperty
-- Conclude our thesis
import Thesis.SIRelBigStep.DeriveCorrect
| {
"alphanum_fraction": 0.7790026247,
"avg_line_length": 43.2954545455,
"ext": "agda",
"hexsha": "61f802b40e49d82271f16a05804f30e71d2d3cdc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Thesis/SIRelBigStep/README.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Thesis/SIRelBigStep/README.agda",
"max_line_length": 87,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Thesis/SIRelBigStep/README.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 894,
"size": 3810
} |
module PiFrac.Eval where
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Data.List as L hiding (_∷_)
open import Data.Maybe
open import Relation.Binary.Core
open import Relation.Binary
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Function using (_∘_)
open import PiFrac.Syntax
open import PiFrac.Opsem
open import PiFrac.NoRepeat
-- Stuck states must be either of the form [ c ∣ v ∣ ☐ ] or ⊠
Stuck : ∀ {st} → is-stuck st
→ (Σ[ A ∈ 𝕌 ] Σ[ B ∈ 𝕌 ] Σ[ c ∈ A ↔ B ] Σ[ v ∈ ⟦ B ⟧ ] st ≡ [ c ∣ v ∣ ☐ ]) ⊎ st ≡ ⊠
Stuck {⟨ uniti₊l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ unite₊l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ swap₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocl₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocr₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ unite⋆l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ uniti⋆l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ swap⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocl⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocr⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ dist ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ factor ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ id↔ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₂))
Stuck {⟨ ηₓ v ∣ tt ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦η))
Stuck {⟨ εₓ v ∣ v' , ↻ ∣ κ ⟩} stuck with v ≟ v'
... | yes eq = ⊥-elim (stuck (_ , ↦ε₁ {eq = eq}))
... | no neq = ⊥-elim (stuck (_ , ↦ε₂ {neq = neq}))
Stuck {⟨ c₁ ⨾ c₂ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₃))
Stuck {⟨ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₄))
Stuck {⟨ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₅))
Stuck {⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₆))
Stuck {[ c ∣ v ∣ ☐ ]} stuck = inj₁ (_ , _ , _ , _ , refl)
Stuck {[ c ∣ v ∣ ☐⨾ c₂ • κ ]} stuck = ⊥-elim (stuck (_ , ↦₇))
Stuck {[ c ∣ v ∣ c₁ ⨾☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₀))
Stuck {[ c ∣ v ∣ ☐⊕ c₂ • κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₁))
Stuck {[ c ∣ v ∣ c₁ ⊕☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₂))
Stuck {[ c ∣ v ∣ ☐⊗[ c₂ , y ]• κ ]} stuck = ⊥-elim (stuck (_ , ↦₈))
Stuck {[ c ∣ v ∣ [ c₁ , x ]⊗☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₉))
Stuck {⊠} stuck = inj₂ refl
-- Auxiliary function for forward evaluator
ev : ∀ {A B κ} → (c : A ↔ B) (v : ⟦ A ⟧)
→ Σ[ v' ∈ ⟦ B ⟧ ] ⟨ c ∣ v ∣ κ ⟩ ↦* [ c ∣ v' ∣ κ ]
⊎ ⟨ c ∣ v ∣ κ ⟩ ↦* ⊠
ev uniti₊l v = inj₁ ((inj₂ v) , ↦₁ ∷ ◾)
ev unite₊l (inj₂ y) = inj₁ (y , ↦₁ ∷ ◾)
ev swap₊ (inj₁ v) = inj₁ (inj₂ v , (↦₁ ∷ ◾))
ev swap₊ (inj₂ v) = inj₁ (inj₁ v , (↦₁ ∷ ◾))
ev assocl₊ (inj₁ v) = inj₁ (inj₁ (inj₁ v) , (↦₁ ∷ ◾))
ev assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₁ (inj₂ v) , (↦₁ ∷ ◾))
ev assocl₊ (inj₂ (inj₂ v)) = inj₁ (inj₂ v , (↦₁ ∷ ◾))
ev assocr₊ (inj₁ (inj₁ v)) = inj₁ (inj₁ v , (↦₁ ∷ ◾))
ev assocr₊ (inj₁ (inj₂ v)) = inj₁ (inj₂ (inj₁ v) , (↦₁ ∷ ◾))
ev assocr₊ (inj₂ v) = inj₁ (inj₂ (inj₂ v) , (↦₁ ∷ ◾))
ev unite⋆l (tt , v) = inj₁ (v , (↦₁ ∷ ◾))
ev uniti⋆l v = inj₁ ((tt , v) , (↦₁ ∷ ◾))
ev swap⋆ (x , y) = inj₁ ((y , x) , (↦₁ ∷ ◾))
ev assocl⋆ (x , (y , z)) = inj₁ (((x , y) , z) , (↦₁ ∷ ◾))
ev assocr⋆ ((x , y) , z) = inj₁ ((x , (y , z)) , (↦₁ ∷ ◾))
ev dist (inj₁ x , z) = inj₁ (inj₁ (x , z) , (↦₁ ∷ ◾))
ev dist (inj₂ y , z) = inj₁ (inj₂ (y , z) , (↦₁ ∷ ◾))
ev factor (inj₁ (x , z)) = inj₁ ((inj₁ x , z) , (↦₁ ∷ ◾))
ev factor (inj₂ (y , z)) = inj₁ ((inj₂ y , z) , (↦₁ ∷ ◾))
ev id↔ v = inj₁ (v , (↦₂ ∷ ◾))
ev {κ = κ} (c₁ ⨾ c₂) v₁ with ev {κ = ☐⨾ c₂ • κ} c₁ v₁
... | inj₁ (v₂ , c₁↦*) with ev {κ = c₁ ⨾☐• κ} c₂ v₂
... | inj₁ (v₃ , c₂↦*) = inj₁ (v₃ , ((↦₃ ∷ c₁↦* ++↦ (↦₇ ∷ ◾)) ++↦ (c₂↦* ++↦ (↦₁₀ ∷ ◾))))
... | inj₂ c₂↦* = inj₂ ((↦₃ ∷ c₁↦* ++↦ (↦₇ ∷ ◾)) ++↦ c₂↦*)
ev {κ = κ} (c₁ ⨾ c₂) v₁ | inj₂ c₁↦* = inj₂ (↦₃ ∷ c₁↦*)
ev {κ = κ} (c₁ ⊕ c₂) (inj₁ x) with ev {κ = ☐⊕ c₂ • κ} c₁ x
... | inj₁ (x' , c₁↦*) = inj₁ (inj₁ x' , ↦₄ ∷ c₁↦* ++↦ (↦₁₁ ∷ ◾))
... | inj₂ c₁↦* = inj₂ (↦₄ ∷ c₁↦*)
ev {κ = κ} (c₁ ⊕ c₂) (inj₂ y) with ev {κ = c₁ ⊕☐• κ} c₂ y
... | inj₁ (y' , c₂↦*) = inj₁ (inj₂ y' , ↦₅ ∷ c₂↦* ++↦ (↦₁₂ ∷ ◾))
... | inj₂ c₂↦* = inj₂ (↦₅ ∷ c₂↦*)
ev {κ = κ} (c₁ ⊗ c₂) (x , y) with ev {κ = ☐⊗[ c₂ , y ]• κ} c₁ x
... | inj₁ (x' , c₁↦*) with ev {κ = [ c₁ , x' ]⊗☐• κ} c₂ y
... | inj₁ (y' , c₂↦*) = inj₁ ((x' , y') , ((↦₆ ∷ c₁↦*) ++↦ ((↦₈ ∷ c₂↦*) ++↦ (↦₉ ∷ ◾))))
... | inj₂ c₂↦* = inj₂ ((↦₆ ∷ c₁↦*) ++↦ (↦₈ ∷ c₂↦*))
ev {κ = κ} (c₁ ⊗ c₂) (x , y) | inj₂ c₁↦* = inj₂ (↦₆ ∷ c₁↦*)
ev (ηₓ v) tt = inj₁ ((v , ↻) , (↦η ∷ ◾))
ev (εₓ v) (v' , ↻) with v ≟ v'
... | yes eq = inj₁ (tt , (↦ε₁ {eq = eq} ∷ ◾))
... | no neq = inj₂ (↦ε₂ {neq = neq} ∷ ◾)
-- Forward evaluator for PiFrac
eval : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → Maybe ⟦ B ⟧
eval c v = [ just ∘ proj₁ , (λ _ → nothing) ]′ (ev {κ = ☐} c v)
-- Forward evaluator which returns execution trace
evalₜᵣ : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → List State
evalₜᵣ c v = [ convert ∘ proj₂ , convert ]′ (ev {κ = ☐} c v)
where
convert : ∀ {st st'} → st ↦* st' → List State
convert (◾ {st}) = st L.∷ []
convert (_∷_ {st} r rs) = st L.∷ convert rs
-- Auxiliary function for backward evaluator
evᵣₑᵥ : ∀ {A B κ} → (c : A ↔ B) (v : ⟦ B ⟧)
→ Σ[ v' ∈ ⟦ A ⟧ ] [ c ∣ v ∣ κ ] ↦ᵣₑᵥ* ⟨ c ∣ v' ∣ κ ⟩
⊎ ∃[ A ] (∃[ v' ] (∃[ v'' ] (∃[ κ' ] (v' ≢ v'' × [ c ∣ v ∣ κ ] ↦ᵣₑᵥ* [ ηₓ {A} v' ∣ (v'' , ↻) ∣ κ' ]))))
evᵣₑᵥ uniti₊l (inj₂ v) = inj₁ (v , (↦₁ ᵣₑᵥ ∷ ◾))
evᵣₑᵥ unite₊l v = inj₁ ((inj₂ v) , (↦₁ ᵣₑᵥ ∷ ◾))
evᵣₑᵥ swap₊ (inj₁ x) = inj₁ (inj₂ x , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ swap₊ (inj₂ y) = inj₁ (inj₁ y , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl₊ (inj₁ (inj₁ x)) = inj₁ (inj₁ x , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl₊ (inj₁ (inj₂ y)) = inj₁ (inj₂ (inj₁ y) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl₊ (inj₂ z) = inj₁ (inj₂ (inj₂ z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr₊ (inj₁ x) = inj₁ (inj₁ (inj₁ x) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr₊ (inj₂ (inj₁ y)) = inj₁ (inj₁ (inj₂ y) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr₊ (inj₂ (inj₂ z)) = inj₁ (inj₂ z , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ unite⋆l v = inj₁ ((tt , v) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ uniti⋆l (tt , v) = inj₁ (v , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ swap⋆ (x , y) = inj₁ ((y , x) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl⋆ ((x , y) , z) = inj₁ ((x , (y , z)) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr⋆ (x , (y , z)) = inj₁ (((x , y) , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ dist (inj₁ (x , z)) = inj₁ ((inj₁ x , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ dist (inj₂ (y , z)) = inj₁ ((inj₂ y , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ factor (inj₁ x , z) = inj₁ (inj₁ (x , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ factor (inj₂ y , z) = inj₁ (inj₂ (y , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ id↔ v = inj₁ (v , (↦₂ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ {κ = κ} (c₁ ⨾ c₂) v₃ with evᵣₑᵥ {κ = c₁ ⨾☐• κ} c₂ v₃
... | inj₁ (v₂ , rs) with evᵣₑᵥ {κ = ☐⨾ c₂ • κ} c₁ v₂
... | inj₁ (v₁ , rs') = inj₁ (v₁ , ((↦₁₀ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₇ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ (rs' ++↦ᵣₑᵥ ((↦₃ ᵣₑᵥ) ∷ ◾)))
... | inj₂ (_ , _ , _ , _ , neq , rs') = inj₂ (_ , _ , _ , _ , neq , (((↦₁₀ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₇ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ rs'))
evᵣₑᵥ (c₁ ⨾ c₂) v₃ | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (((↦₁₀ ᵣₑᵥ) ∷ ◾) ++↦ᵣₑᵥ rs))
evᵣₑᵥ {κ = κ} (c₁ ⊕ c₂) (inj₁ x) with evᵣₑᵥ {κ = ☐⊕ c₂ • κ} c₁ x
... | inj₁ (x' , rs) = inj₁ (inj₁ x' , (↦₁₁ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₄ ᵣₑᵥ) ∷ ◾)))
... | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (↦₁₁ ᵣₑᵥ) ∷ rs)
evᵣₑᵥ {κ = κ} (c₁ ⊕ c₂) (inj₂ y) with evᵣₑᵥ {κ = c₁ ⊕☐• κ} c₂ y
... | inj₁ (y' , rs) = inj₁ (inj₂ y' , (↦₁₂ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₅ ᵣₑᵥ) ∷ ◾)))
... | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (↦₁₂ ᵣₑᵥ) ∷ rs)
evᵣₑᵥ {κ = κ} (c₁ ⊗ c₂) (x , y) with evᵣₑᵥ {κ = [ c₁ , x ]⊗☐• κ} c₂ y
... | inj₁ (y' , rs) with evᵣₑᵥ {κ = ☐⊗[ c₂ , y' ]• κ} c₁ x
... | inj₁ (x' , rs') = inj₁ ((x' , y') , (((↦₉ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₈ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ (rs' ++↦ᵣₑᵥ ((↦₆ ᵣₑᵥ) ∷ ◾))))
... | inj₂ (_ , _ , _ , _ , neq , rs') = inj₂ (_ , _ , _ , _ , neq , (((↦₉ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₈ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ rs'))
evᵣₑᵥ (c₁ ⊗ c₂) (x , y) | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , ((↦₉ ᵣₑᵥ) ∷ rs))
evᵣₑᵥ (ηₓ v) (v' , ↻) with v ≟ v'
... | yes refl = inj₁ (tt , ((↦η ᵣₑᵥ) ∷ ◾))
... | no neq = inj₂ (_ , _ , _ , _ , neq , ◾)
evᵣₑᵥ (εₓ v) tt = inj₁ ((v , ↻) , ((↦ε₁ {eq = refl} ᵣₑᵥ) ∷ ◾))
-- Backward evaluator for Pi
evalᵣₑᵥ : ∀ {A B} → (c : A ↔ B) → ⟦ B ⟧ → Maybe ⟦ A ⟧
evalᵣₑᵥ c v = [ just ∘ proj₁ , (λ _ → nothing) ]′ (evᵣₑᵥ {κ = ☐} c v)
| {
"alphanum_fraction": 0.4382745472,
"avg_line_length": 54.1419354839,
"ext": "agda",
"hexsha": "04bafb94ba90c4debc8181e0de4d78b3e392577b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "PiFrac/Eval.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "PiFrac/Eval.agda",
"max_line_length": 123,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "PiFrac/Eval.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 5331,
"size": 8392
} |
{-# OPTIONS --no-termination-check --universe-polymorphism #-}
module PiF where
open import Level
open import Data.Empty
open import Data.Unit
open import Data.Bool
open import Data.Sum hiding (map)
open import Data.Product hiding (map)
open import Relation.Binary.PropositionalEquality hiding (sym; [_])
open import Singleton
infixr 30 _⟷_
infixr 30 _⟺_
infixr 20 _◎_
------------------------------------------------------------------------------
-- A universe of our value types
mutual
data BF : Set zero where
ZEROF : BF
ONEF : BF
PLUSF : BF → BF → BF
TIMESF : BF → BF → BF
RECIP : BF → BF
--data VF : Set where
-- unitF :
-- data hasType :
-- normalize : (b : BF) → (hasType v b) → normalform v b
-- fractional types are un-interpreted
data Reciprocal (A : Set) : Set where
rec : (b : A) → ((x : Singleton b) → ⊤) → Reciprocal A
data Recip (A : Set) : Set where
recip : (a : A) → Recip A
⟦_⟧F : BF → Set zero
⟦ ZEROF ⟧F = ⊥
⟦ ONEF ⟧F = ⊤
⟦ PLUSF b1 b2 ⟧F = ⟦ b1 ⟧F ⊎ ⟦ b2 ⟧F
⟦ TIMESF b1 b2 ⟧F = ⟦ b1 ⟧F × ⟦ b2 ⟧F
⟦ RECIP b ⟧F = -- Σ ⟦ b ⟧F (λ v → ((x : Singleton v) → ⊤))
Reciprocal ⟦ b ⟧F
------------------------------------------------------------------------------
-- Primitive isomorphisms
data _⟷_ : BF → BF → Set where
-- (+,0) commutative monoid
unite₊ : { b : BF } → PLUSF ZEROF b ⟷ b
uniti₊ : { b : BF } → b ⟷ PLUSF ZEROF b
swap₊ : { b₁ b₂ : BF } → PLUSF b₁ b₂ ⟷ PLUSF b₂ b₁
assocl₊ : { b₁ b₂ b₃ : BF } → PLUSF b₁ (PLUSF b₂ b₃) ⟷ PLUSF (PLUSF b₁ b₂) b₃
assocr₊ : { b₁ b₂ b₃ : BF } → PLUSF (PLUSF b₁ b₂) b₃ ⟷ PLUSF b₁ (PLUSF b₂ b₃)
-- (*,1) commutative monoid
unite⋆ : { b : BF } → TIMESF ONEF b ⟷ b
uniti⋆ : { b : BF } → b ⟷ TIMESF ONEF b
swap⋆ : { b₁ b₂ : BF } → TIMESF b₁ b₂ ⟷ TIMESF b₂ b₁
assocl⋆ : { b₁ b₂ b₃ : BF } → TIMESF b₁ (TIMESF b₂ b₃) ⟷ TIMESF (TIMESF b₁ b₂) b₃
assocr⋆ : { b₁ b₂ b₃ : BF } → TIMESF (TIMESF b₁ b₂) b₃ ⟷ TIMESF b₁ (TIMESF b₂ b₃)
-- * distributes over +
dist : { b₁ b₂ b₃ : BF } →
TIMESF (PLUSF b₁ b₂) b₃ ⟷ PLUSF (TIMESF b₁ b₃) (TIMESF b₂ b₃)
factor : { b₁ b₂ b₃ : BF } →
PLUSF (TIMESF b₁ b₃) (TIMESF b₂ b₃) ⟷ TIMESF (PLUSF b₁ b₂) b₃
-- id
id⟷ : { b : BF } → b ⟷ b
adjointP : { b₁ b₂ : BF } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁)
adjointP unite₊ = uniti₊
adjointP uniti₊ = unite₊
adjointP swap₊ = swap₊
adjointP assocl₊ = assocr₊
adjointP assocr₊ = assocl₊
adjointP unite⋆ = uniti⋆
adjointP uniti⋆ = unite⋆
adjointP swap⋆ = swap⋆
adjointP assocl⋆ = assocr⋆
adjointP assocr⋆ = assocl⋆
adjointP dist = factor
adjointP factor = dist
adjointP id⟷ = id⟷
evalP : { b₁ b₂ : BF } → (b₁ ⟷ b₂) → ⟦ b₁ ⟧F → ⟦ b₂ ⟧F
evalP unite₊ (inj₁ ())
evalP unite₊ (inj₂ v) = v
evalP uniti₊ v = inj₂ v
evalP swap₊ (inj₁ v) = inj₂ v
evalP swap₊ (inj₂ v) = inj₁ v
evalP assocl₊ (inj₁ v) = inj₁ (inj₁ v)
evalP assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
evalP assocl₊ (inj₂ (inj₂ v)) = inj₂ v
evalP assocr₊ (inj₁ (inj₁ v)) = inj₁ v
evalP assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
evalP assocr₊ (inj₂ v) = inj₂ (inj₂ v)
evalP unite⋆ (tt , v) = v
evalP uniti⋆ v = (tt , v)
evalP swap⋆ (v₁ , v₂) = (v₂ , v₁)
evalP assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
evalP assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
evalP dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
evalP dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
evalP factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
evalP factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
evalP id⟷ v = v
-- normalize values in BF to x * 1/y and then decide equality of normalized values
-- _≡B_ {b₁ = ONEF} {b₂ = ONEF} tt tt = true
--_≡B_ {b₁ = TIMESF d c} {b₂ = TIMESF c d} (v₁ , v₃) (v₄ , v₂) =
-- _≡B_ {b₁ = d} {b₂ = d} v₁ v₂ ∧ _≡B_ {b₁ = c} {b₂ = c} v₃ v₄
-- zero??
-- Backwards evaluator
bevalP : { b₁ b₂ : BF } → (b₁ ⟷ b₂) → ⟦ b₂ ⟧F → ⟦ b₁ ⟧F
bevalP c v = evalP (adjointP c) v
------------------------------------------------------------------------------
-- Closure combinators
data _⟺_ : BF → BF → Set where
iso : { b₁ b₂ : BF } → (b₁ ⟷ b₂) → (b₁ ⟺ b₂)
sym : { b₁ b₂ : BF } → (b₁ ⟺ b₂) → (b₂ ⟺ b₁)
_◎_ : { b₁ b₂ b₃ : BF } → (b₁ ⟺ b₂) → (b₂ ⟺ b₃) → (b₁ ⟺ b₃)
_⊕_ : { b₁ b₂ b₃ b₄ : BF } →
(b₁ ⟺ b₃) → (b₂ ⟺ b₄) → (PLUSF b₁ b₂ ⟺ PLUSF b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : BF } →
(b₁ ⟺ b₃) → (b₂ ⟺ b₄) → (TIMESF b₁ b₂ ⟺ TIMESF b₃ b₄)
refe⋆ : { b : BF } → RECIP (RECIP b) ⟺ b
refi⋆ : { b : BF } → b ⟺ RECIP (RECIP b)
rile⋆ : { b : BF } → TIMESF b (TIMESF b (RECIP b)) ⟺ b
rili⋆ : { b : BF } → b ⟺ TIMESF b (TIMESF b (RECIP b))
--
adjoint : { b₁ b₂ : BF } → (b₁ ⟺ b₂) → (b₂ ⟺ b₁)
adjoint (iso c) = iso (adjointP c)
adjoint (sym c) = c
adjoint (c₁ ◎ c₂) = adjoint c₂ ◎ adjoint c₁
adjoint (c₁ ⊕ c₂) = adjoint c₁ ⊕ adjoint c₂
adjoint (c₁ ⊗ c₂) = adjoint c₁ ⊗ adjoint c₂
adjoint refe⋆ = refi⋆
adjoint refi⋆ = refe⋆
adjoint rile⋆ = rili⋆
adjoint rili⋆ = rile⋆
--
-- (Context a b c d) represents a combinator (c <-> d) with a hole
-- requiring something of type (a <-> b). When we use these contexts,
-- it is always the case that the (c <-> a) part of the computation
-- has ALREADY been done and that we are about to evaluate (a <-> b)
-- using a given 'a'. The continuation takes the output 'b' and
-- produces a 'd'.
data Context : BF → BF → BF → BF → Set where
emptyC : {a b : BF} → Context a b a b
seqC₁ : {a b c i o : BF} → (b ⟺ c) → Context a c i o → Context a b i o
seqC₂ : {a b c i o : BF} → (a ⟺ b) → Context a c i o → Context b c i o
leftC : {a b c d i o : BF} →
(c ⟺ d) → Context (PLUSF a c) (PLUSF b d) i o → Context a b i o
rightC : {a b c d i o : BF} →
(a ⟺ b) → Context (PLUSF a c) (PLUSF b d) i o → Context c d i o
-- the (i <-> a) part of the computation is completely done; so we must store
-- the value of type [[ c ]] as part of the context
fstC : {a b c d i o : BF} →
⟦ c ⟧F → (c ⟺ d) → Context (TIMESF a c) (TIMESF b d) i o → Context a b i o
-- the (i <-> c) part of the computation and the (a <-> b) part of
-- the computation are completely done; so we must store the value
-- of type [[ b ]] as part of the context
sndC : {a b c d i o : BF} →
(a ⟺ b) → ⟦ b ⟧F → Context (TIMESF a c) (TIMESF b d) i o → Context c d i o
-- Evaluation
mutual
-- The (c <-> a) part of the computation has been done.
-- We have an 'a' and we are about to do the (a <-> b) computation.
-- We get a 'b' and examine the context to get the 'd'
eval_c : { a b c : BF } → (a ⟺ b) → ⟦ a ⟧F → Context a b c c → ⟦ c ⟧F
eval_c (iso f) v C = eval_k (iso f) (evalP f v) C
eval_c (sym c) v C = eval_c (adjoint c) v C
eval_c (f ◎ g) v C = eval_c f v (seqC₁ g C)
eval_c (f ⊕ g) (inj₁ v) C = eval_c f v (leftC g C)
eval_c (f ⊕ g) (inj₂ v) C = eval_c g v (rightC f C)
eval_c (f ⊗ g) (v₁ , v₂) C = eval_c f v₁ (fstC v₂ g C)
eval_c refe⋆ (rec (rec v _) _) C = eval_k refe⋆ v C
eval_c refi⋆ v C = eval_k refi⋆ (rec (rec v (λ x → tt)) ff) C
where ff = λ x → tt
eval_c rile⋆ (v₁ , (v₂ , rec v₃ _)) C = eval_k rile⋆ v₁ C
eval_c rili⋆ v C = eval_k rili⋆ (v , (v , {!!})) C
-- The (c <-> a) part of the computation has been done.
-- The (a <-> b) part of the computation has been done.
-- We need to examine the context to get the 'd'.
-- We rebuild the combinator on the way out.
eval_k : { a b c : BF } → (a ⟺ b) → ⟦ b ⟧F → Context a b c c → ⟦ c ⟧F
eval_k f v emptyC = v
eval_k f v (seqC₁ g C) = eval_c g v (seqC₂ f C)
eval_k g v (seqC₂ f C) = eval_k (f ◎ g) v C
eval_k f v (leftC g C) = eval_k (f ⊕ g) (inj₁ v) C
eval_k g v (rightC f C) = eval_k (f ⊕ g) (inj₂ v) C
eval_k f v₁ (fstC v₂ g C) = eval_c g v₂ (sndC f v₁ C)
eval_k g v₂ (sndC f v₁ C) = eval_k (f ⊗ g) (v₁ , v₂) C
-- Backwards evaluator
-- The (d <-> b) part of the computation has been done.
-- We have a 'b' and we are about to do the (a <-> b) computation backwards.
-- We get an 'a' and examine the context to get the 'c'
beval_c : { a b c : BF } → (a ⟺ b) → ⟦ b ⟧F → Context a b c c → ⟦ c ⟧F
beval_c (iso f) v C = beval_k (iso f) (bevalP f v) C
beval_c (sym c) v C = beval_c (adjoint c) v C
beval_c (f ◎ g) v C = beval_c g v (seqC₂ f C)
beval_c (f ⊕ g) (inj₁ v) C = beval_c f v (leftC g C)
beval_c (f ⊕ g) (inj₂ v) C = beval_c g v (rightC f C)
beval_c (f ⊗ g) (v₁ , v₂) C = beval_c g v₂ (sndC f v₁ C)
beval_c refe⋆ v C = beval_k refe⋆ {!!} C
beval_c refi⋆ _ C = beval_k refi⋆ {!!} C
beval_c rile⋆ v C = beval_k rile⋆ (v , (v , {!!})) C
beval_c rili⋆ (v₁ , (v₂ , _)) C = {!!}
-- The (d <-> b) part of the computation has been done.
-- The (a <-> b) backwards computation has been done.
-- We have an 'a' and examine the context to get the 'c'
beval_k : { a b c : BF } → (a ⟺ b) → ⟦ a ⟧F → Context a b c c → ⟦ c ⟧F
beval_k f v emptyC = v
beval_k g v (seqC₂ f C) = beval_c f v (seqC₁ g C)
beval_k f v (seqC₁ g C) = beval_k (f ◎ g) v C
beval_k f v (leftC g C) = beval_k (f ⊕ g) (inj₁ v) C
beval_k g v (rightC f C) = beval_k (f ⊕ g) (inj₂ v) C
beval_k g v₂ (sndC f v₁ C) = beval_c f v₁ (fstC v₂ g C)
beval_k f v₁ (fstC v₂ g C) = beval_k (f ⊗ g) (v₁ , v₂) C
------------------------------------------------------------------------------
-- Top level eval
eval : { a : BF } → (a ⟺ a) → ⟦ a ⟧F → ⟦ a ⟧F
eval f v = eval_c f v emptyC
--
BOOL : BF
BOOL = PLUSF ONEF ONEF
test1 : ⟦ BOOL ⟧F
test1 = eval {BOOL} (iso swap₊) (inj₁ tt)
| {
"alphanum_fraction": 0.5233827771,
"avg_line_length": 37.1954022989,
"ext": "agda",
"hexsha": "8f3d034f6f6b59495d66088e055c6b8495d8c03d",
"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/PiF.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "agda/PiF.agda",
"max_line_length": 84,
"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/PiF.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 4246,
"size": 9708
} |
-- Basic intuitionistic contextual modal logic, without ∨ or ⊥.
-- Gentzen-style formalisation of syntax with context pairs, after Nanevski-Pfenning-Pientka.
-- Simple terms.
module BasicICML.Syntax.DyadicGentzen where
open import BasicICML.Syntax.Common public
-- Derivations.
-- NOTE: Only var is an instance constructor, which allows the instance argument for mvar to be automatically inferred, in many cases.
mutual
infix 3 _⊢_
data _⊢_ : Cx² Ty Box → Ty → Set where
instance
var : ∀ {A Γ Δ} → A ∈ Γ → Γ ⁏ Δ ⊢ A
lam : ∀ {A B Γ Δ} → Γ , A ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ A ▻ B
app : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ B
mvar : ∀ {Ψ A Γ Δ} → [ Ψ ] A ∈ Δ → {{_ : Γ ⁏ Δ ⊢⋆ Ψ}} → Γ ⁏ Δ ⊢ A
box : ∀ {Ψ A Γ Δ} → Ψ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ [ Ψ ] A
unbox : ∀ {Ψ A C Γ Δ} → Γ ⁏ Δ ⊢ [ Ψ ] A → Γ ⁏ Δ , [ Ψ ] A ⊢ C → Γ ⁏ Δ ⊢ C
pair : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ A ∧ B
fst : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B → Γ ⁏ Δ ⊢ A
snd : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B → Γ ⁏ Δ ⊢ B
unit : ∀ {Γ Δ} → Γ ⁏ Δ ⊢ ⊤
infix 3 _⊢⋆_
data _⊢⋆_ : Cx² Ty Box → Cx Ty → Set where
instance
∙ : ∀ {Γ Δ} → Γ ⁏ Δ ⊢⋆ ∅
_,_ : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢⋆ Ξ , A
-- Monotonicity with respect to context inclusion.
mutual
mono⊢ : ∀ {A Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢ A → Γ′ ⁏ Δ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η (mvar i {{ts}}) = mvar i {{mono⊢⋆ η ts}}
mono⊢ η (box t) = box t
mono⊢ η (unbox t u) = unbox (mono⊢ η t) (mono⊢ η u)
mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)
mono⊢ η (fst t) = fst (mono⊢ η t)
mono⊢ η (snd t) = snd (mono⊢ η t)
mono⊢ η unit = unit
mono⊢⋆ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⋆ Ξ → Γ′ ⁏ Δ ⊢⋆ Ξ
mono⊢⋆ η ∙ = ∙
mono⊢⋆ η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Monotonicity with respect to modal context inclusion.
mutual
mmono⊢ : ∀ {A Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ′ ⊢ A
mmono⊢ θ (var i) = var i
mmono⊢ θ (lam t) = lam (mmono⊢ θ t)
mmono⊢ θ (app t u) = app (mmono⊢ θ t) (mmono⊢ θ u)
mmono⊢ θ (mvar i {{ts}}) = mvar (mono∈ θ i) {{mmono⊢⋆ θ ts}}
mmono⊢ θ (box t) = box (mmono⊢ θ t)
mmono⊢ θ (unbox t u) = unbox (mmono⊢ θ t) (mmono⊢ (keep θ) u)
mmono⊢ θ (pair t u) = pair (mmono⊢ θ t) (mmono⊢ θ u)
mmono⊢ θ (fst t) = fst (mmono⊢ θ t)
mmono⊢ θ (snd t) = snd (mmono⊢ θ t)
mmono⊢ θ unit = unit
mmono⊢⋆ : ∀ {Ξ Δ Δ′ Γ} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ′ ⊢⋆ Ξ
mmono⊢⋆ θ ∙ = ∙
mmono⊢⋆ θ (ts , t) = mmono⊢⋆ θ ts , mmono⊢ θ t
-- Monotonicity using context pairs.
mono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A
mono²⊢ (η , θ) = mono⊢ η ∘ mmono⊢ θ
-- 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₂
mv₀ : ∀ {Ψ A Γ Δ}
→ {{_ : Γ ⁏ Δ , [ Ψ ] A ⊢⋆ Ψ}}
→ Γ ⁏ Δ , [ Ψ ] A ⊢ A
mv₀ = mvar i₀
mv₁ : ∀ {Ψ Ψ′ A B Γ Δ}
→ {{_ : Γ ⁏ Δ , [ Ψ ] A , [ Ψ′ ] B ⊢⋆ Ψ}}
→ Γ ⁏ Δ , [ Ψ ] A , [ Ψ′ ] B ⊢ A
mv₁ = mvar i₁
mv₂ : ∀ {Ψ Ψ′ Ψ″ A B C Γ Δ}
→ {{_ : Γ ⁏ Δ , [ Ψ ] A , [ Ψ′ ] B , [ Ψ″ ] C ⊢⋆ Ψ}}
→ Γ ⁏ Δ , [ Ψ ] A , [ Ψ′ ] B , [ Ψ″ ] C ⊢ A
mv₂ = mvar i₂
-- Generalised reflexivity.
instance
refl⊢⋆ : ∀ {Γ Ψ Δ} → {{_ : Ψ ⊆ Γ}} → Γ ⁏ Δ ⊢⋆ Ψ
refl⊢⋆ {∅} {{done}} = ∙
refl⊢⋆ {Γ , A} {{skip η}} = mono⊢⋆ weak⊆ (refl⊢⋆ {{η}})
refl⊢⋆ {Γ , A} {{keep η}} = mono⊢⋆ weak⊆ (refl⊢⋆ {{η}}) , v₀
-- Deduction theorem is built-in.
-- Modal deduction theorem.
mlam : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ , [ Ψ ] A ⊢ B
→ Γ ⁏ Δ ⊢ [ Ψ ] A ▻ B
mlam t = lam (unbox v₀ (mono⊢ weak⊆ t))
-- Detachment theorems.
det : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B → Γ , A ⁏ Δ ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
mdet : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] A ▻ B
→ Γ ⁏ Δ , [ Ψ ] A ⊢ B
mdet t = app (mmono⊢ weak⊆ t) (box mv₀)
-- Cut and multicut.
cut : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A → Γ , A ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ B
cut t u = app (lam u) t
mcut : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] A
→ Γ ⁏ Δ , [ Ψ ] A ⊢ B
→ Γ ⁏ Δ ⊢ B
mcut t u = app (mlam u) t
multicut : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Ξ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A
multicut ∙ u = mono⊢ bot⊆ u
multicut (ts , t) u = app (multicut ts (lam u)) t
-- 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)))
mcont : ∀ {Ψ A B Γ Δ} → Γ ⁏ Δ , [ Ψ ] A , [ Ψ ] A ⊢ B → Γ ⁏ Δ , [ Ψ ] A ⊢ B
mcont t = mdet (app ccont (mlam (mlam 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))))
mexch : ∀ {Ψ Ψ′ A B C Γ Δ}
→ Γ ⁏ Δ , [ Ψ ] A , [ Ψ′ ] B ⊢ C
→ Γ ⁏ Δ , [ Ψ′ ] B , [ Ψ ] A ⊢ C
mexch t = mdet (mdet (app cexch (mlam (mlam 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))
mcomp : ∀ {Ψ Ψ′ Ψ″ A B C Γ Δ}
→ Γ ⁏ Δ , [ Ψ′ ] B ⊢ [ Ψ″ ] C
→ Γ ⁏ Δ , [ Ψ ] A ⊢ [ Ψ′ ] B
→ Γ ⁏ Δ , [ Ψ ] A ⊢ [ Ψ″ ] C
mcomp t u = mdet (app (app ccomp (mlam t)) (mlam u))
-- Useful theorems in functional form.
dist : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] (A ▻ B)
→ Γ ⁏ Δ ⊢ [ Ψ ] A
→ Γ ⁏ Δ ⊢ [ Ψ ] B
dist t u = unbox t (unbox (mmono⊢ weak⊆ u) (box (app mv₁ mv₀)))
up : ∀ {Ψ A Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] A
→ Γ ⁏ Δ ⊢ [ Ψ ] [ Ψ ] A
up t = unbox t (box (box mv₀))
down : ∀ {Ψ A Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] A
→ {{_ : Γ ⁏ Δ , [ Ψ ] A ⊢⋆ Ψ}}
→ Γ ⁏ Δ ⊢ A
down t = unbox t mv₀
distup : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] ([ Ψ ] A ▻ B)
→ Γ ⁏ Δ ⊢ [ Ψ ] A
→ Γ ⁏ Δ ⊢ [ Ψ ] B
distup t u = dist t (up u)
-- Useful theorems in combinatory form.
ci : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A ▻ A
ci = lam v₀
ck : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B ▻ A
ck = lam (lam v₁)
cs : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))
cdist : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] (A ▻ B) ▻
[ Ψ ] A ▻
[ Ψ ] B
cdist = lam (lam (dist v₁ v₀))
cup : ∀ {Ψ A Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] A ▻
[ Ψ ] [ Ψ ] A
cup = lam (up v₀)
cdistup : ∀ {Ψ A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] ([ Ψ ] A ▻ B) ▻
[ Ψ ] A ▻ [ Ψ ] B
cdistup = lam (lam (dist v₁ (up v₀)))
cunbox : ∀ {Ψ A C Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ] A ▻
([ Ψ ] A ▻ C) ▻
C
cunbox = lam (lam (app v₀ v₁))
cpair : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B ▻ A ∧ B
cpair = lam (lam (pair v₁ v₀))
cfst : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B ▻ A
cfst = lam (fst v₀)
csnd : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B ▻ B
csnd = lam (snd v₀)
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ {Δ} → Γ , A ⁏ Δ ⊢ B → Γ′ ⁏ Δ ⊢ A → Γ ⧺ Γ′ ⁏ Δ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
mconcat : ∀ {Ψ A B Γ Δ} Δ′ → Γ ⁏ Δ , [ Ψ ] A ⊢ B → Γ ⁏ Δ′ ⊢ [ Ψ ] A → Γ ⁏ Δ ⧺ Δ′ ⊢ B
mconcat Δ′ t u = app (mmono⊢ (weak⊆⧺₁ Δ′) (mlam t)) (mmono⊢ weak⊆⧺₂ u)
-- Substitution.
mutual
[_≔_]_ : ∀ {A C Γ Δ} → (i : A ∈ Γ) → Γ ∖ i ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ C → Γ ∖ i ⁏ Δ ⊢ C
[ i ≔ s ] var j with i ≟∈ j
[ i ≔ s ] var .i | same = s
[ i ≔ s ] var ._ | diff j = var j
[ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)
[ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] mvar j {{ts}} = mvar j {{[ i ≔ s ]⋆ ts}}
[ i ≔ s ] box t = box t
[ i ≔ s ] unbox t u = unbox ([ i ≔ s ] t) ([ i ≔ mmono⊢ weak⊆ s ] u)
[ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] fst t = fst ([ i ≔ s ] t)
[ i ≔ s ] snd t = snd ([ i ≔ s ] t)
[ i ≔ s ] unit = unit
[_≔_]⋆_ : ∀ {Ξ A Γ Δ} → (i : A ∈ Γ) → Γ ∖ i ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢⋆ Ξ → Γ ∖ i ⁏ Δ ⊢⋆ Ξ
[_≔_]⋆_ i s ∙ = ∙
[_≔_]⋆_ i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t
-- Modal substitution.
mutual
m[_≔_]_ : ∀ {Ψ A C Γ Δ} → (i : [ Ψ ] A ∈ Δ) → Ψ ⁏ Δ ∖ i ⊢ A → Γ ⁏ Δ ⊢ C → Γ ⁏ Δ ∖ i ⊢ C
m[ i ≔ s ] var j = var j
m[ i ≔ s ] lam t = lam (m[ i ≔ s ] t)
m[ i ≔ s ] app t u = app (m[ i ≔ s ] t) (m[ i ≔ s ] u)
m[ i ≔ s ] mvar j {{ts}} with i ≟∈ j
m[ i ≔ s ] mvar .i {{ts}} | same = multicut (m[ i ≔ s ]⋆ ts) s
m[ i ≔ s ] mvar ._ {{ts}} | diff j = mvar j {{m[ i ≔ s ]⋆ ts}}
m[ i ≔ s ] box t = box (m[ i ≔ s ] t)
m[ i ≔ s ] unbox t u = unbox (m[ i ≔ s ] t) (m[ pop i ≔ mmono⊢ weak⊆ s ] u)
m[ i ≔ s ] pair t u = pair (m[ i ≔ s ] t) (m[ i ≔ s ] u)
m[ i ≔ s ] fst t = fst (m[ i ≔ s ] t)
m[ i ≔ s ] snd t = snd (m[ i ≔ s ] t)
m[ i ≔ s ] unit = unit
m[_≔_]⋆_ : ∀ {Ξ Ψ A Γ Δ} → (i : [ Ψ ] A ∈ Δ) → Ψ ⁏ Δ ∖ i ⊢ A → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ∖ i ⊢⋆ Ξ
m[_≔_]⋆_ i s ∙ = ∙
m[_≔_]⋆_ i s (ts , t) = m[ i ≔ s ]⋆ ts , m[ i ≔ s ] t
-- Convertibility.
data _⋙_ {Δ : Cx Box} {Γ : 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
conglam⋙ : ∀ {A B} → {t t′ : Γ , A ⁏ Δ ⊢ B}
→ t ⋙ t′
→ lam t ⋙ lam t′
congapp⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A ▻ B} → {u u′ : Γ ⁏ Δ ⊢ A}
→ t ⋙ t′ → u ⋙ u′
→ app t u ⋙ app t′ u′
-- NOTE: Rejected by Pfenning and Davies.
-- congbox⋙ : ∀ {Ψ A} → {t t′ : Ψ ⁏ Δ ⊢ A}
-- → t ⋙ t′
-- → box t ⋙ box t′
congunbox⋙ : ∀ {Ψ A C} → {t t′ : Γ ⁏ Δ ⊢ [ Ψ ] A} → {u u′ : Γ ⁏ Δ , [ Ψ ] A ⊢ C}
→ t ⋙ t′ → u ⋙ u′
→ unbox t u ⋙ unbox t′ u′
congpair⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A} → {u u′ : Γ ⁏ Δ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ pair t u ⋙ pair t′ u′
congfst⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A ∧ B}
→ t ⋙ t′
→ fst t ⋙ fst t′
congsnd⋙ : ∀ {A B} → {t t′ : Γ ⁏ Δ ⊢ A ∧ B}
→ t ⋙ t′
→ snd t ⋙ snd t′
beta▻⋙ : ∀ {A B} → {t : Γ , A ⁏ Δ ⊢ B} → {u : Γ ⁏ Δ ⊢ A}
→ app (lam t) u ⋙ ([ top ≔ u ] t)
eta▻⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A ▻ B}
→ t ⋙ lam (app (mono⊢ weak⊆ t) v₀)
beta□⋙ : ∀ {Ψ A C} → {t : Ψ ⁏ Δ ⊢ A} → {u : Γ ⁏ Δ , [ Ψ ] A ⊢ C}
→ unbox (box t) u ⋙ (m[ top ≔ t ] u)
eta□⋙ : ∀ {Ψ A} → {t : Γ ⁏ Δ ⊢ [ Ψ ] A}
→ t ⋙ unbox t (box mv₀)
-- TODO: What about commuting conversions for □?
beta∧₁⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A} → {u : Γ ⁏ Δ ⊢ B}
→ fst (pair t u) ⋙ t
beta∧₂⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A} → {u : Γ ⁏ Δ ⊢ B}
→ snd (pair t u) ⋙ u
eta∧⋙ : ∀ {A B} → {t : Γ ⁏ Δ ⊢ A ∧ B}
→ t ⋙ pair (fst t) (snd t)
eta⊤⋙ : ∀ {t : Γ ⁏ Δ ⊢ ⊤} → t ⋙ unit
-- Examples from the Nanevski-Pfenning-Pientka paper.
-- NOTE: In many cases, the instance argument for mvar can be automatically inferred, but not always.
module Examples where
e₁ : ∀ {A C D Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , C ] A ▻
[ ∅ , C , D ] A
e₁ = lam (unbox v₀ (box mv₀))
e₂ : ∀ {A C Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , C , C ] A ▻
[ ∅ , C ] A
e₂ = lam (unbox v₀ (box mv₀))
e₃ : ∀ {A Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , A ] A
e₃ = box v₀
e₄ : ∀ {A B C Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , A ] B ▻
[ ∅ , A ] [ ∅ , B ] C ▻
[ ∅ , A ] C
e₄ = lam (lam (unbox v₁ (unbox v₀ (box
(unbox mv₀ (mv₀ {{∙ , mv₂}}))))))
e₅ : ∀ {A Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ ] A ▻ A
e₅ = lam (unbox v₀ mv₀)
e₆ : ∀ {A C D Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , C ] A ▻
[ ∅ , D ] [ ∅ , C ] A
e₆ = lam (unbox v₀ (box (box mv₀)))
e₇ : ∀ {A B C D Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , C ] (A ▻ B) ▻
[ ∅ , D ] A ▻
[ ∅ , C , D ] B
e₇ = lam (lam (unbox v₁ (unbox v₀ (box
(app mv₁ mv₀)))))
e₈ : ∀ {A B C Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , A ] (A ▻ B) ▻
[ ∅ , B ] C ▻
[ ∅ , A ] C
e₈ = lam (lam (unbox v₁ (unbox v₀ (box
(mv₀ {{∙ , app mv₁ v₀}})))))
| {
"alphanum_fraction": 0.3646430231,
"avg_line_length": 29.6873563218,
"ext": "agda",
"hexsha": "8ea69984811c5f2e5028c4740cc3b26f024218ac",
"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": "BasicICML/Syntax/DyadicGentzen.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": "BasicICML/Syntax/DyadicGentzen.agda",
"max_line_length": 134,
"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": "BasicICML/Syntax/DyadicGentzen.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": 6565,
"size": 12914
} |
{-# OPTIONS --without-K #-}
module AC {a b c} {A : Set a} {B : A → Set b} {C : (x : A) → B x → Set c} where
open import Equivalence
open import FunExt
open import Types
left : Set _
left = (x : A) → Σ (B x) λ y → C x y
right : Set _
right = Σ ((x : A) → B x) λ f → (x : A) → C x (f x)
to : left → right
to f = π₁ ∘ f , π₂ ∘ f
from : right → left
from f x = π₁ f x , π₂ f x
AC∞ : right ≃ left
AC∞
= from
, (to , λ _ → refl)
, (to , λ _ → refl)
| {
"alphanum_fraction": 0.5098901099,
"avg_line_length": 18.2,
"ext": "agda",
"hexsha": "9e3f6d2493228816b9dbba9ec35a8c3243d1905b",
"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": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/AC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"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": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/AC.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/AC.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 193,
"size": 455
} |
module Oscar.Data.Vec.Properties where
open import Oscar.Data.Vec
open import Data.Vec.Properties public
open import Data.Nat
open import Data.Product renaming (map to mapP)
open import Relation.Binary.PropositionalEquality
open import Data.Fin
map-∈ : ∀ {a b} {A : Set a} {B : Set b} {y : B} {f : A → B} {n} {xs : Vec A n} → y ∈ map f xs → ∃ λ x → f x ≡ y
map-∈ {xs = []} ()
map-∈ {xs = x ∷ xs} here = x , refl
map-∈ {xs = x ∷ xs} (there y∈mapfxs) = map-∈ y∈mapfxs
∈-map₂ : ∀ {a b} {A : Set a} {B : Set b} {m n : ℕ}
→ ∀ {c} {F : Set c} (f : A → B → F)
{xs : Vec A m} {ys : Vec B n}
{x y} → x ∈ xs → y ∈ ys → (f x y) ∈ map₂ f xs ys
∈-map₂ f {xs = x ∷ xs} {ys} here y∈ys =
∈-++ₗ (∈-map (f x) y∈ys)
∈-map₂ f {xs = x ∷ xs} {ys} (there x∈xs) y∈ys =
∈-++ᵣ (map (f x) ys) (∈-map₂ f x∈xs y∈ys)
lookup-delete-thin : ∀ {a n} {A : Set a} (x : Fin (suc n)) (y : Fin n) (v : Vec A (suc n)) →
lookup y (delete x v) ≡ lookup (thin x y) v
lookup-delete-thin zero zero (_ ∷ _) = refl
lookup-delete-thin zero (suc _) (_ ∷ _) = refl
lookup-delete-thin (suc _) zero (_ ∷ _) = refl
lookup-delete-thin (suc x) (suc y) (_ ∷ v) = lookup-delete-thin x y v
| {
"alphanum_fraction": 0.5268373245,
"avg_line_length": 36.696969697,
"ext": "agda",
"hexsha": "0b941fcf7f494f2277f5c7621d8d6913cb9fd426",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data/Vec/Properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data/Vec/Properties.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data/Vec/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 506,
"size": 1211
} |
{-# OPTIONS --copatterns #-}
module IOExampleGraphicsDrawingProgram where
open import Data.Bool.Base
open import Data.Char.Base renaming (primCharEquality to charEquality)
open import Data.Nat.Base hiding (_≟_;_⊓_; _+_; _*_)
open import Data.List.Base hiding (_++_)
open import Data.Integer.Base hiding (suc)
open import Data.String.Base
open import Data.Maybe.Base
open import Function
open import SizedIO.Base
open import SizedIO.IOGraphicsLib
open import NativeInt --PrimTypeHelpers
open import NativeIO
integerLess : ℤ → ℤ → Bool
integerLess x y with ∣(y - (x ⊓ y))∣
... | zero = true
... | z = false
line : Point → Point → Graphic
line p newpoint = withColor red (polygon
(nativePoint x y
∷ nativePoint a b
∷ nativePoint (a + xAddition) (b + yAddition)
∷ nativePoint (x + xAddition) (y + yAddition)
∷ [] ) )
where
x = nativeProj1Point p
y = nativeProj2Point p
a = nativeProj1Point newpoint
b = nativeProj2Point newpoint
diffx = + ∣ (a - x) ∣
diffy = + ∣ (b - y) ∣
diffx*3 = diffx * (+ 3)
diffy*3 = diffy * (+ 3)
condition = (integerLess diffx diffy*3) ∧ (integerLess diffy diffx*3)
xAddition = if condition then + 2 else + 1
yAddition = if condition then + 2 else + 1
State = Maybe Point
loop : ∀{i} → Window → State → IOGraphics i Unit
force (loop w s) = exec' (getWindowEvent w)
λ{ (Key c t) → if charEquality c 'x' then (exec (closeWindow w) return)
else loop w s
; (MouseMove p₂) → case s of
λ{ nothing → loop w (just p₂)
; (just p₁) → exec (drawInWindow w (line p₁ p₂)) λ _ →
loop w (just p₂)
}
; _ → loop w s
}
{-
loop : ∀{i} → Window → State → IOGraphics i Unit
force (loop w s) = exec' (getWindowEvent w)
λ{ (Key c t) → if charEquality c 'x' then return _ else loop w s
; (MouseMove p₂) → case s of
λ{ nothing → loop w (just p₂)
; (just p₁) → exec (drawInWindow w (line p₁ p₂)) λ _ →
loop w (just p₂)
}
; _ → loop w s
}
-}
{-
mutual
loop : ∀{i} → Window → State → IOGraphics i Unit
force (loop w s) = exec' (getWindowEvent w) (λ e → aux w e s)
aux : ∀{i} → Window → Event → State → IOGraphics i Unit
aux w (Key c t) s = if charEquality c 'x' then (exec (closeWindow w) λ _ → return _)
else loop w s
aux w (MouseMove p₂) (just p₁) = exec (drawInWindow w (line p₁ p₂)) (λ _ →
loop w (just p₂))
aux w (MouseMove p₂) nothing = loop w (just p₂)
aux w _ s = loop w s
-}
{-
tailrecursion discussion
mutual
loop : ∀{i} → Window → State → IOGraphics i Unit
command (force (loop w s)) = (getWindowEvent w)
response (force (loop w s)) e = aux w e s
aux : ∀{i} → Window → Event → State → IOGraphics i Unit
command (aux w (MouseMove p₂) (just p₁)) = (drawInWindow w (line p₁ p₂))
response (aux w (MouseMove p₂) (just p₁)) _ = loop w (just p₂))
aux w (MouseMove p₂) nothing = loop w (just p₂)
aux w _ s = loop w s
-}
{-
λ{ (Key c t) → if charEquality c 'x' then
(exec ? λ _ → return _) else loop w s
; (MouseMove p₂) → case s of
λ{ nothing → loop w (just p₂)
; (just p₁) → exec (drawInWindow w (line p₁ p₂)) λ _ →
loop w (just p₂)
}
; _ → loop w s
}
-}
myProgram : ∀{i} → IOGraphics i Unit
myProgram =
exec (openWindow "Drawing Program" nothing
1000 1000 nativeDrawGraphic nothing) λ window →
loop window nothing
main : NativeIO Unit
main = nativeRunGraphics (translateIOGraphics myProgram)
| {
"alphanum_fraction": 0.5366766467,
"avg_line_length": 29.6888888889,
"ext": "agda",
"hexsha": "f55628e0bca153112da6bfeb8a55a3b3b0ed765d",
"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/DrawingProgram/IOExampleGraphicsDrawingProgram.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/DrawingProgram/IOExampleGraphicsDrawingProgram.agda",
"max_line_length": 99,
"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/DrawingProgram/IOExampleGraphicsDrawingProgram.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": 1228,
"size": 4008
} |
------------------------------------------------------------------------------
-- Streams properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Stream.PropertiesI where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Base.List.PropertiesI
open import FOTC.Data.Conat
open import FOTC.Data.Conat.Equality.Type
open import FOTC.Data.Colist
open import FOTC.Data.Colist.PropertiesI
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesI
open import FOTC.Data.Stream
-----------------------------------------------------------------------------
-- Because a greatest post-fixed point is a fixed-point, then the
-- Stream predicate is also a pre-fixed point of the functional
-- StreamF, i.e.
--
-- StreamF Stream ≤ Stream (see FOTC.Data.Stream.Type).
Stream-in : ∀ {xs} →
∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs' →
Stream xs
Stream-in h = Stream-coind A h' h
where
A : D → Set
A xs = ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs'
h' : ∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
h' (x' , xs' , prf , Sxs') = x' , xs' , prf , Stream-out Sxs'
zeros-Stream : Stream zeros
zeros-Stream = Stream-coind A h refl
where
A : D → Set
A xs = xs ≡ zeros
h : ∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
h Axs = zero , zeros , trans Axs zeros-eq , refl
ones-Stream : Stream ones
ones-Stream = Stream-coind A h refl
where
A : D → Set
A xs = xs ≡ ones
h : ∀ {xs} → A xs → ∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs'
h Axs = succ₁ zero , ones , trans Axs ones-eq , refl
∷-Stream : ∀ {x xs} → Stream (x ∷ xs) → Stream xs
∷-Stream {x} {xs} h = ∷-Stream-helper (Stream-out h)
where
∷-Stream-helper : ∃[ x' ] ∃[ xs' ] x ∷ xs ≡ x' ∷ xs' ∧ Stream xs' →
Stream xs
∷-Stream-helper (x' , xs' , prf , Sxs') =
subst Stream (sym (∧-proj₂ (∷-injective prf))) Sxs'
-- Version using Agda with constructor.
∷-Stream' : ∀ {x xs} → Stream (x ∷ xs) → Stream xs
∷-Stream' h with Stream-out h
... | x' , xs' , prf , Sxs' =
subst Stream (sym (∧-proj₂ (∷-injective prf))) Sxs'
Stream→Colist : ∀ {xs} → Stream xs → Colist xs
Stream→Colist {xs} Sxs = Colist-coind A h₁ h₂
where
A : D → Set
A ys = Stream ys
h₁ : ∀ {xs} → A xs → xs ≡ [] ∨ (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ A xs')
h₁ Axs with Stream-out Axs
... | x' , xs' , prf , Sxs' = inj₂ (x' , xs' , prf , Sxs')
h₂ : A xs
h₂ = Sxs
-- Adapted from (Sander 1992, p. 59).
streamLength : ∀ {xs} → Stream xs → length xs ≈ ∞
streamLength {xs} Sxs = ≈-coind R h₁ h₂
where
R : D → D → Set
R m n = ∃[ xs ] Stream xs ∧ m ≡ length xs ∧ n ≡ ∞
h₁ : ∀ {m n} → R m n →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')
h₁ {m} {n} (xs , Sxs , m=lxs , n≡∞) = helper₁ (Stream-out Sxs)
where
helper₁ : (∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ Stream xs') →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')
helper₁ (x' , xs' , xs≡x'∷xs' , Sxs') =
inj₂ (length xs'
, ∞
, helper₂
, trans n≡∞ ∞-eq
, (xs' , Sxs' , refl , refl))
where
helper₂ : m ≡ succ₁ (length xs')
helper₂ = trans m=lxs (trans (lengthCong xs≡x'∷xs') (length-∷ x' xs'))
h₂ : R (length xs) ∞
h₂ = xs , Sxs , refl , refl
-- Adapted from (Sander 1992, p. 59). Version using Agda with
-- constructor.
streamLength' : ∀ {xs} → Stream xs → length xs ≈ ∞
streamLength' {xs} Sxs = ≈-coind R h₁ h₂
where
R : D → D → Set
R m n = ∃[ xs ] Stream xs ∧ m ≡ length xs ∧ n ≡ ∞
h₁ : ∀ {m n} → R m n →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')
h₁ {m} (xs , Sxs , m=lxs , n≡∞) with Stream-out Sxs
... | x' , xs' , xs≡x'∷xs' , Sxs' =
inj₂ (length xs' , ∞ , helper , trans n≡∞ ∞-eq , (xs' , Sxs' , refl , refl))
where
helper : m ≡ succ₁ (length xs')
helper = trans m=lxs (trans (lengthCong xs≡x'∷xs') (length-∷ x' xs'))
h₂ : R (length xs) ∞
h₂ = xs , Sxs , refl , refl
------------------------------------------------------------------------------
-- References
--
-- Sander, Herbert P. (1992). A Logic of Functional Programs with an
-- Application to Concurrency. PhD thesis. Department of Computer
-- Sciences: Chalmers University of Technology and University of
-- Gothenburg.
| {
"alphanum_fraction": 0.4971652857,
"avg_line_length": 32.524822695,
"ext": "agda",
"hexsha": "598edf4561251944b74482cac06ffab0439dffa7",
"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/Stream/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Stream/PropertiesI.agda",
"max_line_length": 80,
"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/Stream/PropertiesI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1682,
"size": 4586
} |
{-# OPTIONS --sized-types #-}
module SizedTypesScopeExtrusion where
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {size ^}
suc : {size : Size} -> Nat {size} -> Nat {size ^}
data Empty : Set where
data Unit : Set where
unit : Unit
Zero : (i : Size) -> Nat {i} -> Set
Zero ._ zero = Unit
Zero ._ (suc _) = Empty
bla : Set
bla = (x : Nat) -> (i : Size) -> Zero i x
| {
"alphanum_fraction": 0.5586592179,
"avg_line_length": 18.5172413793,
"ext": "agda",
"hexsha": "2fd98ceb26bf6e6b2dfda1d170f82e441792b2a7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/SizedTypesScopeExtrusion.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/SizedTypesScopeExtrusion.agda",
"max_line_length": 52,
"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/SizedTypesScopeExtrusion.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": 180,
"size": 537
} |
module DifferentArities where
open import Common.Equality
open import Common.Prelude
f : Nat → Nat → Nat
f zero = λ x → x
f (suc n) m = f n (suc m)
testf1 : f zero ≡ λ x → x
testf1 = refl
testf2 : ∀ {n m} → f (suc n) m ≡ f n (suc m)
testf2 = refl
testf3 : f 4 5 ≡ 9
testf3 = refl
-- Andreas, 2015-01-21 proper matching on additional argument
Sum : Nat → Set
Sum 0 = Nat
Sum (suc n) = Nat → Sum n
sum : (acc : Nat) (n : Nat) → Sum n
sum acc 0 = acc
sum acc (suc n) 0 = sum acc n
sum acc (suc n) m = sum (m + acc) n
nzero : (n : Nat) → Sum n
nzero 0 = 0
nzero (suc n) m = nzero n
mult : (acc : Nat) (n : Nat) → Sum n
mult acc 0 = acc
mult acc (suc n) 0 = nzero n
mult acc (suc n) m = mult (m * acc) n
| {
"alphanum_fraction": 0.5758807588,
"avg_line_length": 18.9230769231,
"ext": "agda",
"hexsha": "6bf5d188dccca862699de5de5d91003d8b703f5b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/DifferentArities.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/DifferentArities.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/DifferentArities.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": 308,
"size": 738
} |
module safety where
open import Algebra
open import Data.List
open import Data.List.Relation.Unary.All using (All; []; _∷_)
open import Data.Rational
open import Data.Rational.Properties
open import Data.Nat using (z≤n; s≤s)
open import Data.Integer using (+≤+; +<+; +_)
open import Data.Vec using (_∷_)
open import Level using (0ℓ)
open import Relation.Binary.PropositionalEquality
open import Vehicle.Data.Tensor
open ≤-Reasoning
------------------------------------------------------------------------
-- Things to work out how to put in standard library
2ℚ = + 2 / 1
3ℚ = + 3 / 1
p+q-q≡p : ∀ p q → p + q - q ≡ p
p+q-q≡p p q = begin-equality
p + q - q ≡⟨ +-assoc p q (- q) ⟩
p + (q - q) ≡⟨ cong (λ v → p + v) (+-inverseʳ q) ⟩
p + 0ℚ ≡⟨ +-identityʳ p ⟩
p ∎
+-isCommutativeSemigroup : IsCommutativeSemigroup _≡_ _+_
+-isCommutativeSemigroup = isCommutativeSemigroup
where open IsCommutativeMonoid +-0-isCommutativeMonoid
+-commutativeSemigroup : CommutativeSemigroup 0ℓ 0ℓ
+-commutativeSemigroup = record
{ isCommutativeSemigroup = +-isCommutativeSemigroup
}
2*x≡x+x : ∀ p → 2ℚ * p ≡ p + p
2*x≡x+x p = begin-equality
2ℚ * p ≡⟨⟩
(1ℚ + 1ℚ) * p ≡⟨ *-distribʳ-+ p 1ℚ 1ℚ ⟩
1ℚ * p + 1ℚ * p ≡⟨ cong₂ _+_ (*-identityˡ p) (*-identityˡ p) ⟩
p + p ∎
open import Algebra.Properties.CommutativeSemigroup +-commutativeSemigroup
------------------------------------------------------------------------
-- The controller
postulate controller : ℚ → ℚ → ℚ
postulate controller-lem : ∀ x y → ∣ x ∣ < 3ℚ → ∣ controller x y + 2ℚ * x - y ∣ < 2ℚ
------------------------------------------------------------------------
-- The model
record State : Set where
no-eta-equality
field
windSpeed : ℚ
position : ℚ
velocity : ℚ
open State
initialState : State
initialState = record
{ windSpeed = 0ℚ
; position = 0ℚ
; velocity = 0ℚ
}
nextState : ℚ → State → State
nextState changeInWindSpeed s = record
{ windSpeed = newWindSpeed
; position = newPosition
; velocity = velocity s + controller newPosition (position s)
}
where
newWindSpeed = windSpeed s + changeInWindSpeed
newPosition = position s + velocity s + newWindSpeed
finalState : List ℚ → State
finalState xs = foldr nextState initialState xs
------------------------------------------------------------------------
-- Definition and proof of safety
stateSum : State → ℚ
stateSum s = position s + velocity s + windSpeed s
Safe : State → Set
Safe s = ∣ position s ∣ < 3ℚ
Good : State → Set
Good s = ∣ stateSum s ∣ < 2ℚ
LowWind : ℚ → Set
LowWind x = ∣ x ∣ ≤ 1ℚ
-- A state being good will imply the next state is safe
good⇒nextSafe : ∀ dw → ∣ dw ∣ ≤ 1ℚ → ∀ s → Good s → Safe (nextState dw s)
good⇒nextSafe dw ∣dw∣≤1 s ∣Σ∣<2 = begin-strict
∣ (position s + velocity s) + (windSpeed s + dw) ∣ ≡˘⟨ cong ∣_∣ (+-assoc (position s + velocity s) (windSpeed s) dw) ⟩
∣ (position s + velocity s) + windSpeed s + dw ∣ ≤⟨ ∣p+q∣≤∣p∣+∣q∣ (stateSum s) dw ⟩
∣ position s + velocity s + windSpeed s ∣ + ∣ dw ∣ <⟨ +-monoˡ-< ∣ dw ∣ ∣Σ∣<2 ⟩
2ℚ + ∣ dw ∣ ≤⟨ +-monoʳ-≤ 2ℚ ∣dw∣≤1 ⟩
2ℚ + 1ℚ ≡⟨⟩
3ℚ ∎
-- Initial state is both safe and good
initialState-safe : Safe initialState
initialState-safe = *<* (+<+ (s≤s z≤n))
initialState-good : Good initialState
initialState-good = *<* (+<+ (s≤s z≤n))
good⇒nextGood : ∀ dw → ∣ dw ∣ ≤ 1ℚ → ∀ s → Good s → Good (nextState dw s)
good⇒nextGood dw ∣dw∣≤1 s Σ≤2 =
let
s' = nextState dw s
dv = controller (position s') (position s)
s'-safe = good⇒nextSafe dw ∣dw∣≤1 s Σ≤2
in
begin-strict
∣ position s' + velocity s' + windSpeed s' ∣ ≡⟨⟩
∣ position s' + (velocity s + dv) + windSpeed s' ∣ ≡⟨ cong (λ v → ∣ v + windSpeed s' ∣) (x∙yz≈zx∙y (position s') (velocity s) dv) ⟩
∣ dv + position s' + velocity s + windSpeed s' ∣ ≡⟨ cong ∣_∣ (sym (p+q-q≡p (dv + position s' + velocity s + windSpeed s') (position s))) ⟩
∣ dv + position s' + velocity s + windSpeed s' + position s - position s ∣ ≡⟨ cong (λ v → ∣ v + position s - position s ∣) (+-assoc (dv + position s') (velocity s) (windSpeed s')) ⟩
∣ dv + position s' + (velocity s + windSpeed s') + position s - position s ∣ ≡⟨ cong (λ v → ∣ v - position s ∣) (+-assoc (dv + position s') (velocity s + windSpeed s') (position s)) ⟩
∣ dv + position s' + (velocity s + windSpeed s' + position s) - position s ∣ ≡⟨ cong (λ v → ∣ dv + position s' + v - position s ∣) (xy∙z≈zx∙y (velocity s) (windSpeed s') (position s)) ⟩
∣ dv + position s' + (position s + velocity s + windSpeed s') - position s ∣ ≡⟨⟩
∣ dv + position s' + position s' - position s ∣ ≡⟨ cong (λ v → ∣ v - position s ∣) (+-assoc dv (position s') (position s')) ⟩
∣ dv + (position s' + position s') - position s ∣ ≡⟨ cong (λ v → ∣ dv + v - position s ∣) (sym (2*x≡x+x (position s'))) ⟩
∣ dv + 2ℚ * position s' - position s ∣ <⟨ controller-lem (position s') (position s) s'-safe ⟩
2ℚ ∎
finalState-good : ∀ xs → All LowWind xs → Good (finalState xs)
finalState-good [] [] = initialState-good
finalState-good (x ∷ xs) (px ∷ pxs) = good⇒nextGood x px (finalState xs) (finalState-good xs pxs)
finalState-safe : ∀ xs → All LowWind xs → Safe (finalState xs)
finalState-safe [] [] = initialState-safe
finalState-safe (x ∷ xs) (px ∷ pxs) = good⇒nextSafe x px (finalState xs) (finalState-good xs pxs)
| {
"alphanum_fraction": 0.5424405485,
"avg_line_length": 38.1523178808,
"ext": "agda",
"hexsha": "174851cb62043062127a61008e290c832c6ea967",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-11-16T14:30:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-03-15T15:22:31.000Z",
"max_forks_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "wenkokke/vehicle",
"max_forks_repo_path": "examples/network/windController/safety.agda",
"max_issues_count": 53,
"max_issues_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_issues_repo_issues_event_max_datetime": "2021-12-15T22:42:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-16T07:26:42.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "wenkokke/vehicle",
"max_issues_repo_path": "examples/network/windController/safety.agda",
"max_line_length": 189,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "wenkokke/vehicle",
"max_stars_repo_path": "examples/network/windController/safety.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T01:35:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-24T05:55:15.000Z",
"num_tokens": 2012,
"size": 5761
} |
------------------------------------------------------------------------
-- Finite maps, i.e. lookup tables (currently only some type
-- signatures)
------------------------------------------------------------------------
module Data.Map where
open import Relation.Nullary
open import Relation.Binary
open import Data.List as L using (List)
open import Data.Product
module Map₁ (key-dto : DecTotalOrder) (elem-s : Setoid) where
open DecTotalOrder key-dto renaming (carrier to key)
open Setoid elem-s renaming (carrier to elem; _≈_ to _≗_)
infixr 6 _∪_
infix 5 _∈?_
infix 4 _∈_ _|≈|_
abstract postulate decSetoid : DecSetoid
Map : Set
Map = Setoid.carrier (DecSetoid.setoid decSetoid)
_|≈|_ : Rel Map
_|≈|_ = Setoid._≈_ (DecSetoid.setoid decSetoid)
abstract
postulate
empty : Map
insert : key → elem → Map → Map
_∪_ : Map → Map → Map
_∈_ : key → Map → Set
_↦_∈_ : key → elem → Map → Set
data LookupResult (k : key) (s : Map) : Set where
found : (e : elem) (k↦e∈s : k ↦ e ∈ s) → LookupResult k s
notFound : (k∉s : ¬ k ∈ s) → LookupResult k s
abstract
postulate
_∈?_ : (k : key) → (s : Map) → LookupResult k s
toList : Map → List (key × elem)
postulate
prop-∈₁ : ∀ {x v s} → x ↦ v ∈ s → x ∈ s
prop-∈₂ : ∀ {x s} → x ∈ s → Σ elem (λ v → x ↦ v ∈ s)
prop-∈₃ : ∀ {x v w s} → x ↦ v ∈ s → x ↦ w ∈ s → v ≗ w
prop-∈-insert₁ : ∀ {x y v w s} →
x ≈ y → v ≗ w → x ↦ v ∈ insert y w s
prop-∈-insert₂ : ∀ {x y v w s} →
¬ x ≈ y → x ↦ v ∈ s → x ↦ v ∈ insert y w s
prop-∈-insert₃ : ∀ {x y v w s} →
¬ x ≈ y → x ↦ v ∈ insert y w s → x ↦ v ∈ s
prop-∈-empty : ∀ {x} → ¬ x ∈ empty
prop-∈-∪ : ∀ {x s₁ s₂} → x ∈ s₁ → x ∈ s₁ ∪ s₂
prop-∪₁ : ∀ {s₁ s₂} → s₁ ∪ s₂ |≈| s₂ ∪ s₁
prop-∪₂ : ∀ {s₁ s₂ s₃} → s₁ ∪ (s₂ ∪ s₃) |≈| (s₁ ∪ s₂) ∪ s₃
prop-∈-|≈|₁ : ∀ {x} → (λ s → x ∈ s) Respects _|≈|_
prop-∈-|≈|₂ : ∀ {x v} → (λ s → x ↦ v ∈ s) Respects _|≈|_
prop-∈-≈₁ : ∀ {s} → (λ x → x ∈ s) Respects _≈_
prop-∈-≈₂ : ∀ {v s} → (λ x → x ↦ v ∈ s) Respects _≈_
prop-∈-≗ : ∀ {x s} → (λ v → x ↦ v ∈ s) Respects _≗_
-- TODO: Postulates for toList.
singleton : key → elem → Map
singleton k v = insert k v empty
⋃_ : List Map → Map
⋃_ = L.foldr _∪_ empty
fromList : List (key × elem) → Map
fromList = L.foldr (uncurry insert) empty
open Map₁ public renaming (Map to _⇰_)
| {
"alphanum_fraction": 0.4748402556,
"avg_line_length": 29.8095238095,
"ext": "agda",
"hexsha": "9f750245d487806e800a1de571c29747c8e42def",
"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/Map.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/Map.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/Map.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": 1014,
"size": 2504
} |
module List.Permutation.Alternative (A : Set) where
open import Data.List
data _∼_ : List A → List A → Set where
∼refl : {xs : List A}
→ xs ∼ xs
∼trans : {xs ys zs : List A}
→ xs ∼ ys
→ ys ∼ zs
→ xs ∼ zs
∼head : {xs ys : List A}(x : A)
→ xs ∼ ys
→ (x ∷ xs) ∼ (x ∷ ys)
∼swap : {xs ys : List A}{x y : A}
→ (x ∷ y ∷ xs) ∼ ys
→ (y ∷ x ∷ xs) ∼ ys
| {
"alphanum_fraction": 0.349609375,
"avg_line_length": 26.9473684211,
"ext": "agda",
"hexsha": "cc6da3a894dc4c47a0e9f9d18eda71eb33ae6c83",
"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/List/Permutation/Alternative.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/List/Permutation/Alternative.agda",
"max_line_length": 51,
"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/List/Permutation/Alternative.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": 177,
"size": 512
} |
module Data.Binary.Tests.Semantics where
open import Data.Binary.Definitions
open import Data.Binary.Operations.Semantics
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.List as List using (List; _∷_; [])
open import Relation.Binary.PropositionalEquality
prop : ℕ → Set
prop n = let xs = List.upTo n in List.map (λ x → ⟦ ⟦ x ⇑⟧ ⇓⟧ ) xs ≡ xs
_ : prop 50
_ = refl
| {
"alphanum_fraction": 0.7146596859,
"avg_line_length": 25.4666666667,
"ext": "agda",
"hexsha": "5fae7cdcb7a47f3332895d4761e89b732e33108d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Binary/Tests/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-binary",
"max_issues_repo_path": "Data/Binary/Tests/Semantics.agda",
"max_line_length": 70,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Binary/Tests/Semantics.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 119,
"size": 382
} |
module CTL.Modalities.AF where
open import FStream.Core
open import Library
-- Certainly sometime : s₀ ⊧ φ ⇔ ∀ s₀ R s₁ R ... ∃ i . sᵢ ⊧ φ
-- TODO Unclear whether this needs sizes
data AF' {ℓ₁ ℓ₂} {C : Container ℓ₁}
(props : FStream' C (Set ℓ₂)) : Set (ℓ₁ ⊔ ℓ₂) where
alreadyA : head props → AF' props
notYetA : A (fmap AF' (inF (tail props))) → AF' props
open AF' public
AF : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)
AF props = APred AF' (inF props)
mutual
AFₛ' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream' C (Set ℓ₂) → FStream' {i} C (Set (ℓ₁ ⊔ ℓ₂))
head (AFₛ' props) = AF' props
tail (AFₛ' props) = AFₛ (tail props)
AFₛ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → FStream {i} C (Set (ℓ₁ ⊔ ℓ₂))
inF (AFₛ props) = fmap AFₛ' (inF props)
| {
"alphanum_fraction": 0.5889570552,
"avg_line_length": 30.1851851852,
"ext": "agda",
"hexsha": "7d9fc1e188183614605426e61ca2d388a815fbc9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "zimbatm/condatis",
"max_forks_repo_path": "CTL/Modalities/AF.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "zimbatm/condatis",
"max_issues_repo_path": "CTL/Modalities/AF.agda",
"max_line_length": 61,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Aerate/condatis",
"max_stars_repo_path": "CTL/Modalities/AF.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z",
"num_tokens": 362,
"size": 815
} |
-- Andreas, 2011-04-26
{-# OPTIONS --universe-polymorphism #-}
module Issue411 where
import Common.Irrelevance
record A : Set₁ where
field
.foo : Set
-- this yielded a panic "-1 not a valid deBruijn index" due to old code for assignS | {
"alphanum_fraction": 0.7148760331,
"avg_line_length": 26.8888888889,
"ext": "agda",
"hexsha": "04bd6cdff0ff24a03f0ffb4fa5db934befb7eb72",
"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/succeed/Issue411.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/Issue411.agda",
"max_line_length": 83,
"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/Issue411.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": 71,
"size": 242
} |
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel)
open import Algebra.Structures.Bundles.Field
module Algebra.Linear.Morphism.Definitions
{k ℓᵏ} (K : Field k ℓᵏ)
{a} (A : Set a)
{b} (B : Set b)
{ℓ} (_≈_ : Rel B ℓ)
where
open import Algebra.Linear.Core
open import Function
import Algebra.Morphism as Morphism
open Morphism.Definitions A B _≈_
private
K' : Set k
K' = Field.Carrier K
Linear : Morphism
-> VectorAddition A -> ScalarMultiplication K' A
-> VectorAddition B -> ScalarMultiplication K' B
-> Set _
Linear ⟦_⟧ _+₁_ _∙₁_ _+₂_ _∙₂_ =
∀ (a b : K') (u v : A) ->
⟦ (a ∙₁ u) +₁ (b ∙₁ v) ⟧ ≈ ((a ∙₂ ⟦ u ⟧) +₂ (b ∙₂ ⟦ v ⟧))
ScalarHomomorphism : Morphism
-> ScalarMultiplication K' A
-> ScalarMultiplication K' B
-> Set _
ScalarHomomorphism ⟦_⟧ _∙_ _∘_ = ∀ (c : K') (u : A) -> ⟦ c ∙ u ⟧ ≈ (c ∘ ⟦ u ⟧)
| {
"alphanum_fraction": 0.5686695279,
"avg_line_length": 25.1891891892,
"ext": "agda",
"hexsha": "fba40f9a8266e2e0089b07b0e1534ba4d92a718c",
"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": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Morphism/Definitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"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": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Morphism/Definitions.agda",
"max_line_length": 78,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Morphism/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 344,
"size": 932
} |
module SafeFlagPrimTrustMe where
open import Agda.Builtin.Equality
private
primitive
primTrustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y
| {
"alphanum_fraction": 0.6879432624,
"avg_line_length": 17.625,
"ext": "agda",
"hexsha": "2de86c90bd28fac9380b0cac29530a2a472dde90",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/SafeFlagPrimTrustMe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/SafeFlagPrimTrustMe.agda",
"max_line_length": 52,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/SafeFlagPrimTrustMe.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 48,
"size": 141
} |
-- statically checked sorted lists
-- see http://www2.tcs.ifi.lmu.de/~abel/DepTypes.pdf
module SortedList where
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Data.Bool using (Bool; true; false)
----------------------------------------------------------------------
-- Curry-Howard stuff
Proposition = Set
-- intentionally blank. signifies the empty set in the type system.
data Absurd : Proposition where
-- tt = trivially true
data Truth : Proposition where
tt : Truth
-- ∧ = conjunction
data _∧_ (A B : Proposition) : Proposition where
_,_ : A → B → A ∧ B
fst : {A B : Proposition} → A ∧ B → A
fst (a , b) = a
snd : {A B : Proposition} → A ∧ B → B
snd (a , b) = b
-- Cartesian product = conjunction
_×_ = _∧_
-- ∨ = disjunction
data _∨_ (A B : Proposition) : Proposition where
inl : A → A ∨ B
inr : B → A ∨ B
-- given: A or B is true, A implies C, B implies C. then C is true.
case : {A B C : Proposition} → A ∨ B → (A → C) → (B → C) → C
case (inl a) f g = f a
case (inr b) f g = g b
-- map booleans to propositions by mapping true to Truth and false to Absurd
True : Bool → Proposition
True true = Truth
True false = Absurd
----------------------------------------------------------------------
_≤_ : ℕ → ℕ → Bool
zero ≤ n = true
suc m ≤ zero = false
suc m ≤ suc n = m ≤ n
-- proposition: ≤ is reflexive. proof: induction.
refl≤ : (n : ℕ) → True (n ≤ n)
refl≤ zero = tt
refl≤ (suc n) = refl≤ n
----------------------------------------------------------------------
data SortedList : ℕ → Set where
∅ : SortedList zero
⋉ : {n : ℕ} (m : ℕ) → True (n ≤ m) → SortedList n → SortedList m
-- the arguments to ⋉ are
-- m : a natural number to prepend to the given sorted list xs
-- p : a proof that m (the new head) is ≥ head xs
-- xs : a list such that head xs = n
-- for constant natural numbers, proofs that n ≤ m are trivial since
-- ≤ is decidable; this is why we pass in `tt` in the examples below
-- examples:
one : ℕ
one = suc zero
s1 = ⋉ one tt (⋉ zero tt ∅)
-- s2 = ⋉ zero tt (⋉ one tt ∅) -- fails statically, as desired
s3 = ⋉ one tt s1 -- normal form: ⋉ 1 tt (⋉ 1 tt (⋉ 0 tt ∅))
s4 = ⋉ (suc one) tt s1 -- normal form: ⋉ 2 tt (⋉ 1 tt (⋉ 0 tt ∅))
| {
"alphanum_fraction": 0.5555555556,
"avg_line_length": 26.0470588235,
"ext": "agda",
"hexsha": "815d3a9f967f4ac1f6d3bd8f1ebc2b6a4cb6a3cf",
"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": "e70ef1ea1891cff6157fba682a61c6f227a26fd8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sshastry/agda-examples",
"max_forks_repo_path": "SortedList.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e70ef1ea1891cff6157fba682a61c6f227a26fd8",
"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": "sshastry/agda-examples",
"max_issues_repo_path": "SortedList.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e70ef1ea1891cff6157fba682a61c6f227a26fd8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "sshastry/agda-examples",
"max_stars_repo_path": "SortedList.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 722,
"size": 2214
} |
module 110-natural-model where
open import 010-false-true
open import 020-equivalence
open import 100-natural
-- We prove that there is a model of the naturals within Agda's lambda
-- calculus. This also shows that the Peano axioms are consistent.
data ℕ : Set where
zero : ℕ
suc : ℕ -> ℕ
thm-ℕ-is-natural : Natural zero suc _≡_
thm-ℕ-is-natural = record {
equiv = thm-≡-is-equivalence;
sucn!=zero = sucn!=zero;
sucinjective = sucinjective;
cong = cong;
induction = induction
}
where
sucn!=zero : ∀ {r} -> suc r ≡ zero -> False
sucn!=zero ()
sucinjective : ∀ {r s} -> suc r ≡ suc s -> r ≡ s
sucinjective refl = refl
cong : ∀ {r s} -> r ≡ s -> suc r ≡ suc s
cong refl = refl
-- This is the only tricky bit: proving the principle of induction.
induction : (p : ℕ -> Set) -> p zero -> (∀ n -> p n -> p (suc n)) -> ∀ n -> p n
-- We first prove that p n holds for n equal to zero. This is just
-- the base case.
induction p base hypothesis zero = base
-- Then we prove that p (suc n) holds, using induction on n, that is,
-- we may assume that p n is proven, or more precisely, that
-- "induction p base hypothesis n" is a proof of p n.
induction p base hypothesis (suc n) =
hypothesis n (induction p base hypothesis n)
| {
"alphanum_fraction": 0.6357361963,
"avg_line_length": 32.6,
"ext": "agda",
"hexsha": "e524375942c9c7a1700dfd574c911c429137b6e3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mcmtroffaes/agda-proofs",
"max_forks_repo_path": "110-natural-model.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mcmtroffaes/agda-proofs",
"max_issues_repo_path": "110-natural-model.agda",
"max_line_length": 83,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mcmtroffaes/agda-proofs",
"max_stars_repo_path": "110-natural-model.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z",
"num_tokens": 401,
"size": 1304
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Int
open import lib.types.Group
open import lib.types.List
open import lib.types.Word
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
open import lib.groups.FreeAbelianGroup
open import lib.groups.GeneratedGroup
open import lib.types.SetQuotient
module lib.groups.Int where
ℤ-group-structure : GroupStructure ℤ
ℤ-group-structure = record
{ ident = 0
; inv = ℤ~
; comp = _ℤ+_
; unit-l = ℤ+-unit-l
; assoc = ℤ+-assoc
; inv-l = ℤ~-inv-l
}
ℤ-group : Group₀
ℤ-group = group _ ℤ-group-structure
ℤ-group-is-abelian : is-abelian ℤ-group
ℤ-group-is-abelian = ℤ+-comm
ℤ-abgroup : AbGroup₀
ℤ-abgroup = ℤ-group , ℤ-group-is-abelian
private
module OneGeneratorFreeAbGroup = FreeAbelianGroup Unit
OneGenFreeAbGroup : AbGroup lzero
OneGenFreeAbGroup = OneGeneratorFreeAbGroup.FreeAbGroup
private
module OneGenFreeAbGroup = AbGroup OneGenFreeAbGroup
ℤ-iso-FreeAbGroup-Unit : ℤ-group ≃ᴳ OneGenFreeAbGroup.grp
ℤ-iso-FreeAbGroup-Unit = ≃-to-≃ᴳ (equiv to from to-from from-to) to-pres-comp where
open OneGeneratorFreeAbGroup
module F = Freeness ℤ-abgroup
to : Group.El ℤ-group → OneGenFreeAbGroup.El
to = OneGenFreeAbGroup.exp qw[ inl unit :: nil ]
from : OneGenFreeAbGroup.El → Group.El ℤ-group
from = GroupHom.f (F.extend (λ _ → 1))
abstract
to-pres-comp = OneGenFreeAbGroup.exp-+ qw[ inl unit :: nil ]
to-from' : ∀ l → to (Word-extendᴳ ℤ-group (λ _ → 1) l) == qw[ l ]
to-from' nil = idp
to-from' (inl unit :: nil) = idp
to-from' (inl unit :: l@(_ :: _)) =
OneGenFreeAbGroup.exp-succ qw[ inl unit :: nil ] (Word-extendᴳ ℤ-group (λ _ → 1) l)
∙ ap (OneGenFreeAbGroup.comp qw[ inl unit :: nil ]) (to-from' l)
to-from' (inr unit :: nil) = idp
to-from' (inr unit :: l@(_ :: _)) =
OneGenFreeAbGroup.exp-pred qw[ inl unit :: nil ] (Word-extendᴳ ℤ-group (λ _ → 1) l)
∙ ap (OneGenFreeAbGroup.comp qw[ inr unit :: nil ]) (to-from' l)
to-from : ∀ fs → to (from fs) == fs
to-from = QuotWord-elim to-from' (λ _ → prop-has-all-paths-↓)
from-to : ∀ z → from (to z) == z
from-to (pos 0) = idp
from-to (pos 1) = idp
from-to (negsucc 0) = idp
from-to (pos (S (S n))) =
GroupHom.pres-comp (F.extend (λ _ → 1))
qw[ inl unit :: nil ] (OneGenFreeAbGroup.exp qw[ inl unit :: nil ] (pos (S n)))
∙ ap succ (from-to (pos (S n)))
from-to (negsucc (S n)) =
GroupHom.pres-comp (F.extend (λ _ → 1))
qw[ inr unit :: nil ] (OneGenFreeAbGroup.exp qw[ inl unit :: nil ] (negsucc n))
∙ ap pred (from-to (negsucc n))
exp-shom : ∀ {i} {GEl : Type i} (GS : GroupStructure GEl) (g : GEl) → ℤ-group-structure →ᴳˢ GS
exp-shom GS g = group-structure-hom (GroupStructure.exp GS g) (GroupStructure.exp-+ GS g)
exp-hom : ∀ {i} (G : Group i) (g : Group.El G) → ℤ-group →ᴳ G
exp-hom G g = group-hom (Group.exp G g) (Group.exp-+ G g)
| {
"alphanum_fraction": 0.6458752515,
"avg_line_length": 33.8863636364,
"ext": "agda",
"hexsha": "4795b27b5ebf3bef970ff6e7911dbb26d6ad15b9",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/groups/Int.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/groups/Int.agda",
"max_line_length": 94,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/groups/Int.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": 1051,
"size": 2982
} |
module _ where
open import Common.Prelude
print : Float → IO Unit
print x = putStrLn (primShowFloat x)
printB : Bool → IO Unit
printB true = putStrLn "true"
printB false = putStrLn "false"
_/_ = primFloatDiv
_==_ = primFloatEquality
_=N=_ = primFloatNumericalEquality
_<N_ = primFloatNumericalLess
_<_ = primFloatLess
NaN : Float
NaN = 0.0 / 0.0
-NaN : Float
-NaN = primFloatNegate NaN
Inf : Float
Inf = 1.0 / 0.0
-Inf : Float
-Inf = -1.0 / 0.0
sin = primSin
cos = primCos
tan = primTan
asin = primASin
acos = primACos
atan = primATan
atan2 = primATan2
isZero : Float → String
isZero 0.0 = "pos"
isZero -0.0 = "neg"
isZero _ = "nonzero"
main : IO Unit
main =
putStr "123.4 = " ,, print 123.4 ,,
putStr "-42.9 = " ,, print -42.9 ,,
-- Disabled because Issue #2359.
-- putStr "1.0 = " ,, print 1.0 ,,
-- putStr "-0.0 = " ,, print -0.0 ,,
putStr "NaN = " ,, print NaN ,,
putStr "Inf = " ,, print Inf ,,
putStr "-Inf = " ,, print -Inf ,,
putStr "Inf == Inf = " ,, printB (Inf == Inf) ,,
-- Issues #2155 and #2194.
putStr "NaN == NaN = " ,, printB (NaN == NaN) ,,
-- Issue #2194.
putStr "NaN == -NaN = " ,, printB (NaN == (primFloatNegate NaN)) ,,
-- Issue #2169.
putStr "0.0 == -0.0 = " ,, printB (0.0 == -0.0) ,,
-- Issue #2216
putStr "isZero 0.0 = " ,, putStrLn (isZero 0.0) ,,
putStr "isZero -0.0 = " ,, putStrLn (isZero -0.0) ,,
putStr "isZero 1.0 = " ,, putStrLn (isZero 1.0) ,,
-- numerical equality
putStr "NaN =N= NaN = " ,, printB (NaN =N= NaN) ,,
putStr "0.0 =N= -0.0 = " ,, printB (0.0 =N= -0.0) ,,
putStr "0.0 =N= 12.0 = " ,, printB (0.0 =N= 12.0) ,,
putStr "NaN < -Inf = " ,, printB (NaN < -Inf) ,,
putStr "-Inf < NaN = " ,, printB (-Inf < NaN) ,,
putStr "0.0 < -0.0 = " ,, printB (0.0 < -0.0) ,,
putStr "-0.0 < 0.0 = " ,, printB (-0.0 < 0.0) ,,
-- Issue #2208.
putStr "NaN < NaN = " ,, printB (NaN < NaN) ,,
putStr "-NaN < -NaN = " ,, printB (-NaN < -NaN) ,,
putStr "NaN < -NaN = " ,, printB (NaN < -NaN) ,,
putStr "-NaN < NaN = " ,, printB (-NaN < NaN) ,,
putStr "NaN < -5.0 = " ,, printB (NaN < -5.0) ,,
putStr "-5.0 < NaN = " ,, printB (-5.0 < NaN) ,,
putStr "NaN <N -Inf = " ,, printB (NaN <N -Inf) ,,
putStr "-Inf <N NaN = " ,, printB (-Inf <N NaN) ,,
putStr "0.0 <N -0.0 = " ,, printB (0.0 <N -0.0) ,,
putStr "-0.0 <N 0.0 = " ,, printB (-0.0 <N 0.0) ,,
-- Issue #2208.
putStr "NaN <N NaN = " ,, printB (NaN <N NaN) ,,
putStr "-NaN <N -NaN = " ,, printB (-NaN <N -NaN) ,,
putStr "NaN <N -NaN = " ,, printB (NaN <N -NaN) ,,
putStr "-NaN <N NaN = " ,, printB (-NaN <N NaN) ,,
putStr "NaN <N -5.0 = " ,, printB (NaN <N -5.0) ,,
putStr "-5.0 <N NaN = " ,, printB (-5.0 <N NaN) ,,
putStr "e = " ,, print (primExp 1.0) ,,
putStr "sin (asin 0.6) = " ,, print (sin (asin 0.6)) ,,
putStr "cos (acos 0.6) = " ,, print (cos (acos 0.6)) ,,
putStr "tan (atan 0.4) = " ,, print (tan (atan 0.4)) ,,
putStr "tan (atan2 0.4 1.0) = " ,, print (tan (atan2 0.4 1.0)) ,,
return unit
| {
"alphanum_fraction": 0.5114775299,
"avg_line_length": 28.376146789,
"ext": "agda",
"hexsha": "52ae6865f280d4e4433fa501f4b04c0c35d2b4f6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/Floats.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Compiler/simple/Floats.agda",
"max_line_length": 69,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Compiler/simple/Floats.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 1323,
"size": 3093
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Structures.Bundles.Field
module Algebra.Linear.Morphism
{k ℓᵏ} (K : Field k ℓᵏ)
where
open import Algebra.Linear.Morphism.Definitions K public
open import Algebra.Linear.Morphism.Bundles K public
open import Algebra.Linear.Morphism.VectorSpace K public
| {
"alphanum_fraction": 0.7680250784,
"avg_line_length": 26.5833333333,
"ext": "agda",
"hexsha": "d5a326c6b68eb0f98ec84fc7f31d8ed7a1aa68ca",
"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": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Morphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"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": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Morphism.agda",
"max_line_length": 56,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Morphism.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 81,
"size": 319
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Reflection.StrictEquiv where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv.Base
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.List.Base
open import Cubical.Data.Unit.Base
import Agda.Builtin.Reflection as R
open import Cubical.Reflection.Base
strictEquivClauses : R.Term → R.Term → List R.Clause
strictEquivClauses f g =
R.clause []
(R.proj (quote fst) v∷ [])
f
∷ R.clause []
(R.proj (quote snd) v∷ R.proj (quote equiv-proof) v∷ [])
(R.def (quote strictContrFibers) (g v∷ []))
∷ []
strictEquivTerm : R.Term → R.Term → R.Term
strictEquivTerm f g = R.pat-lam (strictEquivClauses f g) []
strictEquivMacro : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ (A → B) → (B → A) → R.Term → R.TC Unit
strictEquivMacro {A = A} {B} f g hole =
R.quoteTC (A ≃ B) >>= λ equivTy →
R.checkType hole equivTy >>
R.quoteTC f >>= λ `f` →
R.quoteTC g >>= λ `g` →
R.unify (strictEquivTerm `f` `g`) hole
strictIsoToEquivMacro : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ Iso A B → R.Term → R.TC Unit
strictIsoToEquivMacro isom =
strictEquivMacro (Iso.fun isom) (Iso.inv isom)
-- For use with unquoteDef
defStrictEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ R.Name → (A → B) → (B → A) → R.TC Unit
defStrictEquiv idName f g =
R.quoteTC f >>= λ `f` →
R.quoteTC g >>= λ `g` →
R.defineFun idName (strictEquivClauses `f` `g`)
defStrictIsoToEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ R.Name → Iso A B → R.TC Unit
defStrictIsoToEquiv idName isom =
defStrictEquiv idName (Iso.fun isom) (Iso.inv isom)
-- For use with unquoteDef
declStrictEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ R.Name → (A → B) → (B → A) → R.TC Unit
declStrictEquiv {A = A} {B = B} idName f g =
R.quoteTC (A ≃ B) >>= λ ty →
R.declareDef (varg idName) ty >>
defStrictEquiv idName f g
declStrictIsoToEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ R.Name → Iso A B → R.TC Unit
declStrictIsoToEquiv idName isom =
declStrictEquiv idName (Iso.fun isom) (Iso.inv isom)
macro
-- (f : A → B) → (g : B → A) → (A ≃ B)
-- Assumes that `f` and `g` are inverse up to definitional equality
strictEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ (A → B) → (B → A) → R.Term → R.TC Unit
strictEquiv = strictEquivMacro
-- (isom : Iso A B) → (A ≃ B)
-- Assumes that the functions defining `isom` are inverse up to definitional equality
strictIsoToEquiv : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
→ Iso A B → R.Term → R.TC Unit
strictIsoToEquiv = strictIsoToEquivMacro
| {
"alphanum_fraction": 0.6320790574,
"avg_line_length": 32.0853658537,
"ext": "agda",
"hexsha": "d3e14edf8536d7fcd3a08b1adfdde0fd117d9877",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Reflection/StrictEquiv.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Reflection/StrictEquiv.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Reflection/StrictEquiv.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 987,
"size": 2631
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.ShapeView {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Agda.Primitive
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties.Escape
open import Definition.LogicalRelation.Properties.Reflexivity
open import Tools.Embedding
open import Tools.Product
open import Tools.Empty using (⊥; ⊥-elim ; ⊥-elimω)
import Tools.PropositionalEquality as PE
-- Type for maybe embeddings of reducible types
data MaybeEmb (l : TypeLevel) (⊩⟨_⟩ : TypeLevel → Set) : Set where
noemb : ⊩⟨ l ⟩ → MaybeEmb l ⊩⟨_⟩
emb : ∀ {l′} → l′ < l → MaybeEmb l′ ⊩⟨_⟩ → MaybeEmb l ⊩⟨_⟩
-- Specific reducible types with possible embedding
_⊩⟨_⟩U : (Γ : Con Term) (l : TypeLevel) → Set
Γ ⊩⟨ l ⟩U = MaybeEmb l (λ l′ → Γ ⊩′⟨ l′ ⟩U)
_⊩⟨_⟩ℕ_ : (Γ : Con Term) (l : TypeLevel) (A : Term) → Set
Γ ⊩⟨ l ⟩ℕ A = MaybeEmb l (λ l′ → Γ ⊩ℕ A)
_⊩⟨_⟩ne_ : (Γ : Con Term) (l : TypeLevel) (A : Term) → Set
Γ ⊩⟨ l ⟩ne A = MaybeEmb l (λ l′ → Γ ⊩ne A)
data _⊩⟨_⟩Π_ (Γ : Con Term) (l : TypeLevel) (A : Term) : Setω where
noemb : Γ ⊩′⟨ l ⟩Π A → Γ ⊩⟨ l ⟩Π A
emb : ∀ {l′} → l′ < l → Γ ⊩⟨ l′ ⟩Π A → Γ ⊩⟨ l ⟩Π A
-- -- Construct a general reducible type from a specific
U-intr : ∀ {Γ l} → Γ ⊩⟨ l ⟩U → Γ ⊩⟨ l ⟩ U
U-intr (noemb (Uᵣ l′ l< ⊢Γ)) = Uᵣ′ l′ l< ⊢Γ
U-intr (emb 0<1 x) = emb′ 0<1 (U-intr x)
ℕ-intr : ∀ {A Γ l} → Γ ⊩⟨ l ⟩ℕ A → Γ ⊩⟨ l ⟩ A
ℕ-intr (noemb x) = ℕᵣ x
ℕ-intr (emb 0<1 x) = emb′ 0<1 (ℕ-intr x)
ne-intr : ∀ {A Γ l} → Γ ⊩⟨ l ⟩ne A → Γ ⊩⟨ l ⟩ A
ne-intr (noemb x) = LRPack _ _ _ (LRne x)
ne-intr (emb 0<1 x) = emb′ 0<1 (ne-intr x)
Π-intr : ∀ {A Γ l} → Γ ⊩⟨ l ⟩Π A → Γ ⊩⟨ l ⟩ A
Π-intr (noemb x) = LRPack _ _ _ (LRΠ x)
Π-intr (emb 0<1 x) = emb′ 0<1 (Π-intr x)
-- -- Construct a specific reducible type from a general with some criterion
U-elim : ∀ {Γ l} → Γ ⊩⟨ l ⟩ U → Γ ⊩⟨ l ⟩U
U-elim (Uᵣ′ l′ l< ⊢Γ) = noemb (Uᵣ l′ l< ⊢Γ)
U-elim (ℕᵣ D) = ⊥-elim (U≢ℕ (whnfRed* (red D) Uₙ))
U-elim (ne′ K D neK K≡K) = ⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))
U-elim (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = ⊥-elim (U≢Π (whnfRed* (red D) Uₙ))
U-elim (emb′ 0<1 x) with U-elim x
U-elim (emb′ 0<1 x) | noemb x₁ = emb 0<1 (noemb x₁)
U-elim (emb′ 0<1 x) | emb () x₁
ℕ-elim′ : ∀ {A Γ l} → Γ ⊢ A ⇒* ℕ → Γ ⊩⟨ l ⟩ A → Γ ⊩⟨ l ⟩ℕ A
ℕ-elim′ D (Uᵣ′ l′ l< ⊢Γ) = ⊥-elim (U≢ℕ (whrDet* (id (Uⱼ ⊢Γ) , Uₙ) (D , ℕₙ)))
ℕ-elim′ D (ℕᵣ D′) = noemb D′
ℕ-elim′ D (ne′ K D′ neK K≡K) =
⊥-elim (ℕ≢ne neK (whrDet* (D , ℕₙ) (red D′ , ne neK)))
ℕ-elim′ D (Πᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) =
⊥-elim (ℕ≢Π (whrDet* (D , ℕₙ) (red D′ , Πₙ)))
ℕ-elim′ D (emb′ 0<1 x) with ℕ-elim′ D x
ℕ-elim′ D (emb′ 0<1 x) | noemb x₁ = emb 0<1 (noemb x₁)
ℕ-elim′ D (emb′ 0<1 x) | emb () x₂
ℕ-elim : ∀ {Γ l} → Γ ⊩⟨ l ⟩ ℕ → Γ ⊩⟨ l ⟩ℕ ℕ
ℕ-elim [ℕ] = ℕ-elim′ (id (escape [ℕ])) [ℕ]
ne-elim′ : ∀ {A Γ l K} → Γ ⊢ A ⇒* K → Neutral K → Γ ⊩⟨ l ⟩ A → Γ ⊩⟨ l ⟩ne A
ne-elim′ D neK (Uᵣ′ l′ l< ⊢Γ) =
⊥-elim (U≢ne neK (whrDet* (id (Uⱼ ⊢Γ) , Uₙ) (D , ne neK)))
ne-elim′ D neK (ℕᵣ D′) = ⊥-elim (ℕ≢ne neK (whrDet* (red D′ , ℕₙ) (D , ne neK)))
ne-elim′ D neK (ne′ K D′ neK′ K≡K) = noemb (ne K D′ neK′ K≡K)
ne-elim′ D neK (Πᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) =
⊥-elim (Π≢ne neK (whrDet* (red D′ , Πₙ) (D , ne neK)))
ne-elim′ D neK (emb′ 0<1 x) with ne-elim′ D neK x
ne-elim′ D neK (emb′ 0<1 x) | noemb x₁ = emb 0<1 (noemb x₁)
ne-elim′ D neK (emb′ 0<1 x) | emb () x₂
ne-elim : ∀ {Γ l K} → Neutral K → Γ ⊩⟨ l ⟩ K → Γ ⊩⟨ l ⟩ne K
ne-elim neK [K] = ne-elim′ (id (escape [K])) neK [K]
Π-elim′ : ∀ {A Γ F G l} → Γ ⊢ A ⇒* Π F ▹ G → Γ ⊩⟨ l ⟩ A → Γ ⊩⟨ l ⟩Π A
Π-elim′ D (Uᵣ′ l′ l< ⊢Γ) = ⊥-elimω (U≢Π (whrDet* (id (Uⱼ ⊢Γ) , Uₙ) (D , Πₙ)))
Π-elim′ D (ℕᵣ D′) = ⊥-elimω (ℕ≢Π (whrDet* (red D′ , ℕₙ) (D , Πₙ)))
Π-elim′ D (ne′ K D′ neK K≡K) =
⊥-elimω (Π≢ne neK (whrDet* (D , Πₙ) (red D′ , ne neK)))
Π-elim′ D (Πᵣ′ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) =
noemb (Πᵣ F G D′ ⊢F ⊢G A≡A [F] [G] G-ext)
Π-elim′ D (emb′ 0<1 x) with Π-elim′ D x
Π-elim′ D (emb′ 0<1 x) | noemb x₁ = emb 0<1 (noemb x₁)
Π-elim′ D (emb′ 0<1 x) | emb () x₂
Π-elim : ∀ {Γ F G l} → Γ ⊩⟨ l ⟩ Π F ▹ G → Γ ⊩⟨ l ⟩Π Π F ▹ G
Π-elim [Π] = Π-elim′ (id (escape [Π])) [Π]
-- Extract a type and a level from a maybe embedding
extractMaybeEmb : ∀ {l ⊩⟨_⟩} → MaybeEmb l ⊩⟨_⟩ → ∃ λ l′ → ⊩⟨ l′ ⟩
extractMaybeEmb (noemb x) = _ , x
extractMaybeEmb (emb 0<1 x) = extractMaybeEmb x
extractMaybeEmbΠl : ∀ {Γ A l} → Γ ⊩⟨ l ⟩Π A → TypeLevel
extractMaybeEmbΠl {l = l} (noemb x) = l
extractMaybeEmbΠl (emb 0<1 x) = ⁰
extractMaybeEmbΠ : ∀ {Γ A l} → ([A] : Γ ⊩⟨ l ⟩Π A) → Γ ⊩′⟨ extractMaybeEmbΠl [A] ⟩Π A
extractMaybeEmbΠ {l = l} (noemb x) = x
extractMaybeEmbΠ (emb 0<1 (noemb x)) = x
-- emb, but with a propositional equality for the target level
emb″ : ∀ {Γ A} (l : TypeLevel) → (l PE.≡ ¹) → (p : Γ ⊩⟨ ⁰ ⟩ A) → Γ ⊩⟨ l ⟩ A
emb″ .¹ PE.refl p = emb′ 0<1 p
-- A view for constructor equality of types where embeddings are ignored
data ShapeView Γ (l l′ : TypeLevel) : ∀ A B (p : Γ ⊩⟨ l ⟩ A) (q : Γ ⊩⟨ l′ ⟩ B)
→ Set (lsuc (lsuc (toLevel l ⊔ toLevel l′))) where
Uᵥ : ∀ l'A l<A ⊢ΓA l'B l<B ⊢ΓB
→ ShapeView Γ l l′ U U
(LRPack _ _ _ (LRU ⊢ΓA l'A l<A))
(LRPack _ _ _ (LRU ⊢ΓB l'B l<B))
ℕᵥ : ∀ {A B} ℕA ℕB
→ ShapeView Γ l l′ A B
(LRPack _ _ _ (LRℕ ℕA))
(LRPack _ _ _ (LRℕ ℕB))
ne : ∀ {A B} neA neB
→ ShapeView Γ l l′ A B
(LRPack _ _ _ (LRne neA))
(LRPack _ _ _ (LRne neB))
Πᵥ : ∀ {A B} ΠA ΠB
→ ShapeView Γ l l′ A B
(LRPack _ _ _ (LRΠ ΠA))
(LRPack _ _ _ (LRΠ ΠB))
emb⁰¹ : ∀ {A B p q}
→ (l≡ : l PE.≡ ¹)
→ ShapeView Γ ⁰ l′ A B p q
→ ShapeView Γ l l′ A B (emb″ l l≡ p) q
emb¹⁰ : ∀ {A B p q}
→ (l≡ : l′ PE.≡ ¹)
→ ShapeView Γ l ⁰ A B p q
→ ShapeView Γ l l′ A B p (emb″ l′ l≡ q)
-- Construct an shape view from an equality
goodCases : ∀ {l l′ Γ A B} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A] → ShapeView Γ l l′ A B [A] [B]
goodCases (Uᵣ′ lA l<A ⊢ΓA) (Uᵣ′ lB l<B ⊢ΓB) A≡B = Uᵥ lA l<A ⊢ΓA lB l<B ⊢ΓB
goodCases (Uᵣ′ _ _ ⊢Γ) (ℕᵣ D) (U₌ PE.refl) = ⊥-elim (U≢ℕ (whnfRed* (red D) Uₙ))
goodCases (Uᵣ′ _ _ ⊢Γ) (ne′ K D neK K≡K) (U₌ PE.refl) = ⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))
goodCases (Uᵣ′ _ _ ⊢Γ) (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (U₌ PE.refl) =
⊥-elim (U≢Π (whnfRed* (red D) Uₙ))
goodCases (ℕᵣ D) (Uᵣ′ _ _ ⊢Γ) (ιx (ℕ₌ A≡B)) = ⊥-elim (U≢ℕ (whnfRed* A≡B Uₙ))
goodCases (ℕᵣ ℕA) (ℕᵣ ℕB) A≡B = ℕᵥ ℕA ℕB
goodCases (ℕᵣ D) (ne′ K D₁ neK K≡K) (ιx (ℕ₌ A≡B)) =
⊥-elim (ℕ≢ne neK (whrDet* (A≡B , ℕₙ) (red D₁ , ne neK)))
goodCases (ℕᵣ D) (Πᵣ′ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) (ιx (ℕ₌ A≡B)) =
⊥-elim (ℕ≢Π (whrDet* (A≡B , ℕₙ) (red D₁ , Πₙ)))
goodCases (ne′ K D neK K≡K) (Uᵣ′ _ _ ⊢Γ) (ιx (ne₌ M D′ neM K≡M)) =
⊥-elim (U≢ne neM (whnfRed* (red D′) Uₙ))
goodCases (ne′ K D neK K≡K) (ℕᵣ D₁) (ιx (ne₌ M D′ neM K≡M)) =
⊥-elim (ℕ≢ne neM (whrDet* (red D₁ , ℕₙ) (red D′ , ne neM)))
goodCases (ne′ K D neK K≡K) (ne′ K′ D′ neK′ K≡K′) A≡B = ne (ne K D neK K≡K) (ne K′ D′ neK′ K≡K′)
goodCases (ne′ K D neK K≡K) (Πᵣ′ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext) (ιx (ne₌ M D′ neM K≡M)) =
⊥-elim (Π≢ne neM (whrDet* (red D₁ , Πₙ) (red D′ , ne neM)))
goodCases (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Uᵣ′ _ _ ⊢Γ)
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
⊥-elim (U≢Π (whnfRed* D′ Uₙ))
goodCases (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ℕᵣ D₁)
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
⊥-elim (ℕ≢Π (whrDet* (red D₁ , ℕₙ) (D′ , Πₙ)))
goodCases (Πᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ne′ K D₁ neK K≡K)
(Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
⊥-elim (Π≢ne neK (whrDet* (D′ , Πₙ) (red D₁ , ne neK)))
goodCases (LRPack _ _ _ (LRΠ ΠA)) (LRPack _ _ _ (LRΠ ΠB)) A≡B = Πᵥ ΠA ΠB
goodCases {l} [A] (emb′ 0<1 x) A≡B =
emb¹⁰ PE.refl (goodCases {l} {⁰} [A] x A≡B)
goodCases {l′ = l} (emb′ 0<1 x) [B] (ιx A≡B) =
emb⁰¹ PE.refl (goodCases {⁰} {l} x [B] A≡B)
-- Construct an shape view between two derivations of the same type
goodCasesRefl : ∀ {l l′ Γ A} ([A] : Γ ⊩⟨ l ⟩ A) ([A′] : Γ ⊩⟨ l′ ⟩ A)
→ ShapeView Γ l l′ A A [A] [A′]
goodCasesRefl [A] [A′] = goodCases [A] [A′] (reflEq [A])
-- A view for constructor equality between three types
data ShapeView₃ Γ (l l′ l″ : TypeLevel) : ∀ A B C
(p : Γ ⊩⟨ l ⟩ A)
(q : Γ ⊩⟨ l′ ⟩ B)
(r : Γ ⊩⟨ l″ ⟩ C)
→ Set (lsuc (lsuc (toLevel l ⊔ toLevel l′ ⊔ toLevel l″))) where
Uᵥ : ∀ lA l<A ⊢ΓA lB l<B ⊢ΓB lC l<C ⊢ΓC
→ ShapeView₃ Γ l l′ l″ U U U
(LRPack _ _ _ (LRU ⊢ΓA lA l<A))
(LRPack _ _ _ (LRU ⊢ΓB lB l<B))
(LRPack _ _ _ (LRU ⊢ΓC lC l<C))
ℕᵥ : ∀ {A B C} ℕA ℕB ℕC
→ ShapeView₃ Γ l l′ l″ A B C
(LRPack _ _ _ (LRℕ ℕA))
(LRPack _ _ _ (LRℕ ℕB))
(LRPack _ _ _ (LRℕ ℕC))
ne : ∀ {A B C} neA neB neC
→ ShapeView₃ Γ l l′ l″ A B C
(LRPack _ _ _ (LRne neA))
(LRPack _ _ _ (LRne neB))
(LRPack _ _ _ (LRne neC))
Πᵥ : ∀ {A B C} ΠA ΠB ΠC
→ ShapeView₃ Γ l l′ l″ A B C
(LRPack _ _ _ (LRΠ ΠA))
(LRPack _ _ _ (LRΠ ΠB))
(LRPack _ _ _ (LRΠ ΠC))
emb⁰¹¹ : ∀ {A B C p q r}
→ (l≡ : l PE.≡ ¹)
→ ShapeView₃ Γ ⁰ l′ l″ A B C p q r
→ ShapeView₃ Γ l l′ l″ A B C (emb″ l l≡ p) q r
emb¹⁰¹ : ∀ {A B C p q r}
→ (l≡ : l′ PE.≡ ¹)
→ ShapeView₃ Γ l ⁰ l″ A B C p q r
→ ShapeView₃ Γ l l′ l″ A B C p (emb″ l′ l≡ q) r
emb¹¹⁰ : ∀ {A B C p q r}
→ (l≡ : l″ PE.≡ ¹)
→ ShapeView₃ Γ l l′ ⁰ A B C p q r
→ ShapeView₃ Γ l l′ l″ A B C p q (emb″ l″ l≡ r)
-- Combines two two-way views into a three-way view
combine : ∀ {Γ l l′ l″ l‴ A B C [A] [B] [B]′ [C]}
→ ShapeView Γ l l′ A B [A] [B]
→ ShapeView Γ l″ l‴ B C [B]′ [C]
→ ShapeView₃ Γ l l′ l‴ A B C [A] [B] [C]
combine (Uᵥ lA l<A ⊢ΓA lB l<B ⊢ΓB) (Uᵥ _ _ _ lC l<C ⊢ΓC) = Uᵥ lA l<A ⊢ΓA lB l<B ⊢ΓB lC l<C ⊢ΓC
combine (Uᵥ lA l<A ⊢ΓA lB l<B ⊢ΓB) (ℕᵥ ℕA ℕB) = ⊥-elim (U≢ℕ (whnfRed* (red ℕA) Uₙ))
combine (Uᵥ lA l<A ⊢ΓA lB l<B ⊢ΓB) (ne (ne K D neK K≡K) neB) =
⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))
combine (Uᵥ lA l<A ⊢ΓA lB l<B ⊢ΓB) (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) =
⊥-elim (U≢Π (whnfRed* (red D) Uₙ))
combine (ℕᵥ ℕA ℕB) (Uᵥ lB l<B ⊢ΓB lC l<C ⊢ΓC) = ⊥-elim (U≢ℕ (whnfRed* (red ℕB) Uₙ))
combine (ℕᵥ ℕA₁ ℕB₁) (ℕᵥ ℕA ℕB) = ℕᵥ ℕA₁ ℕB₁ ℕB
combine (ℕᵥ ℕA ℕB) (ne (ne K D neK K≡K) neB) =
⊥-elim (ℕ≢ne neK (whrDet* (red ℕB , ℕₙ) (red D , ne neK)))
combine (ℕᵥ ℕA ℕB) (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) =
⊥-elim (ℕ≢Π (whrDet* (red ℕB , ℕₙ) (red D , Πₙ)))
combine (ne neA (ne K D neK K≡K)) (Uᵥ lB l<B ⊢ΓB lC l<C ⊢ΓC) =
⊥-elim (U≢ne neK (whnfRed* (red D) Uₙ))
combine (ne neA (ne K D neK K≡K)) (ℕᵥ ℕA ℕB) =
⊥-elim (ℕ≢ne neK (whrDet* (red ℕA , ℕₙ) (red D , ne neK)))
combine (ne neA₁ neB₁) (ne neA neB) = ne neA₁ neB₁ neB
combine (ne neA (ne K D₁ neK K≡K)) (Πᵥ (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext) ΠB) =
⊥-elim (Π≢ne neK (whrDet* (red D , Πₙ) (red D₁ , ne neK)))
combine (Πᵥ ΠA (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (Uᵥ lB l<B ⊢ΓB lC l<C ⊢ΓC) =
⊥-elim (U≢Π (whnfRed* (red D) Uₙ))
combine (Πᵥ ΠA (Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (ℕᵥ ℕA ℕB) =
⊥-elim (ℕ≢Π (whrDet* (red ℕA , ℕₙ) (red D , Πₙ)))
combine (Πᵥ ΠA (Πᵣ F G D₁ ⊢F ⊢G A≡A [F] [G] G-ext)) (ne (ne K D neK K≡K) neB) =
⊥-elim (Π≢ne neK (whrDet* (red D₁ , Πₙ) (red D , ne neK)))
combine (Πᵥ ΠA₁ ΠB₁) (Πᵥ ΠA ΠB) = Πᵥ ΠA₁ ΠB₁ ΠB
combine (emb⁰¹ l≡ [AB]) [BC] = emb⁰¹¹ l≡ (combine [AB] [BC])
combine (emb¹⁰ l≡ [AB]) [BC] = emb¹⁰¹ l≡ (combine [AB] [BC])
combine [AB] (emb⁰¹ l≡ [BC]) = combine [AB] [BC]
combine [AB] (emb¹⁰ l≡ [BC]) = emb¹¹⁰ l≡ (combine [AB] [BC])
| {
"alphanum_fraction": 0.5163976648,
"avg_line_length": 42.5109489051,
"ext": "agda",
"hexsha": "174ea97c7b130b7770743199372d92b1e2a0b0b0",
"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": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/ShapeView.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"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": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/ShapeView.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/ShapeView.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6622,
"size": 11648
} |
module IllTyped where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Bool : Set where
false : Bool
true : Bool
F : Nat -> Set
F zero = Nat
F (suc x) = Bool
postulate
D : (x:Nat)(y:F x) -> Set
T : Nat -> Set
f : {x:Nat -> Nat}{y:F (x zero)} ->
(T (x zero) -> T (suc zero)) ->
(D zero zero -> D (x zero) y) ->
Nat
test = f {?} (\x -> x) (\x -> x)
| {
"alphanum_fraction": 0.4811083123,
"avg_line_length": 14.7037037037,
"ext": "agda",
"hexsha": "0c591fb171cda1ed7c979f7da69285929e90e7d2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "notes/papers/implicit/examples/IllTyped.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/agda",
"max_issues_repo_path": "notes/papers/implicit/examples/IllTyped.agda",
"max_line_length": 38,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "notes/papers/implicit/examples/IllTyped.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 152,
"size": 397
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- 1 dimensional pretty printing of rose trees
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Text.Tree.Linear where
open import Level using (Level)
open import Size
open import Data.Bool.Base using (Bool; true; false; if_then_else_; _∧_)
open import Data.DifferenceList as DList renaming (DiffList to DList) using ()
open import Data.List.Base as List using (List; []; [_]; _∷_; _∷ʳ_)
open import Data.Nat.Base using (ℕ; _∸_)
open import Data.Product using (_×_; _,_)
open import Data.String.Base
open import Data.Tree.Rose using (Rose; node)
open import Function.Base using (flip)
private
variable
a : Level
A : Set a
i : Size
display : Rose (List String) i → List String
display t = DList.toList (go (([] , t) ∷ [])) where
padding : Bool → List Bool → String → String
padding dir? [] str = str
padding dir? (b ∷ bs) str =
(if dir? ∧ List.null bs
then if b then " ├ " else " └ "
else if b then " │ " else " ")
++ padding dir? bs str
nodePrefixes : List A → List Bool
nodePrefixes as = true ∷ List.replicate (List.length as ∸ 1) false
childrenPrefixes : List A → List Bool
childrenPrefixes as = List.replicate (List.length as ∸ 1) true ∷ʳ false
go : List (List Bool × Rose (List String) i) → DList String
go [] = DList.[]
go ((bs , node a ts₁) ∷ ts) =
let bs′ = List.reverse bs in
DList.fromList (List.zipWith (flip padding bs′) (nodePrefixes a) a)
DList.++ go (List.zip (List.map (_∷ bs) (childrenPrefixes ts₁)) ts₁)
DList.++ go ts
| {
"alphanum_fraction": 0.5893580104,
"avg_line_length": 33.25,
"ext": "agda",
"hexsha": "353a9321a6fb64d3b1860d29c2c2bf01212d8f82",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Text/Tree/Linear.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Text/Tree/Linear.agda",
"max_line_length": 78,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Text/Tree/Linear.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 478,
"size": 1729
} |
{-# OPTIONS --type-in-type #-}
Ty% : Set
Ty% =
(Ty% : Set)
(nat top bot : Ty%)
(arr prod sum : Ty% → Ty% → Ty%)
→ Ty%
nat% : Ty%; nat% = λ _ nat% _ _ _ _ _ → nat%
top% : Ty%; top% = λ _ _ top% _ _ _ _ → top%
bot% : Ty%; bot% = λ _ _ _ bot% _ _ _ → bot%
arr% : Ty% → Ty% → Ty%; arr%
= λ A B Ty% nat% top% bot% arr% prod sum →
arr% (A Ty% nat% top% bot% arr% prod sum) (B Ty% nat% top% bot% arr% prod sum)
prod% : Ty% → Ty% → Ty%; prod%
= λ A B Ty% nat% top% bot% arr% prod% sum →
prod% (A Ty% nat% top% bot% arr% prod% sum) (B Ty% nat% top% bot% arr% prod% sum)
sum% : Ty% → Ty% → Ty%; sum%
= λ A B Ty% nat% top% bot% arr% prod% sum% →
sum% (A Ty% nat% top% bot% arr% prod% sum%) (B Ty% nat% top% bot% arr% prod% sum%)
Con% : Set; Con%
= (Con% : Set)
(nil : Con%)
(snoc : Con% → Ty% → Con%)
→ Con%
nil% : Con%; nil%
= λ Con% nil% snoc → nil%
snoc% : Con% → Ty% → Con%; snoc%
= λ Γ A Con% nil% snoc% → snoc% (Γ Con% nil% snoc%) A
Var% : Con% → Ty% → Set; Var%
= λ Γ A →
(Var% : Con% → Ty% → Set)
(vz : ∀ Γ A → Var% (snoc% Γ A) A)
(vs : ∀ Γ B A → Var% Γ A → Var% (snoc% Γ B) A)
→ Var% Γ A
vz% : ∀{Γ A} → Var% (snoc% Γ A) A; vz%
= λ Var% vz% vs → vz% _ _
vs% : ∀{Γ B A} → Var% Γ A → Var% (snoc% Γ B) A; vs%
= λ x Var% vz% vs% → vs% _ _ _ (x Var% vz% vs%)
Tm% : Con% → Ty% → Set; Tm%
= λ Γ A →
(Tm% : Con% → Ty% → Set)
(var : ∀ Γ A → Var% Γ A → Tm% Γ A)
(lam : ∀ Γ A B → Tm% (snoc% Γ A) B → Tm% Γ (arr% A B))
(app : ∀ Γ A B → Tm% Γ (arr% A B) → Tm% Γ A → Tm% Γ B)
(tt : ∀ Γ → Tm% Γ top%)
(pair : ∀ Γ A B → Tm% Γ A → Tm% Γ B → Tm% Γ (prod% A B))
(fst : ∀ Γ A B → Tm% Γ (prod% A B) → Tm% Γ A)
(snd : ∀ Γ A B → Tm% Γ (prod% A B) → Tm% Γ B)
(left : ∀ Γ A B → Tm% Γ A → Tm% Γ (sum% A B))
(right : ∀ Γ A B → Tm% Γ B → Tm% Γ (sum% A B))
(case : ∀ Γ A B C → Tm% Γ (sum% A B) → Tm% Γ (arr% A C) → Tm% Γ (arr% B C) → Tm% Γ C)
(zero : ∀ Γ → Tm% Γ nat%)
(suc : ∀ Γ → Tm% Γ nat% → Tm% Γ nat%)
(rec : ∀ Γ A → Tm% Γ nat% → Tm% Γ (arr% nat% (arr% A A)) → Tm% Γ A → Tm% Γ A)
→ Tm% Γ A
var% : ∀{Γ A} → Var% Γ A → Tm% Γ A; var%
= λ x Tm% var% lam app tt pair fst snd left right case zero suc rec →
var% _ _ x
lam% : ∀{Γ A B} → Tm% (snoc% Γ A) B → Tm% Γ (arr% A B); lam%
= λ t Tm% var% lam% app tt pair fst snd left right case zero suc rec →
lam% _ _ _ (t Tm% var% lam% app tt pair fst snd left right case zero suc rec)
app% : ∀{Γ A B} → Tm% Γ (arr% A B) → Tm% Γ A → Tm% Γ B; app%
= λ t u Tm% var% lam% app% tt pair fst snd left right case zero suc rec →
app% _ _ _ (t Tm% var% lam% app% tt pair fst snd left right case zero suc rec)
(u Tm% var% lam% app% tt pair fst snd left right case zero suc rec)
tt% : ∀{Γ} → Tm% Γ top%; tt%
= λ Tm% var% lam% app% tt% pair fst snd left right case zero suc rec → tt% _
pair% : ∀{Γ A B} → Tm% Γ A → Tm% Γ B → Tm% Γ (prod% A B); pair%
= λ t u Tm% var% lam% app% tt% pair% fst snd left right case zero suc rec →
pair% _ _ _ (t Tm% var% lam% app% tt% pair% fst snd left right case zero suc rec)
(u Tm% var% lam% app% tt% pair% fst snd left right case zero suc rec)
fst% : ∀{Γ A B} → Tm% Γ (prod% A B) → Tm% Γ A; fst%
= λ t Tm% var% lam% app% tt% pair% fst% snd left right case zero suc rec →
fst% _ _ _ (t Tm% var% lam% app% tt% pair% fst% snd left right case zero suc rec)
snd% : ∀{Γ A B} → Tm% Γ (prod% A B) → Tm% Γ B; snd%
= λ t Tm% var% lam% app% tt% pair% fst% snd% left right case zero suc rec →
snd% _ _ _ (t Tm% var% lam% app% tt% pair% fst% snd% left right case zero suc rec)
left% : ∀{Γ A B} → Tm% Γ A → Tm% Γ (sum% A B); left%
= λ t Tm% var% lam% app% tt% pair% fst% snd% left% right case zero suc rec →
left% _ _ _ (t Tm% var% lam% app% tt% pair% fst% snd% left% right case zero suc rec)
right% : ∀{Γ A B} → Tm% Γ B → Tm% Γ (sum% A B); right%
= λ t Tm% var% lam% app% tt% pair% fst% snd% left% right% case zero suc rec →
right% _ _ _ (t Tm% var% lam% app% tt% pair% fst% snd% left% right% case zero suc rec)
case% : ∀{Γ A B C} → Tm% Γ (sum% A B) → Tm% Γ (arr% A C) → Tm% Γ (arr% B C) → Tm% Γ C; case%
= λ t u v Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero suc rec →
case% _ _ _ _
(t Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero suc rec)
(u Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero suc rec)
(v Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero suc rec)
zero% : ∀{Γ} → Tm% Γ nat%; zero%
= λ Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc rec → zero% _
suc% : ∀{Γ} → Tm% Γ nat% → Tm% Γ nat%; suc%
= λ t Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc% rec →
suc% _ (t Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc% rec)
rec% : ∀{Γ A} → Tm% Γ nat% → Tm% Γ (arr% nat% (arr% A A)) → Tm% Γ A → Tm% Γ A; rec%
= λ t u v Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc% rec% →
rec% _ _
(t Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc% rec%)
(u Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc% rec%)
(v Tm% var% lam% app% tt% pair% fst% snd% left% right% case% zero% suc% rec%)
v0% : ∀{Γ A} → Tm% (snoc% Γ A) A; v0%
= var% vz%
v1% : ∀{Γ A B} → Tm% (snoc% (snoc% Γ A) B) A; v1%
= var% (vs% vz%)
v2% : ∀{Γ A B C} → Tm% (snoc% (snoc% (snoc% Γ A) B) C) A; v2%
= var% (vs% (vs% vz%))
v3% : ∀{Γ A B C D} → Tm% (snoc% (snoc% (snoc% (snoc% Γ A) B) C) D) A; v3%
= var% (vs% (vs% (vs% vz%)))
tbool% : Ty%; tbool%
= sum% top% top%
true% : ∀{Γ} → Tm% Γ tbool%; true%
= left% tt%
tfalse% : ∀{Γ} → Tm% Γ tbool%; tfalse%
= right% tt%
ifthenelse% : ∀{Γ A} → Tm% Γ (arr% tbool% (arr% A (arr% A A))); ifthenelse%
= lam% (lam% (lam% (case% v2% (lam% v2%) (lam% v1%))))
times4% : ∀{Γ A} → Tm% Γ (arr% (arr% A A) (arr% A A)); times4%
= lam% (lam% (app% v1% (app% v1% (app% v1% (app% v1% v0%)))))
add% : ∀{Γ} → Tm% Γ (arr% nat% (arr% nat% nat%)); add%
= lam% (rec% v0%
(lam% (lam% (lam% (suc% (app% v1% v0%)))))
(lam% v0%))
mul% : ∀{Γ} → Tm% Γ (arr% nat% (arr% nat% nat%)); mul%
= lam% (rec% v0%
(lam% (lam% (lam% (app% (app% add% (app% v1% v0%)) v0%))))
(lam% zero%))
fact% : ∀{Γ} → Tm% Γ (arr% nat% nat%); fact%
= lam% (rec% v0% (lam% (lam% (app% (app% mul% (suc% v1%)) v0%)))
(suc% zero%))
| {
"alphanum_fraction": 0.4899184239,
"avg_line_length": 38.6726190476,
"ext": "agda",
"hexsha": "66c6e66a70fd5214823df5fb7ac86a2881757b48",
"lang": "Agda",
"max_forks_count": 19,
"max_forks_repo_forks_event_max_datetime": "2022-03-03T19:46:54.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-05T21:11:34.000Z",
"max_forks_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "int-index/smalltt",
"max_forks_repo_path": "bench/stlc_lessimpl.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_issues_repo_issues_event_max_datetime": "2022-02-28T21:51:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-16T09:14:57.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "int-index/smalltt",
"max_issues_repo_path": "bench/stlc_lessimpl.agda",
"max_line_length": 92,
"max_stars_count": 377,
"max_stars_repo_head_hexsha": "6a87f295148bd753d2519d50c2e1011b64c859ff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "int-index/smalltt",
"max_stars_repo_path": "bench/stlc_lessimpl.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T21:31:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-26T16:57:16.000Z",
"num_tokens": 2886,
"size": 6497
} |
-- Andreas, 2012-09-07
module DataParameterPolarity where
data Bool : Set where
true false : Bool
data ⊥ : Set where
record ⊤ : Set where
-- True uses its first argument.
True : Bool → Set
True true = ⊤
True false = ⊥
-- Hence, D also uses its first argument.
-- A buggy polarity analysis may consider D as constant.
data D (b : Bool) : Set where
c : True b → D b
d : {b : Bool} → D b → True b
d (c x) = x
-- This cast is fatal, possible if D is considered constant.
cast : (a b : Bool) → D a → D b
cast a b x = x
bot : ⊥
bot = d (cast true false (c _))
| {
"alphanum_fraction": 0.6378091873,
"avg_line_length": 19.5172413793,
"ext": "agda",
"hexsha": "6163633df36039c9f50882d1a8a40efe9fc54166",
"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/DataParameterPolarity.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/DataParameterPolarity.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/DataParameterPolarity.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": 184,
"size": 566
} |
{-
This file contains:
- Id, refl and J (with definitional computation rule)
- Basic theory about Id, proved using J
- Lemmas for going back and forth between Path and Id
- Function extensionality for Id
- fiber, isContr, equiv all defined using Id
- The univalence axiom expressed using only Id ([EquivContr])
- Propositional truncation and its elimination principle
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.Id 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
; funExt to funExtPath
; isContr to isContrPath
; isProp to isPropPath
; isSet to isSetPath
; fst to pr₁ -- as in the HoTT book
; snd to pr₂
)
open import Cubical.Core.Glue
renaming ( isEquiv to isEquivPath
; _≃_ to EquivPath
; equivFun to equivFunPath )
open import Cubical.Foundations.Equiv
renaming ( fiber to fiberPath
; equivIsEquiv to equivIsEquivPath
; equivCtr to equivCtrPath )
hiding ( isPropIsEquiv )
open import Cubical.Foundations.Univalence
renaming ( EquivContr to EquivContrPath )
open import Cubical.HITs.PropositionalTruncation public
renaming ( squash to squashPath
; recPropTrunc to recPropTruncPath
; elimPropTrunc to elimPropTruncPath )
open import Cubical.Core.Id public
private
variable
ℓ ℓ' : Level
A : Type ℓ
-- Version of the constructor for Id where the y is also
-- explicit. This is sometimes useful when it is needed for
-- typechecking (see JId below).
conId : ∀ {x : A} φ (y : A [ φ ↦ (λ _ → x) ])
(w : (Path _ x (outS y)) [ φ ↦ (λ { (φ = i1) → λ _ → x}) ]) →
x ≡ outS y
conId φ _ w = ⟨ φ , outS w ⟩
-- Reflexivity
refl : ∀ {x : A} → x ≡ x
refl {x = x} = ⟨ i1 , (λ _ → x) ⟩
-- Definition of J for Id
module _ {x : A} (P : ∀ (y : A) → Id x y → Type ℓ') (d : P x refl) where
J : ∀ {y : A} (w : x ≡ y) → P y w
J {y = y} = elimId P (λ φ y w → comp (λ i → P _ (conId (φ ∨ ~ i) (inS (outS w i))
(inS (λ j → outS w (i ∧ j)))))
(λ i → λ { (φ = i1) → d}) d) {y = y}
-- Check that J of refl is the identity function
Jdefeq : Path _ (J refl) d
Jdefeq _ = d
-- Basic theory about Id, proved using J
transport : ∀ (B : A → Type ℓ') {x y : A}
→ x ≡ y → B x → B y
transport B {x} p b = J (λ y p → B y) b p
_⁻¹ : {x y : A} → x ≡ y → y ≡ x
_⁻¹ {x = x} p = J (λ z _ → z ≡ x) refl p
ap : ∀ {B : Type ℓ'} (f : A → B) → ∀ {x y : A} → x ≡ y → f x ≡ f y
ap f {x} = J (λ z _ → f x ≡ f z) refl
_∙_ : ∀ {x y z : A} → x ≡ y → y ≡ z → x ≡ z
_∙_ {x = x} p = J (λ y _ → x ≡ y) p
infix 4 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ p ⟩ q = p ∙ q
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- Convert between Path and Id
pathToId : ∀ {x y : A} → Path _ x y → Id x y
pathToId {x = x} = JPath (λ y _ → Id x y) refl
pathToIdRefl : ∀ {x : A} → Path _ (pathToId (λ _ → x)) refl
pathToIdRefl {x = x} = JPathRefl (λ y _ → Id x y) refl
idToPath : ∀ {x y : A} → Id x y → Path _ x y
idToPath {x = x} = J (λ y _ → Path _ x y) (λ _ → x)
idToPathRefl : ∀ {x : A} → Path _ (idToPath {x = x} refl) reflPath
idToPathRefl {x = x} _ _ = x
pathToIdToPath : ∀ {x y : A} → (p : Path _ x y) → Path _ (idToPath (pathToId p)) p
pathToIdToPath {x = x} = JPath (λ y p → Path _ (idToPath (pathToId p)) p)
(λ i → idToPath (pathToIdRefl i))
idToPathToId : ∀ {x y : A} → (p : Id x y) → Path _ (pathToId (idToPath p)) p
idToPathToId {x = x} = J (λ b p → Path _ (pathToId (idToPath p)) p) pathToIdRefl
-- We get function extensionality by going back and forth between Path and Id
funExt : ∀ {B : A → Type ℓ'} {f g : (x : A) → B x} →
((x : A) → f x ≡ g x) → f ≡ g
funExt p = pathToId (λ i x → idToPath (p x) i)
-- Equivalences expressed using Id
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
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (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 : ∀ {B : Type ℓ'} → A ≃ B → A → B
equivFun e = pr₁ e
equivIsEquiv : ∀ {B : Type ℓ'} (e : A ≃ B) → isEquiv (equivFun e)
equivIsEquiv e = pr₂ e
equivCtr : ∀ {B : Type ℓ'} (e : A ≃ B) (y : B) → fiber (equivFun e) y
equivCtr e y = e .pr₂ .equiv-proof y .pr₁
-- 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 : ∀ {B : Type ℓ'} {f : A → B} {y : B} →
fiberPath f y → fiber f y
fiberPathToFiber (x , p) = (x , pathToId p)
fiberToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B} →
fiber f y → fiberPath f y
fiberToFiberPath (x , p) = (x , idToPath p)
fiberToFiber : ∀ {B : Type ℓ'} {f : A → B} {y : B}
(p : fiber f y) → Path _ (fiberPathToFiber (fiberToFiberPath p)) p
fiberToFiber (x , p) = λ i → x , idToPathToId p i
fiberPathToFiberPath : ∀ {B : Type ℓ'} {f : A → B} {y : B}
(p : fiberPath f y) → Path _ (fiberToFiberPath (fiberPathToFiber p)) p
fiberPathToFiberPath (x , p) = λ i → x , pathToIdToPath p i
isContrPathToIsContr : isContrPath A → isContr A
isContrPathToIsContr (ctr , p) = (ctr , λ y → pathToId (p y))
isContrToIsContrPath : isContr A → isContrPath A
isContrToIsContrPath (ctr , p) = (ctr , λ y → idToPath (p y))
isPropPathToIsProp : isPropPath A → isProp A
isPropPathToIsProp H x y = pathToId (H x y)
isPropToIsPropPath : isProp A → isPropPath A
isPropToIsPropPath H x y i = idToPath (H x y) i
-- 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 → pathToId (λ 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 → idToPath (rem y))
where
rem : ∀ (y : A) → g x ≡ y
rem y =
g x ≡⟨ ap g (p (f y)) ⟩
g (f y) ≡⟨ pathToId (h y) ⟩
y ∎
-- This proof is essentially the one for proving that isContr with
-- Path is a proposition, but as we are working with Id we have to
-- insert a lof of conversion functions. It is still nice that is
-- works like this though.
isPropIsContr : ∀ (p1 p2 : isContr A) → Path (isContr A) p1 p2
isPropIsContr (a0 , p0) (a1 , p1) j =
( idToPath (p0 a1) j ,
hcomp (λ i → λ { (j = i0) → λ x → idToPathToId (p0 x) i
; (j = i1) → λ x → idToPathToId (p1 x) i })
(λ x → pathToId (λ i → hcomp (λ k → λ { (i = i0) → idToPath (p0 a1) j
; (i = i1) → idToPath (p0 x) (j ∨ k)
; (j = i0) → idToPath (p0 x) (i ∧ k)
; (j = i1) → idToPath (p1 x) i })
(idToPath (p0 (idToPath (p1 x) i)) j))))
-- We now prove that isEquiv is a proposition
isPropIsEquiv : ∀ {A : Type ℓ} {B : Type ℓ} → {f : A → B} → (h1 h2 : isEquiv f) → Path _ h1 h2
equiv-proof (isPropIsEquiv {f = f} h1 h2 i) y =
isPropIsContr {A = fiber f y} (h1 .equiv-proof y) (h2 .equiv-proof y) i
-- Go from a Path equivalence to an Id equivalence
equivPathToEquiv : ∀ {A : Type ℓ} {B : Type ℓ'} → EquivPath A B → A ≃ B
equivPathToEquiv (f , p) =
(f , λ { .equiv-proof y → helper1 fiberPathToFiber fiberToFiberPath fiberToFiber (p .equiv-proof y) })
-- Go from an Id equivalence to a Path equivalence
equivToEquivPath : ∀ {A : Type ℓ} {B : Type ℓ'} → A ≃ B → EquivPath A B
equivToEquivPath (f , p) =
(f , λ { .equiv-proof y → helper2 fiberPathToFiber fiberToFiberPath fiberPathToFiberPath (p .equiv-proof y) })
equivToEquiv : ∀ {A : Type ℓ} {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)
-- We can finally prove univalence with Id everywhere from the one for Path
EquivContr : ∀ (A : Type ℓ) → isContr (Σ[ T ∈ Type ℓ ] (T ≃ A))
EquivContr A = helper1 f1 f2 f12 (EquivContrPath A)
where
f1 : ∀ {ℓ} {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (EquivPath T A) → Σ[ T ∈ Type ℓ ] (T ≃ A)
f1 (x , p) = x , equivPathToEquiv p
f2 : ∀ {ℓ} {A : Type ℓ} → Σ[ T ∈ Type ℓ ] (T ≃ A) → Σ[ T ∈ Type ℓ ] (EquivPath T A)
f2 (x , p) = x , equivToEquivPath p
f12 : ∀ {ℓ} {A : Type ℓ} → (y : Σ[ T ∈ Type ℓ ] (T ≃ A)) → Path _ (f1 (f2 y)) y
f12 (x , p) = λ i → x , equivToEquiv p i
-- Propositional truncation
∥∥-isProp : ∀ (x y : ∥ A ∥) → x ≡ y
∥∥-isProp x y = pathToId (squashPath x y)
∥∥-recursion : ∀ {A : Type ℓ} {P : Type ℓ} → isProp P → (A → P) → ∥ A ∥ → P
∥∥-recursion Pprop f x = recPropTruncPath (isPropToIsPropPath Pprop) f x
∥∥-induction : ∀ {A : Type ℓ} {P : ∥ A ∥ → Type ℓ} → ((a : ∥ A ∥) → isProp (P a)) →
((x : A) → P ∣ x ∣) → (a : ∥ A ∥) → P a
∥∥-induction Pprop f x = elimPropTruncPath (λ a → isPropToIsPropPath (Pprop a)) f x
| {
"alphanum_fraction": 0.5438492651,
"avg_line_length": 35.3205574913,
"ext": "agda",
"hexsha": "4ccbd9a5a95a308885d928382f26d278e70319ff",
"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/Foundations/Id.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/Foundations/Id.agda",
"max_line_length": 136,
"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/Foundations/Id.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3907,
"size": 10137
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Vec.Relation.Binary.Pointwise.Extensional directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Relation.Pointwise.Inductive where
open import Data.Vec.Relation.Binary.Pointwise.Inductive public
| {
"alphanum_fraction": 0.5092592593,
"avg_line_length": 33.2307692308,
"ext": "agda",
"hexsha": "7f3ef250339de10df9d8d4034b988068b9f64903",
"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/Pointwise/Inductive.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/Pointwise/Inductive.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/Pointwise/Inductive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 71,
"size": 432
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.Nat
test : (n : Nat) → Nat
test n with zero
... | n = {!n!}
| {
"alphanum_fraction": 0.5952380952,
"avg_line_length": 15.75,
"ext": "agda",
"hexsha": "9f59153d554c7dda605b9b7fadbdafaee285624e",
"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/Issue1820.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/Issue1820.agda",
"max_line_length": 38,
"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/Issue1820.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": 42,
"size": 126
} |
-- This file is imported by Issue1597.Main
module Issue1597 where
module A where
module M where -- needs to be module
postulate Nat : Set
| {
"alphanum_fraction": 0.7328767123,
"avg_line_length": 18.25,
"ext": "agda",
"hexsha": "afb99281370bb3e7062e7fd9090ebbbb9bb6adde",
"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/Issue1597.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/Issue1597.agda",
"max_line_length": 42,
"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/Issue1597.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": 38,
"size": 146
} |
------------------------------------------------------------------------------
-- The division specification
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Program.Division.Specification where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Inequalities
------------------------------------------------------------------------------
-- Specification: The division is total and the result is correct.
divSpec : D → D → D → Set
divSpec i j q = N q ∧ (∃[ r ] N r ∧ r < j ∧ i ≡ j * q + r)
| {
"alphanum_fraction": 0.4212651413,
"avg_line_length": 37.15,
"ext": "agda",
"hexsha": "5b4f0df9092a3a087e22277674b719fa349d0996",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/Division/Specification.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/Division/Specification.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/Division/Specification.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": 140,
"size": 743
} |
module Categories.Ran where
open import Level
open import Categories.Category
open import Categories.Functor hiding (_≡_)
open import Categories.NaturalTransformation
record Ran {o₀ ℓ₀ e₀} {o₁ ℓ₁ e₁} {o₂ ℓ₂ e₂}
{A : Category o₀ ℓ₀ e₀} {B : Category o₁ ℓ₁ e₁} {C : Category o₂ ℓ₂ e₂}
(F : Functor A B) (X : Functor A C) : Set (o₀ ⊔ ℓ₀ ⊔ e₀ ⊔ o₁ ⊔ ℓ₁ ⊔ e₁ ⊔ o₂ ⊔ ℓ₂ ⊔ e₂) where
field
R : Functor B C
η : NaturalTransformation (R ∘ F) X
δ : (M : Functor B C) → (α : NaturalTransformation (M ∘ F) X) → NaturalTransformation M R
.δ-unique : {M : Functor B C} → {α : NaturalTransformation (M ∘ F) X} →
(δ′ : NaturalTransformation M R) → α ≡ η ∘₁ (δ′ ∘ʳ F) → δ′ ≡ δ M α
.commutes : (M : Functor B C) → (α : NaturalTransformation (M ∘ F) X) → α ≡ η ∘₁ (δ M α ∘ʳ F)
| {
"alphanum_fraction": 0.5917375456,
"avg_line_length": 41.15,
"ext": "agda",
"hexsha": "a777c14a9943731332b55c2caebe04f343c3bf9b",
"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/Ran.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/Ran.agda",
"max_line_length": 103,
"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/Ran.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": 323,
"size": 823
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Hash
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Encode
-- This module brings in the base types used through libra
-- and those necessary for the abstract model.
module LibraBFT.Abstract.Types where
open import LibraBFT.Base.Types public
-- Simple way to flag meta-information without having it getting
-- in the way.
Meta : ∀{ℓ} → Set ℓ → Set ℓ
Meta x = x
-- An epoch-configuration carries only simple data about the epoch; the complicated
-- parts will be provided by the System, defined below.
--
-- The reason for the separation is that we should be able to provide
-- an EpochConfig from a single peer state.
record EpochConfig : Set₁ where
constructor mkEpochConfig
field
-- TODO-2 : This should really be a UID as Hash should not show up in the Abstract
-- namespace. This will require some refactoring of modules and reordering of
-- module parameters.
genesisUID : Hash
epochId : EpochId
authorsN : ℕ
-- The set of members of this epoch.
Member : Set
Member = Fin authorsN
-- There is a partial isomorphism between NodeIds and the
-- authors participating in this epoch.
field
toNodeId : Member → NodeId
isMember? : NodeId → Maybe Member
nodeid-author-id : ∀{α} → isMember? (toNodeId α) ≡ just α
author-nodeid-id : ∀{nid α} → isMember? nid ≡ just α
→ toNodeId α ≡ nid
getPubKey : Member → PK
PK-inj : ∀ {m1 m2} → getPubKey m1 ≡ getPubKey m2 → m1 ≡ m2
IsQuorum : List Member → Set
bft-assumption : ∀ {xs ys}
→ IsQuorum xs → IsQuorum ys
→ ∃[ α ] (α ∈ xs × α ∈ ys × Meta-Honest-PK (getPubKey α))
open EpochConfig
toNodeId-inj : ∀{𝓔}{x y : Member 𝓔} → toNodeId 𝓔 x ≡ toNodeId 𝓔 y → x ≡ y
toNodeId-inj {𝓔} hyp = just-injective (trans (sym (nodeid-author-id 𝓔))
(trans (cong (isMember? 𝓔) hyp)
(nodeid-author-id 𝓔)))
record EpochConfigFor (eid : ℕ) : Set₁ where
field
epochConfig : EpochConfig
forEpochId : epochId epochConfig ≡ eid
MemberSubst : ∀ {𝓔} {𝓔'}
→ 𝓔' ≡ 𝓔
→ EpochConfig.Member 𝓔
→ EpochConfig.Member 𝓔'
MemberSubst refl = id
-- A member of an epoch is considered "honest" iff its public key is honest.
Meta-Honest-Member : (𝓔 : EpochConfig) → Member 𝓔 → Set
Meta-Honest-Member 𝓔 α = Meta-Honest-PK (getPubKey 𝓔 α)
-- Naturally, if two witnesses that two authors belong
-- in the epoch are the same, then the authors are also the same.
--
-- This proof is very Galois-like, because of the way we structured
-- our partial isos. It's actually pretty nice! :)
member≡⇒author≡ : ∀{α β}{𝓔 : EpochConfig}
→ (authorα : Is-just (isMember? 𝓔 α))
→ (authorβ : Is-just (isMember? 𝓔 β))
→ to-witness authorα ≡ to-witness authorβ
→ α ≡ β
member≡⇒author≡ {α} {β} {𝓔} a b prf
with isMember? 𝓔 α | inspect (isMember? 𝓔) α
...| nothing | [ _ ] = ⊥-elim (maybe-any-⊥ a)
member≡⇒author≡ {α} {β} {𝓔} (just _) b prf
| just ra | [ RA ]
with isMember? 𝓔 β | inspect (isMember? 𝓔) β
...| nothing | [ _ ] = ⊥-elim (maybe-any-⊥ b)
member≡⇒author≡ {α} {β} {𝓔} (just _) (just _) prf
| just ra | [ RA ]
| just rb | [ RB ]
= trans (sym (author-nodeid-id 𝓔 RA))
(trans (cong (toNodeId 𝓔) prf)
(author-nodeid-id 𝓔 RB))
-- The abstract model is connected to the implementaton by means of
-- 'VoteEvidence'. The record module will be parameterized by a
-- v of type 'VoteEvidence 𝓔 UID'; this v will provide evidence
-- that a given author voted for a given block (identified by the UID)
-- on the specified round.
--
-- When it comes time to instantiate the v above concretely, it will
-- be something that states that we have a signature from the specified
-- author voting for the specified block.
record AbsVoteData (𝓔 : EpochConfig)(UID : Set) : Set where
constructor mkAbsVoteData
field
abs-vRound : Round
abs-vMember : EpochConfig.Member 𝓔
abs-vBlockUID : UID
open AbsVoteData public
AbsVoteData-η : ∀ {𝓔} {UID : Set} {r1 r2 : Round} {m1 m2 : EpochConfig.Member 𝓔} {b1 b2 : UID}
→ r1 ≡ r2
→ m1 ≡ m2
→ b1 ≡ b2
→ mkAbsVoteData {𝓔} {UID} r1 m1 b1 ≡ mkAbsVoteData r2 m2 b2
AbsVoteData-η refl refl refl = refl
VoteEvidence : EpochConfig → Set → Set₁
VoteEvidence 𝓔 UID = AbsVoteData 𝓔 UID → Set
| {
"alphanum_fraction": 0.6142456983,
"avg_line_length": 37.0222222222,
"ext": "agda",
"hexsha": "08e17a3d9ecface32c6106c9750dca465b1462c1",
"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": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_forks_repo_path": "LibraBFT/Abstract/Types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"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": "lisandrasilva/bft-consensus-agda-1",
"max_issues_repo_path": "LibraBFT/Abstract/Types.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7dd98dd90d98fbb934ef8cb4f3314940986790d",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "lisandrasilva/bft-consensus-agda-1",
"max_stars_repo_path": "LibraBFT/Abstract/Types.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1536,
"size": 4998
} |
module Thesis.Syntax where
open import Thesis.Types public
open import Thesis.Contexts public
data Const : (τ : Type) → Set where
unit : Const unit
lit : ℤ → Const int
plus : Const (int ⇒ int ⇒ int)
minus : Const (int ⇒ int ⇒ int)
cons : ∀ {t1 t2} → Const (t1 ⇒ t2 ⇒ pair t1 t2)
fst : ∀ {t1 t2} → Const (pair t1 t2 ⇒ t1)
snd : ∀ {t1 t2} → Const (pair t1 t2 ⇒ t2)
linj : ∀ {t1 t2} → Const (t1 ⇒ sum t1 t2)
rinj : ∀ {t1 t2} → Const (t2 ⇒ sum t1 t2)
match : ∀ {t1 t2 t3} → Const (sum t1 t2 ⇒ (t1 ⇒ t3) ⇒ (t2 ⇒ t3) ⇒ t3)
data Term (Γ : Context) :
(τ : Type) → Set where
-- constants aka. primitives
const : ∀ {τ} →
(c : Const τ) →
Term Γ τ
var : ∀ {τ} →
(x : Var Γ τ) →
Term Γ τ
app : ∀ {σ τ}
(s : Term Γ (σ ⇒ τ)) →
(t : Term Γ σ) →
Term Γ τ
-- we use de Bruijn indices, so we don't need binding occurrences.
abs : ∀ {σ τ}
(t : Term (σ • Γ) τ) →
Term Γ (σ ⇒ τ)
-- Weakening
weaken : ∀ {Γ₁ Γ₂ τ} →
(Γ₁≼Γ₂ : Γ₁ ≼ Γ₂) →
Term Γ₁ τ →
Term Γ₂ τ
weaken Γ₁≼Γ₂ (const c) = const c
weaken Γ₁≼Γ₂ (var x) = var (weaken-var Γ₁≼Γ₂ x)
weaken Γ₁≼Γ₂ (app s t) = app (weaken Γ₁≼Γ₂ s) (weaken Γ₁≼Γ₂ t)
weaken Γ₁≼Γ₂ (abs {σ} t) = abs (weaken (keep σ • Γ₁≼Γ₂) t)
-- Shorthands for nested applications
app₂ : ∀ {Γ α β γ} →
Term Γ (α ⇒ β ⇒ γ) →
Term Γ α → Term Γ β → Term Γ γ
app₂ f x = app (app f x)
app₃ : ∀ {Γ α β γ δ} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ
app₃ f x = app₂ (app f x)
app₄ : ∀ {Γ α β γ δ ε} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ →
Term Γ ε
app₄ f x = app₃ (app f x)
app₅ : ∀ {Γ α β γ δ ε ζ} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε ⇒ ζ) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ →
Term Γ ε → Term Γ ζ
app₅ f x = app₄ (app f x)
app₆ : ∀ {Γ α β γ δ ε ζ η} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε ⇒ ζ ⇒ η) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ →
Term Γ ε → Term Γ ζ → Term Γ η
app₆ f x = app₅ (app f x)
| {
"alphanum_fraction": 0.5178389399,
"avg_line_length": 26.16,
"ext": "agda",
"hexsha": "96b9b4eda38a03342eae5dfe8c2af427bf8cfd86",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Thesis/Syntax.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Thesis/Syntax.agda",
"max_line_length": 72,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Thesis/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 903,
"size": 1962
} |
open import Common.Reflection
macro
round-trip : Term → Tactic
round-trip v hole = unify v hole
module M (A : Set) where
data D : Set where
test : Set
test = round-trip D
| {
"alphanum_fraction": 0.6702702703,
"avg_line_length": 14.2307692308,
"ext": "agda",
"hexsha": "53651da983ceea7cfa8115c433ab77cbb55fe09f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1890.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1890.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1890.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": 58,
"size": 185
} |
module MissingWithClauses where
data D : Set where
c : D
f : D -> D
f c with c
| {
"alphanum_fraction": 0.6506024096,
"avg_line_length": 10.375,
"ext": "agda",
"hexsha": "de1355df4499f5450d14a19ace45a1269d22f7b0",
"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/MissingWithClauses.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/MissingWithClauses.agda",
"max_line_length": 31,
"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/MissingWithClauses.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": 83
} |
module PiInSet where
Rel : Set -> Set1
Rel A = A -> A -> Set
Reflexive : {A : Set} -> Rel A -> Set
Reflexive {A} _R_ = forall x -> x R x
Symmetric : {A : Set} -> Rel A -> Set
Symmetric {A} _R_ = forall x y -> x R y -> y R x
data True : Set where
tt : True
data False : Set where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
_==_ : Rel Nat
zero == zero = True
zero == suc _ = False
suc _ == zero = False
suc n == suc m = n == m
refl== : Reflexive _==_
refl== zero = tt
refl== (suc n) = refl== n
sym== : Symmetric _==_
sym== zero zero tt = tt
sym== zero (suc _) ()
sym== (suc _) zero ()
sym== (suc n) (suc m) n==m = sym== n m n==m
| {
"alphanum_fraction": 0.5402985075,
"avg_line_length": 17.6315789474,
"ext": "agda",
"hexsha": "d9eaa5691a8368591e1f3dffeff48089d92f43f0",
"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/PiInSet.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/PiInSet.agda",
"max_line_length": 48,
"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/PiInSet.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": 263,
"size": 670
} |
{-# OPTIONS --without-K --allow-unsolved-metas --exact-split #-}
module 21-pushouts where
import 20-pullbacks
open 20-pullbacks public
-- Section 14.1
{- We define the type of cocones with vertex X on a span. Since we will use it
later on, we will also characterize the identity type of the type of cocones
with a given vertex X. -}
cocone :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) → UU l4 → UU _
cocone {A = A} {B = B} f g X =
Σ (A → X) (λ i → Σ (B → X) (λ j → (i ∘ f) ~ (j ∘ g)))
{- We characterize the identity type of the type of cocones with vertex C. -}
coherence-htpy-cocone :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →
(K : (pr1 c) ~ (pr1 c')) (L : (pr1 (pr2 c)) ~ (pr1 (pr2 c'))) → UU (l1 ⊔ l4)
coherence-htpy-cocone f g c c' K L =
((pr2 (pr2 c)) ∙h (L ·r g)) ~ ((K ·r f) ∙h (pr2 (pr2 c')))
htpy-cocone :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} →
cocone f g X → cocone f g X → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4)))
htpy-cocone f g c c' =
Σ ((pr1 c) ~ (pr1 c'))
( λ K → Σ ((pr1 (pr2 c)) ~ (pr1 (pr2 c')))
( coherence-htpy-cocone f g c c' K))
reflexive-htpy-cocone :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
htpy-cocone f g c c
reflexive-htpy-cocone f g (pair i (pair j H)) =
pair refl-htpy (pair refl-htpy htpy-right-unit)
htpy-cocone-eq :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →
Id c c' → htpy-cocone f g c c'
htpy-cocone-eq f g c .c refl = reflexive-htpy-cocone f g c
is-contr-total-htpy-cocone :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
is-contr (Σ (cocone f g X) (htpy-cocone f g c))
is-contr-total-htpy-cocone f g c =
is-contr-total-Eq-structure
( λ i' jH' K → Σ ((pr1 (pr2 c)) ~ (pr1 jH'))
( coherence-htpy-cocone f g c (pair i' jH') K))
( is-contr-total-htpy (pr1 c))
( pair (pr1 c) refl-htpy)
( is-contr-total-Eq-structure
( λ j' H' → coherence-htpy-cocone f g c
( pair (pr1 c) (pair j' H'))
( refl-htpy))
( is-contr-total-htpy (pr1 (pr2 c)))
( pair (pr1 (pr2 c)) refl-htpy)
( is-contr-is-equiv'
( Σ (((pr1 c) ∘ f) ~ ((pr1 (pr2 c)) ∘ g)) (λ H' → (pr2 (pr2 c)) ~ H'))
( tot (λ H' M → htpy-right-unit ∙h M))
( is-equiv-tot-is-fiberwise-equiv (λ H' → is-equiv-htpy-concat _ _))
( is-contr-total-htpy (pr2 (pr2 c)))))
is-equiv-htpy-cocone-eq :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →
is-equiv (htpy-cocone-eq f g c c')
is-equiv-htpy-cocone-eq f g c =
fundamental-theorem-id c
( reflexive-htpy-cocone f g c)
( is-contr-total-htpy-cocone f g c)
( htpy-cocone-eq f g c)
eq-htpy-cocone :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) →
htpy-cocone f g c c' → Id c c'
eq-htpy-cocone f g c c' = inv-is-equiv (is-equiv-htpy-cocone-eq f g c c')
{- Given a cocone c on a span S with vertex X, and a type Y, the function
cocone-map sends a function X → Y to a new cocone with vertex Y. -}
cocone-map :
{l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} {Y : UU l5} →
cocone f g X → (X → Y) → cocone f g Y
cocone-map f g (pair i (pair j H)) h =
pair (h ∘ i) (pair (h ∘ j) (h ·l H))
cocone-map-id :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
Id (cocone-map f g c id) c
cocone-map-id f g (pair i (pair j H)) =
eq-pair refl (eq-pair refl (eq-htpy (λ s → ap-id (H s))))
cocone-map-comp :
{l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X)
{Y : UU l5} (h : X → Y) {Z : UU l6} (k : Y → Z) →
Id (cocone-map f g c (k ∘ h)) (cocone-map f g (cocone-map f g c h) k)
cocone-map-comp f g (pair i (pair j H)) h k =
eq-pair refl (eq-pair refl (eq-htpy (λ s → ap-comp k h (H s))))
{- A cocone c on a span S is said to satisfy the universal property of the
pushout of S if the function cocone-map is an equivalence for every type Y.
-}
universal-property-pushout :
{l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} →
cocone f g X → UU _
universal-property-pushout l f g c =
(Y : UU l) → is-equiv (cocone-map f g {Y = Y} c)
map-universal-property-pushout :
{l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
( up-c : {l : Level} → universal-property-pushout l f g c)
{Y : UU l5} → cocone f g Y → (X → Y)
map-universal-property-pushout f g c up-c {Y} = inv-is-equiv (up-c Y)
htpy-cocone-map-universal-property-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
( f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
( up-c : {l : Level} → universal-property-pushout l f g c)
{ Y : UU l5} (d : cocone f g Y) →
htpy-cocone f g
( cocone-map f g c
( map-universal-property-pushout f g c up-c d))
( d)
htpy-cocone-map-universal-property-pushout f g c up-c {Y} d =
htpy-cocone-eq f g
( cocone-map f g c (map-universal-property-pushout f g c up-c d))
( d)
( issec-inv-is-equiv (up-c Y) d)
uniqueness-map-universal-property-pushout :
{ l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
( f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
( up-c : {l : Level} → universal-property-pushout l f g c) →
{ Y : UU l5} (d : cocone f g Y) →
is-contr ( Σ (X → Y) (λ h → htpy-cocone f g (cocone-map f g c h) d))
uniqueness-map-universal-property-pushout f g c up-c {Y} d =
is-contr-is-equiv'
( fib (cocone-map f g c) d)
( tot (λ h → htpy-cocone-eq f g (cocone-map f g c h) d))
( is-equiv-tot-is-fiberwise-equiv
( λ h → is-equiv-htpy-cocone-eq f g (cocone-map f g c h) d))
( is-contr-map-is-equiv (up-c Y) d)
{- We derive a 3-for-2 property of pushouts, analogous to the 3-for-2 property
of pullbacks. -}
triangle-cocone-cocone :
{ l1 l2 l3 l4 l5 l6 : Level}
{ S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5}
{ f : S → A} {g : S → B} (c : cocone f g X) (d : cocone f g Y)
( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d)
( Z : UU l6) →
( cocone-map f g d) ~ ((cocone-map f g c) ∘ (λ (k : Y → Z) → k ∘ h))
triangle-cocone-cocone {Y = Y} {f = f} {g = g} c d h KLM Z k =
inv
( ( cocone-map-comp f g c h k) ∙
( ap
( λ t → cocone-map f g t k)
( eq-htpy-cocone f g (cocone-map f g c h) d KLM)))
is-equiv-up-pushout-up-pushout :
{ l1 l2 l3 l4 l5 : Level}
{ S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5}
( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) →
( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) →
( up-c : {l : Level} → universal-property-pushout l f g c) →
( up-d : {l : Level} → universal-property-pushout l f g d) →
is-equiv h
is-equiv-up-pushout-up-pushout f g c d h KLM up-c up-d =
is-equiv-is-equiv-precomp h
( λ l Z →
is-equiv-right-factor
( cocone-map f g d)
( cocone-map f g c)
( precomp h Z)
( triangle-cocone-cocone c d h KLM Z)
( up-c Z)
( up-d Z))
up-pushout-up-pushout-is-equiv :
{ l1 l2 l3 l4 l5 : Level}
{ S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5}
( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) →
( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) →
is-equiv h →
( up-c : {l : Level} → universal-property-pushout l f g c) →
{l : Level} → universal-property-pushout l f g d
up-pushout-up-pushout-is-equiv f g c d h KLM is-equiv-h up-c Z =
is-equiv-comp
( cocone-map f g d)
( cocone-map f g c)
( precomp h Z)
( triangle-cocone-cocone c d h KLM Z)
( is-equiv-precomp-is-equiv h is-equiv-h Z)
( up-c Z)
up-pushout-is-equiv-up-pushout :
{ l1 l2 l3 l4 l5 : Level}
{ S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5}
( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) →
( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) →
( up-d : {l : Level} → universal-property-pushout l f g d) →
is-equiv h →
{l : Level} → universal-property-pushout l f g c
up-pushout-is-equiv-up-pushout f g c d h KLM up-d is-equiv-h Z =
is-equiv-left-factor
( cocone-map f g d)
( cocone-map f g c)
( precomp h Z)
( triangle-cocone-cocone c d h KLM Z)
( up-d Z)
( is-equiv-precomp-is-equiv h is-equiv-h Z)
uniquely-unique-pushout :
{ l1 l2 l3 l4 l5 : Level}
{ S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5}
( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) →
( up-c : {l : Level} → universal-property-pushout l f g c) →
( up-d : {l : Level} → universal-property-pushout l f g d) →
is-contr
( Σ (X ≃ Y) (λ e → htpy-cocone f g (cocone-map f g c (map-equiv e)) d))
uniquely-unique-pushout f g c d up-c up-d =
is-contr-total-Eq-substructure
( uniqueness-map-universal-property-pushout f g c up-c d)
( is-subtype-is-equiv)
( map-universal-property-pushout f g c up-c d)
( htpy-cocone-map-universal-property-pushout f g c up-c d)
( is-equiv-up-pushout-up-pushout f g c d
( map-universal-property-pushout f g c up-c d)
( htpy-cocone-map-universal-property-pushout f g c up-c d)
( up-c)
( up-d))
{- We will assume that every span has a pushout. Moreover, we will introduce
some further terminology to facilitate working with these pushouts. -}
postulate pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → UU (l1 ⊔ l2 ⊔ l3)
postulate inl-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → A → pushout f g
postulate inr-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → B → pushout f g
postulate glue-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → ((inl-pushout f g) ∘ f) ~ ((inr-pushout f g) ∘ g)
cocone-pushout :
{l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) → cocone f g (pushout f g)
cocone-pushout f g =
pair
( inl-pushout f g)
( pair
( inr-pushout f g)
( glue-pushout f g))
postulate up-pushout : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → universal-property-pushout l4 f g (cocone-pushout f g)
cogap :
{ l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
( f : S → A) (g : S → B) →
{ X : UU l4} (c : cocone f g X) → pushout f g → X
cogap f g =
map-universal-property-pushout f g
( cocone-pushout f g)
( up-pushout f g)
is-pushout :
{ l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3}
( f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
UU (l1 ⊔ l2 ⊔ l3 ⊔ l4)
is-pushout f g c = is-equiv (cogap f g c)
-- Section 14.2 Suspensions
suspension-structure :
{l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (l1 ⊔ l2)
suspension-structure X Y = Σ Y (λ N → Σ Y (λ S → (x : X) → Id N S))
suspension-cocone' :
{l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (l1 ⊔ l2)
suspension-cocone' X Y = cocone (const X unit star) (const X unit star) Y
cocone-suspension-structure :
{l1 l2 : Level} (X : UU l1) (Y : UU l2) →
suspension-structure X Y → suspension-cocone' X Y
cocone-suspension-structure X Y (pair N (pair S merid)) =
pair
( const unit Y N)
( pair
( const unit Y S)
( merid))
universal-property-suspension' :
(l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2)
(susp-str : suspension-structure X Y) → UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-suspension' l X Y susp-str-Y =
universal-property-pushout l
( const X unit star)
( const X unit star)
( cocone-suspension-structure X Y susp-str-Y)
is-suspension :
(l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (lsuc l ⊔ l1 ⊔ l2)
is-suspension l X Y =
Σ (suspension-structure X Y) (universal-property-suspension' l X Y)
suspension :
{l : Level} → UU l → UU l
suspension X = pushout (const X unit star) (const X unit star)
N-susp :
{l : Level} {X : UU l} → suspension X
N-susp {X = X} = inl-pushout (const X unit star) (const X unit star) star
S-susp :
{l : Level} {X : UU l} → suspension X
S-susp {X = X} = inr-pushout (const X unit star) (const X unit star) star
merid-susp :
{l : Level} {X : UU l} → X → Id (N-susp {X = X}) (S-susp {X = X})
merid-susp {X = X} = glue-pushout (const X unit star) (const X unit star)
sphere : ℕ → UU lzero
sphere zero-ℕ = bool
sphere (succ-ℕ n) = suspension (sphere n)
N-sphere : (n : ℕ) → sphere n
N-sphere zero-ℕ = true
N-sphere (succ-ℕ n) = N-susp
S-sphere : (n : ℕ) → sphere n
S-sphere zero-ℕ = false
S-sphere (succ-ℕ n) = S-susp
{- We now work towards Lemma 17.2.2. -}
suspension-cocone :
{l1 l2 : Level} (X : UU l1) (Z : UU l2) → UU _
suspension-cocone X Z = Σ Z (λ z1 → Σ Z (λ z2 → (x : X) → Id z1 z2))
ev-suspension :
{l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} →
(susp-str-Y : suspension-structure X Y) →
(Z : UU l3) → (Y → Z) → suspension-cocone X Z
ev-suspension (pair N (pair S merid)) Z h =
pair (h N) (pair (h S) (h ·l merid))
universal-property-suspension :
(l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) →
suspension-structure X Y → UU (lsuc l ⊔ l1 ⊔ l2)
universal-property-suspension l X Y susp-str-Y =
(Z : UU l) → is-equiv (ev-suspension susp-str-Y Z)
comparison-suspension-cocone :
{l1 l2 : Level} (X : UU l1) (Z : UU l2) →
suspension-cocone' X Z ≃ suspension-cocone X Z
comparison-suspension-cocone X Z =
equiv-toto
( λ z1 → Σ Z (λ z2 → (x : X) → Id z1 z2))
( equiv-ev-star' Z)
( λ z1 →
equiv-toto
( λ z2 → (x : X) → Id (z1 star) z2)
( equiv-ev-star' Z)
( λ z2 → equiv-id ((x : X) → Id (z1 star) (z2 star))))
map-comparison-suspension-cocone :
{l1 l2 : Level} (X : UU l1) (Z : UU l2) →
suspension-cocone' X Z → suspension-cocone X Z
map-comparison-suspension-cocone X Z =
map-equiv (comparison-suspension-cocone X Z)
is-equiv-map-comparison-suspension-cocone :
{l1 l2 : Level} (X : UU l1) (Z : UU l2) →
is-equiv (map-comparison-suspension-cocone X Z)
is-equiv-map-comparison-suspension-cocone X Z =
is-equiv-map-equiv (comparison-suspension-cocone X Z)
triangle-ev-suspension :
{l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} →
(susp-str-Y : suspension-structure X Y) →
(Z : UU l3) →
( ( map-comparison-suspension-cocone X Z) ∘
( cocone-map
( const X unit star)
( const X unit star)
( cocone-suspension-structure X Y susp-str-Y))) ~
( ev-suspension susp-str-Y Z)
triangle-ev-suspension (pair N (pair S merid)) Z h = refl
is-equiv-ev-suspension :
{ l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} →
( susp-str-Y : suspension-structure X Y) →
( up-Y : universal-property-suspension' l3 X Y susp-str-Y) →
( Z : UU l3) → is-equiv (ev-suspension susp-str-Y Z)
is-equiv-ev-suspension {X = X} susp-str-Y up-Y Z =
is-equiv-comp
( ev-suspension susp-str-Y Z)
( map-comparison-suspension-cocone X Z)
( cocone-map
( const X unit star)
( const X unit star)
( cocone-suspension-structure X _ susp-str-Y))
( htpy-inv (triangle-ev-suspension susp-str-Y Z))
( up-Y Z)
( is-equiv-map-comparison-suspension-cocone X Z)
{- Pointed maps and pointed homotopies. -}
pointed-fam :
{l1 : Level} (l : Level) (X : UU-pt l1) → UU (lsuc l ⊔ l1)
pointed-fam l (pair X x) = Σ (X → UU l) (λ P → P x)
pointed-Π :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → UU (l1 ⊔ l2)
pointed-Π (pair X x) (pair P p) = Σ ((x' : X) → P x') (λ f → Id (f x) p)
pointed-htpy :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →
(f g : pointed-Π X P) → UU (l1 ⊔ l2)
pointed-htpy (pair X x) (pair P p) (pair f α) g =
pointed-Π (pair X x) (pair (λ x' → Id (f x') (pr1 g x')) (α ∙ (inv (pr2 g))))
pointed-refl-htpy :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →
(f : pointed-Π X P) → pointed-htpy X P f f
pointed-refl-htpy (pair X x) (pair P p) (pair f α) =
pair refl-htpy (inv (right-inv α))
pointed-htpy-eq :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →
(f g : pointed-Π X P) → Id f g → pointed-htpy X P f g
pointed-htpy-eq X P f .f refl = pointed-refl-htpy X P f
is-contr-total-pointed-htpy :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) (f : pointed-Π X P) →
is-contr (Σ (pointed-Π X P) (pointed-htpy X P f))
is-contr-total-pointed-htpy (pair X x) (pair P p) (pair f α) =
is-contr-total-Eq-structure
( λ g β (H : f ~ g) → Id (H x) (α ∙ (inv β)))
( is-contr-total-htpy f)
( pair f refl-htpy)
( is-contr-equiv'
( Σ (Id (f x) p) (λ β → Id β α))
( equiv-tot (λ β → equiv-con-inv refl β α))
( is-contr-total-path' α))
is-equiv-pointed-htpy-eq :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →
(f g : pointed-Π X P) → is-equiv (pointed-htpy-eq X P f g)
is-equiv-pointed-htpy-eq X P f =
fundamental-theorem-id f
( pointed-refl-htpy X P f)
( is-contr-total-pointed-htpy X P f)
( pointed-htpy-eq X P f)
eq-pointed-htpy :
{l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) →
(f g : pointed-Π X P) → (pointed-htpy X P f g) → Id f g
eq-pointed-htpy X P f g = inv-is-equiv (is-equiv-pointed-htpy-eq X P f g)
-- Section 14.3 Duality of pushouts and pullbacks
{- The universal property of the pushout of a span S can also be stated as a
pullback-property: a cocone c = (pair i (pair j H)) with vertex X
satisfies the universal property of the pushout of S if and only if the
square
Y^X -----> Y^B
| |
| |
V V
Y^A -----> Y^S
is a pullback square for every type Y. Below, we first define the cone of
this commuting square, and then we introduce the type
pullback-property-pushout, which states that the above square is a pullback.
-}
htpy-precomp :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{f g : A → B} (H : f ~ g) (C : UU l3) →
(precomp f C) ~ (precomp g C)
htpy-precomp H C h = eq-htpy (h ·l H)
compute-htpy-precomp :
{l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : UU l3) →
(htpy-precomp (refl-htpy' f) C) ~ refl-htpy
compute-htpy-precomp f C h = eq-htpy-refl-htpy (h ∘ f)
cone-pullback-property-pushout :
{l1 l2 l3 l4 l : Level} {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) (Y : UU l) →
cone (λ (h : A → Y) → h ∘ f) (λ (h : B → Y) → h ∘ g) (X → Y)
cone-pullback-property-pushout f g {X} c Y =
pair
( precomp (pr1 c) Y)
( pair
( precomp (pr1 (pr2 c)) Y)
( htpy-precomp (pr2 (pr2 c)) Y))
pullback-property-pushout :
{l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3}
(f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
UU (l1 ⊔ (l2 ⊔ (l3 ⊔ (l4 ⊔ lsuc l))))
pullback-property-pushout l {S} {A} {B} f g {X} c =
(Y : UU l) → is-pullback
( precomp f Y)
( precomp g Y)
( cone-pullback-property-pushout f g c Y)
{- In order to show that the universal property of pushouts is equivalent to
the pullback property, we show that the maps cocone-map and the gap map fit
in a commuting triangle, where the third map is an equivalence. The claim
then follows from the 3-for-2 property of equivalences. -}
triangle-pullback-property-pushout-universal-property-pushout :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2}
{B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
{l : Level} (Y : UU l) →
( cocone-map f g c) ~
( ( tot (λ i' → tot (λ j' p → htpy-eq p))) ∘
( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y)))
triangle-pullback-property-pushout-universal-property-pushout
{S = S} {A = A} {B = B} f g (pair i (pair j H)) Y h =
eq-pair refl (eq-pair refl (inv (issec-eq-htpy (h ·l H))))
pullback-property-pushout-universal-property-pushout :
{l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2}
{B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
universal-property-pushout l f g c → pullback-property-pushout l f g c
pullback-property-pushout-universal-property-pushout
l f g (pair i (pair j H)) up-c Y =
let c = (pair i (pair j H)) in
is-equiv-right-factor
( cocone-map f g c)
( tot (λ i' → tot (λ j' p → htpy-eq p)))
( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y))
( triangle-pullback-property-pushout-universal-property-pushout f g c Y)
( is-equiv-tot-is-fiberwise-equiv
( λ i' → is-equiv-tot-is-fiberwise-equiv
( λ j' → funext (i' ∘ f) (j' ∘ g))))
( up-c Y)
universal-property-pushout-pullback-property-pushout :
{l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2}
{B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) →
pullback-property-pushout l f g c → universal-property-pushout l f g c
universal-property-pushout-pullback-property-pushout
l f g (pair i (pair j H)) pb-c Y =
let c = (pair i (pair j H)) in
is-equiv-comp
( cocone-map f g c)
( tot (λ i' → tot (λ j' p → htpy-eq p)))
( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y))
( triangle-pullback-property-pushout-universal-property-pushout f g c Y)
( pb-c Y)
( is-equiv-tot-is-fiberwise-equiv
( λ i' → is-equiv-tot-is-fiberwise-equiv
( λ j' → funext (i' ∘ f) (j' ∘ g))))
cocone-compose-horizontal :
{ l1 l2 l3 l4 l5 l6 : Level}
{ A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6}
( f : A → X) (i : A → B) (k : B → C) →
( c : cocone f i Y) (d : cocone (pr1 (pr2 c)) k Z) →
cocone f (k ∘ i) Z
cocone-compose-horizontal f i k (pair j (pair g H)) (pair l (pair h K)) =
pair
( l ∘ j)
( pair
( h)
( (l ·l H) ∙h (K ·r i)))
{-
is-pushout-rectangle-is-pushout-right-square :
( l : Level) { l1 l2 l3 l4 l5 l6 : Level}
{ A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6}
( f : A → X) (i : A → B) (k : B → C) →
( c : cocone f i Y) (d : cocone (pr1 (pr2 c)) k Z) →
universal-property-pushout l f i c →
universal-property-pushout l (pr1 (pr2 c)) k d →
universal-property-pushout l f (k ∘ i) (cocone-compose-horizontal f i k c d)
is-pushout-rectangle-is-pushout-right-square l f i k c d up-Y up-Z =
universal-property-pushout-pullback-property-pushout l f (k ∘ i)
( cocone-compose-horizontal f i k c d)
( λ T → is-pullback-htpy {!!} {!!} {!!} {!!} {!!} {!!} {!!})
-}
-- Examples of pushouts
{- The cofiber of a map. -}
cofiber :
{l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2)
cofiber {A = A} f = pushout f (const A unit star)
cocone-cofiber :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
cocone f (const A unit star) (cofiber f)
cocone-cofiber {A = A} f = cocone-pushout f (const A unit star)
inl-cofiber :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → B → cofiber f
inl-cofiber {A = A} f = pr1 (cocone-cofiber f)
inr-cofiber :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → unit → cofiber f
inr-cofiber f = pr1 (pr2 (cocone-cofiber f))
pt-cofiber :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → cofiber f
pt-cofiber {A = A} f = inr-cofiber f star
cofiber-ptd :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → UU-pt (l1 ⊔ l2)
cofiber-ptd f = pair (cofiber f) (pt-cofiber f)
up-cofiber :
{ l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
( {l : Level} →
universal-property-pushout l f (const A unit star) (cocone-cofiber f))
up-cofiber {A = A} f = up-pushout f (const A unit star)
_*_ :
{l1 l2 : Level} (A : UU l1) (B : UU l2) → UU (l1 ⊔ l2)
A * B = pushout (pr1 {A = A} {B = λ x → B}) pr2
cocone-join :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
cocone (pr1 {A = A} {B = λ x → B}) pr2 (A * B)
cocone-join A B = cocone-pushout pr1 pr2
up-join :
{l1 l2 : Level} (A : UU l1) (B : UU l2) →
( {l : Level} → universal-property-pushout l
( pr1 {A = A} {B = λ x → B}) pr2 (cocone-join A B))
up-join A B = up-pushout pr1 pr2
inl-join :
{l1 l2 : Level} (A : UU l1) (B : UU l2) → A → A * B
inl-join A B = pr1 (cocone-join A B)
inr-join :
{l1 l2 : Level} (A : UU l1) (B : UU l2) → B → A * B
inr-join A B = pr1 (pr2 (cocone-join A B))
glue-join :
{l1 l2 : Level} (A : UU l1) (B : UU l2) (t : A × B) →
Id (inl-join A B (pr1 t)) (inr-join A B (pr2 t))
glue-join A B = pr2 (pr2 (cocone-join A B))
_∨_ :
{l1 l2 : Level} (A : UU-pt l1) (B : UU-pt l2) → UU-pt (l1 ⊔ l2)
A ∨ B =
pair
( pushout
( const unit (pr1 A) (pr2 A))
( const unit (pr1 B) (pr2 B)))
( inl-pushout
( const unit (pr1 A) (pr2 A))
( const unit (pr1 B) (pr2 B))
( pr2 A))
indexed-wedge :
{l1 l2 : Level} (I : UU l1) (A : I → UU-pt l2) → UU-pt (l1 ⊔ l2)
indexed-wedge I A =
pair
( cofiber (λ i → pair i (pr2 (A i))))
( pt-cofiber (λ i → pair i (pr2 (A i))))
wedge-inclusion :
{l1 l2 : Level} (A : UU-pt l1) (B : UU-pt l2) →
pr1 (A ∨ B) → (pr1 A) × (pr1 B)
wedge-inclusion {l1} {l2} (pair A a) (pair B b) =
inv-is-equiv
( up-pushout
( const unit A a)
( const unit B b)
( A × B))
( pair
( λ x → pair x b)
( pair
( λ y → pair a y)
( refl-htpy)))
-- Exercises
-- Exercise 13.1
-- Exercise 13.2
is-equiv-universal-property-pushout :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(f : S → A) (g : S → B) (c : cocone f g C) →
is-equiv f →
({l : Level} → universal-property-pushout l f g c) → is-equiv (pr1 (pr2 c))
is-equiv-universal-property-pushout
{A = A} {B} f g (pair i (pair j H)) is-equiv-f up-c =
is-equiv-is-equiv-precomp j
( λ l T →
is-equiv-is-pullback'
( λ (h : A → T) → h ∘ f)
( λ (h : B → T) → h ∘ g)
( cone-pullback-property-pushout f g (pair i (pair j H)) T)
( is-equiv-precomp-is-equiv f is-equiv-f T)
( pullback-property-pushout-universal-property-pushout
l f g (pair i (pair j H)) up-c T))
equiv-universal-property-pushout :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(e : S ≃ A) (g : S → B) (c : cocone (map-equiv e) g C) →
({l : Level} → universal-property-pushout l (map-equiv e) g c) →
B ≃ C
equiv-universal-property-pushout e g c up-c =
pair
( pr1 (pr2 c))
( is-equiv-universal-property-pushout
( map-equiv e)
( g)
( c)
( is-equiv-map-equiv e)
( up-c))
is-equiv-universal-property-pushout' :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(f : S → A) (g : S → B) (c : cocone f g C) →
is-equiv g →
({l : Level} → universal-property-pushout l f g c) →
is-equiv (pr1 c)
is-equiv-universal-property-pushout' f g (pair i (pair j H)) is-equiv-g up-c =
is-equiv-is-equiv-precomp i
( λ l T →
is-equiv-is-pullback
( precomp f T)
( precomp g T)
( cone-pullback-property-pushout f g (pair i (pair j H)) T)
( is-equiv-precomp-is-equiv g is-equiv-g T)
( pullback-property-pushout-universal-property-pushout
l f g (pair i (pair j H)) up-c T))
equiv-universal-property-pushout' :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(f : S → A) (e : S ≃ B) (c : cocone f (map-equiv e) C) →
({l : Level} → universal-property-pushout l f (map-equiv e) c) →
A ≃ C
equiv-universal-property-pushout' f e c up-c =
pair
( pr1 c)
( is-equiv-universal-property-pushout'
( f)
( map-equiv e)
( c)
( is-equiv-map-equiv e)
( up-c))
universal-property-pushout-is-equiv :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(f : S → A) (g : S → B) (c : cocone f g C) →
is-equiv f → is-equiv (pr1 (pr2 c)) →
({l : Level} → universal-property-pushout l f g c)
universal-property-pushout-is-equiv f g (pair i (pair j H)) is-equiv-f is-equiv-j {l} =
let c = (pair i (pair j H)) in
universal-property-pushout-pullback-property-pushout l f g c
( λ T → is-pullback-is-equiv'
( λ h → h ∘ f)
( λ h → h ∘ g)
( cone-pullback-property-pushout f g c T)
( is-equiv-precomp-is-equiv f is-equiv-f T)
( is-equiv-precomp-is-equiv j is-equiv-j T))
universal-property-pushout-is-equiv' :
{l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(f : S → A) (g : S → B) (c : cocone f g C) →
is-equiv g → is-equiv (pr1 c) →
({l : Level} → universal-property-pushout l f g c)
universal-property-pushout-is-equiv'
f g (pair i (pair j H)) is-equiv-g is-equiv-i {l} =
let c = (pair i (pair j H)) in
universal-property-pushout-pullback-property-pushout l f g c
( λ T → is-pullback-is-equiv
( precomp f T)
( precomp g T)
( cone-pullback-property-pushout f g c T)
( is-equiv-precomp-is-equiv g is-equiv-g T)
( is-equiv-precomp-is-equiv i is-equiv-i T))
is-contr-suspension-is-contr :
{l : Level} {X : UU l} → is-contr X → is-contr (suspension X)
is-contr-suspension-is-contr {l} {X} is-contr-X =
is-contr-is-equiv'
( unit)
( pr1 (pr2 (cocone-pushout (const X unit star) (const X unit star))))
( is-equiv-universal-property-pushout
( const X unit star)
( const X unit star)
( cocone-pushout
( const X unit star)
( const X unit star))
( is-equiv-is-contr (const X unit star) is-contr-X is-contr-unit)
( up-pushout (const X unit star) (const X unit star)))
( is-contr-unit)
is-contr-cofiber-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) →
is-equiv f → is-contr (cofiber f)
is-contr-cofiber-is-equiv {A = A} {B} f is-equiv-f =
is-contr-is-equiv'
( unit)
( pr1 (pr2 (cocone-cofiber f)))
( is-equiv-universal-property-pushout
( f)
( const A unit star)
( cocone-cofiber f)
( is-equiv-f)
( up-cofiber f))
( is-contr-unit)
is-equiv-cofiber-point :
{l : Level} {B : UU l} (b : B) →
is-equiv (pr1 (cocone-pushout (const unit B b) (const unit unit star)))
is-equiv-cofiber-point {l} {B} b =
is-equiv-universal-property-pushout'
( const unit B b)
( const unit unit star)
( cocone-pushout (const unit B b) (const unit unit star))
( is-equiv-is-contr (const unit unit star) is-contr-unit is-contr-unit)
( up-pushout (const unit B b) (const unit unit star))
is-equiv-inr-join-empty :
{l : Level} (X : UU l) → is-equiv (inr-join empty X)
is-equiv-inr-join-empty X =
is-equiv-universal-property-pushout
( pr1 {A = empty} {B = λ t → X})
( pr2)
( cocone-join empty X)
( is-equiv-pr1-prod-empty X)
( up-join empty X)
left-unit-law-join :
{l : Level} (X : UU l) → X ≃ (empty * X)
left-unit-law-join X =
pair (inr-join empty X) (is-equiv-inr-join-empty X)
is-equiv-inl-join-empty :
{l : Level} (X : UU l) → is-equiv (inl-join X empty)
is-equiv-inl-join-empty X =
is-equiv-universal-property-pushout'
( pr1)
( pr2)
( cocone-join X empty)
( is-equiv-pr2-prod-empty X)
( up-join X empty)
right-unit-law-join :
{l : Level} (X : UU l) → X ≃ (X * empty)
right-unit-law-join X =
pair (inl-join X empty) (is-equiv-inl-join-empty X)
inv-map-left-unit-law-prod :
{l : Level} (X : UU l) → X → (unit × X)
inv-map-left-unit-law-prod X = pair star
issec-inv-map-left-unit-law-prod :
{l : Level} (X : UU l) → (pr2 ∘ (inv-map-left-unit-law-prod X)) ~ id
issec-inv-map-left-unit-law-prod X x = refl
isretr-inv-map-left-unit-law-prod :
{l : Level} (X : UU l) → ((inv-map-left-unit-law-prod X) ∘ pr2) ~ id
isretr-inv-map-left-unit-law-prod X (pair star x) = refl
is-equiv-left-unit-law-prod :
{l : Level} (X : UU l) → is-equiv (pr2 {A = unit} {B = λ t → X})
is-equiv-left-unit-law-prod X =
is-equiv-has-inverse
( inv-map-left-unit-law-prod X)
( issec-inv-map-left-unit-law-prod X)
( isretr-inv-map-left-unit-law-prod X)
left-unit-law-prod :
{l : Level} (X : UU l) → (unit × X) ≃ X
left-unit-law-prod X =
pair pr2 (is-equiv-left-unit-law-prod X)
is-equiv-inl-join-unit :
{l : Level} (X : UU l) → is-equiv (inl-join unit X)
is-equiv-inl-join-unit X =
is-equiv-universal-property-pushout'
( pr1)
( pr2)
( cocone-join unit X)
( is-equiv-left-unit-law-prod X)
( up-join unit X)
left-zero-law-join :
{l : Level} (X : UU l) → is-contr (unit * X)
left-zero-law-join X =
is-contr-equiv'
( unit)
( pair (inl-join unit X) (is-equiv-inl-join-unit X))
( is-contr-unit)
inv-map-right-unit-law-prod :
{l : Level} (X : UU l) → X → X × unit
inv-map-right-unit-law-prod X x = pair x star
issec-inv-map-right-unit-law-prod :
{l : Level} (X : UU l) → (pr1 ∘ (inv-map-right-unit-law-prod X)) ~ id
issec-inv-map-right-unit-law-prod X x = refl
isretr-inv-map-right-unit-law-prod :
{l : Level} (X : UU l) → ((inv-map-right-unit-law-prod X) ∘ pr1) ~ id
isretr-inv-map-right-unit-law-prod X (pair x star) = refl
is-equiv-right-unit-law-prod :
{l : Level} (X : UU l) → is-equiv (pr1 {A = X} {B = λ t → unit})
is-equiv-right-unit-law-prod X =
is-equiv-has-inverse
( inv-map-right-unit-law-prod X)
( issec-inv-map-right-unit-law-prod X)
( isretr-inv-map-right-unit-law-prod X)
right-unit-law-prod :
{l : Level} (X : UU l) → (X × unit) ≃ X
right-unit-law-prod X =
pair pr1 (is-equiv-right-unit-law-prod X)
is-equiv-inr-join-unit :
{l : Level} (X : UU l) → is-equiv (inr-join X unit)
is-equiv-inr-join-unit X =
is-equiv-universal-property-pushout
( pr1)
( pr2)
( cocone-join X unit)
( is-equiv-right-unit-law-prod X)
( up-join X unit)
right-zero-law-join :
{l : Level} (X : UU l) → is-contr (X * unit)
right-zero-law-join X =
is-contr-equiv'
( unit)
( pair (inr-join X unit) (is-equiv-inr-join-unit X))
( is-contr-unit)
unit-pt : UU-pt lzero
unit-pt = pair unit star
is-contr-pt :
{l : Level} → UU-pt l → UU l
is-contr-pt A = is-contr (pr1 A)
-- Exercise 16.2
-- ev-disjunction :
-- {l1 l2 l3 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) (R : UU-Prop l3) →
-- ((type-Prop P) * (type-Prop Q) → (type-Prop R)) →
-- (type-Prop P → type-Prop R) × (type-Prop Q → type-Prop R)
-- ev-disjunction P Q R f =
-- pair
-- ( f ∘ (inl-join (type-Prop P) (type-Prop Q)))
-- ( f ∘ (inr-join (type-Prop P) (type-Prop Q)))
-- comparison-ev-disjunction :
-- {l1 l2 l3 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) (R : UU-Prop l3) →
-- cocone-join (type-Prop P) (type-Prop Q) (type-Prop R)
-- universal-property-disjunction-join-prop :
-- {l1 l2 l3 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) (R : UU-Prop l3) →
-- is-equiv (ev-disjunction P Q R)
| {
"alphanum_fraction": 0.5655887562,
"avg_line_length": 35.4670719352,
"ext": "agda",
"hexsha": "ac93ee92b5b9acec082b7b0ae81f36dd4c098318",
"lang": "Agda",
"max_forks_count": 30,
"max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z",
"max_forks_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "hemangandhi/HoTT-Intro",
"max_forks_repo_path": "Agda/21-pushouts.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "hemangandhi/HoTT-Intro",
"max_issues_repo_path": "Agda/21-pushouts.agda",
"max_line_length": 161,
"max_stars_count": 333,
"max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "hemangandhi/HoTT-Intro",
"max_stars_repo_path": "Agda/21-pushouts.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z",
"num_tokens": 14274,
"size": 35006
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Monoidal
-- the definition used here is not very similar to what one usually sees in nLab or
-- any textbook. the difference is that usually closed monoidal category is defined
-- through a right adjoint of -⊗X, which is [X,-]. then there is an induced bifunctor
-- [-,-].
--
-- but in proof relevant context, the induced bifunctor [-,-] does not have to be
-- exactly the intended bifunctor! in fact, one can probably only show that the
-- intended bifunctor is only naturally isomorphic to the induced one, which is
-- significantly weaker.
--
-- the approach taken here as an alternative is to BEGIN with a bifunctor
-- already. however, is it required to have mates between any given two adjoints. this
-- definition can be shown equivalent to the previous one but just works better.
module Categories.Category.Monoidal.Closed {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where
private
module C = Category C
open Category C
variable
X Y A B : Obj
open import Level
open import Data.Product using (_,_)
open import Categories.Adjoint
open import Categories.Adjoint.Mate
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor
open import Categories.Functor.Hom
open import Categories.Category.Instance.Setoids
open import Categories.NaturalTransformation hiding (id)
open import Categories.NaturalTransformation.Properties
open import Categories.NaturalTransformation.NaturalIsomorphism as NI
record Closed : Set (levelOfTerm M) where
open Monoidal M public
field
[-,-] : Bifunctor C.op C C
adjoint : (-⊗ X) ⊣ appˡ [-,-] X
mate : (f : X ⇒ Y) → Mate (adjoint {X}) (adjoint {Y}) (appʳ-nat ⊗ f) (appˡ-nat [-,-] f)
module [-,-] = Functor [-,-]
module adjoint {X} = Adjoint (adjoint {X})
module mate {X Y} f = Mate (mate {X} {Y} f)
[_,-] : Obj → Functor C C
[_,-] = appˡ [-,-]
[-,_] : Obj → Functor C.op C
[-,_] = appʳ [-,-]
[_,_]₀ : Obj → Obj → Obj
[ X , Y ]₀ = [-,-].F₀ (X , Y)
[_,_]₁ : A ⇒ B → X ⇒ Y → [ B , X ]₀ ⇒ [ A , Y ]₀
[ f , g ]₁ = [-,-].F₁ (f , g)
Hom[-⊗_,-] : ∀ X → Bifunctor C.op C (Setoids ℓ e)
Hom[-⊗ X ,-] = adjoint.Hom[L-,-] {X}
Hom[-,[_,-]] : ∀ X → Bifunctor C.op C (Setoids ℓ e)
Hom[-,[ X ,-]] = adjoint.Hom[-,R-] {X}
Hom-NI : ∀ {X : Obj} → NaturalIsomorphism Hom[-⊗ X ,-] Hom[-,[ X ,-]]
Hom-NI = Hom-NI′ adjoint
| {
"alphanum_fraction": 0.6552706553,
"avg_line_length": 33.6575342466,
"ext": "agda",
"hexsha": "071597c56ad1ea8ad85fa6f5a17c3b28044ea33c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Closed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Closed.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Closed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 765,
"size": 2457
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Bifunctor where
open import Level
open import Data.Product using (_,_; swap)
open import Categories.Category
open import Categories.Functor public
open import Categories.Product
Bifunctor : ∀ {o ℓ e} {o′ ℓ′ e′} {o′′ ℓ′′ e′′} → Category o ℓ e → Category o′ ℓ′ e′ → Category o′′ ℓ′′ e′′ → Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′ ⊔ o′′ ⊔ ℓ′′ ⊔ e′′)
Bifunctor C D E = Functor (Product C D) E
overlap-× : ∀ {o ℓ e} {o′₁ ℓ′₁ e′₁} {o′₂ ℓ′₂ e′₂} {C : Category o ℓ e} {D₁ : Category o′₁ ℓ′₁ e′₁} {D₂ : Category o′₂ ℓ′₂ e′₂} (H : Bifunctor D₁ D₂ C) {o″ ℓ″ e″} {E : Category o″ ℓ″ e″} (F : Functor E D₁) (G : Functor E D₂) → Functor E C
overlap-× H F G = H ∘ (F ※ G)
reduce-× : ∀ {o ℓ e} {o′₁ ℓ′₁ e′₁} {o′₂ ℓ′₂ e′₂} {C : Category o ℓ e} {D₁ : Category o′₁ ℓ′₁ e′₁} {D₂ : Category o′₂ ℓ′₂ e′₂} (H : Bifunctor D₁ D₂ C) {o″₁ ℓ″₁ e″₁} {E₁ : Category o″₁ ℓ″₁ e″₁} (F : Functor E₁ D₁) {o″₂ ℓ″₂ e″₂} {E₂ : Category o″₂ ℓ″₂ e″₂} (G : Functor E₂ D₂) → Bifunctor E₁ E₂ C
reduce-× H F G = H ∘ (F ⁂ G)
flip-bifunctor : ∀ {o ℓ e} {o′ ℓ′ e′} {o′′ ℓ′′ e′′} {C : Category o ℓ e} → {D : Category o′ ℓ′ e′} → {E : Category o′′ ℓ′′ e′′} → Bifunctor C D E → Bifunctor D C E
flip-bifunctor {C = C} {D = D} {E = E} b = _∘_ b (Swap {C = C} {D = D})
| {
"alphanum_fraction": 0.5598425197,
"avg_line_length": 55.2173913043,
"ext": "agda",
"hexsha": "758b5c5163d6200a16a7e5dda444dcb44e58ae7e",
"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/Bifunctor.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/Bifunctor.agda",
"max_line_length": 293,
"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/Bifunctor.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": 630,
"size": 1270
} |
module Cats.Functor.Op where
open import Cats.Category.Base
open import Cats.Category.Op using (_ᵒᵖ)
open import Cats.Functor using (Functor)
open Functor
Op : ∀ {lo la l≈ lo′ la′ l≈′}
→ {C : Category lo la l≈} {D : Category lo′ la′ l≈′}
→ Functor C D
→ Functor (C ᵒᵖ) (D ᵒᵖ)
Op F = record
{ fobj = fobj F
; fmap = fmap F
; fmap-resp = fmap-resp F
; fmap-id = fmap-id F
; fmap-∘ = fmap-∘ F
}
| {
"alphanum_fraction": 0.5962441315,
"avg_line_length": 20.2857142857,
"ext": "agda",
"hexsha": "969bf0996be77272e621693b2c92400b645cf26f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Functor/Op.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Functor/Op.agda",
"max_line_length": 54,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Functor/Op.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 168,
"size": 426
} |
module Tactic.Deriving.Quotable where
open import Prelude
open import Container.Traversable
open import Tactic.Reflection
open import Tactic.Reflection.Quote.Class
open import Tactic.Deriving
private
-- Bootstrapping
qVis : Visibility → Term
qVis visible = con (quote visible) []
qVis hidden = con (quote hidden) []
qVis instance′ = con (quote instance′) []
qRel : Relevance → Term
qRel relevant = con (quote relevant) []
qRel irrelevant = con (quote irrelevant) []
qArgInfo : ArgInfo → Term
qArgInfo (arg-info v r) = con₂ (quote arg-info) (qVis v) (qRel r)
qArg : Arg Term → Term
qArg (arg i x) = con₂ (quote arg) (qArgInfo i) x
qList : List Term → Term
qList = foldr (λ x xs → con₂ (quote List._∷_) x xs)
(con₀ (quote List.[]))
-- Could compute this from the type of the dictionary constructor
quoteType : Name → TC Type
quoteType d =
caseM instanceTelescope d (quote Quotable) of λ
{ (tel , vs) → pure $ telPi tel $ def d vs `→ def (quote Term) []
}
dictConstructor : TC Name
dictConstructor =
caseM getConstructors (quote Quotable) of λ
{ (c ∷ []) → pure c
; _ → typeErrorS "impossible" }
patArgs : Telescope → List (Arg Pattern)
patArgs tel = map (var "x" <$_) tel
quoteArgs′ : Nat → Telescope → List Term
quoteArgs′ 0 _ = []
quoteArgs′ _ [] = []
quoteArgs′ (suc n) (a ∷ tel) =
qArg (def₁ (quote `) (var n []) <$ a) ∷ quoteArgs′ n tel
quoteArgs : Nat → Telescope → Term
quoteArgs pars tel = qList $ replicate pars (qArg $ hArg (con₀ (quote Term.unknown))) ++
quoteArgs′ (length tel) tel
constructorClause : Nat → Name → TC Clause
constructorClause pars c = do
tel ← drop pars ∘ fst ∘ telView <$> getType c
pure (clause (vArg (con c (patArgs tel)) ∷ [])
(con₂ (quote Term.con) (lit (name c)) (quoteArgs pars tel)))
quoteClauses : Name → TC (List Clause)
quoteClauses d = do
n ← getParameters d
caseM getConstructors d of λ where
[] → pure [ absurd-clause (vArg absurd ∷ []) ]
cs → mapM (constructorClause n) cs
declareQuotableInstance : Name → Name → TC ⊤
declareQuotableInstance iname d =
declareDef (iArg iname) =<< instanceType d (quote Quotable)
defineQuotableInstance : Name → Name → TC ⊤
defineQuotableInstance iname d = do
fname ← freshName ("quote[" & show d & "]")
declareDef (vArg fname) =<< quoteType d
dictCon ← dictConstructor
defineFun iname (clause [] (con₁ dictCon (def₀ fname)) ∷ [])
defineFun fname =<< quoteClauses d
return _
deriveQuotable : Name → Name → TC ⊤
deriveQuotable iname d =
declareQuotableInstance iname d >>
defineQuotableInstance iname d
| {
"alphanum_fraction": 0.6488888889,
"avg_line_length": 31.0344827586,
"ext": "agda",
"hexsha": "f3e4d9074df431b9183f6373b114ee0703a088ea",
"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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Tactic/Deriving/Quotable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"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": "lclem/agda-prelude",
"max_issues_repo_path": "src/Tactic/Deriving/Quotable.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Tactic/Deriving/Quotable.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 824,
"size": 2700
} |
open import Data.Product using ( _×_ )
open import FRP.LTL.ISet.Core using ( ISet ; ⌈_⌉ ; M⟦_⟧ )
open import FRP.LTL.Time using ( Time )
open import FRP.LTL.Time.Bound using ( fin ; _≺_ )
open import FRP.LTL.Time.Interval using ( [_⟩ ; sing )
module FRP.LTL.ISet.Until where
data _Until_ (A B : ISet) (t : Time) : Set where
now : M⟦ B ⟧ (sing t) → (A Until B) t
later : ∀ {u} → .(t≺u : fin t ≺ fin u) → M⟦ A ⟧ [ t≺u ⟩ → M⟦ B ⟧ (sing u) → (A Until B) t
_U_ : ISet → ISet → ISet
A U B = ⌈ A Until B ⌉ | {
"alphanum_fraction": 0.5940594059,
"avg_line_length": 36.0714285714,
"ext": "agda",
"hexsha": "bdd848e8a8323d77b7f56206f4503f29626b24fb",
"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/Until.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/Until.agda",
"max_line_length": 91,
"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/Until.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": 216,
"size": 505
} |
module Sets.ExtensionalPredicateSet where
import Lvl
open import Data
open import Data.Boolean
open import Data.Either as Either using (_‖_)
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
open import Function.Equals
open import Function.Equals.Proofs
open import Function.Inverse
open import Function.Proofs
open import Logic
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Logic.Predicate
open import Structure.Setoid renaming (_≡_ to _≡ₑ_)
open import Structure.Function.Domain
open import Structure.Function.Domain.Proofs
open import Structure.Function
open import Structure.Relator.Equivalence
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Structure.Relator.Proofs
open import Structure.Relator
open import Syntax.Transitivity
open import Type
open import Type.Size
private variable ℓ ℓₒ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓ₁ ℓ₂ ℓ₃ : Lvl.Level
private variable T A A₁ A₂ B : Type{ℓ}
-- A set of objects of a certain type where equality is based on setoids.
-- This is defined by the containment predicate (_∋_) and a proof that it respects the setoid structure.
-- (A ∋ a) is read "The set A contains the element a".
-- Note: This is only a "set" within a certain type, so a collection of type PredSet(T) is actually a subcollection of T.
record PredSet {ℓ ℓₒ ℓₑ} (T : Type{ℓₒ}) ⦃ equiv : Equiv{ℓₑ}(T) ⦄ : Type{Lvl.𝐒(ℓ) Lvl.⊔ ℓₒ Lvl.⊔ ℓₑ} where
constructor intro
field
_∋_ : T → Stmt{ℓ}
⦃ preserve-equiv ⦄ : UnaryRelator(_∋_)
open PredSet using (_∋_) public
open PredSet using (preserve-equiv)
-- Element-set relations.
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
-- The membership relation.
-- (a ∈ A) is read "The element a is included in the set A".
_∈_ : T → PredSet{ℓ}(T) → Stmt
_∈_ = swap(_∋_)
_∉_ : T → PredSet{ℓ}(T) → Stmt
_∉_ = (¬_) ∘₂ (_∈_)
_∌_ : PredSet{ℓ}(T) → T → Stmt
_∌_ = (¬_) ∘₂ (_∋_)
NonEmpty : PredSet{ℓ}(T) → Stmt
NonEmpty(S) = ∃(_∈ S)
-- Set-bounded quantifiers.
module _ {T : Type{ℓₒ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
∀ₛ : PredSet{ℓ}(T) → (T → Stmt{ℓ₁}) → Stmt{ℓ Lvl.⊔ ℓ₁ Lvl.⊔ ℓₒ}
∀ₛ(S) P = ∀{elem : T} → (elem ∈ S) → P(elem)
∃ₛ : PredSet{ℓ}(T) → (T → Stmt{ℓ₁}) → Stmt{ℓ Lvl.⊔ ℓ₁ Lvl.⊔ ℓₒ}
∃ₛ(S) P = ∃(elem ↦ (elem ∈ S) ∧ P(elem))
-- Sets and set operations.
module _ {T : Type{ℓₒ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
-- An empty set.
-- Contains nothing.
∅ : PredSet{ℓ}(T)
∅ ∋ x = Empty
UnaryRelator.substitution (preserve-equiv ∅) = const id
-- An universal set.
-- Contains everything.
-- Note: Everything as in every object of type T.
𝐔 : PredSet{ℓ}(T)
𝐔 ∋ x = Unit
UnaryRelator.substitution (preserve-equiv 𝐔) = const id
-- A singleton set (a set containing only one element).
•_ : T → PredSet(T)
(• a) ∋ x = x ≡ₑ a
UnaryRelator.substitution (preserve-equiv (• a)) xy xa = symmetry(_≡ₑ_) xy 🝖 xa
-- An union of two sets.
-- Contains the elements that any of the both sets contain.
_∪_ : PredSet{ℓ₁}(T) → PredSet{ℓ₂}(T) → PredSet(T)
(A ∪ B) ∋ x = (A ∋ x) ∨ (B ∋ x)
UnaryRelator.substitution (preserve-equiv (A ∪ B)) xy = Either.map (substitute₁(A ∋_) xy) (substitute₁(B ∋_) xy)
infixr 1000 _∪_
-- An intersection of two sets.
-- Contains the elements that both of the both sets contain.
_∩_ : PredSet{ℓ₁}(T) → PredSet{ℓ₂}(T) → PredSet(T)
(A ∩ B) ∋ x = (A ∋ x) ∧ (B ∋ x)
UnaryRelator.substitution (preserve-equiv (A ∩ B)) xy = Tuple.map (substitute₁(A ∋_) xy) (substitute₁(B ∋_) xy)
infixr 1001 _∩_
-- A complement of a set.
-- Contains the elements that the set does not contain.
∁_ : PredSet{ℓ}(T) → PredSet(T)
(∁ A) ∋ x = A ∌ x
UnaryRelator.substitution (preserve-equiv (∁ A)) xy = contrapositiveᵣ (substitute₁(A ∋_) (symmetry(_≡ₑ_) xy))
infixr 1002 ∁_
-- A relative complement of a set.
-- Contains the elements that the left set contains without the elements included in the right set..
_∖_ : PredSet{ℓ₁}(T) → PredSet{ℓ₂}(T) → PredSet(T)
A ∖ B = (A ∩ (∁ B))
infixr 1001 _∖_
filter : (P : T → Stmt{ℓ₁}) ⦃ _ : UnaryRelator(P) ⦄ → PredSet{ℓ₂}(T) → PredSet(T)
filter P(A) ∋ x = (x ∈ A) ∧ P(x)
_⨯_.left (UnaryRelator.substitution (preserve-equiv (filter P A)) xy ([∧]-intro xA Px)) = substitute₁(A ∋_) xy xA
_⨯_.right (UnaryRelator.substitution (preserve-equiv (filter P A)) xy ([∧]-intro xA Px)) = substitute₁(P) xy Px
unapply : ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) ⦃ func-f : Function(f) ⦄ → B → PredSet(A)
unapply f(y) ∋ x = f(x) ≡ₑ y
preserve-equiv (unapply f(y)) = [∘]-unaryRelator ⦃ rel = binary-unaryRelatorᵣ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄
⊶ : ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) → PredSet(B)
⊶ f ∋ y = ∃(x ↦ f(x) ≡ₑ y)
preserve-equiv (⊶ f) = [∃]-unaryRelator ⦃ rel-P = binary-unaryRelatorₗ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄
unmap : ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) ⦃ _ : Function(f) ⦄ → PredSet{ℓ}(B) → PredSet(A)
(unmap f(Y)) ∋ x = f(x) ∈ Y
preserve-equiv (unmap f x) = [∘]-unaryRelator
map : ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) → PredSet{ℓ}(A) → PredSet(B)
map f(S) ∋ y = ∃(x ↦ (x ∈ S) ∧ (f(x) ≡ₑ y))
preserve-equiv (map f S) = [∃]-unaryRelator ⦃ rel-P = [∧]-unaryRelator ⦃ rel-Q = binary-unaryRelatorₗ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄ ⦄
map₂ : ⦃ _ : Equiv{ℓₑ₁}(A₁) ⦄ ⦃ _ : Equiv{ℓₑ₂}(A₂) ⦄ ⦃ _ : Equiv{ℓₑ₃}(B) ⦄ → (_▫_ : A₁ → A₂ → B) → PredSet{ℓ₁}(A₁) → PredSet{ℓ₂}(A₂) → PredSet(B)
map₂(_▫_) S₁ S₂ ∋ y = ∃{Obj = _ ⨯ _}(\{(x₁ , x₂) → (x₁ ∈ S₁) ∧ (x₂ ∈ S₂) ∧ ((x₁ ▫ x₂) ≡ₑ y)})
preserve-equiv (map₂ (_▫_) S₁ S₂) = [∃]-unaryRelator ⦃ rel-P = [∧]-unaryRelator ⦃ rel-P = [∧]-unaryRelator ⦄ ⦃ rel-Q = binary-unaryRelatorₗ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄ ⦄
-- Set-set relations.
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
record _⊆_ (A : PredSet{ℓ₁}(T)) (B : PredSet{ℓ₂}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x} → (x ∈ A) → (x ∈ B)
record _⊇_ (A : PredSet{ℓ₁}(T)) (B : PredSet{ℓ₂}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x} → (x ∈ A) ← (x ∈ B)
record _≡_ (A : PredSet{ℓ₁}(T)) (B : PredSet{ℓ₂}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x} → (x ∈ A) ↔ (x ∈ B)
instance
[≡]-reflexivity : Reflexivity(_≡_ {ℓ})
Reflexivity.proof [≡]-reflexivity = intro [↔]-reflexivity
instance
[≡]-symmetry : Symmetry(_≡_ {ℓ})
Symmetry.proof [≡]-symmetry (intro xy) = intro([↔]-symmetry xy)
[≡]-transitivity-raw : ∀{A : PredSet{ℓ₁}(T)}{B : PredSet{ℓ₂}(T)}{C : PredSet{ℓ₃}(T)} → (A ≡ B) → (B ≡ C) → (A ≡ C)
[≡]-transitivity-raw (intro xy) (intro yz) = intro([↔]-transitivity xy yz)
instance
[≡]-transitivity : Transitivity(_≡_ {ℓ})
Transitivity.proof [≡]-transitivity (intro xy) (intro yz) = intro([↔]-transitivity xy yz)
instance
[≡]-equivalence : Equivalence(_≡_ {ℓ})
[≡]-equivalence = intro
instance
[≡]-equiv : Equiv(PredSet{ℓ}(T))
Equiv._≡_ ([≡]-equiv {ℓ}) x y = x ≡ y
Equiv.equivalence [≡]-equiv = [≡]-equivalence
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
instance
-- Note: The purpose of this module is to satisfy this property for arbitrary equivalences.
[∋]-binaryRelator : BinaryRelator(_∋_ {ℓ}{T = T})
BinaryRelator.substitution [∋]-binaryRelator (intro pₛ) pₑ p = [↔]-to-[→] pₛ(substitute₁(_) pₑ p)
instance
[∋]-unaryRelatorₗ : ∀{a : T} → UnaryRelator(A ↦ _∋_ {ℓ} A a)
[∋]-unaryRelatorₗ = BinaryRelator.left [∋]-binaryRelator
-- TODO: There are level problems here that I am not sure how to solve. The big union of a set of sets are not of the same type as the inner sets. So, for example it would be useful if (⋃ As : PredSet{ℓₒ Lvl.⊔ Lvl.𝐒(ℓ₁)}(T)) and (A : PredSet{ℓ₁}(T)) for (A ∈ As) had the same type/levels when (As : PredSet{Lvl.𝐒(ℓ₁)}(PredSet{ℓ₁}(T))) so that they become comparable. But here, the result of big union is a level greater.
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
-- ⋃_ : PredSet{Lvl.𝐒(ℓ₁)}(PredSet{ℓ₁}(T)) → PredSet{ℓₒ Lvl.⊔ Lvl.𝐒(ℓ₁)}(T)
⋃ : PredSet{ℓ₁}(PredSet{ℓ₂}(T)) → PredSet(T)
(⋃ As) ∋ x = ∃(A ↦ (A ∈ As) ∧ (x ∈ A))
UnaryRelator.substitution (preserve-equiv (⋃ As)) xy = [∃]-map-proof (Tuple.mapRight (substitute₁(_) xy))
⋂ : PredSet{ℓ₁}(PredSet{ℓ₂}(T)) → PredSet(T)
(⋂ As) ∋ x = ∀{A} → (A ∈ As) → (x ∈ A)
UnaryRelator.substitution (preserve-equiv (⋂ As)) xy = substitute₁(_) xy ∘_
-- Indexed set operations.
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
⋃ᵢ : ∀{I : Type{ℓ₁}} → (I → PredSet{ℓ₂}(T)) → PredSet{ℓ₁ Lvl.⊔ ℓ₂}(T)
(⋃ᵢ Ai) ∋ x = ∃(i ↦ x ∈ Ai(i))
UnaryRelator.substitution (preserve-equiv (⋃ᵢ Ai)) xy = [∃]-map-proof (\{i} → substitute₁(_) ⦃ preserve-equiv(Ai(i)) ⦄ xy)
⋂ᵢ : ∀{I : Type{ℓ₁}} → (I → PredSet{ℓ₂}(T)) → PredSet{ℓ₁ Lvl.⊔ ℓ₂}(T)
(⋂ᵢ Ai) ∋ x = ∀ₗ(i ↦ x ∈ Ai(i))
UnaryRelator.substitution (preserve-equiv (⋂ᵢ Ai)) xy p {i} = substitute₁(_) ⦃ preserve-equiv(Ai(i)) ⦄ xy p
-- When the indexed union is indexed by a boolean, it is the same as the small union.
⋃ᵢ-of-boolean : ∀{A B : PredSet{ℓ}(T)} → ((⋃ᵢ{I = Bool}(if_then B else A)) ≡ (A ∪ B))
∃.witness (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introₗ p)) = 𝐹
∃.proof (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introₗ p)) = p
∃.witness (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introᵣ p)) = 𝑇
∃.proof (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introᵣ p)) = p
_⨯_.right (_≡_.proof ⋃ᵢ-of-boolean) ([∃]-intro 𝐹 ⦃ p ⦄) = [∨]-introₗ p
_⨯_.right (_≡_.proof ⋃ᵢ-of-boolean) ([∃]-intro 𝑇 ⦃ p ⦄) = [∨]-introᵣ p
-- When the indexed intersection is indexed by a boolean, it is the same as the small intersection.
⋂ᵢ-of-boolean : ∀{A B : PredSet{ℓ}(T)} → ((⋂ᵢ{I = Bool}(if_then B else A)) ≡ (A ∩ B))
_⨯_.left (_≡_.proof ⋂ᵢ-of-boolean) p {𝐹} = [∧]-elimₗ p
_⨯_.left (_≡_.proof ⋂ᵢ-of-boolean) p {𝑇} = [∧]-elimᵣ p
_⨯_.left (_⨯_.right (_≡_.proof ⋂ᵢ-of-boolean) p) = p{𝐹}
_⨯_.right (_⨯_.right (_≡_.proof ⋂ᵢ-of-boolean) p) = p{𝑇}
module _
⦃ equiv : Equiv{ℓₑ}(T) ⦄
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
where
⋃ᵢ-of-bijection : ∀{f : B → PredSet{ℓ}(T)} ⦃ func-f : Function(f)⦄ → (([∃]-intro g) : A ≍ B) → (⋃ᵢ{I = A}(f ∘ g) ≡ ⋃ᵢ{I = B}(f))
∃.witness (_⨯_.left (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro b ⦃ p ⦄)) = inv g ⦃ bijective-to-invertible ⦄ (b)
∃.proof (_⨯_.left (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro b ⦃ p ⦄)) = substitute₂(_∋_) (symmetry(_≡_) (congruence₁(f) (inverse-right(g)(inv g ⦃ bijective-to-invertible ⦄) ⦃ [∧]-elimᵣ([∃]-proof bijective-to-invertible) ⦄))) (reflexivity(_≡ₑ_)) p
∃.witness (_⨯_.right (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro a ⦃ p ⦄)) = g(a)
∃.proof (_⨯_.right (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro b ⦃ p ⦄)) = p
⋂ᵢ-of-bijection : ∀{f : B → PredSet{ℓ}(T)} ⦃ func-f : Function(f)⦄ → (([∃]-intro g) : A ≍ B) → (⋂ᵢ{I = A}(f ∘ g) ≡ ⋂ᵢ{I = B}(f))
_⨯_.left (_≡_.proof (⋂ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄)) {x}) p {b} = p{g(b)}
_⨯_.right (_≡_.proof (⋂ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄)) {x}) p {b} = substitute₂(_∋_) (congruence₁(f) (inverse-right(g)(inv g ⦃ bijective-to-invertible ⦄) ⦃ [∧]-elimᵣ([∃]-proof bijective-to-invertible) ⦄)) (reflexivity(_≡ₑ_)) (p{inv g ⦃ bijective-to-invertible ⦄ (b)})
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
instance
singleton-function : ∀{A : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(A) ⦄ → Function{A = A}(•_)
_≡_.proof (Function.congruence singleton-function {x} {y} xy) {a} = [↔]-intro (_🝖 symmetry(_≡ₑ_) xy) (_🝖 xy)
| {
"alphanum_fraction": 0.602348269,
"avg_line_length": 47.0853658537,
"ext": "agda",
"hexsha": "f076e2b6b55f56b70fd04938e927f5baf1ece2c3",
"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": "Sets/ExtensionalPredicateSet.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": "Sets/ExtensionalPredicateSet.agda",
"max_line_length": 420,
"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": "Sets/ExtensionalPredicateSet.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": 5319,
"size": 11583
} |
open import MLib.Prelude
open import MLib.Algebra.PropertyCode
open import MLib.Algebra.PropertyCode.Structures
module MLib.Matrix.Plus {c ℓ} (struct : Struct bimonoidCode c ℓ) {m n : ℕ} where
open import MLib.Matrix.Core
open import MLib.Matrix.Equality struct
open FunctionProperties
-- Pointwise addition --
infixl 6 _⊕_
_⊕_ : Matrix S m n → Matrix S m n → Matrix S m n
(A ⊕ B) i j = A i j ⟨ + ⟩ B i j
⊕-cong : Congruent₂ _⊕_
⊕-cong p q = λ i j → S.cong + (p i j) (q i j)
⊕-assoc : ⦃ props : Has₁ (associative on +) ⦄ → Associative _⊕_
⊕-assoc ⦃ props ⦄ A B C i j = from props (associative on +) (A i j) (B i j) (C i j)
0● : Matrix S m n
0● _ _ = ⟦ 0# ⟧
⊕-identityˡ : ⦃ props : Has₁ (0# is leftIdentity for +) ⦄ → LeftIdentity 0● _⊕_
⊕-identityˡ ⦃ props ⦄ A i j = from props (0# is leftIdentity for +) (A i j)
⊕-identityʳ : ⦃ props : Has₁ (0# is rightIdentity for +) ⦄ → RightIdentity 0● _⊕_
⊕-identityʳ ⦃ props ⦄ A i j = from props (0# is rightIdentity for +) (A i j)
⊕-comm : ⦃ props : Has₁ (commutative on +) ⦄ → Commutative _⊕_
⊕-comm ⦃ props ⦄ A B i j = from props (commutative on +) (A i j) (B i j)
| {
"alphanum_fraction": 0.6366071429,
"avg_line_length": 31.1111111111,
"ext": "agda",
"hexsha": "79902a4d181cad529c65860cc45c7ba8782a380b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Matrix/Plus.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Matrix/Plus.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Matrix/Plus.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 480,
"size": 1120
} |
{-
Practical Relational Algebra
Toon Nolten
based on
The Power Of Pi
-}
module relational-algebra where
open import Data.Empty
open import Data.Unit hiding (_≤_)
open import Data.Bool
open import Data.Nat
open import Data.Integer hiding (show)
open import Data.List
open import Data.Char hiding (_==_) renaming (show to charToString)
open import Data.Vec hiding (_++_; lookup; map; foldr; _>>=_)
open import Data.String using (String; toVec; _==_; strictTotalOrder)
renaming (_++_ to _∥_)
open import Data.Product using (_×_; _,_; proj₁)
open import Coinduction
open import IO
open import Relation.Binary
open StrictTotalOrder Data.String.strictTotalOrder renaming (compare to str_cmp)
data Order : Set where
LT EQ GT : Order
module InsertionSort where
insert : {A : Set} → (A → A → Order) → A → List A → List A
insert _ e [] = e ∷ []
insert cmp e (l ∷ ls) with cmp e l
... | GT = l ∷ insert cmp e ls
... | _ = e ∷ l ∷ ls
sort : {A : Set} → (A → A → Order) → List A → List A
sort cmp = foldr (insert cmp) []
open InsertionSort using (insert; sort)
-- Universe U exists of type U and el : U → Set
data U : Set where
CHAR NAT BOOL : U
VEC : U → ℕ → U
el : U → Set
el CHAR = Char
el NAT = ℕ
el (VEC u n) = Vec (el u) n
el BOOL = Bool
parens : String → String
parens str = "(" ∥ str ∥ ")"
show : {u : U} → el u → String
show {CHAR } c = charToString c
show {NAT } zero = "Zero"
show {NAT } (suc k) = "Succ " ∥ parens (show k)
show {VEC u zero } Nil = "Nil"
show {VEC u (suc k)} (x ∷ xs) = parens (show x) ∥ " ∷ " ∥ parens (show xs)
show {BOOL } true = "True"
show {BOOL } false = "False"
_=ᴺ_ : ℕ → ℕ → Bool
zero =ᴺ zero = true
suc m =ᴺ suc n = (m =ᴺ n)
_ =ᴺ _ = false
_≤ᴺ_ : ℕ → ℕ → Order
zero ≤ᴺ zero = EQ
zero ≤ᴺ _ = LT
_ ≤ᴺ zero = GT
suc a ≤ᴺ suc b = a ≤ᴺ b
_=ᵁ_ : U → U → Bool
CHAR =ᵁ CHAR = true
NAT =ᵁ NAT = true
BOOL =ᵁ BOOL = true
VEC u x =ᵁ VEC u' x' = (u =ᵁ u') ∧ (x =ᴺ x')
_ =ᵁ _ = false
_≤ᵁ_ : U → U → Order
CHAR ≤ᵁ CHAR = EQ
CHAR ≤ᵁ _ = LT
_ ≤ᵁ CHAR = GT
NAT ≤ᵁ NAT = EQ
NAT ≤ᵁ _ = LT
_ ≤ᵁ NAT = GT
BOOL ≤ᵁ BOOL = EQ
BOOL ≤ᵁ _ = LT
_ ≤ᵁ BOOL = GT
VEC a x ≤ᵁ VEC b y with a ≤ᵁ b
... | LT = LT
... | EQ = x ≤ᴺ y
... | GT = GT
So : Bool → Set
So true = ⊤
So false = ⊥
data SqlValue : Set where
SqlString : String → SqlValue
SqlChar : Char → SqlValue
SqlBool : Bool → SqlValue
SqlInteger : ℤ → SqlValue
--{-# COMPILED_DATA SqlValue SqlValue SqlString SqlChar SqlBool SqlInteger #-}
module OrderedSchema where
SchemaDescription = List (List SqlValue)
Attribute : Set
Attribute = String × U
-- Compare on type if names are equal.
-- SQL DB's probably don't allow columns with the same name
-- but nothing prevents us from writing a Schema that does,
-- this is necessary to make our sort return a unique answer.
attr_cmp : Attribute → Attribute → Order
attr_cmp (nm₁ , U₁) (nm₂ , U₂) with str_cmp nm₁ nm₂ | U₁ ≤ᵁ U₂
... | tri< _ _ _ | _ = LT
... | tri≈ _ _ _ | U₁≤U₂ = U₁≤U₂
... | tri> _ _ _ | _ = GT
data Schema : Set where
sorted : List Attribute → Schema
mkSchema : List Attribute → Schema
mkSchema xs = sorted (sort attr_cmp xs)
expandSchema : Attribute → Schema → Schema
expandSchema x (sorted xs) = sorted (insert attr_cmp x xs)
schemify : SchemaDescription → Schema
schemify sdesc = {!!}
disjoint : Schema → Schema → Bool
disjoint (sorted [] ) (_ ) = true
disjoint (_ ) (sorted [] ) = true
disjoint (sorted (x ∷ xs)) (sorted (y ∷ ys)) with attr_cmp x y
... | LT = disjoint (sorted xs ) (sorted (y ∷ ys))
... | EQ = false
... | GT = disjoint (sorted (x ∷ xs)) (sorted ys )
sub : Schema → Schema → Bool
sub (sorted [] ) (_ ) = true
sub (sorted (x ∷ _) ) (sorted [] ) = false
sub (sorted (x ∷ xs)) (sorted (X ∷ Xs)) with attr_cmp x X
... | LT = false
... | EQ = sub (sorted xs ) (sorted Xs)
... | GT = sub (sorted (x ∷ xs)) (sorted Xs)
same' : List Attribute → List Attribute → Bool
same' ([] ) ([] ) = true
same' ((nm₁ , ty₁) ∷ xs) ((nm₂ , ty₂) ∷ ys) =
(nm₁ == nm₂) ∧ (ty₁ =ᵁ ty₂) ∧ same' xs ys
same' (_ ) (_ ) = false
same : Schema → Schema → Bool
same (sorted xs) (sorted ys) = same' xs ys
occurs : String → Schema → Bool
occurs nm (sorted s) = any (_==_ nm) (map (proj₁) s)
lookup' : (nm : String) → (s : List Attribute)
→ So (occurs nm (sorted s)) → U
lookup' _ [] ()
lookup' nm ((name , type) ∷ s') p with nm == name
... | true = type
... | false = lookup' nm s' p
lookup : (nm : String) → (s : Schema) → So (occurs nm s) → U
lookup nm (sorted s) = lookup' nm s
append : (s s' : Schema) → Schema
append (sorted s) (sorted s') = mkSchema (s ++ s')
open OrderedSchema using (Schema; mkSchema; expandSchema; schemify;
disjoint; sub; same; occurs; lookup;
append)
data Row : Schema → Set where
EmptyRow : Row (mkSchema [])
ConsRow : ∀ {name u s} → el u → Row s → Row (expandSchema (name , u) s)
Table : Schema → Set
Table s = List (Row s)
DatabasePath = String
TableName = String
postulate
Connection : Set
connectSqlite3 : DatabasePath → IO Connection
describe_table : TableName → Connection → IO (List (List SqlValue))
-- {-# COMPILED_TYPE Connection Connection #-}
-- {-# COMPILED connectSqlite3 connectSqlite3 #-}
-- {-# COMPILED describe_table describe_table #-}
data Handle : Schema → Set where
conn : Connection → (s : Schema) → Handle s
-- Connect currently ignores differences between
-- the expected schema and the actual schema.
-- According to tpop this should result in
-- "a *runtime exception* in the *IO* monad."
-- Agda does not have exceptions(?)
-- -> postulate error with a compiled pragma?
connect : DatabasePath → TableName → (s : Schema) → IO (Handle s)
connect DB table schema_expect =
♯ (connectSqlite3 DB) >>=
(λ sqlite_conn →
♯ (♯ (describe_table table sqlite_conn) >>=
(λ description →
♯ (♯ (return (schemify description)) >>=
(λ schema_actual →
♯ (♯ (return (same schema_expect schema_actual)) >>=
(λ { true → ♯ (return (conn sqlite_conn schema_expect));
false → ♯ (return (conn sqlite_conn schema_expect)) })))))))
data Expr : Schema → U → Set where
equal : ∀ {u s} → Expr s u → Expr s u → Expr s BOOL
lessThan : ∀ {u s} → Expr s u → Expr s u → Expr s BOOL
_!_ : (s : Schema) → (nm : String) → {p : So (occurs nm s)}
→ Expr s (lookup nm s p)
data RA : Schema → Set where
Read : ∀ {s} → Handle s → RA s
Union : ∀ {s} → RA s → RA s → RA s
Diff : ∀ {s} → RA s → RA s → RA s
Product : ∀ {s s'} → {_ : So (disjoint s s')} → RA s → RA s'
→ RA (append s s')
Project : ∀ {s} → (s' : Schema) → {_ : So (sub s' s)} → RA s → RA s'
Select : ∀ {s} → Expr s BOOL → RA s → RA s
-- ...
{-
As we mentioned previously, we have taken a very minimal set of relational
algebra operators. It should be fairly straightforward to add operators
for the many other operators in relational algebra, such as the
natural join, θ-join, equijoin, renaming, or division,
using the same techniques. Alternatively, you can define many of these
operations in terms of the operations we have implemented in the RA data type.
-}
-- We could:
postulate
toSQL : ∀ {s} → RA s → String
-- We can do much better:
postulate
query : {s : Schema} → RA s → IO (List (Row s))
{-
The *query* function uses *toSQL* to produce a query, and passes this to the
database server. When the server replies, however, we know exactly how to
parse the response: we know the schema of the table resulting from our query,
and can use this to parse the database server's response in a type-safe
manner. The type checker can then statically check that the program uses the
returned list in a way consistent with its type.
-}
Cars : Schema
Cars = mkSchema (("Model" , VEC CHAR 20) ∷ ("Time" , VEC CHAR 6)
∷ ("Wet" , BOOL) ∷ [])
zonda : Row Cars
zonda = ConsRow (toVec "Pagani Zonda C12 F ")
(ConsRow (toVec "1:18.4")
(ConsRow false EmptyRow))
Models : Schema
Models = mkSchema (("Model" , VEC CHAR 20) ∷ [])
models : Handle Cars → RA Models
models h = Project Models (Read h)
wet : Handle Cars → RA Models
wet h = Project Models (Select (Cars ! "Wet") (Read h))
{- Discussion
==========
There are many, many aspects of this proposal that can be improved. Some
attributes of a schema contain *NULL*-values; we should close our universe
under *Maybe* accordingly. Some database servers silently truncate strings
longer than 255 characters. We would do well to ensure statically that this
never happens. Our goal, however, was not to provide a complete model of all
of SQL's quirks and idiosyncrasies: we want to show how a language with
dependent types can schine where Haskell struggles.
Our choice of *Schema* data type suffers from the usual disadvantages of
using a list to represent a set: our *Schema* data type may contain
duplicates and the order of the elements matters. The first problem is easy
to solve. Using an implicit proof argument in the *Cons* case, we can define
a data type for lists that do not contain duplicates. The type of *Cons* then
becomes:
Cons : (nm : String) → (u : U) → (s : Schema) → {_ : So (not (elem nm s))}
→ Schema
The second point is a bit trickier. The real solution would involve quotient
types to make the order of the elements unobservable. As Agda does not
support quotient types, however, the best we can do is parameterise our
constructors by an additional proof argument, when necessary. For example,
the *Union* constructor could be defined as follows:
Union : ∀ {s s'} → {_ : So (permute s s')} → RA s → RA s' → RA s
Instead of requiring that both arguments of *Union* are indexed by the same
schema, we should only require that the two schemas are equal up to a
permutation of the elements. Alternatively, we could represent the *Schema*
using a data structure that fixes the order in which its constituent
elements occur, such as a trie or sorted list.
Finally, we would like to return to our example table. We chose to model
the lap time as a fixed-length string ─ clearly, a triple of integers would
be a better representation. Unfortunately, most database servers only
support a handful of built-in types, such as strings, numbers, bits. There
is no way to extend these primitive types. This problem is sometimes
referred to as the *object-relational impedance mismatch*. We believe the
generic programming techniques and views from the previous sections can be
used to marshall data between a low-level representation in the database
and the high-level representation in our programming language.
-}
| {
"alphanum_fraction": 0.6199928788,
"avg_line_length": 34.0424242424,
"ext": "agda",
"hexsha": "4424fe3b3f4b8be02715101ee6918423a5a5857f",
"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": "b397a6d9b84e29bbaa260f85f036869d511eb3eb",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "toonn/agda-casestt",
"max_forks_repo_path": "relational-algebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b397a6d9b84e29bbaa260f85f036869d511eb3eb",
"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": "toonn/agda-casestt",
"max_issues_repo_path": "relational-algebra.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b397a6d9b84e29bbaa260f85f036869d511eb3eb",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "toonn/agda-casestt",
"max_stars_repo_path": "relational-algebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3344,
"size": 11234
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U
open import Definition.Typed
open import Definition.Typed.Weakening
open import Agda.Primitive
open import Tools.Product
open import Tools.Embedding
import Tools.PropositionalEquality as PE
-- The different cases of the logical relation are spread out through out
-- this file. This is due to them having different dependencies.
-- We will refer to expressions that satisfies the logical relation as reducible.
-- Reducibility of Neutrals:
-- Neutral type
record _⊩ne_ (Γ : Con Term) (A : Term) : Set where
constructor ne
field
K : Term
D : Γ ⊢ A :⇒*: K
neK : Neutral K
K≡K : Γ ⊢ K ~ K ∷ U
-- Neutral type equality
record _⊩ne_≡_/_ (Γ : Con Term) (A B : Term) ([A] : Γ ⊩ne A) : Set where
constructor ne₌
open _⊩ne_ [A]
field
M : Term
D′ : Γ ⊢ B :⇒*: M
neM : Neutral M
K≡M : Γ ⊢ K ~ M ∷ U
-- Neutral term in WHNF
record _⊩neNf_∷_ (Γ : Con Term) (k A : Term) : Set where
inductive
constructor neNfₜ
field
neK : Neutral k
⊢k : Γ ⊢ k ∷ A
k≡k : Γ ⊢ k ~ k ∷ A
-- Neutral term
record _⊩ne_∷_/_ (Γ : Con Term) (t A : Term) ([A] : Γ ⊩ne A) : Set where
inductive
constructor neₜ
open _⊩ne_ [A]
field
k : Term
d : Γ ⊢ t :⇒*: k ∷ K
nf : Γ ⊩neNf k ∷ K
-- Neutral term equality in WHNF
record _⊩neNf_≡_∷_ (Γ : Con Term) (k m A : Term) : Set where
inductive
constructor neNfₜ₌
field
neK : Neutral k
neM : Neutral m
k≡m : Γ ⊢ k ~ m ∷ A
-- Neutral term equality
record _⊩ne_≡_∷_/_ (Γ : Con Term) (t u A : Term) ([A] : Γ ⊩ne A) : Set where
constructor neₜ₌
open _⊩ne_ [A]
field
k m : Term
d : Γ ⊢ t :⇒*: k ∷ K
d′ : Γ ⊢ u :⇒*: m ∷ K
nf : Γ ⊩neNf k ≡ m ∷ K
-- Reducibility of natural numbers:
-- Natural number type
_⊩ℕ_ : (Γ : Con Term) (A : Term) → Set
Γ ⊩ℕ A = Γ ⊢ A :⇒*: ℕ
-- Natural number type equality
data _⊩ℕ_≡_ (Γ : Con Term) (A B : Term) : Set where
ℕ₌ : Γ ⊢ B ⇒* ℕ → Γ ⊩ℕ A ≡ B
mutual
-- Natural number term
data _⊩ℕ_∷ℕ (Γ : Con Term) (t : Term) : Set where
ℕₜ : (n : Term) (d : Γ ⊢ t :⇒*: n ∷ ℕ) (n≡n : Γ ⊢ n ≅ n ∷ ℕ)
(prop : Natural-prop Γ n)
→ Γ ⊩ℕ t ∷ℕ
-- WHNF property of natural number terms
data Natural-prop (Γ : Con Term) : (n : Term) → Set where
sucᵣ : ∀ {n} → Γ ⊩ℕ n ∷ℕ → Natural-prop Γ (suc n)
zeroᵣ : Natural-prop Γ zero
ne : ∀ {n} → Γ ⊩neNf n ∷ ℕ → Natural-prop Γ n
mutual
-- Natural number term equality
data _⊩ℕ_≡_∷ℕ (Γ : Con Term) (t u : Term) : Set where
ℕₜ₌ : (k k′ : Term) (d : Γ ⊢ t :⇒*: k ∷ ℕ) (d′ : Γ ⊢ u :⇒*: k′ ∷ ℕ)
(k≡k′ : Γ ⊢ k ≅ k′ ∷ ℕ)
(prop : [Natural]-prop Γ k k′) → Γ ⊩ℕ t ≡ u ∷ℕ
-- WHNF property of Natural number term equality
data [Natural]-prop (Γ : Con Term) : (n n′ : Term) → Set where
sucᵣ : ∀ {n n′} → Γ ⊩ℕ n ≡ n′ ∷ℕ → [Natural]-prop Γ (suc n) (suc n′)
zeroᵣ : [Natural]-prop Γ zero zero
ne : ∀ {n n′} → Γ ⊩neNf n ≡ n′ ∷ ℕ → [Natural]-prop Γ n n′
-- Natural extraction from term WHNF property
natural : ∀ {Γ n} → Natural-prop Γ n → Natural n
natural (sucᵣ x) = sucₙ
natural zeroᵣ = zeroₙ
natural (ne (neNfₜ neK ⊢k k≡k)) = ne neK
-- Natural extraction from term equality WHNF property
split : ∀ {Γ a b} → [Natural]-prop Γ a b → Natural a × Natural b
split (sucᵣ x) = sucₙ , sucₙ
split zeroᵣ = zeroₙ , zeroₙ
split (ne (neNfₜ₌ neK neM k≡m)) = ne neK , ne neM
-- Type levels
data TypeLevel : Set where
⁰ : TypeLevel
¹ : TypeLevel
data _<_ : (i j : TypeLevel) → Set where
0<1 : ⁰ < ¹
toLevel : TypeLevel → Level
toLevel ⁰ = lzero
toLevel ¹ = lsuc lzero
-- Logical relation
record LogRelKit (ℓ : Level) : Set (lsuc (lsuc ℓ)) where
constructor Kit
field
_⊩U : (Γ : Con Term) → Set (lsuc ℓ)
_⊩Π_ : (Γ : Con Term) → Term → Set (lsuc ℓ)
_⊩_ : (Γ : Con Term) → Term → Set (lsuc ℓ)
_⊩_≡_/_ : (Γ : Con Term) (A B : Term) → Γ ⊩ A → Set ℓ
_⊩_∷_/_ : (Γ : Con Term) (t A : Term) → Γ ⊩ A → Set ℓ
_⊩_≡_∷_/_ : (Γ : Con Term) (t u A : Term) → Γ ⊩ A → Set ℓ
module LogRel (l : TypeLevel) (rec : ∀ {l′} → l′ < l → LogRelKit (toLevel l)) where
record _⊩¹U (Γ : Con Term) : Set (lsuc (lsuc (toLevel l))) where
constructor Uᵣ
field
l′ : TypeLevel
l< : l′ < l
⊢Γ : ⊢ Γ
-- Universe type equality
record _⊩¹U≡_ (Γ : Con Term) (B : Term) : Set (lsuc (toLevel l)) where
constructor U₌
field
B≡U : B PE.≡ U
-- Universe term
record _⊩¹U_∷U/_ {l′} (Γ : Con Term) (t : Term) (l< : l′ < l) : Set (lsuc (toLevel l)) where
constructor Uₜ
open LogRelKit (rec l<)
field
A : Term
d : Γ ⊢ t :⇒*: A ∷ U
typeA : Type A
A≡A : Γ ⊢ A ≅ A ∷ U
[t] : Γ ⊩ t
-- Universe term equality
record _⊩¹U_≡_∷U/_ {l′} (Γ : Con Term) (t u : Term) (l< : l′ < l) : Set (lsuc (toLevel l)) where
constructor Uₜ₌
open LogRelKit (rec l<)
field
A B : Term
d : Γ ⊢ t :⇒*: A ∷ U
d′ : Γ ⊢ u :⇒*: B ∷ U
typeA : Type A
typeB : Type B
A≡B : Γ ⊢ A ≅ B ∷ U
[t] : Γ ⊩ t
[u] : Γ ⊩ u
[t≡u] : Γ ⊩ t ≡ u / [t]
RedRel : Set (lsuc (lsuc (lsuc (toLevel l))))
RedRel = Con Term → Term → (Term → Set (lsuc (toLevel l))) → (Term → Set (lsuc (toLevel l))) → (Term → Term → Set (lsuc (toLevel l))) → Set (lsuc (lsuc (toLevel l)))
record _⊩⁰_/_ (Γ : Con Term) (A : Term) (_⊩_▸_▸_▸_ : RedRel) : Set (lsuc (lsuc (toLevel l))) where
inductive
eta-equality
constructor LRPack
field
⊩Eq : Term → Set (lsuc (toLevel l))
⊩Term : Term → Set (lsuc (toLevel l))
⊩EqTerm : Term → Term → Set (lsuc (toLevel l))
⊩LR : Γ ⊩ A ▸ ⊩Eq ▸ ⊩Term ▸ ⊩EqTerm
_⊩⁰_≡_/_ : {R : RedRel} (Γ : Con Term) (A B : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l))
Γ ⊩⁰ A ≡ B / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩Eq B
_⊩⁰_∷_/_ : {R : RedRel} (Γ : Con Term) (t A : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l))
Γ ⊩⁰ t ∷ A / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩Term t
_⊩⁰_≡_∷_/_ : {R : RedRel} (Γ : Con Term) (t u A : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l))
Γ ⊩⁰ t ≡ u ∷ A / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩EqTerm t u
record _⊩¹Π_/_ (Γ : Con Term) (A : Term) (R : RedRel) : Set (lsuc (lsuc (toLevel l))) where
inductive
eta-equality
constructor Πᵣ
field
F : Term
G : Term
D : Γ ⊢ A :⇒*: Π F ▹ G
⊢F : Γ ⊢ F
⊢G : Γ ∙ F ⊢ G
A≡A : Γ ⊢ Π F ▹ G ≅ Π F ▹ G
[F] : ∀ {ρ Δ} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ) → Δ ⊩⁰ U.wk ρ F / R
[G] : ∀ {ρ Δ a}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ
→ Δ ⊩⁰ U.wk (lift ρ) G [ a ] / R
G-ext : ∀ {ρ Δ a b}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
→ ([b] : Δ ⊩⁰ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
→ Δ ⊩⁰ a ≡ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ
→ Δ ⊩⁰ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G [ b ] / [G] [ρ] ⊢Δ [a]
record _⊩¹Π_≡_/_ {R : RedRel} (Γ : Con Term) (A B : Term) ([A] : Γ ⊩¹Π A / R) : Set (lsuc (toLevel l)) where
inductive
eta-equality
constructor Π₌
open _⊩¹Π_/_ [A]
field
F′ : Term
G′ : Term
D′ : Γ ⊢ B ⇒* Π F′ ▹ G′
A≡B : Γ ⊢ Π F ▹ G ≅ Π F′ ▹ G′
[F≡F′] : ∀ {ρ Δ}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ Δ ⊩⁰ U.wk ρ F ≡ U.wk ρ F′ / [F] [ρ] ⊢Δ
[G≡G′] : ∀ {ρ Δ a}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
→ Δ ⊩⁰ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G′ [ a ] / [G] [ρ] ⊢Δ [a]
-- Term of Π-type
_⊩¹Π_∷_/_ : {R : RedRel} (Γ : Con Term) (t A : Term) ([A] : Γ ⊩¹Π A / R) → Set (lsuc (toLevel l))
Γ ⊩¹Π t ∷ A / Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
∃ λ f → Γ ⊢ t :⇒*: f ∷ Π F ▹ G
× Function f
× Γ ⊢ f ≅ f ∷ Π F ▹ G
× (∀ {ρ Δ a b}
→ ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
([b] : Δ ⊩⁰ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
([a≡b] : Δ ⊩⁰ a ≡ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
→ Δ ⊩⁰ U.wk ρ f ∘ a ≡ U.wk ρ f ∘ b ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a])
× (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
→ Δ ⊩⁰ U.wk ρ f ∘ a ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a])
-- Issue: Agda complains about record use not being strictly positive.
-- Therefore we have to use ×
-- Term equality of Π-type
_⊩¹Π_≡_∷_/_ : {R : RedRel} (Γ : Con Term) (t u A : Term) ([A] : Γ ⊩¹Π A / R) → Set (lsuc (toLevel l))
Γ ⊩¹Π t ≡ u ∷ A / Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext =
let [A] = Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext
in ∃₂ λ f g →
Γ ⊢ t :⇒*: f ∷ Π F ▹ G
× Γ ⊢ u :⇒*: g ∷ Π F ▹ G
× Function f
× Function g
× Γ ⊢ f ≅ g ∷ Π F ▹ G
× Γ ⊩¹Π t ∷ A / [A]
× Γ ⊩¹Π u ∷ A / [A]
× (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ)
→ ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ)
→ Δ ⊩⁰ U.wk ρ f ∘ a ≡ U.wk ρ g ∘ a ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a])
-- Issue: Same as above.
-- Logical relation definition
data _⊩LR_▸_▸_▸_ : RedRel where
LRU : ∀ {Γ} (⊢Γ : ⊢ Γ) → (l' : TypeLevel) → (l< : l' < l) → Γ ⊩LR U
▸ (λ B → Γ ⊩¹U≡ B)
▸ (λ t → Γ ⊩¹U t ∷U/ l<)
▸ (λ t u → Γ ⊩¹U t ≡ u ∷U/ l<)
LRℕ : ∀ {Γ A} → Γ ⊩ℕ A → Γ ⊩LR A
▸ (λ B → ι′ (Γ ⊩ℕ A ≡ B))
▸ (λ t → ι′ (Γ ⊩ℕ t ∷ℕ))
▸ (λ t u → ι′ (Γ ⊩ℕ t ≡ u ∷ℕ))
LRne : ∀ {Γ A} → (neA : Γ ⊩ne A) → Γ ⊩LR A
▸ (λ B → ι′ (Γ ⊩ne A ≡ B / neA))
▸ (λ t → ι′ (Γ ⊩ne t ∷ A / neA))
▸ (λ t u → ι′ (Γ ⊩ne t ≡ u ∷ A / neA))
LRΠ : ∀ {Γ A} → (ΠA : Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) → Γ ⊩LR A
▸ (λ B → Γ ⊩¹Π A ≡ B / ΠA)
▸ (λ t → Γ ⊩¹Π t ∷ A / ΠA)
▸ (λ t u → Γ ⊩¹Π t ≡ u ∷ A / ΠA)
LRemb : ∀ {Γ A l′} (l< : l′ < l) (let open LogRelKit (rec l<)) ([A] : Γ ⊩ A) → Γ ⊩LR A
▸ (λ B → ι (Γ ⊩ A ≡ B / [A]))
▸ (λ t → ι (Γ ⊩ t ∷ A / [A]))
▸ (λ t u → ι (Γ ⊩ t ≡ u ∷ A / [A]))
_⊩¹_ : (Γ : Con Term) → (A : Term) → Set (lsuc (lsuc (toLevel l)))
Γ ⊩¹ A = Γ ⊩⁰ A / _⊩LR_▸_▸_▸_
_⊩¹_≡_/_ : (Γ : Con Term) (A B : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l))
Γ ⊩¹ A ≡ B / [A] = Γ ⊩⁰ A ≡ B / [A]
_⊩¹_∷_/_ : (Γ : Con Term) (t A : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l))
Γ ⊩¹ t ∷ A / [A] = Γ ⊩⁰ t ∷ A / [A]
_⊩¹_≡_∷_/_ : (Γ : Con Term) (t u A : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l))
Γ ⊩¹ t ≡ u ∷ A / [A] = Γ ⊩⁰ t ≡ u ∷ A / [A]
open LogRel public using (Uᵣ; Πᵣ; Π₌; U₌ ; Uₜ; Uₜ₌ ; LRU ; LRℕ ; LRne ; LRΠ ; LRemb ; LRPack)
pattern Πₜ f d funcF f≡f [f] [f]₁ = f , d , funcF , f≡f , [f] , [f]₁
pattern Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g] = f , g , d , d′ , funcF , funcG , f≡g , [f] , [g] , [f≡g]
pattern ℕᵣ a = LRPack _ _ _ (LRℕ a)
pattern emb′ a b = LRPack _ _ _ (LRemb a b)
pattern Uᵣ′ a b c = LRPack _ _ _ (LRU c a b)
pattern ne′ a b c d = LRPack _ _ _ (LRne (ne a b c d))
pattern Πᵣ′ a b c d e f g h i = LRPack _ _ _ (LRΠ (Πᵣ a b c d e f g h i))
kit₀ : LogRelKit (lsuc (lzero))
kit₀ = Kit _⊩¹U (λ Γ A → Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) _⊩¹_ _⊩¹_≡_/_ _⊩¹_∷_/_ _⊩¹_≡_∷_/_ where open LogRel ⁰ (λ ())
logRelRec : ∀ l {l′} → l′ < l → LogRelKit (toLevel l)
logRelRec ⁰ = λ ()
logRelRec ¹ 0<1 = kit₀
kit : ∀ (l : TypeLevel) → LogRelKit (lsuc (toLevel l))
kit l = Kit _⊩¹U (λ Γ A → Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) _⊩¹_ _⊩¹_≡_/_ _⊩¹_∷_/_ _⊩¹_≡_∷_/_ where open LogRel l (logRelRec l)
-- a bit of repetition in "kit ¹" definition, would work better with Fin 2 for
-- TypeLevel because you could recurse.
record _⊩′⟨_⟩U (Γ : Con Term) (l : TypeLevel) : Set where
constructor Uᵣ
field
l′ : TypeLevel
l< : l′ < l
⊢Γ : ⊢ Γ
_⊩′⟨_⟩Π_ : (Γ : Con Term) (l : TypeLevel) → Term → Set (lsuc (lsuc (toLevel l)))
Γ ⊩′⟨ l ⟩Π A = Γ ⊩Π A where open LogRelKit (kit l)
_⊩⟨_⟩_ : (Γ : Con Term) (l : TypeLevel) → Term → Set (lsuc (lsuc (toLevel l)))
Γ ⊩⟨ l ⟩ A = Γ ⊩ A where open LogRelKit (kit l)
_⊩⟨_⟩_≡_/_ : (Γ : Con Term) (l : TypeLevel) (A B : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l))
Γ ⊩⟨ l ⟩ A ≡ B / [A] = Γ ⊩ A ≡ B / [A] where open LogRelKit (kit l)
_⊩⟨_⟩_∷_/_ : (Γ : Con Term) (l : TypeLevel) (t A : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l))
Γ ⊩⟨ l ⟩ t ∷ A / [A] = Γ ⊩ t ∷ A / [A] where open LogRelKit (kit l)
_⊩⟨_⟩_≡_∷_/_ : (Γ : Con Term) (l : TypeLevel) (t u A : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l))
Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A] = Γ ⊩ t ≡ u ∷ A / [A] where open LogRelKit (kit l)
| {
"alphanum_fraction": 0.4754398535,
"avg_line_length": 33.496,
"ext": "agda",
"hexsha": "149bd472fc276de373587569edf725c866936553",
"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": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"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": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation.agda",
"max_line_length": 167,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6351,
"size": 12561
} |
{-# OPTIONS --verbose=10 #-}
module leafsF where
open import Data.Nat
open import Data.Vec
open import Agda.Builtin.Sigma
open import Data.Product
open import Data.Fin using (fromℕ)
open import trees
open import optics
open import lemmas
leafsTreeF : {A : Set} -> (t : Tree A) -> Vec A (#leafs t) × (Vec A (#leafs t) -> Tree A)
leafsTreeF empty = ([] , λ _ -> empty)
-- leafsTreeF (node empty root empty) = (root ∷ [] , λ { (hd ∷ []) -> node empty hd empty })
leafsTreeF {A} (node t₁ x t₂) with t₁ | t₂
... | empty | empty = (x ∷ [] , λ { (hd ∷ []) -> node empty hd empty })
leafsTreeF _ | node t11 x1 t12 | t2 with leafsTreeF (node t11 x1 t12) | leafsTreeF t2
... | (g₁ , p₁) | (g₂ , p₂) =
-- (g₁ ++ g₂ , λ v -> node (p₁ (take n₁ v)) x (p₂ (drop n₁ v)))
({!!} , λ v -> node (p₁ {!!}) x1 (p₂ {!!}))
where
n₁ = #leafs (node t11 x1 t12)
n₂ = #leafs t2
leafsTreeF (node t₁ x t₂) | _ | (node _ _ _) with leafsTreeF t₁ | leafsTreeF t₂
... | (g₁ , p₁) | (g₂ , p₂) =
-- (g₁ ++ g₂ , λ v -> node (p₁ (take n₁ v)) x (p₂ (drop n₁ v)))
({!!} , λ v -> node (p₁ {!!}) x (p₂ {!!}))
where
n₁ = #leafs t₁
n₂ = #leafs t₂
module tests where
tree1 : Tree ℕ
tree1 = node (node empty 1 empty) 3 empty
open Traversal
| {
"alphanum_fraction": 0.4759972955,
"avg_line_length": 36.975,
"ext": "agda",
"hexsha": "48ae20f2bf3fcb2668e14487ccca92f607790218",
"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": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "hablapps/safeoptics",
"max_forks_repo_path": "src/main/agda/leafsF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "hablapps/safeoptics",
"max_issues_repo_path": "src/main/agda/leafsF.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "hablapps/safeoptics",
"max_stars_repo_path": "src/main/agda/leafsF.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 515,
"size": 1479
} |
{-# OPTIONS --no-sized-types #-}
postulate
Size : Set
_^ : Size -> Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC _^ #-}
{-# BUILTIN SIZEINF ∞ #-}
data Nat : {size : Size} -> Set where
zero : {size : Size} -> Nat {size ^}
suc : {size : Size} -> Nat {size} -> Nat {size ^}
weak : {i : Size} -> Nat {i} -> Nat {∞}
weak x = x
-- Should give error without sized types.
-- .i != ∞ of type Size
-- when checking that the expression x has type Nat
| {
"alphanum_fraction": 0.5523012552,
"avg_line_length": 20.7826086957,
"ext": "agda",
"hexsha": "192c50dc5c3b5c3d7590d3c77a5ad4ac51948b8a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/NoSizedTypes.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/NoSizedTypes.agda",
"max_line_length": 52,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/fail/NoSizedTypes.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 154,
"size": 478
} |
{-# OPTIONS --cubical #-}
module Properties where
open import Data.Fin renaming (zero to Fzero; suc to Fsuc) hiding (_+_; _≟_)
open import Data.Nat
open import Data.Nat.DivMod using (_mod_; _div_; m≡m%n+[m/n]*n)
open import Data.Nat.Properties using (+-comm)
open import Data.Product
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable using (False)
open ≡-Reasoning
open import Pitch
RelAbs : (n : Pitch) → (relativeToAbsolute ∘ absoluteToRelative) n ≡ n
RelAbs (pitch zero) = refl
RelAbs (pitch (suc n)) =
begin
(relativeToAbsolute ∘ absoluteToRelative) (pitch (suc n))
≡⟨ refl ⟩
relativeToAbsolute (pitchClass ((suc n) mod chromaticScaleSize) ,
octave ((suc n) div chromaticScaleSize))
≡⟨ refl ⟩
pitch (((suc n) div chromaticScaleSize) * chromaticScaleSize +
(toℕ ((suc n) mod chromaticScaleSize)))
≡⟨ cong pitch
(+-comm (((suc n) div chromaticScaleSize) * chromaticScaleSize)
(toℕ ((suc n) mod chromaticScaleSize))) ⟩
pitch ((toℕ ((suc n) mod chromaticScaleSize)) +
(((suc n) div chromaticScaleSize) * chromaticScaleSize))
≡⟨ cong pitch (sym {!!}) ⟩
-- ≡⟨ cong pitch (sym (m≡m%n+[m/n]*n n chromaticScaleSize)) ⟩
pitch (suc n)
∎
{-
absRelAbs (pitch (+_ zero)) = refl
absRelAbs (pitch (+_ (suc n))) = let x = absRelAbs (pitch (+ n)) in {!!}
absRelAbs (pitch (-[1+_] zero)) = refl
absRelAbs (pitch (-[1+_] (suc n))) = {!!}
-}
AbsRel : (n : PitchOctave) → (absoluteToRelative ∘ relativeToAbsolute) n ≡ n
AbsRel (pitchClass p , octave o) =
begin
(absoluteToRelative ∘ relativeToAbsolute) (pitchClass p , octave o)
≡⟨ refl ⟩
absoluteToRelative (pitch (o * chromaticScaleSize + (toℕ p)))
≡⟨ refl ⟩
(pitchClass ((o * chromaticScaleSize + (toℕ p)) mod chromaticScaleSize) ,
octave ((o * chromaticScaleSize + (toℕ p)) div chromaticScaleSize))
≡⟨ {!!} ⟩
(pitchClass p , octave o)
∎
{-
relAbsRel (relativePitch zero , octave (+_ zero)) = refl
relAbsRel (relativePitch zero , octave (+_ (suc n))) = {!!}
relAbsRel (relativePitch zero , octave (-[1+_] zero)) = refl
relAbsRel (relativePitch zero , octave (-[1+_] (suc n))) = {!!}
relAbsRel (relativePitch (suc n) , octave (+_ zero)) = {!!}
relAbsRel (relativePitch (suc n) , octave (+_ (suc o))) = {!!}
relAbsRel (relativePitch (suc n) , octave (-[1+_] zero)) = {!!}
relAbsRel (relativePitch (suc n) , octave (-[1+_] (suc o))) = {!!}
-}
| {
"alphanum_fraction": 0.6245120999,
"avg_line_length": 37.6764705882,
"ext": "agda",
"hexsha": "7614e02203468c62fac5362e9d0716a042ba91f1",
"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/Properties.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/Properties.agda",
"max_line_length": 84,
"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/Properties.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": 842,
"size": 2562
} |
open import Agda.Builtin.IO
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
private
n : Nat
n = 7
{-# COMPILE GHC n as n #-}
postulate
main : IO ⊤
{-# COMPILE GHC main = print n #-}
| {
"alphanum_fraction": 0.6568627451,
"avg_line_length": 12.75,
"ext": "agda",
"hexsha": "f9132e3bc88b4c0f83e2ef00be5d3bb72a611dcc",
"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/Compiler/simple/Issue2914.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/Compiler/simple/Issue2914.agda",
"max_line_length": 34,
"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/Compiler/simple/Issue2914.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": 66,
"size": 204
} |
-- Also works for parts of operators.
module NotInScope where
postulate
X : Set
if_then_else_ : X -> X -> X -> X
x : X
bad = if x thenn x else x
-- The error message should /not/ claim that "if" is out of scope.
| {
"alphanum_fraction": 0.6561085973,
"avg_line_length": 18.4166666667,
"ext": "agda",
"hexsha": "9bce6a14a2d534bfff8499bd1be2e0328aa5a240",
"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/NotInScope.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/NotInScope.agda",
"max_line_length": 66,
"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/NotInScope.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": 69,
"size": 221
} |
-- It would be nice if this worked. The constraint we can't solve is
-- P x y = ? (x, y)
-- Solution: extend the notion of Miller patterns to include record
-- constructions.
--
-- Andreas, 2012-02-27 works now! (see issues 376 and 456)
module UncurryMeta where
data Unit : Set where
unit : Unit
record R : Set where
field
x : Unit
y : Unit
_,_ : Unit -> Unit -> R
x , y = record {x = x; y = y}
data P : Unit -> Unit -> Set where
mkP : forall x y -> P x y
data D : (R -> Set) -> Set1 where
d : {F : R -> Set} -> (forall x y -> F (x , y)) -> D F
unD : {F : R -> Set} -> D F -> Unit
unD (d _) = unit
test : Unit
test = unD (d mkP)
| {
"alphanum_fraction": 0.5764525994,
"avg_line_length": 21.0967741935,
"ext": "agda",
"hexsha": "7371735decbdbe265ec27680be37df2f19ae1fb6",
"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/UncurryMeta.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/UncurryMeta.agda",
"max_line_length": 68,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/UncurryMeta.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 225,
"size": 654
} |
-- Category of indexed families
module SOAS.Families.Core {T : Set} where
open import SOAS.Common
open import SOAS.Context {T}
open import SOAS.Sorting {T}
-- | Unsorted
-- Sets indexed by a context
Family : Set₁
Family = Ctx → Set
-- Indexed functions between families
_⇾_ : Family → Family → Set
X ⇾ Y = ∀{Γ : Ctx} → X Γ → Y Γ
infixr 10 _⇾_
-- Category of indexed families of sets and indexed functions between them
𝔽amilies : Category 1ℓ 0ℓ 0ℓ
𝔽amilies = categoryHelper record
{ Obj = Family
; _⇒_ = _⇾_
; _≈_ = λ {X}{Y} f g → ∀{Γ : Ctx}{x : X Γ} → f x ≡ g x
; id = id
; _∘_ = λ g f → g ∘ f
; assoc = refl
; identityˡ = refl
; identityʳ = refl
; equiv = record { refl = refl ; sym = λ p → sym p ; trans = λ p q → trans p q }
; ∘-resp-≈ = λ where {f = f} p q → trans (cong f q) p
}
module 𝔽am = Category 𝔽amilies
-- | Sorted
-- Category of sorted families
𝔽amiliesₛ : Category 1ℓ 0ℓ 0ℓ
𝔽amiliesₛ = 𝕊orted 𝔽amilies
module 𝔽amₛ = Category 𝔽amiliesₛ
-- Type of sorted families
Familyₛ : Set₁
Familyₛ = 𝔽amₛ.Obj
-- Maps between sorted families
_⇾̣_ : Familyₛ → Familyₛ → Set
_⇾̣_ = 𝔽amₛ._⇒_
infixr 10 _⇾̣_
-- Turn sorted family into unsorted by internally quantifying over the sort
∀[_] : Familyₛ → Family
∀[ 𝒳 ] Γ = {τ : T} → 𝒳 τ Γ
-- Maps between Familyₛ functors
_⇾̣₂_ : (Familyₛ → Familyₛ) → (Familyₛ → Familyₛ) → Set₁
(𝓧 ⇾̣₂ 𝓨) = {𝒵 : Familyₛ} → 𝓧 𝒵 ⇾̣ 𝓨 𝒵
| {
"alphanum_fraction": 0.6375358166,
"avg_line_length": 22.8852459016,
"ext": "agda",
"hexsha": "e42e73f1e68c19c76be0017c088120f5c53a8496",
"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": "SOAS/Families/Core.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": "SOAS/Families/Core.agda",
"max_line_length": 82,
"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": "SOAS/Families/Core.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": 599,
"size": 1396
} |
{-
In this file we apply the cubical machinery to Martin Hötzel-Escardó's
structure identity principle:
https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.SIP where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence renaming (ua-pathToEquiv to ua-pathToEquiv')
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.FunExtEquiv
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HAEquiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.Prod.Base hiding (_×_) renaming (_×Σ_ to _×_)
private
variable
ℓ ℓ' ℓ'' ℓ''' ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ : Level
-- For technical reasons we reprove ua-pathToEquiv using the
-- particular proof constructed by iso→HAEquiv. The reason is that we
-- want to later be able to extract
--
-- eq : ua-au (ua e) ≡ cong ua (au-ua e)
--
uaHAEquiv : (A B : Type ℓ) → HAEquiv (A ≃ B) (A ≡ B)
uaHAEquiv A B = iso→HAEquiv (iso ua pathToEquiv ua-pathToEquiv' pathToEquiv-ua)
open isHAEquiv
-- We now extract the particular proof constructed from iso→HAEquiv
-- for reasons explained above.
ua-pathToEquiv : {A B : Type ℓ} (e : A ≡ B) → ua (pathToEquiv e) ≡ e
ua-pathToEquiv e = uaHAEquiv _ _ .snd .ret e
-- A structure is a type-family S : Type ℓ → Type ℓ', i.e. for X : Type ℓ and s : S X, the pair (X , s)
-- means that X is equipped with a S-structure, which is witnessed by s.
-- An S-structure should have a notion of S-homomorphism, or rather S-isomorphism.
-- This will be implemented by a function ι
-- that gives us for any two types with S-structure (X , s) and (Y , t) a family:
-- ι (X , s) (Y , t) : (X ≃ Y) → Type ℓ''
-- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be
-- a proposition. Indeed this type should correspond to the ways s and t can be identified
-- as S-structures. This we call a standard notion of structure or SNS.
-- We will use a different definition, but the two definitions are interchangeable.
SNS : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')
SNS {ℓ = ℓ} S ι = ∀ {X : (Type ℓ)} (s t : S X) → ((s ≡ t) ≃ ι (X , s) (X , t) (idEquiv X))
-- We introduce the notation for structure preserving equivalences a bit differently,
-- but this definition doesn't actually change from Escardó's notes.
_≃[_]_ : {S : Type ℓ → Type ℓ'}
→ (A : Σ[ X ∈ (Type ℓ) ] (S X))
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ (B : Σ[ X ∈ (Type ℓ) ] (S X))
→ Type (ℓ-max ℓ ℓ'')
A ≃[ ι ] B = Σ[ f ∈ ((A .fst) ≃ (B. fst)) ] (ι A B f)
-- Before we can formulate our version of an SNS we introduce a bit of
-- notation and prove a few basic results. First, we define the
-- "cong-≃":
_⋆_ : (S : Type ℓ → Type ℓ') → {X Y : Type ℓ} → (X ≃ Y) → S X ≃ S Y
S ⋆ f = pathToEquiv (cong S (ua f))
-- Next, we prove a couple of helpful results about this ⋆ operation:
⋆-idEquiv : (S : Type ℓ → Type ℓ') (X : Type ℓ) → S ⋆ (idEquiv X) ≡ idEquiv (S X)
⋆-idEquiv S X = S ⋆ (idEquiv X) ≡⟨ cong (λ p → pathToEquiv (cong S p)) uaIdEquiv ⟩
pathToEquiv refl ≡⟨ pathToEquivRefl ⟩
idEquiv (S X) ∎
⋆-char : (S : Type ℓ → Type ℓ') {X Y : Type ℓ} (f : X ≃ Y) → ua (S ⋆ f) ≡ cong S (ua f)
⋆-char S f = ua-pathToEquiv (cong S (ua f))
PathP-⋆-lemma : (S : Type ℓ → Type ℓ') (A B : Σ[ X ∈ (Type ℓ) ] (S X)) (f : A .fst ≃ B .fst)
→ (PathP (λ i → ua (S ⋆ f) i) (A .snd) (B .snd)) ≡ (PathP (λ i → S ((ua f) i)) (A .snd) (B .snd))
PathP-⋆-lemma S A B f i = PathP (λ j → (⋆-char S f) i j) (A .snd) (B .snd)
-- Our new definition of standard notion of structure SNS' using the ⋆ notation.
-- This is easier to work with than SNS wrt Glue-types
SNS' : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')
SNS' S ι = (A B : Σ[ X ∈ (Type _) ] (S X)) → (f : A .fst ≃ B .fst)
→ (equivFun (S ⋆ f) (A .snd) ≡ (B .snd)) ≃ (ι A B f)
-- We can unfold SNS' as follows:
SNS'' : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')
SNS'' S ι = (A B : Σ[ X ∈ (Type _) ] (S X)) → (f : A .fst ≃ B .fst)
→ (transport (λ i → S (ua f i)) (A .snd) ≡ (B .snd)) ≃ (ι A B f)
SNS'≡SNS'' : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ SNS' S ι ≡ SNS'' S ι
SNS'≡SNS'' S ι = refl
-- A quick sanity-check that our definition is interchangeable with
-- Escardó's. The direction SNS→SNS' corresponds more or less to an
-- EquivJ formulation of Escardó's homomorphism-lemma.
SNS'→SNS : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ SNS' S ι → SNS S ι
SNS'→SNS S ι θ {X = X} s t = subst (λ x → (equivFun x s ≡ t) ≃ ι (X , s) (X , t) (idEquiv X)) (⋆-idEquiv S X) θ-id
where
θ-id = θ (X , s) (X , t) (idEquiv X)
SNS→SNS' : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ SNS S ι → SNS' S ι
SNS→SNS' S ι θ A B f = EquivJ P C (B .fst) (A .fst) f (B .snd) (A .snd)
where
P : (X Y : Type _) → Y ≃ X → Type _
P X Y g = (s : S X) (t : S Y) → (equivFun (S ⋆ g) t ≡ s) ≃ ι (Y , t) (X , s) g
C : (X : Type _) → (s t : S X) → (equivFun (S ⋆ (idEquiv X)) t ≡ s) ≃ ι (X , t) (X , s) (idEquiv X)
C X s t = subst (λ u → (u ≡ s) ≃ (ι (X , t) (X , s) (idEquiv X)))
(sym ( cong (λ f → (equivFun f) t) (⋆-idEquiv S X))) (θ t s)
-- The following transport-free version of SNS'' is a bit easier to
-- work with for the proof of the SIP
SNS''' : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ Type (ℓ-max (ℓ-max(ℓ-suc ℓ) ℓ') ℓ'')
SNS''' S ι = (A B : Σ[ X ∈ (Type _) ] (S X)) → (e : A .fst ≃ B .fst)
→ (PathP (λ i → S (ua e i)) (A .snd) (B .snd)) ≃ ι A B e
-- We can easily go between SNS'' (which is def. equal to SNS') and SNS'''
-- We should be able to find are more direct version of PathP≃Path for the family (λ i → S (ua f i))
-- using glue and unglue terms.
SNS''→SNS''' : {S : Type ℓ → Type ℓ'}
→ {ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ''}
→ SNS'' S ι → SNS''' S ι
SNS''→SNS''' {S = S} h A B f = PathP (λ i → S (ua f i)) (A .snd) (B .snd)
≃⟨ PathP≃Path (λ i → S (ua f i)) (A .snd) (B .snd) ⟩
h A B f
SNS'''→SNS'' : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ SNS''' S ι → SNS'' S ι
SNS'''→SNS'' S ι h A B f = transport (λ i → S (ua f i)) (A .snd) ≡ (B .snd)
≃⟨ invEquiv (PathP≃Path (λ i → S (ua f i)) (A .snd) (B .snd)) ⟩
h A B f
-- We can now directly define a function
-- sip : A ≃[ ι ] B → A ≡ B
-- together with is inverse.
-- Here, these functions use SNS''' and are expressed using a Σ-type instead as it is a bit
-- easier to work with
sip : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ (θ : SNS''' S ι)
→ (A B : Σ[ X ∈ (Type ℓ) ] (S X))
→ A ≃[ ι ] B
→ Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd))
sip S ι θ A B (e , p) = ua e , invEq (θ A B e) p
-- The inverse to sip using the following little lemma
lem : (S : Type ℓ → Type ℓ')
(A B : Σ[ X ∈ (Type ℓ) ] (S X))
(e : A .fst ≡ B .fst)
→ PathP (λ i → S (ua (pathToEquiv e) i)) (A .snd) (B .snd) ≡
PathP (λ i → S (e i)) (A .snd) (B .snd)
lem S A B e i = PathP (λ j → S (ua-pathToEquiv e i j)) (A .snd) (B .snd)
sip⁻ : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ (θ : SNS''' S ι)
→ (A B : Σ[ X ∈ (Type ℓ) ] (S X))
→ Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd))
→ A ≃[ ι ] B
sip⁻ S ι θ A B (e , r) = pathToEquiv e , θ A B (pathToEquiv e) .fst q
where
q : PathP (λ i → S (ua (pathToEquiv e) i)) (A .snd) (B .snd)
q = transport (λ i → lem S A B e (~ i)) r
-- we can rather directly show that sip and sip⁻ are mutually inverse:
sip-sip⁻ : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ (θ : SNS''' S ι)
→ (A B : Σ[ X ∈ (Type ℓ) ] (S X))
→ (r : Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd)))
→ sip S ι θ A B (sip⁻ S ι θ A B r) ≡ r
sip-sip⁻ S ι θ A B (p , q) =
sip S ι θ A B (sip⁻ S ι θ A B (p , q))
≡⟨ refl ⟩
ua (pathToEquiv p) , invEq (θ A B (pathToEquiv p)) (θ A B (pathToEquiv p) .fst (transport (λ i → lem S A B p (~ i)) q))
≡⟨ (λ i → ua (pathToEquiv p) , secEq (θ A B (pathToEquiv p)) (transport (λ i → lem S A B p (~ i)) q) i) ⟩
ua (pathToEquiv p) , transport (λ i → lem S A B p (~ i)) q
≡⟨ (λ i → ua-pathToEquiv p i ,
transp (λ k → PathP (λ j → S (ua-pathToEquiv p (i ∧ k) j)) (A .snd) (B .snd))
(~ i)
(transport (λ i → lem S A B p (~ i)) q)) ⟩
p , transport (λ i → lem S A B p i) (transport (λ i → lem S A B p (~ i)) q)
≡⟨ (λ i → p , transportTransport⁻ (lem S A B p) q i) ⟩
p , q ∎
-- The trickier direction:
sip⁻-sip : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ (θ : SNS''' S ι)
→ (A B : Σ[ X ∈ (Type ℓ) ] (S X))
→ (r : A ≃[ ι ] B)
→ sip⁻ S ι θ A B (sip S ι θ A B r) ≡ r
sip⁻-sip S ι θ A B (e , p) =
sip⁻ S ι θ A B (sip S ι θ A B (e , p))
≡⟨ refl ⟩
pathToEquiv (ua e) , θ A B (pathToEquiv (ua e)) .fst (f⁺ p')
≡⟨ (λ i → pathToEquiv-ua e i , θ A B (pathToEquiv-ua e i) .fst (pth' i)) ⟩
e , θ A B e .fst (f⁻ (f⁺ p'))
≡⟨ (λ i → e , θ A B e .fst (transportTransport⁻ (lem S A B (ua e)) p' i)) ⟩
e , θ A B e .fst (invEq (θ A B e) p)
≡⟨ (λ i → e , (retEq (θ A B e) p i)) ⟩
e , p ∎
where
p' : PathP (λ i → S (ua e i)) (A .snd) (B .snd)
p' = invEq (θ A B e) p
f⁺ : PathP (λ i → S (ua e i)) (A .snd) (B .snd)
→ PathP (λ i → S (ua (pathToEquiv (ua e)) i)) (A .snd) (B .snd)
f⁺ = transport (λ i → PathP (λ j → S (ua-pathToEquiv (ua e) (~ i) j)) (A .snd) (B .snd))
f⁻ : PathP (λ i → S (ua (pathToEquiv (ua e)) i)) (A .snd) (B .snd)
→ PathP (λ i → S (ua e i)) (A .snd) (B .snd)
f⁻ = transport (λ i → PathP (λ j → S (ua-pathToEquiv (ua e) i j)) (A .snd) (B .snd))
-- We can prove the following as in sip∘pis-id, but the type is not
-- what we want as it should be "cong ua (pathToEquiv-ua e)"
pth : PathP (λ j → PathP (λ k → S (ua-pathToEquiv (ua e) j k)) (A .snd) (B .snd))
(f⁺ p') (f⁻ (f⁺ p'))
pth i = transp (λ k → PathP (λ j → S (ua-pathToEquiv (ua e) (i ∧ k) j)) (A .snd) (B .snd))
(~ i)
(f⁺ p')
-- So we build an equality that we want to cast the types with
casteq : PathP (λ j → PathP (λ k → S (ua-pathToEquiv (ua e) j k)) (A .snd) (B .snd))
(f⁺ p') (f⁻ (f⁺ p'))
≡ PathP (λ j → PathP (λ k → S (cong ua (pathToEquiv-ua e) j k)) (A .snd) (B .snd))
(f⁺ p') (f⁻ (f⁺ p'))
casteq i = PathP (λ j → PathP (λ k → S (eq i j k)) (A .snd) (B .snd)) (f⁺ p') (f⁻ (f⁺ p'))
where
-- This is where we need the half-adjoint equivalence property
eq : ua-pathToEquiv (ua e) ≡ cong ua (pathToEquiv-ua e)
eq = sym (uaHAEquiv (A .fst) (B .fst) .snd .com e)
-- We then get a term of the type we need
pth' : PathP (λ j → PathP (λ k → S (cong ua (pathToEquiv-ua e) j k)) (A .snd) (B .snd))
(f⁺ p') (f⁻ (f⁺ p'))
pth' = transport (λ i → casteq i) pth
-- Finally package everything up to get the cubical SIP
SIP : (S : Type ℓ → Type ℓ')
→ (ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
→ (θ : SNS''' S ι)
→ (A B : Σ[ X ∈ (Type ℓ) ] (S X))
→ A ≃[ ι ] B ≃ (A ≡ B)
SIP S ι θ A B = (A ≃[ ι ] B ) ≃⟨ eq ⟩ Σ≡
where
eq : A ≃[ ι ] B ≃ Σ (A .fst ≡ B .fst) (λ p → PathP (λ i → S (p i)) (A .snd) (B .snd))
eq = isoToEquiv (iso (sip S ι θ A B) (sip⁻ S ι θ A B)
(sip-sip⁻ S ι θ A B) (sip⁻-sip S ι θ A B))
-- Now, we want to add axioms (i.e. propositions) to our Structure S that don't affect the ι.
-- For this and the remainder of this file we will work with SNS'
-- We use a lemma due to Zesen Qian, which can now be found in Foundations.Prelude:
-- https://github.com/riaqn/cubical/blob/hgroup/Cubical/Data/Group/Properties.agda#L83
add-to-structure : (S : Type ℓ → Type ℓ')
(axioms : (X : Type ℓ) → (S X) → Type ℓ''')
→ Type ℓ → Type (ℓ-max ℓ' ℓ''')
add-to-structure S axioms X = Σ[ s ∈ S X ] (axioms X s)
add-to-iso : (S : Type ℓ → Type ℓ')
(ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
(axioms : (X : Type ℓ) → (S X) → Type ℓ''')
→ (A B : Σ[ X ∈ (Type ℓ) ] (add-to-structure S axioms X)) → A .fst ≃ B .fst
→ Type ℓ''
add-to-iso S ι axioms (X , (s , a)) (Y , (t , b)) f = ι (X , s) (Y , t) f
add-⋆-lemma : (S : Type ℓ → Type ℓ')
(axioms : (X : Type ℓ) → (S X) → Type ℓ''')
(axioms-are-Props : (X : Type ℓ) (s : S X) → isProp (axioms X s))
{X Y : Type ℓ} {s : S X} {t : S Y} {a : axioms X s} {b : axioms Y t}
(f : X ≃ Y)
→ (equivFun (add-to-structure S axioms ⋆ f) (s , a) ≡ (t , b)) ≃ (equivFun (S ⋆ f) s ≡ t)
add-⋆-lemma S axioms axioms-are-Props {Y = Y} {s = s} {t = t} {a = a} {b = b} f = isoToEquiv (iso φ ψ η ε)
where
φ : equivFun ((add-to-structure S axioms) ⋆ f) (s , a) ≡ (t , b)
→ equivFun (S ⋆ f) s ≡ t
φ r i = r i .fst
ψ : equivFun (S ⋆ f) s ≡ t
→ equivFun ((add-to-structure S axioms) ⋆ f) (s , a) ≡ (t , b)
ψ p i = p i , isProp→PathP (λ j → axioms-are-Props Y (p j)) (equivFun (add-to-structure S axioms ⋆ f) (s , a) .snd) b i
η : section φ ψ
η p = refl
ε : retract φ ψ
ε r i j = r j .fst
, isProp→isSet-PathP (λ k → axioms-are-Props Y (r k .fst)) _ _
(isProp→PathP (λ j → axioms-are-Props Y (r j .fst))
(equivFun (add-to-structure S axioms ⋆ f) (s , a) .snd) b)
(λ k → r k .snd) i j
add-axioms-SNS' : (S : Type ℓ → Type ℓ')
(ι : (A B : Σ[ X ∈ (Type ℓ) ] (S X)) → A .fst ≃ B .fst → Type ℓ'')
(axioms : (X : Type ℓ) → (S X) → Type ℓ''')
(axioms-are-Props : (X : Type ℓ) (s : S X) → isProp (axioms X s))
(θ : SNS' S ι)
→ SNS' (add-to-structure S axioms) (add-to-iso S ι axioms)
add-axioms-SNS' S ι axioms axioms-are-Props θ (X , (s , a)) (Y , (t , b)) f =
equivFun (add-to-structure S axioms ⋆ f) (s , a) ≡ (t , b) ≃⟨ add-⋆-lemma S axioms axioms-are-Props f ⟩
equivFun (S ⋆ f) s ≡ t ≃⟨ θ (X , s) (Y , t) f ⟩
add-to-iso S ι axioms (X , (s , a)) (Y , (t , b)) f ■
-- Now, we want to join two structures. Together with the adding of
-- axioms this will allow us to prove that a lot of mathematical
-- structures are a standard notion of structure
technical-×-lemma : {A : Type ℓ₁} {B : Type ℓ₂} {C : Type ℓ₃} {D : Type ℓ₄}
→ A ≃ C → B ≃ D → A × B ≃ C × D
technical-×-lemma {A = A} {B = B} {C = C} {D = D} f g = isoToEquiv (iso φ ψ η ε)
where
φ : (A × B) → (C × D)
φ (a , b) = equivFun f a , equivFun g b
ψ : (C × D) → (A × B)
ψ (c , d) = equivFun (invEquiv f) c , equivFun (invEquiv g) d
η : section φ ψ
η (c , d) i = retEq f c i , retEq g d i
ε : retract φ ψ
ε (a , b) i = secEq f a i , secEq g b i
join-structure : (S₁ : Type ℓ₁ → Type ℓ₂) (S₂ : Type ℓ₁ → Type ℓ₄)
→ Type ℓ₁ → Type (ℓ-max ℓ₂ ℓ₄)
join-structure S₁ S₂ X = S₁ X × S₂ X
join-iso : {S₁ : Type ℓ₁ → Type ℓ₂}
(ι₁ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₁ X)) → A .fst ≃ B .fst → Type ℓ₃)
{S₂ : Type ℓ₁ → Type ℓ₄}
(ι₂ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₂ X)) → A .fst ≃ B .fst → Type ℓ₅)
(A B : Σ[ X ∈ (Type ℓ₁) ] (join-structure S₁ S₂ X))
→ A .fst ≃ B .fst
→ Type (ℓ-max ℓ₃ ℓ₅)
join-iso ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) f = (ι₁ (X , s₁) (Y , t₁) f) × (ι₂ (X , s₂) (Y , t₂) f)
join-⋆-lemma : (S₁ : Type ℓ₁ → Type ℓ₂) (S₂ : Type ℓ₁ → Type ℓ₄)
{X Y : Type ℓ₁} {s₁ : S₁ X} {s₂ : S₂ X} {t₁ : S₁ Y} {t₂ : S₂ Y} (f : X ≃ Y)
→ (equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)) ≃
(equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)
join-⋆-lemma S₁ S₂ {Y = Y} {s₁ = s₁} {s₂ = s₂} {t₁ = t₁} {t₂ = t₂} f = isoToEquiv (iso φ ψ η ε)
where
φ : equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)
→ (equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)
φ p = (λ i → p i .fst) , (λ i → p i .snd)
ψ : (equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)
→ equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)
ψ (p , q) i = (p i) , (q i)
η : section φ ψ
η (p , q) = refl
ε : retract φ ψ
ε p = refl
join-SNS' : (S₁ : Type ℓ₁ → Type ℓ₂)
(ι₁ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₁ X)) → A .fst ≃ B .fst → Type ℓ₃)
(θ₁ : SNS' S₁ ι₁)
(S₂ : Type ℓ₁ → Type ℓ₄)
(ι₂ : (A B : Σ[ X ∈ (Type ℓ₁) ] (S₂ X)) → A .fst ≃ B .fst → Type ℓ₅)
(θ₂ : SNS' S₂ ι₂)
→ SNS' (join-structure S₁ S₂) (join-iso ι₁ ι₂)
join-SNS' S₁ ι₁ θ₁ S₂ ι₂ θ₂ (X , s₁ , s₂) (Y , t₁ , t₂) f =
equivFun (join-structure S₁ S₂ ⋆ f) (s₁ , s₂) ≡ (t₁ , t₂)
≃⟨ join-⋆-lemma S₁ S₂ f ⟩
(equivFun (S₁ ⋆ f) s₁ ≡ t₁) × (equivFun (S₂ ⋆ f) s₂ ≡ t₂)
≃⟨ technical-×-lemma (θ₁ (X , s₁) (Y , t₁) f) (θ₂ (X , s₂) (Y , t₂) f) ⟩
join-iso ι₁ ι₂ (X , s₁ , s₂) (Y , t₁ , t₂) f ■
-- Now, we want to do Monoids as an example. We begin by showing SNS' for simple structures, i.e. pointed types and ∞-magmas.
-- Pointed types with SNS'
pointed-structure : Type ℓ → Type ℓ
pointed-structure X = X
Pointed-Type : Type (ℓ-suc ℓ)
Pointed-Type {ℓ = ℓ} = Σ (Type ℓ) pointed-structure
pointed-iso : (A B : Pointed-Type) → A .fst ≃ B .fst → Type ℓ
pointed-iso A B f = equivFun f (A .snd) ≡ B .snd
pointed-is-SNS' : SNS' {ℓ = ℓ} pointed-structure pointed-iso
pointed-is-SNS' A B f = transportEquiv (λ i → transportRefl (equivFun f (A .snd)) i ≡ B .snd)
-- ∞-Magmas with SNS'
-- We need function extensionality for binary functions.
-- TODO: upstream
funExtBin : {A : Type ℓ} {B : A → Type ℓ'} {C : (x : A) → B x → Type ℓ''} {f g : (x : A) → (y : B x) → C x y}
→ ((x : A) (y : B x) → f x y ≡ g x y) → f ≡ g
funExtBin p i x y = p x y i
module _ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} {C : (x : A) → B x → Type ℓ''} {f g : (x : A) → (y : B x) → C x y} where
private
appl : f ≡ g → ∀ x y → f x y ≡ g x y
appl eq x y i = eq i x y
fib : (p : f ≡ g) → fiber funExtBin p
fib p = (appl p , refl)
funExtBin-fiber-isContr
: (p : f ≡ g)
→ (fi : fiber funExtBin p)
→ fib p ≡ fi
funExtBin-fiber-isContr p (h , eq) i = (appl (eq (~ i)) , λ j → eq (~ i ∨ j))
funExtBin-isEquiv : isEquiv funExtBin
equiv-proof funExtBin-isEquiv p = (fib p , funExtBin-fiber-isContr p)
funExtBinEquiv : (∀ x y → f x y ≡ g x y) ≃ (f ≡ g)
funExtBinEquiv = (funExtBin , funExtBin-isEquiv)
-- ∞-Magmas
∞-magma-structure : Type ℓ → Type ℓ
∞-magma-structure X = X → X → X
∞-Magma : Type (ℓ-suc ℓ)
∞-Magma {ℓ = ℓ} = Σ (Type ℓ) ∞-magma-structure
∞-magma-iso : (A B : ∞-Magma) → A .fst ≃ B .fst → Type ℓ
∞-magma-iso (X , _·_) (Y , _∗_) f = (x x' : X) → equivFun f (x · x') ≡ (equivFun f x) ∗ (equivFun f x')
∞-magma-is-SNS' : SNS' {ℓ = ℓ} ∞-magma-structure ∞-magma-iso
∞-magma-is-SNS' (X , _·_) (Y , _∗_) f = SNS→SNS' ∞-magma-structure ∞-magma-iso C (X , _·_) (Y , _∗_) f
where
C : {X : Type ℓ} (_·_ _∗_ : X → X → X) → (_·_ ≡ _∗_) ≃ ((x x' : X) → (x · x') ≡ (x ∗ x'))
C _·_ _∗_ = invEquiv funExtBinEquiv
-- Now we're getting serious: Monoids
raw-monoid-structure : Type ℓ → Type ℓ
raw-monoid-structure X = X × (X → X → X)
raw-monoid-iso : (M N : Σ (Type ℓ) raw-monoid-structure) → (M .fst) ≃ (N .fst) → Type ℓ
raw-monoid-iso (M , e , _·_) (N , d , _∗_) f = (equivFun f e ≡ d)
× ((x y : M) → equivFun f (x · y) ≡ (equivFun f x) ∗ (equivFun f y))
-- If we ignore the axioms we get something like a "raw" monoid, which essentially is the join of a pointed type and an ∞-magma
raw-monoid-is-SNS' : SNS' {ℓ = ℓ} raw-monoid-structure raw-monoid-iso
raw-monoid-is-SNS' = join-SNS' pointed-structure pointed-iso pointed-is-SNS'
∞-magma-structure ∞-magma-iso ∞-magma-is-SNS'
-- Now define monoids
monoid-axioms : (X : Type ℓ) → raw-monoid-structure X → Type ℓ
monoid-axioms X (e , _·_ ) = isSet X
× ((x y z : X) → (x · (y · z)) ≡ ((x · y) · z))
× ((x : X) → (x · e) ≡ x)
× ((x : X) → (e · x) ≡ x)
monoid-structure : Type ℓ → Type ℓ
monoid-structure = add-to-structure (raw-monoid-structure) monoid-axioms
-- TODO: it might be nicer to formulate the SIP lemmas so that they're
-- easier to use for things that are not "completely packaged"
Monoids : Type (ℓ-suc ℓ)
Monoids = Σ (Type _) monoid-structure
monoid-iso : (M N : Monoids) → M .fst ≃ N .fst → Type ℓ
monoid-iso = add-to-iso raw-monoid-structure raw-monoid-iso monoid-axioms
-- We have to show that the monoid axioms are indeed Propositions
monoid-axioms-are-Props : (X : Type ℓ) (s : raw-monoid-structure X) → isProp (monoid-axioms X s)
monoid-axioms-are-Props X (e , _·_) s = β s
where
α = s .fst
β = isOfHLevelΣ 1 isPropIsSet
λ _ → isOfHLevelΣ 1 (hLevelPi 1 (λ x → hLevelPi 1 λ y → hLevelPi 1 λ z → α (x · (y · z)) ((x · y) · z)))
λ _ → isOfHLevelΣ 1 (hLevelPi 1 λ x → α (x · e) x)
λ _ → hLevelPi 1 λ x → α (e · x) x
monoid-is-SNS' : SNS' {ℓ = ℓ} monoid-structure monoid-iso
monoid-is-SNS' = add-axioms-SNS' raw-monoid-structure raw-monoid-iso
monoid-axioms monoid-axioms-are-Props raw-monoid-is-SNS'
MonoidPath : (M N : Monoids {ℓ}) → (M ≃[ monoid-iso ] N) ≃ (M ≡ N)
MonoidPath M N = SIP monoid-structure monoid-iso (SNS''→SNS''' monoid-is-SNS') M N
| {
"alphanum_fraction": 0.5066508626,
"avg_line_length": 44.2310679612,
"ext": "agda",
"hexsha": "f73bd50aa946cb0426f27d27408ad154d3123298",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Foundations/SIP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Foundations/SIP.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Foundations/SIP.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9834,
"size": 22779
} |
module WrongHidingInApplication where
id : (A : Set) -> A -> A
id A x = x
foo : (A : Set) -> A -> A
foo A x = id {A} x
| {
"alphanum_fraction": 0.5365853659,
"avg_line_length": 12.3,
"ext": "agda",
"hexsha": "25f70fb69d82134b0ef439a5164ef92ede77d5a4",
"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/WrongHidingInApplication.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/WrongHidingInApplication.agda",
"max_line_length": 37,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/WrongHidingInApplication.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 49,
"size": 123
} |
module GTFL where
open import Data.Nat hiding (_⊓_; erase; _≟_; _≤_)
open import Data.Bool hiding (_≟_)
open import Data.Fin using (Fin; zero; suc; toℕ)
open import Data.Vec
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Data.Empty
open import Function using (_∘_)
-- | Types
infixr 30 _⇒_
data GType : Set where
nat : GType
bool : GType
_⇒_ : GType → GType → GType
✭ : GType
err : GType -- easier to model this as a type in Agda
-- | Untyped Expressions
data Expr : Set where
litNat : ℕ → Expr
litBool : Bool → Expr
dyn : Expr
err : Expr
var : ℕ → Expr
lam : GType → Expr → Expr
_∙_ : Expr → Expr → Expr
_⊕_ : Expr → Expr → Expr
if_thn_els_ : Expr → Expr → Expr → Expr
Ctx : ℕ → Set
Ctx = Vec GType
infixr 10 _~_
data _~_ {A B : Set} (x : A) (y : B) : Set where
cons : x ~ y
~dom : ∀ (t : GType) → GType
~dom (t ⇒ t₁) = t₁
~dom _ = err
~cod : ∀ (t : GType) → GType
~cod (t ⇒ t₁) = t₁
~cod _ = err
_⊓_ : ∀ (t₁ t₂ : GType) → GType
nat ⊓ nat = nat
bool ⊓ bool = bool
t₁ ⊓ ✭ = t₁
✭ ⊓ t₂ = t₂
(t₁ ⇒ t₂) ⊓ (t₃ ⇒ t₄) = (t₁ ⊓ t₃) ⇒ (t₂ ⊓ t₄)
_ ⊓ _ = err
-- | Typed Terms
data Term {n} (Γ : Ctx n) : GType → Set where
Tx : ∀ {t} (v : Fin n) → t ≡ lookup v Γ → Term Γ t
Tn : ℕ → Term Γ nat
Tb : Bool → Term Γ bool
Tdy : Term Γ ✭
_T∙_ : ∀ {t₁ t₂} → Term Γ t₁ → Term Γ t₂ → t₂ ~ (~dom t₁) → Term Γ (~cod t₁)
_T⊕_ : ∀ {t₁ t₂} → Term Γ t₁ → Term Γ t₂ → (t₁ ~ nat) → (t₂ ~ nat) → Term Γ (t₁ ⊓ t₂)
Tif : ∀ {t₁ t₂ t₃} → Term Γ t₁ → Term Γ t₂ → Term Γ t₃ → (t₁ ~ bool) → Term Γ (t₂ ⊓ t₃)
Tlam : ∀ t₁ {t₂} → Term (t₁ ∷ Γ) t₂ → Term Γ (t₁ ⇒ t₂)
erase : ∀ {n} {Γ : Ctx n} {t} → Term Γ t → Expr
erase (Tx v x) = var (toℕ v)
erase (Tn x) = litNat x
erase (Tb x) = litBool x
erase Tdy = dyn
erase ((term T∙ term₁) _) = (erase term) ∙ (erase term₁)
erase ((term T⊕ term₁) _ _) = (erase term) ⊕ (erase term₁)
erase (Tif b tt ff _) = if erase b thn erase tt els erase ff
erase (Tlam t₁ term) = lam t₁ (erase term)
data Fromℕ (n : ℕ) : ℕ → Set where
yes : (m : Fin n) → Fromℕ n (toℕ m)
no : (m : ℕ) → Fromℕ n (n + m)
fromℕ : ∀ n m → Fromℕ n m
fromℕ zero m = no m
fromℕ (suc n) zero = yes zero
fromℕ (suc n) (suc m) with fromℕ n m
fromℕ (suc n) (suc .(toℕ m)) | yes m = yes (suc m)
fromℕ (suc n) (suc .(n + m)) | no m = no m
data Check {n} (Γ : Ctx n) : Expr → Set where
yes : (τ : GType) (t : Term Γ τ) → Check Γ (erase t)
no : {e : Expr} → Check Γ e
staticCheck : ∀ {n} (Γ : Ctx n) (t : Expr) → Check Γ t
-- | primitives
staticCheck Γ (litNat x) = yes nat (Tn x)
staticCheck Γ (litBool x) = yes bool (Tb x)
staticCheck {n} Γ dyn = yes ✭ Tdy
staticCheck Γ err = no
-- | var lookup
staticCheck {n} Γ (var v) with fromℕ n v
staticCheck {n} Γ (var .(toℕ m)) | yes m = yes (lookup m Γ) (Tx m refl)
staticCheck {n} Γ (var .(n + m)) | no m = no
-- | lambda abstraction
staticCheck Γ (lam x t) with staticCheck (x ∷ Γ) t
staticCheck Γ (lam x .(erase t)) | yes τ t = yes (x ⇒ τ) (Tlam x t) -- double check this
staticCheck Γ (lam x t) | no = no
-- | application
staticCheck Γ (t₁ ∙ t₂) with staticCheck Γ t₁ | staticCheck Γ t₂
staticCheck Γ (.(erase t₁) ∙ .(erase t)) | yes (τ₁ ⇒ τ₂) t₁ | (yes τ t) = yes τ₂ ((t₁ T∙ t) cons)
staticCheck Γ (.(erase t₁) ∙ .(erase t)) | yes _ t₁ | (yes τ t) = no -- not sure about this
staticCheck Γ (t₁ ∙ t₂) | _ | _ = no
-- | addition
staticCheck Γ (t₁ ⊕ t₂) with staticCheck Γ t₁ | staticCheck Γ t₂
staticCheck Γ (.(erase t₁) ⊕ .(erase t)) | yes nat t₁ | (yes nat t) = yes nat ((t₁ T⊕ t) cons cons)
staticCheck Γ (.(erase t₁) ⊕ .(erase t)) | yes ✭ t₁ | (yes nat t) = yes (✭ ⊓ nat) ((t₁ T⊕ t) cons cons)
staticCheck Γ (.(erase t₁) ⊕ .(erase t)) | yes nat t₁ | (yes ✭ t) = yes (nat ⊓ ✭) ((t₁ T⊕ t) cons cons)
staticCheck Γ (.(erase t₁) ⊕ .(erase t)) | yes ✭ t₁ | (yes ✭ t) = yes ✭ ((t₁ T⊕ t) cons cons)
staticCheck Γ (t₁ ⊕ t₂) | _ | _ = no
-- | if ... then ... else
staticCheck Γ (if t thn t₁ els t₂) with staticCheck Γ t
staticCheck Γ (if .(erase t) thn t₁ els t₂) | yes bool t with staticCheck Γ t₁ | staticCheck Γ t₂
staticCheck Γ (if .(erase t₂) thn .(erase t₁) els .(erase t)) | yes bool t₂ | (yes τ₁ t₁) | (yes τ₂ t) = yes (τ₁ ⊓ τ₂) (Tif t₂ t₁ t cons)
staticCheck Γ (if .(erase t₁) thn .(erase t) els t₂) | yes bool t₁ | (yes τ t) | no = no
staticCheck Γ (if .(erase t₂) thn t₁ els .(erase t)) | yes bool t₂ | no | (yes τ t) = no
staticCheck Γ (if .(erase t) thn t₁ els t₂) | yes bool t | no | _ = no
staticCheck Γ (if .(erase t) thn t₁ els t₂) | yes ✭ t with staticCheck Γ t₁ | staticCheck Γ t₂
staticCheck Γ (if .(erase t₂) thn .(erase t₁) els .(erase t)) | yes ✭ t₂ | (yes τ₁ t₁) | (yes τ₂ t) = yes (τ₁ ⊓ τ₂) (Tif t₂ t₁ t cons)
staticCheck Γ (if .(erase t₁) thn .(erase t) els t₂) | yes ✭ t₁ | (yes τ t) | no = no
staticCheck Γ (if .(erase t₂) thn t₁ els .(erase t)) | yes ✭ t₂ | no | (yes τ t) = no
staticCheck Γ (if .(erase t) thn t₁ els t₂) | yes ✭ t | no | no = no
staticCheck Γ (if .(erase t) thn t₁ els t₂) | yes _ t = no
staticCheck Γ (if t thn t₁ els t₂) | no = no
extractType : ∀ {n} {Γ : Ctx n} {t : Expr} → Check Γ t → GType
extractType (yes τ t) = τ
extractType no = err
-- Type Precision
data _⊑_ : GType → GType → Set where
n⊑✭ : nat ⊑ ✭
b⊑✭ : bool ⊑ ✭
⇒⊑ : ∀ (t₁ t₂ : GType) → (t₁ ⇒ t₂) ⊑ ✭
n⊑n : nat ⊑ nat
b⊑b : bool ⊑ bool
✭⊑✭ : ✭ ⊑ ✭
app⊑ : ∀ (t₁ t₂ t₃ t₄ : GType) → t₁ ⊑ t₃ → t₂ ⊑ t₄ → (t₁ ⇒ t₃) ⊑ (t₃ ⇒ t₄)
-- Term Precision
data _≤_ : Expr → Expr → Set where
n≤n : ∀ {n} → litNat n ≤ litNat n
b≤b : ∀ {b} → litBool b ≤ litBool b
n≤✭ : ∀ {n} → litNat n ≤ dyn
b≤✭ : ∀ {b} → litBool b ≤ dyn
d≤d : dyn ≤ dyn
ssG : ∀ {n} {Γ : Ctx n} {e₁ e₂ : Expr} → e₁ ≤ e₂ → extractType (staticCheck Γ e₁) ⊑ extractType (staticCheck Γ e₂)
ssG n≤n = n⊑n
ssG b≤b = b⊑b
ssG n≤✭ = n⊑✭
ssG b≤✭ = b⊑✭
ssG d≤d = ✭⊑✭
| {
"alphanum_fraction": 0.5450799407,
"avg_line_length": 36.1130952381,
"ext": "agda",
"hexsha": "1c08b2d9fe68d84d5fb0fa1648c8c509ece8a357",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kellino/TypeSystems",
"max_forks_repo_path": "Agda/GTFL.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "kellino/TypeSystems",
"max_issues_repo_path": "Agda/GTFL.agda",
"max_line_length": 137,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "acf5a153e14a7bdc0c9332fa602fa369fe7add46",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kellino/TypeSystems",
"max_stars_repo_path": "Agda/GTFL.agda",
"max_stars_repo_stars_event_max_datetime": "2017-05-26T23:06:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-27T08:05:40.000Z",
"num_tokens": 2630,
"size": 6067
} |
------------------------------------------------------------------------------
-- Arithmetic properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.PropertiesI
open import FOTC.Data.Nat
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.Nat.UnaryNumbers.TotalityI
------------------------------------------------------------------------------
-- Congruence properties
+-leftCong : ∀ {m n o} → m ≡ n → m + o ≡ n + o
+-leftCong refl = refl
+-rightCong : ∀ {m n o} → n ≡ o → m + n ≡ m + o
+-rightCong refl = refl
∸-leftCong : ∀ {m n o} → m ≡ n → m ∸ o ≡ n ∸ o
∸-leftCong refl = refl
∸-rightCong : ∀ {m n o} → n ≡ o → m ∸ n ≡ m ∸ o
∸-rightCong refl = refl
*-leftCong : ∀ {m n o} → m ≡ n → m * o ≡ n * o
*-leftCong refl = refl
*-rightCong : ∀ {m n o} → n ≡ o → m * n ≡ m * o
*-rightCong refl = refl
------------------------------------------------------------------------------
Sx≢x : ∀ {n} → N n → succ₁ n ≢ n
Sx≢x nzero h = ⊥-elim (0≢S (sym h))
Sx≢x (nsucc Nn) h = ⊥-elim (Sx≢x Nn (succInjective h))
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity = +-0x
+-rightIdentity : ∀ {n} → N n → n + zero ≡ n
+-rightIdentity nzero = +-leftIdentity zero
+-rightIdentity (nsucc {n} Nn) =
trans (+-Sx n zero) (succCong (+-rightIdentity Nn))
pred-N : ∀ {n} → N n → N (pred₁ n)
pred-N nzero = subst N (sym pred-0) nzero
pred-N (nsucc {n} Nn) = subst N (sym (pred-S n)) Nn
+-N : ∀ {m n} → N m → N n → N (m + n)
+-N {n = n} nzero Nn = subst N (sym (+-leftIdentity n)) Nn
+-N {n = n} (nsucc {m} Nm) Nn = subst N (sym (+-Sx m n)) (nsucc (+-N Nm Nn))
∸-N : ∀ {m n} → N m → N n → N (m ∸ n)
∸-N {m} Nm nzero = subst N (sym (∸-x0 m)) Nm
∸-N {m} Nm (nsucc {n} Nn) = subst N (sym (∸-xS m n)) (pred-N (∸-N Nm Nn))
+-assoc : ∀ {m} → N m → ∀ n o → m + n + o ≡ m + (n + o)
+-assoc nzero n o =
zero + n + o ≡⟨ +-leftCong (+-leftIdentity n) ⟩
n + o ≡⟨ sym (+-leftIdentity (n + o)) ⟩
zero + (n + o) ∎
+-assoc (nsucc {m} Nm) n o =
succ₁ m + n + o ≡⟨ +-leftCong (+-Sx m n) ⟩
succ₁ (m + n) + o ≡⟨ +-Sx (m + n) o ⟩
succ₁ (m + n + o) ≡⟨ succCong (+-assoc Nm n o) ⟩
succ₁ (m + (n + o)) ≡⟨ sym (+-Sx m (n + o)) ⟩
succ₁ m + (n + o) ∎
x+Sy≡S[x+y] : ∀ {m} → N m → ∀ n → m + succ₁ n ≡ succ₁ (m + n)
x+Sy≡S[x+y] nzero n =
zero + succ₁ n ≡⟨ +-leftIdentity (succ₁ n) ⟩
succ₁ n ≡⟨ succCong (sym (+-leftIdentity n)) ⟩
succ₁ (zero + n) ∎
x+Sy≡S[x+y] (nsucc {m} Nm) n =
succ₁ m + succ₁ n ≡⟨ +-Sx m (succ₁ n) ⟩
succ₁ (m + succ₁ n) ≡⟨ succCong (x+Sy≡S[x+y] Nm n) ⟩
succ₁ (succ₁ (m + n)) ≡⟨ succCong (sym (+-Sx m n)) ⟩
succ₁ (succ₁ m + n) ∎
+-comm : ∀ {m n} → N m → N n → m + n ≡ n + m
+-comm {n = n} nzero Nn =
zero + n ≡⟨ +-leftIdentity n ⟩
n ≡⟨ sym (+-rightIdentity Nn) ⟩
n + zero ∎
+-comm {n = n} (nsucc {m} Nm) Nn =
succ₁ m + n ≡⟨ +-Sx m n ⟩
succ₁ (m + n) ≡⟨ succCong (+-comm Nm Nn) ⟩
succ₁ (n + m) ≡⟨ sym (x+Sy≡S[x+y] Nn m) ⟩
n + succ₁ m ∎
0∸x : ∀ {n} → N n → zero ∸ n ≡ zero
0∸x nzero = ∸-x0 zero
0∸x (nsucc {n} Nn) =
zero ∸ succ₁ n ≡⟨ ∸-xS zero n ⟩
pred₁ (zero ∸ n) ≡⟨ predCong (0∸x Nn) ⟩
pred₁ zero ≡⟨ pred-0 ⟩
zero ∎
S∸S : ∀ {m n} → N m → N n → succ₁ m ∸ succ₁ n ≡ m ∸ n
S∸S {m} _ nzero =
succ₁ m ∸ succ₁ zero ≡⟨ ∸-xS (succ₁ m) zero ⟩
pred₁ (succ₁ m ∸ zero) ≡⟨ predCong (∸-x0 (succ₁ m)) ⟩
pred₁ (succ₁ m) ≡⟨ pred-S m ⟩
m ≡⟨ sym (∸-x0 m) ⟩
m ∸ zero ∎
S∸S {m} Nm (nsucc {n} Nn) =
succ₁ m ∸ succ₁ (succ₁ n) ≡⟨ ∸-xS (succ₁ m) (succ₁ n) ⟩
pred₁ (succ₁ m ∸ succ₁ n) ≡⟨ predCong (S∸S Nm Nn) ⟩
pred₁ (m ∸ n) ≡⟨ sym (∸-xS m n) ⟩
m ∸ succ₁ n ∎
x∸x≡0 : ∀ {n} → N n → n ∸ n ≡ zero
x∸x≡0 nzero = ∸-x0 zero
x∸x≡0 (nsucc Nn) = trans (S∸S Nn Nn) (x∸x≡0 Nn)
Sx∸x≡1 : ∀ {n} → N n → succ₁ n ∸ n ≡ 1'
Sx∸x≡1 nzero = ∸-x0 1'
Sx∸x≡1 (nsucc Nn) = trans (S∸S (nsucc Nn) Nn) (Sx∸x≡1 Nn)
[x+Sy]∸y≡Sx : ∀ {m n} → N m → N n → m + succ₁ n ∸ n ≡ succ₁ m
[x+Sy]∸y≡Sx {n = n} nzero Nn =
zero + succ₁ n ∸ n ≡⟨ ∸-leftCong (+-leftIdentity (succ₁ n)) ⟩
succ₁ n ∸ n ≡⟨ Sx∸x≡1 Nn ⟩
1' ∎
[x+Sy]∸y≡Sx (nsucc {m} Nm) nzero =
succ₁ m + 1' ∸ zero ≡⟨ ∸-leftCong (+-Sx m 1') ⟩
succ₁ (m + 1') ∸ zero ≡⟨ ∸-x0 (succ₁ (m + 1')) ⟩
succ₁ (m + 1') ≡⟨ succCong (+-comm Nm 1-N) ⟩
succ₁ (1' + m) ≡⟨ succCong (+-Sx zero m) ⟩
succ₁ (succ₁ (zero + m)) ≡⟨ succCong (succCong (+-leftIdentity m)) ⟩
succ₁ (succ₁ m) ∎
[x+Sy]∸y≡Sx (nsucc {m} Nm) (nsucc {n} Nn) =
succ₁ m + succ₁ (succ₁ n) ∸ succ₁ n
≡⟨ ∸-leftCong (+-Sx m (succ₁ (succ₁ n))) ⟩
succ₁ (m + succ₁ (succ₁ n)) ∸ succ₁ n
≡⟨ S∸S (+-N Nm (nsucc (nsucc Nn))) Nn ⟩
m + succ₁ (succ₁ n) ∸ n
≡⟨ ∸-leftCong (x+Sy≡S[x+y] Nm (succ₁ n)) ⟩
succ₁ (m + succ₁ n) ∸ n
≡⟨ ∸-leftCong (sym (+-Sx m (succ₁ n))) ⟩
succ₁ m + succ₁ n ∸ n
≡⟨ [x+Sy]∸y≡Sx (nsucc Nm) Nn ⟩
succ₁ (succ₁ m) ∎
[x+y]∸[x+z]≡y∸z : ∀ {m n o} → N m → N n → N o → (m + n) ∸ (m + o) ≡ n ∸ o
[x+y]∸[x+z]≡y∸z {n = n} {o} nzero _ _ =
(zero + n) ∸ (zero + o) ≡⟨ ∸-leftCong (+-leftIdentity n) ⟩
n ∸ (zero + o) ≡⟨ ∸-rightCong (+-leftIdentity o) ⟩
n ∸ o ∎
[x+y]∸[x+z]≡y∸z {n = n} {o} (nsucc {m} Nm) Nn No =
(succ₁ m + n) ∸ (succ₁ m + o) ≡⟨ ∸-leftCong (+-Sx m n) ⟩
succ₁ (m + n) ∸ (succ₁ m + o) ≡⟨ ∸-rightCong (+-Sx m o) ⟩
succ₁ (m + n) ∸ succ₁ (m + o) ≡⟨ S∸S (+-N Nm Nn) (+-N Nm No) ⟩
(m + n) ∸ (m + o) ≡⟨ [x+y]∸[x+z]≡y∸z Nm Nn No ⟩
n ∸ o ∎
*-leftZero : ∀ n → zero * n ≡ zero
*-leftZero = *-0x
*-rightZero : ∀ {n} → N n → n * zero ≡ zero
*-rightZero nzero = *-leftZero zero
*-rightZero (nsucc {n} Nn) =
trans (*-Sx n zero)
(trans (+-leftIdentity (n * zero)) (*-rightZero Nn))
*-N : ∀ {m n} → N m → N n → N (m * n)
*-N {n = n} nzero Nn = subst N (sym (*-leftZero n)) nzero
*-N {n = n} (nsucc {m} Nm) Nn = subst N (sym (*-Sx m n)) (+-N Nn (*-N Nm Nn))
*-leftIdentity : ∀ {n} → N n → 1' * n ≡ n
*-leftIdentity {n} Nn =
1' * n ≡⟨ *-Sx zero n ⟩
n + zero * n ≡⟨ +-rightCong (*-leftZero n) ⟩
n + zero ≡⟨ +-rightIdentity Nn ⟩
n ∎
x*Sy≡x+xy : ∀ {m n} → N m → N n → m * succ₁ n ≡ m + m * n
x*Sy≡x+xy {n = n} nzero Nn = sym
(
zero + zero * n ≡⟨ +-rightCong (*-leftZero n) ⟩
zero + zero ≡⟨ +-leftIdentity zero ⟩
zero ≡⟨ sym (*-leftZero (succ₁ n)) ⟩
zero * succ₁ n ∎
)
x*Sy≡x+xy {n = n} (nsucc {m} Nm) Nn =
succ₁ m * succ₁ n
≡⟨ *-Sx m (succ₁ n) ⟩
succ₁ n + m * succ₁ n
≡⟨ +-rightCong (x*Sy≡x+xy Nm Nn) ⟩
succ₁ n + (m + m * n)
≡⟨ +-Sx n (m + m * n) ⟩
succ₁ (n + (m + m * n))
≡⟨ succCong (sym (+-assoc Nn m (m * n))) ⟩
succ₁ (n + m + m * n)
≡⟨ succCong (+-leftCong (+-comm Nn Nm)) ⟩
succ₁ (m + n + m * n)
≡⟨ succCong (+-assoc Nm n (m * n)) ⟩
succ₁ (m + (n + m * n))
≡⟨ sym (+-Sx m (n + m * n)) ⟩
succ₁ m + (n + m * n)
≡⟨ +-rightCong (sym (*-Sx m n)) ⟩
succ₁ m + succ₁ m * n ∎
*-comm : ∀ {m n} → N m → N n → m * n ≡ n * m
*-comm {n = n} nzero Nn = trans (*-leftZero n) (sym (*-rightZero Nn))
*-comm {n = n} (nsucc {m} Nm) Nn =
succ₁ m * n ≡⟨ *-Sx m n ⟩
n + m * n ≡⟨ +-rightCong (*-comm Nm Nn) ⟩
n + n * m ≡⟨ sym (x*Sy≡x+xy Nn Nm) ⟩
n * succ₁ m ∎
*-rightIdentity : ∀ {n} → N n → n * 1' ≡ n
*-rightIdentity {n} Nn = trans (*-comm Nn (nsucc nzero)) (*-leftIdentity Nn)
*∸-leftDistributive : ∀ {m n o} → N m → N n → N o → (m ∸ n) * o ≡ m * o ∸ n * o
*∸-leftDistributive {m} {o = o} _ nzero _ =
(m ∸ zero) * o ≡⟨ *-leftCong (∸-x0 m) ⟩
m * o ≡⟨ sym (∸-x0 (m * o)) ⟩
m * o ∸ zero ≡⟨ ∸-rightCong (sym (*-leftZero o)) ⟩
m * o ∸ zero * o ∎
*∸-leftDistributive {o = o} nzero (nsucc {n} Nn) No =
(zero ∸ succ₁ n) * o ≡⟨ *-leftCong (0∸x (nsucc Nn)) ⟩
zero * o ≡⟨ *-leftZero o ⟩
zero ≡⟨ sym (0∸x (*-N (nsucc Nn) No)) ⟩
zero ∸ succ₁ n * o ≡⟨ ∸-leftCong (sym (*-leftZero o)) ⟩
zero * o ∸ succ₁ n * o ∎
*∸-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) nzero =
(succ₁ m ∸ succ₁ n) * zero
≡⟨ *-comm (∸-N (nsucc Nm) (nsucc Nn)) nzero ⟩
zero * (succ₁ m ∸ succ₁ n)
≡⟨ *-leftZero (succ₁ m ∸ succ₁ n) ⟩
zero
≡⟨ sym (0∸x (*-N (nsucc Nn) nzero)) ⟩
zero ∸ succ₁ n * zero
≡⟨ ∸-leftCong (sym (*-leftZero (succ₁ m))) ⟩
zero * succ₁ m ∸ succ₁ n * zero
≡⟨ ∸-leftCong (*-comm nzero (nsucc Nm)) ⟩
succ₁ m * zero ∸ succ₁ n * zero ∎
*∸-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) =
(succ₁ m ∸ succ₁ n) * succ₁ o
≡⟨ *-leftCong (S∸S Nm Nn) ⟩
(m ∸ n) * succ₁ o
≡⟨ *∸-leftDistributive Nm Nn (nsucc No) ⟩
m * succ₁ o ∸ n * succ₁ o
≡⟨ sym ([x+y]∸[x+z]≡y∸z (nsucc No) (*-N Nm (nsucc No)) (*-N Nn (nsucc No))) ⟩
(succ₁ o + m * succ₁ o) ∸ (succ₁ o + n * succ₁ o)
≡⟨ ∸-leftCong (sym (*-Sx m (succ₁ o))) ⟩
(succ₁ m * succ₁ o) ∸ (succ₁ o + n * succ₁ o)
≡⟨ ∸-rightCong (sym (*-Sx n (succ₁ o))) ⟩
(succ₁ m * succ₁ o) ∸ (succ₁ n * succ₁ o) ∎
*+-leftDistributive : ∀ {m n o} → N m → N n → N o → (m + n) * o ≡ m * o + n * o
*+-leftDistributive {m} {n} Nm Nn nzero =
(m + n) * zero
≡⟨ *-comm (+-N Nm Nn) nzero ⟩
zero * (m + n)
≡⟨ *-leftZero (m + n) ⟩
zero
≡⟨ sym (*-leftZero m) ⟩
zero * m
≡⟨ *-comm nzero Nm ⟩
m * zero
≡⟨ sym (+-rightIdentity (*-N Nm nzero)) ⟩
m * zero + zero
≡⟨ +-rightCong (trans (sym (*-leftZero n)) (*-comm nzero Nn)) ⟩
m * zero + n * zero ∎
*+-leftDistributive {n = n} nzero Nn (nsucc {o} No) =
(zero + n) * succ₁ o ≡⟨ *-leftCong (+-leftIdentity n) ⟩
n * succ₁ o ≡⟨ sym (+-leftIdentity (n * succ₁ o)) ⟩
zero + n * succ₁ o ≡⟨ +-leftCong (sym (*-leftZero (succ₁ o))) ⟩
zero * succ₁ o + n * succ₁ o ∎
*+-leftDistributive (nsucc {m} Nm) nzero (nsucc {o} No) =
(succ₁ m + zero) * succ₁ o
≡⟨ *-leftCong (+-rightIdentity (nsucc Nm)) ⟩
succ₁ m * succ₁ o
≡⟨ sym (+-rightIdentity (*-N (nsucc Nm) (nsucc No))) ⟩
succ₁ m * succ₁ o + zero
≡⟨ +-rightCong (sym (*-leftZero (succ₁ o))) ⟩
succ₁ m * succ₁ o + zero * succ₁ o ∎
*+-leftDistributive (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) =
(succ₁ m + succ₁ n) * succ₁ o
≡⟨ *-leftCong (+-Sx m (succ₁ n)) ⟩
succ₁ (m + succ₁ n) * succ₁ o
≡⟨ *-Sx (m + succ₁ n) (succ₁ o) ⟩
succ₁ o + (m + succ₁ n) * succ₁ o
≡⟨ +-rightCong (*+-leftDistributive Nm (nsucc Nn) (nsucc No)) ⟩
succ₁ o + (m * succ₁ o + succ₁ n * succ₁ o)
≡⟨ sym (+-assoc (nsucc No) (m * succ₁ o) (succ₁ n * succ₁ o)) ⟩
succ₁ o + m * succ₁ o + succ₁ n * succ₁ o
≡⟨ +-leftCong (sym (*-Sx m (succ₁ o))) ⟩
succ₁ m * succ₁ o + succ₁ n * succ₁ o ∎
xy≡0→x≡0∨y≡0 : ∀ {m n} → N m → N n → m * n ≡ zero → m ≡ zero ∨ n ≡ zero
xy≡0→x≡0∨y≡0 nzero _ _ = inj₁ refl
xy≡0→x≡0∨y≡0 (nsucc Nm) nzero _ = inj₂ refl
xy≡0→x≡0∨y≡0 (nsucc {m} Nm) (nsucc {n} Nn) SmSn≡0 = ⊥-elim (0≢S prf)
where
prf : zero ≡ succ₁ (n + m * succ₁ n)
prf = zero ≡⟨ sym SmSn≡0 ⟩
succ₁ m * succ₁ n ≡⟨ *-Sx m (succ₁ n) ⟩
succ₁ n + m * succ₁ n ≡⟨ +-Sx n (m * succ₁ n) ⟩
succ₁ (n + m * succ₁ n) ∎
xy≡1→x≡1 : ∀ {m n} → N m → N n → m * n ≡ 1' → m ≡ 1'
xy≡1→x≡1 {n = n} nzero Nn h = ⊥-elim (0≢S (trans (sym (*-leftZero n)) h))
xy≡1→x≡1 (nsucc nzero) Nn h = refl
xy≡1→x≡1 (nsucc (nsucc {m} Nm)) nzero h =
⊥-elim (0≢S (trans (sym (*-rightZero (nsucc (nsucc Nm)))) h))
xy≡1→x≡1 (nsucc (nsucc {m} Nm)) (nsucc {n} Nn) h = ⊥-elim (0≢S prf₂)
where
prf₁ : 1' ≡ succ₁ (succ₁ (m + n * succ₁ (succ₁ m)))
prf₁ = 1'
≡⟨ sym h ⟩
succ₁ (succ₁ m) * succ₁ n
≡⟨ *-comm (nsucc (nsucc Nm)) (nsucc Nn) ⟩
succ₁ n * succ₁ (succ₁ m)
≡⟨ *-Sx n (succ₁ (succ₁ m)) ⟩
succ₁ (succ₁ m) + n * succ₁ (succ₁ m)
≡⟨ +-Sx (succ₁ m) (n * succ₁ (succ₁ m)) ⟩
succ₁ (succ₁ m + n * succ₁ (succ₁ m))
≡⟨ succCong (+-Sx m (n * succ₁ (succ₁ m))) ⟩
succ₁ (succ₁ (m + n * succ₁ (succ₁ m))) ∎
prf₂ : zero ≡ succ₁ (m + n * succ₁ (succ₁ m))
prf₂ = succInjective prf₁
xy≡1→y≡1 : ∀ {m n} → N m → N n → m * n ≡ 1' → n ≡ 1'
xy≡1→y≡1 Nm Nn h = xy≡1→x≡1 Nn Nm (trans (*-comm Nn Nm) h)
-- Feferman's axiom as presented by (Beeson 1986, p. 74).
succOnto : ∀ {n} → N n → n ≢ zero → succ₁ (pred₁ n) ≡ n
succOnto nzero h = ⊥-elim (h refl)
succOnto (nsucc {n} Nn) h = succCong (pred-S n)
------------------------------------------------------------------------------
-- References
--
-- Beeson, M. J. (1986). Proving Programs and Programming Proofs. In:
-- Logic, Methodology and Philosophy of Science VII (1983). Ed. by
-- Barcan Marcus, Ruth, Dorn, George J. W. and Weingartner,
-- Paul. Vol. 114. Studies in Logic and the Foundations of
-- Mathematics. Elsevier, pp. 51–82.
| {
"alphanum_fraction": 0.4656471125,
"avg_line_length": 35.8119891008,
"ext": "agda",
"hexsha": "8b7c4b048c6a7e5f47f94f408bb505d086a2bbb0",
"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/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Nat/PropertiesI.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/FOTC/Data/Nat/PropertiesI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 6314,
"size": 13143
} |
module datatype-util where
open import constants
open import ctxt
open import syntax-util
open import general-util
open import type-util
open import cedille-types
open import subst
open import rename
open import free-vars
{-# TERMINATING #-}
decompose-arrows : ctxt → type → params × type
decompose-arrows Γ (TpAbs me x atk T) =
let x' = fresh-var-new Γ x in
case decompose-arrows (ctxt-var-decl x' Γ) (rename-var Γ x x' T) of λ where
(ps , T') → Param me x' atk :: ps , T'
decompose-arrows Γ T = [] , T
decompose-ctr-type : ctxt → type → type × params × 𝕃 tmtp
decompose-ctr-type Γ T with decompose-arrows Γ T
...| ps , Tᵣ with decompose-tpapps Tᵣ
...| Tₕ , as = Tₕ , ps , as
{-# TERMINATING #-}
kind-to-indices : ctxt → kind → indices
kind-to-indices Γ (KdAbs x atk k) =
let x' = fresh-var-new Γ x in
Index x' atk :: kind-to-indices (ctxt-var-decl x' Γ) (rename-var Γ x x' k)
kind-to-indices Γ _ = []
rename-indices-h : ctxt → renamectxt → indices → 𝕃 tmtp → indices
rename-indices-h Γ ρ (Index x atk :: is) (ty :: tys) =
Index x' atk' ::
rename-indices-h (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') is tys
where
x' = fresh-var-renamectxt Γ ρ (maybe-else x id (is-var-unqual ty))
atk' = subst-renamectxt Γ ρ -tk atk
rename-indices-h Γ ρ (Index x atk :: is) [] =
let x' = fresh-var-renamectxt Γ ρ x in
Index x' (subst-renamectxt Γ ρ -tk atk) ::
rename-indices-h (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') is []
rename-indices-h _ _ [] _ = []
rename-indices : ctxt → indices → 𝕃 tmtp → indices
rename-indices Γ = rename-indices-h Γ empty-renamectxt
positivity : Set
positivity = 𝔹 × 𝔹 -- occurs positively × occurs negatively
pattern occurs-nil = ff , ff
pattern occurs-pos = tt , ff
pattern occurs-neg = ff , tt
pattern occurs-all = tt , tt
--positivity-inc : positivity → positivity
--positivity-dec : positivity → positivity
positivity-neg : positivity → positivity
positivity-add : positivity → positivity → positivity
--positivity-inc = map-fst λ _ → tt
--positivity-dec = map-snd λ _ → tt
positivity-neg = uncurry $ flip _,_
positivity-add (+ₘ , -ₘ) (+ₙ , -ₙ) = (+ₘ || +ₙ) , (-ₘ || -ₙ)
data ctorCheckT : Set where
ctorOk : ctorCheckT
ctorNotInReturnType : ctorCheckT
ctorNegative : ctorCheckT
posₒ = fst
negₒ = snd
occurs : positivity → ctorCheckT
occurs p = if (negₒ p) then ctorNegative else ctorOk
or-ctorCheckT : ctorCheckT → ctorCheckT → ctorCheckT
or-ctorCheckT ctorOk r = r
or-ctorCheckT ctorNegative _ = ctorNegative
or-ctorCheckT ctorNotInReturnType _ = ctorNotInReturnType
posM : Set → Set
posM A = 𝕃 tpkd → A × 𝕃 tpkd
run-posM : ∀{A : Set} → posM A → A × 𝕃 tpkd
run-posM p = p []
extract-pos : ∀{A : Set} → posM A → A
extract-pos = fst ∘ run-posM
instance
posM-monad : monad posM
return ⦃ posM-monad ⦄ a = λ l → a , l
_>>=_ ⦃ posM-monad ⦄ p ap l with p l
_>>=_ ⦃ posM-monad ⦄ p ap l | a , l' = ap a l'
posM-functor : functor posM
fmap ⦃ posM-functor ⦄ g m l with m l
fmap ⦃ posM-functor ⦄ g m l | a , l' = g a , l'
posM-applicative : applicative posM
pure ⦃ posM-applicative ⦄ = return
_<*>_ ⦃ posM-applicative ⦄ mab ma l with mab l
_<*>_ ⦃ posM-applicative ⦄ mab ma l | f , l' with ma l'
_<*>_ ⦃ posM-applicative ⦄ mab ma l | f , l' | a , l'' =
f a , l''
add-posM : tpkd → posM ⊤
add-posM x = λ l → triv , x :: l
module positivity (x : var) where
open import conversion
if-free : ∀ {ed} → ⟦ ed ⟧ → positivity
if-free t with is-free-in x t
...| f = f , f
if-free-args : args → positivity
if-free-args as =
let c = stringset-contains (free-vars-args as) x in c , c
hnf' : ∀ {ed} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
hnf' Γ T = hnf Γ unfold-no-defs T
mtt = maybe-else tt id
mff = maybe-else ff id
{-# TERMINATING #-}
type+ : ctxt → type → posM positivity
kind+ : ctxt → kind → posM positivity
tpkd+ : ctxt → tpkd → posM positivity
tpapp+ : ctxt → type → posM positivity
type+h : ctxt → type → posM positivity
kind+h : ctxt → kind → posM positivity
tpkd+h : ctxt → tpkd → posM positivity
tpapp+h : ctxt → type → posM positivity
type+ Γ T = type+h Γ T -- >>= λ p → add-posM (Tkt T) >> return p
kind+ Γ k = kind+h Γ k
tpkd+ Γ x = tpkd+h Γ x
tpapp+ Γ T = tpapp+h Γ T
type+h Γ (TpAbs me x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
pure positivity-add <*>
(fmap positivity-neg $ tpkd+ Γ $ hnf' Γ -tk atk) <*>
(type+ Γ' $ hnf' Γ' T)
type+h Γ (TpIota x' T T') =
let Γ' = ctxt-var-decl x' Γ in
pure positivity-add <*>
(type+ Γ $ hnf' Γ T) <*>
(type+ Γ' $ hnf' Γ' T')
type+h Γ (TpApp T tT) = tpapp+ Γ $ hnf' Γ $ TpApp T tT
type+h Γ (TpEq tₗ tᵣ) = pure occurs-nil
type+h Γ (TpHole _) = pure occurs-nil
type+h Γ (TpLam x' atk T)=
let Γ' = ctxt-var-decl x' Γ in
pure positivity-add <*>
(fmap positivity-neg $ tpkd+ Γ $ hnf' Γ -tk atk) <*>
(type+ Γ' (hnf' Γ' T))
type+h Γ (TpVar x') = pure $ x =string x' , ff
kind+h Γ (KdAbs x' atk k) =
let Γ' = ctxt-var-decl x' Γ in
pure positivity-add <*>
(fmap positivity-neg $ tpkd+ Γ $ hnf' Γ -tk atk) <*>
(kind+ Γ' k)
kind+h Γ _ = pure occurs-nil
tpkd+h Γ (Tkt T) = type+ Γ (hnf' Γ T)
tpkd+h Γ (Tkk k) = kind+ Γ k
tpapp+h Γ T with decompose-tpapps T
tpapp+h Γ T | TpVar x' , as =
let f = if-free-args (tmtps-to-args NotErased as) in
if x =string x'
then pure (positivity-add occurs-pos f)
else maybe-else' (data-lookup Γ x' as) (pure f)
λ {(mk-data-info x'' xₒ'' asₚ asᵢ ps kᵢ k cs csₚₛ eds gds) →
let s = (inst-type Γ ps asₚ (hnf' Γ $ TpAbs tt x'' (Tkk k) $ foldr (uncurry λ cₓ cₜ → TpAbs ff ignored-var (Tkt cₜ)) (TpVar x'') cs)) in
add-posM (Tkt s) >>
type+ Γ s }
tpapp+h Γ T | _ , _ = pure $ if-free T
{-# TERMINATING #-}
arrs+ : ctxt → type → posM ctorCheckT
arrs+ Γ (TpAbs me x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
pure or-ctorCheckT <*>
(fmap occurs (tpkd+ Γ $ hnf' Γ -tk atk)) <*>
(arrs+ Γ' (hnf' Γ' T))
arrs+ Γ (TpApp T tT) = fmap occurs (tpapp+ Γ $ hnf' Γ (TpApp T tT))
arrs+ Γ (TpLam x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
pure or-ctorCheckT <*>
(fmap occurs (tpkd+ Γ $ hnf' Γ -tk atk)) <*>
(arrs+ Γ' (hnf' Γ' T))
arrs+ Γ (TpVar x') = return $ if (x =string x') then ctorOk else ctorNotInReturnType
arrs+ _ _ = return ctorNegative
ctr-positive : ctxt → type → posM ctorCheckT
ctr-positive Γ = (arrs+ Γ ∘ hnf' Γ)
-- build the evidence for a sigma-term, given datatype X with associated info μ
sigma-build-evidence : var → datatype-info → term
sigma-build-evidence X μ =
if datatype-info.name μ =string X then recompose-apps (datatype-info.asₚ μ) (Var (data-is/ X)) else Var (mu-isType/' X)
| {
"alphanum_fraction": 0.6118586426,
"avg_line_length": 31.9009433962,
"ext": "agda",
"hexsha": "61b9033ed6e1ebdd4ef0bd942164b82d6632bc85",
"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": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ice1k/cedille",
"max_forks_repo_path": "src/datatype-util.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"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": "ice1k/cedille",
"max_issues_repo_path": "src/datatype-util.agda",
"max_line_length": 146,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ice1k/cedille",
"max_stars_repo_path": "src/datatype-util.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2500,
"size": 6763
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Ring.DirectProd where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring.Base
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
module _
(A'@(A , Ar) : Ring ℓ)
(B'@(B , Br) : Ring ℓ')
where
open RingStr Ar using ()
renaming
( 0r to 0A
; 1r to 1A
; _+_ to _+A_
; -_ to -A_
; _·_ to _·A_
; +Assoc to +AAssoc
; +IdR to +AIdR
; +IdL to +AIdL
; +InvR to +AInvR
; +InvL to +AInvL
; +Comm to +AComm
; ·Assoc to ·AAssoc
; ·IdL to ·AIdL
; ·IdR to ·AIdR
; ·DistR+ to ·ADistR+
; ·DistL+ to ·ADistL+
; is-set to isSetA )
open RingStr Br using ()
renaming
( 0r to 0B
; 1r to 1B
; _+_ to _+B_
; -_ to -B_
; _·_ to _·B_
; +Assoc to +BAssoc
; +IdR to +BIdR
; +IdL to +BIdL
; +InvR to +BInvR
; +InvL to +BInvL
; +Comm to +BComm
; ·Assoc to ·BAssoc
; ·IdL to ·BIdL
; ·IdR to ·BIdR
; ·DistR+ to ·BDistR+
; ·DistL+ to ·BDistL+
; is-set to isSetB )
DirectProd-Ring : Ring (ℓ-max ℓ ℓ')
fst DirectProd-Ring = A × B
RingStr.0r (snd DirectProd-Ring) = 0A , 0B
RingStr.1r (snd DirectProd-Ring) = 1A , 1B
(snd DirectProd-Ring RingStr.+ (a , b)) (a' , b') = (a +A a') , (b +B b')
(snd DirectProd-Ring RingStr.· (a , b)) (a' , b') = (a ·A a') , (b ·B b')
(RingStr.- snd DirectProd-Ring) (a , b) = (-A a) , (-B b)
RingStr.isRing (snd DirectProd-Ring) =
makeIsRing (isSet× isSetA isSetB)
(λ x y z i → +AAssoc (fst x) (fst y) (fst z) i , +BAssoc (snd x) (snd y) (snd z) i)
(λ x i → (+AIdR (fst x) i) , (+BIdR (snd x) i))
(λ x i → (+AInvR (fst x) i) , +BInvR (snd x) i)
(λ x y i → (+AComm (fst x) (fst y) i) , (+BComm (snd x) (snd y) i))
(λ x y z i → (·AAssoc (fst x) (fst y) (fst z) i) , (·BAssoc (snd x) (snd y) (snd z) i))
(λ x i → (·AIdR (fst x) i) , (·BIdR (snd x) i))
(λ x i → (·AIdL (fst x) i) , (·BIdL (snd x) i))
(λ x y z i → (·ADistR+ (fst x) (fst y) (fst z) i) , (·BDistR+ (snd x) (snd y) (snd z) i))
(λ x y z i → (·ADistL+ (fst x) (fst y) (fst z) i) , (·BDistL+ (snd x) (snd y) (snd z) i))
module Coproduct-Equiv
{Xr@(X , Xstr) : Ring ℓ}
{Yr@(Y , Ystr) : Ring ℓ'}
{X'r@(X' , X'str) : Ring ℓ''}
{Y'r@(Y' , Y'str) : Ring ℓ'''}
where
open Iso
open IsRingHom
open RingStr
_+X×X'_ : X × X' → X × X' → X × X'
_+X×X'_ = _+_ (snd (DirectProd-Ring Xr X'r))
_+Y×Y'_ : Y × Y' → Y × Y' → Y × Y'
_+Y×Y'_ = _+_ (snd (DirectProd-Ring Yr Y'r))
_·X×X'_ : X × X' → X × X' → X × X'
_·X×X'_ = _·_ (snd (DirectProd-Ring Xr X'r))
_·Y×Y'_ : Y × Y' → Y × Y' → Y × Y'
_·Y×Y'_ = _·_ (snd (DirectProd-Ring Yr Y'r))
re×re' : (re : RingEquiv Xr Yr) → (re' : RingEquiv X'r Y'r) → (X × X') ≃ (Y × Y')
re×re' re re' = ≃-× (fst re) (fst re')
Coproduct-Equiv-12 : (re : RingEquiv Xr Yr) → (re' : RingEquiv X'r Y'r) →
RingEquiv (DirectProd-Ring Xr X'r) (DirectProd-Ring Yr Y'r)
fst (Coproduct-Equiv-12 re re') = re×re' re re'
snd (Coproduct-Equiv-12 re re') = makeIsRingHom fun-pres1 fun-pres+ fun-pres·
where
fun-pres1 : (fst (re×re' re re')) (1r Xstr , 1r X'str) ≡ (1r (Yr .snd) , 1r (Y'r .snd))
fun-pres1 = ≡-× (pres1 (snd re)) (pres1 (snd re'))
fun-pres+ : (x1 x2 : X × X') → (fst (re×re' re re')) (x1 +X×X' x2) ≡ (( (fst (re×re' re re')) x1) +Y×Y' ( (fst (re×re' re re')) x2))
fun-pres+ (x1 , x'1) (x2 , x'2) = ≡-× (pres+ (snd re) x1 x2) (pres+ (snd re') x'1 x'2)
fun-pres· : (x1 x2 : X × X') → (fst (re×re' re re')) (x1 ·X×X' x2) ≡ (( (fst (re×re' re re')) x1) ·Y×Y' ( (fst (re×re' re re')) x2))
fun-pres· (x1 , x'1) (x2 , x'2) = ≡-× (pres· (snd re) x1 x2) (pres· (snd re') x'1 x'2)
| {
"alphanum_fraction": 0.495412844,
"avg_line_length": 34.1779661017,
"ext": "agda",
"hexsha": "56ec50b91408939872b6dce0b59b274f88a09253",
"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/Algebra/Ring/DirectProd.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/Algebra/Ring/DirectProd.agda",
"max_line_length": 136,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/Ring/DirectProd.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1819,
"size": 4033
} |
module Issue213 where
postulate
Prod : Set → Set → Set
A : Set
Foo : Set
Foo = let infixr 3 _×_
_×_ : Set → Set → Set
_×_ = Prod
in A × A × A
| {
"alphanum_fraction": 0.4943820225,
"avg_line_length": 13.6923076923,
"ext": "agda",
"hexsha": "86ac4df98cfa6b647111c90ad59564089ed3217a",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue213.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue213.agda",
"max_line_length": 31,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue213.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 64,
"size": 178
} |
module Categories.Functor.Construction.Product where
open import Categories.Category
open import Categories.Category.Cartesian
open import Categories.Category.BinaryProducts
open import Categories.Functor.Bifunctor
open import Data.Product using (_,_)
module _ {o ℓ e} (𝒞 : Category o ℓ e) (cartesian : Cartesian 𝒞) where
open Cartesian cartesian
open BinaryProducts products
open Category 𝒞
Product : Bifunctor 𝒞 𝒞 𝒞
Product = record
{ F₀ = λ (x , y) → x × y
; F₁ = λ (f , g) → f ⁂ g
; identity = Equiv.trans (⟨⟩-cong₂ identityˡ identityˡ) η
; homomorphism = Equiv.sym ⁂∘⁂
; F-resp-≈ = λ (x , y) → ⁂-cong₂ x y
}
| {
"alphanum_fraction": 0.6292134831,
"avg_line_length": 29.6666666667,
"ext": "agda",
"hexsha": "9eb90f241ad0820219201e5fae999c8fc79b59c9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Categories/Functor/Construction/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "elpinal/exsub-ccc",
"max_issues_repo_path": "Categories/Functor/Construction/Product.agda",
"max_line_length": 71,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Categories/Functor/Construction/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 219,
"size": 712
} |
{-# OPTIONS --allow-unsolved-metas #-} -- FIXME
open import Everything
module Test.Test3 where
module _
{𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂}
where
postulate instance functor : Functor 𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂
open Functor ⦃ … ⦄
test : asInstance `IsFunctor $ {!Transextensionality!.type _∼₁_ _∼̇₁_!}
test = asInstance `IsFunctor transextensionality
-- -- Test1.test-functor-transextensionality
| {
"alphanum_fraction": 0.6873449132,
"avg_line_length": 26.8666666667,
"ext": "agda",
"hexsha": "05c980053c952572f107b04e82f85807708a116a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Test/Test3.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Test/Test3.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Test/Test3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 158,
"size": 403
} |
{-# OPTIONS --type-in-type #-}
module Record where
open import Prelude
record Sigma (A : Set)(B : A -> Set) : Set
record Sigma A B where
constructor pair
field
fst : A
snd : B fst
open Sigma
data Unit : Set
data Unit where
tt : Unit
Cat : Set
Cat =
Sigma Set (\ Obj ->
Sigma (Obj -> Obj -> Set) (\ Hom ->
Sigma ((X : _) -> Hom X X) (\ id ->
Sigma ((X Y Z : _) -> Hom Y Z -> Hom X Y -> Hom X Z) (\ comp ->
Sigma ((X Y : _)(f : Hom X Y) -> comp _ _ _ (id Y) f == f) (\ idl ->
Sigma ((X Y : _)(f : Hom X Y) -> comp _ _ _ f (id X) == f) (\ idr ->
Sigma ((W X Y Z : _)
(f : Hom W X)(g : Hom X Y)(h : Hom Y Z) ->
comp _ _ _ (comp _ _ _ h g) f ==
comp _ _ _ h (comp _ _ _ g f)) (\ assoc ->
Unit)))))))
Obj : (C : Cat) -> Set
Obj C = fst C
Hom : (C : Cat) -> Obj C -> Obj C -> Set
Hom C = fst (snd C)
id : (C : Cat) -> (X : _) -> Hom C X X
id C = fst (snd (snd C))
comp : (C : Cat) -> (X Y Z : _) -> Hom C Y Z -> Hom C X Y -> Hom C X Z
comp C = fst (snd (snd (snd C)))
idl : (C : Cat) -> (X Y : _)(f : Hom C X Y) ->
comp C _ _ _ (id C Y) f == f
idl C = fst (snd (snd (snd (snd C))))
idr : (C : Cat) -> (X Y : _)(f : Hom C X Y) ->
comp C _ _ _ f (id C X) == f
idr C = fst (snd (snd (snd (snd (snd C)))))
assoc : (C : Cat) ->
(W X Y Z : _) (f : Hom C W X)(g : Hom C X Y)(h : Hom C Y Z) ->
comp C _ _ _ (comp C _ _ _ h g) f ==
comp C _ _ _ h (comp C _ _ _ g f)
assoc C = fst (snd (snd (snd (snd (snd (snd C))))))
| {
"alphanum_fraction": 0.423030303,
"avg_line_length": 28.4482758621,
"ext": "agda",
"hexsha": "e1dd10f5c29cdbebdfefa96061db49560f993689",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "src/prototyping/term/examples/Record.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "src/prototyping/term/examples/Record.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "src/prototyping/term/examples/Record.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 576,
"size": 1650
} |
-- By Philipp Hausmann.
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Agda.Builtin.Float
data ⊥ : Set where
_/_ = primFloatDiv
_<_ = primFloatNumericalLess
cong : {A B : Set} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
0eq : 0.0 ≡ -0.0
0eq = refl
bug : ⊥
bug = f (cong (λ x → (1.0 / x) < 0.0) 0eq)
where
f : false ≡ true → ⊥
f ()
| {
"alphanum_fraction": 0.5888324873,
"avg_line_length": 16.4166666667,
"ext": "agda",
"hexsha": "5371388c8a861cba9170149414fe7fb279fbe078",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2169.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue2169.agda",
"max_line_length": 60,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue2169.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 165,
"size": 394
} |
module Data.BinaryTree.Properties where
import Lvl
open import Data hiding (empty)
open import Data.BinaryTree
open import Data.Boolean
open import Functional as Fn
open import Logic.Propositional
open import Numeral.Natural
open import Type
private variable ℓ ℓᵢ ℓₗ ℓₙ ℓₒ : Lvl.Level
private variable n : ℕ
private variable N N₁ N₂ L T A B : Type{ℓ}
-- A tree is full when every node has no or all children.
data Full {L : Type{ℓₗ}}{N : Type{ℓₙ}} : BinaryTree L N → Type{ℓₗ Lvl.⊔ ℓₙ} where
leaf : ∀{l} → Full(Leaf l)
single : ∀{a}{l₁ l₂} → Full(Node a (Leaf l₁) (Leaf l₂))
step : ∀{al ar a}{cll clr crl crr} → Full(Node al cll clr) → Full(Node ar crl crr) → Full(Node a (Node al cll clr) (Node ar crl crr))
-- A tree is perfect at depth `n` when all leaves are at height `n`.
-- In other words, a tree is perfect when all leaves are at the same height.
data Perfect {L : Type{ℓₗ}}{N : Type{ℓₙ}} : BinaryTree L N → ℕ → Type{ℓₗ Lvl.⊔ ℓₙ} where
leaf : ∀{l} → Perfect(Leaf l)(𝟎)
step : ∀{a}{l r}{h} → Perfect(l)(h) → Perfect(r)(h) → Perfect(Node a l r)(𝐒(h))
data Complete {L : Type{ℓₗ}}{N : Type{ℓₙ}} : BinaryTree L N → ℕ → Bool → Type{ℓₗ Lvl.⊔ ℓₙ} where
perfect-leaf : ∀{l} → Complete(Leaf l)(𝟎)(𝑇)
imperfect-leaf : ∀{l} → Complete(Leaf l)(𝐒(𝟎))(𝐹)
step₀ : ∀{a}{l r}{h} → Complete(l)(h)(𝐹) → Complete(r)(h)(𝐹) → Complete(Node a l r)(𝐒(h))(𝐹)
step₁ : ∀{a}{l r}{h} → Complete(l)(h)(𝑇) → Complete(r)(h)(𝐹) → Complete(Node a l r)(𝐒(h))(𝐹)
step₂ : ∀{a}{l r}{h} → Complete(l)(h)(𝑇) → Complete(r)(h)(𝑇) → Complete(Node a l r)(𝐒(h))(𝑇)
data DepthOrdered {L : Type{ℓₗ}}{N : Type{ℓₙ}} (_≤_ : N → N → Type{ℓₒ}) : BinaryTree L N → Type{ℓₗ Lvl.⊔ ℓₙ Lvl.⊔ ℓₒ} where
leaf : ∀{l} → DepthOrdered(_≤_)(Leaf l)
step : ∀{a}{l₁ l₂} → DepthOrdered(_≤_)(Node a (Leaf l₁) (Leaf l₂))
stepₗ : ∀{a al ar}{l}{rl rr} → (a ≤ al) → DepthOrdered(_≤_)(Node al rl rr)
→ DepthOrdered(_≤_)(Node a (Leaf l) (Node ar rl rr))
stepᵣ : ∀{a al ar}{l}{ll lr} → (a ≤ ar) → DepthOrdered(_≤_)(Node ar ll lr)
→ DepthOrdered(_≤_)(Node a (Node al ll lr) (Leaf l))
stepₗᵣ : ∀{a al ar}{ll lr rl rr} → (a ≤ al) → DepthOrdered(_≤_)(Node al ll lr)
→ (a ≤ ar) → DepthOrdered(_≤_)(Node ar rl rr)
→ DepthOrdered(_≤_)(Node a (Node al ll lr) (Node ar rl rr))
Heap : ∀{L : Type{ℓₗ}}{N : Type{ℓₙ}} → (N → N → Type{ℓₒ}) → BinaryTree L N → ℕ → Bool → Type
Heap(_≤_) tree height perfect = DepthOrdered(_≤_)(tree) ∧ Complete(tree)(height)(perfect)
| {
"alphanum_fraction": 0.5813323005,
"avg_line_length": 53.7916666667,
"ext": "agda",
"hexsha": "27cf4b9b3813e538f4e770a9b8b84702fdbcd4f4",
"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": "Data/BinaryTree/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/BinaryTree/Properties.agda",
"max_line_length": 137,
"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": "Data/BinaryTree/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1032,
"size": 2582
} |
record Unit : Set where
constructor unit
module S {A : Set} where
id : {A : Set} → A → A
id a = a
module T {A : Set} = S
Sid : (A : Set) → A → A
Sid A = S.id {A = Unit} {A = A}
Tid : (A : Set) → A → A
Tid A = T.id {A = Unit} {A = Unit} {A = A}
| {
"alphanum_fraction": 0.4862745098,
"avg_line_length": 15.9375,
"ext": "agda",
"hexsha": "5f969a3a00e42dfa7fb8faae77cd8c0e82ab91d6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2572.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2572.agda",
"max_line_length": 42,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2572.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 110,
"size": 255
} |
module trie-thms where
open import bool
open import bool-thms
open import bool-thms2
open import char
open import eq
open import list
open import list-thms
open import maybe
open import product
open import product-thms
open import sum
open import string
open import trie
trie-lookup-empty-h : ∀ {A} x → trie-lookup-h{A} empty-trie x ≡ nothing
trie-lookup-empty-h [] = refl
trie-lookup-empty-h (_ :: _) = refl
trie-lookup-empty : ∀ {A} x → trie-lookup{A} empty-trie x ≡ nothing
trie-lookup-empty x = trie-lookup-empty-h (string-to-𝕃char x)
trie-cal-insert-nonempty : ∀{A : Set}(ts : cal (trie A))(c : char)(t : trie A) → trie-nonempty t ≡ tt →
trie-cal-nonempty (cal-insert ts c t) ≡ tt
trie-cal-insert-nonempty [] c t p rewrite p = refl
trie-cal-insert-nonempty ((c , t') :: ts) c' t p with c' =char c
trie-cal-insert-nonempty ((c , t') :: ts) c' t p | tt rewrite p = refl
trie-cal-insert-nonempty ((c , t') :: ts) c' t p | ff rewrite (trie-cal-insert-nonempty ts c' t p) =
||-tt (trie-nonempty t')
trie-insert-h-nonempty : ∀{A : Set}(t : trie A)(cs : 𝕃 char)(a : A) → trie-nonempty (trie-insert-h t cs a) ≡ tt
trie-insert-h-nonempty (Node x x₁) [] a = refl
trie-insert-h-nonempty (Node x ts) (c :: cs) a with cal-lookup ts c
trie-insert-h-nonempty (Node (just x) ts) (c :: cs) a | just t = refl
trie-insert-h-nonempty (Node nothing ts) (c :: cs) a | just t =
trie-cal-insert-nonempty ts c (trie-insert-h t cs a) (trie-insert-h-nonempty t cs a)
trie-insert-h-nonempty (Node (just x) ts) (c :: cs) a | nothing = refl
trie-insert-h-nonempty (Node nothing ts) (c :: cs) a | nothing rewrite (trie-insert-h-nonempty empty-trie cs a) = refl
trie-insert-nonempty : ∀{A : Set}(t : trie A)(s : string)(a : A) → trie-nonempty (trie-insert t s a) ≡ tt
trie-insert-nonempty t s a = trie-insert-h-nonempty t (string-to-𝕃char s) a
trie-mappings-h-nonempty : ∀ {A : Set}(t : trie A)(prev-str : 𝕃 char) →
trie-nonempty t ≡ tt → is-empty (trie-mappings-h t prev-str) ≡ ff
trie-cal-mappings-h-nonempty : ∀ {A : Set}(ts : cal (trie A))(prev-str : 𝕃 char) →
trie-cal-nonempty ts ≡ tt → is-empty (trie-cal-mappings-h ts prev-str) ≡ ff
trie-mappings-h-nonempty (Node (just x) x₁) prev-str _ = refl
trie-mappings-h-nonempty (Node nothing ts) prev-str p = trie-cal-mappings-h-nonempty ts prev-str p
trie-cal-mappings-h-nonempty [] prev-str ()
trie-cal-mappings-h-nonempty ((a , t) :: ts) prev-str p rewrite is-empty-++ (trie-mappings-h t (a :: prev-str)) (trie-cal-mappings-h ts prev-str) with ||-elim{trie-nonempty t} p
trie-cal-mappings-h-nonempty ((a , t) :: ts) prev-str _ | inj₁ p rewrite trie-mappings-h-nonempty t (a :: prev-str) p = refl
trie-cal-mappings-h-nonempty ((a , t) :: ts) prev-str _ | inj₂ p rewrite trie-cal-mappings-h-nonempty ts prev-str p | &&-ff (is-empty (trie-mappings-h t (a :: prev-str))) = refl
trie-mappings-nonempty : ∀ {A : Set}(t : trie A) →
trie-nonempty t ≡ tt → is-empty (trie-mappings t) ≡ ff
trie-mappings-nonempty t p = trie-mappings-h-nonempty t [] p | {
"alphanum_fraction": 0.6449742268,
"avg_line_length": 53.5172413793,
"ext": "agda",
"hexsha": "96c9b72b236bde0caeebe9c7c915b697905a4385",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "trie-thms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "trie-thms.agda",
"max_line_length": 178,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "trie-thms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 976,
"size": 3104
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Level polymorphic Empty type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Empty.Polymorphic where
open import Level
data ⊥ {ℓ : Level} : Set ℓ where
⊥-elim : ∀ {w ℓ} {Whatever : Set w} → ⊥ {ℓ} → Whatever
⊥-elim ()
| {
"alphanum_fraction": 0.4029850746,
"avg_line_length": 23.6470588235,
"ext": "agda",
"hexsha": "6a37cbcc7518136b5b16ca890185d92ca099d363",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Empty/Polymorphic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Empty/Polymorphic.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Empty/Polymorphic.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 89,
"size": 402
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Functions.Definition
open import Fields.Fields
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Fields.Orders.Partial.Definition {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) where
open Ring R
record PartiallyOrderedField {p} {_<_ : Rel {_} {p} A} (pOrder : SetoidPartialOrder S _<_) : Set (lsuc (m ⊔ n ⊔ p)) where
field
oRing : PartiallyOrderedRing R pOrder
| {
"alphanum_fraction": 0.6926536732,
"avg_line_length": 35.1052631579,
"ext": "agda",
"hexsha": "2f657fd873efee8d1aa5e836d8beb1fd3755a41a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/Orders/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": "Fields/Orders/Partial/Definition.agda",
"max_line_length": 161,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/Orders/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": 212,
"size": 667
} |
{-# OPTIONS --cubical --safe #-}
open import Algebra
open import Relation.Binary
open import Algebra.Monus
module Data.MonoidalHeap {s} (monus : TMPOM s) where
open TMPOM monus
open import Prelude
open import Data.List using (List; _∷_; [])
import Data.Nat as ℕ
import Data.Nat.Properties as ℕ
𝒮 : Type s
𝒮 = 𝑆 → 𝑆
⟦_⇑⟧ : 𝑆 → 𝒮
⟦_⇑⟧ = _∙_
⟦_⇓⟧ : 𝒮 → 𝑆
⟦ x ⇓⟧ = x ε
infixl 10 _⊙_
_⊙_ : (𝑆 → A) → 𝑆 → 𝑆 → A
f ⊙ x = λ y → f (x ∙ y)
infixr 6 _∹_&_
data Heap (V : 𝑆 → Type a) : Type (a ℓ⊔ s) where
[] : Heap V
_∹_&_ : (key : 𝑆) (val : V key) (children : List (Heap (V ⊙ key))) → Heap V
Heap⋆ : (V : 𝑆 → Type a) → Type (a ℓ⊔ s)
Heap⋆ V = List (Heap V)
private
variable
v : Level
V : 𝑆 → Type v
⊙ε : V ≡ V ⊙ ε
⊙ε {V = V} i x = V (sym (ε∙ x) i)
lemma : ∀ x y k → x ≡ y ∙ k → ⟦ x ⇑⟧ ≡ ⟦ y ⇑⟧ ∘ ⟦ k ⇑⟧
lemma x y k x≡y∙k i z = (cong (_∙ z) x≡y∙k ; assoc y k z) i
merge : Heap V → Heap V → Heap V
merge [] ys = ys
merge (x ∹ xv & xs) [] = x ∹ xv & xs
merge {V = V} (x ∹ xv & xs) (y ∹ yv & ys) with x ≤|≥ y
... | inl (k , x≤y) = x ∹ xv & (k ∹ subst V x≤y yv & subst (List ∘ Heap ∘ _∘_ V) (lemma y x k x≤y) ys ∷ xs)
... | inr (k , x≥y) = y ∹ yv & (k ∹ subst V x≥y xv & subst (List ∘ Heap ∘ _∘_ V) (lemma x y k x≥y) xs ∷ ys)
mergeQs⁺ : Heap V → Heap⋆ V → Heap V
mergeQs⁺ x₁ [] = x₁
mergeQs⁺ x₁ (x₂ ∷ []) = merge x₁ x₂
mergeQs⁺ x₁ (x₂ ∷ x₃ ∷ xs) = merge (merge x₁ x₂) (mergeQs⁺ x₃ xs)
mergeQs : Heap⋆ V → Heap V
mergeQs [] = []
mergeQs (x ∷ xs) = mergeQs⁺ x xs
singleton : ∀ x → V x → Heap V
singleton x xv = x ∹ xv & []
insert : ∀ x → V x → Heap V → Heap V
insert x xv = merge (singleton x xv)
minView : Heap V → Maybe (∃ p × V p × Heap (V ⊙ p))
minView [] = nothing
minView (x ∹ xv & xs) = just (x , xv , mergeQs xs)
variable
v₁ v₂ : Level
V₁ : 𝑆 → Type v₁
V₂ : 𝑆 → Type v₂
mutual
maps : (∀ {x} → V₁ x → V₂ x) → Heap⋆ V₁ → Heap⋆ V₂
maps f [] = []
maps f (x ∷ xs) = map f x ∷ maps f xs
map : (∀ {x} → V₁ x → V₂ x) → Heap V₁ → Heap V₂
map f [] = []
map f (k ∹ v & xs) = k ∹ f v & maps f xs
mutual
size : Heap V → ℕ
size [] = zero
size (_ ∹ _ & xs) = suc (sizes xs)
sizes : Heap⋆ V → ℕ
sizes [] = 0
sizes (x ∷ xs) = size x ℕ.+ sizes xs
open import Data.Maybe using (maybe)
open import Path.Reasoning
open import Cubical.Foundations.Prelude using (substRefl)
lemma₂ : ∀ {x y : 𝑆 → 𝑆} xs (p : x ≡ y) → sizes (subst (List ∘ Heap ∘ _∘_ V) p xs) ≡ sizes xs
lemma₂ {V = V} xs = J (λ _ p → sizes (subst (List ∘ Heap ∘ _∘_ V) p xs) ≡ sizes xs) (cong sizes (substRefl {B = List ∘ Heap ∘ _∘_ V} xs))
merge-size : (xs ys : Heap V) → size (merge xs ys) ≡ size xs ℕ.+ size ys
merge-size [] ys = refl
merge-size (x ∹ xv & xs) [] = sym (ℕ.+-idʳ _)
merge-size {V = V} (x ∹ xv & xs) (y ∹ yv & ys) with x ≤|≥ y
merge-size {V = V} (x ∹ xv & xs) (y ∹ yv & ys) | inr (k , x≥y) =
suc (suc (sizes (subst (List ∘ Heap ∘ _∘_ V) (lemma x y k x≥y) xs)) ℕ.+ sizes ys) ≡˘⟨ ℕ.+-suc _ (sizes ys) ⟩
suc (sizes (subst (List ∘ Heap ∘ _∘_ V) (lemma x y k x≥y) xs)) ℕ.+ suc (sizes ys) ≡⟨ cong (ℕ._+ suc (sizes ys)) (cong suc (lemma₂ {V = V} xs (lemma x y k x≥y))) ⟩
suc (sizes xs) ℕ.+ suc (sizes ys) ∎
merge-size {V = V} (x ∹ xv & xs) (y ∹ yv & ys) | inl (k , x≤y) =
suc (suc (sizes (subst (List ∘ Heap ∘ _∘_ V) (lemma y x k x≤y) ys)) ℕ.+ sizes xs) ≡˘⟨ ℕ.+-suc _ (sizes xs) ⟩
suc (sizes (subst (List ∘ Heap ∘ _∘_ V) (lemma y x k x≤y) ys)) ℕ.+ suc (sizes xs) ≡⟨ cong (ℕ._+ suc (sizes xs)) (cong suc (lemma₂ {V = V} ys (lemma y x k x≤y))) ⟩
suc (sizes ys) ℕ.+ suc (sizes xs) ≡⟨ ℕ.+-comm (suc (sizes ys)) (suc (sizes xs)) ⟩
suc (sizes xs) ℕ.+ suc (sizes ys) ∎
mutual
minViewSizes : (xs : Heap⋆ V) → sizes xs ≡ size (mergeQs xs)
minViewSizes [] = refl
minViewSizes (x ∷ xs) = minViewSizes⁺ x xs
minViewSizes⁺ : (x : Heap V) → (xs : Heap⋆ V) → sizes (x ∷ xs) ≡ size (mergeQs⁺ x xs)
minViewSizes⁺ x₁ [] = ℕ.+-idʳ _
minViewSizes⁺ x₁ (x₂ ∷ []) = cong (λ z → size x₁ ℕ.+ z) (ℕ.+-idʳ _) ; sym (merge-size x₁ x₂)
minViewSizes⁺ x₁ (x₂ ∷ x₃ ∷ xs) =
size x₁ ℕ.+ (size x₂ ℕ.+ sizes (x₃ ∷ xs)) ≡˘⟨ ℕ.+-assoc (size x₁) (size x₂) (sizes (x₃ ∷ xs)) ⟩
(size x₁ ℕ.+ size x₂) ℕ.+ sizes (x₃ ∷ xs) ≡⟨ cong ((size x₁ ℕ.+ size x₂) ℕ.+_) (minViewSizes⁺ x₃ xs) ⟩
(size x₁ ℕ.+ size x₂) ℕ.+ size (mergeQs⁺ x₃ xs) ≡˘⟨ cong (ℕ._+ size (mergeQs⁺ x₃ xs)) (merge-size x₁ x₂) ⟩
size (merge x₁ x₂) ℕ.+ size (mergeQs⁺ x₃ xs) ≡˘⟨ merge-size (merge x₁ x₂) (mergeQs⁺ x₃ xs) ⟩
size (merge (merge x₁ x₂) (mergeQs⁺ x₃ xs)) ∎
minViewSize : (xs : Heap V) → size xs ≡ maybe zero (suc ∘ size ∘ snd ∘ snd) (minView xs)
minViewSize [] = refl
minViewSize (x ∹ xv & xs) = cong suc (minViewSizes xs)
zer : Heap⋆ V
zer = []
one : Heap⋆ V
one = [] ∷ []
open import Data.List using (_++_; concatMap)
_<+>_ : Heap⋆ V → Heap⋆ V → Heap⋆ V
_<+>_ = _++_
multIn : (p : 𝑆 → 𝑆) → (c : ∀ {x y} → V (p x) → V y → V (p (x ∙ y))) → (V ⇒ V ∘ p) → Heap⋆ (V ∘ p) → Heap⋆ V → Heap⋆ (V ∘ p)
multIn {V = V} p c f [] ys = []
multIn {V = V} p c f ([] ∷ xs) ys = maps f ys ++ multIn p c f xs ys
multIn {V = V} p c f (x ∹ xv & xc ∷ xs) ys = x ∹ xv & multIn (p ∘ ⟦ x ⇑⟧) (λ v₁ v₂ → subst V (cong p (assoc x _ _)) (c v₁ v₂)) (c xv) xc ys ∷ multIn p c f xs ys
appl : (∀ {x y} → V x → V y → V (x ∙ y)) → Heap⋆ V → Heap⋆ V → Heap⋆ V
appl {V = V} f xs ys = multIn {V = V} id f id xs ys
| {
"alphanum_fraction": 0.5301250474,
"avg_line_length": 33.8333333333,
"ext": "agda",
"hexsha": "0700fd0bced6aac8c7e6e1ea33898fc78bf19e05",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/MonoidalHeap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/MonoidalHeap.agda",
"max_line_length": 164,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/MonoidalHeap.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": 2553,
"size": 5278
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Group
open import lib.types.List
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.Word
open import lib.groups.Homomorphism
open import lib.groups.GeneratedGroup
open import lib.groups.GeneratedAbelianGroup
open import lib.groups.Isomorphism
module lib.groups.TensorProduct where
module TensorProduct₀ {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G = AbGroup G
module H = AbGroup H
⊗-pair : Type (lmax i j)
⊗-pair = G.El × H.El
data ⊗-rel : Word ⊗-pair → Word ⊗-pair → Type (lmax i j) where
linear-l : (g₁ g₂ : G.El) (h : H.El) →
⊗-rel (inl (G.comp g₁ g₂ , h) :: nil) (inl (g₁ , h) :: inl (g₂ , h) :: nil)
linear-r : (g : G.El) (h₁ h₂ : H.El) →
⊗-rel (inl (g , H.comp h₁ h₂) :: nil) (inl (g , h₁) :: inl (g , h₂) :: nil)
private
module Gen = GeneratedAbelianGroup ⊗-pair ⊗-rel
open Gen hiding (GenGroup; GenAbGroup; El) public
abstract
abgroup : AbGroup (lmax i j)
abgroup = Gen.GenAbGroup
open AbGroup abgroup public
abstract
infixr 80 _⊗_
_⊗_ : G.El → H.El → El
_⊗_ g h = insert (g , h)
⊗-lin-l : ∀ g₁ g₂ h → G.comp g₁ g₂ ⊗ h == comp (g₁ ⊗ h) (g₂ ⊗ h)
⊗-lin-l g₁ g₂ h = rel-holds (linear-l g₁ g₂ h)
⊗-lin-r : ∀ g h₁ h₂ → g ⊗ H.comp h₁ h₂ == comp (g ⊗ h₁) (g ⊗ h₂)
⊗-lin-r g h₁ h₂ = rel-holds (linear-r g h₁ h₂)
⊗-unit-l : ∀ h → G.ident ⊗ h == ident
⊗-unit-l h = cancel-l (G.ident ⊗ h) $
comp (G.ident ⊗ h) (G.ident ⊗ h)
=⟨ ! (⊗-lin-l G.ident G.ident h) ⟩
G.comp G.ident G.ident ⊗ h
=⟨ ap (_⊗ h) (G.unit-l G.ident) ⟩
G.ident ⊗ h
=⟨ ! (unit-r (G.ident ⊗ h)) ⟩
comp (G.ident ⊗ h) ident =∎
⊗-unit-r : ∀ g → g ⊗ H.ident == ident
⊗-unit-r g = cancel-r (g ⊗ H.ident) $
comp (g ⊗ H.ident) (g ⊗ H.ident)
=⟨ ! (⊗-lin-r g H.ident H.ident) ⟩
g ⊗ H.comp H.ident H.ident
=⟨ ap (g ⊗_) (H.unit-l H.ident) ⟩
g ⊗ H.ident
=⟨ ! (unit-r (g ⊗ H.ident)) ⟩
comp (g ⊗ H.ident) ident =∎
ins-l-hom : H.El → G.grp →ᴳ grp
ins-l-hom h = group-hom (_⊗ h) (λ g₁ g₂ → ⊗-lin-l g₁ g₂ h)
ins-r-hom : G.El → H.grp →ᴳ grp
ins-r-hom g = group-hom (g ⊗_) (⊗-lin-r g)
module BilinearMaps {k} (L : AbGroup k) where
private
module L = AbGroup L
module HE = Gen.HomomorphismEquiv L
is-linear-l : (G.El → H.El → L.El) → Type (lmax i (lmax j k))
is-linear-l b = ∀ g₁ g₂ h → b (G.comp g₁ g₂) h == L.comp (b g₁ h) (b g₂ h)
is-linear-l-is-prop : (b : G.El → H.El → L.El) → is-prop (is-linear-l b)
is-linear-l-is-prop b =
Π-level $ λ g₁ →
Π-level $ λ g₂ →
Π-level $ λ h →
has-level-apply L.El-level _ _
is-linear-r : (G.El → H.El → L.El) → Type (lmax i (lmax j k))
is-linear-r b = ∀ g h₁ h₂ → b g (H.comp h₁ h₂) == L.comp (b g h₁) (b g h₂)
is-linear-r-is-prop : (b : G.El → H.El → L.El) → is-prop (is-linear-r b)
is-linear-r-is-prop b =
Π-level $ λ g →
Π-level $ λ h₁ →
Π-level $ λ h₂ →
has-level-apply L.El-level _ _
record BilinearMap : Type (lmax i (lmax j k)) where
field
bmap : G.El → H.El → L.El
linearity-l : is-linear-l bmap
linearity-r : is-linear-r bmap
BilinearMap= : {b b' : BilinearMap}
→ BilinearMap.bmap b == BilinearMap.bmap b'
→ b == b'
BilinearMap= {b} {b'} idp =
ap2 mk-bilinear-map
(prop-path (is-linear-l-is-prop b.bmap) b.linearity-l b'.linearity-l)
(prop-path (is-linear-r-is-prop b.bmap) b.linearity-r b'.linearity-r)
where
module b = BilinearMap b
module b' = BilinearMap b'
mk-bilinear-map : is-linear-l b.bmap → is-linear-r b.bmap → BilinearMap
mk-bilinear-map lin-l lin-r =
record { bmap = b.bmap; linearity-l = lin-l; linearity-r = lin-r }
bilinear-to-legal-equiv : BilinearMap ≃ HE.RelationRespectingFunction
bilinear-to-legal-equiv =
equiv to from
(λ lf → HE.RelationRespectingFunction= idp)
(λ b → BilinearMap= idp)
where
to : BilinearMap → HE.RelationRespectingFunction
to b = HE.rel-res-fun f f-respects
where
module b = BilinearMap b
f : ⊗-pair → L.El
f (g , h) = b.bmap g h
f-respects : HE.respects-rel f
f-respects (linear-l g₁ g₂ h) = b.linearity-l g₁ g₂ h
f-respects (linear-r g h₁ h₂) = b.linearity-r g h₁ h₂
from : HE.RelationRespectingFunction → BilinearMap
from (HE.rel-res-fun f f-respects) =
record { bmap = bmap; linearity-l = linearity-l; linearity-r = linearity-r }
where
bmap : G.El → H.El → L.El
bmap g h = f (g , h)
linearity-l : is-linear-l bmap
linearity-l g₁ g₂ h = f-respects (linear-l g₁ g₂ h)
linearity-r : is-linear-r bmap
linearity-r g h₁ h₂ = f-respects (linear-r g h₁ h₂)
module UniversalProperty {k} (L : AbGroup k) where
open BilinearMaps L public
private
module HE = Gen.HomomorphismEquiv L
abstract
extend-equiv : BilinearMap ≃ (grp →ᴳ AbGroup.grp L)
extend-equiv =
HE.extend-equiv ∘e bilinear-to-legal-equiv
extend : BilinearMap → (grp →ᴳ AbGroup.grp L)
extend = –> extend-equiv
restrict : (grp →ᴳ AbGroup.grp L) → BilinearMap
restrict = <– extend-equiv
extend-β : ∀ b g h → GroupHom.f (extend b) (g ⊗ h) == BilinearMap.bmap b g h
extend-β b g h = idp
hom= : ∀ {ϕ ψ : grp →ᴳ AbGroup.grp L}
→ (∀ g h → GroupHom.f ϕ (g ⊗ h) == GroupHom.f ψ (g ⊗ h))
→ ϕ == ψ
hom= {ϕ} {ψ} e =
ϕ
=⟨ ! (<–-inv-r extend-equiv ϕ) ⟩
extend (restrict ϕ)
=⟨ ap extend (BilinearMap= (λ= (λ g → λ= (λ h → e g h)))) ⟩
extend (restrict ψ)
=⟨ <–-inv-r extend-equiv ψ ⟩
ψ =∎
module TensorProduct₁ {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G⊗H = TensorProduct₀ G H
module H⊗G = TensorProduct₀ H G
module F = G⊗H.UniversalProperty H⊗G.abgroup
b : F.BilinearMap
b =
record
{ bmap = λ g h → h H⊗G.⊗ g
; linearity-l = λ g₁ g₂ h → H⊗G.⊗-lin-r h g₁ g₂
; linearity-r = λ g h₁ h₂ → H⊗G.⊗-lin-l h₁ h₂ g
}
swap : (G⊗H.grp →ᴳ H⊗G.grp)
swap = F.extend b
swap-β : ∀ g h →
GroupHom.f swap (g G⊗H.⊗ h) == h H⊗G.⊗ g
swap-β g h = F.extend-β b g h
open G⊗H public
module TensorProduct₂ {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G⊗H = TensorProduct₁ G H
module H⊗G = TensorProduct₁ H G
swap-swap : ∀ s → GroupHom.f (H⊗G.swap ∘ᴳ G⊗H.swap) s == s
swap-swap s =
ap (λ ϕ → GroupHom.f ϕ s) $
G⊗H.UniversalProperty.hom= G⊗H.abgroup {ϕ = H⊗G.swap ∘ᴳ G⊗H.swap} {ψ = idhom _} $
λ g h → ap (GroupHom.f H⊗G.swap) (G⊗H.swap-β g h) ∙ H⊗G.swap-β h g
swap-swap-idhom : H⊗G.swap ∘ᴳ G⊗H.swap == idhom G⊗H.grp
swap-swap-idhom = group-hom= (λ= swap-swap)
open G⊗H public
module TensorProduct {i} {j} (G : AbGroup i) (H : AbGroup j) where
private
module G⊗H = TensorProduct₂ G H
module H⊗G = TensorProduct₂ H G
swap-is-equiv : is-equiv (GroupHom.f G⊗H.swap)
swap-is-equiv = is-eq _ (GroupHom.f H⊗G.swap) H⊗G.swap-swap G⊗H.swap-swap
commutative : G⊗H.grp ≃ᴳ H⊗G.grp
commutative = G⊗H.swap , swap-is-equiv
open G⊗H public
| {
"alphanum_fraction": 0.5603202606,
"avg_line_length": 31.2245762712,
"ext": "agda",
"hexsha": "df9190f8cd5e848276bd51406937d4cdb602de8c",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/groups/TensorProduct.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/groups/TensorProduct.agda",
"max_line_length": 85,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/groups/TensorProduct.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": 2860,
"size": 7369
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
{-# OPTIONS --allow-unsolved-metas #-}
open import LibraBFT.Base.Types
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Crypto
open import Optics.All
open import Util.Encode
open import Util.KVMap as Map
open import Util.Lemmas
open import Util.PKCS
open import Util.Prelude
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
-- This module defines types for connecting abstract and concrete
-- votes by defining what constitutes enough "evidence" that a
-- vote was cast, which is passed around in the abstract model as
-- the variable (𝓥 : VoteEvidence); here we instantiate it to
-- 'ConcreteVoteEvidence'.
--
-- Some of the types in this module depend on an EpochConfig, but
-- never inspect it. Consequently, we define everything over an
-- abstract 𝓔 passed around as module parameter to an inner module
-- WithEC. Before that, we define some definitions relevant to
-- constructing EpochConfigs from RoundManager.
module LibraBFT.ImplShared.Consensus.Types.EpochDep where
-- Note that the definitions below are relevant only to the verification, not the implementation.
-- They should probably move somewhere else.
-- ValidatorVerifier-correct imposes requirements on a ValidatorVerifier that are sufficient to
-- ensure that we can construct an abstract EpochConfig based on it (see α-EC-VV below).
ValidatorVerifier-correct : ValidatorVerifier → Set
ValidatorVerifier-correct vv =
let authorsInfo = List-map proj₂ (kvm-toList (vv ^∙ vvAddressToValidatorInfo))
totalVotPower = f-sum (_^∙ vciVotingPower) authorsInfo
quorumVotPower = vv ^∙ vvQuorumVotingPower
bizF = totalVotPower ∸ quorumVotPower
pksAll≢ = ∀ v₁ v₂ nId₁ nId₂ → nId₁ ≢ nId₂
→ lookup nId₁ (vv ^∙ vvAddressToValidatorInfo) ≡ just v₁
→ lookup nId₂ (vv ^∙ vvAddressToValidatorInfo) ≡ just v₂
→ v₁ ^∙ vciPublicKey ≢ v₂ ^∙ vciPublicKey
in 3 * bizF < totalVotPower
× quorumVotPower ≤ totalVotPower
× pksAll≢
× f-sum (_^∙ vciVotingPower) (List-filter (Meta-DishonestPK? ∘ (_^∙ vciPublicKey)) authorsInfo) ≤ bizF
open DecLemmas {A = NodeId} _≟_
import LibraBFT.Abstract.BFT
-- α-EC-VV computes an abstract EpochConfig given a ValidatorVerifier
-- that satisfies the conditions stipulated by ValidVerifier-correct
α-EC-VV : Σ ValidatorVerifier ValidatorVerifier-correct → Epoch → EpochConfig
α-EC-VV (vv , ok) epoch =
EpochConfig∙new bsId
epoch
numAuthors
toNodeId
(list-index (_≟_ ∘ proj₁) authors)
(index∘lookup-id authors proj₁ authorsIDs≢)
(λ lkp≡α → lookup∘index-id authors proj₁ authorsIDs≢ lkp≡α)
getPubKey
getPKey-Inj
(λ quorum → qsize ≤ VotPowerMembers quorum
× allDistinct quorum)
λ q₁ q₂ → LibraBFT.Abstract.BFT.bft-lemma
numAuthors
(_^∙ vciVotingPower ∘ getAuthorInfo)
(f-sum (_^∙ vciVotingPower) authorsInfo ∸ qsize)
(≤-trans (proj₁ ok) (≡⇒≤ totalVotPower≡))
getPubKey
(let disMembers = List-filter (Meta-DishonestPK? ∘ getPubKey) members
sumDisM≡ = sum-f∘g disMembers (_^∙ vciVotingPower) getAuthorInfo
disM≡disNId = map∘filter members authorsInfo getAuthorInfo
(Meta-DishonestPK? ∘ (_^∙ vciPublicKey)) getAuthInfo≡VCI
sumDis≤bizF = (proj₂ ∘ proj₂ ∘ proj₂) ok
in ≤-trans (≡⇒≤ (trans sumDisM≡ (cong (f-sum _vciVotingPower) disM≡disNId))) sumDis≤bizF)
(proj₂ q₁) (proj₂ q₂)
(≤-trans (≡⇒≤ N∸bizF≡Qsize) (proj₁ q₁))
(≤-trans (≡⇒≤ N∸bizF≡Qsize) (proj₁ q₂))
-- TODO-2: this takes the per-epoch genesisUID from the GenesisInfo
-- for the *first* epoch (soon to be renamed to BootStrapInfo avoid
-- this confusion). This is temporary until we do epoch change; then
-- it will need to be provided by the caller.
where bsId = fakeBootstrapInfo ^∙ bsiLIWS ∙ liwsLedgerInfo ∙ liConsensusDataHash
authorsMap = vv ^∙ vvAddressToValidatorInfo
authors = kvm-toList authorsMap
authorsIDs≢ = kvm-keys-All≢ authorsMap
authorsInfo = List-map proj₂ authors
numAuthors = length authors
members = allFin numAuthors
qsize = vv ^∙ vvQuorumVotingPower
toNodeId = proj₁ ∘ List-lookup authors
getAuthorInfo = proj₂ ∘ List-lookup authors
getPubKey = _^∙ vciPublicKey ∘ getAuthorInfo
VotPowerMembers = f-sum (_^∙ vciVotingPower ∘ getAuthorInfo)
VotPowerAuthors = f-sum (_^∙ vciVotingPower)
bizF = VotPowerAuthors authorsInfo ∸ qsize
getAuthInfo≡VCI : List-map getAuthorInfo members ≡ authorsInfo
getAuthInfo≡VCI = trans (List-map-compose members) (cong (List-map proj₂) (map-lookup-allFin authors))
totalVotPower≡ : VotPowerAuthors authorsInfo ≡ VotPowerMembers members
totalVotPower≡ = let sumf∘g = sum-f∘g members (_^∙ vciVotingPower) getAuthorInfo
in sym (trans sumf∘g (cong (f-sum (_^∙ vciVotingPower)) getAuthInfo≡VCI))
N∸bizF≡Qsize = subst ((_≡ qsize) ∘ (_∸ bizF)) totalVotPower≡ (m∸[m∸n]≡n ((proj₁ ∘ proj₂) ok))
getPKey-Inj : ∀ {m₁ m₂} → getPubKey m₁ ≡ getPubKey m₂ → m₁ ≡ m₂
getPKey-Inj {m₁} {m₂} pk≡
with m₁ ≟Fin m₂
...| yes m₁≡m₂ = m₁≡m₂
...| no m₁≢m₂ = let nIdm₁≢nIdm₂ = allDistinct-Map {xs = authors} proj₁ authorsIDs≢ m₁≢m₂
pksAll≢ = (proj₁ ∘ proj₂ ∘ proj₂) ok
in ⊥-elim (pksAll≢ (getAuthorInfo m₁) (getAuthorInfo m₂)
(toNodeId m₁) (toNodeId m₂) nIdm₁≢nIdm₂
(kvm-toList-lookup authorsMap) (kvm-toList-lookup authorsMap)
pk≡)
postulate -- TODO-2: define BootstrapInfo to match implementation and write these functions
init-EC : BootstrapInfo → EpochConfig
module WithEC (𝓔 : EpochConfig) where
open EpochConfig 𝓔
open WithAbsVote 𝓔
-- A 'ConcreteVoteEvidence' is a piece of information that
-- captures that the 'vd : AbsVoteData' in question was not /invented/
-- but instead, comes from a concrete vote that is /valid/ (that is,
-- signature has been checked and author belongs to this epoch).
--
-- Moreover, we will also store the RecordChain that leads to the vote;
-- this requires some mutually-recursive shenanigans, so we first declare
-- ConcreteVoteEvidence, then import the necessary modules, and then define it.
record ConcreteVoteEvidence (vd : AbsVoteData) : Set
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 ConcreteVoteEvidence as Abs hiding (qcVotes; Vote)
data VoteCoherence (v : Vote) (b : Abs.Block) : Set where
initial : v ^∙ vParentId ≡ genesisUID
→ v ^∙ vParentRound ≡ 0
→ Abs.bPrevQC b ≡ nothing
→ VoteCoherence v b
¬initial : ∀{b' q}
→ v ^∙ vParentId ≢ genesisUID
→ v ^∙ vParentRound ≢ 0
→ v ^∙ vParentId ≡ Abs.bId b'
→ v ^∙ vParentRound ≡ Abs.bRound b'
→ (Abs.B b') ← (Abs.Q q)
→ (Abs.Q q) ← (Abs.B b)
→ VoteCoherence v b
-- Estabilishing validity of a concrete vote involves checking:
--
-- i) Vote author belongs to the current epoch
-- ii) Vote signature is correctly verified
-- iii) Existence of a RecordChain up to the voted-for block.
-- iv) Coherence of 'vdParent' field with the above record chain.
--
record IsValidVote (v : Vote) : Set where
constructor IsValidVote∙new
inductive
field
_ivvMember : Member
_ivvAuthor : isMember? (_vAuthor v) ≡ just _ivvMember
_ivvSigned : WithVerSig (getPubKey _ivvMember) v
_ivvVDhash : v ^∙ vLedgerInfo ∙ liConsensusDataHash ≡ hashVD (v ^∙ vVoteData)
-- A valid vote must vote for a block that exists and is
-- inserted in a RecordChain.
_ivvBlock : Abs.Block
_ivvBlockId : v ^∙ vProposedId ≡ Abs.bId _ivvBlock
-- Moreover; we must check that the 'parent' field of the vote is coherent.
_ivvCoherent : VoteCoherence v _ivvBlock
-- Finally, the vote is for the correct epoch
_ivvEpoch : v ^∙ vEpoch ≡ epoch
_ivvEpoch2 : v ^∙ vParent ∙ biEpoch ≡ epoch -- Not needed?
open IsValidVote public
-- A valid vote can be directly mapped to an AbsVoteData. Abstraction of QCs
-- and blocks will be given in LibraBFT.Concrete.Records, since those are
-- more involved functions.
α-ValidVote : (v : Vote) → Member → AbsVoteData
α-ValidVote v mbr = AbsVoteData∙new (v ^∙ vProposed ∙ biRound)
mbr
(v ^∙ vProposed ∙ biId)
-- α-ValidVote is the same for two votes that have the same vAuthor, vdProposed and vOrder
α-ValidVote-≡ : ∀ {cv v'} {m : Member}
→ _vdProposed (_vVoteData cv) ≡ _vdProposed (_vVoteData v')
→ α-ValidVote cv m ≡ α-ValidVote v' m
α-ValidVote-≡ {cv} {v'} prop≡ =
AbsVoteData-η (cong _biRound prop≡) refl (cong _biId prop≡)
-- Finally; evidence for some abstract vote consists of a concrete valid vote
-- that is coherent with the abstract vote data.
record ConcreteVoteEvidence vd where
constructor CVE∙new
inductive
field
_cveVote : Vote
_cveIsValidVote : IsValidVote _cveVote
_cveIsAbs : α-ValidVote _cveVote (_ivvMember _cveIsValidVote) ≡ vd
open ConcreteVoteEvidence public
-- Gets the signature of a concrete vote evidence
_cveSignature : ∀{vd} → ConcreteVoteEvidence vd → Signature
_cveSignature = _vSignature ∘ _cveVote
-- A valid quorum certificate contains a collection of valid votes, such that
-- the members represented by those votes (which exist because the votes are valid)
-- constitutes a quorum.
record MetaIsValidQC (qc : QuorumCert) : Set where
field
_ivqcMetaVotesValid : All (IsValidVote ∘ rebuildVote qc) (qcVotes qc)
_ivqcMetaIsQuorum : IsQuorum (All-reduce _ivvMember _ivqcMetaVotesValid)
open MetaIsValidQC public
-- A valid TimeoutCertificate has a quorum of signatures that are valid for the current
-- EpochConfig. There will be a lot of overlap with MetaIsValidQc and IsValidVote.
-- TODO-2: flesh out the details.
postulate -- TODO-1: defined if needed (see draft below)
MetaIsValidTimeoutCert : TimeoutCertificate → Set
{-
record MetaIsValidTimeoutCert (tc : TimeoutCertificate) : Set where
field
_ivtcMetaSigsValid :
_ivtcMetaIsQuorum :
-}
vqcMember : (qc : QuorumCert) → MetaIsValidQC qc
→ ∀ {as} → as ∈ qcVotes qc → Member
vqcMember qc v {α , _ , _} as∈qc with All-lookup (_ivqcMetaVotesValid v) as∈qc
...| prf = _ivvMember prf
| {
"alphanum_fraction": 0.6130290456,
"avg_line_length": 49.1836734694,
"ext": "agda",
"hexsha": "cf703553e52e8753385f4cf5f0dc925fba1015d2",
"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/ImplShared/Consensus/Types/EpochDep.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/ImplShared/Consensus/Types/EpochDep.agda",
"max_line_length": 124,
"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/ImplShared/Consensus/Types/EpochDep.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3380,
"size": 12050
} |
{-# OPTIONS --without-K #-}
module isos-examples where
open import Function
open import Function.Related.TypeIsomorphisms.NP
import Function.Inverse.NP as FI
open FI using (_↔_; inverses; module Inverse) renaming (_$₁_ to to; _$₂_ to from)
import Function.Related as FR
open import Type hiding (★)
open import Data.Product.NP
open import Data.Bool.NP using (✓)
open import Data.One using (𝟙)
open import Data.Bits
open import Relation.Binary
import Relation.Binary.PropositionalEquality as ≡
open ≡ using (_≡_; subst)
_≈₂_ : ∀ {a} {A : ★ a} (f g : A → Bit) → ★ _
_≈₂_ {A = A} f g = Σ A (✓ ∘ f) ↔ Σ A (✓ ∘ g)
module _ {a r} {A : ★ a} {R : ★ r} where
_≈_ : (f g : A → R) → ★ _
f ≈ g = ∀ (O : R → ★ r) → Σ A (O ∘ f) ↔ Σ A (O ∘ g)
≈-refl : Reflexive {A = A → R} _≈_
≈-refl _ = FI.id
≈-trans : Transitive {A = A → R} _≈_
≈-trans p q O = q O FI.∘ p O
≈-sym : Symmetric {A = A → R} _≈_
≈-sym p O = FI.sym (p O)
module _ {a r} {A : ★ a} {R : ★ r} (f : A → R) (p : A ↔ A) where
stable : f ≈ (f ∘ from p)
stable _ = first-iso p
stable′ : f ≈ (f ∘ to p)
stable′ _ = first-iso (FI.sym p)
module _ {a b r} {A : ★ a} {B : ★ b} {R : ★ r} where
_≋_ : (f : A → R) (g : B → R) → ★ _
f ≋ g = (f ∘ proj₁) ≈ (g ∘ proj₂)
module _ {a b r} {A : ★ a} {B : ★ b} {R : ★ r} where
_≋′_ : (f : A → R) (g : B → R) → ★ _
f ≋′ g = ∀ (O : R → ★ r) →
(B × Σ A (O ∘ f)) ↔ (A × Σ B (O ∘ g))
module _ {f : A → R} {g : B → R} where
open FR.EquationalReasoning
≋′→≋ : f ≋′ g → f ≋ g
≋′→≋ h O = Σ (A × B) (O ∘ f ∘ proj₁)
↔⟨ Σ×-swap ⟩
Σ (B × A) (O ∘ f ∘ proj₂)
↔⟨ Σ-assoc ⟩
(B × Σ A (O ∘ f))
↔⟨ h O ⟩
(A × Σ B (O ∘ g))
↔⟨ FI.sym Σ-assoc ⟩
Σ (A × B) (O ∘ g ∘ proj₂)
∎
≋→≋′ : f ≋ g → f ≋′ g
≋→≋′ h O = (B × Σ A (O ∘ f))
↔⟨ FI.sym Σ-assoc ⟩
Σ (B × A) (O ∘ f ∘ proj₂)
↔⟨ Σ×-swap ⟩
Σ (A × B) (O ∘ f ∘ proj₁)
↔⟨ h O ⟩
Σ (A × B) (O ∘ g ∘ proj₂)
↔⟨ Σ-assoc ⟩
(A × Σ B (O ∘ g))
∎
-- -}
-- -}
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.4046140195,
"avg_line_length": 27.487804878,
"ext": "agda",
"hexsha": "10e0eae92cab52c912df6290a66ff88da1f1e01e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Experimental/iso-probabilistic-reasoning.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Experimental/iso-probabilistic-reasoning.agda",
"max_line_length": 81,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Experimental/iso-probabilistic-reasoning.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 987,
"size": 2254
} |
{-# OPTIONS --without-K #-}
open import container.core
module container.w.algebra
{li la lb}(c : Container li la lb) where
open import sum
open import equality
open import container.w.core
open import function.extensionality
open import function.isomorphism
open import hott.level.core
open Container c
Alg : ∀ ℓ → Set _
Alg ℓ = Σ (I → Set ℓ) λ X → F X →ⁱ X
carrier : ∀ {ℓ} → Alg ℓ → I → Set ℓ
carrier (X , _) = X
IsMor : ∀ {ℓ₁ ℓ₂}(𝓧 : Alg ℓ₁)(𝓨 : Alg ℓ₂)
→ (carrier 𝓧 →ⁱ carrier 𝓨) → Set _
IsMor (X , θ) (Y , ψ) f = ψ ∘ⁱ imap f ≡ f ∘ⁱ θ
Mor : ∀ {ℓ₁ ℓ₂} → Alg ℓ₁ → Alg ℓ₂ → Set _
Mor 𝓧 𝓨 = Σ (carrier 𝓧 →ⁱ carrier 𝓨) (IsMor 𝓧 𝓨)
𝓦 : Alg _
𝓦 = W c , inW c
module _ {ℓ₁ ℓ₂}(𝓧 : Alg ℓ₁)(𝓨 : Alg ℓ₂) where
private
X = proj₁ 𝓧; θ = proj₂ 𝓧
Y = proj₁ 𝓨; ψ = proj₂ 𝓨
is-mor-transp : {f g : X →ⁱ Y}(p : f ≡ g)
→ (α : IsMor 𝓧 𝓨 f)
→ sym (ap (λ h → ψ ∘ⁱ imap h) p) · α · ap (λ h → h ∘ⁱ θ) p
≡ subst (IsMor 𝓧 𝓨) p α
is-mor-transp {f} {.f} refl α = left-unit α
MorEq : Mor 𝓧 𝓨 → Mor 𝓧 𝓨 → Set _
MorEq (f , α) (g , β) = Σ (f ≡ g) λ p
→ sym (ap (λ h → ψ ∘ⁱ imap h) p) · α · ap (λ h → h ∘ⁱ θ) p ≡ β
MorH : Mor 𝓧 𝓨 → Mor 𝓧 𝓨 → Set _
MorH (f , α) (g , β) = Σ (∀ i x → f i x ≡ g i x) λ p
→ ∀ i x → sym (ap (ψ i) (hmap p i x)) · funext-invⁱ α i x · p i (θ i x)
≡ funext-invⁱ β i x
mor-eq-h-iso : (f g : Mor 𝓧 𝓨) → MorEq f g ≅ MorH f g
mor-eq-h-iso (f , α) (g , β) = Σ-ap-iso (sym≅ funext-isoⁱ) λ p → lem f g α β p
where
lem : (f g : X →ⁱ Y)(α : IsMor 𝓧 𝓨 f)(β : IsMor 𝓧 𝓨 g)(p : f ≡ g)
→ (sym (ap (λ h → ψ ∘ⁱ imap h) p) · α · ap (λ h → h ∘ⁱ θ) p ≡ β)
≅ (∀ i x → sym (ap (ψ i) (hmap (funext-invⁱ p) i x))
· funext-invⁱ α i x
· funext-invⁱ p i (θ i x)
≡ funext-invⁱ β i x)
lem f .f α β refl = begin
(α · refl ≡ β)
≅⟨ sym≅ (trans≡-iso (left-unit α)) ⟩
(α ≡ β)
≅⟨ iso≡ (sym≅ funext-isoⁱ) ⟩
(funext-invⁱ α ≡ funext-invⁱ β)
≅⟨ sym≅ ((Π-ap-iso refl≅ λ _ → strong-funext-iso) ·≅ strong-funext-iso) ⟩
(∀ i x → funext-invⁱ α i x ≡ funext-invⁱ β i x)
≅⟨ ( Π-ap-iso refl≅ λ i
→ Π-ap-iso refl≅ λ x
→ trans≡-iso (comp i x) ) ⟩
(∀ i x → sym (ap (ψ i) (hmap (funext-invⁱ p₀) i x))
· funext-invⁱ α i x
· refl
≡ funext-invⁱ β i x)
∎
where
open ≅-Reasoning
p₀ : f ≡ f
p₀ = refl
comp : ∀ i x → sym (ap (ψ i) (hmap (funext-invⁱ (refl {x = f})) i x))
· funext-invⁱ α i x
· refl
≡ funext-invⁱ α i x
comp i x = ap (λ q → sym (ap (ψ i) q) · funext-invⁱ α i x · refl)
(hmap-id f i x)
· left-unit (funext-invⁱ α i x)
eq-mor-iso : {f g : Mor 𝓧 𝓨} → (f ≡ g) ≅ MorH f g
eq-mor-iso {f , α} {g , β} = begin
((f , α) ≡ (g , β))
≅⟨ sym≅ Σ-split-iso ⟩
(Σ (f ≡ g) λ p → subst (IsMor 𝓧 𝓨) p α ≡ β)
≅⟨ (Σ-ap-iso refl≅ λ p → trans≡-iso (is-mor-transp p α)) ⟩
MorEq (f , α) (g , β)
≅⟨ mor-eq-h-iso _ _ ⟩
MorH (f , α) (g , β)
∎
where
open ≅-Reasoning
module _ {ℓ} (𝓧 : Alg ℓ) where
private
X = proj₁ 𝓧; θ = proj₂ 𝓧
lem : ∀ {ℓ}{A : Set ℓ}{x y z w : A}
→ (p : x ≡ w) (q : y ≡ x) (r : y ≡ z) (s : z ≡ w)
→ p ≡ sym q · r · s → sym r · q · p ≡ s
lem p refl refl refl α = α
W-mor-prop : (f g : Mor 𝓦 𝓧) → f ≡ g
W-mor-prop (f , α) (g , β) = invert (eq-mor-iso 𝓦 𝓧) (p , p-h)
where
p : ∀ i x → f i x ≡ g i x
p i (sup a u)
= sym (funext-invⁱ α i (a , u))
· ap (θ i) (ap (_,_ a) (funext (λ b → p (r b) (u b))))
· funext-invⁱ β i (a , u)
p-h : ∀ i x
→ sym (ap (θ i) (hmap p i x))
· funext-invⁱ α i x
· p i (inW c i x)
≡ funext-invⁱ β i x
p-h i (a , u) = lem (p i (sup a u))
(funext-invⁱ α i (a , u)) _
(funext-invⁱ β i (a , u))
refl
W-mor : Mor 𝓦 𝓧
W-mor = fold c θ , funextⁱ (λ i x → fold-β c θ x)
W-initial : ∀ {ℓ} (𝓧 : Alg ℓ) → contr (Mor 𝓦 𝓧)
W-initial 𝓧 = W-mor 𝓧 , W-mor-prop 𝓧 (W-mor 𝓧)
-- special case of the isomorphism above, with better
-- computational behaviour
W-initial-W : contr (Mor 𝓦 𝓦)
W-initial-W = id-mor , W-mor-prop 𝓦 id-mor
where
id-mor : Mor 𝓦 𝓦
id-mor = (λ i x → x) , refl
| {
"alphanum_fraction": 0.4441027894,
"avg_line_length": 31.4,
"ext": "agda",
"hexsha": "ca1f43aa38d118ad00e5cf55945d30ae88206be5",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/w/algebra.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "container/w/algebra.agda",
"max_line_length": 81,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/w/algebra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 2050,
"size": 4553
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.