Search is not available for this dataset
text
string | meta
dict |
---|---|
module Structure.Function.Proofs where
import Lvl
open import Functional
open import Structure.Function
open import Structure.Operator
open import Structure.Operator.Properties
open import Structure.Setoid
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ : Lvl.Level
private variable T A B C D : Type{ℓ}
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
⦃ equiv-C : Equiv{ℓₑ₃}(C) ⦄
⦃ equiv-D : Equiv{ℓₑ₄}(D) ⦄
{f : C → D} ⦃ func : Function(f) ⦄
{_▫_ : A → B → C} ⦃ oper : BinaryOperator(_▫_) ⦄
where
[∘₂]-function : BinaryOperator(f ∘₂ (_▫_))
BinaryOperator.congruence [∘₂]-function = congruence₁(f) ∘₂ congruence₂(_▫_)
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
⦃ equiv-C : Equiv{ℓₑ₃}(C) ⦄
{_▫_ : A → B → C}
⦃ funcₗ : ∀{x} → Function(x ▫_) ⦄
⦃ funcᵣ : ∀{y} → Function(_▫ y) ⦄
where
binaryOperator-from-function : BinaryOperator(_▫_)
BinaryOperator.congruence binaryOperator-from-function xy1 xy2 = congruence₁(_▫ _) xy1 🝖 congruence₁(_ ▫_) xy2
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{_▫_ : A → A → B}
⦃ funcᵣ : ∀{y} → Function(_▫ y) ⦄
⦃ comm : Commutativity(_▫_) ⦄
where
functionₗ-from-commutative-functionᵣ : ∀{x} → Function(x ▫_)
Function.congruence (functionₗ-from-commutative-functionᵣ{a}) {x}{y} xy = commutativity(_▫_) {a}{x} 🝖 congruence₁(_▫ a) xy 🝖 commutativity(_▫_) {y}{a}
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{_▫_ : A → A → B}
⦃ funcᵣ : ∀{x} → Function(x ▫_) ⦄
⦃ comm : Commutativity(_▫_) ⦄
where
functionᵣ-from-commutative-functionₗ : ∀{y} → Function(_▫ y)
Function.congruence (functionᵣ-from-commutative-functionₗ{a}) {x}{y} xy = commutativity(_▫_) {x}{a} 🝖 congruence₁(a ▫_) xy 🝖 commutativity(_▫_) {a}{y}
| {
"alphanum_fraction": 0.637704918,
"avg_line_length": 30.5,
"ext": "agda",
"hexsha": "e37c0f5064a99ad87891fad6bb08d5aa9cf98ad2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Function/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Function/Proofs.agda",
"max_line_length": 152,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Function/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 852,
"size": 1830
} |
module PredicateLifting where
import Level
open import Data.Empty
open import Data.Unit as Unit
open import Data.Nat
open import Data.List as List renaming ([] to Ø; [_] to [_]L)
open import NonEmptyList as NList
open import Data.Fin hiding (_+_)
open import Data.Vec as Vec renaming ([_] to [_]V; _++_ to _++V_)
open import Data.Product as Prod
open import Function
open import Relation.Binary.PropositionalEquality as PE hiding ([_])
open import Relation.Binary
open ≡-Reasoning
open import Common.Context as Context
open import Algebra
open Monoid {{ ... }} hiding (refl)
open import SyntaxRaw
open import Syntax
-- | Extend the parameter context of each type variable in the given
-- type context by one extra variable. We need this to specify the new
-- type variable context, in which the predicate lifting of a type lives.
-- See predL below for the correspond typing rule.
liftTyCtx : ∀ {Θ} → TyCtxMorP Ø Θ → TyCtx
liftTyCtx {Ø} f = Ø
liftTyCtx {Γ ∷ Θ} (A , f) = (∗ ∷ Γ) ∷ liftTyCtx f
-- | Extend a parameter context by a variable of the given type.
extTyVarParams : (Γ₂ : RawCtx) → PreType Ø Ø Γ₂ → RawCtx
extTyVarParams Γ₂ A = ∗ ∷ Γ₂
-- | Get the Yᵢ : (Γᵢ, xᵢ : Bᵢ) ⊸ ∗ corresponding to Xᵢ : Γᵢ ⊸ ∗ in
-- the lifted context, c.f. the typing rule for predL below.
liftTyVar : ∀{Θ Γ₂} → (f : TyCtxMorP Ø Θ) (X : TyVar Θ Γ₂) →
TyVar (liftTyCtx f) (extTyVarParams Γ₂ (getTy f X))
liftTyVar f zero = zero
liftTyVar (A , f) (succ Γ X) =
succ (extTyVarParams Γ (getTy f X)) (liftTyVar f X)
-- | Turn an instantiation into a substitution.
instToSubst : ∀{Γ₁} (A : U) (Γ₂ : RawCtx) → PreTerm Γ₁ Ø →
CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ (Γ₂ ↑ A) ++ Γ₁)
instToSubst {Γ₁} A Γ₂ t =
let f = weakenPO' (∗ ∷ Γ₂) t ∷ ctxProjP Γ₁ (∗ ∷ Γ₂)
in subst (CtxMorP (∗ ∷ Γ₂ ++ Γ₁))
(PE.sym (cong (_∷_ ∗ ) (assoc Γ₂ (A ∷ Ø) Γ₁)))
(extendProj (∗ ∷ Γ₂) Ø f)
-- | Auxiliary function to define predL below.
predL₀ : ∀ {Θ Γ₁ Γ₂} →
(A : Raw Θ Γ₁ Γ₂) → DecentType A → (f : TyCtxMorP Ø Θ) →
liftTyCtx f ∣ ∗ ∷ Γ₂ ++ Γ₁ / Ø ⊸Ty
predL₀ ._ (DT-⊤ Θ Γ) f =
⊤-PT (liftTyCtx f) (∗ ∷ Ø ++ Γ)
predL₀ ._ (DT-tyVar Γ₁ X) f =
tyVarPT _ (liftTyVar f X) §ₜ ctxProjP' Ø _ Γ₁
predL₀ ._ (DT-inst {Γ₂ = Γ₂} B t B-dec t-dec) f =
let B' = predL₀ B B-dec f
in substPT B' (instToSubst _ Γ₂ (mkPreTerm t-dec))
predL₀ ._ (DT-paramAbstr {Γ₂ = Γ₂} {B = B} Γ₁ A-dec) f =
subst (λ u → PreType (liftTyCtx f) u Ø)
(cong (_∷_ ∗) (PE.sym (assoc Γ₂ (B ∷ Ø) Γ₁)))
(predL₀ _ A-dec f)
predL₀ {Θ} {.Γ₁} {Γ₂} ._ (DT-fp Γ₁ ρ D p) f =
fpPT (∗ ∷ Γ₂ ++ Γ₁) ρ (mkD' D p 0) §ₜ f'
where
f' : CtxMorP (∗ ∷ Γ₂ ++ Γ₁) (∗ ∷ Γ₂)
f' = extendP ∗ (ctxProjP' Ø Γ₂ Γ₁)
mkD' : (D : FpData Raw Θ Γ₂) → DecentFpData D → ℕ →
FpDataP (liftTyCtx f) (∗ ∷ Γ₂)
mkD' [ Γ , g , A ] (g-dec , A-dec) k =
let A' = predL₀ A A-dec (substTy (fpPT Ø ρ (mkFpDataP {D = D} p)) f , f)
in
[ ( (∗ ∷ Γ)
, (α (∗ ∷ Γ) Γ ∗ k §ₘ ctxidP (∗ ∷ Γ))
∷ (mkCtxMorP {Γ} {Γ₂} {g} g-dec • ctxProjP Γ (∗ ∷ Ø))
, A' ) ]
mkD' ((Γ , g , A) ∷ D₁) ((g-dec , A-dec) , q) k =
let A' = predL₀ A A-dec (substTy (fpPT Ø ρ (mkFpDataP {D = D} p)) f , f)
in ( ∗ ∷ Γ
, (α (∗ ∷ Γ) Γ ∗ k §ₘ ctxidP (∗ ∷ Γ))
∷ (mkCtxMorP {Γ} {Γ₂} {g} g-dec • ctxProjP Γ (∗ ∷ Ø))
, A' )
∷ mkD' D₁ q (suc k)
-- | Lift an open type A to predicates. More specifically, predL
-- implements the following rule, in which we write Ā for predL A.
-- X₁ : Δ₁ ⊸ Ty, ..., Xₙ : Δₙ ⊸ Ty | Γ₁ ⊢ A : Γ₂ ⊸ Ty
-- B₁ : Δ₁ ⊸ Ty
-- ...
-- Bₙ : Δ₁ ⊸ Ty
-- ================================================================= (predL)
-- Y₁ : (Δ₁, x₁ : B₁ ⊙ id) ⊸ Ty, ..., (Yₙ : Δₙ, xₙ : Bₙ ⊙ id) ⊸ Ty
-- | Γ₁, Γ₂, z : A[B₁/X₁, ..., Bₙ/Xₙ] ⊙ id
-- ⊢ Ā : Ty
predL : ∀ {Θ Γ₁ Γ₂} →
PreType Θ Γ₁ Γ₂ →
(f : TyCtxMorP Ø Θ) →
-- ===========================================================
liftTyCtx f ∣ ∗ ∷ Γ₂ ++ Γ₁ / Ø ⊸Ty
predL (A , A-dec) = predL₀ A A-dec
-- | Special instance of the predicate lifting for types with one
-- free variable and no parameters.
-- X : Δ ⊸ Ty | Γ ⊢ A : Ty B : Δ ⊸ Ty
-- =============================================================== (predL₁)
-- Y : (Δ, x : B ⊙ id) ⊸ ∗ | Γ, z : A[B/X] ⊢ Ā : Ty
predL₁ : ∀ {Δ Γ} →
((Δ ∷ Ø) ∣ Γ / Ø ⊸Ty) → (Ø ∣ Ø / Δ ⊸Ty) →
-- ===========================================================
((∗ ∷ Δ) ∷ Ø) ∣ ∗ ∷ Γ / Ø ⊸Ty
predL₁ A B = predL A (B , tt)
| {
"alphanum_fraction": 0.5020399399,
"avg_line_length": 38.8083333333,
"ext": "agda",
"hexsha": "4efca6a30c542ca6d9e849822196401523d9c25f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-24T10:54:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-24T10:54:38.000Z",
"max_forks_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "StillerHarpo/CoindDepTypes",
"max_forks_repo_path": "Syntax/PredicateLifting.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_issues_repo_issues_event_max_datetime": "2020-07-24T12:53:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-07-24T12:53:30.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "StillerHarpo/CoindDepTypes",
"max_issues_repo_path": "Syntax/PredicateLifting.agda",
"max_line_length": 78,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "480ee27c2c0c20fb35f371177a68721cbc6668c3",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "StillerHarpo/CoindDepTypes",
"max_stars_repo_path": "Syntax/PredicateLifting.agda",
"max_stars_repo_stars_event_max_datetime": "2018-04-06T02:10:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-27T14:45:11.000Z",
"num_tokens": 1854,
"size": 4657
} |
{-# OPTIONS --without-K #-}
-- Universes
open import Agda.Primitive
module main where
-- I don't really understand exactly which equality gets imported in agda if
-- I try to import the builtin, so define the sane MLTT one here.
infixl 4 _≡_
data _≡_ {n : Level} {A : Set n} : A → A → Set n where
refl : {a : A} → a ≡ a
{-# BUILTIN EQUALITY _≡_ #-}
-- Lemma 2.1.1 all paths have inverses
inv : ∀ {n} {A : Set n} {a b : A} → a ≡ b → b ≡ a
inv refl = refl
-- This is painful to type so I'll just stick with inv most of the time
_⁻¹ = inv
-- Lemma 2.1.2 any two paths with connecting endpoint compose
trans : ∀ {n} {A : Set n} {a b c : A} → a ≡ b → b ≡ c → a ≡ c
trans refl p = p
_∙_ = trans
infixl 50 _∙_
-- Lemma 2.1.4 types are groupoids
-- (i) left and right identity laws
left-id : ∀ {n} {A : Set n} {a b : A} → (p : a ≡ b) → refl ∙ p ≡ p
left-id refl = refl
right-id : ∀ {n} {A : Set n} {a b : A} → (p : a ≡ b) → p ∙ refl ≡ p
right-id refl = refl
-- (ii) inverses compose to identity
left-inv : ∀ {n} {A : Set n} {a b : A} → (p : a ≡ b) → (inv p) ∙ p ≡ refl
left-inv refl = refl
right-inv : ∀ {n} {A : Set n} {a b : A} → (p : a ≡ b) → p ∙ (inv p) ≡ refl
right-inv refl = refl
-- (iii) inverse of inverse gives an equal path
inv-inv : ∀ {n} {A : Set n} {a b : A} → (p : a ≡ b) → inv (inv p) ≡ p
inv-inv refl = refl
-- (iv) associativity of path composition
assoc :
∀ {n} {A : Set n} {a b c d : A} →
(p : a ≡ b) (q : b ≡ c) (r : c ≡ d) →
p ∙ (q ∙ r) ≡ (p ∙ q) ∙ r
assoc refl q r = refl
-- Theorem 2.1.6 Eckmann-Hilton
loop-space : (A : Set) (a : A) → Set
loop-space A a = a ≡ a
Ω = loop-space
loop-space-2d : (A : Set) (a : A) → Set
loop-space-2d A a = loop-space (a ≡ a) (refl {a = a})
Ω² = loop-space-2d
_∙ᵣ_ :
∀ {n} {A : Set n} {a b c : A} {p q : a ≡ b} →
(α : p ≡ q) (r : b ≡ c) →
(p ∙ r ≡ q ∙ r)
α ∙ᵣ refl = (right-id _) ∙ α ∙ (inv (right-id _))
-- My emacs setup doesn't show subscript l for some reason, or I typed it wrong
_∙ₗ_ :
∀ {n} {A : Set n} {a b c : A} {r s : b ≡ c} →
(q : a ≡ b) (β : r ≡ s) →
(q ∙ r ≡ q ∙ s)
refl ∙ₗ β = β
horizontal-comp : ∀ {n} {A : Set n} {a b c : A} →
{p q : a ≡ b} {r s : b ≡ c} →
(α : p ≡ q) (β : r ≡ s) →
(p ∙ r ≡ q ∙ s)
horizontal-comp {q = q} {r = r} α β = (α ∙ᵣ r) ∙ (q ∙ₗ β)
_⋆_ = horizontal-comp
horizontal-comp' : ∀ {n} {A : Set n} {a b c : A}
{p q : a ≡ b} {r s : b ≡ c} →
(α : p ≡ q) (β : r ≡ s) →
(p ∙ r ≡ q ∙ s)
horizontal-comp' {p = p} {s = s} α β = (p ∙ₗ β) ∙ (α ∙ᵣ s)
_⋆'_ = horizontal-comp'
-- two compositions agree
comp-agree : {A : Set} {a : A} → (α β : loop-space-2d A a) → α ⋆ β ≡ α ⋆' β
comp-agree α β = comp-agree' α β
where
-- (more generally at two free endpoints, or we won't get path induction)
comp-agree' : {A : Set} {a : A} {p r : a ≡ a} → (α : p ≡ refl) (β : refl ≡ r) → α ⋆ β ≡ α ⋆' β
comp-agree' refl refl = refl
eckmann-hilton : {A : Set} {a : A} → (α β : loop-space-2d A a) → α ∙ β ≡ β ∙ α
eckmann-hilton α β = (inv horizontal-comp-simp) ∙ (comp-agree α β) ∙ horizontal-comp-simp'
where
horizontal-comp-simp : α ⋆ β ≡ α ∙ β
horizontal-comp-simp = remove α β
where
-- not hard, just annoying to do directly.
remove :
{A : Set} {a b c : A} (p : a ≡ b) (q : b ≡ c) → (p ∙ refl) ∙ q ≡ p ∙ q
remove refl refl = refl
horizontal-comp-simp' : α ⋆' β ≡ β ∙ α
horizontal-comp-simp' = remove β α
where
remove :
{A : Set} {a b c : A} (p : a ≡ b) (q : b ≡ c) → p ∙ (q ∙ refl) ≡ p ∙ q
remove refl refl = refl
-- Lemma 2.2.1 action on paths preserve path equality
ap :
∀ {n m} {A : Set n} {B : Set m} {x y : A} →
(f : A → B) (p : x ≡ y) → f x ≡ f y
ap f refl = refl
-- Lemma 2.2.2 functions are functors
-- (i) functions preserves composition
ap-preserves-composition :
∀ {n m} {A : Set n} {B : Set m} {x y z : A} {f : A → B} →
(p : x ≡ y) (q : y ≡ z) →
ap f (p ∙ q) ≡ (ap f p) ∙ (ap f q)
ap-preserves-composition refl q = refl
-- (ii) functions preserves inverses
ap-preserves-inverses :
∀ {n m} {A : Set n} {B : Set m} {x y z : A} {f : A → B} →
(p : x ≡ y) →
ap f (inv p) ≡ inv (ap f p)
ap-preserves-inverses refl = refl
-- (iii) functors compose
_∘_ :
∀ {n m p} {A : Set n} {B : A → Set m} {C : (x : A) → B x → Set p} →
(g : {x : A} → (y : B x) → C x y) (f : (x : A) → B x) →
(x : A) → C x (f x)
(g ∘ f) x = g (f x)
ap-preserves-function-composition :
∀ {n} {A B C : Set n} {x y z : A} {f : A → B} {g : B → C} →
(p : x ≡ y) →
ap g (ap f p) ≡ ap (g ∘ f) p
ap-preserves-function-composition refl = refl
-- (iv) identity maps to identity
ap-identity-map :
∀ {n} {A : Set n} {x y : A} →
(p : x ≡ y) →
ap (λ x → x) p ≡ p
ap-identity-map refl = refl
-- Lemma 2.3.1 transport
transport :
∀ {n m} {A : Set n} {x y : A} →
(P : A → Set m) (p : x ≡ y) →
P x → P y
transport _ refl x = x
-- Lemma 2.3.4 dependent action on paths
apd :
∀ {n m} {A : Set n} {B : A → Set m} {x y : A} →
(f : (x : A) → B x) →
(p : x ≡ y) →
transport B p (f x) ≡ f y
apd f refl = refl
-- Lemma 2.3.5 non-dependent transport moves around ap path
transport-const :
∀ {n} {A B : Set n} {x y : A} →
(p : x ≡ y) (b : B) →
transport (λ _ → B) p b ≡ b
transport-const refl b = refl
-- Lemma 2.3.8 relation between dependent and nondependent transport
apd-ap :
∀ {n} {A B : Set n} {x y : A} →
(f : A → B) (p : x ≡ y) →
apd f p ≡ (transport-const p (f x)) ∙ (ap f p)
apd-ap f refl = refl
-- Lemma 2.3.9 transport unrolling
transport-unroll :
∀ {n m} {A : Set n} {P : A → Set m} {x y z : A} →
(p : x ≡ y) (q : y ≡ z) →
{u : P x} → transport P q (transport P p u) ≡ transport P (p ∙ q) u
transport-unroll refl refl = refl
-- Lemma 2.3.10 transport over ap
transport-ap :
∀ {n m} {A B : Set n} {P : B → Set m} {x y : A} →
(f : A → B) (p : x ≡ y) →
{u : P (f x)} → transport (P ∘ f) p u ≡ transport P (ap f p) u
transport-ap f refl = refl
-- Lemma 2.3.11 transport naturality
transport-natural :
∀ {n m} {A : Set n} {P Q : A → Set m} {x y : A} →
(f : (x : A) → P x → Q x) (p : x ≡ y) →
{u : P x} → transport Q p (f x u) ≡ f y (transport P p u)
transport-natural f refl = refl
-- Definition 2.4.1 homotopy between functions
homotopy : ∀ {n m} {A : Set n} {P : A → Set m} → (f g : (x : A) → P x) → Set (n ⊔ m)
homotopy {A = A} f g = (x : A) → f x ≡ g x
_~_ = homotopy
infixl 10 _~_
-- Lemma 2.4.2 homotopy is an equivalence relation
homotopy-refl :
∀ {n m} {A : Set n} {P : A → Set m} →
(f : (x : A) → P x) → f ~ f
homotopy-refl f x = refl
homotopy-sym :
∀ {n m} {A : Set n} {P : A → Set m} →
(f g : (x : A) → P x) → f ~ g → g ~ f
homotopy-sym f g f-g-hom x = inv (f-g-hom x)
homotopy-trans :
∀ {n m} {A : Set n} {P : A → Set m} →
(f g h : (x : A) → P x) → f ~ g → g ~ h → f ~ h
homotopy-trans f g h f-g-hom g-h-hom x = (f-g-hom x) ∙ (g-h-hom x)
-- Lemma 2.4.3 homotopies are natural transformations between functions
homotopy-natural :
∀ {n} {A B : Set n} {x y : A} {p : x ≡ y} →
(f g : A → B) (H : f ~ g) →
(H x) ∙ (ap g p) ≡ (ap f p) ∙ (H y)
homotopy-natural {x = x} {p = refl} f g h = right-id (h x)
-- Corollary 2.4.4 naturality over identity
homotopy-natural-id :
∀ {n} {A : Set n} →
(f : A → A) (H : f ~ (λ x → x)) →
{x : A} → H (f x) ≡ ap f (H x)
homotopy-natural-id f H {x = x} = remove-ends (H x) (inv commute-square)
where
f-x-path : f x ≡ x
f-x-path = H x
-- annoying to reason about, not hard
replace-inline :
∀ {n} {A : Set n} {x y z : A} →
{p : x ≡ y} {q q' : y ≡ z} {r : x ≡ z} →
p ∙ q ≡ r → q ≡ q' → p ∙ q' ≡ r
replace-inline {p = refl} q-r q-q' = (inv q-q') ∙ q-r
commute-square : (ap f (H x)) ∙ (H x) ≡ (H (f x)) ∙ (H x)
commute-square = inv
(replace-inline
(homotopy-natural {p = f-x-path} f (λ x → x) H)
(ap-identity-map (H x)))
-- annoying to reason about, not hard
remove-ends :
∀ {n} {A : Set n} {x y z : A} →
{p p' : x ≡ y} → (q : y ≡ z) →
p ∙ q ≡ p' ∙ q → p ≡ p'
remove-ends {p = p} {p' = p'} refl p-q-eq-p'-eq =
(inv (right-id p)) ∙ p-q-eq-p'-eq ∙ (right-id p')
-- Definition 2.4.6 quasi-inverse
record qinv {n m : Level} {A : Set n} {B : Set m} (f : A → B) : Set (n ⊔ m) where
constructor _st_and_
field
g : B → A
α : f ∘ g ~ λ x → x
β : g ∘ f ~ λ x → x
-- Example 2.4.7 the identity function is a quasi-inverse
id-qinv : ∀ {n} {A : Set n} → qinv {A = A} {B = A} (λ x → x)
id-qinv = (λ x → x) st (λ x → refl) and (λ x → refl)
-- Example 2.4.8 path concats are quasi-inverses
preconcat-qinv :
∀ {n} {A : Set n} {x y z : A} →
(p : x ≡ y) → qinv (λ (q : y ≡ z) → p ∙ q)
preconcat-qinv {x = x} {y = y} {z = z} p =
g st α and β
where
f : y ≡ z → x ≡ z
f q = p ∙ q
g : x ≡ z → y ≡ z
g pq = (inv p) ∙ pq
α : (f ∘ g) ~ λ x → x
α refl = simpl p
where
simpl : ∀ {n} {A : Set n} {x y : A} → (p : x ≡ y) → p ∙ ((inv p) ∙ refl) ≡ refl
simpl refl = refl
β : (g ∘ f) ~ λ x → x
β refl = simpl p
where
simpl : ∀ {n} {A : Set n} {x y : A} → (p : x ≡ y) → (inv p) ∙ (p ∙ refl) ≡ refl
simpl refl = refl
postconcat-qinv :
∀ {n} {A : Set n} {x y z : A} →
(p : x ≡ y) → qinv (λ (q : z ≡ x) → q ∙ p)
postconcat-qinv {x = x} {y = y} {z = z} p =
g st α and β
where
f : z ≡ x → z ≡ y
f q = q ∙ p
g : z ≡ y → z ≡ x
g qp = qp ∙ (inv p)
α : (f ∘ g) ~ λ x → x
α refl = left-inv p
β : (g ∘ f) ~ λ x → x
β refl = right-inv p
-- Example 2.4.9 transport over paths induces a quasi-inverse over the inverse path
transport-qinv :
∀ {n m} {A : Set n} {x y : A} →
(P : A → Set m) (p : x ≡ y) →
qinv (transport P p)
transport-qinv {x = x} {y = y} P p =
g st α and β
where
f : P x → P y
f = transport P p
g : P y → P x
g = transport P (inv p)
transport-equiv-paths :
∀ {n m} {A : Set n} {x y : A} →
(P : A → Set m) (p q : x ≡ y) →
p ≡ q → {n : P x} → transport P p n ≡ transport P q n
transport-equiv-paths P p .p refl = refl
transport-refl-paths :
∀ {n m} {A : Set n} {x : A} →
(P : A → Set m) (p : x ≡ x) →
p ≡ refl → {n : P x} → transport P p n ≡ n
transport-refl-paths P p p-refl {n = n} =
transport-equiv-paths P p refl p-refl {n = n}
α : (f ∘ g) ~ λ x → x
α x =
(transport-unroll {P = P} (inv p) p) ∙
(transport-refl-paths P ((inv p) ∙ p) (left-inv p) {n = x})
β : (g ∘ f) ~ λ x → x
β x =
(transport-unroll {P = P} p (inv p)) ∙
(transport-refl-paths P _ (right-inv p))
-- 2.4.10 a specific definition of equivalence
record isequiv {n m : Level} {A : Set n} {B : Set m} (f : A → B) : Set (n ⊔ m) where
constructor _st_also_st_
field
g : B → A
α : f ∘ g ~ λ x → x
h : B → A
β : h ∘ f ~ λ x → x
-- (i) quasi-inverses induce equivalences
qinv-to-isequiv :
∀ {n m} {A : Set n} {B : Set m} → (f : A → B) → qinv f → isequiv f
qinv-to-isequiv f (g st α and β) = g st α also g st β
-- (ii) equivalences induce quasi-inverses
isequiv-to-qinv :
∀ {n m} {A : Set n} {B : Set m} → (f : A → B) → isequiv f → qinv f
isequiv-to-qinv {A} {B} f (g st α also h st β) = g st α and β'
where
g~h∘f∘g : g ~ (h ∘ (f ∘ g))
g~h∘f∘g x = inv (β (g x))
h∘f∘g~h : (h ∘ (f ∘ g)) ~ h
h∘f∘g~h x = ap h (α x)
g~h : g ~ h
g~h = homotopy-trans _ _ _ g~h∘f∘g h∘f∘g~h
β' : g ∘ f ~ λ x → x
β' x = g~h (f x) ∙ (β x)
-- Definition 2.4.11 equivalence between types
record _≃_ {n : Level} (A B : Set n) : Set n where
constructor _withequiv_
field
f : A → B
e : isequiv f
-- Lemma 2.4.12 type equivalence is a equivalence relation
equiv-refl : ∀ {n} {A : Set n} → A ≃ A
equiv-refl =
(λ x → x) withequiv
(qinv-to-isequiv (λ x → x) ((λ x → x) st (λ x → refl) and (λ x → refl)))
equiv-sym : ∀ {n} {A B : Set n} → A ≃ B → B ≃ A
equiv-sym (f withequiv equiv) with (isequiv-to-qinv f equiv)
... | g st α and β = g withequiv qinv-to-isequiv g (f st β and α)
equiv-trans : ∀ {n} {A B C : Set n} → A ≃ B → B ≃ C → A ≃ C
equiv-trans (fab withequiv equivab) (fbc withequiv equivbc)
with (isequiv-to-qinv fab equivab) | (isequiv-to-qinv fbc equivbc)
... | gab st αab and βab | gbc st αbc and βbc =
(fbc ∘ fab) withequiv
(qinv-to-isequiv (fbc ∘ fab) ((gab ∘ gbc)
st (λ x → ap fbc (αab (gbc x)) ∙ (αbc x))
and λ x → ap gab (βbc (fab x)) ∙ (βab x)))
record _×_ {n m : Level} (A : Set n) (B : Set m) : Set (n ⊔ m) where
constructor _,,_
field
fst : A
snd : B
fst : ∀ {n m} {A : Set n} {B : Set m} → A × B → A
fst (fst ,, snd) = fst
snd : ∀ {n m} {A : Set n} {B : Set m} → A × B → B
snd (fst ,, snd) = snd
-- Function 2.6.1 a path between products induces a pair of paths between elements
product-path-to-elem-path :
∀ {n m} {A : Set n} {B : Set m} {x y : A × B} →
x ≡ y → (fst x ≡ fst y) × (snd x ≡ snd y)
product-path-to-elem-path refl = refl ,, refl
-- Theorem 2.6.2 product path to element paths is an equivalence
product-path-to-elem-path-equiv :
∀ {n m} {A : Set n} {B : Set m} {x y : A × B} →
isequiv (product-path-to-elem-path {A = A} {B = B} {x = x} {y = y})
product-path-to-elem-path-equiv {A = A} {B = B} {x = x} {y = y} =
qinv-to-isequiv product-path-to-elem-path (g st α and β)
where
f = product-path-to-elem-path
g : (fst x ≡ fst y) × (snd x ≡ snd y) → x ≡ y
g = g' x y
where
g' : (x y : A × B) → (fst x ≡ fst y) × (snd x ≡ snd y) → x ≡ y
g' (fst₁ ,, snd₁) (.fst₁ ,, .snd₁) (refl ,, refl) = refl
α : f ∘ g ~ λ x → x
α (refl ,, refl) = refl
β : g ∘ f ~ λ x → x
β refl = refl
-- Theorem 2.6.4 transport over a path to a product fiber is a product of fibers over a path
product-transport :
∀ {n m} {Z : Set n} {A B : Z → Set m} {z w : Z} →
(p : z ≡ w) (x : (A z) × (B z)) →
transport (λ z → (A z) × (B z)) p x ≡ (transport A p (fst x) ,, transport B p (snd x))
product-transport refl (fst ,, snd) = refl
-- Definition of pair⁼
pair⁼ :
∀ {n m} {A : Set n} {B : Set m} {x y : A × B} →
(fst x ≡ fst y) × (snd x ≡ snd y) →
x ≡ y
pair⁼ {A = A} {B = B} {x = x} {y = y} =
isequiv.g (product-path-to-elem-path-equiv {A = A} {B = B} {x = x} {y = y})
-- Theorem 2.6.5 functions are functors over products
function-functor-pair :
{A B A' B' : Set} →
(g : A → A') (h : B → B') →
{x y : A × B} {p : fst x ≡ fst y} {q : snd x ≡ snd y} →
ap (λ x → (g (fst x) ,, h (snd x))) (pair⁼ (p ,, q)) ≡ pair⁼ (ap g p ,, ap h q)
function-functor-pair g h {x = fstx ,, sndx} {y = .fstx ,, .sndx} {p = refl} {q = refl} = refl
-- Theorem 2.7.2 dependent functions are fibrations over Σ-types
record Sigma (A : Set) (B : A → Set) : Set where
constructor _,,_
field
pr1 : A
pr2 : B pr1
syntax Sigma A (λ x → y) = Σ x of A , y
pr1 : {A : Set} {B : A → Set} → Σ x of A , B x → A
pr1 (left ,, right) = left
pr2 : {A : Set} {B : A → Set} → (v : Σ x of A , B x) → B (pr1 {A} {B} v)
pr2 (left ,, right) = right
-- Theorem 2.7.2 dependent functions are functors over fibrations
function-fibration-product :
{A : Set} {P : A → Set} {w w' : Σ x of A , P x} →
(w ≡ w') ≃ (Σ p of (pr1 w ≡ pr1 w') , (transport P p (pr2 w) ≡ pr2 w'))
function-fibration-product {A = A} {P = P} {w = w} {w' = w'} =
f withequiv qinv-to-isequiv f (g st α and β)
where
f :
{w w' : Σ x of A , P x} →
(w ≡ w') → (Σ p of (pr1 w ≡ pr1 w') , (transport P p (pr2 w) ≡ pr2 w'))
f refl = refl ,, refl
g :
{w w' : Σ x of A , P x} →
(Σ p of (pr1 w ≡ pr1 w') , (transport P p (pr2 w) ≡ pr2 w')) → (w ≡ w')
g {w = w1 ,, w2} {w' = .w1 ,, .w2} (refl ,, refl) = refl
α : f ∘ g ~ λ x → x
α (refl ,, refl) = refl
β : g ∘ f ~ λ x → x
β refl = refl
-- Corollary 2.7.3 computation rule for Σ types
computation-sigma :
{A : Set} {P : A → Set} →
(z : Σ x of A , P x) → z ≡ (pr1 z ,, pr2 z)
computation-sigma z =
isequiv.g (_≃_.e function-fibration-product)
(refl ,, refl)
-- Theorem 2.8.1 : only one path between unit elements
record Unit : Set where
constructor unit
single-path-between-unit : {x y : Unit} → (x ≡ y) ≃ Unit
single-path-between-unit {x = x} {y = y} =
f withequiv qinv-to-isequiv f
(g st α and β)
where
f : x ≡ y → Unit
f _ = unit
g : {x y : Unit} → Unit → x ≡ y
g {x = unit} {y = unit} _ = refl
α : f ∘ g ~ λ x → x
α unit = refl
β : g ∘ f ~ λ x → x
β refl = refl
-- Theorem 2.9.2 path between functions are homotopies
happly :
∀ {n m} {A : Set n} {B : A → Set m} {f g : (x : A) → B x} →
(f ≡ g) → f ~ g
happly refl x = refl
-- Axiom 2.9.3 function extensionality
postulate
funext-equiv : ∀ {n m} {A : Set n} {B : A → Set m} {f g : (x : A) → B x} →
isequiv (happly {A = A} {B = B} {f = f} {g = g})
funext :
∀ {n m} {A : Set n} {B : A → Set m} {f g : (x : A) → B x} →
f ~ g → f ≡ g
funext = isequiv.g funext-equiv
-- Lemma 2.9.6
function-path-transport-equiv :
∀ {n m} {X : Set n} {A B : X → Set m} {x y : X} →
{p : x ≡ y} (f : A x → B x) (g : A y → B y) →
(transport (λ x → A x → B x) p f ≡ g) ≃
((a : A x) → (transport B p (f a) ≡ g (transport A p a)))
function-path-transport-equiv {p = refl} f g = happly withequiv funext-equiv
-- Lemma 2.10.1 paths between types are equivalences.
id-to-equiv : ∀ {n} {A B : Set n} → A ≡ B → A ≃ B
id-to-equiv refl = equiv-refl
-- Axiom 2.10.3 univalence axiom.
postulate univalence-equiv : ∀ {n} {A B : Set n} → isequiv (id-to-equiv {A = A} {B = B})
| {
"alphanum_fraction": 0.5004855755,
"avg_line_length": 30.0773195876,
"ext": "agda",
"hexsha": "b1fdd275a5eedd766ee45e56d7ddd7cd38e95191",
"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": "d1c69d43b685b28d7ad63cfef890e500facb3ac8",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haoxuany/hott-practice",
"max_forks_repo_path": "main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d1c69d43b685b28d7ad63cfef890e500facb3ac8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haoxuany/hott-practice",
"max_issues_repo_path": "main.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d1c69d43b685b28d7ad63cfef890e500facb3ac8",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haoxuany/hott-practice",
"max_stars_repo_path": "main.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7602,
"size": 17505
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module stash.modalities.FiberedPushout {i j k} {X : Type i} {Y : Type j} where
{-
X ---glue-left--- P ---glue-right--- Y
-}
module _ (P : X → Y → Type k) where
fibered-pushout-span : Span
fibered-pushout-span = record
{ A = Σ X λ x → Σ Y λ y → P x y
; B = Coprod X Y
; C = Coprod (Σ X λ x → Σ Y λ y → P x y) (Σ X λ x → Σ Y λ y → P x y)
; f = λ{ (inl p) → p ; (inr p) → p}
; g = λ{ (inl p) → inl (fst p) ; (inr p) → inr (fst (snd p))}
}
FiberedPushout : Type (lmax (lmax i j) k)
FiberedPushout = Pushout fibered-pushout-span
module _ {P : X → Y → Type k} where
in-left : X → FiberedPushout P
in-left = right ∘ inl
in-right : Y → FiberedPushout P
in-right = right ∘ inr
in-mid : ∀ {x y} → P x y → FiberedPushout P
in-mid p = left (_ , _ , p)
glue-left : ∀ {x y} (p : P x y) → in-mid p == in-left x
glue-left p = glue (inl (_ , _ , p))
glue-right : ∀ {x y} (p : P x y) → in-mid p == in-right y
glue-right p = glue (inr (_ , _ , p))
module FiberedPushoutElim {l}
(C : FiberedPushout P → Type l)
(b1 : (x : X) → C (in-left x))
(b2 : (x : X) (y : Y) (p : P x y) → C (in-mid p))
(b3 : (y : Y) → C (in-right y))
(glue-left' : (x : X) (y : Y) (p : P x y) → b2 x y p == b1 x [ C ↓ glue-left p ])
(glue-right' : (x : X) (y : Y) (p : P x y) → b2 x y p == b3 y [ C ↓ glue-right p ])
where
private
module PElim = PushoutElim {d = fibered-pushout-span P} {P = C}
(λ{(x , y , p) → b2 x y p})
(λ{(inl x) → b1 x ; (inr y) → b3 y})
(λ{(inl (_ , _ , p)) → glue-left' _ _ p
; (inr (_ , _ , p)) → glue-right' _ _ p})
f = PElim.f
glue-left-β : ∀ {x y} (p : P x y) → apd f (glue-left p) == glue-left' x y p
glue-left-β p = PElim.glue-β (inl (_ , _ , p))
glue-right-β : ∀ {x y} (p : P x y) → apd f (glue-right p) == glue-right' x y p
glue-right-β p = PElim.glue-β (inr (_ , _ , p))
| {
"alphanum_fraction": 0.4733785092,
"avg_line_length": 32.7936507937,
"ext": "agda",
"hexsha": "fabb99a97bf9101073af66a8d5833444ced98370",
"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": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/stash/modalities/FiberedPushout.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"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": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/stash/modalities/FiberedPushout.agda",
"max_line_length": 89,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/stash/modalities/FiberedPushout.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": 830,
"size": 2066
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A Categorical view of the Sum type (Right-biased)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Level
module Data.Sum.Categorical.Right (a : Level) {b} (B : Set b) where
open import Data.Sum.Base
open import Category.Functor
open import Category.Applicative
open import Category.Monad
open import Function
import Function.Identity.Categorical as Id
Sumᵣ : Set (a ⊔ b) → Set (a ⊔ b)
Sumᵣ A = A ⊎ B
functor : RawFunctor Sumᵣ
functor = record { _<$>_ = map₁ }
applicative : RawApplicative Sumᵣ
applicative = record
{ pure = inj₁
; _⊛_ = [ map₁ , const ∘ inj₂ ]′
}
monadT : RawMonadT (_∘′ Sumᵣ)
monadT M = record
{ return = M.pure ∘′ inj₁
; _>>=_ = λ ma f → ma M.>>= [ f , M.pure ∘′ inj₂ ]′
} where module M = RawMonad M
monad : RawMonad Sumᵣ
monad = monadT Id.monad
------------------------------------------------------------------------
-- Get access to other monadic functions
module TraversableA {F} (App : RawApplicative {a ⊔ b} F) where
open RawApplicative App
sequenceA : ∀ {A} → Sumᵣ (F A) → F (Sumᵣ A)
sequenceA (inj₂ a) = pure (inj₂ a)
sequenceA (inj₁ x) = inj₁ <$> x
mapA : ∀ {A B} → (A → F B) → Sumᵣ A → F (Sumᵣ B)
mapA f = sequenceA ∘ map₁ f
forA : ∀ {A B} → Sumᵣ A → (A → F B) → F (Sumᵣ B)
forA = flip mapA
module TraversableM {M} (Mon : RawMonad {a ⊔ b} M) where
open RawMonad Mon
open TraversableA rawIApplicative public
renaming
( sequenceA to sequenceM
; mapA to mapM
; forA to forM
)
| {
"alphanum_fraction": 0.5510817308,
"avg_line_length": 24.115942029,
"ext": "agda",
"hexsha": "a991c490dd22069eac0daea06049f24555a61d9b",
"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/Sum/Categorical/Right.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/Sum/Categorical/Right.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/Sum/Categorical/Right.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": 544,
"size": 1664
} |
module MJ.Syntax.Scoped where
open import Prelude
open import Data.Maybe as Maybe using (Maybe; just)
open import Data.Maybe.All as MayAll
open import Data.Vec as Vec hiding (_∈_)
open import Data.Star.Indexed
open import Data.List
open import Data.List.Properties.Extra
open import Data.List.Prefix
open import Data.List.Any
open import Data.List.All as List∀ hiding (lookup)
open import Data.List.All.Properties.Extra
open import Relation.Binary.PropositionalEquality
import Data.Vec.All as Vec∀
open Membership-≡
open import MJ.Types
NativeBinOp = ℕ → ℕ → ℕ
data Expr {n : ℕ} (Γ : Ctx c n) : Ty c → Set where
new : (C : Fin c) → All (Expr Γ) (Class.constr (clookup C)) → Expr Γ (ref C)
unit : Expr Γ void
num : ℕ → Expr Γ int
iop : NativeBinOp → (l r : Expr Γ int) → Expr Γ int
call : ∀ {cid as b} →
Expr Γ (ref cid) → Member Σ cid MTH (as , b) → All (Expr Γ) as →
Expr Γ b
var : (i : Fin n) → Expr Γ (lookup i Γ)
get : ∀ {cid ty} → Expr Γ (ref cid) → Member Σ cid FLD ty → Expr Γ ty
upcast : ∀ {c c'} → Σ ⊢ c <: c' → Expr Γ (ref c) → Expr Γ (ref c')
data Cmd {n}(I : Ctx c n)(r : Ty c) : ∀ {m} → (O : Ctx c m) → Set where
loc : ∀ a → Expr I a → Cmd I r (a ∷ I)
asgn : ∀ (i : Fin n) → Expr I (lookup i I) → Cmd I r I
set : ∀ {C a} → Expr I (ref C) →
Member Σ C FLD a → Expr I a → Cmd I r I
do : ∀ {a} → Expr I a → Cmd I r I
ret : Expr I r → Cmd I r I
Stmts : ∀ {n m}→ (Ctx c n) → Ty c → (Ctx c m) → Set
Stmts I r O = Star ℕ (λ n m (I : Ctx c n) (O : Ctx c m) → Cmd I r O) I O
data Body {n}(I : Ctx c n) : Ty c → Set where
body : ∀ {m r}{O : Ctx c m} → Stmts I r O → Expr O r → Body I r
-- mapping of namespace typings to the type of their implementation
Def : ∀ {ns} → Fin c → typing ns c → Set
-- methods have bodies
Def {MTH} C (as , b) = Body (ref C ∷ (fromList as)) b
-- fields have initializers
Def {FLD} C a = Body (fromList (Class.constr (clookup C))) a
record Implementation (cid : Fin c) : Set where
constructor impl
open Class (clookup cid) public
field
-- mapping construct arguments to super constructor arguments
super-args :
Maybe.All
(λ p → All (Expr (fromList constr)) (Class.constr (clookup p)))
parent
-- definitions for all local members
defs : ∀ ns → All (Def cid) (decls ns)
-- implementation of a classtable
record Impl : Set where
field
bodies : ∀ (cid : Fin c) → Implementation cid
-- get member definition from a class
getDef : ∀ {ns ty}→ (cid : Fin c) → (m : Member Σ cid ns ty) → Impl → Def (proj₁ m) ty
getDef {ns = ns} cid (_ , refl , def) I with clookup cid | inspect clookup cid
... | C@(class parent constr decls) | [ refl ] with Impl.bodies I cid
... | impl _ defs = ∈-all def (defs ns)
getDef cid (P' , super {pid = pid} p P<:P' , def) I = getDef pid (P' , P<:P' , def) I
Prog : Ty c → Set
Prog a = Impl × (Body [] a)
| {
"alphanum_fraction": 0.6101283385,
"avg_line_length": 34.734939759,
"ext": "agda",
"hexsha": "8bf2952c7fdf2de79c4a0ba3844fe0f455a88335",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Syntax/Scoped.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Syntax/Scoped.agda",
"max_line_length": 86,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Syntax/Scoped.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 995,
"size": 2883
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
import LibraBFT.Base.KVMap as Map
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.Prelude
open import Optics.All
module LibraBFT.Impl.Consensus.TestUtils.MockSharedStorage where
new : ValidatorSet → MockSharedStorage
new = mkMockSharedStorage
Map.empty
Map.empty
Map.empty
nothing
nothing
newObmWithLIWS : ValidatorSet → LedgerInfoWithSignatures → MockSharedStorage
newObmWithLIWS vs obmLIWS =
new vs & mssLis ∙~ Map.singleton (obmLIWS ^∙ liwsVersion) obmLIWS
| {
"alphanum_fraction": 0.7613488975,
"avg_line_length": 30.84,
"ext": "agda",
"hexsha": "577fea15f745447d2e424edd31d7c4261e96afda",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z",
"max_forks_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "oracle/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Consensus/TestUtils/MockSharedStorage.agda",
"max_issues_count": 72,
"max_issues_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "oracle/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Consensus/TestUtils/MockSharedStorage.agda",
"max_line_length": 111,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "49f8b1b70823be805d84ffc3157c3b880edb1e92",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "oracle/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Consensus/TestUtils/MockSharedStorage.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z",
"num_tokens": 216,
"size": 771
} |
{-# OPTIONS --allow-unsolved-metas #-} -- FIXME
open import Everything
module Test.Test1 where
test-functor-transextensionality : ∀
{𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂}
⦃ functor : Functor 𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂ ⦄
(open Functor functor)
→ {!Transextensionality!.type _∼₁_ _∼̇₁_!}
test-functor-transextensionality = transextensionality
-- test-functor-transextensionality ⦃ functor ⦄ = let open Functor ⦃ … ⦄ in transextensionality1
| {
"alphanum_fraction": 0.7057471264,
"avg_line_length": 31.0714285714,
"ext": "agda",
"hexsha": "dcde433233e311310d93d0affaa71e0bb31849fd",
"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/Test1.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/Test1.agda",
"max_line_length": 98,
"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/Test1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 179,
"size": 435
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Ways to give instances of certain structures where some fields can
-- be given in terms of others
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
module Algebra.Structures.Biased
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality relation
where
open import Algebra.Core
open import Algebra.Definitions _≈_
open import Algebra.Structures _≈_
import Algebra.Consequences.Setoid as Consequences
open import Data.Product using (_,_; proj₁; proj₂)
open import Level using (_⊔_)
------------------------------------------------------------------------
-- IsCommutativeMonoid
record IsCommutativeMonoidˡ (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identityˡ : LeftIdentity ε ∙
comm : Commutative ∙
open IsSemigroup isSemigroup
private
identityʳ : RightIdentity ε ∙
identityʳ = Consequences.comm+idˡ⇒idʳ setoid comm identityˡ
identity : Identity ε ∙
identity = (identityˡ , identityʳ)
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = isSemigroup
; identity = identity
}
; comm = comm
}
open IsCommutativeMonoidˡ public
using () renaming (isCommutativeMonoid to isCommutativeMonoidˡ)
record IsCommutativeMonoidʳ (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where
field
isSemigroup : IsSemigroup ∙
identityʳ : RightIdentity ε ∙
comm : Commutative ∙
open IsSemigroup isSemigroup
private
identityˡ : LeftIdentity ε ∙
identityˡ = Consequences.comm+idʳ⇒idˡ setoid comm identityʳ
identity : Identity ε ∙
identity = (identityˡ , identityʳ)
isCommutativeMonoid : IsCommutativeMonoid ∙ ε
isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = isSemigroup
; identity = identity
}
; comm = comm
}
open IsCommutativeMonoidʳ public
using () renaming (isCommutativeMonoid to isCommutativeMonoidʳ)
------------------------------------------------------------------------
-- IsCommutativeSemiring
record IsCommutativeSemiringˡ (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
distribʳ : * DistributesOverʳ +
zeroˡ : LeftZero 0# *
private
module +-CM = IsCommutativeMonoid +-isCommutativeMonoid
open module *-CM = IsCommutativeMonoid *-isCommutativeMonoid public
using () renaming (comm to *-comm)
distribˡ : * DistributesOverˡ +
distribˡ = Consequences.comm+distrʳ⇒distrˡ
+-CM.setoid +-CM.∙-cong *-comm distribʳ
distrib : * DistributesOver +
distrib = (distribˡ , distribʳ)
zeroʳ : RightZero 0# *
zeroʳ = Consequences.comm+zeˡ⇒zeʳ +-CM.setoid *-comm zeroˡ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-CM.isMonoid
; distrib = distrib
}
; zero = zero
}
; *-comm = *-comm
}
open IsCommutativeSemiringˡ public
using () renaming (isCommutativeSemiring to isCommutativeSemiringˡ)
record IsCommutativeSemiringʳ (+ * : Op₂ A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
+-isCommutativeMonoid : IsCommutativeMonoid + 0#
*-isCommutativeMonoid : IsCommutativeMonoid * 1#
distribˡ : * DistributesOverˡ +
zeroʳ : RightZero 0# *
private
module +-CM = IsCommutativeMonoid +-isCommutativeMonoid
open module *-CM = IsCommutativeMonoid *-isCommutativeMonoid public
using () renaming (comm to *-comm)
distribʳ : * DistributesOverʳ +
distribʳ = Consequences.comm+distrˡ⇒distrʳ
+-CM.setoid +-CM.∙-cong *-comm distribˡ
distrib : * DistributesOver +
distrib = (distribˡ , distribʳ)
zeroˡ : LeftZero 0# *
zeroˡ = Consequences.comm+zeʳ⇒zeˡ +-CM.setoid *-comm zeroʳ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isCommutativeSemiring : IsCommutativeSemiring + * 0# 1#
isCommutativeSemiring = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = +-isCommutativeMonoid
; *-isMonoid = *-CM.isMonoid
; distrib = distrib
}
; zero = zero
}
; *-comm = *-comm
}
open IsCommutativeSemiringʳ public
using () renaming (isCommutativeSemiring to isCommutativeSemiringʳ)
------------------------------------------------------------------------
-- IsRing
-- We can recover a ring without proving that 0# annihilates *.
record IsRingWithoutAnnihilatingZero (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A)
: Set (a ⊔ ℓ) where
field
+-isAbelianGroup : IsAbelianGroup + 0# -_
*-isMonoid : IsMonoid * 1#
distrib : * DistributesOver +
private
module + = IsAbelianGroup +-isAbelianGroup
module * = IsMonoid *-isMonoid
open + using (setoid) renaming (∙-cong to +-cong)
open * using () renaming (∙-cong to *-cong)
zeroˡ : LeftZero 0# *
zeroˡ = Consequences.assoc+distribʳ+idʳ+invʳ⇒zeˡ setoid
+-cong *-cong +.assoc (proj₂ distrib) +.identityʳ +.inverseʳ
zeroʳ : RightZero 0# *
zeroʳ = Consequences.assoc+distribˡ+idʳ+invʳ⇒zeʳ setoid
+-cong *-cong +.assoc (proj₁ distrib) +.identityʳ +.inverseʳ
zero : Zero 0# *
zero = (zeroˡ , zeroʳ)
isRing : IsRing + * -_ 0# 1#
isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-isMonoid = *-isMonoid
; distrib = distrib
; zero = zero
}
open IsRingWithoutAnnihilatingZero public
using () renaming (isRing to isRingWithoutAnnihilatingZero)
| {
"alphanum_fraction": 0.610100682,
"avg_line_length": 29.0471698113,
"ext": "agda",
"hexsha": "fe3f5b88774a207da90f77901a265895e06cefda",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Structures/Biased.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Structures/Biased.agda",
"max_line_length": 75,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Structures/Biased.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": 1941,
"size": 6158
} |
{-# OPTIONS --cubical --safe #-}
module Data.Unit.Properties where
open import Data.Unit
open import Level
open import HLevels
isProp⊤ : isProp ⊤
isProp⊤ _ _ i = tt
| {
"alphanum_fraction": 0.7142857143,
"avg_line_length": 15.2727272727,
"ext": "agda",
"hexsha": "0aaf2fdd00b02a0f79497715692038ccf10ac19f",
"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/Unit/Properties.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/Unit/Properties.agda",
"max_line_length": 33,
"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/Unit/Properties.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": 51,
"size": 168
} |
module ExtendedLambdaCase where
data Bool : Set where
true false : Bool
data Void : Set where
foo : Bool -> Bool -> Bool -> Bool
foo = λ { x → λ { y z → {!!} } }
data Bar : (Bool -> Bool) -> Set where
baz : (t : Void) -> Bar λ { x → {!!} }
-- with hidden argument
data Bar' : (Bool -> Bool) -> Set where
baz' : {t : Void} -> Bar' λ { x' → {!!} }
| {
"alphanum_fraction": 0.5350140056,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "039d72ce7f277b712e438b482e50bddf24ac0b3d",
"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": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/interaction/ExtendedLambdaCase.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"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": "asr/agda-kanso",
"max_issues_repo_path": "test/interaction/ExtendedLambdaCase.agda",
"max_line_length": 43,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/interaction/ExtendedLambdaCase.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 116,
"size": 357
} |
{-# OPTIONS --without-K #-}
-- Expose all the core types and theorems.
module hott.core.theorems where
open import hott.core public
open import hott.core.equality.theorems public
| {
"alphanum_fraction": 0.69,
"avg_line_length": 22.2222222222,
"ext": "agda",
"hexsha": "c8b8b5b413f9376e5247d1b29741a8d77d23a566",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "piyush-kurur/hott",
"max_forks_repo_path": "agda/hott/core/theorems.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "piyush-kurur/hott",
"max_issues_repo_path": "agda/hott/core/theorems.agda",
"max_line_length": 46,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "876ecdcfddca1abf499e8f00db321c6dc3d5b2bc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "piyush-kurur/hott",
"max_stars_repo_path": "agda/hott/core/theorems.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 44,
"size": 200
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bounded vectors, basic types and operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Bounded.Base where
open import Level using (Level)
open import Data.Nat.Base
import Data.Nat.Properties as ℕₚ
open import Data.List.Base as List using (List)
open import Data.List.Extrema ℕₚ.≤-totalOrder
open import Data.List.Relation.Unary.All as All using (All)
import Data.List.Relation.Unary.All.Properties as Allₚ
open import Data.List.Membership.Propositional using (mapWith∈)
open import Data.Product using (∃; _×_; _,_; proj₁; proj₂)
open import Data.Vec.Base as Vec using (Vec)
open import Data.These.Base as These using (These)
open import Function
open import Relation.Nullary
open import Relation.Unary
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
private
variable
a b c p : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- Types
infix 4 _,_
record Vec≤ (A : Set a) (n : ℕ) : Set a where
constructor _,_
field {length} : ℕ
vec : Vec A length
.bound : length ≤ n
------------------------------------------------------------------------
-- Conversion functions
fromVec : ∀ {n} → Vec A n → Vec≤ A n
fromVec v = v , ℕₚ.≤-refl
padRight : ∀ {n} → A → Vec≤ A n → Vec A n
padRight a (vs , m≤n)
with recompute (_ ℕₚ.≤″? _) (ℕₚ.≤⇒≤″ m≤n)
... | less-than-or-equal refl = vs Vec.++ Vec.replicate a
padLeft : ∀ {n} → A → Vec≤ A n → Vec A n
padLeft a as@(vs , m≤n)
with recompute (_ ℕₚ.≤″? _) (ℕₚ.≤⇒≤″ m≤n)
... | less-than-or-equal {k} ∣as∣+k≡n
with P.trans (ℕₚ.+-comm k (Vec≤.length as)) ∣as∣+k≡n
... | refl = Vec.replicate a Vec.++ vs
private
split : ∀ {m n} k → m + k ≡ n → ⌊ k /2⌋ + (m + ⌈ k /2⌉) ≡ n
split {m} {n} k eq = begin
⌊ k /2⌋ + (m + ⌈ k /2⌉) ≡⟨ ℕₚ.+-comm ⌊ k /2⌋ _ ⟩
m + ⌈ k /2⌉ + ⌊ k /2⌋ ≡⟨ ℕₚ.+-assoc m ⌈ k /2⌉ ⌊ k /2⌋ ⟩
m + (⌈ k /2⌉ + ⌊ k /2⌋) ≡⟨ P.cong (m +_) (ℕₚ.+-comm ⌈ k /2⌉ ⌊ k /2⌋) ⟩
m + (⌊ k /2⌋ + ⌈ k /2⌉) ≡⟨ P.cong (m +_) (ℕₚ.⌊n/2⌋+⌈n/2⌉≡n k) ⟩
m + k ≡⟨ eq ⟩
n ∎ where open P.≡-Reasoning
padBoth : ∀ {n} → A → A → Vec≤ A n → Vec A n
padBoth aₗ aᵣ as@(vs , m≤n)
with recompute (_ ℕₚ.≤″? _) (ℕₚ.≤⇒≤″ m≤n)
... | less-than-or-equal {k} ∣as∣+k≡n
with split k ∣as∣+k≡n
... | refl = Vec.replicate {n = ⌊ k /2⌋} aₗ
Vec.++ vs
Vec.++ Vec.replicate {n = ⌈ k /2⌉} aᵣ
fromList : (as : List A) → Vec≤ A (List.length as)
fromList = fromVec ∘ Vec.fromList
toList : ∀ {n} → Vec≤ A n → List A
toList = Vec.toList ∘ Vec≤.vec
------------------------------------------------------------------------
-- Creating new Vec≤ vectors
replicate : ∀ {m n} .(m≤n : m ≤ n) → A → Vec≤ A n
replicate m≤n a = Vec.replicate a , m≤n
[] : ∀ {n} → Vec≤ A n
[] = Vec.[] , z≤n
infixr 5 _∷_
_∷_ : ∀ {n} → A → Vec≤ A n → Vec≤ A (suc n)
a ∷ (as , p) = a Vec.∷ as , s≤s p
------------------------------------------------------------------------
-- Modifying Vec≤ vectors
≤-cast : ∀ {m n} → .(m≤n : m ≤ n) → Vec≤ A m → Vec≤ A n
≤-cast m≤n (v , p) = v , ℕₚ.≤-trans p m≤n
≡-cast : ∀ {m n} → .(eq : m ≡ n) → Vec≤ A m → Vec≤ A n
≡-cast m≡n = ≤-cast (ℕₚ.≤-reflexive m≡n)
map : (A → B) → ∀ {n} → Vec≤ A n → Vec≤ B n
map f (v , p) = Vec.map f v , p
reverse : ∀ {n} → Vec≤ A n → Vec≤ A n
reverse (v , p) = Vec.reverse v , p
-- Align and Zip.
alignWith : (These A B → C) → ∀ {n} → Vec≤ A n → Vec≤ B n → Vec≤ C n
alignWith f (as , p) (bs , q) = Vec.alignWith f as bs , ℕₚ.⊔-least p q
zipWith : (A → B → C) → ∀ {n} → Vec≤ A n → Vec≤ B n → Vec≤ C n
zipWith f (as , p) (bs , q) = Vec.restrictWith f as bs , ℕₚ.m≤n⇒m⊓o≤n _ p
zip : ∀ {n} → Vec≤ A n → Vec≤ B n → Vec≤ (A × B) n
zip = zipWith _,_
align : ∀ {n} → Vec≤ A n → Vec≤ B n → Vec≤ (These A B) n
align = alignWith id
-- take and drop
take : ∀ {m} n → Vec≤ A m → Vec≤ A (n ⊓ m)
take zero _ = []
take (suc n) (Vec.[] , p) = []
take {m = suc m} (suc n) (a Vec.∷ as , p) = a ∷ take n (as , ℕₚ.≤-pred p)
drop : ∀ {m} n → Vec≤ A m → Vec≤ A (m ∸ n)
drop zero v = v
drop (suc n) (Vec.[] , p) = []
drop {m = suc m} (suc n) (a Vec.∷ as , p) = drop n (as , ℕₚ.≤-pred p)
------------------------------------------------------------------------
-- Lifting a collection of bounded vectors to the same size
rectangle : List (∃ (Vec≤ A)) → ∃ (List ∘ Vec≤ A)
rectangle {A = A} rows = width , padded where
sizes = List.map proj₁ rows
width = max 0 sizes
all≤ : All (λ v → proj₁ v ≤ width) rows
all≤ = Allₚ.map⁻ (xs≤max 0 sizes)
padded : List (Vec≤ A width)
padded = mapWith∈ rows $ λ {x} x∈rows →
≤-cast (All.lookup all≤ x∈rows) (proj₂ x)
| {
"alphanum_fraction": 0.4773098937,
"avg_line_length": 31.1592356688,
"ext": "agda",
"hexsha": "53e046c8cfbc7fad846d417ebbca8e6d60d67f7f",
"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/Vec/Bounded/Base.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/Vec/Bounded/Base.agda",
"max_line_length": 74,
"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/Vec/Bounded/Base.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": 2005,
"size": 4892
} |
{-# OPTIONS --erased-cubical --no-main --save-metas #-}
open import Agda.Builtin.Bool
open import Erased-cubical-Cubical
postulate
f : Not-compiled → Bool
-- It is at the time of writing not possible to give a COMPILE GHC
-- pragma for f, because Not-compiled is not compiled.
{-# COMPILE GHC f = \_ -> True #-}
| {
"alphanum_fraction": 0.6959247649,
"avg_line_length": 22.7857142857,
"ext": "agda",
"hexsha": "a3306463f9ac2074479601c4690e6a81d254ac13",
"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": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/Compiler/simple/Erased-cubical-FFI.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/Compiler/simple/Erased-cubical-FFI.agda",
"max_line_length": 66,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Compiler/simple/Erased-cubical-FFI.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 88,
"size": 319
} |
{-# OPTIONS --copatterns --sized-types --without-K #-}
module PolyFinalCoalg where
open import Data.Product
open import Data.Nat
open import Data.Fin
open import Data.Unit as Unit
open import Data.Empty
open import Data.Vec hiding (_∈_; [_])
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Sum as Sum
open import Size
open import Poly
-- | Indexed product
_×ᵢ_ : {I : Set} → Fam I → Fam I → Fam I
(A ×ᵢ B) i = A i × B i
-- | Product of indexed functors
_×ᵢ'_ : {I J K : Set} →
(Fam K → Fam I) → (Fam J → Fam I) → (Fam K × Fam J → Fam I)
(F ×ᵢ' G) (X , Y) = F X ×ᵢ G Y
record Isomorphic (A B : Set) : Set where
-- constructor isIso
field
f : A → B
f⃖ : B → A
is-invˡ : (a : A) → f⃖ (f a) ≡ a
is-invʳ : (b : B) → f (f⃖ b) ≡ b
_≃_ = Isomorphic
_≃'_ : {I : Set} → Fam I → Fam I → Set
_≃'_ {I} A B = (i : I) → A i ≃ B i
-- | Avoid setoids for now
postulate
Π'-ext : {I J : Set} {u : I → J} {P : Fam I} →
(j : J) (f g : Π' u P j) →
((i : I) → (p : u i ≡ j) → f (i , p) ≡ g (i , p)) → f ≡ g
Π'-ext' : {I J : Set} {u : I → J} {P : Fam I} →
(f g : (i : I) → Π' u P (u i)) →
((i : I) → app i (f i) ≡ app i (g i)) → (i : I) → f i ≡ g i
-- | Dependent polynomials
record ParamPoly {I J : Set} : Set₁ where
constructor ppoly
field
-- J ←t- B -p→ A -s→ I
A : Set -- ^ Labels
s : A → I
B : Set
p₁ p₂ : B → A
t₁ : B → J
t₂ : B → I
first : {I J : Set} → ParamPoly {I} {J} → DPoly {I} {J}
first (ppoly A s B p₁ p₂ t₁ t₂) = dpoly A s B p₁ t₁
second : {I J : Set} → ParamPoly {I} {J} → DPoly {I} {I}
second (ppoly A s B p₁ p₂ t₁ t₂) = dpoly A s B p₂ t₂
R : {I J : Set} → ParamPoly {I} {J} →
(X : Fam J) → (Y : Fam I) → Fam I
R (ppoly A s B p₁ p₂ t₁ t₂) X Y =
Σ' s (Π' p₁ ((t₁ *) X) ×ᵢ Π' p₂ ((t₂ *) Y))
data ⊤' (I : Set) : I → Set where
tt : (i : I) → ⊤' I i
⊤'-unique : {I : Set} {i : I} → (x y : ⊤' I i) → x ≡ y
⊤'-unique (tt i) (tt .i) = refl
triv-param : {I J : Set} → (P : ParamPoly {I} {J}) →
(Y : Fam I) → R P (⊤' J) Y ≃' T (second P) Y
triv-param {I} {J} (ppoly A s B p₁ p₂ t₁ t₂) Y i =
record
{ f = f i
; f⃖ = g i
; is-invˡ = is-invˡ i
; is-invʳ = is-invʳ i
}
where
P = ppoly A s B p₁ p₂ t₁ t₂
f : (i : I) → R P (⊤' J) Y i → T (second P) Y i
f ._ (ins a (v₁ , v₂)) = ins a v₂
triv : (a : A) → Π' p₁ ((t₁ *) (⊤' J)) a
triv a = abs (λ b → tt (t₁ b)) a
g : (i : I) → T (second P) Y i → R P (⊤' J) Y i
g ._ (ins a v) = ins a (triv a , v)
is-invˡ : (i : I) → (x : R P (⊤' J) Y i) → g i (f i x) ≡ x
is-invˡ ._ (ins a (v₁ , v₂)) =
Σ'-eq a a (triv a , v₂) (v₁ , v₂)
refl
(×-eq (triv a) v₁ v₂ v₂
(Π'-ext a (triv a) v₁ (lem a v₁))
refl)
where
lem : (a : A) (v₁ : Π' p₁ ((t₁ *) (⊤' J)) a)
(i₁ : B) (p : p₁ i₁ ≡ a) →
triv a (i₁ , p) ≡ v₁ (i₁ , p)
lem ._ v₁ i₁ refl = ⊤'-unique (tt (t₁ i₁)) (app i₁ v₁)
is-invʳ : (i : I) → (x : T (second P) Y i) → f i (g i x) ≡ x
is-invʳ ._ (ins a x) = refl
triv : {I J : Set} (P : DPoly {I} {J}) → T P (⊤' J) ≃' toFam (DPoly.s P)
triv {I} {J} (dpoly A s E p t) i =
record
{ f = f i
; f⃖ = g i
; is-invˡ = p₁ i
; is-invʳ = p₂ i
}
where
P = dpoly A s E p t
f : (i : I) → T P (⊤' J) i → toFam s i
f ._ (ins a v) = (a , refl)
g : (i : I) → toFam s i → T P (⊤' J) i
g ._ (a , refl) = ins a (abs'' a v)
where
v : (b : E) → p b ≡ a → ⊤' J (t b)
v b _ = tt (t b)
p₁ : (i : I) → (x : T (dpoly A s E p t) (⊤' J) i) → g i (f i x) ≡ x
p₁ ._ (ins a v) =
Σ'-eq a a (abs'' a (λ b _ → tt (t b))) v
refl
(Π'-ext a (abs'' a (λ b _ → tt (t b))) v
(λ b p₂ → ⊤'-unique (tt (t b)) (v (b , p₂))))
p₂ : (i : I) (b : toFam s i) → f i (g i b) ≡ b
p₂ ._ (a , refl) = refl
foo : {A C P : Set} (B : Fam A) (D : Fam C) (Q : Fam P) (X : Set) →
Σ (A × C) (λ {(a , c) → (B a → X) × (D c → Σ P (λ p → Q p → X)) })
≃
Σ (A × Σ C (λ c → D c → P))
(λ {(a , c , t) → ((B a → X) × ((Σ (D c) ((t *) Q)) → X))})
foo {A} {C} {P} B D Q X =
record
{ f = f
; f⃖ = g
; is-invˡ = {!!}
; is-invʳ = {!!}
}
where
f : Σ (A × C) (λ {(a , c) → (B a → X) × (D c → Σ P (λ p → Q p → X)) }) →
Σ (A × Σ C (λ c → D c → P))
(λ {(a , c , t) → ((B a → X) × ((Σ (D c) ((t *) Q)) → X))})
f ((a , c) , t) =
((a , c , (λ d → proj₁ (proj₂ t d) ))
, ((proj₁ t) , (λ { (d , q) → proj₂ (proj₂ t d) q})))
g : Σ (A × Σ C (λ c → D c → P))
(λ {(a , c , t) → ((B a → X) × ((Σ (D c) ((t *) Q)) → X))}) →
Σ (A × C) (λ {(a , c) → (B a → X) × (D c → Σ P (λ p → Q p → X)) })
g ((a , c , t₁) , t₂) =
((a , c)
, (proj₁ t₂)
, (λ d → (t₁ d , (λ q → proj₂ t₂ (d , q)))))
δ : {I : Set} → I → I × I
δ i = (i , i)
bar : {I K L : Set} (t : K → I) (v : L → I) (A : Fam K) (B : Fam L) →
(Σ' t A ×ᵢ Σ' v B) ≃' (δ *) (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B))
bar {I} {K} {L} t v A B i =
record
{ f = f i
; f⃖ = g i
; is-invˡ = {!!}
; is-invʳ = {!!}
}
where
f : (i : I) →
(Σ' t A ×ᵢ Σ' v B) i → (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B)) (i , i)
f .(t k) (ins k x , y) = h k x (t k) refl y
where
h : (k : K) (x : A k) (i : I) (p : t k ≡ i) →
(Σ' v B) i → (Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B)) (i , i)
h k x ._ p (ins l y) =
ins' (k , l)
((v l) , (v l))
(⊗-eq {f = t} {v} k l p)
(x , y)
g : (i : I) →
(Σ' (t ⊗ v) ((proj₁ *) A ×ᵢ (proj₂ *) B)) (i , i) → (Σ' t A ×ᵢ Σ' v B) i
g i x =
let
k = proj₁ (p₁' x)
l = proj₂ (p₁' x)
q₁ : t k ≡ i
q₁ = ×-eqˡ (p₌' x)
q₂ : v l ≡ i
q₂ = ×-eqʳ (p₌' x)
u : A k × B l
u = p₂' x
in (ins' k i q₁ (proj₁ u) , ins' l i q₂ (proj₂ u))
_∣_ : {I J : Set} → Fam I → Fam J → Fam (I ⊎ J)
X ∣ Y = [ X , Y ]′
PB : {A₁ A₂ I : Set} → (A₁ → I) → (A₂ → I) → Set
PB {A₁} {A₂} f g = Σ[ x ∈ A₁ × A₂ ] (f (proj₁ x) ≡ g (proj₂ x))
PB-idx : {A₁ A₂ I : Set} → (f : A₁ → I) → (g : A₂ → I) → (PB f g → I)
PB-idx f _ ((x₁ , x₂) , _) = f x₁
_⊎'_ : {I J K : Set} → DPoly {I} {J} → DPoly {I} {K} → DPoly {I} {J ⊎ K}
(dpoly A₁ s₁ B₁ p₁ t₁) ⊎' (dpoly A₂ s₂ B₂ p₂ t₂)
= dpoly A (PB-idx s₁ s₂) (U₁ ⊎ U₂) [ q₁ , q₂ ]′ (Sum.map (t₁ ∘ r₁) (t₂ ∘ r₂))
where
A = PB s₁ s₂
U₁ = PB {A} (proj₁ ∘ proj₁) p₁
U₂ = PB {A} (proj₂ ∘ proj₁) p₂
q₁ : U₁ → A
q₁ = proj₁ ∘ proj₁
q₂ : U₂ → A
q₂ = proj₁ ∘ proj₁
r₁ : U₁ → B₁
r₁ = proj₂ ∘ proj₁
r₂ : U₂ → B₂
r₂ = proj₂ ∘ proj₁
parametric-poly-by-sum : {I J K : Set} →
(P : DPoly {I} {J}) → (Q : DPoly {I} {K}) →
∀ X Y → (T P ×ᵢ' T Q)(X , Y) ≃' T (P ⊎' Q) (X ∣ Y)
parametric-poly-by-sum {I} {J} P Q X Y i =
record
{ f = f i
; f⃖ = g i
; is-invˡ = {!!}
; is-invʳ = {!!}
}
where
f : (i : I) → (T P ×ᵢ' T Q) (X , Y) i → T (P ⊎' Q) (X ∣ Y) i
f ._ (ins a v , y) = h a v (DPoly.s P a) refl y
where
h : (a : DPoly.A P)
(v : Π' (DPoly.p P) (λ e → X (DPoly.t P e)) a)
(i : I)
(p : DPoly.s P a ≡ i) →
T Q Y i → T (P ⊎' Q) (X ∣ Y) i
h a₁ v₁ ._ p (ins a₂ v₂) = ins' a₃ (DPoly.s Q a₂) p₃ v₃
where
a₃ : DPoly.A (P ⊎' Q)
a₃ = (a₁ , a₂) , p
p₃ : DPoly.s (P ⊎' Q) a₃ ≡ DPoly.s Q a₂
p₃ = trans refl p
v₃ : Π' (DPoly.p (P ⊎' Q)) (λ e → (X ∣ Y) (DPoly.t (P ⊎' Q) e)) a₃
v₃ = abs'' a₃ (v' a₃ refl)
where
v' : (u : DPoly.A (P ⊎' Q)) →
(a₁ , a₂) ≡ proj₁ u →
(i₁ : DPoly.E (P ⊎' Q)) →
DPoly.p (P ⊎' Q) i₁ ≡ u →
((X ∣ Y) (DPoly.t (P ⊎' Q) i₁))
v' u r (inj₁ ((.u , b) , q)) refl = v₁ (b , sym (trans (×-eqˡ r) q))
v' u r (inj₂ ((.u , b) , q)) refl = v₂ (b , sym (trans (×-eqʳ r) q))
g : (i : I) → T (P ⊎' Q) (X ∣ Y) i → (T P ×ᵢ' T Q) (X , Y) i
g ._ (ins x v) =
(ins (proj₁ (proj₁ x)) v₁
, ins' a₂ (DPoly.s P a₁) (sym (proj₂ x)) v₂)
where
a₁ = proj₁ (proj₁ x)
a₂ = proj₂ (proj₁ x)
v₁ : Π' (DPoly.p P) (((DPoly.t P) *) X) a₁
v₁ = abs'' a₁ (v₁' a₁ refl)
where
v₁' : (a : DPoly.A P) (p : a₁ ≡ a) (b : DPoly.E P) →
DPoly.p P b ≡ a → X (DPoly.t P b)
v₁' ._ p b refl = v ((inj₁ ((x , b) , p)) , refl)
v₂ : Π' (DPoly.p Q) (((DPoly.t Q) *) Y) a₂
v₂ = abs'' a₂ (v₂' a₂ refl)
where
v₂' : (a : DPoly.A Q) (p : a₂ ≡ a) (b : DPoly.E Q) →
DPoly.p Q b ≡ a → Y (DPoly.t Q b)
v₂' ._ p b refl = v ((inj₂ ((x , b) , p)) , refl)
{-
: {I J : Set} → (P : DPoly {I} {J}) → (Q : DPoly {I} {J}) →
let H = λ X Y → ⟦ P ⟧ X ×ᵢ ⟦ Q ⟧
in
-}
| {
"alphanum_fraction": 0.3837352776,
"avg_line_length": 28.9448051948,
"ext": "agda",
"hexsha": "aa298aad9f1aa907f2afeee9a232940635229b23",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "TypeTheory/Container/PolyFinalCoalg.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "TypeTheory/Container/PolyFinalCoalg.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "TypeTheory/Container/PolyFinalCoalg.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4375,
"size": 8915
} |
------------------------------------------------------------------------------
-- Properties related with lists (using induction on the FOTC lists type)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.List.PropertiesByInductionI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Base.List.PropertiesI
open import FOTC.Data.List
open import FOTC.Data.Nat.Type
------------------------------------------------------------------------------
-- Congruence properties
++-leftCong : ∀ {xs ys zs} → xs ≡ ys → xs ++ zs ≡ ys ++ zs
++-leftCong refl = refl
------------------------------------------------------------------------------
-- Totality properties
lengthList-N : ∀ {xs} → List xs → N (length xs)
lengthList-N = List-ind A A[] h
where
A : D → Set
A ds = N (length ds)
A[] : A []
A[] = subst N (sym length-[]) nzero
h : ∀ a {as} → A as → A (a ∷ as)
h a {as} Aas = subst N (sym (length-∷ a as)) (nsucc Aas)
------------------------------------------------------------------------------
++-leftIdentity : ∀ xs → [] ++ xs ≡ xs
++-leftIdentity = ++-[]
++-assoc : ∀ {xs} → List xs → ∀ ys zs → (xs ++ ys) ++ zs ≡ xs ++ ys ++ zs
++-assoc Lxs ys zs = List-ind A A[] h Lxs
where
A : D → Set
A as = (as ++ ys) ++ zs ≡ as ++ ys ++ zs
A[] : A []
A[] = ([] ++ ys) ++ zs ≡⟨ ++-leftCong (++-leftIdentity ys) ⟩
ys ++ zs ≡⟨ sym (++-leftIdentity (ys ++ zs)) ⟩
[] ++ ys ++ zs ∎
h : ∀ a {as} → A as → A (a ∷ as)
h a {as} Aas =
((a ∷ as) ++ ys) ++ zs ≡⟨ ++-leftCong (++-∷ a as ys) ⟩
(a ∷ (as ++ ys)) ++ zs ≡⟨ ++-∷ a (as ++ ys) zs ⟩
a ∷ ((as ++ ys) ++ zs) ≡⟨ ∷-rightCong Aas ⟩
a ∷ (as ++ ys ++ zs) ≡⟨ sym (++-∷ a as (ys ++ zs)) ⟩
(a ∷ as) ++ ys ++ zs ∎
| {
"alphanum_fraction": 0.4092261905,
"avg_line_length": 31.5,
"ext": "agda",
"hexsha": "850fddcb61c93c2d8e4b8c17cd3414b284566cfd",
"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/List/PropertiesByInductionI.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/List/PropertiesByInductionI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/List/PropertiesByInductionI.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": 613,
"size": 2016
} |
module Thesis.BigStepSILR2 where
open import Data.Empty
open import Data.Unit.Base hiding (_≤_)
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Relation.Binary hiding (_⇒_)
open import Data.Nat -- using (ℕ; zero; suc; decTotalOrder; _<_; _≤_)
open import Data.Nat.Properties
open import Thesis.FunBigStepSILR2
-- Standard relational big-step semantics, with step-indexes matching a small-step semantics.
-- Protip: doing this on ANF terms would be much easier.
data _⊢_↓[_]_ {Γ} (ρ : ⟦ Γ ⟧Context) : ∀ {τ} → Term Γ τ → ℕ → Val τ → Set where
abs : ∀ {τ₁ τ₂} {t : Term (τ₁ • Γ) τ₂} →
ρ ⊢ abs t ↓[ 0 ] closure t ρ
app : ∀ n1 n2 n3 {Γ′ τ₁ τ₂ ρ′ v₂ v′} {t₁ : Term Γ (τ₁ ⇒ τ₂)} {t₂ : Term Γ τ₁} {t′ : Term (τ₁ • Γ′) τ₂} →
ρ ⊢ t₁ ↓[ n1 ] closure t′ ρ′ →
ρ ⊢ t₂ ↓[ n2 ] v₂ →
(v₂ • ρ′) ⊢ t′ ↓[ n3 ] v′ →
ρ ⊢ app t₁ t₂ ↓[ suc n1 + n2 + n3 ] v′
var : ∀ {τ} (x : Var Γ τ) →
ρ ⊢ var x ↓[ 0 ] (⟦ x ⟧Var ρ)
lit : ∀ n →
ρ ⊢ const (lit n) ↓[ 0 ] intV n
-- Silly lemmas for eval-dec-sound
module _ where
Done-inj : ∀ {τ} m n {v1 v2 : Val τ} → Done v1 m ≡ Done v2 n → m ≡ n
Done-inj _ _ refl = refl
lem1 : ∀ n d → d ≢ suc (n + d)
lem1 n d eq rewrite +-comm n d = m≢1+m+n d eq
subd : ∀ n d → n + d ≡ d → n ≡ 0
subd zero d eq = refl
subd (suc n) d eq = ⊥-elim (lem1 n d (sym eq))
comp∸ : ∀ a b → b ≤ a → suc a ∸ b ≡ suc (a ∸ b)
comp∸ a zero le = refl
comp∸ zero (suc b) ()
comp∸ (suc a) (suc b) (s≤s le) = comp∸ a b le
rearr∸ : ∀ a b c → c ≤ b → a + (b ∸ c) ≡ (a + b) ∸ c
rearr∸ a b zero c≤b = refl
rearr∸ a zero (suc c) ()
rearr∸ a (suc b) (suc c) (s≤s c≤b) rewrite +-suc a b = rearr∸ a b c c≤b
cancel∸ : ∀ a b → b ≤ a → a ∸ b + b ≡ a
cancel∸ a zero b≤a = +-identityʳ a
cancel∸ zero (suc b) ()
cancel∸ (suc a) (suc b) (s≤s b≤a) rewrite +-suc (a ∸ b) b = cong suc (cancel∸ a b b≤a)
lemR : ∀ {τ} n m {v1 v2 : Val τ} → Done v1 m ≡ Done v2 n → m ≡ n
lemR n .n refl = refl
lem2 : ∀ n n3 r → n3 ≤ n → n + n3 ≡ suc r → ∃ λ s → (n ≡ suc s)
lem2 zero .0 r z≤n ()
lem2 (suc n) n3 .(n + n3) le refl = n , refl
{-# TERMINATING #-}
eval-dec-sound : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ v m n → eval t ρ m ≡ Done v n → ρ ⊢ t ↓[ m ∸ n ] v
eval-dec-sound (const (lit x)) ρ (intV v) m n eq with lemR n m eq
eval-dec-sound (const (lit x)) ρ (intV .x) m .m refl | refl rewrite n∸n≡0 m = lit x
eval-dec-sound (var x) ρ v m n eq with lemR n m eq
eval-dec-sound (var x) ρ .(⟦ x ⟧Var ρ) m .m refl | refl rewrite n∸n≡0 m = var x
eval-dec-sound (abs t) ρ v m n eq with lemR n m eq
eval-dec-sound (abs t) ρ .(closure t ρ) m .m refl | refl rewrite n∸n≡0 m = abs
eval-dec-sound (app s t) ρ v zero n ()
eval-dec-sound (app s t) ρ v (suc r) n eq with eval s ρ r | inspect (eval s ρ) r
eval-dec-sound (app s t) ρ v (suc r) n eq | (Done sv n1) | [ seq ] with eval t ρ n1 | inspect (eval t ρ) n1
eval-dec-sound (app s t) ρ v (suc r) n eq | (Done (closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] with eval st (tv • sρ) n2 | inspect (eval st (tv • sρ)) n2
eval-dec-sound (app s t) ρ .v (suc r) .n3 refl | (Done sv@(closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] | (Done v n3) | [ veq ] = body
where
n1≤r : n1 ≤ r
n1≤r = eval-dec s ρ sv r n1 seq
n2≤n1 : n2 ≤ n1
n2≤n1 = eval-dec t ρ tv n1 n2 teq
n3≤n2 : n3 ≤ n2
n3≤n2 = eval-dec st (tv • sρ) v n2 n3 veq
eval1 = eval-dec-sound s ρ sv r n1 seq
eval2 = eval-dec-sound t ρ tv n1 n2 teq
eval3 = eval-dec-sound st (tv • sρ) v n2 n3 veq
l1 : suc r ∸ n3 ≡ suc (r ∸ n3)
l1 = comp∸ r n3 (≤-trans n3≤n2 (≤-trans n2≤n1 n1≤r))
l2 : suc r ∸ n3 ≡ suc (((r ∸ n1) + (n1 ∸ n2)) + (n2 ∸ n3))
l2
rewrite rearr∸ (r ∸ n1) n1 n2 n2≤n1 | cancel∸ r n1 n1≤r
| rearr∸ (r ∸ n2) n2 n3 n3≤n2 | cancel∸ r n2 (≤-trans n2≤n1 n1≤r) = l1
foo : ρ ⊢ app s t ↓[ suc (r ∸ n1 + (n1 ∸ n2) + (n2 ∸ n3)) ] v
foo = app (r ∸ n1) (n1 ∸ n2) (n2 ∸ n3) {t₁ = s} {t₂ = t} {t′ = st} eval1 eval2 eval3
body : ρ ⊢ app s t ↓[ suc r ∸ n3 ] v
body rewrite l2 = foo
eval-dec-sound (app s t) ρ v (suc r) n () | (Done (closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] | Error | [ veq ]
eval-dec-sound (app s t) ρ v (suc r) n () | (Done (closure st sρ) n1) | [ seq ] | (Done tv n2) | [ teq ] | TimeOut | [ veq ]
eval-dec-sound (app s t) ρ v (suc r) n () | (Done sv n1) | [ seq ] | Error | [ teq ]
eval-dec-sound (app s t) ρ v (suc r) n () | (Done sv n1) | [ seq ] | TimeOut | [ teq ]
eval-dec-sound (app s t) ρ v (suc r) n () | Error | [ seq ]
eval-dec-sound (app s t) ρ v (suc r) n () | TimeOut | [ seq ]
-- ↦-sound : ∀ {Γ τ} ρ (x : Var Γ τ) →
-- ((Den.⟦ x ⟧Var) (⟦ ρ ⟧Context)) ≡ (⟦ (⟦ x ⟧Var) ρ ⟧Val)
-- ↦-sound (px • ρ) this = refl
-- ↦-sound (px • ρ) (that x) = ↦-sound ρ x
-- ↓-sound : ∀ {Γ τ ρ v} {t : Term Γ τ} →
-- ρ ⊢ t ↓ v →
-- ⟦ t ⟧Term ⟦ ρ ⟧Env ≡ ⟦ v ⟧Val
-- ↓-sound abs = refl
-- ↓-sound (app ↓₁ ↓₂ ↓′) rewrite ↓-sound ↓₁ | ↓-sound ↓₂ | ↓-sound ↓′ = refl
-- ↓-sound (var x) = ↦-sound _ x
-- ↓-sound (lit n) = refl
import Data.Integer as I
open I using (ℤ)
-- The extra "r" stands for "relational", because unlike relT and relV, rrelV
-- and rrelT are based on a *relational* big-step semantics.
mutual
rrelT : ∀ {τ Γ} (t1 : Term Γ τ) (t2 : Term Γ τ) (ρ1 : ⟦ Γ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
rrelT {τ} t1 t2 ρ1 ρ2 k =
(v1 : Val τ) →
∀ j (j<k : j < k) →
(ρ1⊢t1↓[j]v1 : ρ1 ⊢ t1 ↓[ j ] v1) →
Σ[ v2 ∈ Val τ ] Σ[ n2 ∈ ℕ ] ρ2 ⊢ t2 ↓[ n2 ] v2 × rrelV τ v1 v2 (k ∸ j)
rrelV : ∀ τ (v1 v2 : Val τ) → ℕ → Set
rrelV nat (intV v1) (intV v2) n = Σ[ dv ∈ ℤ ] dv I.+ (I.+ v1) ≡ (I.+ v2)
rrelV (σ ⇒ τ) (closure {Γ1} t1 ρ1) (closure {Γ2} t2 ρ2) n =
Σ (Γ1 ≡ Γ2) λ { refl →
∀ (k : ℕ) (k<n : k < n) v1 v2 →
(vv : rrelV σ v1 v2 k) →
rrelT t1 t2 (v1 • ρ1) (v2 • ρ2) k
}
rrelρ : ∀ Γ (ρ1 ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
rrelρ ∅ ∅ ∅ n = ⊤
rrelρ (τ • Γ) (v1 • ρ1) (v2 • ρ2) n = rrelV τ v1 v2 n × rrelρ Γ ρ1 ρ2 n
⟦_⟧RelVar : ∀ {Γ τ n} (x : Var Γ τ) {ρ1 ρ2 : ⟦ Γ ⟧Context} →
rrelρ Γ ρ1 ρ2 n →
rrelV τ (⟦ x ⟧Var ρ1) (⟦ x ⟧Var ρ2) n
⟦ this ⟧RelVar {v1 • ρ1} {v2 • ρ2} (vv , ρρ) = vv
⟦ that x ⟧RelVar {v1 • ρ1} {v2 • ρ2} (vv , ρρ) = ⟦ x ⟧RelVar ρρ
rrelV-mono : ∀ m n → m ≤ n → ∀ τ v1 v2 → rrelV τ v1 v2 n → rrelV τ v1 v2 m
rrelV-mono m n m≤n nat (intV v1) (intV v2) vv = vv
rrelV-mono m n m≤n (σ ⇒ τ) (closure t1 ρ1) (closure t2 ρ2) (refl , ff) = refl , λ k k≤m → ff k (≤-trans k≤m m≤n)
rrelρ-mono : ∀ m n → m ≤ n → ∀ Γ ρ1 ρ2 → rrelρ Γ ρ1 ρ2 n → rrelρ Γ ρ1 ρ2 m
rrelρ-mono m n m≤n ∅ ∅ ∅ tt = tt
rrelρ-mono m n m≤n (τ • Γ) (v1 • ρ1) (v2 • ρ2) (vv , ρρ) = rrelV-mono m n m≤n _ v1 v2 vv , rrelρ-mono m n m≤n Γ ρ1 ρ2 ρρ
rfundamentalV : ∀ {Γ τ} (x : Var Γ τ) → (n : ℕ) → (ρ1 ρ2 : ⟦ Γ ⟧Context) (ρρ : rrelρ Γ ρ1 ρ2 n) → rrelT (var x) (var x) ρ1 ρ2 n
rfundamentalV x n ρ1 ρ2 ρρ .(⟦ x ⟧Var ρ1) .0 j<n (var .x) = ⟦ x ⟧Var ρ2 , 0 , (var x) , ⟦ x ⟧RelVar ρρ
bar : ∀ m {n o} → o ≤ n → m ≤ (m + n) ∸ o
bar m {n} {o} o≤n rewrite +-∸-assoc m o≤n = m≤m+n m (n ∸ o)
suc∸ : ∀ m n → n ≤ m → suc (m ∸ n) ≡ suc m ∸ n
suc∸ m zero z≤n = refl
suc∸ (suc m) (suc n) (s≤s n≤m) = suc∸ m n n≤m
suc∸suc : ∀ m n → n < m → suc (m ∸ suc n) ≡ m ∸ n
suc∸suc (suc m) zero (s≤s n<m) = refl
suc∸suc (suc m) (suc n) (s≤s n<m) = suc∸suc m n n<m
m≡m∸1+1 : ∀ m {n} → n < m → m ≡ suc (m ∸ 1)
m≡m∸1+1 (suc m) (s≤s n<m) = refl
m∸[n+1]<m : ∀ m n → n < m → m ∸ suc n < m
m∸[n+1]<m (suc m) zero (s≤s n<m) = s≤s ≤-refl
m∸[n+1]<m (suc m) (suc n) (s≤s n<m) rewrite sym (suc∸suc m n n<m) = ≤-step (m∸[n+1]<m m n n<m)
sub∸ : ∀ m n o → m + n ≤ o → n ≤ o ∸ m
sub∸ m n o n+m≤o rewrite +-comm m n | cong (_≤ o ∸ m) (sym (m+n∸n≡m n m)) = ∸-mono n+m≤o (≤-refl {m})
rfundamental : ∀ {Γ τ} (t : Term Γ τ) → (n : ℕ) → (ρ1 ρ2 : ⟦ Γ ⟧Context) (ρρ : rrelρ Γ ρ1 ρ2 n) → rrelT t t ρ1 ρ2 n
rfundamental (var x) n ρ1 ρ2 ρρ = rfundamentalV x n ρ1 ρ2 ρρ
rfundamental (const (lit x)) n ρ1 ρ2 ρρ .(intV x) .0 j<n (lit .x) = intV x , 0 , lit x , I.+ 0 , refl
rfundamental (abs t) n ρ1 ρ2 ρρ .(closure t ρ1) .0 j<n abs = closure t ρ2 , 0 , abs , refl , (λ k k<n v1 v2 vv v3 j j<k ρ1⊢t1↓[j]v1 → rfundamental t k (v1 • ρ1) (v2 • ρ2) (vv , rrelρ-mono k n (lt1 k<n) _ _ _ ρρ) v3 j j<k ρ1⊢t1↓[j]v1 )
rfundamental (app s t) n ρ1 ρ2 ρρ v1 .(suc (n1 + n2 + n3)) 1+n1+n2+n3<n (app n1 n2 n3 ρ1⊢t1↓[j]v1 ρ1⊢t1↓[j]v2 ρ1⊢t1↓[j]v3) = body
where
open ≤-Reasoning
n1≤sum : n1 ≤ n1 + n2 + n3
n1≤sum rewrite +-assoc n1 n2 n3 = m≤m+n n1 (n2 + n3)
n1<n : n1 < n
n1<n = ≤-trans (s≤s (≤-step n1≤sum)) 1+n1+n2+n3<n
n2≤sum : n2 ≤ n1 + n2 + n3
n2≤sum rewrite +-assoc n1 n2 n3 = ≤-steps {n2} {n2 + n3} n1 (m≤m+n n2 n3)
n2<n : n2 < n
n2<n = ≤-trans (s≤s (≤-step n2≤sum)) 1+n1+n2+n3<n
n1+n2<n : n1 + n2 < n
n1+n2<n = ≤-trans (s≤s (≤-step (m≤m+n (n1 + n2) n3))) 1+n1+n2+n3<n
n2+n1<n : n2 + n1 < n
n2+n1<n rewrite +-comm n2 n1 = n1+n2<n
n1+n3≤sum : n1 + n3 ≤ (n1 + n2) + n3
n1+n3≤sum = m≤m+n n1 n2 +-mono (≤-refl {n3})
foo : suc n2 ≡ suc (n1 + n2 + n3) ∸ (n1 + n3)
foo rewrite cong suc (sym (m+n∸n≡m n2 (n1 + n3))) | sym (+-assoc n2 n1 n3) | +-comm n2 n1 = suc∸ (n1 + n2 + n3) (n1 + n3) n1+n3≤sum
n2<n∸n1 : n2 < n ∸ n1
n2<n∸n1 rewrite foo = ∸-mono {suc (n1 + n2 + n3)} {n} {n1 + n3} {n1} (lt1 1+n1+n2+n3<n) (m≤m+n n1 n3)
n-[1+n1+n2]<n-n1 : n ∸ n1 ∸ suc n2 < n ∸ n1
n-[1+n1+n2]<n-n1 = m∸[n+1]<m (n ∸ n1) n2 n2<n∸n1
n-[1+n1+n2]<n-n2 : n ∸ n1 ∸ suc n2 < n ∸ n2
n-[1+n1+n2]<n-n2 rewrite ∸-+-assoc n n1 (suc n2) | +-suc n1 n2 | +-comm n1 n2 | suc∸suc n (n2 + n1) n2+n1<n | sym (∸-+-assoc n n2 n1) = n∸m≤n n1 (n ∸ n2)
baz : n1 + suc (n2 + suc n3) ≤ n
baz rewrite +-suc n2 n3 | +-suc n1 (suc (n2 + n3)) | +-suc n1 (n2 + n3) | +-assoc n1 n2 n3 = 1+n1+n2+n3<n
n3<n-n1-[1+n2] : n3 < n ∸ n1 ∸ suc n2
n3<n-n1-[1+n2] = sub∸ (suc n2) (suc n3) (n ∸ n1) (sub∸ n1 (suc (n2 + suc n3)) n baz)
l1 : suc (n1 + n2 + n3) ≡ n1 + suc n2 + n3
l1 = cong (_+ n3) (sym (+-suc n1 n2))
n-1+sum≡alt : n ∸ suc (n1 + n2 + n3) ≡ n ∸ n1 ∸ suc n2 ∸ n3
n-1+sum≡alt rewrite l1 | sym (∸-+-assoc n (n1 + suc n2) n3) | sym (∸-+-assoc n n1 (suc n2)) = refl
body : Σ[ v2 ∈ Val _ ] Σ[ tn ∈ ℕ ] ρ2 ⊢ app s t ↓[ tn ] v2 × rrelV _ v1 v2 (n ∸ suc (n1 + n2 + n3))
body with rfundamental s n ρ1 ρ2 ρρ _ n1 n1<n ρ1⊢t1↓[j]v1 | rfundamental t n ρ1 ρ2 ρρ _ n2 n2<n ρ1⊢t1↓[j]v2
... | sv2@(closure st2 sρ2) , sn2 , ρ2⊢s↓ , refl , sv1v2 | tv2 , tn2 , ρ2⊢t↓ , tv1v2 with sv1v2 (n ∸ n1 ∸ suc n2) n-[1+n1+n2]<n-n1 _ tv2 (rrelV-mono (n ∸ n1 ∸ suc n2) (n ∸ n2) (lt1 n-[1+n1+n2]<n-n2) _ _ tv2 tv1v2) v1 n3 n3<n-n1-[1+n2] ρ1⊢t1↓[j]v3
... | v2 , stn , ρ2⊢st2↓ , vv rewrite n-1+sum≡alt = v2 , suc (sn2 + tn2 + stn) , app _ _ _ ρ2⊢s↓ ρ2⊢t↓ ρ2⊢st2↓ , vv
mutual
rrelT3 : ∀ {τ Γ ΔΓ} (t1 : Term Γ τ) (dt : Term ΔΓ (Δτ τ)) (t2 : Term Γ τ) (ρ1 : ⟦ Γ ⟧Context) (dρ : ⟦ ΔΓ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
rrelT3 {τ} t1 dt t2 ρ1 dρ ρ2 k =
(v1 v2 : Val τ) →
∀ j n2 (j<k : j < k) →
(ρ1⊢t1↓[j]v1 : ρ1 ⊢ t1 ↓[ j ] v1) →
(ρ2⊢t2↓[n2]v2 : ρ2 ⊢ t2 ↓[ n2 ] v2) →
Σ[ dv ∈ Val (Δτ τ) ] Σ[ dn ∈ ℕ ]
dρ ⊢ dt ↓[ dn ] dv ×
rrelV3 τ v1 dv v2 (k ∸ j)
rrelV3 : ∀ τ (v1 : Val τ) (dv : Val (Δτ τ)) (v2 : Val τ) → ℕ → Set
rrelV3 nat (intV v1) (intV dv) (intV v2) n = dv + v1 ≡ v2
-- XXX What we want for rrelV3:
-- rrelV3 (σ ⇒ τ) (closure {Γ1} t1 ρ1) (dclosure dt dρ) (closure {Γ2} t2 ρ2) n =
-- Σ (Γ1 ≡ Γ2) λ { refl →
-- ∀ (k : ℕ) (k<n : k < n) v1 dv v2 →
-- rrelV3 σ v1 dv v2 k →
-- rrelT3
-- t1
-- dt
-- t2
-- (v1 • ρ1)
-- (dv • v1 • dρ)
-- (v2 • ρ2) k
-- }
-- However, we don't have separate change values, so we write:
rrelV3 (σ ⇒ τ) (closure {Γ1} t1 ρ1) (closure dt' dρ) (closure {Γ2} t2 ρ2) n =
-- Require a proof that the two contexts match:
Σ (Γ1 ≡ Γ2) λ { refl →
∀ (k : ℕ) (k<n : k < n) v1 dv v2 →
rrelV3 σ v1 dv v2 k →
rrelT3
t1
-- XXX The next expression is wrong.
-- rrelV3 should require dv to be a change closure,
-- (λ x dx . dt , dρ) or (dclosure dt dρ).
-- Then, here we could write as conclusion.
-- rrelT3 t1 dt t2 (v1 • ρ1) (dv • v1 • dρ) (v2 • ρ2) k
-- Instead, with this syntax I can just match dv as a normal closure,
-- closure dt' dρ or (λ x . dt', dρ), where we hope that dt' evaluates
-- to λ dx. dt. So, instead of writing dt, I must write dt' dx where
-- dx is a newly bound variable (hence, var this), and dt' must be
-- weakened once. Hence, we write instead:
(app (weaken (drop (Δτ σ) • ≼-refl) dt') (var this))
t2
(v1 • ρ1)
(dv • v1 • dρ)
(v2 • ρ2)
k
}
ΔΓ : Context → Context
ΔΓ ∅ = ∅
ΔΓ (τ • Γ) = Δτ τ • ΔΓ Γ
rrelρ3 : ∀ Γ (ρ1 : ⟦ Γ ⟧Context) (dρ : ⟦ ΔΓ Γ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
rrelρ3 ∅ ∅ ∅ ∅ n = ⊤
rrelρ3 (τ • Γ) (v1 • ρ1) (dv • dρ) (v2 • ρ2) n = rrelV3 τ v1 dv v2 n × rrelρ3 Γ ρ1 dρ ρ2 n
derive-var : ∀ {Γ τ} → Var Γ τ → Var (ΔΓ Γ) (Δτ τ)
derive-var this = this
derive-var (that x) = that (derive-var x)
⟦_⟧RelVar3 : ∀ {Γ τ n} (x : Var Γ τ)
{ρ1 : ⟦ Γ ⟧Context} {dρ : ⟦ ΔΓ Γ ⟧Context} {ρ2 : ⟦ Γ ⟧Context} →
rrelρ3 Γ ρ1 dρ ρ2 n →
rrelV3 τ (⟦ x ⟧Var ρ1) (⟦ derive-var x ⟧Var dρ) (⟦ x ⟧Var ρ2) n
⟦ this ⟧RelVar3 {v1 • ρ1} {dv • dρ} {v2 • ρ2} (vv , ρρ) = vv
⟦ that x ⟧RelVar3 {v1 • ρ1} {dv • dρ} {v2 • ρ2} (vv , ρρ) = ⟦ x ⟧RelVar3 ρρ
rfundamentalV3 : ∀ {Γ τ} (x : Var Γ τ) → (n : ℕ) → (ρ1 : ⟦ Γ ⟧Context) (dρ : ⟦ ΔΓ Γ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) (ρρ : rrelρ3 Γ ρ1 dρ ρ2 n) → rrelT3 (var x) (var (derive-var x)) (var x) ρ1 dρ ρ2 n
rfundamentalV3 x n ρ1 dρ ρ2 ρρ .(⟦ x ⟧Var ρ1) .(⟦ x ⟧Var ρ2) .0 .0 j<n (var .x) (var .x) = ⟦ derive-var x ⟧Var dρ , 0 , (var (derive-var x)) , ⟦ x ⟧RelVar3 ρρ
| {
"alphanum_fraction": 0.5082644628,
"avg_line_length": 45.6754966887,
"ext": "agda",
"hexsha": "620997825cd0e676e23345fdb9058507ca035ea0",
"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/BigStepSILR2.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/BigStepSILR2.agda",
"max_line_length": 251,
"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/BigStepSILR2.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": 7282,
"size": 13794
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Homomorphisms.Definition
open import Groups.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.Homomorphisms.Definition
open import Groups.Homomorphisms.Lemmas
open import Groups.Subgroups.Definition
open import Rings.Cosets
open import Groups.Lemmas
open import Setoids.Functions.Lemmas
open import Rings.Ideals.Definition
module Rings.Ideals.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} (R : Ring S _+_ _*_) where
open import Rings.Divisible.Definition R
idealPredForKernel : {c d : _} {C : Set c} {T : Setoid {c} {d} C} {_+2_ _*2_ : C → C → C} (R2 : Ring T _+2_ _*2_) {f : A → C} (fHom : RingHom R R2 f) → A → Set d
idealPredForKernel {T = T} R2 {f} fHom a = Setoid._∼_ T (f a) (Ring.0R R2)
idealPredForKernelWellDefined : {c d : _} {C : Set c} {T : Setoid {c} {d} C} {_+2_ _*2_ : C → C → C} (R2 : Ring T _+2_ _*2_) {f : A → C} (fHom : RingHom R R2 f) → {x y : A} → (Setoid._∼_ S x y) → (idealPredForKernel R2 fHom x → idealPredForKernel R2 fHom y)
idealPredForKernelWellDefined {T = T} R2 {f} fHom a x=0 = Equivalence.transitive (Setoid.eq T) (GroupHom.wellDefined (RingHom.groupHom fHom) (Equivalence.symmetric (Setoid.eq S) a)) x=0
kernelIdealIsIdeal : {c d : _} {C : Set c} {T : Setoid {c} {d} C} {_+2_ _*2_ : C → C → C} {R2 : Ring T _+2_ _*2_} {f : A → C} (fHom : RingHom R R2 f) → Ideal R (idealPredForKernel R2 fHom)
Subgroup.isSubset (Ideal.isSubgroup (kernelIdealIsIdeal {R2 = R2} fHom)) = idealPredForKernelWellDefined R2 fHom
Subgroup.closedUnderPlus (Ideal.isSubgroup (kernelIdealIsIdeal {T = T} {R2 = R2} fHom)) {x} {y} fx=0 fy=0 = transitive (transitive (GroupHom.groupHom (RingHom.groupHom fHom)) (+WellDefined fx=0 fy=0)) identLeft
where
open Ring R2
open Group (Ring.additiveGroup R2)
open Setoid T
open Equivalence eq
Subgroup.containsIdentity (Ideal.isSubgroup (kernelIdealIsIdeal fHom)) = imageOfIdentityIsIdentity (RingHom.groupHom fHom)
Subgroup.closedUnderInverse (Ideal.isSubgroup (kernelIdealIsIdeal {T = T} {R2 = R2} fHom)) {x} fx=0 = zeroImpliesInverseZero (RingHom.groupHom fHom) fx=0
where
open Ring R2
open Group (Ring.additiveGroup R2)
open Setoid T
open Equivalence eq
Ideal.accumulatesTimes (kernelIdealIsIdeal {T = T} {R2 = R2} {f = f} fHom) {x} {y} fx=0 = transitive (RingHom.ringHom fHom) (transitive (Ring.*WellDefined R2 fx=0 reflexive) (transitive (Ring.*Commutative R2) (Ring.timesZero R2 {f y})))
where
open Setoid T
open Equivalence eq
open Ring R
open Group additiveGroup
open Setoid S
open Equivalence eq
translate : {c : _} {pred : A → Set c} → (i : Ideal R pred) → {a : A} → pred a → pred (inverse (Ring.0R (cosetRing R i)) + a)
translate {a} i predA = Ideal.isSubset i (transitive (symmetric identLeft) (+WellDefined (symmetric (invIdent additiveGroup)) reflexive)) predA
translate' : {c : _} {pred : A → Set c} → (i : Ideal R pred) → {a : A} → pred (inverse (Ring.0R (cosetRing R i)) + a) → pred a
translate' i = Ideal.isSubset i (transitive (+WellDefined (invIdent additiveGroup) reflexive) identLeft)
inverseImageIsIdeal : {c d : _} {C : Set c} {T : Setoid {c} {d} C} {_+2_ _*2_ : C → C → C} {R2 : Ring T _+2_ _*2_} {f : C → A} (fHom : RingHom R2 R f) → {e : _} {pred : A → Set e} → (i : Ideal R pred) → Ideal R2 (inverseImagePred {S = T} {S} {f} (GroupHom.wellDefined (RingHom.groupHom fHom)) (Ideal.isSubset i))
Subgroup.isSubset (Ideal.isSubgroup (inverseImageIsIdeal {T = T} fHom i)) = inverseImageWellDefined {S = T} {S} (GroupHom.wellDefined (RingHom.groupHom fHom)) (Ideal.isSubset i)
Subgroup.closedUnderPlus (Ideal.isSubgroup (inverseImageIsIdeal fHom i)) {g} {h} (c , (prC ,, fg=c)) (d , (prD ,, fh=d)) = (c + d) , (Ideal.closedUnderPlus i prC prD ,, transitive (GroupHom.groupHom (RingHom.groupHom fHom)) (+WellDefined fg=c fh=d))
Subgroup.containsIdentity (Ideal.isSubgroup (inverseImageIsIdeal fHom i)) = 0G , (Ideal.containsIdentity i ,, imageOfIdentityIsIdentity (RingHom.groupHom fHom))
Subgroup.closedUnderInverse (Ideal.isSubgroup (inverseImageIsIdeal fHom i)) (a , (prA ,, fg=a)) = inverse a , (Ideal.closedUnderInverse i prA ,, transitive (homRespectsInverse (RingHom.groupHom fHom)) (inverseWellDefined additiveGroup fg=a))
Ideal.accumulatesTimes (inverseImageIsIdeal {_*2_ = _*2_} {f = f} fHom i) {g} {h} (a , (prA ,, fg=a)) = (a * f h) , (Ideal.accumulatesTimes i prA ,, transitive (RingHom.ringHom fHom) (*WellDefined fg=a reflexive))
memberDividesImpliesMember : {a b : A} → {c : _} → {pred : A → Set c} → (i : Ideal R pred) → pred a → a ∣ b → pred b
memberDividesImpliesMember {a} {b} i pA (s , as=b) = Ideal.isSubset i as=b (Ideal.accumulatesTimes i pA)
generatorZeroImpliesMembersZero : {x : A} → generatedIdealPred R 0R x → x ∼ 0R
generatorZeroImpliesMembersZero {x} (a , b) = transitive (symmetric b) (transitive *Commutative timesZero)
| {
"alphanum_fraction": 0.6962635597,
"avg_line_length": 71.1142857143,
"ext": "agda",
"hexsha": "e4cb81569055fb728bdeb42f78a01842a02381f1",
"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": "Rings/Ideals/Lemmas.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": "Rings/Ideals/Lemmas.agda",
"max_line_length": 312,
"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": "Rings/Ideals/Lemmas.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": 1748,
"size": 4978
} |
------------------------------------------------------------------------------
-- Propositional equality
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Tested with the development version of Agda on 15 June 2012.
module FOT.Agsy.NoStd.MyPropositionalEquality where
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Relation/Binary/Core.agda).
infix 7 _≡_
------------------------------------------------------------------------------
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
-- Identity properties
sym : ∀ {A} → {x y : A} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {A} → {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl y≡z = y≡z
cong : {A B : Set} (f : A → B) → ∀ {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
module ≡-Reasoning where
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Relation/Binary/PreorderReasoning.agda).
infix 7 _≃_
infix 4 begin_
infixr 5 _≡⟨_⟩_
infix 6 _∎
----------------------------------------------------------------------------
-- Adapted from the Agda standard library 0.8.1 (see
-- Relation/Binary/PreorderReasoning.agda).
private
data _≃_ {A : Set}(x y : A) : Set where
prf : x ≡ y → x ≃ y
begin_ : {A : Set}{x y : A} → x ≃ y → x ≡ y
begin prf x≡y = x≡y
_≡⟨_⟩_ : {A : Set}(x : A){y z : A} → x ≡ y → y ≃ z → x ≃ z
_ ≡⟨ x≡y ⟩ prf y≡z = prf (trans x≡y y≡z)
_∎ : {A : Set}(x : A) → x ≃ x
_∎ _ = prf refl
| {
"alphanum_fraction": 0.4467956469,
"avg_line_length": 29.0175438596,
"ext": "agda",
"hexsha": "40474964409be21fdda7f556a396e0a38fc75f83",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/Agsy/NoStd/MyPropositionalEquality.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/Agsy/NoStd/MyPropositionalEquality.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": "notes/FOT/Agsy/NoStd/MyPropositionalEquality.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": 556,
"size": 1654
} |
{-
Importing and re-exporting this module allows for (constrained) natural number
and negative integer literals for any type (e.g. Int, ℕ₋₁, ℕ₋₂, ℕ₊₁).
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.Nat.Literals where
open import Agda.Builtin.FromNat public
renaming (Number to HasFromNat)
open import Agda.Builtin.FromNeg public
renaming (Negative to HasFromNeg)
open import Cubical.Data.Unit.Base public
-- Natural number literals for ℕ
open import Agda.Builtin.Nat renaming (Nat to ℕ)
instance
fromNatℕ : HasFromNat ℕ
fromNatℕ = record { Constraint = λ _ → Unit ; fromNat = λ n → n }
| {
"alphanum_fraction": 0.7323076923,
"avg_line_length": 28.2608695652,
"ext": "agda",
"hexsha": "edb52ea0ef8846a7b1dddaf0fe08035e5c65810d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Nat/Literals.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/Nat/Literals.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Nat/Literals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 184,
"size": 650
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.LoopSpaceCircle
-- This file is temporarily put in the cw/ directory for
-- development, but it actually belongs to somewhere else.
module homotopy.SphereEndomorphism where
⊙SphereS-endo-out : ∀ n
→ Trunc 0 (⊙Sphere (S n) ⊙→ ⊙Sphere (S n))
→ Trunc 0 ( Sphere (S n) → Sphere (S n))
⊙SphereS-endo-out n = Trunc-rec Trunc-level ([_] ∘ fst)
-- For [S¹], the pointedness is free because of the commutativity of its loop space.
-- favonia: maybe one can simplify the proofs through
-- an intermediate type [Σ S¹ (λ x → x == x)]?
private
⊙S¹-endo-in'' : (base* : S¹) (loop* : base* == base*) → (⊙S¹ ⊙→ ⊙S¹)
⊙S¹-endo-in'' = S¹-elim
(λ loop* → S¹-rec base loop* , idp)
(↓-app→cst-in λ r → ap (λ loop* → (S¹-rec base loop* , idp)) (lemma₀ r)) where
abstract
lemma₀ : ∀ {loop₁ loop₂}
→ loop₁ == loop₂ [ (λ x → x == x) ↓ loop ]
→ loop₁ == loop₂
lemma₀ {loop₁} {loop₂} p = anti-whisker-right loop $
loop₁ ∙ loop
=⟨ ↓-idf=idf-out' p ⟩
loop ∙' loop₂
=⟨ ∙'=∙ loop loop₂ ⟩
loop ∙ loop₂
=⟨ ΩS¹-is-abelian loop loop₂ ⟩
loop₂ ∙ loop
=∎
⊙S¹-endo-in' : (S¹ → S¹) → (⊙S¹ ⊙→ ⊙S¹)
⊙S¹-endo-in' f = ⊙S¹-endo-in'' (f base) (ap f loop)
⊙S¹-endo-in : Trunc 0 (S¹ → S¹) → Trunc 0 (⊙S¹ ⊙→ ⊙S¹)
⊙S¹-endo-in = Trunc-fmap ⊙S¹-endo-in'
abstract
⊙S¹-endo-in-η : ∀ f → ⊙S¹-endo-in (⊙SphereS-endo-out 0 f) == f
⊙S¹-endo-in-η = Trunc-elim (λ _ → =-preserves-set Trunc-level)
λ{(f , pt) → ap [_] $
⊙S¹-endo-in''-shifted pt (ap f loop) ∙ ⊙λ= (S¹-rec-η f) idp}
where
-- free one end to apply identification elimination
⊙S¹-endo-in''-shifted : {base* : S¹}
(shift : base* == base) (loop* : base* == base*)
→ ⊙S¹-endo-in'' base* loop* == (S¹-rec base* loop* , shift)
⊙S¹-endo-in''-shifted idp _ = idp
⊙S¹-endo-out-β : ∀ f → ⊙SphereS-endo-out 0 (⊙S¹-endo-in f) == f
⊙S¹-endo-out-β = Trunc-elim (λ _ → =-preserves-level Trunc-level)
λ f → ! (ap (λ f → [ fst (⊙S¹-endo-in' f) ]) (λ= $ S¹-rec-η f))
∙ ⊙S¹-endo-out'-β (f base) (ap f loop)
∙ ap [_] (λ= $ S¹-rec-η f)
where
-- free [base*] to apply circle elimination
⊙S¹-endo-out'-β : (base* : S¹) (loop* : base* == base*)
→ [ fst (⊙S¹-endo-in' (S¹-rec base* loop*)) ]
== [ S¹-rec base* loop* ] :> Trunc 0 (S¹ → S¹)
⊙S¹-endo-out'-β = S¹-elim
(λ loop* → ap (λ loop* → [ S¹-rec base loop* ]) (S¹Rec.loop-β base loop*))
(prop-has-all-paths-↓ $ Π-is-prop λ loop* → Trunc-level {n = 0} _ _)
⊙S¹-endo-out-is-equiv : is-equiv (⊙SphereS-endo-out 0)
⊙S¹-endo-out-is-equiv = is-eq _ ⊙S¹-endo-in ⊙S¹-endo-out-β ⊙S¹-endo-in-η
-- For [Sphere (S (S n))], the pointedness is free because of its connectivity.
private
SphereSS-conn : ∀ n → is-connected 1 (Sphere (S (S n)))
SphereSS-conn n = connected-≤T (≤T-+2+-l 1 (-2≤T ⟨ n ⟩₋₂)) (Sphere-conn (S (S n)))
SphereSS-conn-path : ∀ n (x y : Sphere (S (S n))) → is-connected 0 (x == y)
SphereSS-conn-path n x y = path-conn (SphereSS-conn n)
SphereSS-has-all-trunc-paths : ∀ n (x y : Sphere (S (S n))) → Trunc 0 (x == y)
SphereSS-has-all-trunc-paths n x y = –> (Trunc=-equiv [ x ] [ y ])
(contr-has-all-paths (SphereSS-conn n) [ x ] [ y ])
⊙SphereSS-endo-in : ∀ n
→ Trunc 0 ( Sphere (S (S n)) → Sphere (S (S n)))
→ Trunc 0 (⊙Sphere (S (S n)) ⊙→ ⊙Sphere (S (S n)))
⊙SphereSS-endo-in n = Trunc-rec Trunc-level λ f →
Trunc-rec Trunc-level (λ pt → [ f , pt ])
(SphereSS-has-all-trunc-paths n (f north) north)
abstract
⊙SphereSS-endo-in-η : ∀ n f → ⊙SphereSS-endo-in n (⊙SphereS-endo-out (S n) f) == f
⊙SphereSS-endo-in-η n = Trunc-elim (λ _ → =-preserves-set Trunc-level)
λ{(f , pt) → ap (Trunc-rec Trunc-level (λ pt → [ f , pt ]))
(contr-has-all-paths (SphereSS-conn-path n (f north) north)
(SphereSS-has-all-trunc-paths n (f north) north) [ pt ])}
⊙SphereSS-endo-out-β : ∀ n f → ⊙SphereS-endo-out (S n) (⊙SphereSS-endo-in n f) == f
⊙SphereSS-endo-out-β n = Trunc-elim (λ _ → =-preserves-set Trunc-level)
λ f → Trunc-elim
{P = λ pt → ⊙SphereS-endo-out (S n) (Trunc-rec Trunc-level (λ pt → [ f , pt ]) pt) == [ f ]}
(λ _ → =-preserves-set Trunc-level)
(λ pt → idp) (SphereSS-has-all-trunc-paths n (f north) north)
⊙SphereSS-endo-out-is-equiv : ∀ n → is-equiv (⊙SphereS-endo-out (S n))
⊙SphereSS-endo-out-is-equiv n = is-eq
(⊙SphereS-endo-out (S n)) (⊙SphereSS-endo-in n)
(⊙SphereSS-endo-out-β n) (⊙SphereSS-endo-in-η n)
-- the unified interface
⊙SphereS-endo-out-is-equiv : ∀ n → is-equiv (⊙SphereS-endo-out n)
⊙SphereS-endo-out-is-equiv 0 = ⊙S¹-endo-out-is-equiv
⊙SphereS-endo-out-is-equiv (S n) = ⊙SphereSS-endo-out-is-equiv n
⊙SphereS-endo-in : ∀ n
→ Trunc 0 ( Sphere (S n) → Sphere (S n))
→ Trunc 0 (⊙Sphere (S n) ⊙→ ⊙Sphere (S n))
⊙SphereS-endo-in n = is-equiv.g (⊙SphereS-endo-out-is-equiv n)
| {
"alphanum_fraction": 0.5513964313,
"avg_line_length": 41.5806451613,
"ext": "agda",
"hexsha": "484ad9246d90244762c62e7b986f834c9e143bf1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/SphereEndomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/SphereEndomorphism.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/SphereEndomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2050,
"size": 5156
} |
open import Common.Prelude
open import Common.Reflect
open import Common.Equality
postulate
trustme : ∀ {a} {A : Set a} {x y : A} → x ≡ y
magic : Term → Term
magic _ = def (quote trustme) []
id : ∀ {a} {A : Set a} → A → A
id x = x
science : Term → Term
science _ = def (quote id) []
by-magic : ∀ n → n + 4 ≡ 3
by-magic n = tactic magic
by-science : ∀ n → 0 + n ≡ n
by-science n = tactic science | refl
| {
"alphanum_fraction": 0.603406326,
"avg_line_length": 17.8695652174,
"ext": "agda",
"hexsha": "b0ef95df0c954d277ca2f6a48953ff37a26cf746",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "test/succeed/Tactic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/agda",
"max_issues_repo_path": "test/succeed/Tactic.agda",
"max_line_length": 47,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Tactic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 150,
"size": 411
} |
-- 2010-09-06 Andreas
module IrrelevantApplication where
-- an unknown function that does not use its second argument
postulate
f : {A B : Set} -> A -> .B -> A
data _==_ {A : Set}(a : A) : A -> Set where
refl : a == a
-- the second argument is irrelevant for equality
proofIrr : {A : Set}{x y z : A} -> f x y == f x z
proofIrr = refl
-- irrelevant arguments (like x) may appear as arguments to irrelevant func.s
id : {A B : Set} -> (.A -> B) -> .A -> B
id g x = g x
pId : {A : Set} -> A -> A
pId x = x
-- t = pId id
record Prod (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
-- matching an irrelevant record is ok as long as fields are use irrelevantly
irrElim : {A B C : Set} → .(Prod A B) → (.A → .B → C) → C
irrElim (a , b) f = f a b
lemma : {A B C : Set}(a : A)(b : B)(f : .A -> .B -> C) -> irrElim (a , b) f == f a b
lemma a b f = refl
| {
"alphanum_fraction": 0.5683615819,
"avg_line_length": 22.125,
"ext": "agda",
"hexsha": "6d16bf9ee6f6679b862b1fe5db4d70fb0e70d299",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/IrrelevantApplication.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/IrrelevantApplication.agda",
"max_line_length": 84,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/IrrelevantApplication.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": 319,
"size": 885
} |
-- Andreas, 2017-10-08, issue #2594, reported by gallais
-- Incomplete pattern matching should be reported as such,
-- rather than crashing on a split error.
-- {-# OPTIONS -v tc.cover:10 #-}
open import Agda.Builtin.Bool
dispatch : Bool → Set
dispatch true = Bool
dispatch false = Bool
argh : (b : Bool) → dispatch b → Bool
argh false false = true
argh false true = false
-- Error was: Cannot split on non-datatype
-- Expected error:
-- Incomplete pattern matching
| {
"alphanum_fraction": 0.7094736842,
"avg_line_length": 21.5909090909,
"ext": "agda",
"hexsha": "b62a7ad71021576ff7a0c9fb17a652287d4432e7",
"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/Issue2594.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/Issue2594.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2594.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": 127,
"size": 475
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Pi {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening using (_∷_⊆_)
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Weakening
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Weakening
open import Definition.LogicalRelation.Substitution.Properties
import Definition.LogicalRelation.Substitution.Irrelevance as S
open import Definition.LogicalRelation.Substitution.Introductions.Universe
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Validity of Π.
Πᵛ : ∀ {F G Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
→ Γ ∙ F ⊩ᵛ⟨ l ⟩ G / ([Γ] ∙″ [F])
→ Γ ⊩ᵛ⟨ l ⟩ Π F ▹ G / [Γ]
Πᵛ {F} {G} {Γ} {l} [Γ] [F] [G] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [F]σ {σ′} [σ′] = [F] {σ = σ′} ⊢Δ [σ′]
[σF] = proj₁ ([F]σ [σ])
⊢F {σ′} [σ′] = escape (proj₁ ([F]σ {σ′} [σ′]))
⊢F≡F = escapeEq [σF] (reflEq [σF])
[G]σ {σ′} [σ′] = [G] {σ = liftSubst σ′} (⊢Δ ∙ ⊢F [σ′])
(liftSubstS {F = F} [Γ] ⊢Δ [F] [σ′])
⊢G {σ′} [σ′] = escape (proj₁ ([G]σ {σ′} [σ′]))
⊢G≡G = escapeEq (proj₁ ([G]σ [σ])) (reflEq (proj₁ ([G]σ [σ])))
⊢ΠF▹G = Πⱼ ⊢F [σ] ▹ ⊢G [σ]
[G]a : ∀ {ρ Δ₁} a ([ρ] : ρ ∷ Δ₁ ⊆ Δ) (⊢Δ₁ : ⊢ Δ₁)
([a] : Δ₁ ⊩⟨ l ⟩ a ∷ subst (ρ •ₛ σ) F
/ proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])))
→ Σω₀ (Δ₁ ⊩⟨ l ⟩ subst (consSubst (ρ •ₛ σ) a) G)
(λ [Aσ] →
{σ′ : Nat → Term} →
(Σω₂ (Δ₁ ⊩ˢ tail σ′ ∷ Γ / [Γ] / ⊢Δ₁)
(λ [tailσ] →
Δ₁ ⊩⟨ l ⟩ head σ′ ∷ subst (tail σ′) F / proj₁ ([F] ⊢Δ₁ [tailσ]))) →
Δ₁ ⊩ˢ consSubst (ρ •ₛ σ) a ≡ σ′ ∷ Γ ∙ F /
[Γ] ∙″ [F] / ⊢Δ₁ /
consSubstS {t = a} {A = F} [Γ] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]) [F]
[a] →
Δ₁ ⊩⟨ l ⟩ subst (consSubst (ρ •ₛ σ) a) G ≡
subst σ′ G / [Aσ])
[G]a {ρ} a [ρ] ⊢Δ₁ [a] = ([G] {σ = consSubst (ρ •ₛ σ) a} ⊢Δ₁
(consSubstS {t = a} {A = F} [Γ] ⊢Δ₁
(wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])
[F] [a]))
[G]a′ : ∀ {ρ Δ₁} a ([ρ] : ρ ∷ Δ₁ ⊆ Δ) (⊢Δ₁ : ⊢ Δ₁)
→ Δ₁ ⊩⟨ l ⟩ a ∷ subst (ρ •ₛ σ) F
/ proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]))
→ Δ₁ ⊩⟨ l ⟩ U.wk (lift ρ) (subst (liftSubst σ) G) [ a ]
[G]a′ a ρ ⊢Δ₁ [a] = irrelevance′ (PE.sym (singleSubstWkComp a σ G))
(proj₁ ([G]a a ρ ⊢Δ₁ [a]))
in Πᵣ′ (subst σ F) (subst (liftSubst σ) G)
(idRed:*: ⊢ΠF▹G) (⊢F [σ]) (⊢G [σ]) (≅-Π-cong (⊢F [σ]) ⊢F≡F ⊢G≡G)
(λ ρ ⊢Δ₁ → wk ρ ⊢Δ₁ [σF])
(λ {ρ} {Δ₁} {a} [ρ] ⊢Δ₁ [a] →
let [a]′ = irrelevanceTerm′
(wk-subst F) (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]))) [a]
in [G]a′ a [ρ] ⊢Δ₁ [a]′)
(λ {ρ} {Δ₁} {a} {b} [ρ] ⊢Δ₁ [a] [b] [a≡b] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[a]′ = irrelevanceTerm′
(wk-subst F) (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[b]′ = irrelevanceTerm′
(wk-subst F) (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [b]
[a≡b]′ = irrelevanceEqTerm′
(wk-subst F) (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a≡b]
in irrelevanceEq″
(PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp b σ G))
(proj₁ ([G]a a [ρ] ⊢Δ₁ [a]′))
([G]a′ a [ρ] ⊢Δ₁ [a]′)
(proj₂ ([G]a a [ρ] ⊢Δ₁ [a]′)
([ρσ] , [b]′)
(reflSubst [Γ] ⊢Δ₁ [ρσ] , [a≡b]′)))
, (λ {σ′} [σ′] [σ≡σ′] →
let var0 = var (⊢Δ ∙ ⊢F [σ])
(PE.subst (λ x → 0 ∷ x ∈ (Δ ∙ subst σ F))
(wk-subst F) here)
[wk1σ] = wk1SubstS [Γ] ⊢Δ (⊢F [σ]) [σ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ (⊢F [σ]) [σ′]
[wk1σ≡wk1σ′] = wk1SubstSEq [Γ] ⊢Δ (⊢F [σ]) [σ] [σ≡σ′]
[F][wk1σ] = proj₁ ([F] (⊢Δ ∙ ⊢F [σ]) [wk1σ])
[F][wk1σ′] = proj₁ ([F] (⊢Δ ∙ ⊢F [σ]) [wk1σ′])
var0′ = conv var0
(≅-eq (escapeEq [F][wk1σ]
(proj₂ ([F] (⊢Δ ∙ ⊢F [σ]) [wk1σ])
[wk1σ′] [wk1σ≡wk1σ′])))
in Π₌ _ _ (id (Πⱼ ⊢F [σ′] ▹ ⊢G [σ′]))
(≅-Π-cong (⊢F [σ])
(escapeEq (proj₁ ([F] ⊢Δ [σ]))
(proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]))
(escapeEq (proj₁ ([G]σ [σ])) (proj₂ ([G]σ [σ])
([wk1σ′] , neuTerm [F][wk1σ′] (var 0) var0′ (~-var var0′))
([wk1σ≡wk1σ′] , neuEqTerm [F][wk1σ]
(var 0) (var 0) var0 var0 (~-var var0)))))
(λ ρ ⊢Δ₁ → wkEq ρ ⊢Δ₁ [σF] (proj₂ ([F] ⊢Δ [σ]) [σ′] [σ≡σ′]))
(λ {ρ} {Δ₁} {a} [ρ] ⊢Δ₁ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[ρσ′] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ′]
[a]′ = irrelevanceTerm′ (wk-subst F) (wk [ρ] ⊢Δ₁ [σF])
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[a]″ = convTerm₁ (proj₁ ([F] ⊢Δ₁ [ρσ]))
(proj₁ ([F] ⊢Δ₁ [ρσ′]))
(proj₂ ([F] ⊢Δ₁ [ρσ]) [ρσ′]
(wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] [σ≡σ′]))
[a]′
[ρσa≡ρσ′a] = consSubstSEq {t = a} {A = F} [Γ] ⊢Δ₁
(wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ])
(wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] [σ≡σ′])
[F] [a]′
in irrelevanceEq″ (PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ′ G))
(proj₁ ([G]a a [ρ] ⊢Δ₁ [a]′))
([G]a′ a [ρ] ⊢Δ₁ [a]′)
(proj₂ ([G]a a [ρ] ⊢Δ₁ [a]′)
(wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ′] , [a]″)
[ρσa≡ρσ′a])))
-- Validity of Π-congurence.
Π-congᵛ : ∀ {F G H E Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / ([Γ] ∙″ [F]))
([H] : Γ ⊩ᵛ⟨ l ⟩ H / [Γ])
([E] : Γ ∙ H ⊩ᵛ⟨ l ⟩ E / ([Γ] ∙″ [H]))
([F≡H] : Γ ⊩ᵛ⟨ l ⟩ F ≡ H / [Γ] / [F])
([G≡E] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G ≡ E / [Γ] ∙″ [F] / [G])
→ Γ ⊩ᵛ⟨ l ⟩ Π F ▹ G ≡ Π H ▹ E / [Γ] / Πᵛ {F} {G} [Γ] [F] [G]
Π-congᵛ {F} {G} {H} {E} [Γ] [F] [G] [H] [E] [F≡H] [G≡E] {σ = σ} ⊢Δ [σ] =
let [ΠFG] = Πᵛ {F} {G} [Γ] [F] [G]
[σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ])
Πᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext′ = extractMaybeEmbΠ (Π-elim [σΠFG])
[σF] = proj₁ ([F] ⊢Δ [σ])
⊢σF = escape [σF]
[σG] = proj₁ ([G] (⊢Δ ∙ ⊢σF) (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))
⊢σH = escape (proj₁ ([H] ⊢Δ [σ]))
⊢σE = escape (proj₁ ([E] (⊢Δ ∙ ⊢σH) (liftSubstS {F = H} [Γ] ⊢Δ [H] [σ])))
⊢σF≡σH = escapeEq [σF] ([F≡H] ⊢Δ [σ])
⊢σG≡σE = escapeEq [σG] ([G≡E] (⊢Δ ∙ ⊢σF) (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))
in Π₌ (subst σ H)
(subst (liftSubst σ) E)
(id (Πⱼ ⊢σH ▹ ⊢σE))
(≅-Π-cong ⊢σF ⊢σF≡σH ⊢σG≡σE)
(λ ρ ⊢Δ₁ → let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ ρ [σ]
in irrelevanceEq″ (PE.sym (wk-subst F))
(PE.sym (wk-subst H))
(proj₁ ([F] ⊢Δ₁ [ρσ]))
([F]′ ρ ⊢Δ₁)
([F≡H] ⊢Δ₁ [ρσ]))
(λ {ρ} {Δ} {a} [ρ] ⊢Δ₁ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]
[a]′ = irrelevanceTerm′ (wk-subst F)
([F]′ [ρ] ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[aρσ] = consSubstS {t = a} {A = F} [Γ] ⊢Δ₁ [ρσ] [F] [a]′
in irrelevanceEq″ (PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ E))
(proj₁ ([G] ⊢Δ₁ [aρσ]))
([G]′ [ρ] ⊢Δ₁ [a])
([G≡E] ⊢Δ₁ [aρσ]))
-- Validity of Π as a term.
Πᵗᵛ : ∀ {F G Γ} ([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ ¹ ⟩ F / [Γ])
([U] : Γ ∙ F ⊩ᵛ⟨ ¹ ⟩ U / ([Γ] ∙″ [F]))
→ Γ ⊩ᵛ⟨ ¹ ⟩ F ∷ U / [Γ] / Uᵛ [Γ]
→ Γ ∙ F ⊩ᵛ⟨ ¹ ⟩ G ∷ U / [Γ] ∙″ [F] / (λ {Δ} {σ} → [U] {Δ} {σ})
→ Γ ⊩ᵛ⟨ ¹ ⟩ Π F ▹ G ∷ U / [Γ] / Uᵛ [Γ]
Πᵗᵛ {F} {G} {Γ} [Γ] [F] [U] [Fₜ] [Gₜ] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
⊢Fₜ = escapeTerm (Uᵣ′ ⁰ 0<1 ⊢Δ) (proj₁ ([Fₜ] ⊢Δ [σ]))
⊢F≡Fₜ = escapeTermEq (Uᵣ′ ⁰ 0<1 ⊢Δ)
(reflEqTerm (Uᵣ′ ⁰ 0<1 ⊢Δ) (proj₁ ([Fₜ] ⊢Δ [σ])))
⊢Gₜ = escapeTerm (proj₁ ([U] (⊢Δ ∙ ⊢F) [liftσ]))
(proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]))
⊢G≡Gₜ = escapeTermEq (proj₁ ([U] (⊢Δ ∙ ⊢F) [liftσ]))
(reflEqTerm (proj₁ ([U] (⊢Δ ∙ ⊢F) [liftσ]))
(proj₁ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ])))
[F]₀ = univᵛ {F} [Γ] (Uᵛ [Γ]) [Fₜ]
[Gₜ]′ = S.irrelevanceTerm {A = U} {t = G}
(_∙″_ {A = F} [Γ] [F]) (_∙″_ {A = F} [Γ] [F]₀)
(λ {Δ} {σ} → [U] {Δ} {σ})
(λ {Δ} {σ} → Uᵛ (_∙″_ {A = F} [Γ] [F]₀) {Δ} {σ})
[Gₜ]
[G]₀ = univᵛ {G} (_∙″_ {A = F} [Γ] [F]₀)
(λ {Δ} {σ} → Uᵛ (_∙″_ {A = F} [Γ] [F]₀) {Δ} {σ})
(λ {Δ} {σ} → [Gₜ]′ {Δ} {σ})
[ΠFG] = (Πᵛ {F} {G} [Γ] [F]₀ [G]₀) ⊢Δ [σ]
in Uₜ (Π subst σ F ▹ subst (liftSubst σ) G) (idRedTerm:*: (Πⱼ ⊢Fₜ ▹ ⊢Gₜ))
Πₙ (≅ₜ-Π-cong ⊢F ⊢F≡Fₜ ⊢G≡Gₜ) (proj₁ [ΠFG])
, (λ {σ′} [σ′] [σ≡σ′] →
let [liftσ′] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ′]
[wk1σ] = wk1SubstS [Γ] ⊢Δ ⊢F [σ]
[wk1σ′] = wk1SubstS [Γ] ⊢Δ ⊢F [σ′]
var0 = conv (var (⊢Δ ∙ ⊢F)
(PE.subst (λ x → 0 ∷ x ∈ (Δ ∙ subst σ F))
(wk-subst F) here))
(≅-eq (escapeEq (proj₁ ([F] (⊢Δ ∙ ⊢F) [wk1σ]))
(proj₂ ([F] (⊢Δ ∙ ⊢F) [wk1σ]) [wk1σ′]
(wk1SubstSEq [Γ] ⊢Δ ⊢F [σ] [σ≡σ′]))))
[liftσ′]′ = [wk1σ′]
, neuTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [wk1σ′])) (var 0)
var0 (~-var var0)
⊢F′ = escape (proj₁ ([F] ⊢Δ [σ′]))
⊢Fₜ′ = escapeTerm (Uᵣ′ ⁰ 0<1 ⊢Δ) (proj₁ ([Fₜ] ⊢Δ [σ′]))
⊢Gₜ′ = escapeTerm (proj₁ ([U] (⊢Δ ∙ ⊢F′) [liftσ′]))
(proj₁ ([Gₜ] (⊢Δ ∙ ⊢F′) [liftσ′]))
⊢F≡F′ = escapeTermEq (Uᵣ′ ⁰ 0<1 ⊢Δ)
(proj₂ ([Fₜ] ⊢Δ [σ]) [σ′] [σ≡σ′])
⊢G≡G′ = escapeTermEq (proj₁ ([U] (⊢Δ ∙ ⊢F) [liftσ]))
(proj₂ ([Gₜ] (⊢Δ ∙ ⊢F) [liftσ]) [liftσ′]′
(liftSubstSEq {F = F} [Γ] ⊢Δ [F] [σ] [σ≡σ′]))
[ΠFG]′ = (Πᵛ {F} {G} [Γ] [F]₀ [G]₀) ⊢Δ [σ′]
in Uₜ₌ (Π subst σ F ▹ subst (liftSubst σ) G)
(Π subst σ′ F ▹ subst (liftSubst σ′) G)
(idRedTerm:*: (Πⱼ ⊢Fₜ ▹ ⊢Gₜ))
(idRedTerm:*: (Πⱼ ⊢Fₜ′ ▹ ⊢Gₜ′))
Πₙ Πₙ (≅ₜ-Π-cong ⊢F ⊢F≡F′ ⊢G≡G′)
(proj₁ [ΠFG]) (proj₁ [ΠFG]′) (proj₂ [ΠFG] [σ′] [σ≡σ′]))
-- Validity of Π-congurence as a term equality.
Π-congᵗᵛ : ∀ {F G H E Γ}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ ¹ ⟩ F / [Γ])
([H] : Γ ⊩ᵛ⟨ ¹ ⟩ H / [Γ])
([UF] : Γ ∙ F ⊩ᵛ⟨ ¹ ⟩ U / ([Γ] ∙″ [F]))
([UH] : Γ ∙ H ⊩ᵛ⟨ ¹ ⟩ U / ([Γ] ∙″ [H]))
([F]ₜ : Γ ⊩ᵛ⟨ ¹ ⟩ F ∷ U / [Γ] / Uᵛ [Γ])
([G]ₜ : Γ ∙ F ⊩ᵛ⟨ ¹ ⟩ G ∷ U / [Γ] ∙″ [F]
/ (λ {Δ} {σ} → [UF] {Δ} {σ}))
([H]ₜ : Γ ⊩ᵛ⟨ ¹ ⟩ H ∷ U / [Γ] / Uᵛ [Γ])
([E]ₜ : Γ ∙ H ⊩ᵛ⟨ ¹ ⟩ E ∷ U / [Γ] ∙″ [H]
/ (λ {Δ} {σ} → [UH] {Δ} {σ}))
([F≡H]ₜ : Γ ⊩ᵛ⟨ ¹ ⟩ F ≡ H ∷ U / [Γ] / Uᵛ [Γ])
([G≡E]ₜ : Γ ∙ F ⊩ᵛ⟨ ¹ ⟩ G ≡ E ∷ U / [Γ] ∙″ [F]
/ (λ {Δ} {σ} → [UF] {Δ} {σ}))
→ Γ ⊩ᵛ⟨ ¹ ⟩ Π F ▹ G ≡ Π H ▹ E ∷ U / [Γ] / Uᵛ [Γ]
Π-congᵗᵛ {F} {G} {H} {E}
[Γ] [F] [H] [UF] [UH] [F]ₜ [G]ₜ [H]ₜ [E]ₜ [F≡H]ₜ [G≡E]ₜ {Δ} {σ} ⊢Δ [σ] =
let ⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
⊢H = escape (proj₁ ([H] ⊢Δ [σ]))
[liftFσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
[liftHσ] = liftSubstS {F = H} [Γ] ⊢Δ [H] [σ]
[F]ᵤ = univᵛ {F} [Γ] (Uᵛ [Γ]) [F]ₜ
[G]ᵤ₁ = univᵛ {G} {l′ = ⁰} (_∙″_ {A = F} [Γ] [F])
(λ {Δ} {σ} → [UF] {Δ} {σ}) [G]ₜ
[G]ᵤ = S.irrelevance {A = G} (_∙″_ {A = F} [Γ] [F])
(_∙″_ {A = F} [Γ] [F]ᵤ) [G]ᵤ₁
[H]ᵤ = univᵛ {H} [Γ] (Uᵛ [Γ]) [H]ₜ
[E]ᵤ = S.irrelevance {A = E} (_∙″_ {A = H} [Γ] [H]) (_∙″_ {A = H} [Γ] [H]ᵤ)
(univᵛ {E} {l′ = ⁰} (_∙″_ {A = H} [Γ] [H])
(λ {Δ} {σ} → [UH] {Δ} {σ}) [E]ₜ)
[F≡H]ᵤ = univEqᵛ {F} {H} [Γ] (Uᵛ [Γ]) [F]ᵤ [F≡H]ₜ
[G≡E]ᵤ = S.irrelevanceEq {A = G} {B = E} (_∙″_ {A = F} [Γ] [F])
(_∙″_ {A = F} [Γ] [F]ᵤ) [G]ᵤ₁ [G]ᵤ
(univEqᵛ {G} {E} (_∙″_ {A = F} [Γ] [F])
(λ {Δ} {σ} → [UF] {Δ} {σ}) [G]ᵤ₁ [G≡E]ₜ)
ΠFGₜ = Πⱼ escapeTerm {l = ¹} (Uᵣ′ ⁰ 0<1 ⊢Δ) (proj₁ ([F]ₜ ⊢Δ [σ]))
▹ escapeTerm (proj₁ ([UF] (⊢Δ ∙ ⊢F) [liftFσ]))
(proj₁ ([G]ₜ (⊢Δ ∙ ⊢F) [liftFσ]))
ΠHEₜ = Πⱼ escapeTerm {l = ¹} (Uᵣ′ ⁰ 0<1 ⊢Δ) (proj₁ ([H]ₜ ⊢Δ [σ]))
▹ escapeTerm (proj₁ ([UH] (⊢Δ ∙ ⊢H) [liftHσ]))
(proj₁ ([E]ₜ (⊢Δ ∙ ⊢H) [liftHσ]))
in Uₜ₌ (Π subst σ F ▹ subst (liftSubst σ) G)
(Π subst σ H ▹ subst (liftSubst σ) E)
(idRedTerm:*: ΠFGₜ) (idRedTerm:*: ΠHEₜ)
Πₙ Πₙ
(≅ₜ-Π-cong ⊢F (escapeTermEq (Uᵣ′ ⁰ 0<1 ⊢Δ) ([F≡H]ₜ ⊢Δ [σ]))
(escapeTermEq (proj₁ ([UF] (⊢Δ ∙ ⊢F) [liftFσ]))
([G≡E]ₜ (⊢Δ ∙ ⊢F) [liftFσ])))
(proj₁ (Πᵛ {F} {G} [Γ] [F]ᵤ [G]ᵤ ⊢Δ [σ]))
(proj₁ (Πᵛ {H} {E} [Γ] [H]ᵤ [E]ᵤ ⊢Δ [σ]))
(Π-congᵛ {F} {G} {H} {E} [Γ] [F]ᵤ [G]ᵤ [H]ᵤ [E]ᵤ [F≡H]ᵤ [G≡E]ᵤ ⊢Δ [σ])
-- Validity of non-dependent function types.
▹▹ᵛ : ∀ {F G Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
→ Γ ⊩ᵛ⟨ l ⟩ G / [Γ]
→ Γ ⊩ᵛ⟨ l ⟩ F ▹▹ G / [Γ]
▹▹ᵛ {F} {G} [Γ] [F] [G] =
Πᵛ {F} {wk1 G} [Γ] [F] (wk1ᵛ {G} {F} [Γ] [F] [G])
-- Validity of non-dependent function type congurence.
▹▹-congᵛ : ∀ {F F′ G G′ Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([F′] : Γ ⊩ᵛ⟨ l ⟩ F′ / [Γ])
([F≡F′] : Γ ⊩ᵛ⟨ l ⟩ F ≡ F′ / [Γ] / [F])
([G] : Γ ⊩ᵛ⟨ l ⟩ G / [Γ])
([G′] : Γ ⊩ᵛ⟨ l ⟩ G′ / [Γ])
([G≡G′] : Γ ⊩ᵛ⟨ l ⟩ G ≡ G′ / [Γ] / [G])
→ Γ ⊩ᵛ⟨ l ⟩ F ▹▹ G ≡ F′ ▹▹ G′ / [Γ] / ▹▹ᵛ {F} {G} [Γ] [F] [G]
▹▹-congᵛ {F} {F′} {G} {G′} [Γ] [F] [F′] [F≡F′] [G] [G′] [G≡G′] =
Π-congᵛ {F} {wk1 G} {F′} {wk1 G′} [Γ]
[F] (wk1ᵛ {G} {F} [Γ] [F] [G])
[F′] (wk1ᵛ {G′} {F′} [Γ] [F′] [G′])
[F≡F′] (wk1Eqᵛ {G} {G′} {F} [Γ] [F] [G] [G≡G′])
| {
"alphanum_fraction": 0.3318716122,
"avg_line_length": 50.9906832298,
"ext": "agda",
"hexsha": "513406669c7c216af5921a52c57623e671f18c47",
"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/Substitution/Introductions/Pi.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/Substitution/Introductions/Pi.agda",
"max_line_length": 90,
"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/Substitution/Introductions/Pi.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8180,
"size": 16419
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Groups.Abelian.Definition
open import Groups.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Lists.Lists
module Groups.Polynomials.Group {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) where
open import Groups.Polynomials.Definition G
open import Groups.Polynomials.Addition G public
open Setoid S
open Equivalence eq
polyGroup : Group naivePolySetoid _+P_
Group.+WellDefined polyGroup = +PwellDefined
Group.0G polyGroup = []
Group.inverse polyGroup = inverse'
Group.+Associative polyGroup {a} {b} {c} = assoc {a} {b} {c}
Group.identRight polyGroup = PidentRight
Group.identLeft polyGroup = PidentLeft
Group.invLeft polyGroup {a} = invLeft' {a}
Group.invRight polyGroup {a} = invRight' {a}
abelian : AbelianGroup G → AbelianGroup polyGroup
AbelianGroup.commutative (abelian ab) {x} {y} = comm ab {x} {y}
| {
"alphanum_fraction": 0.742344245,
"avg_line_length": 32.6551724138,
"ext": "agda",
"hexsha": "2b8a4ff547b3ce9ea788e2c5d7d9910cf6429bca",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/Polynomials/Group.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Polynomials/Group.agda",
"max_line_length": 118,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/Polynomials/Group.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": 284,
"size": 947
} |
{-# OPTIONS --two-level #-}
open import Agda.Primitive
data Unit : Set where tt : Unit
data Unitω : Setω where tt : Unitω
data SUnit : SSet where tt : SUnit
data SUnitω : SSetω where tt : SUnitω
-- Cannot eliminate fibrant type Unit
-- unless target type is also fibrant
-- f1 : Unit → SUnit
-- f1 tt = tt
-- Cannot eliminate fibrant type Unit
-- unless target type is also fibrant
-- f2 : Unit → SUnitω
-- f2 tt = tt
--f3 : Unitω → SUnit
--f3 tt = tt
f4 : Unitω → SUnitω
f4 tt = tt
| {
"alphanum_fraction": 0.6707566462,
"avg_line_length": 19.56,
"ext": "agda",
"hexsha": "e506cd0de2584691fbabe8b1ae1311a66795cd30",
"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/Fail/Issue4951b.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/Fail/Issue4951b.agda",
"max_line_length": 37,
"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/Fail/Issue4951b.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": 161,
"size": 489
} |
open import Common.Prelude
infixr 9 _∘_
_∘_ : {A B C : Set} → (B → C) → (A → B) → (A → C)
f ∘ g = λ x → f (g x)
test : Nat → Nat
test = _* 5 ∘ 6 +_ ∘ 2 ∸_
| {
"alphanum_fraction": 0.4620253165,
"avg_line_length": 15.8,
"ext": "agda",
"hexsha": "c68e50903237513c663fa2660478636109e31dfd",
"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/Sections-1.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/Sections-1.agda",
"max_line_length": 49,
"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/Sections-1.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": 83,
"size": 158
} |
{-# OPTIONS --erased-cubical --no-subtyping #-}
module Agda.Primitive.Cubical where
{-# BUILTIN CUBEINTERVALUNIV IUniv #-} -- IUniv : SSet₁
{-# BUILTIN INTERVAL I #-} -- I : IUniv
{-# BUILTIN IZERO i0 #-}
{-# BUILTIN IONE i1 #-}
-- I is treated as the type of booleans.
{-# COMPILE JS i0 = false #-}
{-# COMPILE JS i1 = true #-}
infix 30 primINeg
infixr 20 primIMin primIMax
primitive
primIMin : I → I → I
primIMax : I → I → I
primINeg : I → I
{-# BUILTIN ISONE IsOne #-} -- IsOne : I → Setω
postulate
itIsOne : IsOne i1
IsOne1 : ∀ i j → IsOne i → IsOne (primIMax i j)
IsOne2 : ∀ i j → IsOne j → IsOne (primIMax i j)
{-# BUILTIN ITISONE itIsOne #-}
{-# BUILTIN ISONE1 IsOne1 #-}
{-# BUILTIN ISONE2 IsOne2 #-}
-- IsOne i is treated as the unit type.
{-# COMPILE JS itIsOne = { "tt" : a => a["tt"]() } #-}
{-# COMPILE JS IsOne1 =
_ => _ => _ => { return { "tt" : a => a["tt"]() } }
#-}
{-# COMPILE JS IsOne2 =
_ => _ => _ => { return { "tt" : a => a["tt"]() } }
#-}
-- Partial : ∀{ℓ} (i : I) (A : Set ℓ) → Set ℓ
-- Partial i A = IsOne i → A
{-# BUILTIN PARTIAL Partial #-}
{-# BUILTIN PARTIALP PartialP #-}
postulate
isOneEmpty : ∀ {ℓ} {A : Partial i0 (Set ℓ)} → PartialP i0 A
{-# BUILTIN ISONEEMPTY isOneEmpty #-}
-- Partial i A and PartialP i A are treated as IsOne i → A.
{-# COMPILE JS isOneEmpty =
_ => x => _ => x({ "tt" : a => a["tt"]() })
#-}
primitive
primPOr : ∀ {ℓ} (i j : I) {A : Partial (primIMax i j) (Set ℓ)}
→ (u : PartialP i (λ z → A (IsOne1 i j z)))
→ (v : PartialP j (λ z → A (IsOne2 i j z)))
→ PartialP (primIMax i j) A
-- Computes in terms of primHComp and primTransp
primComp : ∀ {ℓ} (A : (i : I) → Set (ℓ i)) {φ : I} (u : ∀ i → Partial φ (A i)) (a : A i0) → A i1
syntax primPOr p q u t = [ p ↦ u , q ↦ t ]
primitive
primTransp : ∀ {ℓ} (A : (i : I) → Set (ℓ i)) (φ : I) (a : A i0) → A i1
primHComp : ∀ {ℓ} {A : Set ℓ} {φ : I} (u : ∀ i → Partial φ A) (a : A) → A
postulate
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
| {
"alphanum_fraction": 0.5219443134,
"avg_line_length": 26.8227848101,
"ext": "agda",
"hexsha": "55ad06996dc6e2eb2c3e3b6fd61d0fec251c53a5",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Primitive/Cubical.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"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": "cruhland/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Primitive/Cubical.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Primitive/Cubical.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 841,
"size": 2119
} |
module *-example where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
open import Naturals using (_*_)
*-example : 3 * 4 ≡ 12
*-example =
begin
3 * 4
≡⟨⟩
4 + (2 * 4)
≡⟨⟩
4 + (4 + (1 * 4))
≡⟨⟩
4 + (4 + (4 + (0 * 4)))
≡⟨⟩
4 + (4 + (4 + 0))
≡⟨⟩
12
∎
| {
"alphanum_fraction": 0.4862637363,
"avg_line_length": 15.1666666667,
"ext": "agda",
"hexsha": "f47fac7692139c77f00c58ce19bd592f103aee05",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/naturals/*-example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/naturals/*-example.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/naturals/*-example.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 177,
"size": 364
} |
open import x1-Base
module x3-PropositionalEquality where
data _≡_ {X} : Rel X where
refl : ∀ {x} → x ≡ x
{-
What propositional equality means.
DEFINITIONAL EQUALITY
To decide if two types/terms are "the same", it reduces them to their normal form,
then compares them syntactically, plus some additional laws.
Every term terminates, so refl : ((λ x → x) 1) ≡ 1 is acceptable
PROPOSITIONAL EQUALITY
User-level equality expressed by the inductive family defined.
Having a propositional equality in scope does not imply definitional equality for the
related terms, unless the propositional equality is a closed term.
That is the reason ≡ is not used from the beginning.
Instead, chose to parametrise the equality relation:
- sometimes propositional equality does not work, for example when working with functions.
In general there might be propositional equalities in scope
that do not necessarily hold or involve abstracted variables, think of λ (p : 3 ≡ 1) → ....
-}
-- prove ≡ is an equivalence relation
sym : ∀ {X} {x y : X} → x ≡ y → y ≡ x
sym refl = refl
trans : ∀ {X} {x y z : X} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
equivalence : ∀ {X} → Equivalence {X} _≡_
equivalence = record { refl = refl; sym = sym; trans = trans }
-- useful
cong : ∀ {X} {x y : X} → (f : X → X) → x ≡ y → f x ≡ f y
cong _ refl = refl
{-
Above uses pattern matching in a new way:
Since value of indices of ≡ depends on constructors,
matching on constructor refines context with new information.
E.g., sym matching refl will unify y and x,
turning them into the same variable in the context for the body of sym,
therefore letting refl be invoked again.
DEPENDENT PATTERN MATCHING
Pattern matching in Agda can change the context AND constraint possible constructors
of other parameters, if they are a type with indices and those indices have been refined.
-}
| {
"alphanum_fraction": 0.729468599,
"avg_line_length": 32.6842105263,
"ext": "agda",
"hexsha": "c3da61d49503fd4b8ff450cf7dc33cb6c1bbd20d",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x3-PropositionalEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x3-PropositionalEquality.agda",
"max_line_length": 92,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/topic/order/2013-04-01-sorting-francesco-mazzo/x3-PropositionalEquality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 497,
"size": 1863
} |
------------------------------------------------------------------------
-- A library of parser combinators
------------------------------------------------------------------------
-- This module also provides examples of parsers for which the indices
-- cannot be inferred.
module StructurallyRecursiveDescentParsing.Lib where
open import StructurallyRecursiveDescentParsing.Grammar
open import StructurallyRecursiveDescentParsing.Index
open import Data.Nat hiding (_≟_)
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Data.List using (List; []; _∷_; foldr; foldl; reverse)
open import Data.Product
open import Data.Bool using (Bool; true; false; _∧_; _∨_)
open import Function
open import Data.Maybe hiding (_>>=_)
open import Data.Unit using (⊤)
open import Data.Char using (Char; _==_)
import Data.Char.Properties as Char
open import Codata.Musical.Notation
open import Algebra
import Data.Bool.Properties as Bool
private
module BCS = CommutativeSemiring Bool.∨-∧-commutativeSemiring
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
import Level
------------------------------------------------------------------------
-- Some important derived combinators
infixl 10 _>>=_
_>>=_ : ∀ {NT Tok e₁ c₁ i₂ R₁ R₂} → let i₁ = e₁ ◇ c₁ in
Parser NT Tok i₁ R₁ →
(R₁ → Parser NT Tok i₂ R₂) →
Parser NT Tok (i₁ · i₂) R₂
_>>=_ {e₁ = true } p₁ p₂ = p₁ ?>>= p₂
_>>=_ {e₁ = false} p₁ p₂ = p₁ !>>= λ x → ♯ p₂ x
cast : ∀ {NT Tok e₁ e₂ c₁ c₂ R} →
e₁ ≡ e₂ → c₁ ≡ c₂ →
Parser NT Tok (e₁ ◇ c₁) R → Parser NT Tok (e₂ ◇ c₂) R
cast refl refl p = p
------------------------------------------------------------------------
-- Applicative functor parsers
-- We could get these for free with better library support.
infixl 50 _⊛_ _⊛!_ _<⊛_ _⊛>_ _<$>_ _<$_ _⊗_ _⊗!_
_⊛_ : ∀ {NT Tok i₁ i₂ R₁ R₂} →
Parser NT Tok i₁ (R₁ → R₂) →
Parser NT Tok i₂ R₁ →
Parser NT Tok _ R₂
p₁ ⊛ p₂ = p₁ >>= λ f → p₂ >>= λ x → return (f x)
-- A variant: If the second parser does not accept the empty string,
-- then neither does the combination. (This is immediate for the first
-- parser, but for the second one a small lemma is needed, hence this
-- variant.)
_⊛!_ : ∀ {NT Tok i₁ c₂ R₁ R₂} →
Parser NT Tok i₁ (R₁ → R₂) →
Parser NT Tok (false ◇ c₂) R₁ →
Parser NT Tok (false ◇ _) R₂
_⊛!_ {i₁ = i₁} p₁ p₂ = cast (BCS.*-comm (empty i₁) false) refl
(p₁ ⊛ p₂)
_<$>_ : ∀ {NT Tok i R₁ R₂} →
(R₁ → R₂) →
Parser NT Tok i R₁ →
Parser NT Tok _ R₂
f <$> p = return f ⊛ p
_<⊛_ : ∀ {NT Tok i₁ i₂ R₁ R₂} →
Parser NT Tok i₁ R₁ →
Parser NT Tok i₂ R₂ →
Parser NT Tok _ R₁
p₁ <⊛ p₂ = const <$> p₁ ⊛ p₂
_⊛>_ : ∀ {NT Tok i₁ i₂ R₁ R₂} →
Parser NT Tok i₁ R₁ →
Parser NT Tok i₂ R₂ →
Parser NT Tok _ R₂
p₁ ⊛> p₂ = flip const <$> p₁ ⊛ p₂
_<$_ : ∀ {NT Tok i R₁ R₂} →
R₁ →
Parser NT Tok i R₂ →
Parser NT Tok _ R₁
x <$ p = const x <$> p
_⊗_ : ∀ {NT Tok i₁ i₂ R₁ R₂} →
Parser NT Tok i₁ R₁ → Parser NT Tok i₂ R₂ →
Parser NT Tok _ (R₁ × R₂)
p₁ ⊗ p₂ = (_,_) <$> p₁ ⊛ p₂
_⊗!_ : ∀ {NT Tok i₁ c₂ R₁ R₂} →
Parser NT Tok i₁ R₁ → Parser NT Tok (false ◇ c₂) R₂ →
Parser NT Tok (false ◇ _) (R₁ × R₂)
p₁ ⊗! p₂ = (_,_) <$> p₁ ⊛! p₂
------------------------------------------------------------------------
-- Parsing sequences
infix 55 _⋆ _+
-- Not accepted by the productivity checker:
-- mutual
-- _⋆ : ∀ {NT Tok R c} →
-- Parser NT Tok (false ◇ c) R →
-- Parser NT Tok _ (List R)
-- p ⋆ = return [] ∣ p +
-- _+ : ∀ {NT Tok R c} →
-- Parser NT Tok (false ◇ c) R →
-- Parser NT Tok _ (List R)
-- p + = _∷_ <$> p ⊛ p ⋆
-- In fact the code above risks leading to infinite loops in the
-- current version of Agda (Mar 2009), since it does not contain any
-- coinductive constructors. The following code is OK, though:
mutual
_⋆ : ∀ {NT Tok R c} →
Parser NT Tok (false ◇ c) R →
Parser NT Tok _ (List R)
p ⋆ = return [] ∣ p +
_+ : ∀ {NT Tok R c} →
Parser NT Tok (false ◇ c) R →
Parser NT Tok _ (List R)
p + = p !>>= λ x → ♯
(p ⋆ ?>>= λ xs →
return (x ∷ xs))
-- p sepBy⟨ ne ⟩ sep and p sepBy sep parse one or more ps separated by
-- seps.
_sepBy⟨_⟩_ : ∀ {NT Tok i i′ R R′} →
Parser NT Tok i R →
(empty i′ ∧ true) ∧ (empty i ∧ true) ≡ false →
Parser NT Tok i′ R′ →
Parser NT Tok _ (List R)
p sepBy⟨ non-empty ⟩ sep = _∷_ <$> p ⊛ cast₁ (sep ⊛> p) ⋆
where cast₁ = cast non-empty refl
-- _sepBy_ could be implemented by using _sepBy⟨_⟩_, but the following
-- definition is handled more efficiently by the current version of
-- Agda (Dec 2008).
_sepBy_ : ∀ {NT Tok i c R R′} →
Parser NT Tok i R → Parser NT Tok (false ◇ c) R′ →
Parser NT Tok _ (List R)
p sepBy sep = _∷_ <$> p ⊛ (sep ⊛> p) ⋆
mutual
-- Note that the index of atLeast is only partly inferred; the
-- recursive structure of atLeast-index is given manually.
atLeast-index : Corners → ℕ → Index
atLeast-index c zero = _
atLeast-index c (suc n) = _
-- At least n occurrences of p.
atLeast : ∀ {NT Tok c R} (n : ℕ) →
Parser NT Tok (false ◇ c) R →
Parser NT Tok (atLeast-index c n) (List R)
atLeast zero p = p ⋆
atLeast (suc n) p = _∷_ <$> p ⊛ atLeast n p
-- exactly n p parses n occurrences of p.
--
-- (Note that, unlike what is written in "Structurally Recursive
-- Descent Parsing", Agda as of 2012-03-16 can no longer infer
-- exactly-index's second right-hand side.)
exactly-index : Index → ℕ → Index
exactly-index i zero = 1I
exactly-index i (suc n) = (1I · i · 1I) · exactly-index i n · 1I
exactly : ∀ {NT Tok i R} n →
Parser NT Tok i R →
Parser NT Tok (exactly-index i n) (Vec R n)
exactly zero p = return []
exactly (suc n) p = _∷_ <$> p ⊛ exactly n p
-- A function with a similar type:
sequence : ∀ {NT Tok i R n} →
Vec (Parser NT Tok i R) n →
Parser NT Tok (exactly-index i n) (Vec R n)
sequence [] = return []
sequence (p ∷ ps) = _∷_ <$> p ⊛ sequence ps
mutual
-- p between ps parses p repeatedly, between the elements of ps:
-- ∙ between (x ∷ y ∷ z ∷ []) ≈ x ∙ y ∙ z.
between-corners : Corners → ℕ → Corners
between-corners c′ zero = _
between-corners c′ (suc n) = _
_between_ : ∀ {NT Tok i R c′ R′ n} →
Parser NT Tok i R →
Vec (Parser NT Tok (false ◇ c′) R′) (suc n) →
Parser NT Tok (false ◇ between-corners c′ n) (Vec R n)
p between (x ∷ []) = [] <$ x
p between (x ∷ y ∷ xs) = _∷_ <$> (x ⊛> p) ⊛ (p between (y ∷ xs))
------------------------------------------------------------------------
-- Chaining
-- Associativity. Used to specify how chain≥ should apply the parsed
-- operators: left or right associatively.
data Assoc : Set where
left : Assoc
right : Assoc
-- Application.
appʳ : {R : Set} → R × (R → R → R) → R → R
appʳ (x , _•_) y = x • y
appˡ : {R : Set} → R → (R → R → R) × R → R
appˡ x (_•_ , y) = x • y
-- Shifting. See Examples below for an illuminating example.
shiftʳ : {A B : Set} → A → List (B × A) → List (A × B) × A
shiftʳ x [] = ([] , x)
shiftʳ x₁ ((x₂ , x₃) ∷ xs₄) = ((x₁ , x₂) ∷ proj₁ xs₃x₄ , proj₂ xs₃x₄)
where xs₃x₄ = shiftʳ x₃ xs₄
-- Post-processing for the chain≥ parser.
chain≥-combine : {R : Set} → Assoc → R → List ((R → R → R) × R) → R
chain≥-combine left x ys = foldl appˡ x ys
chain≥-combine right x ys with shiftʳ x ys
... | (xs , y) = foldr appʳ y xs
-- Chains at least n occurrences of op, in an a-associative
-- manner. The ops are surrounded by ps.
chain≥ : ∀ {NT Tok c₁ i₂ R} (n : ℕ) →
Assoc →
Parser NT Tok (false ◇ c₁) R →
Parser NT Tok i₂ (R → R → R) →
Parser NT Tok _ R
chain≥ n a p op = chain≥-combine a <$> p ⊛ atLeast n (op ⊗! p)
private
module Examples {R S : Set}
(x y z : R)
(a b : S)
(_+_ _*_ : R → R → R)
where
ex : shiftʳ x ((a , y) ∷ (b , z) ∷ []) ≡ ((x , a) ∷ (y , b) ∷ [] , z)
ex = refl
exʳ : chain≥-combine right x ((_+_ , y) ∷ (_*_ , z) ∷ []) ≡
(x + (y * z))
exʳ = refl
exˡ : chain≥-combine left x ((_+_ , y) ∷ (_*_ , z) ∷ []) ≡
((x + y) * z)
exˡ = refl
------------------------------------------------------------------------
-- N-ary variants of _∣_
-- choice ps parses one of the elements in ps.
choice-corners : Corners → ℕ → Corners
choice-corners c zero = ε
choice-corners c (suc n) = c ∪ choice-corners c n
choice : ∀ {NT Tok c R n} →
Vec (Parser NT Tok (false ◇ c) R) n →
Parser NT Tok (false ◇ choice-corners c n) R
choice [] = fail
choice (p ∷ ps) = p ∣ choice ps
-- choiceMap f xs ≈ choice (map f xs), but avoids use of Vec and
-- fromList.
choiceMap-corners : {A : Set} → (A → Corners) → List A → Corners
choiceMap-corners c [] = ε
choiceMap-corners c (x ∷ xs) = c x ∪ choiceMap-corners c xs
choiceMap : ∀ {NT Tok R} {A : Set} {c : A → Corners} →
((x : A) → Parser NT Tok (false ◇ c x) R) →
(xs : List A) →
Parser NT Tok (false ◇ choiceMap-corners c xs) R
choiceMap f [] = fail
choiceMap f (x ∷ xs) = f x ∣ choiceMap f xs
------------------------------------------------------------------------
-- sat and friends
sat : ∀ {NT Tok R} → (Tok → Maybe R) → Parser NT Tok (0I · 1I) R
sat {NT} {Tok} {R} p = token !>>= λ c → ♯ ok (p c)
where
mutual
okIndex : Maybe R → Index
okIndex nothing = _
okIndex (just _) = _
ok : (x : Maybe R) → Parser NT Tok (okIndex x) R
ok nothing = fail
ok (just x) = return x
sat' : ∀ {NT Tok} → (Tok → Bool) → Parser NT Tok _ ⊤
sat' p = sat (boolToMaybe ∘ p)
any : ∀ {NT Tok} → Parser NT Tok _ Tok
any = sat just
------------------------------------------------------------------------
-- Token parsers
module Token (A : DecSetoid Level.zero Level.zero) where
open DecSetoid A using (_≟_) renaming (Carrier to Tok)
-- Parses a given token (or, really, a given equivalence class of
-- tokens).
tok : ∀ {NT} → Tok → Parser NT Tok _ Tok
tok tok = sat p
where
p : Tok → Maybe Tok
p tok′ with tok ≟ tok′
... | yes _ = just tok′
... | no _ = nothing
-- Parses a sequence of tokens.
theString : ∀ {NT n} → Vec Tok n → Parser NT Tok _ (Vec Tok n)
theString cs = sequence (Vec.map tok cs)
------------------------------------------------------------------------
-- Character parsers
digit : ∀ {NT} → Parser NT Char _ ℕ
digit = 0 <$ tok '0'
∣ 1 <$ tok '1'
∣ 2 <$ tok '2'
∣ 3 <$ tok '3'
∣ 4 <$ tok '4'
∣ 5 <$ tok '5'
∣ 6 <$ tok '6'
∣ 7 <$ tok '7'
∣ 8 <$ tok '8'
∣ 9 <$ tok '9'
where open Token Char.decSetoid
number : ∀ {NT} → Parser NT Char _ ℕ
number = toNum <$> digit +
where
toNum = foldr (λ n x → 10 * x + n) 0 ∘ reverse
-- whitespace recognises an incomplete but useful list of whitespace
-- characters.
whitespace : ∀ {NT} → Parser NT Char _ ⊤
whitespace = sat' isSpace
where
isSpace = λ c →
(c == ' ') ∨ (c == '\t') ∨ (c == '\n') ∨ (c == '\r')
| {
"alphanum_fraction": 0.5216625572,
"avg_line_length": 29.4961038961,
"ext": "agda",
"hexsha": "fc73f72245d29e293bec4e32e1f32c999656a307",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "StructurallyRecursiveDescentParsing/Lib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "StructurallyRecursiveDescentParsing/Lib.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "StructurallyRecursiveDescentParsing/Lib.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 3848,
"size": 11356
} |
{-# OPTIONS --without-K --safe #-}
open import Axiom.Extensionality.Propositional using (Extensionality)
module Cats.Category.Sets.Facts.Exponential
(funext : ∀ {a b} → Extensionality a b)
where
open import Data.Product using (_×_ ; _,_ ; proj₁ ; proj₂)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym)
open import Cats.Category
open import Cats.Category.Sets using (Sets)
open import Cats.Category.Sets.Facts.Product using (hasBinaryProducts)
instance
hasExponentials : ∀ {l} → HasExponentials (Sets l)
hasExponentials .HasExponentials.hasBinaryProducts = hasBinaryProducts
hasExponentials .HasExponentials._↝′_ B C = record
{ Cᴮ = B → C
; eval = λ { (f , x) → f x }
; curry′ = λ f → record
{ arr = λ a b → f (a , b)
; prop = λ x → refl
; unique = λ eq a → funext λ b → sym (eq _)
}
}
| {
"alphanum_fraction": 0.6689734717,
"avg_line_length": 30.9642857143,
"ext": "agda",
"hexsha": "ce0cb9533e25768652825d2222a454caa166bd97",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Sets/Facts/Exponential.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Sets/Facts/Exponential.agda",
"max_line_length": 74,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Sets/Facts/Exponential.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 258,
"size": 867
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics hiding (take; drop; take-drop-split)
open import lib.types.Pointed
open import lib.types.Paths
module lib.types.FunctionSeq where
infixr 80 _◃∘_
data FunctionSeq {i} : Type i → Type i → Type (lsucc i) where
idf-seq : {A : Type i} → FunctionSeq A A
_◃∘_ : {A B C : Type i} (g : B → C) (fs : FunctionSeq A B) → FunctionSeq A C
infix 30 _–→_
_–→_ = FunctionSeq
infix 90 _◃idf
_◃idf : ∀ {i} {A B : Type i} → (A → B) → A –→ B
_◃idf fs = fs ◃∘ idf-seq
compose : ∀ {i} {A B : Type i} → (A –→ B) → A → B
compose idf-seq = idf _
compose (g ◃∘ fs) = g ∘ compose fs
de⊙-seq : ∀ {i} {X Y : Ptd i} → (X ⊙–→ Y) → (de⊙ X –→ de⊙ Y)
de⊙-seq ⊙idf-seq = idf-seq
de⊙-seq (f ◃⊙∘ fs) = fst f ◃∘ de⊙-seq fs
de⊙-seq-⊙compose : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y)
→ compose (de⊙-seq fs) == fst (⊙compose fs)
de⊙-seq-⊙compose ⊙idf-seq = idp
de⊙-seq-⊙compose (f ◃⊙∘ fs) = ap (fst f ∘_) (de⊙-seq-⊙compose fs)
private
pt-seq' : ∀ {i} {j} {X Y : Ptd i} {C : Type j} (g : de⊙ Y → C) (fs : X ⊙–→ Y)
→ g (compose (de⊙-seq fs) (pt X)) =-= g (pt Y)
pt-seq' g ⊙idf-seq = []
pt-seq' g (f ◃⊙∘ fs) =
pt-seq' (g ∘ fst f) fs ∙∙
ap g (snd f) ◃∎
pt-seq : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y)
→ compose (de⊙-seq fs) (pt X) =-= pt Y
pt-seq ⊙idf-seq = []
pt-seq (f ◃⊙∘ fs) = pt-seq' (fst f) fs ∙▹ snd f
private
⊙compose-pt' : ∀ {i} {j} {X Y : Ptd i} {C : Type j} (g : de⊙ Y → C) (fs : X ⊙–→ Y)
→ ap g (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
ap g (snd (⊙compose fs)) ◃∎
=ₛ
↯ (pt-seq' g fs) ◃∎
⊙compose-pt' g ⊙idf-seq = =ₛ-in idp
⊙compose-pt' {_} {_} {X} g (f ◃⊙∘ fs) =
ap g (app= (ap (fst f ∘_) (de⊙-seq-⊙compose fs)) (pt X)) ◃∙
ap g (snd (⊙compose (f ◃⊙∘ fs))) ◃∎
=ₛ₁⟨ 0 & 1 & ∘-ap g (_$ pt X) (ap (fst f ∘_) (de⊙-seq-⊙compose fs)) ∙
∘-ap (λ h → g (h (pt X))) (fst f ∘_) (de⊙-seq-⊙compose fs) ∙
ap-∘ (g ∘ fst f) (_$ pt X) (de⊙-seq-⊙compose fs) ⟩
ap (g ∘ fst f) (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
ap g (snd (⊙compose (f ◃⊙∘ fs))) ◃∎
=ₛ⟨ 1 & 1 & ap-seq-∙ g (ap (fst f) (snd (⊙compose fs)) ◃∙ snd f ◃∎) ⟩
ap (g ∘ fst f) (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
ap g (ap (fst f) (snd (⊙compose fs))) ◃∙
ap g (snd f) ◃∎
=ₛ₁⟨ 1 & 1 & ∘-ap g (fst f) (snd (⊙compose fs)) ⟩
ap (g ∘ fst f) (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
ap (g ∘ fst f) (snd (⊙compose fs)) ◃∙
ap g (snd f) ◃∎
=ₛ⟨ 0 & 2 & ⊙compose-pt' (g ∘ fst f) fs ⟩
↯ (pt-seq' (g ∘ fst f) fs) ◃∙
ap g (snd f) ◃∎
=ₛ₁⟨ ! (↯-∙∙ (pt-seq' (g ∘ fst f) fs) (ap g (snd f) ◃∎)) ⟩
↯ (pt-seq' (g ∘ fst f) fs ∙▹ ap g (snd f)) ◃∎ ∎ₛ
⊙compose-pt : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y)
→ app= (de⊙-seq-⊙compose fs) (pt X) ◃∙
snd (⊙compose fs) ◃∎
=ₛ
↯ (pt-seq fs) ◃∎
⊙compose-pt ⊙idf-seq = =ₛ-in idp
⊙compose-pt {_} {X} {Y} (f ◃⊙∘ fs) =
app= (de⊙-seq-⊙compose (f ◃⊙∘ fs)) (pt X) ◃∙
snd (f ⊙∘ ⊙compose fs) ◃∎
=ₛ⟨ 1 & 1 & expand (ap (fst f) (snd (⊙compose fs)) ◃∙ snd f ◃∎) ⟩
app= (de⊙-seq-⊙compose (f ◃⊙∘ fs)) (pt X) ◃∙
ap (fst f) (snd (⊙compose fs)) ◃∙
snd f ◃∎
=ₛ₁⟨ 0 & 1 & ∘-ap (_$ pt X) (fst f ∘_) (de⊙-seq-⊙compose fs) ∙
ap-∘ (fst f) (_$ pt X) (de⊙-seq-⊙compose fs) ⟩
ap (fst f) (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
ap (fst f) (snd (⊙compose fs)) ◃∙
snd f ◃∎
=ₛ⟨ 0 & 2 & ⊙compose-pt' (fst f) fs ⟩
↯ (pt-seq' (fst f) fs) ◃∙
snd f ◃∎
=ₛ₁⟨ ! (↯-∙∙ (pt-seq' (fst f) fs) (snd f ◃∎)) ⟩
↯ (pt-seq' (fst f) fs ∙∙ snd f ◃∎) ◃∎ ∎ₛ
record _=∘_ {i} {A B : Type i} (fs gs : A –→ B) : Type i where
constructor =∘-in
field
=∘-out : compose fs == compose gs
open _=∘_ public
abstract
de⊙-seq-=⊙∘ : ∀ {i} {X Y : Ptd i} {fs gs : X ⊙–→ Y}
→ fs =⊙∘ gs
→ de⊙-seq fs =∘ de⊙-seq gs
de⊙-seq-=⊙∘ {fs = fs} {gs = gs} p = =∘-in $
compose (de⊙-seq fs)
=⟨ de⊙-seq-⊙compose fs ⟩
fst (⊙compose fs)
=⟨ ap fst (=⊙∘-out p) ⟩
fst (⊙compose gs)
=⟨ ! (de⊙-seq-⊙compose gs) ⟩
compose (de⊙-seq gs) =∎
⊙seq-λ= : ∀ {i} {X Y : Ptd i} {fs gs : X ⊙–→ Y}
→ (p : compose (de⊙-seq fs) ∼ compose (de⊙-seq gs))
→ pt-seq fs =ₛ p (pt X) ◃∙ pt-seq gs
→ fs =⊙∘ gs
⊙seq-λ= {_} {X} {Y} {fs} {gs} p q =
=⊙∘-in $
pair= (! (de⊙-seq-⊙compose fs) ∙ λ= p ∙ de⊙-seq-⊙compose gs) $
↓-app=cst-in $ =ₛ-out $
snd (⊙compose fs) ◃∎
=ₛ⟨ pre-rotate-in (⊙compose-pt fs) ⟩
! (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
↯ (pt-seq fs) ◃∎
=ₛ₁⟨ 1 & 1 & =ₛ-out q ⟩
! (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
↯ (p (pt X) ◃∙ pt-seq gs) ◃∎
=ₛ⟨ 1 & 1 & =ₛ-in {t = p (pt X) ◃∙ ↯ (pt-seq gs) ◃∎} $
↯-∙∙ (p (pt X) ◃∎) (pt-seq gs) ⟩
! (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
p (pt X) ◃∙
↯ (pt-seq gs) ◃∎
=ₛ⟨ 2 & 1 & !ₛ (⊙compose-pt gs) ⟩
! (app= (de⊙-seq-⊙compose fs) (pt X)) ◃∙
p (pt X) ◃∙
app= (de⊙-seq-⊙compose gs) (pt X) ◃∙
snd (⊙compose gs) ◃∎
=ₛ₁⟨ 0 & 1 & !-ap (_$ pt X) (de⊙-seq-⊙compose fs) ⟩
app= (! (de⊙-seq-⊙compose fs)) (pt X) ◃∙
p (pt X) ◃∙
app= (de⊙-seq-⊙compose gs) (pt X) ◃∙
snd (⊙compose gs) ◃∎
=ₛ₁⟨ 1 & 1 & ! (app=-β p (pt X)) ⟩
app= (! (de⊙-seq-⊙compose fs)) (pt X) ◃∙
app= (λ= p) (pt X) ◃∙
app= (de⊙-seq-⊙compose gs) (pt X) ◃∙
snd (⊙compose gs) ◃∎
=ₛ⟨ 0 & 3 & ∙-ap-seq (_$ pt X) (_ ◃∙ _ ◃∙ _ ◃∎) ⟩
app= (! (de⊙-seq-⊙compose fs) ∙ λ= p ∙ de⊙-seq-⊙compose gs) (pt X) ◃∙
snd (⊙compose gs) ◃∎ ∎ₛ
abstract
!⊙∘ : ∀ {i} {X Y : Ptd i} {fs gs : X ⊙–→ Y} → fs =⊙∘ gs → gs =⊙∘ fs
!⊙∘ (=⊙∘-in p) = =⊙∘-in (! p)
⊙expand : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y) → (⊙compose fs ◃⊙idf) =⊙∘ fs
⊙expand fs = =⊙∘-in idp
⊙contract : ∀ {i} {X Y : Ptd i} {fs : X ⊙–→ Y} → fs =⊙∘ (⊙compose fs ◃⊙idf)
⊙contract = =⊙∘-in idp
private
_∙⊙∘_ : ∀ {i} {X Y : Ptd i} {fs gs hs : X ⊙–→ Y} → fs =⊙∘ gs → gs =⊙∘ hs → fs =⊙∘ hs
_∙⊙∘_ (=⊙∘-in p) (=⊙∘-in q) = =⊙∘-in (p ∙ q)
point-from-target : ∀ {i} {X Y : Ptd i}
→ ℕ → (X ⊙–→ Y) → Ptd i
point-from-target {Y = Y} O fs = Y
point-from-target {Y = Y} (S n) ⊙idf-seq = Y
point-from-target (S n) (f ◃⊙∘ fs) = point-from-target n fs
take : ∀ {i} (n : ℕ) {X Y : Ptd i} (fs : X ⊙–→ Y) → point-from-target n fs ⊙–→ Y
take O s = ⊙idf-seq
take (S n) ⊙idf-seq = ⊙idf-seq
take (S n) (f ◃⊙∘ fs) = f ◃⊙∘ take n fs
drop : ∀ {i} (n : ℕ) {X Y : Ptd i} (fs : X ⊙–→ Y) → X ⊙–→ point-from-target n fs
drop 0 fs = fs
drop (S n) ⊙idf-seq = ⊙idf-seq
drop (S n) (f ◃⊙∘ fs) = drop n fs
infixr 80 _⊙∘∘_
_⊙∘∘_ : ∀ {i} {X Y Z : Ptd i} (gs : Y ⊙–→ Z) (fs : X ⊙–→ Y) → (X ⊙–→ Z)
⊙idf-seq ⊙∘∘ fs = fs
(g ◃⊙∘ gs) ⊙∘∘ fs = g ◃⊙∘ (gs ⊙∘∘ fs)
⊙compose-⊙∘∘ : ∀ {i} {X Y Z : Ptd i} (gs : Y ⊙–→ Z) (fs : X ⊙–→ Y)
→ ⊙compose (gs ⊙∘∘ fs) == ⊙compose gs ⊙∘ ⊙compose fs
⊙compose-⊙∘∘ ⊙idf-seq fs = ! (⊙λ= (⊙∘-unit-l (⊙compose fs)))
⊙compose-⊙∘∘ (g ◃⊙∘ gs) fs =
ap (g ⊙∘_) (⊙compose-⊙∘∘ gs fs) ∙
! (⊙λ= (⊙∘-assoc g (⊙compose gs) (⊙compose fs)))
take-drop-split' : ∀ {i} {X Y : Ptd i} (n : ℕ) (fs : X ⊙–→ Y)
→ fs == take n fs ⊙∘∘ drop n fs
take-drop-split' O fs = idp
take-drop-split' (S n) ⊙idf-seq = idp
take-drop-split' (S n) (f ◃⊙∘ fs) = ap (f ◃⊙∘_) (take-drop-split' n fs)
take-drop-split : ∀ {i} {X Y : Ptd i} (n : ℕ) (s : X ⊙–→ Y)
→ ⊙compose s ◃⊙idf =⊙∘ ⊙compose (take n s) ◃⊙∘ ⊙compose (drop n s) ◃⊙idf
take-drop-split n fs = =⊙∘-in $
⊙compose fs
=⟨ ap ⊙compose (take-drop-split' n fs) ⟩
⊙compose (take n fs ⊙∘∘ drop n fs)
=⟨ ⊙compose-⊙∘∘ (take n fs) (drop n fs) ⟩
⊙compose (take n fs) ⊙∘ ⊙compose (drop n fs) =∎
abstract
private
infixr 10 _⊙compose=⟨_&_&_&_⟩_
_⊙compose=⟨_&_&_&_⟩_ : ∀ {i} {X Y : Ptd i} {f : X ⊙→ Y}
→ (fs : X ⊙–→ Y)
→ (n : ℕ) (m : ℕ)
→ (gs : point-from-target m (drop n fs) ⊙–→ point-from-target n fs)
→ ⊙compose (take m (drop n fs)) == ⊙compose gs
→ ⊙compose (take n fs ⊙∘∘ gs ⊙∘∘ drop m (drop n fs)) == f
→ ⊙compose fs == f
_⊙compose=⟨_&_&_&_⟩_ {f = f} fs n m gs p p' =
⊙compose fs
=⟨ =⊙∘-out (take-drop-split n fs) ⟩
⊙compose (take n fs) ⊙∘ ⊙compose (drop n fs)
=⟨ ap (⊙compose (take n fs) ⊙∘_) (=⊙∘-out (take-drop-split m (drop n fs))) ⟩
⊙compose (take n fs) ⊙∘ ⊙compose (take m (drop n fs)) ⊙∘ ⊙compose (drop m (drop n fs))
=⟨ ap (λ v → ⊙compose (take n fs) ⊙∘ v ⊙∘ ⊙compose (drop m (drop n fs))) p ⟩
⊙compose (take n fs) ⊙∘ ⊙compose gs ⊙∘ ⊙compose (drop m (drop n fs))
=⟨ ap (⊙compose (take n fs) ⊙∘_) (! (⊙compose-⊙∘∘ gs (drop m (drop n fs)))) ⟩
⊙compose (take n fs) ⊙∘ ⊙compose (gs ⊙∘∘ drop m (drop n fs))
=⟨ ! (⊙compose-⊙∘∘ (take n fs) (gs ⊙∘∘ drop m (drop n fs))) ⟩
⊙compose (take n fs ⊙∘∘ gs ⊙∘∘ drop m (drop n fs))
=⟨ p' ⟩
f =∎
infixr 10 _=⊙∘⟨_⟩_
_=⊙∘⟨_⟩_ : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y) {gs hs : X ⊙–→ Y}
→ fs =⊙∘ gs
→ gs =⊙∘ hs
→ fs =⊙∘ hs
_=⊙∘⟨_⟩_ _ p q = p ∙⊙∘ q
infixr 10 _=⊙∘⟨_&_&_⟩_
_=⊙∘⟨_&_&_⟩_ : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y) {gs : X ⊙–→ Y}
→ (m n : ℕ)
→ {hs : point-from-target n (drop m fs) ⊙–→ point-from-target m fs}
→ take n (drop m fs) =⊙∘ hs
→ take m fs ⊙∘∘ hs ⊙∘∘ drop n (drop m fs) =⊙∘ gs
→ fs =⊙∘ gs
_=⊙∘⟨_&_&_⟩_ fs m n {hs} p p' = =⊙∘-in (fs ⊙compose=⟨ m & n & hs & =⊙∘-out p ⟩ =⊙∘-out p')
infixr 10 _=⊙∘₁⟨_⟩_
_=⊙∘₁⟨_⟩_ : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y) {gs : X ⊙–→ Y}
→ {h : X ⊙→ Y}
→ ⊙compose fs == h
→ h ◃⊙idf =⊙∘ gs
→ fs =⊙∘ gs
_=⊙∘₁⟨_⟩_ fs p p' = =⊙∘-in p ∙⊙∘ p'
infixr 10 _=⊙∘₁⟨_&_&_⟩_
_=⊙∘₁⟨_&_&_⟩_ : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y) {gs : X ⊙–→ Y}
→ (m n : ℕ)
→ {h : point-from-target n (drop m fs) ⊙→ point-from-target m fs}
→ ⊙compose (take n (drop m fs)) == h
→ take m fs ⊙∘∘ h ◃⊙∘ drop n (drop m fs) =⊙∘ gs
→ fs =⊙∘ gs
_=⊙∘₁⟨_&_&_⟩_ fs m n {h} p p' = fs =⊙∘⟨ m & n & (=⊙∘-in {gs = h ◃⊙idf} p) ⟩ p'
infix 15 _∎⊙∘
_∎⊙∘ : ∀ {i} {X Y : Ptd i} (fs : X ⊙–→ Y) → fs =⊙∘ fs
_∎⊙∘ _ = =⊙∘-in idp
⊙coe-seq : ∀ {i} {X Y : Ptd i}
→ X =-= Y
→ X ⊙–→ Y
⊙coe-seq [] = ⊙idf-seq
⊙coe-seq (p ◃∙ ps) = ⊙coe-seq ps ⊙∘∘ ⊙coe p ◃⊙idf
⊙coe-seq-∙ : ∀ {i} {X Y : Ptd i} (ps : X =-= Y)
→ ⊙coe (↯ ps) ◃⊙idf =⊙∘ ⊙coe-seq ps
⊙coe-seq-∙ [] = =⊙∘-in idp
⊙coe-seq-∙ (p ◃∙ ps) =
⊙coe (↯ (p ◃∙ ps)) ◃⊙idf
=⊙∘₁⟨ ap ⊙coe (↯-∙∙ (p ◃∎) ps) ⟩
⊙coe (p ∙ ↯ ps) ◃⊙idf
=⊙∘⟨ ⊙coe-∙ p (↯ ps) ⟩
⊙coe (↯ ps) ◃⊙∘ ⊙coe p ◃⊙idf
=⊙∘⟨ 0 & 1 & ⊙coe-seq-∙ ps ⟩
⊙coe-seq ps ⊙∘∘ ⊙coe p ◃⊙idf ∎⊙∘
⊙coe-seq-=ₛ : ∀ {i} {X Y : Ptd i} {ps qs : X =-= Y}
→ ps =ₛ qs
→ ⊙coe-seq ps =⊙∘ ⊙coe-seq qs
⊙coe-seq-=ₛ {ps = ps} {qs = qs} r =
⊙coe-seq ps
=⊙∘⟨ !⊙∘ (⊙coe-seq-∙ ps) ⟩
⊙coe (↯ ps) ◃⊙idf
=⊙∘₁⟨ ap ⊙coe (=ₛ-out r) ⟩
⊙coe (↯ qs) ◃⊙idf
=⊙∘⟨ ⊙coe-seq-∙ qs ⟩
⊙coe-seq qs ∎⊙∘
| {
"alphanum_fraction": 0.4367719691,
"avg_line_length": 35.068627451,
"ext": "agda",
"hexsha": "d20cdb5ec221ffeb308f621f247654f4b22485b5",
"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/types/FunctionSeq.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/types/FunctionSeq.agda",
"max_line_length": 92,
"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/types/FunctionSeq.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": 6344,
"size": 10731
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- The Colist type and some operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Colist where
open import Size
open import Data.Unit
open import Data.Nat.Base
open import Data.Product using (_×_ ; _,_)
open import Data.These using (These; this; that; these)
open import Data.Maybe using (Maybe; nothing; just)
open import Data.List.Base using (List; []; _∷_)
open import Data.List.NonEmpty using (List⁺; _∷_)
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Data.BoundedVec as BVec using (BoundedVec)
open import Function
open import Codata.Thunk using (Thunk; force)
open import Codata.Conat as Conat using (Conat ; zero ; suc)
open import Codata.Cowriter as CW using (Cowriter; _∷_)
open import Codata.Delay as Delay using (Delay ; now ; later)
open import Codata.Stream using (Stream ; _∷_)
data Colist {a} (A : Set a) (i : Size) : Set a where
[] : Colist A i
_∷_ : A → Thunk (Colist A) i → Colist A i
module _ {w a} {W : Set w} {A : Set a} where
------------------------------------------------------------------------
-- Relationship to Cowriter.
fromCowriter : ∀ {i} → Cowriter W A i → Colist W i
fromCowriter CW.[ _ ] = []
fromCowriter (w ∷ ca) = w ∷ λ where .force → fromCowriter (ca .force)
module _ {a} {A : Set a} where
toCowriter : ∀ {i} → Colist A i → Cowriter A ⊤ i
toCowriter [] = CW.[ _ ]
toCowriter (a ∷ as) = a ∷ λ where .force → toCowriter (as .force)
------------------------------------------------------------------------
-- Basic functions.
[_] : A → Colist A ∞
[ a ] = a ∷ λ where .force → []
length : ∀ {i} → Colist A i → Conat i
length [] = zero
length (x ∷ xs) = suc λ where .force → length (xs .force)
replicate : ∀ {i} → Conat i → A → Colist A i
replicate zero a = []
replicate (suc n) a = a ∷ λ where .force → replicate (n .force) a
infixr 5 _++_ _⁺++_
_++_ : ∀ {i} → Colist A i → Colist A i → Colist A i
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ λ where .force → xs .force ++ ys
lookup : ℕ → Colist A ∞ → Maybe A
lookup n [] = nothing
lookup zero (a ∷ as) = just a
lookup (suc n) (a ∷ as) = lookup n (as .force)
colookup : ∀ {i} → Conat i → Colist A i → Delay (Maybe A) i
colookup n [] = now nothing
colookup zero (a ∷ as) = now (just a)
colookup (suc n) (a ∷ as) =
later λ where .force → colookup (n .force) (as .force)
take : ∀ (n : ℕ) → Colist A ∞ → BoundedVec A n
take zero xs = BVec.[]
take n [] = BVec.[]
take (suc n) (x ∷ xs) = x BVec.∷ take n (xs .force)
cotake : ∀ {i} → Conat i → Stream A i → Colist A i
cotake zero xs = []
cotake (suc n) (x ∷ xs) = x ∷ λ where .force → cotake (n .force) (xs .force)
fromList : List A → Colist A ∞
fromList [] = []
fromList (x ∷ xs) = x ∷ λ where .force → fromList xs
_⁺++_ : ∀ {i} → List⁺ A → Thunk (Colist A) i → Colist A i
(x ∷ xs) ⁺++ ys = x ∷ λ where .force → fromList xs ++ ys .force
fromStream : ∀ {i} → Stream A i → Colist A i
fromStream = cotake Conat.infinity
module _ {ℓ} {A : Set ℓ} where
chunksOf : (n : ℕ) → Colist A ∞ → Cowriter (Vec A n) (BoundedVec A n) ∞
chunksOf n = chunksOfAcc n id id module ChunksOf where
chunksOfAcc : ∀ {i} m →
-- We have two continuations but we are only ever going to use one.
-- If we had linear types, we would write the type using the & conjunction here.
(k≤ : BoundedVec A m → BoundedVec A n) →
(k≡ : Vec A m → Vec A n) →
-- Finally we chop up the input stream.
Colist A ∞ → Cowriter (Vec A n) (BoundedVec A n) i
chunksOfAcc zero k≤ k≡ as = k≡ [] ∷ λ where .force → chunksOfAcc n id id as
chunksOfAcc (suc k) k≤ k≡ [] = CW.[ k≤ BVec.[] ]
chunksOfAcc (suc k) k≤ k≡ (a ∷ as) =
chunksOfAcc k (k≤ ∘ (a BVec.∷_)) (k≡ ∘ (a ∷_)) (as .force)
module _ {a b} {A : Set a} {B : Set b} where
map : ∀ {i} (f : A → B) → Colist A i → Colist B i
map f [] = []
map f (a ∷ as) = f a ∷ λ where .force → map f (as .force)
unfold : ∀ {i} → (A → Maybe (A × B)) → A → Colist B i
unfold next seed with next seed
... | nothing = []
... | just (seed′ , b) = b ∷ λ where .force → unfold next seed′
scanl : ∀ {i} → (B → A → B) → B → Colist A i → Colist B i
scanl c n [] = n ∷ λ where .force → []
scanl c n (a ∷ as) = n ∷ λ where .force → scanl c (c n a) (as .force)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
alignWith : ∀ {i} → (These A B → C) → Colist A i → Colist B i → Colist C i
alignWith f [] bs = map (f ∘′ that) bs
alignWith f as@(_ ∷ _) [] = map (f ∘′ this) as
alignWith f (a ∷ as) (b ∷ bs) =
f (these a b) ∷ λ where .force → alignWith f (as .force) (bs .force)
zipWith : ∀ {i} → (A → B → C) → Colist A i → Colist B i → Colist C i
zipWith f [] bs = []
zipWith f as [] = []
zipWith f (a ∷ as) (b ∷ bs) =
f a b ∷ λ where .force → zipWith f (as .force) (bs .force)
module _ {a b} {A : Set a} {B : Set b} where
align : ∀ {i} → Colist A i → Colist B i → Colist (These A B) i
align = alignWith id
zip : ∀ {i} → Colist A i → Colist B i → Colist (A × B) i
zip = zipWith _,_
ap : ∀ {i} → Colist (A → B) i → Colist A i → Colist B i
ap = zipWith _$′_
| {
"alphanum_fraction": 0.5279912184,
"avg_line_length": 35.4935064935,
"ext": "agda",
"hexsha": "a2b4346c0cddb8cd4b1ef57ed37bf7f207641608",
"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/Codata/Colist.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/Codata/Colist.agda",
"max_line_length": 88,
"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/Codata/Colist.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1939,
"size": 5466
} |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <esz@posteo.de>
module Algebra.Group where
open import Algebra.Group.Group public
open import Algebra.Group.Monoid public
open import Algebra.Group.Semigroup public
| {
"alphanum_fraction": 0.7824427481,
"avg_line_length": 26.2,
"ext": "agda",
"hexsha": "2f871417d2c65c970799fb154750787dae3bf5f2",
"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": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "esoeylemez/agda-simple",
"max_forks_repo_path": "Algebra/Group.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"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": "esoeylemez/agda-simple",
"max_issues_repo_path": "Algebra/Group.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "esoeylemez/agda-simple",
"max_stars_repo_path": "Algebra/Group.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z",
"num_tokens": 76,
"size": 262
} |
{-# OPTIONS --without-K #-}
module Agda.Builtin.Coinduction where
infix 1000 ♯_
{-# BUILTIN INFINITY ∞ #-}
{-# BUILTIN SHARP ♯_ #-}
{-# BUILTIN FLAT ♭ #-}
| {
"alphanum_fraction": 0.5808383234,
"avg_line_length": 16.7,
"ext": "agda",
"hexsha": "3359341b69eb8f23e4ccdf635b97cbb18baeda84",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Coinduction.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": "src/data/lib/prim/Agda/Builtin/Coinduction.agda",
"max_line_length": 37,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Coinduction.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-07T10:49:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-07T10:49:57.000Z",
"num_tokens": 53,
"size": 167
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
{-
Various combinators for working with Isomorphisms in the
context of morphism equalities
both for Category (Switch) and IsGroupoid (GroupoidR)
-}
module Categories.Morphism.Reasoning.Iso {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Function renaming (id to idᶠ; _∘_ to _∙_)
open import Categories.Category.Groupoid using (IsGroupoid)
open import Categories.Morphism C
open import Categories.Morphism.Reasoning.Core C
open import Relation.Binary hiding (_⇒_)
open Category C
private
variable
A B X Y : Obj
f g h k : X ⇒ Y
open HomReasoning
module Switch (i : X ≅ Y) where
open _≅_ i
switch-fromtoˡ : from ∘ h ≈ k → h ≈ to ∘ k
switch-fromtoˡ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelˡ isoˡ ⟩
to ∘ (from ∘ h) ≈⟨ refl⟩∘⟨ pf ⟩
to ∘ k ∎
switch-tofromˡ : to ∘ h ≈ k → h ≈ from ∘ k
switch-tofromˡ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelˡ isoʳ ⟩
from ∘ (to ∘ h) ≈⟨ refl⟩∘⟨ pf ⟩
from ∘ k ∎
switch-fromtoʳ : h ∘ from ≈ k → h ≈ k ∘ to
switch-fromtoʳ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelʳ isoʳ ⟩
(h ∘ from) ∘ to ≈⟨ pf ⟩∘⟨refl ⟩
k ∘ to ∎
switch-tofromʳ : h ∘ to ≈ k → h ≈ k ∘ from
switch-tofromʳ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelʳ isoˡ ⟩
(h ∘ to) ∘ from ≈⟨ pf ⟩∘⟨refl ⟩
k ∘ from ∎
cancel-fromʳ : h ∘ from ≈ k ∘ from → h ≈ k
cancel-fromʳ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelʳ isoʳ ⟩
(h ∘ from) ∘ to ≈⟨ pf ⟩∘⟨refl ⟩
(k ∘ from) ∘ to ≈⟨ cancelʳ isoʳ ⟩
k ∎
cancel-fromˡ : from ∘ h ≈ from ∘ k → h ≈ k
cancel-fromˡ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelˡ isoˡ ⟩
to ∘ (from ∘ h) ≈⟨ refl⟩∘⟨ pf ⟩
to ∘ (from ∘ k) ≈⟨ cancelˡ isoˡ ⟩
k ∎
cancel-toʳ : h ∘ to ≈ k ∘ to → h ≈ k
cancel-toʳ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelʳ isoˡ ⟩
(h ∘ to) ∘ from ≈⟨ pf ⟩∘⟨refl ⟩
(k ∘ to) ∘ from ≈⟨ cancelʳ isoˡ ⟩
k ∎
cancel-toˡ : to ∘ h ≈ to ∘ k → h ≈ k
cancel-toˡ {h = h} {k = k} pf = begin
h ≈˘⟨ cancelˡ isoʳ ⟩
from ∘ (to ∘ h) ≈⟨ refl⟩∘⟨ pf ⟩
from ∘ (to ∘ k) ≈⟨ cancelˡ isoʳ ⟩
k ∎
-- We can flip an iso i in a commuting triangle, like so:
--
-- i i⁻¹
-- X --------> Y X <-------- Y
-- \ ≃ / \ ≃ /
-- \ / \ /
-- g \ / h ===> g \ / h
-- \ / \ /
-- V V V V
-- A A
--
flip-iso : {g : X ⇒ A} {h : Y ⇒ A} → g ≈ h ∘ from → g ∘ to ≈ h
flip-iso tr₁ = sym (switch-fromtoʳ (sym tr₁))
-- Consider two commuting squares
--
-- f₁ f₂
-- X -------> A X -------> A
-- | | | |
-- | | | |
-- ≃ | i | h ≃ | i | h
-- | | | |
-- V V V V
-- Y -------> B Y -------> B
-- g₁ g₂
--
-- with i an isomorphism. Then g₁ ≈ g₂ if f₁ ≈ f₂.
push-eq : {f₁ f₂ : X ⇒ A} {g₁ g₂ : Y ⇒ B} {h : A ⇒ B} →
CommutativeSquare f₁ from h g₁ →
CommutativeSquare f₂ from h g₂ →
f₁ ≈ f₂ → g₁ ≈ g₂
push-eq {f₁ = f₁} {f₂} {g₁} {g₂} {h₂} sq₁ sq₂ hyp = begin
g₁ ≈˘⟨ flip-iso sq₁ ⟩
(h₂ ∘ f₁) ∘ to ≈⟨ ∘-resp-≈ˡ (∘-resp-≈ʳ hyp) ⟩
(h₂ ∘ f₂) ∘ to ≈⟨ flip-iso sq₂ ⟩
g₂ ∎
open Switch public
-- conjugates
module _ (i : A ≅ B) (j : X ≅ Y) where
private
module i = _≅_ i
module j = _≅_ j
conjugate-from : f ∘ i.from ≈ j.from ∘ g → j.to ∘ f ≈ g ∘ i.to
conjugate-from {f = f} {g = g} eq = begin
j.to ∘ f ≈⟨ introʳ i.isoʳ ⟩
(j.to ∘ f) ∘ i.from ∘ i.to ≈⟨ center eq ⟩
j.to ∘ (j.from ∘ g) ∘ i.to ≈⟨ center⁻¹ j.isoˡ refl ⟩
id ∘ g ∘ i.to ≈⟨ identityˡ ⟩
g ∘ i.to ∎
conjugate-to : j.to ∘ f ≈ g ∘ i.to → f ∘ i.from ≈ j.from ∘ g
conjugate-to {f = f} {g = g} eq = begin
f ∘ i.from ≈⟨ introˡ j.isoʳ ⟩
(j.from ∘ j.to) ∘ f ∘ i.from ≈⟨ center eq ⟩
j.from ∘ (g ∘ i.to) ∘ i.from ≈⟨ center⁻¹ refl i.isoˡ ⟩
(j.from ∘ g) ∘ id ≈⟨ identityʳ ⟩
j.from ∘ g ∎
module GroupoidR (G : IsGroupoid C) where
open IsGroupoid G using (_⁻¹; iso; equiv-obj)
switch-fromtoˡ′ : f ∘ h ≈ k → h ≈ f ⁻¹ ∘ k
switch-fromtoˡ′ = switch-fromtoˡ (equiv-obj _)
switch-tofromˡ′ : f ⁻¹ ∘ h ≈ k → h ≈ f ∘ k
switch-tofromˡ′ = switch-tofromˡ (equiv-obj _)
switch-fromtoʳ′ : h ∘ f ≈ k → h ≈ k ∘ f ⁻¹
switch-fromtoʳ′ = switch-fromtoʳ (equiv-obj _)
switch-tofromʳ′ : h ∘ f ⁻¹ ≈ k → h ≈ k ∘ f
switch-tofromʳ′ = switch-tofromʳ (equiv-obj _)
| {
"alphanum_fraction": 0.4282025819,
"avg_line_length": 31.46875,
"ext": "agda",
"hexsha": "f933717a76f02520299ff63c575f4090a8d4b4ef",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Morphism/Reasoning/Iso.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Morphism/Reasoning/Iso.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Morphism/Reasoning/Iso.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2123,
"size": 5035
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on floats
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Float.Properties where
open import Data.Bool.Base as Bool using (Bool)
open import Data.Float.Base
import Data.Word.Base as Word
import Data.Word.Properties as Wₚ
open import Relation.Nullary.Decidable as RN using (map′)
open import Relation.Binary
import Relation.Binary.Construct.On as On
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- Primitive properties
open import Agda.Builtin.Float.Properties
renaming (primFloatToWord64Injective to toWord-injective)
public
------------------------------------------------------------------------
-- Properties of _≈_
≈⇒≡ : _≈_ ⇒ _≡_
≈⇒≡ eq = toWord-injective _ _ (Wₚ.≈⇒≡ eq)
≈-reflexive : _≡_ ⇒ _≈_
≈-reflexive eq = Wₚ.≈-reflexive (cong toWord eq)
≈-refl : Reflexive _≈_
≈-refl = refl
≈-sym : Symmetric _≈_
≈-sym = sym
≈-trans : Transitive _≈_
≈-trans = trans
≈-subst : ∀ {ℓ} → Substitutive _≈_ ℓ
≈-subst P x≈y p = subst P (≈⇒≡ x≈y) p
infix 4 _≈?_
_≈?_ : Decidable _≈_
_≈?_ = On.decidable toWord Word._≈_ Wₚ._≈?_
≈-isEquivalence : IsEquivalence _≈_
≈-isEquivalence = record
{ refl = λ {i} → ≈-refl {i}
; sym = λ {i j} → ≈-sym {i} {j}
; trans = λ {i j k} → ≈-trans {i} {j} {k}
}
≈-setoid : Setoid _ _
≈-setoid = record
{ isEquivalence = ≈-isEquivalence
}
≈-isDecEquivalence : IsDecEquivalence _≈_
≈-isDecEquivalence = record
{ isEquivalence = ≈-isEquivalence
; _≟_ = _≈?_
}
≈-decSetoid : DecSetoid _ _
≈-decSetoid = record
{ isDecEquivalence = ≈-isDecEquivalence
}
------------------------------------------------------------------------
-- Properties of _≡_
infix 4 _≟_
_≟_ : DecidableEquality Float
x ≟ y = map′ ≈⇒≡ ≈-reflexive (x ≈? y)
≡-setoid : Setoid _ _
≡-setoid = setoid Float
≡-decSetoid : DecSetoid _ _
≡-decSetoid = decSetoid _≟_
------------------------------------------------------------------------
-- Boolean equality test.
infix 4 _==_
_==_ : Float → Float → Bool
w₁ == w₂ = RN.⌊ w₁ ≟ w₂ ⌋
------------------------------------------------------------------------
-- Properties of _<_
infix 4 _<?_
_<?_ : Decidable _<_
_<?_ = On.decidable toWord Word._<_ Wₚ._<?_
<-strictTotalOrder-≈ : StrictTotalOrder _ _ _
<-strictTotalOrder-≈ = On.strictTotalOrder Wₚ.<-strictTotalOrder-≈ toWord
| {
"alphanum_fraction": 0.5321821036,
"avg_line_length": 24.7378640777,
"ext": "agda",
"hexsha": "3f4b5c7568497536b0f378c24ec85855721c71ce",
"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/Float/Properties.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/Float/Properties.agda",
"max_line_length": 73,
"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/Float/Properties.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": 824,
"size": 2548
} |
open import Agda.Builtin.Equality
cong : ∀ {A B : Set} → (f : A → B) → ∀ {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
data ⊥ : Set where
data N : Set where
ze : N
su : (⊥ → N) → N
foo : N
foo = su (\ ())
postulate
ext : ∀ {A : Set} → (f g : ⊥ → A) → f ≡ g
foo-suc : foo ≡ su (\ _ → foo)
foo-suc = cong su (ext (λ ()) (λ _ → foo))
-- bad!
no-cycle : ∀ {n} → n ≡ su (\ _ → n) → ⊥
no-cycle ()
false : ⊥
false = no-cycle foo-suc
| {
"alphanum_fraction": 0.4681818182,
"avg_line_length": 15.7142857143,
"ext": "agda",
"hexsha": "87b0a3b9ad79f0946205b9ecedc02719634dbe6d",
"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/Issue4995.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/Issue4995.agda",
"max_line_length": 64,
"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/Issue4995.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": 193,
"size": 440
} |
module Automaton.Deterministic.Oper where
open import Automaton.Deterministic
open import Logic.Propositional
import Lvl
open import Data.Boolean
import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
open import Data.List renaming (∅ to [])
open import Data.Tuple as Tuple using (_,_) renaming (_⨯_ to _⨯'_)
open import Data.Tuple.Equivalence
open import Functional
open import Sets.ExtensionalPredicateSet as PredSet using (PredSet ; _∈_)
open import Structure.Operator
open import Structure.Relator.Proofs
open import Structure.Setoid
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₚ ℓₚ₁ ℓₚ₂ : Lvl.Level
private variable Q Q₁ Q₂ State : Type{ℓ}
private variable Σ Σ₁ Σ₂ Alphabet : Type{ℓ}
module _ ⦃ equiv₁ : Equiv{ℓₑ₁}(Q₁) ⦄ ⦃ equiv₂ : Equiv{ℓₑ₂}(Q₂) ⦄ ⦃ equivₑ : Equiv{ℓₑ₃}(Σ) ⦄ where
-- Automaton that accepts words accepted by both of the specified automatons
_⨯_ : Deterministic{ℓₚ = ℓₚ₁}(Q₁)(Σ) → Deterministic{ℓₚ = ℓₚ₂}(Q₂)(Σ) → Deterministic(Q₁ ⨯' Q₂)(Σ)
_⨯_ (deterministic δ₁ q₀₁ F₁) (deterministic δ₂ q₀₂ F₂) = deterministic δ ⦃ δ-op ⦄ q₀ F where
δ : (Q₁ ⨯' Q₂) → Σ → (Q₁ ⨯' Q₂)
δ(q₁ , q₂)(word) = (δ₁(q₁)(word) , δ₂(q₂)(word))
instance
δ-op : BinaryOperator(δ)
BinaryOperator.congruence δ-op ([∧]-intro xyl xyr) cc = [∧]-intro (congruence₂(δ₁) xyl cc) (congruence₂(δ₂) xyr cc)
q₀ : (Q₁ ⨯' Q₂)
q₀ = (q₀₁ , q₀₂)
F : PredSet(Q₁ ⨯' Q₂)
F = PredSet.intro (\{(q₁ , q₂) → (q₁ ∈ F₁) ∧ (q₂ ∈ F₂)})
⦃ [∧]-unaryRelator
⦃ rel-P = [∘]-unaryRelator ⦃ rel = PredSet.preserve-equiv F₁ ⦄ ⦄
⦃ rel-Q = [∘]-unaryRelator ⦃ rel = PredSet.preserve-equiv F₂ ⦄ ⦄
⦄
-- Automaton that accepts words accepted by any of the specified automatons
_+_ : Deterministic{ℓₚ = ℓₚ₁}(Q₁)(Σ) → Deterministic{ℓₚ = ℓₚ₂}(Q₂)(Σ) → Deterministic(Q₁ ⨯' Q₂)(Σ)
_+_ (deterministic δ₁ q₀₁ F₁) (deterministic δ₂ q₀₂ F₂) = deterministic δ q₀ F where
δ : (Q₁ ⨯' Q₂) → Σ → (Q₁ ⨯' Q₂)
δ(q₀₁ , q₀₂)(word) = (δ₁(q₀₁)(word) , δ₂(q₀₂)(word))
instance
δ-op : BinaryOperator(δ)
BinaryOperator.congruence δ-op ([∧]-intro xyl xyr) cc = [∧]-intro (congruence₂(δ₁) xyl cc) (congruence₂(δ₂) xyr cc)
q₀ : (Q₁ ⨯' Q₂)
q₀ = (q₀₁ , q₀₂)
F : PredSet(Q₁ ⨯' Q₂)
F = PredSet.intro (\{(q₁ , q₂) → (q₁ ∈ F₁) ∨ (q₂ ∈ F₂)})
⦃ [∨]-unaryRelator
⦃ rel-P = [∘]-unaryRelator ⦃ rel = PredSet.preserve-equiv F₁ ⦄ ⦄
⦃ rel-Q = [∘]-unaryRelator ⦃ rel = PredSet.preserve-equiv F₂ ⦄ ⦄
⦄
module _ ⦃ equiv : Equiv{ℓₑ}(Q) ⦄ ⦃ equivₑ : Equiv{ℓₑ₃}(Σ) ⦄ where
-- Automaton that accepts words not accepted by the specified automaton
∁_ : Deterministic{ℓₚ = ℓₚ}(Q)(Σ) → Deterministic(Q)(Σ)
∁_ (deterministic δ q₀ F) = deterministic δ q₀ (PredSet.∁ F)
| {
"alphanum_fraction": 0.6390489914,
"avg_line_length": 40.8235294118,
"ext": "agda",
"hexsha": "683467b7505872ed234f722a9c5c5dca4c927ced",
"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": "Automaton/Deterministic/Oper.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": "Automaton/Deterministic/Oper.agda",
"max_line_length": 121,
"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": "Automaton/Deterministic/Oper.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": 1199,
"size": 2776
} |
open import Agda.Builtin.Equality
postulate
A : Set
id : A → A
id x = x
mutual
?Y : A → A → A
?Y = _
?X : A → A → A
?X = _
-- This tries to solve ?X x x := ?Y x y, which fails but prunes
-- ?Y x y := ?Z x. Failing ?X := ?Y we then try the other direction
-- without realising that ?Y has been instantiated and (re)solve
-- ?Y x y := ?X x x, leaving ?Z hanging!
-- The `id` call is to make sure we get into `compareAtom`. The
-- corresponding code in `compareTerm` does the right thing.
constr₁ : ∀ x y → id (?X x x) ≡ id (?Y x y)
constr₁ x y = refl
-- We can then solve ?X.
constr₂ : ∀ x y → ?X x y ≡ x
constr₂ x y = refl
-- And check that they really are solved
checkY : ?Y ≡ λ x y → x
checkY = refl
checkX : ?X ≡ λ x y → x
checkX = refl
-- ...but we still have ?Z unsolved.
| {
"alphanum_fraction": 0.5860805861,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "3b3893980b28eabd4e0916884688dc0a5ee24ba0",
"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/Issue2978.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/Issue2978.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2978.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": 296,
"size": 819
} |
open import Prelude hiding (_<_)
module Implicits.Resolution.GenericFinite.TerminationCondition
where
open import Induction.WellFounded
open import Implicits.Syntax
record TerminationCondition : Set₁ where
field
TCtx : Set
_<_ : TCtx → TCtx → Set
_<?_ : (x y : TCtx) → Dec (x < y)
step : ∀ {ν} → TCtx → ICtx ν → Type ν → Type ν → SimpleType ν → TCtx
wf-< : Well-founded _<_
T-Acc : TCtx → Set
T-Acc Φ = Acc _<_ Φ
| {
"alphanum_fraction": 0.6532438479,
"avg_line_length": 23.5263157895,
"ext": "agda",
"hexsha": "bae74a677d06563b54cb2894ac874582c505648e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/GenericFinite/TerminationCondition.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/GenericFinite/TerminationCondition.agda",
"max_line_length": 72,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/GenericFinite/TerminationCondition.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 150,
"size": 447
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Finite where
open import Level
open import Data.Product using (Σ; _,_; ∃₂)
open import Function.Equality using (Π; _⟶_)
open import Function.Inverse
open import Data.Nat as ℕ hiding (_⊔_)
import Data.Fin as Fin
open import Data.Vec as Vec
open import Relation.Binary using (Setoid)
import Relation.Binary.PropositionalEquality as ≡
open import Categories.Category
open Π
FiniteSetoid : ∀ {c ℓ} n (S : Setoid c ℓ) → Set _
FiniteSetoid n S = Inverse (≡.setoid (Fin.Fin n)) S
record Finite {o ℓ e} (C : Category o ℓ e) : Set (o ⊔ ℓ ⊔ e) where
open Category C
field
∣Obj∣ : ℕ
∣_⇒_∣ : Obj → Obj → ℕ
Obj-finite : FiniteSetoid ∣Obj∣ (≡.setoid Obj)
⇒-finite : ∀ A B → FiniteSetoid ∣ A ⇒ B ∣ (hom-setoid {A} {B})
module Obj-finite = Inverse Obj-finite
module ⇒-finite A B = Inverse (⇒-finite A B)
private
Fins : ∀ n → Vec (Fin.Fin n) n
Fins ℕ.zero = []
Fins (ℕ.suc n) = Fin.fromℕ n ∷ Vec.map (Fin.raise 1) (Fins n)
-- enumeration of all objects
Objs : Vec Obj ∣Obj∣
Objs = Vec.map (Obj-finite.to ⟨$⟩_) (Fins ∣Obj∣)
private
ObjPairs : ∀ {a} {A : Set a} → (Obj → Obj → A) → Vec A (∣Obj∣ * ∣Obj∣)
ObjPairs {_} {A} f = Objs >>= ap
where ap : Obj → Vec A ∣Obj∣
ap X = Vec.map (f X) Objs
-- enumeration of all morphisms of a given pair of objects
⟦_⇒_⟧ : ∀ A B → Vec (A ⇒ B) ∣ A ⇒ B ∣
⟦ A ⇒ B ⟧ = Vec.map (⇒-finite.to A B ⟨$⟩_) (Fins ∣ A ⇒ B ∣)
-- number of all morphisms
∣-⇒-| : ℕ
∣-⇒-| = foldr (λ _ → ℕ) _+_ 0 (ObjPairs ∣_⇒_∣)
| {
"alphanum_fraction": 0.5948166877,
"avg_line_length": 28.25,
"ext": "agda",
"hexsha": "8efac41273f4576215209ec04e7bd5e81555df59",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Category/Finite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Category/Finite.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Category/Finite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 620,
"size": 1582
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some properties imply others
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Unary.Consequences where
open import Relation.Unary
open import Relation.Nullary using (recompute)
dec⟶recomputable : {a ℓ : _} {A : Set a} {P : Pred A ℓ} → Decidable P → Recomputable P
dec⟶recomputable P-dec = recompute (P-dec _)
| {
"alphanum_fraction": 0.5040322581,
"avg_line_length": 31,
"ext": "agda",
"hexsha": "23bf21b22da4fe31e4c13a7107fd068f89cd8b69",
"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/Unary/Consequences.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/Unary/Consequences.agda",
"max_line_length": 86,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Unary/Consequences.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": 107,
"size": 496
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Presheaves where
open import Level using (_⊔_ ; suc)
open import Cats.Category
open import Cats.Category.Fun using (Fun)
open import Cats.Category.Op using (_ᵒᵖ)
open import Cats.Category.Setoids using (Setoids)
Presheaves : ∀ {lo la l≈} (C : Category lo la l≈) l l′
→ Category (lo ⊔ la ⊔ l≈ ⊔ suc (l ⊔ l′)) (lo ⊔ la ⊔ l ⊔ l′) (lo ⊔ l ⊔ l′)
Presheaves C l l′ = Fun (C ᵒᵖ) (Setoids l l′)
| {
"alphanum_fraction": 0.6503340757,
"avg_line_length": 29.9333333333,
"ext": "agda",
"hexsha": "03313b33e091d7e9d71327b418fcfa7a2425b354",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Presheaves.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Presheaves.agda",
"max_line_length": 75,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Presheaves.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 166,
"size": 449
} |
{-# OPTIONS --without-K #-}
infixr 1 _‘→’_
record ⊤ : Set where
constructor tt
data ⊥ : Set where
mutual
data Type : Set where
_‘→’_ : Type → Type → Type
‘□’ : Type → Type
‘⊤’ : Type
‘⊥’ : Type
data □ : Type → Set where
Lӧb : ∀ {X} → □ (‘□’ X ‘→’ X) → □ X
‘tt’ : □ ‘⊤’
mutual
⌞_⌟ : Type → Set
⌞ A ‘→’ B ⌟ = ⌞ A ⌟ → ⌞ B ⌟
⌞ ‘□’ T ⌟ = □ T
⌞ ‘⊤’ ⌟ = ⊤
⌞ ‘⊥’ ⌟ = ⊥
⌞_⌟t : ∀ {T : Type} → □ T → ⌞ T ⌟
⌞ (Lӧb □‘X’→X) ⌟t = ⌞ □‘X’→X ⌟t (Lӧb □‘X’→X)
⌞ ‘tt’ ⌟t = tt
¬_ : Set → Set
¬ T = T → ⊥
‘¬’_ : Type → Type
‘¬’ T = T ‘→’ ‘⊥’
lӧb : ∀ {‘X’} → □ (‘□’ ‘X’ ‘→’ ‘X’) → ⌞ ‘X’ ⌟
lӧb f = ⌞ Lӧb f ⌟t
incompleteness : ¬ □ (‘¬’ (‘□’ ‘⊥’))
incompleteness = lӧb
soundness : ¬ □ ‘⊥’
soundness x = ⌞ x ⌟t
non-emptyness : □ ‘⊤’
non-emptyness = ‘tt’
| {
"alphanum_fraction": 0.3803526448,
"avg_line_length": 16.5416666667,
"ext": "agda",
"hexsha": "092aa5fc37103f66b6ddb36bbbc79968378f5a4c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z",
"max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JasonGross/lob",
"max_forks_repo_path": "internal/mini-mini-lob.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JasonGross/lob",
"max_issues_repo_path": "internal/mini-mini-lob.agda",
"max_line_length": 46,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JasonGross/lob",
"max_stars_repo_path": "internal/mini-mini-lob.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z",
"num_tokens": 499,
"size": 794
} |
------------------------------------------------------------------------
-- Truncation, defined as a HIT
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- The beginning of this module follows the HoTT book rather closely.
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining the truncation uses path equality,
-- but the supplied notion of equality is used for many other things.
import Equality.Path as P
module H-level.Truncation
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as TP using (∥_∥)
open import Monad equality-with-J
open import Nat equality-with-J as Nat using (_≤_; min)
import Pointed-type equality-with-J as PT
open import Sphere eq
open import Suspension eq as Susp using (north)
open import Univalence-axiom equality-with-J
private
variable
a b ℓ p : Level
A B C : Type a
P : A → Type p
e x y : A
f g r : A → B
m n : ℕ
k : Isomorphism-kind
-- A truncation operator for positive h-levels.
data ∥_∥[1+_] (A : Type a) (n : ℕ) : Type a where
∣_∣ : A → ∥ A ∥[1+ n ]
hub : (r : 𝕊 n → ∥ A ∥[1+ n ]) → ∥ A ∥[1+ n ]
spokeᴾ : (r : 𝕊 n → ∥ A ∥[1+ n ]) (x : 𝕊 n) → r x P.≡ hub r
-- Spoke equalities.
spoke : (r : 𝕊 n → ∥ A ∥[1+ n ]) (x : 𝕊 n) → r x ≡ hub r
spoke r x = _↔_.from ≡↔≡ (spokeᴾ r x)
-- The truncation operator produces types of the right h-level.
truncation-has-correct-h-level : ∀ n → H-level (1 + n) ∥ A ∥[1+ n ]
truncation-has-correct-h-level {A = A} n =
_↔_.from +↔∀contractible𝕊→ᴮ c
where
c : ∀ x → Contractible ((𝕊 n , north) PT.→ᴮ (∥ A ∥[1+ n ] , x))
c x =
(const x , (const x (north {A = 𝕊 n}) ≡⟨⟩
x ∎))
, λ { (f , fn≡x) → Σ-≡,≡→≡
(⟨ext⟩ λ y →
const x y ≡⟨⟩
x ≡⟨ sym fn≡x ⟩
f north ≡⟨ spoke f north ⟩
hub f ≡⟨ sym $ spoke f y ⟩∎
f y ∎)
(subst (λ f → f north ≡ x)
(⟨ext⟩ (λ y → trans (sym fn≡x)
(trans (spoke f north)
(sym (spoke f y)))))
(refl x) ≡⟨ subst-ext _ _ ⟩
subst (_≡ x)
(trans (sym fn≡x)
(trans (spoke f north) (sym (spoke f north))))
(refl x) ≡⟨ cong (λ p → subst (_≡ x) (trans (sym fn≡x) p) (refl x)) $ trans-symʳ _ ⟩
subst (_≡ x) (trans (sym fn≡x) (refl (f north))) (refl x) ≡⟨ cong (λ p → subst (_≡ x) p (refl x)) $ trans-reflʳ _ ⟩
subst (_≡ x) (sym fn≡x) (refl x) ≡⟨ subst-trans _ ⟩
trans fn≡x (refl x) ≡⟨ trans-reflʳ _ ⟩∎
fn≡x ∎)
}
-- A dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : ∥ A ∥[1+ n ] → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
hubʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) →
(∀ x → P (r x)) →
P (hub r)
spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ])
(p : ∀ x → P (r x))
(x : 𝕊 n) →
P.[ (λ i → P (spokeᴾ r x i)) ] p x ≡ hubʳ r p
open Elimᴾ public
elimᴾ : Elimᴾ P → ∀ x → P x
elimᴾ {P = P} e = helper
where
module E = Elimᴾ e
helper : ∀ x → P x
helper ∣ x ∣ = E.∣∣ʳ x
helper (hub r) = E.hubʳ r (λ x → helper (r x))
helper (spokeᴾ r x i) = E.spokeʳ r (λ x → helper (r x)) x i
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (n : ℕ) (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
hubʳ : (𝕊 n → ∥ A ∥[1+ n ]) → (𝕊 n → B) → B
spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) (p : 𝕊 n → B) (x : 𝕊 n) →
p x P.≡ hubʳ r p
open Recᴾ public
recᴾ : Recᴾ n A B → ∥ A ∥[1+ n ] → B
recᴾ r = elimᴾ eᴾ
where
module R = Recᴾ r
eᴾ : Elimᴾ _
eᴾ .∣∣ʳ = r .∣∣ʳ
eᴾ .hubʳ = r .hubʳ
eᴾ .spokeʳ = r .spokeʳ
-- A dependent eliminator.
record Elim′ {A : Type a} (P : ∥ A ∥[1+ n ] → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
hubʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) →
(∀ x → P (r x)) →
P (hub r)
spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ])
(p : ∀ x → P (r x))
(x : 𝕊 n) →
subst P (spoke r x) (p x) ≡ hubʳ r p
open Elim′ public
elim′ : Elim′ P → ∀ x → P x
elim′ e′ = elimᴾ eᴾ
where
module E′ = Elim′ e′
eᴾ : Elimᴾ _
eᴾ .∣∣ʳ = E′.∣∣ʳ
eᴾ .hubʳ = E′.hubʳ
eᴾ .spokeʳ r p x = subst≡→[]≡ (E′.spokeʳ r p x)
elim′-spoke :
dcong (elim′ e) (spoke r x) ≡
Elim′.spokeʳ e r (λ x → elim′ e (r x)) x
elim′-spoke = dcong-subst≡→[]≡ (refl _)
-- A non-dependent eliminator.
record Rec′ (n : ℕ) (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
hubʳ : (𝕊 n → ∥ A ∥[1+ n ]) → (𝕊 n → B) → B
spokeʳ : (r : 𝕊 n → ∥ A ∥[1+ n ]) (p : 𝕊 n → B) (x : 𝕊 n) →
p x ≡ hubʳ r p
open Rec′ public
rec′ : Rec′ n A B → ∥ A ∥[1+ n ] → B
rec′ r′ = recᴾ rᴾ
where
module R′ = Rec′ r′
rᴾ : Recᴾ _ _ _
rᴾ .∣∣ʳ = R′.∣∣ʳ
rᴾ .hubʳ = R′.hubʳ
rᴾ .spokeʳ r p x = _↔_.to ≡↔≡ (R′.spokeʳ r p x)
rec′-spoke :
cong (rec′ e) (spoke r x) ≡ Rec′.spokeʳ e r (λ x → rec′ e (r x)) x
rec′-spoke = cong-≡↔≡ (refl _)
-- A dependent eliminator that can be used when the motive is a family
-- of types, all of a certain h-level.
record Elim {A : Type a} (P : ∥ A ∥[1+ n ] → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
∣∣ʳ : ∀ x → P ∣ x ∣
h-levelʳ : ∀ x → H-level (1 + n) (P x)
open Elim public
elim : Elim {n = n} {A = A} P → ∀ x → P x
elim {n = n} {A = A} {P = P} e = elim′ e′
where
module _ (r : 𝕊 n → ∥ A ∥[1+ n ]) (p : ∀ x → P (r x)) where
h′ : 𝕊 n → P (hub r)
h′ x = subst P (spoke r x) (p x)
h = h′ north
lemma = $⟨ e .h-levelʳ ⟩
(∀ x → H-level (1 + n) (P x)) ↝⟨ _$ _ ⟩
H-level (1 + n) (P (hub r)) ↔⟨ +↔∀contractible𝕊→ᴮ ⟩
(∀ h → Contractible ((𝕊 n , north) PT.→ᴮ (P (hub r) , h))) ↝⟨ _$ _ ⟩
Contractible ((𝕊 n , north) PT.→ᴮ (P (hub r) , h)) ↝⟨ mono₁ _ ⟩□
Is-proposition ((𝕊 n , north) PT.→ᴮ (P (hub r) , h)) □
s = λ x →
subst P (spoke r x) (p x) ≡⟨⟩
h′ x ≡⟨ cong (λ f → proj₁ f x) $ lemma (h′ , refl _) (const h , refl _) ⟩
const h x ≡⟨⟩
h ∎
e′ : Elim′ _
e′ .∣∣ʳ = e .∣∣ʳ
e′ .hubʳ = h
e′ .spokeʳ = s
-- A non-dependent eliminator that can be used when the motive is a
-- type of a certain h-level.
record Rec (n : ℕ) (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
∣∣ʳ : A → B
h-levelʳ : H-level (1 + n) B
open Rec public
rec : Rec n A B → ∥ A ∥[1+ n ] → B
rec r = elim λ where
.∣∣ʳ → r .∣∣ʳ
.h-levelʳ _ → r .h-levelʳ
-- Dependent functions into P that agree on the image of ∣_∣ agree
-- everywhere, if P is a family of types that all have a certain
-- h-level.
uniqueness′ :
{f g : (x : ∥ A ∥[1+ n ]) → P x} →
(∀ x → H-level (2 + n) (P x)) →
((x : A) → f ∣ x ∣ ≡ g ∣ x ∣) →
((x : ∥ A ∥[1+ n ]) → f x ≡ g x)
uniqueness′ {n = n} P-h f≡g = elim λ where
.∣∣ʳ → f≡g
.h-levelʳ _ → +⇒≡ {n = suc n} (P-h _)
-- A special case of the previous property.
uniqueness :
{f g : ∥ A ∥[1+ n ] → B} →
H-level (1 + n) B →
((x : A) → f ∣ x ∣ ≡ g ∣ x ∣) →
((x : ∥ A ∥[1+ n ]) → f x ≡ g x)
uniqueness h = uniqueness′ (λ _ → mono₁ _ h)
-- The truncation operator's universal property.
universal-property :
H-level (1 + n) B →
(∥ A ∥[1+ n ] → B) ↔ (A → B)
universal-property h = record
{ surjection = record
{ logical-equivalence = record
{ to = _∘ ∣_∣
; from = λ f → rec λ where
.∣∣ʳ → f
.h-levelʳ → h
}
; right-inverse-of = refl
}
; left-inverse-of = λ f → ⟨ext⟩ $ uniqueness h (λ x → f ∣ x ∣ ∎)
}
-- The truncation operator ∥_∥[1+ n ] is a functor.
∥∥-map : (A → B) → ∥ A ∥[1+ n ] → ∥ B ∥[1+ n ]
∥∥-map f = rec λ where
.∣∣ʳ x → ∣ f x ∣
.h-levelʳ → truncation-has-correct-h-level _
∥∥-map-id :
(x : ∥ A ∥[1+ n ]) →
∥∥-map id x ≡ x
∥∥-map-id = uniqueness
(truncation-has-correct-h-level _)
(λ x → ∣ x ∣ ∎)
∥∥-map-∘ :
(x : ∥ A ∥[1+ n ]) →
∥∥-map (f ∘ g) x ≡ ∥∥-map f (∥∥-map g x)
∥∥-map-∘ {f = f} {g = g} = uniqueness
(truncation-has-correct-h-level _)
(λ x → ∣ f (g x) ∣ ∎)
-- A zip function.
∥∥-zip : (A → B → C) → ∥ A ∥[1+ n ] → ∥ B ∥[1+ n ] → ∥ C ∥[1+ n ]
∥∥-zip f = rec λ where
.∣∣ʳ x → ∥∥-map (f x)
.h-levelʳ → Π-closure ext _ λ _ →
truncation-has-correct-h-level _
-- A has h-level 1 + n if and only if it is isomorphic to
-- ∥ A ∥[1+ n ].
+⇔∥∥↔ : H-level (1 + n) A ⇔ (∥ A ∥[1+ n ] ↔ A)
+⇔∥∥↔ {n = n} {A = A} = record
{ to = λ h → record
{ surjection = record
{ logical-equivalence = record
{ from = ∣_∣
; to = rec λ where
.∣∣ʳ → id
.h-levelʳ → h
}
; right-inverse-of = refl
}
; left-inverse-of = elim λ where
.∣∣ʳ x → ∣ x ∣ ∎
.h-levelʳ _ → ⇒≡ _ $ truncation-has-correct-h-level _
}
; from =
∥ A ∥[1+ n ] ↔ A ↝⟨ H-level-cong ext _ ⟩
(H-level (1 + n) ∥ A ∥[1+ n ] ↔ H-level (1 + n) A) ↝⟨ (λ hyp → _↔_.to hyp (truncation-has-correct-h-level _)) ⟩□
H-level (1 + n) A □
}
-- The (1 + n)-truncation of x ≡ y, where x and y have type A, is
-- equivalent to the equality of ∣ x ∣ and ∣ y ∣ (as elements of the
-- (2 + n)-truncation of A), assuming univalence.
--
-- Along with the fact that this lemma computes in a certain way (see
-- below) this is more or less Theorem 7.3.12 from the HoTT book.
∥≡∥≃∣∣≡∣∣ :
{A : Type a} {x y : A} →
Univalence a →
∥ x ≡ y ∥[1+ n ] ≃ _≡_ {A = ∥ A ∥[1+ suc n ]} ∣ x ∣ ∣ y ∣
∥≡∥≃∣∣≡∣∣ {n = n} {A = A} univ = Eq.↔→≃
(decode ∣ _ ∣ ∣ _ ∣)
(encode ∣ _ ∣ ∣ _ ∣)
(decode-encode _)
(encode-decode _ _)
where
Eq : (_ _ : ∥ A ∥[1+ suc n ]) → ∃ λ (B : Type _) → H-level (suc n) B
Eq = rec λ where
.h-levelʳ →
Π-closure ext (2 + n) λ _ →
∃-H-level-H-level-1+ ext univ (1 + n)
.∣∣ʳ x → rec λ where
.h-levelʳ → ∃-H-level-H-level-1+ ext univ (1 + n)
.∣∣ʳ y →
∥ x ≡ y ∥[1+ n ] , truncation-has-correct-h-level n
Eq-refl : (x : ∥ A ∥[1+ suc n ]) → proj₁ (Eq x x)
Eq-refl = elim λ where
.∣∣ʳ x → ∣ refl x ∣
.h-levelʳ x → mono₁ (1 + n) $ proj₂ (Eq x x)
decode : ∀ x y → proj₁ (Eq x y) → x ≡ y
decode = elim λ where
.h-levelʳ _ →
Π-closure ext (2 + n) λ _ →
Π-closure ext (2 + n) λ _ →
mono₁ (2 + n) $ truncation-has-correct-h-level (1 + n)
.∣∣ʳ x → elim λ where
.h-levelʳ _ →
Π-closure ext (2 + n) λ _ →
mono₁ (2 + n) $ truncation-has-correct-h-level (1 + n)
.∣∣ʳ y → rec λ where
.h-levelʳ → truncation-has-correct-h-level (1 + n)
.∣∣ʳ → cong ∣_∣
encode : ∀ x y → x ≡ y → proj₁ (Eq x y)
encode x y x≡y = subst (λ y → proj₁ (Eq x y)) x≡y (Eq-refl x)
decode-encode : ∀ x (x≡y : x ≡ y) → decode x y (encode x y x≡y) ≡ x≡y
decode-encode = elim λ where
.h-levelʳ _ →
Π-closure ext (2 + n) λ _ →
mono₁ (3 + n) $ mono₁ (2 + n) $
truncation-has-correct-h-level (1 + n)
.∣∣ʳ x → elim¹
(λ x≡y → decode _ _ (encode _ _ x≡y) ≡ x≡y)
(decode (∣ x ∣) (∣ x ∣) (encode ∣ x ∣ ∣ x ∣ (refl ∣ x ∣)) ≡⟨⟩
decode (∣ x ∣) (∣ x ∣)
(subst (λ y → proj₁ (Eq ∣ x ∣ y)) (refl ∣ x ∣) ∣ refl x ∣) ≡⟨ cong (decode _ _) $ subst-refl _ _ ⟩
decode (∣ x ∣) (∣ x ∣) (∣ refl x ∣) ≡⟨⟩
cong ∣_∣ (refl x) ≡⟨ cong-refl _ ⟩∎
refl ∣ x ∣ ∎)
encode-decode :
∀ x y (eq : proj₁ (Eq x y)) → encode x y (decode x y eq) ≡ eq
encode-decode = elim λ where
.h-levelʳ x →
Π-closure ext (2 + n) λ y →
Π-closure ext (2 + n) λ _ →
mono₁ (2 + n) $ mono₁ (1 + n) $
proj₂ (Eq x y)
.∣∣ʳ x → elim λ where
.h-levelʳ y →
Π-closure ext (2 + n) λ _ →
mono₁ (2 + n) $ mono₁ (1 + n) $
proj₂ (Eq ∣ x ∣ y)
.∣∣ʳ y → elim λ where
.h-levelʳ _ →
mono₁ (1 + n) $ truncation-has-correct-h-level n
.∣∣ʳ eq →
encode ∣ x ∣ ∣ y ∣ (decode (∣ x ∣) (∣ y ∣) (∣ eq ∣)) ≡⟨⟩
subst (λ y → proj₁ (Eq ∣ x ∣ y)) (cong ∣_∣ eq) (∣ refl x ∣) ≡⟨ sym $ subst-∘ _ _ _ ⟩
subst (λ y → proj₁ (Eq ∣ x ∣ ∣ y ∣)) eq (∣ refl x ∣) ≡⟨⟩
subst (λ y → ∥ x ≡ y ∥[1+ n ]) eq (∣ refl x ∣) ≡⟨ elim¹
(λ eq → subst (λ y → ∥ x ≡ y ∥[1+ n ]) eq (∣ refl x ∣) ≡
∣ subst (x ≡_) eq (refl x) ∣)
(trans (subst-refl _ _) $
cong ∣_∣ $ sym $ subst-refl _ _)
_ ⟩
∣ subst (x ≡_) eq (refl x) ∣ ≡⟨ cong ∣_∣ $ sym trans-subst ⟩
∣ trans (refl x) eq ∣ ≡⟨ cong ∣_∣ $ trans-reflˡ _ ⟩∎
∣ eq ∣ ∎
_ :
{A : Type a} {x y : A} {univ : Univalence a}
{x≡y : x ≡ y} →
_≃_.to (∥≡∥≃∣∣≡∣∣ {n = n} univ) ∣ x≡y ∣ ≡ cong ∣_∣ x≡y
_ = refl _
-- The truncation operator commutes with _×_.
--
-- This result is similar to Theorem 7.3.8 from the HoTT book.
∥∥×∥∥≃∥×∥ : (∥ A ∥[1+ n ] × ∥ B ∥[1+ n ]) ≃ ∥ A × B ∥[1+ n ]
∥∥×∥∥≃∥×∥ {n = n} = Eq.↔→≃
(uncurry $ rec λ where
.h-levelʳ → Π-closure ext _ λ _ →
truncation-has-correct-h-level _
.∣∣ʳ x → rec λ where
.h-levelʳ → truncation-has-correct-h-level _
.∣∣ʳ y → ∣ x , y ∣)
(rec λ where
.∣∣ʳ → Σ-map ∣_∣ ∣_∣
.h-levelʳ → s)
(elim λ where
.∣∣ʳ _ → refl _
.h-levelʳ _ →
mono₁ (1 + n) $ truncation-has-correct-h-level n)
(uncurry $ elim λ where
.h-levelʳ _ → Π-closure ext (1 + n) λ _ →
mono₁ (1 + n) s
.∣∣ʳ _ → elim λ where
.h-levelʳ _ → mono₁ (1 + n) s
.∣∣ʳ _ → refl _)
where
s = ×-closure _
(truncation-has-correct-h-level _)
(truncation-has-correct-h-level _)
-- Nested truncations where the inner truncation's h-level is at least
-- as large as the outer truncation's h-level can be flattened.
flatten-≥ : m ≤ n → ∥ ∥ A ∥[1+ n ] ∥[1+ m ] ↔ ∥ A ∥[1+ m ]
flatten-≥ m≤n = record
{ surjection = record
{ logical-equivalence = record
{ from = ∥∥-map ∣_∣
; to = rec λ where
.h-levelʳ → truncation-has-correct-h-level _
.∣∣ʳ → rec λ where
.∣∣ʳ → ∣_∣
.h-levelʳ → mono (Nat.suc≤suc m≤n)
(truncation-has-correct-h-level _)
}
; right-inverse-of = uniqueness
(truncation-has-correct-h-level _)
(λ x → ∣ x ∣ ∎)
}
; left-inverse-of = uniqueness
(truncation-has-correct-h-level _)
(uniqueness
(mono (Nat.suc≤suc m≤n)
(truncation-has-correct-h-level _))
(λ x → ∣ ∣ x ∣ ∣ ∎))
}
-- The remainder of this module is not based on the HoTT book.
-- Nested truncations where the inner truncation's h-level is at most
-- as large as the outer truncation's h-level can be flattened.
flatten-≤ : m ≤ n → ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↔ ∥ A ∥[1+ m ]
flatten-≤ m≤n = record
{ surjection = record
{ logical-equivalence = record
{ from = ∣_∣
; to = rec λ where
.∣∣ʳ → id
.h-levelʳ → mono (Nat.suc≤suc m≤n)
(truncation-has-correct-h-level _)
}
; right-inverse-of = refl
}
; left-inverse-of = uniqueness
(truncation-has-correct-h-level _)
(λ x → ∣ x ∣ ∎)
}
-- Nested truncations can be flattened.
flatten : ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↔ ∥ A ∥[1+ min m n ]
flatten {A = A} {m = m} {n = n} = case Nat.total m n of λ where
(inj₁ m≤n) → ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↝⟨ flatten-≤ m≤n ⟩
∥ A ∥[1+ m ] ↝⟨ ≡⇒↝ _ $ cong ∥ A ∥[1+_] $ sym $ _⇔_.to Nat.≤⇔min≡ m≤n ⟩□
∥ A ∥[1+ min m n ] □
(inj₂ m≥n) → ∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↝⟨ flatten-≥ m≥n ⟩
∥ A ∥[1+ n ] ↝⟨ ≡⇒↝ _ $ cong ∥ A ∥[1+_] $ sym $ _⇔_.to Nat.≤⇔min≡ m≥n ⟩
∥ A ∥[1+ min n m ] ↝⟨ ≡⇒↝ _ $ cong ∥ A ∥[1+_] $ Nat.min-comm _ _ ⟩□
∥ A ∥[1+ min m n ] □
-- The propositional truncation operator ∥_∥ is pointwise isomorphic
-- to ∥_∥[1+ 0 ].
∥∥↔∥∥ : ∥ A ∥ ↔ ∥ A ∥[1+ 0 ]
∥∥↔∥∥ = record
{ surjection = record
{ logical-equivalence = record
{ to = TP.rec (truncation-has-correct-h-level 0) ∣_∣
; from = rec λ where
.∣∣ʳ → TP.∣_∣
.h-levelʳ → TP.truncation-is-proposition
}
; right-inverse-of = λ _ → truncation-has-correct-h-level 0 _ _
}
; left-inverse-of = λ _ → TP.truncation-is-proposition _ _
}
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ : ∥ A ∥[1+ n ] → (A → ∥ B ∥[1+ n ]) → ∥ B ∥[1+ n ]
_>>=′_ {A = A} {n = n} {B = B} = curry (
∥ A ∥[1+ n ] × (A → ∥ B ∥[1+ n ]) ↝⟨ uncurry (flip ∥∥-map) ⟩
∥ ∥ B ∥[1+ n ] ∥[1+ n ] ↔⟨ flatten-≤ Nat.≤-refl ⟩□
∥ B ∥[1+ n ] □)
-- ∥_∥[1+ n ] is a monad.
instance
monad : Monad {c = ℓ} (∥_∥[1+ n ])
Raw-monad.return (Monad.raw-monad monad) = ∣_∣
Raw-monad._>>=_ (Monad.raw-monad monad) = _>>=′_
Monad.left-identity monad = λ _ _ → refl _
Monad.right-identity monad =
uniqueness (truncation-has-correct-h-level _) (λ _ → refl _)
Monad.associativity monad = flip λ f → flip λ g → uniqueness
(truncation-has-correct-h-level _)
(λ x → f x >>=′ g ∎)
-- The truncation operator preserves logical equivalences.
∥∥-cong-⇔ : A ⇔ B → ∥ A ∥[1+ n ] ⇔ ∥ B ∥[1+ n ]
∥∥-cong-⇔ A⇔B = record
{ to = ∥∥-map (_⇔_.to A⇔B)
; from = ∥∥-map (_⇔_.from A⇔B)
}
-- The truncation operator preserves bijections.
∥∥-cong : A ↔[ k ] B → ∥ A ∥[1+ n ] ↔[ k ] ∥ B ∥[1+ n ]
∥∥-cong {n = n} A↝B = from-bijection (record
{ surjection = record
{ logical-equivalence = record
{ to = ∥∥-map (_↔_.to A↔B)
; from = ∥∥-map (_↔_.from A↔B)
}
; right-inverse-of = lemma A↔B
}
; left-inverse-of = lemma (inverse A↔B)
})
where
A↔B = from-isomorphism A↝B
lemma :
(A↔B : A ↔ B) (x : ∥ B ∥[1+ n ]) →
∥∥-map (_↔_.to A↔B) (∥∥-map (_↔_.from A↔B) x) ≡ x
lemma A↔B x =
∥∥-map (_↔_.to A↔B) (∥∥-map (_↔_.from A↔B) x) ≡⟨ sym $ ∥∥-map-∘ x ⟩
∥∥-map (_↔_.to A↔B ∘ _↔_.from A↔B) x ≡⟨ cong (λ f → ∥∥-map f x) $ ⟨ext⟩ $ _↔_.right-inverse-of A↔B ⟩
∥∥-map id x ≡⟨ ∥∥-map-id x ⟩∎
x ∎
-- ∥ A ∥[1+_] is downwards closed.
downwards-closed : m ≤ n → ∥ A ∥[1+ n ] → ∥ A ∥[1+ m ]
downwards-closed {m = m} {n = n} {A = A} m≤n =
∥ A ∥[1+ n ] ↝⟨ ∥∥-map ∣_∣ ⟩
∥ ∥ A ∥[1+ m ] ∥[1+ n ] ↔⟨ flatten-≤ m≤n ⟩□
∥ A ∥[1+ m ] □
| {
"alphanum_fraction": 0.4399154292,
"avg_line_length": 32.1295418641,
"ext": "agda",
"hexsha": "bcd1702f64663ce4b9abbf568a5e2d5d7d89e43b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/H-level/Truncation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/H-level/Truncation.agda",
"max_line_length": 147,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/H-level/Truncation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 8590,
"size": 20338
} |
open import Prelude
module Implicits.Resolution.Termination where
open import Implicits.Resolution.Termination.SizeMeasures public
open import Implicits.Resolution.Termination.Stack public
open import Implicits.Resolution.Termination.Lemmas public
| {
"alphanum_fraction": 0.876,
"avg_line_length": 31.25,
"ext": "agda",
"hexsha": "52670f36d5cdc79183cf9030633df77598689685",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Termination.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Termination.agda",
"max_line_length": 64,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Termination.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 58,
"size": 250
} |
-- This combination should not be allowed:
{-# OPTIONS --guardedness --sized-types --safe #-}
| {
"alphanum_fraction": 0.6842105263,
"avg_line_length": 23.75,
"ext": "agda",
"hexsha": "c5801b130b04597d30f7f70bf1e73144cdd7e66b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "caryoscelus/agda",
"max_forks_repo_path": "test/Fail/Issue1209-3.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "caryoscelus/agda",
"max_issues_repo_path": "test/Fail/Issue1209-3.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98d6f195fe672e54ef0389b4deb62e04e3e98327",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "caryoscelus/agda",
"max_stars_repo_path": "test/Fail/Issue1209-3.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 20,
"size": 95
} |
module Relation.Ternary.Separation.Morphisms where
open import Level
open import Function
open import Relation.Unary
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Separation
open import Data.Product
open import Function using (_∘_)
record Morphism {a b} (A : Set a) (B : Set b)
{{r : RawSep A}} {u} {{s₁ : IsUnitalSep r u}}
{{rb : RawSep B}} : Set (a ⊔ suc b) where
field
j : A → B
-- j "commutes" with _⊎_
j-⊎ : ∀ {Φ₁ Φ₂ Φ} → Φ₁ ⊎ Φ₂ ≣ Φ → j Φ₁ ⊎ j Φ₂ ≣ j Φ
j-⊎⁻ : ∀ {Φ₁ Φ₂ Φ} → j Φ₁ ⊎ j Φ₂ ≣ Φ → ∃ λ Φ' → Φ ≡ j Φ' × Φ₁ ⊎ Φ₂ ≣ Φ'
instance _ = s₁
infixr 8 _⇒ⱼ_
_⇒ⱼ_ : ∀ {p q} → Pred A p → Pred B q → Pred A _
P ⇒ⱼ Q = P ⇒ (Q ∘ j)
infixr 8 _─✴ⱼ_
_─✴ⱼ_ : ∀ {p q} → Pred A p → Pred B q → Pred B _
P ─✴ⱼ Q = P ─✴[ j ] Q
{- Such a morphism on SAs induces a functor on SA-predicates -}
module _ where
data J {p} (P : Pred A p) : Pred B (a ⊔ p) where
inj : ∀ {Φ} → P Φ → J P (j Φ)
jstar : ∀ {p q} {P : Pred A p} {Q : Pred A q} → ∀[ J (P ✴ Q) ⇒ J P ✴ J Q ]
jstar (inj (p ×⟨ σ ⟩ q)) = inj p ×⟨ j-⊎ σ ⟩ inj q
jmap : ∀ {p q} {P : Pred A p} {Q : Pred A q} → ∀[ (P ─✴ Q) ⇒ⱼ (J P ─✴ J Q) ]
app (jmap f) (inj px) σ with j-⊎⁻ σ
... | _ , refl , σ' = inj (app f px σ')
wanditⱼ : ∀ {p q} {P : Pred A p} {Q : Pred B q} → ∀[ P ⇒ⱼ Q ] → (P ─✴ⱼ Q) (j u)
app (wanditⱼ f) px σ with j-⊎⁻ σ
... | _ , refl , σ' with ⊎-id⁻ˡ σ'
... | refl = f px
{- identity morphism -}
module _ {a} {A : Set a} {{r : RawSep A}} {u} {{s₁ : IsUnitalSep r u}} where
instance id-morph : Morphism A A
id-morph = record
{ j = id
; j-⊎ = id
; j-⊎⁻ = λ x → -, refl , x
}
| {
"alphanum_fraction": 0.5023894863,
"avg_line_length": 28.3728813559,
"ext": "agda",
"hexsha": "c7c32ed14cc3e08e37fdf6b0b31c706d87eef14d",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Morphisms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Morphisms.agda",
"max_line_length": 81,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Morphisms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 812,
"size": 1674
} |
------------------------------------------------------------------------------
-- Common (interactive and automatic) properties using the induction principle
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Inductive.PropertiesByInduction where
open import PA.Inductive.Base
------------------------------------------------------------------------------
-- Congruence properties
succCong : ∀ {m n} → m ≡ n → succ m ≡ succ n
succCong refl = refl
------------------------------------------------------------------------------
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity n = refl
+-rightIdentity : ∀ n → n + zero ≡ n
+-rightIdentity n = ℕ-ind A A0 is n
where
A : ℕ → Set
A i = i + zero ≡ i
A0 : A zero
A0 = refl
is : ∀ i → A i → A (succ i)
is i ih = succCong ih
+-assoc : ∀ m n o → m + n + o ≡ m + (n + o)
+-assoc m n o = ℕ-ind A A0 is m
where
A : ℕ → Set
A i = i + n + o ≡ i + (n + o)
A0 : A zero
A0 = refl
is : ∀ i → A i → A (succ i)
is i ih = succCong ih
x+Sy≡S[x+y] : ∀ m n → m + succ n ≡ succ (m + n)
x+Sy≡S[x+y] m n = ℕ-ind A A0 is m
where
A : ℕ → Set
A i = i + succ n ≡ succ (i + n)
A0 : A zero
A0 = refl
is : ∀ i → A i → A (succ i)
is i ih = succCong ih
| {
"alphanum_fraction": 0.4164345404,
"avg_line_length": 23.9333333333,
"ext": "agda",
"hexsha": "831f456210057310780fcf2d3dcbadf2cc35783a",
"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/PA/Inductive/PropertiesByInduction.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/PA/Inductive/PropertiesByInduction.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/PA/Inductive/PropertiesByInduction.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": 418,
"size": 1436
} |
module Proof where
-- we give an example of a structure that satisfies the monad laws, but does not have a join operation.
open import Relation.Binary.PropositionalEquality
F : Set → Set₁
F x = Set → x
return : ∀ {x} → x → F x
return = λ z _ → z
_>>=_ : ∀ {x y} -> F x → (x -> F y) → F y
a >>= f = λ z → f (a z) z
-- Notice that the structure (F,return,>>=) satisfies the monad laws:
left-id : ∀ {S₁ S₂} → (f : S₁ → F S₂) → (a : S₁) →
(return a >>= f) ≡ f a
left-id f a = refl
right-id : ∀ {S₁} → (m : F S₁) →
(m >>= return) ≡ m
right-id m = refl
assoc : ∀ {S₁ S₂ S₃} → (f : S₁ → F S₂) → (g : S₂ → F S₃) → (m : F S₁) →
(m >>= f) >>= g ≡ m >>= (λ x → f x >>= g)
assoc f g m = refl
-- One could try to define this monad as the structure (F,return,fmap,join).
fmap : ∀ {S₁ S₂} → (S₁ → S₂) → F S₁ → F S₂
fmap f x = λ z → f (x z)
-- However, a definition with signature
---- join : ∀ {x} → F (F x) → F x
-- cannot typecheck, since
---- Set₁ != Set
---- when checking that the expression F x has type Set.
| {
"alphanum_fraction": 0.5180055402,
"avg_line_length": 25.7857142857,
"ext": "agda",
"hexsha": "ecb1674de2da46476ab5686d01492ecdc5d4d1da",
"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": "c04ae5dd5fab9b2d840c3bf8db6eca0d6c8cc681",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zaklogician/monads-are-not",
"max_forks_repo_path": "Proof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c04ae5dd5fab9b2d840c3bf8db6eca0d6c8cc681",
"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": "zaklogician/monads-are-not",
"max_issues_repo_path": "Proof.agda",
"max_line_length": 103,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "c04ae5dd5fab9b2d840c3bf8db6eca0d6c8cc681",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zaklogician/monads-are-not",
"max_stars_repo_path": "Proof.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-19T17:52:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-14T18:34:55.000Z",
"num_tokens": 395,
"size": 1083
} |
module ExplicitImplicitConversion where
open import ExpressionChanging
open import Data.Nat
open import Data.List
open import ParseTree
open import ScopeState
open import Data.Vec using (Vec ; _∷_)
open import Data.Fin
open import Data.List.NonEmpty
open import AgdaHelperFunctions
open import Data.Bool
open import ParseTreeOperations
-- is given types before conversion
-- namedArgument for type, never just implicit!!!!!!
conversionIns : {n : ℕ} -> Vec Expr n -> Fin n -> (List Expr -> List Expr)
conversionIns Vec.[] () l
conversionIns _ _ [] = []
conversionIns (namedArgument _ {false} ∷ x₁) zero (implicit y ∷ list) = y ∷ list
-- expecting implicit and getting explicit, i.e. argument to be moved
-- isn't specified.
conversionIns (namedArgument _ {false} ∷ x₁) zero (y ∷ list) = newUnderscore ∷ y ∷ list
conversionIns (x ∷ x₁) zero (x₂ ∷ list) = implicit x₂ ∷ list
conversionIns (namedArgument _ {false} ∷ x₁) (suc n) (implicit x₂ ∷ list) =
implicit x₂ ∷ conversionIns x₁ n list
conversionIns (namedArgument _ {false} ∷ x₁) (suc n) (x₂ ∷ list) =
let result = conversionIns x₁ n (x₂ ∷ list)
in if headImplicit? result then (implicit newUnderscore) ∷ result
else result
where headImplicit? : List Expr -> Bool
headImplicit? (implicit x ∷ l) = true
headImplicit? _ = false
conversionIns (x ∷ x₁) (suc n) (x₂ ∷ list) = x₂ ∷ conversionIns x₁ n list
convertInExpr : TypeSignature -> ℕ -> ScopeState (List⁺ Expr -> List⁺ Expr)
convertInExpr t n = makeInstruction t n conversionIns
convertInSignature : {n : ℕ} -> Vec Expr (suc n) -> Fin n -> ScopeState (Vec Expr (suc n))
convertInSignature (namedArgument arg {isExplicit} {c}{c2} ∷ l) zero =
return $ namedArgument arg {not isExplicit}{c}{c2} ∷ l
convertInSignature (implicit x ∷ l) zero = return $ x ∷ l
convertInSignature (x ∷ l) zero = do
newName <- getUniqueIdentifier
return $ namedArgument (typeSignature newName x) {false} {[]} {[]} ∷ l
convertInSignature (x ∷ v) (suc f) = do
rest <- convertInSignature v f
return $ x ∷ rest
convert : List ParseTree -> (funcID : ℕ) -> (whichArgument : ℕ) -> ScopeState (List ParseTree)
convert code funcId whichArgument = doForArgument code funcId whichArgument convertInSignature convertInExpr
| {
"alphanum_fraction": 0.7088888889,
"avg_line_length": 44.1176470588,
"ext": "agda",
"hexsha": "ee0bba544cc1a4712fdd519ad4b00055e85d1e07",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/ExplicitImplicitConversion.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/ExplicitImplicitConversion.agda",
"max_line_length": 108,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/ExplicitImplicitConversion.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 666,
"size": 2250
} |
{-# OPTIONS --with-K #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
single : {m n : Nat} → suc m ≡ suc n → n ≡ m
single p with refl ← p = refl
double : {m n p : Nat} → suc m ≡ n → suc n ≡ 2 + p → m ≡ p
double p q with refl ← p | refl ← q = refl
_∋_ : (A : Set) → A → A
A ∋ a = a
-- The second equality proof is only well-typed
-- after the first one has been used
tele : {m n : Nat} → suc m ≡ suc n → m ≡ n
tele {m} {n} p
with refl ← p
| refl ← (n ≡ m) ∋ refl
= refl
tele' : {m n : Nat} → m ≡ n → m ≡ n
tele' {m} {n} p with refl ← p with (n ≡ m) ∋ refl
... | q = refl
-- Further splitting after a using & with
tele'' : {m n : Nat} → m ≡ n → Nat → Nat
tele'' {m} {n} p r with refl ← p | (n ≡ m) ∋ refl
tele'' {m} {m} p zero | q = m
tele'' {m} {m} p (suc r) | q = r
data Vec {a} (A : Set a) : Nat → Set a where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
module _ {a} {A : Set a} {n} (xs : Vec A (suc n)) where
head : A
head with (x ∷ _) ← xs = x
tail : Vec A n
tail with (_ ∷ xs) ← xs = xs -- pattern shadows variable with'd on
castVec : ∀ {m n} → m ≡ n → Vec Nat m → Vec Nat n
castVec eq ms with refl ← eq = ms
data All (P : Nat → Set) : ∀ {n} → Vec Nat n → Set where
[] : All P []
_∷_ : ∀ {n x xs} → P x → All P {n} xs → All P (x ∷ xs)
open import Agda.Builtin.Sigma
castAll : ∀ {P m n xs ys} → Σ (m ≡ n) (λ eq → castVec eq xs ≡ ys) →
All P xs → All P ys
castAll (refl , refl) all = all
| {
"alphanum_fraction": 0.5158462576,
"avg_line_length": 25.1355932203,
"ext": "agda",
"hexsha": "4348889aa1be552adbf61d0b495e0ab549e78f7b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Succeed/UsingEq.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Succeed/UsingEq.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/UsingEq.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 611,
"size": 1483
} |
open import Prelude
open import dynamics-core
module lemmas-matching where
-- arrow matching produces unique answers
▸arr-unicity : ∀{τ τ2 τ3} →
τ ▸arr τ2 →
τ ▸arr τ3 →
τ2 == τ3
▸arr-unicity MAHole MAHole = refl
▸arr-unicity MAArr MAArr = refl
-- only consistent types arrow match
▸arr-consist : ∀{τ1 τ2} →
τ1 ▸arr τ2 →
(τ1 ~ τ2)
▸arr-consist MAHole = TCHole2
▸arr-consist MAArr = TCRefl
-- if an arrow matches, then it's consistent with the
-- least restrictive function type
▸arr-consist-hole : ∀{t t'} →
t ▸arr t' →
t ~ (⦇-⦈ ==> ⦇-⦈)
▸arr-consist-hole MAHole = TCHole2
▸arr-consist-hole MAArr = TCArr TCHole1 TCHole1
-- sum matching produces unique answers
▸sum-unicity : ∀{τ τ2 τ3} →
τ ▸sum τ2 →
τ ▸sum τ3 →
τ2 == τ3
▸sum-unicity MSHole MSHole = refl
▸sum-unicity MSSum MSSum = refl
-- only consistent types sum match
▸sum-consist : ∀{τ1 τ2} →
τ1 ▸sum τ2 →
(τ1 ~ τ2)
▸sum-consist MSHole = TCHole2
▸sum-consist MSSum = TCRefl
-- if a sum matches, then it's consistent with the
-- least restrictive function type
▸sum-consist-hole : ∀{t t'} →
t ▸sum t' →
t ~ (⦇-⦈ ⊕ ⦇-⦈)
▸sum-consist-hole MSHole = TCHole2
▸sum-consist-hole MSSum = TCSum TCHole1 TCHole1
-- product matching produces unique answers
▸prod-unicity : ∀{τ τ2 τ3} →
τ ▸prod τ2 →
τ ▸prod τ3 →
τ2 == τ3
▸prod-unicity MPHole MPHole = refl
▸prod-unicity MPProd MPProd = refl
-- only consistent types product match
▸prod-consist : ∀{τ1 τ2} →
τ1 ▸prod τ2 →
(τ1 ~ τ2)
▸prod-consist MPHole = TCHole2
▸prod-consist MPProd = TCRefl
-- if a sum matches, then it's consistent with the
-- least restrictive function type
▸prod-consist-hole : ∀{t t'} →
t ▸prod t' →
t ~ (⦇-⦈ ⊠ ⦇-⦈)
▸prod-consist-hole MPHole = TCHole2
▸prod-consist-hole MPProd = TCProd TCHole1 TCHole1
| {
"alphanum_fraction": 0.5315315315,
"avg_line_length": 30.4109589041,
"ext": "agda",
"hexsha": "057b5721ac008c0857e3d4ccbb43115378f12996",
"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": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "lemmas-matching.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "lemmas-matching.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "lemmas-matching.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 786,
"size": 2220
} |
module Haskell.Prim.Ord where
open import Agda.Builtin.Nat as Nat hiding (_==_; _<_)
open import Agda.Builtin.Char
open import Haskell.Prim
open import Haskell.Prim.Eq
open import Haskell.Prim.Bool
open import Haskell.Prim.Int
open import Haskell.Prim.Word
open import Haskell.Prim.Integer
open import Haskell.Prim.Double
open import Haskell.Prim.Tuple
open import Haskell.Prim.Monoid
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Either
--------------------------------------------------
-- Ordering
data Ordering : Set where
LT EQ GT : Ordering
instance
iEqOrdering : Eq Ordering
iEqOrdering ._==_ LT LT = true
iEqOrdering ._==_ EQ EQ = true
iEqOrdering ._==_ GT GT = true
iEqOrdering ._==_ _ _ = false
iSemigroupOrdering : Semigroup Ordering
iSemigroupOrdering ._<>_ LT _ = LT
iSemigroupOrdering ._<>_ EQ o = o
iSemigroupOrdering ._<>_ GT _ = GT
iMonoidOrdering : Monoid Ordering
iMonoidOrdering .mempty = EQ
--------------------------------------------------
-- Ord
record Ord (a : Set) : Set where
field
compare : a → a → Ordering
_<_ : a → a → Bool
_>_ : a → a → Bool
_>=_ : a → a → Bool
_<=_ : a → a → Bool
max : a → a → a
min : a → a → a
overlap ⦃ super ⦄ : Eq a
infix 4 _<_ _>_ _<=_ _>=_
open Ord ⦃ ... ⦄ public
{-# COMPILE AGDA2HS Ord existing-class #-}
ordFromCompare : ⦃ Eq a ⦄ → (a → a → Ordering) → Ord a
ordFromCompare cmp .compare = cmp
ordFromCompare cmp ._<_ x y = cmp x y == LT
ordFromCompare cmp ._>_ x y = cmp x y == GT
ordFromCompare cmp ._<=_ x y = cmp x y /= GT
ordFromCompare cmp ._>=_ x y = cmp x y /= LT
ordFromCompare cmp .max x y = if cmp x y == LT then y else x
ordFromCompare cmp .min x y = if cmp x y == GT then y else x
ordFromLessThan : ⦃ Eq a ⦄ → (a → a → Bool) → Ord a
ordFromLessThan _<_ .compare x y = if x < y then LT else if x == y then EQ else GT
ordFromLessThan _<_ ._<_ x y = x < y
ordFromLessThan _<_ ._>_ x y = y < x
ordFromLessThan _<_ ._<=_ x y = x < y || x == y
ordFromLessThan _<_ ._>=_ x y = y < x || x == y
ordFromLessThan _<_ .max x y = if x < y then y else x
ordFromLessThan _<_ .min x y = if y < x then y else x
ordFromLessEq : ⦃ Eq a ⦄ → (a → a → Bool) → Ord a
ordFromLessEq _<=_ .compare x y = if x == y then EQ else if x <= y then LT else GT
ordFromLessEq _<=_ ._<_ x y = x <= y && not (x == y)
ordFromLessEq _<=_ ._>_ x y = y <= x && not (x == y)
ordFromLessEq _<=_ ._<=_ x y = x <= y
ordFromLessEq _<=_ ._>=_ x y = y <= x
ordFromLessEq _<=_ .max x y = if y <= x then x else y
ordFromLessEq _<=_ .min x y = if x <= y then x else y
private
compareFromLt : ⦃ Eq a ⦄ → (a → a → Bool) → a → a → Ordering
compareFromLt _<_ x y = if x < y then LT else if x == y then EQ else GT
instance
iOrdNat : Ord Nat
iOrdNat = ordFromLessThan Nat._<_
iOrdInteger : Ord Integer
iOrdInteger = ordFromLessThan ltInteger
iOrdInt : Ord Int
iOrdInt = ordFromLessThan ltInt
iOrdWord : Ord Word
iOrdWord = ordFromLessThan ltWord
iOrdDouble : Ord Double
iOrdDouble = ordFromLessThan primFloatNumericalLess
iOrdChar : Ord Char
iOrdChar = ordFromLessThan λ x y → primCharToNat x < primCharToNat y
iOrdBool : Ord Bool
iOrdBool = ordFromCompare λ where
false true → LT
true false → GT
_ _ → EQ
iOrdTuple₀ : Ord (Tuple [])
iOrdTuple₀ = ordFromCompare λ _ _ → EQ
iOrdTuple : ∀ {as} → ⦃ Ord a ⦄ → ⦃ Ord (Tuple as) ⦄ → Ord (Tuple (a ∷ as))
iOrdTuple = ordFromCompare λ where (x ∷ xs) (y ∷ ys) → compare x y <> compare xs ys
compareList : ⦃ Ord a ⦄ → List a → List a → Ordering
compareList [] [] = EQ
compareList [] (_ ∷ _) = LT
compareList (_ ∷ _) [] = GT
compareList (x ∷ xs) (y ∷ ys) = compare x y <> compareList xs ys
instance
iOrdList : ⦃ Ord a ⦄ → Ord (List a)
iOrdList = ordFromCompare compareList
iOrdMaybe : ⦃ Ord a ⦄ → Ord (Maybe a)
iOrdMaybe = ordFromCompare λ where
Nothing Nothing → EQ
Nothing (Just _) → LT
(Just _) Nothing → GT
(Just x) (Just y) → compare x y
iOrdEither : ⦃ Ord a ⦄ → ⦃ Ord b ⦄ → Ord (Either a b)
iOrdEither = ordFromCompare λ where
(Left x) (Left y) → compare x y
(Left _) (Right _) → LT
(Right _) (Left _) → GT
(Right x) (Right y) → compare x y
iOrdOrdering : Ord Ordering
iOrdOrdering = ordFromCompare λ where
LT LT → EQ
LT _ → LT
_ LT → GT
EQ EQ → EQ
EQ GT → LT
GT EQ → GT
GT GT → EQ
| {
"alphanum_fraction": 0.6145576708,
"avg_line_length": 28.6217948718,
"ext": "agda",
"hexsha": "cb67ab2d5ca8f23a3591394ad2f79b2037ddceac",
"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": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dxts/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Ord.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"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": "dxts/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Ord.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Ord.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1570,
"size": 4465
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Polynomials.UnivariateHIT.Polyn-nPoly where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat renaming (_+_ to _+n_; _·_ to _·n_)
open import Cubical.Data.Vec
open import Cubical.Data.Sigma
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
open import Cubical.Algebra.Ring
open import Cubical.Algebra.GradedRing.DirectSumFun
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Instances.Polynomials.UnivariatePolyHIT
open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.Poly0-A
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[Am[X]]-Anm[X]
open import Cubical.Algebra.Polynomials.Multivariate.EquivCarac.AB-An[X]Bn[X]
open CommRingEquivs renaming (compCommRingEquiv to _∘-ecr_ ; invCommRingEquiv to inv-ecr)
private variable
ℓ : Level
-----------------------------------------------------------------------------
-- Definition
module equiv1 (A'@(A , Astr) : CommRing ℓ)
where
private
PA = PolyCommRing A' 1
PAstr = snd PA
PA' = nUnivariatePolyHIT A' 1
PA'str = snd PA'
open CommRingStr
directSense : fst (PolyCommRing A' 1) → fst (nUnivariatePolyHIT A' 1)
directSense = DS-Rec-Set.f _ _ _ _
(is-set PA'str)
(0r PA'str)
(λ { (n ∷ []) a → base n a})
(_+_ PA'str)
(+Assoc PA'str)
(+IdR PA'str)
(+Comm PA'str)
(λ { (n ∷ []) → base-neutral _ })
λ { (n ∷ []) a b → base-add _ _ _}
convSense : fst (nUnivariatePolyHIT A' 1) → fst (PolyCommRing A' 1)
convSense = DS-Rec-Set.f _ _ _ _
(is-set PAstr)
(0r PAstr)
(λ n a → base (n ∷ []) a)
(_+_ PAstr)
(+Assoc PAstr)
(+IdR PAstr)
(+Comm PAstr)
(λ n → base-neutral _)
λ _ _ _ → base-add _ _ _
retr : (x : fst (PolyCommRing A' 1)) → convSense (directSense x) ≡ x
retr = DS-Ind-Prop.f _ _ _ _ (λ _ → is-set PAstr _ _)
refl
(λ { (n ∷ []) a → refl})
(λ {U V} ind-U ind-V → cong₂ (_+_ PAstr) ind-U ind-V)
sect : (x : fst (nUnivariatePolyHIT A' 1)) → (directSense (convSense x) ≡ x)
sect = DS-Ind-Prop.f _ _ _ _ (λ _ → is-set PA'str _ _)
refl
(λ n a → refl)
(λ {U V} ind-U ind-V → cong₂ (_+_ PA'str) ind-U ind-V)
converseSense-pres· : (x y : fst (PolyCommRing A' 1)) →
directSense (_·_ PAstr x y) ≡ _·_ PA'str (directSense x) (directSense y)
converseSense-pres· = DS-Ind-Prop.f _ _ _ _
(λ _ → isPropΠ λ _ → is-set PA'str _ _)
(λ _ → refl)
(λ { (n ∷ []) a → DS-Ind-Prop.f _ _ _ _ (λ _ → is-set PA'str _ _)
refl
(λ { (m ∷ []) b → refl})
λ {U V} ind-U ind-V → cong₂ (_+_ PA'str) ind-U ind-V})
λ {U V} ind-U ind-V y → cong₂ (_+_ PA'str) (ind-U y) (ind-V y)
open Iso
equivR : CommRingEquiv PA PA'
fst equivR = isoToEquiv is
where
is : Iso (PA .fst) (PA' .fst)
fun is = directSense
inv is = convSense
rightInv is = sect
leftInv is = retr
snd equivR = makeIsRingHom refl (λ _ _ → refl) converseSense-pres·
open equiv1
Equiv-Polyn-nPolyHIT : (A' : CommRing ℓ) → (n : ℕ) → CommRingEquiv (PolyCommRing A' n) (nUnivariatePolyHIT A' n)
Equiv-Polyn-nPolyHIT A' zero = CRE-Poly0-A A'
Equiv-Polyn-nPolyHIT A' (suc n) = inv-ecr _ _ (CRE-PolyN∘M-PolyN+M A' 1 n)
∘-ecr (lift-equiv-poly _ _ 1 (Equiv-Polyn-nPolyHIT A' n)
∘-ecr equivR (nUnivariatePolyHIT A' n))
| {
"alphanum_fraction": 0.5575460123,
"avg_line_length": 36.7117117117,
"ext": "agda",
"hexsha": "1cf5da60ec79cb9546aaed682e02ca0cdd7e1490",
"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/Polynomials/UnivariateHIT/Polyn-nPoly.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/Polynomials/UnivariateHIT/Polyn-nPoly.agda",
"max_line_length": 112,
"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/Polynomials/UnivariateHIT/Polyn-nPoly.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1267,
"size": 4075
} |
{-# OPTIONS --without-K --safe #-}
module Data.Unit where
open import Agda.Builtin.Unit public
| {
"alphanum_fraction": 0.7113402062,
"avg_line_length": 16.1666666667,
"ext": "agda",
"hexsha": "714ba9633cf5d70871590b2b19449e934bb5ec14",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Unit.agda",
"max_line_length": 36,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Unit.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": 22,
"size": 97
} |
{-# OPTIONS --experimental-irrelevance #-}
-- Andreas, 2011-04-15
-- {-# OPTIONS -v tc.data:20 #-}
module IrrelevantDataParameter where
postulate
A : Set
data K .(a : A) : Set where
c : K a
postulate
a : A
data K' .(b : A) : Set where
c : K' a
-- ok, since parameter irrelevant
-- 2011-09-09
postulate
_×_ : ..(A B : Set) -> Set
Lst : ..(A : Set) -> Set
nl : .(A : Set) -> Lst A
cns : .(A : Set) -> A × Lst A -> Lst A
-- cns' : .(A : Set) -> (a : A) -> (as : Lst A) -> Lst A -- not well-formed! | {
"alphanum_fraction": 0.5307692308,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "a848543a1397d5267ff2cc39dde33818af551249",
"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/IrrelevantDataParameter.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/IrrelevantDataParameter.agda",
"max_line_length": 78,
"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/IrrelevantDataParameter.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": 210,
"size": 520
} |
module Structure.Operator.Functions where
import Lvl
open import Logic
open import Structure.Setoid
open import Structure.Operator.Properties
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ : Lvl.Level
module _ {A : Type{ℓ₁}} {X : Type{ℓ₂}} ⦃ equiv-X : Equiv{ℓₑ₁}(X) ⦄ {Y : Type{ℓ₃}} ⦃ equiv-Y : Equiv{ℓₑ₂}(Y) ⦄ where
-- `a` is a element which yields the left identity element in the function `f`.
-- (a ∈ kernelₗ(f)) means (f(a) = id).
kernelₗ : ∀{_▫_ : X → Y → Y}{id : X} → ⦃ _ : Identityₗ(_▫_)(id) ⦄ → (A → X) → A → Stmt
kernelₗ {_}{id} (f)(a) = (f(a) ≡ id)
-- `a` is a element which yields the right identity element in the function `f`.
-- (a ∈ kernelₗ(f)) means (f(a) = id).
kernelᵣ : ∀{_▫_ : Y → X → Y}{id : X} → ⦃ _ : Identityᵣ(_▫_)(id) ⦄ → (A → X) → A → Stmt
kernelᵣ {_}{id} (f)(a) = (f(a) ≡ id)
| {
"alphanum_fraction": 0.5914489311,
"avg_line_length": 40.0952380952,
"ext": "agda",
"hexsha": "9cc5234d69afe26a9743cceb2394b3eb3df9cc46",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Operator/Functions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Operator/Functions.agda",
"max_line_length": 115,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Operator/Functions.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": 368,
"size": 842
} |
open import Relation.Binary.Core
module Heapsort.Impl1.Correctness.Order {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import Data.List
open import Function using (_∘_)
open import Heapsort.Impl1 _≤_ tot≤ trans≤
open import List.Sorted _≤_
open import OList _≤_
open import OList.Properties _≤_
theorem-heapsort-sorted : (xs : List A) → Sorted (forget (heapsort xs))
theorem-heapsort-sorted = lemma-olist-sorted ∘ heapsort
| {
"alphanum_fraction": 0.6570881226,
"avg_line_length": 30.7058823529,
"ext": "agda",
"hexsha": "29a1fb9b8ebfef25a537f091efa812a24ab33728",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/Heapsort/Impl1/Correctness/Order.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/Heapsort/Impl1/Correctness/Order.agda",
"max_line_length": 71,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/Heapsort/Impl1/Correctness/Order.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": 159,
"size": 522
} |
module Data.Option.Functions where
import Lvl
open import Data
open import Data.Boolean
open import Data.Either as Either using (_‖_)
open import Data.Option
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Type
private variable ℓ : Lvl.Level
private variable T A B T₁ T₂ T₃ : Type{ℓ}
-- Applies a function to the inner value of the option container.
-- A functor map for options.
map : (T₁ → T₂) → Option(T₁) → Option(T₂)
map f(Some x) = Some(f(x))
map f(None) = None
-- Either the value inside the option container or the default value when it is none.
-- An option eliminator.
_or_ : Option(T) → T → T
_or_ (Some x) _ = x
_or_ None def = def
-- Either transforming the value inside the option container or the default value when it is none.
-- An option eliminator.
partialMap : B → (A → B) → (Option(A) → B)
partialMap _ f (Some x) = f(x)
partialMap def _ None = def
-- If the option have a value (is Some).
isSome : Option(T) → Bool
isSome (Some _) = 𝑇
isSome None = 𝐹
-- If the option have no value (is None).
isNone : Option(T) → Bool
isNone (Some _) = 𝐹
isNone None = 𝑇
-- Passes the inner value of the option to an option-valued function.
-- A monadic bind for options.
_andThen_ : Option(T₁) → (T₁ → Option(T₂)) → Option(T₂)
_andThen_ None _ = None
_andThen_ (Some x) f = f(x)
-- Combines options of different types by applying the specified binary operator when both options have a value, and none otherwise.
and-combine : (T₁ → T₂ → T₃) → (Option(T₁) → Option(T₂) → Option(T₃))
and-combine (_▫_) (Some x) (Some y) = Some(x ▫ y)
{-# CATCHALL #-}
and-combine _ _ _ = None
-- Combines options of different types by applying the specified binary operator when both options have a value, and the side functions when only the respective sides have a value. None otherwise.
or-combine : (T₁ → T₂ → T₃) → (T₁ → T₃) → (T₂ → T₃) → (Option(T₁) → Option(T₂) → Option(T₃))
or-combine(_▫_) l r None None = None
or-combine(_▫_) l r None (Some y) = Some(r(y))
or-combine(_▫_) l r (Some x) None = Some(l(x))
or-combine(_▫_) l r (Some x) (Some y) = Some(x ▫ y)
module Same where
_orₗ_ : Option(T) → Option(T) → Option(T)
_orₗ_ = or-combine(\x y → x) (\x → x) (\x → x)
_orᵣ_ : Option(T) → Option(T) → Option(T)
_orᵣ_ = or-combine(\x y → y) (\x → x) (\x → x)
_andₗ_ : Option(T) → Option(T) → Option(T)
_andₗ_ = and-combine(\x y → x)
_andᵣ_ : Option(T) → Option(T) → Option(T)
_andᵣ_ = and-combine(\x y → y)
module Different where
_orₗ_ : Option(T₁) → Option(T₂) → Option(T₁ ‖ T₂)
_orₗ_ = or-combine(\x y → Either.Left(x)) Either.Left Either.Right
_orᵣ_ : Option(T₁) → Option(T₂) → Option(T₁ ‖ T₂)
_orᵣ_ = or-combine(\x y → Either.Right(y)) Either.Left Either.Right
_and_ : Option(T₁) → Option(T₂) → Option(T₁ ⨯ T₂)
_and_ = and-combine(_,_)
| {
"alphanum_fraction": 0.6557434813,
"avg_line_length": 34.1927710843,
"ext": "agda",
"hexsha": "f59f602c6dea7491c1aa9efc6608d418ca4b2bc8",
"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/Option/Functions.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/Option/Functions.agda",
"max_line_length": 196,
"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/Option/Functions.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": 964,
"size": 2838
} |
------------------------------------------------------------------------
-- Partiality algebra categories
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module Partiality-algebra.Category where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (T)
open import Bijection equality-with-J as Bijection using (_↔_)
open import Category equality-with-J as Category
open import Equality.Path.Isomorphisms.Univalence equality-with-paths
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Structure-identity-principle equality-with-J
open import Univalence-axiom equality-with-J
open import Partiality-algebra as PA hiding (id; _∘_)
------------------------------------------------------------------------
-- Equality characterisation lemmas for Partiality-algebra-with
abstract
-- An equality characterisation lemma for Partiality-algebra-with.
equality-characterisation-Partiality-algebra-with₁ :
∀ {a p q} {A : Type a} {T : Type p}
{P₁ P₂ : Partiality-algebra-with T q A} →
let module P₁ = Partiality-algebra-with P₁
module P₂ = Partiality-algebra-with P₂
in
(∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (≡⇒→ (⊑≡⊑ _ _) ∘_) s))
↔
P₁ ≡ P₂
equality-characterisation-Partiality-algebra-with₁
{q = q} {A} {T} {P₁} {P₂} =
(∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (≡⇒→ (⊑≡⊑ _ _) ∘_) s)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ s →
≡⇒↝ _ $ cong (λ (p : {f : ℕ → T} → _) →
P₁.⨆ s ≡ P₂.⨆ (Σ-map id p s)) $
(implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.⊑-propositional)
(≡⇒→ (⊑≡⊑ _ _) ∘_)
(λ {f} → ≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n))
(⟨ext⟩ (⟨ext⟩ ∘ ⊑≡⊑))))) ⟩
(∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ (Σ-map id
(λ {f} →
≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n))
(⟨ext⟩ (⟨ext⟩ ∘ ⊑≡⊑))))
s)) ↝⟨ Σ-cong (∀-cong ext λ _ →
Eq.extensionality-isomorphism bad-ext) (λ _ → F.id) ⟩
(∃ λ (⊑≡⊑ : ∀ x → P₁._⊑_ x ≡ P₂._⊑_ x) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ (Σ-map id
(λ {f} →
≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n))
(⟨ext⟩ ⊑≡⊑)))
s)) ↝⟨ Σ-cong (Eq.extensionality-isomorphism bad-ext) (λ _ → F.id) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ (Σ-map id
(λ {f} →
≡⇒→ (cong (λ _⊑_ → ∀ n → f n ⊑ f (suc n))
⊑≡⊑))
s)) ↔⟨⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ ( proj₁ s
, ≡⇒→ (cong (λ _⊑_ →
∀ n → proj₁ s n ⊑ proj₁ s (suc n))
⊑≡⊑)
(proj₂ s)
)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ eq → _ ≡ P₂.⨆ (_ , ≡⇒→ eq _)) $ sym $
cong-∘ _ _ ⊑≡⊑) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ ( proj₁ s
, ≡⇒→ (cong (uncurry λ _⊑_ (f : ℕ → T) →
∀ n → f n ⊑ f (suc n))
(cong (_, _) ⊑≡⊑))
(proj₂ s)
)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ inc → _ ≡ P₂.⨆ (_ , inc)) $ sym $
subst-in-terms-of-≡⇒↝ equivalence (cong (_, _) ⊑≡⊑) _ _) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ ( proj₁ s
, subst (uncurry λ _⊑_ (f : ℕ → T) →
∀ n → f n ⊑ f (suc n))
(cong (_, _) ⊑≡⊑)
(proj₂ s)
)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ eq → _ ≡
P₂.⨆ (_ , subst (uncurry λ _⊑_ (f : ℕ → T) →
∀ n → f n ⊑ f (suc n))
eq _)) $ sym $
Σ-≡,≡→≡-subst-const ⊑≡⊑ refl) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ ( proj₁ s
, subst (uncurry λ _⊑_ (f : ℕ → T) →
∀ n → f n ⊑ f (suc n))
(Σ-≡,≡→≡ ⊑≡⊑ (subst-const ⊑≡⊑))
(proj₂ s)
)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ s → _ ≡ P₂.⨆ s) $ sym $
push-subst-pair′ {y≡z = ⊑≡⊑} _ _ (subst-const ⊑≡⊑)) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ (subst (λ _⊑_ → ∃ λ f → ∀ n → f n ⊑ f (suc n))
⊑≡⊑ s)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ eq → _ ≡
P₂.⨆ (subst (λ _⊑_ → ∃ λ f → ∀ n →
f n ⊑ f (suc n)) eq _)) $
sym $ sym-sym ⊑≡⊑) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
P₂.⨆ (subst (λ _⊑_ → ∃ λ f → ∀ n → f n ⊑ f (suc n))
(sym (sym ⊑≡⊑)) s)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (_ ≡_) $ sym $
subst-→-domain _ (sym ⊑≡⊑)) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡
subst (λ _⊑_ → ∃ (λ f → ∀ n → f n ⊑ f (suc n)) → T)
(sym ⊑≡⊑) P₂.⨆ s) ↔⟨ ∃-cong (λ _ → ∃-cong λ _ →
Eq.extensionality-isomorphism ext
×-cong
Eq.extensionality-isomorphism ext) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
P₁.now ≡ P₂.now
×
P₁.⨆ ≡ subst _ (sym ⊑≡⊑) P₂.⨆) ↝⟨ ∃-cong (λ ⊑≡⊑ → ∃-cong λ _ → ∃-cong λ _ →
≡⇒↝ _ $ elim (λ ⊑≡⊑ → ∀ {⨆₁ ⨆₂} →
(⨆₁ ≡ subst _ (sym ⊑≡⊑) ⨆₂) ≡
(subst _ ⊑≡⊑ ⨆₁ ≡ ⨆₂))
(λ _ → refl) ⊑≡⊑) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
P₁.never ≡ P₂.never
×
P₁.now ≡ P₂.now
×
subst _ ⊑≡⊑ P₁.⨆ ≡ P₂.⨆) ↝⟨ ∃-cong (λ ⊑≡⊑ →
≡⇒↝ _ (cong (_≡ _) $ sym $ subst-const ⊑≡⊑)
×-cong
≡⇒↝ _ (cong (_≡ _) $ sym $ subst-const ⊑≡⊑)
×-cong
F.id) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
subst _ ⊑≡⊑ P₁.never ≡ P₂.never
×
subst _ ⊑≡⊑ P₁.now ≡ P₂.now
×
subst _ ⊑≡⊑ P₁.⨆ ≡ P₂.⨆) ↝⟨ ∃-cong (λ _ → ∃-cong λ _ → ≡×≡↔≡) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
subst _ ⊑≡⊑ P₁.never ≡ P₂.never
×
(subst _ ⊑≡⊑ P₁.now , subst _ ⊑≡⊑ P₁.⨆) ≡
(P₂.now , P₂.⨆)) ↝⟨ ∃-cong (λ _ → ≡×≡↔≡) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
(subst _ ⊑≡⊑ P₁.never , subst _ ⊑≡⊑ P₁.now , subst _ ⊑≡⊑ P₁.⨆) ≡
(P₂.never , P₂.now , P₂.⨆)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ≡⇒↝ _ $ cong (λ x → (subst _ ⊑≡⊑ P₁.never , x) ≡ _) $
sym $ push-subst-, {y≡z = ⊑≡⊑} _
(λ _⊑_ → (∃ λ f → ∀ n → f n ⊑ f (suc n)) → _)) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
(subst _ ⊑≡⊑ P₁.never , subst _ ⊑≡⊑ (P₁.now , P₁.⨆)) ≡
(P₂.never , P₂.now , P₂.⨆)) ↝⟨ ∃-cong (λ ⊑≡⊑ → ≡⇒↝ _ $ cong (_≡ _) $ sym $
push-subst-, {y≡z = ⊑≡⊑} _ _) ⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
subst _ ⊑≡⊑ (P₁.never , P₁.now , P₁.⨆) ≡
(P₂.never , P₂.now , P₂.⨆)) ↔⟨⟩
(∃ λ (⊑≡⊑ : P₁._⊑_ ≡ P₂._⊑_) →
subst _ ⊑≡⊑ (proj₂ (proj₁ (_↔_.to rearrange P₁))) ≡
proj₂ (proj₁ (_↔_.to rearrange P₂))) ↝⟨ Bijection.Σ-≡,≡↔≡ ⟩
proj₁ (_↔_.to rearrange P₁) ≡ proj₁ (_↔_.to rearrange P₂) ↝⟨ ignore-propositional-component
(×-closure 1 (implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.T-is-set) $
×-closure 1 (H-level-propositional ext 2) $
×-closure 1 (Π-closure ext 1 λ _ →
P₂.⊑-propositional) $
×-closure 1 (implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.⊑-propositional) $
×-closure 1 (Π-closure ext 1 λ _ →
P₂.⊑-propositional) $
×-closure 1 (Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.⊑-propositional) $
×-closure 1 (Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
P₂.⊑-propositional)
(implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Is-proposition-propositional ext)) ⟩
_↔_.to rearrange P₁ ≡ _↔_.to rearrange P₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ rearrange) ⟩□
P₁ ≡ P₂ □
where
module P₁ = Partiality-algebra-with P₁
module P₂ = Partiality-algebra-with P₂
rearrange :
Partiality-algebra-with T q A
↔
∃ λ ((_⊑_ , never , _ , ⨆) :
∃ λ (_⊑_ : T → T → Type q) →
T ×
(A → T) ×
((∃ λ (f : ℕ → T) → ∀ n → f n ⊑ f (suc n)) → T)) →
(∀ {x y} → x ⊑ y → y ⊑ x → x ≡ y)
×
Is-set T
×
(∀ x → x ⊑ x)
×
(∀ {x y z} → x ⊑ y → y ⊑ z → x ⊑ z)
×
(∀ x → never ⊑ x)
×
(∀ s → ∀ n → proj₁ s n ⊑ ⨆ s)
×
(∀ s ub → (∀ n → proj₁ s n ⊑ ub) → ⨆ s ⊑ ub)
×
(∀ {x y} → Is-proposition (x ⊑ y))
rearrange = record
{ surjection = record
{ logical-equivalence = record
{ to = λ P → let open Partiality-algebra-with P in
( _⊑_
, never
, now
, ⨆
)
, antisymmetry
, T-is-set-unused
, ⊑-refl
, ⊑-trans
, never⊑
, upper-bound
, least-upper-bound
, ⊑-propositional
; from = λ where
((LE , ne , n , l) , a , u , r , t , le , ub , lub , p) →
record
{ _⊑_ = LE
; never = ne
; now = n
; ⨆ = l
; antisymmetry = a
; T-is-set-unused = u
; ⊑-refl = r
; ⊑-trans = t
; never⊑ = le
; upper-bound = ub
; least-upper-bound = lub
; ⊑-propositional = p
}
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
-- Another equality characterisation lemma for
-- Partiality-algebra-with.
equality-characterisation-Partiality-algebra-with₂ :
∀ {a p q} {A : Type a} {T : Type p}
{P₁ P₂ : Partiality-algebra-with T q A} →
let module P₁ = Partiality-algebra-with P₁
module P₂ = Partiality-algebra-with P₂
in
(∃ λ (⊑⇔⊑ : ∀ x y → x P₁.⊑ y ⇔ x P₂.⊑ y) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (_⇔_.to (⊑⇔⊑ _ _) ∘_) s))
↔
P₁ ≡ P₂
equality-characterisation-Partiality-algebra-with₂
{q = q} {A} {T} {P₁} {P₂} =
(∃ λ (⊑⇔⊑ : ∀ x y → x P₁.⊑ y ⇔ x P₂.⊑ y) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (_⇔_.to (⊑⇔⊑ _ _) ∘_) s)) ↝⟨ Σ-cong (∀-cong ext λ _ → ∀-cong ext λ _ →
Eq.⇔↔≃ ext P₁.⊑-propositional P₂.⊑-propositional)
(λ _ → F.id) ⟩
(∃ λ (⊑≃⊑ : ∀ x y → (x P₁.⊑ y) ≃ (x P₂.⊑ y)) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (_≃_.to (⊑≃⊑ _ _) ∘_) s)) ↝⟨ inverse $ Σ-cong
(∀-cong ext λ _ → ∀-cong ext λ _ →
≡≃≃ (_≃_.to
(Propositional-extensionality-is-univalence-for-propositions
ext)
prop-ext
P₁.⊑-propositional
P₂.⊑-propositional))
(λ _ → F.id) ⟩
(∃ λ (⊑≡⊑ : ∀ x y → (x P₁.⊑ y) ≡ (x P₂.⊑ y)) →
P₁.never ≡ P₂.never
×
(∀ x → P₁.now x ≡ P₂.now x)
×
∀ s → P₁.⨆ s ≡ P₂.⨆ (Σ-map id (≡⇒→ (⊑≡⊑ _ _) ∘_) s)) ↝⟨ equality-characterisation-Partiality-algebra-with₁ ⟩□
P₁ ≡ P₂ □
where
module P₁ = Partiality-algebra-with P₁
module P₂ = Partiality-algebra-with P₂
------------------------------------------------------------------------
-- Partiality algebra categories
-- Partiality algebras (with fixed levels and types) form
-- precategories.
precategory :
∀ {a} p q (A : Type a) → Precategory (a ⊔ lsuc (p ⊔ q)) (a ⊔ p ⊔ q)
Precategory.precategory (precategory p q A) =
Partiality-algebra p q A
, (λ P Q → Morphism P Q , Morphism-set)
, PA.id
, PA._∘_
, _↔_.to equality-characterisation-Morphism refl
, _↔_.to equality-characterisation-Morphism refl
, _↔_.to equality-characterisation-Morphism refl
-- A "standard notion of structure" built using
-- Partiality-algebra-with.
standard-notion-of-structure :
∀ {a} p q (A : Type a) →
Standard-notion-of-structure _ _ (precategory-Set p ext)
standard-notion-of-structure p q A = record
{ P = λ B → Partiality-algebra-with (proj₁ B) q A
; H = Is-morphism-with
; H-prop = λ { {p = P} {q = Q} _ →
Is-morphism-with-propositional P Q
}
; H-id = λ { {p = P} →
proj₂ $
_↔_.to Morphism↔Morphism-as-Σ
(PA.id {P = ⟨ P ⟩})
}
; H-∘ = λ { {p = P} {q = Q} {r = R}
f-morphism g-morphism →
proj₂ $
_↔_.to Morphism↔Morphism-as-Σ
(_↔_.from
(Morphism↔Morphism-as-Σ
{P₁ = ⟨ Q ⟩} {P₂ = ⟨ R ⟩})
(_ , g-morphism)
PA.∘
_↔_.from
(Morphism↔Morphism-as-Σ {P₁ = ⟨ P ⟩})
(_ , f-morphism))
}
; H-antisymmetric = λ P Q id-morphism-P→Q id-morphism-Q→P →
_↔_.to
(equality-characterisation-Partiality-algebra-with₂)
( (λ x y → record { to = proj₁ id-morphism-P→Q
; from = proj₁ id-morphism-Q→P
})
, proj₁ (proj₂ id-morphism-P→Q)
, proj₁ (proj₂ (proj₂ id-morphism-P→Q))
, proj₂ (proj₂ (proj₂ id-morphism-P→Q))
)
}
abstract
-- The precategory obtained from the standard notion of structure is
-- equal to the direct definition above.
precategories-equal :
∀ {a p q} {A : Type a} →
Standard-notion-of-structure.Str
(standard-notion-of-structure p q A)
≡
precategory p q A
precategories-equal {p = p} {q} {A} =
_↔_.to (equality-characterisation-Precategory ext univ univ)
( ≃Partiality-algebra
, (λ _ _ → Eq.↔⇒≃ $ inverse $ Morphism↔Morphism-as-Σ)
, (λ _ → refl)
, (λ _ _ _ _ _ → refl)
)
where
≃Partiality-algebra :
(∃ λ (T : Set p) → Partiality-algebra-with (proj₁ T) q A)
≃
Partiality-algebra p q A
≃Partiality-algebra =
(∃ λ (T : Set p) → Partiality-algebra-with (proj₁ T) q A) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (T : Type p) →
Is-set T × Partiality-algebra-with T q A) ↔⟨ ∃-cong (λ _ → drop-⊤-left-× λ P → _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(H-level-propositional ext 2)
(Partiality-algebra-with.T-is-set P)) ⟩
(∃ λ (T : Type p) → Partiality-algebra-with T q A) ↝⟨ Eq.↔⇒≃ record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ _ P → ⟨ P ⟩
; from = λ P → T P , partiality-algebra-with P
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
} ⟩□
Partiality-algebra p q A □
where
open Partiality-algebra
-- Thus the precategory is a category.
category :
∀ {a} p q (A : Type a) →
Category (a ⊔ lsuc (p ⊔ q)) (a ⊔ p ⊔ q)
Category.category (category p q A) =
precategory _ _ A
, subst (λ C → ∀ {P Q} → Eq.Is-equivalence
(Precategory.≡→≅ C {P} {Q}))
precategories-equal
(structure-identity-principle
ext
(category-Set _ ext (λ _ _ → univ))
(standard-notion-of-structure p q A))
private
precategory-category :
∀ {a p q} {A : Type a} →
Category.precategory (category p q A) ≡ precategory p q A
precategory-category = refl
| {
"alphanum_fraction": 0.2806558387,
"avg_line_length": 50.0616570328,
"ext": "agda",
"hexsha": "26cd63a3fdc5182351d01796474f026b4f97ab3d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-algebra/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-algebra/Category.agda",
"max_line_length": 148,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-algebra/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 7547,
"size": 25982
} |
module _ where
open import Common.Prelude hiding (_>>=_)
open import Common.Reflection
open import Agda.Builtin.Sigma
infix -100 This:_ this:_
data This:_ {a} {A : Set a} : A → Set where
this:_ : ∀ x → This: x
macro
runT : Tactic → Tactic
runT m = m
evalT : ∀ {a} {A : Set a} → TC A → Tactic
evalT m hole = m >>= quoteTC >>= unify hole
-- The context on the rhs of each of the two functions below is the same, a single String
Γ : Telescope
Γ = ("s" , vArg (def (quote String) [])) ∷ []
context-Γ₀ : String → This: Γ
context-Γ₀ s = this: evalT getContext
module _ (S : String) where
Γ' : Telescope
Γ' = ("S" , vArg (def (quote String) [])) ∷ []
context-Γ₁ : This: Γ'
context-Γ₁ = this: evalT getContext
downMap : {A : Set} → (Nat → A) → Nat → List A
downMap f zero = []
downMap f (suc n) = f n ∷ downMap f n
f-type : Term
f-type = def (quote String) []
f-tel : Nat → List (Σ String λ _ → Arg Type)
f-tel n = downMap (λ _ → "_" , vArg unknown) n
f-pats : Nat → List (Arg Pattern)
f-pats n = downMap (λ x → vArg (var x)) n
f-term : Nat → Term
f-term n = var n []
defineFresh : Nat → Nat → TC QName
defineFresh #pats #term =
freshName "f" >>= λ f →
define (vArg f) (funDef f-type (clause (f-tel #pats) (f-pats #pats) (f-term #term) ∷ [])) >>= λ _ →
returnTC f
freshFun : Nat → Nat → TC Bool
freshFun #pats #term =
catchTC (defineFresh #pats #term >>= λ _ → returnTC true)
(returnTC false)
-- Check that the pattern list must be of length 0
-- and the context features 1 available variable.
define-Γ₀-0-0 : String → This: true
define-Γ₀-0-0 s = this: evalT (freshFun 0 0)
define-Γ₀-1-0 : String → This: false
define-Γ₀-1-0 s = this: evalT (freshFun 1 0)
define-Γ₀-1-1 : String → This: false
define-Γ₀-1-1 s = this: evalT (freshFun 0 1)
module _ (S : String) where
define-Γ₁-0-0 : This: true
define-Γ₁-0-0 = this: evalT (freshFun 0 0)
define-Γ₁-0-1 : This: false
define-Γ₁-0-1 = this: evalT (freshFun 0 1)
define-Γ₁-1-0 : This: false
define-Γ₁-1-0 = this: evalT (freshFun 1 0)
f₀ : String → String
f₀ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])
f₁ : String → String
f₁ = λ s → runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])
f₂ : String → String
f₂ s = runT λ hole → defineFresh 0 0 >>= λ f → unify hole (def f [])
where x = 0
| {
"alphanum_fraction": 0.620453573,
"avg_line_length": 25.402173913,
"ext": "agda",
"hexsha": "c5d3f6d008b8d44e74c85ea6d1e2d8948635f273",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue1833.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue1833.agda",
"max_line_length": 101,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue1833.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 881,
"size": 2337
} |
{-# OPTIONS --without-K --safe #-}
-- The 'original' version of Lawvere Theory, based on
-- Nat^op and IOO functors. Contrast with the weak version at
-- https://ncatlab.org/nlab/show/Lawvere+theory
-- Unfortunately, many results on the weak version are not in
-- the literature, so doing that development would be new research.
module Categories.Theory.Lawvere where
open import Data.Nat using (ℕ)
open import Level
open import Categories.Category.Cartesian using (Cartesian)
open import Categories.Category.Cartesian.Bundle using (CartesianCategory)
import Categories.Category.Core as Cat
open import Categories.Category.Instance.Nat using (Nat; Natop-Cartesian)
open import Categories.Category.Instance.Setoids
open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-CartesianCategory)
open import Categories.Category.Unbundled using (Category)
open import Categories.Category.Unbundled.Properties using (pack′; unpack′)
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.Functor.Cartesian
open import Categories.Functor.Cartesian.Properties
open import Categories.Functor.IdentityOnObjects
private
variable
ℓ e o′ ℓ′ e′ ℓ″ e″ : Level
record LawvereTheory (ℓ e : Level) : Set (suc (ℓ ⊔ e)) where
private
𝒩 = Cat.Category.op Nat
field
L : Category ℕ ℓ e
L′ : Cat.Category 0ℓ ℓ e
L′ = pack′ L
field
T : Cartesian L′
CartT : CartesianCategory 0ℓ ℓ e
CartT = record { U = L′ ; cartesian = T }
field
I : IdentityOnObjects (unpack′ 𝒩) L
CartF : IsCartesianF Natop-Cartesian CartT (IOO⇒Functor I)
record LT-Hom (T₁ : LawvereTheory ℓ e) (T₂ : LawvereTheory ℓ′ e′) : Set (ℓ ⊔ e ⊔ ℓ′ ⊔ e′) where
private
module T₁ = LawvereTheory T₁
module T₂ = LawvereTheory T₂
field
cartF : CartesianF T₁.CartT T₂.CartT
module cartF = CartesianF cartF using (F)
LT-id : {A : LawvereTheory ℓ e} → LT-Hom A A
LT-id = record { cartF = idF-CartesianF _ }
LT-∘ : {A : LawvereTheory ℓ e} {B : LawvereTheory ℓ′ e′} {C : LawvereTheory ℓ″ e″} →
LT-Hom B C → LT-Hom A B → LT-Hom A C
LT-∘ G H = record { cartF = ∘-CartesianF (cartF G) (cartF H) }
where open LT-Hom
-- A 'Model' will be taken to be in Setoids.
record Model (LT : LawvereTheory ℓ e) : Set (ℓ ⊔ e ⊔ suc (ℓ′ ⊔ e′)) where
private
module LT = LawvereTheory LT
field
cartF : CartesianF LT.CartT (Setoids-CartesianCategory ℓ′ e′)
module cartF = CartesianF cartF
mod : Functor LT.L′ (Setoids ℓ′ e′)
mod = cartF.F
-- But we can have more general models 'in' a cartesian category
record ModelsOf_In_ (LT : LawvereTheory ℓ e) (𝒞 : CartesianCategory o′ ℓ′ e′) : Set (ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module LT = LawvereTheory LT using (L′; CartT)
module CC = CartesianCategory 𝒞 using (U)
field
cartF : CartesianF LT.CartT 𝒞
mod : Functor LT.L′ CC.U
mod = CartesianF.F cartF
| {
"alphanum_fraction": 0.7057192374,
"avg_line_length": 33.5465116279,
"ext": "agda",
"hexsha": "2852edc643596ca92420bb8e3d56ec49905ee299",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Theory/Lawvere.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Theory/Lawvere.agda",
"max_line_length": 112,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Theory/Lawvere.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 927,
"size": 2885
} |
{-# OPTIONS --without-K --safe #-}
module Magma where
open import Magma.Bundles public
open import Magma.Structures public
open import Magma.Definitions public
| {
"alphanum_fraction": 0.7777777778,
"avg_line_length": 20.25,
"ext": "agda",
"hexsha": "e4db8a481466b1612ce686c6ce191ed9fcc8b297",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Magma.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Magma.agda",
"max_line_length": 36,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Magma.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 38,
"size": 162
} |
-- Andreas, 2015-02-24, issue reported by g.x.allais
-- {-# OPTIONS -v interaction.give:100 #-}
record R : Set1 where
field
-v : Set
goal : R
goal = {!!}
-- refine here
-- WAS: error due to rendering or record as
-- record {-v = ?}
| {
"alphanum_fraction": 0.6049382716,
"avg_line_length": 17.3571428571,
"ext": "agda",
"hexsha": "f2234b5a699b52adcea1e27f46485423798b50a3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue1434.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1434.agda",
"max_line_length": 52,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1434.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 78,
"size": 243
} |
{-
ℤ is a Commutative Ring (using QuoInt)
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.QuoInt where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.CommRing
open import Cubical.Data.Nat using (ℕ ; zero ; suc)
open import Cubical.Data.Bool using (not)
open import Cubical.Data.Int.MoreInts.QuoInt
renaming (ℤ to ℤType ; _+_ to _+ℤ_; _·_ to _·ℤ_; -_ to -ℤ_)
open CommRingStr
-- The missing additive inversion
+InvL' : ∀ n s → signed (not s) n +ℤ signed s n ≡ signed s zero
+InvL' zero _ = refl
+InvL' (suc n) spos = predℤ-+ʳ (neg n) (pos (suc n)) ∙ (λ i → neg n +ℤ predSucℤ (pos n) i) ∙ +InvL' n spos
+InvL' (suc n) sneg = sucℤ-+ʳ (pos n) (neg (suc n)) ∙ (λ i → pos n +ℤ sucPredℤ (neg n) i) ∙ +InvL' n sneg
+InvL : (n : ℤType) → (-ℤ n) +ℤ n ≡ 0
+InvL (signed spos n) = +InvL' n spos
+InvL (signed sneg n) = +InvL' n sneg ∙ sym posneg
+InvL (posneg i) j =
hcomp (λ k → λ
{ (i = i0) → 0
; (i = i1) → compPath-filler refl (sym posneg) k j
; (j = i0) → posneg i
; (j = i1) → posneg (i ∧ ~ k) })
(posneg i)
+InvR : (n : ℤType) → n +ℤ (-ℤ n) ≡ 0
+InvR n = +-comm n (-ℤ n) ∙ +InvL n
ℤCommRing : CommRing ℓ-zero
ℤCommRing .fst = ℤType
ℤCommRing .snd .0r = 0
ℤCommRing .snd .1r = 1
ℤCommRing .snd ._+_ = _+ℤ_
ℤCommRing .snd ._·_ = _·ℤ_
ℤCommRing .snd .-_ = -ℤ_
ℤCommRing .snd .isCommRing = isCommRingℤ
where
abstract
isCommRingℤ : IsCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_
isCommRingℤ = makeIsCommRing
isSetℤ +-assoc (+-zeroʳ _)
+InvR +-comm ·-assoc
·-identityʳ (λ x y z → sym (·-distribˡ x y z)) ·-comm
| {
"alphanum_fraction": 0.6139798489,
"avg_line_length": 28.3571428571,
"ext": "agda",
"hexsha": "3da9aa5ebc152ee0fe46e891f2595730d9228fdc",
"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": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "gmagaf/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/QuoInt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"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": "gmagaf/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/QuoInt.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "gmagaf/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/QuoInt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 705,
"size": 1588
} |
-- Intuitionistic propositional calculus.
-- Common syntax.
module IPC.Syntax.Common where
open import Common.Context public
-- Types, or propositions.
infixl 9 _∧_
infixl 8 _∨_
infixr 7 _▻_
data Ty : Set where
α_ : Atom → Ty
_▻_ : Ty → Ty → Ty
_∧_ : Ty → Ty → Ty
⊤ : Ty
⊥ : Ty
_∨_ : Ty → Ty → Ty
-- Additional useful types.
¬_ : Ty → Ty
¬ A = A ▻ ⊥
infix 7 _▻◅_
_▻◅_ : Ty → Ty → Ty
A ▻◅ B = (A ▻ B) ∧ (B ▻ A)
infixr 7 _▻⋯▻_
_▻⋯▻_ : Cx Ty → Ty → Ty
∅ ▻⋯▻ B = B
(Ξ , A) ▻⋯▻ B = Ξ ▻⋯▻ (A ▻ B)
infixr 7 _▻⋯▻⋆_
_▻⋯▻⋆_ : Cx Ty → Cx Ty → Ty
Γ ▻⋯▻⋆ ∅ = ⊤
Γ ▻⋯▻⋆ (Ξ , A) = (Γ ▻⋯▻⋆ Ξ) ∧ (Γ ▻⋯▻ A)
-- Inversion principles.
invα : ∀ {P P′} → α P ≡ α P′ → P ≡ P′
invα refl = refl
inv▻₁ : ∀ {A A′ B B′} → A ▻ B ≡ A′ ▻ B′ → A ≡ A′
inv▻₁ refl = refl
inv▻₂ : ∀ {A A′ B B′} → A ▻ B ≡ A′ ▻ B′ → B ≡ B′
inv▻₂ refl = refl
inv∧₁ : ∀ {A A′ B B′} → A ∧ B ≡ A′ ∧ B′ → A ≡ A′
inv∧₁ refl = refl
inv∧₂ : ∀ {A A′ B B′} → A ∧ B ≡ A′ ∧ B′ → B ≡ B′
inv∧₂ refl = refl
inv∨₁ : ∀ {A A′ B B′} → A ∨ B ≡ A′ ∨ B′ → A ≡ A′
inv∨₁ refl = refl
inv∨₂ : ∀ {A A′ B B′} → A ∨ B ≡ A′ ∨ B′ → B ≡ B′
inv∨₂ refl = refl
-- Decidable equality on types.
_≟ᵀ_ : (A A′ : Ty) → Dec (A ≡ A′)
(α P) ≟ᵀ (α P′) with P ≟ᵅ P′
(α P) ≟ᵀ (α .P) | yes refl = yes refl
(α P) ≟ᵀ (α P′) | no P≢P′ = no (P≢P′ ∘ invα)
(α P) ≟ᵀ (A′ ▻ B′) = no λ ()
(α P) ≟ᵀ (A′ ∧ B′) = no λ ()
(α P) ≟ᵀ ⊤ = no λ ()
(α P) ≟ᵀ ⊥ = no λ ()
(α P) ≟ᵀ (A′ ∨ B′) = no λ ()
(A ▻ B) ≟ᵀ (α P′) = no λ ()
(A ▻ B) ≟ᵀ (A′ ▻ B′) with A ≟ᵀ A′ | B ≟ᵀ B′
(A ▻ B) ≟ᵀ (.A ▻ .B) | yes refl | yes refl = yes refl
(A ▻ B) ≟ᵀ (A′ ▻ B′) | no A≢A′ | _ = no (A≢A′ ∘ inv▻₁)
(A ▻ B) ≟ᵀ (A′ ▻ B′) | _ | no B≢B′ = no (B≢B′ ∘ inv▻₂)
(A ▻ B) ≟ᵀ (A′ ∧ B′) = no λ ()
(A ▻ B) ≟ᵀ ⊤ = no λ ()
(A ▻ B) ≟ᵀ ⊥ = no λ ()
(A ▻ B) ≟ᵀ (A′ ∨ B′) = no λ ()
(A ∧ B) ≟ᵀ (α P′) = no λ ()
(A ∧ B) ≟ᵀ (A′ ▻ B′) = no λ ()
(A ∧ B) ≟ᵀ (A′ ∧ B′) with A ≟ᵀ A′ | B ≟ᵀ B′
(A ∧ B) ≟ᵀ (.A ∧ .B) | yes refl | yes refl = yes refl
(A ∧ B) ≟ᵀ (A′ ∧ B′) | no A≢A′ | _ = no (A≢A′ ∘ inv∧₁)
(A ∧ B) ≟ᵀ (A′ ∧ B′) | _ | no B≢B′ = no (B≢B′ ∘ inv∧₂)
(A ∧ B) ≟ᵀ ⊤ = no λ ()
(A ∧ B) ≟ᵀ ⊥ = no λ ()
(A ∧ B) ≟ᵀ (A′ ∨ B′) = no λ ()
⊤ ≟ᵀ (α P′) = no λ ()
⊤ ≟ᵀ (A′ ▻ B′) = no λ ()
⊤ ≟ᵀ (A′ ∧ B′) = no λ ()
⊤ ≟ᵀ ⊤ = yes refl
⊤ ≟ᵀ ⊥ = no λ ()
⊤ ≟ᵀ (A′ ∨ B′) = no λ ()
⊥ ≟ᵀ (α P′) = no λ ()
⊥ ≟ᵀ (A′ ▻ B′) = no λ ()
⊥ ≟ᵀ (A′ ∧ B′) = no λ ()
⊥ ≟ᵀ ⊤ = no λ ()
⊥ ≟ᵀ ⊥ = yes refl
⊥ ≟ᵀ (A′ ∨ B′) = no λ ()
(A ∨ B) ≟ᵀ (α P′) = no λ ()
(A ∨ B) ≟ᵀ (A′ ▻ B′) = no λ ()
(A ∨ B) ≟ᵀ (A′ ∧ B′) = no λ ()
(A ∨ B) ≟ᵀ ⊤ = no λ ()
(A ∨ B) ≟ᵀ ⊥ = no λ ()
(A ∨ B) ≟ᵀ (A′ ∨ B′) with A ≟ᵀ A′ | B ≟ᵀ B′
(A ∨ B) ≟ᵀ (.A ∨ .B) | yes refl | yes refl = yes refl
(A ∨ B) ≟ᵀ (A′ ∨ B′) | no A≢A′ | _ = no (A≢A′ ∘ inv∨₁)
(A ∨ B) ≟ᵀ (A′ ∨ B′) | _ | no B≢B′ = no (B≢B′ ∘ inv∨₂)
open ContextEquality (_≟ᵀ_) public
| {
"alphanum_fraction": 0.3549465241,
"avg_line_length": 25.1428571429,
"ext": "agda",
"hexsha": "eee49f91e3581612d223f164ff330b49b9856db6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "IPC/Syntax/Common.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "IPC/Syntax/Common.agda",
"max_line_length": 62,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "IPC/Syntax/Common.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": 1841,
"size": 2992
} |
{-# OPTIONS --sized-types #-}
module CoSig where
open import Data.Product as Prod
open import Data.Fin
open import Data.Unit
open import Data.Empty
open import Data.Sum
open import Data.Nat
open import Size
open import Function
open import Relation.Binary.PropositionalEquality using (_≡_; refl; subst)
---- We don't use dependencies for now.
-- record CoSigDep (I : Set) : Set₁ where
-- field
-- ∥_∥ : I → Set
-- coar : {i : I} → ∥_∥ i → Set
-- sel : {i : I} (d : ∥_∥ i) → coar d → I
-- open CoSigDep public
-- Fam : Set → Set₁
-- Fam I = I → Set
-- -- | Extension of co-signature Δ, on objects
-- ⟪_⟫ : ∀{I} → CoSigDep I → Fam I → Fam I
-- ⟪ Δ ⟫ X i = (d : ∥ Δ ∥ i) → Σ[ u ∈ coar Δ d ] (X (sel Δ d u))
record CoSig : Set₁ where
field
∥_∥ : Set
coar : ∥_∥ → Set
open CoSig public
-- | Extension of co-signature Δ, on objects
⟪_⟫ : CoSig → Set → Set
--⟪ Δ ⟫ X = (d : ∥ Δ ∥) → Σ[ u ∈ coar Δ d ] X
⟪ Δ ⟫ X = (d : ∥ Δ ∥) → (coar Δ d) × X
-- | Extension of signature Σ, on morphisms
⟪_⟫₁ : (Δ : CoSig) {A B : Set} → (A → B) → ⟪ Δ ⟫ A → ⟪ Δ ⟫ B
⟪ Δ ⟫₁ f o d = Prod.map id f (o d)
-- | Lift ⟪ Δ ⟫ to relations
cosig-lift : {Δ : CoSig} {X : Set} (R : X → X → Set) (o₁ o₂ : ⟪ Δ ⟫ X) → Set
cosig-lift {Δ} _R_ o₁ o₂ =
∀ d → proj₁ (o₁ d) ≡ proj₁ (o₂ d) ×
proj₂ (o₁ d) R proj₂ (o₂ d)
record CoSig-FP (Δ : CoSig) : Set where
coinductive
field destr : ⟪ Δ ⟫ (CoSig-FP Δ)
open CoSig-FP public
record Str {i : Size} (A : Set) : Set where
coinductive
constructor _∷_
field
hd : A
tl : ∀ {j : Size< i} → Str {j} A
open Str public
--- Example: Streams
Str-CoSig : Set → CoSig
Str-CoSig A = record
{ ∥_∥ = ⊤
; coar = λ _ → A
}
Str' : Set → Set
Str' A = CoSig-FP (Str-CoSig A)
-- We can indeed extract a stream from stream implemented through cosignatures.
Str'-Str : ∀{A} → Str' A → Str A
hd (Str'-Str s) = proj₁ (destr s tt)
tl (Str'-Str s) = Str'-Str (proj₂ (destr s tt))
-- Example: Mealy machines
MM-CoSig : Set → Set → CoSig
MM-CoSig I O = record
{ ∥_∥ = I
; coar = λ _ → O
}
MM : Set → Set → Set
MM I O = CoSig-FP (MM-CoSig I O)
-- Such a Mealy machine gives rise to a causal stream transformation.
MM-Causal : ∀{I O} → MM I O → ∀{i} → Str {i} I → Str {i} O
hd (MM-Causal m s) = proj₁ (destr m (hd s))
tl (MM-Causal m s) = MM-Causal (proj₂ (destr m (hd s))) (tl s)
--- Not quite Example: Streams with stop button
BStr-CoSig : Set → CoSig
BStr-CoSig A = record
{ ∥_∥ = ⊥ ⊎ ⊤
; coar = BStr-CoSig-coar
}
where
BStr-CoSig-coar : ⊥ ⊎ ⊤ → Set
BStr-CoSig-coar (inj₁ x) = ⊥-elim x
BStr-CoSig-coar (inj₂ y) = A
BStr : Set → Set
BStr A = CoSig-FP (BStr-CoSig A)
st-ones : BStr ℕ
destr st-ones (inj₁ x) = ⊥-elim x
destr st-ones (inj₂ x) = (1 , st-ones)
-- Claim: This way of definining streams with a "stop button" renders
-- the button unusable. Thus, we only get streams back.
BStr-Str : ∀{A} → BStr A → Str A
hd (BStr-Str s) = proj₁ (destr s (inj₂ tt))
tl (BStr-Str s) = BStr-Str (proj₂ (destr s (inj₂ tt)))
Str-BStr : ∀{A} → Str A → BStr A
destr (Str-BStr s) (inj₁ x) = ⊥-elim x
destr (Str-BStr s) (inj₂ y) = (hd s , Str-BStr (tl s))
--- Example: Streams with stop button
BStr'-CoSig : Set → CoSig
BStr'-CoSig A = record
{ ∥_∥ = ⊤ ⊎ ⊤
; coar = BStr-CoSig-coar
}
where
BStr-CoSig-coar : ⊤ ⊎ ⊤ → Set
BStr-CoSig-coar (inj₁ x) = ⊥
BStr-CoSig-coar (inj₂ y) = A
BStr' : Set → Set
BStr' A = CoSig-FP (BStr'-CoSig A)
-- Claim: This way of defining streams with a stop button makes any
-- such stream undefinable. Thus, the fixed point is trivial.
BStr'-triv : ∀{A} → BStr' A → ⊥
BStr'-triv s = proj₁ (destr s (inj₁ tt))
-- An extension of cosignatures that allow us to give a continuation
-- for the following states. This enables us to specify systems with,
-- for example, termination.
record CoSig₂ : Set₁ where
field
∥_∥₂ : Set
coar₂ : ∥_∥₂ → Set
cont : ∥_∥₂ → Set
open CoSig₂ public
-- | Extension of co-signature Δ, on objects
⟪_⟫₂ : CoSig₂ → Set → Set
⟪ Δ ⟫₂ X = (d : ∥ Δ ∥₂) → (coar₂ Δ d) × (cont Δ d → X)
record CoSig₂-FP (Δ : CoSig₂) : Set where
coinductive
field destr₂ : ⟪ Δ ⟫₂ (CoSig₂-FP Δ)
open CoSig₂-FP public
--- Example: Streams with stop button
BStr-CoSig₂ : Set → CoSig₂
BStr-CoSig₂ A = record
{ ∥_∥₂ = ⊤ ⊎ ⊤
; coar₂ = BStr-CoSig-coar
; cont = BStr-CoSig-cont
}
where
BStr-CoSig-coar : ⊤ ⊎ ⊤ → Set
BStr-CoSig-coar (inj₁ x) = ⊤
BStr-CoSig-coar (inj₂ y) = A
BStr-CoSig-cont : ⊤ ⊎ ⊤ → Set
BStr-CoSig-cont (inj₁ x) = ⊥
BStr-CoSig-cont (inj₂ y) = ⊤
BStr₂ : Set → Set
BStr₂ A = CoSig₂-FP (BStr-CoSig₂ A)
st-ones₂ : BStr₂ ℕ
destr₂ st-ones₂ (inj₁ tt) = (tt , ⊥-elim)
destr₂ st-ones₂ (inj₂ tt) = (1 , (λ _ → st-ones₂))
| {
"alphanum_fraction": 0.5919846515,
"avg_line_length": 25.6338797814,
"ext": "agda",
"hexsha": "84791aed28899a9a3bac8b7f8bbf44b0b31256ef",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "CoSig/CoSig.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "CoSig/CoSig.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "CoSig/CoSig.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1944,
"size": 4691
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor.Bifunctor
module Categories.Diagram.End {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′}
(F : Bifunctor (Category.op C) C D) where
private
module C = Category C
module D = Category D
open D
open HomReasoning
variable
A B : Obj
f g : A ⇒ B
open import Level
open import Data.Product using (Σ; _,_)
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.NaturalTransformation.Dinatural
open import Categories.Morphism.Reasoning D
open Functor F
record Wedge : Set (levelOfTerm F) where
field
E : Obj
dinatural : DinaturalTransformation (const E) F
module dinatural = DinaturalTransformation dinatural
Wedge-∘ : (W : Wedge) → A ⇒ Wedge.E W → Wedge
Wedge-∘ {A = A} W f = record
{ E = A
; dinatural = extranaturalʳ (λ X → dinatural.α X ∘ f)
(⟺ assoc ○ ∘-resp-≈ˡ (extranatural-commʳ dinatural) ○ assoc )
}
where open Wedge W
record End : Set (levelOfTerm F) where
field
wedge : Wedge
module wedge = Wedge wedge
open wedge public
open Wedge
field
factor : (W : Wedge) → E W ⇒ wedge.E
universal : ∀ {W : Wedge} {A} → wedge.dinatural.α A ∘ factor W ≈ dinatural.α W A
unique : ∀ {W : Wedge} {g : E W ⇒ wedge.E} → (∀ {A} → wedge.dinatural.α A ∘ g ≈ dinatural.α W A) → factor W ≈ g
η-id : factor wedge ≈ D.id
η-id = unique identityʳ
unique′ :(∀ {A} → wedge.dinatural.α A ∘ f ≈ wedge.dinatural.α A ∘ g) → f ≈ g
unique′ {f = f} {g = g} eq = ⟺ (unique {W = Wedge-∘ wedge f} refl) ○ unique (⟺ eq)
| {
"alphanum_fraction": 0.6324228029,
"avg_line_length": 27.606557377,
"ext": "agda",
"hexsha": "b88eb2cd58a5b439fa136d1eb229eda5d0eb0c86",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Diagram/End.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Diagram/End.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Diagram/End.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 581,
"size": 1684
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.ImplShared.Consensus.Types
module LibraBFT.Impl.IO.OBM.ObmNeedFetch where
{-
The functions in this module are used when a node needs to catchup.
TODO-3: model catchup request/response in Agda.
In haskell, for each message received from the network (including messages to self),
each message is processed in a single thread that completes the processing
before then processing a subsequent message.
However, a node detects that it needs to catchup "in the middle" of that processing.
In Haskell we use unsafePerformIO to send a network request to other nodes asking
for "catchup" data.
The responses are received by a different thread that then feeds them to the waiting thread,
which then proceeds.
-}
postulate -- TODO-3: writeRequestReadResponseUNSAFE
writeRequestReadResponseUNSAFE
: ObmNeedFetch → Author → Author → BlockRetrievalRequest
→ BlockRetrievalResponse
| {
"alphanum_fraction": 0.7913043478,
"avg_line_length": 33.8235294118,
"ext": "agda",
"hexsha": "722e0fbd924dd8848b8801873e0d7440a0235004",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T01:04:32.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-16T19:43:52.000Z",
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/IO/OBM/ObmNeedFetch.agda",
"max_issues_count": 72,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T05:36:11.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-02-04T05:04:33.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/IO/OBM/ObmNeedFetch.agda",
"max_line_length": 111,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/IO/OBM/ObmNeedFetch.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-18T19:24:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-16T19:43:41.000Z",
"num_tokens": 274,
"size": 1150
} |
{- PROOF OF BOUNDING THEOREM -}
open import Preliminaries
open import Source
open import Complexity
open import Translation
open import Bounding-Lemmas
module Bounding where
boundingRec : ∀ {τ} (v : [] Source.|- nat) (val-v : val v)
(e0 : [] Source.|- τ)
(e1 : (nat :: susp τ :: []) Source.|- τ)
(E : [] Complexity.|- nat)
(E0 : [] Complexity.|- || τ ||)
(E1 : (nat :: || τ || :: []) Complexity.|- || τ ||)
→ valBound v val-v E → expBound e0 E0
→ ((v' : [] Source.|- nat) (val-v' : val v') (E' : [] Complexity.|- nat) → valBound v' val-v' E'
→ (r : [] Source.|- susp τ) (val-r : val r) (R : [] Complexity.|- || τ ||) → valBound r val-r R
→ expBound (Source.subst e1 (Source.lem4 v' r)) (Complexity.subst E1 (Complexity.lem4 E' R)))
→ ((vbranch : [] Source.|- τ) (val-vbranch : val vbranch) (nbranch : Cost)
→ evals-rec-branch e0 e1 v vbranch nbranch
→ (plusC 1C (interp-Cost nbranch) ≤s l-proj (rec E (1C +C E0) (1C +C E1))
× (valBound vbranch val-vbranch (r-proj (rec E (1C +C E0) (1C +C E1))))))
boundingRec .z z-isval e0 e1 E E0 E1 vbound e0bound e1bound vbranch val-vbranch nbranch (evals-rec-z evals-branch) =
(cong-+ refl-s (fst usee0bound ) trans l-proj-s) trans cong-lproj (rec-steps-z trans cong-rec vbound) ,
weakeningVal' val-vbranch (snd usee0bound) (r-proj-s trans cong-rproj (rec-steps-z trans (cong-rec (vbound))))
where usee0bound = (e0bound vbranch val-vbranch nbranch evals-branch)
boundingRec .(suc v') (suc-isval v' val-v') e0 e1 E E0 E1 (E' , v'bound , sucE'≤E) e0bound e1bound vbranch val-vbranch nbranch (evals-rec-s evals-branch) =
(cong-+ refl-s (fst usee1bound) trans l-proj-s) trans cong-lproj (rec-steps-s trans cong-rec sucE'≤E) ,
weakeningVal' val-vbranch (snd usee1bound) (r-proj-s trans cong-rproj (rec-steps-s trans cong-rec sucE'≤E)) where
IH = boundingRec v' val-v' e0 e1 E' E0 E1 v'bound e0bound e1bound
usee1bound = e1bound v' val-v' E' v'bound
(delay (rec v' e0 e1)) (delay-isval _) (rec E' (1C +C E0) (1C +C E1) )
(λ { vr vvr ._ (rec-evals{n1 = n1} {n2 = n2} D D') →
let useIH = IH vr vvr n2 (transport (λ H → evals-rec-branch e0 e1 H vr n2) (! (fst (val-evals-inversion val-v' D))) D')
in (cong-+ (Eq0C-≤0 (snd (val-evals-inversion val-v' D))) refl-s trans +-unit-l) trans fst useIH , snd useIH } )
vbranch val-vbranch nbranch evals-branch
boundingListRec : ∀ {τ τ'} (v : [] Source.|- list τ') (vv : val v)
(e0 : [] Source.|- τ)
(e1 : τ' :: list τ' :: susp τ :: [] Source.|- τ)
(E : [] Complexity.|- list ⟨⟨ τ' ⟩⟩)
(E0 : [] Complexity.|- || τ ||)
(E1 : ⟨⟨ τ' ⟩⟩ :: list ⟨⟨ τ' ⟩⟩ :: || τ || :: [] Complexity.|- || τ ||)
→ valBound v vv E → expBound e0 E0
→ ((h' : [] Source.|- τ') (vh' : val h') (H' : [] Complexity.|- ⟨⟨ τ' ⟩⟩)
→ valBound h' vh' H'
→ (v' : [] Source.|- list τ') (vv' : val v') (V' : [] Complexity.|- list ⟨⟨ τ' ⟩⟩)
→ valBound v' vv' V'
→ (r : [] Source.|- susp τ) (vr : val r) (R : [] Complexity.|- || τ ||)
→ valBound r vr R
→ expBound (Source.subst e1 (Source.lem5 h' v' r)) (Complexity.subst E1 (Complexity.lem5 H' V' R)))
→ (vbranch : [] Source.|- τ) (vvbranch : val vbranch) (nbranch : Cost)
→ evals-listrec-branch e0 e1 v vbranch nbranch
→ plusC 1C (interp-Cost nbranch) ≤s l-proj (listrec E (1C +C E0) (1C +C E1))
× valBound vbranch vvbranch (r-proj (listrec E (1C +C E0) (1C +C E1)))
boundingListRec .nil nil-isval e0 e1 E E0 E1 vbv e0b e1b vbranch vvbranch n (evals-listrec-nil evals-branch) =
((cong-+ refl-s (fst usee0bound) trans l-proj-s) trans cong-lproj (listrec-steps-nil trans cong-listrec vbv)) ,
weakeningVal' vvbranch (snd usee0bound) (r-proj-s trans cong-rproj (listrec-steps-nil trans cong-listrec vbv))
where usee0bound = e0b vbranch vvbranch n evals-branch
boundingListRec .(x ::s xs) (cons-isval x xs vv vv₁) e0 e1 E E0 E1 (h' , t' , (vbxh' , vbxst') , h'::t'≤sE)
e0b e1b vbranch vvbranch nbranch (evals-listrec-cons evals-branch) =
(cong-+ refl-s (fst usee1bound) trans l-proj-s) trans cong-lproj (listrec-steps-cons trans cong-listrec h'::t'≤sE) ,
weakeningVal' vvbranch (snd usee1bound) (r-proj-s trans cong-rproj (listrec-steps-cons trans cong-listrec h'::t'≤sE))
where
IH = boundingListRec xs vv₁ e0 e1 t' E0 E1 vbxst' e0b e1b
usee1bound = e1b x vv h' vbxh' xs vv₁ t' vbxst'
(delay (listrec xs e0 e1)) (delay-isval _) (listrec t' (1C +C E0) (1C +C E1))
(λ { vr vvr ._ (listrec-evals {_} {n2} D D') →
let useIH = IH vr vvr n2 (transport (λ H → evals-listrec-branch e0 e1 H vr n2) (! (fst (val-evals-inversion vv₁ D))) D')
in (cong-+ (Eq0C-≤0 (snd (val-evals-inversion vv₁ D))) refl-s trans +-unit-l) trans fst useIH , snd useIH } )
vbranch vvbranch nbranch evals-branch
bounding : ∀{Γ τ} → (e : Γ Source.|- τ) → (Θ : Source.sctx [] Γ)
→ (a : substVal Θ)
→ (Θ' : Complexity.sctx [] ⟨⟨ Γ ⟩⟩c)
→ substBound Θ a Θ'
→ expBound (Source.subst e Θ) (Complexity.subst || e ||e Θ')
bounding unit Θ a Θ' sb unit unit-isval 0c unit-evals = l-proj-s , <>
bounding (var x) Θ a Θ' sb v vv c evals =
inv1 (a x) evals trans l-proj-s ,
weakeningVal' vv (transport-valBound (inv2 (a x) evals) (val-hprop (transport val (inv2 (a x) evals) (a x)) vv) _ (sb x)) r-proj-s
bounding z Θ a Θ' sb .z z-isval .0c z-evals = l-proj-s , r-proj-s
bounding (suc e) Θ a Θ' sb .(suc e₁) (suc-isval e₁ vv) n (s-evals evals) =
fst IH trans l-proj-s ,
(r-proj (Complexity.subst || e ||e Θ')) , (snd IH) , r-proj-s
where
IH = (bounding e Θ a Θ' sb _ vv _ evals)
bounding (rec e e₁ e₂) Θ a Θ' sb e' val-e' ._ (rec-evals {v = v} arg-evals branch-evals) =
cong-+ (fst IH1) (fst lemma) trans l-proj-s , weakeningVal' val-e' (snd lemma) r-proj-s
where
IH1 = bounding e Θ a Θ' sb _ (evals-val arg-evals) _ arg-evals
lemma = boundingRec v (evals-val arg-evals) _
(Source.subst e₂ (Source.s-extend (Source.s-extend Θ))) _ _ (Complexity.subst || e₂ ||e (Complexity.s-extend (Complexity.s-extend Θ')))
(snd IH1)
(bounding e₁ Θ a Θ' sb )
(λ v' valv' E' valBoundv' r valr R valBoundR v'' valv'' c'' evals-rec →
let IH3 = (bounding e₂ (Source.lem4' Θ v' r) (extend-substVal2 a valv' valr) (Complexity.lem4' Θ' E' R)
(extend-substBound2 sb valBoundv' valBoundR) v'' valv'' c'' (transport (λ x → evals x v'' c'')
(Source.subst-compose4 Θ v' r e₂) evals-rec))
in (fst IH3 trans cong-refl (ap l-proj (! (Complexity.subst-compose4 Θ' E' R || e₂ ||e))) ,
weakeningVal' valv'' (snd IH3) (cong-rproj (cong-refl (! (Complexity.subst-compose4 Θ' E' R || e₂ ||e))))))
e' val-e' _ branch-evals
bounding {τ = ρ ->s τ} (lam e) Θ a Θ' sb .(lam (Source.subst e (Source.s-extend Θ))) (lam-isval .(Source.subst e (Source.s-extend Θ))) .0c lam-evals =
l-proj-s ,
(λ v₁ vv₁ E1 valbound1 v vv n body-evals →
let IH = bounding e (Source.lem3' Θ v₁) (extend-substVal a vv₁)
(Complexity.lem3' Θ' E1) (extend-substBound sb valbound1)
v vv n (transport (λ x → evals x v n) (Source.subst-compose Θ v₁ e) body-evals)
in
fst IH trans cong-lproj (cong-refl (! (Complexity.subst-compose Θ' E1 || e ||e)) trans lam-s trans cong-app r-proj-s) ,
weakeningVal' vv (snd IH) (cong-rproj (cong-refl (! (Complexity.subst-compose Θ' E1 || e ||e)) trans lam-s trans cong-app r-proj-s)))
bounding (app e1 e2) Θ a Θ' sb v val-v .((n0 +c n1) +c n)
(app-evals {n0} {n1} {n} {τ2} {τ} {.(Source.subst e1 Θ)} {e1'} {.(Source.subst e2 Θ)} {v2} e1-evals e2-evals subst-evals) =
cong-+ (cong-+ (fst IH1) (fst IH2)) (fst IH1a) trans l-proj-s ,
weakeningVal' val-v (snd IH1a) r-proj-s
where
IH1 = (bounding e1 Θ a Θ' sb (lam e1') (lam-isval e1') n0 e1-evals)
v2-val = evals-val e2-evals
IH2 = (bounding e2 Θ a Θ' sb v2 v2-val n1 e2-evals)
IH1a = snd IH1 v2 v2-val (r-proj (Complexity.subst || e2 ||e Θ')) (snd IH2) v val-v n subst-evals
bounding {Γ} {τ1 ×s τ2} (prod e1 e2) Θ a Θ' sb .(prod e3 e4) (pair-isval e3 e4 val-e3 val-e4) .(n1 +c n2) (pair-evals {n1} {n2} evals-c1 evals-c2) =
cong-+ (fst IH1) (fst IH2) trans l-proj-s ,
weakeningVal' val-e3 (snd IH1) (l-proj-s trans cong-lproj r-proj-s) ,
weakeningVal' val-e4 (snd IH2) (r-proj-s trans cong-rproj r-proj-s)
where
IH1 = (bounding e1 Θ a Θ' sb _ val-e3 _ evals-c1)
IH2 = (bounding e2 Θ a Θ' sb _ val-e4 _ evals-c2)
bounding (delay e) Θ a Θ' sb .(delay (Source.subst e Θ)) (delay-isval .(Source.subst e Θ)) .0c delay-evals =
l-proj-s ,
(λ v₁ vv n x →
let IH = bounding e Θ a Θ' sb v₁ vv n x in
fst IH trans cong-lproj (r-proj-s trans refl-s) ,
weakeningVal' vv (snd IH) (cong-rproj r-proj-s))
bounding (force e) Θ a Θ' sb v vv ._ (force-evals {n1} {n2} {τ} {e'} {.v} {.(Source.subst e Θ)} evals evals₁) =
(cong-+ (fst IH) (fst (snd IH v vv n2 evals₁)) trans l-proj-s) ,
weakeningVal' vv (snd (snd IH v vv n2 evals₁)) r-proj-s
where
IH = (bounding e Θ a Θ' sb _ (delay-isval e') n1 evals)
bounding {Γ} {τ} (split e0 e1) Θ a Θ' sb e' val-e' .(n1 +c n2) (split-evals {n1} {n2} {.τ} {τ1} {τ2} {.(Source.subst e0 Θ)} {v1} {v2} evals-in-c0 evals-in-c1) with evals-val evals-in-c0 | (bounding e0 Θ a Θ' sb (prod v1 v2) (evals-val evals-in-c0) _ evals-in-c0)
... | pair-isval ._ ._ val-v1 val-v2 | (IH11 , vb1 , vb2)
= cong-+ IH11 (fst IH2) trans
cong-+ refl-s (cong-lproj (cong-refl (! (Complexity.subst-compose3 Θ' || e1 ||e (l-proj (r-proj || e0 ||e)) (r-proj (r-proj || e0 ||e)))))) trans l-proj-s ,
weakeningVal' val-e' (snd IH2)
(cong-rproj (cong-refl
(! (Complexity.subst-compose3 Θ' || e1 ||e (l-proj (r-proj || e0 ||e)) (r-proj (r-proj || e0 ||e))))) trans r-proj-s) where
IH2 = bounding e1 (Source.lem4' Θ v1 v2)
(extend-substVal2 a val-v1 val-v2)
(Complexity.lem4' Θ' (l-proj (r-proj (Complexity.subst || e0 ||e Θ'))) (r-proj (r-proj (Complexity.subst || e0 ||e Θ'))))
(extend-substBound2 sb vb1 vb2)
e' val-e' n2 (transport (λ x → evals x e' n2) (Source.subst-compose3 Θ e1 v1 v2) evals-in-c1)
bounding nil Θ a Θ' sb .nil nil-isval .0c nil-evals = l-proj-s , r-proj-s
bounding (e ::s e₁) Θ a Θ' sb .(x ::s xs) (cons-isval x xs vv vv₁) ._ (cons-evals evals evals₁) =
(cong-+ (fst IH1) (fst IH2) trans l-proj-s) ,
(r-proj (Complexity.subst || e ||e Θ')) , r-proj (Complexity.subst || e₁ ||e Θ') , ((snd IH1 , snd IH2) , r-proj-s)
where
IH1 = (bounding e Θ a Θ' sb _ vv _ evals)
IH2 = (bounding e₁ Θ a Θ' sb _ vv₁ _ evals₁)
bounding (listrec e e₁ e₂) Θ a Θ' sb v vv ._ (listrec-evals {v = k} arg-evals branch-evals) =
(cong-+ (fst IH1) (fst lemma) trans l-proj-s) , weakeningVal' vv (snd lemma) r-proj-s
where
IH1 = bounding e Θ a Θ' sb _ (evals-val arg-evals) _ arg-evals
lemma = boundingListRec k (evals-val arg-evals) _
(Source.subst e₂ (Source.s-extend (Source.s-extend (Source.s-extend Θ)))) _ _
(Complexity.subst || e₂ ||e (Complexity.s-extend (Complexity.s-extend (Complexity.s-extend Θ'))))
(snd IH1)
(bounding e₁ Θ a Θ' sb)
(λ h' vh' H' vbh'H' v' vv' V' vbv'V' r vr R vbrR v₁ vv₁ n x₂ →
let IH3 = bounding e₂ (Source.lem5' Θ h' v' r) (extend-substVal3 a vh' vv' vr) (Complexity.lem5' Θ' H' V' R)
(extend-substBound3 sb vbh'H' vbv'V' vbrR) v₁ vv₁ n
(transport (λ x → evals x v₁ n) (Source.subst-compose5 Θ e₂ h' v' r) x₂)
in
fst IH3 trans cong-refl (ap l-proj (! (Complexity.subst-compose5 Θ' || e₂ ||e H' V' R))) ,
weakeningVal' vv₁ (snd IH3) (cong-rproj (cong-refl (! (Complexity.subst-compose5 Θ' || e₂ ||e H' V' R)))))
v vv _ branch-evals
bounding true Θ a Θ' sb .true true-isval .0c true-evals = l-proj-s , r-proj-s
bounding false Θ a Θ' sb .false false-isval .0c false-evals = l-proj-s , r-proj-s
| {
"alphanum_fraction": 0.5399984863,
"avg_line_length": 73.8156424581,
"ext": "agda",
"hexsha": "2f459349f165c31bc28425cb1a8661090ae603fd",
"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": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity/Bounding.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity/Bounding.agda",
"max_line_length": 264,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity/Bounding.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 4770,
"size": 13213
} |
------------------------------------------------------------------------------
-- Properties related with lists of natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Nat.List.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Nat.List
open import FOTC.Data.List
------------------------------------------------------------------------------
++-ListN : ∀ {ms ns} → ListN ms → ListN ns → ListN (ms ++ ns)
++-ListN {ns = ns} lnnil nsL = prf
where postulate prf : ListN ([] ++ ns)
{-# ATP prove prf #-}
++-ListN {ns = ns} (lncons {m} {ms} Nd LNms) LNns = prf (++-ListN LNms LNns)
where postulate prf : ListN (ms ++ ns) → ListN ((m ∷ ms) ++ ns)
{-# ATP prove prf #-}
| {
"alphanum_fraction": 0.4432882414,
"avg_line_length": 35.5925925926,
"ext": "agda",
"hexsha": "d0b329fcabecd17bc34ba8716e8d5d687d1c2dbd",
"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/List/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Nat/List/PropertiesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/Nat/List/PropertiesATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 228,
"size": 961
} |
module Issue847 where
data ⊥ : Set where
bad : ⊥
bad = bad′
where
abstract
bad′ : ⊥
bad′ = bad
| {
"alphanum_fraction": 0.5688073394,
"avg_line_length": 9.9090909091,
"ext": "agda",
"hexsha": "e872b1983773cbcf3fba9089a78318ead12468fd",
"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/Issue847.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/Issue847.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue847.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": 109
} |
open import Logic.Classical
open import Structure.Real
module Structure.Real.Abs {ℓ₁ ℓ₂ ℓₑ} {R} ⦃ R-equiv ⦄ (_+_) (_⋅_) (_≤_) ⦃ classical : ∀{ℓ}{P} → Classical{ℓ}(P) ⦄ ⦃ reals : RealTheory{ℓ₁}{ℓₑ}{ℓ₂} {R} ⦃ R-equiv ⦄ (_+_)(_⋅_)(_≤_) ⦄ where
open RealTheory(reals)
open import Data.Boolean
import Lvl
open import Functional
open import Logic
open import Logic.Classical
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Setoid
open import Structure.Operator.Field
open import Structure.Operator.Monoid
open import Structure.Operator.Group
open import Structure.Relator.Ordering
open Structure.Relator.Ordering.Weak.Properties
open import Structure.Relator.Properties
open import Syntax.Type
open import Type
-- TODO: This file is probably redundant. Move this to Structure.Operator.OrderedField.Abs
-- TODO: Prove somewhere that: (P → ([∨]-elim x y (_ :of: (P ∨ Q)) ≡ x)) ∧ (Q → ([∨]-elim x y (_ :of: (P ∨ Q)) ≡ y)) because this is neccessary when proving the properties of abs
-- abs : R → R
-- abs(x) = if(decide{P = x ≤ 𝟎}) then (− x) else x
| {
"alphanum_fraction": 0.7129798903,
"avg_line_length": 35.2903225806,
"ext": "agda",
"hexsha": "c914ec586866538c534247ea7bbf586cb48d9649",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Real/Abs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Real/Abs.agda",
"max_line_length": 185,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Real/Abs.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": 346,
"size": 1094
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Object.Zero
module Categories.Object.Kernel.Properties {o ℓ e} {𝒞 : Category o ℓ e} (𝒞-Zero : Zero 𝒞) where
open import Function using (_$_)
open import Categories.Diagram.Equalizer 𝒞
open import Categories.Diagram.Pullback 𝒞 renaming (glue to glue-pullback; up-to-iso to pullback-up-to-iso)
open import Categories.Diagram.Pullback.Properties 𝒞
open import Categories.Object.Kernel 𝒞-Zero
open import Categories.Object.Terminal 𝒞
open import Categories.Morphism 𝒞
open import Categories.Morphism.Reasoning 𝒞
open Category 𝒞
open HomReasoning
open Equiv
open Zero 𝒞-Zero
private
variable
A B : Obj
f : A ⇒ B
-- We can express kernels as pullbacks along the morphism '! : ⊥ ⇒ A'.
Kernel⇒Pullback : Kernel f → Pullback f !
Kernel⇒Pullback {f = f} kernel = record
{ p₁ = kernel⇒
; p₂ = ¡
; isPullback = record
{ commute = commute
; universal = λ {C} {h₁} {h₂} eq → universal {h = h₁} $ begin
f ∘ h₁ ≈⟨ eq ⟩
! ∘ h₂ ≈˘⟨ refl⟩∘⟨ ¡-unique h₂ ⟩
zero⇒ ∎
; unique = λ {C} {h₁} {h₂} {i} k-eq h-eq → unique $ begin
h₁ ≈˘⟨ k-eq ⟩
kernel⇒ ∘ i ∎
; p₁∘universal≈h₁ = ⟺ factors
; p₂∘universal≈h₂ = ¡-unique₂ _ _
}
}
where
open Kernel kernel
-- All pullbacks along the morphism '! : ⊥ ⇒ A' are also kernels.
Pullback⇒Kernel : Pullback f ! → Kernel f
Pullback⇒Kernel {f = f} pullback = record
{ kernel⇒ = p₁
; isKernel = record
{ commute = begin
f ∘ p₁ ≈⟨ commute ⟩
! ∘ p₂ ≈˘⟨ refl⟩∘⟨ ¡-unique p₂ ⟩
zero⇒ ∎
; universal = λ eq → universal eq
; factors = ⟺ p₁∘universal≈h₁
; unique = λ eq → unique (⟺ eq) (⟺ (¡-unique _))
}
}
where
open Pullback pullback
-- We can also express kernels as the equalizer of 'f' and the zero morphism.
Kernel⇒Equalizer : Kernel f → Equalizer f zero⇒
Kernel⇒Equalizer {f = f} kernel = record
{ arr = kernel⇒
; isEqualizer = record
{ equality = begin
f ∘ kernel⇒ ≈⟨ commute ⟩
zero⇒ ≈⟨ pushʳ (¡-unique (¡ ∘ kernel⇒)) ⟩
zero⇒ ∘ kernel⇒ ∎
; equalize = λ {_} {h} eq → universal (eq ○ pullʳ (⟺ (¡-unique (¡ ∘ h))))
; universal = factors
; unique = unique
}
}
where
open Kernel kernel
-- Furthermore, all equalizers of 'f' and the zero morphism are equalizers
Equalizer⇒Kernel : Equalizer f zero⇒ → Kernel f
Equalizer⇒Kernel {f = f} equalizer = record
{ kernel⇒ = arr
; isKernel = record
{ commute = begin
f ∘ arr ≈⟨ equality ⟩
zero⇒ ∘ arr ≈⟨ pullʳ (⟺ (¡-unique (¡ ∘ arr))) ⟩
zero⇒ ∎
; universal = λ {_} {h} eq → equalize (eq ○ pushʳ (¡-unique (¡ ∘ h)))
; factors = universal
; unique = unique
}
}
where
open Equalizer equalizer
module _ (K : Kernel f) where
open Kernel K
Kernel-Mono : Mono kernel⇒
Kernel-Mono g₁ g₂ eq = begin
g₁ ≈⟨ unique refl ⟩
universal universal-∘ ≈˘⟨ unique eq ⟩
g₂ ∎
module _ (has-kernels : ∀ {A B} → (f : A ⇒ B) → Kernel f) where
-- The kernel of a kernel is isomorphic to the zero object.
kernel²-zero : ∀ {A B} {f : A ⇒ B} → Kernel.kernel (has-kernels (Kernel.kernel⇒ (has-kernels f))) ≅ zero
kernel²-zero {B = B} {f = f} = pullback-up-to-iso kernel-pullback (pullback-mono-mono !-Mono)
where
K : Kernel f
K = has-kernels f
module K = Kernel K
K′ : Kernel K.kernel⇒
K′ = has-kernels K.kernel⇒
kernel-pullback : Pullback ! !
kernel-pullback = Pullback-resp-≈ (glue-pullback (Kernel⇒Pullback K) (swap (Kernel⇒Pullback K′))) (!-unique (f ∘ !)) refl
pullback-mono-mono : ∀ {A B} {f : A ⇒ B} → Mono f → Pullback f f
pullback-mono-mono mono = record
{ p₁ = id
; p₂ = id
; isPullback = pullback-self-mono mono
}
| {
"alphanum_fraction": 0.6038978141,
"avg_line_length": 28.3358208955,
"ext": "agda",
"hexsha": "9873cce57c5714074f80f8c1d5599287e272ebb5",
"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": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FintanH/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Kernel/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"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": "FintanH/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Kernel/Properties.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3ef03f73bce18f1efba2890df9ddf3d76ed2de32",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FintanH/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Kernel/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1387,
"size": 3797
} |
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Non-canonical model equipment for Kripke-style semantics.
module BasicIS4.Equipment.KripkeDyadicNonCanonical where
open import BasicIS4.Syntax.Common public
module Syntax
(_⊢_ : Cx² Ty Ty → Ty → Set)
(mono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A)
(up : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ (□ □ A))
(down : ∀ {A Π} → Π ⊢ (□ A) → Π ⊢ A)
(lift : ∀ {A Γ Δ} → (Γ ⁏ Δ) ⊢ A → (□⋆ Γ ⁏ Δ) ⊢ (□ A))
where
-- Worlds.
Worldᶜ : Set
Worldᶜ = Cx² Ty Ty
-- Intuitionistic accessibility.
infix 3 _≤ᶜ_
_≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_≤ᶜ_ = _⊆²_
refl≤ᶜ : ∀ {w} → w ≤ᶜ w
refl≤ᶜ = refl⊆²
trans≤ᶜ : ∀ {w w′ w″} → w ≤ᶜ w′ → w′ ≤ᶜ w″ → w ≤ᶜ w″
trans≤ᶜ = trans⊆²
bot≤ᶜ : ∀ {w} → ∅² ≤ᶜ w
bot≤ᶜ = bot⊆²
-- Not the canonical modal accessibility, based on the 4 axiom.
infix 3 _Яᶜ_
_Яᶜ_ : Worldᶜ → Worldᶜ → Set
w Яᶜ w′ = ∀ {A} → w ⊢ (□ A) → w′ ⊢ (□ □ A)
reflЯᶜ : ∀ {w} → w Яᶜ w
reflЯᶜ = up
transЯᶜ : ∀ {w w′ w″} → w Яᶜ w′ → w′ Яᶜ w″ → w Яᶜ w″
transЯᶜ ζ ζ′ = down ∘ ζ′ ∘ ζ
botЯᶜ : ∀ {w} → ∅² Яᶜ w
botЯᶜ = mono²⊢ bot≤ᶜ ∘ up
liftЯᶜ : ∀ {Γ Δ} → Γ ⁏ Δ Яᶜ □⋆ Γ ⁏ Δ
liftЯᶜ = down ∘ lift ∘ up
-- Composition of accessibility.
infix 3 _≤⨾Яᶜ_
_≤⨾Яᶜ_ : Worldᶜ → Worldᶜ → Set
_≤⨾Яᶜ_ = _≤ᶜ_ ⨾ _Яᶜ_
infix 3 _Я⨾≤ᶜ_
_Я⨾≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_Я⨾≤ᶜ_ = _Яᶜ_ ⨾ _≤ᶜ_
refl≤⨾Яᶜ : ∀ {w} → w ≤⨾Яᶜ w
refl≤⨾Яᶜ {w} = w , (refl≤ᶜ , reflЯᶜ)
reflЯ⨾≤ᶜ : ∀ {w} → w Я⨾≤ᶜ w
reflЯ⨾≤ᶜ {w} = w , (reflЯᶜ , refl≤ᶜ)
-- Persistence condition, after Iemhoff; included by Ono.
--
-- w′ v′ → v′
-- ◌───Я───● → ●
-- │ → ╱
-- ≤ ξ,ζ → Я
-- │ → ╱
-- ● → ●
-- w → w
≤⨾Я→Яᶜ : ∀ {v′ w} → w ≤⨾Яᶜ v′ → w Яᶜ v′
≤⨾Я→Яᶜ (w′ , (ξ , ζ)) = ζ ∘ mono²⊢ ξ
-- Brilliance condition, after Iemhoff.
--
-- v′ → v′
-- ● → ●
-- │ → ╱
-- ζ,ξ ≤ → Я
-- │ → ╱
-- ●───Я───◌ → ●
-- w v → w
Я⨾≤→Яᶜ : ∀ {w v′} → w Я⨾≤ᶜ v′ → w Яᶜ v′
Я⨾≤→Яᶜ (v , (ζ , ξ)) = mono²⊢ ξ ∘ ζ
-- Minor persistence condition, included by Božić and Došen.
--
-- w′ v′ → v′
-- ◌───Я───● → ●
-- │ → │
-- ≤ ξ,ζ → ≤
-- │ → │
-- ● → ●───Я───◌
-- w → w v
--
-- w″ → w″
-- ● → ●
-- │ → │
-- ξ′,ζ′ ≤ → │
-- │ → │
-- ●───R───◌ → ≤
-- │ v′ → │
-- ξ,ζ ≤ → │
-- │ → │
-- ●───R───◌ → ●───────R───────◌
-- w v → w v″
≤⨾Я→Я⨾≤ᶜ : ∀ {v′ w} → w ≤⨾Яᶜ v′ → w Я⨾≤ᶜ v′
≤⨾Я→Я⨾≤ᶜ {v′} ξ,ζ = v′ , (≤⨾Я→Яᶜ ξ,ζ , refl≤ᶜ)
transЯ⨾≤ᶜ : ∀ {w′ w w″} → w Я⨾≤ᶜ w′ → w′ Я⨾≤ᶜ w″ → w Я⨾≤ᶜ w″
transЯ⨾≤ᶜ {w′} (v , (ζ , ξ)) (v′ , (ζ′ , ξ′)) = let v″ , (ζ″ , ξ″) = ≤⨾Я→Я⨾≤ᶜ (w′ , (ξ , ζ′))
in v″ , (transЯᶜ ζ ζ″ , trans≤ᶜ ξ″ ξ′)
≤→Яᶜ : ∀ {v′ w} → w ≤ᶜ v′ → w Яᶜ v′
≤→Яᶜ {v′} ξ = ≤⨾Я→Яᶜ (v′ , (ξ , reflЯᶜ))
-- Minor brilliance condition, included by Ewald and Alechina et al.
--
-- v′ → w′ v′
-- ● → ◌───Я───●
-- │ → │
-- ζ,ξ ≤ → ≤
-- │ → │
-- ●───Я───◌ → ●
-- w v → w
--
-- v′ w″ → v″ w″
-- ◌───R───● → ◌───────R───────●
-- │ → │
-- ≤ ξ′,ζ′ → │
-- v │ → │
-- ◌───R───● → ≤
-- │ w′ → │
-- ≤ ξ,ζ → │
-- │ → │
-- ● → ●
-- w → w
Я⨾≤→≤⨾Яᶜ : ∀ {w v′} → w Я⨾≤ᶜ v′ → w ≤⨾Яᶜ v′
Я⨾≤→≤⨾Яᶜ {w} ζ,ξ = w , (refl≤ᶜ , Я⨾≤→Яᶜ ζ,ξ)
trans≤⨾Яᶜ : ∀ {w′ w w″} → w ≤⨾Яᶜ w′ → w′ ≤⨾Яᶜ w″ → w ≤⨾Яᶜ w″
trans≤⨾Яᶜ {w′} (v , (ξ , ζ)) (v′ , (ξ′ , ζ′)) = let v″ , (ξ″ , ζ″) = Я⨾≤→≤⨾Яᶜ (w′ , (ζ , ξ′))
in v″ , (trans≤ᶜ ξ ξ″ , transЯᶜ ζ″ ζ′)
≤→Яᶜ′ : ∀ {w v′} → w ≤ᶜ v′ → w Яᶜ v′
≤→Яᶜ′ {w} ξ = Я⨾≤→Яᶜ (w , (reflЯᶜ , ξ))
-- Infimum (greatest lower bound) of accessibility.
--
-- w′
-- ●
-- │
-- ≤ ξ,ζ
-- │
-- ◌───R───●
-- w v
infix 3 _≤⊓Яᶜ_
_≤⊓Яᶜ_ : Worldᶜ → Worldᶜ → Set
_≤⊓Яᶜ_ = _≤ᶜ_ ⊓ _Яᶜ_
infix 3 _Я⊓≤ᶜ_
_Я⊓≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_Я⊓≤ᶜ_ = _Яᶜ_ ⊓ _≤ᶜ_
≤⊓Я→Я⊓≤ᶜ : ∀ {w′ v} → w′ ≤⊓Яᶜ v → v Я⊓≤ᶜ w′
≤⊓Я→Я⊓≤ᶜ (w , (ξ , ζ)) = w , (ζ , ξ)
Я⊓≤→≤⊓Яᶜ : ∀ {w′ v} → v Я⊓≤ᶜ w′ → w′ ≤⊓Яᶜ v
Я⊓≤→≤⊓Яᶜ (w , (ζ , ξ)) = w , (ξ , ζ)
-- Supremum (least upper bound) of accessibility.
--
-- w′ v′
-- ●───R───◌
-- │
-- ξ,ζ ≤
-- │
-- ●
-- v
infix 3 _≤⊔Яᶜ_
_≤⊔Яᶜ_ : Worldᶜ → Worldᶜ → Set
_≤⊔Яᶜ_ = _≤ᶜ_ ⊔ _Яᶜ_
infix 3 _Я⊔≤ᶜ_
_Я⊔≤ᶜ_ : Worldᶜ → Worldᶜ → Set
_Я⊔≤ᶜ_ = _Яᶜ_ ⊔ _≤ᶜ_
≤⊔Я→Я⊔≤ᶜ : ∀ {w′ v} → w′ ≤⊔Яᶜ v → v Я⊔≤ᶜ w′
≤⊔Я→Я⊔≤ᶜ (v′ , (ξ , ζ)) = v′ , (ζ , ξ)
Я⊔≤→≤⊔Яᶜ : ∀ {w′ v} → v Я⊔≤ᶜ w′ → w′ ≤⊔Яᶜ v
Я⊔≤→≤⊔Яᶜ (v′ , (ζ , ξ)) = v′ , (ξ , ζ)
-- Infimum-to-supremum condition, included by Ewald.
--
-- w′ → w′ v′
-- ● → ●───Я───◌
-- │ → │
-- ≤ ξ,ζ → ≤
-- │ → │
-- ◌───Я───● → ●
-- w v → v
-- NOTE: This could be more precise.
≤⊓Я→≤⊔Яᶜ : ∀ {v w′} → w′ ≤⊓Яᶜ v → v ≤⊔Яᶜ w′
≤⊓Я→≤⊔Яᶜ {v} {w′} (w , (ξ , ζ)) =
(w′ ⧺² v) , (weak⊆²⧺₂ , mono²⊢ (weak⊆²⧺₁ v) ∘ up)
-- Supremum-to-infimum condition.
--
-- w′ v′ → w′
-- ●───Я───◌ → ●
-- │ → │
-- ξ,ζ ≤ → ≤
-- │ → │
-- ● → ◌───Я───●
-- v → w v
-- NOTE: This could be more precise.
≤⊔Я→≤⊓Яᶜ : ∀ {w′ v} → v ≤⊔Яᶜ w′ → w′ ≤⊓Яᶜ v
≤⊔Я→≤⊓Яᶜ (v′ , (ξ , ζ)) = ∅² , (bot≤ᶜ , botЯᶜ)
| {
"alphanum_fraction": 0.2912182187,
"avg_line_length": 25.5418326693,
"ext": "agda",
"hexsha": "678865a48df5f008bd1c2447150944b73d207691",
"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": "BasicIS4/Equipment/KripkeDyadicNonCanonical.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": "BasicIS4/Equipment/KripkeDyadicNonCanonical.agda",
"max_line_length": 95,
"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": "BasicIS4/Equipment/KripkeDyadicNonCanonical.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": 3738,
"size": 6411
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
{-
Helper routines most often used in reasoning with commutative squares,
at the level of arrows in categories.
Basic : reasoning about identity
Pulls : use a ∘ b ≈ c as left-to-right rewrite
Pushes : use c ≈ a ∘ b as a left-to-right rewrite
IntroElim : introduce/eliminate an equivalent-to-id arrow
Extend : 'extends' a commutative square with an equality on left/right/both
-}
module Categories.Morphism.Reasoning.Core {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Function renaming (id to idᶠ; _∘_ to _∙_)
open import Relation.Binary hiding (_⇒_)
open Category C
private
variable
X Y : Obj
a a′ a″ b b′ b″ c c′ c″ : X ⇒ Y
f g h i : X ⇒ Y
open HomReasoning
module Basic where
id-unique : ∀ {o} {f : o ⇒ o} → (∀ g → g ∘ f ≈ g) → f ≈ id
id-unique g∘f≈g = trans (sym identityˡ) (g∘f≈g id)
id-comm : ∀ {a b} {f : a ⇒ b} → f ∘ id ≈ id ∘ f
id-comm = trans identityʳ (sym identityˡ)
id-comm-sym : ∀ {a b} {f : a ⇒ b} → id ∘ f ≈ f ∘ id
id-comm-sym = trans identityˡ (sym identityʳ)
open Basic public
module Utils where
assoc² : ((i ∘ h) ∘ g) ∘ f ≈ i ∘ (h ∘ (g ∘ f))
assoc² = trans assoc assoc
assoc²' : (i ∘ (h ∘ g)) ∘ f ≈ i ∘ (h ∘ (g ∘ f))
assoc²' = trans assoc (∘-resp-≈ʳ assoc)
open Utils public
module Pulls (ab≡c : a ∘ b ≈ c) where
pullʳ : (f ∘ a) ∘ b ≈ f ∘ c
pullʳ {f = f} = begin
(f ∘ a) ∘ b ≈⟨ assoc ⟩
f ∘ (a ∘ b) ≈⟨ refl⟩∘⟨ ab≡c ⟩
f ∘ c ∎
pullˡ : a ∘ b ∘ f ≈ c ∘ f
pullˡ {f = f} = begin
a ∘ b ∘ f ≈⟨ sym assoc ⟩
(a ∘ b) ∘ f ≈⟨ ab≡c ⟩∘⟨refl ⟩
c ∘ f ∎
open Pulls public
module Pushes (c≡ab : c ≈ a ∘ b) where
pushʳ : f ∘ c ≈ (f ∘ a) ∘ b
pushʳ {f = f} = begin
f ∘ c ≈⟨ refl⟩∘⟨ c≡ab ⟩
f ∘ (a ∘ b) ≈˘⟨ assoc ⟩
(f ∘ a) ∘ b ∎
pushˡ : c ∘ f ≈ a ∘ (b ∘ f)
pushˡ {f = f} = begin
c ∘ f ≈⟨ c≡ab ⟩∘⟨refl ⟩
(a ∘ b) ∘ f ≈⟨ assoc ⟩
a ∘ (b ∘ f) ∎
open Pushes public
module IntroElim (a≡id : a ≈ id) where
elimʳ : f ∘ a ≈ f
elimʳ {f = f} = begin
f ∘ a ≈⟨ refl⟩∘⟨ a≡id ⟩
f ∘ id ≈⟨ identityʳ ⟩
f ∎
introʳ : f ≈ f ∘ a
introʳ = Equiv.sym elimʳ
elimˡ : (a ∘ f) ≈ f
elimˡ {f = f} = begin
a ∘ f ≈⟨ a≡id ⟩∘⟨refl ⟩
id ∘ f ≈⟨ identityˡ ⟩
f ∎
introˡ : f ≈ a ∘ f
introˡ = Equiv.sym elimˡ
open IntroElim public
module Extends (s : CommutativeSquare f g h i) where
extendˡ : CommutativeSquare f g (a ∘ h) (a ∘ i)
extendˡ {a = a} = begin
(a ∘ h) ∘ f ≈⟨ pullʳ s ⟩
a ∘ i ∘ g ≈˘⟨ assoc ⟩
(a ∘ i) ∘ g ∎
extendʳ : CommutativeSquare (f ∘ a) (g ∘ a) h i
extendʳ {a = a} = begin
h ∘ (f ∘ a) ≈⟨ pullˡ s ⟩
(i ∘ g) ∘ a ≈⟨ assoc ⟩
i ∘ (g ∘ a) ∎
extend² : CommutativeSquare (f ∘ b) (g ∘ b) (a ∘ h) (a ∘ i)
extend² {b = b} {a = a } = begin
(a ∘ h) ∘ (f ∘ b) ≈⟨ pullʳ extendʳ ⟩
a ∘ (i ∘ (g ∘ b)) ≈˘⟨ assoc ⟩
(a ∘ i) ∘ (g ∘ b) ∎
open Extends public
-- essentially composition in the arrow category
{-
A₁ -- c --> B₁
| |
b′ comm b
| |
V V
A₂ -- c′ -> B₂
| |
a′ comm a
| |
V V
A₃ -- c″ -> B₃
then the whole diagram commutes
-}
glue : CommutativeSquare c′ a′ a c″ →
CommutativeSquare c b′ b c′ →
CommutativeSquare c (a′ ∘ b′) (a ∘ b) c″
glue {c′ = c′} {a′ = a′} {a = a} {c″ = c″} {c = c} {b′ = b′} {b = b} sq-a sq-b = begin
(a ∘ b) ∘ c ≈⟨ pullʳ sq-b ⟩
a ∘ (c′ ∘ b′) ≈⟨ pullˡ sq-a ⟩
(c″ ∘ a′) ∘ b′ ≈⟨ assoc ⟩
c″ ∘ (a′ ∘ b′) ∎
glue◃◽ : a ∘ c′ ≈ c″ → CommutativeSquare c b′ b c′ → CommutativeSquare c b′ (a ∘ b) c″
glue◃◽ {a = a} {c′ = c′} {c″ = c″} {c = c} {b′ = b′} {b = b} tri-a sq-b = begin
(a ∘ b) ∘ c ≈⟨ pullʳ sq-b ⟩
a ∘ (c′ ∘ b′) ≈⟨ pullˡ tri-a ⟩
c″ ∘ b′ ∎
glue◃◽′ : c ∘ c′ ≈ a′ → CommutativeSquare a b a′ b′ → CommutativeSquare (c′ ∘ a) b c b′
glue◃◽′ {c = c} {c′ = c′} {a′ = a′} {a = a} {b = b} {b′ = b′} tri sq = begin
c ∘ c′ ∘ a ≈⟨ pullˡ tri ⟩
a′ ∘ a ≈⟨ sq ⟩
b′ ∘ b ∎
glue◽◃ : CommutativeSquare a b a′ b′ → b ∘ c ≈ c′ → CommutativeSquare (a ∘ c) c′ a′ b′
glue◽◃ {a = a} {b = b} {a′ = a′} {b′ = b′} {c = c} {c′ = c′} sq tri = begin
a′ ∘ a ∘ c ≈⟨ pullˡ sq ⟩
(b′ ∘ b) ∘ c ≈⟨ pullʳ tri ⟩
b′ ∘ c′ ∎
glue▹◽ : b ∘ a″ ≈ c → CommutativeSquare a b a′ b′ → CommutativeSquare (a ∘ a″) c a′ b′
glue▹◽ {b = b} {a″ = a″} {c = c} {a = a} {a′ = a′} {b′ = b′} tri sq = begin
a′ ∘ a ∘ a″ ≈⟨ pullˡ sq ⟩
(b′ ∘ b) ∘ a″ ≈⟨ pullʳ tri ⟩
b′ ∘ c ∎
-- essentially composition in the over category
glueTrianglesʳ : a ∘ b ≈ a′ → a′ ∘ b′ ≈ a″ → a ∘ (b ∘ b′) ≈ a″
glueTrianglesʳ {a = a} {b = b} {a′ = a′} {b′ = b′} {a″ = a″} a∘b≡a′ a′∘b′≡a″ = begin
a ∘ (b ∘ b′) ≈⟨ pullˡ a∘b≡a′ ⟩
a′ ∘ b′ ≈⟨ a′∘b′≡a″ ⟩
a″ ∎
-- essentially composition in the under category
glueTrianglesˡ : a′ ∘ b′ ≈ b″ → a ∘ b ≈ b′ → (a′ ∘ a) ∘ b ≈ b″
glueTrianglesˡ {a′ = a′} {b′ = b′} {b″ = b″} {a = a} {b = b} a′∘b′≡b″ a∘b≡b′ = begin
(a′ ∘ a) ∘ b ≈⟨ pullʳ a∘b≡b′ ⟩
a′ ∘ b′ ≈⟨ a′∘b′≡b″ ⟩
b″ ∎
module Cancellers (inv : h ∘ i ≈ id) where
cancelʳ : (f ∘ h) ∘ i ≈ f
cancelʳ {f = f} = begin
(f ∘ h) ∘ i ≈⟨ pullʳ inv ⟩
f ∘ id ≈⟨ identityʳ ⟩
f ∎
cancelˡ : h ∘ (i ∘ f) ≈ f
cancelˡ {f = f} = begin
h ∘ (i ∘ f) ≈⟨ pullˡ inv ⟩
id ∘ f ≈⟨ identityˡ ⟩
f ∎
cancelInner : (f ∘ h) ∘ (i ∘ g) ≈ f ∘ g
cancelInner {f = f} {g = g} = begin
(f ∘ h) ∘ (i ∘ g) ≈⟨ pullˡ cancelʳ ⟩
f ∘ g ∎
open Cancellers public
center : g ∘ h ≈ a → (f ∘ g) ∘ h ∘ i ≈ f ∘ a ∘ i
center {g = g} {h = h} {a = a} {f = f} {i = i} eq = begin
(f ∘ g) ∘ h ∘ i ≈⟨ assoc ⟩
f ∘ g ∘ h ∘ i ≈⟨ refl⟩∘⟨ pullˡ eq ⟩
f ∘ a ∘ i ∎
center⁻¹ : f ∘ g ≈ a → h ∘ i ≈ b → f ∘ (g ∘ h) ∘ i ≈ a ∘ b
center⁻¹ {f = f} {g = g} {a = a} {h = h} {i = i} {b = b} eq eq′ = begin
f ∘ (g ∘ h) ∘ i ≈⟨ refl⟩∘⟨ pullʳ eq′ ⟩
f ∘ g ∘ b ≈⟨ pullˡ eq ⟩
a ∘ b ∎
pull-last : h ∘ i ≈ a → (f ∘ g ∘ h) ∘ i ≈ f ∘ g ∘ a
pull-last {h = h} {i = i} {a = a} {f = f} {g = g} eq = begin
(f ∘ g ∘ h) ∘ i ≈⟨ assoc ⟩
f ∘ (g ∘ h) ∘ i ≈⟨ refl⟩∘⟨ pullʳ eq ⟩
f ∘ g ∘ a ∎
pull-first : f ∘ g ≈ a → f ∘ (g ∘ h) ∘ i ≈ a ∘ h ∘ i
pull-first {f = f} {g = g} {a = a} {h = h} {i = i} eq = begin
f ∘ (g ∘ h) ∘ i ≈⟨ refl⟩∘⟨ assoc ⟩
f ∘ g ∘ h ∘ i ≈⟨ pullˡ eq ⟩
a ∘ h ∘ i ∎
| {
"alphanum_fraction": 0.4484213817,
"avg_line_length": 27.5775862069,
"ext": "agda",
"hexsha": "8fb910c14f4c898f440613bfc6498b1068bef3ad",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Morphism/Reasoning/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Morphism/Reasoning/Core.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Morphism/Reasoning/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3382,
"size": 6398
} |
{-# OPTIONS --cubical --safe #-}
module TreeFold.Indexed where
open import Prelude
open import Data.Binary using (𝔹; 0ᵇ; 1ᵇ_; 2ᵇ_; ⟦_⇓⟧; ⟦_⇑⟧; inc)
open import Data.Binary.Isomorphism
open import Data.Nat
private
variable
n m : ℕ
t : Level
N : ℕ → Type t
ns : 𝔹
double : ℕ → ℕ
double n = n * 2
2^_*_ : ℕ → ℕ → ℕ
2^ zero * m = m
2^ suc n * m = double (2^ n * m)
infixr 5 _1∷_ _2∷_
data Array (T : ℕ → Type a) : 𝔹 → Type a where
[] : Array T 0ᵇ
_1∷_ : T 1 → Array (T ∘ double) ns → Array T (1ᵇ ns)
_2∷_ : T 2 → Array (T ∘ double) ns → Array T (2ᵇ ns)
cons : (∀ n → N n → N n → N (double n)) → N 1 → Array N ns → Array N (inc ns)
cons branch x [] = x 1∷ []
cons branch x (y 1∷ ys) = branch 1 x y 2∷ ys
cons branch x (y 2∷ ys) = x 1∷ cons (branch ∘ double) y ys
array-foldr : (N : ℕ → Type t) → (∀ n m → N (2^ n * 1) → N (2^ n * m) → N (2^ n * suc m)) → N 0 → Array N ns → N ⟦ ns ⇓⟧
array-foldr {ns = 0ᵇ} N c b [] = b
array-foldr {ns = 2ᵇ ns} N c b (x 2∷ xs) = c 1 ⟦ ns ⇓⟧ x (array-foldr (N ∘ double) (c ∘ suc) b xs)
array-foldr {ns = 1ᵇ ns} N c b (x 1∷ xs) = c 0 (⟦ ns ⇓⟧ * 2) x (array-foldr (N ∘ double) (c ∘ suc) b xs)
open import Data.Vec
import Data.Nat.Properties as ℕ
double≡*2 : ∀ n → n + n ≡ n * 2
double≡*2 zero = refl
double≡*2 (suc n) = cong suc (ℕ.+-suc n n ; cong suc (double≡*2 n))
module NonNorm {t} (N : ℕ → Type t) (f : ∀ p n m → N (2^ p * n) → N (2^ p * m) → N (2^ p * (n + m))) (z : N 0) where
spine : Vec (N 1) n → Array (N ) ⟦ n ⇑⟧
spine [] = []
spine (x ∷ xs) = cons (λ n x y → subst N (double≡*2 n) (f 0 n n x y)) x (spine xs)
unspine : Array N ns → N ⟦ ns ⇓⟧
unspine = array-foldr N (λ n → f n 1) z
treeFold : Vec (N 1) n → N n
treeFold xs = subst N (𝔹-rightInv _) (unspine (spine xs))
pow-suc : ∀ n m → (2^ n * 1) + (2^ n * m) ≡ (2^ n * suc m)
pow-suc zero m = refl
pow-suc (suc n) m = sym (ℕ.+-*-distrib (2^ n * 1) (2^ n * m) 2) ; cong (_* 2) (pow-suc n m)
module _ {t} (N : ℕ → Type t) (f : ∀ {n m} → N n → N m → N (n + m)) (z : N 0) where
spine : Vec (N 1) n → Array (N ) ⟦ n ⇑⟧
spine [] = []
spine (x ∷ xs) = cons (λ n x y → subst N (double≡*2 n) (f x y)) x (spine xs)
unspine : Array N ns → N ⟦ ns ⇓⟧
unspine = array-foldr N (λ n m xs ys → subst N (pow-suc n m) (f xs ys)) z
treeFold : Vec (N 1) n → N n
treeFold xs = subst N (𝔹-rightInv _) (unspine (spine xs))
| {
"alphanum_fraction": 0.5174443043,
"avg_line_length": 33.0416666667,
"ext": "agda",
"hexsha": "314849a9fb11513db9ad60e9412ff38559778679",
"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": "TreeFold/Indexed.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": "TreeFold/Indexed.agda",
"max_line_length": 120,
"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": "TreeFold/Indexed.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": 1134,
"size": 2379
} |
module Computability.Recursive where
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Unit using (⊤)
open import Data.Bool using (Bool; false; true)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; pred)
open import Data.Product using (_×_)
open import Data.Fin using (Fin; zero; suc; punchIn; punchOut)
open import Data.Sum using (_⊎_)
open import Data.Vec using (Vec; _∷_; []; lookup) renaming (map to map-Vec)
open import Function using (Bijective)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Level renaming (zero to lzero; suc to lsuc)
variable
n m : ℕ
b : Bool
data RecFun : (use-mu : Bool) → ℕ → Set where
Var : Fin n → RecFun b n
Bind : Vec (RecFun b m) n → RecFun b n → RecFun b m
Zero : RecFun b 0
Suc : RecFun b 1
Rec : RecFun b n → RecFun b (2 + n) → RecFun b (suc n)
Mu : RecFun b (suc n) → RecFun true n
mutual
eval-no-mu : Vec ℕ n → RecFun false n → ℕ
eval-no-mu v (Var i) = lookup v i
eval-no-mu v (Bind xs r) = eval-no-mu (eval-bindings v xs) r
eval-no-mu v Zero = zero
eval-no-mu (x ∷ []) Suc = suc x
eval-no-mu (x ∷ v) (Rec base rec) = eval-no-mu-rec x v base rec
eval-bindings : ∀{n m} → Vec ℕ m → Vec (RecFun false m) n → Vec ℕ n
eval-bindings v [] = []
eval-bindings v (x ∷ xs) = eval-no-mu v x ∷ eval-bindings v xs
eval-no-mu-rec : ℕ → Vec ℕ n → RecFun false n → RecFun false (2 + n) → ℕ
eval-no-mu-rec zero v base rec = eval-no-mu v base
eval-no-mu-rec (suc k) v base rec = eval-no-mu (k ∷ result ∷ v) rec
where result = eval-no-mu-rec k v base rec
postulate
enum-RecFun : ∀ vars → ℕ → RecFun true vars
enum-RecFun-Surj : ∀ vars → ℕ → Bijective {A = ℕ} {B = RecFun true vars} _≡_ _≡_ (enum-RecFun vars)
| {
"alphanum_fraction": 0.6477404403,
"avg_line_length": 35.9583333333,
"ext": "agda",
"hexsha": "cae34b4ef5deaa9afd7742e64c083ac7963e7d7c",
"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": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jesyspa/computability-in-agda",
"max_forks_repo_path": "Computability/Recursive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"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": "jesyspa/computability-in-agda",
"max_issues_repo_path": "Computability/Recursive.agda",
"max_line_length": 101,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jesyspa/computability-in-agda",
"max_stars_repo_path": "Computability/Recursive.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-30T11:15:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-19T15:51:22.000Z",
"num_tokens": 615,
"size": 1726
} |
module Experimental.Finite where
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
data Fin : ℕ → Set where
Fin-S : ∀ {n} → Fin n → Fin (S n)
Fin-Z : ∀ {n} → Fin (S n)
| {
"alphanum_fraction": 0.5337423313,
"avg_line_length": 16.3,
"ext": "agda",
"hexsha": "7ebee87f4ad7abb8c2cb6c32adf90053b28967ee",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/Experimental/Finite.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andrejbauer/formaltt",
"max_issues_repo_path": "src/Experimental/Finite.agda",
"max_line_length": 35,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/Experimental/Finite.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 63,
"size": 163
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
import LibraBFT.Concrete.Properties.Common as Common
import LibraBFT.Concrete.Properties.VotesOnce as VO
open import LibraBFT.Impl.Consensus.Network as Network
open import LibraBFT.Impl.Consensus.Network.Properties as NetworkProps
open import LibraBFT.Impl.Consensus.RoundManager
import LibraBFT.Impl.Handle as Handle
open import LibraBFT.Impl.IO.OBM.InputOutputHandlers
open import LibraBFT.Impl.IO.OBM.Properties.InputOutputHandlers
open import LibraBFT.Impl.Handle.Properties
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.Lemmas
open import Util.PKCS
open import Util.Prelude
open Invariants
open RoundManagerTransProps
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open ParamsWithInitAndHandlers Handle.InitHandler.initAndHandlers
open PeerCanSignForPK
open import LibraBFT.ImplShared.Util.HashCollisions Handle.InitHandler.initAndHandlers
open import Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms
Handle.InitHandler.initAndHandlers
PeerCanSignForPK PeerCanSignForPK-stable
open import LibraBFT.Impl.Handle.InitProperties
open initHandlerSpec
-- This module contains definitions and lemmas used by proofs of the
-- implementation obligations for VotesOnce and PreferredRoundRule.
module LibraBFT.Impl.Properties.Common where
postulate -- TODO-3: prove (note: advanced; waiting on: `handle`)
-- This will require updates to the existing proofs for the peer handlers. We
-- will need to show that honest peers sign things only for their only PK, and
-- that they either resend messages signed before or if sending a new one,
-- that signature hasn't been sent before
impl-sps-avp : StepPeerState-AllValidParts
open Structural impl-sps-avp
-- We can prove this easily for the Agda model because (unlike the Haskell
-- prototype) it does not yet do epoch changes, so only the initial EC is
-- relevant. Later, this will require us to use the fact that epoch changes
-- require proof of committing an epoch-changing transaction.
availEpochsConsistent :
∀{pid pid' v v' pk}{st : SystemState}
→ (pkvpf : PeerCanSignForPK st v pid pk)
→ (pkvpf' : PeerCanSignForPK st v' pid' pk)
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ pcs4𝓔 pkvpf ≡ pcs4𝓔 pkvpf'
availEpochsConsistent (mkPCS4PK _ (inBootstrapInfo refl) _) (mkPCS4PK _ (inBootstrapInfo refl) _) refl = refl
postulate -- TODO-1: Prove (waiting on: complete definition of `initRM`)
uninitQcs∈Bootstrap
: ∀ {pid qc vs}{st : SystemState}
→ ReachableSystemState st
→ initialised st pid ≡ uninitd
→ qc QCProps.∈RoundManager (peerStates st pid)
→ vs ∈ qcVotes qc
→ ∈BootstrapInfo-impl fakeBootstrapInfo (proj₂ vs)
module ∈BootstrapInfoProps where
sameSig∉ : ∀ {pk} {v v' : Vote}
→ (sig : WithVerSig pk v) (sig' : WithVerSig pk v')
→ ¬ ∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig)
→ ver-signature sig' ≡ ver-signature sig
→ ¬ ∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig')
sameSig∉ _ _ ¬bootstrap ≡sig rewrite ≡sig = ¬bootstrap
-- Lemmas for `PeerCanSignForPK`
module PeerCanSignForPKProps where
msb4 -- NOTE: This proof requires updating when we model epoch changes.
: ∀ {pid v pk}{pre post : SystemState}
→ ReachableSystemState pre
→ Step pre post
→ PeerCanSignForPK post v pid pk
→ Meta-Honest-PK pk → (sig : WithVerSig pk v)
→ MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
→ PeerCanSignForPK pre v pid pk
msb4 preach step (mkPCS4PK 𝓔@._ (inBootstrapInfo refl) (mkPCS4PKin𝓔 𝓔id≡ mbr nid≡ pk≡)) hpk sig mws∈pool =
mkPCS4PK 𝓔 (inBootstrapInfo refl) (mkPCS4PKin𝓔 𝓔id≡ mbr nid≡ pk≡)
msb4-eid≡
: ∀ {pre post : SystemState} {v v' pid pk}
→ ReachableSystemState pre
→ Step pre post
→ Meta-Honest-PK pk
→ PeerCanSignForPK post v pid pk
→ v ≡L v' at vEpoch
→ (sig' : WithVerSig pk v')
→ MsgWithSig∈ pk (ver-signature sig') (msgPool pre)
→ PeerCanSignForPK pre v pid pk
msb4-eid≡ rss step hpk pcsfpk ≡eid sig' mws' =
peerCanSignEp≡ (msb4 rss step (peerCanSignEp≡ pcsfpk ≡eid) hpk sig' mws') (sym ≡eid)
pidInjective
: ∀ {pid pid' pk v v'}{st : SystemState}
→ PeerCanSignForPK st v pid pk
→ PeerCanSignForPK st v' pid' pk
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ pid ≡ pid'
pidInjective{pid}{pid'}{pk} pcsfpk₁ pcsfpk₂ ≡epoch = begin
pid ≡⟨ sym (nid≡ (pcs4in𝓔 pcsfpk₁)) ⟩
pcsfpk₁∙pid ≡⟨ PK-inj-same-ECs{pcs4𝓔 pcsfpk₁}{pcs4𝓔 pcsfpk₂}
(availEpochsConsistent pcsfpk₁ pcsfpk₂ ≡epoch) pcsfpk∙pk≡ ⟩
pcsfpk₂∙pid ≡⟨ nid≡ (pcs4in𝓔 pcsfpk₂) ⟩
pid' ∎
where
open ≡-Reasoning
open PeerCanSignForPKinEpoch
open PeerCanSignForPK
pcsfpk₁∙pid = EpochConfig.toNodeId (pcs4𝓔 pcsfpk₁) (mbr (pcs4in𝓔 pcsfpk₁))
pcsfpk₂∙pid = EpochConfig.toNodeId (pcs4𝓔 pcsfpk₂) (mbr (pcs4in𝓔 pcsfpk₂))
pcsfpk₁∙pk = EpochConfig.getPubKey (pcs4𝓔 pcsfpk₁) (mbr (pcs4in𝓔 pcsfpk₁))
pcsfpk₂∙pk = EpochConfig.getPubKey (pcs4𝓔 pcsfpk₂) (mbr (pcs4in𝓔 pcsfpk₂))
pcsfpk∙pk≡ : pcsfpk₁∙pk ≡ pcsfpk₂∙pk
pcsfpk∙pk≡ = begin
pcsfpk₁∙pk ≡⟨ pk≡ (pcs4in𝓔 pcsfpk₁) ⟩
pk ≡⟨ sym (pk≡ (pcs4in𝓔 pcsfpk₂)) ⟩
pcsfpk₂∙pk ∎
module ReachableSystemStateProps where
mws∈pool⇒initd
: ∀ {pid pk v}{st : SystemState}
→ ReachableSystemState st
→ PeerCanSignForPK st v pid pk
→ Meta-Honest-PK pk
→ (sig : WithVerSig pk v)
→ ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig))
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
→ initialised st pid ≡ initd
mws∈pool⇒initd{pk = pk}{v} (step-s{pre = pre} rss step@(step-peer sp@(step-cheat cmc))) pcsfpk hpk sig ¬bootstrap mws∈pool =
peersRemainInitialized step (mws∈pool⇒initd rss (PeerCanSignForPKProps.msb4 rss step pcsfpk hpk sig mws∈poolPre) hpk sig ¬bootstrap mws∈poolPre)
where
¬bootstrap' = ∈BootstrapInfoProps.sameSig∉ sig (msgSigned mws∈pool) ¬bootstrap (msgSameSig mws∈pool)
mws∈poolPre : MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
mws∈poolPre = ¬cheatForgeNew sp refl unit hpk mws∈pool ¬bootstrap'
mws∈pool⇒initd{pid₁}{pk = pk} (step-s{pre = pre} rss step@(step-peer sp@(step-honest{pid₂} sps@(step-init {rm} rm×acts uni)))) pcsfpk hpk sig ¬bootstrap mws∈pool
with pid₁ ≟ pid₂
...| yes refl = StepPeer-post-lemma2 {pre = pre} sps
...| no neq
with newMsg⊎msgSentB4 rss sps hpk (msgSigned mws∈pool) ¬bootstrap' (msg⊆ mws∈pool) (msg∈pool mws∈pool)
where
¬bootstrap' = ∈BootstrapInfoProps.sameSig∉ sig (msgSigned mws∈pool) ¬bootstrap (msgSameSig mws∈pool)
...| Right mws∈poolPre = peersRemainInitialized step (mws∈pool⇒initd rss (PeerCanSignForPKProps.msb4 rss step pcsfpk hpk sig mws∈poolPre') hpk sig ¬bootstrap mws∈poolPre')
where
mws∈poolPre' : MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
mws∈poolPre' rewrite msgSameSig mws∈pool = mws∈poolPre
...| Left (send∈acts , _ , _)
with initHandlerSpec.contract pid₂ fakeBootstrapInfo rm×acts
...| init-contract
with msg⊆ mws∈pool
...| vote∈vm
= ⊥-elim
(P≢V (sym (proj₁ (proj₂ (initHandlerSpec.ContractOk.isInitPM init-contract send∈acts)))))
...| vote∈qc vs∈qc _ qc∈pm
with initHandlerSpec.ContractOk.isInitPM init-contract send∈acts
...| (_ , refl , noSigs) = ⊥-elim (noSigs vs∈qc qc∈pm)
mws∈pool⇒initd{pid₁}{pk}{v} (step-s{pre = pre} rss step@(step-peer{pid₂} sp@(step-honest sps@(step-msg _ ini)))) pcsfpk hpk sig ¬bootstrap mws∈pool
with newMsg⊎msgSentB4 rss sps hpk (msgSigned mws∈pool) ¬bootstrap' (msg⊆ mws∈pool) (msg∈pool mws∈pool)
where
¬bootstrap' = ∈BootstrapInfoProps.sameSig∉ sig (msgSigned mws∈pool) ¬bootstrap (msgSameSig mws∈pool)
...| Left (m∈outs , pcsfpk' , ¬msb4)
with pid≡
where
vd₁≡vd₂ : v ≡L msgPart mws∈pool at vVoteData
vd₁≡vd₂ = either (⊥-elim ∘ PerReachableState.meta-no-collision rss) id (sameSig⇒sameVoteData (msgSigned mws∈pool) sig (msgSameSig mws∈pool))
pid≡ : pid₁ ≡ pid₂
pid≡ = PeerCanSignForPKProps.pidInjective pcsfpk pcsfpk' (cong (_^∙ vdProposed ∙ biEpoch) vd₁≡vd₂)
...| refl rewrite StepPeer-post-lemma2{pid₂}{pre = pre} sps = refl
mws∈pool⇒initd{pid₁}{pk} (step-s{pre = pre} rss step@(step-peer{pid₂} sp@(step-honest sps@(step-msg _ ini)))) pcsfpk hpk sig ¬bootstrap mws∈pool | Right mws∈poolPre =
peersRemainInitialized step (mws∈pool⇒initd rss (PeerCanSignForPKProps.msb4 rss step pcsfpk hpk sig mws∈poolPre') hpk sig ¬bootstrap mws∈poolPre')
where
mws∈poolPre' : MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
mws∈poolPre' rewrite msgSameSig mws∈pool = mws∈poolPre
mws∈pool⇒epoch≡
: ∀ {pid v s' outs pk}{st : SystemState}
→ ReachableSystemState st
→ (sps : StepPeerState pid (msgPool st) (initialised st) (peerStates st pid) (s' , outs))
→ PeerCanSignForPK st v pid pk
→ Meta-Honest-PK pk → (sig : WithVerSig pk v)
→ ¬ (∈BootstrapInfo-impl fakeBootstrapInfo (ver-signature sig))
→ MsgWithSig∈ pk (ver-signature sig) (msgPool st)
→ s' ^∙ rmEpoch ≡ v ^∙ vEpoch
→ peerStates st pid ^∙ rmEpoch ≡ v ^∙ vEpoch
mws∈pool⇒epoch≡ rss (step-init _ uni) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ =
absurd (uninitd ≡ initd) case (trans (sym uni) ini) of λ ()
where
ini = mws∈pool⇒initd rss pcsfpk hpk sig ¬bootstrap mws∈pool
mws∈pool⇒epoch≡{pid}{v}{st = st} rss (step-msg{_ , P pm} m∈pool ini) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ = begin
hpPre ^∙ rmEpoch ≡⟨ noEpochChange ⟩
hpPos ^∙ rmEpoch ≡⟨ epoch≡ ⟩
v ^∙ vEpoch ∎
where
hpPool = msgPool st
hpPre = peerStates st pid
hpPos = LBFT-post (handleProposal 0 pm) hpPre
open handleProposalSpec.Contract (handleProposalSpec.contract! 0 pm hpPool hpPre)
open ≡-Reasoning
mws∈pool⇒epoch≡{pid}{v}{st = st} rss (step-msg{sndr , V vm} _ _) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ = begin
hvPre ^∙ rmEpoch ≡⟨ noEpochChange ⟩
hvPos ^∙ rmEpoch ≡⟨ epoch≡ ⟩
v ^∙ vEpoch ∎
where
hvPre = peerStates st pid
hvPos = LBFT-post (handleVote 0 vm) hvPre
open handleVoteSpec.Contract (handleVoteSpec.contract! 0 vm (msgPool st) hvPre)
open ≡-Reasoning
mws∈pool⇒epoch≡{pid}{v}{st = st} rss (step-msg{sndr , C cm} _ _) pcsfpk hpk sig ¬bootstrap mws∈pool epoch≡ = epoch≡
| {
"alphanum_fraction": 0.6926281471,
"avg_line_length": 45.6280991736,
"ext": "agda",
"hexsha": "00d6a0d4d1299e3e84e7d1fa876438eb1ddd20ab",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Properties/Common.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Properties/Common.agda",
"max_line_length": 173,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Properties/Common.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3888,
"size": 11042
} |
open import Agda.Primitive using (lzero; lsuc; _⊔_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong; subst; setoid)
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂; zip; map; <_,_>; swap)
import Function.Equality
open import Relation.Binary using (Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
import Categories.Category
import Categories.Functor
import Categories.Category.Instance.Setoids
import Categories.Monad.Relative
import Categories.Category.Equivalence
import Categories.Category.Cocartesian
import Categories.Category.Construction.Functors
import Categories.Category.Product
import Categories.NaturalTransformation
import Categories.NaturalTransformation.NaturalIsomorphism
import SecondOrder.Arity
import SecondOrder.Signature
import SecondOrder.Metavariable
import SecondOrder.VRenaming
import SecondOrder.MRenaming
import SecondOrder.Term
import SecondOrder.Substitution
import SecondOrder.RelativeMonadMorphism
import SecondOrder.Instantiation
import SecondOrder.IndexedCategory
import SecondOrder.RelativeKleisli
import SecondOrder.Mslot
module SecondOrder.MRelativeMonad
{ℓ}
{𝔸 : SecondOrder.Arity.Arity}
(Σ : SecondOrder.Signature.Signature ℓ 𝔸)
where
open SecondOrder.Signature.Signature Σ
open SecondOrder.Metavariable Σ
open SecondOrder.Term Σ
open SecondOrder.VRenaming Σ
open SecondOrder.MRenaming Σ
open SecondOrder.Mslot Σ
open SecondOrder.Substitution Σ
open SecondOrder.Instantiation Σ
open import SecondOrder.RelativeMonadMorphism
open Categories.Category
open Categories.Functor using (Functor)
open Categories.NaturalTransformation renaming (id to idNt)
open Categories.NaturalTransformation.NaturalIsomorphism renaming (refl to reflNt; sym to symNt; trans to transNt)
open Categories.Category.Construction.Functors
open Categories.Category.Instance.Setoids
open Categories.Category.Product
open Function.Equality using () renaming (setoid to Π-setoid)
open SecondOrder.IndexedCategory
-- open import SecondOrder.RelativeKleisli
module MTerm {Γ : VContext} where
open Category
open NaturalTransformation
open Functor
open Categories.Monad.Relative
open Function.Equality using () renaming (setoid to Π-setoid)
open Categories.Category.Equivalence using (StrongEquivalence)
open SecondOrder.RelativeKleisli
MMonad : Monad Mslots
MMonad =
let open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong) in
record
{ F₀ = λ Θ A →
record
{ F₀ = λ Ψ → record
{ F₀ = λ Δ → Term-setoid (Θ ,, Ψ) (Γ ,, Δ) A
; F₁ = λ {Δ} {Ξ} ρ → record { _⟨$⟩_ = [_]ᵛ_ (ʳ⇑ᵛ ρ) ; cong = λ t≈s → []ᵛ-resp-≈ t≈s }
; identity = λ t≈s → ≈-trans ([]ᵛ-resp-≡ᵛ idᵛ+idᵛ) (≈-trans [idᵛ] t≈s)
; homomorphism = λ t≈s → ≈-trans ([]ᵛ-resp-≈ t≈s) ∘ᵛ-resp-ʳ⇑ᵛ-term
; F-resp-≈ = λ ρ≈τ t≈s → {!!}
}
; F₁ = λ ι → record
{ η = λ Δ → record { _⟨$⟩_ = [_]ᵐ_ (ᵐ⇑ᵐ ι) ; cong = λ t≈s → []ᵐ-resp-≈ t≈s }
; commute = λ ρ t≈s → ≈-trans ([]ᵐ-resp-≈ ([]ᵛ-resp-≈ t≈s)) vr-comm-mr
; sym-commute = λ ρ t≈s → ≈-trans (≈-sym vr-comm-mr) ([]ᵐ-resp-≈ ([]ᵛ-resp-≈ t≈s))
}
; identity = λ t≈s → ≈-trans ([]ᵐ-resp-≈ t≈s) (≈-trans ([]ᵐ-resp-≡ᵐ ᵐ⇑ᵐ-resp-idᵐ) [idᵐ])
; homomorphism = λ t≈s → ≈-trans ([]ᵐ-resp-≈ t≈s) ∘ᵐ-resp-ᵐ⇑-term
; F-resp-≈ = λ ι≈μ t≈s → ≈-trans ([]ᵐ-resp-≈ t≈s) ([]ᵐ-resp-≡ᵐ (ᵐ⇑ᵐ-resp-≡ᵐ ι≈μ))
}
; unit = λ A → record
{ η = λ Θ →
record
{ η = λ Δ → record { _⟨$⟩_ = [_]ᵛ_ inrᵛ ; cong = λ t≈s → []ᵛ-resp-≈ t≈s }
; commute = λ ρ t≈s → ≈-trans ([]ᵛ-resp-≈ ([]ᵛ-resp-≈ t≈s)) (≈-sym ʳ⇑ᵛ-comm-inrᵛ-term)
; sym-commute = λ ρ t≈s → ≈-trans ʳ⇑ᵛ-comm-inrᵛ-term ([]ᵛ-resp-≈ ([]ᵛ-resp-≈ t≈s))
}
; commute = λ f t≈s → ≈-trans ([]ᵛ-resp-≈ ([]ᵐ-resp-≈ t≈s)) mr-comm-vr
; sym-commute = λ f t≈s → ≈-trans ? ([]ᵛ-resp-≈ ([]ᵐ-resp-≈ t≈s))
}
; extend = λ I A → record
{ η = λ Θ →
record
{ η = λ Ψ → record { _⟨$⟩_ = [_]ⁱ_ {!!} ; cong = {!!} }
; commute = {!!}
; sym-commute = {!!}
}
; commute = {!!}
; sym-commute = {!!}
}
; identityʳ = {!!}
; identityˡ = {!!}
; assoc = {!!}
; extend-≈ = {!!}
}
| {
"alphanum_fraction": 0.5647806478,
"avg_line_length": 42.4173913043,
"ext": "agda",
"hexsha": "8132d615213278d861da8e78232fbe8541fbf60b",
"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": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejbauer/formaltt",
"max_forks_repo_path": "src/SecondOrder/MRelativeMonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"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": "andrejbauer/formaltt",
"max_issues_repo_path": "src/SecondOrder/MRelativeMonad.agda",
"max_line_length": 116,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejbauer/formal",
"max_stars_repo_path": "src/SecondOrder/MRelativeMonad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-18T18:21:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-18T18:21:00.000Z",
"num_tokens": 1615,
"size": 4878
} |
module Tactic.Monoid.Exp where
open import Prelude
open import Tactic.Reflection.Quote
open import Tactic.Deriving.Quotable
data Exp : Set where
var : Nat → Exp
ε : Exp
_⊕_ : Exp → Exp → Exp
unquoteDecl QuoteExp = deriveQuotable QuoteExp (quote Exp)
flatten : Exp → List Nat
flatten (var x) = x ∷ []
flatten ε = []
flatten (e ⊕ e₁) = flatten e ++ flatten e₁
| {
"alphanum_fraction": 0.6991869919,
"avg_line_length": 19.4210526316,
"ext": "agda",
"hexsha": "2da81a23d806f69151a67cc6f4e7732c80ed5226",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Monoid/Exp.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Monoid/Exp.agda",
"max_line_length": 58,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Monoid/Exp.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 116,
"size": 369
} |
module cry.gfp where
-- open import Agda.Primitive using (lsuc; _⊔_)
open import Level
-- import Agda.Builtin.FromNat
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
open import Algebra.FunctionProperties.Core using (Op₁; Op₂)
open import Relation.Nullary
-- open import Relation.Binary.Core using (Rel; Decidable; Substitutive)
-- open import Relation.Binary.PropositionalEquality.Core using (subst)
Rel : ∀ {a} → Set a → (ℓ : Level) → Set (a ⊔ suc ℓ)
Rel A ℓ = A → A → Set ℓ
Decidable : ∀ {a ℓ} {A : Set a} → Rel A ℓ → Set _
Decidable _∼_ = ∀ x y → Dec (x ∼ y)
_Respects_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → (A → Set ℓ₁) → Rel A ℓ₂ → Set _
P Respects _∼_ = ∀ {x y} → x ∼ y → P x → P y
Substitutive : ∀ {a ℓ₁} {A : Set a} → Rel A ℓ₁ → (ℓ₂ : Level) → Set _
Substitutive {A = A} _∼_ p = (P : A → Set p) → P Respects _∼_
subst : ∀ {a p} {A : Set a} → Substitutive (_≡_ {A = A}) p
subst P refl p = p
record RawField c ℓ : Set (suc (c ⊔ ℓ)) where
infix 10 _⁻¹
infix 9 -_
infixl 8 _²
infixl 7 _*_
infixl 6 _+_ _-_
infix 4 _≈_ _≈?_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_≈?_ : Decidable _≈_
_?≈_ : Carrier → Carrier → Bool
_+_ : Op₂ Carrier
_-_ : Op₂ Carrier
_*_ : Op₂ Carrier
_² : Op₁ Carrier
-_ : Op₁ Carrier
_⁻¹ : Op₁ Carrier
0# : Carrier
1# : Carrier
open import Agda.Builtin.Nat as N using () renaming (Nat to ℕ)
_mod_ : (dividend divisor : ℕ) → ℕ
(d mod 0) = 0
(d mod N.suc s) = N.mod-helper 0 s d s
_div_ : (dividend divisor : ℕ) → ℕ
(d div 0) = 0
(d div N.suc s) = N.div-helper 0 s d s
{-# TERMINATING #-}
times : ∀ {a} {A : Set a} →
(one : A) (dbl : A → A) (add : A → A → A) →
A → ℕ → A
times {A = A} one dbl add = mul where
mul : A → ℕ → A
f : A → ℕ → A
-- f u n = uⁿ
g : A → A → ℕ → A
-- g t u n = uⁿ t
mul x 0 = one
mul x n = f x n
f u 1 = u
f u n with n mod 2
... | 0 = f (dbl u) (n div 2)
... | _ = g u (dbl u) ((n N.- 1) div 2)
g t u 1 = add t u
g t u n with n mod 2
... | 0 = g t (dbl u) (n div 2)
... | _ = g (add t u) (dbl u) ((n N.- 1) div 2)
module 𝔽ₚ (p : ℕ) where
𝔽 : Set
𝔽 = ℕ
to𝔽 : ℕ → 𝔽
to𝔽 i = i mod p
_==_ : 𝔽 → 𝔽 → Set
x == y = x ≡ y
open N using (zero; suc)
pred : ℕ → ℕ
pred zero = 0
pred (suc n) = n
_≟_ : (x y : 𝔽) → Dec (x == y)
zero ≟ zero = yes refl
suc m ≟ suc n with m ≟ n
suc m ≟ suc .m | yes refl = yes refl
suc m ≟ suc n | no prf = no λ x → prf ((λ p → subst (λ x → m ≡ pred x) p refl) x)
zero ≟ suc n = no λ()
suc m ≟ zero = no λ()
infix 10 _⁻¹
infix 9 -_
infixl 8 _²
infixl 7 _*_
infixl 6 _+_ _-_
_+_ : 𝔽 → 𝔽 → 𝔽
n + m = to𝔽 (n N.+ m)
_*_ : 𝔽 → 𝔽 → 𝔽
n * m = to𝔽 (n N.* m)
_² : 𝔽 → 𝔽
x ² = x * x
-_ : 𝔽 → 𝔽
- 0 = 0
- N.suc n = (p N.- N.suc n)
_-_ : 𝔽 → 𝔽 → 𝔽
x - y = x + (- y)
0# : 𝔽
0# = 0
1# : 𝔽
1# = 1
_^_ : 𝔽 → ℕ → 𝔽
_^_ = times 1# _² _*_
_⁻¹ : 𝔽 → 𝔽
x ⁻¹ = x ^ (p N.- 2)
gfp : ℕ → RawField _ _
gfp p = record
{ Carrier = 𝔽
; _≈_ = _==_
; _≈?_ = _≟_
; _?≈_ = N._==_
; _+_ = _+_
; _-_ = _-_
; _*_ = _*_
; _² = _²
; -_ = -_
; _⁻¹ = _⁻¹
; 0# = 0#
; 1# = 1#
} where open 𝔽ₚ p
| {
"alphanum_fraction": 0.4827272727,
"avg_line_length": 21.568627451,
"ext": "agda",
"hexsha": "89100d1ae5c6c8f24ea1f832a96b5a7a6fdbabdc",
"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": "44297e5099d12dea7f3165c1f1d53924736ec058",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "semenov-vladyslav/cry-agda",
"max_forks_repo_path": "src/cry/gfp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44297e5099d12dea7f3165c1f1d53924736ec058",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "semenov-vladyslav/cry-agda",
"max_issues_repo_path": "src/cry/gfp.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "44297e5099d12dea7f3165c1f1d53924736ec058",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "semenov-vladyslav/cry-agda",
"max_stars_repo_path": "src/cry/gfp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1542,
"size": 3300
} |
{-# OPTIONS --without-K --safe #-}
module Fragment.Examples.Semigroup.Types where
open import Fragment.Prelude
open import Level using (zero)
open import Function.Related
open import Function.Related.TypeIsomorphisms
using (×-isSemigroup; ⊎-isSemigroup)
open import Function.Inverse using (_↔_)
open import Data.Product using (_×_)
open import Data.Sum using (_⊎_)
×-semigroup = semigroup→model (×-isSemigroup bijection zero)
⊎-semigroup = semigroup→model (⊎-isSemigroup bijection zero)
×-assoc₁ : ∀ {A B C : Set} → (A × (B × C)) ↔ ((A × B) × C)
×-assoc₁ = fragment SemigroupFrex ×-semigroup
×-assoc₂ : ∀ {A B C : Set} → ((A × B) × (B × C)) ↔ (A × (B × B) × C)
×-assoc₂ = fragment SemigroupFrex ×-semigroup
⊎-assoc₁ : ∀ {A B C : Set} → (A ⊎ (B ⊎ C)) ↔ ((A ⊎ B) ⊎ C)
⊎-assoc₁ = fragment SemigroupFrex ⊎-semigroup
⊎-assoc₂ : ∀ {A B C : Set} → ((A ⊎ B) ⊎ (B ⊎ C)) ↔ (A ⊎ (B ⊎ B) ⊎ C)
⊎-assoc₂ = fragment SemigroupFrex ⊎-semigroup
| {
"alphanum_fraction": 0.6389776358,
"avg_line_length": 30.2903225806,
"ext": "agda",
"hexsha": "f12adcaed9c1f56a99ffc9ae1dff94aa6b904cb4",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Examples/Semigroup/Types.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Examples/Semigroup/Types.agda",
"max_line_length": 68,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Examples/Semigroup/Types.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 352,
"size": 939
} |
module QuoteTerm where
open import Common.Reflection
open import Common.Prelude renaming (Nat to ℕ; module Nat to ℕ)
data _≡_ {a}{A : Set a}(x : A) : A → Set where
refl : x ≡ x
test₁ : quoteTerm (λ {A : Set} (x : A) → x)
≡ lam hidden (abs "A" (lam visible (abs "x" (var 0 []))))
test₁ = refl
-- Local variables are de Bruijn indices, do not forget to shift
test₂ : (λ {A : Set} (x : A) → quoteTerm x) ≡ (λ x → var 0 [])
test₂ = refl
-- Terms are not normalized before being unquoted
test₃ : quoteTerm (1 + 1) ≡ lit (nat 2) → ⊥
test₃ ()
syntax id A x = x ∶ A
id : (A : Set) → A → A
id A x = x
-- _∶_ from the Function module can help in case of ambiguities
test₄ : quoteTerm (zero ∶ ℕ) ≡
def (quote id)
(vArg (def (quote ℕ) []) ∷
vArg (con (quote zero) []) ∷
[])
test₄ = refl
-- Andreas, 2020-06-05, issue #4734
-- Test that primShowQName prints something reasonable
-- for quoted names.
issue4734 : primShowQName (quote ℕ) ≡ "Agda.Builtin.Nat.ℕ"
issue4734 = refl
-- Not sure this response is very reasonable, since
-- it suggest a qualified name that does not exist.
| {
"alphanum_fraction": 0.6176211454,
"avg_line_length": 26.3953488372,
"ext": "agda",
"hexsha": "a54c4e3c7fc9fbbb819e91effa34f351202f9f91",
"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": "e2c6241b2bf0cbd7bddbe2c2b56e6d6ce69d1e3a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pnlph/agda",
"max_forks_repo_path": "test/Succeed/QuoteTerm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2c6241b2bf0cbd7bddbe2c2b56e6d6ce69d1e3a",
"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": "pnlph/agda",
"max_issues_repo_path": "test/Succeed/QuoteTerm.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e2c6241b2bf0cbd7bddbe2c2b56e6d6ce69d1e3a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pnlph/agda",
"max_stars_repo_path": "test/Succeed/QuoteTerm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 382,
"size": 1135
} |
record ⊤ : Set where
instance constructor tt
data ⊥ : Set where
data Inf : Set where
-∞ ∞ : Inf
Less : Inf → Inf → Set
Less ∞ _ = ⊥
Less _ ∞ = ⊤
Less _ _ = ⊥
data Bounded : Inf → Set where
bound : ∀ {b} {{lt : Less -∞ b}} → Bounded b
-- The first time around the target type is Less -∞ _b which results in no
-- candidates. Once _b gets solved candidates need to be recomputed.
foo : Bounded ∞
foo = bound
| {
"alphanum_fraction": 0.6315789474,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "fedeb9eacb4deb1e780d437e4b5f1e255f8989fa",
"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/RecomputeInstanceCandidates.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/RecomputeInstanceCandidates.agda",
"max_line_length": 74,
"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/RecomputeInstanceCandidates.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": 142,
"size": 418
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Instantiates indexed binary structures at an index to the equivalent
-- non-indexed structures.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Indexed.Heterogeneous.Construct.At where
open import Relation.Binary
open import Relation.Binary.Indexed.Heterogeneous
hiding (IsEquivalence; Setoid)
------------------------------------------------------------------------
-- Structures
module _ {a i} {I : Set i} {A : I → Set a} where
isEquivalence : ∀ {ℓ} {_≈_ : IRel A ℓ} → IsIndexedEquivalence A _≈_ →
(index : I) → IsEquivalence (_≈_ {index})
isEquivalence isEq index = record
{ refl = refl
; sym = sym
; trans = trans
}
where open IsIndexedEquivalence isEq
isPreorder : ∀ {ℓ₁ ℓ₂} {_≈_ : IRel A ℓ₁} {_∼_ : IRel A ℓ₂} →
IsIndexedPreorder A _≈_ _∼_ →
(index : I) → IsPreorder (_≈_ {index}) _∼_
isPreorder isPreorder index = record
{ isEquivalence = isEquivalence O.isEquivalence index
; reflexive = O.reflexive
; trans = O.trans
}
where module O = IsIndexedPreorder isPreorder
------------------------------------------------------------------------
-- Packages
module _ {a i} {I : Set i} where
setoid : ∀ {ℓ} → IndexedSetoid I a ℓ → I → Setoid a ℓ
setoid S index = record
{ Carrier = S.Carrier index
; _≈_ = S._≈_
; isEquivalence = isEquivalence S.isEquivalence index
}
where module S = IndexedSetoid S
preorder : ∀ {ℓ₁ ℓ₂} → IndexedPreorder I a ℓ₁ ℓ₂ → I → Preorder a ℓ₁ ℓ₂
preorder O index = record
{ Carrier = O.Carrier index
; _≈_ = O._≈_
; _∼_ = O._∼_
; isPreorder = isPreorder O.isPreorder index
}
where module O = IndexedPreorder O
------------------------------------------------------------------------
-- Some useful shorthand infix notation
module _ {a i} {I : Set i} where
_atₛ_ : ∀ {ℓ} → IndexedSetoid I a ℓ → I → Setoid a ℓ
_atₛ_ = setoid
| {
"alphanum_fraction": 0.5148285449,
"avg_line_length": 31.2753623188,
"ext": "agda",
"hexsha": "2eec4f5403ff7bf4eca32cfaf3a0db6d013442e2",
"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/Relation/Binary/Indexed/Heterogeneous/Construct/At.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/Relation/Binary/Indexed/Heterogeneous/Construct/At.agda",
"max_line_length": 73,
"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/Relation/Binary/Indexed/Heterogeneous/Construct/At.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 605,
"size": 2158
} |
{-# OPTIONS --cubical-compatible --safe #-}
data E (@0 A : Set) : Set where
c₁ c₂ : A → E A
@0 c₃ : A → E A
| {
"alphanum_fraction": 0.5221238938,
"avg_line_length": 18.8333333333,
"ext": "agda",
"hexsha": "33963342e20d10bfffe0e12c3688452f529fdaf9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Fail/Issue4638-2.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Fail/Issue4638-2.agda",
"max_line_length": 43,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue4638-2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 45,
"size": 113
} |
module Relation.Ternary.Separation.Monad.Update where
open import Level hiding (Lift)
open import Function using (_∘_; case_of_)
open import Relation.Binary.PropositionalEquality using (refl)
open import Relation.Unary
open import Relation.Unary.PredicateTransformer hiding (_⊔_; [_])
open import Relation.Ternary.Separation
open import Relation.Ternary.Separation.Monad
open import Data.Unit
open import Data.Product
module _ {a} {A : Set a} {{s : RawSep A}} {u} {{s : IsUnitalSep s u}} where
instance
⤇-monad : Monad {I = ⊤} (λ _ _ → ⤇ {p = a})
Monad.return ⤇-monad px = local λ σ → -, -, σ , px
app (Monad.bind ⤇-monad f) p σₚ = local λ fr →
let
_ , σ₁ , σ₂ = ⊎-assoc (⊎-comm σₚ) fr
Δ , Σ , σ₃ , px = update p σ₁
_ , σ₄ , σ₅ = ⊎-unassoc σ₃ σ₂
in update (app f px (⊎-comm σ₄)) σ₅
| {
"alphanum_fraction": 0.6499402628,
"avg_line_length": 34.875,
"ext": "agda",
"hexsha": "ab2c19a585af4a10c6ca651574e7cf4ccb3b9a73",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Monad/Update.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Monad/Update.agda",
"max_line_length": 75,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Monad/Update.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 293,
"size": 837
} |
module Scratch.Data.List.Relation.Helpers where
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Relation.Unary
open import Relation.Binary hiding (Decidable)
open import Data.Product
open import Data.List.Base
open import Data.List.Relation.Unary.All as All
open import Data.List.Relation.Unary.All.Properties
open import Data.List.Relation.Unary.AllPairs
module _ {a ℓ ℓ₁ ℓ₂} {A : Set a}
{R : Rel A ℓ₁} {S : Rel A ℓ₂}
{P : Pred A ℓ} (P? : Decidable P) where
filter⁺⁺ : ∀ {xs} → (∀ {x y} → P x → P y → R x y → S x y) →
AllPairs R xs → AllPairs S (filter P? xs)
filter⁺⁺ {[]} _ _ = []
filter⁺⁺ {x ∷ xs} Δ (h ∷ t) with (P? x)
... | yes p = let
hf : All (R x) (filter P? xs)
hf = filter⁺ P? h
ap : All P (filter P? xs)
ap = all-filter P? xs
w : All (P ∩ R x) (filter P? xs)
w = All.zip ( ap , hf )
y : P ∩ R x ⊆ S x
y = λ z → Δ p (proj₁ z) (proj₂ z)
z : All (S x) (filter P? xs)
z = All.map y w
in z ∷ filter⁺⁺ {xs} Δ t
... | no ¬p = filter⁺⁺ {xs} Δ t
| {
"alphanum_fraction": 0.5053061224,
"avg_line_length": 33.1081081081,
"ext": "agda",
"hexsha": "12f2036241a98554bd0b799c77b7a89afa2a09c6",
"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": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zampino/ggt",
"max_forks_repo_path": "src/scratch/Data/List/Relation/Helpers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"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": "zampino/ggt",
"max_issues_repo_path": "src/scratch/Data/List/Relation/Helpers.agda",
"max_line_length": 61,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zampino/ggt",
"max_stars_repo_path": "src/scratch/Data/List/Relation/Helpers.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:48:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-17T11:10:00.000Z",
"num_tokens": 395,
"size": 1225
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.Functor.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
private
variable
ℓC ℓC' ℓD ℓD' : Level
record Functor (C : Precategory ℓC ℓC') (D : Precategory ℓD ℓD') : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where
no-eta-equality
open Precategory
field
F-ob : C .ob → D .ob
F-hom : {x y : C .ob} → C [ x , y ] → D [(F-ob x) , (F-ob y)]
F-id : {x : C .ob} → F-hom (C .id x) ≡ D .id (F-ob x)
F-seq : {x y z : C .ob} (f : C [ x , y ]) (g : C [ y , z ]) → F-hom (f ⋆⟨ C ⟩ g) ≡ (F-hom f) ⋆⟨ D ⟩ (F-hom g)
isFull = (x y : _) (F[f] : D [(F-ob x) , (F-ob y)]) → ∃ (C [ x , y ]) (λ f → F-hom f ≡ F[f])
isFaithful = (x y : _) (f g : C [ x , y ]) → F-hom f ≡ F-hom g → f ≡ g
isEssentiallySurj = ∀ (d : D .ob) → Σ[ c ∈ C .ob ] CatIso {C = D} (F-ob c) d
private
variable
ℓ ℓ' : Level
C D E : Precategory ℓ ℓ'
open Precategory
open Functor
-- Helpful notation
-- action on objects
infix 30 _⟅_⟆
_⟅_⟆ : (F : Functor C D)
→ C .ob
→ D .ob
_⟅_⟆ = F-ob
-- action on morphisms
infix 30 _⟪_⟫ -- same infix level as on objects since these will never be used in the same context
_⟪_⟫ : (F : Functor C D)
→ ∀ {x y}
→ C [ x , y ]
→ D [(F ⟅ x ⟆) , (F ⟅ y ⟆)]
_⟪_⟫ = F-hom
-- Functor constructions
𝟙⟨_⟩ : ∀ (C : Precategory ℓ ℓ') → Functor C C
𝟙⟨ C ⟩ .F-ob x = x
𝟙⟨ C ⟩ .F-hom f = f
𝟙⟨ C ⟩ .F-id = refl
𝟙⟨ C ⟩ .F-seq _ _ = refl
-- functor composition
funcComp : ∀ (G : Functor D E) (F : Functor C D) → Functor C E
(funcComp G F) .F-ob c = G ⟅ F ⟅ c ⟆ ⟆
(funcComp G F) .F-hom f = G ⟪ F ⟪ f ⟫ ⟫
(funcComp {D = D} {E = E} {C = C} G F) .F-id {c}
= (G ⟪ F ⟪ C .id c ⟫ ⟫)
≡⟨ cong (G ⟪_⟫) (F .F-id) ⟩
G .F-id
-- (G ⟪ D .id (F ⟅ c ⟆) ⟫) -- deleted this cause the extra refl composition was annoying
-- ≡⟨ G .F-id ⟩
-- E .id (G ⟅ F ⟅ c ⟆ ⟆)
-- ∎
(funcComp {D = D} {E = E} {C = C} G F) .F-seq {x} {y} {z} f g
= (G ⟪ F ⟪ f ⋆⟨ C ⟩ g ⟫ ⟫)
≡⟨ cong (G ⟪_⟫) (F .F-seq _ _) ⟩
G .F-seq _ _
-- (G ⟪ (F ⟪ f ⟫) ⋆⟨ D ⟩ (F ⟪ g ⟫) ⟫) -- deleted for same reason as above
-- ≡⟨ G .F-seq _ _ ⟩
-- (G ⟪ F ⟪ f ⟫ ⟫) ⋆⟨ E ⟩ (G ⟪ F ⟪ g ⟫ ⟫)
-- ∎
infixr 30 funcComp
syntax funcComp G F = G ∘F F
_^opF : Functor C D → Functor (C ^op) (D ^op)
(F ^opF) .F-ob = F .F-ob
(F ^opF) .F-hom = F .F-hom
(F ^opF) .F-id = F .F-id
(F ^opF) .F-seq f g = F .F-seq g f
| {
"alphanum_fraction": 0.4957438184,
"avg_line_length": 27.4111111111,
"ext": "agda",
"hexsha": "cd7c612f4f4ee72552561977eefaec5e88df8531",
"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/Categories/Functor/Base.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/Categories/Functor/Base.agda",
"max_line_length": 115,
"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/Categories/Functor/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1198,
"size": 2467
} |
module 14-implicitConfigurations where
postulate
Integral : Set → Set
add : ∀ {A} {{ intA : Integral A }} → A → A → A
mul : ∀ {A} {{ intA : Integral A }} → A → A → A
mod : ∀ {A} {{ intA : Integral A }} → A → A → A
N : Set
zero one two three : N
nInt : Integral N
private postulate Token : Set
record Modulus (s : Token) (A : Set) : Set where
field modulus : A
data M (s : Token) (A : Set) : Set where
MkM : A → M s A
unMkM : ∀ {A s} → M s A → A
unMkM (MkM a) = a
private postulate theOnlyToken : Token
withModulus :
∀ {A} → {{ intA : Integral A }} → (modulus : A) →
(∀ {s} → {{ mod : Modulus s A }} → M s A) → A
withModulus modulus f = unMkM
(f {theOnlyToken} {{ record { modulus = modulus } }})
open Modulus {{...}}
normalize : ∀ {s A} {{intA : Integral A}} {{mod : Modulus s A}} →
A → M s A
normalize a = MkM (mod modulus a)
_+_ : ∀ {s A} {{intA : Integral A}} {{mod : Modulus s A}} →
M s A → M s A → M s A
(MkM a) + (MkM b) = normalize (add a b)
_*_ : ∀ {s A} → {{intA : Integral A}} → {{mod : Modulus s A}} →
M s A → M s A → M s A
(MkM a) * (MkM b) = normalize (mul a b)
test₁ : N
test₁ = withModulus two (let o = MkM one in (o + o)*(o + o))
testExpr : ∀ {s} → {{mod : Modulus s N}} → M s N
testExpr = let o = MkM one ; t = MkM two in
(o + t) * t
test₂ : N
test₂ = withModulus three testExpr
| {
"alphanum_fraction": 0.5357142857,
"avg_line_length": 24.9454545455,
"ext": "agda",
"hexsha": "fd33c417f37e9717873344763dc8575cb733f816",
"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": "examples/instance-arguments/14-implicitConfigurations.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": "examples/instance-arguments/14-implicitConfigurations.agda",
"max_line_length": 65,
"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": "examples/instance-arguments/14-implicitConfigurations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 530,
"size": 1372
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
------------------------------------------------------------------------------
open import Haskell.Modules.RWS.RustAnyHow
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block
import LibraBFT.Impl.Consensus.ConsensusTypes.QuorumCert as QuorumCert
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
import LibraBFT.Impl.Consensus.ConsensusTypes.VoteData as VoteData
import LibraBFT.Impl.Consensus.SafetyRules.PersistentSafetyStorage as PersistentSafetyStorage
import LibraBFT.Impl.OBM.Crypto as Crypto
open import LibraBFT.Impl.OBM.Logging.Logging
import LibraBFT.Impl.Types.BlockInfo as BlockInfo
import LibraBFT.Impl.Types.EpochChangeProof as EpochChangeProof
import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.Impl.Types.Verifier
import LibraBFT.Impl.Types.Waypoint as Waypoint
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
import LibraBFT.ImplShared.Util.Crypto as Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.PKCS
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
------------------------------------------------------------------------------
module LibraBFT.Impl.Consensus.SafetyRules.SafetyRules where
------------------------------------------------------------------------------
new : PersistentSafetyStorage → Bool → Either ErrLog SafetyRules
new persistentStorage exportConsensusKey = do
pure $ mkSafetyRules
persistentStorage
exportConsensusKey
nothing
nothing
------------------------------------------------------------------------------
signer : SafetyRules → Either ErrLog ValidatorSigner
signer self = maybeS (self ^∙ srValidatorSigner) (Left fakeErr {- error: signer not initialized -}) Right
------------------------------------------------------------------------------
extensionCheck : VoteProposal → Either ErrLog VoteData
extensionCheck voteProposal = do
let proposedBlock = voteProposal ^∙ vpBlock
obmAEP = voteProposal ^∙ vpAccumulatorExtensionProof
-- IMPL-TODO: verify .accumulator_extension_proof().verify ...
in pure
(VoteData.new
(Block.genBlockInfo
proposedBlock
-- OBM-LBFT-DIFF: completely different
(Crypto.obmHashVersion (obmAEP ^∙ aepObmNumLeaves))
(obmAEP ^∙ aepObmNumLeaves)
(voteProposal ^∙ vpNextEpochState))
(proposedBlock ^∙ bQuorumCert ∙ qcCertifiedBlock))
------------------------------------------------------------------------------
constructLedgerInfoM : Block → HashValue → LBFT (Either ErrLog LedgerInfo)
constructLedgerInfoM proposedBlock consensusDataHash = do
let block2 = proposedBlock ^∙ bRound
block1 = proposedBlock ^∙ bQuorumCert ∙ qcCertifiedBlock ∙ biRound
block0 = proposedBlock ^∙ bQuorumCert ∙ qcParentBlock ∙ biRound
commit = (block0 + 1 == block1) ∧ (block1 + 1 == block2)
commitInfo ←
if commit
then (do
let c = proposedBlock ^∙ bQuorumCert ∙ qcParentBlock
logInfo fakeInfo -- lSR (Info3ChainDetected proposedBlock c)
pure c)
else
pure BlockInfo.empty
ok (LedgerInfo∙new commitInfo consensusDataHash)
------------------------------------------------------------------------------
-- PREFERRED ROUND RULE (2nd VOTING RULE) : this avoids voting to commit a conflicting Block
verifyAndUpdatePreferredRoundM : QuorumCert → SafetyData → LBFT (Either ErrLog SafetyData)
verifyAndUpdatePreferredRoundM quorumCert safetyData = do
let preferredRound = safetyData ^∙ sdPreferredRound
oneChainRound = quorumCert ^∙ qcCertifiedBlock ∙ biRound
twoChainRound = quorumCert ^∙ qcParentBlock ∙ biRound
-- LBFT-ALGO v3:p6: "... votes in round k only if the QC inside the k proposal
-- is at least" PreferredRound."
ifD oneChainRound <? preferredRound
then bail fakeErr -- error: incorrect preferred round, QC round does not match preferred round
else do
updated ← case (compare twoChainRound preferredRound) of λ where
GT → do
logInfo fakeInfo -- updated preferred round
pure (safetyData & sdPreferredRound ∙~ twoChainRound)
LT → do
logInfo fakeInfo -- 2-chain round is lower than preferred round, but 1-chain is higher
pure safetyData
EQ →
pure safetyData
ok updated
------------------------------------------------------------------------------
verifyAuthorM : Maybe Author → LBFT (Either ErrLog Unit)
verifyAuthorM author = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr) {-(ErrL (here' ["srValidatorSigner", "Nothing"]))-} $ λ validatorSigner →
maybeSD
author
(bail fakeErr) -- (ErrL (here' ["InvalidProposal", "No author found in the proposal"])))
(\a ->
ifD validatorSigner ^∙ vsAuthor /= a
then bail fakeErr -- (ErrL (here' ["InvalidProposal", "Proposal author is not validator signer"]))
else ok unit)
where
here' : List String → List String
here' t = "SafetyRules" ∷ "verifyAuthorM" ∷ t
------------------------------------------------------------------------------
verifyEpochM : Epoch → SafetyData → LBFT (Either ErrLog Unit)
verifyEpochM epoch safetyData =
ifD epoch /= safetyData ^∙ sdEpoch
then bail fakeErr -- incorrect epoch
else ok unit
------------------------------------------------------------------------------
-- INCREASING ROUND RULE (1st VOTING RULE) : ensures voting only ONCE per round
verifyAndUpdateLastVoteRoundM : Round → SafetyData → LBFT (Either ErrLog SafetyData)
verifyAndUpdateLastVoteRoundM round safetyData =
-- LBFT-ALGO v3:p6 : "... votes in round k it if is higher than" LastVotedRound
ifD round >? (safetyData ^∙ sdLastVotedRound)
then ok (safetyData & sdLastVotedRound ∙~ round )
else bail fakeErr -- incorrect last vote round
------------------------------------------------------------------------------
verifyQcM : QuorumCert → LBFT (Either ErrLog Unit)
verifyQcM qc = do
validatorVerifier ← use (lRoundManager ∙ srValidatorVerifier)
pure (QuorumCert.verify qc validatorVerifier) ∙^∙ withErrCtx ("InvalidQuorumCertificate" ∷ [])
------------------------------------------------------------------------------
consensusState : SafetyRules → ConsensusState
consensusState self =
ConsensusState∙new (self ^∙ srPersistentStorage ∙ pssSafetyData)
(self ^∙ srPersistentStorage ∙ pssWaypoint)
------------------------------------------------------------------------------
-- ** NOTE: PAY PARTICULAR ATTENTION TO THIS FUNCTION **
-- ** Because : it is long with lots of branches, so easy to transcribe wrong. **
-- ** And if initialization is wrong, everything is wrong. **
-- TODO: convert to EitherD (and perhaps break into more steps?)
initialize : SafetyRules → EpochChangeProof → Either ErrLog SafetyRules
initialize self proof = do
let waypoint = self ^∙ srPersistentStorage ∙ pssWaypoint
lastLi ← withErrCtx' (here' ("EpochChangeProof.verify" ∷ []))
( EpochChangeProof.verify proof waypoint)
let ledgerInfo = lastLi ^∙ liwsLedgerInfo
epochState ← maybeS (ledgerInfo ^∙ liNextEpochState)
(Left fakeErr) -- ["last ledger info has no epoch state"]
pure
let currentEpoch = self ^∙ srPersistentStorage ∙ pssSafetyData ∙ sdEpoch
if-dec currentEpoch <? epochState ^∙ esEpoch
then (do
waypoint' ← withErrCtx' (here' ("Waypoint.newEpochBoundary" ∷ []))
( Waypoint.newEpochBoundary ledgerInfo)
continue1 (self & srPersistentStorage ∙ pssWaypoint ∙~ waypoint'
& srPersistentStorage ∙ pssSafetyData ∙~
SafetyData∙new (epochState ^∙ esEpoch) {-Round-} 0 {-Round-} 0 nothing)
epochState)
else continue1 self epochState
where
continue2 : SafetyRules → EpochState → Either ErrLog SafetyRules
here' : List String → List String
continue1 : SafetyRules → EpochState → Either ErrLog SafetyRules
continue1 self1 epochState =
continue2 (self1 & srEpochState ?~ epochState) epochState
continue2 self2 epochState = do
let author = self2 ^∙ srPersistentStorage ∙ pssAuthor
maybeS (ValidatorVerifier.getPublicKey (epochState ^∙ esVerifier) author)
(Left fakeErr) -- ["ValidatorNotInSet", lsA author] $
λ expectedKey → do
let currKey = eitherS (signer self2)
(const nothing)
(just ∘ ValidatorSigner.publicKey_USE_ONLY_AT_INIT)
grd‖ currKey == just expectedKey ≔
Right self2
‖ self2 ^∙ srExportConsensusKey ≔ (do
consensusKey ← withErrCtx' (here' ("ValidatorKeyNotFound" ∷ []))
(PersistentSafetyStorage.consensusKeyForVersion
(self2 ^∙ srPersistentStorage) expectedKey)
Right (self2 & srValidatorSigner ?~ ValidatorSigner∙new author consensusKey))
‖ otherwise≔
Left fakeErr -- ["srExportConsensusKey", "False", "NOT IMPLEMENTED"]
here' t = "SafetyRules" ∷ "initialize" ∷ t
abstract
initialize-e-abs = initialize
-- TODO: temporary until initialize is converted to EitherD
initialize-ed-abs : SafetyRules → EpochChangeProof → EitherD ErrLog SafetyRules
initialize-ed-abs sr ecp = fromEither $ initialize sr ecp
initialize-ed-abs-≡ : ∀ {sr ecp} → EitherD-run (initialize-ed-abs sr ecp) ≡ initialize sr ecp
initialize-ed-abs-≡ {sr} {ecp}
with initialize sr ecp
... | Left x = refl
... | Right y = refl
------------------------------------------------------------------------------
constructAndSignVoteM-continue0 : VoteProposal → ValidatorSigner → LBFT (Either ErrLog Vote)
constructAndSignVoteM-continue1 : VoteProposal → ValidatorSigner → Block → SafetyData → LBFT (Either ErrLog Vote)
constructAndSignVoteM-continue2 : VoteProposal → ValidatorSigner → Block → SafetyData → LBFT (Either ErrLog Vote)
constructAndSignVoteM : MaybeSignedVoteProposal → LBFT (Either ErrLog Vote)
constructAndSignVoteM maybeSignedVoteProposal = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr {- srValidatorSigner is nothing -}) λ validatorSigner → do
let voteProposal = maybeSignedVoteProposal ^∙ msvpVoteProposal
constructAndSignVoteM-continue0 voteProposal validatorSigner
module constructAndSignVoteM-continue0 (voteProposal : VoteProposal) (validatorSigner : ValidatorSigner) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : SafetyData → LBFT (Either ErrLog Vote)
proposedBlock = voteProposal ^∙ vpBlock
step₀ = do
safetyData0 ← use (lPersistentSafetyStorage ∙ pssSafetyData)
verifyEpochM (proposedBlock ^∙ bEpoch) safetyData0 ∙?∙ λ _ → step₁ safetyData0
step₁ safetyData0 = do
caseMD (safetyData0 ^∙ sdLastVote) of λ where
(just vote) →
ifD vote ^∙ vVoteData ∙ vdProposed ∙ biRound == proposedBlock ^∙ bRound
then ok vote
else constructAndSignVoteM-continue1 voteProposal validatorSigner proposedBlock safetyData0
nothing → constructAndSignVoteM-continue1 voteProposal validatorSigner proposedBlock safetyData0
constructAndSignVoteM-continue0 = constructAndSignVoteM-continue0.step₀
module constructAndSignVoteM-continue1
(voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData0 : SafetyData) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : LBFT (Either ErrLog Vote)
step₂ : ValidatorVerifier → LBFT (Either ErrLog Vote)
step₃ : LBFT (Either ErrLog Vote)
step₀ =
verifyQcM (proposedBlock ^∙ bQuorumCert) ∙?∙ λ _ → step₁
step₁ = do
validatorVerifier ← use (lRoundManager ∙ srValidatorVerifier)
step₂ validatorVerifier
step₂ validatorVerifier =
pure (Block.validateSignature proposedBlock validatorVerifier) ∙?∙ λ _ → step₃
step₃ =
verifyAndUpdatePreferredRoundM (proposedBlock ^∙ bQuorumCert) safetyData0 ∙?∙
constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock
constructAndSignVoteM-continue1 = constructAndSignVoteM-continue1.step₀
module constructAndSignVoteM-continue2 (voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData : SafetyData) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : SafetyData → LBFT (Either ErrLog Vote)
step₂ : SafetyData → VoteData → LBFT (Either ErrLog Vote)
step₃ : SafetyData → VoteData → Author → LedgerInfo → LBFT (Either ErrLog Vote)
step₀ =
verifyAndUpdateLastVoteRoundM (proposedBlock ^∙ bBlockData ∙ bdRound) safetyData ∙?∙ step₁
step₁ safetyData1 = do
pssSafetyData-rm ∙= safetyData1
pure (extensionCheck voteProposal) ∙?∙ (step₂ safetyData1)
step₂ safetyData1 voteData = do
let author = validatorSigner ^∙ vsAuthor
constructLedgerInfoM proposedBlock (Crypto.hashVD voteData)
∙^∙ withErrCtx ("" ∷ []) ∙?∙ (step₃ safetyData1 voteData author)
step₃ safetyData1 voteData author ledgerInfo = do
let signature = ValidatorSigner.sign validatorSigner ledgerInfo
vote = Vote.newWithSignature voteData author ledgerInfo signature
pssSafetyData-rm ∙= (safetyData1 & sdLastVote ?~ vote)
logInfo fakeInfo -- InfoUpdateLastVotedRound
ok vote
constructAndSignVoteM-continue2 = constructAndSignVoteM-continue2.step₀
------------------------------------------------------------------------------
signProposalM : BlockData → LBFT (Either ErrLog Block)
signProposalM blockData = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr) {-ErrL (here' ["srValidatorSigner", "Nothing"])-} $ λ validatorSigner → do
safetyData ← use (lPersistentSafetyStorage ∙ pssSafetyData)
verifyAuthorM (blockData ^∙ bdAuthor) ∙?∙ λ _ →
verifyEpochM (blockData ^∙ bdEpoch) safetyData ∙?∙ λ _ →
ifD blockData ^∙ bdRound ≤?ℕ safetyData ^∙ sdLastVotedRound
then bail fakeErr
-- {- ErrL (here' [ "InvalidProposal"
-- , "Proposed round is not higher than last voted round "
-- , lsR (blockData ^∙ bdRound), lsR (safetyData ^∙ sdLastVotedRound) ])-}
else do
verifyQcM (blockData ^∙ bdQuorumCert) ∙?∙ λ _ →
verifyAndUpdatePreferredRoundM (blockData ^∙ bdQuorumCert) safetyData ∙?∙ λ safetyData1 → do
pssSafetyData-rm ∙= safetyData1
let signature = ValidatorSigner.sign validatorSigner blockData
ok (Block.newProposalFromBlockDataAndSignature blockData signature)
where
here' : List String → List String
here' t = "SafetyRules" ∷ "signProposalM" ∷ t
------------------------------------------------------------------------------
signTimeoutM : Timeout → LBFT (Either ErrLog Signature)
signTimeoutM timeout = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr) {-"srValidatorSigner", "Nothing"-} $ λ validatorSigner → do
safetyData ← use (lPersistentSafetyStorage ∙ pssSafetyData)
verifyEpochM (timeout ^∙ toEpoch) safetyData ∙^∙ withErrCtx (here' []) ∙?∙ λ _ → do
ifD‖ timeout ^∙ toRound ≤? safetyData ^∙ sdPreferredRound ≔
bail fakeErr
--(ErrIncorrectPreferredRound (here []) (timeout ^∙ toRound) (safetyData ^∙ sdPreferredRound))
‖ timeout ^∙ toRound <? safetyData ^∙ sdLastVotedRound ≔
bail fakeErr
--(ErrIncorrectLastVotedRound (here []) (timeout ^∙ toRound) (safetyData ^∙ sdLastVotedRound))
‖ timeout ^∙ toRound >? safetyData ^∙ sdLastVotedRound ≔
verifyAndUpdateLastVoteRoundM (timeout ^∙ toRound) safetyData
∙^∙ withErrCtx (here' [])
∙?∙ (λ safetyData1 → do
pssSafetyData-rm ∙= safetyData1
logInfo fakeInfo -- (InfoUpdateLastVotedRound (timeout ^∙ toRound))
continue validatorSigner)
‖ otherwise≔
continue validatorSigner
where
continue : ValidatorSigner → LBFT (Either ErrLog Signature)
continue validatorSigner = do
let signature = ValidatorSigner.sign validatorSigner timeout
ok signature
here' : List String → List String
here' t = "SafetyRules" ∷ "signTimeoutM" ∷ {-lsTO timeout ∷-} t
| {
"alphanum_fraction": 0.6360827747,
"avg_line_length": 46.6168478261,
"ext": "agda",
"hexsha": "6a8d526d0d6bf9b7ba45f52b37a23911dce1dbf7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/SafetyRules/SafetyRules.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/SafetyRules/SafetyRules.agda",
"max_line_length": 114,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/SafetyRules/SafetyRules.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4323,
"size": 17155
} |
module Base.Ascription where
-- Encode infix ascription.
as' : ∀ {ℓ} (A : Set ℓ) (a : A) → A
as' _ a = a
syntax as' A a = a as A
| {
"alphanum_fraction": 0.5846153846,
"avg_line_length": 18.5714285714,
"ext": "agda",
"hexsha": "bb40eeb2e75afa497eeb070e535c18613b79571b",
"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": "Base/Ascription.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": "Base/Ascription.agda",
"max_line_length": 35,
"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": "Base/Ascription.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": 52,
"size": 130
} |
module UnifyTermL (A : Set) where
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat using (ℕ; suc; zero)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂; cong; sym; trans)
open import Function using (_∘_)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (∃; _,_; _×_)
open import Data.Empty using (⊥-elim)
data Term (n : ℕ) : Set where
i : (x : Fin n) -> Term n
leaf : A → Term n
_fork_ : (s t : Term n) -> Term n
Term-leaf-inj : ∀ {n l₁ l₂} → leaf {n} l₁ ≡ leaf l₂ → l₁ ≡ l₂
Term-leaf-inj refl = refl
_~>_ : (m n : ℕ) -> Set
m ~> n = Fin m -> Term n
▹ : ∀ {m n} -> (r : Fin m -> Fin n) -> Fin m -> Term n
▹ r = i ∘ r
_◃_ : ∀ {m n} -> (f : m ~> n) -> Term m -> Term n
f ◃ i x = f x
f ◃ (leaf l) = leaf l
f ◃ (s fork t) = (f ◃ s) fork (f ◃ t)
_≐_ : {m n : ℕ} -> (Fin m -> Term n) -> (Fin m -> Term n) -> Set
f ≐ g = ∀ x -> f x ≡ g x
◃ext : ∀ {m n} {f g : Fin m -> Term n} -> f ≐ g -> ∀ t -> f ◃ t ≡ g ◃ t
◃ext p (i x) = p x
◃ext p (leaf l) = refl
◃ext p (s fork t) = cong₂ _fork_ (◃ext p s) (◃ext p t)
_◇_ : ∀ {l m n : ℕ } -> (f : Fin m -> Term n) (g : Fin l -> Term m) -> Fin l -> Term n
f ◇ g = (f ◃_) ∘ g
≐-cong : ∀ {m n o} {f : m ~> n} {g} (h : _ ~> o) -> f ≐ g -> (h ◇ f) ≐ (h ◇ g)
≐-cong h f≐g t = cong (h ◃_) (f≐g t)
≐-sym : ∀ {m n} {f : m ~> n} {g} -> f ≐ g -> g ≐ f
≐-sym f≐g = sym ∘ f≐g
module Sub where
fact1 : ∀ {n} -> (t : Term n) -> i ◃ t ≡ t
fact1 (i x) = refl
fact1 (leaf l) = refl
fact1 (s fork t) = cong₂ _fork_ (fact1 s) (fact1 t)
fact2 : ∀ {l m n} -> (f : Fin m -> Term n) (g : _) (t : Term l)
-> (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
fact2 f g (i x) = refl
fact2 f g (leaf l) = refl
fact2 f g (s fork t) = cong₂ _fork_ (fact2 f g s) (fact2 f g t)
fact3 : ∀ {l m n} (f : Fin m -> Term n) (r : Fin l -> Fin m) -> (f ◇ (▹ r)) ≡ (f ∘ r)
fact3 f r = refl -- ext (λ _ -> refl)
◃ext' : ∀ {m n o} {f : Fin m -> Term n}{g : Fin m -> Term o}{h} -> f ≐ (h ◇ g) -> ∀ t -> f ◃ t ≡ h ◃ (g ◃ t)
◃ext' p t = trans (◃ext p t) (Sub.fact2 _ _ t)
open import Data.Maybe
open import Category.Functor
open import Category.Monad
import Level
open RawMonad (Data.Maybe.monad {Level.zero})
open import UnifyFin
check : ∀{n} (x : Fin (suc n)) (t : Term (suc n)) -> Maybe (Term n)
check x (i y) = i <$> thick x y
check x (leaf l) = just (leaf l)
check x (s fork t) = _fork_ <$> check x s ⊛ check x t
_for_ : ∀ {n} (t' : Term n) (x : Fin (suc n)) -> Fin (suc n) -> Term n
(t' for x) y = maybe′ i t' (thick x y)
data AList : ℕ -> ℕ -> Set where
anil : ∀ {n} -> AList n n
_asnoc_/_ : ∀ {m n} (σ : AList m n) (t' : Term m) (x : Fin (suc m))
-> AList (suc m) n
sub : ∀ {m n} (σ : AList m n) -> Fin m -> Term n
sub anil = i
sub (σ asnoc t' / x) = sub σ ◇ (t' for x)
_++_ : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> AList l n
ρ ++ anil = ρ
ρ ++ (σ asnoc t' / x) = (ρ ++ σ) asnoc t' / x
++-assoc : ∀ {l m n o} (ρ : AList l m) (σ : AList n _) (τ : AList o _) -> ρ ++ (σ ++ τ) ≡ (ρ ++ σ) ++ τ
++-assoc ρ σ anil = refl
++-assoc ρ σ (τ asnoc t / x) = cong (λ s -> s asnoc t / x) (++-assoc ρ σ τ)
module SubList where
anil-id-l : ∀ {m n} (σ : AList m n) -> anil ++ σ ≡ σ
anil-id-l anil = refl
anil-id-l (σ asnoc t' / x) = cong (λ σ -> σ asnoc t' / x) (anil-id-l σ)
fact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) -> sub (ρ ++ σ) ≐ (sub ρ ◇ sub σ)
fact1 ρ anil v = refl
fact1 {suc l} {m} {n} r (s asnoc t' / x) v = trans hyp-on-terms ◃-assoc
where
t = (t' for x) v
hyp-on-terms = ◃ext (fact1 r s) t
◃-assoc = Sub.fact2 (sub r) (sub s) t
_∃asnoc_/_ : ∀ {m} (a : ∃ (AList m)) (t' : Term m) (x : Fin (suc m))
-> ∃ (AList (suc m))
(n , σ) ∃asnoc t' / x = n , σ asnoc t' / x
flexFlex : ∀ {m} (x y : Fin m) -> ∃ (AList m)
flexFlex {suc m} x y with thick x y
... | just y' = m , anil asnoc i y' / x
... | nothing = suc m , anil
flexFlex {zero} () _
flexRigid : ∀ {m} (x : Fin m) (t : Term m) -> Maybe (∃(AList m))
flexRigid {suc m} x t with check x t
... | just t' = just (m , anil asnoc t' / x)
... | nothing = nothing
flexRigid {zero} () _
| {
"alphanum_fraction": 0.4899038462,
"avg_line_length": 32.7559055118,
"ext": "agda",
"hexsha": "719934e3aab8f2a4974c20affdd73bc610968064",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/UnifyTermL.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/UnifyTermL.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/UnifyTermL.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1854,
"size": 4160
} |
module Numeral.Integer.Proofs where
import Data.Either as Either
open import Data.Tuple as Tuple using (_,_)
open import Logic
import Lvl
open import Functional
open import Numeral.Integer
open import Numeral.Integer.Oper
open import Numeral.Integer.Sign
open import Numeral.Natural.Induction
open import Numeral.Natural as ℕ using (ℕ)
import Numeral.Natural.Oper as ℕ
import Numeral.Natural.Oper.Proofs as ℕ
import Numeral.Natural.Relation.Order as ℕ
import Numeral.Sign as Sign
import Numeral.Sign.Oper0 as Sign
import Numeral.Sign.Proofs as Sign
open import Lang.Inspect
open import Logic.IntroInstances
open import Logic.Propositional
open import Logic.Predicate
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Function.Domain.Proofs
open import Structure.Function.Multi
import Structure.Function.Names as Names
open import Structure.Operator
open import Structure.Operator.Group
open import Structure.Operator.Monoid
import Structure.Operator.Names as Names
open import Structure.Operator.Properties
open import Structure.Operator.Proofs
open import Structure.Operator.Ring
open import Structure.OrderedField
open import Structure.Relator.Properties
open import Syntax.Number
open import Syntax.Transitivity
open import Type
private variable ℓ : Lvl.Level
-- TODO: Prove the usual structures for ℤ
instance
[+ₙ][𝐒]-preserving : Preserving₁(+ₙ_) ℕ.𝐒 𝐒
[+ₙ][𝐒]-preserving = intro [≡]-intro
instance
[+ₙ][+]-preserving : Preserving₂(+ₙ_) (ℕ._+_) (_+_)
[+ₙ][+]-preserving = intro [≡]-intro
instance
[+ₙ][⋅]-preserving : Preserving₂(+ₙ_) (ℕ._⋅_) (_⋅_)
Preserving.proof [+ₙ][⋅]-preserving {ℕ.𝟎} {ℕ.𝟎} = [≡]-intro
Preserving.proof [+ₙ][⋅]-preserving {ℕ.𝟎} {ℕ.𝐒 y} = [≡]-intro
Preserving.proof [+ₙ][⋅]-preserving {ℕ.𝐒 x} {ℕ.𝟎} = [≡]-intro
Preserving.proof [+ₙ][⋅]-preserving {ℕ.𝐒 x} {ℕ.𝐒 y} = [≡]-intro
-- [−₀]-preserving : Preserving₂(+ₙ_) (_−₀ₙ_) (_−₀_)
-- [/₀]-preserving : Preserving₂(+ₙ_) (_/₀ₙ_) (_/₀_)
instance
[−ₙ][𝐒][𝐏]-preserving : Preserving₁(−ₙ_) ℕ.𝐒 𝐏
Preserving.proof [−ₙ][𝐒][𝐏]-preserving {ℕ.𝟎} = [≡]-intro
Preserving.proof [−ₙ][𝐒][𝐏]-preserving {ℕ.𝐒 x} = [≡]-intro
instance
[−ₙ][+]-preserving : Preserving₂(−ₙ_) (ℕ._+_) (_+_)
Preserving.proof [−ₙ][+]-preserving {ℕ.𝟎} {ℕ.𝟎} = [≡]-intro
Preserving.proof [−ₙ][+]-preserving {ℕ.𝟎} {ℕ.𝐒(_)} = [≡]-intro
Preserving.proof [−ₙ][+]-preserving {ℕ.𝐒(_)} {ℕ.𝟎} = [≡]-intro
Preserving.proof [−ₙ][+]-preserving {ℕ.𝐒(_)} {ℕ.𝐒(_)} = [≡]-intro
instance
[−][𝐒][𝐏]-preserving : Preserving₁(−_) 𝐒 𝐏
Preserving.proof [−][𝐒][𝐏]-preserving {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [−][𝐒][𝐏]-preserving {+ₙ ℕ.𝐒 x} = [≡]-intro
Preserving.proof [−][𝐒][𝐏]-preserving {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [−][𝐒][𝐏]-preserving {−𝐒ₙ ℕ.𝐒 x} = [≡]-intro
instance
[−𝐒ₙ][𝐒][𝐏]-preserving : Preserving₁(−𝐒ₙ_) ℕ.𝐒 𝐏
Preserving.proof [−𝐒ₙ][𝐒][𝐏]-preserving = [≡]-intro
instance
[+𝐒ₙ][𝐒]-preserving : Preserving₁(+𝐒ₙ_) ℕ.𝐒 𝐒
Preserving.proof [+𝐒ₙ][𝐒]-preserving = [≡]-intro
instance
[−][+]-preserving : Preserving₂(−_) (_+_)(_+_)
Preserving.proof [−][+]-preserving {x}{y} = p{x}{y} where
[−ₙ]-distribute-[−] : ∀{x y} → (−(x −ₙ y) ≡ y −ₙ x)
[−ₙ]-distribute-[−] {ℕ.𝟎} {ℕ.𝟎} = [≡]-intro
[−ₙ]-distribute-[−] {ℕ.𝟎} {ℕ.𝐒 x} = [≡]-intro
[−ₙ]-distribute-[−] {ℕ.𝐒 x} {ℕ.𝟎} = [≡]-intro
[−ₙ]-distribute-[−] {ℕ.𝐒 x} {ℕ.𝐒 y} = [−ₙ]-distribute-[−] {x} {y}
p : Names.Preserving₂(−_) (_+_)(_+_)
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
p {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {−𝐒ₙ y} = [−ₙ]-distribute-[−] {x}{y}
p {−𝐒ₙ x} {+ₙ ℕ.𝐒 y} = [−ₙ]-distribute-[−] {y}{x}
p {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
p {−𝐒ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
p {−𝐒ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
p {−𝐒ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
p {−𝐒ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
p {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
instance
[absₙ][⋅]-preserving : Preserving₂(absₙ)(_⋅_)(ℕ._⋅_)
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {−𝐒ₙ x} {−𝐒ₙ y} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [absₙ][⋅]-preserving {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
instance
[sign0][⋅]-preserving : Preserving₂(sign0)(_⋅_)(Sign._⨯_)
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {−𝐒ₙ x} {−𝐒ₙ y} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
Preserving.proof [sign0][⋅]-preserving {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
[ℤ]-non-negative-induction : ∀{P : ℤ → Type{ℓ}} → P(𝟎) → (∀(n) → P(+ₙ(n)) → P(+𝐒ₙ(n))) → (∀{n} → P(+ₙ n))
[ℤ]-non-negative-induction {P = P} = [ℕ]-induction {φ = P ∘ +ₙ_}
[ℤ]-positive-induction : ∀{P : ℤ → Type{ℓ}} → P(+𝐒ₙ(ℕ.𝟎)) → (∀(n) → P(+𝐒ₙ(n)) → P(+𝐒ₙ(ℕ.𝐒(n)))) → (∀{n} → P(+𝐒ₙ n))
[ℤ]-positive-induction {P = P} [1] [+] {ℕ.𝟎} = [1]
[ℤ]-positive-induction {P = P} [1] [+] {ℕ.𝐒 n} = [+] n ([ℤ]-positive-induction {P = P} [1] [+] {n})
[ℤ]-non-positive-induction : ∀{P : ℤ → Type{ℓ}} → P(𝟎) → (∀(n) → P(−ₙ(n)) → P(−𝐒ₙ(n))) → (∀{n} → P(−ₙ n))
[ℤ]-non-positive-induction {P = P} [0] [−] {ℕ.𝟎} = [0]
[ℤ]-non-positive-induction {P = P} [0] [−] {ℕ.𝐒 n} = [−] n ([ℤ]-non-positive-induction {P = P} [0] [−] {n})
[ℤ]-negative-induction : ∀{P : ℤ → Type{ℓ}} → P(−𝐒ₙ(ℕ.𝟎)) → (∀(n) → P(−𝐒ₙ(n)) → P(−𝐒ₙ(ℕ.𝐒(n)))) → (∀{n} → P(−𝐒ₙ n))
[ℤ]-negative-induction {P = P} = [ℕ]-induction {φ = P ∘ −𝐒ₙ_}
-- An intuitive induction proof method on integers
[ℤ]-intuitive-induction : ∀{P : ℤ → Type{ℓ}} → (∀{n} → P(−ₙ n) → P(−𝐒ₙ(n))) → P(𝟎) → (∀{n} → P(+ₙ n) → P(+𝐒ₙ(n))) → (∀{n} → P(n))
[ℤ]-intuitive-induction {P = P} [−] [0] [+] {𝟎} = [0]
[ℤ]-intuitive-induction {P = P} [−] [0] [+] {+𝐒ₙ(n)} = [+] ([ℤ]-intuitive-induction {P = P} [−] [0] [+] {+ₙ n})
[ℤ]-intuitive-induction {P = P} [−] [0] [+] {−𝐒ₙ(ℕ.𝟎)} = [−] ([0])
[ℤ]-intuitive-induction {P = P} [−] [0] [+] {−𝐒ₙ(ℕ.𝐒(n))} = [−] ([ℤ]-intuitive-induction {P = P} [−] [0] [+] {−𝐒ₙ(n)})
[−𝐒ₙ]-equality : ∀{n} → (−𝐒ₙ(n) ≡ −ₙ(ℕ.𝐒(n)))
[−𝐒ₙ]-equality = [≡]-intro
[+𝐒ₙ]-equality : ∀{n} → (+𝐒ₙ(n) ≡ +ₙ(ℕ.𝐒(n)))
[+𝐒ₙ]-equality = [≡]-intro
-- (−n)−1 = −(n+1)
[𝐏]-negative : ∀{n} → (𝐏(−ₙ n) ≡ −𝐒ₙ(n))
[𝐏]-negative {ℕ.𝟎} = [≡]-intro
[𝐏]-negative {ℕ.𝐒(n)} = [≡]-intro
-- (−(n+1))+1 = −n
[𝐒][−𝐒ₙ]-negative-identity : ∀{n} → (𝐒(−𝐒ₙ(n)) ≡ −ₙ n)
[𝐒][−𝐒ₙ]-negative-identity {ℕ.𝟎} = [≡]-intro
[𝐒][−𝐒ₙ]-negative-identity {ℕ.𝐒(n)} = [≡]-intro
instance
[𝐒][𝐏]-inverse : Inverse(𝐒)(𝐏)
Inverseᵣ.proof (Tuple.left [𝐒][𝐏]-inverse) {+ₙ ℕ.𝟎} = [≡]-intro
Inverseᵣ.proof (Tuple.left [𝐒][𝐏]-inverse) {+ₙ ℕ.𝐒 x} = [≡]-intro
Inverseᵣ.proof (Tuple.left [𝐒][𝐏]-inverse) {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Inverseᵣ.proof (Tuple.left [𝐒][𝐏]-inverse) {−𝐒ₙ ℕ.𝐒 x} = [≡]-intro
Inverseᵣ.proof (Tuple.right [𝐒][𝐏]-inverse) {+ₙ ℕ.𝟎} = [≡]-intro
Inverseᵣ.proof (Tuple.right [𝐒][𝐏]-inverse) {+ₙ ℕ.𝐒 x} = [≡]-intro
Inverseᵣ.proof (Tuple.right [𝐒][𝐏]-inverse) {−𝐒ₙ ℕ.𝟎} = [≡]-intro
Inverseᵣ.proof (Tuple.right [𝐒][𝐏]-inverse) {−𝐒ₙ ℕ.𝐒 x} = [≡]-intro
[−ₙ]-identityᵣ : ∀{x} → (x −ₙ ℕ.𝟎 ≡ +ₙ x)
[−ₙ]-identityᵣ = [≡]-intro
[−ₙ]-antiidentityₗ : ∀{x} → (ℕ.𝟎 −ₙ x ≡ −ₙ x)
[−ₙ]-antiidentityₗ {ℕ.𝟎} = [≡]-intro
[−ₙ]-antiidentityₗ {ℕ.𝐒(_)} = [≡]-intro
[−ₙ][𝐒]-step : ∀{x y} → (ℕ.𝐒(x) −ₙ y ≡ 𝐒(x −ₙ y))
[−ₙ][𝐒]-step {ℕ.𝟎} {ℕ.𝟎} = [≡]-intro
[−ₙ][𝐒]-step {ℕ.𝟎} {ℕ.𝐒(y)} = [−ₙ]-antiidentityₗ {y} 🝖 symmetry(_≡_) ([𝐒][−𝐒ₙ]-negative-identity{y})
[−ₙ][𝐒]-step {ℕ.𝐒(_)}{ℕ.𝟎} = [≡]-intro
[−ₙ][𝐒]-step {ℕ.𝐒(x)}{ℕ.𝐒(y)} = [−ₙ][𝐒]-step {x}{y}
[−][−ₙ] : ∀{x} → (−(+ₙ x) ≡ −ₙ x)
[−][−ₙ] {ℕ.𝟎} = [≡]-intro
[−][−ₙ] {ℕ.𝐒(_)} = [≡]-intro
instance
[+ₙ]-injectivity : Injective(+ₙ_)
Injective.proof [+ₙ]-injectivity [≡]-intro = [≡]-intro
instance
[−𝐒ₙ]-injectivity : Injective(−𝐒ₙ_)
Injective.proof [−𝐒ₙ]-injectivity [≡]-intro = [≡]-intro
instance
[−ₙ]-injectivity : Injective(−ₙ_)
Injective.proof [−ₙ]-injectivity {ℕ.𝟎} {ℕ.𝟎} xy = [≡]-intro
Injective.proof [−ₙ]-injectivity {ℕ.𝐒 x} {ℕ.𝐒 .x} [≡]-intro = [≡]-intro
instance
[+𝐒ₙ]-injectivity : Injective(+𝐒ₙ_)
Injective.proof [+𝐒ₙ]-injectivity [≡]-intro = [≡]-intro
[−ₙ]-self : ∀{x} → (x −ₙ x ≡ 𝟎)
[−ₙ]-self {ℕ.𝟎} = [≡]-intro
[−ₙ]-self {ℕ.𝐒(x)} = [−ₙ]-self {x}
instance
[+]-commutativity : Commutativity(_+_)
[+]-commutativity = intro(\{x y} → p{x}{y}) where
p : Names.Commutativity(_+_)
p {+ₙ x} {+ₙ y} = congruence₁(+ₙ_) (commutativity(ℕ._+_) {x}{y})
p {+ₙ _} {−𝐒ₙ _} = [≡]-intro
p {−𝐒ₙ _} {+ₙ _} = [≡]-intro
p {−𝐒ₙ x} {−𝐒ₙ y} = congruence₁(−𝐒ₙ_ ∘ ℕ.𝐒) (commutativity(ℕ._+_) {x}{y})
instance
[+]-identityₗ : Identityₗ(_+_)(𝟎)
Identityₗ.proof [+]-identityₗ {+ₙ _} = [≡]-intro
Identityₗ.proof [+]-identityₗ {−𝐒ₙ _} = [≡]-intro
instance
[+]-identityᵣ : Identityᵣ(_+_)(𝟎)
Identityᵣ.proof [+]-identityᵣ {+ₙ _} = [≡]-intro
Identityᵣ.proof [+]-identityᵣ {−𝐒ₙ _} = [≡]-intro
instance
[+]-identity : Identity(_+_)(𝟎)
[+]-identity = intro
instance
[+]-inverseFunctionₗ : InverseFunctionₗ(_+_)(−_)
InverseFunctionₗ.proof [+]-inverseFunctionₗ {+ₙ ℕ.𝟎} = [≡]-intro
InverseFunctionₗ.proof [+]-inverseFunctionₗ {+ₙ ℕ.𝐒(x)} = [−ₙ]-self {x}
InverseFunctionₗ.proof [+]-inverseFunctionₗ {−𝐒ₙ(x)} = [−ₙ]-self {x}
instance
[+]-inverseFunctionᵣ : InverseFunctionᵣ(_+_)(−_)
InverseFunctionᵣ.proof [+]-inverseFunctionᵣ {+ₙ ℕ.𝟎} = [≡]-intro
InverseFunctionᵣ.proof [+]-inverseFunctionᵣ {+ₙ ℕ.𝐒(x)} = [−ₙ]-self {x}
InverseFunctionᵣ.proof [+]-inverseFunctionᵣ {−𝐒ₙ(x)} = [−ₙ]-self {x}
instance
[+]-inverseFunction : InverseFunction(_+_)(−_)
[+]-inverseFunction = intro
instance
[−]-involution : Involution(−_)
Involution.proof [−]-involution {+ₙ ℕ.𝟎} = [≡]-intro
Involution.proof [−]-involution {+ₙ ℕ.𝐒(x)} = [≡]-intro
Involution.proof [−]-involution {−𝐒ₙ x} = [≡]-intro
instance
[−]-injectivity : Injective(−_)
Injective.proof [−]-injectivity {a}{b} p =
a 🝖[ _≡_ ]-[ involution(−_) ]-sym
−(− a) 🝖[ _≡_ ]-[ congruence₁(−_) p ]
−(− b) 🝖[ _≡_ ]-[ involution(−_) ]
b 🝖-end
instance
[−]-surjectivity : Surjective(−_)
Surjective.proof [−]-surjectivity {y} = [∃]-intro (− y) ⦃ involution(−_) ⦄
instance
[−]-bijectivity : Bijective(−_)
[−]-bijectivity = injective-surjective-to-bijective(−_)
instance
abs-idempotent : Idempotent(abs)
Idempotent.proof abs-idempotent {+ₙ x} = [≡]-intro
Idempotent.proof abs-idempotent {−𝐒ₙ x} = [≡]-intro
abs-injective-zero : ∀{n} → (abs(n) ≡ 𝟎) → (n ≡ 𝟎)
abs-injective-zero {𝟎} [≡]-intro = [≡]-intro
abs-[−] : ∀{n} → (abs(− n) ≡ abs(n))
abs-[−] {𝟎} = [≡]-intro
abs-[−] {+𝐒ₙ(_)} = [≡]-intro
abs-[−] {−𝐒ₙ(_)} = [≡]-intro
abs-preserving : ∀{x} → (abs(x) ≡ +ₙ(absₙ(x)))
abs-preserving {𝟎} = [≡]-intro
abs-preserving {+𝐒ₙ(_)} = [≡]-intro
abs-preserving {−𝐒ₙ(_)} = [≡]-intro
absₙ-zero : ∀{n} → (absₙ(n) ≡ ℕ.𝟎) → (n ≡ 𝟎)
absₙ-zero {𝟎} ([≡]-intro) = [≡]-intro
[+][𝐒]-stepₗ : ∀{x y} → (𝐒(x) + y ≡ 𝐒(x + y))
[+][𝐒]-stepₗ {+ₙ x} {+ₙ y} = [≡]-intro
[+][𝐒]-stepₗ {+ₙ ℕ.𝟎 } {−𝐒ₙ ℕ.𝟎 } = [≡]-intro
[+][𝐒]-stepₗ {+ₙ ℕ.𝟎 } {−𝐒ₙ ℕ.𝐒(_)} = [≡]-intro
[+][𝐒]-stepₗ {+ₙ ℕ.𝐒(_)} {−𝐒ₙ ℕ.𝟎 } = [≡]-intro
[+][𝐒]-stepₗ {+ₙ ℕ.𝐒(x)} {−𝐒ₙ ℕ.𝐒(y)} = [−ₙ][𝐒]-step{x}{ℕ.𝐒(y)}
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝟎 } {+ₙ ℕ.𝟎 } = [≡]-intro
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝐒(_)} {+ₙ ℕ.𝟎 } = [≡]-intro
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝟎 } {+ₙ ℕ.𝐒(_)} = [≡]-intro
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝐒(y)} {+ₙ ℕ.𝐒(x)} = [−ₙ][𝐒]-step{x}{ℕ.𝐒(y)}
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝟎 } {−𝐒ₙ ℕ.𝟎 } = [≡]-intro
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝐒(_)} {−𝐒ₙ ℕ.𝟎 } = [≡]-intro
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝟎 } {−𝐒ₙ ℕ.𝐒(_)} = [≡]-intro
[+][𝐒]-stepₗ {−𝐒ₙ ℕ.𝐒(y)} {−𝐒ₙ ℕ.𝐒(x)} = [≡]-intro
instance
[𝐒]-preserving-[+]ₗ : ∀{y} → Preserving₁(𝐒) (_+ y)(_+ y)
Preserving.proof ([𝐒]-preserving-[+]ₗ {y}) {x} = symmetry(_≡_) ([+][𝐒]-stepₗ {x}{y})
[+][𝐒]-stepᵣ : ∀{x y} → (x + 𝐒(y) ≡ 𝐒(x + y))
[+][𝐒]-stepᵣ {+ₙ x} {+ₙ y} = [≡]-intro
[+][𝐒]-stepᵣ {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
[+][𝐒]-stepᵣ {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 x} = [≡]-intro
[+][𝐒]-stepᵣ {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
[+][𝐒]-stepᵣ {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [+][𝐒]-stepᵣ {−𝐒ₙ y}{+ₙ x}
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [+][𝐒]-stepᵣ {−𝐒ₙ x}{+ₙ y}
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
[+][𝐒]-stepᵣ {−𝐒ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
instance
[𝐒]-preserving-[+]ᵣ : ∀{x} → Preserving₁(𝐒) (_+_ x)(_+_ x)
Preserving.proof ([𝐒]-preserving-[+]ᵣ {x}) {y} = symmetry(_≡_) ([+][𝐒]-stepᵣ {x}{y})
[+][𝐏]-stepₗ : ∀{x y} → (𝐏(x) + y ≡ 𝐏(x + y))
[+][𝐏]-stepₗ {x}{y} =
𝐏(x) + y 🝖[ _≡_ ]-[ congruence₂(_+_) (congruence₁(𝐏) (involution(−_) {x})) (involution(−_) {y}) ]-sym
𝐏(−(− x)) + (−(− y)) 🝖[ _≡_ ]-[ congruence₂ₗ(_+_)(−(− y)) (preserving₁(−_)(𝐒)(𝐏) {− x}) ]-sym
(− 𝐒(− x)) + (−(− y)) 🝖[ _≡_ ]-[ preserving₂(−_)(_+_)(_+_) {𝐒(− x)}{− y} ]-sym
−(𝐒(− x) + (− y)) 🝖[ _≡_ ]-[ congruence₁(−_) ([+][𝐒]-stepₗ {− x}{− y}) ]
−(𝐒((− x) + (− y))) 🝖[ _≡_ ]-[ preserving₁(−_)(𝐒)(𝐏) ]
𝐏(−((− x) + (− y))) 🝖[ _≡_ ]-[ congruence₁(𝐏) (preserving₂(−_)(_+_)(_+_) {− x}{− y}) ]
𝐏(((−(− x)) + (−(− y)))) 🝖[ _≡_ ]-[ congruence₁(𝐏) (congruence₂(_+_) (involution(−_) {x}) (involution(−_) {y})) ]
𝐏(x + y) 🝖-end
instance
[𝐏]-preserving-[+]ₗ : ∀{y} → Preserving₁(𝐏) (_+ y)(_+ y)
Preserving.proof ([𝐏]-preserving-[+]ₗ {y}) {x} = symmetry(_≡_) ([+][𝐏]-stepₗ {x}{y})
[+][𝐏]-stepᵣ : ∀{x y} → (x + 𝐏(y) ≡ 𝐏(x + y))
[+][𝐏]-stepᵣ {x}{y} =
x + 𝐏(y) 🝖[ _≡_ ]-[ congruence₂(_+_) (involution(−_) {x}) (congruence₁(𝐏) (involution(−_) {y})) ]-sym
(−(− x)) + 𝐏(−(− y)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(−(− x)) (preserving₁(−_)(𝐒)(𝐏) {− y}) ]-sym
(−(− x)) + (− 𝐒(− y)) 🝖[ _≡_ ]-[ preserving₂(−_)(_+_)(_+_) {− x}{𝐒(− y)} ]-sym
−((− x) + 𝐒(− y)) 🝖[ _≡_ ]-[ congruence₁(−_) ([+][𝐒]-stepᵣ {− x}{− y}) ]
−(𝐒((− x) + (− y))) 🝖[ _≡_ ]-[ preserving₁(−_)(𝐒)(𝐏) ]
𝐏(−((− x) + (− y))) 🝖[ _≡_ ]-[ congruence₁(𝐏) (preserving₂(−_)(_+_)(_+_) {− x}{− y}) ]
𝐏(((−(− x)) + (−(− y)))) 🝖[ _≡_ ]-[ congruence₁(𝐏) (congruence₂(_+_) (involution(−_) {x}) (involution(−_) {y})) ]
𝐏(x + y) 🝖-end
instance
[𝐏]-preserving-[+]ᵣ : ∀{x} → Preserving₁(𝐏) (_+_ x)(_+_ x)
Preserving.proof ([𝐏]-preserving-[+]ᵣ {x}) {y} = symmetry(_≡_) ([+][𝐏]-stepᵣ {x}{y})
[−]-of-[+𝐒ₙ] : ∀{x y} → (+𝐒ₙ x) − (+𝐒ₙ y) ≡ (+ₙ x) − (+ₙ y)
[−]-of-[+𝐒ₙ] {y = ℕ.𝟎} = [≡]-intro
[−]-of-[+𝐒ₙ] {y = ℕ.𝐒 _} = [≡]-intro
[+ₙ][−₀][−]-preserving : ∀{x y} → (x ℕ.≥ y) → ((+ₙ(x ℕ.−₀ y)) ≡ ((+ₙ x) − (+ₙ y)))
[+ₙ][−₀][−]-preserving ℕ.min = [≡]-intro
[+ₙ][−₀][−]-preserving {ℕ.𝐒 x}{ℕ.𝐒 y} (ℕ.succ p) = [+ₙ][−₀][−]-preserving {x}{y} p 🝖 symmetry(_≡_) ([−]-of-[+𝐒ₙ] {x}{y})
[−ₙ]-on-[+]ₗ-redundancy : ∀{a b c} → ((a ℕ.+ b) −ₙ (a ℕ.+ c) ≡ b −ₙ c)
[−ₙ]-on-[+]ₗ-redundancy{ℕ.𝟎} {b}{c} = [≡]-intro
[−ₙ]-on-[+]ₗ-redundancy{ℕ.𝐒 a}{b}{c} = [−ₙ]-on-[+]ₗ-redundancy{a}{b}{c}
instance
[+]-associativity : Associativity(_+_)
[+]-associativity = intro(\{x y z} → p{x}{y}{z}) where
postulate p : Names.Associativity(_+_)
{-p {x} {y} {𝟎} =
(x + y) + 𝟎 🝖[ _≡_ ]-[ identityᵣ(_+_)(𝟎) ]
x + y 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x) (identityᵣ(_+_)(𝟎)) ]-sym
x + (y + 𝟎) 🝖-end
p {x} {y} {+𝐒ₙ z} =
(x + y) + (+𝐒ₙ(z)) 🝖[ _≡_ ]-[]
(x + y) + 𝐒(+ₙ(z)) 🝖[ _≡_ ]-[ [+][𝐒]-stepᵣ {x + y}{+ₙ(z)} ]
𝐒((x + y) + (+ₙ(z))) 🝖[ _≡_ ]-[ congruence₁(𝐒) (p{x}{y}{+ₙ z}) ]
𝐒(x + (y + (+ₙ(z)))) 🝖[ _≡_ ]-[ [+][𝐒]-stepᵣ {x}{y + (+ₙ z)} ]-sym
x + 𝐒(y + (+ₙ(z))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x) ([+][𝐒]-stepᵣ {y}{+ₙ z}) ]-sym
x + (y + 𝐒(+ₙ(z))) 🝖[ _≡_ ]-[]
x + (y + (+𝐒ₙ(z))) 🝖-end
p {x} {y} {−𝐒ₙ z} =
(x + y) + (−𝐒ₙ(z)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x + y) [𝐏]-negative ]-sym
(x + y) + 𝐏(−ₙ(z)) 🝖[ _≡_ ]-[ [+][𝐏]-stepᵣ {x + y}{−ₙ(z)} ]
𝐏((x + y) + (−ₙ(z))) 🝖[ _≡_ ]-[ congruence₁(𝐏) (p{x}{y}{−ₙ z}) ]
𝐏(x + (y + (−ₙ(z)))) 🝖[ _≡_ ]-[ [+][𝐏]-stepᵣ {x}{y + (−ₙ z)} ]-sym
x + 𝐏(y + (−ₙ(z))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x) ([+][𝐏]-stepᵣ {y}{−ₙ z}) ]-sym
x + (y + 𝐏(−ₙ(z))) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x) (congruence₂ᵣ(_+_)(y) [𝐏]-negative) ]
x + (y + (−𝐒ₙ(z))) 🝖-end
-}
instance
[+]-monoid : Monoid(_+_)
[+]-monoid = intro
instance
[+]-group : Group(_+_)
[+]-group = intro
instance
[+]-commutative-group : CommutativeGroup(_+_)
[+]-commutative-group = intro
absₙ-of-[⋅] : ∀{x y} → (absₙ(x ⋅ y) ≡ absₙ(x) ℕ.⋅ absₙ(y))
absₙ-of-[⋅] {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
absₙ-of-[⋅] {−𝐒ₙ x} {−𝐒ₙ y} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
absₙ-of-[⋅] {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
absₙ-of-[⋅] {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
absₙ-of-[⋅] {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
absₙ-of-[⋅] {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
absₙ-of-[⋅] {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
sign-of-[⋅] : ∀{x y} → (sign0(x ⋅ y) ≡ sign0(x) Sign.⨯ sign0(y))
sign-of-[⋅] {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
sign-of-[⋅] {−𝐒ₙ x} {−𝐒ₙ y} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝟎} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝟎} = [≡]-intro
sign-of-[⋅] {+ₙ ℕ.𝐒 x} {−𝐒ₙ ℕ.𝐒 y} = [≡]-intro
sign-of-[⋅] {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
sign-of-[⋅] {−𝐒ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} = [≡]-intro
sign-of-[⋅] {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} = [≡]-intro
sign-of-[⋅] {−𝐒ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} = [≡]-intro
signed-inverse : ∀{x} → (signed0 (sign0 x) (absₙ x) ≡ x)
signed-inverse {+𝐒ₙ _} = [≡]-intro
signed-inverse {𝟎} = [≡]-intro
signed-inverse {−𝐒ₙ _} = [≡]-intro
sign0-inverse : ∀{x}{y} → (sign0(signed0 x (ℕ.𝐒(y))) ≡ x)
sign0-inverse {Sign.➕} {y} = [≡]-intro
sign0-inverse {Sign.𝟎} {y} = [≡]-intro
sign0-inverse {Sign.➖} {y} = [≡]-intro
absₙ-inverse : ∀{x}{y} → (x ≢ Sign.𝟎) → (absₙ(signed0 x y) ≡ y)
absₙ-inverse {Sign.➕} {ℕ.𝟎} _ = [≡]-intro
absₙ-inverse {Sign.➕} {ℕ.𝐒 y} _ = [≡]-intro
absₙ-inverse {Sign.➖} {ℕ.𝟎} _ = [≡]-intro
absₙ-inverse {Sign.➖} {ℕ.𝐒 y} _ = [≡]-intro
absₙ-inverse {Sign.𝟎} {ℕ.𝟎} _ = [≡]-intro
absₙ-inverse {Sign.𝟎} {ℕ.𝐒 y} p with () ← p [≡]-intro
absₙ-of-[−ₙ] : ∀{x} → (absₙ(−ₙ x) ≡ x)
absₙ-of-[−ₙ] {ℕ.𝟎} = [≡]-intro
absₙ-of-[−ₙ] {ℕ.𝐒 x} = [≡]-intro
[⋅]-equality : ∀{x y z} → (x ⋅ y ≡ z) ↔ (sign0(x) Sign.⨯ sign0(y) ≡ sign0 z) ∧ (absₙ(x) ℕ.⋅ absₙ(y) ≡ absₙ(z))
[⋅]-equality {x}{y}{z} = [↔]-intro (Tuple.uncurry l) r where
l : ∀{x y z} → (sign0(x) Sign.⨯ sign0(y) ≡ sign0 z) → (absₙ(x) ℕ.⋅ absₙ(y) ≡ absₙ(z)) → (x ⋅ y ≡ z)
l{x}{y}{z} p q = congruence₂(signed0) p q 🝖 signed-inverse
r : ∀{x y z} → (x ⋅ y ≡ z) → (sign0(x) Sign.⨯ sign0(y) ≡ sign0 z) ∧ (absₙ(x) ℕ.⋅ absₙ(y) ≡ absₙ(z))
r{x}{y}{z} p = [∧]-intro (symmetry(_≡_) (preserving₂(sign0)(_⋅_)(Sign._⨯_)) 🝖 congruence₁(sign0) p) (symmetry(_≡_) (preserving₂(absₙ)(_⋅_)(ℕ._⋅_) {x}{y}) 🝖 congruence₁(absₙ) p)
instance
[⋅]-identityₗ : Identityₗ(_⋅_)(𝟏)
Identityₗ.proof [⋅]-identityₗ {x} with sign0 x | x
... | Sign.➕ | 𝟎 = [≡]-intro
... | Sign.➕ | +𝐒ₙ _ = [≡]-intro
... | Sign.➕ | −𝐒ₙ _ = [≡]-intro
... | Sign.𝟎 | 𝟎 = [≡]-intro
... | Sign.𝟎 | +𝐒ₙ _ = [≡]-intro
... | Sign.𝟎 | −𝐒ₙ _ = [≡]-intro
... | Sign.➖ | 𝟎 = [≡]-intro
... | Sign.➖ | +𝐒ₙ _ = [≡]-intro
... | Sign.➖ | −𝐒ₙ _ = [≡]-intro
instance
[⋅]-identityᵣ : Identityᵣ(_⋅_)(𝟏)
Identityᵣ.proof [⋅]-identityᵣ {x} with sign0 x | x
... | Sign.➕ | 𝟎 = [≡]-intro
... | Sign.➕ | +𝐒ₙ _ = [≡]-intro
... | Sign.➕ | −𝐒ₙ _ = [≡]-intro
... | Sign.𝟎 | 𝟎 = [≡]-intro
... | Sign.𝟎 | +𝐒ₙ _ = [≡]-intro
... | Sign.𝟎 | −𝐒ₙ _ = [≡]-intro
... | Sign.➖ | 𝟎 = [≡]-intro
... | Sign.➖ | +𝐒ₙ _ = [≡]-intro
... | Sign.➖ | −𝐒ₙ _ = [≡]-intro
instance
[⋅]-commutativity : Commutativity(_⋅_)
Commutativity.proof [⋅]-commutativity {x}{y} = congruence₂(signed0) (commutativity(Sign._⨯_)) (commutativity(ℕ._⋅_) {absₙ x}{absₙ y})
instance
postulate [⋅]-associativity : Associativity(_⋅_)
{-Associativity.proof [⋅]-associativity {x}{y}{z} =
congruence₂(signed0)
(congruence₂ₗ(Sign._⨯_)(sign0 z) sign0-inverse 🝖 associativity(Sign._⨯_) 🝖 symmetry(_≡_) (congruence₂ᵣ(Sign._⨯_)(sign0(x)) (sign-of-[⋅] {y}{z})))
(congruence₂ₗ(ℕ._⋅_) (absₙ(z)) (absₙ-inverse{sign0(x) Sign.⨯ sign0(y)}{absₙ(x) ℕ.⋅ absₙ(y)}) 🝖 associativity(ℕ._⋅_){absₙ x}{absₙ y}{absₙ z} 🝖 symmetry(_≡_) (congruence₂ᵣ(ℕ._⋅_) (absₙ (x)) (absₙ-of-[⋅] {y}{z})))
-}
instance
postulate [⋅][+]-distributivityₗ : Distributivityₗ(_⋅_)(_+_)
{-[⋅][+]-distributivityₗ = intro p where
p : Names.Distributivityₗ(_⋅_)(_+_)
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 z} = [≡]-intro
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} {+ₙ ℕ.𝐒 z} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 z} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} {+ₙ ℕ.𝐒 z} = {!!}
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} {−𝐒ₙ z} = [≡]-intro
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} {−𝐒ₙ z} = {!!}
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} {−𝐒ₙ z} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} {−𝐒ₙ z} = {!!}
p {+ₙ ℕ.𝟎} {−𝐒ₙ y} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝟎} {−𝐒ₙ y} {+ₙ ℕ.𝐒 z} = {!!}
p {+ₙ ℕ.𝐒 x} {−𝐒ₙ y} {+ₙ ℕ.𝟎} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {−𝐒ₙ y} {+ₙ ℕ.𝐒 z} = {!!}
p {+ₙ ℕ.𝟎} {−𝐒ₙ y} {−𝐒ₙ z} = [≡]-intro
p {+ₙ ℕ.𝐒 x} {−𝐒ₙ y} {−𝐒ₙ z} = {!!}
p {−𝐒ₙ x} {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} = [≡]-intro
p {−𝐒ₙ x} {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 z} = [≡]-intro
p {−𝐒ₙ x} {+ₙ ℕ.𝐒 y} {+ₙ ℕ.𝟎} = [≡]-intro
p {−𝐒ₙ x} {+ₙ ℕ.𝐒 y} {+ₙ ℕ.𝐒 z} = {!!}
p {−𝐒ₙ x} {+ₙ ℕ.𝟎} {−𝐒ₙ z} = [≡]-intro
p {−𝐒ₙ x} {+ₙ ℕ.𝐒 y} {−𝐒ₙ z} = {!!}
p {−𝐒ₙ x} {−𝐒ₙ y} {+ₙ ℕ.𝟎} = [≡]-intro
p {−𝐒ₙ x} {−𝐒ₙ y} {+ₙ ℕ.𝐒 z} = {!!}
p {−𝐒ₙ x} {−𝐒ₙ y} {−𝐒ₙ z} = {!!}-}
{-
x ⋅ (y + z) 🝖[ _≡_ ]-[]
signed0 ((sign0 x) Sign.⨯ (sign0(y + z))) ((absₙ x) ℕ.⋅ (absₙ(y + z))) 🝖[ _≡_ ]-[ {!congruence₂(signed0) ? ?!} ]
signed0 ((sign0 x) Sign.⨯ sign0(y + z)) ((absₙ x) ℕ.⋅ (absₙ(y + z))) 🝖[ _≡_ ]-[ {!!} ]
(signed0 ((sign0 x) Sign.⨯ (sign0 y)) ((absₙ x) ℕ.⋅ (absₙ y))) + (signed0 ((sign0 x) Sign.⨯ (sign0 z)) ((absₙ x) ℕ.⋅ (absₙ z))) 🝖[ _≡_ ]-[]
(x ⋅ y) + (x ⋅ z) 🝖-end
where
sign0-proof : ∀{x y z} → ((sign0 x) Sign.⨯ sign0(y + z) ≡ (sign0(x) + sign0(z)) Sign.⨯ (sign0(x) + sign0(z)))
-}
instance
postulate [⋅][+]-distributivityᵣ : Distributivityᵣ(_⋅_)(_+_)
instance
postulate [⋅][−]-distributivityₗ : Distributivityₗ(_⋅_)(_−_)
instance
postulate [⋅][−]-distributivityᵣ : Distributivityᵣ(_⋅_)(_−_)
instance
[+][⋅]-rng : Rng(_+_)(_⋅_)
[+][⋅]-rng = record{}
instance
[+][⋅]-ring-unity : Unity(_+_)(_⋅_)
Unity.[⋅]-identity-existence [+][⋅]-ring-unity = [∃]-intro 𝟏 ⦃ intro ⦄
instance
[+][⋅]-ring : Ring(_+_)(_⋅_)
[+][⋅]-ring = record{}
import Numeral.Natural.Relation.Order as ℕ
import Numeral.Natural.Relation.Order.Proofs as ℕ
import Structure.Relator.Ordering as Structure
data _≤_ : ℤ → ℤ → Type{Lvl.𝟎} where
pos : ∀{a b} → (a ℕ.≤ b) → ((+ₙ a) ≤ (+ₙ b))
neg : ∀{a b} → (a ℕ.≥ b) → ((−𝐒ₙ a) ≤ (−𝐒ₙ b))
mix : ∀{a b} → ((−𝐒ₙ a) ≤ (+ₙ b))
instance
[≤]-reflexivity : Reflexivity(_≤_)
Reflexivity.proof [≤]-reflexivity {+ₙ x} = pos (reflexivity(ℕ._≤_))
Reflexivity.proof [≤]-reflexivity {−𝐒ₙ x} = neg (reflexivity(ℕ._≤_))
instance
[≤]-transitivity : Transitivity(_≤_)
Transitivity.proof [≤]-transitivity (pos p) (pos q) = pos(transitivity(ℕ._≤_) p q)
Transitivity.proof [≤]-transitivity (neg p) (neg q) = neg(transitivity(ℕ._≤_) q p)
Transitivity.proof [≤]-transitivity (neg p) mix = mix
Transitivity.proof [≤]-transitivity mix (pos q) = mix
instance
[≤]-antisymmetry : Antisymmetry(_≤_)(_≡_)
Antisymmetry.proof [≤]-antisymmetry (pos {ℕ.𝟎} {ℕ.𝟎} p) (pos q) = [≡]-intro
Antisymmetry.proof [≤]-antisymmetry (neg {ℕ.𝟎} {ℕ.𝟎} p) (neg q) = [≡]-intro
Antisymmetry.proof [≤]-antisymmetry (pos {ℕ.𝐒 a} {ℕ.𝐒 b} p) (pos q) = congruence₁(+ₙ_) (antisymmetry(ℕ._≤_)(_≡_) p q)
Antisymmetry.proof [≤]-antisymmetry (neg {ℕ.𝐒 a} {ℕ.𝐒 b} p) (neg q) = congruence₁(−𝐒ₙ_) (antisymmetry(ℕ._≤_)(_≡_) q p)
instance
[≤]-converseTotal : ConverseTotal(_≤_)
ConverseTotal.proof [≤]-converseTotal {+ₙ x} {+ₙ y} = Either.map pos pos (converseTotal(ℕ._≤_))
ConverseTotal.proof [≤]-converseTotal {+ₙ x} {−𝐒ₙ y} = Either.Right mix
ConverseTotal.proof [≤]-converseTotal {−𝐒ₙ x} {+ₙ y} = Either.Left mix
ConverseTotal.proof [≤]-converseTotal {−𝐒ₙ x} {−𝐒ₙ y} = Either.map neg neg (converseTotal(ℕ._≤_))
instance
[≤]-weakPartialOrder : Structure.Weak.PartialOrder(_≤_)(_≡_)
[≤]-weakPartialOrder = record{}
instance
[≤]-totalOrder : Structure.Weak.TotalOrder(_≤_)(_≡_)
[≤]-totalOrder = record{}
instance
[+][⋅][≤]-orderedRing : Ordered(_+_)(_⋅_)(_≤_)
Ordered.[≤][+]ₗ-preserve [+][⋅][≤]-orderedRing = p where
postulate p : ∀{x y z} → (x ≤ y) → ((x + z) ≤ (y + z))
{-p {+ₙ x} {+ₙ y} {+ₙ z} (pos xy) = pos {!!}
p {−𝐒ₙ x} {−𝐒ₙ y} {−𝐒ₙ z} (neg xy) = neg {!!}
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} {−𝐒ₙ z} (pos xy) = reflexivity(_≤_)
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} {−𝐒ₙ z} (pos xy) = {!!}
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y}{−𝐒ₙ z} (pos xy) = {!!}
p {.(−𝐒ₙ _)} {.(+ₙ _)} {+ₙ z} mix = {!!}
p {.(−𝐒ₙ _)} {.(+ₙ _)} {−𝐒ₙ z} mix = {!!}-}
Ordered.[≤][⋅]-zero [+][⋅][≤]-orderedRing = p where
p : ∀{x y} → (𝟎 ≤ x) → (𝟎 ≤ y) → (𝟎 ≤ (x ⋅ y))
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝟎} (pos px) (pos py) = pos py
p {+ₙ ℕ.𝟎} {+ₙ ℕ.𝐒 y} (pos px) (pos py) = pos px
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝟎} (pos px) (pos py) = pos py
p {+ₙ ℕ.𝐒 x} {+ₙ ℕ.𝐒 y} (pos px) (pos py) = pos ℕ.[≤]-minimum
| {
"alphanum_fraction": 0.4928006776,
"avg_line_length": 41.9171597633,
"ext": "agda",
"hexsha": "03696a2bd01ea0c0b559682e2eb4b7ad8ff0e2a2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Integer/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Integer/Proofs.agda",
"max_line_length": 221,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Integer/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 16332,
"size": 28336
} |