hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
3906b24d5e03224d32031bd172ad0479b609748a
357
agda
Agda
test/Succeed/Issue695.agda
vlopezj/agda
ff4d89e75970cf27599fb9f572bd43c9455cbb56
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Succeed/Issue695.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/Issue695.agda
vikfret/agda
49ad0b3f0d39c01bc35123478b857e702b29fb9d
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
module _ where data Sigma (A : Set)(B : A → Set) : Set where _,_ : (x : A) → B x → Sigma A B record Top : Set where _o_ : {A B : Set}{C : Set1} → (f : B → C) → (g : A → B) → (A → C) f o g = \ x → f (g x) mutual data U : Set where top : U sig : (X : U) → (T X → U) → U T : U → Set T top = Top T (sig a b) = Sigma (T a) (T o b)
17
45
0.436975
39c687a2828d48664b21a5e696a382df91f2da90
4,887
agda
Agda
Formalization/PredicateLogic/Classical/Semantics/Satisfaction.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Formalization/PredicateLogic/Classical/Semantics/Satisfaction.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Formalization/PredicateLogic/Classical/Semantics/Satisfaction.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
open import Formalization.PredicateLogic.Signature module Formalization.PredicateLogic.Classical.Semantics.Satisfaction (𝔏 : Signature) {ℓₘ} where open Signature(𝔏) import Lvl open import Data open import Data.Boolean open import Data.Boolean.Stmt open import Data.ListSized import Data.ListSized.Functions as List open import Formalization.PredicateLogic.Classical.Semantics(𝔏){ℓₘ} open import Formalization.PredicateLogic.Syntax(𝔏) open import Functional using (_∘_ ; _∘₂_) import Logic.Propositional as Logic import Logic.Predicate as Logic open import Numeral.Finite open import Numeral.Finite.Bound open import Numeral.Natural open import Relator.Equals open import Sets.PredicateSet using (PredSet) open Sets.PredicateSet.BoundedQuantifiers open import Syntax.Function open import Type.Dependent renaming (intro to _,_) open import Type.Properties.Decidable open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable P : Type{ℓₚ} private variable args n vars : ℕ private variable 𝔐 : Model -- A `VarMapping(vars)(𝔐)` maps `vars` number of variables to objects in the domain of the model `𝔐`. -- Also called: Variable assignment. VarMapping : ℕ → Model → Type VarMapping(vars)(𝔐) = 𝕟(vars) → Model.Domain(𝔐) module VarMapping where -- Adds a mapping to an object in the domain of the model `𝔐`. add0 : VarMapping(vars)(𝔐) → Model.Domain(𝔐) → VarMapping(𝐒(vars))(𝔐) add0 𝔰 t 𝟎 = t add0 𝔰 t (𝐒(v)) = 𝔰(v) private variable 𝔰 : VarMapping(vars)(𝔐) module _ ((𝔐 , 𝔰) : Σ Model (VarMapping(vars))) where -- Maps terms to objects in the domain given a model and a variable mapping. val : Term(vars) → Model.Domain(𝔐) val₊ : List(Term(vars))(n) → List(Model.Domain(𝔐))(n) val(var v) = 𝔰(v) val(func f x) = Model.function 𝔐 f (val₊ x) val₊ {0} ∅ = ∅ val₊ {𝐒(n)} (t ⊰ ts) = (val t ⊰ val₊ {n} ts) --val₊ = List.map val -- Satisfication relation. -- ((𝔐 , 𝔰) ⊧ φ) means that the formula φ is satisfied in the model 𝔐 with the variable mapping. -- Or in other words: A formula is true in the model 𝔐. _⊧_ : (Σ Model (VarMapping(vars))) → Formula(vars) → Type{ℓₘ} (𝔐 , 𝔰) ⊧ (f $ x) = Lvl.Up(IsTrue(Model.relation 𝔐 f (val₊(𝔐 , 𝔰) x))) -- A model decides whether a relation is satisfied. (𝔐 , 𝔰) ⊧ ⊤ = Unit -- All models satisfy top. (𝔐 , 𝔰) ⊧ ⊥ = Empty -- No model satisfies bottom. (𝔐 , 𝔰) ⊧ (φ ∧ ψ) = ((𝔐 , 𝔰) ⊧ φ) Logic.∧ ((𝔐 , 𝔰) ⊧ ψ) -- A model satisfies a conjunction when it satisfies both of the propositions. (𝔐 , 𝔰) ⊧ (φ ∨ ψ) = ((𝔐 , 𝔰) ⊧ φ) Logic.∨ ((𝔐 , 𝔰) ⊧ ψ) -- A model satisfies a disjunction when it satisfies any one of the propositions. (𝔐 , 𝔰) ⊧ (φ ⟶ ψ) = Logic.¬((𝔐 , 𝔰) ⊧ φ) Logic.∨ ((𝔐 , 𝔰) ⊧ ψ) (𝔐 , 𝔰) ⊧ (Ɐ φ) = Logic.∀ₗ(t ↦ (𝔐 , VarMapping.add0{𝔐 = 𝔐} 𝔰 t) ⊧ φ) (𝔐 , 𝔰) ⊧ (∃ φ) = Logic.∃(t ↦ (𝔐 , VarMapping.add0{𝔐 = 𝔐} 𝔰 t) ⊧ φ) -- Satisfication of a set of formulas. -- This means that a model satisfies all formulas at the same time. _⊧₊_ : (Σ Model (VarMapping(vars))) → PredSet{ℓ}(Formula(vars)) → Type 𝔐 ⊧₊ Γ = ∀ₛ(Γ) (𝔐 ⊧_) -- Validity of a formula. -- A formula is valid when it is true independent of any model (is satisfied by all models). -- Examples: -- Valid(⊤) -- Valid(⊥ ⟶ ⊥) -- ¬ Valid(⊥) -- ¬ Valid(P) where P : Prop(0) Valid : Formula(vars) → Type Valid(φ) = Logic.∀ₗ(_⊧ φ) -- Satisfiability of sets of formulas. -- A set of formulas is satisfiable when there is a model that satisfies all of them at the same time. Satisfiable : PredSet{ℓ}(Formula(vars)) → Type Satisfiable(Γ) = Logic.∃(_⊧₊ Γ) -- Unsatisfiability of sets of formulas. Unsatisfiable : PredSet{ℓ}(Formula(vars)) → Type Unsatisfiable{ℓ} = Logic.¬_ ∘ Satisfiable{ℓ} -- Semantic entailment of a formula. -- A hypothetical statement. If a model would satisfy all formulas in Γ, then this same model satisifes the formula φ. _⊨_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type Γ ⊨ φ = ∀{𝔐} → (𝔐 ⊧₊ Γ) → (𝔐 ⊧ φ) _⊭_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type _⊭_ = (Logic.¬_) ∘₂ (_⊨_) -- Axiomatization of a theory by a set of axioms. -- A set of axioms is a set of formulas. -- A theory is the closure of a set of axioms. -- An axiomatization is a subset of formulas of the theory which entails all formulas in the axiomatized theory. _axiomatizes_ : PredSet{ℓ₁}(Formula(vars)) → PredSet{ℓ₂}(Formula(vars)) → Type Γ₁ axiomatizes Γ₂ = ∀{φ} → (Γ₁ ⊨ φ) → Γ₂(φ) -- A set of formulas is closed when it includes all formulas that it entails. Closed : PredSet{ℓ}(Formula(vars)) → Type Closed(Γ) = Γ axiomatizes Γ _⊨₊_ : PredSet{ℓ₁}(Formula(vars)) → PredSet{ℓ₂}(Formula(vars)) → Type Γ₁ ⊨₊ Γ₂ = ∀{𝔐} → (𝔐 ⊧₊ Γ₁) → (𝔐 ⊧₊ Γ₂) _⊭₊_ : PredSet{ℓ₁}(Formula(vars)) → PredSet{ℓ₂}(Formula(vars)) → Type _⊭₊_ = (Logic.¬_) ∘₂ (_⊨₊_)
41.769231
155
0.647227
d0c3c7276059d96ef7b60d7a2b98b32c02e1bc6b
11,927
agda
Agda
Groups/Examples/ExampleSheet1.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/Examples/ExampleSheet1.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/Examples/ExampleSheet1.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Functions.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Numbers.Naturals.Naturals open import Numbers.Integers.Integers open import Groups.Definition open import Groups.Homomorphisms.Definition open import Groups.Homomorphisms.Lemmas open import Groups.Isomorphisms.Definition open import Groups.Abelian.Definition open import Groups.Subgroups.Definition open import Groups.Lemmas open import Groups.Groups open import Rings.Definition open import Rings.Lemmas open import Fields.Fields open import Sets.EquivalenceRelations module Groups.Examples.ExampleSheet1 where {- Question 1: e is the unique solution of x^2 = x -} question1 : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} → (G : Group S _+_) → (x : A) → Setoid._∼_ S (x + x) x → Setoid._∼_ S x (Group.0G G) question1 {S = S} {_+_ = _+_} G x x+x=x = transitive (symmetric identRight) (transitive (+WellDefined reflexive (symmetric invRight)) (transitive +Associative (transitive (+WellDefined x+x=x reflexive) invRight))) where open Group G open Setoid S open Equivalence eq question1' : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} → (G : Group S _+_) → Setoid._∼_ S ((Group.0G G) + (Group.0G G)) (Group.0G G) question1' G = Group.identRight G {- Question 3. We can't talk about ℝ yet, so we'll just work in an arbitrary integral domain. Show that the collection of linear functions over a ring forms a group; is it abelian? -} record LinearFunction {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) : Set (a ⊔ b) where field xCoeff : A xCoeffNonzero : (Setoid._∼_ S xCoeff (Ring.0R R) → False) constant : A interpretLinearFunction : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} (f : LinearFunction F) → A → A interpretLinearFunction {_+_ = _+_} {_*_ = _*_} record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant } a = (xCoeff * a) + constant composeLinearFunctions : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} (f1 : LinearFunction F) (f2 : LinearFunction F) → LinearFunction F LinearFunction.xCoeff (composeLinearFunctions {_+_ = _+_} {_*_ = _*_} record { xCoeff = xCoeff1 ; xCoeffNonzero = xCoeffNonzero1 ; constant = constant1 } record { xCoeff = xCoeff2 ; xCoeffNonzero = xCoeffNonzero2 ; constant = constant2 }) = xCoeff1 * xCoeff2 LinearFunction.xCoeffNonzero (composeLinearFunctions {S = S} {R = R} {F = F} record { xCoeff = xCoeff1 ; xCoeffNonzero = xCoeffNonzero1 ; constant = constant1 } record { xCoeff = xCoeff2 ; xCoeffNonzero = xCoeffNonzero2 ; constant = constant2 }) pr = xCoeffNonzero2 bad where open Setoid S open Ring R open Equivalence eq bad : Setoid._∼_ S xCoeff2 0R bad with Field.allInvertible F xCoeff1 xCoeffNonzero1 ... | xinv , pr' = transitive (symmetric identIsIdent) (transitive (*WellDefined (symmetric pr') reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive pr) (Ring.timesZero R)))) LinearFunction.constant (composeLinearFunctions {_+_ = _+_} {_*_ = _*_} record { xCoeff = xCoeff1 ; xCoeffNonzero = xCoeffNonzero1 ; constant = constant1 } record { xCoeff = xCoeff2 ; xCoeffNonzero = xCoeffNonzero2 ; constant = constant2 }) = (xCoeff1 * constant2) + constant1 compositionIsCorrect : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} (f1 : LinearFunction F) (f2 : LinearFunction F) → {r : A} → Setoid._∼_ S (interpretLinearFunction (composeLinearFunctions f1 f2) r) (((interpretLinearFunction f1) ∘ (interpretLinearFunction f2)) r) compositionIsCorrect {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant } record { xCoeff = xCoeff' ; xCoeffNonzero = xCoeffNonzero' ; constant = constant' } {r} = ans where open Setoid S open Ring R open Equivalence eq ans : (((xCoeff * xCoeff') * r) + ((xCoeff * constant') + constant)) ∼ (xCoeff * ((xCoeff' * r) + constant')) + constant ans = transitive (Group.+Associative additiveGroup) (Group.+WellDefined additiveGroup (transitive (Group.+WellDefined additiveGroup (symmetric (Ring.*Associative R)) reflexive) (symmetric (Ring.*DistributesOver+ R))) (reflexive {constant})) linearFunctionsSetoid : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (I : Field R) → Setoid (LinearFunction I) Setoid._∼_ (linearFunctionsSetoid {S = S} I) f1 f2 = ((LinearFunction.xCoeff f1) ∼ (LinearFunction.xCoeff f2)) && ((LinearFunction.constant f1) ∼ (LinearFunction.constant f2)) where open Setoid S Equivalence.reflexive (Setoid.eq (linearFunctionsSetoid {S = S} I)) = Equivalence.reflexive (Setoid.eq S) ,, Equivalence.reflexive (Setoid.eq S) Equivalence.symmetric (Setoid.eq (linearFunctionsSetoid {S = S} I)) (fst ,, snd) = Equivalence.symmetric (Setoid.eq S) fst ,, Equivalence.symmetric (Setoid.eq S) snd Equivalence.transitive (Setoid.eq (linearFunctionsSetoid {S = S} I)) (fst1 ,, snd1) (fst2 ,, snd2) = Equivalence.transitive (Setoid.eq S) fst1 fst2 ,, Equivalence.transitive (Setoid.eq S) snd1 snd2 linearFunctionsGroup : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) → Group (linearFunctionsSetoid F) (composeLinearFunctions) Group.+WellDefined (linearFunctionsGroup {R = R} F) {record { xCoeff = xCoeffM ; xCoeffNonzero = xCoeffNonzeroM ; constant = constantM }} {record { xCoeff = xCoeffN ; xCoeffNonzero = xCoeffNonzeroN ; constant = constantN }} {record { xCoeff = xCoeffX ; xCoeffNonzero = xCoeffNonzeroX ; constant = constantX }} {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} (fst1 ,, snd1) (fst2 ,, snd2) = *WellDefined fst1 fst2 ,, Group.+WellDefined additiveGroup (*WellDefined fst1 snd2) snd1 where open Ring R Group.0G (linearFunctionsGroup {S = S} {R = R} F) = record { xCoeff = Ring.1R R ; constant = Ring.0R R ; xCoeffNonzero = λ p → Field.nontrivial F (Equivalence.symmetric (Setoid.eq S) p) } Group.inverse (linearFunctionsGroup {S = S} {_*_ = _*_} {R = R} F) record { xCoeff = xCoeff ; constant = c ; xCoeffNonzero = pr } with Field.allInvertible F xCoeff pr ... | (inv , pr') = record { xCoeff = inv ; constant = inv * (Group.inverse (Ring.additiveGroup R) c) ; xCoeffNonzero = λ p → Field.nontrivial F (transitive (symmetric (transitive (Ring.*WellDefined R p reflexive) (transitive (Ring.*Commutative R) (Ring.timesZero R)))) pr') } where open Setoid S open Equivalence eq Group.+Associative (linearFunctionsGroup {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} F) {record { xCoeff = xA ; xCoeffNonzero = xANonzero ; constant = cA }} {record { xCoeff = xB ; xCoeffNonzero = xBNonzero ; constant = cB }} {record { xCoeff = xC ; xCoeffNonzero = xCNonzero ; constant = cC }} = Ring.*Associative R ,, transitive (Group.+WellDefined additiveGroup (transitive *DistributesOver+ (Group.+WellDefined additiveGroup *Associative reflexive)) reflexive) (symmetric (Group.+Associative additiveGroup)) where open Setoid S open Equivalence eq open Ring R Group.identRight (linearFunctionsGroup {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} = transitive (Ring.*Commutative R) (Ring.identIsIdent R) ,, transitive (Group.+WellDefined additiveGroup (Ring.timesZero R) reflexive) (Group.identLeft additiveGroup) where open Ring R open Setoid S open Equivalence eq Group.identLeft (linearFunctionsGroup {S = S} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} = identIsIdent ,, transitive (Group.identRight additiveGroup) identIsIdent where open Setoid S open Ring R open Equivalence eq Group.invLeft (linearFunctionsGroup F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} with Field.allInvertible F xCoeff xCoeffNonzero Group.invLeft (linearFunctionsGroup {S = S} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} | inv , prInv = prInv ,, transitive (symmetric *DistributesOver+) (transitive (*WellDefined reflexive (Group.invRight additiveGroup)) (Ring.timesZero R)) where open Setoid S open Ring R open Equivalence eq Group.invRight (linearFunctionsGroup {S = S} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} with Field.allInvertible F xCoeff xCoeffNonzero ... | inv , pr = transitive *Commutative pr ,, transitive (Group.+WellDefined additiveGroup *Associative reflexive) (transitive (Group.+WellDefined additiveGroup (*WellDefined (transitive *Commutative pr) reflexive) reflexive) (transitive (Group.+WellDefined additiveGroup identIsIdent reflexive) (Group.invLeft additiveGroup))) where open Setoid S open Ring R open Equivalence eq {- Question 3, part 2: prove that linearFunctionsGroup is not abelian -} -- We'll assume the field doesn't have characteristic 2. linearFunctionsGroupNotAbelian : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} → (nonChar2 : Setoid._∼_ S ((Ring.1R R) + (Ring.1R R)) (Ring.0R R) → False) → AbelianGroup (linearFunctionsGroup F) → False linearFunctionsGroupNotAbelian {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} {F = F} pr record { commutative = commutative } = ans where open Ring R open Group additiveGroup open Equivalence (Setoid.eq S) renaming (symmetric to symmetricS ; transitive to transitiveS ; reflexive to reflexiveS) f : LinearFunction F f = record { xCoeff = 1R ; xCoeffNonzero = λ p → Field.nontrivial F (symmetricS p) ; constant = 1R } g : LinearFunction F g = record { xCoeff = 1R + 1R ; xCoeffNonzero = pr ; constant = 0R } gf : LinearFunction F gf = record { xCoeff = 1R + 1R ; xCoeffNonzero = pr ; constant = 1R + 1R } fg : LinearFunction F fg = record { xCoeff = 1R + 1R ; xCoeffNonzero = pr ; constant = 1R } oneWay : Setoid._∼_ (linearFunctionsSetoid F) gf (composeLinearFunctions g f) oneWay = symmetricS (transitiveS *Commutative identIsIdent) ,, transitiveS (symmetricS (transitiveS *Commutative identIsIdent)) (symmetricS (Group.identRight additiveGroup)) otherWay : Setoid._∼_ (linearFunctionsSetoid F) fg (composeLinearFunctions f g) otherWay = symmetricS identIsIdent ,, transitiveS (symmetricS (Group.identLeft additiveGroup)) (Group.+WellDefined additiveGroup (symmetricS identIsIdent) (reflexiveS {1R})) open Equivalence (Setoid.eq (linearFunctionsSetoid F)) bad : Setoid._∼_ (linearFunctionsSetoid F) gf fg bad = transitive {gf} {composeLinearFunctions g f} {fg} oneWay (transitive {composeLinearFunctions g f} {composeLinearFunctions f g} {fg} (commutative {g} {f}) (symmetric {fg} {composeLinearFunctions f g} otherWay)) ans : False ans with bad ans | _ ,, contr = Field.nontrivial F (symmetricS (transitiveS {1R} {1R + (1R + Group.inverse additiveGroup 1R)} (transitiveS (symmetricS (Group.identRight additiveGroup)) (Group.+WellDefined additiveGroup reflexiveS (symmetricS (Group.invRight additiveGroup)))) (transitiveS (Group.+Associative additiveGroup) (transitiveS (Group.+WellDefined additiveGroup contr reflexiveS) (Group.invRight additiveGroup)))))
77.448052
515
0.683156
cb88ee1f0007354de506a4f1f99c4b6b541afaeb
374
agda
Agda
test/Succeed/UnderscoresAsDataParam.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/UnderscoresAsDataParam.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/UnderscoresAsDataParam.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- We can let Agda infer the parameters of the constructor target data List (A : Set) : Set where nil : List _ cons : A → List A → List _ -- 2017-01-12, Andreas: we can even omit the whole target -- (for parameterized data types, but not inductive families) data Bool : Set where true false : _ data Maybe (A : Set) : Set where nothing : _ just : (x : A) → _
23.375
65
0.660428
c55ad304adbfc457452444df15e40951702bd699
316
agda
Agda
test/bugs/fixed/DroppingParameters.agda
gallais/agda
e7f588d478bdd3c03088c49e009bcdf6a2a3310f
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/bugs/fixed/DroppingParameters.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/bugs/fixed/DroppingParameters.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
module bug where data True : Set where tt : True data Sigma (x : True) : Set where pair : True -> Sigma x postulate p : True T : True -> Sigma p -> Set T tt (pair _) = True postulate S : True -> Sigma p -> Set z : Sigma p z = pair p postulate build : (q : Sigma p) -> T p q -> True pz : T p z
12.153846
40
0.572785
fbca91b19494673ce5339919637198b2f6106440
85
agda
Agda
test/interaction/Issue2447/Type-error.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2447/Type-error.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2447/Type-error.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue2447.Type-error where import Issue2447.M Rejected : Set Rejected = Set
12.142857
33
0.788235
50f15a7215fe5a8e7823dbd33d1781c354776919
18,088
agda
Agda
theorems/groups/CoefficientExtensionality.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
theorems/groups/CoefficientExtensionality.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
theorems/groups/CoefficientExtensionality.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} open import HoTT module groups.CoefficientExtensionality where module _ {i} {A : Type i} (dec : has-dec-eq A) where Word-coef : Word A → (A → ℤ) Word-coef nil a = 0 Word-coef (inl a' :: w) a with dec a' a Word-coef (inl a' :: w) a | inl a'=a = succ $ Word-coef w a Word-coef (inl a' :: w) a | inr a'≠a = Word-coef w a Word-coef (inr a' :: w) a with dec a' a Word-coef (inr a' :: w) a | inl a'=a = pred $ Word-coef w a Word-coef (inr a' :: w) a | inr a'≠a = Word-coef w a abstract Word-coef-++ : ∀ w₁ w₂ a → Word-coef (w₁ ++ w₂) a == Word-coef w₁ a ℤ+ Word-coef w₂ a Word-coef-++ nil w₂ a = idp Word-coef-++ (inl a' :: w₁) w₂ a with dec a' a Word-coef-++ (inl a' :: w₁) w₂ a | inl a'=a = ap succ (Word-coef-++ w₁ w₂ a) ∙ ! (succ-+ (Word-coef w₁ a) (Word-coef w₂ a)) Word-coef-++ (inl a' :: w₁) w₂ a | inr a'≠a = Word-coef-++ w₁ w₂ a Word-coef-++ (inr a' :: w₁) w₂ a with dec a' a Word-coef-++ (inr a' :: w₁) w₂ a | inl a'=a = ap pred (Word-coef-++ w₁ w₂ a) ∙ ! (pred-+ (Word-coef w₁ a) (Word-coef w₂ a)) Word-coef-++ (inr a' :: w₁) w₂ a | inr a'≠a = Word-coef-++ w₁ w₂ a Word-coef-flip : ∀ w a → Word-coef (Word-flip w) a == ℤ~ (Word-coef w a) Word-coef-flip nil a = idp Word-coef-flip (inl a' :: w) a with dec a' a Word-coef-flip (inl a' :: w) a | inl a'=a = ap pred (Word-coef-flip w a) ∙ ! (ℤ~-succ (Word-coef w a)) Word-coef-flip (inl a' :: w) a | inr a'≠a = Word-coef-flip w a Word-coef-flip (inr a' :: w) a with dec a' a Word-coef-flip (inr a' :: w) a | inl a'=a = ap succ (Word-coef-flip w a) ∙ ! (ℤ~-pred (Word-coef w a)) Word-coef-flip (inr a' :: w) a | inr a'≠a = Word-coef-flip w a private abstract FormalSum-coef-rel : {w₁ w₂ : Word A} → FormalSumRel w₁ w₂ → ∀ a → Word-coef w₁ a == Word-coef w₂ a FormalSum-coef-rel (fsr-refl p) a = ap (λ w → Word-coef w a) p FormalSum-coef-rel (fsr-trans fwr₁ fwr₂) a = (FormalSum-coef-rel fwr₁ a) ∙ (FormalSum-coef-rel fwr₂ a) FormalSum-coef-rel (fsr-sym fsr) a = ! $ FormalSum-coef-rel fsr a FormalSum-coef-rel (fsr-cons x fwr) a = Word-coef-++ (x :: nil) _ a ∙ ap (Word-coef (x :: nil) a ℤ+_) (FormalSum-coef-rel fwr a) ∙ ! (Word-coef-++ (x :: nil) _ a) FormalSum-coef-rel (fsr-swap x y w) a = Word-coef-++ (x :: y :: nil) _ a ∙ ap (_ℤ+ Word-coef w a) ( Word-coef-++ (x :: nil) (y :: nil) a ∙ ℤ+-comm (Word-coef (x :: nil) a) (Word-coef (y :: nil) a) ∙ ! (Word-coef-++ (y :: nil) (x :: nil) a)) ∙ ! (Word-coef-++ (y :: x :: nil) _ a) FormalSum-coef-rel (fsr-flip x w) a = Word-coef-++ (x :: flip x :: nil) w a ∙ ap (_ℤ+ Word-coef w a) ( Word-coef-++ (x :: nil) (flip x :: nil) a ∙ ap (Word-coef (x :: nil) a ℤ+_) (Word-coef-flip (x :: nil) a) ∙ ℤ~-inv-r (Word-coef (x :: nil) a) ) ∙ ℤ+-unit-l (Word-coef w a) FormalSum-coef : FormalSum A → (A → ℤ) FormalSum-coef = FormalSum-rec Word-coef (λ r → λ= $ FormalSum-coef-rel r) -- Theorem : if coef w a == 0 then FormalSumRel w nil private abstract Word-exp-succ : ∀ (a : A) z → FormalSumRel (inl a :: Word-exp a z) (Word-exp a (succ z)) Word-exp-succ a (pos _) = fsr-refl idp Word-exp-succ a (negsucc 0) = fsr-flip (inl a) nil Word-exp-succ a (negsucc (S n)) = fsr-flip (inl a) (Word-exp a (negsucc n)) Word-exp-pred : ∀ (a : A) z → FormalSumRel (inr a :: Word-exp a z) (Word-exp a (pred z)) Word-exp-pred a (pos 0) = fsr-refl idp Word-exp-pred a (pos (S n)) = fsr-flip (inr a) (Word-exp a (pos n)) Word-exp-pred a (negsucc _) = fsr-refl idp Word-coef-inl-eq : ∀ {a b} (p : b == a) w → Word-coef (inl b :: w) a == succ (Word-coef w a) Word-coef-inl-eq {a} {b} p w with dec b a Word-coef-inl-eq {a} {b} p w | inl _ = idp Word-coef-inl-eq {a} {b} p w | inr ¬p = ⊥-rec (¬p p) Word-coef-inr-eq : ∀ {a b} (p : b == a) w → Word-coef (inr b :: w) a == pred (Word-coef w a) Word-coef-inr-eq {a} {b} p w with dec b a Word-coef-inr-eq {a} {b} p w | inl _ = idp Word-coef-inr-eq {a} {b} p w | inr ¬p = ⊥-rec (¬p p) Word-coef-inl-neq : ∀ {a b} (p : b ≠ a) w → Word-coef (inl b :: w) a == Word-coef w a Word-coef-inl-neq {a} {b} ¬p w with dec b a Word-coef-inl-neq {a} {b} ¬p w | inl p = ⊥-rec (¬p p) Word-coef-inl-neq {a} {b} ¬p w | inr _ = idp Word-coef-inr-neq : ∀ {a b} (p : b ≠ a) w → Word-coef (inr b :: w) a == Word-coef w a Word-coef-inr-neq {a} {b} ¬p w with dec b a Word-coef-inr-neq {a} {b} ¬p w | inl p = ⊥-rec (¬p p) Word-coef-inr-neq {a} {b} ¬p w | inr _ = idp -- TODO maybe there is a better way to prove the final theorem? -- Here we are collecting all elements [inl a] and [inr a], and recurse on the rest. -- The [right-shorter] field makes sure that it is terminating. record CollectSplitIH (a : A) {n : ℕ} (w : Word A) (len : length w == n) : Type i where field left-exponent : ℤ left-captures-all : Word-coef w a == left-exponent right-list : Word A right-shorter : length right-list ≤ n fsr : FormalSumRel w (Word-exp a left-exponent ++ right-list) abstract collect-split : ∀ a {n} w (len=n : length w == n) → CollectSplitIH a w len=n collect-split a nil idp = record { left-exponent = 0; left-captures-all = idp; right-list = nil; right-shorter = inl idp; fsr = fsr-refl idp} collect-split a (inl b :: w) idp with dec b a ... | inl b=a = record { left-exponent = succ left-exponent; left-captures-all = Word-coef-inl-eq b=a w ∙ ap succ left-captures-all; right-list = right-list; right-shorter = ≤-trans right-shorter (inr ltS); fsr = fsr-trans (fsr-refl (ap (λ a → inl a :: w) b=a)) $ fsr-trans (fsr-cons (inl a) fsr) $ (FormalSumRel-cong-++-l (Word-exp-succ a left-exponent) right-list)} where open CollectSplitIH (collect-split a w idp) ... | inr b≠a = record { left-exponent = left-exponent; left-captures-all = Word-coef-inl-neq b≠a w ∙ left-captures-all; right-list = inl b :: right-list; right-shorter = ≤-ap-S right-shorter; fsr = fsr-trans (fsr-cons (inl b) fsr) $ fsr-sym (FormalSumRel-swap1 (inl b) (Word-exp a left-exponent) right-list)} where open CollectSplitIH (collect-split a w idp) collect-split a (inr b :: w) idp with dec b a ... | inl b=a = record { left-exponent = pred left-exponent; left-captures-all = Word-coef-inr-eq b=a w ∙ ap pred left-captures-all; right-list = right-list; right-shorter = ≤-trans right-shorter (inr ltS); fsr = fsr-trans (fsr-refl (ap (λ a → inr a :: w) b=a)) $ fsr-trans (fsr-cons (inr a) fsr) $ (FormalSumRel-cong-++-l (Word-exp-pred a left-exponent) right-list)} where open CollectSplitIH (collect-split a w idp) ... | inr b≠a = record { left-exponent = left-exponent; left-captures-all = Word-coef-inr-neq b≠a w ∙ left-captures-all; right-list = inr b :: right-list; right-shorter = ≤-ap-S right-shorter; fsr = fsr-trans (fsr-cons (inr b) fsr) $ fsr-sym (FormalSumRel-swap1 (inr b) (Word-exp a left-exponent) right-list)} where open CollectSplitIH (collect-split a w idp) -- We simulate strong induction by recursing on both [m] and [n≤m]. -- We could develop a general framework for strong induction but I am lazy. -Favonia zero-coef-is-ident' : ∀ {m n} (n≤m : n ≤ m) (w : Word A) (len : length w == n) → (∀ a → Word-coef w a == 0) → FormalSumRel w nil zero-coef-is-ident' (inr ltS) w len zero-coef = zero-coef-is-ident' (inl idp) w len zero-coef zero-coef-is-ident' (inr (ltSR lt)) w len zero-coef = zero-coef-is-ident' (inr lt) w len zero-coef zero-coef-is-ident' {m = O} (inl idp) nil _ _ = fsr-refl idp zero-coef-is-ident' {m = O} (inl idp) (_ :: _) len _ = ⊥-rec $ ℕ-S≠O _ len zero-coef-is-ident' {m = S m} (inl idp) nil len _ = ⊥-rec $ ℕ-S≠O _ (! len) zero-coef-is-ident' {m = S m} (inl idp) (inl a :: w) len zero-coef = fsr-trans whole-is-right (zero-coef-is-ident' right-shorter right-list idp right-zero-coef) where open CollectSplitIH (collect-split a w (ℕ-S-is-inj _ _ len)) left-exponent-is-minus-one : left-exponent == -1 left-exponent-is-minus-one = succ-is-inj left-exponent -1 $ ap succ (! left-captures-all) ∙ ! (Word-coef-inl-eq idp w) ∙ zero-coef a whole-is-right : FormalSumRel (inl a :: w) right-list whole-is-right = fsr-trans (fsr-cons (inl a) fsr) $ fsr-trans (fsr-refl (ap (λ e → inl a :: Word-exp a e ++ right-list) left-exponent-is-minus-one)) $ fsr-flip (inl a) right-list right-zero-coef : ∀ a' → Word-coef right-list a' == 0 right-zero-coef a' = ! (FormalSum-coef-rel whole-is-right a') ∙ zero-coef a' zero-coef-is-ident' {m = S m} (inl idp) (inr a :: w) len zero-coef = fsr-trans whole-is-right (zero-coef-is-ident' right-shorter right-list idp right-zero-coef) where open CollectSplitIH (collect-split a w (ℕ-S-is-inj _ _ len)) left-exponent-is-one : left-exponent == 1 left-exponent-is-one = pred-is-inj left-exponent 1 $ ap pred (! left-captures-all) ∙ ! (Word-coef-inr-eq idp w) ∙ zero-coef a whole-is-right : FormalSumRel (inr a :: w) right-list whole-is-right = fsr-trans (fsr-cons (inr a) fsr) $ fsr-trans (fsr-refl (ap (λ e → inr a :: Word-exp a e ++ right-list) left-exponent-is-one)) $ fsr-flip (inr a) right-list right-zero-coef : ∀ a' → Word-coef right-list a' == 0 right-zero-coef a' = ! (FormalSum-coef-rel whole-is-right a') ∙ zero-coef a' zero-coef-is-ident : ∀ (w : Word A) → (∀ a → Word-coef w a == 0) → FormalSumRel w nil zero-coef-is-ident w = zero-coef-is-ident' (inl idp) w idp abstract FormalSum-coef-ext' : ∀ w₁ w₂ → (∀ a → Word-coef w₁ a == Word-coef w₂ a) → fs[ w₁ ] == fs[ w₂ ] FormalSum-coef-ext' w₁ w₂ same-coef = G.inv-is-inj fs[ w₁ ] fs[ w₂ ] $ G.inv-unique-l (G.inv fs[ w₂ ]) fs[ w₁ ] $ quot-rel $ zero-coef-is-ident (Word-flip w₂ ++ w₁) (λ a → Word-coef-++ (Word-flip w₂) w₁ a ∙ ap2 _ℤ+_ (Word-coef-flip w₂ a) (same-coef a) ∙ ℤ~-inv-l (Word-coef w₂ a)) where module G = FreeAbGroup A FormalSum-coef-ext : ∀ fs₁ fs₂ → (∀ a → FormalSum-coef fs₁ a == FormalSum-coef fs₂ a) → fs₁ == fs₂ FormalSum-coef-ext = FormalSum-elim (λ w₁ → FormalSum-elim (λ w₂ → FormalSum-coef-ext' w₁ w₂) (λ _ → prop-has-all-paths-↓)) (λ _ → prop-has-all-paths-↓) has-finite-support : (A → ℤ) → Type i has-finite-support f = Σ (FormalSum A) λ fs → ∀ a → f a == FormalSum-coef fs a module _ {i} {A : Type i} {dec : has-dec-eq A} where abstract has-finite-support-is-prop : ∀ f → is-prop (has-finite-support dec f) has-finite-support-is-prop f = all-paths-is-prop λ{(fs₁ , match₁) (fs₂ , match₂) → pair= (FormalSum-coef-ext dec fs₁ fs₂ λ a → ! (match₁ a) ∙ match₂ a) prop-has-all-paths-↓} module _ where private abstract Word-coef-exp-diag-pos : ∀ {I} (<I : Fin I) n → Word-coef Fin-has-dec-eq (Word-exp <I (pos n)) <I == pos n Word-coef-exp-diag-pos <I O = idp Word-coef-exp-diag-pos <I (S n) with Fin-has-dec-eq <I <I ... | inl _ = ap succ (Word-coef-exp-diag-pos <I n) ... | inr ¬p = ⊥-rec (¬p idp) Word-coef-exp-diag-negsucc : ∀ {I} (<I : Fin I) n → Word-coef Fin-has-dec-eq (Word-exp <I (negsucc n)) <I == negsucc n Word-coef-exp-diag-negsucc <I O with Fin-has-dec-eq <I <I ... | inl _ = idp ... | inr ¬p = ⊥-rec (¬p idp) Word-coef-exp-diag-negsucc <I (S n) with Fin-has-dec-eq <I <I ... | inl _ = ap pred (Word-coef-exp-diag-negsucc <I n) ... | inr ¬p = ⊥-rec (¬p idp) Word-coef-exp-diag : ∀ {I} (<I : Fin I) z → Word-coef Fin-has-dec-eq (Word-exp <I z) <I == z Word-coef-exp-diag <I (pos n) = Word-coef-exp-diag-pos <I n Word-coef-exp-diag <I (negsucc n) = Word-coef-exp-diag-negsucc <I n Word-coef-exp-≠-pos : ∀ {I} {<I <I' : Fin I} (_ : <I ≠ <I') n → Word-coef Fin-has-dec-eq (Word-exp <I (pos n)) <I' == 0 Word-coef-exp-≠-pos _ O = idp Word-coef-exp-≠-pos {<I = <I} {<I'} neq (S n) with Fin-has-dec-eq <I <I' ... | inl p = ⊥-rec (neq p) ... | inr ¬p = Word-coef-exp-≠-pos neq n Word-coef-exp-≠-negsucc : ∀ {I} {<I <I' : Fin I} (_ : <I ≠ <I') n → Word-coef Fin-has-dec-eq (Word-exp <I (negsucc n)) <I' == 0 Word-coef-exp-≠-negsucc {<I = <I} {<I'} neq O with Fin-has-dec-eq <I <I' ... | inl p = ⊥-rec (neq p) ... | inr ¬p = idp Word-coef-exp-≠-negsucc {<I = <I} {<I'} neq (S n) with Fin-has-dec-eq <I <I' ... | inl p = ⊥-rec (neq p) ... | inr ¬p = Word-coef-exp-≠-negsucc neq n Word-coef-exp-≠ : ∀ {I} {<I <I' : Fin I} (_ : <I ≠ <I') z → Word-coef Fin-has-dec-eq (Word-exp <I z) <I' == 0 Word-coef-exp-≠ neq (pos n) = Word-coef-exp-≠-pos neq n Word-coef-exp-≠ neq (negsucc n) = Word-coef-exp-≠-negsucc neq n Word-sum' : ∀ (I : ℕ) {A : Type₀} (F : Fin I → A) (f : Fin I → ℤ) → Word A Word-sum' 0 F f = nil Word-sum' (S I) F f = Word-sum' I (F ∘ Fin-S) (f ∘ Fin-S) ++ Word-exp (F (I , ltS)) (f (I , ltS)) Word-sum : ∀ {I : ℕ} (f : Fin I → ℤ) → Word (Fin I) Word-sum {I} f = Word-sum' I (idf (Fin I)) f abstract Word-coef-sum'-late : ∀ n m (I : ℕ) (f : Fin I → ℤ) → Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' m) f) (Fin-S^' n (ℕ-S^' m I , ltS)) == 0 Word-coef-sum'-late n m 0 f = idp Word-coef-sum'-late n m (S I) f = Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' (S m)) (f ∘ Fin-S) ++ Word-exp (Fin-S^' (S n) (Fin-S^' m (I , ltS))) (f (I , ltS))) (Fin-S^' n (ℕ-S^' (S m) I , ltS)) =⟨ Word-coef-++ Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' (S m)) (f ∘ Fin-S)) (Word-exp (Fin-S^' (S n) (Fin-S^' m (I , ltS))) (f (I , ltS))) (Fin-S^' n (ℕ-S^' (S m) I , ltS)) ⟩ Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n) ∘ Fin-S^' (S m)) (f ∘ Fin-S)) (Fin-S^' n (ℕ-S^' (S m) I , ltS)) ℤ+ Word-coef Fin-has-dec-eq (Word-exp (Fin-S^' (S n) (Fin-S^' m (I , ltS))) (f (I , ltS))) (Fin-S^' n (ℕ-S^' (S m) I , ltS)) =⟨ ap2 _ℤ+_ (Word-coef-sum'-late n (S m) I (f ∘ Fin-S)) (Word-coef-exp-≠ (Fin-S^'-≠ n (ltSR≠ltS _)) (f (I , ltS))) ⟩ 0 =∎ Word-coef-sum' : ∀ n {I} (f : Fin I → ℤ) <I → Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' n) f) (Fin-S^' n <I) == f <I Word-coef-sum' n f (I , ltS) = Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S) ++ Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' n (I , ltS)) =⟨ Word-coef-++ Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S)) (Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' n (I , ltS)) ⟩ Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S)) (Fin-S^' n (I , ltS)) ℤ+ Word-coef Fin-has-dec-eq (Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' n (I , ltS)) =⟨ ap2 _ℤ+_ (Word-coef-sum'-late n 0 I (f ∘ Fin-S)) (Word-coef-exp-diag (Fin-S^' n (I , ltS)) (f (I , ltS))) ⟩ f (I , ltS) =∎ Word-coef-sum' n {I = S I} f (m , ltSR m<I) = Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S) ++ Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' (S n) (m , m<I)) =⟨ Word-coef-++ Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S)) (Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' (S n) (m , m<I)) ⟩ Word-coef Fin-has-dec-eq (Word-sum' I (Fin-S^' (S n)) (f ∘ Fin-S)) (Fin-S^' (S n) (m , m<I)) ℤ+ Word-coef Fin-has-dec-eq (Word-exp (Fin-S^' n (I , ltS)) (f (I , ltS))) (Fin-S^' (S n) (m , m<I)) =⟨ ap2 _ℤ+_ (Word-coef-sum' (S n) {I} (f ∘ Fin-S) (m , m<I)) (Word-coef-exp-≠ (Fin-S^'-≠ n (ltS≠ltSR (m , m<I))) (f (I , ltS))) ⟩ f (m , ltSR m<I) ℤ+ 0 =⟨ ℤ+-unit-r _ ⟩ f (m , ltSR m<I) =∎ FormalSum-sum' : ∀ n (I : ℕ) (f : Fin I → ℤ) → FormalSum (Fin (ℕ-S^' n I)) FormalSum-sum' n I f = Group.sum (FreeAbGroup.grp (Fin (ℕ-S^' n I))) (λ <I → Group.exp (FreeAbGroup.grp (Fin (ℕ-S^' n I))) fs[ inl (Fin-S^' n <I) :: nil ] (f <I)) FormalSum-sum : ∀ {I : ℕ} (f : Fin I → ℤ) → FormalSum (Fin I) FormalSum-sum {I} = FormalSum-sum' 0 I private abstract FormalSum-sum'-β : ∀ n (I : ℕ) (f : Fin I → ℤ) → FormalSum-sum' n I f == fs[ Word-sum' I (Fin-S^' n) f ] FormalSum-sum'-β n O f = idp FormalSum-sum'-β n (S I) f = ap2 (Group.comp (FreeAbGroup.grp (Fin (ℕ-S^' (S n) I)))) (FormalSum-sum'-β (S n) I (f ∘ Fin-S)) (! (FormalSumRel-pres-exp (Fin-S^' n (I , ltS)) (f (I , ltS)))) Fin→-has-finite-support : ∀ {I} (f : Fin I → ℤ) → has-finite-support Fin-has-dec-eq f Fin→-has-finite-support {I} f = FormalSum-sum f , lemma where abstract lemma = λ <I → ! (ap (λ fs → FormalSum-coef Fin-has-dec-eq fs <I) (FormalSum-sum'-β 0 I f) ∙ Word-coef-sum' 0 f <I)
47.475066
134
0.514208
4d624704f10bc909a879a4fe3feb502b4354bd89
1,574
agda
Agda
src/Categories/Category/Instance/Monoidals.agda
jaykru/agda-categories
a4053cf700bcefdf73b857c3352f1eae29382a60
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Instance/Monoidals.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Instance/Monoidals.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Monoidals where open import Level open import Categories.Category open import Categories.Category.Helper open import Categories.Category.Monoidal open import Categories.Functor.Monoidal open import Categories.Functor.Monoidal.Properties open import Categories.NaturalTransformation.NaturalIsomorphism.Monoidal module _ o ℓ e where Monoidals : Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) Monoidals = categoryHelper record { Obj = MonoidalCategory o ℓ e ; _⇒_ = MonoidalFunctor ; _≈_ = Lax._≃_ ; id = idF-Monoidal _ ; _∘_ = ∘-Monoidal -- NOTE: these η-expanded versions typecheck much faster... ; assoc = λ {_ _ _ _ F G H} → associator {F = F} {G} {H} ; identityˡ = λ {_ _ F} → unitorˡ {F = F} ; identityʳ = λ {_ _ F} → unitorʳ {F = F} ; equiv = isEquivalence ; ∘-resp-≈ = _ⓘₕ_ } where open Lax StrongMonoidals : Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) StrongMonoidals = categoryHelper record { Obj = MonoidalCategory o ℓ e ; _⇒_ = StrongMonoidalFunctor ; _≈_ = Strong._≃_ ; id = idF-StrongMonoidal _ ; _∘_ = ∘-StrongMonoidal -- NOTE: these η-expanded versions typecheck much faster... ; assoc = λ {_ _ _ _ F G H} → associator {F = F} {G} {H} ; identityˡ = λ {_ _ F} → unitorˡ {F = F} ; identityʳ = λ {_ _ F} → unitorʳ {F = F} ; equiv = isEquivalence ; ∘-resp-≈ = _ⓘₕ_ } where open Strong
33.489362
72
0.595934
23b812dc48ae78297e7bf67af06a6317079c5277
643
agda
Agda
agda-stdlib/src/Algebra/Module/Definitions/Bi.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Algebra/Module/Definitions/Bi.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Algebra/Module/Definitions/Bi.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties connecting left-scaling and right-scaling ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary -- The properties are parameterised by the three carriers and -- the result equality. module Algebra.Module.Definitions.Bi {a a′ b ℓb} (A : Set a) (A′ : Set a′) {B : Set b} (_≈_ : Rel B ℓb) where open import Algebra.Core Associative : Opₗ A B → Opᵣ A′ B → Set _ Associative _∙ₗ_ _∙ᵣ_ = ∀ x m y → ((x ∙ₗ m) ∙ᵣ y) ≈ (x ∙ₗ (m ∙ᵣ y))
29.227273
72
0.496112
cb67ab2d5ca8f23a3591394ad2f79b2037ddceac
4,465
agda
Agda
lib/Haskell/Prim/Ord.agda
JonathanBrouwer/agda2hs
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
[ "MIT" ]
null
null
null
lib/Haskell/Prim/Ord.agda
JonathanBrouwer/agda2hs
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
[ "MIT" ]
null
null
null
lib/Haskell/Prim/Ord.agda
JonathanBrouwer/agda2hs
dcf63cc7ce51a325a97ac58bdd0aeace24c08b15
[ "MIT" ]
null
null
null
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
28.621795
85
0.614558
4d18d98a3c4e99cae6d7b6b804c5affb4fc1e49c
766
agda
Agda
notes/papers/implicit/examples/Example.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
notes/papers/implicit/examples/Example.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
notes/papers/implicit/examples/Example.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Example where data Nat : Set where zero : Nat suc : Nat -> Nat postulate case-Nat : (P : Nat -> Set) -> P zero -> ((n:Nat) -> P (suc n)) -> (n : Nat) -> P n -- test : Nat -> Nat test = case-Nat _ zero (\n -> n) {- data Size : Set where empty : Size nonempty : Size whatever : Size data Nat : Set where zero : Nat suc : Nat -> Nat data List (A:Set) : Set where nil : List A (::) : A -> List A -> List A data Monad (M:Set -> Set) : Set1 where monad : Monad M postulate build : {M:Set -> Set} -> Monad M -> {C:Size -> Set} -> (A:Set) -> (A -> C nonempty) -> ((n:Size) -> List (C n) -> M (List A)) -> List A -> M (C whatever) test : (A:Set) -> Nat test A = build monad A (\x -> x) (\n xs -> xs) nil -}
18.238095
68
0.513055
4ad9972bdc895f896b929e9012a9977c30d587d3
1,301
agda
Agda
agda-stdlib/src/Relation/Binary/Properties/MeetSemilattice.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Properties/MeetSemilattice.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Properties/MeetSemilattice.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by meet semilattices ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary.Lattice module Relation.Binary.Properties.MeetSemilattice {c ℓ₁ ℓ₂} (M : MeetSemilattice c ℓ₁ ℓ₂) where open MeetSemilattice M open import Algebra.Definitions _≈_ open import Data.Product open import Function using (flip) open import Relation.Binary open import Relation.Binary.Properties.Poset poset import Relation.Binary.Properties.JoinSemilattice as J -- The dual construction is a join semilattice. dualIsJoinSemilattice : IsJoinSemilattice _≈_ (flip _≤_) _∧_ dualIsJoinSemilattice = record { isPartialOrder = invIsPartialOrder ; supremum = infimum } dualJoinSemilattice : JoinSemilattice c ℓ₁ ℓ₂ dualJoinSemilattice = record { _∨_ = _∧_ ; isJoinSemilattice = dualIsJoinSemilattice } open J dualJoinSemilattice public using (isAlgSemilattice; algSemilattice) renaming ( ∨-monotonic to ∧-monotonic ; ∨-cong to ∧-cong ; ∨-comm to ∧-comm ; ∨-assoc to ∧-assoc ; ∨-idempotent to ∧-idempotent ; x≤y⇒x∨y≈y to y≤x⇒x∧y≈y )
27.680851
72
0.631822
fb7b6ee2e28e1fd84140703524de1f167455ca62
3,116
agda
Agda
out/Sub/Syntax.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
39
2021-11-09T20:39:55.000Z
2022-03-19T17:33:12.000Z
out/Sub/Syntax.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
1
2021-11-21T12:19:32.000Z
2021-11-21T12:19:32.000Z
out/Sub/Syntax.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
4
2021-11-09T20:39:59.000Z
2022-01-24T12:49:17.000Z
{- This second-order term syntax was created from the following second-order syntax description: syntax Sub | S type L : 0-ary T : 0-ary term vr : L -> T sb : L.T T -> T theory (C) x y : T |> sb (a. x[], y[]) = x[] (L) x : T |> sb (a. vr(a), x[]) = x[] (R) a : L x : L.T |> sb (b. x[b], vr(a[])) = x[a[]] (A) x : (L,L).T y : L.T z : T |> sb (a. sb (b. x[a,b], y[a]), z[]) = sb (b. sb (a. x[a, b], z[]), sb (a. y[a], z[])) -} module Sub.Syntax where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Construction.Structure open import SOAS.ContextMaps.Inductive open import SOAS.Metatheory.Syntax open import Sub.Signature private variable Γ Δ Π : Ctx α : ST 𝔛 : Familyₛ -- Inductive term declaration module S:Terms (𝔛 : Familyₛ) where data S : Familyₛ where var : ℐ ⇾̣ S mvar : 𝔛 α Π → Sub S Π Γ → S α Γ vr : S L Γ → S T Γ sb : S T (L ∙ Γ) → S T Γ → S T Γ open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛 Sᵃ : MetaAlg S Sᵃ = record { 𝑎𝑙𝑔 = λ where (vrₒ ⋮ a) → vr a (sbₒ ⋮ a , b) → sb a b ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) } module Sᵃ = MetaAlg Sᵃ module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where open MetaAlg 𝒜ᵃ 𝕤𝕖𝕞 : S ⇾̣ 𝒜 𝕊 : Sub S Π Γ → Π ~[ 𝒜 ]↝ Γ 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t 𝕊 (t ◂ σ) (old v) = 𝕊 σ v 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε) 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v 𝕤𝕖𝕞 (vr a) = 𝑎𝑙𝑔 (vrₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (sb a b) = 𝑎𝑙𝑔 (sbₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b) 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Sᵃ 𝒜ᵃ 𝕤𝕖𝕞 𝕤𝕖𝕞ᵃ⇒ = record { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t } ; ⟨𝑣𝑎𝑟⟩ = refl ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } } where open ≡-Reasoning ⟨𝑎𝑙𝑔⟩ : (t : ⅀ S α Γ) → 𝕤𝕖𝕞 (Sᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t) ⟨𝑎𝑙𝑔⟩ (vrₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (sbₒ ⋮ _) = refl 𝕊-tab : (mε : Π ~[ S ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v) 𝕊-tab mε new = refl 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v module _ (g : S ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Sᵃ 𝒜ᵃ g) where open MetaAlg⇒ gᵃ⇒ 𝕤𝕖𝕞! : (t : S α Γ) → 𝕤𝕖𝕞 t ≡ g t 𝕊-ix : (mε : Sub S Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v) 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε)) = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε)) 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩ 𝕤𝕖𝕞! (vr a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (sb a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩ -- Syntax instance for the signature S:Syn : Syntax S:Syn = record { ⅀F = ⅀F ; ⅀:CS = ⅀:CompatStr ; mvarᵢ = S:Terms.mvar ; 𝕋:Init = λ 𝔛 → let open S:Terms 𝔛 in record { ⊥ = S ⋉ Sᵃ ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ } ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } } -- Instantiation of the syntax and metatheory open Syntax S:Syn public open S:Terms public open import SOAS.Families.Build public open import SOAS.Syntax.Shorthands Sᵃ public open import SOAS.Metatheory S:Syn public
24.730159
120
0.520218
0e95f87f782e0e72ec6f0f1f31be46f52206c5f4
1,004
agda
Agda
test/Succeed/Issue826-2.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue826-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue826-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --guardedness #-} module Issue826-2 where open import Common.Coinduction data _≡_ {A : Set} (x y : A) : Set where data D : Set where c : ∞ D → D delay : D → ∞ D delay x = ♯ x data P : D → Set where o : (x : ∞ D) → P (♭ x) → P (c x) postulate h : (x : D) → P x → P x f : (x : D) → P (c (delay x)) → P x f x (o .(delay x) p) = h x p g : (x : D) → P x → P (c (delay x)) g x p = h (c (delay x)) (o (delay x) p) postulate bar : (x : ∞ D) (p : P (♭ x)) → h (c x) (o x (h (♭ x) p)) ≡ o x p foo : (x : D) (p : P (c (delay x))) → g x (f x p) ≡ p foo x (o .(delay x) p) = goal where x′ = _ goal : _ ≡ o x′ p goal = bar x′ p -- The following error message seems to indicate that an expression is -- not forced properly: -- -- Bug.agda:30,26-30 -- ♭ (.Bug.♯-0 x) != x of type D -- when checking that the expression goal has type -- g x (f x (o (.Bug.♯-0 x) p)) ≡ o (.Bug.♯-0 x) p -- -- Thus it seems as if this problem affects plain type-checking as -- well.
20.489796
70
0.511952
c5d1a5273b81901b87ce8b583d926c7bc2e1bfe9
555
agda
Agda
Orders/Partial/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Orders/Partial/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Orders/Partial/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Functions.Definition module Orders.Partial.Definition {a : _} (carrier : Set a) where record PartialOrder {b : _} : Set (a ⊔ lsuc b) where field _<_ : Rel {a} {b} carrier irreflexive : {x : carrier} → (x < x) → False <Transitive : {a b c : carrier} → (a < b) → (b < c) → (a < c) <WellDefined : {r s t u : carrier} → (r ≡ t) → (s ≡ u) → r < s → t < u <WellDefined refl refl r<s = r<s
32.647059
72
0.601802
23a61b4d73d21797d0810d01a954e4c9ebebc138
6,875
agda
Agda
agda-stdlib-0.9/src/Induction/Nat.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Induction/Nat.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Induction/Nat.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Various forms of induction for natural numbers ------------------------------------------------------------------------ module Induction.Nat where open import Function open import Data.Nat open import Data.Fin using (_≺_) open import Data.Fin.Properties open import Data.Product open import Data.Unit open import Induction open import Induction.WellFounded as WF open import Level using (Lift) open import Relation.Binary.PropositionalEquality open import Relation.Unary ------------------------------------------------------------------------ -- Ordinary induction Rec : ∀ ℓ → RecStruct ℕ ℓ ℓ Rec _ P zero = Lift ⊤ Rec _ P (suc n) = P n rec-builder : ∀ {ℓ} → RecursorBuilder (Rec ℓ) rec-builder P f zero = _ rec-builder P f (suc n) = f n (rec-builder P f n) rec : ∀ {ℓ} → Recursor (Rec ℓ) rec = build rec-builder ------------------------------------------------------------------------ -- Complete induction CRec : ∀ ℓ → RecStruct ℕ ℓ ℓ CRec _ P zero = Lift ⊤ CRec _ P (suc n) = P n × CRec _ P n cRec-builder : ∀ {ℓ} → RecursorBuilder (CRec ℓ) cRec-builder P f zero = _ cRec-builder P f (suc n) = f n ih , ih where ih = cRec-builder P f n cRec : ∀ {ℓ} → Recursor (CRec ℓ) cRec = build cRec-builder ------------------------------------------------------------------------ -- Complete induction based on _<′_ <-Rec : ∀ {ℓ} → RecStruct ℕ ℓ ℓ <-Rec = WfRec _<′_ mutual <-well-founded : Well-founded _<′_ <-well-founded n = acc (<-well-founded′ n) <-well-founded′ : ∀ n → <-Rec (Acc _<′_) n <-well-founded′ zero _ () <-well-founded′ (suc n) .n ≤′-refl = <-well-founded n <-well-founded′ (suc n) m (≤′-step m<n) = <-well-founded′ n m m<n module _ {ℓ} where open WF.All <-well-founded ℓ public renaming ( wfRec-builder to <-rec-builder ; wfRec to <-rec ) ------------------------------------------------------------------------ -- Complete induction based on _≺_ ≺-Rec : ∀ {ℓ} → RecStruct ℕ ℓ ℓ ≺-Rec = WfRec _≺_ ≺-well-founded : Well-founded _≺_ ≺-well-founded = Subrelation.well-founded ≺⇒<′ <-well-founded module _ {ℓ} where open WF.All ≺-well-founded ℓ public renaming ( wfRec-builder to ≺-rec-builder ; wfRec to ≺-rec ) ------------------------------------------------------------------------ -- Examples private module Examples where -- Doubles its input. twice : ℕ → ℕ twice = rec _ λ { zero _ → zero ; (suc n) twice-n → suc (suc twice-n) } -- Halves its input (rounding downwards). -- -- The step function is mentioned in a proof below, so it has been -- given a name. (The mutual keyword is used to avoid having to give -- a type signature for the step function.) mutual half₁-step = λ { zero _ → zero ; (suc zero) _ → zero ; (suc (suc n)) (_ , half₁n , _) → suc half₁n } half₁ : ℕ → ℕ half₁ = cRec _ half₁-step -- An alternative implementation of half₁. mutual half₂-step = λ { zero _ → zero ; (suc zero) _ → zero ; (suc (suc n)) rec → suc (rec n (≤′-step ≤′-refl)) } half₂ : ℕ → ℕ half₂ = <-rec _ half₂-step -- The application half₁ (2 + n) is definitionally equal to -- 1 + half₁ n. Perhaps it is instructive to see why. half₁-2+ : ∀ n → half₁ (2 + n) ≡ 1 + half₁ n half₁-2+ n = begin half₁ (2 + n) ≡⟨⟩ cRec (λ _ → ℕ) half₁-step (2 + n) ≡⟨⟩ half₁-step (2 + n) (cRec-builder (λ _ → ℕ) half₁-step (2 + n)) ≡⟨⟩ half₁-step (2 + n) (let ih = cRec-builder (λ _ → ℕ) half₁-step (1 + n) in half₁-step (1 + n) ih , ih) ≡⟨⟩ half₁-step (2 + n) (let ih = cRec-builder (λ _ → ℕ) half₁-step n in half₁-step (1 + n) (half₁-step n ih , ih) , half₁-step n ih , ih) ≡⟨⟩ 1 + half₁-step n (cRec-builder (λ _ → ℕ) half₁-step n) ≡⟨⟩ 1 + cRec (λ _ → ℕ) half₁-step n ≡⟨⟩ 1 + half₁ n ∎ where open ≡-Reasoning -- The application half₂ (2 + n) is definitionally equal to -- 1 + half₂ n. Perhaps it is instructive to see why. half₂-2+ : ∀ n → half₂ (2 + n) ≡ 1 + half₂ n half₂-2+ n = begin half₂ (2 + n) ≡⟨⟩ <-rec (λ _ → ℕ) half₂-step (2 + n) ≡⟨⟩ half₂-step (2 + n) (<-rec-builder (λ _ → ℕ) half₂-step (2 + n)) ≡⟨⟩ 1 + <-rec-builder (λ _ → ℕ) half₂-step (2 + n) n (≤′-step ≤′-refl) ≡⟨⟩ 1 + Some.wfRec-builder (λ _ → ℕ) half₂-step (2 + n) (<-well-founded (2 + n)) n (≤′-step ≤′-refl) ≡⟨⟩ 1 + Some.wfRec-builder (λ _ → ℕ) half₂-step (2 + n) (acc (<-well-founded′ (2 + n))) n (≤′-step ≤′-refl) ≡⟨⟩ 1 + half₂-step n (Some.wfRec-builder (λ _ → ℕ) half₂-step n (<-well-founded′ (2 + n) n (≤′-step ≤′-refl))) ≡⟨⟩ 1 + half₂-step n (Some.wfRec-builder (λ _ → ℕ) half₂-step n (<-well-founded′ (1 + n) n ≤′-refl)) ≡⟨⟩ 1 + half₂-step n (Some.wfRec-builder (λ _ → ℕ) half₂-step n (<-well-founded n)) ≡⟨⟩ 1 + half₂-step n (<-rec-builder (λ _ → ℕ) half₂-step n) ≡⟨⟩ 1 + <-rec (λ _ → ℕ) half₂-step n ≡⟨⟩ 1 + half₂ n ∎ where open ≡-Reasoning -- Some properties that the functions above satisfy, proved using -- cRec. half₁-+₁ : ∀ n → half₁ (twice n) ≡ n half₁-+₁ = cRec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) (_ , half₁twice-n≡n , _) → cong (suc ∘ suc) half₁twice-n≡n } half₂-+₁ : ∀ n → half₂ (twice n) ≡ n half₂-+₁ = cRec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) (_ , half₁twice-n≡n , _) → cong (suc ∘ suc) half₁twice-n≡n } -- Some properties that the functions above satisfy, proved using -- <-rec. half₁-+₂ : ∀ n → half₁ (twice n) ≡ n half₁-+₂ = <-rec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) rec → cong (suc ∘ suc) (rec n (≤′-step ≤′-refl)) } half₂-+₂ : ∀ n → half₂ (twice n) ≡ n half₂-+₂ = <-rec _ λ { zero _ → refl ; (suc zero) _ → refl ; (suc (suc n)) rec → cong (suc ∘ suc) (rec n (≤′-step ≤′-refl)) }
29.131356
77
0.453236
4a981f17bae682b8c200a5dccd1671de008fe0f9
206
agda
Agda
test/fail/ATPBadHint1.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
1
2016-03-17T01:45:59.000Z
2016-03-17T01:45:59.000Z
test/fail/ATPBadHint1.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
null
null
null
test/fail/ATPBadHint1.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
-- An ATP hint must be used with functions. -- This error is detected by Syntax.Translation.ConcreteToAbstract. module ATPBadHint1 where data Bool : Set where false true : Bool {-# ATP hint false #-}
18.727273
67
0.73301
c539cdf3e4af305f63e08ed240d8d74dc5765d11
835
agda
Agda
BasicT/Metatheory/Gentzen-BasicTarski.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicT/Metatheory/Gentzen-BasicTarski.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicT/Metatheory/Gentzen-BasicTarski.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module BasicT.Metatheory.Gentzen-BasicTarski where open import BasicT.Syntax.Gentzen public open import BasicT.Semantics.BasicTarski public -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A eval (var i) γ = lookup i γ eval (lam t) γ = λ a → eval t (γ , a) eval (app t u) γ = eval t γ $ eval u γ eval (pair t u) γ = eval t γ , eval u γ eval (fst t) γ = π₁ (eval t γ) eval (snd t) γ = π₂ (eval t γ) eval unit γ = ∙ eval true γ = true eval false γ = false eval (if t u v) γ = ifᴮ (eval t γ) (eval u γ) (eval v γ) eval zero γ = zero eval (suc t) γ = suc (eval t γ) eval (it t u v) γ = itᴺ (eval t γ) (eval u γ) (eval v γ) eval (rec t u v) γ = recᴺ (eval t γ) (eval u γ) (eval v γ) -- TODO: Correctness of evaluation with respect to conversion.
30.925926
62
0.601198
10f5c0c24a959673db8a16647c8994caf47b186c
5,228
agda
Agda
core/lib/cubical/SquareOver.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
core/lib/cubical/SquareOver.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
core/lib/cubical/SquareOver.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Base open import lib.PathGroupoid open import lib.PathOver open import lib.cubical.Square module lib.cubical.SquareOver where SquareOver : ∀ {i j} {A : Type i} (B : A → Type j) {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} (sq : Square p₀₋ p₋₀ p₋₁ p₁₋) {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} (q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]) (q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]) (q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]) (q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]) → Type j SquareOver B ids = Square apd-square : ∀ {i j} {A : Type i} {B : A → Type j} (f : Π A B) {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} (sq : Square p₀₋ p₋₀ p₋₁ p₁₋) → SquareOver B sq (apd f p₀₋) (apd f p₋₀) (apd f p₋₁) (apd f p₁₋) apd-square f ids = ids ↓-=-to-squareover : ∀ {i j} {A : Type i} {B : A → Type j} {f g : Π A B} {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} → u == v [ (λ z → f z == g z) ↓ p ] → SquareOver B vid-square u (apd f p) (apd g p) v ↓-=-to-squareover {p = idp} idp = hid-square ↓-=-from-squareover : ∀ {i j} {A : Type i} {B : A → Type j} {f g : Π A B} {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} → SquareOver B vid-square u (apd f p) (apd g p) v → u == v [ (λ z → f z == g z) ↓ p ] ↓-=-from-squareover {p = idp} sq = horiz-degen-path sq squareover-cst-in : ∀ {i j} {A : Type i} {B : Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ b₀₁ b₁₀ b₁₁ : B} {q₀₋ : b₀₀ == b₀₁} {q₋₀ : b₀₀ == b₁₀} {q₋₁ : b₀₁ == b₁₁} {q₁₋ : b₁₀ == b₁₁} (sq' : Square q₀₋ q₋₀ q₋₁ q₁₋) → SquareOver (λ _ → B) sq (↓-cst-in q₀₋) (↓-cst-in q₋₀) (↓-cst-in q₋₁) (↓-cst-in q₁₋) squareover-cst-in {sq = ids} sq' = sq' ↓↓-from-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)} {p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂} {α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]} → SquareOver B (natural-square p q) α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β → α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ] ↓↓-from-squareover {q = idp} sq = lemma sq where lemma : ∀ {i j} {A : Type i} {B : A → Type j} {x y : A} {u : B x} {v : B y} {p : x == y} {α β : u == v [ B ↓ p ]} → SquareOver B hid-square α idp idp β → α == β lemma {p = idp} sq = horiz-degen-path sq ↓↓-to-squareover : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x y : C → A} {u : (c : C) → B (x c)} {v : (c : C) → B (y c)} {p : (c : C) → x c == y c} {c₁ c₂ : C} {q : c₁ == c₂} {α : u c₁ == v c₁ [ B ↓ p c₁ ]} {β : u c₂ == v c₂ [ B ↓ p c₂ ]} → α == β [ (λ c → u c == v c [ B ↓ p c ]) ↓ q ] → SquareOver B (natural-square p q) α (↓-ap-in _ _ (apd u q)) (↓-ap-in _ _ (apd v q)) β ↓↓-to-squareover {q = idp} r = lemma r where lemma : ∀ {i j} {A : Type i} {B : A → Type j} {x y : A} {u : B x} {v : B y} {p : x == y} {α β : u == v [ B ↓ p ]} → α == β → SquareOver B hid-square α idp idp β lemma {p = idp} r = horiz-degen-square r infixr 80 _∙v↓⊡_ _∙h↓⊡_ _↓⊡v∙_ _↓⊡h∙_ _∙h↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ q₀₋' : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → q₀₋ == q₀₋' → SquareOver B sq q₀₋' q₋₀ q₋₁ q₁₋ → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ _∙h↓⊡_ {sq = ids} = _∙h⊡_ _∙v↓⊡_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ q₋₀' : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → q₋₀ == q₋₀' → SquareOver B sq q₀₋ q₋₀' q₋₁ q₁₋ → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ _∙v↓⊡_ {sq = ids} = _∙v⊡_ _↓⊡v∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ q₋₁' : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ → q₋₁ == q₋₁' → SquareOver B sq q₀₋ q₋₀ q₋₁' q₁₋ _↓⊡v∙_ {sq = ids} = _⊡v∙_ _↓⊡h∙_ : ∀ {i j} {A : Type i} {B : A → Type j} {a₀₀ a₀₁ a₁₀ a₁₁ : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁} {sq : Square p₀₋ p₋₀ p₋₁ p₁₋} {b₀₀ : B a₀₀} {b₀₁ : B a₀₁} {b₁₀ : B a₁₀} {b₁₁ : B a₁₁} {q₀₋ : b₀₀ == b₀₁ [ B ↓ p₀₋ ]} {q₋₀ : b₀₀ == b₁₀ [ B ↓ p₋₀ ]} {q₋₁ : b₀₁ == b₁₁ [ B ↓ p₋₁ ]} {q₁₋ q₁₋' : b₁₀ == b₁₁ [ B ↓ p₁₋ ]} → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋ → q₁₋ == q₁₋' → SquareOver B sq q₀₋ q₋₀ q₋₁ q₁₋' _↓⊡h∙_ {sq = ids} = _⊡h∙_
41.165354
77
0.446825
4a327fa6a00ed5ae98e0a2f9cb9766ca3d7d9bd4
437
agda
Agda
src/Tactic/Nat/Exp.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Tactic/Nat/Exp.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Tactic/Nat/Exp.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Tactic.Nat.Exp where open import Prelude Var = Nat Env : Set → Set Env Atom = Atom → Nat infixl 6 _⟨+⟩_ infixl 7 _⟨*⟩_ data Exp (Atom : Set) : Set where var : (x : Atom) → Exp Atom lit : (n : Nat) → Exp Atom _⟨+⟩_ _⟨*⟩_ : (e e₁ : Exp Atom) → Exp Atom ⟦_⟧e : ∀ {Atom} → Exp Atom → Env Atom → Nat ⟦ var x ⟧e ρ = ρ x ⟦ lit n ⟧e ρ = n ⟦ e₁ ⟨+⟩ e₂ ⟧e ρ = ⟦ e₁ ⟧e ρ + ⟦ e₂ ⟧e ρ ⟦ e₁ ⟨*⟩ e₂ ⟧e ρ = ⟦ e₁ ⟧e ρ * ⟦ e₂ ⟧e ρ
18.208333
44
0.514874
104caa697dcdaa0b658eb6e4c0cc6eb7ed790ecd
565
agda
Agda
RecursiveTypes/Subtyping/Example.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
1
2021-02-13T14:48:45.000Z
2021-02-13T14:48:45.000Z
RecursiveTypes/Subtyping/Example.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
RecursiveTypes/Subtyping/Example.agda
nad/codata
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- An example ------------------------------------------------------------------------ module RecursiveTypes.Subtyping.Example where open import Codata.Musical.Notation open import Data.Fin open import Data.Nat open import RecursiveTypes.Syntax open import RecursiveTypes.Subtyping.Semantic.Coinductive -- σ = μX. X ⟶ X. σ : Ty 0 σ = μ var zero ⟶ var zero -- τ = μX. (X ⟶ ⊥) ⟶ ⊤. τ : Ty 0 τ = μ (var zero ⟶ ⊥) ⟶ ⊤ -- σ is a subtype of τ. σ≤τ : σ ≤Coind τ σ≤τ = ♯ (♯ σ≤τ ⟶ ♯ ⊥) ⟶ ♯ ⊤
20.178571
72
0.470796
0b6ea86a4ee0ddbe1a933299b9b4fb0697ce211f
538
agda
Agda
agda-stdlib/src/Data/List/Any/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Any/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Any/Properties.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Unary.Any.Properties directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Any.Properties where open import Data.List.Relation.Unary.Any.Properties public {-# WARNING_ON_IMPORT "Data.List.Any.Properties was deprecated in v1.0. Use Data.List.Relation.Unary.Any.Properties instead." #-}
29.888889
72
0.550186
4ab64de6a2384eaa3940d66fe10269bd07df7b96
385
agda
Agda
src/prototyping/term/examples/Nat.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
src/prototyping/term/examples/Nat.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
src/prototyping/term/examples/Nat.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Nat where data Nat : Set data Nat where zero : Nat suc : Nat -> Nat plus : Nat -> Nat -> Nat plus zero n = n plus (suc m) n = suc (plus m n) elim : (P : (n : Nat) -> Set) -> (z : P (plus zero zero)) -> (s : (n : Nat) -> P (plus zero n) -> P (plus (suc zero) n)) -> (n : Nat) -> P n elim P z s zero = z elim P z s (suc n) = s n (elim P z s n)
20.263158
69
0.483117
1842fc52187acd383680a1444c5e1e7b97a0e9f3
2,710
agda
Agda
src/NTypes.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
src/NTypes.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
src/NTypes.agda
vituscze/HoTT-lectures
7730385adfdbdda38ee8b124be3cdeebb7312c65
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K #-} module NTypes where open import Equivalence open import FunExt open import GroupoidStructure open import NTypes.Contractible open import PathOperations open import Transport open import Types isProp : ∀ {a} → Set a → Set _ isProp A = (x y : A) → x ≡ y isSet : ∀ {a} → Set a → Set _ isSet A = (x y : A) (p q : x ≡ y) → p ≡ q set→id-prop : ∀ {a} {A : Set a} → isSet A → {x y : A} → isProp (x ≡ y) set→id-prop A-set = A-set _ _ id-prop→set : ∀ {a} {A : Set a} → ({x y : A} → isProp (x ≡ y)) → isSet A id-prop→set f _ _ = f prop-eq : ∀ {a b} {A : Set a} {B : Set b} → A ≃ B → isProp A → isProp B prop-eq (f , (g , α) , (h , β)) A-prop x y = tr id ( ap (λ z → z ≡ f (g y)) (α x) · ap (λ z → x ≡ z) (α y) ) (ap f (A-prop (g x) (g y))) -- Levels. is-[_-2]-type : ℕ → ∀ {a} → Set a → Set a is-[ n -2]-type = ind (λ _ → Set _ → Set _) (λ _ r A → (x y : A) → r (x ≡ y)) isContr n -- isProp and is-(-1)-type. prop→-1-type : ∀ {a} {A : Set a} → isProp A → is-[ 1 -2]-type A prop→-1-type {A = A} A-prop x y = A-prop x y , path where split-path : {x y : A} (p : x ≡ y) → A-prop x y ≡ p · A-prop y y split-path = J (λ x y p → A-prop x y ≡ p · A-prop y y) (λ _ → refl) _ _ path : {x y : A} (p : x ≡ y) → A-prop x y ≡ p path = J (λ x y p → A-prop x y ≡ p) (λ x → split-path (A-prop x x ⁻¹) · p⁻¹·p (A-prop x x)) _ _ -1-type→prop : ∀ {a} {A : Set a} → is-[ 1 -2]-type A → isProp A -1-type→prop A-1 x y = π₁ (A-1 x y) -- isSet and is-0-type. set→0-type : ∀ {a} {A : Set a} → isSet A → is-[ 2 -2]-type A set→0-type A-set x y = prop→-1-type (A-set x y) 0-type→set : ∀ {a} {A : Set a} → is-[ 2 -2]-type A → isSet A 0-type→set A0 x y = -1-type→prop (A0 x y) -- Cumulativity. n-type-suc : ∀ n {a} {A : Set a} → is-[ n -2]-type A → is-[ suc n -2]-type A n-type-suc n = ind (λ n → ∀ {A} → is-[ n -2]-type A → is-[ suc n -2]-type A) (λ _ r h x y → r (h x y)) (λ h → prop→-1-type λ x y → π₂ h x ⁻¹ · π₂ h y) n -- From lectures. prop→set : ∀ {a} {A : Set a} → isProp A → isSet A prop→set A-prop x y p q = lem p · lem q ⁻¹ where g : _ g = A-prop x lem : (p : x ≡ y) → p ≡ g x ⁻¹ · g y lem p = id·p p ⁻¹ · ap (λ z → z · p) (p⁻¹·p (g x)) ⁻¹ · p·q·r (g x ⁻¹) (g x) p ⁻¹ · ap (λ z → g x ⁻¹ · z) ( tr-post x p (g x) ⁻¹ · apd g p ) isProp-is-prop : ∀ {a} {A : Set a} → isProp (isProp A) isProp-is-prop f g = funext λ x → funext λ y → prop→set f _ _ (f x y) (g x y) isSet-is-prop : ∀ {a} {A : Set a} → isProp (isSet A) isSet-is-prop f g = funext λ x → funext λ y → funext λ p → funext λ q → prop→set (f x y) _ _ (f x y p q) (g x y p q)
23.362069
71
0.483026
235bceb046a8a8646e92fdd04e32ed41299ce8f5
2,450
agda
Agda
test/agda/FRP/JS/Test/Nat.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
63
2015-04-20T21:47:00.000Z
2022-02-28T09:46:14.000Z
test/agda/FRP/JS/Test/Nat.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
null
null
null
test/agda/FRP/JS/Test/Nat.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
7
2016-11-07T21:50:58.000Z
2022-03-12T11:39:38.000Z
open import FRP.JS.Bool using ( Bool ; not ) open import FRP.JS.Maybe using ( Maybe ; just ; nothing ; _≟[_]_ ) open import FRP.JS.Nat using ( ℕ ; _≟_ ; _+_ ; _*_ ; _∸_ ; _/_ ; _/?_ ; _≤_ ; _<_ ; show ; float ) open import FRP.JS.Float using ( ℝ ) renaming ( _≟_ to _≟r_ ) open import FRP.JS.String using () renaming ( _≟_ to _≟s_ ) open import FRP.JS.QUnit using ( TestSuite ; ok ; ok! ; test ; _,_ ) module FRP.JS.Test.Nat where infixr 2 _≟?r_ _≟?r_ : Maybe ℝ → Maybe ℝ → Bool x ≟?r y = x ≟[ _≟r_ ] y tests : TestSuite tests = ( test "≟" ( ok "0 ≟ 0" (0 ≟ 0) , ok "1 ≟ 1" (1 ≟ 1) , ok "2 ≟ 2" (2 ≟ 2) , ok "0 != 1" (not (0 ≟ 1)) , ok "0 != 2" (not (0 ≟ 2)) , ok "1 != 2" (not (1 ≟ 2)) , ok "1 != 0" (not (1 ≟ 0)) ) , test "+" ( ok "0 + 0" (0 + 0 ≟ 0) , ok "1 + 1" (1 + 1 ≟ 2) , ok "37 + 0" (37 + 0 ≟ 37) , ok "37 + 1" (37 + 1 ≟ 38) , ok "37 + 5" (37 + 5 ≟ 42) ) , test "*" ( ok "0 * 0" (0 * 0 ≟ 0) , ok "1 * 1" (1 * 1 ≟ 1) , ok "37 * 0" (37 * 0 ≟ 0) , ok "37 * 1" (37 * 1 ≟ 37) , ok "37 * 5" (37 * 5 ≟ 185) ) , test "∸" ( ok "0 ∸ 0" (0 ∸ 0 ≟ 0) , ok "1 ∸ 1" (1 ∸ 1 ≟ 0) , ok "37 ∸ 0" (37 ∸ 0 ≟ 37) , ok "37 ∸ 1" (37 ∸ 1 ≟ 36) , ok "37 ∸ 5" (37 ∸ 5 ≟ 32) , ok "5 ∸ 37" (5 ∸ 37 ≟ 0) ) , test "/" ( ok "1 / 1" (1 / 1 ≟r 1.0) , ok "37 / 1" (37 / 1 ≟r 37.0) , ok "37 / 5" (37 / 5 ≟r 7.4) , ok "0 /? 0" (0 /? 0 ≟?r nothing) , ok "1 /? 1" (1 /? 1 ≟?r just 1.0) , ok "37 /? 0" (37 /? 0 ≟?r nothing) , ok "37 /? 1" (37 /? 1 ≟?r just 37.0) , ok "37 /? 5" (37 /? 5 ≟?r just 7.4) ) , test "≤" ( ok "0 ≤ 0" (0 ≤ 0) , ok "0 ≤ 1" (0 ≤ 1) , ok "1 ≤ 0" (not (1 ≤ 0)) , ok "1 ≤ 1" (1 ≤ 1) , ok "37 ≤ 0" (not (37 ≤ 0)) , ok "37 ≤ 1" (not (37 ≤ 1)) , ok "37 ≤ 5" (not (37 ≤ 5)) , ok "5 ≤ 37" (5 ≤ 37) ) , test "<" ( ok "0 < 0" (not (0 < 0)) , ok "0 < 1" (0 < 1) , ok "1 < 0" (not (1 < 0)) , ok "1 < 1" (not (1 < 1)) , ok "37 < 0" (not (37 < 0)) , ok "37 < 1" (not (37 < 1)) , ok "37 < 5" (not (37 < 5)) , ok "5 < 37" (5 < 37) ) , test "show" ( ok "show 0" (show 0 ≟s "0") , ok "show 1" (show 1 ≟s "1") , ok "show 5" (show 5 ≟s "5") , ok "show 37" (show 37 ≟s "37") ) , test "float" ( ok "float 0" (float 0 ≟r 0.0) , ok "float 1" (float 1 ≟r 1.0) , ok "float 5" (float 5 ≟r 5.0) , ok "float 37" (float 37 ≟r 37.0) ) )
30.246914
98
0.386531
0bc05fafd5bac1a9749467899e1b1683c6cdf6cb
5,059
agda
Agda
Univalence/OldUnivalence/Equivalences.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
14
2015-08-18T21:40:15.000Z
2021-05-05T01:07:57.000Z
Univalence/OldUnivalence/Equivalences.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
4
2018-06-07T16:27:41.000Z
2021-10-29T20:41:23.000Z
Univalence/OldUnivalence/Equivalences.agda
JacquesCarette/pi-dual
003835484facfde0b770bc2b3d781b42b76184c1
[ "BSD-2-Clause" ]
3
2016-05-29T01:56:33.000Z
2019-09-10T09:47:13.000Z
{-# OPTIONS --without-K #-} module Equivalences where open import Level open import Data.Empty open import Data.Sum renaming (map to _⊎→_) open import Data.Product renaming (map to _×→_) open import Function renaming (_∘_ to _○_) open import SimpleHoTT infix 4 _∼_ -- homotopy between two functions infix 4 _≃_ -- type of equivalences infix 2 _∎≃ -- equational reasoning for equivalences infixr 2 _≃⟨_⟩_ -- equational reasoning for equivalences -- Equivalences _∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} → (f g : (x : A) → P x) → Set (ℓ ⊔ ℓ') _∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x -- Lemma 2.4.2 refl∼ : {A B : Set} {f : A → B} → (f ∼ f) refl∼ {A} {B} {f} x = refl (f x) sym∼ : {A B : Set} {f g : A → B} → (f ∼ g) → (g ∼ f) sym∼ H x = ! (H x) trans∼ : {A B : Set} {f g h : A → B} → (f ∼ g) → (g ∼ h) → (f ∼ h) trans∼ H G x = H x ∘ G x -- record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkqinv field g : B → A α : (f ○ g) ∼ id β : (g ○ f) ∼ id idqinv : ∀ {ℓ} → {A : Set ℓ} → qinv {ℓ} {ℓ} {A} {A} id idqinv = record { g = id ; α = λ b → refl b ; β = λ a → refl a } record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) : Set (ℓ ⊔ ℓ') where constructor mkisequiv field g : B → A α : (f ○ g) ∼ id h : B → A β : (h ○ f) ∼ id equiv₁ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f equiv₁ (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ equiv₂ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → isequiv f → qinv f equiv₂ {f = f} (mkisequiv ig iα ih iβ) = record { g = ig ; α = iα ; β = λ x → ig (f x) ≡⟨ ! (iβ (ig (f x))) ⟩ ih (f (ig (f x))) ≡⟨ ap ih (iα (f x)) ⟩ ih (f x) ≡⟨ iβ x ⟩ x ∎ } _≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ ⊔ ℓ') A ≃ B = Σ (A → B) isequiv id≃ : ∀ {ℓ} {A : Set ℓ} → A ≃ A id≃ = (id , equiv₁ idqinv) sym≃ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → (A ≃ B) → B ≃ A sym≃ (A→B , equiv) with equiv₂ equiv ... | mkqinv g α β = g , equiv₁ (mkqinv A→B β α) trans≃ : {A B C : Set} → A ≃ B → B ≃ C → A ≃ C trans≃ (f , feq) (g , geq) with equiv₂ feq | equiv₂ geq ... | mkqinv ff fα fβ | mkqinv gg gα gβ = (g ○ f , equiv₁ (mkqinv (ff ○ gg) (λ c → g (f (ff (gg c))) ≡⟨ ap g (fα (gg c)) ⟩ g (gg c) ≡⟨ gα c ⟩ c ∎) (λ a → ff (gg (g (f a))) ≡⟨ ap ff (gβ (f a)) ⟩ ff (f a) ≡⟨ fβ a ⟩ a ∎))) -- equivalences are injective _⋆_ : {A B : Set} → (A ≃ B) → (x : A) → B (f , _) ⋆ x = f x inj≃ : {A B : Set} → (eq : A ≃ B) → (x y : A) → (eq ⋆ x ≡ eq ⋆ y → x ≡ y) inj≃ (f , mkisequiv g α h β) x y p = ! (β x) ∘ (ap h p ∘ β y) -- equivalences for coproducts (Sec. 2.12) codeqinv : {A B : Set} {a₀ : A} {x : A ⊎ B} → qinv (encode a₀ x) codeqinv {A} {B} {a₀} {x} = record { g = decode a₀ x ; α = indCP (λ x → (c : code a₀ x) → encode a₀ x (decode a₀ x c) ≡ c) (λ a c → encode a₀ (inj₁ a) (decode a₀ (inj₁ a) c) ≡⟨ bydef ⟩ encode a₀ (inj₁ a) (ap inj₁ c) ≡⟨ bydef ⟩ transport (code a₀) (ap inj₁ c) (refl a₀) ≡⟨ ! (transport-f inj₁ (code a₀) c (refl a₀)) ⟩ transport (λ a → code {A} {B} a₀ (inj₁ a)) c (refl a₀) ≡⟨ bydef ⟩ transport (λ a → a₀ ≡ a) c (refl a₀) ≡⟨ transportIdR c (refl a₀) ⟩ (refl a₀) ∘ c ≡⟨ ! (unitTransL c) ⟩ c ∎) (λ b ()) x ; β = λ p → basedPathInd (inj₁ a₀) (λ x p → decode a₀ x (encode a₀ x p) ≡ p) (decode a₀ (inj₁ a₀) (encode {A} {B} a₀ (inj₁ a₀) (refl (inj₁ a₀))) ≡⟨ bydef ⟩ (decode a₀ (inj₁ a₀) (transport (code {A} {B} a₀) (refl (inj₁ a₀)) (refl a₀))) ≡⟨ bydef ⟩ (decode a₀ (inj₁ a₀) (refl a₀)) ≡⟨ bydef ⟩ (ap inj₁ (refl a₀)) ≡⟨ bydef ⟩ refl (inj₁ a₀) ∎) x p } thm2-12-5 : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (inj₁ a₀ ≡ x) ≃ code a₀ x thm2-12-5 {A} {B} a₀ x = (encode a₀ x , equiv₁ codeqinv) inj₁₁path : {A B : Set} → (a₁ a₂ : A) → (inj₁ {A = A} {B = B} a₁ ≡ inj₁ a₂) ≃ (a₁ ≡ a₂) inj₁₁path a₁ a₂ = thm2-12-5 a₁ (inj₁ a₂) inj₁₂path : {A B : Set} → (a : A) (b : B) → (inj₁ a ≡ inj₂ b) ≃ ⊥ inj₁₂path a b = thm2-12-5 a (inj₂ b) -- Abbreviations for equivalence compositions _≃⟨_⟩_ : (A : Set) {B C : Set} → (A ≃ B) → (B ≃ C) → (A ≃ C) _ ≃⟨ p ⟩ q = trans≃ p q _∎≃ : {ℓ : Level} {A : Set ℓ} → A ≃ A _∎≃ {ℓ} {A} = id≃ {ℓ} {A}
30.293413
77
0.401858
10fe317b542557d6c20eaf6cd536449fa388f96c
6,193
agda
Agda
vendor/stdlib/src/Relation/Binary/Flip.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Relation/Binary/Flip.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Relation/Binary/Flip.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- Many properties which hold for _∼_ also hold for flip₁ _∼_ ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.Flip where open import Data.Function open import Data.Product implies : ∀ {A} (≈ ∼ : Rel A) → ≈ ⇒ ∼ → flip₁ ≈ ⇒ flip₁ ∼ implies _ _ impl = impl reflexive : ∀ {A} (∼ : Rel A) → Reflexive ∼ → Reflexive (flip₁ ∼) reflexive _ refl = refl irreflexive : ∀ {A} (≈ ∼ : Rel A) → Irreflexive ≈ ∼ → Irreflexive (flip₁ ≈) (flip₁ ∼) irreflexive _ _ irrefl = irrefl symmetric : ∀ {A} (∼ : Rel A) → Symmetric ∼ → Symmetric (flip₁ ∼) symmetric _ sym = sym transitive : ∀ {A} (∼ : Rel A) → Transitive ∼ → Transitive (flip₁ ∼) transitive _ trans = flip trans antisymmetric : ∀ {A} (≈ ≤ : Rel A) → Antisymmetric ≈ ≤ → Antisymmetric (flip₁ ≈) (flip₁ ≤) antisymmetric _ _ antisym = antisym asymmetric : ∀ {A} (< : Rel A) → Asymmetric < → Asymmetric (flip₁ <) asymmetric _ asym = asym respects : ∀ {A} (∼ : Rel A) P → Symmetric ∼ → P Respects ∼ → P Respects flip₁ ∼ respects _ _ sym resp ∼ = resp (sym ∼) respects₂ : ∀ {A} (∼₁ ∼₂ : Rel A) → Symmetric ∼₂ → ∼₁ Respects₂ ∼₂ → flip₁ ∼₁ Respects₂ flip₁ ∼₂ respects₂ _ _ sym (resp₁ , resp₂) = ((λ {_} {_} {_} ∼ → resp₂ (sym ∼)) , λ {_} {_} {_} ∼ → resp₁ (sym ∼)) decidable : ∀ {A} (∼ : Rel A) → Decidable ∼ → Decidable (flip₁ ∼) decidable _ dec x y = dec y x total : ∀ {A} (∼ : Rel A) → Total ∼ → Total (flip₁ ∼) total _ tot x y = tot y x trichotomous : ∀ {A} (≈ < : Rel A) → Trichotomous ≈ < → Trichotomous (flip₁ ≈) (flip₁ <) trichotomous _ _ compare x y = compare y x isEquivalence : ∀ {A} {≈ : Rel A} → IsEquivalence ≈ → IsEquivalence (flip₁ ≈) isEquivalence {≈ = ≈} eq = record { refl = reflexive ≈ Eq.refl ; sym = symmetric ≈ Eq.sym ; trans = transitive ≈ Eq.trans } where module Eq = IsEquivalence eq setoid : Setoid → Setoid setoid S = record { _≈_ = flip₁ S._≈_ ; isEquivalence = isEquivalence S.isEquivalence } where module S = Setoid S isPreorder : ∀ {A} {≈ ∼ : Rel A} → IsPreorder ≈ ∼ → IsPreorder (flip₁ ≈) (flip₁ ∼) isPreorder {≈ = ≈} {∼} pre = record { isEquivalence = isEquivalence Pre.isEquivalence ; reflexive = implies ≈ ∼ Pre.reflexive ; trans = transitive ∼ Pre.trans ; ∼-resp-≈ = respects₂ ∼ ≈ Pre.Eq.sym Pre.∼-resp-≈ } where module Pre = IsPreorder pre preorder : Preorder → Preorder preorder P = record { _∼_ = flip₁ P._∼_ ; _≈_ = flip₁ P._≈_ ; isPreorder = isPreorder P.isPreorder } where module P = Preorder P isDecEquivalence : ∀ {A} {≈ : Rel A} → IsDecEquivalence ≈ → IsDecEquivalence (flip₁ ≈) isDecEquivalence {≈ = ≈} dec = record { isEquivalence = isEquivalence Dec.isEquivalence ; _≟_ = decidable ≈ Dec._≟_ } where module Dec = IsDecEquivalence dec decSetoid : DecSetoid → DecSetoid decSetoid S = record { _≈_ = flip₁ S._≈_ ; isDecEquivalence = isDecEquivalence S.isDecEquivalence } where module S = DecSetoid S isPartialOrder : ∀ {A} {≈ ≤ : Rel A} → IsPartialOrder ≈ ≤ → IsPartialOrder (flip₁ ≈) (flip₁ ≤) isPartialOrder {≈ = ≈} {≤} po = record { isPreorder = isPreorder Po.isPreorder ; antisym = antisymmetric ≈ ≤ Po.antisym } where module Po = IsPartialOrder po poset : Poset → Poset poset O = record { _≈_ = flip₁ O._≈_ ; _≤_ = flip₁ O._≤_ ; isPartialOrder = isPartialOrder O.isPartialOrder } where module O = Poset O isStrictPartialOrder : ∀ {A} {≈ < : Rel A} → IsStrictPartialOrder ≈ < → IsStrictPartialOrder (flip₁ ≈) (flip₁ <) isStrictPartialOrder {≈ = ≈} {<} spo = record { isEquivalence = isEquivalence Spo.isEquivalence ; irrefl = irreflexive ≈ < Spo.irrefl ; trans = transitive < Spo.trans ; <-resp-≈ = respects₂ < ≈ Spo.Eq.sym Spo.<-resp-≈ } where module Spo = IsStrictPartialOrder spo strictPartialOrder : StrictPartialOrder → StrictPartialOrder strictPartialOrder O = record { _≈_ = flip₁ O._≈_ ; _<_ = flip₁ O._<_ ; isStrictPartialOrder = isStrictPartialOrder O.isStrictPartialOrder } where module O = StrictPartialOrder O isTotalOrder : ∀ {A} {≈ ≤ : Rel A} → IsTotalOrder ≈ ≤ → IsTotalOrder (flip₁ ≈) (flip₁ ≤) isTotalOrder {≈ = ≈} {≤} to = record { isPartialOrder = isPartialOrder To.isPartialOrder ; total = total ≤ To.total } where module To = IsTotalOrder to totalOrder : TotalOrder → TotalOrder totalOrder O = record { _≈_ = flip₁ O._≈_ ; _≤_ = flip₁ O._≤_ ; isTotalOrder = isTotalOrder O.isTotalOrder } where module O = TotalOrder O isDecTotalOrder : ∀ {A} {≈ ≤ : Rel A} → IsDecTotalOrder ≈ ≤ → IsDecTotalOrder (flip₁ ≈) (flip₁ ≤) isDecTotalOrder {≈ = ≈} {≤} dec = record { isTotalOrder = isTotalOrder Dec.isTotalOrder ; _≟_ = decidable ≈ Dec._≟_ ; _≤?_ = decidable ≤ Dec._≤?_ } where module Dec = IsDecTotalOrder dec decTotalOrder : DecTotalOrder → DecTotalOrder decTotalOrder O = record { _≈_ = flip₁ O._≈_ ; _≤_ = flip₁ O._≤_ ; isDecTotalOrder = isDecTotalOrder O.isDecTotalOrder } where module O = DecTotalOrder O isStrictTotalOrder : ∀ {A} {≈ < : Rel A} → IsStrictTotalOrder ≈ < → IsStrictTotalOrder (flip₁ ≈) (flip₁ <) isStrictTotalOrder {≈ = ≈} {<} sto = record { isEquivalence = isEquivalence Sto.isEquivalence ; trans = transitive < Sto.trans ; compare = trichotomous ≈ < Sto.compare ; <-resp-≈ = respects₂ < ≈ Sto.Eq.sym Sto.<-resp-≈ } where module Sto = IsStrictTotalOrder sto strictTotalOrder : StrictTotalOrder → StrictTotalOrder strictTotalOrder O = record { _≈_ = flip₁ O._≈_ ; _<_ = flip₁ O._<_ ; isStrictTotalOrder = isStrictTotalOrder O.isStrictTotalOrder } where module O = StrictTotalOrder O
33.657609
72
0.578556
4a55ddc35cfdb4c0755b77f9e95eb38eafcc20b7
493
agda
Agda
agda-stdlib/src/Data/Word.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Word.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Word.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Machine words ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Word where ------------------------------------------------------------------------ -- Re-export base definitions and decidability of equality open import Data.Word.Base public open import Data.Word.Properties using (_≈?_; _<?_; _≟_; _==_) public
30.8125
72
0.395538
0b2ec2e82730d119bd61fce9af9dabcba8a39833
4,378
agda
Agda
Rings/PrincipalIdealDomains/Lemmas.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Rings/PrincipalIdealDomains/Lemmas.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Rings/PrincipalIdealDomains/Lemmas.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Sets.EquivalenceRelations open import Setoids.Setoids open import Rings.Definition open import Rings.PrincipalIdealDomains.Definition open import Rings.IntegralDomains.Definition open import Rings.Ideals.Maximal.Definition module Rings.PrincipalIdealDomains.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) (pid : {c : _} → PrincipalIdealDomain intDom {c}) where open import Rings.Ideals.Definition R open import Rings.Irreducibles.Definition intDom open import Rings.Ideals.Principal.Definition R open import Rings.Divisible.Definition R open import Rings.Associates.Lemmas intDom open import Rings.Ideals.Lemmas R open import Rings.Units.Definition R open import Rings.Irreducibles.Lemmas intDom open import Rings.Units.Lemmas R open import Rings.Ideals.Prime.Definition {R = R} open import Rings.Ideals.Prime.Lemmas {R = R} open import Rings.Primes.Definition intDom open import Rings.Primes.Lemmas intDom open import Rings.Ideals.Principal.Lemmas R open import Rings.Ideals.Maximal.Lemmas {R = R} open Ring R open Setoid S open Equivalence eq irreducibleImpliesMaximalIdeal : {r : A} → Irreducible r → {d : _} → MaximalIdeal (generatedIdeal r) {d} MaximalIdeal.notContained (irreducibleImpliesMaximalIdeal {r} irred {d}) = 1R MaximalIdeal.notContainedIsNotContained (irreducibleImpliesMaximalIdeal {r} irred {d}) = Irreducible.nonunit irred MaximalIdeal.isMaximal (irreducibleImpliesMaximalIdeal {r} irred {d}) {biggerPred} bigger biggerContains (outsideR , (biggerContainsOutside ,, notInR)) {x} = biggerPrincipal' (unitImpliesGeneratedIdealEverything w {x}) where biggerGen : A biggerGen = PrincipalIdeal.generator (pid bigger) biggerPrincipal : {x : A} → biggerPred x → biggerGen ∣ x biggerPrincipal = PrincipalIdeal.genGenerates (pid bigger) bp : biggerPred biggerGen bp = PrincipalIdeal.genIsInIdeal (pid bigger) biggerPrincipal' : {x : A} → biggerGen ∣ x → biggerPred x biggerPrincipal' {y} bg|y = memberDividesImpliesMember bigger bp bg|y u : biggerGen ∣ r u = biggerPrincipal (biggerContains (1R , transitive *Commutative identIsIdent)) biggerGenNonzero : biggerGen ∼ 0R → False biggerGenNonzero bg=0 = notInR (Ideal.isSubset (generatedIdeal r) (symmetric t) (Ideal.containsIdentity (generatedIdeal r))) where t : outsideR ∼ 0R t with biggerPrincipal {outsideR} biggerContainsOutside ... | mult , pr = transitive (symmetric pr) (transitive (*WellDefined bg=0 reflexive) (transitive *Commutative timesZero)) v : (r ∣ biggerGen) → False v r|bg with mutualDivisionImpliesAssociate r|bg u (Irreducible.nonzero irred) v r|bg | assoc = notInR (associateImpliesGeneratedIdealsEqual' assoc (PrincipalIdeal.genGenerates (pid bigger) biggerContainsOutside)) w : Unit biggerGen w = dividesIrreducibleImpliesUnit irred u v primeIdealIsMaximal : {c : _} {pred : A → Set c} → {i : Ideal pred} → (nonzero : Sg A (λ a → ((a ∼ 0R) → False) && pred a)) → PrimeIdeal i → {d : _} → MaximalIdeal i {d} primeIdealIsMaximal {pred = pred} {i} (m , (m!=0 ,, predM)) prime {d = d} = maximalIdealWellDefined (generatedIdeal (PrincipalIdeal.generator princ)) i (memberDividesImpliesMember i (PrincipalIdeal.genIsInIdeal princ)) (PrincipalIdeal.genGenerates princ) isMaximal where princ : PrincipalIdeal i princ = pid i isPrime : Prime (PrincipalIdeal.generator princ) isPrime = primeIdealImpliesPrime (λ gen=0 → PrimeIdeal.notContainedIsNotContained prime (exFalso (m!=0 (generatorZeroImpliesAllZero princ gen=0 predM)))) (primeIdealWellDefined i (generatedIdeal (PrincipalIdeal.generator princ)) (PrincipalIdeal.genGenerates princ) (memberDividesImpliesMember i (PrincipalIdeal.genIsInIdeal princ)) prime) isIrreducible : Irreducible (PrincipalIdeal.generator princ) isIrreducible = primeIsIrreducible isPrime isMaximal : MaximalIdeal (generatedIdeal (PrincipalIdeal.generator princ)) {d} isMaximal = irreducibleImpliesMaximalIdeal isIrreducible {d} irreducibleImpliesPrime : {x : A} → Irreducible x → Prime x irreducibleImpliesPrime {x} irred = primeIdealImpliesPrime (Irreducible.nonzero irred) (idealMaximalImpliesIdealPrime (generatedIdeal x) (irreducibleImpliesMaximalIdeal irred))
59.162162
342
0.76085
50049579f770565137f99497137bb58cb0adf8f2
1,028
agda
Agda
test/Fail/Issue1023-MaskNonData.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Fail/Issue1023-MaskNonData.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Fail/Issue1023-MaskNonData.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
-- Andreas, 2014-01-10 -- Code by Jesper Cockx and Conor McBride and folks from the Coq-club {-# OPTIONS --cubical-compatible #-} -- An empty type. data Zero : Set where -- A unit type as W-type. mutual data WOne : Set where wrap : FOne -> WOne FOne = Zero -> WOne -- Type equality. data _<->_ (X : Set) : Set -> Set₁ where Refl : X <-> X -- This postulate is compatible with univalence: postulate iso : WOne <-> FOne -- But accepting that is incompatible with univalence: auoo : WOne -> Zero auoo (wrap f) = noo FOne iso f where noo : (X : Set) -> (WOne <-> X) -> X -> Zero noo .WOne Refl w = auoo w -- Matching against Refl silently applies the conversion -- FOne -> WOne to f. But this conversion corresponds -- to an application of wrap. Thus, f, which is really -- (wrap f), should not be considered a subterm of (wrap f) -- by the termination checker. -- At least, if we want to be compatible with univalence. absurd : Zero absurd = auoo (wrap \ ()) -- noo should fail termination check.
22.844444
69
0.662451
18aadfabab6ac4672952334661c3a2b4b9d9b043
6,648
agda
Agda
test/succeed/PatternSynonyms.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/succeed/PatternSynonyms.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/PatternSynonyms.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- {-# OPTIONS -v scope.pat:10 #-} -- {-# OPTIONS -v tc.lhs:10 #-} module PatternSynonyms where data ℕ : Set where zero : ℕ suc : (n : ℕ) → ℕ {-# BUILTIN NATURAL ℕ #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC suc #-} pattern z = zero pattern sz = suc z pattern ss x = suc (suc x) data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x test : z ≡ zero test = refl test′ : sz ≡ suc zero test′ = refl test″ : ss z ≡ suc (suc zero) test″ = refl test‴ : ss ≡ λ x → suc (suc x) test‴ = refl f : ℕ → ℕ f z = zero f sz = suc z f (ss 0) = 2 f (ss (suc n)) = n test-f : f zero ≡ zero test-f = refl test-f′ : f (suc zero) ≡ suc zero test-f′ = refl test-f″ : f (suc (suc 0)) ≡ 2 test-f″ = refl test-f‴ : ∀ {n} → f (suc (suc (suc n))) ≡ n test-f‴ = refl ------------------------------------------------------------------------ data L (A : Set) : Set where nil : L A cons : A → L A → L A pattern cc x y xs = cons x (cons y xs) test-cc : ∀ {A} → cc ≡ λ (x : A) y xs → cons x (cons y xs) test-cc = refl crazyLength : ∀ {A} → L A → ℕ crazyLength nil = 0 crazyLength (cons x nil) = 1 crazyLength (cc x y xs) = 9000 swap : ∀ {A} → L A → L A swap nil = nil swap (cons x nil) = cons x nil swap (cc x y xs) = cc y x xs test-swap : ∀ {xs} → swap (cons 1 (cons 2 xs)) ≡ cons 2 (cons 1 xs) test-swap = refl ------------------------------------------------------------------------ -- refl and _ record ⊤ : Set where constructor tt data _⊎_ (A B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B infixr 4 _,_ record Σ (A : Set)(B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ _×_ : (A B : Set) → Set A × B = Σ A λ _ → B infixr 5 _+_ infixr 6 _*_ data Sig (O : Set) : Set₁ where ε ψ : Sig O ρ : (o : O) → Sig O ι : (o : O) → Sig O _+_ _*_ : (Σ Σ′ : Sig O) → Sig O σ π : (A : Set)(φ : A → Sig O) → Sig O ⟦_⟧ : ∀ {O} → Sig O → (Set → (O → Set) → (O → Set)) ⟦ ε ⟧ P R o = ⊤ ⟦ ψ ⟧ P R o = P ⟦ ρ o′ ⟧ P R o = R o′ ⟦ ι o′ ⟧ P R o = o ≡ o′ ⟦ Σ + Σ′ ⟧ P R o = ⟦ Σ ⟧ P R o ⊎ ⟦ Σ′ ⟧ P R o ⟦ Σ * Σ′ ⟧ P R o = ⟦ Σ ⟧ P R o × ⟦ Σ′ ⟧ P R o ⟦ σ A φ ⟧ P R o = Σ A λ x → ⟦ φ x ⟧ P R o ⟦ π A φ ⟧ P R o = (x : A) → ⟦ φ x ⟧ P R o ′List : Sig ⊤ ′List = ε + ψ * ρ _ data μ {O}(Σ : Sig O)(P : Set)(o : O) : Set where ⟨_⟩ : ⟦ Σ ⟧ P (μ Σ P) o → μ Σ P o List : Set → Set List A = μ ′List A _ infixr 5 _∷_ pattern [] = ⟨ inj₁ _ ⟩ pattern _∷_ x xs = ⟨ inj₂ (x , xs) ⟩ length : ∀ {A} → List A → ℕ length [] = zero length (x ∷ xs) = suc (length xs) test-list : List ℕ test-list = 1 ∷ 2 ∷ [] test-length : length test-list ≡ 2 test-length = refl ′Vec : Sig ℕ ′Vec = ι 0 + σ ℕ λ m → ψ * ρ m * ι (suc m) Vec : Set → ℕ → Set Vec A n = μ ′Vec A n pattern []V = ⟨ inj₁ refl ⟩ pattern _∷V_ x xs = ⟨ inj₂ (_ , x , xs , refl) ⟩ nilV : ∀ {A} → Vec A zero nilV = []V consV : ∀ {A n} → A → Vec A n → Vec A (suc n) consV x xs = x ∷V xs lengthV : ∀ {A n} → Vec A n → ℕ lengthV []V = 0 lengthV (x ∷V xs) = suc (lengthV xs) test-lengthV : lengthV (consV 1 (consV 2 (consV 3 nilV))) ≡ 3 test-lengthV = refl ------------------------------------------------------------------------ -- .-patterns pattern zr = (.zero , refl) pattern underscore² = _ , _ dot : (p : Σ ℕ λ n → n ≡ zero) → ⊤ × ⊤ dot zr = underscore² ------------------------------------------------------------------------ -- Implicit arguments {- pattern hiddenUnit = {_} -- XXX: We get lhs error msgs, can we refine -- that? imp : {p : ⊤} → ⊤ imp hiddenUnit = _ -} data Box (A : Set) : Set where box : {x : A} → Box A pattern [_] y = box {x = y} b : Box ℕ b = [ 1 ] test-box : b ≡ box {x = 1} test-box = refl ------------------------------------------------------------------------ -- Anonymous λs g : ℕ → ℕ g = λ { z → z ; sz → sz ; (ss n) → n } test-g : g zero ≡ zero test-g = refl test-g′ : g sz ≡ suc zero test-g′ = refl test-g″ : ∀ {n} → g (suc (suc n)) ≡ n test-g″ = refl ------------------------------------------------------------------------ -- λs postulate X Y : Set h : X → Y p : (x : X)(y : Y) → h x ≡ y → ⊤ p x .((λ x → x) (h x)) refl = _ pattern app x = x , .((λ x → x) (h x)) p′ : (p : X × Y) → h (proj₁ p) ≡ proj₂ p → ⊤ p′ (app x) refl = _ ------------------------------------------------------------------------ -- records record Rec : Set where constructor rr field r : ℕ rrr : (x : Rec) → x ≡ record { r = 0 } → ⊤ rrr .(record { r = 0}) refl = _ rrr′ : (x : Rec) → x ≡ record { r = 0 } → ⊤ rrr′ .(rr 0) refl = _ rrrr : (a : Rec × ℕ) → proj₁ a ≡ record { r = proj₂ a } → ⊤ rrrr (.(rr 0) , 0) refl = _ rrrr (.(rr (suc n)) , suc n) refl = _ pattern pair x = (.(record { r = x }) , x) rrrr′ : (a : Rec × ℕ) → proj₁ a ≡ record { r = proj₂ a } → ⊤ rrrr′ (pair 0) refl = _ rrrr′ (pair (suc n)) refl = _ ------------------------------------------------------------------------ -- lets pp : (x : X)(y : Y) → h x ≡ y → ⊤ pp x .(let i = (λ x → x) in i (h x)) refl = _ pattern llet x = x , .(let i = (λ x → x) in i (h x)) pp′ : (p : X × Y) → h (proj₁ p) ≡ proj₂ p → ⊤ pp′ (llet x) refl = _ ------------------------------------------------------------------------ -- absurd patterns pattern absurd = () data ⊥ : Set where ⊥-elim : ∀ {A : Set} → ⊥ → A ⊥-elim absurd ------------------------------------------------------------------------ -- ambiguous constructors data ℕ2 : Set where zero : ℕ2 suc : ℕ2 -> ℕ2 -- This needs a type signature, because it is ambiguous: amb : ℕ2 amb = suc (suc zero) -- This isn't ambiguous, because the overloading is resolved when the -- pattern synonym is scope-checked: unamb = ss z ------------------------------------------------------------------------ -- underscore pattern trivial = ._ trivf : (a : ⊤) -> a ≡ tt -> ⊤ trivf trivial refl = trivial ------------------------------------------------------------------------ -- let open pattern nuts = .(let open Σ in z) foo : (n : ℕ) -> n ≡ z -> ℕ foo nuts refl = nuts ------------------------------------------------------------------------ -- pattern synonym inside unparamterised module module M where pattern sss x = suc (suc (suc x)) a : ℕ a = sss 2 mb : ℕ mb = M.sss 0 mf : ℕ -> ℕ -> ℕ mf (M.sss _) = M.sss mf _ = \ _ -> 0 {- module M (A : Set)(a : A) where pattern peep x = x , .a pop : (z : A × A) -> proj₂ z ≡ a -> ⊤ pop (peep x) refl = _ peep' = peep pop' : (z : ⊤ × ⊤) -> proj₂ z ≡ tt -> ⊤ pop' (M.peep tt) refl = _ peep' = M.peep -}
19.213873
72
0.422232
d03594b963e8cbc6124c80d32fe51e13c9f105a5
2,752
agda
Agda
Cubical/Functions/Surjection.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
null
null
null
Cubical/Functions/Surjection.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
null
null
null
Cubical/Functions/Surjection.agda
LuuBluum/cubical
ce8fe04f9c5d2c9faf8690885c1b702434626621
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
{-# OPTIONS --safe #-} module Cubical.Functions.Surjection where open import Cubical.Core.Everything open import Cubical.Data.Sigma open import Cubical.Data.Unit open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Functions.Embedding open import Cubical.HITs.PropositionalTruncation as PropTrunc private variable ℓ ℓ' : Level A : Type ℓ B : Type ℓ' f : A → B isSurjection : (A → B) → Type _ isSurjection f = ∀ b → ∥ fiber f b ∥ _↠_ : Type ℓ → Type ℓ' → Type (ℓ-max ℓ ℓ') A ↠ B = Σ[ f ∈ (A → B) ] isSurjection f section→isSurjection : {g : B → A} → section f g → isSurjection f section→isSurjection {g = g} s b = ∣ g b , s b ∣ isPropIsSurjection : isProp (isSurjection f) isPropIsSurjection = isPropΠ λ _ → squash isEquiv→isSurjection : isEquiv f → isSurjection f isEquiv→isSurjection e b = ∣ fst (equiv-proof e b) ∣ isEquiv→isEmbedding×isSurjection : isEquiv f → isEmbedding f × isSurjection f isEquiv→isEmbedding×isSurjection e = isEquiv→isEmbedding e , isEquiv→isSurjection e isEmbedding×isSurjection→isEquiv : isEmbedding f × isSurjection f → isEquiv f equiv-proof (isEmbedding×isSurjection→isEquiv {f = f} (emb , sur)) b = inhProp→isContr (PropTrunc.rec fib' (λ x → x) fib) fib' where hpf : hasPropFibers f hpf = isEmbedding→hasPropFibers emb fib : ∥ fiber f b ∥ fib = sur b fib' : isProp (fiber f b) fib' = hpf b isEquiv≃isEmbedding×isSurjection : isEquiv f ≃ isEmbedding f × isSurjection f isEquiv≃isEmbedding×isSurjection = isoToEquiv (iso isEquiv→isEmbedding×isSurjection isEmbedding×isSurjection→isEquiv (λ _ → isOfHLevelΣ 1 isPropIsEmbedding (\ _ → isPropIsSurjection) _ _) (λ _ → isPropIsEquiv _ _ _)) -- obs: for epi⇒surjective to go through we require a stronger -- hypothesis that one would expect: -- f must cancel functions from a higher universe. rightCancellable : (f : A → B) → Type _ rightCancellable {ℓ} {A} {ℓ'} {B} f = ∀ {C : Type (ℓ-suc (ℓ-max ℓ ℓ'))} → ∀ (g g' : B → C) → (∀ x → g (f x) ≡ g' (f x)) → ∀ y → g y ≡ g' y -- This statement is in Mac Lane & Moerdijk (page 143, corollary 5). epi⇒surjective : (f : A → B) → rightCancellable f → isSurjection f epi⇒surjective f rc y = transport (fact₂ y) tt* where hasPreimage : (A → B) → B → _ hasPreimage f y = ∥ fiber f y ∥ fact₁ : ∀ x → Unit* ≡ hasPreimage f (f x) fact₁ x = hPropExt isPropUnit* propTruncIsProp (λ _ → ∣ (x , refl) ∣) (λ _ → tt*) fact₂ : ∀ y → Unit* ≡ hasPreimage f y fact₂ = rc _ _ fact₁
33.975309
83
0.660247
4d60a5b5789108b822ca5566e0982c9ae49e5ed4
23,563
agda
Agda
src/Types/IND.agda
peterthiemann/dual-session
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
[ "BSD-2-Clause" ]
1
2022-02-13T05:43:25.000Z
2022-02-13T05:43:25.000Z
src/Types/IND.agda
peterthiemann/dual-session
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
[ "BSD-2-Clause" ]
null
null
null
src/Types/IND.agda
peterthiemann/dual-session
7a8bc1f6b2f808bd2a22c592bd482dbcc271979c
[ "BSD-2-Clause" ]
1
2019-12-07T16:12:50.000Z
2019-12-07T16:12:50.000Z
module Types.IND where open import Data.Nat open import Data.Fin hiding (_+_) open import Data.Product open import Function open import Relation.Binary.PropositionalEquality hiding (Extensionality) open import Types.Direction open import Auxiliary.Extensionality open import Auxiliary.RewriteLemmas private variable m n : ℕ ---------------------------------------------------------------------- -- session type inductively with explicit rec data Polarity : Set where POS NEG : Polarity mutual data Type n : Set where TUnit TInt : Type n TPair : (T₁ : Type n) (T₂ : Type n) → Type n TChan : (S : SType n) → Type n data SType n : Set where gdd : (G : GType n) → SType n rec : (G : GType (suc n) ) → SType n var : (p : Polarity) → (x : Fin n) → SType n data GType n : Set where transmit : (d : Dir) (T : Type n) (S : SType n) → GType n choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n end : GType n TType = Type -- weakening weakenS : (n : ℕ) → SType m → SType (m + n) weakenG : (n : ℕ) → GType m → GType (m + n) weakenT : (n : ℕ) → TType m → TType (m + n) weakenS n (gdd gst) = gdd (weakenG n gst) weakenS n (rec gst) = rec (weakenG n gst) weakenS n (var p x) = var p (inject+ n x) weakenG n (transmit d t s) = transmit d (weakenT n t) (weakenS n s) weakenG n (choice d m alt) = choice d m (weakenS n ∘ alt) weakenG n end = end weakenT n TUnit = TUnit weakenT n TInt = TInt weakenT n (TPair ty ty₁) = TPair (weakenT n ty) (weakenT n ty₁) weakenT n (TChan x) = TChan (weakenS n x) weaken1 : SType m → SType (suc m) weaken1{m} stm with weakenS 1 stm ... | r rewrite n+1=suc-n {m} = r module CheckWeaken where s0 : SType 0 s0 = rec (transmit SND TUnit (var POS zero)) s1 : SType 1 s1 = rec (transmit SND TUnit (var POS zero)) s2 : SType 2 s2 = rec (transmit SND TUnit (var POS zero)) check-weakenS1 : weakenS 1 s0 ≡ s1 check-weakenS1 = cong rec (cong (transmit SND TUnit) refl) check-weakenS2 : weakenS 2 s0 ≡ s2 check-weakenS2 = cong rec (cong (transmit SND TUnit) refl) weaken1'N : Fin (suc n) → Fin n → Fin (suc n) weaken1'N zero x = suc x weaken1'N (suc i) zero = zero weaken1'N (suc i) (suc x) = suc (weaken1'N i x) weaken1'S : Fin (suc n) → SType n → SType (suc n) weaken1'G : Fin (suc n) → GType n → GType (suc n) weaken1'T : Fin (suc n) → TType n → TType (suc n) weaken1'S i (gdd gst) = gdd (weaken1'G i gst) weaken1'S i (rec gst) = rec (weaken1'G (suc i) gst) weaken1'S i (var p x) = var p (weaken1'N i x) weaken1'G i (transmit d t s) = transmit d (weaken1'T i t) (weaken1'S i s) weaken1'G i (choice d m alt) = choice d m (weaken1'S i ∘ alt) weaken1'G i end = end weaken1'T i TUnit = TUnit weaken1'T i TInt = TInt weaken1'T i (TPair t₁ t₂) = TPair (weaken1'T i t₁) (weaken1'T i t₂) weaken1'T i (TChan x) = TChan (weaken1'S i x) weaken1S : SType n → SType (suc n) weaken1G : GType n → GType (suc n) weaken1T : Type n → Type (suc n) weaken1S = weaken1'S zero weaken1G = weaken1'G zero weaken1T = weaken1'T zero module CheckWeaken1' where sxy : ∀ n → Fin (suc n) → SType n sxy n x = rec (transmit SND TUnit (var POS x)) s00 : SType 0 s00 = sxy 0 zero s10 : SType 1 s10 = sxy 1 zero s11 : SType 1 s11 = sxy 1 (suc zero) s22 : SType 2 s22 = sxy 2 (suc (suc zero)) check-weaken-s01 : weaken1'S zero s00 ≡ s10 check-weaken-s01 = refl check-weaken-s1-s2 : weaken1'S zero s11 ≡ s22 check-weaken-s1-s2 = refl check-weaken-s21 : weaken1'S (suc zero) (sxy 2 (suc zero)) ≡ sxy 3 (suc zero) check-weaken-s21 = refl -------------------------------------------------------------------- dual-pol : Polarity → Polarity dual-pol POS = NEG dual-pol NEG = POS dual-pol-inv : ∀ p → dual-pol (dual-pol p) ≡ p dual-pol-inv POS = refl dual-pol-inv NEG = refl swap-polS : (i : Fin (suc n)) → SType (suc n) → SType (suc n) swap-polG : (i : Fin (suc n)) → GType (suc n) → GType (suc n) swap-polT : (i : Fin (suc n)) → Type (suc n) → Type (suc n) swap-polG i (transmit d t st) = transmit d (swap-polT i t) (swap-polS i st) swap-polG i (choice d m alt) = choice d m (swap-polS i ∘ alt) swap-polG i end = end swap-polS i (gdd gst) = gdd (swap-polG i gst) swap-polS i (rec st) = rec (swap-polG (suc i) st) swap-polS zero (var p zero) = var (dual-pol p) zero swap-polS (suc i) (var p zero) = var p zero swap-polS zero (var p (suc x)) = var p (suc x) swap-polS {suc n} (suc i) (var p (suc x)) = weaken1S (swap-polS i (var p x)) swap-polT i TUnit = TUnit swap-polT i TInt = TInt swap-polT i (TPair t₁ t₂) = TPair (swap-polT i t₁) (swap-polT i t₂) swap-polT i (TChan x) = TChan (swap-polS i x) -------------------------------------------------------------------- weak-weakN : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (x : Fin n) → weaken1'N (suc i) (weaken1'N j x) ≡ weaken1'N (inject₁ j) (weaken1'N i x) weak-weakG : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (g : GType n) → weaken1'G (suc i) (weaken1'G j g) ≡ weaken1'G (inject₁ j) (weaken1'G i g) weak-weakS : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s : SType n) → weaken1'S (suc i) (weaken1'S j s) ≡ weaken1'S (inject₁ j) (weaken1'S i s) weak-weakT : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (t : Type n) → weaken1'T (suc i) (weaken1'T j t) ≡ weaken1'T (inject₁ j) (weaken1'T i t) weak-weakN zero zero le x = refl weak-weakN (suc i) zero le x = refl weak-weakN (suc i) (suc j) (s≤s le) zero = refl weak-weakN{suc n} (suc i) (suc j) (s≤s le) (suc x) = cong suc (weak-weakN i j le x) weak-weakG i j le (transmit d t s) = cong₂ (transmit d) (weak-weakT i j le t) (weak-weakS i j le s) weak-weakG i j le (choice d m alt) = cong (choice d m) (ext (weak-weakS i j le ∘ alt)) weak-weakG i j le end = refl weak-weakS i j le (gdd gst) = cong gdd (weak-weakG i j le gst) weak-weakS i j le (rec gst) = cong rec (weak-weakG (suc i) (suc j) (s≤s le) gst) weak-weakS i j le (var p x) = cong (var p) (weak-weakN i j le x) weak-weakT i j le TUnit = refl weak-weakT i j le TInt = refl weak-weakT i j le (TPair t t₁) = cong₂ TPair (weak-weakT i j le t) (weak-weakT i j le t₁) weak-weakT i j le (TChan s) = cong TChan (weak-weakS i j le s) weaken1-weakenN : (m : ℕ) (j : Fin (suc n)) (x : Fin n) → inject+ m (weaken1'N j x) ≡ weaken1'N (inject+ m j) (inject+ m x) weaken1-weakenN m zero zero = refl weaken1-weakenN m zero (suc x) = refl weaken1-weakenN m (suc j) zero = refl weaken1-weakenN m (suc j) (suc x) = cong suc (weaken1-weakenN m j x) weaken1-weakenS : (m : ℕ) (j : Fin (suc n)) (s : SType n) → weakenS m (weaken1'S j s) ≡ weaken1'S (inject+ m j) (weakenS m s) weaken1-weakenG : (m : ℕ) (j : Fin (suc n)) (g : GType n) → weakenG m (weaken1'G j g) ≡ weaken1'G (inject+ m j) (weakenG m g) weaken1-weakenT : (m : ℕ) (j : Fin (suc n)) (t : Type n) → weakenT m (weaken1'T j t) ≡ weaken1'T (inject+ m j) (weakenT m t) weaken1-weakenS m j (gdd gst) = cong gdd (weaken1-weakenG m j gst) weaken1-weakenS m j (rec gst) = cong rec (weaken1-weakenG m (suc j) gst) weaken1-weakenS m zero (var p zero) = refl weaken1-weakenS m zero (var p (suc x)) = refl weaken1-weakenS {suc n} m (suc j) (var p zero) = refl weaken1-weakenS {suc n} m (suc j) (var p (suc x)) = cong (var p) (cong suc (weaken1-weakenN m j x)) weaken1-weakenG m j (transmit d t s) = cong₂ (transmit d) (weaken1-weakenT m j t) (weaken1-weakenS m j s) weaken1-weakenG m j (choice d m₁ alt) = cong (choice d m₁) (ext (weaken1-weakenS m j ∘ alt)) weaken1-weakenG m j end = refl weaken1-weakenT m j TUnit = refl weaken1-weakenT m j TInt = refl weaken1-weakenT m j (TPair t t₁) = cong₂ TPair (weaken1-weakenT m j t) (weaken1-weakenT m j t₁) weaken1-weakenT m j (TChan x) = cong TChan (weaken1-weakenS m j x) -------------------------------------------------------------------- -- weakening of later index {-# TERMINATING #-} swap-weaken1'G : (i : Fin (suc (suc n))) (j : Fin′ i) (gst : GType (suc n)) → swap-polG (inject j) (weaken1'G i gst) ≡ weaken1'G i (swap-polG (inject! j) gst) swap-weaken1'S : (i : Fin (suc (suc n))) (j : Fin′ i) (sst : SType (suc n)) → swap-polS (inject j) (weaken1'S i sst) ≡ weaken1'S i (swap-polS (inject! j) sst) swap-weaken1'T : (i : Fin (suc (suc n))) (j : Fin′ i) (t : Type (suc n)) → swap-polT (inject j) (weaken1'T i t) ≡ weaken1'T i (swap-polT (inject! j) t) swap-weaken1'G i j (transmit d t s) = cong₂ (transmit d) (swap-weaken1'T i j t) (swap-weaken1'S i j s) swap-weaken1'G i j (choice d m alt) = cong (choice d m) (ext (swap-weaken1'S i j ∘ alt)) swap-weaken1'G i j end = refl swap-weaken1'S i j (gdd gst) = cong gdd (swap-weaken1'G i j gst) swap-weaken1'S i j (rec gst) = cong rec (swap-weaken1'G (suc i) (suc j) gst) swap-weaken1'S zero () (var p x) swap-weaken1'S (suc i) zero (var p zero) = refl swap-weaken1'S (suc i) zero (var p (suc x)) = refl swap-weaken1'S (suc i) (suc j) (var p zero) = refl swap-weaken1'S{suc n} (suc i) (suc j) (var p (suc x)) rewrite (weak-weakS i zero z≤n (swap-polS (inject! j) (var p x))) = let sws = swap-weaken1'S{n} i j (var p x) in cong (weaken1'S zero) sws swap-weaken1'T i j TUnit = refl swap-weaken1'T i j TInt = refl swap-weaken1'T i j (TPair t₁ t₂) = cong₂ TPair (swap-weaken1'T i j t₁) (swap-weaken1'T i j t₂) swap-weaken1'T i j (TChan s) = cong TChan (swap-weaken1'S i j s) -------------------------------------------------------------------- -- weakening of earlier index {-# TERMINATING #-} swap-weaken1'S< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (s : SType (suc n)) → swap-polS (suc i) (weaken1'S (inject₁ j) s) ≡ weaken1'S (inject₁ j) (swap-polS i s) swap-weaken1'G< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (g : GType (suc n)) → swap-polG (suc i) (weaken1'G (inject₁ j) g) ≡ weaken1'G (inject₁ j) (swap-polG i g) swap-weaken1'T< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (t : Type (suc n)) → swap-polT (suc i) (weaken1'T (inject₁ j) t) ≡ weaken1'T (inject₁ j) (swap-polT i t) swap-weaken1'S< i j le (gdd gst) = cong gdd (swap-weaken1'G< i j le gst) swap-weaken1'S< i j le (rec gst) = cong rec (swap-weaken1'G< (suc i) (suc j) (s≤s le) gst) swap-weaken1'S< zero zero le (var p x) = refl swap-weaken1'S< (suc i) zero le (var p x) = refl swap-weaken1'S<{suc n} (suc i) (suc j) le (var p zero) = refl swap-weaken1'S<{suc n} (suc i) (suc j) (s≤s le) (var p (suc x)) rewrite (weak-weakS (inject₁ j) zero z≤n (swap-polS i (var p x))) = let sws = swap-weaken1'S<{n} i j le (var p x) in cong (weaken1'S zero) sws swap-weaken1'G< i j le (transmit d t s) = cong₂ (transmit d) (swap-weaken1'T< i j le t) (swap-weaken1'S< i j le s) swap-weaken1'G< i j le (choice d m alt) = cong (choice d m) (ext ((swap-weaken1'S< i j le) ∘ alt)) swap-weaken1'G< i j le end = refl swap-weaken1'T< i j le TUnit = refl swap-weaken1'T< i j le TInt = refl swap-weaken1'T< i j le (TPair t t₁) = cong₂ (TPair) (swap-weaken1'T< i j le t) (swap-weaken1'T< i j le t₁) swap-weaken1'T< i j le (TChan s) = cong (TChan) (swap-weaken1'S< i j le s) swap-weakenS : (i : Fin (suc n)) → (s : SType (suc n)) → swap-polS (suc i) (weaken1S s) ≡ weaken1S (swap-polS i s) swap-weakenG : (i : Fin (suc n)) → (g : GType (suc n)) → swap-polG (suc i) (weaken1G g) ≡ weaken1G (swap-polG i g) swap-weakenT : (i : Fin (suc n)) → (t : Type (suc n)) → swap-polT (suc i) (weaken1T t) ≡ weaken1T (swap-polT i t) swap-weakenS i s = swap-weaken1'S< i zero z≤n s swap-weakenG i g = swap-weaken1'G< i zero z≤n g swap-weakenT i t = swap-weaken1'T< i zero z≤n t -------------------------------------------------------------------- -- swapping of general weakening {-# TERMINATING #-} swap-weakenG' : (m : ℕ) (j : Fin (suc n)) (gst : GType (suc n)) → swap-polG (inject+ m j) (weakenG m gst) ≡ weakenG m (swap-polG j gst) swap-weakenS' : (m : ℕ) (j : Fin (suc n)) (s : SType (suc n)) → swap-polS (inject+ m j) (weakenS m s) ≡ weakenS m (swap-polS j s) swap-weakenT' : (m : ℕ) (j : Fin (suc n)) (t : Type (suc n)) → swap-polT (inject+ m j) (weakenT m t) ≡ weakenT m (swap-polT j t) swap-weakenG' m j (transmit d t s) = cong₂ (transmit d) (swap-weakenT' m j t) (swap-weakenS' m j s) swap-weakenG' m j (choice d m₁ alt) = cong (choice d m₁) (ext (swap-weakenS' m j ∘ alt)) swap-weakenG' m j end = refl swap-weakenS' m j (gdd gst) = cong gdd (swap-weakenG' m j gst) swap-weakenS' m j (rec gst) = cong rec (swap-weakenG' m (suc j) gst) swap-weakenS' m zero (var p zero) = refl swap-weakenS' m (suc j) (var p zero) = refl swap-weakenS' m zero (var p (suc zero)) = refl swap-weakenS' m zero (var p (suc (suc x))) = refl swap-weakenS' {suc n} m (suc j) (var p (suc x)) rewrite (weaken1-weakenS m zero (swap-polS j (var p x))) = let rst = swap-weakenS'{n} m j (var p x) in cong weaken1S rst swap-weakenT' m j TUnit = refl swap-weakenT' m j TInt = refl swap-weakenT' m j (TPair t t₁) = cong₂ TPair (swap-weakenT' m j t) (swap-weakenT' m j t₁) swap-weakenT' m j (TChan x) = cong TChan (swap-weakenS' m j x) -------------------------------------------------------------------- {-# TERMINATING #-} swap-pol-invS : (i : Fin (suc n)) → (st : SType (suc n)) → swap-polS i (swap-polS i st) ≡ st swap-pol-invG : (i : Fin (suc n)) → (st : GType (suc n)) → swap-polG i (swap-polG i st) ≡ st swap-pol-invT : (i : Fin (suc n)) → (ty : Type (suc n)) → swap-polT i (swap-polT i ty) ≡ ty swap-pol-invS i (gdd gst) = cong gdd (swap-pol-invG i gst) swap-pol-invS i (rec gst) = cong rec (swap-pol-invG (suc i) gst) swap-pol-invS zero (var p zero) rewrite dual-pol-inv p = refl swap-pol-invS (suc i) (var p zero) = refl swap-pol-invS zero (var p (suc x)) rewrite dual-pol-inv p = refl swap-pol-invS {suc n} (suc i) (var p (suc x)) rewrite swap-weakenS i (swap-polS i (var p x)) | swap-pol-invS i (var p x) = refl -- extensionality needed swap-pol-invG i (transmit d t s) = cong₂ (transmit d) (swap-pol-invT i t) (swap-pol-invS i s) swap-pol-invG i (choice d m alt) = cong (choice d m) (ext R) where R : ∀ x → swap-polS i (swap-polS i (alt x)) ≡ alt x R x rewrite swap-pol-invS i (alt x) = refl swap-pol-invG i end = refl swap-pol-invT i TUnit = refl swap-pol-invT i TInt = refl swap-pol-invT i (TPair ty ty₁) = cong₂ TPair (swap-pol-invT i ty) (swap-pol-invT i ty₁) swap-pol-invT i (TChan x) = cong TChan (swap-pol-invS i x) -------------------------------------------------------------------- -- LM duality dualS : SType n → SType n dualG : GType n → GType n dualG (transmit d t st) = transmit (dual-dir d) t (dualS st) dualG (choice d m alt) = choice (dual-dir d) m (dualS ∘ alt) dualG end = end dualS (gdd gst) = gdd (dualG gst) dualS (rec gst) = rec (swap-polG zero (dualG gst)) dualS (var p x) = var (dual-pol p) x -------------------------------------------------------------------- dual-weakenS : (i : Fin (suc n)) (s : SType n) → dualS (weaken1'S i s) ≡ weaken1'S i (dualS s) dual-weakenG : (i : Fin (suc n)) (g : GType n) → dualG (weaken1'G i g) ≡ weaken1'G i (dualG g) dual-weakenS i (gdd gst) = cong gdd (dual-weakenG i gst) dual-weakenS i (rec gst) rewrite (sym (swap-weaken1'G (suc i) zero (dualG gst))) = cong rec (cong (swap-polG zero) (dual-weakenG (suc i) gst)) dual-weakenS i (var p x) = refl dual-weakenG i (transmit d t s) = cong₂ (transmit (dual-dir d)) refl (dual-weakenS i s) dual-weakenG i (choice d m alt) = cong (choice (dual-dir d) m) (ext (dual-weakenS i ∘ alt)) dual-weakenG i end = refl dual-weakenS' : (m : ℕ) (s : SType n) → dualS (weakenS m s) ≡ weakenS m (dualS s) dual-weakenG' : (m : ℕ) (g : GType n) → dualG (weakenG m g) ≡ weakenG m (dualG g) dual-weakenS' n (gdd gst) = cong gdd (dual-weakenG' n gst) dual-weakenS' n (rec gst) rewrite (sym (swap-weakenG' n zero (dualG gst))) = cong rec (cong (swap-polG zero) (dual-weakenG' n gst)) dual-weakenS' n (var p x) = refl dual-weakenG' n (transmit d t s) = cong₂ (transmit (dual-dir d)) refl (dual-weakenS' n s) dual-weakenG' n (choice d m alt) = cong (choice (dual-dir d) m) (ext (dual-weakenS' n ∘ alt)) dual-weakenG' n end = refl -------------------------------------------------------------------- aux : (i : Fin n) (x : Fin n) (p' : Polarity) → var p' (suc (suc x)) ≡ weaken1S (var p' (suc x)) aux i x p = refl var-suc : (i : Fin n) (x : Fin n) (p : Polarity) → ∃ λ p' → swap-polS (suc i) (var p (suc x)) ≡ var p' (suc x) var-suc zero zero p = dual-pol p , refl var-suc (suc i) zero p = p , refl var-suc zero (suc x) p = p , refl var-suc (suc i) (suc x) p with var-suc i x p ... | p' , snd rewrite sym (aux i x p') = p' , cong weaken1S snd -------------------------------------------------------------------- {-# TERMINATING #-} swap-swapG : (gst : GType (suc n)) → (i : Fin (suc n)) (j : Fin′ i) → swap-polG i (swap-polG (inject j) gst) ≡ swap-polG (inject j) (swap-polG i gst) swap-swapT : (t : Type (suc n)) → (i : Fin (suc n)) (j : Fin′ i) → swap-polT i (swap-polT (inject j) t) ≡ swap-polT (inject j) (swap-polT i t) swap-swapS : (st : SType (suc n)) → (i : Fin (suc n)) (j : Fin′ i) → swap-polS i (swap-polS (inject j) st) ≡ swap-polS (inject j) (swap-polS i st) swap-swapG (transmit d t s) i j = cong₂ (transmit d) (swap-swapT t i j) (swap-swapS s i j) swap-swapG (choice d m alt) i j = cong (choice d m) (ext (λ x → swap-swapS (alt x) i j)) swap-swapG end i j = refl swap-swapT TUnit i j = refl swap-swapT TInt i j = refl swap-swapT (TPair t t₁) i j = cong₂ TPair (swap-swapT t i j) (swap-swapT t₁ i j) swap-swapT (TChan x) i j = cong TChan (swap-swapS x i j) swap-swapS (gdd gst) i j = cong gdd (swap-swapG gst i j) swap-swapS (rec gst) i j = cong rec (swap-swapG gst (suc i) (suc j)) swap-swapS (var p zero) zero () swap-swapS (var p zero) (suc i) zero = refl swap-swapS (var p zero) (suc i) (suc j) = refl swap-swapS (var p (suc x)) zero () swap-swapS (var p (suc x)) (suc i) zero with var-suc i x p ... | p' , snd rewrite snd = refl swap-swapS {suc n} (var p (suc x)) (suc i) (suc j) rewrite swap-weakenS i (swap-polS (inject j) (var p x)) with swap-swapS (var p x) i j ... | pxij rewrite swap-weakenS (inject j) (swap-polS i (var p x)) = cong weaken1S pxij {-# TERMINATING #-} swap-pol-dualG : (i : Fin (suc n)) (gst : GType (suc n)) → swap-polG i (dualG gst) ≡ dualG (swap-polG i gst) swap-pol-dualS : (i : Fin (suc n)) (st : SType (suc n)) → swap-polS i (dualS st) ≡ dualS (swap-polS i st) swap-pol-dualG i (transmit d t s) = cong (transmit _ (swap-polT i t)) (swap-pol-dualS i s) swap-pol-dualG i (choice d m alt) = cong (choice _ _) (ext (swap-pol-dualS i ∘ alt)) swap-pol-dualG i end = refl swap-pol-dualS i (gdd gst) = cong gdd (swap-pol-dualG i gst) swap-pol-dualS i (rec gst) rewrite sym (swap-pol-dualG (suc i) gst) = cong rec (swap-swapG (dualG gst) (suc i) zero) swap-pol-dualS zero (var p zero) = refl swap-pol-dualS (suc i) (var p zero) = refl swap-pol-dualS zero (var p (suc x)) = refl swap-pol-dualS {suc n} (suc i) (var p (suc x)) rewrite (dual-weakenS zero (swap-polS i (var p x))) = cong weaken1S (swap-pol-dualS i (var p x)) -------------------------------------------------------------------- dual-invS : (st : SType n) → st ≡ dualS (dualS st) dual-invG : (gst : GType n) → gst ≡ dualG (dualG gst) dual-invS (gdd gst) = cong gdd (dual-invG gst) dual-invS (rec gst) rewrite sym (swap-pol-dualG zero (dualG gst)) | swap-pol-invG zero (dualG (dualG gst)) = cong rec (dual-invG gst) dual-invS (var p x) rewrite dual-pol-inv p = refl dual-invG (transmit d t s) rewrite dual-dir-inv d = cong₂ (transmit d) refl (dual-invS s) dual-invG (choice d m alt) rewrite dual-dir-inv d = cong (choice d m) (ext R) where R : (x : Fin m) → alt x ≡ dualS (dualS (alt x)) R x rewrite sym (dual-invS (alt x)) = refl dual-invG end = refl dual-if : Polarity → SType n → SType n dual-if POS s = s dual-if NEG s = dualS s dual-if-dual : (p : Polarity) (ist : SType 0) → dual-if p ist ≡ dual-if (dual-pol p) (dualS ist) dual-if-dual POS ist = (dual-invS ist) dual-if-dual NEG ist = refl -------------------------------------------------------------------- -- substitution st-substS : SType (suc n) → Fin (suc n) → SType 0 → SType n st-substG : GType (suc n) → Fin (suc n) → SType 0 → GType n st-substT : Type (suc n) → Fin (suc n) → SType 0 → Type n st-substS (gdd gst) i st0 = gdd (st-substG gst i st0) st-substS (rec gst) i st0 = rec (st-substG gst (suc i) st0) st-substS {n} (var p zero) zero st0 = weakenS n (dual-if p st0) st-substS {suc n} (var p zero) (suc i) st0 = var p zero st-substS {suc n} (var p (suc x)) zero st0 = var p x st-substS {suc n} (var p (suc x)) (suc i) st0 = weaken1S (st-substS (var p x) i st0) st-substG (transmit d t s) i st0 = transmit d (st-substT t i st0) (st-substS s i st0) st-substG (choice d m alt) i st0 = choice d m (λ j → st-substS (alt j) i st0) st-substG end i st0 = end st-substT TUnit i st0 = TUnit st-substT TInt i st0 = TInt st-substT (TPair ty ty₁) i st0 = TPair (st-substT ty i st0) (st-substT ty₁ i st0) st-substT (TChan st) i st0 = TChan (st-substS st i st0) -------------------------------------------------------------------- trivial-subst-var : (p : Polarity) (x : Fin n) (ist₁ ist₂ : SType 0) → st-substS (var p (suc x)) zero ist₁ ≡ st-substS (var p (suc x)) zero ist₂ trivial-subst-var p zero ist1 ist2 = refl trivial-subst-var p (suc x) ist1 ist2 = refl trivial-subst-var' : (p : Polarity) (i : Fin n) (ist₁ ist₂ : SType 0) → st-substS (var p zero) (suc i) ist₁ ≡ st-substS (var p zero) (suc i) ist₂ trivial-subst-var' p zero ist1 ist2 = refl trivial-subst-var' p (suc x) ist1 ist2 = refl -------------------------------------------------------------------- -- equivalence variable t t₁ t₂ t₁' t₂' : Type n s s₁ s₂ : SType n g g₁ g₂ : GType n unfold : SType 0 → GType 0 unfold (gdd gst) = gst unfold (rec gst) = st-substG gst zero (rec gst) -- type equivalence data EquivT (R : SType n → SType n → Set) : Type n → Type n → Set where eq-unit : EquivT R TUnit TUnit eq-int : EquivT R TInt TInt eq-pair : EquivT R t₁ t₁' → EquivT R t₂ t₂' → EquivT R (TPair t₁ t₂) (TPair t₁' t₂') eq-chan : R s₁ s₂ → EquivT R (TChan s₁) (TChan s₂) -- session type equivalence data EquivG (R : SType n → SType n → Set) : GType n → GType n → Set where eq-transmit : (d : Dir) → EquivT R t₁ t₂ → R s₁ s₂ → EquivG R (transmit d t₁ s₁) (transmit d t₂ s₂) eq-choice : ∀ {alt alt'} → (d : Dir) → ((i : Fin m) → R (alt i) (alt' i)) → EquivG R (choice d m alt) (choice d m alt') eq-end : EquivG R end end record Equiv (s₁ s₂ : SType 0) : Set where coinductive field force : EquivG Equiv (unfold s₁) (unfold s₂) open Equiv _≈_ = Equiv _≈'_ = EquivG Equiv _≈ᵗ_ = EquivT Equiv -- reflexive ≈-refl : s ≈ s ≈'-refl : g ≈' g ≈ᵗ-refl : t ≈ᵗ t force (≈-refl {s}) = ≈'-refl ≈'-refl {transmit d t s} = eq-transmit d ≈ᵗ-refl ≈-refl ≈'-refl {choice d m alt} = eq-choice d (λ i → ≈-refl) ≈'-refl {end} = eq-end ≈ᵗ-refl {TUnit} = eq-unit ≈ᵗ-refl {TInt} = eq-int ≈ᵗ-refl {TPair t t₁} = eq-pair ≈ᵗ-refl ≈ᵗ-refl ≈ᵗ-refl {TChan x} = eq-chan ≈-refl -- symmetric ≈-symm : s₁ ≈ s₂ → s₂ ≈ s₁ ≈'-symm : g₁ ≈' g₂ → g₂ ≈' g₁ ≈ᵗ-symm : t₁ ≈ᵗ t₂ → t₂ ≈ᵗ t₁ force (≈-symm s₁≈s₂) = ≈'-symm (force s₁≈s₂) ≈'-symm (eq-transmit d x x₁) = eq-transmit d (≈ᵗ-symm x) (≈-symm x₁) ≈'-symm (eq-choice d x) = eq-choice d (≈-symm ∘ x) ≈'-symm eq-end = eq-end ≈ᵗ-symm eq-unit = eq-unit ≈ᵗ-symm eq-int = eq-int ≈ᵗ-symm (eq-pair t₁≈ᵗt₂ t₁≈ᵗt₃) = eq-pair (≈ᵗ-symm t₁≈ᵗt₂) (≈ᵗ-symm t₁≈ᵗt₃) ≈ᵗ-symm (eq-chan x) = eq-chan (≈-symm x)
40.555938
142
0.595637
0b42cf652e344bc866b1857de6bc49ecc65ae43e
88
agda
Agda
src/L/Base/Sigma.agda
borszag/smallib
83707537b182ba8906228ac0bcb9ccef972eaaa3
[ "BSD-2-Clause" ]
null
null
null
src/L/Base/Sigma.agda
borszag/smallib
83707537b182ba8906228ac0bcb9ccef972eaaa3
[ "BSD-2-Clause" ]
10
2020-10-19T10:13:16.000Z
2020-11-09T16:40:39.000Z
src/L/Base/Sigma.agda
borszag/smallib
83707537b182ba8906228ac0bcb9ccef972eaaa3
[ "BSD-2-Clause" ]
null
null
null
module L.Base.Sigma where -- Reexport definitions open import L.Base.Sigma.Core public
17.6
36
0.795455
39182682fd4568d82f547e82c8fe9100540c21a5
7,734
agda
Agda
examples/outdated-and-incorrect/iird/Proof/Setup.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/iird/Proof/Setup.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/iird/Proof/Setup.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Proof.Setup where import LF import IIRD import IIRDr import DefinitionalEquality import Identity open LF open IIRD open IIRDr open DefinitionalEquality open Identity -- Given a code for a general IIRD we should give a code for a restricted IIRD. ε : {I : Set}{D : I -> Set1} -> OPg I D -> OPr I D ε {I}{D} (ι < j | e >') = \i -> σ (j == i) \p -> ι (subst₁ D p e) ε (σ A γ) = \i -> σ A \a -> ε (γ a) i ε (δ A j γ) = \i -> δ A j \g -> ε (γ g) i G→H : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (a : Gu γ U T) -> Hu (ε γ) U T (Gi γ U T a) G→H (ι < i | e >') U T ★ = < refl | ★ > G→H (σ A γ) U T < a | b > = < a | G→H (γ a) U T b > G→H (δ A i γ) U T < g | b > = < g | G→H (γ (T « i × g »)) U T b > H→G : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I) -> Hu (ε γ) U T i -> Gu γ U T H→G (ι < j | e >') U T i < p | ★ > = ★ H→G (σ A γ) U T i < a | b > = < a | H→G (γ a) U T i b > H→G (δ A j γ) U T i < g | b > = < g | H→G (γ (T « j × g »)) U T i b > -- We can turn an inductive argument of the general IIRD to an inductive -- argument of the restricted version. H→G∘G→H-identity : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (a : Gu γ U T) -> H→G γ U T (Gi γ U T a) (G→H γ U T a) ≡ a H→G∘G→H-identity (ι < i | e >') U T ★ = refl-≡ H→G∘G→H-identity (σ A γ) U T < a | b > = cong-≡ (\z -> < a | z >) (H→G∘G→H-identity (γ a) U T b) H→G∘G→H-identity (δ A i γ) U T < g | b > = cong-≡ (\z -> < g | z >) (H→G∘G→H-identity (γ (T « i × g »)) U T b) {- Gi∘H→G-identity : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(b : Hu (ε γ) U T i) -> Gi γ U T (H→G γ U T i b) == i Gi∘H→G-identity (ι < j | e >') U T i < p | ★ > = p Gi∘H→G-identity (σ A γ) U T i < a | b > = Gi∘H→G-identity (γ a) U T i b Gi∘H→G-identity (δ A j γ) U T i < g | b > = Gi∘H→G-identity (γ (T « j × g »)) U T i b Gt∘H→G-identity : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(b : Hu (ε γ) U T i) -> Gt γ U T (H→G γ U T i b) ≡₁ Ht (ε γ) U T i b Gt∘H→G-identity γ U T i b = ? -- This one ain't true! p ≢ refl : x == y G→H∘H→G-identity : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(b : Hu (ε γ) U T i) -> G→H γ U T (H→G γ U T i b) ≡ b G→H∘H→G-identity (ι < j | e >') U T i < p | ★ > = ? G→H∘H→G-identity (σ A γ) U T i < a | b > = ? G→H∘H→G-identity (δ A j γ) U T i < g | b > = ? -} -- Rather than proving equalities (which doesn't hold anyway) we provide -- substitution rules. G→H∘H→G-subst : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (F : (i : I)(a : Hu (ε γ) U T i) -> Set1) (i : I)(a : Hu (ε γ) U T i) (h : F (Gi γ U T (H→G γ U T i a)) (G→H γ U T (H→G γ U T i a))) -> F i a G→H∘H→G-subst (ι < j | e >') U T F i < p | ★ > h = elim==₁ j (\z q -> F z < q | ★ >) h i p G→H∘H→G-subst (σ A γ) U T F i < a | b > h = G→H∘H→G-subst (γ a) U T (\j c -> F j < a | c >) i b h G→H∘H→G-subst (δ A j γ) U T F i < g | b > h = G→H∘H→G-subst (γ (T « j × g »)) U T (\j c -> F j < g | c >) i b h -- Q. When can we remove a G→H∘H→G-subst ? -- A. When a = G→H γ U T i a' G→H∘H→G-identity : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (F : (i : I)(a : Hu (ε γ) U T i) -> Set1) (a : Gu γ U T) (h : F (Gi γ U T (H→G γ U T (Gi γ U T a) (G→H γ U T a))) (G→H γ U T (H→G γ U T (Gi γ U T a) (G→H γ U T a))) ) -> G→H∘H→G-subst γ U T F (Gi γ U T a) (G→H γ U T a) h ≡₁ h G→H∘H→G-identity (ι < i | e >') U T F ★ h = refl-≡₁ G→H∘H→G-identity (σ A γ) U T F < a | b > h = G→H∘H→G-identity (γ a) U T (\j c -> F j < a | c >) b h G→H∘H→G-identity (δ A i γ) U T F < g | b > h = G→H∘H→G-identity (γ (T « i × g »)) U T (\j c -> F j < g | c >) b h εIArg : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(a : Hu (ε γ) U T i) -> KIArg γ U T (H→G γ U T i a) -> KIArg (ε γ i) U T a εIArg (ι < j | e >') U T i < h | ★ > () εIArg (σ A γ) U T i < a | b > v = εIArg (γ a) U T i b v εIArg (δ A j γ) U T i < g | b > (inl a) = inl a εIArg (δ A j γ) U T i < g | b > (inr v) = inr (εIArg (γ (T « j × g »)) U T i b v) εIArg→I-identity : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(a : Hu (ε γ) U T i)(v : KIArg γ U T (H→G γ U T i a)) -> KIArg→I (ε γ i) U T a (εIArg γ U T i a v) ≡ KIArg→I γ U T (H→G γ U T i a) v εIArg→I-identity (ι < j | e >') U T i < p | ★ > () εIArg→I-identity (σ A γ) U T i < a | b > v = εIArg→I-identity (γ a) U T i b v εIArg→I-identity (δ A j γ) U T i < g | b > (inl a) = refl-≡ εIArg→I-identity (δ A j γ) U T i < g | b > (inr v) = εIArg→I-identity (γ (T « j × g »)) U T i b v εIArg→U-identity : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (i : I)(a : Hu (ε γ) U T i)(v : KIArg γ U T (H→G γ U T i a)) -> KIArg→U (ε γ i) U T a (εIArg γ U T i a v) ≡ KIArg→U γ U T (H→G γ U T i a) v εIArg→U-identity (ι < j | e >') U T i < p | ★ > () εIArg→U-identity (σ A γ) U T i < a | b > v = εIArg→U-identity (γ a) U T i b v εIArg→U-identity (δ A j γ) U T i < g | b > (inl a) = refl-≡ εIArg→U-identity (δ A j γ) U T i < g | b > (inr v) = εIArg→U-identity (γ (T « j × g »)) U T i b v εIArg-subst : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (F : (i : I)(u : U i) -> Set1) (i : I)(a : Hu (ε γ) U T i)(v : KIArg γ U T (H→G γ U T i a)) -> F (KIArg→I (ε γ i) U T a (εIArg γ U T i a v)) (KIArg→U (ε γ i) U T a (εIArg γ U T i a v)) -> F (KIArg→I γ U T (H→G γ U T i a) v) (KIArg→U γ U T (H→G γ U T i a) v) εIArg-subst (ι < j | e >') U T F i < p | ★ > () h εIArg-subst (σ A γ) U T F i < a | b > v h = εIArg-subst (γ a) U T F i b v h εIArg-subst (δ A j γ) U T F i < g | b > (inl a) h = h εIArg-subst (δ A j γ) U T F i < g | b > (inr v) h = εIArg-subst (γ (T « j × g »)) U T F i b v h εIArg-identity : {I : Set}{D : I -> Set1} (γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (F : (i : I)(u : U i) -> Set1) (a : Gu γ U T) (v : KIArg γ U T (H→G γ U T (Gi γ U T a) (G→H γ U T a))) (h : F (KIArg→I (ε γ (Gi γ U T a)) U T (G→H γ U T a) (εIArg γ U T (Gi γ U T a) (G→H γ U T a) v)) (KIArg→U (ε γ (Gi γ U T a)) U T (G→H γ U T a) (εIArg γ U T (Gi γ U T a) (G→H γ U T a) v)) ) -> εIArg-subst γ U T F (Gi γ U T a) (G→H γ U T a) v h ≡₁ h εIArg-identity (ι < i | e >') U T F ★ () h εIArg-identity (σ A γ) U T F < a | b > v h = εIArg-identity (γ a) U T F b v h εIArg-identity (δ A i γ) U T F < g | b > (inl a) h = refl-≡₁ εIArg-identity (δ A i γ) U T F < g | b > (inr v) h = εIArg-identity (γ (T « i × g »)) U T F b v h
50.220779
113
0.388156
0b98f5c14bd54e1b649e009add08f15a00818196
1,128
agda
Agda
src/Categories/Category/Instance/Quivers.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Instance/Quivers.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Instance/Quivers.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Quivers where -- The Category of Quivers open import Level using (Level; suc; _⊔_) open import Relation.Binary.PropositionalEquality.Core using (refl) open import Data.Quiver using (Quiver) open import Data.Quiver.Morphism using (Morphism; id; _∘_; _≃_; ≃-Equivalence; ≃-resp-∘) open import Categories.Category.Core using (Category) private variable o ℓ e o′ ℓ′ e′ : Level Quivers : ∀ o ℓ e → Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) Quivers o ℓ e = record { Obj = Quiver o ℓ e ; _⇒_ = Morphism ; _≈_ = _≃_ ; id = id ; _∘_ = _∘_ ; assoc = λ {_ _ _ G} → record { F₀≡ = refl ; F₁≡ = Equiv.refl G } ; sym-assoc = λ {_ _ _ G} → record { F₀≡ = refl ; F₁≡ = Equiv.refl G } ; identityˡ = λ {_ G} → record { F₀≡ = refl ; F₁≡ = Equiv.refl G } ; identityʳ = λ {_ G} → record { F₀≡ = refl ; F₁≡ = Equiv.refl G } ; identity² = λ {G} → record { F₀≡ = refl ; F₁≡ = Equiv.refl G } ; equiv = ≃-Equivalence ; ∘-resp-≈ = ≃-resp-∘ } where open Quiver using (module Equiv)
33.176471
88
0.574468
4d90a7a692963506af22fa06103b2736945af6b5
129
agda
Agda
test/Succeed/Issue1290b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue1290b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue1290b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue1290b where open import Issue1290 data Eq (x : R) : R → Set where refl : Eq x x test : Eq x (exp x) test = refl
12.9
31
0.651163
df7ca02b72d1fb42d3a3ead26768e0a70fe782f1
21,243
agda
Agda
agda/sn-calculus-props.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
3
2020-04-16T10:58:53.000Z
2020-07-01T03:59:31.000Z
agda/sn-calculus-props.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
null
null
null
agda/sn-calculus-props.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
1
2020-04-15T20:02:49.000Z
2020-04-15T20:02:49.000Z
module _ where open import Data.Nat using (ℕ ; _+_ ; _≤′_ ; suc) open import Induction.Nat using (<′-rec) open import Esterel.Lang.CanFunction open import Function using (_∋_ ; _∘_ ; id ; _$_) open import Data.Nat.Properties.Simple using ( +-comm ; +-assoc) open import utility open import noetherian using (noetherian ; ∥_∥s) open import Esterel.Lang open import Esterel.Lang.Properties open import Esterel.Environment as Env open import Esterel.Context open import Data.Product open import Data.Sum open import Data.Bool open import Data.List using ([] ; [_] ; _∷_ ; List ; _++_) open import Relation.Nullary open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym ; subst ; cong ; trans ; module ≡-Reasoning ; cong₂ ; subst₂ ; inspect) open import Data.Empty open import sn-calculus open import context-properties -- get view, E-views open import Esterel.Lang.Binding open import Data.Maybe using ( just ) -- open import coherence open import Data.List.Any open import Data.List.Any.Properties open import Esterel.Lang.CanFunction.Base open import eval open import blocked open import Data.List.All open ≡-Reasoning using (_≡⟨_⟩_ ; _≡⟨⟩_ ; _∎) open import Relation.Nullary.Decidable using (⌊_⌋) open import Data.FiniteMap import Data.OrderedListMap as OMap open import Esterel.Variable.Signal as Signal using (Signal ; _ₛ) open import Esterel.Variable.Shared as SharedVar using (SharedVar ; _ₛₕ) open import Esterel.Variable.Sequential as SeqVar using (SeqVar ; _ᵥ) open import Esterel.CompletionCode as Code using () renaming (CompletionCode to Code) open import sn-calculus-compatconf using (1-step) open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM open import binding-preserve {- definition of two relations commuting (wrt to Correct Binding) -} CB-COMMUTE : (Term -> Term -> Set) -> (Term -> Term -> Set) -> Set CB-COMMUTE R1 R2 = ∀ {p q r BV FV} -> CorrectBinding p BV FV -> R1 p q -> R2 p r -> ∃ λ {z → (R2 q z × R1 r z)} {- a relation that commutes with itself is confluent -} CB-CONFLUENT : (Term -> Term -> Set) -> Set CB-CONFLUENT R = CB-COMMUTE R R sn⟶*-confluent : CB-CONFLUENT _sn⟶*_ sn⟶*-confluent {p} {q} {r} {BV} {FV} CB = newman ∥ p ∥s p q r BV FV refl CB where {- Proof of Newman's lemma from: _Confluent Reductions: Abstract Properties and Applications to Term Rewriting Systems_ by Gérard Huet. Oct 1980; JACM volume 27 issue 4 https://dl.acm.org/citation.cfm?id=322230 -} newmantype : ℕ -> Set newmantype c = ∀ p q r BV FV -> ∥ p ∥s ≡ c -> CorrectBinding p BV FV -> p sn⟶* q -> p sn⟶* r -> Σ[ z ∈ Term ] (q sn⟶* z × r sn⟶* z) step : ∀ (c : ℕ) -> ((c′ : ℕ) → suc c′ ≤′ c → newmantype c′) -> (newmantype c) step c rec x .x z BV FV nsx≡c CB rrefl s*xz = z , (s*xz , rrefl) step c rec x y .x BV FV nsx≡c CB s*xy rrefl = y , (rrefl , s*xy) step c rec x y z BV FV refl CB (rstep {.x} {y1} {.y} sxy1 s*y1y) (rstep {.x} {z1} {.z} sxz1 s*z1z) with 1-step {x} {y1} {z1} {BV} {FV} CB sxy1 sxz1 ... | (u , s*y1u , s*z1u) with sn⟶-maintains-binding CB sxy1 ... | (BVy1 , FVy1) , (CBy1 , _) with sn⟶-maintains-binding CB sxz1 ... | (BVz1 , FVz1) , (CBz1 , _) with rec ∥ y1 ∥s (noetherian{x}{y1} sxy1) y1 y u BVy1 FVy1 refl CBy1 s*y1y s*y1u ... | (v , s*yv , s*uv) with rec ∥ z1 ∥s (noetherian{x}{z1} sxz1) z1 v z BVz1 FVz1 refl CBz1 (sn⟶*+ s*z1u s*uv) s*z1z ... | (t , s*vt , s*zt) = t , (sn⟶*+ s*yv s*vt) , s*zt newman : ∀ c -> newmantype c newman = <′-rec _ step lift-sn⟶* : ∀ {p q} → (P : Term → Set) → (∀ {p q} → P p → p sn⟶ q → P q) → P p → p sn⟶* q → P q lift-sn⟶* P P-respects-sn⟶ Pp rrefl = Pp lift-sn⟶* P P-respects-sn⟶ Pp (rstep psn⟶r rsn⟶*q) = lift-sn⟶* P P-respects-sn⟶ (P-respects-sn⟶ Pp psn⟶r) rsn⟶*q sn≡ₑ-preserve-cb : ∀{p q BV FV} → CorrectBinding p BV FV → p sn≡ₑ q → Σ (VarList × VarList) λ {(BVq , FVq) → CorrectBinding q BVq FVq} sn≡ₑ-preserve-cb cb (rstp x) with sn⟶-maintains-binding cb x ... | (bv,fv , cbq , _)= _ , cbq sn≡ₑ-preserve-cb cb (rsym psn≡ₑq x) = _ , x sn≡ₑ-preserve-cb cb rref = _ , cb sn≡ₑ-preserve-cb cb (rtrn psn≡ₑq psn≡ₑq₁) = sn≡ₑ-preserve-cb (proj₂ (sn≡ₑ-preserve-cb cb psn≡ₑq)) psn≡ₑq₁ sn≡ₑ-consistent : ∀{p q BV FV} → CorrectBinding p BV FV → p sn≡ₑ q → Σ[ r ∈ Term ] p sn⟶* r × q sn⟶* r sn≡ₑ-consistent cb (rstp x) = _ , rstep x rrefl , rrefl sn≡ₑ-consistent cb (rsym qsn≡ₑp cbq) with sn≡ₑ-consistent cbq qsn≡ₑp ... | (r , qsn⟶r , psn⟶r ) = (r , psn⟶r , qsn⟶r) sn≡ₑ-consistent cb rref = _ , rrefl , rrefl sn≡ₑ-consistent cb (rtrn psn≡ₑs ssn≡ₑq) with (sn≡ₑ-preserve-cb cb psn≡ₑs) ... | (_ , cbs) with sn≡ₑ-consistent cb psn≡ₑs | sn≡ₑ-consistent cbs ssn≡ₑq ... | (rl , psn⟶*rl , ssn⟶*rl) | (rr , ssn⟶*rr , qsn⟶*rr) with sn⟶*-confluent cbs ssn⟶*rl ssn⟶*rr ... | (r , rlsn⟶*r , rrsn⟶*r) = r , (sn⟶*+ psn⟶*rl rlsn⟶*r , sn⟶*+ qsn⟶*rr rrsn⟶*r ) irreducibility-of-complete-sn⟶₁ : ∀{p q} → complete p → p sn⟶₁ q → ⊥ irreducibility-of-complete-sn⟶₁ (codone p/done) psn⟶₁q = done-¬sn⟶₁ p/done psn⟶₁q irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q with ρ-stays-ρ-sn⟶₁ ρθpsn⟶₁ρθ'q ... | θ' , q , A' , refl with get-view ρθpsn⟶₁ρθ'q irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q | θ' , q , A' , refl | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , e-view) = ⊥-elim (done-E-view-term-disjoint (done-⟦⟧e p/done p≐E⟦pin⟧) (->E-view-inner-term e-view)) irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q | θ' , q , A' , refl | inj₂ (refl , refl , vabsence S S∈ x₂ x₃) with x S S∈ ... | inj₁ S≡ = lookup-S-eq θ S S∈ S∈ S≡ x₂ (λ ()) ... | inj₂ S≡ = lookup-S-eq θ S S∈ S∈ S≡ x₂ (λ ()) irreducibility-of-complete-sn⟶₁ (coenv {θ} (θcomplete x x₁) p/done) ρθpsn⟶₁ρθ'q | θ' , q , A' , refl | inj₂ (refl , refl , vreadyness s s∈ x₂ x₃) with x₁ s s∈ ... | s≡ with x₂ ... | inj₁ s2≡ = lookup-s-eq θ s s∈ s∈ s≡ s2≡ (λ ()) ... | inj₂ s2≡ = lookup-s-eq θ s s∈ s∈ s≡ s2≡ (λ ()) inescapability-of-paused-sn⟶ : ∀ {p q} -> paused p -> p sn⟶ q -> paused q inescapability-of-paused-sn⟶ ppause (rcontext .[] dchole ()) inescapability-of-paused-sn⟶ (pseq ()) (rcontext .[] dchole rseq-done) inescapability-of-paused-sn⟶ (pseq ()) (rcontext .[] dchole rseq-exit) inescapability-of-paused-sn⟶ (pseq pausedp) (rcontext _ (dcseq₁ dc) psn⟶₁p') = pseq (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p')) inescapability-of-paused-sn⟶ (pseq pausedp) (rcontext _ (dcseq₂ dc) psn⟶₁p') = pseq pausedp inescapability-of-paused-sn⟶ (ploopˢ ()) (rcontext .[] dchole rloopˢ-exit) inescapability-of-paused-sn⟶ (ploopˢ pausedp) (rcontext _ (dcloopˢ₁ dc) psn⟶₁p') = ploopˢ (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p')) inescapability-of-paused-sn⟶ (ploopˢ pausedp) (rcontext _ (dcloopˢ₂ dc) psn⟶₁p') = ploopˢ pausedp inescapability-of-paused-sn⟶ (ppar pausedp _) (rcontext .[] dchole (rpar-done-right p' q')) = ⊥-elim (halted-paused-disjoint p' pausedp) inescapability-of-paused-sn⟶ (ppar _ pausedq) (rcontext .[] dchole (rpar-done-left p' q')) = ⊥-elim (halted-paused-disjoint q' pausedq) inescapability-of-paused-sn⟶ (ppar pausedp pausedq) (rcontext _ (dcpar₁ dc) psn⟶₁p') = ppar (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p')) pausedq inescapability-of-paused-sn⟶ (ppar pausedp pausedq) (rcontext _ (dcpar₂ dc) psn⟶₁p') = ppar pausedp (inescapability-of-paused-sn⟶ pausedq (rcontext _ dc psn⟶₁p')) inescapability-of-paused-sn⟶ (psuspend pausedp) (rcontext .[] dchole (rsuspend-done haltedp)) = ⊥-elim (halted-paused-disjoint haltedp pausedp) inescapability-of-paused-sn⟶ (psuspend pausedp) (rcontext _ (dcsuspend dc) psn⟶₁p') = psuspend (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p')) inescapability-of-paused-sn⟶ (ptrap ()) (rcontext .[] dchole (rtrap-done hnothin)) inescapability-of-paused-sn⟶ (ptrap ()) (rcontext .[] dchole (rtrap-done (hexit n))) inescapability-of-paused-sn⟶ (ptrap pausedp) (rcontext _ (dctrap dc) psn⟶₁p') = ptrap (inescapability-of-paused-sn⟶ pausedp (rcontext _ dc psn⟶₁p')) inescapability-of-paused-sn⟶* : ∀ {p q} -> paused p -> p sn⟶* q -> paused q inescapability-of-paused-sn⟶* pausedp rrefl = pausedp inescapability-of-paused-sn⟶* pausedp (rstep psn⟶r r⟶q) = inescapability-of-paused-sn⟶* (inescapability-of-paused-sn⟶ pausedp psn⟶r) r⟶q inescapability-of-complete-sn⟶ : ∀{p q} → complete p → p sn⟶ q → complete q inescapability-of-complete-sn⟶ c@(codone p-done) psn⟶q = codone (done-sn⟶ p-done psn⟶q) inescapability-of-complete-sn⟶ c@(coenv x x₁) (rcontext .[] dchole psn⟶₁p') = ⊥-elim (irreducibility-of-complete-sn⟶₁ c psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x (dhalted hnothin)) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dhalted hnothin)) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x (dhalted (hexit n))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dhalted (hexit n))) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x (dpaused p/paused)) (rcontext .(cenv _ _ ∷ _) (dcenv dc) psn⟶₁p') with (inescapability-of-complete-sn⟶ (codone (dpaused p/paused)) (rcontext _ dc psn⟶₁p')) inescapability-of-complete-sn⟶ (coenv x (dpaused ppause)) (rcontext .(cenv _ _ ∷ _) (dcenv dchole) psn⟶₁p') | rec = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused ppause)) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ploopˢ p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (ploopˢ p/paused))) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ploopˢ p/paused))) (rcontext .(cenv _ _ ∷ ceval (eloopˢ _) ∷ _) (dcenv (dcloopˢ₁ dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ploopˢ p/paused))) (rcontext .(cenv _ _ ∷ cloopˢ₂ _ ∷ _) (dcenv (dcloopˢ₂ dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (pseq p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (pseq p/paused))) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (pseq p/paused))) (rcontext .(cenv _ _ ∷ ceval (eseq _) ∷ _) (dcenv (dcseq₁ dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (pseq p/paused))) (rcontext .(cenv _ _ ∷ cseq₂ _ ∷ _) (dcenv (dcseq₂ dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x (dpaused (ppar p/paused p/paused₁))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (ppar p/paused p/paused₁))) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ppar p/paused p/paused₁))) (rcontext .(cenv _ _ ∷ ceval (epar₁ _) ∷ _) (dcenv (dcpar₁ dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ppar p/paused p/paused₁))) (rcontext .(cenv _ _ ∷ ceval (epar₂ _) ∷ _) (dcenv (dcpar₂ dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x (dpaused (psuspend p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (psuspend p/paused))) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (psuspend p/paused))) (rcontext .(cenv _ _ ∷ ceval (esuspend _) ∷ _) (dcenv (dcsuspend dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn⟶ (coenv x (dpaused (ptrap p/paused))) (rcontext .(cenv _ _ ∷ []) (dcenv dchole) psn⟶₁p') | rec = ⊥-elim (irreducibility-of-complete-sn⟶₁ (codone (dpaused (ptrap p/paused))) psn⟶₁p') inescapability-of-complete-sn⟶ (coenv x₁ (dpaused (ptrap p/paused))) (rcontext .(cenv _ _ ∷ ceval etrap ∷ _) (dcenv (dctrap dc)) psn⟶₁p') | codone x = coenv x₁ x inescapability-of-complete-sn : ∀{p q} → complete p → p sn⟶* q → complete q inescapability-of-complete-sn = lift-sn⟶* complete inescapability-of-complete-sn⟶ equality-of-complete-sn⟶* : ∀{θ θ' p q A A'} → complete (ρ⟨ θ , A ⟩· p) → (ρ⟨ θ , A ⟩· p) sn⟶* (ρ⟨ θ' , A' ⟩· q) → θ ≡ θ' × A ≡ A' equality-of-complete-sn⟶* ρθp/complete rrefl = refl , refl equality-of-complete-sn⟶* ρθp/complete (rstep (rcontext _ dchole ρθpsn⟶₁ρθ''r) ρθ''rsn⟶*ρθ'q) with irreducibility-of-complete-sn⟶₁ ρθp/complete ρθpsn⟶₁ρθ''r ... | () equality-of-complete-sn⟶* ρθp/complete (rstep (rcontext _ (dcenv ρθp≐C⟦p'⟧) p'sn⟶₁r) ρθrsn⟶*ρθ'q) = equality-of-complete-sn⟶* (inescapability-of-complete-sn⟶ ρθp/complete (rcontext _ (dcenv ρθp≐C⟦p'⟧) p'sn⟶₁r)) ρθrsn⟶*ρθ'q get-view/blocked : ∀{θ θ' p q A A'} → blocked θ A p → (ρθpsn⟶₁ρθ'q : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A' ⟩· q) → ∃ (λ a → ∃ (->pot-view ρθpsn⟶₁ρθ'q a)) get-view/blocked p/blocked ρθpsn⟶₁ρθ'q with get-view ρθpsn⟶₁ρθ'q ... | inj₂ refl-pot-view = refl-pot-view ... | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , e-view) with blocked-⟦⟧e p/blocked p≐E⟦pin⟧ | ->E-view-inner-term e-view ... | inj₂ pin/done | e-view-term = ⊥-elim (done-E-view-term-disjoint pin/done (->E-view-inner-term e-view)) ... | (inj₁ (bpar-both pin'/blocked qin'/blocked)) | () ... | (inj₁ (bpar-left pin'/blocked qin'/done)) | () ... | (inj₁ (bpar-right pin'/done qin'/blocked)) | () ... | (inj₁ (bloopˢ pin/blocked)) | () ... | (inj₁ (bseq pin/blocked)) | () ... | (inj₁ (bsusp pin/blocked)) | () ... | (inj₁ (btrap pin/blocked)) | () get-view/blocked {θ} p/blocked (ris-present S∈' θS≡present .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vis-present) | (inj₁ (bsig-exists S S∈ θS≡unknown)) | evt-present with trans (sym θS≡present) (trans (Env.sig-stats-∈-irr {S} {θ} S∈' S∈) θS≡unknown) ... | () get-view/blocked {θ} p/blocked (ris-absent S∈' θS≡absent .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vis-absent) | (inj₁ (bsig-exists S S∈ θS≡unknown)) | evt-present with trans (sym θS≡absent) (trans (Env.sig-stats-∈-irr {S} {θ} S∈' S∈) θS≡unknown) ... | () get-view/blocked p/blocked (rraise-shared {s = s} e' .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vraise-shared) | (inj₁ (bshared e/blocked)) | evt-raise-shared = ⊥-elim (all-ready-blocked-disjoint (e' , e/blocked)) get-view/blocked p/blocked (rset-shared-value-old {s = s} e' s∈ θs≡old .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vset-shared-value-old) | (inj₁ (bsset e/blocked)) | evt-set-shared = ⊥-elim (all-ready-blocked-disjoint (e' , e/blocked)) get-view/blocked p/blocked (rset-shared-value-new {s = s} e' s∈ θs≡new .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vset-shared-value-new) | (inj₁ (bsset e/blocked)) | evt-set-shared = ⊥-elim (all-ready-blocked-disjoint (e' , e/blocked)) get-view/blocked p/blocked (rraise-var {x = x} e' .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vraise-var) | (inj₁ (bvar e/blocked)) | evt-raise-var = ⊥-elim (all-ready-blocked-disjoint (e' , e/blocked)) get-view/blocked p/blocked (rset-var {x = x} x∈ e' .p≐E⟦pin⟧) | inj₁ (E , pin , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , vset-var) | (inj₁ (bxset e/blocked)) | evt-set-var = ⊥-elim (all-ready-blocked-disjoint (e' , e/blocked)) get-view/blocked {A = .WAIT} p/blocked ρθpsn⟶₁ρθ'q | inj₁ (E , s ⇐ e , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , ()) | inj₁ bwset | evt-set-shared get-view/blocked {A = .WAIT} p/blocked ρθpsn⟶₁ρθ'q | inj₁ (E , emit S , qin , p≐E⟦pin⟧ , q≐E⟦qin⟧ , ()) | inj₁ bwemit | evt-emit irreducibility-of-blocked-sn⟶₁ : ∀ {θ p q A} → blocked θ A p → p sn⟶₁ q → ⊥ irreducibility-of-blocked-sn⟶₁ (bsig-exists S S∈ θS≡unknown) () irreducibility-of-blocked-sn⟶₁ (bshared e/blocked) () irreducibility-of-blocked-sn⟶₁ (bsset e/blocked) () irreducibility-of-blocked-sn⟶₁ (bvar e/blocked) () irreducibility-of-blocked-sn⟶₁ (bxset e/blocked) () irreducibility-of-blocked-sn⟶₁ {p = s ⇐ e} {A = WAIT} bwset () irreducibility-of-blocked-sn⟶₁ {p = emit S} {A = WAIT} bwemit () irreducibility-of-blocked-sn⟶₁ (bpar-both p/blocked q/blocked) (rpar-done-right p/halted q/done) = halted-blocked-disjoint p/halted p/blocked irreducibility-of-blocked-sn⟶₁ (bpar-left p/blocked q/done) (rpar-done-right p/halted q/done') = halted-blocked-disjoint p/halted p/blocked irreducibility-of-blocked-sn⟶₁ (bpar-right p/done q/blocked) (rpar-done-right p/halted q/done) = done-blocked-disjoint q/done q/blocked irreducibility-of-blocked-sn⟶₁ (bpar-both p/blocked q/blocked) (rpar-done-left p/done q/halted) = halted-blocked-disjoint q/halted q/blocked irreducibility-of-blocked-sn⟶₁ (bpar-left p/blocked q/done) (rpar-done-left p/done q/halted) = done-blocked-disjoint p/done p/blocked irreducibility-of-blocked-sn⟶₁ (bpar-right p/done q/blocked) (rpar-done-left p/done' q/halted) = halted-blocked-disjoint q/halted q/blocked irreducibility-of-blocked-sn⟶₁ (bseq ()) rseq-done irreducibility-of-blocked-sn⟶₁ (bseq ()) rseq-exit irreducibility-of-blocked-sn⟶₁ (bloopˢ ()) rloopˢ-exit irreducibility-of-blocked-sn⟶₁ (bsusp p/blocked) (rsuspend-done p/halted) = halted-blocked-disjoint p/halted p/blocked irreducibility-of-blocked-sn⟶₁ (btrap p/blocked) (rtrap-done p/halted) = halted-blocked-disjoint p/halted p/blocked irreducibility-of-halted-sn⟶ : ∀ {p q} -> halted p -> p sn⟶ q -> ⊥ irreducibility-of-halted-sn⟶ hnothin (rcontext [] dchole ()) irreducibility-of-halted-sn⟶ (hexit n) (rcontext [] dchole ()) -- not sure if it's worthwhile for now to also prove this for ρ θ · p sn⟶₁ ρ θ' · p inescapability-of-blocked-inside-sn⟶ : ∀{θ p q A} → blocked θ A p → p sn⟶ q → blocked θ A q inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ dchole psn⟶₁p') = ⊥-elim (irreducibility-of-blocked-sn⟶₁ p/blocked psn⟶₁p') inescapability-of-blocked-inside-sn⟶ (bpar-both p/blocked q/blocked) (rcontext _ (dcpar₁ p≐C⟦pin⟧) pinsn⟶₁pin') = bpar-both (inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) q/blocked inescapability-of-blocked-inside-sn⟶ (bpar-both p/blocked q/blocked) (rcontext _ (dcpar₂ p≐C⟦pin⟧) pinsn⟶₁pin') = bpar-both p/blocked (inescapability-of-blocked-inside-sn⟶ q/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (bpar-left p/blocked q/done) (rcontext _ (dcpar₁ p≐C⟦pin⟧) pinsn⟶₁pin') = bpar-left (inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) q/done inescapability-of-blocked-inside-sn⟶ (bpar-left p/blocked q/done) (rcontext _ (dcpar₂ p≐C⟦pin⟧) pinsn⟶₁pin') = bpar-left p/blocked (done-sn⟶ q/done (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (bpar-right p/done q/blocked) (rcontext _ (dcpar₁ p≐C⟦pin⟧) pinsn⟶₁pin') = bpar-right (done-sn⟶ p/done (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) q/blocked inescapability-of-blocked-inside-sn⟶ (bpar-right p/done q/blocked) (rcontext _ (dcpar₂ p≐C⟦pin⟧) pinsn⟶₁pin') = bpar-right p/done (inescapability-of-blocked-inside-sn⟶ q/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (bseq p/blocked) (rcontext _ (dcseq₁ p≐C⟦pin⟧) pinsn⟶₁pin') = bseq (inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (bseq p/blocked) (rcontext _ (dcseq₂ p≐C⟦pin⟧) pinsn⟶₁pin') = bseq p/blocked inescapability-of-blocked-inside-sn⟶ (bloopˢ p/blocked) (rcontext _ (dcloopˢ₁ p≐C⟦pin⟧) pinsn⟶₁pin') = bloopˢ (inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (bloopˢ p/blocked) (rcontext _ (dcloopˢ₂ p≐C⟦pin⟧) pinsn⟶₁pin') = bloopˢ p/blocked inescapability-of-blocked-inside-sn⟶ (bsusp p/blocked) (rcontext _ (dcsuspend p≐C⟦pin⟧) pinsn⟶₁pin') = bsusp (inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (btrap p/blocked) (rcontext _ (dctrap p≐C⟦pin⟧) pinsn⟶₁pin') = btrap (inescapability-of-blocked-inside-sn⟶ p/blocked (rcontext _ p≐C⟦pin⟧ pinsn⟶₁pin')) inescapability-of-blocked-inside-sn⟶ (bshared e/blocked) (rcontext _ (dcshared p≐C⟦pin⟧) pinsn⟶₁pin') = bshared e/blocked inescapability-of-blocked-inside-sn⟶ (bvar e/blocked) (rcontext _ (dcvar p≐C⟦pin⟧) pinsn⟶₁pin') = bvar e/blocked inescapability-of-blocked-inside-sn⟶ {θ} {A = A}(bsig-exists S S∈ θS≡unknown) (rcontext _ S?p:q≐C⟦pin⟧ pinsn⟶₁pin') with S?p:q≐C⟦pin⟧ -- we still have the dchole case here since Agda can't determine that it cannot happen ... | dchole = ⊥-elim (irreducibility-of-blocked-sn⟶₁ {A = A} (bsig-exists {θ} S S∈ θS≡unknown) pinsn⟶₁pin') ... | dcpresent₁ p≐C⟦pin⟧ = bsig-exists S S∈ θS≡unknown ... | dcpresent₂ p≐C⟦pin⟧ = bsig-exists S S∈ θS≡unknown
48.947005
174
0.653627
1cfb7ccbfcb8f79b823114f1abeddfcf04a31be9
423
agda
Agda
Cubical/Data/Strict2Group/Categorical.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Data/Strict2Group/Categorical.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Data/Strict2Group/Categorical.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Strict2Group.Categorical where open import Cubical.Foundations.Prelude open import Cubical.Categories.InternalCategory open import Cubical.Categories.Groups {-- Formalization of strict 2-groups as internal categories of the 1-category Grp of Groups. --} Strict2GroupInternalCat : (ℓ : Level) → Type (ℓ-suc ℓ) Strict2GroupInternalCat ℓ = InternalCategory (1BGROUP ℓ)
28.2
56
0.787234
cb2a93d33f6233ed5b88a4b5166752b56393304a
2,324
agda
Agda
test/succeed/Lambda.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/Lambda.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/Lambda.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
{-# OPTIONS --no-termination-check #-} module Lambda where module Prelude where data Bool : Set where true : Bool false : Bool if_then_else_ : {A : Set} -> Bool -> A -> A -> A if true then x else y = x if false then x else y = y _∧_ : Bool -> Bool -> Bool true ∧ y = y false ∧ y = false _∨_ : Bool -> Bool -> Bool true ∨ y = true false ∨ y = y ¬_ : Bool -> Bool ¬ true = false ¬ false = true data List (A : Set) : Set where nil : List A _::_ : A -> List A -> List A _++_ : {A : Set} -> List A -> List A -> List A nil ++ ys = ys (x :: xs) ++ ys = x :: xs ++ ys filter : {A : Set} -> (A -> Bool) -> List A -> List A filter p nil = nil filter p (x :: xs) = if p x then x :: filter p xs else filter p xs postulate String : Set Int : Set Char : Set {-# BUILTIN BOOL Bool #-} {-# BUILTIN FALSE false #-} {-# BUILTIN TRUE true #-} {-# BUILTIN STRING String #-} {-# BUILTIN INTEGER Int #-} {-# BUILTIN CHAR Char #-} {-# BUILTIN LIST List #-} {-# BUILTIN NIL nil #-} {-# BUILTIN CONS _::_ #-} primitive primStringEquality : String -> String -> Bool _==_ = primStringEquality infix 10 if_then_else_ infixr 50 _::_ _++_ infixl 5 _∨_ infixl 7 _∧_ infix 50 ¬_ infix 15 _==_ open Prelude Name : Set Name = String data Exp : Set where var : Name -> Exp ƛ_⟶_ : Name -> Exp -> Exp _$_ : Exp -> Exp -> Exp infixl 50 _$_ infix 20 ƛ_⟶_ infix 80 _[_/_] infix 15 _∈_ _∈_ : Name -> List Name -> Bool x ∈ y :: ys = x == y ∨ x ∈ ys x ∈ nil = false -- Free variables FV : Exp -> List Name FV (var x) = x :: nil FV (s $ t) = FV s ++ FV t FV (ƛ x ⟶ t) = filter (\y -> ¬ (x == y)) (FV t) -- Fresh names fresh : Name -> Exp -> Name fresh x e = fresh' (FV e) where fresh' : List Name -> Name fresh' xs = "z" -- TODO -- Substitution _[_/_] : Exp -> Exp -> Name -> Exp var x [ r / z ] = if x == z then r else var x (s $ t) [ r / z ] = s [ r / z ] $ t [ r / z ] (ƛ x ⟶ t) [ r / z ] = if x == z then ƛ x ⟶ t else if x ∈ FV r then ( let y : Name y = fresh x r in ƛ y ⟶ t [ var y / x ] [ r / z ] ) else ƛ x ⟶ t [ r / z ]
20.936937
68
0.480207
4d2d3b1f2a0ea6f201f3f92a1a240558df37774b
4,739
agda
Agda
agda-stdlib/src/Data/Nat/LCM.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/Nat/LCM.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/Nat/LCM.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Least common multiple ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Nat.LCM where open import Algebra open import Data.Nat.Base open import Data.Nat.Coprimality using (Coprime) open import Data.Nat.Divisibility open import Data.Nat.DivMod open import Data.Nat.Properties open import Data.Nat.Solver open import Data.Nat.GCD open import Data.Product open import Data.Sum.Base using (_⊎_; inj₁; inj₂) open import Function open import Relation.Binary.PropositionalEquality as P using (_≡_; refl; sym; trans; cong; cong₂; module ≡-Reasoning) open import Relation.Binary open import Relation.Nullary.Decidable using (False; fromWitnessFalse) open +-*-Solver private gcd≢0′ : ∀ m n → False (gcd (suc m) n ≟ 0) gcd≢0′ m n = fromWitnessFalse (gcd[m,n]≢0 (suc m) n (inj₁ (λ()))) ------------------------------------------------------------------------ -- Definition lcm : ℕ → ℕ → ℕ lcm zero n = zero lcm m@(suc m-1) n = m * (n / gcd m n) {gcd≢0′ m-1 n} ------------------------------------------------------------------------ -- Core properties private rearrange : ∀ m-1 n → lcm (suc m-1) n ≡ ((suc m-1) * n / gcd (suc m-1) n) {gcd≢0′ m-1 n} rearrange m-1 n = sym (*-/-assoc m {n} {gcd m n} {gcd≢0′ m-1 n} (gcd[m,n]∣n m n)) where m = suc m-1 m∣lcm[m,n] : ∀ m n → m ∣ lcm m n m∣lcm[m,n] zero n = 0 ∣0 m∣lcm[m,n] m@(suc _) n = m∣m*n (n / gcd m n) n∣lcm[m,n] : ∀ m n → n ∣ lcm m n n∣lcm[m,n] zero n = n ∣0 n∣lcm[m,n] m@(suc m-1) n = begin n ∣⟨ m∣m*n (m / gcd m n) ⟩ n * (m / gcd m n) ≡⟨ sym (*-/-assoc n {≢0 = gcd≢0′ m-1 n} (gcd[m,n]∣m m n)) ⟩ n * m / gcd m n ≡⟨ cong (λ v → (v / gcd m n) {gcd≢0′ m-1 n}) (*-comm n m) ⟩ m * n / gcd m n ≡⟨ sym (rearrange m-1 n) ⟩ m * (n / gcd m n) ∎ where open ∣-Reasoning lcm-least : ∀ {m n c} → m ∣ c → n ∣ c → lcm m n ∣ c lcm-least {zero} {n} {c} 0∣c _ = 0∣c lcm-least {m@(suc m-1)} {n} {c} m∣c n∣c = P.subst (_∣ c) (sym (rearrange m-1 n)) (m∣n*o⇒m/n∣o {n≢0 = gcd≢0′ m-1 n} gcd[m,n]∣m*n mn∣c*gcd) where open ∣-Reasoning gcd[m,n]∣m*n : gcd m n ∣ m * n gcd[m,n]∣m*n = ∣-trans (gcd[m,n]∣m m n) (m∣m*n n) mn∣c*gcd : m * n ∣ c * gcd m n mn∣c*gcd = begin m * n ∣⟨ gcd-greatest (P.subst (_∣ c * m) (*-comm n m) (*-monoˡ-∣ m n∣c)) (*-monoˡ-∣ n m∣c) ⟩ gcd (c * m) (c * n) ≡⟨ sym (c*gcd[m,n]≡gcd[cm,cn] c m n) ⟩ c * gcd m n ∎ ------------------------------------------------------------------------ -- Other properties -- Note that all other properties of `gcd` should be inferable from the -- 3 core properties above. gcd*lcm : ∀ m n → gcd m n * lcm m n ≡ m * n gcd*lcm zero n = *-zeroʳ (gcd 0 n) gcd*lcm m@(suc m-1) n = trans (cong (gcd m n *_) (rearrange m-1 n)) (m*[n/m]≡n {gcd m n} (begin gcd m n ∣⟨ gcd[m,n]∣m m n ⟩ m ∣⟨ m∣m*n n ⟩ m * n ∎)) where open ∣-Reasoning lcm[0,n]≡0 : ∀ n → lcm 0 n ≡ 0 lcm[0,n]≡0 n = 0∣⇒≡0 (m∣lcm[m,n] 0 n) lcm[n,0]≡0 : ∀ n → lcm n 0 ≡ 0 lcm[n,0]≡0 n = 0∣⇒≡0 (n∣lcm[m,n] n 0) lcm-comm : ∀ m n → lcm m n ≡ lcm n m lcm-comm m n = ∣-antisym (lcm-least (n∣lcm[m,n] n m) (m∣lcm[m,n] n m)) (lcm-least (n∣lcm[m,n] m n) (m∣lcm[m,n] m n)) ------------------------------------------------------------------------ -- Least common multiple (lcm). module LCM where -- Specification of the least common multiple (lcm) of two natural -- numbers. record LCM (i j lcm : ℕ) : Set where field -- The lcm is a common multiple. commonMultiple : i ∣ lcm × j ∣ lcm -- The lcm divides all common multiples, i.e. the lcm is the least -- common multiple according to the partial order _∣_. least : ∀ {m} → i ∣ m × j ∣ m → lcm ∣ m open LCM public -- The lcm is unique. unique : ∀ {d₁ d₂ m n} → LCM m n d₁ → LCM m n d₂ → d₁ ≡ d₂ unique d₁ d₂ = ∣-antisym (LCM.least d₁ (LCM.commonMultiple d₂)) (LCM.least d₂ (LCM.commonMultiple d₁)) open LCM public using (LCM) hiding (module LCM) ------------------------------------------------------------------------ -- Calculating the LCM lcm-LCM : ∀ m n → LCM m n (lcm m n) lcm-LCM m n = record { commonMultiple = m∣lcm[m,n] m n , n∣lcm[m,n] m n ; least = uncurry′ lcm-least } mkLCM : ∀ m n → ∃ λ d → LCM m n d mkLCM m n = lcm m n , lcm-LCM m n GCD*LCM : ∀ {m n g l} → GCD m n g → LCM m n l → m * n ≡ g * l GCD*LCM {m} {n} {g} {l} gc lc = sym (begin g * l ≡⟨ cong₂ _*_ (GCD.unique gc (gcd-GCD m n)) (LCM.unique lc (lcm-LCM m n)) ⟩ gcd m n * lcm m n ≡⟨ gcd*lcm m n ⟩ m * n ∎) where open ≡-Reasoning
32.238095
111
0.491876
0bbaae82dcf94a68e789fc714e7253495037fce7
4,016
agda
Agda
UniDB/Subst/Pair.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
UniDB/Subst/Pair.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
UniDB/Subst/Pair.agda
skeuchel/unidb-agda
7ae52205db44ad4f463882ba7e5082120fb76349
[ "MIT" ]
null
null
null
module UniDB.Subst.Pair where open import UniDB.Subst.Core open import UniDB.Morph.Pair instance iLkPair : {T : STX} {{apTT : Ap T T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} → Lk T (Pair Ξ Ζ) lk {{iLkPair {T}}} (ξ ⊗ ζ) i = ap {T} ζ (lk {T} ξ i) iLkRenPair : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} {Ξ : MOR} {{lkIxΞ : Lk Ix Ξ}} {{lkTΞ : Lk T Ξ}} {{lkRenTΞ : LkRen T Ξ}} {Ζ : MOR} {{lkIxΖ : Lk Ix Ζ}} {{lkTΖ : Lk T Ζ}} {{lkRenTΖ : LkRen T Ζ}} {{upΖ : Up Ζ}} → LkRen T (Pair Ξ Ζ) lk-ren {{iLkRenPair {T} {Ξ} {Ζ}}} (ξ ⊗ ζ) i = begin ap {T} ζ (lk {T} ξ i) ≡⟨ cong (ap {T} ζ) (lk-ren {T} ξ i) ⟩ ap {T} ζ (vr (lk {Ix} ξ i)) ≡⟨ ap-vr {T} ζ (lk {Ix} ξ i) ⟩ lk {T} ζ (lk {Ix} ξ i) ≡⟨ lk-ren {T} ζ (lk {Ix} ξ i) ⟩ vr (lk {Ix} ζ (lk {Ix} ξ i)) ∎ iLkHCompPair : {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} → LkHCompAp T Ξ Ζ (Pair Ξ Ζ) lk-⊡-ap {{iLkHCompPair}} ξ ζ i = refl iLkUpPairRenaming : (T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} (Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} {{lkIxΞ : Lk Ix Ξ}} {{lkRenTΞ : LkRen T Ξ}} {{lkUpIxΞ : LkUp Ix Ξ}} (Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} → LkUp T (Pair Ξ Ζ) lk-↑₁-zero {{iLkUpPairRenaming T Ξ Ζ}} (ξ ⊗ ζ) = begin ap {T} (ζ ↑₁) (lk {T} (ξ ↑₁) zero) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-↑₁-zero ξ) ⟩ ap {T} (ζ ↑₁) (vr zero) ≡⟨ ap-vr {T} (ζ ↑₁) zero ⟩ lk (ζ ↑₁) zero ≡⟨ lk-↑₁-zero ζ ⟩ vr zero ∎ lk-↑₁-suc {{iLkUpPairRenaming T Ξ Ζ}} (ξ ⊗ ζ) i = begin ap {T} (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-ren (ξ ↑₁) (suc i)) ⟩ ap {T} (ζ ↑₁) (vr (lk (ξ ↑₁) (suc i))) ≡⟨ ap-vr {T} (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ⟩ lk (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ≡⟨ cong (lk (_↑₁ ζ)) (lk-↑₁-suc ξ i) ⟩ lk (ζ ↑₁) (suc (lk ξ i)) ≡⟨ lk-↑₁-suc ζ (lk ξ i) ⟩ wk₁ (lk ζ (lk ξ i)) ≡⟨ cong wk₁ (sym (ap-vr {T} ζ (lk ξ i))) ⟩ wk₁ (ap {T} ζ (vr (lk ξ i))) ≡⟨ cong wk₁ (cong (ap {T} ζ) (sym (lk-ren ξ i))) ⟩ wk₁ (ap {T} ζ (lk ξ i)) ∎ iLkUpPairSubstitution : (T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} (Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} (Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} (ap-wk₁-TΖ : {γ₁ γ₂ : Dom} (ζ : Ζ γ₁ γ₂) (t : T γ₁) → ap {T} (ζ ↑₁) (wk₁ t) ≡ wk₁ (ap {T} ζ t)) → LkUp T (Pair Ξ Ζ) lk-↑₁-zero {{iLkUpPairSubstitution T Ξ Ζ ap-wk₁-TΖ}} (ξ ⊗ ζ) = begin ap {T} (ζ ↑₁) (lk (ξ ↑₁) zero) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-↑₁-zero ξ) ⟩ ap {T} (ζ ↑₁) (vr zero) ≡⟨ ap-vr {T} (ζ ↑₁) zero ⟩ lk (ζ ↑₁) zero ≡⟨ lk-↑₁-zero ζ ⟩ vr zero ∎ lk-↑₁-suc {{iLkUpPairSubstitution T Ξ Ζ ap-wk₁-TΖ}} (ξ ⊗ ζ) i = begin ap {T} (ζ ↑₁) (lk (ξ ↑₁) (suc i)) ≡⟨ cong (ap {T} (ζ ↑₁)) (lk-↑₁-suc ξ i) ⟩ ap {T} (ζ ↑₁) (wk₁ (lk ξ i)) ≡⟨ ap-wk₁-TΖ ζ (lk ξ i) ⟩ wk₁ (ap {T} ζ (lk ξ i)) ∎ instance iLkUpPair : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} {{apWkTT : ApWk T T}} {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}} → LkUp T (Pair Ξ Ζ) iLkUpPair {T} {Ξ} {Ζ} = iLkUpPairSubstitution T Ξ Ζ (ap-wk₁ {T}) record ApPair (T : STX) {{apTT : Ap T T}} (X : STX) {{apTX : Ap T X}} : Set₁ where field ap-pair : {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζ : Ζ γ₂ γ₃) (x : X γ₁) → ap {T} (ξ ⊗ ζ) x ≡ ap {T} ζ (ap {T} ξ x) open ApPair {{...}} public instance iApPairIxIx : ApPair Ix Ix ap-pair {{iApPairIxIx}} {Ξ} ξ ζ i = refl
43.652174
92
0.44248
dc4f04380ddfb2a22d25764982637c3b5b600970
11,936
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Permutation/Inductive/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Permutation/Inductive/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Permutation/Inductive/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties of permutation ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Permutation.Inductive.Properties where open import Algebra open import Algebra.FunctionProperties open import Algebra.Structures open import Data.List.Base as List open import Data.List.Relation.Binary.Permutation.Inductive open import Data.List.Relation.Unary.Any using (Any; here; there) open import Data.List.Relation.Unary.All using (All; []; _∷_) open import Data.List.Membership.Propositional open import Data.List.Membership.Propositional.Properties open import Data.List.Relation.Binary.BagAndSetEquality using (bag; _∼[_]_; empty-unique; drop-cons; commutativeMonoid) import Data.List.Properties as Lₚ open import Data.Product using (_,_; _×_; ∃; ∃₂) open import Function using (_∘_) open import Function.Equality using (_⟨$⟩_) open import Function.Inverse as Inv using (inverse) open import Relation.Unary using (Pred) open import Relation.Binary open import Relation.Binary.PropositionalEquality as ≡ using (_≡_ ; refl ; cong; cong₂; _≢_; inspect) open PermutationReasoning ------------------------------------------------------------------------ -- sym module _ {a} {A : Set a} where ↭-sym-involutive : ∀ {xs ys : List A} (p : xs ↭ ys) → ↭-sym (↭-sym p) ≡ p ↭-sym-involutive refl = refl ↭-sym-involutive (prep x ↭) = cong (prep x) (↭-sym-involutive ↭) ↭-sym-involutive (swap x y ↭) = cong (swap x y) (↭-sym-involutive ↭) ↭-sym-involutive (trans ↭₁ ↭₂) = cong₂ trans (↭-sym-involutive ↭₁) (↭-sym-involutive ↭₂) ------------------------------------------------------------------------ -- Relationships to other predicates module _ {a} {A : Set a} where All-resp-↭ : ∀ {ℓ} {P : Pred A ℓ} → (All P) Respects _↭_ All-resp-↭ refl wit = wit All-resp-↭ (prep x p) (px ∷ wit) = px ∷ All-resp-↭ p wit All-resp-↭ (swap x y p) (px ∷ py ∷ wit) = py ∷ px ∷ All-resp-↭ p wit All-resp-↭ (trans p₁ p₂) wit = All-resp-↭ p₂ (All-resp-↭ p₁ wit) Any-resp-↭ : ∀ {ℓ} {P : Pred A ℓ} → (Any P) Respects _↭_ Any-resp-↭ refl wit = wit Any-resp-↭ (prep x p) (here px) = here px Any-resp-↭ (prep x p) (there wit) = there (Any-resp-↭ p wit) Any-resp-↭ (swap x y p) (here px) = there (here px) Any-resp-↭ (swap x y p) (there (here px)) = here px Any-resp-↭ (swap x y p) (there (there wit)) = there (there (Any-resp-↭ p wit)) Any-resp-↭ (trans p p₁) wit = Any-resp-↭ p₁ (Any-resp-↭ p wit) ∈-resp-↭ : ∀ {x : A} → (x ∈_) Respects _↭_ ∈-resp-↭ = Any-resp-↭ ------------------------------------------------------------------------ -- map module _ {a b} {A : Set a} {B : Set b} (f : A → B) where map⁺ : ∀ {xs ys} → xs ↭ ys → map f xs ↭ map f ys map⁺ refl = refl map⁺ (prep x p) = prep _ (map⁺ p) map⁺ (swap x y p) = swap _ _ (map⁺ p) map⁺ (trans p₁ p₂) = trans (map⁺ p₁) (map⁺ p₂) ------------------------------------------------------------------------ -- _++_ module _ {a} {A : Set a} where ++⁺ˡ : ∀ xs {ys zs : List A} → ys ↭ zs → xs ++ ys ↭ xs ++ zs ++⁺ˡ [] ys↭zs = ys↭zs ++⁺ˡ (x ∷ xs) ys↭zs = prep x (++⁺ˡ xs ys↭zs) ++⁺ʳ : ∀ {xs ys : List A} zs → xs ↭ ys → xs ++ zs ↭ ys ++ zs ++⁺ʳ zs refl = refl ++⁺ʳ zs (prep x ↭) = prep x (++⁺ʳ zs ↭) ++⁺ʳ zs (swap x y ↭) = swap x y (++⁺ʳ zs ↭) ++⁺ʳ zs (trans ↭₁ ↭₂) = trans (++⁺ʳ zs ↭₁) (++⁺ʳ zs ↭₂) ++⁺ : _++_ Preserves₂ _↭_ ⟶ _↭_ ⟶ _↭_ ++⁺ ws↭xs ys↭zs = trans (++⁺ʳ _ ws↭xs) (++⁺ˡ _ ys↭zs) -- Some useful lemmas zoom : ∀ h {t xs ys : List A} → xs ↭ ys → h ++ xs ++ t ↭ h ++ ys ++ t zoom h {t} = ++⁺ˡ h ∘ ++⁺ʳ t inject : ∀ (v : A) {ws xs ys zs} → ws ↭ ys → xs ↭ zs → ws ++ [ v ] ++ xs ↭ ys ++ [ v ] ++ zs inject v ws↭ys xs↭zs = trans (++⁺ˡ _ (prep v xs↭zs)) (++⁺ʳ _ ws↭ys) shift : ∀ v (xs ys : List A) → xs ++ [ v ] ++ ys ↭ v ∷ xs ++ ys shift v [] ys = refl shift v (x ∷ xs) ys = begin x ∷ (xs ++ [ v ] ++ ys) <⟨ shift v xs ys ⟩ x ∷ v ∷ xs ++ ys <<⟨ refl ⟩ v ∷ x ∷ xs ++ ys ∎ drop-mid-≡ : ∀ {x} ws xs {ys} {zs} → ws ++ [ x ] ++ ys ≡ xs ++ [ x ] ++ zs → ws ++ ys ↭ xs ++ zs drop-mid-≡ [] [] eq with cong tail eq drop-mid-≡ [] [] eq | refl = refl drop-mid-≡ [] (x ∷ xs) refl = shift _ xs _ drop-mid-≡ (w ∷ ws) [] refl = ↭-sym (shift _ ws _) drop-mid-≡ (w ∷ ws) (x ∷ xs) eq with Lₚ.∷-injective eq ... | refl , eq′ = prep w (drop-mid-≡ ws xs eq′) drop-mid : ∀ {x} ws xs {ys zs} → ws ++ [ x ] ++ ys ↭ xs ++ [ x ] ++ zs → ws ++ ys ↭ xs ++ zs drop-mid {x} ws xs p = drop-mid′ p ws xs refl refl where drop-mid′ : ∀ {l′ l″ : List A} → l′ ↭ l″ → ∀ ws xs {ys zs : List A} → ws ++ [ x ] ++ ys ≡ l′ → xs ++ [ x ] ++ zs ≡ l″ → ws ++ ys ↭ xs ++ zs drop-mid′ refl ws xs refl eq = drop-mid-≡ ws xs (≡.sym eq) drop-mid′ (prep x p) [] [] refl eq with cong tail eq drop-mid′ (prep x p) [] [] refl eq | refl = p drop-mid′ (prep x p) [] (x ∷ xs) refl refl = trans p (shift _ _ _) drop-mid′ (prep x p) (w ∷ ws) [] refl refl = trans (↭-sym (shift _ _ _)) p drop-mid′ (prep x p) (w ∷ ws) (x ∷ xs) refl refl = prep _ (drop-mid′ p ws xs refl refl) drop-mid′ (swap y z p) [] [] refl refl = prep _ p drop-mid′ (swap y z p) [] (x ∷ []) refl eq with cong {B = List _} (λ { (x ∷ _ ∷ xs) → x ∷ xs ; _ → [] }) eq drop-mid′ (swap y z p) [] (x ∷ []) refl eq | refl = prep _ p drop-mid′ (swap y z p) [] (x ∷ _ ∷ xs) refl refl = prep _ (trans p (shift _ _ _)) drop-mid′ (swap y z p) (w ∷ []) [] refl eq with cong tail eq drop-mid′ (swap y z p) (w ∷ []) [] refl eq | refl = prep _ p drop-mid′ (swap y z p) (w ∷ x ∷ ws) [] refl refl = prep _ (trans (↭-sym (shift _ _ _)) p) drop-mid′ (swap y y p) (y ∷ []) (y ∷ []) refl refl = prep _ p drop-mid′ (swap y z p) (y ∷ []) (z ∷ y ∷ xs) refl refl = begin _ ∷ _ <⟨ p ⟩ _ ∷ (xs ++ _ ∷ _) <⟨ shift _ _ _ ⟩ _ ∷ _ ∷ xs ++ _ <<⟨ refl ⟩ _ ∷ _ ∷ xs ++ _ ∎ drop-mid′ (swap y z p) (y ∷ z ∷ ws) (z ∷ []) refl refl = begin _ ∷ _ ∷ ws ++ _ <<⟨ refl ⟩ _ ∷ (_ ∷ ws ++ _) <⟨ ↭-sym (shift _ _ _) ⟩ _ ∷ (ws ++ _ ∷ _) <⟨ p ⟩ _ ∷ _ ∎ drop-mid′ (swap y z p) (y ∷ z ∷ ws) (z ∷ y ∷ xs) refl refl = swap y z (drop-mid′ p _ _ refl refl) drop-mid′ (trans p₁ p₂) ws xs refl refl with ∈-∃++ (∈-resp-↭ p₁ (∈-insert ws)) ... | (h , t , refl) = trans (drop-mid′ p₁ ws h refl refl) (drop-mid′ p₂ h xs refl refl) -- Algebraic properties ++-identityˡ : LeftIdentity {A = List A} _↭_ [] _++_ ++-identityˡ xs = refl ++-identityʳ : RightIdentity {A = List A} _↭_ [] _++_ ++-identityʳ xs = ↭-reflexive (Lₚ.++-identityʳ xs) ++-identity : Identity {A = List A} _↭_ [] _++_ ++-identity = ++-identityˡ , ++-identityʳ ++-assoc : Associative {A = List A} _↭_ _++_ ++-assoc xs ys zs = ↭-reflexive (Lₚ.++-assoc xs ys zs) ++-comm : Commutative _↭_ _++_ ++-comm [] ys = ↭-sym (++-identityʳ ys) ++-comm (x ∷ xs) ys = begin x ∷ xs ++ ys ↭⟨ prep x (++-comm xs ys) ⟩ x ∷ ys ++ xs ≡⟨ cong (λ v → x ∷ v ++ xs) (≡.sym (Lₚ.++-identityʳ _)) ⟩ (x ∷ ys ++ []) ++ xs ↭⟨ ++⁺ʳ xs (↭-sym (shift x ys [])) ⟩ (ys ++ [ x ]) ++ xs ↭⟨ ++-assoc ys [ x ] xs ⟩ ys ++ ([ x ] ++ xs) ≡⟨⟩ ys ++ (x ∷ xs) ∎ ++-isMagma : IsMagma _↭_ _++_ ++-isMagma = record { isEquivalence = ↭-isEquivalence ; ∙-cong = ++⁺ } ++-magma : Magma _ _ ++-magma = record { isMagma = ++-isMagma } ++-isSemigroup : IsSemigroup _↭_ _++_ ++-isSemigroup = record { isMagma = ++-isMagma ; assoc = ++-assoc } ++-semigroup : Semigroup a _ ++-semigroup = record { isSemigroup = ++-isSemigroup } ++-isMonoid : IsMonoid _↭_ _++_ [] ++-isMonoid = record { isSemigroup = ++-isSemigroup ; identity = ++-identity } ++-monoid : Monoid a _ ++-monoid = record { isMonoid = ++-isMonoid } ++-isCommutativeMonoid : IsCommutativeMonoid _↭_ _++_ [] ++-isCommutativeMonoid = record { isSemigroup = ++-isSemigroup ; identityˡ = ++-identityˡ ; comm = ++-comm } ++-commutativeMonoid : CommutativeMonoid _ _ ++-commutativeMonoid = record { isCommutativeMonoid = ++-isCommutativeMonoid } ------------------------------------------------------------------------ -- _∷_ module _ {a} {A : Set a} where drop-∷ : ∀ {x : A} {xs ys} → x ∷ xs ↭ x ∷ ys → xs ↭ ys drop-∷ = drop-mid [] [] ------------------------------------------------------------------------ -- _∷ʳ_ module _ {a} {A : Set a} where ∷↭∷ʳ : ∀ (x : A) xs → x ∷ xs ↭ xs ∷ʳ x ∷↭∷ʳ x xs = ↭-sym (begin xs ++ [ x ] ↭⟨ shift x xs [] ⟩ x ∷ xs ++ [] ≡⟨ Lₚ.++-identityʳ _ ⟩ x ∷ xs ∎) ------------------------------------------------------------------------ -- Relationships to other relations module _ {a} {A : Set a} where ↭⇒∼bag : _↭_ ⇒ _∼[ bag ]_ ↭⇒∼bag xs↭ys {v} = inverse (to xs↭ys) (from xs↭ys) (from∘to xs↭ys) (to∘from xs↭ys) where to : ∀ {xs ys} → xs ↭ ys → v ∈ xs → v ∈ ys to xs↭ys = Any-resp-↭ {A = A} xs↭ys from : ∀ {xs ys} → xs ↭ ys → v ∈ ys → v ∈ xs from xs↭ys = Any-resp-↭ (↭-sym xs↭ys) from∘to : ∀ {xs ys} (p : xs ↭ ys) (q : v ∈ xs) → from p (to p q) ≡ q from∘to refl v∈xs = refl from∘to (prep _ _) (here refl) = refl from∘to (prep _ p) (there v∈xs) = cong there (from∘to p v∈xs) from∘to (swap x y p) (here refl) = refl from∘to (swap x y p) (there (here refl)) = refl from∘to (swap x y p) (there (there v∈xs)) = cong (there ∘ there) (from∘to p v∈xs) from∘to (trans p₁ p₂) v∈xs rewrite from∘to p₂ (Any-resp-↭ p₁ v∈xs) | from∘to p₁ v∈xs = refl to∘from : ∀ {xs ys} (p : xs ↭ ys) (q : v ∈ ys) → to p (from p q) ≡ q to∘from p with from∘to (↭-sym p) ... | res rewrite ↭-sym-involutive p = res ∼bag⇒↭ : _∼[ bag ]_ ⇒ _↭_ ∼bag⇒↭ {[]} eq with empty-unique (Inv.sym eq) ... | refl = refl ∼bag⇒↭ {x ∷ xs} eq with ∈-∃++ (to ⟨$⟩ (here ≡.refl)) where open Inv.Inverse (eq {x}) ... | zs₁ , zs₂ , p rewrite p = begin x ∷ xs <⟨ ∼bag⇒↭ (drop-cons (Inv._∘_ (comm zs₁ (x ∷ zs₂)) eq)) ⟩ x ∷ (zs₂ ++ zs₁) <⟨ ++-comm zs₂ zs₁ ⟩ x ∷ (zs₁ ++ zs₂) ↭˘⟨ shift x zs₁ zs₂ ⟩ zs₁ ++ x ∷ zs₂ ∎ where open CommutativeMonoid (commutativeMonoid bag A) ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 1.0 ↭⇒~bag = ↭⇒∼bag {-# WARNING_ON_USAGE ↭⇒~bag "Warning: ↭⇒~bag was deprecated in v1.0. Please use ? instead (now typed with '\\sim' rather than '~')." #-} ~bag⇒↭ = ∼bag⇒↭ {-# WARNING_ON_USAGE ~bag⇒↭ "Warning: ~bag⇒↭ was deprecated in v1.0. Please use ? instead (now typed with '\\sim' rather than '~')." #-}
37.772152
103
0.447218
4ddac737aec630a83d53fb5acac802846eb1ae2d
801
agda
Agda
examples/lib/Data/Map.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/lib/Data/Map.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/lib/Data/Map.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Data.Map (Key : Set) where import Data.Bool import Data.Maybe open Data.Bool infix 40 _<_ _>_ postulate _<_ : Key -> Key -> Bool _>_ : Key -> Key -> Bool x > y = y < x private data Map' (a : Set) : Set where leaf : Map' a node : Key -> a -> Map' a -> Map' a -> Map' a Map : Set -> Set Map = Map' empty : {a : Set} -> Map a empty = leaf {- insert : {a : Set} -> Key -> a -> Map a -> Map a insert k v leaf = node k v leaf leaf insert k v (node k' v' l r) = | k < k' => node k' v' (insert k v l) r | k > k' => node k' v' l (insert k v r) | otherwise node k' v l r -} open Data.Maybe {- lookup : {a : Set} -> Key -> Map a -> Maybe a lookup k leaf = nothing lookup k (node k' v l r) = | k < k' => lookup k l | k > k' => lookup k r | otherwise just v -}
16.346939
49
0.529338
20fa279544a0ad975feee3bde09d92e63ca85f05
1,122
agda
Agda
test/Fail/ConfluenceTypeLevelReduction.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/ConfluenceTypeLevelReduction.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/ConfluenceTypeLevelReduction.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Jesper, 2019-05-20: When checking confluence of two rewrite rules, -- we disable all reductions during unification of the left-hand -- sides. However, we should not disable reductions at the type-level, -- as shown by this (non-confluent) example. {-# OPTIONS --rewriting --confluence-check #-} open import Agda.Builtin.Unit open import Agda.Builtin.Bool open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite data Unit : Set where unit : Unit A : Unit → Set A unit = ⊤ postulate a b : (u : Unit) → A u f : (u : Unit) → A u → Bool f-a : (u : Unit) → f u (a u) ≡ true f-b : (u : Unit) → f u (b u) ≡ false {-# REWRITE f-a #-} {-# REWRITE f-b #-} cong-f : (u : Unit) (x y : A u) → x ≡ y → f u x ≡ f u y cong-f u x y refl = refl boom : true ≡ false boom = cong-f unit (a unit) (b unit) refl -- Jesper, 2020-01-21: With the fix of #4382, the definition of boom -- no longer typechecks even without --confluence-check. However, we -- can leave the test case as is: the expected behaviour is now that -- Agda reports *both* the confluence issue and the type error in the -- body of boom.
29.526316
70
0.666667
39b954bb8596d00d37af8282d318962ef7498f20
2,223
agda
Agda
notes/FOT/FOTC/Data/Nat/Stream/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/FOTC/Data/Nat/Stream/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/FOTC/Data/Nat/Stream/Type.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- The FOTC streams of total natural numbers type ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- N.B. This module is re-exported by FOTC.Data.Stream. module FOT.FOTC.Data.Nat.Stream.Type where open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.Nat.Type ------------------------------------------------------------------------------ -- The FOTC streams type (co-inductive predicate for total streams). -- Functional for the StreamN predicate. -- StreamNF : (D → Set) → D → Set -- StreamNF P ns = ∃[ n' ] ∃[ ns' ] N n' ∧ P ns' ∧ ns ≡ n' ∷ ns' -- Stream is the greatest fixed-point of StreamF (by Stream-out and -- Stream-coind). postulate StreamN : D → Set postulate -- StreamN is a post-fixed point of StreamNF, i.e. -- -- StreamN ≤ StreamNF StreamN. StreamN-out : ∀ {ns} → StreamN ns → ∃[ n' ] ∃[ ns' ] N n' ∧ StreamN ns' ∧ ns ≡ n' ∷ ns' {-# ATP axiom StreamN-out #-} -- StreamN is the greatest post-fixed point of StreamNF, i.e. -- -- ∀ P. P ≤ StreamNF P ⇒ P ≤ StreamN. -- -- N.B. This is an axiom schema. Because in the automatic proofs we -- *must* use an instance, we do not add this postulate as an ATP -- axiom. postulate StreamN-coind : ∀ (A : D → Set) {ns} → -- A is post-fixed point of StreamNF. (A ns → ∃[ n' ] ∃[ ns' ] N n' ∧ A ns' ∧ ns ≡ n' ∷ ns') → -- StreamN is greater than A. A ns → StreamN ns -- Because a greatest post-fixed point is a fixed-point, then the -- StreamN predicate is also a pre-fixed point of the functional -- StreamNF, i.e. -- -- StreamNF StreamN ≤ StreamN. StreamN-in : ∀ {ns} → ∃[ n' ] ∃[ ns' ] N n' ∧ StreamN ns' ∧ ns ≡ n' ∷ ns' → StreamN ns StreamN-in {ns} h = StreamN-coind A h' h where A : D → Set A ns = ∃[ n' ] ∃[ ns' ] N n' ∧ StreamN ns' ∧ ns ≡ n' ∷ ns' h' : A ns → ∃[ n' ] ∃[ ns' ] N n' ∧ A ns' ∧ ns ≡ n' ∷ ns' h' (_ , _ , Nn' , SNns' , prf) = _ , _ , Nn' , (StreamN-out SNns') , prf
32.691176
78
0.51462
12239f09f96de1b60a90f647e68fb7aa8a5eb00d
3,482
agda
Agda
LibraBFT/Abstract/Records/Extends.agda
lisandrasilva/bft-consensus-agda-1
b7dd98dd90d98fbb934ef8cb4f3314940986790d
[ "UPL-1.0" ]
null
null
null
LibraBFT/Abstract/Records/Extends.agda
lisandrasilva/bft-consensus-agda-1
b7dd98dd90d98fbb934ef8cb4f3314940986790d
[ "UPL-1.0" ]
null
null
null
LibraBFT/Abstract/Records/Extends.agda
lisandrasilva/bft-consensus-agda-1
b7dd98dd90d98fbb934ef8cb4f3314940986790d
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020 Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Abstract.Types module LibraBFT.Abstract.Records.Extends (𝓔 : EpochConfig) (UID : Set) (_≟UID_ : (u₀ u₁ : UID) → Dec (u₀ ≡ u₁)) (𝓥 : VoteEvidence 𝓔 UID) where open import LibraBFT.Abstract.Records 𝓔 UID _≟UID_ 𝓥 -- Most of the conditions in section 4.2 of the paper (see -- LibraBFT.Abstract.RecordChain.Properties) would be checked -- by the implementation to validate data received. -- -- In the Abstract model, however, we are only concerned with -- proving the properties; only round numbers and identifiers -- for previous records are actually critical to thm S5! data _←_ : Record → Record → Set where I←B : {b : Block} → 0 < getRound b → bPrevQC b ≡ nothing → I ← B b Q←B : {q : QC} {b : Block} → getRound q < getRound b → just (qCertBlockId q) ≡ bPrevQC b → Q q ← B b B←Q : {b : Block} {q : QC} → getRound q ≡ getRound b → bId b ≡ qCertBlockId q → B b ← Q q -- Equivalent records extend equivalent records (modulo injectivity -- failure of bId). ←-≈Rec : ∀{r₀ r₁ s₀ s₁} → s₀ ← r₀ → s₁ ← r₁ → r₀ ≈Rec r₁ → NonInjective-≡ bId ⊎ (s₀ ≈Rec s₁) ←-≈Rec (I←B x x₁) (I←B x₂ x₃) hyp = inj₂ eq-I ←-≈Rec (I←B x x₁) (Q←B x₂ x₃) (eq-B refl) = ⊥-elim (maybe-⊥ (sym x₃) x₁) ←-≈Rec (Q←B x x₁) (I←B x₂ x₃) (eq-B refl) = ⊥-elim (maybe-⊥ (sym x₁) x₃) ←-≈Rec (Q←B {q₀} x refl) (Q←B {q₁} x₂ refl) (eq-B refl) = inj₂ (eq-Q refl) -- Here is where we wouldn't be able to -- complete the proof if we required round equality -- in eq-Q ←-≈Rec (B←Q {b₀} x refl) (B←Q {b₁} w refl) (eq-Q refl) with b₀ ≟Block b₁ ...| no hb = inj₁ ((b₀ , b₁) , (λ x → hb x) , refl) ...| yes prf = inj₂ (eq-B prf) ←-irrelevant : Irrelevant _←_ ←-irrelevant (I←B r₁ h₁) (I←B r₂ h₂) = cong₂ I←B (≤-irrelevant r₁ r₂) (≡-irrelevant h₁ h₂) ←-irrelevant (Q←B r₁ h₁) (Q←B r₂ h₂) = cong₂ Q←B (≤-irrelevant r₁ r₂) (≡-irrelevant h₁ h₂) ←-irrelevant (B←Q r₁ h₁) (B←Q r₂ h₂) = cong₂ B←Q (≡-irrelevant r₁ r₂) (≡-irrelevant h₁ h₂) ←-round-≤ : ∀{r₀ r₁} → r₀ ← r₁ → round r₀ ≤ round r₁ ←-round-≤ (I←B r h) = z≤n ←-round-≤ (Q←B r h) = <⇒≤ r ←-round-≤ (B←Q refl h) = ≤-refl ←←-round-< : ∀{r r₀ r₁} → r ← r₀ → r₀ ← r₁ → round r < round r₁ ←←-round-< (I←B r h) (B←Q refl _) = r ←←-round-< (Q←B r h) rr = ≤-trans r (←-round-≤ rr) ←←-round-< (B←Q refl h) (Q←B prf _) = prf -- LemmaS1, clause 2: injectivity of _←_ lemmaS1-2 : ∀{r₀ r₁ r₂ r₂'} → r₂ ≈Rec r₂' → r₀ ← r₂ → r₁ ← r₂' → uid r₀ ≡ uid r₁ lemmaS1-2 {i₀} {i₁} {b} hyp (I←B _ i₀←b) (I←B _ i₁←b) = refl lemmaS1-2 {q} {i} {b} (eq-B refl) (Q←B _ ()) (I←B _ refl) lemmaS1-2 {i} {q} {b} (eq-B refl) (I←B _ refl) (Q←B _ ()) lemmaS1-2 {q₀} {q₁} {b} (eq-B refl) (Q←B _ refl) (Q←B _ refl) = refl lemmaS1-2 {b₀} {b₁} {q} (eq-Q refl) (B←Q _ refl) (B←Q _ refl) = refl -- A better name for lemmaS1-2 ←-inj : ∀{r₀ r₁ r₂} → r₀ ← r₂ → r₁ ← r₂ → uid r₀ ≡ uid r₁ ←-inj = lemmaS1-2 ≈Rec-refl
37.042553
111
0.547387
fb53e6b1ed800c67030c32e89eed3f2a1ffc6fae
1,712
agda
Agda
src/Tactic/Deriving.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Tactic/Deriving.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Tactic/Deriving.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Tactic.Deriving where open import Prelude hiding (abs) open import Tactic.Reflection private makeArgs : Nat → List (Arg Nat) → List (Arg Term) makeArgs n xs = reverse $ map (fmap (λ i → var (n - i - 1) [])) xs computeInstanceType : Name → Nat → List (Arg Nat) → Type → Maybe Term computeInstanceType class n xs (agda-sort _) = just (def class (vArg (var n (makeArgs n xs)) ∷ [])) computeInstanceType class n xs (pi a (abs s b)) = pi (hArg (unArg a)) ∘ abs s <$> computeInstanceType class (suc n) ((n <$ a) ∷ xs) b computeInstanceType _ _ _ _ = nothing computeTel : Name → Nat → List (Arg Nat) → Telescope → Telescope → Telescope × List (Arg Term) computeTel d n xs is [] = reverse is , makeArgs (n + length is) xs computeTel d n xs is ((x , a) ∷ tel) = first ((x , hArg (unArg a)) ∷_) $ case computeInstanceType d 0 [] (weaken 1 $ unArg a) of λ { (just i) → computeTel d (1 + n) ((n <$ a) ∷ xs) ((x , iArg (weaken (length is) i)) ∷ weaken 1 is) tel ; nothing → computeTel d (1 + n) ((n <$ a) ∷ xs) (weaken 1 is) tel } -- Computes the telescope of instances for a given datatype and class. For instance, -- instanceTelescope (quote Vec) (quote Eq) computes to -- {a : Level} {A : Set a} {{_ : Eq A}} {n : Nat} , 3 ∷ 2 ∷ 0 ∷ [] instanceTelescope : Name → Name → TC (Telescope × List (Arg Term)) instanceTelescope d class = computeTel class 0 [] [] <$> (fst ∘ telView <$> getType d) -- Compute the type of an instance declaration for an arbitrary datatype and class. instanceType : Name → Name → TC Type instanceType d class = caseM instanceTelescope d class of λ { (tel , vs) → pure $ telPi tel $ def₁ class (def d vs) }
43.897436
96
0.623832
0b8eefb1994c4c1f4f4f1f05537ede7aa840bd77
1,207
agda
Agda
test/bugs/SizedTypesMergeSort.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/bugs/SizedTypesMergeSort.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/bugs/SizedTypesMergeSort.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --sized-types #-} module SizedTypesMergeSort where postulate Size : Set _^ : Size -> Size ∞ : Size {-# BUILTIN SIZE Size #-} {-# BUILTIN SIZESUC _^ #-} {-# BUILTIN SIZEINF ∞ #-} -- sized lists data List (A : Set) : {_ : Size} -> Set where [] : {size : Size} -> List A {size ^} _::_ : {size : Size} -> A -> List A {size} -> List A {size ^} -- CPS split split : {A : Set}{i : Size} -> List A {i} -> {C : Set} -> (List A {i} -> List A {i} -> C) -> C split [] k = k [] [] split (x :: xs) k = split xs (\ l r -> k (x :: r) l) module Sort (A : Set) (compare : A -> A -> {B : Set} -> B -> B -> B) where {- merge is currently rejected by the termination checker it would be nice if it worked see test/succeed/SizedTypesMergeSort.agda -} merge : List A -> List A -> List A merge [] ys = ys merge xs [] = xs merge (x :: xs) (y :: ys) = compare x y (x :: merge xs (y :: ys)) (y :: merge (x :: xs) ys) sort : {i : Size} -> List A {i} -> List A sort [] = [] sort (x :: []) = x :: [] sort (x :: (y :: xs)) = split xs (\ l r -> merge (sort (x :: l)) (sort (y :: r)))
26.23913
74
0.465617
4d99231a09ca9b1ac7cca718167da4f36010ede5
221
agda
Agda
test/Fail/Issue1209-5.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1209-5.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1209-5.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --safe --no-guardedness #-} record Stream (A : Set) : Set where coinductive field head : A tail : Stream A open Stream repeat : ∀ {A} → A → Stream A repeat x .head = x repeat x .tail = repeat x
15.785714
39
0.61086
cb3ccc6f31fe3c87a89ce2d1d03530443564a2aa
10,330
agda
Agda
Structure/Operator/SetAlgebra.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Structure/Operator/SetAlgebra.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Structure/Operator/SetAlgebra.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
open import Type module Structure.Operator.SetAlgebra {ℓ} (S : Type{ℓ}) where import Lvl open import Functional open import Logic open import Logic.Propositional open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Operator.Properties open import Structure.Operator.Proofs open import Structure.Relator.Properties open import Syntax.Transitivity record Fundamentals : Stmt{ℓ} where infixl 1001 _∩_ infixl 1000 _∪_ field _∪_ : S → S → S -- Union _∩_ : S → S → S -- Intersection ∅ : S -- Empty set 𝐔 : S -- Universal set field -- TODO: This is two commutative monoids with distributivity over each other ⦃ [∪]-commutativity ⦄ : Commutativity(_∪_) ⦃ [∩]-commutativity ⦄ : Commutativity(_∩_) ⦃ [∪]-associativity ⦄ : Associativity(_∪_) ⦃ [∩]-associativity ⦄ : Associativity(_∩_) ⦃ [∪][∩]-distributivityₗ ⦄ : Distributivityₗ(_∪_)(_∩_) ⦃ [∩][∪]-distributivityₗ ⦄ : Distributivityₗ(_∩_)(_∪_) ⦃ [∪]-identityₗ ⦄ : Identityₗ(_∪_)(∅) ⦃ [∩]-identityₗ ⦄ : Identityₗ(_∩_)(𝐔) instance [∪][∩]-distributivityᵣ : Distributivityᵣ(_∪_)(_∩_) [∪][∩]-distributivityᵣ = [↔]-to-[→] OneTypeTwoOp.distributivity-equivalence-by-commutativity [∪][∩]-distributivityₗ instance [∩][∪]-distributivityᵣ : Distributivityᵣ(_∩_)(_∪_) [∩][∪]-distributivityᵣ = [↔]-to-[→] OneTypeTwoOp.distributivity-equivalence-by-commutativity [∩][∪]-distributivityₗ instance [∪]-identityᵣ : Identityᵣ(_∪_)(∅) [∪]-identityᵣ = [↔]-to-[→] One.identity-equivalence-by-commutativity [∪]-identityₗ instance [∩]-identityᵣ : Identityᵣ(_∩_)(𝐔) [∩]-identityᵣ = [↔]-to-[→] One.identity-equivalence-by-commutativity [∩]-identityₗ record Complement : Stmt{ℓ} where infixl 1002 ∁_ infixl 1000 _∖_ field ∁_ : S → S -- Complement field ⦃ fundamentals ⦄ : Fundamentals open Fundamentals(fundamentals) field -- TODO: Not really inverses. These are using the absorbers [∪]-inverseᵣ : ∀{s : S} → (s ∪ ∁(s) ≡ 𝐔) [∩]-inverseᵣ : ∀{s : S} → (s ∩ ∁(s) ≡ ∅) _∖_ : S → S → S -- Difference _∖_ (s₁)(s₂) = s₁ ∩ ∁(s₂) [∪]-inverseₗ : ∀{s : S} → (∁(s) ∪ s ≡ 𝐔) [∪]-inverseₗ = transitivity(_≡_) (commutativity(_∪_)) [∪]-inverseᵣ [∩]-inverseₗ : ∀{s : S} → (∁(s) ∩ s ≡ ∅) [∩]-inverseₗ = transitivity(_≡_) (commutativity(_∩_)) [∩]-inverseᵣ [∁]-of-[∅] : (∁(∅) ≡ 𝐔) [∁]-of-[∅] = symmetry(_≡_) (identityₗ(_∪_)(∅)) 🝖 ([∪]-inverseᵣ) [∁]-of-[𝐔] : (∁(𝐔) ≡ ∅) [∁]-of-[𝐔] = symmetry(_≡_) (identityₗ(_∩_)(𝐔)) 🝖 ([∩]-inverseᵣ) [∪]-idempotence : ∀{s : S} → (s ∪ s) ≡ s [∪]-idempotence{s} = ([≡]-intro) 🝖 (symmetry(_≡_) (identityᵣ(_∩_)(𝐔))) 🝖 ([≡]-with(expr ↦ ((s ∪ s) ∩ expr)) (symmetry(_≡_) [∪]-inverseᵣ)) 🝖 (symmetry(_≡_) (distributivityₗ(_∪_)(_∩_))) 🝖 ([≡]-with(expr ↦ (s ∪ expr)) [∩]-inverseᵣ) 🝖 ((identityᵣ(_∪_)(∅))) [∩]-idempotence : ∀{s : S} → (s ∩ s) ≡ s [∩]-idempotence{s} = ([≡]-intro) 🝖 (symmetry(_≡_) (identityᵣ(_∪_)(∅))) 🝖 ([≡]-with(expr ↦ ((s ∩ s) ∪ expr)) (symmetry(_≡_) [∩]-inverseᵣ)) 🝖 (symmetry(_≡_) (distributivityₗ(_∩_)(_∪_))) 🝖 ([≡]-with(expr ↦ (s ∩ expr)) [∪]-inverseᵣ) 🝖 ((identityᵣ(_∩_)(𝐔))) [∪]-absorber : ∀{s : S} → (s ∪ 𝐔) ≡ 𝐔 [∪]-absorber{s} = ([≡]-with(expr ↦ s ∪ expr) (symmetry(_≡_) [∪]-inverseᵣ)) 🝖 (symmetry(_≡_) (associativity(_∪_))) 🝖 ([≡]-with(expr ↦ expr ∪ ∁(s)) [∪]-idempotence) 🝖 ([∪]-inverseᵣ) -- s∪𝐔 = s∪(s ∪ ∁(s)) = (s∪s) ∪ ∁(s) = s ∪ ∁(s) = 𝐔 [∩]-absorber : ∀{s : S} → (s ∩ ∅) ≡ ∅ [∩]-absorber{s} = ([≡]-with(expr ↦ s ∩ expr) (symmetry(_≡_) [∩]-inverseᵣ)) 🝖 (symmetry(_≡_) (associativity(_∩_))) 🝖 ([≡]-with(expr ↦ expr ∩ ∁(s)) [∩]-idempotence) 🝖 ([∩]-inverseᵣ) -- s∩∅ = s∩(s ∩ ∁(s)) = (s∩s) ∩ ∁(s) = s ∩ ∁(s) = ∅ -- postulate [∪]-absorptionₗ : ∀{s₁ s₂ : S} → (s₁ ∪ (s₁ ∩ s₂)) ≡ s₁ -- s₁∪(s₁∩s₂) -- = (s₁∪s₁)∩(s₁∪s₂) -- = s₁∩(s₁∪s₂) -- = (s₁∩s₁) ∪ (s₁∩s₂) -- = s₁ ∪ (s₁∩s₂) -- = ? -- postulate [∩]-absorptionₗ : ∀{s₁ s₂ : S} → (s₁ ∩ (s₁ ∪ s₂)) ≡ s₁ -- ∁(s₁) ∪ ∁(s₁ ∪ s₂) = ∁(s₁) -- ∁(s₁) ∩ ∁(s₁ ∪ s₂) = ∁(s₁ ∪ s₂) -- ∁(s₁) ∪ ∁(s₁ ∩ s₂) = ∁(s₁ ∩ s₂) -- ∁(s₁) ∩ ∁(s₁ ∩ s₂) = ∁(s₁) -- postulate a : ∀{a} → a -- postulate [∁]-of-[∪] : ∀{s₁ s₂ : S} → ∁(s₁ ∪ s₂) ≡ ∁(s₁) ∩ ∁(s₂) -- [∁]-of-[∪] = -- ((∁(s₁) ∩ ∁(s₂)) ∪ (s₁ ∪ s₂)) = 𝐔 ? -- (s₁ ∪ s₂) ∪ ∁(s₁ ∪ s₂) = 𝐔 -- ∁(s₂) ∩ ((s₁ ∪ s₂) ∪ ∁(s₁ ∪ s₂)) = ∁(s₁) ∩ 𝐔 -- (∁(s₂) ∩ (s₁ ∪ s₂)) ∪ (∁(s₁) ∩ ∁(s₁ ∪ s₂)) = ∁(s₂) ∩ 𝐔 -- (∁(s₂) ∩ (s₁ ∪ s₂)) ∪ (∁(s₁) ∩ ∁(s₁ ∪ s₂)) = ∁(s₂) ∩ 𝐔 -- (∁(s₂) ∩ (s₁ ∪ s₂)) ∪ (∁(s₁) ∩ ∁(s₁ ∪ s₂)) = ∁(s₂) -- ∁(s₂) = (∁(s₂) ∩ (s₁ ∪ s₂)) ∪ (∁(s₁) ∩ ∁(s₁ ∪ s₂)) -- ∁(s₂) = ((∁(s₂) ∩ s₁) ∪ (∁(s₂) ∩ s₂)) ∪ ∁(s₁ ∪ s₂) -- ∁(s₂) = ((∁(s₂) ∩ s₁) ∪ ∅) ∪ ∁(s₁ ∪ s₂) -- ∁(s₂) = (∁(s₂) ∩ s₁) ∪ ∁(s₁ ∪ s₂) -- ∁(s₁) ∩ ∁(s₂) = ∁(s₁) ∩ ((∁(s₂) ∩ s₁) ∪ ∁(s₁ ∪ s₂)) -- ∁(s₁) ∩ ∁(s₂) = (∁(s₁) ∩ (∁(s₂) ∩ s₁)) ∪ (∁(s₁) ∩ ∁(s₁ ∪ s₂)) -- ∁(s₁) ∩ ∁(s₂) = (∁(s₁) ∩ (∁(s₂) ∩ s₁)) ∪ ∁(s₁ ∪ s₂) -- ∁(s₁) ∩ ∁(s₂) = (∁(s₁) ∩ (s₁ ∩ ∁(s₂))) ∪ ∁(s₁ ∪ s₂) -- ∁(s₁) ∩ ∁(s₂) = ((∁(s₁) ∩ s₁) ∩ ∁(s₂)) ∪ ∁(s₁ ∪ s₂) -- ∁(s₁) ∩ ∁(s₂) = (∅ ∩ ∁(s₂)) ∪ ∁(s₁ ∪ s₂) -- ∁(s₁) ∩ ∁(s₂) = ∅ ∪ ∁(s₁ ∪ s₂) -- ∁(s₁) ∩ ∁(s₂) = ∁(s₁ ∪ s₂) -- postulate proof1 : ∀{a b c d} → (a ∩ b) ∩ (c ∪ d) ≡ (a ∩ (b ∩ d)) ∪ (b ∩ (a ∩ c)) -- (a ∩ b) ∩ (c ∪ d) -- = ((a ∩ b) ∩ c) ∪ ((a ∩ b) ∩ d) -- = ((b ∩ a) ∩ c) ∪ ((a ∩ b) ∩ d) -- = (b ∩ (a ∩ c)) ∪ ((a ∩ b) ∩ d) -- = (b ∩ (a ∩ c)) ∪ (a ∩ (b ∩ d)) -- = (a ∩ (b ∩ d)) ∪ (b ∩ (a ∩ c)) -- postulate proof2 : ∀{a b} → (a ∩ b) ∩ (∁(a) ∪ ∁(b)) ≡ ∅ -- (a ∩ b) ∩ (∁(a) ∪ ∁(b)) -- = (a ∩ (b ∩ ∁(b))) ∪ (b ∩ (a ∩ ∁(a))) -- = (a ∩ ∅) ∪ (b ∩ (a ∩ ∁(a))) -- = ∅ ∪ (b ∩ (a ∩ ∁(a))) -- = b ∩ (a ∩ ∁(a)) -- = b ∩ ∅ -- = ∅ -- ∁(s₁ ∪ s₂) ∪ (s₁ ∪ s₂) = 𝐔 -- (∁(s₁ ∪ s₂) ∪ (s₁ ∪ s₂)) ∩ (∁(a) ∪ ∁(b)) = 𝐔 ∩ (∁(a) ∪ ∁(b)) -- (∁(s₁ ∪ s₂) ∪ (s₁ ∪ s₂)) ∩ (∁(a) ∪ ∁(b)) = ∁(a) ∪ ∁(b) -- ∁(a) ∪ ∁(b) = (∁(s₁ ∪ s₂) ∪ (s₁ ∪ s₂)) ∩ (∁(a) ∪ ∁(b)) -- ∁(a) ∪ ∁(b) = (∁(s₁ ∪ s₂) ∩ (∁(a) ∪ ∁(b))) ∪ ((s₁ ∪ s₂) ∩ (∁(a) ∪ ∁(b))) -- ∁(a) ∪ ∁(b) = (∁(s₁ ∪ s₂) ∩ (∁(a) ∪ ∁(b))) ∪ ∅ -- ∁(a) ∪ ∁(b) = ∁(s₁ ∪ s₂) ∩ (∁(a) ∪ ∁(b)) postulate [∁]-of-[∩] : ∀{s₁ s₂ : S} → ∁(s₁ ∩ s₂) ≡ ∁(s₁) ∪ ∁(s₂) [∁∁]-elim : ∀{s : S} → ∁(∁(s)) ≡ s [∁∁]-elim {s} = transitivity(_≡_) proof2 (symmetry(_≡_) proof1) where proof1 : s ≡ s ∪ ∁(∁(s)) proof1 = [∩]-inverseᵣ {∁(s)} ⩺ [≡]-with(s ∪_) ⩺ (eq ↦ transitivity(_≡_) eq ((identityᵣ(_∪_)(∅)) {s})) ⩺ symmetry(_≡_) ⩺ (eq ↦ transitivity(_≡_) eq ((distributivityₗ(_∪_)(_∩_)))) ⩺ (eq ↦ transitivity(_≡_) eq ([≡]-with(_∩ (s ∪ ∁(∁(s)))) ([∪]-inverseᵣ))) ⩺ (eq ↦ transitivity(_≡_) eq (identityₗ(_∩_)(𝐔))) -- ∁(s) ∩ ∁(∁(s)) ≡ ∅ -- s ∪ (∁(s) ∩ ∁(∁(s))) ≡ s ∪ ∅ -- s ∪ (∁(s) ∩ ∁(∁(s))) ≡ s -- s ≡ s ∪ (∁(s) ∩ ∁(∁(s))) -- s ≡ (s ∪ ∁(s)) ∩ (s ∪ ∁(∁(s))) -- s ≡ 𝐔 ∩ (s ∪ ∁(∁(s))) -- s ≡ s ∪ ∁(∁(s)) proof2 : ∁(∁(s)) ≡ s ∪ ∁(∁(s)) proof2 = [∩]-inverseᵣ {s} ⩺ [≡]-with(_∪ ∁(∁(s))) ⩺ (eq ↦ transitivity(_≡_) eq (identityₗ(_∪_)(∅))) ⩺ symmetry(_≡_) ⩺ (eq ↦ transitivity(_≡_) eq ((distributivityᵣ(_∪_)(_∩_)))) ⩺ (eq ↦ transitivity(_≡_) eq ([≡]-with((s ∪ ∁(∁(s))) ∩_) ([∪]-inverseᵣ))) ⩺ (eq ↦ transitivity(_≡_) eq ((identityᵣ(_∩_)(𝐔)))) -- (s ∩ ∁(s)) ∪ ∁(∁(s)) ≡ ∅ ∪ ∁(∁(s)) -- (s ∩ ∁(s)) ∪ ∁(∁(s)) ≡ ∁(∁(s)) -- ∁(∁(s)) ≡ (s ∩ ∁(s)) ∪ ∁(∁(s)) -- ∁(∁(s)) ≡ (s ∪ ∁(∁(s))) ∩ (∁(s) ∪ ∁(∁(s))) -- ∁(∁(s)) ≡ (s ∪ ∁(∁(s))) ∩ 𝐔 -- ∁(∁(s)) ≡ s ∪ ∁(∁(s)) postulate [∁]-uniqueness : ∀{s₁ s₂ : S} → (s₁ ∪ s₂ ≡ 𝐔) → (s₁ ∩ s₂ ≡ ∅) → (s₁ ≡ ∁(s₂)) postulate [∁]-of-[∖] : ∀{s₁ s₂ : S} → ∁(s₁ ∖ s₂) ≡ ∁(s₁) ∪ s₂ postulate [∖]-of-[∁] : ∀{s₁ s₂ : S} → ∁(s₁) ∖ ∁(s₂) ≡ s₂ ∖ s₁ postulate [∖]-of-[∪]ᵣ : ∀{s₁ s₂ s₃ : S} → (s₁ ∖ (s₂ ∪ s₃)) ≡ (s₁ ∖ s₂)∩(s₁ ∖ s₃) postulate [∖]-of-[∩]ᵣ : ∀{s₁ s₂ s₃ : S} → (s₁ ∖ (s₂ ∩ s₃)) ≡ (s₁ ∖ s₂)∪(s₁ ∖ s₃) postulate [∖]-of-[∖]ᵣ : ∀{s₁ s₂ s₃ : S} → (s₁ ∖ (s₂ ∖ s₃)) ≡ (s₁ ∩ s₃)∪(s₁ ∖ s₂) postulate [∩]-from-[∖] : ∀{s₁ s₂ : S} → (s₁ ∖ (s₁ ∖ s₂)) ≡ (s₁ ∩ s₂) -- TODO: from [∖]-of-[∖]ᵣ postulate [∖]-self : ∀{s : S} → s ∖ s ≡ ∅ postulate [∖]-of-[∅]ₗ : ∀{s : S} → ∅ ∖ s ≡ ∅ postulate [∖]-of-[∅]ᵣ : ∀{s : S} → s ∖ ∅ ≡ s postulate [∖]-of-[𝐔]ₗ : ∀{s : S} → 𝐔 ∖ s ≡ ∁(s) postulate [∖]-of-[𝐔]ᵣ : ∀{s : S} → s ∖ 𝐔 ≡ ∅ record Subset : Type{Lvl.𝐒(ℓ)} where field _⊆_ : S → S → Stmt{ℓ} -- Subset ⦃ fundamentals ⦄ : Fundamentals open Fundamentals(fundamentals) field ⦃ [⊆]-antisymmetry ⦄ : Antisymmetry(_⊆_)(_≡_) ⦃ [⊆]-transitivity ⦄ : Transitivity(_⊆_) ⦃ [⊆]-reflexivity ⦄ : Reflexivity(_⊆_) [≡]-to-[⊆] : ∀{a b} → (a ≡ b) → (a ⊆ b) [⊆]ₗ-of-[∪] : ∀{a b c} → (a ⊆ c) → (b ⊆ c) → ((a ∪ b) ⊆ c) [⊆]ᵣ-of-[∪]ₗ : ∀{a b} → (a ⊆ (a ∪ b)) [⊆]ₗ-of-[∩]ₗ : ∀{a b} → ((a ∩ b) ⊆ a) [⊆]ᵣ-of-[∩] : ∀{a b c} → (c ⊆ a) → (c ⊆ b) → (c ⊆ (a ∩ b)) [⊆]ᵣ-of-[∪]ᵣ : ∀{a b} → (b ⊆ (a ∪ b)) [⊆]ᵣ-of-[∪]ᵣ {a}{b} = [⊆]ᵣ-of-[∪]ₗ {b}{a} 🝖 [≡]-to-[⊆] (commutativity(_∪_)) [⊆]ₗ-of-[∩]ᵣ : ∀{a b} → ((a ∩ b) ⊆ b) [⊆]ₗ-of-[∩]ᵣ {a}{b} = [≡]-to-[⊆] (commutativity(_∩_)) 🝖 [⊆]ₗ-of-[∩]ₗ {b}{a} [⊆]-min : ∀{s} → (∅ ⊆ s) [⊆]-min {s} = [⊆]ᵣ-of-[∪]ₗ {∅}{s} 🝖 [≡]-to-[⊆] (identityₗ(_∪_)(∅)) [⊆]-max : ∀{s} → (s ⊆ 𝐔) [⊆]-max {s} = [≡]-to-[⊆] (symmetry(_≡_) (identityₗ(_∩_)(𝐔))) 🝖 [⊆]ₗ-of-[∩]ₗ {𝐔}{s} [⊆][∩]-equiv : ∀{a b} → (a ⊆ b) ↔ (a ∩ b ≡ a) [⊆][∩]-equiv {a}{b} = [↔]-intro l r where l : (a ⊆ b) ← (a ∩ b ≡ a) l aba = [≡]-to-[⊆] (symmetry(_≡_) aba) 🝖 [⊆]ₗ-of-[∩]ᵣ r : (a ⊆ b) → (a ∩ b ≡ a) r ab = (antisymmetry(_⊆_)(_≡_) ([⊆]ₗ-of-[∩]ₗ) ([⊆]ᵣ-of-[∩] {a}{b}{a} (reflexivity(_⊆_)) ab) ) {- [⊆][∪]-equiv : ∀{a b} → (a ⊆ b) ↔ (a ∪ b ≡ b) [⊆][∪]-equiv {a}{b} = [↔]-intro l r where l : (a ⊆ b) ← (a ∪ b ≡ b) l aba = [≡]-to-[⊆] (symmetry(_≡_) aba) 🝖 [⊆]ᵣ-of-[∪]ᵣ r : (a ⊆ b) → (a ∪ b ≡ b) r ab = (antisymmetry ([⊆]ᵣ-of-[∪]ᵣ) ([⊆]ₗ-of-[∪] {a}{b}{a} reflexivity ab) ) -} -- [⊆][∖]-equiv : (a ⊆ b) ↔ (a ∖ b ≡ ∅) -- [⊆][∁]-equiv : (a ⊆ b) ↔ (∁(b) ⊆ ∁(a)) -- [∩][∪]-sub : (a ∩ b) ⊆ (a ∪ b)
32.898089
119
0.391481
5026f854e67cbc98f8efe7daf91c0ac41a8002d2
237
agda
Agda
test/Fail/Issue530.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue530.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue530.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue530 where data Unit : Set where unit : Unit postulate A : Set a : A k : A → Unit data P (a : A) : Unit → Set where p : P a (k a) F : (u : Unit) → P a u → Set₁ F unit _ = Set f : F (k a) p f with k a f | _ = ?
11.285714
33
0.523207
4acb132ae08755470d029049b925d94d19befb56
245
agda
Agda
agda-stdlib/travis/index.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/travis/index.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/travis/index.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
module index where -- You probably want to start with this module: import README -- For a brief presentation of every single module, head over to import Everything -- Otherwise, here is an exhaustive, stern list of all the available modules:
24.5
77
0.77551
1c817c0dc3a0bb035e5e2e233ba2dfd44361ef09
3,779
agda
Agda
src/LibraBFT/Impl/Consensus/ConsensusTypes/Block.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/ConsensusTypes/Block.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/Consensus/ConsensusTypes/Block.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types import LibraBFT.Impl.Consensus.ConsensusTypes.BlockData as BlockData import LibraBFT.Impl.Consensus.ConsensusTypes.QuorumCert as QuorumCert import LibraBFT.Impl.Types.BlockInfo as BlockInfo import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier open import LibraBFT.Impl.OBM.Crypto open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import Optics.All open import Util.Hash open import Util.PKCS open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) module LibraBFT.Impl.Consensus.ConsensusTypes.Block where genBlockInfo : Block → HashValue → Version → Maybe EpochState → BlockInfo genBlockInfo b executedStateId version nextEpochState = BlockInfo∙new (b ^∙ bEpoch) (b ^∙ bRound) (b ^∙ bId) executedStateId version nextEpochState isGenesisBlock : Block → Bool isGenesisBlock b = BlockData.isGenesisBlock (b ^∙ bBlockData) isNilBlock : Block → Bool isNilBlock b = BlockData.isNilBlock (b ^∙ bBlockData) makeGenesisBlockFromLedgerInfo : LedgerInfo → Either ErrLog Block makeGenesisBlockFromLedgerInfo li = do blockData <- BlockData.newGenesisFromLedgerInfo li pure (Block∙new (hashBD blockData) blockData nothing) newNil : Round → QuorumCert → Block newNil r qc = Block∙new (hashBD blockData) blockData nothing where blockData = BlockData.newNil r qc newProposalFromBlockDataAndSignature : BlockData → Signature → Block newProposalFromBlockDataAndSignature blockData signature = Block∙new (hashBD blockData) blockData (just signature) validateSignature : Block → ValidatorVerifier → Either ErrLog Unit validateSignature self validator = case self ^∙ bBlockData ∙ bdBlockType of λ where Genesis → Left fakeErr -- (ErrL (here' ["do not accept genesis from others"])) NilBlock → QuorumCert.verify (self ^∙ bQuorumCert) validator (Proposal _ author) → do fromMaybeM (Left fakeErr) -- (ErrL (here' ["Missing signature in Proposal"]))) (pure (self ^∙ bSignature)) >>= λ sig -> withErrCtx' (here' []) (ValidatorVerifier.verify validator author (self ^∙ bBlockData) sig) QuorumCert.verify (self ^∙ bQuorumCert) validator where here' : List String → List String here' t = "Block" ∷ "validateSignatures" {-∷ lsB self-} ∷ t verifyWellFormed : Block → Either ErrLog Unit verifyWellFormed self = do lcheck (not (isGenesisBlock self)) (here' ("Do not accept genesis from others" ∷ [])) let parent = self ^∙ bQuorumCert ∙ qcCertifiedBlock lcheck (parent ^∙ biRound <? self ^∙ bRound) (here' ("Block must have a greater round than parent's block" ∷ [])) lcheck (parent ^∙ biEpoch == self ^∙ bEpoch) (here' ("block's parent should be in the same epoch" ∷ [])) lcheck (not (BlockInfo.hasReconfiguration parent) ∨ maybe true payloadIsEmpty (self ^∙ bPayload)) (here' ("Reconfiguration suffix should not carry payload" ∷ [])) -- timestamps go here -- Haskell removed them lcheck (not (self ^∙ bQuorumCert ∙ qcEndsEpoch)) (here' ("Block cannot be proposed in an epoch that has ended" ∷ [])) lcheck (self ^∙ bId == hashBD (self ^∙ bBlockData)) (here' ("Block id hash mismatch" ∷ [])) where here' : List String → List String here' t = "Block" ∷ "verifyWellFormed" {-∷ lsB self-} ∷ t
46.085366
111
0.698598
1217bdbfc2c367bed3c271882d084df21c98fae0
11,234
agda
Agda
Cubical/Algebra/Matrix/Elementaries.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/Matrix/Elementaries.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/Matrix/Elementaries.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- Technical results about elementary transformations -} {-# OPTIONS --safe #-} module Cubical.Algebra.Matrix.Elementaries where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Data.Nat hiding (_+_ ; _·_) open import Cubical.Data.Nat.Order open import Cubical.Data.Empty as Empty open import Cubical.Data.Bool open import Cubical.Data.FinData renaming (znots to znotsFin ; snotz to snotzFin) open import Cubical.Relation.Nullary open import Cubical.Algebra.CommRingSolver.Reflection open import Cubical.Algebra.Ring.BigOps open import Cubical.Algebra.CommRing open import Cubical.Algebra.Matrix open import Cubical.Algebra.Matrix.CommRingCoefficient open import Cubical.Algebra.Matrix.RowTransformation private variable ℓ : Level A : Type ℓ m n k l : ℕ module ElemTransformation (𝓡 : CommRing ℓ) where private R = 𝓡 .fst open CommRingStr (𝓡 .snd) renaming ( is-set to isSetR ) open KroneckerDelta (CommRing→Ring 𝓡) open Sum (CommRing→Ring 𝓡) open Coefficient 𝓡 open LinearTransformation 𝓡 open SimRel open Sim open isLinear open isLinear2×2 -- Swapping the first row with another swapMat : Mat 2 2 swapMat zero zero = 0r swapMat zero one = 1r swapMat one zero = 1r swapMat one one = 0r uniSwapMat : swapMat ⋆ swapMat ≡ 𝟙 uniSwapMat t zero zero = (mul2 swapMat swapMat zero zero ∙ helper) t where helper : 0r · 0r + 1r · 1r ≡ 1r helper = solve 𝓡 uniSwapMat t zero one = (mul2 swapMat swapMat zero one ∙ helper) t where helper : 0r · 1r + 1r · 0r ≡ 0r helper = solve 𝓡 uniSwapMat t one zero = (mul2 swapMat swapMat one zero ∙ helper) t where helper : 1r · 0r + 0r · 1r ≡ 0r helper = solve 𝓡 uniSwapMat t one one = (mul2 swapMat swapMat one one ∙ helper) t where helper : 1r · 1r + 0r · 0r ≡ 1r helper = solve 𝓡 isInvSwapMat2 : isInv swapMat isInvSwapMat2 .fst = swapMat isInvSwapMat2 .snd .fst = uniSwapMat isInvSwapMat2 .snd .snd = uniSwapMat swapRow2 : Mat 2 n → Mat 2 n swapRow2 M zero = M one swapRow2 M one = M zero isLinear2×2SwapRow2 : isLinear2×2 {n = n} swapRow2 isLinear2×2SwapRow2 .transMat _ = swapMat isLinear2×2SwapRow2 .transEq M t zero j = ((mul2 swapMat M zero j) ∙ helper _ _) (~ t) where helper : (a b : R) → 0r · a + 1r · b ≡ b helper = solve 𝓡 isLinear2×2SwapRow2 .transEq M t one j = ((mul2 swapMat M one j) ∙ helper _ _) (~ t) where helper : (a b : R) → 1r · a + 0r · b ≡ a helper = solve 𝓡 swapRow : (i₀ : Fin m)(M : Mat (suc m) n) → Mat (suc m) n swapRow i M zero = M (suc i) swapRow zero M one = M zero swapRow zero M (suc (suc i)) = M (suc (suc i)) swapRow (suc i₀) M one = M one swapRow (suc i₀) M (suc (suc i)) = swapRow i₀ (takeRowsᶜ M) (suc i) swapRowMat : (i₀ : Fin m) → Mat (suc m) (suc m) swapRowMat = trans2RowsMat swapMat swapRowEq : (i₀ : Fin m)(M : Mat (suc m) n) → swapRow i₀ M ≡ swapRowMat i₀ ⋆ M swapRowEq {m = suc m} zero M t zero j = (helper1 _ _ ∙ (λ t → 0r · M zero j + ∑Mulr1 _ (λ i → M (suc i) j) zero (~ t)) ∙ (λ t → 0r · M zero j + ∑ (λ i → helper2 (δ i zero) (M (suc i) j) t))) t where helper1 : (a b : R) → b ≡ 0r · a + b helper1 = solve 𝓡 helper2 : (a b : R) → b · a ≡ (1r · a) · b helper2 = solve 𝓡 swapRowEq {m = suc m} zero M t one j = (helper _ ∙ (λ t → (1r · 1r) · M zero j + ∑Mul0r (λ i → M (suc i) j) (~ t))) t where helper : (a : R) → a ≡ (1r · 1r) · a + 0r helper = solve 𝓡 swapRowEq {m = suc m} zero M t (suc (suc i)) j = (helper _ _ ∙ (λ t → (1r · 0r) · M zero j + ∑Mul1r _ (λ l → M (suc l) j) (suc i) (~ t))) t where helper : (a b : R) → b ≡ (1r · 0r) · a + b helper = solve 𝓡 swapRowEq {m = suc m} (suc i₀) M t zero j = (helper1 _ _ ∙ (λ t → 0r · M zero j + ∑Mul1r _ (λ i → M (suc i) j) (suc i₀) (~ t)) ∙ (λ t → 0r · M zero j + ∑ (λ l → helper2 (δ (suc i₀) l) (M (suc l) j) t))) t where helper1 : (a b : R) → b ≡ 0r · a + b helper1 = solve 𝓡 helper2 : (a b : R) → a · b ≡ (1r · a) · b helper2 = solve 𝓡 swapRowEq {m = suc m} (suc i₀) M t one j = (helper _ _ --helper1 _ _ ∙ (λ t → (1r · 0r) · M zero j + ∑Mul1r _ (λ i → M (suc i) j) zero (~ t))) t where helper : (a b : R) → b ≡ (1r · 0r) · a + b helper = solve 𝓡 swapRowEq {m = suc m} (suc i₀) M t (suc (suc i)) j = ((λ t → swapRowEq i₀ (takeRowsᶜ M) t (suc i) j) ∙ helper _ (M one j) _) t where helper : (a b c : R) → a + c ≡ a + (0r · b + c) helper = solve 𝓡 isLinearSwapRow : (i : Fin m) → isLinear (swapRow {n = n} i) isLinearSwapRow i .transMat _ = swapRowMat i isLinearSwapRow i .transEq = swapRowEq i isInvSwapMat : (i : Fin m)(M : Mat (suc m) (suc n)) → isInv (isLinearSwapRow i .transMat M) isInvSwapMat i _ = isInvTrans2RowsMat _ i isInvSwapMat2 -- Similarity defined by swapping record SwapFirstRow (i : Fin m)(M : Mat (suc m) (suc n)) : Type ℓ where field sim : Sim M swapEq : (j : Fin (suc n)) → M (suc i) j ≡ sim .result zero j record SwapFirstCol (j : Fin n)(M : Mat (suc m) (suc n)) : Type ℓ where field sim : Sim M swapEq : (i : Fin (suc m)) → M i (suc j) ≡ sim .result i zero record SwapPivot (i : Fin (suc m))(j : Fin (suc n))(M : Mat (suc m) (suc n)) : Type ℓ where field sim : Sim M swapEq : M i j ≡ sim .result zero zero open SwapFirstRow open SwapFirstCol open SwapPivot swapFirstRow : (i : Fin m)(M : Mat (suc m) (suc n)) → SwapFirstRow i M swapFirstRow i M .sim .result = swapRow i M swapFirstRow i M .sim .simrel .transMatL = isLinearSwapRow i .transMat M swapFirstRow i M .sim .simrel .transMatR = 𝟙 swapFirstRow i M .sim .simrel .transEq = isLinearSwapRow i .transEq _ ∙ sym (⋆rUnit _) swapFirstRow i M .sim .simrel .isInvTransL = isInvSwapMat i M swapFirstRow i M .sim .simrel .isInvTransR = isInv𝟙 swapFirstRow i M .swapEq j = refl swapFirstCol : (j : Fin n)(M : Mat (suc m) (suc n)) → SwapFirstCol j M swapFirstCol j M .sim .result = (swapRow j (M ᵗ))ᵗ swapFirstCol j M .sim .simrel .transMatL = 𝟙 swapFirstCol j M .sim .simrel .transMatR = (isLinearSwapRow j .transMat (M ᵗ))ᵗ swapFirstCol j M .sim .simrel .transEq = let P = isLinearSwapRow j .transMat (M ᵗ) in (λ t → (isLinearSwapRow j .transEq (M ᵗ) t)ᵗ) ∙ compᵗ P (M ᵗ) ∙ (λ t → idemᵗ M t ⋆ P ᵗ) ∙ (λ t → ⋆lUnit M (~ t) ⋆ P ᵗ) swapFirstCol j M .sim .simrel .isInvTransL = isInv𝟙 swapFirstCol j M .sim .simrel .isInvTransR = isInvᵗ {M = isLinearSwapRow j .transMat (M ᵗ)} (isInvSwapMat j (M ᵗ)) swapFirstCol j M .swapEq i t = M i (suc j) swapPivot : (i : Fin (suc m))(j : Fin (suc n))(M : Mat (suc m) (suc n)) → SwapPivot i j M swapPivot zero zero M .sim = idSim M swapPivot zero zero M .swapEq = refl swapPivot (suc i) zero M .sim = swapFirstRow i M .sim swapPivot (suc i) zero M .swapEq = refl swapPivot zero (suc j) M .sim = swapFirstCol j M .sim swapPivot zero (suc j) M .swapEq = refl swapPivot (suc i) (suc j) M .sim = compSim (swapFirstRow i M .sim) (swapFirstCol j _ .sim) swapPivot (suc i) (suc j) M .swapEq = refl -- Add the first row to another addMat : Mat 2 2 addMat zero zero = 1r addMat zero one = 0r addMat one zero = 1r addMat one one = 1r subMat : Mat 2 2 subMat zero zero = 1r subMat zero one = 0r subMat one zero = - 1r subMat one one = 1r add⋆subMat : addMat ⋆ subMat ≡ 𝟙 add⋆subMat t zero zero = (mul2 addMat subMat zero zero ∙ helper) t where helper : 1r · 1r + 0r · - 1r ≡ 1r helper = solve 𝓡 add⋆subMat t zero one = (mul2 addMat subMat zero one ∙ helper) t where helper : 1r · 0r + 0r · 1r ≡ 0r helper = solve 𝓡 add⋆subMat t one zero = (mul2 addMat subMat one zero ∙ helper) t where helper : 1r · 1r + 1r · - 1r ≡ 0r helper = solve 𝓡 add⋆subMat t one one = (mul2 addMat subMat one one ∙ helper) t where helper : 1r · 0r + 1r · 1r ≡ 1r helper = solve 𝓡 sub⋆addMat : subMat ⋆ addMat ≡ 𝟙 sub⋆addMat t zero zero = (mul2 subMat addMat zero zero ∙ helper) t where helper : 1r · 1r + 0r · 1r ≡ 1r helper = solve 𝓡 sub⋆addMat t zero one = (mul2 subMat addMat zero one ∙ helper) t where helper : 1r · 0r + 0r · 1r ≡ 0r helper = solve 𝓡 sub⋆addMat t one zero = (mul2 subMat addMat one zero ∙ helper) t where helper : - 1r · 1r + 1r · 1r ≡ 0r helper = solve 𝓡 sub⋆addMat t one one = (mul2 subMat addMat one one ∙ helper) t where helper : - 1r · 0r + 1r · 1r ≡ 1r helper = solve 𝓡 isInvAddMat2 : isInv addMat isInvAddMat2 .fst = subMat isInvAddMat2 .snd .fst = add⋆subMat isInvAddMat2 .snd .snd = sub⋆addMat addRow2 : Mat 2 n → Mat 2 n addRow2 M zero = M zero addRow2 M one j = M zero j + M one j isLinear2AddRow2 : isLinear2×2 {n = n} addRow2 isLinear2AddRow2 .transMat _ = addMat isLinear2AddRow2 .transEq M t zero j = ((mul2 addMat M zero j) ∙ helper _ _) (~ t) where helper : (a b : R) → 1r · a + 0r · b ≡ a helper = solve 𝓡 isLinear2AddRow2 .transEq M t one j = ((mul2 addMat M one j) ∙ helper _ _) (~ t) where helper : (a b : R) → 1r · a + 1r · b ≡ a + b helper = solve 𝓡 -- Add the first row to all other rows addRows : Mat (suc m) n → Mat (suc m) n addRows M zero = M zero addRows M (suc i) j = M zero j + M (suc i) j private firstRowStayInvariant : (M : Mat (suc m) n) → M zero ≡ transRows addRow2 M zero firstRowStayInvariant = invRow₀ _ (λ _ → refl) addRowsEq : (M : Mat (suc m) n) → transRows addRow2 M ≡ addRows M addRowsEq M t zero = firstRowStayInvariant M (~ t) addRowsEq M t one j = M zero j + M one j addRowsEq M t (suc (suc i)) j = takeCombShufRows addRow2 (λ N → addRowsEq N t) M (suc (suc i)) j isLinearAddRows : isLinear (addRows {m = m} {n = suc n}) isLinearAddRows = let isLinear = isLinearTransRows _ isLinear2AddRow2 _ in record { transMat = isLinear .transMat ; transEq = (λ M → sym (addRowsEq M) ∙ isLinear .transEq M) } isInvAddRows : (M : Mat (suc m) (suc n)) → isInv (isLinearAddRows .transMat M) isInvAddRows = isInvTransRows _ _ (λ _ → isInvAddMat2) -- Similarity defined by adding rows record AddFirstRow (M : Mat (suc m) (suc n)) : Type ℓ where field sim : Sim M inv₀ : M zero ≡ sim .result zero addEq : (i : Fin m)(j : Fin (suc n)) → M zero j + M (suc i) j ≡ sim .result (suc i) j open AddFirstRow addFirstRow : (M : Mat (suc m) (suc n)) → AddFirstRow M addFirstRow M .sim .result = addRows M addFirstRow M .sim .simrel .transMatL = isLinearAddRows .transMat M addFirstRow M .sim .simrel .transMatR = 𝟙 addFirstRow M .sim .simrel .transEq = isLinearAddRows .transEq _ ∙ sym (⋆rUnit _) addFirstRow M .sim .simrel .isInvTransL = isInvAddRows M addFirstRow M .sim .simrel .isInvTransR = isInv𝟙 addFirstRow M .inv₀ = refl addFirstRow M .addEq i j = refl
34.780186
98
0.603347
c54fcd53161d0383843a55caab5418f3b2fa26d1
76
agda
Agda
test/Fail/customised/Issue5644/A/B.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/customised/Issue5644/A/B.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/customised/Issue5644/A/B.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module A.B where {-# NON_TERMINATING #-} easy : (A : Set) → A easy = easy
10.857143
23
0.592105
18d191506468614764f4a732b931cedae7755786
1,411
agda
Agda
agda-stdlib/src/Relation/Binary/Indexed/Heterogeneous/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Relation/Binary/Indexed/Heterogeneous/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Relation/Binary/Indexed/Heterogeneous/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Indexed binary relations ------------------------------------------------------------------------ -- The contents of this module should be accessed via -- `Relation.Binary.Indexed.Heterogeneous`. {-# OPTIONS --without-K --safe #-} module Relation.Binary.Indexed.Heterogeneous.Bundles where open import Function.Base open import Level using (suc; _⊔_) open import Relation.Binary using (_⇒_) open import Relation.Binary.PropositionalEquality.Core as P using (_≡_) open import Relation.Binary.Indexed.Heterogeneous.Core open import Relation.Binary.Indexed.Heterogeneous.Structures ------------------------------------------------------------------------ -- Definitions record IndexedSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where infix 4 _≈_ field Carrier : I → Set c _≈_ : IRel Carrier ℓ isEquivalence : IsIndexedEquivalence Carrier _≈_ open IsIndexedEquivalence isEquivalence public record IndexedPreorder {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _∼_ field Carrier : I → Set c _≈_ : IRel Carrier ℓ₁ -- The underlying equality. _∼_ : IRel Carrier ℓ₂ -- The relation. isPreorder : IsIndexedPreorder Carrier _≈_ _∼_ open IsIndexedPreorder isPreorder public
32.068182
72
0.580439
dcc04e1544f126e424519c78ab8a07108ce45307
114
agda
Agda
test/Succeed/NoQualifiedInstances/ParameterizedImport/A.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/NoQualifiedInstances/ParameterizedImport/A.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/NoQualifiedInstances/ParameterizedImport/A.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module NoQualifiedInstances.ParameterizedImport.A (T : Set) where record I : Set where postulate instance i : I
19
65
0.780702
50d25037fc1fedd9c144f0a64779d626e3360cff
32,873
agda
Agda
src/syntax-util.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/syntax-util.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
src/syntax-util.agda
xoltar/cedille
acf691e37210607d028f4b19f98ec26c4353bfb5
[ "MIT" ]
null
null
null
module syntax-util where open import lib open import cedille-types open import general-util open import constants posinfo-gen : posinfo posinfo-gen = "generated" first-position : posinfo first-position = "1" dummy-var : var dummy-var = "_dummy" id-term : term id-term = Lam posinfo-gen NotErased posinfo-gen "x" NoClass (Var posinfo-gen "x") compileFailType : type compileFailType = Abs posinfo-gen Erased posinfo-gen "X" (Tkk (Star posinfo-gen)) (TpVar posinfo-gen "X") qualif-info : Set qualif-info = var × args qualif : Set qualif = trie qualif-info tag : Set tag = string × rope tagged-val : Set tagged-val = string × rope × 𝕃 tag tags-to-rope : 𝕃 tag → rope tags-to-rope [] = [[]] tags-to-rope ((t , v) :: []) = [[ "\"" ^ t ^ "\":" ]] ⊹⊹ v tags-to-rope ((t , v) :: ts) = [[ "\"" ^ t ^ "\":" ]] ⊹⊹ v ⊹⊹ [[ "," ]] ⊹⊹ tags-to-rope ts -- We number these when so we can sort them back in emacs tagged-val-to-rope : ℕ → tagged-val → rope tagged-val-to-rope n (t , v , []) = [[ "\"" ^ t ^ "\":[\"" ^ ℕ-to-string n ^ "\",\"" ]] ⊹⊹ v ⊹⊹ [[ "\"]" ]] tagged-val-to-rope n (t , v , tags) = [[ "\"" ^ t ^ "\":[\"" ^ ℕ-to-string n ^ "\",\"" ]] ⊹⊹ v ⊹⊹ [[ "\",{" ]] ⊹⊹ tags-to-rope tags ⊹⊹ [[ "}]" ]] tagged-vals-to-rope : ℕ → 𝕃 tagged-val → rope tagged-vals-to-rope n [] = [[]] tagged-vals-to-rope n (s :: []) = tagged-val-to-rope n s tagged-vals-to-rope n (s :: (s' :: ss)) = tagged-val-to-rope n s ⊹⊹ [[ "," ]] ⊹⊹ tagged-vals-to-rope (suc n) (s' :: ss) make-tag : (name : string) → (values : 𝕃 tag) → (start : ℕ) → (end : ℕ) → tag make-tag name vs start end = name , [[ "{\"start\":\"" ^ ℕ-to-string start ^ "\",\"end\":\"" ^ ℕ-to-string end ^ "\"" ]] ⊹⊹ vs-to-rope vs ⊹⊹ [[ "}" ]] where vs-to-rope : 𝕃 tag → rope vs-to-rope [] = [[]] vs-to-rope ((t , v) :: ts) = [[ ",\"" ^ t ^ "\":\"" ]] ⊹⊹ v ⊹⊹ [[ "\"" ]] ⊹⊹ vs-to-rope ts posinfo-to-ℕ : posinfo → ℕ posinfo-to-ℕ pi with string-to-ℕ pi posinfo-to-ℕ pi | just n = n posinfo-to-ℕ pi | nothing = 0 -- should not happen posinfo-plus : posinfo → ℕ → posinfo posinfo-plus pi n = ℕ-to-string (posinfo-to-ℕ pi + n) posinfo-plus-str : posinfo → string → posinfo posinfo-plus-str pi s = posinfo-plus pi (string-length s) star : kind star = Star posinfo-gen -- qualify variable by module name _#_ : string → string → string fn # v = fn ^ qual-global-str ^ v _%_ : posinfo → var → string pi % v = pi ^ qual-local-str ^ v compileFail : var compileFail = "compileFail" compileFail-qual = "" % compileFail mk-inst : params → args → trie arg × params mk-inst (ParamsCons (Decl _ _ _ x _ _) ps) (ArgsCons a as) with mk-inst ps as ...| σ , ps' = trie-insert σ x a , ps' mk-inst ps as = empty-trie , ps apps-term : term → args → term apps-term f (ArgsNil) = f apps-term f (ArgsCons (TermArg me t) as) = apps-term (App f me t) as apps-term f (ArgsCons (TypeArg t) as) = apps-term (AppTp f t) as apps-type : type → args → type apps-type f (ArgsNil) = f apps-type f (ArgsCons (TermArg _ t) as) = apps-type (TpAppt f t) as apps-type f (ArgsCons (TypeArg t) as) = apps-type (TpApp f t) as append-params : params → params → params append-params (ParamsCons p ps) qs = ParamsCons p (append-params ps qs) append-params ParamsNil qs = qs append-args : args → args → args append-args (ArgsCons p ps) qs = ArgsCons p (append-args ps qs) append-args (ArgsNil) qs = qs append-cmds : cmds → cmds → cmds append-cmds CmdsStart = id append-cmds (CmdsNext c cs) = CmdsNext c ∘ append-cmds cs qualif-lookup-term : qualif → string → term qualif-lookup-term σ x with trie-lookup σ x ... | just (x' , as) = apps-term (Var posinfo-gen x') as ... | _ = Var posinfo-gen x qualif-lookup-type : qualif → string → type qualif-lookup-type σ x with trie-lookup σ x ... | just (x' , as) = apps-type (TpVar posinfo-gen x') as ... | _ = TpVar posinfo-gen x qualif-lookup-kind : args → qualif → string → kind qualif-lookup-kind xs σ x with trie-lookup σ x ... | just (x' , as) = KndVar posinfo-gen x' (append-args as xs) ... | _ = KndVar posinfo-gen x xs inst-lookup-term : trie arg → string → term inst-lookup-term σ x with trie-lookup σ x ... | just (TermArg me t) = t ... | _ = Var posinfo-gen x inst-lookup-type : trie arg → string → type inst-lookup-type σ x with trie-lookup σ x ... | just (TypeArg t) = t ... | _ = TpVar posinfo-gen x params-to-args : params → args params-to-args ParamsNil = ArgsNil params-to-args (ParamsCons (Decl _ p me v (Tkt t) _) ps) = ArgsCons (TermArg me (Var posinfo-gen v)) (params-to-args ps) params-to-args (ParamsCons (Decl _ p _ v (Tkk k) _) ps) = ArgsCons (TypeArg (TpVar posinfo-gen v)) (params-to-args ps) qualif-insert-params : qualif → var → var → params → qualif qualif-insert-params σ qv v ps = trie-insert σ v (qv , params-to-args ps) qualif-insert-import : qualif → var → optAs → 𝕃 string → args → qualif qualif-insert-import σ mn oa [] as = σ qualif-insert-import σ mn oa (v :: vs) as = qualif-insert-import (trie-insert σ (import-as v oa) (mn # v , as)) mn oa vs as where import-as : var → optAs → var import-as v NoOptAs = v import-as v (SomeOptAs _ pfx) = pfx # v tk-is-type : tk → 𝔹 tk-is-type (Tkt _) = tt tk-is-type (Tkk _) = ff me-unerased : maybeErased → 𝔹 me-unerased Erased = ff me-unerased NotErased = tt me-erased : maybeErased → 𝔹 me-erased x = ~ (me-unerased x) term-start-pos : term → posinfo type-start-pos : type → posinfo kind-start-pos : kind → posinfo liftingType-start-pos : liftingType → posinfo term-start-pos (App t x t₁) = term-start-pos t term-start-pos (AppTp t tp) = term-start-pos t term-start-pos (Hole pi) = pi term-start-pos (Lam pi x _ x₁ x₂ t) = pi term-start-pos (Let pi _ _) = pi term-start-pos (Open pi _ _) = pi term-start-pos (Parens pi t pi') = pi term-start-pos (Var pi x₁) = pi term-start-pos (Beta pi _ _) = pi term-start-pos (IotaPair pi _ _ _ _) = pi term-start-pos (IotaProj t _ _) = term-start-pos t term-start-pos (Epsilon pi _ _ _) = pi term-start-pos (Phi pi _ _ _ _) = pi term-start-pos (Rho pi _ _ _ _ _) = pi term-start-pos (Chi pi _ _) = pi term-start-pos (Delta pi _ _) = pi term-start-pos (Sigma pi _) = pi term-start-pos (Theta pi _ _ _) = pi term-start-pos (Mu pi _ _ _ _ _ _) = pi term-start-pos (Mu' pi _ _ _ _ _) = pi type-start-pos (Abs pi _ _ _ _ _) = pi type-start-pos (TpLambda pi _ _ _ _) = pi type-start-pos (Iota pi _ _ _ _) = pi type-start-pos (Lft pi _ _ _ _) = pi type-start-pos (TpApp t t₁) = type-start-pos t type-start-pos (TpAppt t x) = type-start-pos t type-start-pos (TpArrow t _ t₁) = type-start-pos t type-start-pos (TpEq pi _ _ pi') = pi type-start-pos (TpParens pi _ pi') = pi type-start-pos (TpVar pi x₁) = pi type-start-pos (NoSpans t _) = type-start-pos t -- we are not expecting this on input type-start-pos (TpHole pi) = pi --ACG type-start-pos (TpLet pi _ _) = pi kind-start-pos (KndArrow k k₁) = kind-start-pos k kind-start-pos (KndParens pi k pi') = pi kind-start-pos (KndPi pi _ x x₁ k) = pi kind-start-pos (KndTpArrow x k) = type-start-pos x kind-start-pos (KndVar pi x₁ _) = pi kind-start-pos (Star pi) = pi liftingType-start-pos (LiftArrow l l') = liftingType-start-pos l liftingType-start-pos (LiftParens pi l pi') = pi liftingType-start-pos (LiftPi pi x₁ x₂ l) = pi liftingType-start-pos (LiftStar pi) = pi liftingType-start-pos (LiftTpArrow t l) = type-start-pos t term-end-pos : term → posinfo type-end-pos : type → posinfo kind-end-pos : kind → posinfo liftingType-end-pos : liftingType → posinfo tk-end-pos : tk → posinfo lterms-end-pos : lterms → posinfo args-end-pos : (if-nil : posinfo) → args → posinfo arg-end-pos : arg → posinfo kvar-end-pos : posinfo → var → args → posinfo term-end-pos (App t x t') = term-end-pos t' term-end-pos (AppTp t tp) = type-end-pos tp term-end-pos (Hole pi) = posinfo-plus pi 1 term-end-pos (Lam pi x _ x₁ x₂ t) = term-end-pos t term-end-pos (Let _ _ t) = term-end-pos t term-end-pos (Open pi _ t) = term-end-pos t term-end-pos (Parens pi t pi') = pi' term-end-pos (Var pi x) = posinfo-plus-str pi x term-end-pos (Beta pi _ (SomeTerm t pi')) = pi' term-end-pos (Beta pi (SomeTerm t pi') _) = pi' term-end-pos (Beta pi NoTerm NoTerm) = posinfo-plus pi 1 term-end-pos (IotaPair _ _ _ _ pi) = pi term-end-pos (IotaProj _ _ pi) = pi term-end-pos (Epsilon pi _ _ t) = term-end-pos t term-end-pos (Phi _ _ _ _ pi) = pi term-end-pos (Rho pi _ _ _ t t') = term-end-pos t' term-end-pos (Chi pi T t') = term-end-pos t' term-end-pos (Delta pi oT t) = term-end-pos t term-end-pos (Sigma pi t) = term-end-pos t term-end-pos (Theta _ _ _ ls) = lterms-end-pos ls term-end-pos (Mu _ _ _ _ _ _ pi) = pi term-end-pos (Mu' _ _ _ _ _ pi) = pi type-end-pos (Abs pi _ _ _ _ t) = type-end-pos t type-end-pos (TpLambda _ _ _ _ t) = type-end-pos t type-end-pos (Iota _ _ _ _ tp) = type-end-pos tp type-end-pos (Lft pi _ _ _ t) = liftingType-end-pos t type-end-pos (TpApp t t') = type-end-pos t' type-end-pos (TpAppt t x) = term-end-pos x type-end-pos (TpArrow t _ t') = type-end-pos t' type-end-pos (TpEq pi _ _ pi') = pi' type-end-pos (TpParens pi _ pi') = pi' type-end-pos (TpVar pi x) = posinfo-plus-str pi x type-end-pos (TpHole pi) = posinfo-plus pi 1 type-end-pos (NoSpans t pi) = pi type-end-pos (TpLet _ _ t) = type-end-pos t kind-end-pos (KndArrow k k') = kind-end-pos k' kind-end-pos (KndParens pi k pi') = pi' kind-end-pos (KndPi pi _ x x₁ k) = kind-end-pos k kind-end-pos (KndTpArrow x k) = kind-end-pos k kind-end-pos (KndVar pi x ys) = args-end-pos (posinfo-plus-str pi x) ys kind-end-pos (Star pi) = posinfo-plus pi 1 tk-end-pos (Tkt T) = type-end-pos T tk-end-pos (Tkk k) = kind-end-pos k args-end-pos pi (ArgsCons x ys) = args-end-pos (arg-end-pos x) ys args-end-pos pi ArgsNil = pi arg-end-pos (TermArg me t) = term-end-pos t arg-end-pos (TypeArg T) = type-end-pos T kvar-end-pos pi v = args-end-pos (posinfo-plus-str pi v) liftingType-end-pos (LiftArrow l l') = liftingType-end-pos l' liftingType-end-pos (LiftParens pi l pi') = pi' liftingType-end-pos (LiftPi x x₁ x₂ l) = liftingType-end-pos l liftingType-end-pos (LiftStar pi) = posinfo-plus pi 1 liftingType-end-pos (LiftTpArrow x l) = liftingType-end-pos l lterms-end-pos (LtermsNil pi) = posinfo-plus pi 1 -- must add one for the implicit Beta that we will add at the end lterms-end-pos (LtermsCons _ _ ls) = lterms-end-pos ls {- return the end position of the given term if it is there, otherwise the given posinfo -} optTerm-end-pos : posinfo → optTerm → posinfo optTerm-end-pos pi NoTerm = pi optTerm-end-pos pi (SomeTerm x x₁) = x₁ optTerm-end-pos-beta : posinfo → optTerm → optTerm → posinfo optTerm-end-pos-beta pi _ (SomeTerm x pi') = pi' optTerm-end-pos-beta pi (SomeTerm x pi') NoTerm = pi' optTerm-end-pos-beta pi NoTerm NoTerm = posinfo-plus pi 1 optAs-or : optAs → posinfo → var → posinfo × var optAs-or NoOptAs pi x = pi , x optAs-or (SomeOptAs pi x) _ _ = pi , x tk-arrow-kind : tk → kind → kind tk-arrow-kind (Tkk k) k' = KndArrow k k' tk-arrow-kind (Tkt t) k = KndTpArrow t k TpApp-tk : type → var → tk → type TpApp-tk tp x (Tkk _) = TpApp tp (TpVar posinfo-gen x) TpApp-tk tp x (Tkt _) = TpAppt tp (Var posinfo-gen x) -- expression descriptor data exprd : Set where TERM : exprd TYPE : exprd KIND : exprd LIFTINGTYPE : exprd TK : exprd ARG : exprd QUALIF : exprd ⟦_⟧ : exprd → Set ⟦ TERM ⟧ = term ⟦ TYPE ⟧ = type ⟦ KIND ⟧ = kind ⟦ LIFTINGTYPE ⟧ = liftingType ⟦ TK ⟧ = tk ⟦ ARG ⟧ = arg ⟦ QUALIF ⟧ = qualif-info exprd-name : exprd → string exprd-name TERM = "term" exprd-name TYPE = "type" exprd-name KIND = "kind" exprd-name LIFTINGTYPE = "lifting type" exprd-name TK = "type-kind" exprd-name ARG = "argument" exprd-name QUALIF = "qualification" -- checking-sythesizing enum data checking-mode : Set where checking : checking-mode synthesizing : checking-mode untyped : checking-mode maybe-to-checking : {A : Set} → maybe A → checking-mode maybe-to-checking (just _) = checking maybe-to-checking nothing = synthesizing is-app : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-app{TERM} (App _ _ _) = tt is-app{TERM} (AppTp _ _) = tt is-app{TYPE} (TpApp _ _) = tt is-app{TYPE} (TpAppt _ _) = tt is-app _ = ff is-term-level-app : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-term-level-app{TERM} (App _ _ _) = tt is-term-level-app{TERM} (AppTp _ _) = tt is-term-level-app _ = ff is-type-level-app : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-type-level-app{TYPE} (TpApp _ _) = tt is-type-level-app{TYPE} (TpAppt _ _) = tt is-type-level-app _ = ff is-parens : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-parens{TERM} (Parens _ _ _) = tt is-parens{TYPE} (TpParens _ _ _) = tt is-parens{KIND} (KndParens _ _ _) = tt is-parens{LIFTINGTYPE} (LiftParens _ _ _) = tt is-parens _ = ff is-arrow : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-arrow{TYPE} (TpArrow _ _ _) = tt is-arrow{KIND} (KndTpArrow _ _) = tt is-arrow{KIND} (KndArrow _ _) = tt is-arrow{LIFTINGTYPE} (LiftArrow _ _) = tt is-arrow{LIFTINGTYPE} (LiftTpArrow _ _) = tt is-arrow _ = ff is-abs : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-abs{TERM} (Let _ _ _) = tt is-abs{TERM} (Lam _ _ _ _ _ _) = tt is-abs{TYPE} (Abs _ _ _ _ _ _) = tt is-abs{TYPE} (TpLambda _ _ _ _ _) = tt is-abs{TYPE} (Iota _ _ _ _ _) = tt is-abs{KIND} (KndPi _ _ _ _ _) = tt is-abs{LIFTINGTYPE} (LiftPi _ _ _ _) = tt is-abs _ = ff is-eq-op : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-eq-op{TERM} (Sigma _ _) = tt is-eq-op{TERM} (Epsilon _ _ _ _) = tt is-eq-op{TERM} (Rho _ _ _ _ _ _) = tt is-eq-op{TERM} (Chi _ _ _) = tt is-eq-op{TERM} (Phi _ _ _ _ _) = tt is-eq-op{TERM} (Delta _ _ _) = tt is-eq-op _ = ff is-beta : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-beta{TERM} (Beta _ _ _) = tt is-beta _ = ff is-hole : {ed : exprd} → ⟦ ed ⟧ → 𝔹 is-hole{TERM} (Hole _) = tt is-hole{TERM} _ = ff is-hole{TYPE} (TpHole _) = tt is-hole{TYPE} _ = ff is-hole{KIND} e = ff is-hole{LIFTINGTYPE} e = ff is-hole{TK} (Tkk x) = is-hole x is-hole{TK} (Tkt x) = is-hole x is-hole{ARG} (TermArg e? t) = is-hole t is-hole{ARG} (TypeArg tp) = is-hole tp is-hole{QUALIF} _ = ff eq-maybeErased : maybeErased → maybeErased → 𝔹 eq-maybeErased Erased Erased = tt eq-maybeErased Erased NotErased = ff eq-maybeErased NotErased Erased = ff eq-maybeErased NotErased NotErased = tt eq-checking-mode : (m₁ m₂ : checking-mode) → 𝔹 eq-checking-mode checking checking = tt eq-checking-mode checking synthesizing = ff eq-checking-mode checking untyped = ff eq-checking-mode synthesizing checking = ff eq-checking-mode synthesizing synthesizing = tt eq-checking-mode synthesizing untyped = ff eq-checking-mode untyped checking = ff eq-checking-mode untyped synthesizing = ff eq-checking-mode untyped untyped = tt optPublic-is-public : optPublic → 𝔹 optPublic-is-public IsPublic = tt optPublic-is-public NotPublic = ff ------------------------------------------------------ -- functions intended for building terms for testing ------------------------------------------------------ mlam : var → term → term mlam x t = Lam posinfo-gen NotErased posinfo-gen x NoClass t Mlam : var → term → term Mlam x t = Lam posinfo-gen Erased posinfo-gen x NoClass t mappe : term → term → term mappe t1 t2 = App t1 Erased t2 mapp : term → term → term mapp t1 t2 = App t1 NotErased t2 mvar : var → term mvar x = Var posinfo-gen x mtpvar : var → type mtpvar x = TpVar posinfo-gen x mall : var → tk → type → type mall x tk tp = Abs posinfo-gen All posinfo-gen x tk tp mtplam : var → tk → type → type mtplam x tk tp = TpLambda posinfo-gen posinfo-gen x tk tp {- strip off lambda-abstractions from the term, return the lambda-bound vars and the innermost body. The intention is to call this with at least the erasure of a term, if not the hnf -- so we do not check for parens, etc. -} decompose-lams : term → (𝕃 var) × term decompose-lams (Lam _ _ _ x _ t) with decompose-lams t decompose-lams (Lam _ _ _ x _ t) | vs , body = (x :: vs) , body decompose-lams t = [] , t {- decompose a term into spine form consisting of a non-applications head and arguments. The outer arguments will come earlier in the list than the inner ones. As for decompose-lams, we assume the term is at least erased. -} decompose-apps : term → term × (𝕃 term) decompose-apps (App t _ t') with decompose-apps t decompose-apps (App t _ t') | h , args = h , (t' :: args) decompose-apps t = t , [] decompose-var-headed : (var → 𝔹) → term → maybe (var × (𝕃 term)) decompose-var-headed is-bound t with decompose-apps t decompose-var-headed is-bound t | Var _ x , args = if is-bound x then nothing else (just (x , args)) decompose-var-headed is-bound t | _ = nothing data tty : Set where tterm : term → tty ttype : type → tty decompose-tpapps : type → type × 𝕃 tty decompose-tpapps (TpApp t t') with decompose-tpapps t decompose-tpapps (TpApp t t') | h , args = h , (ttype t') :: args decompose-tpapps (TpAppt t t') with decompose-tpapps t decompose-tpapps (TpAppt t t') | h , args = h , (tterm t') :: args decompose-tpapps (TpParens _ t _) = decompose-tpapps t decompose-tpapps t = t , [] recompose-tpapps : type × 𝕃 tty → type recompose-tpapps (h , []) = h recompose-tpapps (h , ((tterm t') :: args)) = TpAppt (recompose-tpapps (h , args)) t' recompose-tpapps (h , ((ttype t') :: args)) = TpApp (recompose-tpapps (h , args)) t' recompose-apps : maybeErased → 𝕃 tty → term → term recompose-apps me [] h = h recompose-apps me ((tterm t') :: args) h = App (recompose-apps me args h) me t' recompose-apps me ((ttype t') :: args) h = AppTp (recompose-apps me args h) t' vars-to-𝕃 : vars → 𝕃 var vars-to-𝕃 (VarsStart v) = [ v ] vars-to-𝕃 (VarsNext v vs) = v :: vars-to-𝕃 vs {- lambda-abstract the input variables in reverse order around the given term (so closest to the top of the list is bound deepest in the resulting term). -} Lam* : 𝕃 var → term → term Lam* [] t = t Lam* (x :: xs) t = Lam* xs (Lam posinfo-gen NotErased posinfo-gen x NoClass t) App* : term → 𝕃 (maybeErased × term) → term App* t [] = t App* t ((m , arg) :: args) = App (App* t args) m arg App*' : term → 𝕃 term → term App*' t [] = t App*' t (arg :: args) = App*' (App t NotErased arg) args TpApp* : type → 𝕃 type → type TpApp* t [] = t TpApp* t (arg :: args) = (TpApp (TpApp* t args) arg) LiftArrow* : 𝕃 liftingType → liftingType → liftingType LiftArrow* [] l = l LiftArrow* (l' :: ls) l = LiftArrow* ls (LiftArrow l' l) is-intro-form : term → 𝔹 is-intro-form (Lam _ _ _ _ _ _) = tt --is-intro-form (IotaPair _ _ _ _ _) = tt is-intro-form _ = ff erase : { ed : exprd } → ⟦ ed ⟧ → ⟦ ed ⟧ erase-term : term → term erase-type : type → type erase-kind : kind → kind erase-lterms : term → lterms → term erase-tk : tk → tk -- erase-optType : optType → optType erase-liftingType : liftingType → liftingType erase-cases : cases → cases erase-varargs : varargs → varargs erase-if : 𝔹 → { ed : exprd } → ⟦ ed ⟧ → ⟦ ed ⟧ erase-if tt = erase erase-if ff = id erase-term (Parens _ t _) = erase-term t erase-term (App t1 Erased t2) = erase-term t1 erase-term (App t1 NotErased t2) = App (erase-term t1) NotErased (erase-term t2) erase-term (AppTp t tp) = erase-term t erase-term (Lam _ Erased _ _ _ t) = erase-term t erase-term (Lam _ NotErased _ x oc t) = Lam posinfo-gen NotErased posinfo-gen x NoClass (erase-term t) erase-term (Let _ (DefTerm _ x _ t) t') = Let posinfo-gen (DefTerm posinfo-gen x NoType (erase-term t)) (erase-term t') erase-term (Let _ (DefType _ _ _ _) t) = erase-term t erase-term (Open _ _ t) = erase-term t erase-term (Var _ x) = Var posinfo-gen x erase-term (Beta _ _ NoTerm) = id-term erase-term (Beta _ _ (SomeTerm t _)) = erase-term t erase-term (IotaPair _ t1 t2 _ _) = erase-term t1 erase-term (IotaProj t n _) = erase-term t erase-term (Epsilon _ lr _ t) = erase-term t erase-term (Sigma _ t) = erase-term t erase-term (Hole _) = Hole posinfo-gen erase-term (Phi _ t t₁ t₂ _) = erase-term t₂ erase-term (Rho _ _ _ t _ t') = erase-term t' erase-term (Chi _ T t') = erase-term t' erase-term (Delta _ T t) = id-term erase-term (Theta _ u t ls) = erase-lterms (erase-term t) ls erase-term (Mu _ x t ot _ c _) = Mu posinfo-gen x (erase-term t) NoType posinfo-gen (erase-cases c) posinfo-gen erase-term (Mu' _ t ot _ c _) = Mu' posinfo-gen (erase-term t) NoType posinfo-gen (erase-cases c) posinfo-gen erase-cases NoCase = NoCase erase-cases (SomeCase _ x varargs t cs) = SomeCase posinfo-gen x (erase-varargs varargs) (erase-term t) (erase-cases cs) erase-varargs NoVarargs = NoVarargs erase-varargs (NormalVararg x varargs) = NormalVararg x (erase-varargs varargs) erase-varargs (ErasedVararg x varargs) = erase-varargs varargs erase-varargs (TypeVararg x varargs ) = erase-varargs varargs -- Only erases TERMS in types, leaving the structure of types the same erase-type (Abs _ b _ v atk tp) = Abs posinfo-gen b posinfo-gen v (erase-tk atk) (erase-type tp) erase-type (Iota _ _ v otp tp) = Iota posinfo-gen posinfo-gen v (erase-type otp) (erase-type tp) erase-type (Lft _ _ v t lt) = Lft posinfo-gen posinfo-gen v (erase-term t) (erase-liftingType lt) erase-type (NoSpans tp _) = NoSpans (erase-type tp) posinfo-gen erase-type (TpApp tp tp') = TpApp (erase-type tp) (erase-type tp') erase-type (TpAppt tp t) = TpAppt (erase-type tp) (erase-term t) erase-type (TpArrow tp at tp') = TpArrow (erase-type tp) at (erase-type tp') erase-type (TpEq _ t t' _) = TpEq posinfo-gen (erase-term t) (erase-term t') posinfo-gen erase-type (TpLambda _ _ v atk tp) = TpLambda posinfo-gen posinfo-gen v (erase-tk atk) (erase-type tp) erase-type (TpParens _ tp _) = erase-type tp erase-type (TpHole _) = TpHole posinfo-gen erase-type (TpVar _ x) = TpVar posinfo-gen x erase-type (TpLet _ (DefTerm _ x _ t) T) = TpLet posinfo-gen (DefTerm posinfo-gen x NoType (erase-term t)) (erase-type T) erase-type (TpLet _ (DefType _ x k T) T') = TpLet posinfo-gen (DefType posinfo-gen x (erase-kind k) (erase-type T)) (erase-type T') -- Only erases TERMS in types in kinds, leaving the structure of kinds and types in those kinds the same erase-kind (KndArrow k k') = KndArrow (erase-kind k) (erase-kind k') erase-kind (KndParens _ k _) = erase-kind k erase-kind (KndPi _ _ v atk k) = KndPi posinfo-gen posinfo-gen v (erase-tk atk) (erase-kind k) erase-kind (KndTpArrow tp k) = KndTpArrow (erase-type tp) (erase-kind k) erase-kind (KndVar _ x ps) = KndVar posinfo-gen x ps erase-kind (Star _) = Star posinfo-gen erase{TERM} t = erase-term t erase{TYPE} tp = erase-type tp erase{KIND} k = erase-kind k erase{LIFTINGTYPE} lt = erase-liftingType lt erase{TK} atk = erase-tk atk erase{ARG} a = a erase{QUALIF} q = q erase-tk (Tkt tp) = Tkt (erase-type tp) erase-tk (Tkk k) = Tkk (erase-kind k) erase-liftingType (LiftArrow lt lt') = LiftArrow (erase-liftingType lt) (erase-liftingType lt') erase-liftingType (LiftParens _ lt _) = erase-liftingType lt erase-liftingType (LiftPi _ v tp lt) = LiftPi posinfo-gen v (erase-type tp) (erase-liftingType lt) erase-liftingType (LiftTpArrow tp lt) = LiftTpArrow (erase-type tp) (erase-liftingType lt) erase-liftingType lt = lt erase-lterms t (LtermsNil _) = t erase-lterms t (LtermsCons Erased t' ls) = erase-lterms t ls erase-lterms t (LtermsCons NotErased t' ls) = erase-lterms (App t NotErased (erase-term t')) ls lterms-to-term : theta → term → lterms → term lterms-to-term AbstractEq t (LtermsNil _) = App t Erased (Beta posinfo-gen NoTerm NoTerm) lterms-to-term _ t (LtermsNil _) = t lterms-to-term u t (LtermsCons e t' ls) = lterms-to-term u (App t e t') ls imps-to-cmds : imports → cmds imps-to-cmds ImportsStart = CmdsStart imps-to-cmds (ImportsNext i is) = CmdsNext (ImportCmd i) (imps-to-cmds is) -- TODO handle qualif & module args get-imports : start → 𝕃 string get-imports (File _ is _ _ mn _ cs _) = imports-to-include is ++ get-imports-cmds cs where import-to-include : imprt → string import-to-include (Import _ _ _ x oa _ _) = x imports-to-include : imports → 𝕃 string imports-to-include ImportsStart = [] imports-to-include (ImportsNext x is) = import-to-include x :: imports-to-include is singleton-if-include : cmd → 𝕃 string singleton-if-include (ImportCmd imp) = [ import-to-include imp ] singleton-if-include _ = [] get-imports-cmds : cmds → 𝕃 string get-imports-cmds (CmdsNext c cs) = singleton-if-include c ++ get-imports-cmds cs get-imports-cmds CmdsStart = [] data language-level : Set where ll-term : language-level ll-type : language-level ll-kind : language-level ll-to-string : language-level → string ll-to-string ll-term = "term" ll-to-string ll-type = "type" ll-to-string ll-kind = "kind" is-rho-plus : optPlus → 𝔹 is-rho-plus RhoPlus = tt is-rho-plus _ = ff split-var-h : 𝕃 char → 𝕃 char × 𝕃 char split-var-h [] = [] , [] split-var-h (qual-global-chr :: xs) = [] , xs split-var-h (x :: xs) with split-var-h xs ... | xs' , ys = (x :: xs') , ys split-var : var → var × var split-var v with split-var-h (reverse (string-to-𝕃char v)) ... | xs , ys = 𝕃char-to-string (reverse ys) , 𝕃char-to-string (reverse xs) var-suffix : var → maybe var var-suffix v with split-var v ... | "" , _ = nothing ... | _ , sfx = just sfx -- unique qualif domain prefixes qual-pfxs : qualif → 𝕃 var qual-pfxs q = uniq (prefixes (trie-strings q)) where uniq : 𝕃 var → 𝕃 var uniq vs = stringset-strings (stringset-insert* empty-stringset vs) prefixes : 𝕃 var → 𝕃 var prefixes [] = [] prefixes (v :: vs) with split-var v ... | "" , sfx = vs ... | pfx , sfx = pfx :: prefixes vs unqual-prefix : qualif → 𝕃 var → var → var → var unqual-prefix q [] sfx v = v unqual-prefix q (pfx :: pfxs) sfx v with trie-lookup q (pfx # sfx) ... | just (v' , _) = if v =string v' then pfx # sfx else v ... | nothing = v unqual-bare : qualif → var → var → var unqual-bare q sfx v with trie-lookup q sfx ... | just (v' , _) = if v =string v' then sfx else v ... | nothing = v unqual-local : var → var unqual-local v = f' (string-to-𝕃char v) where f : 𝕃 char → maybe (𝕃 char) f [] = nothing f ('@' :: t) = f t maybe-or just t f (h :: t) = f t f' : 𝕃 char → string f' (meta-var-pfx :: t) = maybe-else' (f t) v (𝕃char-to-string ∘ _::_ meta-var-pfx) f' t = maybe-else' (f t) v 𝕃char-to-string unqual-all : qualif → var → string unqual-all q v with var-suffix v ... | nothing = v ... | just sfx = unqual-bare q sfx (unqual-prefix q (qual-pfxs q) sfx v) erased-params : params → 𝕃 string erased-params (ParamsCons (Decl _ _ Erased x (Tkt _) _) ps) with var-suffix x ... | nothing = x :: erased-params ps ... | just x' = x' :: erased-params ps erased-params (ParamsCons p ps) = erased-params ps erased-params ParamsNil = [] lam-expand-term : params → term → term lam-expand-term (ParamsCons (Decl _ _ me x tk _) ps) t = Lam posinfo-gen (if tk-is-type tk then me else Erased) posinfo-gen x (SomeClass tk) (lam-expand-term ps t) lam-expand-term ParamsNil t = t lam-expand-type : params → type → type lam-expand-type (ParamsCons (Decl _ _ me x tk _) ps) t = TpLambda posinfo-gen posinfo-gen x tk (lam-expand-type ps t) lam-expand-type ParamsNil t = t abs-expand-type : params → type → type abs-expand-type (ParamsCons (Decl _ _ me x tk _) ps) t = Abs posinfo-gen (if tk-is-type tk then me else All) posinfo-gen x tk (abs-expand-type ps t) abs-expand-type ParamsNil t = t abs-expand-type' : params → type → type abs-expand-type' (ParamsCons (Decl _ _ me x tk _) ps) t = Abs posinfo-gen (if tk-is-type tk then me else All) posinfo-gen x tk (abs-expand-type' ps t) abs-expand-type' ParamsNil t = t abs-expand-kind : params → kind → kind abs-expand-kind (ParamsCons (Decl _ _ me x tk _) ps) k = KndPi posinfo-gen posinfo-gen x tk (abs-expand-kind ps k) abs-expand-kind ParamsNil k = k args-length : args → ℕ args-length (ArgsCons p ps) = suc (args-length ps) args-length ArgsNil = 0 erased-args-length : args → ℕ erased-args-length (ArgsCons (TermArg NotErased _) ps) = suc (erased-args-length ps) erased-args-length (ArgsCons (TermArg Erased _) ps) = erased-args-length ps erased-args-length (ArgsCons (TypeArg _) ps) = erased-args-length ps erased-args-length ArgsNil = 0 me-args-length : maybeErased → args → ℕ me-args-length Erased = erased-args-length me-args-length NotErased = args-length spineApp : Set spineApp = qvar × 𝕃 arg term-to-spapp : term → maybe spineApp term-to-spapp (App t me t') = term-to-spapp t ≫=maybe (λ { (v , as) → just (v , TermArg me t' :: as) }) term-to-spapp (AppTp t T) = term-to-spapp t ≫=maybe (λ { (v , as) → just (v , TypeArg T :: as) }) term-to-spapp (Var _ v) = just (v , []) term-to-spapp _ = nothing type-to-spapp : type → maybe spineApp type-to-spapp (TpApp T T') = type-to-spapp T ≫=maybe (λ { (v , as) → just (v , TypeArg T' :: as) }) type-to-spapp (TpAppt T t) = type-to-spapp T ≫=maybe (λ { (v , as) → just (v , TermArg NotErased t :: as) }) type-to-spapp (TpVar _ v) = just (v , []) type-to-spapp _ = nothing spapp-term : spineApp → term spapp-term (v , []) = Var posinfo-gen v spapp-term (v , TermArg me t :: as) = App (spapp-term (v , as)) me t spapp-term (v , TypeArg T :: as) = AppTp (spapp-term (v , as)) T spapp-type : spineApp → type spapp-type (v , []) = TpVar posinfo-gen v spapp-type (v , TermArg me t :: as) = TpAppt (spapp-type (v , as)) t spapp-type (v , TypeArg T :: as) = TpApp (spapp-type (v , as)) T num-gt : num → ℕ → 𝕃 string num-gt n n' = maybe-else [] (λ n'' → if n'' > n' then [ n ] else []) (string-to-ℕ n) nums-gt : nums → ℕ → 𝕃 string nums-gt (NumsStart n) n' = num-gt n n' nums-gt (NumsNext n ns) n' = maybe-else [] (λ n'' → if n'' > n' || iszero n'' then [ n ] else []) (string-to-ℕ n) ++ nums-gt ns n' nums-to-stringset : nums → stringset × 𝕃 string {- Repeated numbers -} nums-to-stringset (NumsStart n) = stringset-insert empty-stringset n , [] nums-to-stringset (NumsNext n ns) with nums-to-stringset ns ...| ss , rs = if stringset-contains ss n then ss , n :: rs else stringset-insert ss n , rs optNums-to-stringset : optNums → maybe stringset × (ℕ → maybe string) optNums-to-stringset NoNums = nothing , λ _ → nothing optNums-to-stringset (SomeNums ns) with nums-to-stringset ns ...| ss , [] = just ss , λ n → case nums-gt ns n of λ where [] → nothing ns-g → just ("Occurrences not found: " ^ 𝕃-to-string id ", " ns-g ^ " (total occurrences: " ^ ℕ-to-string n ^ ")") ...| ss , rs = just ss , λ n → just ("The list of occurrences contains the following repeats: " ^ 𝕃-to-string id ", " rs) ------------------------------------------------------ -- any delta contradiction → boolean contradiction ------------------------------------------------------ nlam : ℕ → term → term nlam 0 t = t nlam (suc n) t = mlam ignored-var (nlam n t) delta-contra-app : ℕ → (ℕ → term) → term delta-contra-app 0 nt = mvar "x" delta-contra-app (suc n) nt = mapp (delta-contra-app n nt) (nt n) delta-contrahh : ℕ → trie ℕ → trie ℕ → var → var → 𝕃 term → 𝕃 term → maybe term delta-contrahh n ls rs x1 x2 as1 as2 with trie-lookup ls x1 | trie-lookup rs x2 ...| just n1 | just n2 = let t1 = nlam (length as1) (mlam "x" (mlam "y" (mvar "x"))) t2 = nlam (length as2) (mlam "x" (mlam "y" (mvar "y"))) in if n1 =ℕ n2 then nothing else just (mlam "x" (delta-contra-app n (λ n → if n =ℕ n1 then t1 else if n =ℕ n2 then t2 else id-term))) ...| _ | _ = nothing {-# TERMINATING #-} delta-contrah : ℕ → trie ℕ → trie ℕ → term → term → maybe term delta-contrah n ls rs (Lam _ _ _ x1 _ t1) (Lam _ _ _ x2 _ t2) = delta-contrah (suc n) (trie-insert ls x1 n) (trie-insert rs x2 n) t1 t2 delta-contrah n ls rs (Lam _ _ _ x1 _ t1) t2 = delta-contrah (suc n) (trie-insert ls x1 n) (trie-insert rs x1 n) t1 (mapp t2 (mvar x1)) delta-contrah n ls rs t1 (Lam _ _ _ x2 _ t2) = delta-contrah (suc n) (trie-insert ls x2 n) (trie-insert rs x2 n) (mapp t1 (mvar x2)) t2 delta-contrah n ls rs t1 t2 with decompose-apps t1 | decompose-apps t2 ...| Var _ x1 , as1 | Var _ x2 , as2 = delta-contrahh n ls rs x1 x2 as1 as2 ...| _ | _ = nothing -- For terms t1 and t2, given that check-beta-inequiv t1 t2 ≡ tt, -- delta-contra produces a function f such that f t1 ≡ tt and f t2 ≡ ff -- If it returns nothing, no contradiction could be found delta-contra : term → term → maybe term delta-contra = delta-contrah 0 empty-trie empty-trie -- postulate: check-beta-inequiv t1 t2 ≡ isJust (delta-contra t1 t2) check-beta-inequiv : term → term → 𝔹 check-beta-inequiv t1 t2 = isJust (delta-contra t1 t2) tk-map : tk → (type → type) → (kind → kind) → tk tk-map (Tkt T) fₜ fₖ = Tkt $ fₜ T tk-map (Tkk k) fₜ fₖ = Tkk $ fₖ k tk-map2 : tk → (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → tk tk-map2 atk f = tk-map atk f f optTerm-map : optTerm → (term → term) → optTerm optTerm-map NoTerm f = NoTerm optTerm-map (SomeTerm t pi) f = SomeTerm (f t) pi optType-map : optType → (type → type) → optType optType-map NoType f = NoType optType-map (SomeType T) f = SomeType $ f T optGuide-map : optGuide → (var → type → type) → optGuide optGuide-map NoGuide f = NoGuide optGuide-map (Guide pi x T) f = Guide pi x $ f x T optClass-map : optClass → (tk → tk) → optClass optClass-map NoClass f = NoClass optClass-map (SomeClass atk) f = SomeClass $ f atk
36.853139
150
0.654975
39d21f97c11a072e4ef15c55a16b63b0bbf1511b
4,384
agda
Agda
Categories/Monoidal/Helpers.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Monoidal/Helpers.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Monoidal/Helpers.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
{-# OPTIONS --universe-polymorphism #-} module Categories.Monoidal.Helpers where open import Data.Nat using (_+_) open import Function using (flip) open import Categories.Category import Categories.Functor open import Categories.Bifunctor hiding (identityˡ; identityʳ; assoc) renaming (id to idF; _≡_ to _≡F_; _∘_ to _∘F_) open import Categories.NaturalIsomorphism open import Categories.NaturalTransformation using (_∘₀_; _∘₁_; _∘ˡ_; _∘ʳ_; NaturalTransformation) renaming (_≡_ to _≡ⁿ_; id to idⁿ) module MonoidalHelperFunctors {o ℓ e} (C : Category o ℓ e) (—⊗— : Bifunctor C C C) (id : Category.Obj C) where private module C = Category C open C hiding (id; identityˡ; identityʳ) import Categories.Power.NaturalTransformation private module PowNat = Categories.Power.NaturalTransformation C open PowNat private module ⊗ = Functor —⊗— renaming (F₀ to ⊗₀; F₁ to ⊗₁; F-resp-≡ to ⊗-resp-≡) open ⊗ infix 2 _⊗_ _⊗_ : ∀ {n m} (F : Powerendo n) (G : Powerendo m) → Powerendo (n + m) _⊗_ = reduce —⊗— _⊗₂_ : ∀ {m} (F G : Powerendo m) → Powerendo m _⊗₂_ = overlaps {C} —⊗— -- reduce (flip-bifunctor {C = C} {C} —⊗—) id↑ : Powerendo 0 id↑ = nullary id x : Powerendo 1 x = unary (idF {C = C}) id⊗x : Powerendo 1 id⊗x = id↑ ⊗ x x⊗id : Powerendo 1 x⊗id = x ⊗ id↑ x⊗y : Powerendo 2 x⊗y = binary —⊗— y⊗x : Powerendo 2 y⊗x = binary (flip-bifunctor {C = C} {C} —⊗—) [x⊗y]⊗z : Powerendo 3 [x⊗y]⊗z = x⊗y ⊗ x x⊗[y⊗z] : Powerendo 3 x⊗[y⊗z] = x ⊗ x⊗y [y⊗z]⊗x : Powerendo 3 [y⊗z]⊗x = (select 1 ⊗₂ select 2) ⊗₂ select 0 [y⊗x]⊗z : Powerendo 3 [y⊗x]⊗z = (select 1 ⊗₂ select 0) ⊗₂ select 2 y⊗[x⊗z] : Powerendo 3 y⊗[x⊗z] = select 1 ⊗₂ (select 0 ⊗₂ select 2) y⊗[z⊗x] : Powerendo 3 y⊗[z⊗x] = select 1 ⊗₂ (select 2 ⊗₂ select 0) z⊗[x⊗y] : Powerendo 3 z⊗[x⊗y] = select 2 ⊗₂ (select 0 ⊗₂ select 1) x⊗[z⊗y] : Powerendo 3 x⊗[z⊗y] = select 0 ⊗₂ (select 2 ⊗₂ select 1) [x⊗z]⊗y : Powerendo 3 [x⊗z]⊗y = (select 0 ⊗₂ select 2) ⊗₂ select 1 [z⊗x]⊗y : Powerendo 3 [z⊗x]⊗y = (select 2 ⊗₂ select 0) ⊗₂ select 1 [x⊗id]⊗y : Powerendo 2 [x⊗id]⊗y = x⊗id ⊗ x x⊗[id⊗y] : Powerendo 2 x⊗[id⊗y] = x ⊗ id⊗x [[x⊗y]⊗z]⊗w : Powerendo 4 [[x⊗y]⊗z]⊗w = [x⊗y]⊗z ⊗ x [x⊗y]⊗[z⊗w] : Powerendo 4 [x⊗y]⊗[z⊗w] = x⊗y ⊗ x⊗y x⊗[y⊗[z⊗w]] : Powerendo 4 x⊗[y⊗[z⊗w]] = x ⊗ x⊗[y⊗z] x⊗[[y⊗z]⊗w] : Powerendo 4 x⊗[[y⊗z]⊗w] = x ⊗ [x⊗y]⊗z [x⊗[y⊗z]]⊗w : Powerendo 4 [x⊗[y⊗z]]⊗w = x⊗[y⊗z] ⊗ x infix 2 _⊗ⁿ_ _⊗ⁿ_ : ∀ {n} {F F′ : Powerendo n} (φ : NaturalTransformation F F′) {m} {G G′ : Powerendo m} (γ : NaturalTransformation G G′) → NaturalTransformation (F ⊗ G) (F′ ⊗ G′) _⊗ⁿ_ = reduceN —⊗— infix 2 _⊗ⁿ′_ _⊗ⁿ′_ : ∀ {n} {F F′ : Powerendo n} (φ : NaturalTransformation F F′) {G G′ : Powerendo n} (γ : NaturalTransformation G G′) → NaturalTransformation (F ⊗₂ G) (F′ ⊗₂ G′) _⊗ⁿ′_ = overlapN —⊗— id₂ : NaturalTransformation x x id₂ = idⁿ id3 : {F : Powerendo 3} → NaturalTransformation F F id3 = idⁿ module Coherence (identityˡ : NaturalIsomorphism id⊗x x) (identityʳ : NaturalIsomorphism x⊗id x) (assoc : NaturalIsomorphism [x⊗y]⊗z x⊗[y⊗z]) where open NaturalIsomorphism identityˡ using () renaming (F⇒G to υˡ) open NaturalIsomorphism identityʳ using () renaming (F⇒G to υʳ) open NaturalIsomorphism assoc using () renaming (F⇒G to α) α-over : ∀ {n₁ n₂ n₃} (F₁ : Powerendo n₁) (F₂ : Powerendo n₂) (F₃ : Powerendo n₃) → NaturalTransformation ((F₁ ⊗ F₂) ⊗ F₃) (reduce2ʳ —⊗— F₁ F₂ F₃) α-over F₁ F₂ F₃ = α ∘ʳ ((hyp F₁ ∥ hyp F₂) ∥ hyp F₃) TriangleLeftSide : NaturalTransformation [x⊗id]⊗y x⊗y TriangleLeftSide = υʳ ⊗ⁿ id₂ TriangleTopSide : NaturalTransformation [x⊗id]⊗y x⊗[id⊗y] TriangleTopSide = α-over x id↑ x TriangleRightSide : NaturalTransformation x⊗[id⊗y] x⊗y TriangleRightSide = id₂ ⊗ⁿ υˡ PentagonNWSide : NaturalTransformation [[x⊗y]⊗z]⊗w [x⊗y]⊗[z⊗w] PentagonNWSide = α-over x⊗y x x PentagonNESide : NaturalTransformation [x⊗y]⊗[z⊗w] x⊗[y⊗[z⊗w]] PentagonNESide = α-over x x x⊗y PentagonSWSide : NaturalTransformation [[x⊗y]⊗z]⊗w [x⊗[y⊗z]]⊗w PentagonSWSide = α ⊗ⁿ id₂ PentagonSSide : NaturalTransformation [x⊗[y⊗z]]⊗w x⊗[[y⊗z]⊗w] PentagonSSide = α-over x x⊗y x PentagonSESide : NaturalTransformation x⊗[[y⊗z]⊗w] x⊗[y⊗[z⊗w]] PentagonSESide = id₂ ⊗ⁿ α
28.283871
168
0.604471
236b959c6ab8ead59c722ed9de1a0f8c735d64ba
99
agda
Agda
test/Fail/FlatDomInequality-2.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/FlatDomInequality-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/FlatDomInequality-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module FlatDomInequality-2 where postulate A : Set h : (@♭ x : A) → A h x = x q : A → A q = h
9
32
0.545455
0bf316a6aa6d83c6f0357c1cafd373325ebb80a0
2,284
agda
Agda
src/LibraBFT/Impl/OBM/Logging/Logging.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/OBM/Logging/Logging.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/Impl/OBM/Logging/Logging.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- 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 open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Interface.Output open import LibraBFT.ImplShared.Util.Dijkstra.All open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) module LibraBFT.Impl.OBM.Logging.Logging where -- NOTE: Logging operations change the structure of the program, and proofs about peer -- operations are sensitive to this structure. Therefore, we add a "skeleton" of -- logging operations so that future refinements do not break existing proofs. -- In the future, we may wish to model and reason about errors and logging in more detail. postulate -- TODO-1 : errText : Note, the existing Agda ErrLog constructors do not contain text. errText : ErrLog → List String errText' : ErrLog → String logErr : ErrLog → LBFT Unit logErr x = tell (LogErr x ∷ []) logInfo : InfoLog → LBFT Unit logInfo x = tell (LogInfo x ∷ []) logEE : ∀ {A} → List String → LBFT A → LBFT A logEE _ f = logInfo fakeInfo >> f >>= λ r → logInfo fakeInfo >> pure r withErrCtx : List String → ErrLog → ErrLog withErrCtx _ = id withErrCtx' : ∀ {A} → List String → Either ErrLog A → Either ErrLog A withErrCtx' ctx = λ where (Left e) → Left (withErrCtx ctx e) (Right b) → pure b withErrCtxD' : ∀ {ℓ} {E : Set → Set → Set ℓ} ⦃ _ : EitherLike E ⦄ → ∀ {A : Set} → List String → E ErrLog A → EitherD ErrLog A withErrCtxD' ctx e = case toEither e of λ where (Left e) → fromEither $ Left (withErrCtx ctx e) (Right b) → fromEither $ Right b lcheck : ∀ {ℓ} {B : Set ℓ} ⦃ _ : ToBool B ⦄ → B → List String → Either ErrLog Unit lcheck b t = case check (toBool b) t of λ where (Left e) → Left fakeErr -- (ErrL [e]) (Right r) → Right r lcheckInfo : ∀ {ℓ} {B : Set ℓ} ⦃ _ : ToBool B ⦄ → B → List String → Either ErrLog Unit lcheckInfo b t = case check (toBool b) t of λ where (Left _) → Left (ErrInfo fakeInfo {-InfoL [e]-}) (Right r) → Right r
38.066667
111
0.662434
50ef6fde0c3abaa8adc98a70323547b9a5240614
93
agda
Agda
test/LaTeXAndHTML/succeed/Issue2756.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/LaTeXAndHTML/succeed/Issue2756.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/LaTeXAndHTML/succeed/Issue2756.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue2756 where module M where postulate A : Set module M′ = M B : Set B = M′.A
8.454545
22
0.645161
fba40f9a8266e2e0089b07b0e1534ba4d92a718c
932
agda
Agda
src/Algebra/Linear/Morphism/Definitions.agda
felko/linear-algebra
d87c5a1eb5dd0569238272e67bce1899616b789a
[ "MIT" ]
15
2019-11-02T14:11:00.000Z
2020-12-30T06:18:08.000Z
src/Algebra/Linear/Morphism/Definitions.agda
felko/linear-algebra
d87c5a1eb5dd0569238272e67bce1899616b789a
[ "MIT" ]
null
null
null
src/Algebra/Linear/Morphism/Definitions.agda
felko/linear-algebra
d87c5a1eb5dd0569238272e67bce1899616b789a
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel) open import Algebra.Structures.Bundles.Field module Algebra.Linear.Morphism.Definitions {k ℓᵏ} (K : Field k ℓᵏ) {a} (A : Set a) {b} (B : Set b) {ℓ} (_≈_ : Rel B ℓ) where open import Algebra.Linear.Core open import Function import Algebra.Morphism as Morphism open Morphism.Definitions A B _≈_ private K' : Set k K' = Field.Carrier K Linear : Morphism -> VectorAddition A -> ScalarMultiplication K' A -> VectorAddition B -> ScalarMultiplication K' B -> Set _ Linear ⟦_⟧ _+₁_ _∙₁_ _+₂_ _∙₂_ = ∀ (a b : K') (u v : A) -> ⟦ (a ∙₁ u) +₁ (b ∙₁ v) ⟧ ≈ ((a ∙₂ ⟦ u ⟧) +₂ (b ∙₂ ⟦ v ⟧)) ScalarHomomorphism : Morphism -> ScalarMultiplication K' A -> ScalarMultiplication K' B -> Set _ ScalarHomomorphism ⟦_⟧ _∙_ _∘_ = ∀ (c : K') (u : A) -> ⟦ c ∙ u ⟧ ≈ (c ∘ ⟦ u ⟧)
25.189189
78
0.56867
c58ae86f7a4b6520f2e0a7a325d1178df79a3180
1,351
agda
Agda
Cubical/HITs/Truncation/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/Truncation/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/Truncation/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Truncation.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Nat open import Cubical.Data.NatMinusOne open import Cubical.HITs.Nullification open import Cubical.HITs.Sn -- For the hub-and-spoke construction discussed in the HoTT book, which doesn't work in the base case -- of contractibility, see `HITs.Truncation.FromNegOne`. The definition of truncation here contains -- two more constructors which are redundant when n ≥ 1 but give contractibility when n = 0. -- data hLevelTrunc {ℓ} (n : HLevel) (A : Type ℓ) : Type (ℓ-max ℓ ℓ') where -- -- the hub-and-spoke definition in `Truncation.FromNegOne` -- ∣_∣ : A → hLevelTrunc n A -- hub : (f : S (-1+ n) → hLevelTrunc n A) → hLevelTrunc n A -- spoke : (f : S (-1+ n) → hLevelTrunc n A) (s : S) → hub f ≡ f s -- -- two additional constructors needed to ensure that hLevelTrunc 0 A is contractible -- ≡hub : ∀ {x y} (p : S (-1+ n) → x ≡ y) → x ≡ y -- ≡spoke : ∀ {x y} (p : S (-1+ n) → x ≡ y) (s : S (-1+ n)) → ≡hub p ≡ p s hLevelTrunc : ∀ {ℓ} → HLevel → Type ℓ → Type ℓ hLevelTrunc n A = Null (S (-1+ n)) A -- Note that relative to the HoTT book, this notation is off by +2 ∥_∥_ : ∀ {ℓ} → Type ℓ → HLevel → Type ℓ ∥ A ∥ n = hLevelTrunc n A
45.033333
101
0.655811
3940727469147333502bce00213e9325274ea2e8
12,572
agda
Agda
Cubical/Foundations/HLevels.agda
scott-fleischman/cubical
337ce3883449862c2d27380b36a2a7b599ef9f0d
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels.agda
scott-fleischman/cubical
337ce3883449862c2d27380b36a2a7b599ef9f0d
[ "MIT" ]
null
null
null
Cubical/Foundations/HLevels.agda
scott-fleischman/cubical
337ce3883449862c2d27380b36a2a7b599ef9f0d
[ "MIT" ]
null
null
null
{- Basic theory about h-levels/n-types: - Basic properties of isContr, isProp and isSet (definitions are in Prelude) - Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq -} {-# OPTIONS --cubical --safe #-} module Cubical.Foundations.HLevels where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.FunExtEquiv open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Foundations.HAEquiv using (congEquiv) open import Cubical.Foundations.Equiv using (isoToEquiv; isPropIsEquiv; retEq; invEquiv) open import Cubical.Foundations.Univalence using (ua; univalence) open import Cubical.Data.Sigma using (ΣPathP; sigmaPath→pathSigma; pathSigma≡sigmaPath; _Σ≡T_) open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-comm) private variable ℓ ℓ' : Level A : Type ℓ B : A → Type ℓ x y : A n : ℕ hProp : ∀ ℓ → Type (ℓ-suc ℓ) hProp ℓ = Σ (Type ℓ) isProp isOfHLevel : ℕ → Type ℓ → Type ℓ isOfHLevel 0 A = isContr A isOfHLevel 1 A = isProp A isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y) isOfHLevelDep : ℕ → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') isOfHLevelDep 0 {A = A} B = {a : A} → B a isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1 isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1) isOfHLevel→isOfHLevelDep : {n : ℕ} → {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B isOfHLevel→isOfHLevelDep {n = 0} {A = A} {B} h {a} = h a .fst isOfHLevel→isOfHLevelDep {n = 1} {A = A} {B} h = λ b0 b1 p → isProp→PathP h p b0 b1 isOfHLevel→isOfHLevelDep {n = suc (suc n)} {A = A} {B} h {a0} {a1} b0 b1 = isOfHLevel→isOfHLevelDep {n = suc n} {B = λ p → PathP (λ i → B (p i)) b0 b1} λ p → helper a1 p b1 where helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1) helper a1 p b1 = J (λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)) (λ _ → h _ _ _) p b1 HLevel : ∀ ℓ → ℕ → Type (ℓ-suc ℓ) HLevel ℓ n = Σ[ A ∈ Type ℓ ] (isOfHLevel n A) inhProp→isContr : A → isProp A → isContr A inhProp→isContr x h = x , h x isPropIsProp : isProp (isProp A) isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i -- A retract of a contractible type is contractible retractIsContr : ∀ {B : Type ℓ} → (f : A → B) (g : B → A) → (h : (x : A) → g (f x) ≡ x) → (v : isContr B) → isContr A retractIsContr f g h (b , p) = (g b , λ x → (cong g (p (f x))) ∙ (h x)) retractIsProp : {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isProp B → isProp A retractIsProp f g h p x y i = hcomp (λ j → λ { (i = i0) → h x j ; (i = i1) → h y j}) (g (p (f x) (f y) i)) retractIsOfHLevel : (n : ℕ) {B : Type ℓ} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isOfHLevel n B → isOfHLevel n A retractIsOfHLevel 0 = retractIsContr retractIsOfHLevel 1 = retractIsProp retractIsOfHLevel (suc (suc n)) f g h ofLevel x y = retractIsOfHLevel (suc n) (cong f) (λ q i → hcomp (λ j → λ { (i = i0) → h x j ; (i = i1) → h y j}) (g (q i))) (λ p k i → hcomp (λ j → λ { (i = i0) → h x (j ∨ k) ; (i = i1) → h y (j ∨ k) ; (k = i1) → p i}) (h (p i) k)) (ofLevel (f x) (f y)) isContrSigma : isContr A → ((x : A) → isContr (B x)) → isContr (Σ[ x ∈ A ] B x) isContrSigma {A = A} {B = B} (a , p) q = let h : (x : A) (y : B x) → (q x) .fst ≡ y h x y = (q x) .snd y in (( a , q a .fst) , ( λ x i → p (x .fst) i , h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i)) isProp→isPropPathP : (∀ a → isProp (B a)) → (m : x ≡ y) (g : B x) (h : B y) → isProp (PathP (λ i → B (m i)) g h) isProp→isPropPathP {B = B} {x = x} isPropB m = J P d m where P : ∀ σc → x ≡ σc → _ P _ m = ∀ g h → isProp (PathP (λ i → B (m i)) g h) d : P x refl d = isProp→isSet (isPropB x) isProp→isContrPathP : (∀ a → isProp (B a)) → (m : x ≡ y) (g : B x) (h : B y) → isContr (PathP (λ i → B (m i)) g h) isProp→isContrPathP isPropB m g h = inhProp→isContr (isProp→PathP isPropB m g h) (isProp→isPropPathP isPropB m g h) isProp→isContr≡ : isProp A → (x y : A) → isContr (x ≡ y) isProp→isContr≡ isPropA x y = inhProp→isContr (isPropA x y) (isProp→isSet isPropA x y) isContrPath : isContr A → (x y : A) → isContr (x ≡ y) isContrPath cA = isProp→isContr≡ (isContr→isProp cA) -- Π preserves propositionality in the following sense: propPi : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x) propPi h f0 f1 i x = h x (f0 x) (f1 x) i ΣProp≡ : ((x : A) → isProp (B x)) → {u v : Σ[ a ∈ A ] B a} → (p : u .fst ≡ v .fst) → u ≡ v ΣProp≡ pB {u} {v} p i = (p i) , isProp→PathP pB p (u .snd) (v .snd) i isPropSigma : isProp A → ((x : A) → isProp (B x)) → isProp (Σ[ x ∈ A ] B x) isPropSigma pA pB t u = ΣProp≡ pB (pA (t .fst) (u .fst)) hLevelPi : ∀ n → ((x : A) → isOfHLevel n (B x)) → isOfHLevel n ((x : A) → B x) hLevelPi 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i hLevelPi {B = B} 1 h f g i x = (h x) (f x) (g x) i hLevelPi (suc (suc n)) h f g = subst (isOfHLevel (suc n)) funExtPath (hLevelPi (suc n) λ x → h x (f x) (g x)) isSetPi : ((x : A) → isSet (B x)) → isSet ((x : A) → B x) isSetPi Bset = hLevelPi 2 (λ a → Bset a) isSet→isSet' : isSet A → isSet' A isSet→isSet' {A = A} Aset {x} {y} {z} {w} p q r s = transport (squeezeSq≡ r p q s) (Aset _ _ p (r ∙∙ q ∙∙ sym s)) isSet'→isSet : isSet' A → isSet A isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl squeezeCu≡ : ∀{w x y z w' x' y' z' : A} → {p : w ≡ y} {q : w ≡ x} {r : y ≡ z} {s : x ≡ z} → {p' : w' ≡ y'} {q' : w' ≡ x'} {r' : y' ≡ z'} {s' : x' ≡ z'} → {a : w ≡ w'} {b : x ≡ x'} {c : y ≡ y'} {d : z ≡ z'} → (ps : Square a p p' c) (qs : Square a q q' b) → (rs : Square c r r' d) (ss : Square b s s' d) → (f0 : Square p q r s) (f1 : Square p' q' r' s') → (f0 ≡ transport⁻ (λ k → Square (ps k) (qs k) (rs k) (ss k)) f1) ≡ Cube ps qs rs ss f0 f1 squeezeCu≡ ps qs rs ss f0 f1 τ = Cube (λ j → ps (j ∧ τ)) (λ j → qs (j ∧ τ)) (λ j → rs (j ∧ τ)) (λ j → ss (j ∧ τ)) f0 (toPathP {A = λ k → Square (ps k) (qs k) (rs k) (ss k)} (transportTransport⁻ (λ k → Square (ps k) (qs k) (rs k) (ss k)) f1) τ) isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A isGroupoid→isGroupoid' Agpd ps qs rs ss f0 f1 = transport ( squeezeCu≡ (λ _ → refl) f0 f1' (λ _ → refl) (λ _ → f0 i0) (λ _ → f1' i1) ∙ transpose≡ ∙ squeezeCu≡ ps qs rs ss f0 f1 ) (Agpd (ps i0 i0) (ss i0 i0) (f0 i0) (f1' i0) refl rs') where Sq = λ k → Square (ps k) (qs k) (rs k) (ss k) f1' = transport⁻ Sq f1 rs' = transport⁻ (λ k → Square refl (f0 k) (f1' k) refl) (λ _ → f1' i1) transpose≡ : Cube (λ i _ → ps i0 i) f0 f1' (λ i _ → ss i0 i) refl refl ≡ Cube refl refl refl refl f0 f1' transpose≡ = ua ((λ cu i j → cu j i) , λ where .equiv-proof cu → ((λ i j → cu j i) , refl) , (λ{ (cu' , p) → λ k → (λ j i → p (~ k) i j) , λ τ → p (~ k ∨ τ) })) isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A isGroupoid'→isGroupoid Agpd' w x p q r s = Agpd' {q = p} {r = q} {q' = p} {r' = q} refl refl refl refl r s hLevelSuc : (n : ℕ) (A : Type ℓ) → isOfHLevel n A → isOfHLevel (suc n) A hLevelSuc 0 A = isContr→isProp hLevelSuc 1 A = isProp→isSet hLevelSuc (suc (suc n)) A h a b = hLevelSuc (suc n) (a ≡ b) (h a b) hLevelLift : (m : ℕ) (hA : isOfHLevel n A) → isOfHLevel (m + n) A hLevelLift zero hA = hA hLevelLift {A = A} (suc m) hA = hLevelSuc _ A (hLevelLift m hA) isPropIsOfHLevel : (n : ℕ) (A : Type ℓ) → isProp (isOfHLevel n A) isPropIsOfHLevel 0 A = isPropIsContr isPropIsOfHLevel 1 A = isPropIsProp isPropIsOfHLevel (suc (suc n)) A f g i a b = isPropIsOfHLevel (suc n) (a ≡ b) (f a b) (g a b) i isPropIsSet : isProp (isSet A) isPropIsSet {A = A} = isPropIsOfHLevel 2 A HLevel≡ : ∀ {A B : Type ℓ} {hA : isOfHLevel n A} {hB : isOfHLevel n B} → (A ≡ B) ≡ ((A , hA) ≡ (B , hB)) HLevel≡ {n = n} {A = A} {B = B} {hA} {hB} = isoToPath (iso intro elim intro-elim elim-intro) where intro : A ≡ B → (A , hA) ≡ (B , hB) intro eq = ΣProp≡ (λ A → isPropIsOfHLevel n _) eq elim : (A , hA) ≡ (B , hB) → A ≡ B elim = cong fst intro-elim : ∀ x → intro (elim x) ≡ x intro-elim eq = cong ΣPathP (ΣProp≡ (λ e → J (λ B e → ∀ k → (x y : PathP (λ i → isOfHLevel n (e i)) hA k) → x ≡ y) (λ k → isProp→isSet (isPropIsOfHLevel n _) _ _) e hB) refl) elim-intro : ∀ x → elim (intro x) ≡ x elim-intro eq = refl -- H-level for Σ-types isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x)) → isOfHLevel n (Σ A B) isOfHLevelΣ zero h1 h2 = let center = (fst h1 , fst (h2 (fst h1))) in let p : ∀ x → center ≡ x p = λ x → sym (sigmaPath→pathSigma _ _ (sym (snd h1 (fst x)) , sym (snd (h2 (fst h1)) _))) in (center , p) isOfHLevelΣ 1 h1 h2 x y = sigmaPath→pathSigma x y ((h1 _ _) , (h2 _ _ _)) isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y = let h3 : isOfHLevel (suc n) (x Σ≡T y) h3 = isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ p → h2 (p i1) (subst B p (snd x)) (snd y) in transport (λ i → isOfHLevel (suc n) (pathSigma≡sigmaPath x y (~ i))) h3 hLevel≃ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B) hLevel≃ zero {A = A} {B = B} hA hB = A≃B , contr where A≃B : A ≃ B A≃B = isoToEquiv (iso (λ _ → fst hB) (λ _ → fst hA) (snd hB ) (snd hA)) contr : (y : A ≃ B) → A≃B ≡ y contr y = ΣProp≡ isPropIsEquiv (funExt (λ a → snd hB (fst y a))) hLevel≃ (suc n) hA hB = isOfHLevelΣ (suc n) (hLevelPi (suc n) (λ _ → hB)) (λ a → subst (λ n → isOfHLevel n (isEquiv a)) (+-comm n 1) (hLevelLift n (isPropIsEquiv a))) hLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : ℕ) → A ≃ B → isOfHLevel n A → isOfHLevel n B hLevelRespectEquiv 0 eq hA = ( fst eq (fst hA) , λ b → cong (fst eq) (snd hA (eq .snd .equiv-proof b .fst .fst)) ∙ eq .snd .equiv-proof b .fst .snd) hLevelRespectEquiv 1 eq hA x y i = hcomp (λ j → λ { (i = i0) → retEq eq x j ; (i = i1) → retEq eq y j }) (cong (eq .fst) (hA (invEquiv eq .fst x) (invEquiv eq .fst y)) i) hLevelRespectEquiv {A = A} {B = B} (suc (suc n)) eq hA x y = hLevelRespectEquiv (suc n) (invEquiv (congEquiv (invEquiv eq))) (hA _ _) hLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≡ B) hLevel≡ n hA hB = hLevelRespectEquiv n (invEquiv univalence) (hLevel≃ n hA hB) hLevelHLevel1 : isProp (HLevel ℓ 0) hLevelHLevel1 x y = ΣProp≡ (λ _ → isPropIsContr) ((hLevel≡ 0 (x .snd) (y .snd) .fst)) hLevelHLevelSuc : ∀ n → isOfHLevel (suc (suc n)) (HLevel ℓ (suc n)) hLevelHLevelSuc n x y = subst (λ e → isOfHLevel (suc n) e) HLevel≡ (hLevel≡ (suc n) (snd x) (snd y)) hProp≡HLevel1 : hProp ℓ ≡ HLevel ℓ 1 hProp≡HLevel1 {ℓ} = isoToPath (iso intro elim intro-elim elim-intro) where intro : hProp ℓ → HLevel ℓ 1 intro h = fst h , snd h elim : HLevel ℓ 1 → hProp ℓ elim h = (fst h) , (snd h) intro-elim : ∀ h → intro (elim h) ≡ h intro-elim h = ΣProp≡ (λ _ → isPropIsOfHLevel 1 _) refl elim-intro : ∀ h → elim (intro h) ≡ h elim-intro h = ΣProp≡ (λ _ → isPropIsProp) refl isSetHProp : isSet (hProp ℓ) isSetHProp = subst (λ X → isOfHLevel 2 X) (sym hProp≡HLevel1) (hLevelHLevelSuc 0) isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ} → (extend : ∀ φ → Partial φ A → A) → (∀ u → u ≡ (extend i1 λ { _ → u})) → isContr A isContrPartial→isContr {A = A} extend law = ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y) where ex = extend i0 empty module Aux (y : A) (i : I) where φ = ~ i ∨ i u : Partial φ A u = λ { (i = i0) → ex ; (i = i1) → y } v = extend φ u isOfHLevelLift : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A) isOfHLevelLift n = retractIsOfHLevel n lower lift λ _ → refl
36.44058
150
0.541203
50484ce9839918f2ca9188e117888151749a176d
14,387
agda
Agda
old/Homotopy/Cover/HomotopyGroupSetIsomorphism.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Homotopy/Cover/HomotopyGroupSetIsomorphism.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Homotopy/Cover/HomotopyGroupSetIsomorphism.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import Base open import Homotopy.Pointed open import Homotopy.Connected module Homotopy.Cover.HomotopyGroupSetIsomorphism {i} (A⋆ : pType i) (A⋆-is-conn : is-connected⋆ ⟨0⟩ A⋆) where open pType A⋆ renaming (∣_∣ to A ; ⋆ to a) open import Algebra.Groups open import Homotopy.Truncation open import Homotopy.HomotopyGroups {i} open import Homotopy.PathTruncation open import Homotopy.Cover.Def A open import Homotopy.Cover.Ribbon A⋆ private module G = group (fundamental-group A⋆) open import Algebra.GroupSets (fundamental-group A⋆) {- Isomorphism between pi1(A)-sets and coverings. -} gset⇒covering : gset → covering gset⇒covering gset[ _ , act , _ ] = cov[ ribbon act , ribbon-is-set ] covering⇒action : ∀ cov → action (covering.fiber cov a) covering⇒action cov = act[ tracing cov , (λ _ → refl) , compose-tracing cov ] covering⇒gset : covering → gset covering⇒gset cov = let open covering cov in gset[ fiber a , covering⇒action cov , fiber-is-set a ] -- The first direction: covering -> gset -> covering -- From 0-connectedness we can get a (-1)-truncated base path. -- The challenge is to get this path. abstract [base-path] : ∀ a₂ → [ a ≡ a₂ ] [base-path] = connected-has-all-τ-paths A⋆-is-conn a -- Part 1: Show that the generated cover (ribbon) is fiberwisely -- equivalent to the original fiber. private module _ (cov : covering) where -- Suppose that we get the path, we can compute the ribbon easily. fiber+path⇒ribbon : ∀ a₂ (y : covering.fiber cov a₂) (p : a ≡ a₂) → ribbon (covering⇒action cov) a₂ fiber+path⇒ribbon a₂ y p = trace (tracing cov y (proj $ ! p)) (proj p) abstract -- Our construction is "constant" with respect to paths. fiber+path⇒ribbon-is-path-irrelevant : ∀ a₂ (y : covering.fiber cov a₂) (p₁ p₂ : a ≡ a₂) → fiber+path⇒ribbon a₂ y p₁ ≡ fiber+path⇒ribbon a₂ y p₂ fiber+path⇒ribbon-is-path-irrelevant .a y p refl = trace (tracing cov y (proj $ ! p)) (proj p) ≡⟨ paste y (proj $ ! p) (proj p) ⟩ trace y (proj $ (! p ∘ p)) ≡⟨ ap (λ x → trace y (proj x)) $ opposite-left-inverse p ⟩∎ trace y refl₀ ∎ -- Call the magical factorization library. open import Homotopy.Extensions.ToPropToConstSet -- Now we can read the (-1)-truncated path. fiber+path₋₁⇒ribbon : ∀ a₂ (y : covering.fiber cov a₂) → [ a ≡ a₂ ] → ribbon (covering⇒action cov) a₂ fiber+path₋₁⇒ribbon a₂ y = cst-extend ⦃ ribbon-is-set a₂ ⦄ (fiber+path⇒ribbon a₂ y) (fiber+path⇒ribbon-is-path-irrelevant a₂ y) -- So the conversion from fiber to ribbon is done. fiber⇒ribbon : ∀ cov a₂ → covering.fiber cov a₂ → ribbon (covering⇒action cov) a₂ fiber⇒ribbon cov a₂ y = fiber+path₋₁⇒ribbon cov a₂ y $ [base-path] a₂ -- The other direction is easy. ribbon⇒fiber : ∀ cov a₂ → ribbon (covering⇒action cov) a₂ → covering.fiber cov a₂ ribbon⇒fiber cov a₂ = let open covering cov in ribbon-rec-nondep a₂ (fiber a₂) ⦃ fiber-is-set a₂ ⦄ (tracing cov) (compose-tracing cov) private -- Some routine computations. abstract ribbon⇒fiber⇒ribbon : ∀ cov a₂ r → fiber⇒ribbon cov a₂ (ribbon⇒fiber cov a₂ r) ≡ r ribbon⇒fiber⇒ribbon cov a₂ = ribbon-rec a₂ (λ r → fiber⇒ribbon cov a₂ (ribbon⇒fiber cov a₂ r) ≡ r) ⦃ λ _ → ≡-is-set $ ribbon-is-set a₂ ⦄ (λ y p → []-extend -- All ugly things will go away when bp = proj bp′ ⦃ λ bp → ribbon-is-set a₂ (fiber+path₋₁⇒ribbon cov a₂ (tracing cov y p) bp) (trace y p) ⦄ (lemma a₂ y p) ([base-path] a₂)) (λ _ _ _ → prop-has-all-paths (ribbon-is-set a₂ _ _) _ _) where abstract lemma : ∀ a₂ (y : covering.fiber cov a) (p : a ≡₀ a₂) (bp : a ≡ a₂) → trace {act = covering⇒action cov} (tracing cov (tracing cov y p) (proj $ ! bp)) (proj bp) ≡ trace y p lemma .a y p refl = trace (tracing cov y p) refl₀ ≡⟨ paste y p refl₀ ⟩ trace y (p ∘₀ refl₀) ≡⟨ ap (trace y) $ refl₀-right-unit p ⟩∎ trace y p ∎ fiber⇒ribbon⇒fiber : ∀ cov a₂ y → ribbon⇒fiber cov a₂ (fiber⇒ribbon cov a₂ y) ≡ y fiber⇒ribbon⇒fiber cov a₂ y = let open covering cov in []-extend -- All ugly things will go away when bp = proj bp′ ⦃ λ bp → fiber-is-set a₂ (ribbon⇒fiber cov a₂ (fiber+path₋₁⇒ribbon cov a₂ y bp)) y ⦄ (lemma a₂ y) ([base-path] a₂) where abstract lemma : ∀ a₂ (y : covering.fiber cov a₂) (bp : a ≡ a₂) → tracing cov (tracing cov y (proj $ ! bp)) (proj bp) ≡ y lemma .a y refl = refl covering⇒gset⇒covering : ∀ cov → gset⇒covering (covering⇒gset cov) ≡ cov covering⇒gset⇒covering cov = covering-eq $ funext λ a₂ → eq-to-path $ ribbon⇒fiber cov a₂ , iso-is-eq (ribbon⇒fiber cov a₂) (fiber⇒ribbon cov a₂) (fiber⇒ribbon⇒fiber cov a₂) (ribbon⇒fiber⇒ribbon cov a₂) -- The second direction : gset -> covering -> gset -- Part 2.1: The fiber over the point a is the carrier. ribbon-a⇒Y : ∀ {Y} {act : action Y} ⦃ _ : is-set Y ⦄ → ribbon act a → Y ribbon-a⇒Y {Y} {act} ⦃ Y-is-set ⦄ = let open action act in ribbon-rec-nondep a Y ⦃ Y-is-set ⦄ _∙_ assoc ribbon-a≃Y : ∀ {Y} {act : action Y} ⦃ _ : is-set Y ⦄ → ribbon act a ≃ Y ribbon-a≃Y {Y} {act} ⦃ Y-is-set ⦄ = let open action act in ribbon-a⇒Y ⦃ Y-is-set ⦄ , iso-is-eq _ (λ y → trace y refl₀) (λ y → right-unit y) (ribbon-rec a (λ r → trace (ribbon-a⇒Y ⦃ Y-is-set ⦄ r) refl₀ ≡ r) ⦃ λ _ → ≡-is-set $ ribbon-is-set a ⦄ (λ y p → trace (y ∙ p) refl₀ ≡⟨ paste y p refl₀ ⟩ trace y (p G.∙ refl₀) ≡⟨ ap (trace y) $ G.right-unit p ⟩∎ trace y p ∎) (λ _ _ _ → prop-has-all-paths (ribbon-is-set a _ _) _ _)) private -- Some lemmas to simplify the proofs. trans-eq-∙ : ∀ {Y₁ Y₂ : Set i} (Y≃ : Y₁ ≃ Y₂) (_∙_ : Y₁ → G.carrier → Y₁) (y₂ : Y₂) (g : G.carrier) → transport (λ Y → Y → G.carrier → Y) (eq-to-path Y≃) _∙_ y₂ g ≡ (Y≃ ☆ (inverse Y≃ y₂ ∙ g)) trans-eq-∙ = equiv-induction (λ {Y₁ Y₂ : Set i} (Y≃ : Y₁ ≃ Y₂) → ∀ (_∙_ : Y₁ → G.carrier → Y₁) (y₂ : Y₂) (g : G.carrier) → transport (λ Y → Y → G.carrier → Y) (eq-to-path Y≃) _∙_ y₂ g ≡ (Y≃ ☆ (inverse Y≃ y₂ ∙ g))) (λ Y _∙_ y₂ g → ap (λ x → transport (λ Y → Y → G.carrier → Y) x _∙_ y₂ g) $ path-to-eq-right-inverse refl) gset⇒covering⇒gset : ∀ gs → covering⇒gset (gset⇒covering gs) ≡ gs gset⇒covering⇒gset gset[ Y , act , Y-is-set ] = let open action act _⊙_ = tracing cov[ ribbon act , ribbon-is-set {Y} {act} ] ≃Y = ribbon-a≃Y ⦃ Y-is-set ⦄ ⇒Y = ribbon-a⇒Y ⦃ Y-is-set ⦄ in gset-eq (eq-to-path ≃Y) (funext λ y → funext $ π₀-extend ⦃ λ _ → ≡-is-set Y-is-set ⦄ λ p → transport (λ Y → Y → G.carrier → Y) (eq-to-path ≃Y) _⊙_ y (proj p) ≡⟨ trans-eq-∙ ≃Y _⊙_ y (proj p) ⟩ ⇒Y (transport (ribbon act) p (trace y refl₀)) ≡⟨ ap ⇒Y $ trans-trace act p y refl₀ ⟩∎ y ∙ proj p ∎) -- Finally... gset-covering-eq : gset ≃ covering gset-covering-eq = gset⇒covering , iso-is-eq _ covering⇒gset covering⇒gset⇒covering gset⇒covering⇒gset {- Universality of the covering generated by the fundamental group itself. -} -- FIXME What's the established terminology for this? canonical-gset : gset canonical-gset = record { carrier = G.carrier ; act = record { _∙_ = _∘₀_ ; right-unit = refl₀-right-unit ; assoc = concat₀-assoc } ; set = π₀-is-set (a ≡ a) } -- FIXME What's the established terminology for this? canonical-covering : covering canonical-covering = gset⇒covering canonical-gset private module Universality where open covering canonical-covering open gset canonical-gset center′ : Σ A fiber center′ = (a , trace {act = act} refl₀ refl₀) center : τ ⟨1⟩ (Σ A fiber) center = proj center′ private -- An ugly lemma for this development only trans-fiber≡cst-proj-Σ-eq : ∀ {i} (P : Set i) (Q : P → Set i) (a : P) (c : Σ P Q) {b₁ b₂} (p : b₁ ≡ b₂) (q : a ≡ π₁ c) (r : transport Q q b₁ ≡ π₂ c) → transport (λ r → (a , r) ≡₀ c) p (proj $ Σ-eq q r) ≡ proj (Σ-eq q (ap (transport Q q) (! p) ∘ r)) trans-fiber≡cst-proj-Σ-eq P Q a c refl q r = refl abstract path-trace-fiber : ∀ {a₂} y (p : a ≡ a₂) → transport fiber (! p ∘ ! y) (trace (proj y) (proj p)) ≡ trace refl₀ refl₀ path-trace-fiber y refl = transport fiber (! y) (trace (proj y) refl₀) ≡⟨ trans-trace act (! y) (proj y) refl₀ ⟩ trace (proj y) (proj $ ! y) ≡⟨ paste refl₀ (proj y) (proj $ ! y) ⟩ trace refl₀ (proj $ y ∘ ! y) ≡⟨ ap (trace refl₀ ◯ proj) $ opposite-right-inverse y ⟩∎ trace refl₀ refl₀ ∎ path-trace : ∀ {a₂} y p → (a₂ , trace {act = act} y p) ≡₀ center′ path-trace {a₂} = π₀-extend ⦃ λ y → Π-is-set λ p → π₀-is-set ((a₂ , trace y p) ≡ center′) ⦄ (λ y → π₀-extend ⦃ λ p → π₀-is-set ((a₂ , trace (proj y) p) ≡ center′) ⦄ (λ p → proj $ Σ-eq (! p ∘ ! y) (path-trace-fiber y p))) abstract path-paste′ : ∀ {a₂} y loop p → transport (λ r → (a₂ , r) ≡₀ center′) (paste (proj y) (proj loop) (proj p)) (path-trace (proj $ y ∘ loop) (proj p)) ≡ path-trace (proj y) (proj $ loop ∘ p) path-paste′ y loop refl = transport (λ r → (a , r) ≡₀ center′) (paste (proj y) (proj loop) refl₀) (proj $ Σ-eq (! (y ∘ loop)) (path-trace-fiber (y ∘ loop) refl)) ≡⟨ trans-fiber≡cst-proj-Σ-eq A fiber a center′ (paste (proj y) (proj loop) refl₀) (! (y ∘ loop)) (path-trace-fiber (y ∘ loop) refl) ⟩ proj (Σ-eq (! (y ∘ loop)) _) ≡⟨ ap proj $ ap2 (λ p q → Σ-eq p q) (! (y ∘ loop) ≡⟨ opposite-concat y loop ⟩ ! loop ∘ ! y ≡⟨ ap (λ x → ! x ∘ ! y) $ ! $ refl-right-unit loop ⟩∎ ! (loop ∘ refl) ∘ ! y ∎) (prop-has-all-paths (ribbon-is-set a _ _) _ _) ⟩∎ proj (Σ-eq (! (loop ∘ refl) ∘ ! y) (path-trace-fiber y (loop ∘ refl))) ∎ abstract path-paste : ∀ {a₂} y loop p → transport (λ r → (a₂ , r) ≡₀ center′) (paste y loop p) (path-trace (y ∘₀ loop) p) ≡ path-trace y (loop ∘₀ p) path-paste {a₂} = π₀-extend ⦃ λ y → Π-is-set λ loop → Π-is-set λ p → ≡-is-set $ π₀-is-set _ ⦄ (λ y → π₀-extend ⦃ λ loop → Π-is-set λ p → ≡-is-set $ π₀-is-set _ ⦄ (λ loop → π₀-extend ⦃ λ p → ≡-is-set $ π₀-is-set _ ⦄ (λ p → path-paste′ y loop p))) path′ : (y : Σ A fiber) → proj {n = ⟨1⟩} y ≡ center path′ y = τ-path-equiv-path-τ-S {n = ⟨0⟩} ☆ ribbon-rec {act = act} (π₁ y) (λ r → (π₁ y , r) ≡₀ center′) ⦃ λ r → π₀-is-set ((π₁ y , r) ≡ center′) ⦄ path-trace path-paste (π₂ y) path : (y : τ ⟨1⟩ (Σ A fiber)) → y ≡ center path = τ-extend {n = ⟨1⟩} ⦃ λ _ → ≡-is-truncated ⟨1⟩ $ τ-is-truncated ⟨1⟩ _ ⦄ path′ canonical-covering-is-universal : is-universal canonical-covering canonical-covering-is-universal = Universality.center , Universality.path -- The other direction: If a covering is universal, then the fiber -- is equivalent to the fundamental group. module _ (cov : covering) (cov-is-universal : is-universal cov) where open covering cov open action (covering⇒action cov) -- We need a point! module GiveMeAPoint (center : fiber a) where -- Goal: fiber a <-> fundamental group fiber-a⇒fg : fiber a → a ≡₀ a fiber-a⇒fg y = ap₀ π₁ $ connected-has-all-τ-paths cov-is-universal (a , center) (a , y) fg⇒fiber-a : a ≡₀ a → fiber a fg⇒fiber-a = tracing cov center fg⇒fiber-a⇒fg : ∀ p → fiber-a⇒fg (fg⇒fiber-a p) ≡ p fg⇒fiber-a⇒fg = π₀-extend ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄ λ p → ap₀ π₁ (connected-has-all-τ-paths cov-is-universal (a , center) (a , transport fiber p center)) ≡⟨ ap (ap₀ π₁) $ ! $ π₂ (connected-has-connected-paths cov-is-universal _ _) (proj $ Σ-eq p refl) ⟩ ap₀ π₁ (proj $ Σ-eq p refl) ≡⟨ ap proj $ base-path-Σ-eq p refl ⟩∎ proj p ∎ fiber-a⇒fg⇒fiber-a : ∀ y → fg⇒fiber-a (fiber-a⇒fg y) ≡ y fiber-a⇒fg⇒fiber-a y = π₀-extend ⦃ λ p → ≡-is-set {x = tracing cov center (ap₀ π₁ p)} {y = y} $ fiber-is-set a ⦄ (λ p → transport fiber (base-path p) center ≡⟨ trans-base-path p ⟩∎ y ∎) (connected-has-all-τ-paths cov-is-universal (a , center) (a , y)) fiber-a≃fg : fiber a ≃ (a ≡₀ a) fiber-a≃fg = fiber-a⇒fg , iso-is-eq _ fg⇒fiber-a fg⇒fiber-a⇒fg fiber-a⇒fg⇒fiber-a -- This is the best we can obtain, because there is no continuous -- choice of the center. [center] : [ fiber a ] [center] = τ-extend-nondep ⦃ prop-is-gpd []-is-prop ⦄ (λ y → []-extend-nondep ⦃ []-is-prop ⦄ (proj ◯ λ p → transport fiber p (π₂ y)) (connected-has-all-τ-paths A⋆-is-conn (π₁ y) a)) (π₁ cov-is-universal) -- [ isomorphism between the fiber and the fundamental group ] -- This is the best we can obtain, because there is no continuous -- choice of the center. [fiber-a≃fg] : [ fiber a ≃ (a ≡₀ a) ] [fiber-a≃fg] = []-extend-nondep ⦃ []-is-prop ⦄ (proj ◯ GiveMeAPoint.fiber-a≃fg) [center]
38.778976
103
0.529019
cb97bdeaf8356b7b980a769a243a1b4d0801f371
1,732
agda
Agda
archive/agda-3/src/Test/SymmetricalSubstitunction.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-3/src/Test/SymmetricalSubstitunction.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-3/src/Test/SymmetricalSubstitunction.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
open import Everything {- open import Oscar.Prelude open import Oscar.Class.HasEquivalence open import Oscar.Class.Symmetrical open import Oscar.Data.Term open import Oscar.Data.Substitunction open import Oscar.Data.Surjcollation open import Oscar.Data.Surjextenscollation open import Oscar.Data.Proposequality import Oscar.Class.HasEquivalence.ExtensionṖroperty import Oscar.Class.HasEquivalence.Ṗroperty import Oscar.Class.Symmetrical.ExtensionalUnifies import Oscar.Class.Symmetrical.Unifies import Oscar.Property.Setoid.Proposequality -- FIXME see _∼⁰_ below; comment this out to observe confusing error messages import Oscar.Property.Functor.SubstitunctionExtensionTerm import Oscar.Class.Surjection.⋆ -} module Test.SymmetricalSubstitunction {𝔭} (𝔓 : Ø 𝔭) (ℓ : Ł) where open Term 𝔓 using () renaming ( Term to 𝑩; Terms to 𝑩') open Substitunction 𝔓 using () renaming ( Substitunction to 𝑪) infix 18 _∼⁰_ _∼⁰_ = ≡-surjcollation⟦ 𝑪 ⟧ -- ≡-Unifies₀⟦ 𝑪 ⟧ -- FIXME gives a confusing error message -- _∼⁰_ = ≡-SymUnifies₀⟦ 𝑪 ⟧ -- FIXME gives a more useful error message open Surjextenscollation 𝑪 _≡̇_ renaming (_⟹_ to _∼¹_) fact1⋆ : ∀ {𝓃} (𝓈 𝓉 : 𝑩 𝓃) → 𝓈 ∼⁰ 𝓉 ≈ 𝓉 ∼⁰ 𝓈 fact1⋆ 𝓈 𝓉 = symmetrical 𝓈 𝓉 -- fact1⋆ 𝓈 𝓉 = symmetrical ⦃ r = Oscar.Class.Symmetrical.Unifies.𝓢ymmetricalUnifies₀ ⦃ ! ⦄ ⦃ ! ⦄ ⦃ Oscar.Property.Setoid.Proposequality.𝓢ymmetryProposequality ⦄ ⦄ 𝓈 𝓉 -- FIXME I wish Agda would tell us that this is how the instances were resolved fact1⋆s : ∀ {N 𝓃} (𝓈 𝓉 : 𝑩' N 𝓃) → 𝓈 ∼⁰ 𝓉 ≈ 𝓉 ∼⁰ 𝓈 fact1⋆s 𝓈 𝓉 = symmetrical 𝓈 𝓉 fact1 : ∀ {𝓃} (𝓈 𝓉 : 𝑩 𝓃) → 𝓈 ∼¹ 𝓉 ≈ 𝓉 ∼¹ 𝓈 fact1 𝓈 𝓉 = symmetrical 𝓈 𝓉 fact1s : ∀ {N 𝓃} (𝓈 𝓉 : 𝑩' N 𝓃) → 𝓈 ∼¹ 𝓉 ≈ 𝓉 ∼¹ 𝓈 fact1s 𝓈 𝓉 = symmetrical 𝓈 𝓉
36.851064
249
0.713048
c5c93ba809e480b2a797ed2a3e0c13ae7c9deacf
1,652
agda
Agda
misc/Everything.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
misc/Everything.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
misc/Everything.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Imports every module so that it is easy to see if everything builds ------------------------------------------------------------------------ module Everything where import Parallel import Parallel.Examples import Parallel.Index import Parallel.Lib import RecursiveDescent.Coinductive import RecursiveDescent.Coinductive.Examples import RecursiveDescent.Coinductive.Internal import RecursiveDescent.Coinductive.Lib import RecursiveDescent.Hybrid import RecursiveDescent.Hybrid.Examples import RecursiveDescent.Hybrid.Lib -- import RecursiveDescent.Hybrid.Memoised -- Agda is too slow... import RecursiveDescent.Hybrid.Memoised.Monad import RecursiveDescent.Hybrid.Mixfix hiding (module Expr) -- Necessary due to an Agda bug. import RecursiveDescent.Hybrid.Mixfix.Example import RecursiveDescent.Hybrid.Mixfix.Expr import RecursiveDescent.Hybrid.Mixfix.Fixity import RecursiveDescent.Hybrid.PBM import RecursiveDescent.Hybrid.Simple import RecursiveDescent.Hybrid.Type import RecursiveDescent.Index import RecursiveDescent.Inductive import RecursiveDescent.Inductive.Char import RecursiveDescent.Inductive.Examples import RecursiveDescent.Inductive.Internal import RecursiveDescent.Inductive.Lib import RecursiveDescent.Inductive.Semantics import RecursiveDescent.Inductive.SimpleLib import RecursiveDescent.Inductive.Token import RecursiveDescent.InductiveWithFix import RecursiveDescent.InductiveWithFix.Examples import RecursiveDescent.InductiveWithFix.Internal import RecursiveDescent.InductiveWithFix.Lib import RecursiveDescent.InductiveWithFix.PBM import Utilities
38.418605
72
0.799637
231ff8ff8561c40daefe120da10bb3c4f3b38260
4,162
agda
Agda
Cubical/HITs/FiniteMultiset/Properties.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/FiniteMultiset/Properties.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
Cubical/HITs/FiniteMultiset/Properties.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.FiniteMultiset.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Nat open import Cubical.Relation.Nullary open import Cubical.HITs.FiniteMultiset.Base open import Cubical.Structures.MultiSet open import Cubical.Relation.Nullary.DecidableEq private variable A : Type₀ infixr 30 _++_ _++_ : ∀ (xs ys : FMSet A) → FMSet A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ xs ++ ys comm x y xs i ++ ys = comm x y (xs ++ ys) i trunc xs zs p q i j ++ ys = trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j unitl-++ : ∀ (xs : FMSet A) → [] ++ xs ≡ xs unitl-++ xs = refl unitr-++ : ∀ (xs : FMSet A) → xs ++ [] ≡ xs unitr-++ = ElimProp.f (trunc _ _) refl (λ x p → cong (_∷_ x) p) assoc-++ : ∀ (xs ys zs : FMSet A) → xs ++ (ys ++ zs) ≡ (xs ++ ys) ++ zs assoc-++ = ElimProp.f (isPropΠ2 (λ _ _ → trunc _ _)) (λ ys zs → refl) (λ x p ys zs → cong (_∷_ x) (p ys zs)) cons-++ : ∀ (x : A) (xs : FMSet A) → x ∷ xs ≡ xs ++ [ x ] cons-++ x = ElimProp.f (trunc _ _) refl (λ y {xs} p → comm x y xs ∙ cong (_∷_ y) p) comm-++ : ∀ (xs ys : FMSet A) → xs ++ ys ≡ ys ++ xs comm-++ = ElimProp.f (isPropΠ (λ _ → trunc _ _)) (λ ys → sym (unitr-++ ys)) (λ x {xs} p ys → cong (x ∷_) (p ys) ∙ cong (_++ xs) (cons-++ x ys) ∙ sym (assoc-++ ys [ x ] xs)) module FMSetUniversal {ℓ} {M : Type ℓ} (MSet : isSet M) (e : M) (_⊗_ : M → M → M) (comm-⊗ : ∀ x y → x ⊗ y ≡ y ⊗ x) (assoc-⊗ : ∀ x y z → x ⊗ (y ⊗ z) ≡ (x ⊗ y) ⊗ z) (unit-⊗ : ∀ x → e ⊗ x ≡ x) (f : A → M) where f-extend : FMSet A → M f-extend = Rec.f MSet e (λ x m → f x ⊗ m) (λ x y m → comm-⊗ (f x) (f y ⊗ m) ∙ sym (assoc-⊗ (f y) m (f x)) ∙ cong (f y ⊗_) (comm-⊗ m (f x))) f-extend-nil : f-extend [] ≡ e f-extend-nil = refl f-extend-cons : ∀ x xs → f-extend (x ∷ xs) ≡ f x ⊗ f-extend xs f-extend-cons x xs = refl f-extend-sing : ∀ x → f-extend [ x ] ≡ f x f-extend-sing x = comm-⊗ (f x) e ∙ unit-⊗ (f x) f-extend-++ : ∀ xs ys → f-extend (xs ++ ys) ≡ f-extend xs ⊗ f-extend ys f-extend-++ = ElimProp.f (isPropΠ λ _ → MSet _ _) (λ ys → sym (unit-⊗ (f-extend ys))) (λ x {xs} p ys → cong (f x ⊗_) (p ys) ∙ assoc-⊗ (f x) (f-extend xs) (f-extend ys)) module _ (h : FMSet A → M) (h-nil : h [] ≡ e) (h-sing : ∀ x → h [ x ] ≡ f x) (h-++ : ∀ xs ys → h (xs ++ ys) ≡ h xs ⊗ h ys) where f-extend-unique : h ≡ f-extend f-extend-unique = funExt (ElimProp.f (MSet _ _) h-nil (λ x {xs} p → (h-++ [ x ] xs) ∙ cong (_⊗ h xs) (h-sing x) ∙ cong (f x ⊗_) p)) -- We want to construct a multiset-structure on FMSet A, the empty set and insertion are given by the constructors, -- for the membership part we use the recursor -- Is there a way around the auxillary functions with the with-syntax? FMSmember-∷*-aux : (a x : A) → Dec (a ≡ x) → ℕ → ℕ FMSmember-∷*-aux a x (yes a≡x) n = suc n FMSmember-∷*-aux a x (no a≢x) n = n FMSmember-comm*-aux : (a x y : A) (n : ℕ) (p : Dec (a ≡ x)) (q : Dec (a ≡ y)) → FMSmember-∷*-aux a x p (FMSmember-∷*-aux a y q n) ≡ FMSmember-∷*-aux a y q (FMSmember-∷*-aux a x p n) FMSmember-comm*-aux a x y n (yes a≡x) (yes a≡y) = refl FMSmember-comm*-aux a x y n (yes a≡x) (no a≢y) = refl FMSmember-comm*-aux a x y n (no a≢x) (yes a≡y) = refl FMSmember-comm*-aux a x y n (no a≢x) (no a≢y) = refl -- If A has decidable equality we can define the member-function: module _(discA : Discrete A) where FMSmember-∷* : A → A → ℕ → ℕ FMSmember-∷* a x n = FMSmember-∷*-aux a x (discA a x) n FMSmember-comm* : (a x y : A) (n : ℕ) → FMSmember-∷* a x (FMSmember-∷* a y n) ≡ FMSmember-∷* a y (FMSmember-∷* a x n) FMSmember-comm* a x y n = FMSmember-comm*-aux a x y n (discA a x) (discA a y) FMSmember : A → FMSet A → ℕ FMSmember a = Rec.f isSetℕ 0 (FMSmember-∷* a) (FMSmember-comm* a) FMS-with-str : Multi-Set A (Discrete→isSet discA) FMS-with-str = (FMSet A , [] , _∷_ , FMSmember)
35.87931
115
0.525949
1cf672c6a850bb233851c6f73a2f28624bcc5d33
334
agda
Agda
examples/outdated-and-incorrect/Alonzo/PreludeInt.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/Alonzo/PreludeInt.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/Alonzo/PreludeInt.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module PreludeInt where open import AlonzoPrelude import RTP int : Nat -> Int int = RTP.primNatToInt _+_ : Int -> Int -> Int _+_ = RTP.primIntAdd _-_ : Int -> Int -> Int _-_ = RTP.primIntSub _*_ : Int -> Int -> Int _*_ = RTP.primIntMul div : Int -> Int -> Int div = RTP.primIntDiv mod : Int -> Int -> Int mod = RTP.primIntMod
13.916667
25
0.640719
1ca916cbbe2f749c0039240393e418f9a50d35ae
1,367
agda
Agda
Cubical/Algebra/RingSolver/CommRingAsAlmostRing.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/RingSolver/CommRingAsAlmostRing.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/RingSolver/CommRingAsAlmostRing.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Algebra.RingSolver.CommRingAsAlmostRing where open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRing.Base open import Cubical.Algebra.RingSolver.AlmostRing open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Ring.Base open import Cubical.Algebra.Ring.Properties private variable ℓ : Level open Cubical.Algebra.Ring.Properties.RingTheory CommRingAsAlmostRing : CommRing ℓ → AlmostRing ℓ CommRingAsAlmostRing {ℓ} (R , commringstr _ _ _ _ _ (iscommring (isring (isabgroup (isgroup +-isMonoid inverse) +-comm) ·-isMonoid dist) ·-comm)) = let R' : CommRing ℓ R' = (R , commringstr _ _ _ _ _ (iscommring (isring (isabgroup (isgroup +-isMonoid inverse) +-comm) ·-isMonoid dist) ·-comm)) R″ = CommRing→Ring R' in almostring R _ _ _ _ _ (isalmostring +-isMonoid ·-isMonoid +-comm ·-comm (λ x y z → fst (dist x y z)) (λ x y z → snd (dist x y z)) (λ x y → sym (-DistL· R″ x y)) (λ x y → sym (-Dist R″ x y)) (λ x → 0LeftAnnihilates R″ x) λ x → 0RightAnnihilates R″ x)
29.717391
87
0.61741
2048777696af76034b2e22d499df9950f944f3c0
3,142
agda
Agda
Rings/UniqueFactorisationDomains/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Rings/UniqueFactorisationDomains/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Rings/UniqueFactorisationDomains/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Rings.Definition open import Rings.IntegralDomains.Definition open import Vectors open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Naturals.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Rings.UniqueFactorisationDomains.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) where open import Rings.Units.Definition R open import Rings.Irreducibles.Definition intDom open import Rings.Associates.Definition intDom open import Rings.Primes.Definition intDom open Ring R open Setoid S private power : A → ℕ → A power x zero = 1R power x (succ n) = x * power x n allDistinct : {n : ℕ} → Vec A n → Set (a ⊔ b) allDistinct [] = True' allDistinct (x ,- xs) = (allDistinct xs) && vecAllTrue (λ n → (n ∼ x) → False) xs record Factorisation {r : A} .(nonzero : (r ∼ 0R) → False) .(nonunit : (Unit r) → False) : Set (a ⊔ b) where field len : ℕ factorise : Vec (A && ℕ) len factoriseIsFactorisation : vecFold (λ x y → y * power (_&&_.fst x) (succ (_&&_.snd x))) 1R factorise ∼ r factoriseIsIrreducibles : vecAllTrue Irreducible (vecMap _&&_.fst factorise) distinct : allDistinct (vecMap _&&_.fst factorise) private equality : {n : ℕ} (v1 v2 : Vec (A && ℕ) n) → Set (a ⊔ b) equality [] [] = True' equality {succ n} ((a ,, an) ,- v1) v2 = Sg ℕ (λ index → Sg (index <N succ n) (λ i<n → (Associates (_&&_.fst (vecIndex v2 index i<n)) a) && ((_&&_.snd (vecIndex v2 index i<n) ≡ an) && equality v1 (vecDelete index i<n v2)))) factorisationEquality : {r : A} → .{nonzero : (r ∼ 0R) → False} → .{nonunit : (Unit r) → False} → Factorisation nonzero nonunit → Factorisation nonzero nonunit → Set (a ⊔ b) factorisationEquality record { len = lenA ; factorise = factoriseA ; factoriseIsFactorisation = factoriseIsFactorisationA ; factoriseIsIrreducibles = factoriseIsIrreduciblesA ; distinct = distinctA } record { len = lenB ; factorise = factoriseB ; factoriseIsFactorisation = factoriseIsFactorisationB ; factoriseIsIrreducibles = factoriseIsIrreduciblesB ; distinct = distinctB } with ℕDecideEquality lenA lenB factorisationEquality record { len = a ; factorise = factoriseA } record { len = .a ; factorise = factoriseB } | inl refl = equality factoriseA factoriseB factorisationEquality record { len = a ; factorise = factoriseA } record { len = b ; factorise = factoriseB } | inr _ = False' record UFD : Set (a ⊔ b) where field factorisation : {r : A} → (nonzero : (r ∼ 0R) → False) → (nonunit : (Unit r) → False) → Factorisation nonzero nonunit uniqueFactorisation : {r : A} → (nonzero : (r ∼ 0R) → False) → (nonunit : (Unit r) → False) → (f1 f2 : Factorisation nonzero nonunit) → factorisationEquality f1 f2 record UFD' : Set (a ⊔ b) where field factorisation : {r : A} → (nonzero : (r ∼ 0R) → False) → (nonunit : (Unit r) → False) → Factorisation nonzero nonunit irreduciblesArePrime : {r : A} → Irreducible r → Prime r
53.254237
408
0.683959
4d2184e028f3082858d72fd36d50e2406cb333f1
2,333
agda
Agda
test/Succeed/LinearTemporalLogic.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/LinearTemporalLogic.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/LinearTemporalLogic.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --guardedness #-} -- {-# OPTIONS -v tc.pos:20 -v tc.meta.eta:100 #-} -- {-# OPTIONS -v tc.lhs:100 #-} module LinearTemporalLogic where import Common.Level record Stream (A : Set) : Set where coinductive field head : A tail : Stream A -- Stream properties Proposition : Set → Set₁ Proposition A = Stream A → Set Now : {A : Set} → (A → Set) → Proposition A Now P s = P (Stream.head s) -- Next time ◌ : {A : Set} → Proposition A → Proposition A ◌ P s = P (Stream.tail s) -- Forever record ▢ {A : Set} (P : Proposition A) (s : Stream A) : Set where coinductive field head : P s tail : ◌ (▢ P) s -- Sometimes data ◇ {A : Set} (P : Proposition A) (s : Stream A) : Set where now : P s → ◇ P s later : ◌ (◇ P) s → ◇ P s -- Infinitely often ▢◇ : {A : Set} → Proposition A → Proposition A ▢◇ P = ▢ (◇ P) -- Next inf. often implies inf. often ◌▢◇⇒▢◇ : {A : Set}{P : Proposition A}{s : Stream A} → ◌ (▢◇ P) s → ▢◇ P s ▢.head (◌▢◇⇒▢◇ f) = later (▢.head f) ▢.tail (◌▢◇⇒▢◇ f) = ◌▢◇⇒▢◇ (▢.tail f) -- Forever implies inf. oft. ▢⇒▢◇ : {A : Set}{P : Proposition A}{s : Stream A} → ▢ P s → ▢◇ P s ▢.head (▢⇒▢◇ f) = now (▢.head f) ▢.tail (▢⇒▢◇ f) = ▢⇒▢◇ (▢.tail f) -- Eventually ◇▢ : {A : Set} → Proposition A → Proposition A ◇▢ P = ◇ (▢ P) -- Eventually implies inf. oft. ◇▢⇒▢◇ : {A : Set}{P : Proposition A}{s : Stream A} → ◇▢ P s → ▢◇ P s ◇▢⇒▢◇ (now forever) = ▢⇒▢◇ forever ◇▢⇒▢◇ (later event) = ◌▢◇⇒▢◇ (◇▢⇒▢◇ event) -- We now prove that inf. oft. does not imply eventually -- by exhibiting a counter example data ⊥ : Set where record ⊤ : Set where constructor tt data Bool : Set where true false : Bool True : Bool → Set True true = ⊤ True false = ⊥ open Stream alternate : Stream Bool ( (head alternate)) = true (head (tail alternate)) = false (tail (tail alternate)) = alternate -- alternate contains infinitely many 'true's thm1 : ▢◇ (Now True) alternate ( (▢.head thm1)) = now tt (▢.head (▢.tail thm1)) = later (now tt) (▢.tail (▢.tail thm1)) = thm1 -- alternate does not eventually contain only 'true's mutual thm2 : ◇▢ (Now True) alternate → ⊥ thm2 (now forever⊤) = ▢.head (▢.tail forever⊤) thm2 (later event) = thm2′ event thm2′ : ◇▢ (Now True) (tail alternate) → ⊥ thm2′ (now forever⊤) = ▢.head forever⊤ thm2′ (later event) = thm2 event
23.565657
65
0.568796
d085a131b1ac825dd51ed48bc5be419c57a87ade
4,215
agda
Agda
src/meta-cedille.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
35
2019-06-13T07:44:50.000Z
2021-10-12T22:59:10.000Z
src/meta-cedille.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
10
2019-06-13T17:44:43.000Z
2020-04-25T15:29:17.000Z
src/meta-cedille.agda
WhatisRT/meta-cedille
62fa6f36e4555360d94041113749bbb6d291691c
[ "MIT" ]
2
2019-06-27T23:12:48.000Z
2021-10-20T10:46:20.000Z
{-# OPTIONS --type-in-type #-} module meta-cedille where open import Data.String using (toList) open import IO using (Main; run) open import Monads.Except open import Monads.ExceptT open import Prelude open import Prelude.Strings open import Parse.Generate open import Parse.TreeConvert open import Bootstrap.InitEnv open import CoreTheory open import Execution record EvalFlags : Set where field printAnything : Bool printInfo : Bool -- print the results generated by a top level command initFlagsDefault : EvalFlags initFlagsDefault = record { printAnything = false ; printInfo = false } runtimeFlagsDefault : EvalFlags runtimeFlagsDefault = record { printAnything = true ; printInfo = true } eval : MetaContext → String → EvalFlags → IO (MetaContext × Bool) eval Γ "" _ = return (Γ , true) eval Γ input flags = let open EvalFlags flags in do (s , (inj₂ (out , _))) ← execute (parseAndExecute input) Γ where (_ , (inj₁ err)) → putStrErr err >> return (Γ , false) if printAnything ∧ printInfo then putStr $ unlines out else return tt return (contextFromState s , true) rep : MetaContext → IO MetaContext rep Γ = do putStr "\nλ> " flushStdout input ← getLine proj₁ <$> eval Γ input runtimeFlagsDefault {-# NON_TERMINATING #-} loop : ∀ {a} {A : Set a} → A → (A → IO A) → IO ⊤ loop start f = do res ← f start loop res f repl : MetaContext → IO ⊤ repl start = loop start rep record Options : Set where field startRepl : Bool importFiles : List String verbose : Bool showHelp : Bool defaultOptions : Options defaultOptions = record { startRepl = true ; importFiles = [] ; verbose = false ; showHelp = false } {-# TERMINATING #-} readOptions : ExceptT IO String Options readOptions = do args ← getArgs return $ readArgs args defaultOptions where argumentDec : Decidable _ argumentDec s = false ≟ isInit "--" (toList s) readArgs : List String → Options → Except String Options readArgs [] current = return current readArgs ("--no-repl" ∷ input) current = readArgs input record current { startRepl = false } readArgs ("--verbose" ∷ input) current = readArgs input record current { verbose = true } readArgs ("--help" ∷ input) current = readArgs input record current { showHelp = true } readArgs ("--load" ∷ input) current with span argumentDec input ... | (files , rest) = readArgs rest record current { importFiles = files } readArgs (x ∷ input) current = inj₁ ("Unknown option: " + x) helpString : String helpString = "Usage: meta-cedille [OPTIONS...]\n" + concat ((λ { (fst , snd) → " --" + padRight ' ' padLength fst + snd + "\n" }) <$> helpTable) where helpTable : List (String × String) helpTable = ("help" , "Show this help") ∷ ("load [FILES]" , "Loads a list of files before starting the REPL") ∷ ("verbose" , "Print supressed output before starting the REPL") ∷ ("no-repl" , "Exits the program when the REPL would start") ∷ [] padLength : ℕ padLength = 4 + maximum (Data.String.length ∘ proj₁ <$> helpTable) initGrammar : Grammar initGrammar = from-inj₂ $ preCoreGrammar {{Except-Monad}} {{Except-MonadExcept}} bootstrapMetaContext : MetaContext bootstrapMetaContext = emptyGlobalContext , record { grammar = initGrammar ; namespace = "" ; evaluator = Sort-A □ } loadFiles : MetaContext → EvalFlags → List String → IO (MetaContext × Bool) loadFiles context flags [] = return (context , true) loadFiles context flags files = eval context (concat $ map (λ file → "import " + file + ".") files) flags main : Main main = run $ do (inj₂ o) ← readOptions where (inj₁ x) → putStr x let open Options o in if showHelp then putStr helpString else do (init , successInit) ← eval bootstrapMetaContext initEnv initFlagsDefault let initFlags = if verbose then runtimeFlagsDefault else initFlagsDefault (postLoad , successLoad) ← loadFiles init initFlags importFiles if startRepl then repl postLoad else if successInit ∧ successLoad then exitSuccess else exitFailure
31.222222
97
0.667853
dc4fc2ff361b1829073002cfcc4a413a5ee3d311
1,208
agda
Agda
src/Examples/Resolution.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/Examples/Resolution.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/Examples/Resolution.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
module Examples.Resolution where open import Prelude open import Implicits.Syntax open import Implicits.Syntax.Type.Constructors open import Implicits.WellTyped open import Implicits.Substitutions open import Extensions.ListFirst open Rules unit = 0 -- simple implicit resolution by implication module ex₁ where r : Type zero r = ∀' (tp-weaken tnat ⇒ (TVar zero)) -- proof that the above type is a rule r-isrule : IsRule r r-isrule = ∀'-rule (rule (tp-weaken tnat) (TVar zero)) -- the context used K = tnat ∷K nil -- partial implicit resolution -- as described by Oliveira et al module ex₂ where r : Type zero r = (tnat ⇒ TC unit ⇒ TC unit) -- proof that the above type is a rule r-isrule : IsRule r r-isrule = rule tnat (TC unit ⇒ TC unit) K : Ktx 0 1 K = TC unit ∷K nil -- higher order resolution module ex₃ where r : Type zero r = ∀' ((TC unit ⇒ TVar zero) ⇒ (TVar zero ×' TVar zero)) r' : Type zero r' = (TC unit ⇒ tnat) ⇒ (tnat ×' tnat) r-isrule : IsRule r r-isrule = ∀'-rule (rule (TC unit ⇒ TVar zero) (TVar zero ×' TVar zero)) r'-isrule : IsRule r' r'-isrule = rule (TC unit ⇒ tnat) (tnat ×' tnat) K : Ktx 0 1 K = (TC unit ⇒ tnat) ∷K nil
21.963636
74
0.660596
0ba207f4e720125c810f46967b34dda323caab78
407
agda
Agda
test/asset/agda-stdlib-1.0/Data/List/All/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/All/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
test/asset/agda-stdlib-1.0/Data/List/All/Properties.agda
omega12345/agda-mode
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Unary.Any.Properties directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.All.Properties where open import Data.List.Relation.Unary.All.Properties public
31.307692
72
0.481572
20c4acaea95ab7427448a51c93c40345582e120a
10,597
agda
Agda
Cubical/HITs/Ints/QuoInt/Properties.agda
mchristianl/cubical
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/QuoInt/Properties.agda
mchristianl/cubical
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
[ "MIT" ]
null
null
null
Cubical/HITs/Ints/QuoInt/Properties.agda
mchristianl/cubical
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Ints.QuoInt.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Relation.Nullary open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc) open import Cubical.Data.Bool as Bool using (Bool; not; notnot) open import Cubical.Data.Empty open import Cubical.Data.Unit renaming (Unit to ⊤) open import Cubical.HITs.Ints.QuoInt.Base ·S-comm : ∀ x y → x ·S y ≡ y ·S x ·S-comm = Bool.⊕-comm ·S-assoc : ∀ x y z → x ·S (y ·S z) ≡ (x ·S y) ·S z ·S-assoc = Bool.⊕-assoc not-·Sˡ : ∀ x y → not (x ·S y) ≡ not x ·S y not-·Sˡ = Bool.not-⊕ˡ snotz : ∀ s n s' → ¬ (signed s (suc n) ≡ signed s' zero) snotz s n s' eq = subst (λ { (signed s (suc n)) → ⊤ ; _ → ⊥ }) eq tt +-zeroʳ : ∀ s m → m + signed s zero ≡ m +-zeroʳ s (signed s' zero) = signed-zero s s' +-zeroʳ s (pos (suc n)) = cong sucℤ (+-zeroʳ s (pos n)) +-zeroʳ s (neg (suc n)) = cong predℤ (+-zeroʳ s (neg n)) +-zeroʳ spos (posneg i) j = posneg (i ∧ j) +-zeroʳ sneg (posneg i) j = posneg (i ∨ ~ j) +-identityʳ : ∀ m → m + pos zero ≡ m +-identityʳ = +-zeroʳ spos sucℤ-+ʳ : ∀ m n → sucℤ (m + n) ≡ m + sucℤ n sucℤ-+ʳ (signed _ zero) _ = refl sucℤ-+ʳ (posneg _) _ = refl sucℤ-+ʳ (pos (suc m)) n = cong sucℤ (sucℤ-+ʳ (pos m) n) sucℤ-+ʳ (neg (suc m)) n = sucPredℤ (neg m + n) ∙∙ sym (predSucℤ (neg m + n)) ∙∙ cong predℤ (sucℤ-+ʳ (neg m) n) -- I wonder if we could somehow use negEq to get this for free from the above... predℤ-+ʳ : ∀ m n → predℤ (m + n) ≡ m + predℤ n predℤ-+ʳ (signed _ zero) _ = refl predℤ-+ʳ (posneg _) _ = refl predℤ-+ʳ (neg (suc m)) n = cong predℤ (predℤ-+ʳ (neg m) n) predℤ-+ʳ (pos (suc m)) n = predSucℤ (pos m + n) ∙∙ sym (sucPredℤ (pos m + n)) ∙∙ cong sucℤ (predℤ-+ʳ (pos m) n) +-inverseʳ : ∀ a → a + (- a) ≡ 0 +-inverseʳ (pos zero) j = posneg ( i1 ∧ ~ j) +-inverseʳ (neg zero) j = posneg ( i0 ∧ ~ j) +-inverseʳ (posneg i) j = posneg (~ i ∧ ~ j) +-inverseʳ (signed s (suc n)) = lem s (suc n) where lem : ∀ s n → signed s n + signed (not s) n ≡ 0 lem spos zero = sym posneg lem spos (suc n) = (λ i → sucℤ (predℤ-+ʳ (pos n) (neg n) (~ i))) ∙ (λ i → sucℤ (predℤ (lem spos n i))) ∙ sym posneg lem sneg zero = refl lem sneg (suc n) = (λ i → predℤ (sucℤ-+ʳ (neg n) (pos n) (~ i))) ∙ (λ i → predℤ (sucℤ (lem sneg n i))) +-comm : ∀ m n → m + n ≡ n + m +-comm (signed s zero) n = sym (+-zeroʳ s n) +-comm (pos (suc m)) n = cong sucℤ (+-comm (pos m) n) ∙ sucℤ-+ʳ n (pos m) +-comm (neg (suc m)) n = cong predℤ (+-comm (neg m) n) ∙ predℤ-+ʳ n (neg m) +-comm (posneg i) n = lemma n i where -- get some help from: -- https://www.codewars.com/kata/reviews/5c878e3ef1abb10001e32eb1/groups/5cca3f9e840f4b0001d8ac98 lemma : ∀ n → (λ i → (posneg i + n) ≡ (n + posneg i)) [ sym (+-zeroʳ spos n) ≡ sym (+-zeroʳ sneg n) ] lemma (pos zero) i j = posneg (i ∧ j) lemma (pos (suc n)) i = cong sucℤ (lemma (pos n) i) lemma (neg zero) i j = posneg (i ∨ ~ j) lemma (neg (suc n)) i = cong predℤ (lemma (neg n) i) lemma (posneg i) j k = posneg ((i ∧ ~ k) ∨ (i ∧ j) ∨ (j ∧ k)) sucℤ-+ˡ : ∀ m n → sucℤ (m + n) ≡ sucℤ m + n sucℤ-+ˡ (pos _) n = refl sucℤ-+ˡ (neg zero) n = refl sucℤ-+ˡ (neg (suc m)) n = sucPredℤ _ sucℤ-+ˡ (posneg _) n = refl -- I wonder if we could somehow use negEq to get this for free from the above... predℤ-+ˡ : ∀ m n → predℤ (m + n) ≡ predℤ m + n predℤ-+ˡ (pos zero) n = refl predℤ-+ˡ (pos (suc m)) n = predSucℤ _ predℤ-+ˡ (neg _) n = refl predℤ-+ˡ (posneg _) n = refl +-assoc : ∀ m n o → m + (n + o) ≡ m + n + o +-assoc (signed s zero) n o = refl +-assoc (posneg i) n o = refl +-assoc (pos (suc m)) n o = cong sucℤ (+-assoc (pos m) n o) ∙ sucℤ-+ˡ (pos m + n) o +-assoc (neg (suc m)) n o = cong predℤ (+-assoc (neg m) n o) ∙ predℤ-+ˡ (neg m + n) o sucℤ-inj : ∀ m n → sucℤ m ≡ sucℤ n → m ≡ n sucℤ-inj m n p = sym (predSucℤ m) ∙ cong predℤ p ∙ predSucℤ n predℤ-inj : ∀ m n → predℤ m ≡ predℤ n → m ≡ n predℤ-inj m n p = sym (sucPredℤ m) ∙ cong sucℤ p ∙ sucPredℤ n +-injˡ : ∀ o m n → o + m ≡ o + n → m ≡ n +-injˡ (signed _ zero) _ _ p = p +-injˡ (posneg _) _ _ p = p +-injˡ (pos (suc o)) m n p = +-injˡ (pos o) m n (sucℤ-inj _ _ p) +-injˡ (neg (suc o)) m n p = +-injˡ (neg o) m n (predℤ-inj _ _ p) +-injʳ : ∀ m n o → m + o ≡ n + o → m ≡ n +-injʳ m n o p = +-injˡ o m n (+-comm o m ∙ p ∙ +-comm n o) ·-comm : ∀ m n → m · n ≡ n · m ·-comm m n i = signed (·S-comm (sign m) (sign n) i) (ℕ.·-comm (abs m) (abs n) i) ·-identityˡ : ∀ n → pos 1 · n ≡ n ·-identityˡ n = cong (signed (sign n)) (ℕ.+-zero (abs n)) ∙ signed-inv n ·-identityʳ : ∀ n → n · pos 1 ≡ n ·-identityʳ n = ·-comm n (pos 1) ∙ ·-identityˡ n ·-zeroˡ : ∀ {s} n → signed s zero · n ≡ signed s zero ·-zeroˡ _ = signed-zero _ _ ·-zeroʳ : ∀ {s} n → n · signed s zero ≡ signed s zero ·-zeroʳ n = cong (signed _) (sym (ℕ.0≡m·0 (abs n))) ∙ signed-zero _ _ ·-signed-pos : ∀ {s} m n → signed s m · pos n ≡ signed s (m ℕ.· n) ·-signed-pos {s} zero n = ·-zeroˡ {s} (pos n) ·-signed-pos {s} (suc m) n i = signed (·S-comm s (sign-pos n i) i) (suc m ℕ.· n) -- this proof is why we defined ℤ using `signed` instead of `pos` and `neg` -- based on that in: https://github.com/danr/Agda-Numerics ·-assoc : ∀ m n o → m · (n · o) ≡ m · n · o ·-assoc (signed s zero) n o = ·-zeroˡ (n · o) ·-assoc m@(signed _ (suc _)) (signed s zero) o = ·-zeroʳ {sign o} m ∙ signed-zero _ _ ∙ cong (_· o) (sym (·-zeroʳ {s} m)) ·-assoc m@(signed _ (suc _)) n@(signed _ (suc _)) (signed s zero) = cong (m ·_) (·-zeroʳ {s} n) ∙ ·-zeroʳ {s} m ∙ sym (·-zeroʳ {s} (m · n)) ·-assoc (signed sm (suc m)) (signed sn (suc n)) (signed so (suc o)) i = signed (·S-assoc sm sn so i) (ℕ.·-assoc (suc m) (suc n) (suc o) i) ·-assoc (posneg i) n o j = isSet→isSet' isSetℤ (·-assoc (pos zero) n o) (·-assoc (neg zero) n o) (λ i → posneg i · (n · o)) (λ i → posneg i · n · o) i j ·-assoc m@(signed _ (suc _)) (posneg i) o j = isSet→isSet' isSetℤ (·-assoc m (pos zero) o) (·-assoc m (neg zero) o) (λ i → m · (posneg i · o)) (λ i → m · posneg i · o) i j ·-assoc m@(signed _ (suc _)) n@(signed _ (suc _)) (posneg i) j = isSet→isSet' isSetℤ (·-assoc m n (pos zero)) (·-assoc m n (neg zero)) (λ i → m · (n · posneg i)) (λ i → m · n · posneg i) i j negateSuc : ∀ n → - sucℤ n ≡ predℤ (- n) negateSuc n i = - sucℤ (negate-invol n (~ i)) negatePred : ∀ n → - predℤ n ≡ sucℤ (- n) negatePred n i = negate-invol (sucℤ (- n)) i negate-+ : ∀ m n → - (m + n) ≡ (- m) + (- n) negate-+ (signed _ zero) n = refl negate-+ (posneg _) n = refl negate-+ (pos (suc m)) n = negateSuc (pos m + n) ∙ cong predℤ (negate-+ (pos m) n) negate-+ (neg (suc m)) n = negatePred (neg m + n) ∙ cong sucℤ (negate-+ (neg m) n) negate-·ˡ : ∀ m n → - (m · n) ≡ (- m) · n negate-·ˡ (signed _ zero) n = signed-zero (not (sign n)) (sign n) negate-·ˡ (signed ss (suc m)) n i = signed (not-·Sˡ ss (sign n) i) (suc m ℕ.· abs n) negate-·ˡ (posneg i) n j = isSet→isSet' isSetℤ (signed-zero (not (sign n)) _) (signed-zero _ _) refl (λ i → posneg (~ i) · n) i j ·-neg1 : ∀ m → -1 · m ≡ - m ·-neg1 m = (λ i → signed (not (sign m)) (ℕ.+-comm (abs m) 0 i)) ∙ cong -_ (signed-inv m) signed-distrib : ∀ s m n → signed s (m ℕ.+ n) ≡ signed s m + signed s n signed-distrib s zero n = refl signed-distrib spos (suc m) n = cong sucℤ (signed-distrib spos m n) signed-distrib sneg (suc m) n = cong predℤ (signed-distrib sneg m n) ·-pos-suc : ∀ m n → pos (suc m) · n ≡ n + pos m · n ·-pos-suc m n = signed-distrib (sign n) (abs n) (m ℕ.· abs n) ∙ (λ i → signed-inv n i + signed (sign-pos m (~ i) ·S sign n) (m ℕ.· abs n)) ·-neg-suc : ∀ m n → neg (suc m) · n ≡ - n + neg m · n ·-neg-suc m n = signed-distrib (not (sign n)) (abs n) (m ℕ.· abs n) ∙ (λ i → cong -_ (signed-inv n) i + γ m i) where γ : ∀ m → signed ( not (sign n)) (m ℕ.· abs n) ≡ signed (sign (neg m) Bool.⊕ sign n) (m ℕ.· abs n) γ zero = signed-zero (not (sign n)) (sign n) γ (suc m) = refl ·-distribˡ-pos : ∀ o m n → (pos o · m) + (pos o · n) ≡ pos o · (m + n) ·-distribˡ-pos zero m n = signed-zero (sign n) (sign (m + n)) ·-distribˡ-pos (suc o) m n = pos (suc o) · m + pos (suc o) · n ≡[ i ]⟨ ·-pos-suc o m i + ·-pos-suc o n i ⟩ m + pos o · m + (n + pos o · n) ≡⟨ +-assoc (m + pos o · m) n (pos o · n) ⟩ m + pos o · m + n + pos o · n ≡[ i ]⟨ +-assoc m (pos o · m) n (~ i) + pos o · n ⟩ m + (pos o · m + n) + pos o · n ≡[ i ]⟨ m + +-comm (pos o · m) n i + pos o · n ⟩ m + (n + pos o · m) + pos o · n ≡[ i ]⟨ +-assoc m n (pos o · m) i + pos o · n ⟩ m + n + pos o · m + pos o · n ≡⟨ sym (+-assoc (m + n) (pos o · m) (pos o · n)) ⟩ m + n + (pos o · m + pos o · n) ≡⟨ cong ((m + n) +_) (·-distribˡ-pos o m n) ⟩ m + n + pos o · (m + n) ≡⟨ sym (·-pos-suc o (m + n)) ⟩ pos (suc o) · (m + n) ∎ ·-distribˡ-neg : ∀ o m n → (neg o · m) + (neg o · n) ≡ neg o · (m + n) ·-distribˡ-neg o m n = neg o · m + neg o · n ≡[ i ]⟨ negate-·ˡ (pos o) m (~ i) + negate-·ˡ (pos o) n (~ i) ⟩ - (pos o · m) + - (pos o · n) ≡⟨ sym (negate-+ (pos o · m) (pos o · n)) ⟩ - (pos o · m + pos o · n) ≡⟨ cong -_ (·-distribˡ-pos o m n) ⟩ - (pos o · (m + n)) ≡⟨ negate-·ˡ (pos o) (m + n) ⟩ neg o · (m + n) ∎ ·-distribˡ : ∀ o m n → (o · m) + (o · n) ≡ o · (m + n) ·-distribˡ (pos o) m n = ·-distribˡ-pos o m n ·-distribˡ (neg o) m n = ·-distribˡ-neg o m n ·-distribˡ (posneg i) m n j = isSet→isSet' isSetℤ (·-distribˡ-pos zero m n) (·-distribˡ-neg zero m n) (λ i → posneg i · n) (λ i → posneg i · (m + n)) i j ·-distribʳ : ∀ m n o → (m · o) + (n · o) ≡ (m + n) · o ·-distribʳ m n o = (λ i → ·-comm m o i + ·-comm n o i) ∙ ·-distribˡ o m n ∙ ·-comm o (m + n) sign-pos-suc-· : ∀ m n → sign (pos (suc m) · n) ≡ sign n sign-pos-suc-· m (signed s zero) = sign-pos (suc m ℕ.· zero) sign-pos-suc-· m (posneg i) = sign-pos (suc m ℕ.· zero) sign-pos-suc-· m (signed s (suc n)) = refl ·-injˡ : ∀ o m n → pos (suc o) · m ≡ pos (suc o) · n → m ≡ n ·-injˡ o m n p = sym (signed-inv m) ∙ (λ i → signed (sign-eq i) (abs-eq i)) ∙ signed-inv n where sign-eq = sym (sign-pos-suc-· o m) ∙ cong sign p ∙ sign-pos-suc-· o n abs-eq = ℕ.inj-sm· {o} (cong abs p) ·-injʳ : ∀ m n o → m · pos (suc o) ≡ n · pos (suc o) → m ≡ n ·-injʳ m n o p = ·-injˡ o m n (·-comm (pos (suc o)) m ∙ p ∙ ·-comm n (pos (suc o)))
41.556863
117
0.525526
cb937946de8b8b80721fcfb693e9cc60ee69bbbd
343
agda
Agda
test/Succeed/MissingDefinition.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/MissingDefinition.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/MissingDefinition.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
null
null
null
module MissingDefinition where open import Agda.Builtin.Equality Q : Set data U : Set S : Set S = U T : S → Set T _ = U V : Set W : V → Set private X : Set module AB where data A : Set B : (a b : A) → a ≡ b mutual U₂ : Set data T₂ : U₂ → Set V₂ : (u₂ : U₂) → T₂ u₂ → Set data W₂ (u₂ : U₂) (t₂ : T₂ u₂) : V₂ u₂ t₂ → Set
11.064516
49
0.553936
5018ea66e48c3cdf467466b50cef6ccc66954e76
68
agda
Agda
test/Fail/Issue586a.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue586a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue586a.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2014-09-09 {-# NON_TERMINATING #-} Foo : Set Foo = Foo
11.333333
23
0.617647
1c57c0465453855531c5fa9a73bb78818ccd2d0e
2,444
agda
Agda
Cubical/Algebra/Semigroup/Morphism.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Semigroup/Morphism.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Semigroup/Morphism.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Semigroup.Morphism where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Functions.Embedding open import Cubical.Algebra open import Cubical.Algebra.Magma.Morphism private variable s t : Level IsSemigroupHom : (S : Semigroup s) (T : Semigroup t) → (⟨ S ⟩ → ⟨ T ⟩) → Type (ℓ-max s t) IsSemigroupHom S T fun = Homomorphic₂ fun (Semigroup._•_ S) (Semigroup._•_ T) record SemigroupHom (S : Semigroup s) (T : Semigroup t) : Type (ℓ-max s t) where constructor semigrouphom field fun : ⟨ S ⟩ → ⟨ T ⟩ isHom : IsSemigroupHom S T fun record SemigroupEquiv (S : Semigroup s) (T : Semigroup t) : Type (ℓ-max s t) where constructor semigroupequiv field eq : ⟨ S ⟩ ≃ ⟨ T ⟩ isHom : IsSemigroupHom S T (equivFun eq) hom : SemigroupHom S T hom = record { isHom = isHom } instance SemigroupHomOperators : HomOperators (Semigroup s) (Semigroup t) (ℓ-max s t) SemigroupHomOperators = record { _⟶ᴴ_ = SemigroupHom; _≃ᴴ_ = SemigroupEquiv } private variable S : Semigroup s T : Semigroup t SemigroupHom→MagmaHom : (S ⟶ᴴ T) → (Semigroup.magma S ⟶ᴴ Semigroup.magma T) SemigroupHom→MagmaHom hom .MagmaHom.fun = hom .SemigroupHom.fun SemigroupHom→MagmaHom hom .MagmaHom.isHom = hom .SemigroupHom.isHom MagmaHom→SemigroupHom : (Semigroup.magma S ⟶ᴴ Semigroup.magma T) → (S ⟶ᴴ T) MagmaHom→SemigroupHom hom .SemigroupHom.fun = hom .MagmaHom.fun MagmaHom→SemigroupHom hom .SemigroupHom.isHom = hom .MagmaHom.isHom SemigroupHom≃MagmaHom : (S ⟶ᴴ T) ≃ (Semigroup.magma S ⟶ᴴ Semigroup.magma T) SemigroupHom≃MagmaHom = isoToEquiv (iso SemigroupHom→MagmaHom MagmaHom→SemigroupHom (λ _ → refl) (λ _ → refl)) SemigroupEquiv→MagmaEquiv : S ≃ᴴ T → Semigroup.magma S ≃ᴴ Semigroup.magma T SemigroupEquiv→MagmaEquiv eq .MagmaEquiv.eq = eq .SemigroupEquiv.eq SemigroupEquiv→MagmaEquiv eq .MagmaEquiv.isHom = eq .SemigroupEquiv.isHom MagmaEquiv→SemigroupEquiv : Semigroup.magma S ≃ᴴ Semigroup.magma T → S ≃ᴴ T MagmaEquiv→SemigroupEquiv eq .SemigroupEquiv.eq = eq .MagmaEquiv.eq MagmaEquiv→SemigroupEquiv eq .SemigroupEquiv.isHom = eq .MagmaEquiv.isHom SemigroupEquiv≃MagmaEquiv : (S ≃ᴴ T) ≃ (Semigroup.magma S ≃ᴴ Semigroup.magma T) SemigroupEquiv≃MagmaEquiv = isoToEquiv (iso SemigroupEquiv→MagmaEquiv MagmaEquiv→SemigroupEquiv (λ _ → refl) (λ _ → refl))
35.941176
122
0.739362
126713be631e1bec66bd6249f98ba9ee33267806
3,499
agda
Agda
Cubical/Homotopy/Connected.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Homotopy/Connected.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
Cubical/Homotopy/Connected.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Homotopy.Connected where open import Cubical.Core.Everything open import Cubical.Foundations.Everything open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Path open import Cubical.Foundations.Univalence open import Cubical.Functions.Fibration open import Cubical.Data.Nat open import Cubical.Data.Sigma open import Cubical.HITs.Nullification open import Cubical.HITs.Truncation as Trunc isHLevelConnected : ∀ {ℓ} (n : ℕ) (A : Type ℓ) → Type ℓ isHLevelConnected n A = isContr (hLevelTrunc n A) isHLevelConnectedFun : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ') isHLevelConnectedFun n f = ∀ b → isHLevelConnected n (fiber f b) isEquivPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (n : ℕ) {A : Type ℓ} {B : Type ℓ'} (P : B → HLevel ℓ'' n) (f : A → B) → isHLevelConnectedFun n f → isEquiv (λ(s : (b : B) → P b .fst) → s ∘ f) isEquivPrecomposeConnected n {A} {B} P f fConn = isoToIsEquiv (iso (_∘ f) (λ t b → inv t b (fConn b .fst)) (λ t → funExt λ a → cong (inv t (f a)) (fConn (f a) .snd ∣ a , refl ∣) ∙ substRefl {B = fst ∘ P} (t a)) (λ s → funExt λ b → Trunc.elim {B = λ d → inv (s ∘ f) b d ≡ s b} (λ _ → isOfHLevelPath n (P b .snd) _ _) (λ {(a , p) i → transp (λ j → P (p (j ∨ i)) .fst) i (s (p i))}) (fConn b .fst))) where inv : ((a : A) → P (f a) .fst) → (b : B) → hLevelTrunc n (fiber f b) → P b .fst inv t b = Trunc.rec (P b .snd) (λ {(a , p) → subst (fst ∘ P) p (t a)}) isOfHLevelPrecomposeConnected : ∀ {ℓ ℓ' ℓ''} (k : ℕ) (n : ℕ) {A : Type ℓ} {B : Type ℓ'} (P : B → HLevel ℓ'' (k + n)) (f : A → B) → isHLevelConnectedFun n f → isOfHLevelFun k (λ(s : (b : B) → P b .fst) → s ∘ f) isOfHLevelPrecomposeConnected zero n P f fConn = isEquivPrecomposeConnected n P f fConn .equiv-proof isOfHLevelPrecomposeConnected (suc k) n P f fConn t = isOfHLevelPath'⁻ k (λ {(s₀ , p₀) (s₁ , p₁) → subst (isOfHLevel k) (sym (fiber≡ (s₀ , p₀) (s₁ , p₁))) (isOfHLevelRetract k (λ {(q , α) → (funExt⁻ q) , (cong funExt⁻ α)}) (λ {(h , β) → (funExt h) , (cong funExt β)}) (λ _ → refl) (isOfHLevelPrecomposeConnected k n (λ b → (s₀ b ≡ s₁ b) , isOfHLevelPath' (k + n) (P b .snd) _ _) f fConn (funExt⁻ (p₀ ∙∙ refl ∙∙ sym p₁))))}) isHLevelConnectedPath : ∀ {ℓ} (n : ℕ) {A : Type ℓ} → isHLevelConnected (suc n) A → (a₀ a₁ : A) → isHLevelConnected n (a₀ ≡ a₁) isHLevelConnectedPath n connA a₀ a₁ = subst isContr (PathIdTrunc _) (isContr→isContrPath connA _ _) isHLevelConnectedRetract : ∀ {ℓ ℓ'} (n : ℕ) {A : Type ℓ} {B : Type ℓ'} (f : A → B) (g : B → A) (h : (x : A) → g (f x) ≡ x) → isHLevelConnected n B → isHLevelConnected n A isHLevelConnectedRetract n f g h = isContrRetract (Trunc.map f) (Trunc.map g) (Trunc.elim (λ _ → isOfHLevelPath n (isOfHLevelTrunc n) _ _) (λ a → cong ∣_∣ (h a))) isHLevelConnectedPoint : ∀ {ℓ} (n : ℕ) {A : Type ℓ} → isHLevelConnected (suc n) A → (a : A) → isHLevelConnectedFun n (λ(_ : Unit) → a) isHLevelConnectedPoint n connA a₀ a = isHLevelConnectedRetract n snd (_ ,_) (λ _ → refl) (isHLevelConnectedPath n connA a₀ a)
36.447917
98
0.589883
507a17629b374f8083f75179d4a28d2053e69378
2,723
agda
Agda
agda-stdlib/src/Axiom/UniquenessOfIdentityProofs.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Axiom/UniquenessOfIdentityProofs.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Axiom/UniquenessOfIdentityProofs.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Results concerning uniqueness of identity proofs ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Axiom.UniquenessOfIdentityProofs where open import Data.Bool.Base using (true; false) open import Data.Empty open import Relation.Nullary.Reflects using (invert) open import Relation.Nullary hiding (Irrelevant) open import Relation.Binary.Core open import Relation.Binary.Definitions open import Relation.Binary.PropositionalEquality.Core ------------------------------------------------------------------------ -- Definition -- -- Uniqueness of Identity Proofs (UIP) states that all proofs of -- equality are themselves equal. In other words, the equality relation -- is irrelevant. Here we define UIP relative to a given type. UIP : ∀ {a} (A : Set a) → Set a UIP A = Irrelevant {A = A} _≡_ ------------------------------------------------------------------------ -- Properties -- UIP always holds when using axiom K -- (see `Axiom.UniquenessOfIdentityProofs.WithK`). -- The existence of a constant function over proofs of equality for -- elements in A is enough to prove UIP for A. Indeed, we can relate any -- proof to its image via this function which we then know is equal to -- the image of any other proof. module Constant⇒UIP {a} {A : Set a} (f : _≡_ {A = A} ⇒ _≡_) (f-constant : ∀ {a b} (p q : a ≡ b) → f p ≡ f q) where ≡-canonical : ∀ {a b} (p : a ≡ b) → trans (sym (f refl)) (f p) ≡ p ≡-canonical refl = trans-symˡ (f refl) ≡-irrelevant : UIP A ≡-irrelevant p q = begin p ≡⟨ sym (≡-canonical p) ⟩ trans (sym (f refl)) (f p) ≡⟨ cong (trans _) (f-constant p q) ⟩ trans (sym (f refl)) (f q) ≡⟨ ≡-canonical q ⟩ q ∎ where open ≡-Reasoning -- If equality is decidable for a given type, then we can prove UIP for -- that type. Indeed, the decision procedure allows us to define a -- function over proofs of equality which is constant: it returns the -- proof produced by the decision procedure. module Decidable⇒UIP {a} {A : Set a} (_≟_ : Decidable {A = A} _≡_) where ≡-normalise : _≡_ {A = A} ⇒ _≡_ ≡-normalise {a} {b} a≡b with a ≟ b ... | true because [p] = invert [p] ... | false because [¬p] = ⊥-elim (invert [¬p] a≡b) ≡-normalise-constant : ∀ {a b} (p q : a ≡ b) → ≡-normalise p ≡ ≡-normalise q ≡-normalise-constant {a} {b} p q with a ≟ b ... | true because _ = refl ... | false because [¬p] = ⊥-elim (invert [¬p] p) ≡-irrelevant : UIP A ≡-irrelevant = Constant⇒UIP.≡-irrelevant ≡-normalise ≡-normalise-constant
35.363636
78
0.576937
1c0519b90a4bd375549d7f6e87634b1ceb4252ae
494
agda
Agda
test/Fail/Issue5856.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Fail/Issue5856.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Fail/Issue5856.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
-- Andreas, 2022-03-28, issue #5856, reported by Szumi Xie. -- Patterns in path-lambdas were simply ignored, but should be illegal. {-# OPTIONS --cubical #-} -- {-# OPTIONS -v tc.term.lambda:30 #-} open import Agda.Builtin.Cubical.Path postulate A E : Set a : A data C : Set where c : E → C p : a ≡ a p = λ (c e) → a -- WAS: accepted. -- Expected error: -- Patterns are not allowed in Path-lambdas -- when checking that the expression λ .patternInTele0 @ (c e) → a has type a ≡ a
19.76
81
0.647773
2324772ccbf95efab9de11df8f332af7ed2cb540
104,061
agda
Agda
src/Erased/Level-1.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/Erased/Level-1.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/Erased/Level-1.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- A type for values that should be erased at run-time ------------------------------------------------------------------------ -- Most of the definitions in this module are reexported, in one way -- or another, from Erased. -- This module imports Function-universe, but not Equivalence.Erased. {-# OPTIONS --without-K --safe #-} open import Equality module Erased.Level-1 {e⁺} (eq-J : ∀ {a p} → Equality-with-J a p e⁺) where open Derived-definitions-and-properties eq-J hiding (module Extensionality) open import Logical-equivalence using (_⇔_) open import Prelude hiding ([_,_]) open import Bijection eq-J as Bijection using (_↔_; Has-quasi-inverse) open import Embedding eq-J as Emb using (Embedding; Is-embedding) open import Equality.Decidable-UIP eq-J open import Equivalence eq-J as Eq using (_≃_; Is-equivalence) import Equivalence.Contractible-preimages eq-J as CP open import Equivalence.Erased.Basics eq-J as EEq using (_≃ᴱ_; Is-equivalenceᴱ) open import Equivalence-relation eq-J open import Function-universe eq-J as F hiding (id; _∘_) open import H-level eq-J as H-level open import H-level.Closure eq-J open import Injection eq-J using (_↣_; Injective) open import Monad eq-J hiding (map; map-id; map-∘) open import Preimage eq-J using (_⁻¹_) open import Surjection eq-J as Surjection using (_↠_; Split-surjective) open import Univalence-axiom eq-J as U using (≡⇒→; _²/≡) private variable a b c d ℓ ℓ₁ ℓ₂ q r : Level A B : Type a eq k k′ p x y : A P : A → Type p f g : A → B n : ℕ ------------------------------------------------------------------------ -- Some basic definitions open import Erased.Basics public ------------------------------------------------------------------------ -- Stability mutual -- A type A is stable if Erased A implies A. Stable : Type a → Type a Stable = Stable-[ implication ] -- A generalisation of Stable. Stable-[_] : Kind → Type a → Type a Stable-[ k ] A = Erased A ↝[ k ] A -- A variant of Stable-[ equivalence ]. Very-stable : Type a → Type a Very-stable A = Is-equivalence [ A ∣_]→ -- A variant of Stable-[ equivalenceᴱ ]. Very-stableᴱ : Type a → Type a Very-stableᴱ A = Is-equivalenceᴱ [ A ∣_]→ -- Variants of the definitions above for equality. Stable-≡ : Type a → Type a Stable-≡ = For-iterated-equality 1 Stable Stable-≡-[_] : Kind → Type a → Type a Stable-≡-[ k ] = For-iterated-equality 1 Stable-[ k ] Very-stable-≡ : Type a → Type a Very-stable-≡ = For-iterated-equality 1 Very-stable Very-stableᴱ-≡ : Type a → Type a Very-stableᴱ-≡ = For-iterated-equality 1 Very-stableᴱ ------------------------------------------------------------------------ -- Erased is a monad -- A universe-polymorphic variant of bind. infixl 5 _>>=′_ _>>=′_ : {@0 A : Type a} {@0 B : Type b} → Erased A → (A → Erased B) → Erased B x >>=′ f = [ erased (f (erased x)) ] instance -- Erased is a monad. raw-monad : Raw-monad (λ (A : Type a) → Erased A) Raw-monad.return raw-monad = [_]→ Raw-monad._>>=_ raw-monad = _>>=′_ monad : Monad (λ (A : Type a) → Erased A) Monad.raw-monad monad = raw-monad Monad.left-identity monad = λ _ _ → refl _ Monad.right-identity monad = λ _ → refl _ Monad.associativity monad = λ _ _ _ → refl _ ------------------------------------------------------------------------ -- Erased preserves some kinds of functions -- Erased is functorial for dependent functions. map-id : {@0 A : Type a} → map id ≡ id {A = Erased A} map-id = refl _ map-∘ : {@0 A : Type a} {@0 P : A → Type b} {@0 Q : {x : A} → P x → Type c} (@0 f : ∀ {x} (y : P x) → Q y) (@0 g : (x : A) → P x) → map (f ∘ g) ≡ map f ∘ map g map-∘ _ _ = refl _ -- Erased preserves logical equivalences. Erased-cong-⇔ : {@0 A : Type a} {@0 B : Type b} → @0 A ⇔ B → Erased A ⇔ Erased B Erased-cong-⇔ A⇔B = record { to = map (_⇔_.to A⇔B) ; from = map (_⇔_.from A⇔B) } -- Erased is functorial for logical equivalences. Erased-cong-⇔-id : {@0 A : Type a} → Erased-cong-⇔ F.id ≡ F.id {A = Erased A} Erased-cong-⇔-id = refl _ Erased-cong-⇔-∘ : {@0 A : Type a} {@0 B : Type b} {@0 C : Type c} (@0 f : B ⇔ C) (@0 g : A ⇔ B) → Erased-cong-⇔ (f F.∘ g) ≡ Erased-cong-⇔ f F.∘ Erased-cong-⇔ g Erased-cong-⇔-∘ _ _ = refl _ -- Erased preserves equivalences with erased proofs. Erased-cong-≃ᴱ : {@0 A : Type a} {@0 B : Type b} → @0 A ≃ᴱ B → Erased A ≃ᴱ Erased B Erased-cong-≃ᴱ A≃ᴱB = EEq.↔→≃ᴱ (map (_≃ᴱ_.to A≃ᴱB)) (map (_≃ᴱ_.from A≃ᴱB)) (cong [_]→ ∘ _≃ᴱ_.right-inverse-of A≃ᴱB ∘ erased) (cong [_]→ ∘ _≃ᴱ_.left-inverse-of A≃ᴱB ∘ erased) ------------------------------------------------------------------------ -- Some isomorphisms -- In an erased context Erased A is always isomorphic to A. Erased↔ : {@0 A : Type a} → Erased (Erased A ↔ A) Erased↔ = [ record { surjection = record { logical-equivalence = record { to = erased ; from = [_]→ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } ] -- The following result is based on a result in Mishra-Linger's PhD -- thesis (see Section 5.4.4). -- Erased (Erased A) is isomorphic to Erased A. Erased-Erased↔Erased : {@0 A : Type a} → Erased (Erased A) ↔ Erased A Erased-Erased↔Erased = record { surjection = record { logical-equivalence = record { to = λ x → [ erased (erased x) ] ; from = [_]→ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased ⊤ is isomorphic to ⊤. Erased-⊤↔⊤ : Erased ⊤ ↔ ⊤ Erased-⊤↔⊤ = record { surjection = record { logical-equivalence = record { to = λ _ → tt ; from = [_]→ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased ⊥ is isomorphic to ⊥. Erased-⊥↔⊥ : Erased (⊥ {ℓ = ℓ}) ↔ ⊥ {ℓ = ℓ} Erased-⊥↔⊥ = record { surjection = record { logical-equivalence = record { to = λ { [ () ] } ; from = [_]→ } ; right-inverse-of = λ () } ; left-inverse-of = λ { [ () ] } } -- Erased commutes with Π A. Erased-Π↔Π : {@0 P : A → Type p} → Erased ((x : A) → P x) ↔ ((x : A) → Erased (P x)) Erased-Π↔Π = record { surjection = record { logical-equivalence = record { to = λ { [ f ] x → [ f x ] } ; from = λ f → [ (λ x → erased (f x)) ] } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- A variant of Erased-Π↔Π. Erased-Π≃ᴱΠ : {@0 A : Type a} {@0 P : A → Type p} → Erased ((x : A) → P x) ≃ᴱ ((x : A) → Erased (P x)) Erased-Π≃ᴱΠ = EEq.[≃]→≃ᴱ (EEq.[proofs] $ from-isomorphism Erased-Π↔Π) -- Erased commutes with Π. Erased-Π↔Π-Erased : {@0 A : Type a} {@0 P : A → Type p} → Erased ((x : A) → P x) ↔ ((x : Erased A) → Erased (P (erased x))) Erased-Π↔Π-Erased = record { surjection = record { logical-equivalence = record { to = λ ([ f ]) → map f ; from = λ f → [ (λ x → erased (f [ x ])) ] } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased commutes with Σ. Erased-Σ↔Σ : {@0 A : Type a} {@0 P : A → Type p} → Erased (Σ A P) ↔ Σ (Erased A) (λ x → Erased (P (erased x))) Erased-Σ↔Σ = record { surjection = record { logical-equivalence = record { to = λ { [ p ] → [ proj₁ p ] , [ proj₂ p ] } ; from = λ { ([ x ] , [ y ]) → [ x , y ] } } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased commutes with ↑ ℓ. Erased-↑↔↑ : {@0 A : Type a} → Erased (↑ ℓ A) ↔ ↑ ℓ (Erased A) Erased-↑↔↑ = record { surjection = record { logical-equivalence = record { to = λ { [ x ] → lift [ lower x ] } ; from = λ { (lift [ x ]) → [ lift x ] } } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased commutes with ¬_ (assuming extensionality). Erased-¬↔¬ : {@0 A : Type a} → Erased (¬ A) ↝[ a ∣ lzero ] ¬ Erased A Erased-¬↔¬ {A = A} ext = Erased (A → ⊥) ↔⟨ Erased-Π↔Π-Erased ⟩ (Erased A → Erased ⊥) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-⊥↔⊥) ⟩□ (Erased A → ⊥) □ -- Erased can be dropped under ¬_ (assuming extensionality). ¬-Erased↔¬ : {A : Type a} → ¬ Erased A ↝[ a ∣ lzero ] ¬ A ¬-Erased↔¬ {a = a} {A = A} = generalise-ext?-prop (record { to = λ ¬[a] a → ¬[a] [ a ] ; from = λ ¬a ([ a ]) → _↔_.to Erased-⊥↔⊥ [ ¬a a ] }) ¬-propositional ¬-propositional -- The following three results are inspired by a result in -- Mishra-Linger's PhD thesis (see Section 5.4.1). -- -- See also Π-Erased↔Π0[], Π-Erased≃Π0[], Π-Erased↔Π0 and Π-Erased≃Π0 -- in Erased.Cubical and Erased.With-K. -- There is a logical equivalence between -- (x : Erased A) → P (erased x) and (@0 x : A) → P x. Π-Erased⇔Π0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) ⇔ ((@0 x : A) → P x) Π-Erased⇔Π0 = record { to = λ f x → f [ x ] ; from = λ f ([ x ]) → f x } -- There is an equivalence with erased proofs between -- (x : Erased A) → P (erased x) and (@0 x : A) → P x. Π-Erased≃ᴱΠ0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) ≃ᴱ ((@0 x : A) → P x) Π-Erased≃ᴱΠ0 = EEq.↔→≃ᴱ (_⇔_.to Π-Erased⇔Π0) (_⇔_.from Π-Erased⇔Π0) refl refl -- There is an equivalence between (x : Erased A) → P (erased x) and -- (@0 x : A) → P x. Π-Erased≃Π0 : {@0 A : Type a} {P : @0 A → Type p} → ((x : Erased A) → P (erased x)) ≃ ((@0 x : A) → P x) Π-Erased≃Π0 {A = A} {P = P} = Eq.↔→≃ {B = (@0 x : A) → P x} (_⇔_.to Π-Erased⇔Π0) (_⇔_.from Π-Erased⇔Π0) (λ _ → refl {A = (@0 x : A) → P x} _) (λ _ → refl _) -- A variant of Π-Erased≃Π0. Π-Erased≃Π0[] : {@0 A : Type a} {P : Erased A → Type p} → ((x : Erased A) → P x) ≃ ((@0 x : A) → P [ x ]) Π-Erased≃Π0[] = Π-Erased≃Π0 -- Erased commutes with W up to logical equivalence. Erased-W⇔W : {@0 A : Type a} {@0 P : A → Type p} → Erased (W A P) ⇔ W (Erased A) (λ x → Erased (P (erased x))) Erased-W⇔W {A = A} {P = P} = record { to = to; from = from } where to : Erased (W A P) → W (Erased A) (λ x → Erased (P (erased x))) to [ sup x f ] = sup [ x ] (λ ([ y ]) → to [ f y ]) from : W (Erased A) (λ x → Erased (P (erased x))) → Erased (W A P) from (sup [ x ] f) = [ sup x (λ y → erased (from (f [ y ]))) ] ---------------------------------------------------------------------- -- Erased is a modality -- Erased is the modal operator of a uniquely eliminating modality -- with [_]→ as the modal unit. -- -- The terminology here roughly follows that of "Modalities in -- Homotopy Type Theory" by Rijke, Shulman and Spitters. uniquely-eliminating-modality : {@0 P : Erased A → Type p} → Is-equivalence (λ (f : (x : Erased A) → Erased (P x)) → f ∘ [ A ∣_]→) uniquely-eliminating-modality {A = A} {P = P} = _≃_.is-equivalence (((x : Erased A) → Erased (P x)) ↔⟨ inverse Erased-Π↔Π-Erased ⟩ Erased ((x : A) → (P [ x ])) ↔⟨ Erased-Π↔Π ⟩ ((x : A) → Erased (P [ x ])) □) -- Two results that are closely related to -- uniquely-eliminating-modality. -- -- These results are based on the Coq source code accompanying -- "Modalities in Homotopy Type Theory" by Rijke, Shulman and -- Spitters. -- Precomposition with [_]→ is injective for functions from Erased A -- to Erased B. ∘-[]-injective : {@0 B : Type b} → Injective (λ (f : Erased A → Erased B) → f ∘ [_]→) ∘-[]-injective = _≃_.injective Eq.⟨ _ , uniquely-eliminating-modality ⟩ -- A rearrangement lemma for ext⁻¹ and ∘-[]-injective. ext⁻¹-∘-[]-injective : {@0 B : Type b} {f g : Erased A → Erased B} {p : f ∘ [_]→ ≡ g ∘ [_]→} → ext⁻¹ (∘-[]-injective {x = f} {y = g} p) [ x ] ≡ ext⁻¹ p x ext⁻¹-∘-[]-injective {x = x} {f = f} {g = g} {p = p} = ext⁻¹ (∘-[]-injective p) [ x ] ≡⟨ elim₁ (λ p → ext⁻¹ p [ x ] ≡ ext⁻¹ (_≃_.from equiv p) x) ( ext⁻¹ (refl g) [ x ] ≡⟨ cong-refl (_$ [ x ]) ⟩ refl (g [ x ]) ≡⟨ sym $ cong-refl _ ⟩ ext⁻¹ (refl (g ∘ [_]→)) x ≡⟨ cong (λ p → ext⁻¹ p x) $ sym $ cong-refl _ ⟩∎ ext⁻¹ (_≃_.from equiv (refl g)) x ∎) (∘-[]-injective p) ⟩ ext⁻¹ (_≃_.from equiv (∘-[]-injective p)) x ≡⟨ cong (flip ext⁻¹ x) $ _≃_.left-inverse-of equiv _ ⟩∎ ext⁻¹ p x ∎ where equiv = Eq.≃-≡ Eq.⟨ _ , uniquely-eliminating-modality ⟩ ---------------------------------------------------------------------- -- Some lemmas related to functions with erased domains -- A variant of H-level.Π-closure for function spaces with erased -- explicit domains. Note the type of P. Πᴱ-closure : {@0 A : Type a} {P : @0 A → Type p} → Extensionality a p → ∀ n → ((@0 x : A) → H-level n (P x)) → H-level n ((@0 x : A) → P x) Πᴱ-closure {P = P} ext n = (∀ (@0 x) → H-level n (P x)) →⟨ Eq._≃₀_.from Π-Erased≃Π0 ⟩ (∀ x → H-level n (P (x .erased))) →⟨ Π-closure ext n ⟩ H-level n (∀ x → P (x .erased)) →⟨ H-level-cong {B = ∀ (@0 x) → P x} _ n Π-Erased≃Π0 ⟩□ H-level n (∀ (@0 x) → P x) □ -- A variant of H-level.Π-closure for function spaces with erased -- implicit domains. Note the type of P. implicit-Πᴱ-closure : {@0 A : Type a} {P : @0 A → Type p} → Extensionality a p → ∀ n → ((@0 x : A) → H-level n (P x)) → H-level n ({@0 x : A} → P x) implicit-Πᴱ-closure {A = A} {P = P} ext n = (∀ (@0 x) → H-level n (P x)) →⟨ Πᴱ-closure ext n ⟩ H-level n (∀ (@0 x) → P x) →⟨ H-level-cong {A = ∀ (@0 x) → P x} {B = ∀ {@0 x} → P x} _ n $ inverse {A = ∀ {@0 x} → P x} {B = ∀ (@0 x) → P x} Bijection.implicit-Πᴱ↔Πᴱ′ ⟩□ H-level n (∀ {@0 x} → P x) □ -- Extensionality implies extensionality for some functions with -- erased arguments (note the type of P). apply-extᴱ : {@0 A : Type a} {P : @0 A → Type p} {f g : (@0 x : A) → P x} → Extensionality a p → ((@0 x : A) → f x ≡ g x) → f ≡ g apply-extᴱ {A = A} {P = P} {f = f} {g = g} ext = ((@0 x : A) → f x ≡ g x) →⟨ Eq._≃₀_.from Π-Erased≃Π0 ⟩ ((x : Erased A) → f (x .erased) ≡ g (x .erased)) →⟨ apply-ext ext ⟩ (λ x → f (x .erased)) ≡ (λ x → g (x .erased)) →⟨ cong {B = (@0 x : A) → P x} (Eq._≃₀_.to Π-Erased≃Π0) ⟩□ f ≡ g □ -- Extensionality implies extensionality for some functions with -- implicit erased arguments (note the type of P). implicit-apply-extᴱ : {@0 A : Type a} {P : @0 A → Type p} {f g : {@0 x : A} → P x} → Extensionality a p → ((@0 x : A) → f {x = x} ≡ g {x = x}) → _≡_ {A = {@0 x : A} → P x} f g implicit-apply-extᴱ {A = A} {P = P} {f = f} {g = g} ext = ((@0 x : A) → f {x = x} ≡ g {x = x}) →⟨ apply-extᴱ ext ⟩ _≡_ {A = (@0 x : A) → P x} (λ x → f {x = x}) (λ x → g {x = x}) →⟨ cong {A = (@0 x : A) → P x} {B = {@0 x : A} → P x} (λ f {x = x} → f x) ⟩□ _≡_ {A = {@0 x : A} → P x} f g □ ------------------------------------------------------------------------ -- A variant of Dec ∘ Erased -- Dec-Erased A means that either we have A (erased), or we have ¬ A -- (also erased). Dec-Erased : @0 Type ℓ → Type ℓ Dec-Erased A = Erased A ⊎ Erased (¬ A) -- Dec A implies Dec-Erased A. Dec→Dec-Erased : {@0 A : Type a} → Dec A → Dec-Erased A Dec→Dec-Erased (yes a) = yes [ a ] Dec→Dec-Erased (no ¬a) = no [ ¬a ] -- In erased contexts Dec-Erased A is equivalent to Dec A. @0 Dec-Erased≃Dec : {@0 A : Type a} → Dec-Erased A ≃ Dec A Dec-Erased≃Dec {A = A} = Eq.with-other-inverse (Erased A ⊎ Erased (¬ A) ↔⟨ erased Erased↔ ⊎-cong erased Erased↔ ⟩□ A ⊎ ¬ A □) Dec→Dec-Erased Prelude.[ (λ _ → refl _) , (λ _ → refl _) ] -- Dec-Erased A is isomorphic to Dec (Erased A) (assuming -- extensionality). Dec-Erased↔Dec-Erased : {@0 A : Type a} → Dec-Erased A ↝[ a ∣ lzero ] Dec (Erased A) Dec-Erased↔Dec-Erased {A = A} ext = Erased A ⊎ Erased (¬ A) ↝⟨ F.id ⊎-cong Erased-¬↔¬ ext ⟩□ Erased A ⊎ ¬ Erased A □ -- A map function for Dec-Erased. Dec-Erased-map : {@0 A : Type a} {@0 B : Type b} → @0 A ⇔ B → Dec-Erased A → Dec-Erased B Dec-Erased-map A⇔B = ⊎-map (map (_⇔_.to A⇔B)) (map (_∘ _⇔_.from A⇔B)) -- Dec-Erased preserves logical equivalences. Dec-Erased-cong-⇔ : {@0 A : Type a} {@0 B : Type b} → @0 A ⇔ B → Dec-Erased A ⇔ Dec-Erased B Dec-Erased-cong-⇔ A⇔B = record { to = Dec-Erased-map A⇔B ; from = Dec-Erased-map (inverse A⇔B) } -- If A and B are decided (with erased proofs), then A × B is. Dec-Erased-× : {@0 A : Type a} {@0 B : Type b} → Dec-Erased A → Dec-Erased B → Dec-Erased (A × B) Dec-Erased-× (no [ ¬a ]) _ = no [ ¬a ∘ proj₁ ] Dec-Erased-× _ (no [ ¬b ]) = no [ ¬b ∘ proj₂ ] Dec-Erased-× (yes [ a ]) (yes [ b ]) = yes [ a , b ] -- If A and B are decided (with erased proofs), then A ⊎ B is. Dec-Erased-⊎ : {@0 A : Type a} {@0 B : Type b} → Dec-Erased A → Dec-Erased B → Dec-Erased (A ⊎ B) Dec-Erased-⊎ (yes [ a ]) _ = yes [ inj₁ a ] Dec-Erased-⊎ (no [ ¬a ]) (yes [ b ]) = yes [ inj₂ b ] Dec-Erased-⊎ (no [ ¬a ]) (no [ ¬b ]) = no [ Prelude.[ ¬a , ¬b ] ] -- A variant of Equality.Decision-procedures.×.dec⇒dec⇒dec. dec-erased⇒dec-erased⇒×-dec-erased : {@0 A : Type a} {@0 B : Type b} {@0 x₁ x₂ : A} {@0 y₁ y₂ : B} → Dec-Erased (x₁ ≡ x₂) → Dec-Erased (y₁ ≡ y₂) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) dec-erased⇒dec-erased⇒×-dec-erased = λ where (no [ x₁≢x₂ ]) _ → no [ x₁≢x₂ ∘ cong proj₁ ] _ (no [ y₁≢y₂ ]) → no [ y₁≢y₂ ∘ cong proj₂ ] (yes [ x₁≡x₂ ]) (yes [ y₁≡y₂ ]) → yes [ cong₂ _,_ x₁≡x₂ y₁≡y₂ ] -- A variant of Equality.Decision-procedures.Σ.set⇒dec⇒dec⇒dec. -- -- See also set⇒dec-erased⇒dec-erased⇒Σ-dec-erased below. set⇒dec⇒dec-erased⇒Σ-dec-erased : {@0 A : Type a} {@0 P : A → Type p} {@0 x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → @0 Is-set A → Dec (x₁ ≡ x₂) → (∀ eq → Dec-Erased (subst P eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) set⇒dec⇒dec-erased⇒Σ-dec-erased _ (no x₁≢x₂) _ = no [ x₁≢x₂ ∘ cong proj₁ ] set⇒dec⇒dec-erased⇒Σ-dec-erased {P = P} {y₁ = y₁} {y₂ = y₂} set₁ (yes x₁≡x₂) dec₂ = ⊎-map (map (Σ-≡,≡→≡ x₁≡x₂)) (map λ cast-y₁≢y₂ eq → $⟨ proj₂ (Σ-≡,≡←≡ eq) ⟩ subst P (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ subst (λ p → subst _ p _ ≡ _) (set₁ _ _) ⟩ subst P x₁≡x₂ y₁ ≡ y₂ ↝⟨ cast-y₁≢y₂ ⟩□ ⊥ □) (dec₂ x₁≡x₂) -- A variant of Equality.Decision-procedures.Σ.decidable⇒dec⇒dec. -- -- See also decidable-erased⇒dec-erased⇒Σ-dec-erased below. decidable⇒dec-erased⇒Σ-dec-erased : {@0 A : Type a} {@0 P : A → Type p} {x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → Decidable-equality A → (∀ eq → Dec-Erased (subst P eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) decidable⇒dec-erased⇒Σ-dec-erased dec = set⇒dec⇒dec-erased⇒Σ-dec-erased (decidable⇒set dec) (dec _ _) ------------------------------------------------------------------------ -- Decidable erased equality -- A variant of Decidable-equality that is defined using Dec-Erased. Decidable-erased-equality : Type ℓ → Type ℓ Decidable-erased-equality A = (x y : A) → Dec-Erased (x ≡ y) -- Decidable equality implies decidable erased equality. Decidable-equality→Decidable-erased-equality : {@0 A : Type a} → Decidable-equality A → Decidable-erased-equality A Decidable-equality→Decidable-erased-equality dec x y = Dec→Dec-Erased (dec x y) -- In erased contexts Decidable-erased-equality A is equivalent to -- Decidable-equality A (assuming extensionality). @0 Decidable-erased-equality≃Decidable-equality : {A : Type a} → Decidable-erased-equality A ↝[ a ∣ a ] Decidable-equality A Decidable-erased-equality≃Decidable-equality {A = A} ext = ((x y : A) → Dec-Erased (x ≡ y)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-equivalence Dec-Erased≃Dec) ⟩□ ((x y : A) → Dec (x ≡ y)) □ -- A map function for Decidable-erased-equality. Decidable-erased-equality-map : A ↠ B → Decidable-erased-equality A → Decidable-erased-equality B Decidable-erased-equality-map A↠B _≟_ x y = $⟨ _↠_.from A↠B x ≟ _↠_.from A↠B y ⟩ Dec-Erased (_↠_.from A↠B x ≡ _↠_.from A↠B y) ↝⟨ Dec-Erased-map (_↠_.logical-equivalence $ Surjection.↠-≡ A↠B) ⟩□ Dec-Erased (x ≡ y) □ -- A variant of Equality.Decision-procedures.×.Dec._≟_. decidable-erased⇒decidable-erased⇒×-decidable-erased : {@0 A : Type a} {@0 B : Type b} → Decidable-erased-equality A → Decidable-erased-equality B → Decidable-erased-equality (A × B) decidable-erased⇒decidable-erased⇒×-decidable-erased decA decB _ _ = dec-erased⇒dec-erased⇒×-dec-erased (decA _ _) (decB _ _) -- A variant of Equality.Decision-procedures.Σ.Dec._≟_. -- -- See also decidable-erased⇒decidable-erased⇒Σ-decidable-erased -- below. decidable⇒decidable-erased⇒Σ-decidable-erased : Decidable-equality A → ({x : A} → Decidable-erased-equality (P x)) → Decidable-erased-equality (Σ A P) decidable⇒decidable-erased⇒Σ-decidable-erased {P = P} decA decP (_ , x₂) (_ , y₂) = decidable⇒dec-erased⇒Σ-dec-erased decA (λ eq → decP (subst P eq x₂) y₂) ------------------------------------------------------------------------ -- Erased binary relations -- Lifts binary relations from A to Erased A. Erasedᴾ : {@0 A : Type a} {@0 B : Type b} → @0 (A → B → Type r) → (Erased A → Erased B → Type r) Erasedᴾ R [ x ] [ y ] = Erased (R x y) -- Erasedᴾ preserves Is-equivalence-relation. Erasedᴾ-preserves-Is-equivalence-relation : {@0 A : Type a} {@0 R : A → A → Type r} → @0 Is-equivalence-relation R → Is-equivalence-relation (Erasedᴾ R) Erasedᴾ-preserves-Is-equivalence-relation equiv = λ where .Is-equivalence-relation.reflexive → [ equiv .Is-equivalence-relation.reflexive ] .Is-equivalence-relation.symmetric → map (equiv .Is-equivalence-relation.symmetric) .Is-equivalence-relation.transitive → zip (equiv .Is-equivalence-relation.transitive) ------------------------------------------------------------------------ -- Some results that hold in erased contexts -- In an erased context there is an equivalence between equality of -- "boxed" values and equality of values. @0 []≡[]≃≡ : ([ x ] ≡ [ y ]) ≃ (x ≡ y) []≡[]≃≡ = Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = cong erased ; from = cong [_]→ } ; right-inverse-of = λ eq → cong erased (cong [_]→ eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ } ; left-inverse-of = λ eq → cong [_]→ (cong erased eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ }) -- In an erased context [_]→ is always an embedding. Erased-Is-embedding-[] : {@0 A : Type a} → Erased (Is-embedding [ A ∣_]→) Erased-Is-embedding-[] = [ (λ x y → _≃_.is-equivalence ( x ≡ y ↝⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse $ erased Erased↔ ⟩□ [ x ] ≡ [ y ] □)) ] -- In an erased context [_]→ is always split surjective. Erased-Split-surjective-[] : {@0 A : Type a} → Erased (Split-surjective [ A ∣_]→) Erased-Split-surjective-[] = [ (λ ([ x ]) → x , refl _) ] ------------------------------------------------------------------------ -- []-cong-axiomatisation -- An axiomatisation for []-cong. -- -- In addition to the results in this section, see -- []-cong-axiomatisation-propositional below. record []-cong-axiomatisation a : Type (lsuc a) where field []-cong : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong {x = x} {y = y}) []-cong-[refl] : {@0 A : Type a} {@0 x : A} → []-cong [ refl x ] ≡ refl [ x ] -- The []-cong axioms can be instantiated in erased contexts. @0 erased-instance-of-[]-cong-axiomatisation : []-cong-axiomatisation a erased-instance-of-[]-cong-axiomatisation .[]-cong-axiomatisation.[]-cong = cong [_]→ ∘ erased erased-instance-of-[]-cong-axiomatisation .[]-cong-axiomatisation.[]-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence (Erased (x ≡ y) ↔⟨ erased Erased↔ ⟩ x ≡ y ↝⟨ inverse []≡[]≃≡ ⟩□ [ x ] ≡ [ y ] □) erased-instance-of-[]-cong-axiomatisation .[]-cong-axiomatisation.[]-cong-[refl] {x = x} = cong [_]→ (erased [ refl x ]) ≡⟨⟩ cong [_]→ (refl x) ≡⟨ cong-refl _ ⟩∎ refl [ x ] ∎ -- If the []-cong axioms can be implemented for a certain universe -- level, then they can also be implemented for all smaller universe -- levels. lower-[]-cong-axiomatisation : ∀ a′ → []-cong-axiomatisation (a ⊔ a′) → []-cong-axiomatisation a lower-[]-cong-axiomatisation {a = a} a′ ax = λ where .[]-cong-axiomatisation.[]-cong → []-cong′ .[]-cong-axiomatisation.[]-cong-equivalence → []-cong′-equivalence .[]-cong-axiomatisation.[]-cong-[refl] → []-cong′-[refl] where open []-cong-axiomatisation ax lemma : {@0 A : Type a} {@0 x y : A} → Erased (lift {ℓ = a′} x ≡ lift y) ≃ ([ x ] ≡ [ y ]) lemma {x = x} {y = y} = Erased (lift {ℓ = a′} x ≡ lift y) ↝⟨ Eq.⟨ _ , []-cong-equivalence ⟩ ⟩ [ lift x ] ≡ [ lift y ] ↝⟨ inverse $ Eq.≃-≡ (Eq.↔→≃ (map lower) (map lift) refl refl) ⟩□ [ x ] ≡ [ y ] □ []-cong′ : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong′ {x = x} {y = y} = Erased (x ≡ y) ↝⟨ map (cong lift) ⟩ Erased (lift {ℓ = a′} x ≡ lift y) ↔⟨ lemma ⟩□ [ x ] ≡ [ y ] □ []-cong′-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong′ {x = x} {y = y}) []-cong′-equivalence {x = x} {y = y} = _≃_.is-equivalence (Erased (x ≡ y) ↝⟨ Eq.↔→≃ (map (cong lift)) (map (cong lower)) (λ ([ eq ]) → [ cong lift (cong lower eq) ] ≡⟨ []-cong [ cong-∘ _ _ _ ] ⟩ [ cong id eq ] ≡⟨ []-cong [ sym $ cong-id _ ] ⟩∎ [ eq ] ∎) (λ ([ eq ]) → [ cong lower (cong lift eq) ] ≡⟨ []-cong′ [ cong-∘ _ _ _ ] ⟩ [ cong id eq ] ≡⟨ []-cong′ [ sym $ cong-id _ ] ⟩∎ [ eq ] ∎) ⟩ Erased (lift {ℓ = a′} x ≡ lift y) ↝⟨ lemma ⟩□ [ x ] ≡ [ y ] □) []-cong′-[refl] : {@0 A : Type a} {@0 x : A} → []-cong′ [ refl x ] ≡ refl [ x ] []-cong′-[refl] {x = x} = cong (map lower) ([]-cong [ cong lift (refl x) ]) ≡⟨ cong (cong (map lower) ∘ []-cong) $ []-cong [ cong-refl _ ] ⟩ cong (map lower) ([]-cong [ refl (lift x) ]) ≡⟨ cong (cong (map lower)) []-cong-[refl] ⟩ cong (map lower) (refl [ lift x ]) ≡⟨ cong-refl _ ⟩∎ refl [ x ] ∎ ------------------------------------------------------------------------ -- An alternative to []-cong-axiomatisation -- Stable-≡-Erased-axiomatisation a is the property that equality is -- stable for Erased A, for every erased type A : Type a, along with a -- "computation" rule. Stable-≡-Erased-axiomatisation : (a : Level) → Type (lsuc a) Stable-≡-Erased-axiomatisation a = ∃ λ (Stable-≡-Erased : {@0 A : Type a} → Stable-≡ (Erased A)) → {@0 A : Type a} {x : Erased A} → Stable-≡-Erased x x [ refl x ] ≡ refl x -- Some lemmas used to implement Extensionality→[]-cong as well as -- Erased.Stability.[]-cong-axiomatisation≃Stable-≡-Erased-axiomatisation. module Stable-≡-Erased-axiomatisation→[]-cong-axiomatisation ((Stable-≡-Erased , Stable-≡-Erased-[refl]) : Stable-≡-Erased-axiomatisation a) where -- An implementation of []-cong. []-cong : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong {x = x} {y = y} = Erased (x ≡ y) ↝⟨ map (cong [_]→) ⟩ Erased ([ x ] ≡ [ y ]) ↝⟨ Stable-≡-Erased _ _ ⟩□ [ x ] ≡ [ y ] □ -- A "computation rule" for []-cong. []-cong-[refl] : {@0 A : Type a} {@0 x : A} → []-cong [ refl x ] ≡ refl [ x ] []-cong-[refl] {x = x} = []-cong [ refl x ] ≡⟨⟩ Stable-≡-Erased _ _ [ cong [_]→ (refl x) ] ≡⟨ cong (Stable-≡-Erased _ _) ([]-cong [ cong-refl _ ]) ⟩ Stable-≡-Erased _ _ [ refl [ x ] ] ≡⟨ Stable-≡-Erased-[refl] ⟩∎ refl [ x ] ∎ -- Equality is very stable for Erased A. Very-stable-≡-Erased : {@0 A : Type a} → Very-stable-≡ (Erased A) Very-stable-≡-Erased x y = _≃_.is-equivalence (Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { from = Stable-≡-Erased x y } ; right-inverse-of = λ ([ eq ]) → []-cong [ lemma eq ] } ; left-inverse-of = lemma })) where lemma = elim¹ (λ eq → Stable-≡-Erased _ _ [ eq ] ≡ eq) Stable-≡-Erased-[refl] -- The following implementations of functions from Erased-cong -- (below) are restricted to types in Type a (where a is the -- universe level for which extensionality is assumed to hold). module _ {@0 A B : Type a} where Erased-cong-↠ : @0 A ↠ B → Erased A ↠ Erased B Erased-cong-↠ A↠B = record { logical-equivalence = Erased-cong-⇔ (_↠_.logical-equivalence A↠B) ; right-inverse-of = λ { [ x ] → []-cong [ _↠_.right-inverse-of A↠B x ] } } Erased-cong-↔ : @0 A ↔ B → Erased A ↔ Erased B Erased-cong-↔ A↔B = record { surjection = Erased-cong-↠ (_↔_.surjection A↔B) ; left-inverse-of = λ { [ x ] → []-cong [ _↔_.left-inverse-of A↔B x ] } } Erased-cong-≃ : @0 A ≃ B → Erased A ≃ Erased B Erased-cong-≃ A≃B = from-isomorphism (Erased-cong-↔ (from-isomorphism A≃B)) -- []-cong is an equivalence. []-cong-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong {x = x} {y = y}) []-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence ( Erased (x ≡ y) ↝⟨ inverse $ Erased-cong-≃ []≡[]≃≡ ⟩ Erased ([ x ] ≡ [ y ]) ↝⟨ inverse Eq.⟨ _ , Very-stable-≡-Erased _ _ ⟩ ⟩□ [ x ] ≡ [ y ] □) -- The []-cong axioms can be instantiated. instance-of-[]-cong-axiomatisation : []-cong-axiomatisation a instance-of-[]-cong-axiomatisation = record { []-cong = []-cong ; []-cong-equivalence = []-cong-equivalence ; []-cong-[refl] = []-cong-[refl] } ------------------------------------------------------------------------ -- In the presence of function extensionality the []-cong axioms can -- be instantiated -- Some lemmas used to implement -- Extensionality→[]-cong-axiomatisation. module Extensionality→[]-cong-axiomatisation (ext′ : Extensionality a a) where private ext = Eq.good-ext ext′ -- Equality is stable for Erased A. -- -- The proof is based on the proof of Lemma 1.25 in "Modalities in -- Homotopy Type Theory" by Rijke, Shulman and Spitters, and the -- corresponding Coq source code. Stable-≡-Erased : {@0 A : Type a} → Stable-≡ (Erased A) Stable-≡-Erased x y eq = x ≡⟨ flip ext⁻¹ eq ( (λ (_ : Erased (x ≡ y)) → x) ≡⟨ ∘-[]-injective ( (λ (_ : x ≡ y) → x) ≡⟨ apply-ext ext (λ (eq : x ≡ y) → x ≡⟨ eq ⟩∎ y ∎) ⟩∎ (λ (_ : x ≡ y) → y) ∎) ⟩∎ (λ (_ : Erased (x ≡ y)) → y) ∎) ⟩∎ y ∎ -- A "computation rule" for Stable-≡-Erased. Stable-≡-Erased-[refl] : {@0 A : Type a} {x : Erased A} → Stable-≡-Erased x x [ refl x ] ≡ refl x Stable-≡-Erased-[refl] {x = [ x ]} = Stable-≡-Erased [ x ] [ x ] [ refl [ x ] ] ≡⟨⟩ ext⁻¹ (∘-[]-injective (apply-ext ext id)) [ refl [ x ] ] ≡⟨ ext⁻¹-∘-[]-injective ⟩ ext⁻¹ (apply-ext ext id) (refl [ x ]) ≡⟨ cong (_$ refl _) $ _≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) _ ⟩∎ refl [ x ] ∎ open Stable-≡-Erased-axiomatisation→[]-cong-axiomatisation (Stable-≡-Erased , Stable-≡-Erased-[refl]) public -- If we have extensionality, then []-cong can be implemented. -- -- The idea for this result comes from "Modalities in Homotopy Type -- Theory" in which Rijke, Shulman and Spitters state that []-cong can -- be implemented for every modality, and that it is an equivalence -- for lex modalities (Theorem 3.1 (ix)). Extensionality→[]-cong-axiomatisation : Extensionality a a → []-cong-axiomatisation a Extensionality→[]-cong-axiomatisation ext = instance-of-[]-cong-axiomatisation where open Extensionality→[]-cong-axiomatisation ext ------------------------------------------------------------------------ -- A variant of []-cong-axiomatisation -- A variant of []-cong-axiomatisation where some erased arguments -- have been replaced with non-erased ones. record []-cong-axiomatisation′ a : Type (lsuc a) where field []-cong : {A : Type a} {x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong-equivalence : Is-equivalence ([]-cong {x = x} {y = y}) []-cong-[refl] : []-cong [ refl x ] ≡ refl [ x ] -- When implementing the []-cong axioms it suffices to prove "weaker" -- variants with fewer erased arguments. -- -- See also -- Erased.Stability.[]-cong-axiomatisation≃[]-cong-axiomatisation′. []-cong-axiomatisation′→[]-cong-axiomatisation : []-cong-axiomatisation′ a → []-cong-axiomatisation a []-cong-axiomatisation′→[]-cong-axiomatisation {a = a} ax = record { []-cong = []-cong₀ ; []-cong-equivalence = []-cong₀-equivalence ; []-cong-[refl] = []-cong₀-[refl] } where open []-cong-axiomatisation′ ax []-cong₀ : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong₀ {A = A} {x = x} {y = y} = Erased (x ≡ y) →⟨ map (cong [_]→) ⟩ Erased ([ x ] ≡ [ y ]) →⟨ []-cong ⟩ [ [ x ] ] ≡ [ [ y ] ] →⟨ cong (map erased) ⟩□ [ x ] ≡ [ y ] □ []-cong₀-[refl] : {@0 A : Type a} {@0 x : A} → []-cong₀ [ refl x ] ≡ refl [ x ] []-cong₀-[refl] {x = x} = cong (map erased) ([]-cong (map (cong [_]→) [ refl x ])) ≡⟨⟩ cong (map erased) ([]-cong [ cong [_]→ (refl x) ]) ≡⟨ cong (cong (map erased) ∘ []-cong) $ []-cong₀ [ cong-refl _ ] ⟩ cong (map erased) ([]-cong [ refl [ x ] ]) ≡⟨ cong (cong (map erased)) []-cong-[refl] ⟩ cong (map erased) (refl [ [ x ] ]) ≡⟨ cong-refl _ ⟩∎ refl [ x ] ∎ []-cong₀-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong₀ {x = x} {y = y}) []-cong₀-equivalence = _≃_.is-equivalence $ Eq.↔→≃ _ (λ [x]≡[y] → [ cong erased [x]≡[y] ]) (λ [x]≡[y] → cong (map erased) ([]-cong (map (cong [_]→) [ cong erased [x]≡[y] ])) ≡⟨⟩ cong (map erased) ([]-cong [ cong [_]→ (cong erased [x]≡[y]) ]) ≡⟨ cong (cong (map erased) ∘ []-cong) $ []-cong₀ [ trans (cong-∘ _ _ _) $ sym $ cong-id _ ] ⟩ cong (map erased) ([]-cong [ [x]≡[y] ]) ≡⟨ elim (λ x≡y → cong (map erased) ([]-cong [ x≡y ]) ≡ x≡y) (λ x → cong (map erased) ([]-cong [ refl x ]) ≡⟨ cong (cong (map erased)) []-cong-[refl] ⟩ cong (map erased) (refl [ x ]) ≡⟨ cong-refl _ ⟩∎ refl x ∎) _ ⟩ [x]≡[y] ∎) (λ ([ x≡y ]) → [ cong erased (cong (map erased) ([]-cong (map (cong [_]→) [ x≡y ]))) ] ≡⟨⟩ [ cong erased (cong (map erased) ([]-cong [ cong [_]→ x≡y ])) ] ≡⟨ []-cong₀ [ elim (λ x≡y → cong erased (cong (map erased) ([]-cong [ cong [_]→ x≡y ])) ≡ x≡y) (λ x → cong erased (cong (map erased) ([]-cong [ cong [_]→ (refl x) ])) ≡⟨ cong (cong erased ∘ cong (map erased) ∘ []-cong) $ []-cong₀ [ cong-refl _ ] ⟩ cong erased (cong (map erased) ([]-cong [ refl [ x ] ])) ≡⟨ cong (cong erased ∘ cong (map erased)) []-cong-[refl] ⟩ cong erased (cong (map erased) (refl [ [ x ] ])) ≡⟨ trans (cong (cong erased) $ cong-refl _) $ cong-refl _ ⟩∎ refl x ∎) _ ] ⟩∎ [ x≡y ] ∎) ------------------------------------------------------------------------ -- Erased preserves some kinds of functions -- The following definitions are parametrised by two implementations -- of the []-cong axioms. module Erased-cong (ax₁ : []-cong-axiomatisation ℓ₁) (ax₂ : []-cong-axiomatisation ℓ₂) {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} where private module BC₁ = []-cong-axiomatisation ax₁ module BC₂ = []-cong-axiomatisation ax₂ -- Erased preserves split surjections. Erased-cong-↠ : @0 A ↠ B → Erased A ↠ Erased B Erased-cong-↠ A↠B = record { logical-equivalence = Erased-cong-⇔ (_↠_.logical-equivalence A↠B) ; right-inverse-of = λ { [ x ] → BC₂.[]-cong [ _↠_.right-inverse-of A↠B x ] } } -- Erased preserves bijections. Erased-cong-↔ : @0 A ↔ B → Erased A ↔ Erased B Erased-cong-↔ A↔B = record { surjection = Erased-cong-↠ (_↔_.surjection A↔B) ; left-inverse-of = λ { [ x ] → BC₁.[]-cong [ _↔_.left-inverse-of A↔B x ] } } -- Erased preserves equivalences. Erased-cong-≃ : @0 A ≃ B → Erased A ≃ Erased B Erased-cong-≃ A≃B = from-isomorphism (Erased-cong-↔ (from-isomorphism A≃B)) -- A variant of Erased-cong (which is defined in Erased.Level-2). Erased-cong? : @0 A ↝[ c ∣ d ] B → Erased A ↝[ c ∣ d ]ᴱ Erased B Erased-cong? hyp = generalise-erased-ext? (Erased-cong-⇔ (hyp _)) (λ ext → Erased-cong-↔ (hyp ext)) ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for a single -- universe level module []-cong₁ (ax : []-cong-axiomatisation ℓ) where open []-cong-axiomatisation ax public open Erased-cong ax ax ---------------------------------------------------------------------- -- Some definitions directly related to []-cong -- There is an equivalence between erased equality proofs and -- equalities between erased values. Erased-≡≃[]≡[] : {@0 A : Type ℓ} {@0 x y : A} → Erased (x ≡ y) ≃ ([ x ] ≡ [ y ]) Erased-≡≃[]≡[] = Eq.⟨ _ , []-cong-equivalence ⟩ -- There is a bijection between erased equality proofs and -- equalities between erased values. Erased-≡↔[]≡[] : {@0 A : Type ℓ} {@0 x y : A} → Erased (x ≡ y) ↔ [ x ] ≡ [ y ] Erased-≡↔[]≡[] = _≃_.bijection Erased-≡≃[]≡[] -- The inverse of []-cong. []-cong⁻¹ : {@0 A : Type ℓ} {@0 x y : A} → [ x ] ≡ [ y ] → Erased (x ≡ y) []-cong⁻¹ = _≃_.from Erased-≡≃[]≡[] -- Rearrangement lemmas for []-cong and []-cong⁻¹. []-cong-[]≡cong-[] : {A : Type ℓ} {x y : A} {x≡y : x ≡ y} → []-cong [ x≡y ] ≡ cong [_]→ x≡y []-cong-[]≡cong-[] {x = x} {x≡y = x≡y} = elim¹ (λ x≡y → []-cong [ x≡y ] ≡ cong [_]→ x≡y) ([]-cong [ refl x ] ≡⟨ []-cong-[refl] ⟩ refl [ x ] ≡⟨ sym $ cong-refl _ ⟩∎ cong [_]→ (refl x) ∎) x≡y []-cong⁻¹≡[cong-erased] : {@0 A : Type ℓ} {@0 x y : A} {@0 x≡y : [ x ] ≡ [ y ]} → []-cong⁻¹ x≡y ≡ [ cong erased x≡y ] []-cong⁻¹≡[cong-erased] {x≡y = x≡y} = []-cong [ erased ([]-cong⁻¹ x≡y) ≡⟨ cong erased (_↔_.from (from≡↔≡to Erased-≡≃[]≡[]) lemma) ⟩ erased [ cong erased x≡y ] ≡⟨⟩ cong erased x≡y ∎ ] where @0 lemma : _ lemma = x≡y ≡⟨ cong-id _ ⟩ cong id x≡y ≡⟨⟩ cong ([_]→ ∘ erased) x≡y ≡⟨ sym $ cong-∘ _ _ _ ⟩ cong [_]→ (cong erased x≡y) ≡⟨ sym []-cong-[]≡cong-[] ⟩∎ []-cong [ cong erased x≡y ] ∎ -- A "computation rule" for []-cong⁻¹. []-cong⁻¹-refl : {@0 A : Type ℓ} {@0 x : A} → []-cong⁻¹ (refl [ x ]) ≡ [ refl x ] []-cong⁻¹-refl {x = x} = []-cong⁻¹ (refl [ x ]) ≡⟨ []-cong⁻¹≡[cong-erased] ⟩ [ cong erased (refl [ x ]) ] ≡⟨ []-cong [ cong-refl _ ] ⟩∎ [ refl x ] ∎ -- []-cong and []-cong⁻¹ commute (kind of) with sym. []-cong⁻¹-sym : {@0 A : Type ℓ} {@0 x y : A} {x≡y : [ x ] ≡ [ y ]} → []-cong⁻¹ (sym x≡y) ≡ map sym ([]-cong⁻¹ x≡y) []-cong⁻¹-sym = elim¹ (λ x≡y → []-cong⁻¹ (sym x≡y) ≡ map sym ([]-cong⁻¹ x≡y)) ([]-cong⁻¹ (sym (refl _)) ≡⟨ cong []-cong⁻¹ sym-refl ⟩ []-cong⁻¹ (refl _) ≡⟨ []-cong⁻¹-refl ⟩ [ refl _ ] ≡⟨ []-cong [ sym sym-refl ] ⟩ [ sym (refl _) ] ≡⟨⟩ map sym [ refl _ ] ≡⟨ cong (map sym) $ sym []-cong⁻¹-refl ⟩∎ map sym ([]-cong⁻¹ (refl _)) ∎) _ []-cong-[sym] : {@0 A : Type ℓ} {@0 x y : A} {@0 x≡y : x ≡ y} → []-cong [ sym x≡y ] ≡ sym ([]-cong [ x≡y ]) []-cong-[sym] {x≡y = x≡y} = sym $ _↔_.to (from≡↔≡to $ Eq.↔⇒≃ Erased-≡↔[]≡[]) ( []-cong⁻¹ (sym ([]-cong [ x≡y ])) ≡⟨ []-cong⁻¹-sym ⟩ map sym ([]-cong⁻¹ ([]-cong [ x≡y ])) ≡⟨ cong (map sym) $ _↔_.left-inverse-of Erased-≡↔[]≡[] _ ⟩∎ map sym [ x≡y ] ∎) -- []-cong and []-cong⁻¹ commute (kind of) with trans. []-cong⁻¹-trans : {@0 A : Type ℓ} {@0 x y z : A} {x≡y : [ x ] ≡ [ y ]} {y≡z : [ y ] ≡ [ z ]} → []-cong⁻¹ (trans x≡y y≡z) ≡ [ trans (erased ([]-cong⁻¹ x≡y)) (erased ([]-cong⁻¹ y≡z)) ] []-cong⁻¹-trans {y≡z = y≡z} = elim₁ (λ x≡y → []-cong⁻¹ (trans x≡y y≡z) ≡ [ trans (erased ([]-cong⁻¹ x≡y)) (erased ([]-cong⁻¹ y≡z)) ]) ([]-cong⁻¹ (trans (refl _) y≡z) ≡⟨ cong []-cong⁻¹ $ trans-reflˡ _ ⟩ []-cong⁻¹ y≡z ≡⟨⟩ [ erased ([]-cong⁻¹ y≡z) ] ≡⟨ []-cong [ sym $ trans-reflˡ _ ] ⟩ [ trans (refl _) (erased ([]-cong⁻¹ y≡z)) ] ≡⟨⟩ [ trans (erased [ refl _ ]) (erased ([]-cong⁻¹ y≡z)) ] ≡⟨ []-cong [ cong (flip trans _) $ cong erased $ sym []-cong⁻¹-refl ] ⟩∎ [ trans (erased ([]-cong⁻¹ (refl _))) (erased ([]-cong⁻¹ y≡z)) ] ∎) _ []-cong-[trans] : {@0 A : Type ℓ} {@0 x y z : A} {@0 x≡y : x ≡ y} {@0 y≡z : y ≡ z} → []-cong [ trans x≡y y≡z ] ≡ trans ([]-cong [ x≡y ]) ([]-cong [ y≡z ]) []-cong-[trans] {x≡y = x≡y} {y≡z = y≡z} = sym $ _↔_.to (from≡↔≡to $ Eq.↔⇒≃ Erased-≡↔[]≡[]) ( []-cong⁻¹ (trans ([]-cong [ x≡y ]) ([]-cong [ y≡z ])) ≡⟨ []-cong⁻¹-trans ⟩ [ trans (erased ([]-cong⁻¹ ([]-cong [ x≡y ]))) (erased ([]-cong⁻¹ ([]-cong [ y≡z ]))) ] ≡⟨ []-cong [ cong₂ (λ p q → trans (erased p) (erased q)) (_↔_.left-inverse-of Erased-≡↔[]≡[] _) (_↔_.left-inverse-of Erased-≡↔[]≡[] _) ] ⟩∎ [ trans x≡y y≡z ] ∎) -- In an erased context there is an equivalence between equality of -- values and equality of "boxed" values. @0 ≡≃[]≡[] : {A : Type ℓ} {x y : A} → (x ≡ y) ≃ ([ x ] ≡ [ y ]) ≡≃[]≡[] = Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = []-cong ∘ [_]→ ; from = cong erased } ; right-inverse-of = λ eq → []-cong [ cong erased eq ] ≡⟨ []-cong-[]≡cong-[] ⟩ cong [_]→ (cong erased eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ } ; left-inverse-of = λ eq → cong erased ([]-cong [ eq ]) ≡⟨ cong (cong erased) []-cong-[]≡cong-[] ⟩ cong erased (cong [_]→ eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ }) -- The left-to-right and right-to-left directions of the equivalence -- are definitionally equal to certain functions. _ : _≃_.to (≡≃[]≡[] {x = x} {y = y}) ≡ []-cong ∘ [_]→ _ = refl _ @0 _ : _≃_.from (≡≃[]≡[] {x = x} {y = y}) ≡ cong erased _ = refl _ ---------------------------------------------------------------------- -- Variants of subst, cong and the J rule that take erased equality -- proofs -- A variant of subst that takes an erased equality proof. substᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : @0 A → Type p) → @0 x ≡ y → P x → P y substᴱ P eq = subst (λ ([ x ]) → P x) ([]-cong [ eq ]) -- A variant of elim₁ that takes an erased equality proof. elim₁ᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 x : A} → @0 x ≡ y → Type p) → P (refl y) → (@0 x≡y : x ≡ y) → P x≡y elim₁ᴱ {x = x} {y = y} P p x≡y = substᴱ (λ p → P (proj₂ p)) (proj₂ (singleton-contractible y) (x , x≡y)) p -- A variant of elim¹ that takes an erased equality proof. elim¹ᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 y : A} → @0 x ≡ y → Type p) → P (refl x) → (@0 x≡y : x ≡ y) → P x≡y elim¹ᴱ {x = x} {y = y} P p x≡y = substᴱ (λ p → P (proj₂ p)) (proj₂ (other-singleton-contractible x) (y , x≡y)) p -- A variant of elim that takes an erased equality proof. elimᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 x y : A} → @0 x ≡ y → Type p) → ((@0 x : A) → P (refl x)) → (@0 x≡y : x ≡ y) → P x≡y elimᴱ {y = y} P p = elim₁ᴱ P (p y) -- A variant of cong that takes an erased equality proof. congᴱ : {@0 A : Type ℓ} {@0 x y : A} (f : @0 A → B) → @0 x ≡ y → f x ≡ f y congᴱ f = elimᴱ (λ {x y} _ → f x ≡ f y) (λ x → refl (f x)) -- A "computation rule" for substᴱ. substᴱ-refl : {@0 A : Type ℓ} {@0 x : A} {P : @0 A → Type p} {p : P x} → substᴱ P (refl x) p ≡ p substᴱ-refl {P = P} {p = p} = subst (λ ([ x ]) → P x) ([]-cong [ refl _ ]) p ≡⟨ cong (flip (subst _) _) []-cong-[refl] ⟩ subst (λ ([ x ]) → P x) (refl [ _ ]) p ≡⟨ subst-refl _ _ ⟩∎ p ∎ -- If all arguments are non-erased, then one can replace substᴱ with -- subst (if the first explicit argument is η-expanded). substᴱ≡subst : {P : @0 A → Type p} {p : P x} → substᴱ P eq p ≡ subst (λ x → P x) eq p substᴱ≡subst {eq = eq} {P = P} {p = p} = elim¹ (λ eq → substᴱ P eq p ≡ subst (λ x → P x) eq p) (substᴱ P (refl _) p ≡⟨ substᴱ-refl ⟩ p ≡⟨ sym $ subst-refl _ _ ⟩∎ subst (λ x → P x) (refl _) p ∎) eq -- A computation rule for elim₁ᴱ. elim₁ᴱ-refl : ∀ {@0 A : Type ℓ} {@0 y} {P : {@0 x : A} → @0 x ≡ y → Type p} {p : P (refl y)} → elim₁ᴱ P p (refl y) ≡ p elim₁ᴱ-refl {y = y} {P = P} {p = p} = substᴱ (λ p → P (proj₂ p)) (proj₂ (singleton-contractible y) (y , refl y)) p ≡⟨ congᴱ (λ q → substᴱ (λ p → P (proj₂ p)) q _) (singleton-contractible-refl _) ⟩ substᴱ (λ p → P (proj₂ p)) (refl (y , refl y)) p ≡⟨ substᴱ-refl ⟩∎ p ∎ -- If all arguments are non-erased, then one can replace elim₁ᴱ with -- elim₁ (if the first explicit argument is η-expanded). elim₁ᴱ≡elim₁ : {P : {@0 x : A} → @0 x ≡ y → Type p} {r : P (refl y)} → elim₁ᴱ P r eq ≡ elim₁ (λ x → P x) r eq elim₁ᴱ≡elim₁ {eq = eq} {P = P} {r = r} = elim₁ (λ eq → elim₁ᴱ P r eq ≡ elim₁ (λ x → P x) r eq) (elim₁ᴱ P r (refl _) ≡⟨ elim₁ᴱ-refl ⟩ r ≡⟨ sym $ elim₁-refl _ _ ⟩∎ elim₁ (λ x → P x) r (refl _) ∎) eq -- A computation rule for elim¹ᴱ. elim¹ᴱ-refl : ∀ {@0 A : Type ℓ} {@0 x} {P : {@0 y : A} → @0 x ≡ y → Type p} {p : P (refl x)} → elim¹ᴱ P p (refl x) ≡ p elim¹ᴱ-refl {x = x} {P = P} {p = p} = substᴱ (λ p → P (proj₂ p)) (proj₂ (other-singleton-contractible x) (x , refl x)) p ≡⟨ congᴱ (λ q → substᴱ (λ p → P (proj₂ p)) q _) (other-singleton-contractible-refl _) ⟩ substᴱ (λ p → P (proj₂ p)) (refl (x , refl x)) p ≡⟨ substᴱ-refl ⟩∎ p ∎ -- If all arguments are non-erased, then one can replace elim¹ᴱ with -- elim¹ (if the first explicit argument is η-expanded). elim¹ᴱ≡elim¹ : {P : {@0 y : A} → @0 x ≡ y → Type p} {r : P (refl x)} → elim¹ᴱ P r eq ≡ elim¹ (λ x → P x) r eq elim¹ᴱ≡elim¹ {eq = eq} {P = P} {r = r} = elim¹ (λ eq → elim¹ᴱ P r eq ≡ elim¹ (λ x → P x) r eq) (elim¹ᴱ P r (refl _) ≡⟨ elim¹ᴱ-refl ⟩ r ≡⟨ sym $ elim¹-refl _ _ ⟩∎ elim¹ (λ x → P x) r (refl _) ∎) eq -- A computation rule for elimᴱ. elimᴱ-refl : {@0 A : Type ℓ} {@0 x : A} {P : {@0 x y : A} → @0 x ≡ y → Type p} (r : (@0 x : A) → P (refl x)) → elimᴱ P r (refl x) ≡ r x elimᴱ-refl _ = elim₁ᴱ-refl -- If all arguments are non-erased, then one can replace elimᴱ with -- elim (if the first two explicit arguments are η-expanded). elimᴱ≡elim : {P : {@0 x y : A} → @0 x ≡ y → Type p} {r : ∀ (@0 x) → P (refl x)} → elimᴱ P r eq ≡ elim (λ x → P x) (λ x → r x) eq elimᴱ≡elim {eq = eq} {P = P} {r = r} = elim (λ eq → elimᴱ P r eq ≡ elim (λ x → P x) (λ x → r x) eq) (λ x → elimᴱ P r (refl _) ≡⟨ elimᴱ-refl r ⟩ r x ≡⟨ sym $ elim-refl _ _ ⟩∎ elim (λ x → P x) (λ x → r x) (refl _) ∎) eq -- A "computation rule" for congᴱ. congᴱ-refl : {@0 A : Type ℓ} {@0 x : A} {f : @0 A → B} → congᴱ f (refl x) ≡ refl (f x) congᴱ-refl {x = x} {f = f} = elimᴱ (λ {x y} _ → f x ≡ f y) (λ x → refl (f x)) (refl x) ≡⟨ elimᴱ-refl (λ x → refl (f x)) ⟩∎ refl (f x) ∎ -- If all arguments are non-erased, then one can replace congᴱ with -- cong (if the first explicit argument is η-expanded). congᴱ≡cong : {f : @0 A → B} → congᴱ f eq ≡ cong (λ x → f x) eq congᴱ≡cong {eq = eq} {f = f} = elim¹ (λ eq → congᴱ f eq ≡ cong (λ x → f x) eq) (congᴱ f (refl _) ≡⟨ congᴱ-refl ⟩ refl _ ≡⟨ sym $ cong-refl _ ⟩∎ cong (λ x → f x) (refl _) ∎) eq ---------------------------------------------------------------------- -- Some equalities -- [_] can be "pushed" through subst. push-subst-[] : {@0 P : A → Type ℓ} {@0 p : P x} {x≡y : x ≡ y} → subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ subst P x≡y p ] push-subst-[] {P = P} {p = p} = elim¹ (λ x≡y → subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ subst P x≡y p ]) (subst (λ x → Erased (P x)) (refl _) [ p ] ≡⟨ subst-refl _ _ ⟩ [ p ] ≡⟨ []-cong [ sym $ subst-refl _ _ ] ⟩∎ [ subst P (refl _) p ] ∎) _ -- []-cong kind of commutes with trans. []-cong-trans : {@0 A : Type ℓ} {@0 x y z : A} {@0 p : x ≡ y} {@0 q : y ≡ z} → []-cong [ trans p q ] ≡ trans ([]-cong [ p ]) ([]-cong [ q ]) []-cong-trans = elim¹ᴱ (λ p → ∀ (@0 q) → []-cong [ trans p q ] ≡ trans ([]-cong [ p ]) ([]-cong [ q ])) (λ q → []-cong [ trans (refl _) q ] ≡⟨ cong []-cong $ []-cong [ trans-reflˡ _ ] ⟩ []-cong [ q ] ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl [ _ ]) ([]-cong [ q ]) ≡⟨ cong (flip trans _) $ sym []-cong-[refl] ⟩∎ trans ([]-cong [ refl _ ]) ([]-cong [ q ]) ∎) _ _ ---------------------------------------------------------------------- -- All h-levels are closed under Erased -- Erased commutes with H-level′ n (assuming extensionality). Erased-H-level′↔H-level′ : {@0 A : Type ℓ} → ∀ n → Erased (H-level′ n A) ↝[ ℓ ∣ ℓ ] H-level′ n (Erased A) Erased-H-level′↔H-level′ {A = A} zero ext = Erased (H-level′ zero A) ↔⟨⟩ Erased (∃ λ (x : A) → (y : A) → x ≡ y) ↔⟨ Erased-Σ↔Σ ⟩ (∃ λ (x : Erased A) → Erased ((y : A) → erased x ≡ y)) ↔⟨ (∃-cong λ _ → Erased-Π↔Π-Erased) ⟩ (∃ λ (x : Erased A) → (y : Erased A) → Erased (erased x ≡ erased y)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → from-isomorphism Erased-≡↔[]≡[]) ⟩ (∃ λ (x : Erased A) → (y : Erased A) → x ≡ y) ↔⟨⟩ H-level′ zero (Erased A) □ Erased-H-level′↔H-level′ {A = A} (suc n) ext = Erased (H-level′ (suc n) A) ↔⟨⟩ Erased ((x y : A) → H-level′ n (x ≡ y)) ↔⟨ Erased-Π↔Π-Erased ⟩ ((x : Erased A) → Erased ((y : A) → H-level′ n (erased x ≡ y))) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ ((x y : Erased A) → Erased (H-level′ n (erased x ≡ erased y))) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → Erased-H-level′↔H-level′ n ext) ⟩ ((x y : Erased A) → H-level′ n (Erased (erased x ≡ erased y))) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → H-level′-cong ext n Erased-≡↔[]≡[]) ⟩ ((x y : Erased A) → H-level′ n (x ≡ y)) ↔⟨⟩ H-level′ (suc n) (Erased A) □ -- Erased commutes with H-level n (assuming extensionality). Erased-H-level↔H-level : {@0 A : Type ℓ} → ∀ n → Erased (H-level n A) ↝[ ℓ ∣ ℓ ] H-level n (Erased A) Erased-H-level↔H-level {A = A} n ext = Erased (H-level n A) ↝⟨ Erased-cong? H-level↔H-level′ ext ⟩ Erased (H-level′ n A) ↝⟨ Erased-H-level′↔H-level′ n ext ⟩ H-level′ n (Erased A) ↝⟨ inverse-ext? H-level↔H-level′ ext ⟩□ H-level n (Erased A) □ -- H-level n is closed under Erased. H-level-Erased : {@0 A : Type ℓ} → ∀ n → @0 H-level n A → H-level n (Erased A) H-level-Erased n h = Erased-H-level↔H-level n _ [ h ] ---------------------------------------------------------------------- -- Some closure properties related to Is-proposition -- If A is a proposition, then Dec-Erased A is a proposition -- (assuming extensionality). Is-proposition-Dec-Erased : {@0 A : Type ℓ} → Extensionality ℓ lzero → @0 Is-proposition A → Is-proposition (Dec-Erased A) Is-proposition-Dec-Erased {A = A} ext p = $⟨ Dec-closure-propositional ext (H-level-Erased 1 p) ⟩ Is-proposition (Dec (Erased A)) ↝⟨ H-level-cong _ 1 (inverse $ Dec-Erased↔Dec-Erased {k = equivalence} ext) ⦂ (_ → _) ⟩□ Is-proposition (Dec-Erased A) □ -- If A is a set, then Decidable-erased-equality A is a proposition -- (assuming extensionality). Is-proposition-Decidable-erased-equality : {A : Type ℓ} → Extensionality ℓ ℓ → @0 Is-set A → Is-proposition (Decidable-erased-equality A) Is-proposition-Decidable-erased-equality ext s = Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Is-proposition-Dec-Erased (lower-extensionality lzero _ ext) s -- Erasedᴾ preserves Is-proposition. Is-proposition-Erasedᴾ : {@0 A : Type a} {@0 B : Type b} {@0 R : A → B → Type ℓ} → @0 (∀ {x y} → Is-proposition (R x y)) → ∀ {x y} → Is-proposition (Erasedᴾ R x y) Is-proposition-Erasedᴾ prop = H-level-Erased 1 prop ---------------------------------------------------------------------- -- A property related to "Modalities in Homotopy Type Theory" by -- Rijke, Shulman and Spitters -- Erased is a lex modality (see Theorem 3.1, case (i) in -- "Modalities in Homotopy Type Theory" for the definition used -- here). lex-modality : {@0 A : Type ℓ} {@0 x y : A} → Contractible (Erased A) → Contractible (Erased (x ≡ y)) lex-modality {A = A} {x = x} {y = y} = Contractible (Erased A) ↝⟨ _⇔_.from (Erased-H-level↔H-level 0 _) ⟩ Erased (Contractible A) ↝⟨ map (⇒≡ 0) ⟩ Erased (Contractible (x ≡ y)) ↝⟨ Erased-H-level↔H-level 0 _ ⟩□ Contractible (Erased (x ≡ y)) □ ---------------------------------------------------------------------- -- Erased "commutes" with various things -- Erased "commutes" with _⁻¹_. Erased-⁻¹ : {@0 A : Type a} {@0 B : Type ℓ} {@0 f : A → B} {@0 y : B} → Erased (f ⁻¹ y) ↔ map f ⁻¹ [ y ] Erased-⁻¹ {f = f} {y = y} = Erased (∃ λ x → f x ≡ y) ↝⟨ Erased-Σ↔Σ ⟩ (∃ λ x → Erased (f (erased x) ≡ y)) ↝⟨ (∃-cong λ _ → Erased-≡↔[]≡[]) ⟩□ (∃ λ x → map f x ≡ [ y ]) □ -- Erased "commutes" with Split-surjective. Erased-Split-surjective↔Split-surjective : {@0 A : Type a} {@0 B : Type ℓ} {@0 f : A → B} → Erased (Split-surjective f) ↝[ ℓ ∣ a ⊔ ℓ ] Split-surjective (map f) Erased-Split-surjective↔Split-surjective {f = f} ext = Erased (∀ y → ∃ λ x → f x ≡ y) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ y → Erased (∃ λ x → f x ≡ erased y)) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-Σ↔Σ) ⟩ (∀ y → ∃ λ x → Erased (f (erased x) ≡ erased y)) ↝⟨ (∀-cong ext λ _ → ∃-cong λ _ → from-isomorphism Erased-≡↔[]≡[]) ⟩ (∀ y → ∃ λ x → [ f (erased x) ] ≡ y) ↔⟨⟩ (∀ y → ∃ λ x → map f x ≡ y) □ ---------------------------------------------------------------------- -- Some lemmas related to whether [_]→ is injective or an embedding -- In erased contexts [_]→ is injective. -- -- See also Erased.With-K.Injective-[]. @0 Injective-[] : {A : Type ℓ} → Injective {A = A} [_]→ Injective-[] = erased ∘ []-cong⁻¹ -- If A is a proposition, then [_]→ {A = A} is an embedding. -- -- See also Erased-Is-embedding-[] and Erased-Split-surjective-[] -- above as well as Very-stable→Is-embedding-[] and -- Very-stable→Split-surjective-[] in Erased.Stability and -- Injective-[] and Is-embedding-[] in Erased.With-K. Is-proposition→Is-embedding-[] : {A : Type ℓ} → Is-proposition A → Is-embedding [ A ∣_]→ Is-proposition→Is-embedding-[] prop = _⇔_.to (Emb.Injective⇔Is-embedding set (H-level-Erased 2 set) [_]→) (λ _ → prop _ _) where set = mono₁ 1 prop ---------------------------------------------------------------------- -- Variants of some functions from Equality.Decision-procedures -- A variant of Equality.Decision-procedures.Σ.set⇒dec⇒dec⇒dec. set⇒dec-erased⇒dec-erased⇒Σ-dec-erased : {@0 A : Type ℓ} {@0 P : A → Type p} {@0 x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → @0 Is-set A → Dec-Erased (x₁ ≡ x₂) → (∀ (@0 eq) → Dec-Erased (substᴱ (λ x → P x) eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) set⇒dec-erased⇒dec-erased⇒Σ-dec-erased _ (no [ x₁≢x₂ ]) _ = no [ x₁≢x₂ ∘ cong proj₁ ] set⇒dec-erased⇒dec-erased⇒Σ-dec-erased {P = P} {y₁ = y₁} {y₂ = y₂} set₁ (yes [ x₁≡x₂ ]) dec₂ = ⊎-map (map λ cast-y₁≡y₂ → Σ-≡,≡→≡ x₁≡x₂ (subst (λ x → P x) x₁≡x₂ y₁ ≡⟨ sym substᴱ≡subst ⟩ substᴱ (λ x → P x) x₁≡x₂ y₁ ≡⟨ cast-y₁≡y₂ ⟩∎ y₂ ∎)) (map λ cast-y₁≢y₂ eq → $⟨ proj₂ (Σ-≡,≡←≡ eq) ⟩ subst (λ x → P x) (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ ≡⇒↝ _ $ cong (_≡ _) $ sym substᴱ≡subst ⟩ substᴱ (λ x → P x) (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ subst (λ p → substᴱ _ p _ ≡ _) (set₁ _ _) ⟩ substᴱ (λ x → P x) x₁≡x₂ y₁ ≡ y₂ ↝⟨ cast-y₁≢y₂ ⟩□ ⊥ □) (dec₂ x₁≡x₂) -- A variant of Equality.Decision-procedures.Σ.decidable⇒dec⇒dec. decidable-erased⇒dec-erased⇒Σ-dec-erased : {@0 A : Type ℓ} {@0 P : A → Type p} {x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → Decidable-erased-equality A → (∀ (@0 eq) → Dec-Erased (substᴱ (λ x → P x) eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) decidable-erased⇒dec-erased⇒Σ-dec-erased dec = set⇒dec-erased⇒dec-erased⇒Σ-dec-erased (decidable⇒set (Decidable-erased-equality≃Decidable-equality _ dec)) (dec _ _) -- A variant of Equality.Decision-procedures.Σ.Dec._≟_. decidable-erased⇒decidable-erased⇒Σ-decidable-erased : {@0 A : Type ℓ} {P : @0 A → Type p} → Decidable-erased-equality A → ({x : A} → Decidable-erased-equality (P x)) → Decidable-erased-equality (Σ A λ x → P x) decidable-erased⇒decidable-erased⇒Σ-decidable-erased {P = P} decA decP (_ , x₂) (_ , y₂) = decidable-erased⇒dec-erased⇒Σ-dec-erased decA (λ eq → decP (substᴱ P eq x₂) y₂) ------------------------------------------------------------------------ -- Erased commutes with W -- Erased commutes with W (assuming extensionality and an -- implementation of the []-cong axioms). -- -- See also Erased-W↔W′ and Erased-W↔W below. Erased-W↔W-[]-cong : {@0 A : Type a} {@0 P : A → Type p} → []-cong-axiomatisation (a ⊔ p) → Erased (W A P) ↝[ p ∣ a ⊔ p ] W (Erased A) (λ x → Erased (P (erased x))) Erased-W↔W-[]-cong {a = a} {p = p} {A = A} {P = P} ax = generalise-ext? Erased-W⇔W (λ ext → to∘from ext , from∘to ext) where open []-cong-axiomatisation ax open _⇔_ Erased-W⇔W to∘from : Extensionality p (a ⊔ p) → (x : W (Erased A) (λ x → Erased (P (erased x)))) → to (from x) ≡ x to∘from ext (sup [ x ] f) = cong (sup [ x ]) $ apply-ext ext λ ([ y ]) → to∘from ext (f [ y ]) from∘to : Extensionality p (a ⊔ p) → (x : Erased (W A P)) → from (to x) ≡ x from∘to ext [ sup x f ] = []-cong [ (cong (sup x) $ apply-ext ext λ y → cong erased (from∘to ext [ f y ])) ] -- Erased commutes with W (assuming extensionality). -- -- See also Erased-W↔W below: That property is defined assuming that -- the []-cong axioms can be instantiated, but is stated using -- _↝[ p ∣ a ⊔ p ]_ instead of _↝[ a ⊔ p ∣ a ⊔ p ]_. Erased-W↔W′ : {@0 A : Type a} {@0 P : A → Type p} → Erased (W A P) ↝[ a ⊔ p ∣ a ⊔ p ] W (Erased A) (λ x → Erased (P (erased x))) Erased-W↔W′ {a = a} = generalise-ext? Erased-W⇔W (λ ext → let bij = Erased-W↔W-[]-cong (Extensionality→[]-cong-axiomatisation ext) (lower-extensionality a lzero ext) in _↔_.right-inverse-of bij , _↔_.left-inverse-of bij) ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for two -- universe levels module []-cong₂ (ax₁ : []-cong-axiomatisation ℓ₁) (ax₂ : []-cong-axiomatisation ℓ₂) where private module BC₁ = []-cong₁ ax₁ module BC₂ = []-cong₁ ax₂ ---------------------------------------------------------------------- -- Some equalities -- The function map (cong f) can be expressed in terms of -- cong (map f) (up to pointwise equality). map-cong≡cong-map : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 x y : A} {@0 f : A → B} {x≡y : Erased (x ≡ y)} → map (cong f) x≡y ≡ BC₂.[]-cong⁻¹ (cong (map f) (BC₁.[]-cong x≡y)) map-cong≡cong-map {f = f} {x≡y = [ x≡y ]} = [ cong f x≡y ] ≡⟨⟩ [ cong (erased ∘ map f ∘ [_]→) x≡y ] ≡⟨ BC₂.[]-cong [ sym $ cong-∘ _ _ _ ] ⟩ [ cong (erased ∘ map f) (cong [_]→ x≡y) ] ≡⟨ BC₂.[]-cong [ cong (cong _) $ sym BC₁.[]-cong-[]≡cong-[] ] ⟩ [ cong (erased ∘ map f) (BC₁.[]-cong [ x≡y ]) ] ≡⟨ BC₂.[]-cong [ sym $ cong-∘ _ _ _ ] ⟩ [ cong erased (cong (map f) (BC₁.[]-cong [ x≡y ])) ] ≡⟨ sym BC₂.[]-cong⁻¹≡[cong-erased] ⟩∎ BC₂.[]-cong⁻¹ (cong (map f) (BC₁.[]-cong [ x≡y ])) ∎ -- []-cong kind of commutes with cong. []-cong-cong : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} {@0 x y : A} {@0 p : x ≡ y} → BC₂.[]-cong [ cong f p ] ≡ cong (map f) (BC₁.[]-cong [ p ]) []-cong-cong {f = f} = BC₁.elim¹ᴱ (λ p → BC₂.[]-cong [ cong f p ] ≡ cong (map f) (BC₁.[]-cong [ p ])) (BC₂.[]-cong [ cong f (refl _) ] ≡⟨ cong BC₂.[]-cong (BC₂.[]-cong [ cong-refl _ ]) ⟩ BC₂.[]-cong [ refl _ ] ≡⟨ BC₂.[]-cong-[refl] ⟩ refl _ ≡⟨ sym $ cong-refl _ ⟩ cong (map f) (refl _) ≡⟨ sym $ cong (cong (map f)) BC₁.[]-cong-[refl] ⟩∎ cong (map f) (BC₁.[]-cong [ refl _ ]) ∎) _ ---------------------------------------------------------------------- -- Erased "commutes" with one thing -- Erased "commutes" with Has-quasi-inverse. Erased-Has-quasi-inverse↔Has-quasi-inverse : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Has-quasi-inverse f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Has-quasi-inverse (map f) Erased-Has-quasi-inverse↔Has-quasi-inverse {A = A} {B = B} {f = f} {k = k} ext = Erased (∃ λ g → (∀ x → f (g x) ≡ x) × (∀ x → g (f x) ≡ x)) ↔⟨ Erased-Σ↔Σ ⟩ (∃ λ g → Erased ((∀ x → f (erased g x) ≡ x) × (∀ x → erased g (f x) ≡ x))) ↝⟨ (∃-cong λ _ → from-isomorphism Erased-Σ↔Σ) ⟩ (∃ λ g → Erased (∀ x → f (erased g x) ≡ x) × Erased (∀ x → erased g (f x) ≡ x)) ↝⟨ Σ-cong Erased-Π↔Π-Erased (λ g → lemma₁ (erased g) ×-cong lemma₂ (erased g)) ⟩□ (∃ λ g → (∀ x → map f (g x) ≡ x) × (∀ x → g (map f x) ≡ x)) □ where lemma₁ : (@0 g : B → A) → _ ↝[ k ] _ lemma₁ g = Erased (∀ x → f (g x) ≡ x) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (f (g (erased x)) ≡ erased x)) ↝⟨ (∀-cong (lower-extensionality? k ℓ₁ ℓ₁ ext) λ _ → from-isomorphism BC₂.Erased-≡↔[]≡[]) ⟩ (∀ x → [ f (g (erased x)) ] ≡ x) ↔⟨⟩ (∀ x → map (f ∘ g) x ≡ x) □ lemma₂ : (@0 g : B → A) → _ ↝[ k ] _ lemma₂ g = Erased (∀ x → g (f x) ≡ x) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (g (f (erased x)) ≡ erased x)) ↝⟨ (∀-cong (lower-extensionality? k ℓ₂ ℓ₂ ext) λ _ → from-isomorphism BC₁.Erased-≡↔[]≡[]) ⟩ (∀ x → [ g (f (erased x)) ] ≡ x) ↔⟨⟩ (∀ x → map (g ∘ f) x ≡ x) □ ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for the maximum -- of two universe levels (as well as for the two universe levels) -- It is possible to instantiate the first two arguments using the -- third and lower-[]-cong-axiomatisation, but this is not what is -- done in the module []-cong below. module []-cong₂-⊔ (ax₁ : []-cong-axiomatisation ℓ₁) (ax₂ : []-cong-axiomatisation ℓ₂) (ax : []-cong-axiomatisation (ℓ₁ ⊔ ℓ₂)) where private module EC = Erased-cong ax ax module BC₁ = []-cong₁ ax₁ module BC₂ = []-cong₁ ax₂ module BC = []-cong₁ ax ---------------------------------------------------------------------- -- A property related to "Modalities in Homotopy Type Theory" by -- Rijke, Shulman and Spitters -- A function f is Erased-connected in the sense of Rijke et al. -- exactly when there is an erased proof showing that f is an -- equivalence (assuming extensionality). -- -- See also Erased-Is-equivalence↔Is-equivalence below. Erased-connected↔Erased-Is-equivalence : {@0 A : Type ℓ₁} {B : Type ℓ₂} {@0 f : A → B} → (∀ y → Contractible (Erased (f ⁻¹ y))) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Erased (Is-equivalence f) Erased-connected↔Erased-Is-equivalence {f = f} {k = k} ext = (∀ y → Contractible (Erased (f ⁻¹ y))) ↝⟨ (∀-cong (lower-extensionality? k ℓ₁ lzero ext) λ _ → inverse-ext? (BC.Erased-H-level↔H-level 0) ext) ⟩ (∀ y → Erased (Contractible (f ⁻¹ y))) ↔⟨ inverse Erased-Π↔Π ⟩ Erased (∀ y → Contractible (f ⁻¹ y)) ↔⟨⟩ Erased (CP.Is-equivalence f) ↝⟨ inverse-ext? (λ ext → EC.Erased-cong? Is-equivalence≃Is-equivalence-CP ext) ext ⟩□ Erased (Is-equivalence f) □ ---------------------------------------------------------------------- -- Erased "commutes" with various things -- Erased "commutes" with Is-equivalence. Erased-Is-equivalence↔Is-equivalence : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Is-equivalence f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Is-equivalence (map f) Erased-Is-equivalence↔Is-equivalence {f = f} {k = k} ext = Erased (Is-equivalence f) ↝⟨ EC.Erased-cong? Is-equivalence≃Is-equivalence-CP ext ⟩ Erased (∀ x → Contractible (f ⁻¹ x)) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (Contractible (f ⁻¹ erased x))) ↝⟨ (∀-cong ext′ λ _ → BC.Erased-H-level↔H-level 0 ext) ⟩ (∀ x → Contractible (Erased (f ⁻¹ erased x))) ↝⟨ (∀-cong ext′ λ _ → H-level-cong ext 0 BC₂.Erased-⁻¹) ⟩ (∀ x → Contractible (map f ⁻¹ x)) ↝⟨ inverse-ext? Is-equivalence≃Is-equivalence-CP ext ⟩□ Is-equivalence (map f) □ where ext′ = lower-extensionality? k ℓ₁ lzero ext -- Erased "commutes" with Injective. Erased-Injective↔Injective : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Injective f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Injective (map f) Erased-Injective↔Injective {f = f} {k = k} ext = Erased (∀ {x y} → f x ≡ f y → x ≡ y) ↔⟨ EC.Erased-cong-↔ Bijection.implicit-Π↔Π ⟩ Erased (∀ x {y} → f x ≡ f y → x ≡ y) ↝⟨ EC.Erased-cong? (λ {k} ext → ∀-cong (lower-extensionality? k ℓ₂ lzero ext) λ _ → from-isomorphism Bijection.implicit-Π↔Π) ext ⟩ Erased (∀ x y → f x ≡ f y → x ≡ y) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (∀ y → f (erased x) ≡ f y → erased x ≡ y)) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ (∀ x y → Erased (f (erased x) ≡ f (erased y) → erased x ≡ erased y)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ (∀ x y → Erased (f (erased x) ≡ f (erased y)) → Erased (erased x ≡ erased y)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → generalise-ext?-sym (λ {k} ext → →-cong (lower-extensionality? ⌊ k ⌋-sym ℓ₁ ℓ₂ ext) (from-isomorphism BC₂.Erased-≡↔[]≡[]) (from-isomorphism BC₁.Erased-≡↔[]≡[])) ext) ⟩ (∀ x y → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism $ inverse Bijection.implicit-Π↔Π) ⟩ (∀ x {y} → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□ (∀ {x y} → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) □ where ext′ = lower-extensionality? k ℓ₂ lzero ext -- Erased "commutes" with Is-embedding. Erased-Is-embedding↔Is-embedding : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Is-embedding f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Is-embedding (map f) Erased-Is-embedding↔Is-embedding {f = f} {k = k} ext = Erased (∀ x y → Is-equivalence (cong f)) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (∀ y → Is-equivalence (cong f))) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ (∀ x y → Erased (Is-equivalence (cong f))) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → Erased-Is-equivalence↔Is-equivalence ext) ⟩ (∀ x y → Is-equivalence (map (cong f))) ↝⟨ (∀-cong ext′ λ x → ∀-cong ext′ λ y → Is-equivalence-cong ext λ _ → []-cong₂.map-cong≡cong-map ax₁ ax₂) ⟩ (∀ x y → Is-equivalence (BC₂.[]-cong⁻¹ ∘ cong (map f) ∘ BC₁.[]-cong)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → inverse-ext? (Is-equivalence≃Is-equivalence-∘ʳ BC₁.[]-cong-equivalence) ext) ⟩ (∀ x y → Is-equivalence (BC₂.[]-cong⁻¹ ∘ cong (map f))) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → inverse-ext? (Is-equivalence≃Is-equivalence-∘ˡ (_≃_.is-equivalence $ from-isomorphism $ inverse BC₂.Erased-≡↔[]≡[])) ext) ⟩□ (∀ x y → Is-equivalence (cong (map f))) □ where ext′ = lower-extensionality? k ℓ₂ lzero ext ---------------------------------------------------------------------- -- Erased commutes with various type formers -- Erased commutes with W (assuming extensionality). Erased-W↔W : {@0 A : Type ℓ₁} {@0 P : A → Type ℓ₂} → Erased (W A P) ↝[ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] W (Erased A) (λ x → Erased (P (erased x))) Erased-W↔W = Erased-W↔W-[]-cong ax -- Erased commutes with _⇔_. Erased-⇔↔⇔ : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} → Erased (A ⇔ B) ↔ (Erased A ⇔ Erased B) Erased-⇔↔⇔ {A = A} {B = B} = Erased (A ⇔ B) ↝⟨ EC.Erased-cong-↔ ⇔↔→×→ ⟩ Erased ((A → B) × (B → A)) ↝⟨ Erased-Σ↔Σ ⟩ Erased (A → B) × Erased (B → A) ↝⟨ Erased-Π↔Π-Erased ×-cong Erased-Π↔Π-Erased ⟩ (Erased A → Erased B) × (Erased B → Erased A) ↝⟨ inverse ⇔↔→×→ ⟩□ (Erased A ⇔ Erased B) □ -- Erased commutes with _↣_. Erased-cong-↣ : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} → @0 A ↣ B → Erased A ↣ Erased B Erased-cong-↣ A↣B = record { to = map (_↣_.to A↣B) ; injective = Erased-Injective↔Injective _ [ _↣_.injective A↣B ] } ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for all -- universe levels module []-cong (ax : ∀ {ℓ} → []-cong-axiomatisation ℓ) where private open module EC {ℓ₁ ℓ₂} = Erased-cong (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) public open module BC₁ {ℓ} = []-cong₁ (ax {ℓ = ℓ}) public open module BC₂ {ℓ₁ ℓ₂} = []-cong₂ (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) public open module BC₂-⊔ {ℓ₁ ℓ₂} = []-cong₂-⊔ (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) (ax {ℓ = ℓ₁ ⊔ ℓ₂}) public ------------------------------------------------------------------------ -- Some results that were proved assuming extensionality and also that -- one or more instances of the []-cong axioms can be implemented, -- reproved without the latter assumptions module Extensionality where -- Erased commutes with H-level′ n (assuming extensionality). Erased-H-level′≃H-level′ : {@0 A : Type a} → Extensionality a a → ∀ n → Erased (H-level′ n A) ≃ H-level′ n (Erased A) Erased-H-level′≃H-level′ ext n = []-cong₁.Erased-H-level′↔H-level′ (Extensionality→[]-cong-axiomatisation ext) n ext -- Erased commutes with H-level n (assuming extensionality). Erased-H-level≃H-level : {@0 A : Type a} → Extensionality a a → ∀ n → Erased (H-level n A) ≃ H-level n (Erased A) Erased-H-level≃H-level ext n = []-cong₁.Erased-H-level↔H-level (Extensionality→[]-cong-axiomatisation ext) n ext -- If A is a set, then Decidable-erased-equality A is a proposition -- (assuming extensionality). Is-proposition-Decidable-erased-equality′ : {A : Type a} → Extensionality a a → @0 Is-set A → Is-proposition (Decidable-erased-equality A) Is-proposition-Decidable-erased-equality′ ext = []-cong₁.Is-proposition-Decidable-erased-equality (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Split-surjective. Erased-Split-surjective≃Split-surjective : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality b (a ⊔ b) → Erased (Split-surjective f) ≃ Split-surjective (map f) Erased-Split-surjective≃Split-surjective {a = a} ext = []-cong₁.Erased-Split-surjective↔Split-surjective (Extensionality→[]-cong-axiomatisation (lower-extensionality lzero a ext)) ext -- A function f is Erased-connected in the sense of Rijke et al. -- exactly when there is an erased proof showing that f is an -- equivalence (assuming extensionality). Erased-connected≃Erased-Is-equivalence : {@0 A : Type a} {B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → (∀ y → Contractible (Erased (f ⁻¹ y))) ≃ Erased (Is-equivalence f) Erased-connected≃Erased-Is-equivalence {a = a} {b = b} ext = []-cong₂-⊔.Erased-connected↔Erased-Is-equivalence (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Is-equivalence (assuming extensionality). Erased-Is-equivalence≃Is-equivalence : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Is-equivalence f) ≃ Is-equivalence (map f) Erased-Is-equivalence≃Is-equivalence {a = a} {b = b} ext = []-cong₂-⊔.Erased-Is-equivalence↔Is-equivalence (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Has-quasi-inverse (assuming -- extensionality). Erased-Has-quasi-inverse≃Has-quasi-inverse : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Has-quasi-inverse f) ≃ Has-quasi-inverse (map f) Erased-Has-quasi-inverse≃Has-quasi-inverse {a = a} {b = b} ext = []-cong₂.Erased-Has-quasi-inverse↔Has-quasi-inverse (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) ext -- Erased "commutes" with Injective (assuming extensionality). Erased-Injective≃Injective : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Injective f) ≃ Injective (map f) Erased-Injective≃Injective {a = a} {b = b} ext = []-cong₂-⊔.Erased-Injective↔Injective (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Is-embedding (assuming extensionality). Erased-Is-embedding≃Is-embedding : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Is-embedding f) ≃ Is-embedding (map f) Erased-Is-embedding≃Is-embedding {a = a} {b = b} ext = []-cong₂-⊔.Erased-Is-embedding↔Is-embedding (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext ------------------------------------------------------------------------ -- Some lemmas related to []-cong-axiomatisation -- Any two implementations of []-cong are pointwise equal. []-cong-unique : {@0 A : Type a} {@0 x y : A} {x≡y : Erased (x ≡ y)} (ax₁ ax₂ : []-cong-axiomatisation a) → []-cong-axiomatisation.[]-cong ax₁ x≡y ≡ []-cong-axiomatisation.[]-cong ax₂ x≡y []-cong-unique {x = x} ax₁ ax₂ = BC₁.elim¹ᴱ (λ x≡y → BC₁.[]-cong [ x≡y ] ≡ BC₂.[]-cong [ x≡y ]) (BC₁.[]-cong [ refl x ] ≡⟨ BC₁.[]-cong-[refl] ⟩ refl [ x ] ≡⟨ sym BC₂.[]-cong-[refl] ⟩∎ BC₂.[]-cong [ refl x ] ∎) _ where module BC₁ = []-cong₁ ax₁ module BC₂ = []-cong₁ ax₂ -- The type []-cong-axiomatisation a is propositional (assuming -- extensionality). -- -- The proof is based on a proof due to Nicolai Kraus that shows that -- "J + its computation rule" is contractible, see -- Equality.Instances-related.Equality-with-J-contractible. []-cong-axiomatisation-propositional : Extensionality (lsuc a) a → Is-proposition ([]-cong-axiomatisation a) []-cong-axiomatisation-propositional {a = a} ext = [inhabited⇒contractible]⇒propositional λ ax → let module BC = []-cong₁ ax module EC = Erased-cong ax ax in _⇔_.from contractible⇔↔⊤ ([]-cong-axiomatisation a ↔⟨ Eq.↔→≃ (λ (record { []-cong = c ; []-cong-equivalence = e ; []-cong-[refl] = r }) _ → (λ ([ _ , _ , x≡y ]) → c [ x≡y ]) , (λ _ → r) , (λ _ _ → e)) (λ f → record { []-cong = λ ([ x≡y ]) → f _ .proj₁ [ _ , _ , x≡y ] ; []-cong-equivalence = f _ .proj₂ .proj₂ _ _ ; []-cong-[refl] = f _ .proj₂ .proj₁ _ }) refl refl ⟩ ((([ A ]) : Erased (Type a)) → ∃ λ (c : ((([ x , y , _ ]) : Erased (A ²/≡)) → [ x ] ≡ [ y ])) → ((([ x ]) : Erased A) → c [ x , x , refl x ] ≡ refl [ x ]) × ((([ x ]) ([ y ]) : Erased A) → Is-equivalence {A = Erased (x ≡ y)} {B = [ x ] ≡ [ y ]} (λ ([ x≡y ]) → c [ x , y , x≡y ]))) ↝⟨ (∀-cong ext λ _ → Σ-cong (inverse $ Π-cong ext′ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ → Bijection.id) λ c → ∃-cong λ r → ∀-cong ext′ λ ([ x ]) → ∀-cong ext′ λ ([ y ]) → Is-equivalence-cong ext′ λ ([ x≡y ]) → c [ x , y , x≡y ] ≡⟨ BC.elim¹ᴱ (λ x≡y → c [ _ , _ , x≡y ] ≡ BC.[]-cong [ x≡y ]) ( c [ x , x , refl x ] ≡⟨ r [ x ] ⟩ refl [ x ] ≡⟨ sym BC.[]-cong-[refl] ⟩∎ BC.[]-cong [ refl x ] ∎) _ ⟩∎ BC.[]-cong [ x≡y ] ∎) ⟩ ((([ A ]) : Erased (Type a)) → ∃ λ (c : ((x : Erased A) → x ≡ x)) → ((x : Erased A) → c x ≡ refl x) × ((([ x ]) ([ y ]) : Erased A) → Is-equivalence {A = Erased (x ≡ y)} {B = [ x ] ≡ [ y ]} (λ ([ x≡y ]) → BC.[]-cong [ x≡y ]))) ↝⟨ (∀-cong ext λ _ → ∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure ext′ 1 λ _ → Π-closure ext′ 1 λ _ → Eq.propositional ext′ _) (λ _ _ → BC.[]-cong-equivalence)) ⟩ ((([ A ]) : Erased (Type a)) → ∃ λ (c : ((x : Erased A) → x ≡ x)) → ((x : Erased A) → c x ≡ refl x)) ↝⟨ (∀-cong ext λ _ → inverse ΠΣ-comm) ⟩ ((([ A ]) : Erased (Type a)) (x : Erased A) → ∃ λ (c : x ≡ x) → c ≡ refl x) ↔⟨⟩ ((([ A ]) : Erased (Type a)) (x : Erased A) → Singleton (refl x)) ↝⟨ _⇔_.to contractible⇔↔⊤ $ (Π-closure ext 0 λ _ → Π-closure ext′ 0 λ _ → singleton-contractible _) ⟩□ ⊤ □) where ext′ : Extensionality a a ext′ = lower-extensionality _ lzero ext -- The type []-cong-axiomatisation a is contractible (assuming -- extensionality). []-cong-axiomatisation-contractible : Extensionality (lsuc a) a → Contractible ([]-cong-axiomatisation a) []-cong-axiomatisation-contractible {a = a} ext = propositional⇒inhabited⇒contractible ([]-cong-axiomatisation-propositional ext) (Extensionality→[]-cong-axiomatisation (lower-extensionality _ lzero ext)) ------------------------------------------------------------------------ -- An alternative to []-cong-axiomatisation -- An axiomatisation of substᴱ, restricted to a fixed universe, along -- with its computation rule. Substᴱ-axiomatisation : (ℓ : Level) → Type (lsuc ℓ) Substᴱ-axiomatisation ℓ = ∃ λ (substᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : @0 A → Type ℓ) → @0 x ≡ y → P x → P y) → {@0 A : Type ℓ} {@0 x : A} {P : @0 A → Type ℓ} {p : P x} → substᴱ P (refl x) p ≡ p private -- The type []-cong-axiomatisation ℓ is logically equivalent to -- Substᴱ-axiomatisation ℓ. []-cong-axiomatisation⇔Substᴱ-axiomatisation : []-cong-axiomatisation ℓ ⇔ Substᴱ-axiomatisation ℓ []-cong-axiomatisation⇔Substᴱ-axiomatisation {ℓ = ℓ} = record { to = to; from = from } where to : []-cong-axiomatisation ℓ → Substᴱ-axiomatisation ℓ to ax = []-cong₁.substᴱ ax , []-cong₁.substᴱ-refl ax from : Substᴱ-axiomatisation ℓ → []-cong-axiomatisation ℓ from (substᴱ , substᴱ-refl) = λ where .[]-cong-axiomatisation.[]-cong → []-cong .[]-cong-axiomatisation.[]-cong-[refl] → substᴱ-refl .[]-cong-axiomatisation.[]-cong-equivalence {x = x} → _≃_.is-equivalence $ Eq.↔→≃ _ (λ [x]≡[y] → [ cong erased [x]≡[y] ]) (elim¹ (λ [x]≡[y] → substᴱ (λ y → [ x ] ≡ [ y ]) (cong erased [x]≡[y]) (refl [ x ]) ≡ [x]≡[y]) (substᴱ (λ y → [ x ] ≡ [ y ]) (cong erased (refl [ x ])) (refl [ x ]) ≡⟨ substᴱ (λ eq → substᴱ (λ y → [ x ] ≡ [ y ]) eq (refl [ x ]) ≡ substᴱ (λ y → [ x ] ≡ [ y ]) (refl x) (refl [ x ])) (sym $ cong-refl _) (refl _) ⟩ substᴱ (λ y → [ x ] ≡ [ y ]) (refl x) (refl [ x ]) ≡⟨ substᴱ-refl ⟩∎ refl [ x ] ∎)) (λ ([ x≡y ]) → []-cong [ elim¹ (λ x≡y → cong erased ([]-cong [ x≡y ]) ≡ x≡y) (cong erased ([]-cong [ refl _ ]) ≡⟨ cong (cong erased) substᴱ-refl ⟩ cong erased (refl [ _ ]) ≡⟨ cong-refl _ ⟩∎ refl _ ∎) x≡y ]) where []-cong : {@0 A : Type ℓ} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong {x = x} ([ x≡y ]) = substᴱ (λ y → [ x ] ≡ [ y ]) x≡y (refl [ x ]) -- The type Substᴱ-axiomatisation ℓ is propositional (assuming -- extensionality). -- -- The proof is based on a proof due to Nicolai Kraus that shows that -- "J + its computation rule" is contractible, see -- Equality.Instances-related.Equality-with-J-contractible. Substᴱ-axiomatisation-propositional : Extensionality (lsuc ℓ) (lsuc ℓ) → Is-proposition (Substᴱ-axiomatisation ℓ) Substᴱ-axiomatisation-propositional {ℓ = ℓ} ext = [inhabited⇒contractible]⇒propositional λ ax → let ax′ = _⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation ax module EC = Erased-cong ax′ ax′ in _⇔_.from contractible⇔↔⊤ (Substᴱ-axiomatisation ℓ ↔⟨ Eq.↔→≃ (λ (substᴱ , substᴱ-refl) _ P → (λ ([ _ , _ , x≡y ]) → substᴱ (λ A → P [ A ]) x≡y) , (λ _ _ → substᴱ-refl)) (λ hyp → (λ P x≡y p → hyp _ (λ ([ A ]) → P A) .proj₁ [ _ , _ , x≡y ] p) , hyp _ _ .proj₂ _ _) refl refl ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) → ∃ λ (s : ((([ x , y , _ ]) : Erased (A ²/≡)) → P [ x ] → P [ y ])) → ((([ x ]) : Erased A) (p : P [ x ]) → s [ x , x , refl x ] p ≡ p)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → Σ-cong (inverse $ Π-cong ext″ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ → Bijection.id) (λ _ → Bijection.id)) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) → ∃ λ (s : ((([ x ]) : Erased A) → P [ x ] → P [ x ])) → ((([ x ]) : Erased A) (p : P [ x ]) → s [ x ] p ≡ p)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → inverse $ ΠΣ-comm F.∘ (∀-cong ext″ λ _ → ΠΣ-comm)) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (x : Erased A) (p : P x) → ∃ λ (p′ : P x) → p′ ≡ p) ↔⟨⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (x : Erased A) (p : P x) → Singleton p) ↝⟨ (_⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → Π-closure ext′ 0 λ _ → Π-closure ext″ 0 λ _ → Π-closure ext″ 0 λ _ → singleton-contractible _) ⟩□ ⊤ □) where ext′ : Extensionality (lsuc ℓ) ℓ ext′ = lower-extensionality lzero _ ext ext″ : Extensionality ℓ ℓ ext″ = lower-extensionality _ _ ext -- The type []-cong-axiomatisation ℓ is equivalent to -- Substᴱ-axiomatisation ℓ (assuming extensionality). []-cong-axiomatisation≃Substᴱ-axiomatisation : []-cong-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Substᴱ-axiomatisation ℓ []-cong-axiomatisation≃Substᴱ-axiomatisation {ℓ = ℓ} = generalise-ext?-prop []-cong-axiomatisation⇔Substᴱ-axiomatisation ([]-cong-axiomatisation-propositional ∘ lower-extensionality lzero _) Substᴱ-axiomatisation-propositional ------------------------------------------------------------------------ -- Another alternative to []-cong-axiomatisation -- An axiomatisation of elim¹ᴱ, restricted to a fixed universe, along -- with its computation rule. Elimᴱ-axiomatisation : (ℓ : Level) → Type (lsuc ℓ) Elimᴱ-axiomatisation ℓ = ∃ λ (elimᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 x y : A} → @0 x ≡ y → Type ℓ) → ((@0 x : A) → P (refl x)) → (@0 x≡y : x ≡ y) → P x≡y) → {@0 A : Type ℓ} {@0 x : A} {P : {@0 x y : A} → @0 x ≡ y → Type ℓ} (r : (@0 x : A) → P (refl x)) → elimᴱ P r (refl x) ≡ r x private -- The type Substᴱ-axiomatisation ℓ is logically equivalent to -- Elimᴱ-axiomatisation ℓ. Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation : Substᴱ-axiomatisation ℓ ⇔ Elimᴱ-axiomatisation ℓ Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation {ℓ = ℓ} = record { to = to; from = from } where to : Substᴱ-axiomatisation ℓ → Elimᴱ-axiomatisation ℓ to ax = elimᴱ , elimᴱ-refl where open []-cong₁ (_⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation ax) from : Elimᴱ-axiomatisation ℓ → Substᴱ-axiomatisation ℓ from (elimᴱ , elimᴱ-refl) = (λ P x≡y p → elimᴱ (λ {x = x} {y = y} _ → P x → P y) (λ _ → id) x≡y p) , (λ {_ _ _ p} → cong (_$ p) $ elimᴱ-refl _) -- The type Elimᴱ-axiomatisation ℓ is propositional (assuming -- extensionality). -- -- The proof is based on a proof due to Nicolai Kraus that shows that -- "J + its computation rule" is contractible, see -- Equality.Instances-related.Equality-with-J-contractible. Elimᴱ-axiomatisation-propositional : Extensionality (lsuc ℓ) (lsuc ℓ) → Is-proposition (Elimᴱ-axiomatisation ℓ) Elimᴱ-axiomatisation-propositional {ℓ = ℓ} ext = [inhabited⇒contractible]⇒propositional λ ax → let ax′ = _⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation $ _⇔_.from Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation ax module EC = Erased-cong ax′ ax′ in _⇔_.from contractible⇔↔⊤ (Elimᴱ-axiomatisation ℓ ↔⟨ Eq.↔→≃ (λ (elimᴱ , elimᴱ-refl) _ P r → (λ ([ _ , _ , x≡y ]) → elimᴱ (λ x≡y → P [ _ , _ , x≡y ]) (λ x → r [ x ]) x≡y) , (λ _ → elimᴱ-refl _)) (λ hyp → (λ P r x≡y → hyp _ (λ ([ _ , _ , x≡y ]) → P x≡y) (λ ([ x ]) → r x) .proj₁ [ _ , _ , x≡y ]) , (λ _ → hyp _ _ _ .proj₂ _)) refl refl ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased (A ²/≡) → Type ℓ) (r : (([ x ]) : Erased A) → P [ x , x , refl x ]) → ∃ λ (e : (x : Erased (A ²/≡)) → P x) → ((([ x ]) : Erased A) → e [ x , x , refl x ] ≡ r [ x ])) ↝⟨ (∀-cong ext λ _ → Π-cong {k₁ = bijection} ext′ (→-cong₁ ext″ (EC.Erased-cong-↔ U.-²/≡↔-)) λ _ → ∀-cong ext‴ λ _ → Σ-cong (inverse $ Π-cong ext‴ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ → Bijection.id) (λ _ → Bijection.id)) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (r : (x : Erased A) → P x) → ∃ λ (e : (x : Erased A) → P x) → (x : Erased A) → e x ≡ r x) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → ∀-cong ext‴ λ _ → inverse ΠΣ-comm) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (r : (x : Erased A) → P x) (x : Erased A) → ∃ λ (p : P x) → p ≡ r x) ↝⟨ (_⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → Π-closure ext′ 0 λ _ → Π-closure ext‴ 0 λ _ → Π-closure ext‴ 0 λ _ → singleton-contractible _) ⟩□ ⊤ □) where ext′ : Extensionality (lsuc ℓ) ℓ ext′ = lower-extensionality lzero _ ext ext″ : Extensionality ℓ (lsuc ℓ) ext″ = lower-extensionality _ lzero ext ext‴ : Extensionality ℓ ℓ ext‴ = lower-extensionality _ _ ext -- The type Substᴱ-axiomatisation ℓ is equivalent to -- Elimᴱ-axiomatisation ℓ (assuming extensionality). Substᴱ-axiomatisation≃Elimᴱ-axiomatisation : Substᴱ-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Elimᴱ-axiomatisation ℓ Substᴱ-axiomatisation≃Elimᴱ-axiomatisation = generalise-ext?-prop Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation Substᴱ-axiomatisation-propositional Elimᴱ-axiomatisation-propositional -- The type []-cong-axiomatisation ℓ is equivalent to -- Elimᴱ-axiomatisation ℓ (assuming extensionality). []-cong-axiomatisation≃Elimᴱ-axiomatisation : []-cong-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Elimᴱ-axiomatisation ℓ []-cong-axiomatisation≃Elimᴱ-axiomatisation {ℓ = ℓ} ext = []-cong-axiomatisation ℓ ↝⟨ []-cong-axiomatisation≃Substᴱ-axiomatisation ext ⟩ Substᴱ-axiomatisation ℓ ↝⟨ Substᴱ-axiomatisation≃Elimᴱ-axiomatisation ext ⟩□ Elimᴱ-axiomatisation ℓ □
39.870115
147
0.444066
0e6a9aa1ef2e36f2dfd66ad80034cbf7ef4f7dff
11,669
agda
Agda
old/Algebra/FreeGroupAsReducedWords.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Algebra/FreeGroupAsReducedWords.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Algebra/FreeGroupAsReducedWords.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K #-} open import Base module Algebra.FreeGroupAsReducedWords {i} (A : Set i) (eq : has-dec-eq A) where A-is-set : is-set A A-is-set = dec-eq-is-set eq data word : Set i where ε : word _∷_ : A → word → word _′∷_ : A → word → word is-reduced : word → Set i is-reduced ε = unit is-reduced (x ∷ ε) = unit is-reduced (x ∷ (y ∷ w)) = is-reduced (y ∷ w) is-reduced (x ∷ (y ′∷ w)) = (x ≢ y) × is-reduced (y ′∷ w) is-reduced (x ′∷ ε) = unit is-reduced (x ′∷ (y ∷ w)) = (x ≢ y) × is-reduced (y ∷ w) is-reduced (x ′∷ (y ′∷ w)) = is-reduced (y ′∷ w) is-reduced-is-prop : (w : word) → is-prop (is-reduced w) is-reduced-is-prop ε = unit-is-prop is-reduced-is-prop (x ∷ ε) = unit-is-prop is-reduced-is-prop (x ∷ (y ∷ w)) = is-reduced-is-prop (y ∷ w) is-reduced-is-prop (x ∷ (y ′∷ w)) = ×-is-truncated _ (Π-is-truncated _ (λ _ → λ ())) (is-reduced-is-prop (y ′∷ w)) is-reduced-is-prop (x ′∷ ε) = unit-is-prop is-reduced-is-prop (x ′∷ (y ∷ w)) = ×-is-truncated _ (Π-is-truncated _ (λ _ → λ ())) (is-reduced-is-prop (y ∷ w)) is-reduced-is-prop (x ′∷ (y ′∷ w)) = is-reduced-is-prop (y ′∷ w) reduced-word : Set i reduced-word = Σ word is-reduced word-total-path : {x y : A} (p : x ≡ y) {v w : word} (q : v ≡ w) → (x ∷ v ≡ y ∷ w) word-total-path refl refl = refl word'-total-path : {x y : A} (p : x ≡ y) {v w : word} (q : v ≡ w) → (x ′∷ v ≡ y ′∷ w) word'-total-path refl refl = refl -- The following six functions prove things like if [x ∷ v ≡ y ∷ w], -- then [x ≡ y]. -- This is not as easy as it sounds, you cannot directly induct on the equality -- (because [x ∷ v] is not a general element of type word), so you have to -- extract the head, but it’s not always possible… word-comp-path-type : (v w : word) → Set i word-comp-path-type ε ε = unit word-comp-path-type ε (y ∷ w) = ⊥ word-comp-path-type ε (y ′∷ w) = ⊥ word-comp-path-type (x ∷ v) ε = ⊥ word-comp-path-type (x ∷ v) (y ∷ w) = (x ≡ y) × (v ≡ w) word-comp-path-type (x ∷ v) (y ′∷ w) = ⊥ word-comp-path-type (x ′∷ v) ε = ⊥ word-comp-path-type (x ′∷ v) (y ∷ w) = ⊥ word-comp-path-type (x ′∷ v) (y ′∷ w) = (x ≡ y) × (v ≡ w) word-comp-path : {v w : word} (p : v ≡ w) → word-comp-path-type v w word-comp-path {v = ε} refl = tt word-comp-path {v = x ∷ v} refl = (refl , refl) word-comp-path {v = x ′∷ v} refl = (refl , refl) word-base-path : {x y : A} {v w : word} (p : x ∷ v ≡ y ∷ w) → x ≡ y word-base-path p = π₁ (word-comp-path p) word-fiber-path : {x y : A} {v w : word} (p : x ∷ v ≡ y ∷ w) → v ≡ w word-fiber-path p = π₂ (word-comp-path p) word'-base-path : {x y : A} {v w : word} (p : x ′∷ v ≡ y ′∷ w) → x ≡ y word'-base-path p = π₁ (word-comp-path p) word'-fiber-path : {x y : A} {v w : word} (p : x ′∷ v ≡ y ′∷ w) → v ≡ w word'-fiber-path p = π₂ (word-comp-path p) -- This one goes to Set and is used to prove that the constructors of [word] are -- disjoint word-cst-dis : (v w : word) → Set word-cst-dis ε ε = unit word-cst-dis ε (y ∷ w) = ⊥ word-cst-dis ε (y ′∷ w) = ⊥ word-cst-dis (x ∷ v) ε = ⊥ word-cst-dis (x ∷ v) (y ∷ w) = unit word-cst-dis (x ∷ v) (y ′∷ w) = ⊥ word-cst-dis (x ′∷ v) ε = ⊥ word-cst-dis (x ′∷ v) (y ∷ w) = ⊥ word-cst-dis (x ′∷ v) (y ′∷ w) = unit word-has-dec-eq : has-dec-eq word word-has-dec-eq ε ε = inl refl word-has-dec-eq ε (x ∷ w) = inr (λ p → transport (word-cst-dis ε) p tt) word-has-dec-eq ε (x ′∷ w) = inr (λ p → transport (word-cst-dis ε) p tt) word-has-dec-eq (x ∷ v) ε = inr (λ p → transport (word-cst-dis (x ∷ v)) p tt) word-has-dec-eq (x ∷ v) (y ∷ w) with (eq x y) word-has-dec-eq (x ∷ v) (y ∷ w) | inl x≡y with (word-has-dec-eq v w) word-has-dec-eq (x ∷ v) (y ∷ w) | inl x≡y | inl v≡w = inl (word-total-path x≡y v≡w) word-has-dec-eq (x ∷ v) (y ∷ w) | inl x≡y | inr v≢w = inr (λ p → v≢w (word-fiber-path p)) word-has-dec-eq (x ∷ v) (y ∷ w) | inr x≢y = inr (λ p → x≢y (word-base-path p)) word-has-dec-eq (x ∷ v) (y ′∷ w) = inr (λ p → transport (word-cst-dis (x ∷ v)) p tt) word-has-dec-eq (x ′∷ v) ε = inr (λ p → transport (word-cst-dis (x ′∷ v)) p tt) word-has-dec-eq (x ′∷ v) (y ∷ w) = inr (λ p → transport (word-cst-dis (x ′∷ v)) p tt) word-has-dec-eq (x ′∷ v) (y ′∷ w) with (eq x y) word-has-dec-eq (x ′∷ v) (y ′∷ w) | inl x≡y with (word-has-dec-eq v w) word-has-dec-eq (x ′∷ v) (y ′∷ w) | inl x≡y | inl v≡w = inl (word'-total-path x≡y v≡w) word-has-dec-eq (x ′∷ v) (y ′∷ w) | inl x≡y | inr v≢w = inr (λ p → v≢w (word'-fiber-path p)) word-has-dec-eq (x ′∷ v) (y ′∷ w) | inr x≢y = inr (λ p → x≢y (word'-base-path p)) word-is-set : is-set word word-is-set = dec-eq-is-set word-has-dec-eq abstract reduced-is-set : is-set reduced-word reduced-is-set = subtype-truncated-S-is-truncated-S _ word-is-set is-reduced-is-prop tail-is-reduced : (x : A) (w : word) (r : is-reduced (x ∷ w)) → is-reduced w tail-is-reduced x ε red = tt tail-is-reduced x (y ∷ w) red = red tail-is-reduced x (y ′∷ w) red = π₂ red tail'-is-reduced : (x : A) (w : word) (r : is-reduced (x ′∷ w)) → is-reduced w tail'-is-reduced x ε red = tt tail'-is-reduced x (y ∷ w) red = π₂ red tail'-is-reduced x (y ′∷ w) red = red import Algebra.FreeGroup as F open F A import Algebra.FreeGroupProps as Fp open Fp A reduced-to-freegroup : reduced-word → freegroup reduced-to-freegroup (ε , _) = e reduced-to-freegroup ((x ∷ w) , r) = x · reduced-to-freegroup (w , tail-is-reduced x w r) reduced-to-freegroup ((x ′∷ w) , r) = x ⁻¹· reduced-to-freegroup (w , tail'-is-reduced x w r) mul-reduce : A → reduced-word → reduced-word mul-reduce x (ε , red) = ((x ∷ ε) , tt) mul-reduce x ((y ∷ w) , red) = ((x ∷ (y ∷ w)) , red) mul-reduce x ((y ′∷ w) , red) with (eq x y) mul-reduce x ((y ′∷ w) , red) | inl equal = (w , tail'-is-reduced y w red) mul-reduce x ((y ′∷ w) , red) | inr different = ((x ∷ (y ′∷ w)) , (different , red)) mul'-reduce : A → reduced-word → reduced-word mul'-reduce x (ε , red) = ((x ′∷ ε) , tt) mul'-reduce x ((y ∷ w) , red) with (eq x y) mul'-reduce x ((y ∷ w) , red) | inl equal = (w , tail-is-reduced y w red) mul'-reduce x ((y ∷ w) , red) | inr different = ((x ′∷ (y ∷ w)) , (different , red)) mul'-reduce x ((y ′∷ w) , red) = (x ′∷ (y ′∷ w)) , red abstract mul-mul'-reduce : (x : A) (w : reduced-word) → mul-reduce x (mul'-reduce x w) ≡ w mul-mul'-reduce x (ε , red) with (eq x x) mul-mul'-reduce x (ε , red) | inl obvious = refl mul-mul'-reduce x (ε , red) | inr absurd = abort-nondep (absurd refl) mul-mul'-reduce x ((y ∷ w) , red) with (eq x y) mul-mul'-reduce x ((y ∷ ε) , red) | inl equal = ap _ equal mul-mul'-reduce x ((y ∷ (z ∷ w)) , red) | inl equal = ap _ equal mul-mul'-reduce x ((y ∷ (z ′∷ w)) , red) | inl equal with (eq x z) mul-mul'-reduce x ((y ∷ (z ′∷ w)) , red) | inl equal | inl absurd = abort-nondep (π₁ red (! equal ∘ absurd)) mul-mul'-reduce x ((y ∷ (z ′∷ w)) , red) | inl equal | inr obvious = Σ-eq (ap _ equal) (π₁ (is-reduced-is-prop (y ∷ (z ′∷ w)) _ _)) mul-mul'-reduce x ((y ∷ w) , red) | inr different with (eq x x) mul-mul'-reduce x ((y ∷ w) , red) | inr different | inl obvious = refl mul-mul'-reduce x ((y ∷ w) , red) | inr different | inr absurd = abort-nondep (absurd refl) mul-mul'-reduce x ((y ′∷ w) , red) with (eq x x) mul-mul'-reduce x ((y ′∷ w) , red) | inl obvious = refl mul-mul'-reduce x ((y ′∷ w) , red) | inr absurd = abort-nondep (absurd refl) abstract mul'-mul-reduce : (x : A) (w : reduced-word) → mul'-reduce x (mul-reduce x w) ≡ w mul'-mul-reduce x (ε , red) with (eq x x) mul'-mul-reduce x (ε , red) | inl obvious = refl mul'-mul-reduce x (ε , red) | inr absurd = abort-nondep (absurd refl) mul'-mul-reduce x ((y ′∷ w) , red) with (eq x y) mul'-mul-reduce x ((y ′∷ ε) , red) | inl equal = ap _ equal mul'-mul-reduce x ((y ′∷ (z ′∷ w)) , red) | inl equal = ap _ equal mul'-mul-reduce x ((y ′∷ (z ∷ w)) , red) | inl equal with (eq x z) mul'-mul-reduce x ((y ′∷ (z ∷ w)) , red) | inl equal | inl absurd = abort-nondep (π₁ red (! equal ∘ absurd)) mul'-mul-reduce x ((y ′∷ (z ∷ w)) , red) | inl equal | inr obvious = Σ-eq (ap _ equal) (π₁ (is-reduced-is-prop (y ′∷ (z ∷ w)) _ _)) mul'-mul-reduce x ((y ′∷ w) , red) | inr different with (eq x x) mul'-mul-reduce x ((y ′∷ w) , red) | inr different | inl obvious = refl mul'-mul-reduce x ((y ′∷ w) , red) | inr different | inr absurd = abort-nondep (absurd refl) mul'-mul-reduce x ((y ∷ w) , red) with (eq x x) mul'-mul-reduce x ((y ∷ w) , red) | inl obvious = refl mul'-mul-reduce x ((y ∷ w) , red) | inr absurd = abort-nondep (absurd refl) freegroup-to-reduced : freegroup → reduced-word freegroup-to-reduced = freegroup-rec-nondep reduced-word (ε , tt) mul-reduce mul'-reduce mul-mul'-reduce mul'-mul-reduce reduced-is-set abstract mul-reduce-reduced : (x : A) (w : word) (red : is-reduced (x ∷ w)) → mul-reduce x (w , tail-is-reduced x w red) ≡ ((x ∷ w) , red) mul-reduce-reduced x ε red = refl mul-reduce-reduced x (y ∷ w) red = refl mul-reduce-reduced x (y ′∷ w) red with (eq x y) mul-reduce-reduced x (y ′∷ w) red | inl absurd = abort-nondep (π₁ red absurd) mul-reduce-reduced x (y ′∷ w) red | inr obvious = Σ-eq refl (π₁ (is-reduced-is-prop (x ∷ (y ′∷ w)) _ _)) abstract mul'-reduce-reduced : (x : A) (w : word) (red : is-reduced (x ′∷ w)) → mul'-reduce x (w , tail'-is-reduced x w red) ≡ ((x ′∷ w) , red) mul'-reduce-reduced x ε red = refl mul'-reduce-reduced x (y ∷ w) red with (eq x y) mul'-reduce-reduced x (y ∷ w) red | inl absurd = abort-nondep (π₁ red absurd) mul'-reduce-reduced x (y ∷ w) red | inr obvious = Σ-eq refl (π₁ (is-reduced-is-prop (x ′∷ (y ∷ w)) _ _)) mul'-reduce-reduced x (y ′∷ w) red = refl inv₁ : (w : reduced-word) → freegroup-to-reduced (reduced-to-freegroup w) ≡ w inv₁ (ε , red) = refl inv₁ ((x ∷ w) , red) = ap (mul-reduce x) (inv₁ (w , tail-is-reduced x w red)) ∘ mul-reduce-reduced x w red inv₁ ((x ′∷ w) , red) = ap (mul'-reduce x) (inv₁ (w , tail'-is-reduced x w red)) ∘ mul'-reduce-reduced x w red reduced-to-freegroup-mul-reduce : (x : A) (v : reduced-word) → reduced-to-freegroup (mul-reduce x v) ≡ x · (reduced-to-freegroup v) reduced-to-freegroup-mul-reduce x (ε , red) = refl reduced-to-freegroup-mul-reduce x ((y ∷ v) , red) = refl reduced-to-freegroup-mul-reduce x ((y ′∷ v) , red) with (eq x y) reduced-to-freegroup-mul-reduce x ((.x ′∷ v) , red) | inl refl = ! (right-inverse-· x (reduced-to-freegroup (v , tail'-is-reduced x v red))) reduced-to-freegroup-mul-reduce x ((y ′∷ v) , red) | inr different = refl reduced-to-freegroup-mul'-reduce : (x : A) (v : reduced-word) → reduced-to-freegroup (mul'-reduce x v) ≡ x ⁻¹· (reduced-to-freegroup v) reduced-to-freegroup-mul'-reduce x (ε , red) = refl reduced-to-freegroup-mul'-reduce x ((y ∷ v) , red) with (eq x y) reduced-to-freegroup-mul'-reduce x ((.x ∷ v) , red) | inl refl = ! (left-inverse-· x (reduced-to-freegroup (v , tail-is-reduced x v red))) reduced-to-freegroup-mul'-reduce x ((y ∷ v) , red) | inr different = refl reduced-to-freegroup-mul'-reduce x ((y ′∷ v) , red) = refl inv₂ : (a : freegroup) → reduced-to-freegroup (freegroup-to-reduced a) ≡ a inv₂ = freegroup-rec _ refl (λ x u p → reduced-to-freegroup-mul-reduce x (freegroup-to-reduced u) ∘ ap (λ t → x · t) {y = u} p) (λ x u p → reduced-to-freegroup-mul'-reduce x (freegroup-to-reduced u) ∘ ap (λ t → x ⁻¹· t) {y = u} p) (λ x u t → π₁ (freegroup-is-set _ _ _ _)) (λ x u t → π₁ (freegroup-is-set _ _ _ _)) (λ u → truncated-is-truncated-S _ (freegroup-is-set _ _)) freegroup-equiv-reduced : freegroup ≃ reduced-word freegroup-equiv-reduced = (freegroup-to-reduced , iso-is-eq _ reduced-to-freegroup inv₁ inv₂)
41.675
80
0.576913
1266f37bd941eeab36ad9258c30015c6a73f5f15
269
agda
Agda
test/Fail/Issue160.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue160.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue160.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue160 where data Bool : Set where true : Bool false : Bool data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x inj : ∀ {A} (f : A -> A) {a b : A} → f a ≡ f b -> a ≡ b inj f refl = refl absurd : true ≡ false absurd = inj (λ _ → true) refl
15.823529
41
0.524164
5040c23d925ea052e48fd539459f44074c40d2a7
3,135
agda
Agda
Cubical/HITs/Join/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/HITs/Join/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/HITs/Join/Base.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.Join.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.HITs.S1 open import Cubical.HITs.S3 -- redtt version : https://github.com/RedPRL/redtt/blob/master/library/cool/s3-to-join.red data join {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') : Type (ℓ-max ℓ ℓ') where inl : A → join A B inr : B → join A B push : ∀ a b → inl a ≡ inr b facek01 : I → I → I → join S¹ S¹ facek01 i j k = hfill (λ l → λ { (j = i0) → push base base (~ l ∧ ~ k) ; (j = i1) → push base base (~ l ∧ ~ k) ; (k = i0) → push (loop j) base (~ l) ; (k = i1) → inl base }) (inS (push base base (~ k))) i border-contraction : I → I → I → I → join S¹ S¹ border-contraction i j k m = hfill (λ l → λ { (i = i0) → facek01 i1 j l ; (i = i1) → push base (loop k) (~ l) ; (j = i0) → push base (loop k) (i ∧ ~ l) ; (j = i1) → push base (loop k) (i ∧ ~ l) ; (k = i0) → facek01 (~ i) j l ; (k = i1) → facek01 (~ i) j l }) (inS (push (loop j) (loop k) i)) m S³→joinS¹S¹ : S³ → join S¹ S¹ S³→joinS¹S¹ base = inl base S³→joinS¹S¹ (surf j k i) = border-contraction i j k i1 joinS¹S¹→S³ : join S¹ S¹ → S³ joinS¹S¹→S³ (inl x) = base joinS¹S¹→S³ (inr x) = base joinS¹S¹→S³ (push base b i) = base joinS¹S¹→S³ (push (loop x) base i) = base joinS¹S¹→S³ (push (loop i) (loop j) k) = surf i j k connection : I → I → I → I → S³ connection i j k l = hfill (λ m → λ { (k = i0) → joinS¹S¹→S³ (facek01 m i j) ; (k = i1) → base ; (j = i0) → base ; (j = i1) → base ; (i = i0) → base ; (i = i1) → base }) (inS base) l S³→joinS¹S¹→S³ : ∀ x → joinS¹S¹→S³ (S³→joinS¹S¹ x) ≡ x S³→joinS¹S¹→S³ base l = base S³→joinS¹S¹→S³ (surf j k i) l = hcomp (λ m → λ { (l = i0) → joinS¹S¹→S³ (border-contraction i j k m) ; (l = i1) → surf j k i ; (i = i0) → connection j m l i1 ; (i = i1) → base ; (j = i0) → base ; (j = i1) → base ; (k = i0) → connection j m l (~ i) ; (k = i1) → connection j m l (~ i) }) (surf j k i) joinS¹S¹→S³→joinS¹S¹ : ∀ x → S³→joinS¹S¹ (joinS¹S¹→S³ x) ≡ x joinS¹S¹→S³→joinS¹S¹ (inl base) l = inl base joinS¹S¹→S³→joinS¹S¹ (inl (loop i)) l = facek01 i1 i (~ l) joinS¹S¹→S³→joinS¹S¹ (inr base) l = push base base l joinS¹S¹→S³→joinS¹S¹ (inr (loop i)) l = push base (loop i) l joinS¹S¹→S³→joinS¹S¹ (push base base i) l = push base base (i ∧ l) joinS¹S¹→S³→joinS¹S¹ (push base (loop k) i) l = push base (loop k) (i ∧ l) joinS¹S¹→S³→joinS¹S¹ (push (loop k) base i) l = facek01 (~ i) k (~ l) joinS¹S¹→S³→joinS¹S¹ (push (loop j) (loop k) i) l = border-contraction i j k (~ l) S³≡joinS¹S¹ : S³ ≡ join S¹ S¹ S³≡joinS¹S¹ = isoToPath (iso S³→joinS¹S¹ joinS¹S¹→S³ joinS¹S¹→S³→joinS¹S¹ S³→joinS¹S¹→S³)
38.703704
90
0.520893
4daa3027f8bae65377ab57aba428181b600f5116
2,694
agda
Agda
src/Prelude/Word.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Prelude/Word.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Prelude/Word.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Prelude.Word where import Agda.Builtin.Word as Word open import Prelude.Nat open import Prelude.Number open import Prelude.Semiring open import Prelude.Equality open import Prelude.Equality.Unsafe open import Prelude.Ord open import Prelude.Unit open import Prelude.Function open import Prelude.Decidable open Word public using (Word64) renaming (primWord64ToNat to word64ToNat; primWord64FromNat to word64FromNat) open Word private 2⁶⁴ : Nat 2⁶⁴ = 18446744073709551616 {-# INLINE 2⁶⁴ #-} inv-word64ToNat : ∀ {a} → word64FromNat (word64ToNat a) ≡ a inv-word64ToNat = unsafeEqual emb-word64FromNat : ∀ n → word64ToNat (word64FromNat n) ≡ n mod 2⁶⁴ emb-word64FromNat n = unsafeEqual inj-word64ToNat : ∀ {a b} → word64ToNat a ≡ word64ToNat b → a ≡ b inj-word64ToNat {a} {b} eq = eraseEquality ( a ≡⟨ inv-word64ToNat ⟩ʳ word64FromNat (word64ToNat a) ≡⟨ word64FromNat $≡ eq ⟩ word64FromNat (word64ToNat b) ≡⟨ inv-word64ToNat ⟩ b ∎) instance NumWord64 : Number Word64 Number.Constraint NumWord64 _ = ⊤ fromNat {{NumWord64}} n = word64FromNat n EqWord64 : Eq Word64 _==_ {{EqWord64}} a b = case word64ToNat a == word64ToNat b of λ where (yes _) → yes unsafeEqual (no _) → no unsafeNotEqual OrdWord64 : Ord Word64 OrdWord64 = OrdBy inj-word64ToNat OrdLawsWord64 : Ord/Laws Word64 OrdLawsWord64 = OrdLawsBy inj-word64ToNat -- Arithmetic -- private natOp : (Nat → Nat → Nat) → Word64 → Word64 → Word64 natOp f a b = fromNat (f (word64ToNat a) (word64ToNat b)) {-# INLINE natOp #-} add64 : Word64 → Word64 → Word64 add64 = natOp _+_ sub64 : Word64 → Word64 → Word64 sub64 = natOp λ a b → a + 2⁶⁴ - b mul64 : Word64 → Word64 → Word64 mul64 = natOp _*_ {-# INLINE add64 #-} {-# INLINE sub64 #-} {-# INLINE mul64 #-} NonZero64 : Word64 → Set NonZero64 a = NonZero (word64ToNat a) infixl 7 divWord64 modWord64 syntax divWord64 b a = a div64 b divWord64 : (b : Word64) {{nz : NonZero64 b}} → Word64 → Word64 divWord64 b a = fromNat (word64ToNat a div word64ToNat b) syntax modWord64 b a = a mod64 b modWord64 : (b : Word64) {{nz : NonZero64 b}} → Word64 → Word64 modWord64 b a = fromNat (word64ToNat a mod word64ToNat b) {-# INLINE divWord64 #-} {-# INLINE modWord64 #-} instance SemiringWord64 : Semiring Word64 Semiring.zro SemiringWord64 = 0 Semiring.one SemiringWord64 = 1 Semiring._+_ SemiringWord64 = add64 Semiring._*_ SemiringWord64 = mul64 NegWord64 : Negative Word64 Negative.Constraint NegWord64 _ = ⊤ fromNeg {{NegWord64}} n = sub64 0 (fromNat n) SubWord64 : Subtractive Word64 _-_ {{SubWord64}} = sub64 negate {{SubWord64}} = sub64 0
25.415094
77
0.695249
12a6238220386af3b23191863a9b1cfa45afea31
2,068
agda
Agda
src/Prelude/Monoid.agda
jespercockx/agda-prelude
1984cf0341835b2f7bfe678098bd57cfe16ea11f
[ "MIT" ]
null
null
null
src/Prelude/Monoid.agda
jespercockx/agda-prelude
1984cf0341835b2f7bfe678098bd57cfe16ea11f
[ "MIT" ]
null
null
null
src/Prelude/Monoid.agda
jespercockx/agda-prelude
1984cf0341835b2f7bfe678098bd57cfe16ea11f
[ "MIT" ]
null
null
null
module Prelude.Monoid where open import Prelude.Function open import Prelude.Maybe open import Prelude.List open import Prelude.Semiring open import Prelude.Applicative open import Prelude.Functor record Monoid {a} (A : Set a) : Set a where infixr 6 _<>_ field mempty : A _<>_ : A → A → A open Monoid {{...}} public {-# DISPLAY Monoid.mempty _ = mempty #-} {-# DISPLAY Monoid._<>_ _ a b = a <> b #-} mconcat : ∀ {a} {A : Set a} {{MonA : Monoid A}} → List A → A mconcat = foldr _<>_ mempty --- Instances --- instance MonoidList : ∀ {a} {A : Set a} → Monoid (List A) mempty {{MonoidList}} = [] _<>_ {{MonoidList}} = _++_ MonoidFun : ∀ {a b} {A : Set a} {B : A → Set b} {{_ : ∀ {x} → Monoid (B x)}} → Monoid (∀ x → B x) mempty {{MonoidFun}} _ = mempty _<>_ {{MonoidFun}} f g x = f x <> g x MonoidMaybe : ∀ {a} {A : Set a} → Monoid (Maybe A) mempty {{MonoidMaybe}} = nothing _<>_ {{MonoidMaybe}} nothing y = y _<>_ {{MonoidMaybe}} (just x) _ = just x record Sum {a} (A : Set a) : Set a where constructor mkSum field getSum : A open Sum public instance MonoidSum : ∀ {a} {A : Set a} {{_ : Semiring A}} → Monoid (Sum A) getSum (mempty {{MonoidSum}}) = zro getSum (_<>_ {{MonoidSum}} x y) = getSum x + getSum y record Product {a} (A : Set a) : Set a where constructor mkProduct field getProduct : A open Product public instance MonoidProduct : ∀ {a} {A : Set a} {{_ : Semiring A}} → Monoid (Product A) getProduct (mempty {{MonoidProduct}}) = one getProduct (_<>_ {{MonoidProduct}} x y) = getProduct x * getProduct y record Const {a b} (A : Set a) (B : Set b) : Set a where constructor mkConst field getConst : A open Const public module _ {a b} {A : Set a} {{MonA : Monoid A}} where instance FunctorConst : Functor {a = b} (Const A) getConst (fmap {{FunctorConst}} f x) = getConst x ApplicativeConst : Applicative (Const A) getConst (pure {{ApplicativeConst}} x) = mempty getConst (_<*>_ {{ApplicativeConst}} wf wx) = getConst wf <> getConst wx
26.857143
99
0.610735
1cbfd89472a49c8e0de042bf09ea0dca1341a81a
475
agda
Agda
test/interaction/Issue3491.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3491.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3491.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Equality record Box (B : Set) : Set₁ where constructor box field unbox : B -- here: .unbox is a valid forced pattern =box : {B : Set} {Γ₀ Γ₁ : Box B} → Box.unbox Γ₀ ≡ Box.unbox Γ₁ → Γ₀ ≡ Γ₁ =box {Γ₀ = box unbox} {box r} p = ? open Box public -- here: .unbox is now the name of a projection and should therefore -- not be generated =box' : {B : Set} {Γ₀ Γ₁ : Box B} → unbox Γ₀ ≡ unbox Γ₁ → Γ₀ ≡ Γ₁ =box' {Γ₀ = box unbox} {box r} p = ?
23.75
72
0.616842
cbb5314a159b110bcd9e32d4f9f13260c2c57ea9
420
agda
Agda
test/Common/List.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
7
2018-11-05T22:13:36.000Z
2018-11-06T16:38:43.000Z
test/Common/List.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
16
2018-10-08T00:32:04.000Z
2019-09-08T13:47:04.000Z
test/Common/List.agda
xekoukou/agda-ocaml
026a8f8473ab91f99c3f6545728e71fa847d2720
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
module Common.List where open import Agda.Builtin.List public open import Common.Nat infixr 5 _++_ _++_ : ∀ {a} {A : Set a} → List A → List A → List A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → List A → List B map _ [] = [] map f (x ∷ xs) = f x ∷ map f xs length : ∀ {a} {A : Set a} → List A → Nat length [] = 0 length (x ∷ xs) = 1 + length xs
22.105263
65
0.495238
50e6cfcbbd00e73547194f0263511d43bff5a1d4
548
agda
Agda
Soundness/agda/SMain.agda
halfaya/Music
5d9a1bbfbe52f55acf33d960763dce0872689c2b
[ "MIT" ]
1
2020-11-10T04:05:28.000Z
2020-11-10T04:05:28.000Z
Soundness/agda/SMain.agda
halfaya/Music
5d9a1bbfbe52f55acf33d960763dce0872689c2b
[ "MIT" ]
null
null
null
Soundness/agda/SMain.agda
halfaya/Music
5d9a1bbfbe52f55acf33d960763dce0872689c2b
[ "MIT" ]
1
2020-11-10T04:05:31.000Z
2020-11-10T04:05:31.000Z
{-# OPTIONS --erased-cubical #-} module SMain where open import Data.List using (map) open import Data.Nat using (_*_) open import Data.Unit using (⊤) open import Midi using (IO; exportTracks; track→htrack) open import Soundness using (soundTracks) open import Motif using (multiplier) main : IO ⊤ main = let ticksPerBeat = 4 * multiplier -- (1 = quarter notes; 4 = 16th notes) file = "/Users/leo/Music/MusicTools/test.mid" song = soundTracks in exportTracks file ticksPerBeat (map track→htrack song)
27.4
74
0.682482
126ced3f83c7326b9815078d2eeedc3fe434c66e
5,360
agda
Agda
Examples/XML.agda
nad/pretty
b956803ba90b6c5f57bbbaab01bb18485d948492
[ "MIT" ]
null
null
null
Examples/XML.agda
nad/pretty
b956803ba90b6c5f57bbbaab01bb18485d948492
[ "MIT" ]
null
null
null
Examples/XML.agda
nad/pretty
b956803ba90b6c5f57bbbaab01bb18485d948492
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Simplified XML documents ------------------------------------------------------------------------ -- This example is based on (but not identical to) one in Wadler's "A -- prettier printer". {-# OPTIONS --guardedness #-} module Examples.XML where open import Codata.Musical.Notation open import Data.Bool open import Data.Char open import Data.List as List using (List; []; _∷_) open import Data.List.NonEmpty as List⁺ using (_∷_) open import Data.Product import Data.String as String open import Data.Unit open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Examples.Identifier open import Grammar.Infinite as Grammar using (Grammar) hiding (module Grammar) open import Pretty using (Pretty-printer) open import Renderer open import Utilities -- Text. is-text-char : Char → Bool is-text-char t = ('A' ≤?C t) ∧ (t ≤?C 'Z') ∨ ('a' ≤?C t) ∧ (t ≤?C 'z') ∨ ('0' ≤?C t) ∧ (t ≤?C '9') ∨ List.any (_==_ t) (String.toList ":./ \n") Text : Set Text = List (∃ λ (t : Char) → T (is-text-char t)) text-g : Grammar Text text-g = sat _ ⋆ where open Grammar text-printer : Pretty-printer text-g text-printer = map⋆ (sat is-text-char) where open Pretty mutual data XML : Set where elt : Identifier → List Att → List XML → XML txt : Text → XML data Att : Set where att : Identifier → Text → Att module _ where open Grammar mutual -- The following grammar is ambiguous: a sequence of txt elements can -- be parsed in several different ways. xml : Grammar XML xml = (start-of-element >>= λ { (t , atts) → elt t atts <$> ( [] <$ string′ "/" ∣ string′ ">" ⊛> xmls <⊛ symbol′ "</" <⊛ symbol (List.map proj₁ (List⁺.toList t)))}) <⊛ symbol′ ">" ∣ txt <$> text-g <⊛ whitespace ⋆ start-of-element : Grammar (Identifier × List Att) start-of-element = _,_ <$ symbol′ "<" ⊛ identifier ⊛ attrs xmls : Grammar (List XML) xmls = whitespace ⋆ ⊛> ♯ xml ⋆ attrs : Grammar (List Att) attrs = [] <$ whitespace ⋆ ∣ List⁺.toList <$> (whitespace + ⊛> attr +) attr : Grammar Att attr = att <$> identifier <⊛ whitespace ⋆ <⊛ symbol′ "=" <⊛ string′ "\"" ⊛ text-g <⊛ symbol′ "\"" open Pretty mutual xml-printer : Pretty-printer xml xml-printer (elt t atts []) = left ((start-of-element-printer (t , atts) ◇ <$> left (<$ text)) <⊛ symbol) xml-printer (elt t atts xs) = left ((start-of-element-printer (t , atts) ◇ <$> right (text ⊛> xmls-printer xs <⊛ symbol <⊛ symbol)) <⊛ symbol) xml-printer (txt t) = -- Wadler pretty-prints text items in a different way. (The -- grammar that I use does not allow me to modify the amount of -- whitespace in the same way as Wadler.) right (<$> text-printer t <⊛ nil-⋆) start-of-element-printer : Pretty-printer start-of-element start-of-element-printer (t , atts) = <$ symbol ⊛ identifier-printer t ⊛ attrs-printer atts attrs-printer : Pretty-printer attrs attrs-printer [] = left (<$ nil-⋆) attrs-printer (a ∷ as) = right (<$> group (nest 2 line tt-⊛> final-line 4 (nest 2 (map+-fill 2 attr-printer (a ∷ as))) 0)) attr-printer : Pretty-printer attr attr-printer (att n v) = <$> identifier-printer n <⊛ nil-⋆ <⊛ symbol <⊛ text ⊛ text-printer v <⊛ symbol -- The following definition uses "fill+ 3 (to-docs x xs)" (along -- with the auxiliary definition of to-docs) rather than -- "map+-fill 3 xml-printer (x ∷ xs)" because the latter piece of -- code makes the termination checker complain. xmls-printer : Pretty-printer xmls xmls-printer [] = nil-⋆ ⊛> nil-⋆ xmls-printer (x ∷ xs) = group (nest 2 line⋆ tt-⊛> final-line-+⋆ 5 (nest 2 (fill+ 3 (to-docs x xs))) 0) where to-docs : ∀ x xs → Docs xml (x ∷ xs) to-docs x [] = [ xml-printer x ] to-docs x (x′ ∷ xs) = xml-printer x ∷ to-docs x′ xs example : XML example = elt (str⁺ "p") (att (str⁺ "color") (str "red") ∷ att (str⁺ "font") (str "Times") ∷ att (str⁺ "size") (str "10") ∷ []) (txt (str "Here is some") ∷ elt (str⁺ "em") [] (txt (str "emphasized") ∷ []) ∷ txt (str "text.") ∷ txt (str "Here is a") ∷ elt (str⁺ "a") (att (str⁺ "href") (str "http://www.eg.com/") ∷ []) (txt (str "link") ∷ []) ∷ txt (str "elsewhere.") ∷ []) test₁ : render 30 (xml-printer example) ≡ "<p\n color=\"red\" font=\"Times\"\n size=\"10\"\n>\n Here is some\n <em> emphasized </em> text.\n Here is a\n <a\n href=\"http://www.eg.com/\"\n > link </a>\n elsewhere.\n</p>" test₁ = refl test₂ : render 60 (xml-printer example) ≡ "<p color=\"red\" font=\"Times\" size=\"10\" >\n Here is some <em> emphasized </em> text. Here is a\n <a href=\"http://www.eg.com/\" > link </a> elsewhere.\n</p>" test₂ = refl
30.11236
196
0.527612
1cd1777e559a12577c81dd70feb29103e399b0b3
7,432
agda
Agda
Numeral/CoordinateVector.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/CoordinateVector.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/CoordinateVector.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.CoordinateVector where import Lvl open import Data.Boolean open import Functional open import Lang.Instance open import Numeral.Finite open import Numeral.Finite.Bound open import Numeral.Finite.Oper open import Numeral.Finite.Oper.Comparisons open import Numeral.Natural import Numeral.Natural.Oper as ℕ open import Numeral.Natural.Function open import Numeral.Natural.Function.Proofs open import Type private variable ℓ : Lvl.Level private variable T A B C : Type{ℓ} private variable d d₁ d₂ : ℕ -- Accessor of data in 1-dimensional finite space (Implies bounded). -- Like a homogenous tuple or a fixed-size list. -- The type is defined as the type of the vector projection function (A cell in the vector). Vector : ℕ → Type{ℓ} → Type Vector(d)(T) = 𝕟(d) → T -- Type of elements in the vector Element : Vector(d)(T) → Type Element{T = T} = const T -- The maximum number of dimensions of a space that the vector can describe points in dim : Vector(d)(T) → ℕ dim{d = d} = const d -- The projection function (which also is the function itself). proj : Vector(d)(T) → 𝕟(d) → T proj = id -- TODO: Move this to a separate "Relations" file open import Logic open import Relator.Equals.Proofs.Equivalence open import Structure.Function.Domain open import Structure.Setoid private variable ℓₑ : Lvl.Level -- The vector's elements are all distinct (the vector contains no duplicate elements). Distinct : ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Vector(d)(T) → Stmt Distinct = Injective ⦃ [≡]-equiv ⦄ -- The first element of a non-empty vector head : Vector(𝐒(d))(T) → T head(v) = v(𝟎) -- The list without the first element of a non-empty vector tail : Vector(𝐒(d))(T) → Vector(d)(T) (tail{𝐒(_)}(v)) (i) = v(𝐒(i)) -- The list without the first element if there were any tail₀ : Vector(d)(T) → Vector(Numeral.Natural.𝐏(d))(T) tail₀{𝟎} = id tail₀{𝐒(_)} = tail -- The last element of a non-empty vector last : Vector(𝐒(d))(T) → T last(v) = v(maximum) -- The list without the last element if there were any withoutLast : Vector(𝐒(d))(T) → Vector(d)(T) (withoutLast v)(i) = v(bound-𝐒(i)) -- Applies a function on every value of the vector map : (A → B) → Vector(d)(A) → Vector(d)(B) (map f(v))(i) = f(v(i)) -- Applies a binary operation on every pair of values, each from 2 vectors elementwise -- Example: -- map₂(_+_) [1,2,3] [10,20,30] = [1+10 , 2+20 , 3+30] = [11,22,33] map₂ : (A → B → C) → Vector(d)(A) → Vector(d)(B) → Vector(d)(C) (map₂(_▫_) (v₁)(v₂))(i) = v₁(i) ▫ v₂(i) map₂-min : (A → B → C) → ∀{d₁ d₂} → Vector(d₁)(A) → Vector(d₂)(B) → Vector(min d₁ d₂)(C) (map₂-min(_▫_) (v₁)(v₂))(i) = v₁(bound-[≤] infer i) ▫ v₂(bound-[≤] infer i) -- Example: -- foldₗ (_▫_) (0) [1,2,3,4] -- = (((0 ▫ 1) ▫ 2) ▫ 3) ▫ 4 foldₗ : (B → A → B) → B → Vector(d)(A) → B foldₗ {d = 𝟎} (_▫_) (init) (v) = init foldₗ {d = 𝐒(d)} (_▫_) (init) (v) = foldₗ {d = d} (_▫_) (init ▫ (head v)) (tail v) -- Example: -- reduceₗ (_▫_) [1,2,3,4] -- = ((1 ▫ 2) ▫ 3) ▫ 4 reduceₗ : (A → A → A) → Vector(𝐒(d))(A) → A reduceₗ(_▫_) v = foldₗ(_▫_) (head v) (tail v) -- Example: -- reduceOrₗ (_▫_) 0 [1,2,3,4] -- = ((1 ▫ 2) ▫ 3) ▫ 4 reduceOrₗ : (A → A → A) → A → Vector(d)(A) → A reduceOrₗ {d = 𝟎} _ empty _ = empty reduceOrₗ {d = 𝐒(d)} (_▫_) empty v = foldₗ(_▫_) (head v) (tail v) -- Example: -- foldᵣ (_▫_) (0) [1,2,3,4] -- = 1 ▫ (2 ▫ (3 ▫ (4 ▫ 0))) foldᵣ : (A → B → B) → B → Vector(d)(A) → B foldᵣ {d = 𝟎} (_▫_) (init) (v) = init foldᵣ {d = 𝐒(d)} (_▫_) (init) (v) = (head v) ▫ (foldᵣ {d = d} (_▫_) (init) (tail v)) -- Example: -- foldᵣ-init (_▫_) (0) [1,2,3,4] -- = 0 ▫ (1 ▫ (2 ▫ (3 ▫ 4))) foldᵣ-init : (A → A → A) → A → Vector(d)(A) → A foldᵣ-init {d = 𝟎} (_▫_) (init) (v) = init foldᵣ-init {d = 𝐒(d)} (_▫_) (init) (v) = init ▫ (foldᵣ-init {d = d} (_▫_) (head v) (tail v)) -- Example: -- reduceᵣ (_▫_) [1,2,3,4] -- = 1 ▫ (2 ▫ (3 ▫ 4)) reduceᵣ : (T → T → T) → Vector(𝐒(d))(T) → T reduceᵣ {d = 𝟎} (_▫_) (v) = head v reduceᵣ {d = 𝐒(d)} (_▫_) (v) = (head v) ▫ (reduceᵣ (_▫_) (tail v)) -- Example: -- reduceOrᵣ (_▫_) (0) [1,2,3,4] -- = 1 ▫ (2 ▫ (3 ▫ 4)) reduceOrᵣ : (T → T → T) → T → Vector(d)(T) → T reduceOrᵣ {d = 𝟎} _ empty v = empty reduceOrᵣ {d = 𝐒(d)} (_▫_) empty v = reduceᵣ(_▫_) v -- A vector filled with multiple copies of a single element. fill : T → Vector(d)(T) fill(elem) = const(elem) -- An empty vector. empty : Vector(0)(T) empty() -- A vector with a single element. singleton : T → Vector(1)(T) singleton x 𝟎 = x -- A vector with two elements. pair : T → T → Vector(2)(T) pair x _ (𝟎) = x pair _ y (𝐒 𝟎) = y -- A vector with an additional element at the start. prepend : T → Vector(d)(T) → Vector(𝐒(d))(T) (prepend(x)(_)) (𝟎) = x (prepend(_)(v)) (𝐒(n)) = v(n) -- A vector with an additional element inserted at an already existing position. -- Examples: -- insert 0 x [a,b,c] = [x,a,b,c] -- insert 1 x [a,b,c] = [a,x,b,c] -- insert 2 x [a,b,c] = [a,b,x,c] -- insert 3 x [a,b,c] is a type error because 3 is not an existing position. insert : 𝕟(d) → T → Vector(d)(T) → Vector(𝐒(d))(T) insert 𝟎 = prepend insert (𝐒 _) _ v 𝟎 = v(𝟎) insert (𝐒 i) x v (𝐒 n) = insert i x (tail v) n -- A vector with an additional element inserted at a position. -- Note: The difference compared to insert is that this includes the postpending operation. -- Examples: -- insert₊ 0 x [a,b] = [x,a,b] -- insert₊ 0 x [a,b] 0 ≟ [x,a,b] 0 = x -- insert₊ 0 x [a,b] 1 ≟ [x,a,b] 1 = a -- insert₊ 0 x [a,b] 2 ≟ [x,a,b] 2 = b -- insert₊ 1 x [a,b] = [a,x,b] -- insert₊ 1 x [a,b] 0 = a -- insert₊ 1 x [a,b] 1 = insert₊ 0 x [b] 0 = x -- insert₊ 1 x [a,b] 2 = insert₊ 0 x [b] 1 = [x,b] 1 = b -- insertv 2 x [a,b] = [a,b,x] -- insert₊ 2 x [a,b] 0 = a -- insert₊ 2 x [a,b] 1 = insert₊ 1 x [b] 0 = b -- insert₊ 2 x [a,b] 2 = insert₊ 1 x [b] 1 = insert₊ 0 x [] 0 = [x] 0 = x insert₊ : 𝕟₌(d) → T → Vector(d)(T) → Vector(𝐒(d))(T) insert₊{_} 𝟎 = prepend insert₊{𝐒 _} (𝐒 _) _ v 𝟎 = v(𝟎) insert₊{𝐒 _} (𝐒 i) x v (𝐒 n) = insert₊ i x (tail v) n -- A vector concatenated with another vector _++_ : Vector(d₁)(T) → Vector(d₂)(T) → Vector(d₁ ℕ.+ d₂)(T) _++_ {d₁ = 𝟎} {d₂ = d₂} v₁ v₂ = v₂ _++_ {d₁ = 𝐒(d₁)} {d₂ = d₂} v₁ v₂ (𝟎) = v₁(𝟎) _++_ {d₁ = 𝐒(d₁)} {d₂ = d₂} v₁ v₂ (𝐒(i)) = _++_ {d₁ = d₁} {d₂ = d₂} (v₁ ∘ 𝐒) v₂ i count : (T → Bool) → Vector(d)(T) → ℕ count {d = 𝟎} (f)(v) = 𝟎 count {d = 𝐒(n)} (f)(v) = (if f(head v) then 𝐒 else id) (count{d = n} (f)(tail v)) reverse : Vector(d)(T) → Vector(d)(T) (reverse(v)) (n) = v(Wrapping.[−] n) indexProject : 𝕟(d) → T → T → Vector(d)(T) indexProject n true false i = if(n ≡? i) then true else false -- A vector without the element at the specified index -- TODO: Implement Numeral.Finite.Bound.bound-𝐏 -- without : ∀{T}{d} → 𝕟(𝐒(d)) → Vector(𝐒(d))(T) → Vector(d)(T) -- Vector.proj (without {_}{𝐒(_)} (𝟎) (v)) (i) = Vector.proj(v)(𝐒(i)) -- Vector.proj (without {_}{𝐒(_)} (𝐒(n))(v)) (i) = if(i ≤? n) then Vector.proj(v)(𝐒(i)) else Vector.proj(v)(bound-𝐏(i)) -- postpend : ∀{T}{d} → T → Vector(d)(T) → Vector(𝐒(d))(T) -- Vector.proj(postpend{_}{d} (x)(_)) (n) = if (n ≡? d) then x else Vector.proj(v)(n) -- concat : ∀{T}{d₁ d₂} → Vector(d₁)(T) → Vector(d₂)(T) → Vector(d₁ + d₂)(T) -- Vector.proj(concat(v₁)(v₂)) (n) with (n < d₁ ≡ 𝑇) -- ... () = Vector.proj(v₁) (n) -- ... () = Vector.proj(v₂) (n) -- TODO: take / truncate -- TODO: Equality by function equality
34.407407
119
0.569833
4d6091193fa82bcf3dfe82b9f5a6bf77c75822f3
2,308
agda
Agda
examples/examplesPaperJFP/CounterCell.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
examples/examplesPaperJFP/CounterCell.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
examples/examplesPaperJFP/CounterCell.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module examplesPaperJFP.CounterCell where open import Data.Product open import Data.Nat.Base open import Data.Nat.Show open import Data.String.Base using (String; _++_) open import Size -- open import NativeIO -- open import SizedIO.Base -- open import SizedIO.Object -- open import SizedIO.IOObject -- open import SizedIO.ConsoleObject -- open import SizedIO.Console hiding (main) open import examplesPaperJFP.NativeIOSafe open import examplesPaperJFP.ConsoleInterface open import examplesPaperJFP.Console hiding (main) open import examplesPaperJFP.Object using (Interface; Method; Result; CellMethod; get; put; CellResult; cellJ) open import examplesPaperJFP.Sized hiding (program; main) data CounterMethod A : Set where super : (m : CellMethod A) → CounterMethod A stats : CounterMethod A pattern getᶜ = super get pattern putᶜ x = super (put x) statsCellI : (A : Set) → Interface Method (statsCellI A) = CounterMethod A Result (statsCellI A) (super m) = Result (cellJ A) m Result (statsCellI A) stats = Unit CounterC : (i : Size) → Set CounterC = IOObject ConsoleInterface (statsCellI String) counterCell : ∀{i} (c : CellC i) (ngets nputs : ℕ) → CounterC i method (counterCell c ngets nputs) getᶜ = method c get >>= λ { (s , c′) → return (s , counterCell c′ (1 + ngets) nputs) } method (counterCell c ngets nputs) (putᶜ x) = method c (put x) >>= λ { (_ , c′) → return (unit , counterCell c′ ngets (1 + nputs)) } method (counterCell c ngets nputs) stats = exec (putStrLn ("Counted " ++ show ngets ++ " calls to get and " ++ show nputs ++ " calls to put.")) λ _ → return (unit , counterCell c ngets nputs) program : String → IO ConsoleInterface ∞ Unit program arg = let c₀ = counterCell (simpleCell "Start") 0 0 in method c₀ getᶜ >>= λ{ (s , c₁) → exec (putStrLn s) λ _ → method c₁ (putᶜ arg) >>= λ{ (_ , c₂) → method c₂ getᶜ >>= λ{ (s′ , c₃) → exec (putStrLn s′) λ _ → method c₃ (putᶜ "Over!") >>= λ{ (_ , c₄) → method c₄ stats >>= λ{ (_ , c₅) → return unit }}}}} main : NativeIO Unit main = translateIO translateIOConsoleLocal (program "Hello")
32.971429
110
0.629983
fb55825eecdcabc7543dc1794bbd8658f356f29f
1,316
agda
Agda
examples/outdated-and-incorrect/tait/Trans.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/tait/Trans.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/tait/Trans.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Trans where open import Prelude Rel : Set -> Set1 Rel A = A -> A -> Set data [_]* {A : Set}(R : Rel A)(x : A) : A -> Set where ref : [ R ]* x x _▹_ : {y z : A} -> R x y -> [ R ]* y z -> [ R ]* x z infixr 40 _▹_ _▹◃_ length : {A : Set}{R : Rel A}{x y : A} -> [ R ]* x y -> Nat length ref = zero length (x ▹ xs) = suc (length xs) _=[_]=>_ : {A B : Set}(R : Rel A)(i : A -> B)(S : Rel B) -> Set R =[ i ]=> S = forall {x y} -> R x y -> S (i x) (i y) map : {A B : Set}{R : Rel A}{S : Rel B}(i : A -> B) -> (R =[ i ]=> S) -> {x y : A} -> [ R ]* x y -> [ S ]* (i x) (i y) map i f ref = ref map i f (x ▹ xs) = f x ▹ map i f xs lem-length-map : {A B : Set}{R : Rel A}{S : Rel B}(i : A -> B) (f : R =[ i ]=> S){x y : A}(xs : [ R ]* x y) -> length xs ≡ length (map {S = S} i f xs) lem-length-map i f ref = refl lem-length-map i f (x ▹ xs) = cong suc (lem-length-map i f xs) _▹◃_ : {A : Set}{R : Rel A}{x y z : A} -> [ R ]* x y -> [ R ]* y z -> [ R ]* x z ref ▹◃ ys = ys (x ▹ xs) ▹◃ ys = x ▹ (xs ▹◃ ys) lem-length▹◃ : {A : Set}{R : Rel A}{x y z : A} (r₁ : [ R ]* x y)(r₂ : [ R ]* y z) -> length r₁ + length r₂ ≡ length (r₁ ▹◃ r₂) lem-length▹◃ ref ys = refl lem-length▹◃ (x ▹ xs) ys = cong suc (lem-length▹◃ xs ys)
29.244444
63
0.417173
393678dacb153b3ba087998acd2809e96d7cfe5c
36
agda
Agda
Categories/Object/Zero.agda
copumpkin/categories
36f4181d751e2ecb54db219911d8c69afe8ba892
[ "BSD-3-Clause" ]
98
2015-04-15T14:57:33.000Z
2022-03-08T05:20:36.000Z
Categories/Object/Zero.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
19
2015-05-23T06:47:10.000Z
2019-08-09T16:31:40.000Z
Categories/Object/Zero.agda
p-pavel/categories
e41aef56324a9f1f8cf3cd30b2db2f73e01066f2
[ "BSD-3-Clause" ]
23
2015-02-05T13:03:09.000Z
2021-11-11T13:50:56.000Z
module Categories.Object.Zero where
18
35
0.861111
12e085c420e60842fbe5d9d97dcbdb61ae7e08b5
9,133
agda
Agda
soundness/ProofUtilities.agda
frelindb/agsyHOL
032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7
[ "MIT" ]
17
2015-09-04T14:38:28.000Z
2021-03-19T20:53:45.000Z
soundness/ProofUtilities.agda
frelindb/agsyHOL
032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7
[ "MIT" ]
null
null
null
soundness/ProofUtilities.agda
frelindb/agsyHOL
032efd5f42e4b56d436ac8e0c3c0f5127b8dc1f7
[ "MIT" ]
3
2016-05-17T20:28:10.000Z
2022-01-15T11:51:19.000Z
module ProofUtilities where -- open import Data.Nat hiding (_>_) open import StdLibStuff open import Syntax open import FSC mutual hn-left-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t β) (G : Form Γ-t α) → Γ ⊢ α ∋ S (headNorm m F) ↔ G → Γ ⊢ α ∋ S F ↔ G hn-left-i m S (app F H) G p = hn-left-i m (λ x → S (app x H)) F G (hn-left-i' m S (headNorm m F) H G p) hn-left-i _ _ (var _ _) _ p = p hn-left-i _ _ N _ p = p hn-left-i _ _ A _ p = p hn-left-i _ _ Π _ p = p hn-left-i _ _ i _ p = p hn-left-i _ _ (lam _ _) _ p = p hn-left-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t α) → Γ ⊢ α ∋ S (headNorm' m F H) ↔ G → Γ ⊢ α ∋ S (app F H) ↔ G hn-left-i' (suc m) S (lam _ F) H G p with hn-left-i m S (sub H F) G p hn-left-i' (suc _) S (lam _ _) _ _ _ | p' = reduce-l {_} {_} {_} {_} {_} {_} {S} p' hn-left-i' 0 _ (lam _ _) _ _ p = p hn-left-i' zero _ (var _ _) _ _ p = p hn-left-i' (suc _) _ (var _ _) _ _ p = p hn-left-i' zero _ N _ _ p = p hn-left-i' (suc _) _ N _ _ p = p hn-left-i' zero _ A _ _ p = p hn-left-i' (suc _) _ A _ _ p = p hn-left-i' zero _ Π _ _ p = p hn-left-i' (suc _) _ Π _ _ p = p hn-left-i' zero _ i _ _ p = p hn-left-i' (suc _) _ i _ _ p = p hn-left-i' zero _ (app _ _) _ _ p = p hn-left-i' (suc _) _ (app _ _) _ _ p = p hn-left : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t α) (G : Form Γ-t α) → Γ ⊢ α ∋ headNorm m F ↔ G → Γ ⊢ α ∋ F ↔ G hn-left m F G p = hn-left-i m (λ x → x) F G p mutual hn-right-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t β) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ S (headNorm m F) → Γ ⊢ α ∋ G ↔ S F hn-right-i m S (app F H) G p = hn-right-i m (λ x → S (app x H)) F G (hn-right-i' m S (headNorm m F) H G p) hn-right-i _ _ (var _ _) _ p = p hn-right-i _ _ N _ p = p hn-right-i _ _ A _ p = p hn-right-i _ _ Π _ p = p hn-right-i _ _ i _ p = p hn-right-i _ _ (lam _ _) _ p = p hn-right-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t α) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ S (headNorm' m F H) → Γ ⊢ α ∋ G ↔ S (app F H) hn-right-i' (suc m) S (lam _ F) H G p with hn-right-i m S (sub H F) G p hn-right-i' (suc _) S (lam _ _) _ _ _ | p' = reduce-r {_} {_} {_} {_} {_} {_} {S} p' hn-right-i' 0 _ (lam _ _) _ _ p = p hn-right-i' zero _ (var _ _) _ _ p = p hn-right-i' (suc _) _ (var _ _) _ _ p = p hn-right-i' zero _ N _ _ p = p hn-right-i' (suc _) _ N _ _ p = p hn-right-i' zero _ A _ _ p = p hn-right-i' (suc _) _ A _ _ p = p hn-right-i' zero _ Π _ _ p = p hn-right-i' (suc _) _ Π _ _ p = p hn-right-i' zero _ i _ _ p = p hn-right-i' (suc _) _ i _ _ p = p hn-right-i' zero _ (app _ _) _ _ p = p hn-right-i' (suc _) _ (app _ _) _ _ p = p hn-right : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t α) (G : Form Γ-t α) → Γ ⊢ α ∋ G ↔ headNorm m F → Γ ⊢ α ∋ G ↔ F hn-right m F G p = hn-right-i m (λ x → x) F G p mutual hn-succ-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) → Γ ⊢ S (headNorm m F) → Γ ⊢ S F hn-succ-i m S (app F H) p = hn-succ-i m (λ x → S (app x H)) F (hn-succ-i' m S (headNorm m F) H p) hn-succ-i _ _ (var _ _) p = p hn-succ-i _ _ N p = p hn-succ-i _ _ A p = p hn-succ-i _ _ Π p = p hn-succ-i _ _ i p = p hn-succ-i _ _ (lam _ _) p = p hn-succ-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) → Γ ⊢ S (headNorm' m F H) → Γ ⊢ S (app F H) hn-succ-i' (suc m) S (lam _ F) H p with hn-succ-i m S (sub H F) p hn-succ-i' (suc _) S (lam _ _) _ _ | p' = reduce {_} {_} {_} {_} {_} {S} p' hn-succ-i' 0 _ (lam _ _) _ p = p hn-succ-i' zero _ (var _ _) _ p = p hn-succ-i' (suc _) _ (var _ _) _ p = p hn-succ-i' zero _ N _ p = p hn-succ-i' (suc _) _ N _ p = p hn-succ-i' zero _ A _ p = p hn-succ-i' (suc _) _ A _ p = p hn-succ-i' zero _ Π _ p = p hn-succ-i' (suc _) _ Π _ p = p hn-succ-i' zero _ i _ p = p hn-succ-i' (suc _) _ i _ p = p hn-succ-i' zero _ (app _ _) _ p = p hn-succ-i' (suc _) _ (app _ _) _ p = p hn-succ : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} (m : ℕ) (F : Form Γ-t $o) → Γ ⊢ headNorm m F → Γ ⊢ F hn-succ m F p = hn-succ-i m (λ x → x) F p mutual hn-ante-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) (G : Form Γ-t $o) → Γ , S (headNorm m F) ⊢ G → Γ , S F ⊢ G hn-ante-i m S (app F H) G p = hn-ante-i m (λ x → S (app x H)) F G (hn-ante-i' m S (headNorm m F) H G p) hn-ante-i _ _ (var _ _) _ p = p hn-ante-i _ _ N _ p = p hn-ante-i _ _ A _ p = p hn-ante-i _ _ Π _ p = p hn-ante-i _ _ i _ p = p hn-ante-i _ _ (lam _ _) _ p = p hn-ante-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (H : Form Γ-t γ) (G : Form Γ-t $o) → Γ , S (headNorm' m F H) ⊢ G → Γ , S (app F H) ⊢ G hn-ante-i' (suc m) S (lam _ F) H G p with hn-ante-i m S (sub H F) G p hn-ante-i' (suc _) S (lam _ _) _ _ _ | p' = reduce {_} {_} {_} {_} {_} {S} p' hn-ante-i' 0 _ (lam _ _) _ _ p = p hn-ante-i' zero _ (var _ _) _ _ p = p hn-ante-i' (suc _) _ (var _ _) _ _ p = p hn-ante-i' zero _ N _ _ p = p hn-ante-i' (suc _) _ N _ _ p = p hn-ante-i' zero _ A _ _ p = p hn-ante-i' (suc _) _ A _ _ p = p hn-ante-i' zero _ Π _ _ p = p hn-ante-i' (suc _) _ Π _ _ p = p hn-ante-i' zero _ i _ _ p = p hn-ante-i' (suc _) _ i _ _ p = p hn-ante-i' zero _ (app _ _) _ _ p = p hn-ante-i' (suc _) _ (app _ _) _ _ p = p hn-ante : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} (m : ℕ) (F : Form Γ-t $o) (G : Form Γ-t $o) → Γ , headNorm m F ⊢ G → Γ , F ⊢ G hn-ante m F G p = hn-ante-i m (λ x → x) F G p mutual hn-ante-eq-i : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t β) (G H : Form Γ-t α) → Γ , S (headNorm m F) ⊢ G == H → Γ , S F ⊢ G == H hn-ante-eq-i m S (app F I) G H p = hn-ante-eq-i m (λ x → S (app x I)) F G H (hn-ante-eq-i' m S (headNorm m F) I G H p) hn-ante-eq-i _ _ (var _ _) _ _ p = p hn-ante-eq-i _ _ N _ _ p = p hn-ante-eq-i _ _ A _ _ p = p hn-ante-eq-i _ _ Π _ _ p = p hn-ante-eq-i _ _ i _ _ p = p hn-ante-eq-i _ _ (lam _ _) _ _ p = p hn-ante-eq-i' : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α β γ : Type n} (m : ℕ) (S : Form Γ-t β → Form Γ-t $o) (F : Form Γ-t (γ > β)) (I : Form Γ-t γ) (G H : Form Γ-t α) → Γ , S (headNorm' m F I) ⊢ G == H → Γ , S (app F I) ⊢ G == H hn-ante-eq-i' (suc m) S (lam _ F) I G H p with hn-ante-eq-i m S (sub I F) G H p hn-ante-eq-i' (suc _) S (lam _ _) _ _ _ _ | p' = reduce {_} {_} {_} {_} {_} {_} {S} p' hn-ante-eq-i' 0 _ (lam _ _) _ _ _ p = p hn-ante-eq-i' zero _ (var _ _) _ _ _ p = p hn-ante-eq-i' (suc _) _ (var _ _) _ _ _ p = p hn-ante-eq-i' zero _ N _ _ _ p = p hn-ante-eq-i' (suc _) _ N _ _ _ p = p hn-ante-eq-i' zero _ A _ _ _ p = p hn-ante-eq-i' (suc _) _ A _ _ _ p = p hn-ante-eq-i' zero _ Π _ _ _ p = p hn-ante-eq-i' (suc _) _ Π _ _ _ p = p hn-ante-eq-i' zero _ i _ _ _ p = p hn-ante-eq-i' (suc _) _ i _ _ _ p = p hn-ante-eq-i' zero _ (app _ _) _ _ _ p = p hn-ante-eq-i' (suc _) _ (app _ _) _ _ _ p = p hn-ante-eq : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} (m : ℕ) (F : Form Γ-t $o) (G H : Form Γ-t α) → Γ , headNorm m F ⊢ G == H → Γ , F ⊢ G == H hn-ante-eq m F G H p = hn-ante-eq-i m (λ x → x) F G H p -- ------------------------------------ head-& : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ & G₁) ↔ (F₂ & G₂) head-& p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-const _ N)) (simp (head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₁)))) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₂)))) head-|| : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ || G₁) ↔ (F₂ || G₂) head-|| p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) p₁)) p₂ head-=> : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ G₁ G₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ => G₁) ↔ (F₂ => G₂) head-=> p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ A)) (simp (head-app _ _ _ _ _ _ (simp (head-const _ N)) p₁)))) p₂ head-~ : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {F₁ F₂ : Form Γ-t $o} → Γ ⊢ $o ∋ F₁ == F₂ → Γ ⊢ $o ∋ (~ F₁) ↔ (~ F₂) head-~ p = head-app _ _ _ _ _ _ (simp (head-const _ N)) p head-== : {n : ℕ} {Γ-t : Ctx n} {Γ : FSC-Ctx n Γ-t} {α : Type n} {F₁ F₂ G₁ G₂ : Form Γ-t α} → Γ ⊢ α ∋ F₁ == F₂ → Γ ⊢ α ∋ G₁ == G₂ → Γ ⊢ $o ∋ (F₁ == G₁) ↔ (F₂ == G₂) head-== p₁ p₂ = head-app _ _ _ _ _ _ (simp (head-app _ _ _ _ _ _ (simp (head-const _ _)) p₁)) p₂
48.068421
257
0.4902
c5a8029189e0ce96b3a7dba043c97bd0f17262e7
14,155
agda
Agda
src/fot/FOTC/Data/Nat/Inequalities/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/FOTC/Data/Nat/Inequalities/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/FOTC/Data/Nat/Inequalities/PropertiesI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Properties of the inequalities ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.Inequalities.PropertiesI where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.PropertiesI open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.EliminationPropertiesI open import FOTC.Data.Nat.PropertiesI open import FOTC.Data.Nat.UnaryNumbers ------------------------------------------------------------------------------ -- N.B. The elimination properties are in the module -- FOTC.Data.Nat.Inequalities.EliminationProperties. ------------------------------------------------------------------------------ -- Congruence properties leLeftCong : ∀ {m n o} → m ≡ n → le m o ≡ le n o leLeftCong refl = refl ltLeftCong : ∀ {m n o} → m ≡ n → lt m o ≡ lt n o ltLeftCong refl = refl ltRightCong : ∀ {m n o} → n ≡ o → lt m n ≡ lt m o ltRightCong refl = refl ltCong : ∀ {m n m' n'} → m ≡ m' → n ≡ n' → lt m n ≡ lt m' n' ltCong refl refl = refl ------------------------------------------------------------------------------ 0≯x : ∀ {n} → N n → zero ≯ n 0≯x nzero = lt-00 0≯x (nsucc {n} Nn) = lt-S0 n x≮x : ∀ {n} → N n → n ≮ n x≮x nzero = lt-00 x≮x (nsucc {n} Nn) = trans (lt-SS n n) (x≮x Nn) Sx≰0 : ∀ {n} → N n → succ₁ n ≰ zero Sx≰0 nzero = x≮x (nsucc nzero) Sx≰0 (nsucc {n} Nn) = trans (lt-SS (succ₁ n) zero) (lt-S0 n) x<Sx : ∀ {n} → N n → n < succ₁ n x<Sx nzero = lt-0S zero x<Sx (nsucc {n} Nn) = trans (lt-SS n (succ₁ n)) (x<Sx Nn) x<y→Sx<Sy : ∀ {m n} → m < n → succ₁ m < succ₁ n x<y→Sx<Sy {m} {n} m<n = trans (lt-SS m n) m<n Sx<Sy→x<y : ∀ {m n} → succ₁ m < succ₁ n → m < n Sx<Sy→x<y {m} {n} Sm<Sn = trans (sym (lt-SS m n)) Sm<Sn x<y→x<Sy : ∀ {m n} → N m → N n → m < n → m < succ₁ n x<y→x<Sy Nm nzero m<0 = ⊥-elim (x<0→⊥ Nm m<0) x<y→x<Sy nzero (nsucc {n} Nn) 0<Sn = lt-0S (succ₁ n) x<y→x<Sy (nsucc {m} Nm) (nsucc {n} Nn) Sm<Sn = x<y→Sx<Sy (x<y→x<Sy Nm Nn (Sx<Sy→x<y Sm<Sn)) x≤x : ∀ {n} → N n → n ≤ n x≤x nzero = lt-0S zero x≤x (nsucc {n} Nn) = trans (lt-SS n (succ₁ n)) (x≤x Nn) x≤y→Sx≤Sy : ∀ {m n} → m ≤ n → succ₁ m ≤ succ₁ n x≤y→Sx≤Sy {m} {n} m≤n = trans (lt-SS m (succ₁ n)) m≤n Sx≤Sy→x≤y : ∀ {m n} → succ₁ m ≤ succ₁ n → m ≤ n Sx≤Sy→x≤y {m} {n} Sm≤Sn = trans (sym (lt-SS m (succ₁ n))) Sm≤Sn Sx≤y→x≤y : ∀ {m n} → N m → N n → succ₁ m ≤ n → m ≤ n Sx≤y→x≤y {m} {n} Nm Nn Sm≤n = x<y→x<Sy Nm Nn (trans (sym (lt-SS m n)) Sm≤n) x≰y→Sx≰Sy : ∀ m n → m ≰ n → succ₁ m ≰ succ₁ n x≰y→Sx≰Sy m n m≰n = trans (lt-SS m (succ₁ n)) m≰n x>y→y<x : ∀ {m n} → N m → N n → m > n → n < m x>y→y<x nzero Nn 0>n = ⊥-elim (0>x→⊥ Nn 0>n) x>y→y<x (nsucc {m} Nm) nzero _ = lt-0S m x>y→y<x (nsucc {m} Nm) (nsucc {n} Nn) Sm>Sn = trans (lt-SS n m) (x>y→y<x Nm Nn (trans (sym (lt-SS n m)) Sm>Sn)) x≥y→x≮y : ∀ {m n} → N m → N n → m ≥ n → m ≮ n x≥y→x≮y nzero nzero _ = x≮x nzero x≥y→x≮y nzero (nsucc Nn) 0≥Sn = ⊥-elim (0≥S→⊥ Nn 0≥Sn) x≥y→x≮y (nsucc {m} Nm) nzero _ = lt-S0 m x≥y→x≮y (nsucc {m} Nm) (nsucc {n} Nn) Sm≥Sn = trans (lt-SS m n) (x≥y→x≮y Nm Nn (trans (sym (lt-SS n (succ₁ m))) Sm≥Sn)) x≮y→x≥y : ∀ {m n} → N m → N n → m ≮ n → m ≥ n x≮y→x≥y nzero nzero 0≮0 = x≤x nzero x≮y→x≥y nzero (nsucc {n} Nn) 0≮Sn = ⊥-elim (t≢f (trans (sym (lt-0S n)) 0≮Sn)) x≮y→x≥y (nsucc {m} Nm) nzero Sm≮n = lt-0S (succ₁ m) x≮y→x≥y (nsucc {m} Nm) (nsucc {n} Nn) Sm≮Sn = trans (lt-SS n (succ₁ m)) (x≮y→x≥y Nm Nn (trans (sym (lt-SS m n)) Sm≮Sn)) x>y→x≰y : ∀ {m n} → N m → N n → m > n → m ≰ n x>y→x≰y nzero Nn 0>m = ⊥-elim (0>x→⊥ Nn 0>m) x>y→x≰y (nsucc Nm) nzero _ = Sx≰0 Nm x>y→x≰y (nsucc {m} Nm) (nsucc {n} Nn) Sm>Sn = x≰y→Sx≰Sy m n (x>y→x≰y Nm Nn (trans (sym (lt-SS n m)) Sm>Sn)) x>y∨x≤y : ∀ {m n} → N m → N n → m > n ∨ m ≤ n x>y∨x≤y {n = n} nzero Nn = inj₂ (lt-0S n) x>y∨x≤y (nsucc {m} Nm) nzero = inj₁ (lt-0S m) x>y∨x≤y (nsucc {m} Nm) (nsucc {n} Nn) = case (λ m>n → inj₁ (trans (lt-SS n m) m>n)) (λ m≤n → inj₂ (x≤y→Sx≤Sy m≤n)) (x>y∨x≤y Nm Nn) x<y∨x≥y : ∀ {m n} → N m → N n → m < n ∨ m ≥ n x<y∨x≥y Nm Nn = x>y∨x≤y Nn Nm x<y∨x≮y : ∀ {m n} → N m → N n → m < n ∨ m ≮ n x<y∨x≮y Nm Nn = case (λ m<n → inj₁ m<n) (λ m≥n → inj₂ (x≥y→x≮y Nm Nn m≥n)) (x<y∨x≥y Nm Nn) x≤y∨x≰y : ∀ {m n} → N m → N n → m ≤ n ∨ m ≰ n x≤y∨x≰y {n = n} nzero Nn = inj₁ (lt-0S n) x≤y∨x≰y (nsucc Nm) nzero = inj₂ (Sx≰0 Nm) x≤y∨x≰y (nsucc {m} Nm) (nsucc {n} Nn) = case (λ m≤n → inj₁ (x≤y→Sx≤Sy m≤n)) (λ m≰n → inj₂ (x≰y→Sx≰Sy m n m≰n)) (x≤y∨x≰y Nm Nn) x≡y→x≤y : ∀ {m n} → N m → N n → m ≡ n → m ≤ n x≡y→x≤y Nm _ refl = x≤x Nm x<y→x≤y : ∀ {m n} → N m → N n → m < n → m ≤ n x<y→x≤y Nm nzero m<0 = ⊥-elim (x<0→⊥ Nm m<0) x<y→x≤y nzero (nsucc {n} Nn) _ = lt-0S (succ₁ n) x<y→x≤y (nsucc {m} Nm) (nsucc {n} Nn) Sm<Sn = x≤y→Sx≤Sy (x<y→x≤y Nm Nn (Sx<Sy→x<y Sm<Sn)) x<Sy→x≤y : ∀ {m n} → N m → N n → m < succ₁ n → m ≤ n x<Sy→x≤y {n = n} nzero Nn 0<Sn = lt-0S n x<Sy→x≤y (nsucc Nm) Nn Sm<Sn = Sm<Sn x≤y→x<Sy : ∀ {m n} → N m → N n → m ≤ n → m < succ₁ n x≤y→x<Sy {n = n} nzero Nn 0≤n = lt-0S n x≤y→x<Sy (nsucc Nm) Nn Sm≤n = Sm≤n x≤Sx : ∀ {m} → N m → m ≤ succ₁ m x≤Sx Nm = x<y→x≤y Nm (nsucc Nm) (x<Sx Nm) x<y→Sx≤y : ∀ {m n} → N m → N n → m < n → succ₁ m ≤ n x<y→Sx≤y Nm nzero m<0 = ⊥-elim (x<0→⊥ Nm m<0) x<y→Sx≤y nzero (nsucc {n} Nn) _ = x≤y→Sx≤Sy (lt-0S n) x<y→Sx≤y (nsucc {m} Nm) (nsucc {n} Nn) Sm<Sn = trans (lt-SS (succ₁ m) (succ₁ n)) Sm<Sn Sx≤y→x<y : ∀ {m n} → N m → N n → succ₁ m ≤ n → m < n Sx≤y→x<y Nm nzero Sm≤0 = ⊥-elim (S≤0→⊥ Nm Sm≤0) Sx≤y→x<y nzero (nsucc {n} Nn) _ = lt-0S n Sx≤y→x<y (nsucc {m} Nm) (nsucc {n} Nn) SSm≤Sn = x<y→Sx<Sy (Sx≤y→x<y Nm Nn (Sx≤Sy→x≤y SSm≤Sn)) x≤y→x≯y : ∀ {m n} → N m → N n → m ≤ n → m ≯ n x≤y→x≯y nzero Nn _ = 0≯x Nn x≤y→x≯y (nsucc Nm) nzero Sm≤0 = ⊥-elim (S≤0→⊥ Nm Sm≤0) x≤y→x≯y (nsucc {m} Nm) (nsucc {n} Nn) Sm≤Sn = trans (lt-SS n m) (x≤y→x≯y Nm Nn (trans (sym (lt-SS m (succ₁ n))) Sm≤Sn)) x≯y→x≤y : ∀ {m n} → N m → N n → m ≯ n → m ≤ n x≯y→x≤y {n = n} nzero Nn _ = lt-0S n x≯y→x≤y (nsucc {m} Nm) nzero Sm≯0 = ⊥-elim (t≢f (trans (sym (lt-0S m)) Sm≯0)) x≯y→x≤y (nsucc {m} Nm) (nsucc {n} Nn) Sm≯Sn = trans (lt-SS m (succ₁ n)) (x≯y→x≤y Nm Nn (trans (sym (lt-SS n m)) Sm≯Sn)) Sx≯y→x≯y : ∀ {m n} → N m → N n → succ₁ m ≯ n → m ≯ n Sx≯y→x≯y Nm Nn Sm≤n = x≤y→x≯y Nm Nn (Sx≤y→x≤y Nm Nn (x≯y→x≤y (nsucc Nm) Nn Sm≤n)) x>y∨x≯y : ∀ {m n} → N m → N n → m > n ∨ m ≯ n x>y∨x≯y nzero Nn = inj₂ (0≯x Nn) x>y∨x≯y (nsucc {m} Nm) nzero = inj₁ (lt-0S m) x>y∨x≯y (nsucc {m} Nm) (nsucc {n} Nn) = case (λ h → inj₁ (trans (lt-SS n m) h)) (λ h → inj₂ (trans (lt-SS n m) h)) (x>y∨x≯y Nm Nn) <-trans : ∀ {m n o} → N m → N n → N o → m < n → n < o → m < o <-trans nzero nzero _ 0<0 _ = ⊥-elim (0<0→⊥ 0<0) <-trans nzero (nsucc Nn) nzero _ Sn<0 = ⊥-elim (S<0→⊥ Sn<0) <-trans nzero (nsucc Nn) (nsucc {o} No) _ _ = lt-0S o <-trans (nsucc Nm) Nn nzero _ n<0 = ⊥-elim (x<0→⊥ Nn n<0) <-trans (nsucc Nm) nzero (nsucc No) Sm<0 _ = ⊥-elim (S<0→⊥ Sm<0) <-trans (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) Sm<Sn Sn<So = x<y→Sx<Sy (<-trans Nm Nn No (Sx<Sy→x<y Sm<Sn) (Sx<Sy→x<y Sn<So)) ≤-trans : ∀ {m n o} → N m → N n → N o → m ≤ n → n ≤ o → m ≤ o ≤-trans {o = o} nzero Nn No _ _ = lt-0S o ≤-trans (nsucc Nm) nzero No Sm≤0 _ = ⊥-elim (S≤0→⊥ Nm Sm≤0) ≤-trans (nsucc Nm) (nsucc Nn) nzero _ Sn≤0 = ⊥-elim (S≤0→⊥ Nn Sn≤0) ≤-trans (nsucc {m} Nm) (nsucc {n} Nn) (nsucc {o} No) Sm≤Sn Sn≤So = x≤y→Sx≤Sy (≤-trans Nm Nn No (Sx≤Sy→x≤y Sm≤Sn) (Sx≤Sy→x≤y Sn≤So)) pred-≤ : ∀ {n} → N n → pred₁ n ≤ n pred-≤ nzero = lt (pred₁ zero) 1' ≡⟨ ltLeftCong pred-0 ⟩ lt zero 1' ≡⟨ lt-0S zero ⟩ true ∎ pred-≤ (nsucc {n} Nn) = lt (pred₁ (succ₁ n)) (succ₁ (succ₁ n)) ≡⟨ ltLeftCong (pred-S n) ⟩ lt n (succ₁ (succ₁ n)) ≡⟨ <-trans Nn (nsucc Nn) (nsucc (nsucc Nn)) (x<Sx Nn) (x<Sx (nsucc Nn)) ⟩ true ∎ x≤x+y : ∀ {m n} → N m → N n → m ≤ m + n x≤x+y {n = n} nzero Nn = lt-0S (zero + n) x≤x+y {n = n} (nsucc {m} Nm) Nn = lt (succ₁ m) (succ₁ (succ₁ m + n)) ≡⟨ lt-SS m (succ₁ m + n) ⟩ lt m (succ₁ m + n) ≡⟨ ltRightCong (+-Sx m n) ⟩ lt m (succ₁ (m + n)) ≡⟨ refl ⟩ le m (m + n) ≡⟨ x≤x+y Nm Nn ⟩ true ∎ x∸y<Sx : ∀ {m n} → N m → N n → m ∸ n < succ₁ m x∸y<Sx {m} Nm nzero = lt (m ∸ zero) (succ₁ m) ≡⟨ ltLeftCong (∸-x0 m) ⟩ lt m (succ₁ m) ≡⟨ x<Sx Nm ⟩ true ∎ x∸y<Sx nzero (nsucc {n} Nn) = lt (zero ∸ succ₁ n) 1' ≡⟨ ltLeftCong (0∸x (nsucc Nn)) ⟩ lt zero 1' ≡⟨ lt-0S zero ⟩ true ∎ x∸y<Sx (nsucc {m} Nm) (nsucc {n} Nn) = lt (succ₁ m ∸ succ₁ n) (succ₁ (succ₁ m)) ≡⟨ ltLeftCong (S∸S Nm Nn) ⟩ lt (m ∸ n) (succ₁ (succ₁ m)) ≡⟨ <-trans (∸-N Nm Nn) (nsucc Nm) (nsucc (nsucc Nm)) (x∸y<Sx Nm Nn) (x<Sx (nsucc Nm)) ⟩ true ∎ Sx∸Sy<Sx : ∀ {m n} → N m → N n → succ₁ m ∸ succ₁ n < succ₁ m Sx∸Sy<Sx {m} {n} Nm Nn = lt (succ₁ m ∸ succ₁ n) (succ₁ m) ≡⟨ ltLeftCong (S∸S Nm Nn) ⟩ lt (m ∸ n) (succ₁ m) ≡⟨ x∸y<Sx Nm Nn ⟩ true ∎ x∸Sy≤x∸y : ∀ {m n} → N m → N n → m ∸ succ₁ n ≤ m ∸ n x∸Sy≤x∸y {m} {n} Nm Nn = le (m ∸ succ₁ n) (m ∸ n) ≡⟨ ltLeftCong (∸-xS m n) ⟩ le (pred₁ (m ∸ n)) (m ∸ n) ≡⟨ pred-≤ (∸-N Nm Nn) ⟩ true ∎ x>y→x∸y+y≡x : ∀ {m n} → N m → N n → m > n → (m ∸ n) + n ≡ m x>y→x∸y+y≡x nzero Nn 0>n = ⊥-elim (0>x→⊥ Nn 0>n) x>y→x∸y+y≡x (nsucc {m} Nm) nzero Sm>0 = trans (+-rightIdentity (∸-N (nsucc Nm) nzero)) (∸-x0 (succ₁ m)) x>y→x∸y+y≡x (nsucc {m} Nm) (nsucc {n} Nn) Sm>Sn = (succ₁ m ∸ succ₁ n) + succ₁ n ≡⟨ +-leftCong (S∸S Nm Nn) ⟩ (m ∸ n) + succ₁ n ≡⟨ +-comm (∸-N Nm Nn) (nsucc Nn) ⟩ succ₁ n + (m ∸ n) ≡⟨ +-Sx n (m ∸ n) ⟩ succ₁ (n + (m ∸ n)) ≡⟨ succCong (+-comm Nn (∸-N Nm Nn)) ⟩ succ₁ ((m ∸ n) + n) ≡⟨ succCong (x>y→x∸y+y≡x Nm Nn (trans (sym (lt-SS n m)) Sm>Sn)) ⟩ succ₁ m ∎ x≤y→y∸x+x≡y : ∀ {m n} → N m → N n → m ≤ n → (n ∸ m) + m ≡ n x≤y→y∸x+x≡y {n = n} nzero Nn 0≤n = trans (+-rightIdentity (∸-N Nn nzero)) (∸-x0 n) x≤y→y∸x+x≡y (nsucc Nm) nzero Sm≤0 = ⊥-elim (S≤0→⊥ Nm Sm≤0) x≤y→y∸x+x≡y (nsucc {m} Nm) (nsucc {n} Nn) Sm≤Sn = (succ₁ n ∸ succ₁ m) + succ₁ m ≡⟨ +-leftCong (S∸S Nn Nm) ⟩ (n ∸ m) + succ₁ m ≡⟨ +-comm (∸-N Nn Nm) (nsucc Nm) ⟩ succ₁ m + (n ∸ m) ≡⟨ +-Sx m (n ∸ m) ⟩ succ₁ (m + (n ∸ m)) ≡⟨ succCong (+-comm Nm (∸-N Nn Nm)) ⟩ succ₁ ((n ∸ m) + m) ≡⟨ succCong (x≤y→y∸x+x≡y Nm Nn (trans (sym (lt-SS m (succ₁ n))) Sm≤Sn)) ⟩ succ₁ n ∎ x<Sy→x<y∨x≡y : ∀ {m n} → N m → N n → m < succ₁ n → m < n ∨ m ≡ n x<Sy→x<y∨x≡y nzero nzero 0<S0 = inj₂ refl x<Sy→x<y∨x≡y nzero (nsucc {n} Nn) 0<SSn = inj₁ (lt-0S n) x<Sy→x<y∨x≡y (nsucc {m} Nm) nzero Sm<S0 = ⊥-elim (x<0→⊥ Nm (trans (sym (lt-SS m zero)) Sm<S0)) x<Sy→x<y∨x≡y (nsucc {m} Nm) (nsucc {n} Nn) Sm<SSn = case (λ m<n → inj₁ (trans (lt-SS m n) m<n)) (λ m≡n → inj₂ (succCong m≡n)) m<n∨m≡n where m<n∨m≡n : m < n ∨ m ≡ n m<n∨m≡n = x<Sy→x<y∨x≡y Nm Nn (trans (sym (lt-SS m (succ₁ n))) Sm<SSn) x≤y→x<y∨x≡y : ∀ {m n} → N m → N n → m ≤ n → m < n ∨ m ≡ n x≤y→x<y∨x≡y = x<Sy→x<y∨x≡y x<y→y≡z→x<z : ∀ {m n o} → m < n → n ≡ o → m < o x<y→y≡z→x<z m<n refl = m<n x≡y→y<z→x<z : ∀ {m n o} → m ≡ n → n < o → m < o x≡y→y<z→x<z refl n<o = n<o x≥y→y>0→x∸y<x : ∀ {m n} → N m → N n → m ≥ n → n > zero → m ∸ n < m x≥y→y>0→x∸y<x Nm nzero _ 0>0 = ⊥-elim (x>x→⊥ nzero 0>0) x≥y→y>0→x∸y<x nzero (nsucc Nn) 0≥Sn _ = ⊥-elim (S≤0→⊥ Nn 0≥Sn) x≥y→y>0→x∸y<x (nsucc {m} Nm) (nsucc {n} Nn) Sm≥Sn Sn>0 = lt (succ₁ m ∸ succ₁ n) (succ₁ m) ≡⟨ ltLeftCong (S∸S Nm Nn) ⟩ lt (m ∸ n) (succ₁ m) ≡⟨ x∸y<Sx Nm Nn ⟩ true ∎ x<y→y≤z→x<z : ∀ {m n o} → N m → N n → N o → m < n → n ≤ o → m < o x<y→y≤z→x<z Nm Nn No m<n n≤o = case (λ n<o → <-trans Nm Nn No m<n n<o) (λ n≡o → x<y→y≡z→x<z m<n n≡o) (x<Sy→x<y∨x≡y Nn No n≤o) ------------------------------------------------------------------------------ -- Properties about the lexicographical order xy<00→⊥ : ∀ {m n} → N m → N n → ¬ (Lexi m n zero zero) xy<00→⊥ Nm Nn mn<00 = case (λ m<0 → ⊥-elim (x<0→⊥ Nm m<0)) (λ m≡0∧n<0 → ⊥-elim (x<0→⊥ Nn (∧-proj₂ m≡0∧n<0))) mn<00 0Sx<00→⊥ : ∀ {m} → ¬ (Lexi zero (succ₁ m) zero zero) 0Sx<00→⊥ 0Sm<00 = case 0<0→⊥ (λ 0≡0∧Sm<0 → S<0→⊥ (∧-proj₂ 0≡0∧Sm<0)) 0Sm<00 Sxy<0y'→⊥ : ∀ {m n n'} → ¬ (Lexi (succ₁ m) n zero n') Sxy<0y'→⊥ Smn<0n' = case S<0→⊥ (λ Sm≡0∧n<n' → ⊥-elim (0≢S (sym (∧-proj₁ Sm≡0∧n<n')))) Smn<0n' xy<x'0→x<x' : ∀ {m n} → N n → ∀ {m'} → Lexi m n m' zero → m < m' xy<x'0→x<x' Nn mn<m'0 = case (λ m<n → m<n) (λ m≡n∧n<0 → ⊥-elim (x<0→⊥ Nn (∧-proj₂ m≡n∧n<0))) mn<m'0 xy<0y'→x≡0∧y<y' : ∀ {m} → N m → ∀ {n n'} → Lexi m n zero n' → m ≡ zero ∧ n < n' xy<0y'→x≡0∧y<y' Nm mn<0n' = case (λ m<0 → ⊥-elim (x<0→⊥ Nm m<0)) (λ m≡0∧n<n' → m≡0∧n<n') mn<0n' [Sx∸Sy,Sy]<[Sx,Sy] : ∀ {m n} → N m → N n → Lexi (succ₁ m ∸ succ₁ n) (succ₁ n) (succ₁ m) (succ₁ n) [Sx∸Sy,Sy]<[Sx,Sy] Nm Nn = inj₁ (Sx∸Sy<Sx Nm Nn) [Sx,Sy∸Sx]<[Sx,Sy] : ∀ {m n} → N m → N n → Lexi (succ₁ m) (succ₁ n ∸ succ₁ m) (succ₁ m) (succ₁ n) [Sx,Sy∸Sx]<[Sx,Sy] Nm Nn = inj₂ (refl , Sx∸Sy<Sx Nn Nm)
38.256757
88
0.440834